From wuwei23 at gmail.com Mon Jun 1 00:24:19 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 May 2009 21:24:19 -0700 (PDT) Subject: try except inside exec References: Message-ID: <451db527-8616-4f7c-96d7-4bc85dca2392@s21g2000vbb.googlegroups.com> Michele Petrazzo wrote: > I want to execute a python code inside a string and so I use the exec > statement. The strange thing is that the try/except couple don't catch > the exception and so it return to the main code. > Is there a solution to convert or make this code work? > > My code: > > STR = """ > err = 0 > try: > ? ?def a_funct(): > ? ? ?1/0 > except: > ? ?import traceback > ? ?err = traceback.format_exc() > """ > > env = {} > exec STR in env > env["a_funct"]() > print env["err"] Hello Michele, >From your code, I'm not sure if you're aware that functions are themselves objects within Python. You could avoid the use of exec entirely by doing something like the following: import traceback class FuncTester(object): def __init__(self, function): self.function = function def test(self, *args, **kwargs): self.result, self.error = None, None try: self.result = self.function(*args, **kwargs) success = True except: self.error = traceback.format_exc() success = False return success >>> def f(x): return 'f does this: %s' % x ... >>> ft = FuncTester(f) # note that we're referring to the function directly >>> ft.test('foo') True >>> ft.result 'f does this: foo' >>> ft.test() False >>> print ft.error Traceback (most recent call last): File "tester.py", line 10, in test self.result = self.function(*args, **kwargs) TypeError: f() takes exactly 1 argument (0 given) I think you'll find this approach to be a lot more flexible than using exec. Hope this helps, alex23 From aahz at pythoncraft.com Mon Jun 1 01:06:16 2009 From: aahz at pythoncraft.com (Aahz) Date: 31 May 2009 22:06:16 -0700 Subject: pygame error: file is not a windows bmp file References: Message-ID: In article , Djames Suhanko wrote: > >"pygame error: file is not a windows bmp file" > > I couldn't found a solution for this problem. >My python script run fine in local machine using cxfreeze, but don't >work when copied to my live linux system. >If I put bmp image, works fine, but png don't. >Can you help me? Convert with PIL? http://www.pythonware.com/products/pil/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From wuwei23 at gmail.com Mon Jun 1 01:23:19 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 May 2009 22:23:19 -0700 (PDT) Subject: Compiling and transporting modules/libraries in python References: <249dbf4f-ef3e-495e-975e-05d848279d39@u10g2000vbd.googlegroups.com> Message-ID: <69a7961c-c394-4df1-bcb7-cc18aa162817@z14g2000yqa.googlegroups.com> On May 31, 2:27?am, Abe wrote: > ? ? I use python at a home office and in a university computer lab, > but I don't have the administrative rights to install libraries on the > lab computers. ?It would be really nice if there were a way I could > put, say, all of numpy into a file "my_numpy.pyc" and treat it as a > single (large) module. You should be able to use virtualenv to provide this functionality: http://pypi.python.org/pypi/virtualenv Create the environment you want on your home computer, then copy it wholesale to your lab computer or even use it directly from a USB device. You might also want to look into one of the portable Python set ups. This way you can have a fully portable environment that you control completely: Portable Python: http://www.portablepython.com/ Movable Python: http://www.voidspace.org.uk/python/movpy/ Hope this helps. alex23 From aleksandar27 at BRISIOVOnet.hr Mon Jun 1 02:05:49 2009 From: aleksandar27 at BRISIOVOnet.hr (alejandro) Date: Mon, 1 Jun 2009 08:05:49 +0200 Subject: Is there any module for sea tides? Message-ID: I found some in C but could not find in Python.... From CGenie at gmail.com Mon Jun 1 02:24:46 2009 From: CGenie at gmail.com (P. Kaminski) Date: Sun, 31 May 2009 23:24:46 -0700 (PDT) Subject: automated web with python? References: Message-ID: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> OK, thanks, I'll give it a try, From stefan_ml at behnel.de Mon Jun 1 02:38:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Jun 2009 08:38:52 +0200 Subject: Turning HTMLParser into an iterator In-Reply-To: <94817710-8bca-4cad-84f5-32d3c5d44ce7@s21g2000vbb.googlegroups.com> References: <94817710-8bca-4cad-84f5-32d3c5d44ce7@s21g2000vbb.googlegroups.com> Message-ID: <4a23777c$0$31339$9b4e6d93@newsspool4.arcor-online.net> samwyse wrote: > I'm processing some potentially large datasets stored as HTML. I've > subclassed HTMLParser so that handle_endtag() accumulates data into a > list, which I can then fetch when everything's done. I'd prefer, > however, to have handle_endtag() somehow yield values while the input > data is still streaming in. I'm sure someone's done something like > this before, but I can't figure it out. Can anyone help? Thanks. If you can afford stepping away from HTMLParser, you could give lxml a try. Its iterparse() function supports HTML parsing. http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk Stefan From lie.1296 at gmail.com Mon Jun 1 03:18:58 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 01 Jun 2009 07:18:58 GMT Subject: Metaclass mystery In-Reply-To: <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> Message-ID: LittleGrasshopper wrote: > On May 31, 2:03 pm, a... at pythoncraft.com (Aahz) wrote: >> In article , >> >> LittleGrasshopper wrote: >>>> On May 31, 12:19=A0am, Arnaud Delobelle wrote: >>>>> [1]http://www.python.org/download/releases/2.2.3/descrintro/ >>> I'm about 2/3 of the way through this paper (although I don't claim to >>> understand all of it.) There is some heavy duty material in there, >>> enough to make me feel really stupid and frustrated at times. I'm >>> making connections as I go though, hopefully everything will sink in >>> eventually. >>> Is this stuff actually tough, or am I just a dummy? >> Definitely tough! Metaclasses can cause dain bramage. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- >> on-a-new-machine-ly y'rs - tim > > Good to know, I'll stick to it and persevere. Will check doctor > regularly for dain bramage though. Fortunately python makes it rare that we actually need to use metaclass. Especially with class decorators and such... With that said, the rare cases where it is really needed; brain hemorrhage is not only possible but when. From CGenie at gmail.com Mon Jun 1 03:26:42 2009 From: CGenie at gmail.com (P. Kaminski) Date: Mon, 1 Jun 2009 00:26:42 -0700 (PDT) Subject: automated web with python? References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: Ech... The problem is that mechanize doesn't support JavaScript, and these web forms are full of various JS functions... Maybe someone knows a way out of this? Doesn't have to be Python... From michele.simionato at gmail.com Mon Jun 1 03:42:31 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Jun 2009 00:42:31 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> Message-ID: <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> On May 31, 2:32?am, LittleGrasshopper wrote: > Seriously, metaclasses are making my brain hurt. How do people like > Michele Simionato and David Mertz figure these things out? Does it all > come to looking at the C source code for the CPython interpreter? Actually I never looked at the C source code. I performed lots of experiments and figured things out the hard way, with trial and errors. Metaclasses are not that hard, descriptors and super were much harder to grasp at that time, since there was next to zero documentation and a set of subtle bugs. For descriptors now there is Raymond Hettinger essay and for super there are my blog posts on Artima: http://www.artima.com/weblogs/index.jsp?blogger=micheles&start=45&thRange=15 (there are also two posts of mine about metaclasses in Python 3.0 that you may want to read) HTH, Michele From jeremiah.dodds at gmail.com Mon Jun 1 04:22:24 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Mon, 1 Jun 2009 09:22:24 +0100 Subject: automated web with python? In-Reply-To: References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: <12cbbbfc0906010122s9733ae9l2496a30cd6894684@mail.gmail.com> On Mon, Jun 1, 2009 at 8:26 AM, P. Kaminski wrote: > Ech... The problem is that mechanize doesn't support JavaScript, and > these web forms are full of various JS functions... Maybe someone > knows a way out of this? Doesn't have to be Python... > -- > http://mail.python.org/mailman/listinfo/python-list > Selenium _might_ be able to help you out. Otherwise, a method you can use (tedious at first, but can speed things up significantly) would be to either use firefox and grab the headers you're sending during a session (the site may use javascript really heavily, but in the end all that matters is that you're sending the same POST/GET requests), and then use mechanize, or read the javascript, and then use mechanize. At my job, I've had to automate a few really javascript-heavy web applications. Firefox+FireBug+HTTPFox with python and mechanize can be a lifesaver here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Jun 1 05:01:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Jun 2009 06:01:40 -0300 Subject: [Tutor] Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: En Mon, 01 Jun 2009 00:28:12 -0300, Michael H. Goldwasser escribi?: > Hi Kent, > > Thanks for your thoughts. > > For the original example code, you are correct that we could make it > work by having B provide the one-arg constructor to match A's > constructor signature. But I don't see this as a general solution. > > Having B.__deepcopy__() make a call to A.__deepcopy__() assumes that A > supports __deepcopy__ either direclty or indirectly. This is not > guaranteed as __deepcopy__ is not supported all the way back to the > object base class. It could be that the author of A has guaranteed > that the syntax deepcopy(instanceA) is properly supported, but that > could be done by other means without an explicit __deepcopy__ (such as > relying on a true deep copy, or using getstate/setstate to affect both > pickling and deepcopy). In general, you have to know whether A implements __deepcopy__ or not. This is a small price for the flexibility (or anarchy) in the copy/pickle interfases: there are several ways to implement the same thing, and you have to know which one your base class has chosen in order to extend it. The following is a possible implementation that doesn't use __init__ at all, so their different signature is not an issue: # class A: def __deepcopy__(self, memo={}): dup = type(self).__new__(type(self)) dup.__aTag = self.__aTag dup.__aList = copy.deepcopy(self.__aList, memo) dup.__aList.reverse() return dup # class B: def __deepcopy__(self, memo={}): dup = A.__deepcopy__(self, memo) dup.__bTag = self.__bTag dup.__bList = copy.deepcopy(self.__bList, memo) return dup Note that A.__deepcopy__ does two things: a) create a new, empty, instance; and b) transfer state. B.__deepcopy__ handles *its* portion of state only. This can be written in a more generic way, relying on __getstate__/__setstate__ (the methods that should return the current state of the object): # class A: def __deepcopy__(self, memo={}): dup = type(self).__new__(type(self)) if hasattr(self, '__getstate__'): state = self.__getstate__() else: state = self.__dict__ state = copy.deepcopy(state, memo) if hasattr(dup, '__setstate__'): dup.__setstate__(state) else: dup.__dict__.update(state) dup.__aList.reverse() return dup # remove __deepcopy__ definition from class B Now, B (and any other subclass) is concerned only with __getstate__ / __setstate__, and only when the default implementation isn't appropriate. > As another basic puzzle, consider a class definition for B where B has > a registry list that it doesn't want cloned for the new instance (but > it does want pickled when serialized). This would seem to require > that B implement its own __deepcopy__. We want to somehow rely on > the class definition for A to enact the cloning fo the state defined > by A. But without knowing about how A supports the deepcopy > semantics, I don't see how to accomplish this goal. I don't understand such bizarre requirement, but anyway, you can override __deepcopy__ (make B fix only the part that the default implementation doesn't implement well) # A.__deepcopy__ as above # class B: def __deepcopy__(self, memo={}): dup = A.__deepcopy__(self, memo) dup.__registry = self.__registry return dup This [the need to know how certain feature is implemented in the base class] is not special or peculiar to pickle/copy, although the multiple (and confusing) ways in which a class can implement pickling doesn't help to understand the issue very well. Consider the + operator: when some subclass wants to implement addition, it must know which of the several special methods involved (__add__, __iadd__, __radd__) are implemented in the base class, in order to extend/override them. Same for __cmp__/__eq__/__hash__: you can't just ignore what your base class implements. All of this applies to other languages too, but in Python, there is an additional consideration: the mere *existence* of some methods/attributes can have consequences on how the object behaves. In short, you can't blindly write __special__ methods. -- Gabriel Genellina From piet at cs.uu.nl Mon Jun 1 05:07:02 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 11:07:02 +0200 Subject: what I would like python.el to do (and maybe it does) References: <85ljolfgaa.fsf@agentultra.com> <87prdsxapj.fsf@agentultra.com> Message-ID: >>>>> J Kenneth King (JKK) wrote: >JKK> Well, that's the thing -- type a statement into a python interpreter and >JKK> you just get a new prompt. >JKK> LISP has a REPL, so you get some sort of feedback printed. iPython also has a REPL, but only when you enter the Python code manually in the iPython window. >JKK> However, some sort of visual cue on the emacs side would be nice. Either >JKK> just flash the block of code being sent or a minibuffer message would be >JKK> nice. >JKK> Look for some SLIME tutorial videos on youtube to see some great >JKK> interpreter <-> editor interaction. I have tried out SLIME with SBCL (just some simple code) but I didn't like the feedback. I got unnecessary compiler warnings, and it was difficult to find some useful information in it. >JKK> The stock Python interpreter probably wouldn't cut it close to something >JKK> like SLIME in terms of features, but the iPython package might be a >JKK> start. For now the iPython package for me has more options than I have had time to try out. On the other hand when you execute some code form a Python file (with C-c C-c or C-c |) you get this ## working on region in file /tmp/python-26084kfr.py... in the *Python* buffer which is very uninformative. This is generated by python-mode, not by iPython. You do get any output printed in the code, however, as well as exceptions. I have made a change in my Python mode such that the ## working on region in file /tmp/python-26084kfr.py... message will be replaced by the actual code executed, if that code is not too big (size configurable). And that looks nicer. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jeanmichel at sequans.com Mon Jun 1 05:21:28 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Jun 2009 11:21:28 +0200 Subject: NameError function not found In-Reply-To: <5700df6b0905291213y4ee08697xb336797adeb468a2@mail.gmail.com> References: <5700df6b0905291213y4ee08697xb336797adeb468a2@mail.gmail.com> Message-ID: <4A239D98.9070107@sequans.com> Cameron Pulsford wrote: > Hey everyone, I am extremely stumped on this. I have 2 functions.. > > def _determinant(m): > return m[0][0] * m[1][1] - m[1][0] * m[0][1] > > def cofactor(self): > """Returns the cofactor of a matrix.""" > newmatrix = [] > for i, minor in enumerate(self.minors()): > newmatrix.append(_determinant(minor.matrix) * ((i%2) * -1)) > return newmatrix > > And I get the following error when I try to run a.cofactor()... > > "NameError: global name '_determinant' is not defined" > > When I put the _determinant function nested within the cofactor > function it works fine. Normally I would do this, but a lot of other > methods use the _determinant method. They are both in the same class, > and they are at the same level, they are even in that order so I know > it should be able to see it. I have a lot of functions that call > other functions in this class and everything is fine. [Also for the > picky, I know my cofactor method isn't mathematically correct yet ;-) > ] Am I missing something obvious here? Also if it helps the rest of > the code is > herehttp://github.com/dlocpuwons/pymath/blob/d1997329e4473f8f6b5c7f11635dbd719d4a14fa/matrix.py though > it is not the latest. Maybe someone has already answered... Looks like cofactor is in a class, so I'm assuming _determinant is in that class as well. 3 solutions: - declare _determinant outside of the class, making it a private module function - declare _determinant as method of the instance : def _determinant(self) - if you want to keep _determinant as part of your class, it's up to you but you have to declare it as staticmethod (goolge it for details) For isntance : class MyClass def _determant()m: ... _determant = staticmethod(_determinant) def cofactor(self): ... x = MyClass._determinant(y) # this is how you call static Class method, but rarely these methods are set private (_ prefix) Jean-Michel From piet at cs.uu.nl Mon Jun 1 05:38:05 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 11:38:05 +0200 Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: >>>>> LittleGrasshopper (L) wrote: >L> On May 31, 3:59?pm, Carl Banks wrote: >>> On May 31, 3:52?pm, LittleGrasshopper wrote: >>> >>> >>> >>> > This is some simple code which I got from Guido's paper on the >>> > unification of classes and types, which Arnaud suggested to improve my >>> > knowledge of metaclasses: >>> >>> > class M1(type): >>> > ? ? pass >>> > class M2(M1): >>> > ? ? pass >>> > class M3(M2): >>> > ? ? pass >>> > class C1: >>> > ? ? __metaclass__ = M1 >>> > class C2(C1): >>> > ? ? __metaclass__ = M2 >>> > class C3(C1, C2): >>> > ? ? __metaclass__ = M3 >>> >>> > It is failing when processing C3: >>> > Traceback (most recent call last): >>> > ? File "metaerror.py", line 18, in >>> > ? ? class C3(C1, C2): >>> > TypeError: Error when calling the metaclass bases >>> > ? ? Cannot create a consistent method resolution >>> > order (MRO) for bases C2, C1 [snip] >L> I guess the resulting MROs do not satisfy monotonicity, I >L> just have to find out how to derive the MRO. I had the notion that it >L> was constructed by listing the current class, followed by the MROs of >L> each base in order, and then retaining the rightmost instance of each >L> class in the MRO list, but I think that might be an >L> oversimplification, since in this case that would be: >L> (C1, object) >L> (C2, C1, object) >L> (C3, C2, C1, object) >L> And I don't see any issues. But I'll read the paper to figure out what >L> the problem is, thanks. Here is exactly the problem. Merging the two MRO's as you state would give C3, C2, C1, object, i.e. C2 before C1. But your class definition: class C3(C1, C2): says that C1 should be before C2. Conflict!! Change it to class C3(C2, C1): You see it has nothing to do with the metaclasses. The following code gives the same error: class C1(object): pass class C2(C1): pass class C3(C1, C2): pass -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From visco31 at gmail.com Mon Jun 1 06:40:50 2009 From: visco31 at gmail.com (Visco Shaun) Date: Mon, 01 Jun 2009 16:10:50 +0530 Subject: "TypeError: 'int' object is not callable" Message-ID: <1243852850.5259.4.camel@ajc> when I was executing the below code I got "TypeError: 'int' object is not callable" exception. Why is it so? if type(c) == type(ERROR): c can be a string or an integer representing an error -- Thanks & Regards visco From ldo at geek-central.gen.new_zealand Mon Jun 1 06:41:44 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Jun 2009 22:41:44 +1200 Subject: Ah, ctypes Message-ID: I wrote some code months ago to output 1-bit-per-pixel PNG files from Python, doing direct calls to libpng using ctypes, because PIL didn't give me sufficient control over colour tables and pixel depths. I thought the code was working fine. I left it aside for some months, came back to it a week or two ago, and found it was crashing. I was creating CFUNCTYPE objects to do callbacks to my own I/O routines, and with GDB I was able to narrow down the crashes to the point where libpng was trying to invoke one of my callbacks. What had changed? I had switched my OS from Gentoo to Debian Unstable. I chrooted back to the Gentoo system, tried my script again--still crashed. Went back to the doc and tried the qsort callback example. Worked fine! And then I noticed this little bit: Important note for callback functions: Make sure you keep references to CFUNCTYPE objects as long as they are used from C code. ctypes doesn?t, and if you don?t, they may be garbage collected, crashing your program when a callback is made. Yup, that was it. I changed my installation of the callbacks from png.png_set_write_fn \ ( write_struct, None, ct.CFUNCTYPE(None, ct.c_void_p, ct.c_void_p, ct.c_size_t)(write_data), ct.CFUNCTYPE(None, ct.c_void_p)(flush_write) ) to cb_write_data = ct.CFUNCTYPE(None, ct.c_void_p, ct.c_void_p, ct.c_size_t)(write_data) cb_flush_write = ct.CFUNCTYPE(None, ct.c_void_p)(flush_write) png.png_set_write_fn \ ( write_struct, None, cb_write_data, cb_flush_write ) and it works again. From piet at cs.uu.nl Mon Jun 1 06:44:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 12:44:17 +0200 Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: >>>>> Piet van Oostrum (I) wrote: >I> But your class definition: >I> class C3(C1, C2): >I> says that C1 should be before C2. Conflict!! >I> Change it to class C3(C2, C1): Of course the C1 is then superfluous. I wonder why you want this. What is the problem you want to solve? Apart from the metaclasses (that you still can use with `class C3(C2)') I could think of the following use case: class C1(object): def m1(self): return 'C1.m1' class C2(C1): # override m1 def m1(self): return 'C2.m1' def m2(self): return 'C2.m2'+self.m1() class C3(C1, C2): def test(self): print self.m1()+self.m2() i.e. in C3 we `ignore' the override of m1 in C2 but still want to make use of the m2 from C2. The question that arises then is: the self.m1() inside m2, which m1 should it use? For an instance of C3 it would use C1.m1, but for an instance of C2 it would use C2.m2. However, every instance of C3 can also be considered an instance of C2, (Liskov substitution principle), therefore there is a conflict. That is exactly the conflict that the MRO signals. If you want that kind of behaviour it can be solved by using a mixin class for the m2 method: class C1(object): __metaclass__ = M1 def m1(self): return 'C1.m1' class Cmix(object): def m2(self): return 'C2.m2'+self.m1() class C2(C1, Cmix): __metaclass__ = M2 # override m1 def m1(self): return 'C2.m1' class C3(C1, Cmix): __metaclass__ = M3 def test(self): print self.m1()+self.m2() -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From R.Brodie at rl.ac.uk Mon Jun 1 06:45:29 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 1 Jun 2009 11:45:29 +0100 Subject: "TypeError: 'int' object is not callable" References: Message-ID: "Visco Shaun" wrote in message news:mailman.966.1243852864.8015.python-list at python.org... > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): You've probably assigned to type somewhere in your code. What does print repr(type) give? From steve at holdenweb.com Mon Jun 1 06:45:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Jun 2009 06:45:48 -0400 Subject: Not going to let this drop ... Message-ID: <4A23B15C.3090403@holdenweb.com> If you have a few minutes to read this message you might just be able to make a big difference to the lives of some very disadvantaged people. If you can't help, don't worry. Sorry for bothering you. There's a project that needs help. The chuzer project is moribund (the rest of this message explains what it is). I accept responsibility for that. I have had a lot on my plate recently, but everything is relative, and my information from other sources tells me that some recipients of this email have far worse problems than I. Paul McNett said in a recent email "this seems like too noble a project to die", and I agree with him. It seems to me that a really quite small amount of development time could see us producing a system that would add a huge amount to the lives of some of the most needy people we can imagine. Or not. Frankly, it's the imagining that scares me. I am having real difficulty imagining what it might be like to be in a position where I can't easily tell someone what I need. The chuzer project will allow severely disabled people to express the most basic needs. Maybe "what I want for pudding" wasn't a particularly good example, but it was the one the project was motivated by, and it's hard to think how frustrating it must be when being able to tell someone what you want for pudding represents an improvement in your quality of life. There are quadriplegics out there with such a limited range of expressive ability that the only way they can express any choice at all is to watch a series of selections tick by until the right one comes up, and then puff into a pipe or bite down on something - basically, perform one of the very few movements of which they are capable - to say "that's what I want". Yes, it might be "what I want for pudding", but how about even more basic choices: a) I need to pee b) I have to take a dump c) I am hungry d) I am thirsty e) Please hug me f) My bedsores are hurting The big problem for a lot of quadriplegics, as far as I understand it, is that uninformed people treat them as though their brains were as damaged as their bodies. Most readers of this email will be able-bodied. Please try and imagine what it would be like to be entombed in a full-body plaster cast and be unable to speak, but to still retain your full mental faculties. Don't you think you might really appreciate even something as simple as a choice program? I was intending to try and recruit assistance at PyCon, but sadly on the Saturday I received news of my mother's death, so that kind of put the kibosh on that, and I had to leave early. I also recently realized rather too late that this project would be an excellent candidate for a Google Summer of Code project, but that's already underway now. Again, I apologize for not having the time to bring chuzer to enough people's attention to get it on the GSoc radar. My bad. I don't know if Google are planning to run a Highly-Open Participation event this year, but if they are then maybe we could establish a few tasks for that. Basically this is a project that really needs some help right now. There's a basic working model, around which an image-selection and audio-recording infrastructure needs to be built so that it's easy for carers to set up appropriate choices and easy for users to indicate choices. It's not rocket science, it just needs a few of us to care enough to keep moving this project forward until it's done. It would make an excellent wxPython learning project. If anyone who reads this email has anything to offer - time, money, equipment, whatever, I'd be *really* grateful to hear from them. I can put you in touch with people who know about things like the range of interface devices available for paraplegic and quadriplegic people. Ideally the program would be adaptable to a wide range of hardware accommodating a broad spectrum of disability, but many quadriplegics use equipment that emulates a standard keyboard and/or mouse, so that would be a great start. Please help, even if only by publicizing this project. You don't even have to code, just to help with ideas for recruiting coding assistance. http://chuzer.org/ Even better, please join the mailing list linked on the site, and help to make the world a better place. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ From andreengels at gmail.com Mon Jun 1 06:48:34 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 1 Jun 2009 12:48:34 +0200 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: <6faf39c90906010348y21167e7ancf5421ef5098d827@mail.gmail.com> On Mon, Jun 1, 2009 at 12:40 PM, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error Could you please give a larger piece of code, preferably such that it can functions as a small stand-alone program that gives the same error message? It looks to me that the problem is most likely in a previous or subsequent line. -- Andr? Engels, andreengels at gmail.com From clp2 at rebertia.com Mon Jun 1 06:50:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 03:50:31 -0700 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: <50697b2c0906010350u8c970a3i3edcf7f055993dcd@mail.gmail.com> On Mon, Jun 1, 2009 at 3:40 AM, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error Please also, now and in the future, provide the full error traceback as it is very necessary in order to determine the problem. Cheers, Chris -- http://blog.rebertia.com From CGenie at gmail.com Mon Jun 1 07:14:12 2009 From: CGenie at gmail.com (P. Kaminski) Date: Mon, 1 Jun 2009 04:14:12 -0700 (PDT) Subject: automated web with python? References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: <74dbd67c-7a64-4df1-9ef9-6903b1b01c1c@o14g2000vbo.googlegroups.com> OK, I found a solution -- Selenium, from http://selenium.org. I downloaded Selenium RC and this works fantastic! I'll get the job done by tomorrow ;) From djames.suhanko at gmail.com Mon Jun 1 07:16:54 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 1 Jun 2009 08:16:54 -0300 Subject: BMP32 for linux Message-ID: Hello, all! Did you know the bmp32 module for linux? This module can to load bmp image with alpha channel where is not supported others images formats. But I couldn't to found this module to install in my linux box. :-( do you have tips? Thanks ! -- Djames Suhanko LinuxUser 158.760 From rhodri at wildebst.demon.co.uk Mon Jun 1 07:16:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 01 Jun 2009 12:16:57 +0100 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: On Mon, 01 Jun 2009 11:40:50 +0100, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error In the absence of the rest of your code this is a wild guess, but have you used `type` as a variable? If you have, that would mask the builtin name `type`, and would give you this error assuming `type` contains an integer. Moral: don't use builtin names for variables. -- Rhodri James *-* Wildebeeste Herder to the Masses From electriclightheads at gmail.com Mon Jun 1 08:49:11 2009 From: electriclightheads at gmail.com ('2+) Date: Mon, 1 Jun 2009 21:49:11 +0900 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) Message-ID: <1078018b0906010549y6f3bd5ebu1270d047644841ef@mail.gmail.com> would like to take advantage of the wave module found a good example here: http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 hmm .. i don't get how to write a stereo .. i mean i can set nchannels .. but how do i actually take control of each ch individually? and what's the range(in float) of the data i can set in wav_file.writeframes(struct.pack('h', data))? tia -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml and supplying oil.py for free: http://oilpy.blogspot.com/ From ed at leafe.com Mon Jun 1 09:00:25 2009 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Jun 2009 09:00:25 -0400 Subject: Dabo 0.9.2 released Message-ID: At long last, we are finally releasing Dabo 0.9.2. This fixes the errors that were found in 0.9.1; adds a brand-new Web Update implementation that should make keeping current much easier, as well as a whole bunch of improvements under the hood. You can grab the latest version at http://dabodev.com/download. -- Ed Leafe From john.center at villanova.edu Mon Jun 1 09:05:52 2009 From: john.center at villanova.edu (John Center) Date: Mon, 1 Jun 2009 06:05:52 -0700 (PDT) Subject: Problem building 64-bit python 2.6.2 on Solaris 10 References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> Message-ID: <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> On May 29, 7:13?pm, "Martin v. L?wis" wrote: > > Ah, too much text - I was confused by you reporting two issues in a > single email message. That has exhausted my capacity for quick message > scanning. > Sorry about that. I have a tendency to over document... > So this is a ctypes problem. You'll have to ignore it - there is > absolutely no way that you could possibly build the ctypes module > with Sun CC (short of rewriting ctypes to support it, of course). > Use gcc if you need the ctypes module, or accept not having the ctypes > module available. > I was afraid that would be the case. I have gcc4sparc, but I usually build with Sun Studio. I believe gcc4sparc uses the Sun Studio backend. I'll try this, but do you know if I would need to do anything different to get the ctypes code to compile? > Unfortunately, no. It is definitely *not* Python who is searching for > these libraries. That you had been passing them to ld during linkage > doesn't help at all. Linking succeeds just fine; Python then tries > to load the the _ssl module, which in turn causes the *dynamic* linker > (ld.so.1) to search for the shared library; it doesn't find it and > therefore gives up loading _ssl.so. > Ok, so it looks like the only option here is to use LD_LIBRARY_PATH. Thanks, Martin. -John From emin.shopper at gmail.com Mon Jun 1 09:06:18 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 09:06:18 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser Message-ID: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> Dear Experts, I am having some issues with the subprocess module and how it interacts with win32security.ImpersonateLoggedOnUser. Specifically, I use the latter to change users but the new user does not seem to be properly inherited when I spawn further subprocesses. I am doing something like import win32security, win32con handle = win32security.LogonUser( user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(handle) Then spawning subprocesses but the subprocesses cannot read the same UNC paths that that the parent could. Any advice on either spawning subprocesses which inherit parent user properly or changing users in a better way on Windows would be greatly appreciated. Thanks, -Emin From jeanmichel at sequans.com Mon Jun 1 09:30:38 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Jun 2009 15:30:38 +0200 Subject: Class Methods help In-Reply-To: References: <_QvUl.14954$y61.8697@news-server.bigpond.net.au> Message-ID: <4A23D7FE.1000102@sequans.com> FYI, same without decorators, if you python version does not support it. class MyClass: def some_func(x): return x+2 some_func = staticmethod(some_func) JM bd satish wrote: > Thanks to Tim Chase & Lie Ryan !! That was exactly what I was looking for !! > > It's time for me to now read the documentation of "decorators" and > @classmethod and also @staticmethod. > > I'm quite new to decorators... > > > -- Satish BD > > > On Sun, May 31, 2009 at 4:44 PM, Lie Ryan wrote: > >> bdsatish wrote: >> >>> Hi, >>> >>> I have a question regarding the difference b/w "class methods" and >>> "object methods". Consider for example: >>> >>> class MyClass: >>> x = 10 >>> >>> Now I can access MyClass.x -- I want a similar thing for functions. I >>> tried >>> >>> class MyClass: >>> def some_func(x): >>> return x+2 >>> >>> When I call MyClass.some_func(10) -- it fails, with error message: >>> >>> >>> TypeError: unbound method some_func() must be called with MyClass >>> instance as first argument (got int instance instead) >>> >>> OK. I figured out that something like this works: >>> obj = MyClass() >>> y = obj.some_func(10) >>> >>> BUT, this means that we have functions applying for instances. That is >>> we have "instance method". Now, how do I implement some function which >>> I can invoke with the class name itself ? Instead of creating a dummy >>> object & then calling.... In short, how exactly do I create "class >>> methods" ?? >>> >> with staticmethod decorator: >> >> >>>>> class MyClass: >>>>> >> ... @staticmethod >> ... def some_func(x): >> ... return x+2 >> ... >> >>>>> MyClass.some_func(10) >>>>> >> 12 >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> From mail at timgolden.me.uk Mon Jun 1 09:38:47 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 01 Jun 2009 14:38:47 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> Message-ID: <4A23D9E7.1080700@timgolden.me.uk> Emin.shopper Martinian.shopper wrote: > Dear Experts, > > I am having some issues with the subprocess module and how it > interacts with win32security.ImpersonateLoggedOnUser. Specifically, I > use the latter to change users but the new user does not seem to be > properly inherited when I spawn further subprocesses. > > I am doing something like > > import win32security, win32con > handle = win32security.LogonUser( > user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, > win32con.LOGON32_PROVIDER_DEFAULT) > > win32security.ImpersonateLoggedOnUser(handle) > > Then spawning subprocesses but the subprocesses cannot read the same > UNC paths that that the parent could. http://support.microsoft.com/kb/111545 """ Even if a thread in the parent process impersonates a client and then creates a new process, the new process still runs under the parent's original security context and not the under the impersonation token. """ TJG From emin.shopper at gmail.com Mon Jun 1 09:45:37 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 09:45:37 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <4A23D9E7.1080700@timgolden.me.uk> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> Message-ID: <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> Thanks. But how do I fix this so that the subprocess does inherit the impersonated stuff? On Mon, Jun 1, 2009 at 9:38 AM, Tim Golden wrote: > Emin.shopper Martinian.shopper wrote: >> >> Dear Experts, >> >> I am having some issues with the subprocess module and how it >> interacts with win32security.ImpersonateLoggedOnUser. Specifically, I >> use the latter to change users but the new user does not seem to be >> properly inherited when I spawn further subprocesses. >> >> I am doing something like >> >> ? ?import win32security, win32con >> ? ?handle = win32security.LogonUser( >> ? ? ? ?user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, >> ? ? ? ?win32con.LOGON32_PROVIDER_DEFAULT) >> >> ? ?win32security.ImpersonateLoggedOnUser(handle) >> >> Then spawning subprocesses but the subprocesses cannot read the same >> UNC paths that that the parent could. > > http://support.microsoft.com/kb/111545 > > """ > Even if a thread in the parent process impersonates a client and then > creates a new process, the new process still runs under the parent's > original security context and not the under the impersonation token. """ > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Mon Jun 1 10:03:45 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 01 Jun 2009 15:03:45 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> Message-ID: <4A23DFC1.6070209@timgolden.me.uk> [slightly rearranged for top-to-bottom reading...] > On Mon, Jun 1, 2009 at 9:38 AM, Tim Golden wrote: >> Emin.shopper Martinian.shopper wrote: >>> Dear Experts, >>> >>> I am having some issues with the subprocess module and how it >>> interacts with win32security.ImpersonateLoggedOnUser. Specifically, I >>> use the latter to change users but the new user does not seem to be >>> properly inherited when I spawn further subprocesses. >>> >>> I am doing something like >>> >>> import win32security, win32con >>> handle = win32security.LogonUser( >>> user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, >>> win32con.LOGON32_PROVIDER_DEFAULT) >>> >>> win32security.ImpersonateLoggedOnUser(handle) >>> >>> Then spawning subprocesses but the subprocesses cannot read the same >>> UNC paths that that the parent could. >> http://support.microsoft.com/kb/111545 >> >> """ >> Even if a thread in the parent process impersonates a client and then >> creates a new process, the new process still runs under the parent's >> original security context and not the under the impersonation token. """ >> >> TJG >> -- >> http://mail.python.org/mailman/listinfo/python-list Emin.shopper Martinian.shopper wrote: > Thanks. But how do I fix this so that the subprocess does inherit the > impersonated stuff? > The source for subprocess just uses CreateProcess. Which means that, short of monkey-patching it, you're going to have to roll your own subprocess-like code (I think). Basically, you'll need to run CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit of a pig in terms of getting the right combination of parameters and privileges, I seem to remember. Haven't got time right now to fish for an example, I'm afraid: maybe someone else on the list has a canned example...? Also worth cross-posting this to the python-win32 list where more win32 expertise resides. TJG From dudekksoft at gmail.com Mon Jun 1 10:16:07 2009 From: dudekksoft at gmail.com (dudekksoft at gmail.com) Date: Mon, 1 Jun 2009 07:16:07 -0700 (PDT) Subject: PyQt4 + WebKit References: Message-ID: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> On 31 Maj, 02:32, David Boddie wrote: > On Saturday 30 May 2009 17:39, dudekks... at gmail.com wrote: > > > I need to grab clicked links in QWebView. Everything is fine when I > > use linkClicked() signal. LinkDelegationPolicy is set to > > DelegateAllLinks and there is a problem. If some site has Javascript > > my procedure receives QUrl from linkClicked, next calls: > > > webView.setUrl(url) #Where "url" is received QUrl > > > Certainly this method doesn't work. Site loads again (in most cases > > it's calledhttp://mywwwsite.net/#). > > OK, so if I understand correctly, you don't know how to handle these > special links if you use a delegation policy, and you would prefer it > if they were handled by WebKit. > > > As I use > > QWebPage::DelegateExternalLinks it happens the same, because my > > procedure grabs links with Javascript. I don't know how to cope with > > this problem. Maybe it's possible to set own policy in > > QWebPage.LinkDelegationPolicy? Or maybe some other method to grab > > protocol, host(if external or not) when user clicks link in webView? > > So, you only want to handle certain links, and pass on to WebKit those which > you can't handle? Is that correct? > > David Yes, I want to handle external links (out of my host) and links starting with download://... (my specific protocol). From emin.shopper at gmail.com Mon Jun 1 10:29:16 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 10:29:16 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <4A23DFC1.6070209@timgolden.me.uk> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> <4A23DFC1.6070209@timgolden.me.uk> Message-ID: <32e43bb70906010729m298ffd71m94d3995a9b1fa878@mail.gmail.com> > The source for subprocess just uses CreateProcess. Which means that, > short of monkey-patching it, you're going to have to roll your own > subprocess-like code (I think). Basically, you'll need to run > CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit > of a pig in terms of getting the right combination of parameters > and privileges, Thanks. I tried rolling my own via CreateProcessAsUser but it complained about needing some special permissions so its probably not going to work. I'd like to try CreateProcessAsLogonW but can't see how to access that via python. I will start a new thread on the python-win32 list about that. Thanks, -Emin From james at agentultra.com Mon Jun 1 11:00:42 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 01 Jun 2009 11:00:42 -0400 Subject: what I would like python.el to do (and maybe it does) References: <85ljolfgaa.fsf@agentultra.com> <87prdsxapj.fsf@agentultra.com> Message-ID: <85ljocc82t.fsf@agentultra.com> Piet van Oostrum writes: >>>>>> J Kenneth King (JKK) wrote: > >>JKK> Well, that's the thing -- type a statement into a python interpreter and >>JKK> you just get a new prompt. > >>JKK> LISP has a REPL, so you get some sort of feedback printed. > > iPython also has a REPL, but only when you enter the Python code > manually in the iPython window. > >>JKK> However, some sort of visual cue on the emacs side would be nice. Either >>JKK> just flash the block of code being sent or a minibuffer message would be >>JKK> nice. > >>JKK> Look for some SLIME tutorial videos on youtube to see some great >>JKK> interpreter <-> editor interaction. > > I have tried out SLIME with SBCL (just some simple code) but I didn't > like the feedback. I got unnecessary compiler warnings, and it was > difficult to find some useful information in it. > >>JKK> The stock Python interpreter probably wouldn't cut it close to something >>JKK> like SLIME in terms of features, but the iPython package might be a >>JKK> start. > > For now the iPython package for me has more options than I have had time > to try out. > On the other hand when you execute some code form a Python file (with > C-c C-c or C-c |) you get this > ## working on region in file /tmp/python-26084kfr.py... in the *Python* > buffer which is very uninformative. This is generated by python-mode, > not by iPython. You do get any output printed in the code, however, as > well as exceptions. > > I have made a change in my Python mode such that the > ## working on region in file /tmp/python-26084kfr.py... > message will be replaced by the actual code executed, if that code is > not too big (size configurable). And that looks nicer. > -- > Piet van Oostrum > URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] > Private email: piet at vanoostrum.org If you have a patch file for that, I'd be interested in trying it out. :) From pataphor at gmail.com Mon Jun 1 11:11:00 2009 From: pataphor at gmail.com (pataphor) Date: Mon, 01 Jun 2009 17:11:00 +0200 Subject: Generating all combinations In-Reply-To: <78g79iF1l1i8bU1@mid.dfncis.de> References: <78g79iF1l1i8bU1@mid.dfncis.de> Message-ID: Johannes Bauer wrote: > Any help is appreciated! This is on the fringe of exploitation, but hey, maybe the code helps you think about the algorithm. IMHO the following code is a glaring complaint about the injustice of omission itertools inflicts on the perfectly natural and obvious procedure of repeat_each (whatever it's name ought to be): from itertools import izip, islice, cycle def repeat_each(seq,n): while True: for x in seq: for i in range(n): yield x def repeat_all(seq,n): while True: for i in range(n): for x in seq: yield x def product(X): N = [] total = 1 for x in X: N.append(total) total *= len(x) R = [repeat_all(repeat_each(x,k),n) for x,k,n in izip(X,N,reversed(N))] return islice(izip(*R),total) def test1(): L = ['a', 'bc','def' ] for x in product(L): print x print def test2(): repeat_all = cycle test1() if __name__ == '__main__': test1() test2() See? Repeat_all and repeat_each are almost brothers, just separated by the tiniest rearrangement of their genetic code (or should I say code genetics?). Yet one is included as 'itertools.cycle' and the other is doomed to live in limbo. Such injustice! Can it be that 'itertools.repeat' has usurped repeat_each's rightful position? P. From martin at v.loewis.de Mon Jun 1 11:16:38 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 01 Jun 2009 17:16:38 +0200 Subject: Building PIL under Cygwin & Python 2.5 In-Reply-To: References: Message-ID: <4a23f0d6$0$7169$9b622d9e@news.freenet.de> > I think this is an issue that probably needs to be addressed by PIL > maintainers that fully understand the root of the problem (and it > should probably go in the PIL FAQ), but in the meantime does anyone > out there know how to get around this issue? Why do you need to use Cygwin Python? Regards, Martin From nick at craig-wood.com Mon Jun 1 11:29:44 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 01 Jun 2009 10:29:44 -0500 Subject: Ah, ctypes References: Message-ID: Lawrence D'Oliveiro wrote: > I wrote some code months ago to output 1-bit-per-pixel PNG files from > Python, doing direct calls to libpng using ctypes, because PIL didn't give > me sufficient control over colour tables and pixel depths. > > I thought the code was working fine. I left it aside for some months, came > back to it a week or two ago, and found it was crashing. I was creating > CFUNCTYPE objects to do callbacks to my own I/O routines [snip] > Make sure you keep references to CFUNCTYPE objects as long as they are > used from C code. ctypes doesn?t, and if you don?t, they may be garbage > collected, crashing your program when a callback is made. > > Yup, that was it. I changed my installation of the callbacks from [snip] As a ctypes user I found this an interesting story - thanks for posting it! ctypes could potentially note that function types don't have enough references to them when passed in as arguments to C functions? It might slow it down microscopically but it would fix this problem. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From martin.hellwig at dcuktec.org Mon Jun 1 11:50:02 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 01 Jun 2009 16:50:02 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> <4A23DFC1.6070209@timgolden.me.uk> Message-ID: <-OidnR8Bs7AtZb7XnZ2dnUVZ8jydnZ2d@bt.com> Emin.shopper Martinian.shopper wrote: >> The source for subprocess just uses CreateProcess. Which means that, >> short of monkey-patching it, you're going to have to roll your own >> subprocess-like code (I think). Basically, you'll need to run >> CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit >> of a pig in terms of getting the right combination of parameters >> and privileges, > > Thanks. I tried rolling my own via CreateProcessAsUser but it > complained about needing some special permissions so its probably not > going to work. I'd like to try CreateProcessAsLogonW but can't see how > to access that via python. I will start a new thread on the > python-win32 list about that. > > Thanks, > -Emin Maybe this post on my blog http://blog.dcuktec.com/2009/05/python-on-windows-from-service-launch.html can be of some help for you, although it was more thought to run under LocalSystem instead of another active user. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From Scott.Daniels at Acm.Org Mon Jun 1 11:53:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 08:53:57 -0700 Subject: BMP32 for linux In-Reply-To: References: Message-ID: Djames Suhanko wrote: > Hello, all! > Did you know the bmp32 module for linux? This module can to load bmp > image with alpha channel where is not supported others images formats. Hmmm, why do you think PNG and TGA do not support alpha? --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Mon Jun 1 12:13:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 01 Jun 2009 18:13:39 +0200 Subject: Problem building 64-bit python 2.6.2 on Solaris 10 In-Reply-To: <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> Message-ID: <4a23fe33$0$20453$9b622d9e@news.freenet.de> > Ok, so it looks like the only option here is to use LD_LIBRARY_PATH. Not really: there is also crle, and LD_RUN_PATH. Regards, Martin From pruebauno at latinmail.com Mon Jun 1 12:19:59 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 1 Jun 2009 09:19:59 -0700 (PDT) Subject: Illegal seek with os.popen Message-ID: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Should I open a bug report for this? Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') >>> Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> os.popen('cat','w') Traceback (most recent call last): File "", line 1, in File "/Python-3.1rc1/Lib/os.py", line 641, in popen return _wrap_close(io.TextIOWrapper(proc.stdin), proc) IOError: [Errno 29] Illegal seek >>> From djames.suhanko at gmail.com Mon Jun 1 12:40:14 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 1 Jun 2009 13:40:14 -0300 Subject: BMP32 for linux In-Reply-To: References: Message-ID: Thank you for answer, Scott ! The python in my embbeded system have not support to others formats. :-( Then, I found a tip about bmp32 with alpha channel, but I don't have this module (bmp32) in Ubuntu. I'm using the cx_Freeze to compile my program, but when I put them in my embbeded system, the png images aren't supported anymore. I did use of pygame.image.get_extended() function. In my desktop it return 1, but when put in my system, this function returns 0. Do you have some tip more? Thank you again!! On Mon, Jun 1, 2009 at 12:53 PM, Scott David Daniels wrote: > Djames Suhanko wrote: >> >> Hello, all! >> Did you know the bmp32 module for linux? This module can to load bmp >> image with alpha channel where is not supported others images formats. > > Hmmm, why do you think PNG and TGA do not support alpha? > > --Scott David Daniels > Scott.Daniels at Acm.Org > -- > http://mail.python.org/mailman/listinfo/python-list > -- Djames Suhanko LinuxUser 158.760 From kiran-siddiqui at hotmail.com Mon Jun 1 12:50:50 2009 From: kiran-siddiqui at hotmail.com (Kiran Siddiqui) Date: Mon, 1 Jun 2009 21:50:50 +0500 Subject: No subject Message-ID: hi have to parse a very complex dumps(whatever it is), i have done the parsing thruogh python.since the parsed data is very huge in amount, i have to feed it in the database (SQL), I have also done this... now the thing is i have to compare the data now present in the sql. in actual i have to compare the data of 1st dump with the data of the 2nd dump..... the both dump have the same fields(attributes) but the values of their field may be change... so i have to detect this change.. for this i have to do the comparison... i.e, let i have a tableA ,its 1st row carry the data of dump1 and then on the 2nd day the data comes from dump2 go into the next row of tableA. and i have to compare both rows. but i dont have the idea how to do this all using python as my front end. plz plzzzz anyone help me:( _________________________________________________________________ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From seattlehanks at yahoo.com Mon Jun 1 13:08:50 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 10:08:50 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> Message-ID: <197458b7-ff38-4ad7-b265-f76ccba689f7@t10g2000vbg.googlegroups.com> On Jun 1, 12:18?am, Lie Ryan wrote: > LittleGrasshopper wrote: > > On May 31, 2:03 pm, a... at pythoncraft.com (Aahz) wrote: > >> In article , > > >> LittleGrasshopper ? wrote: > >>>> On May 31, 12:19=A0am, Arnaud Delobelle wrote: > >>>>> [1]http://www.python.org/download/releases/2.2.3/descrintro/ > >>> I'm about 2/3 of the way through this paper (although I don't claim to > >>> understand all of it.) There is some heavy duty material in there, > >>> enough to make me feel really stupid and frustrated at times. I'm > >>> making connections as I go though, hopefully everything will sink in > >>> eventually. > >>> Is this stuff actually tough, or am I just a dummy? > >> Definitely tough! ?Metaclasses can cause dain bramage. > >> -- > >> Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > >> my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- > >> ? ? on-a-new-machine-ly y'rs ?- tim > > > Good to know, I'll stick to it and persevere. Will check doctor > > regularly for dain bramage though. > > Fortunately python makes it rare that we actually need to use metaclass. > Especially with class decorators and such... > > With that said, the rare cases where it is really needed; brain > hemorrhage is not only possible but when. Lie, I understand what you mean about metaclasses not being something that everybody needs to master on an everyday basis. Unfortunately, I'm the type of person that has to know how things work. I consider this an unfortunate defect, due to the fact that I am unable to compromise and let go even when practical considerations would dictate that is the appropriate course of action. I'm going to stick with this. I haven't even read the official Reference manual, so maybe I'm getting ahead of myself though. My plans are to read the reference manual, then selected parts of the library manual, and take it from there. From Scott.Daniels at Acm.Org Mon Jun 1 13:12:03 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 10:12:03 -0700 Subject: BMP32 for linux In-Reply-To: References: Message-ID: (1) Please don't top post; it is not the norm here. Re-arrange and prune as I've done below. Djames Suhanko wrote: > wrote: >> Djames Suhanko wrote: >>> Hello, all! >>> ... the bmp32 module for linux? This module can to load bmp image >>> with alpha channel where is not supported others images formats. >> Hmmm, why do you think PNG and TGA do not support alpha? > The python in my embbeded system have not support to others formats. :-( > Then, I found a tip about bmp32 with alpha channel, but I don't have > this module (bmp32) in Ubuntu. Sounds like this might be a capability problem on your embedded system. Look for and install PIL (the Python Imaging Library). It might help if you are not simply running up against hardware issues. --Scott David Daniels Scott.Daniels at Acm.Org From seattlehanks at yahoo.com Mon Jun 1 13:18:22 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 10:18:22 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> Message-ID: <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> On Jun 1, 12:42?am, Michele Simionato wrote: > On May 31, 2:32?am, LittleGrasshopper wrote: > > > Seriously, metaclasses are making my brain hurt. How do people like > > Michele Simionato and David Mertz figure these things out? Does it all > > come to looking at the C source code for the CPython interpreter? > > Actually I never looked at the C source code. I performed lots of > experiments > and figured things out the hard way, with trial and errors. > Metaclasses > are not that hard, descriptors and super were much harder to grasp at > that > time, since there was next to zero documentation and a set of subtle > bugs. > For descriptors now there is Raymond Hettinger essay and for super > there are my blog posts > on Artima:http://www.artima.com/weblogs/index.jsp?blogger=micheles&start=45&thR... > (there are also two posts of mine about metaclasses in Python 3.0 that > you may want to > read) > > HTH, > > ? ? ? ? ? ? Michele I have to thank you for all the invaluable materials you have provided to the python community. The process that you followed must have been incredibly arduous. A while back I gathered a lot of papers, many of which you either authored or co-authored, and they have been a great help. Just yesterday I went through your paper on the MRO on the advice of Carl Banks, and it absolutely clarified how the C3 MRO rules work. Once you understand how the MRO works it is actually quite intuitive, and your paper helped me understand this. Thanks for pointing your Artima papers on super(). A few days ago I hit a brick wall due to the terminology used regarding "bound" and "unbound" super objects, so I went on a search for suitable materials, and of course I found your papers on super(). I skimmed through them enough to understand the issues that were escaping me at the moment, but I intend to go through them completely at some point. It was quite fortunate that your papers acted as a catalyst for the change of the official documentation on super() in 2.6. The original documentation was very misleading. As you mentioned, Raymond Hettinger paper on descriptors is excellent as well, and I highly recommend it. Regards, Lukas From goldwamh at slu.edu Mon Jun 1 13:19:19 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Mon, 1 Jun 2009 12:19:19 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> Message-ID: <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Chris, Thanks for your well-written reply. Your analogy to the complexities of other special methods is well noted. I'll accept the "small price for flexibility" that you note, if necessary. However, I still desire a cleaner solution. I can examine the inherited slots to see which special methods are there, and to implement my own __deepcopy__ accordingly. But to do so well seems to essentially require reimplementing the complicated logic of the copy.deepcopy function. That is, if my new class is the first to be implementing an explicit __deepcopy__ function, I seem to have no easy way to invoke the inherited version of "deepcopy(self)". I wonder if the logic inherent in the copy.deepcopy function could instead be implemented directly within object.__deepcopy__ (rather than the current model in which object does not have __deepcopy__). Then I would always have a means for simulating a call to deepcopy(self) based upon the super.__deepcopy__ logic. I wouldn't be surprised if I'm overlooking some undesirable consequence of such a major change in the model, but I don't see one upon first thought. Michael On Monday June 1, 2009, Gabriel Genellina wrote: > In general, you have to know whether A implements __deepcopy__ or not. > This is a small price for the flexibility (or anarchy) in the copy/pickle > interfases: there are several ways to implement the same thing, and you > have to know which one your base class has chosen in order to extend it. > > The following is a possible implementation that doesn't use __init__ at > all, so their different signature is not an issue: > > # class A: > def __deepcopy__(self, memo={}): > dup = type(self).__new__(type(self)) > dup.__aTag = self.__aTag > dup.__aList = copy.deepcopy(self.__aList, memo) > dup.__aList.reverse() > return dup > > # class B: > def __deepcopy__(self, memo={}): > dup = A.__deepcopy__(self, memo) > dup.__bTag = self.__bTag > dup.__bList = copy.deepcopy(self.__bList, memo) > return dup > > Note that A.__deepcopy__ does two things: a) create a new, empty, > instance; and b) transfer state. B.__deepcopy__ handles *its* portion of > state only. This can be written in a more generic way, relying on > __getstate__/__setstate__ (the methods that should return the current > state of the object): > > # class A: > def __deepcopy__(self, memo={}): > dup = type(self).__new__(type(self)) > if hasattr(self, '__getstate__'): state = self.__getstate__() > else: state = self.__dict__ > state = copy.deepcopy(state, memo) > if hasattr(dup, '__setstate__'): dup.__setstate__(state) > else: dup.__dict__.update(state) > dup.__aList.reverse() > return dup > > # remove __deepcopy__ definition from class B > > Now, B (and any other subclass) is concerned only with __getstate__ / > __setstate__, and only when the default implementation isn't appropriate. > > > As another basic puzzle, consider a class definition for B where B has > > a registry list that it doesn't want cloned for the new instance (but > > it does want pickled when serialized). This would seem to require > > that B implement its own __deepcopy__. We want to somehow rely on > > the class definition for A to enact the cloning fo the state defined > > by A. But without knowing about how A supports the deepcopy > > semantics, I don't see how to accomplish this goal. > > I don't understand such bizarre requirement, but anyway, you can override > __deepcopy__ (make B fix only the part that the default implementation > doesn't implement well) > > # A.__deepcopy__ as above > > # class B: > def __deepcopy__(self, memo={}): > dup = A.__deepcopy__(self, memo) > dup.__registry = self.__registry > return dup > > This [the need to know how certain feature is implemented in the base > class] is not special or peculiar to pickle/copy, although the multiple > (and confusing) ways in which a class can implement pickling doesn't help > to understand the issue very well. > > Consider the + operator: when some subclass wants to implement addition, > it must know which of the several special methods involved (__add__, > __iadd__, __radd__) are implemented in the base class, in order to > extend/override them. Same for __cmp__/__eq__/__hash__: you can't just > ignore what your base class implements. All of this applies to other > languages too, but in Python, there is an additional consideration: the > mere *existence* of some methods/attributes can have consequences on how > the object behaves. In short, you can't blindly write __special__ methods. > > -- > Gabriel Genellina From albert at spenarnc.xs4all.nl Mon Jun 1 13:46:19 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Jun 2009 17:46:19 GMT Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: In article , Roy Smith wrote: >In article , > Bar Shirtcliff wrote: > >> I can't say a thing about other editors, except that when some shell >> script perversely dumped me into vi a month ago, I felt as horrified >> as if some actually living bugs had crawled out of my own reflection >> on the computer screen and fallen, clicking and scraping, onto the >> keyboard. That's a personal reaction - totally irrelevant, of course. > > : q ! Make that : q ! >All the vi you ever need to know :-) Now some kind soul give a similar sequence for emacs. > >The real problem is when you get dumped into some editor other than you one >you expected and don't realize it for a while. It's really amazing how >much damage you can do to a file by typing (for example) emacs commands at >vi. Especially if you accidentally stumble upon the sequence for "save >file". Exactly. An indication of how one can see one is in emacs is also appreciated. [Especially insidious is helpful help that lands you in emacs-ing help file for powerful searching (not!).] Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Mon Jun 1 13:53:57 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Jun 2009 17:53:57 GMT Subject: What text editor is everyone using for Python References: Message-ID: In article , Lawrence D'Oliveiro wrote: >In message , Lie Ryan wrote: > >> norseman wrote: >> >>> Suggestion: >>> Take a look at the top two most used OS you use and learn the default >>> (most often available) text editors that come with them. >> >> Which means Notepad on Windows? > >Or you could take a Linux preinstallation on a Live CD/DVD or USB stick. >There's no Windows system so brain-dead it can't be fixed with a simple >ctrl-alt-del. :) > You can carry vim (or Edwin's editor for that matter) on a FAT stick. (As they say: "Speak softly, and carry a large stick.") Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From michele.simionato at gmail.com Mon Jun 1 14:11:02 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Jun 2009 11:11:02 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> Message-ID: <4ffc2806-9d57-40ce-ba25-9841be8a6c71@t21g2000yqi.googlegroups.com> On Jun 1, 7:18?pm, LittleGrasshopper wrote: > I have to thank you for all the invaluable materials you have provided > to the python community. The process that you followed must have been > incredibly arduous. *Incredibly ardous* is an exaggeration, but in the case of the MRO I needed to do some work of reverse engineering in order to go from code (which was posted by Samuele Pedroni on python-dev http://mail.python.org/pipermail/python-dev/2002-October/029176.html) to the rules and to figure out the algorithm. Anyway, there are things much more complicated than the C3 algorithm or metaclasses, nowadays I am fighting with the Scheme module system and I know what I am talking about ;-) From Scott.Daniels at Acm.Org Mon Jun 1 14:13:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 11:13:22 -0700 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> Message-ID: Michael H. Goldwasser wrote: > Chris, > > Thanks for your well-written reply. Your analogy to the > complexities of other special methods is well noted. I'll accept > the "small price for flexibility" that you note, if necessary. > However, I still desire a cleaner solution. You seem to think that "deepcopy" is a well-defined concept. It is not and cannot be. A copy that understands its own abstractions can work, but sometimes a container is used as a simple abstraction, and sometimes it is used as a container. The choice between the two is not one of structure, but one of intent. A true deepcopy could survive making a copy of the number 23, but might fail as it makes a copy of None, True, or False. Certainly a dictionary might or might not be copied, depending on how the dictionary is used. --Scott David Daniels Scott.Daniels at Acm.Org From seattlehanks at yahoo.com Mon Jun 1 14:21:26 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 11:21:26 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> <4ffc2806-9d57-40ce-ba25-9841be8a6c71@t21g2000yqi.googlegroups.com> Message-ID: On Jun 1, 11:11?am, Michele Simionato wrote: > On Jun 1, 7:18?pm, LittleGrasshopper wrote: > > > I have to thank you for all the invaluable materials you have provided > > to the python community. The process that you followed must have been > > incredibly arduous. > > *Incredibly ardous* is an exaggeration, but in the case of the MRO > I needed to do some work of reverse engineering in order to go > from code (which was posted by Samuele Pedroni on python-devhttp://mail.python.org/pipermail/python-dev/2002-October/029176.html) > to the rules and to figure out the algorithm. Anyway, there are > things much more complicated than the C3 algorithm or metaclasses, > nowadays I am fighting with the Scheme module system and I know > what I am talking about ;-) I saw that you were involved right now in Scheme/Lisp. Good luck with it! From mensanator at aol.com Mon Jun 1 14:23:35 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 11:23:35 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> Message-ID: <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> On Jun 1, 10:11?am, pataphor wrote: > Johannes Bauer wrote: > > Any help is appreciated! > > This is on the fringe of exploitation, but hey, maybe the code helps you > think about the algorithm. > > IMHO the following code is a glaring complaint about the injustice of > omission itertools inflicts on the perfectly natural and obvious > procedure of repeat_each (whatever it's name ought to be): I believe the name you're looking for is combinations_with_replacement. It is one of the features being added to 3.1 which should give all the subsets of the Cartesian Product: permutations_with_replacement: product() combinations_with_replacement: combinations_with_replacement() permutations_without_replacement: permutations() combinations_without_replacement: combinations() > > from itertools ?import izip, islice, cycle > > def repeat_each(seq,n): > ? ? ?while True: > ? ? ? ? ?for x in seq: > ? ? ? ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ? ?yield x > > def repeat_all(seq,n): > ? ? ?while True: > ? ? ? ? ?for i in range(n): > ? ? ? ? ? ? ?for x in seq: > ? ? ? ? ? ? ? ? ?yield x > > def product(X): > ? ? ?N = [] > ? ? ?total = 1 > ? ? ?for x in X: > ? ? ? ? ?N.append(total) > ? ? ? ? ?total *= len(x) > ? ? ?R = [repeat_all(repeat_each(x,k),n) > ? ? ? ? ? ? ? ? ? ? ?for x,k,n in izip(X,N,reversed(N))] > ? ? ?return islice(izip(*R),total) > > def test1(): > ? ? ?L = ['a', 'bc','def' ] > ? ? ?for x in product(L): > ? ? ? ? ?print x > ? ? ?print > > def test2(): > ? ? ?repeat_all = cycle > ? ? ?test1() > > if __name__ == '__main__': > ? ? ?test1() > ? ? ?test2() > > See? Repeat_all and repeat_each are almost brothers, just separated by > the tiniest rearrangement of their genetic code (or should I say code > genetics?). Yet one is included as 'itertools.cycle' and the other is > doomed to live in limbo. Such injustice! Can it be that > 'itertools.repeat' has usurped repeat_each's rightful position? > > P. From norseman at hughes.net Mon Jun 1 14:26:20 2009 From: norseman at hughes.net (norseman) Date: Mon, 01 Jun 2009 11:26:20 -0700 Subject: Python, Tkinter and popen problem In-Reply-To: References: Message-ID: <4A241D4C.6010700@hughes.net> Piet van Oostrum wrote: >>>>>> norseman (n) wrote: > >> n> Piet van Oostrum wrote: >>>>>>>>> norseman (n) wrote: >> n> I have tried both and Popen2.popen2(). >> n> os.popen runs both way, contrary to docs. >>>> What do you mean `os.popen runs both way'? > >> n> It reads from child while console writes directly to child - thus >> n> eliminating the problem of coding a pass through from master. > > Yes, but that is not `both way': popen connects the parent to the child > through a pipe. The pipe works one way: from the child to the parent > with 'r' (default), from the parent to the child with 'w'. You can't > communicate the other way through the pipe. So the communication from > the parent process to the child through the popen is ONE WAY. If you > want TWO WAY communication you can use popen2, or better use > subprocess.Popen. We are actually saying the same thing - you do say it better. > > A child process always inherits stdin, stdout and stderr from the parent > unless you change that (e.g. by redirecting to a pipe, like popen does > for one of them). It doesn't matter whether you use os.popen, > subprocess.Popen, os.system, or os.fork to create the child process. So > in your case if the parent inputs from the console, so does the child. > But note: this is not communication from the parent process to the > child, but from YOU to the child. So the parent-child communication is > ONE WAY. > >> n> "... >>>> doesn't work as the iterator for a file, including pipes, does a >>>> read ahead (see the doc on file.next()) and therefore is not suitable >>>> for interactive use. >> n> ..." > >> n> If I understand you the above can be stated as: > >> n> The above does not work as an iterator for any file type, including >> n> pipes, but it does do read aheads .... and therefore is not suitable for >> n> interactive use. > > For files in general it is no problem because the contents of the file > is not interactively generated. Read ahead on a file works as long as > you do'nt use readline() on the file in between the iterator actions. > For a socket it could be the same problem if the other side generates > the output interactively. > >> n> If that is correct then read ahead is simply buffered file reads (grab a >> n> chunk, parcel it out on demand) - yes? > > I don't know, I have looked into the source code but it isn't clear to > me. I noticed that iteration didn't work and then looked up the > documentation. It talks about read ahead for efficiency. > >> n> As for "... not suitable for interactive ..." Really? Except for >> n> special purpose use the current interactive components are all buffered >> n> for read ahead use. Check the actual code for your keyboard, your mouse >> n> and so forth. It's the read ahead that allows faster time to completion. >> n> It's why C-code has the putch function. > > Yes, but they only read what is available. The iterator apparently tries > to read more and then has to wait. In actuality the read ahead does 'run off the end' and then waits. Specifics are coder dependent. But I think I understand what you mean. It may not be treating the incoming buffer as circular. That could explain a few things I'm seeing. > >> n> Yes - Sync IS the bigger hammer! If that is what is needed - so be it. >> n> All character readers (byte at a time) should obey a flush(). Depending >> n> on type, code for the reader controls whether or not it flushes >> n> incomplete "lines" in the in-buffer(s). Proper implementation limits lost >> n> data on system crash. > > I don't understand what you say here. As I told before it has nothing to > do with sync(). Also for reading there is no flush(); the flush() is > done on the other side of the pipe. Yes, and sync() has to do with > system crashes but that is not what we are talking about in this thread. > The line with Sync is just a comment. Sync'ing the whole system just to force a singular flush is not a good way to proceed. The comment is not actually connected to the comments on readers. >> n> In trying to use flush at the master side I keep getting messages >> n> indicating strings (completed or not) are not flushable. Strange practice. > > If you print to the console in the master the flush is done > automatically. The symptoms have been otherwise. Going back to your comments on iterators not proceeding with 'in-line' processing but rather holding onto the bytes until later would give the effect of flush not working. > >> n> --- >> n> from subprocess import Popen, PIPE >> n> xx = Popen(["z6.py"], stdout=PIPE).stdout > >> n> while True: >> n> line = xx.readline() >> n> if not line: break >> n> print "\t" + line, >> n> --- >> n> DOES WORK on Python 2.5.2 on Slackware 10.2 - THANK YOU VERY MUCH!!! >> n> Isn't working on Windows. error message comes as one of two forms. >> n> 1- %1 not found #as shown above >> n> 2- file not found #as ...["python z6.py"]... >> n> same #as #2 even with full paths given > > That should be Popen(["python", "z6.py"], stdout=PIPE).stdout > And then with both python and z6.py given as full paths. > >> n> I get the impression subprocess ignores system things on Windows. >> n> The routines it purposes to replace do use them. At any rate, subprocess >> n> is NOT consistent across platforms. > > subprocess is, but Windows isn't. On Unix-like systems, the python > command is usually in your PATH, so just giving "python" works. In > Windows PATH is underused, and commands like python often are not in > PATH, unless you as a user has adapted the path, or maybe there is an > installation option to adapt the PATH. The reason probably is that in > Windows almost nobody uses the command line but only clicks and the PATH > is not relevant. "The reason" most certainly "is ...." Yep!! Technically - the path is passed as part of the click, but since it is transparent it is easy to forget its presence. > >> n> Some questions: >> n> 1) "...], stdout=PIPE).stdout >> n> ^ ^ why the double use? > > It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen > object, not a file object. If you add .stdout you get the stdout > attribute of the Popen object of which you just before stated that it > should be a pipe. So the stdout=PIPE parameter makes it create a pipe, > and the .stdout returns you that pipe. > I rather thought it might be something like the military: Company - Dress Right - Dress Get the attention, state what is to be done, order it done. :) Python goes to great lengths to "be helpful" but drops the ball on the obvious. stdout=PIPE means the user wants stdout piped back so it should be helpful and do the obvious rather than have the user be redundant. Subprocess - run file - redirect stdout - run redirected ^ redundant :) Subprocess - run I/O redirected file - (closing ')' means) run 1 percent of 100 characters typed is 1 (error). 1 percent of 10,000 characters typed is 100 (errors, minimum, not factoring in fatigue) The more the typing the more the errors and the longer to completion. The less specific the verb, the more the research. >> n> 2) "if not line: break" what tells what to look for EOL >> n> or is the use of 'line' missleading? >> n> is it a byte at a time output? > > No, line is a line, as indicated by the readline() call. The > "if not line" is a test for end of file. In this case the end of the > child process (pipe closed). Got it - that helps! > >> n> how much CPU usage does the loop use? > > Not much, It is mainly waiting for input but that doesn't consume CPU. > >> n> is there something in that loop that >> n> uses the system pipe triggers to >> n> reduce excessive CPU waste or does it >> n> constantly poll? If so where does >> n> what code get put to signal (or set) >> n> the courtesy semiphores so it does >> n> not hog the system? > > It doesn't poll or use semaphores. The beauty of a pipe is that it > automatically synchronises the reader and writer processes. If you do a > read on a pipe and it is empty the OS just blocks you. When the other > end writes something in the pipe, the OS will unblock you. > Unless the OS is using interrupts to signal things - looping is expensive. Yes - interrupts are NOT a good idea for general computing software. The use of interrupts is especially bad in multi-user, multi-tasking environments. The way you stated the process indicates a loop and thus the program is removed from the processing list until the unblock re-instates processing. Some clarity- Interrupts halt all processing until released. They effectively knock the system unconscious until released. Process polling creates an entry in the circular cue for switching the program pointer (and associated registers and maybe memory paging) to the next 'running' process so it gets it's slice of execution time. The effect of multi-processing is realized but the CPU only executes one program at a time, in intermixed pieces. The time slice is the gain. Different processes can have different lengths of run time. Instructions are ignored except during their time slice. Then the current is put on hold and the next in list is run for it's time slice. So if process polling is used and and the program is frozen at the readline that would explain why the program apparently freezes. In fact it does. Master has readline, readline is frozen so master is frozen. Keyboard instructions to child are not passed to child because master is frozen. Thus keyboard 'continue' isn't transmitted, but CTRL-C (tell OS to crash program) is intercepted by OS. GUI interface is separate so mouse clicks still work and at crash (end program) the buffers are dumped. Facts all fit. Solution to problem: 1) read byte at a time from pipe, compositing my own string 2) send self/test for EOD to exit loop, preventing endless loop. Old School - but it works unless Python screws up byte by byte reads. Piet - Thanks for the help. Steve From lh at google.com Mon Jun 1 14:27:41 2009 From: lh at google.com (Leslie Hawthorn) Date: Mon, 1 Jun 2009 11:27:41 -0700 Subject: Not going to let this drop ... In-Reply-To: <4A235A7D.4020507@holdenweb.com> References: <4A235A7D.4020507@holdenweb.com> Message-ID: <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> On Sun, May 31, 2009 at 9:35 PM, Steve Holden wrote: > I don't know if Google are planning to run a Highly-Open Participation > event this year, but if they are then maybe we could establish a few > tasks for that. > We are planning to do so in Q4 of this year, further details TBD. I'll make sure Titus Brown is in the loop when we get started planning so he can point me to the right folks who'd like to help with the PSF's participation in GHOP this year. Cheers, LH -- Leslie Hawthorn Program Manager - Open Source Google Inc. http://code.google.com/opensource/ I blog here: http://google-opensource.blogspot.com - http://www.hawthornlandings.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From 2myemailaddress at gmail.com Mon Jun 1 14:45:04 2009 From: 2myemailaddress at gmail.com (babypython) Date: Mon, 1 Jun 2009 11:45:04 -0700 (PDT) Subject: Parsing Data Message-ID: <23820003.post@talk.nabble.com> I am trying to parse through this data for analysis. I am new to python and wondering what would be the quickest way to extract the data from this file. The data files consists of comments (starting with ! and #). Then, the data follows. All I want is the data in array ( I don't care about the comments),and the data format is freq[], s11[real], s11[imag], s21[real],s21[imag] Any help will be appreciated. Thanks. !Date: Jan 29, 2008 14:40:26 !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) !Measurements: S11, S21: ! Freq S11[real, imag] S21[real,imag] 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 -- View this message in context: http://www.nabble.com/Parsing-Data-tp23820003p23820003.html Sent from the Python - python-list mailing list archive at Nabble.com. From python at mrabarnett.plus.com Mon Jun 1 14:48:53 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Jun 2009 19:48:53 +0100 Subject: Python, Tkinter and popen problem In-Reply-To: <4A241D4C.6010700@hughes.net> References: <4A241D4C.6010700@hughes.net> Message-ID: <4A242295.1040704@mrabarnett.plus.com> norseman wrote: > Piet van Oostrum wrote: >> norseman (n) wrote: [snip] >>> n> Some questions: >>> n> 1) "...], stdout=PIPE).stdout >>> n> ^ ^ why the double use? >> >> It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen >> object, not a file object. If you add .stdout you get the stdout >> attribute of the Popen object of which you just before stated that it >> should be a pipe. So the stdout=PIPE parameter makes it create a pipe, >> and the .stdout returns you that pipe. >> > > I rather thought it might be something like the military: > Company - Dress Right - Dress > Get the attention, state what is to be done, order it done. :) > > Python goes to great lengths to "be helpful" but drops the ball on the > obvious. stdout=PIPE means the user wants stdout piped back so it > should be helpful and do the obvious rather than have the user be > redundant. > What if the user requests both stdin and stdout? and what about all the other useful bits which the returned object provides? From db3l.net at gmail.com Mon Jun 1 14:51:04 2009 From: db3l.net at gmail.com (David Bolen) Date: Mon, 01 Jun 2009 14:51:04 -0400 Subject: Ah, ctypes References: Message-ID: Nick Craig-Wood writes: > ctypes could potentially note that function types don't have enough > references to them when passed in as arguments to C functions? It > might slow it down microscopically but it would fix this problem. Except that ctypes can't know the lifetime needed for the callbacks. If the callbacks are only used while the called function is executing (say, perhaps for a progress indicator or internal completion callback) then it's safe to create the function wrapper just within the function call. -- David From steve at holdenweb.com Mon Jun 1 14:51:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Jun 2009 14:51:53 -0400 Subject: Not going to let this drop ... In-Reply-To: <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> References: <4A235A7D.4020507@holdenweb.com> <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> Message-ID: <4A242349.9070606@holdenweb.com> Leslie Hawthorn wrote: > > > On Sun, May 31, 2009 at 9:35 PM, Steve Holden > wrote: > > I don't know if Google are planning to run a Highly-Open Participation > event this year, but if they are then maybe we could establish a few > tasks for that. > > > We are planning to do so in Q4 of this year, further details TBD. I'll > make sure Titus Brown is in the loop when we get started planning so he > can point me to the right folks who'd like to help with the PSF's > participation in GHOP this year. > Thanks for letting me know. I am sure the PSF will be delighted to pitch in, and Titus will be an entirely satisfactory first point of contact. Hope you are well. Good to hear from you. Won't be at OSCON this year, but maybe next year. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ From goldwamh at slu.edu Mon Jun 1 15:02:06 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Mon, 1 Jun 2009 14:02:06 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: <18980.9646.476988.35123@Michael-Goldwassers-Computer.local> On Monday June 1, 2009, Scott David Daniels wrote: > Michael H. Goldwasser wrote: > > Chris, > > > > Thanks for your well-written reply. Your analogy to the > > complexities of other special methods is well noted. I'll accept > > the "small price for flexibility" that you note, if necessary. > > However, I still desire a cleaner solution. > > You seem to think that "deepcopy" is a well-defined concept. It is > not and cannot be. A copy that understands its own abstractions can > work, but sometimes a container is used as a simple abstraction, and > sometimes it is used as a container. The choice between the two is > not one of structure, but one of intent. A true deepcopy could > survive making a copy of the number 23, but might fail as it makes > a copy of None, True, or False. Certainly a dictionary might or > might not be copied, depending on how the dictionary is used. > > --Scott David Daniels > Scott.Daniels at Acm.Org Hi Scott, It is clear from my original statement of the question that there is a need for classes to be able to customize their own semantics for supporting the deepcopy function. That is why the deepcopy function looks for a __deepcopy__ method within a class as a hook. My concern involves the challenge of providing a valid implementation for __deepcopy__ at one level of inheritance without being overly dependent on the internal mechanism used by ancestor classes in supporting deepcopy. I don't see how your comments address that question. Michael From clp2 at rebertia.com Mon Jun 1 15:10:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 12:10:21 -0700 Subject: Parsing Data In-Reply-To: <23820003.post@talk.nabble.com> References: <23820003.post@talk.nabble.com> Message-ID: <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> On Mon, Jun 1, 2009 at 11:45 AM, babypython <2myemailaddress at gmail.com> wrote: > > I am trying to parse through ?this data for analysis. I am new to python and > wondering what would be the quickest way to extract the data from this file. > The data files consists of comments (starting with ! and #). Then, the data > follows. All I want is the data in array ( I don't care about the > comments),and the data format is ?freq[], s11[real], s11[imag], > s21[real],s21[imag] > > ?Any help will be appreciated. Thanks. > > > !Date: Jan 29, 2008 14:40:26 > !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) > !Measurements: S11, S21: > ! Freq ?S11[real, imag] ?S21[real,imag] > 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 > 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 > 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 > 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 > 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 > 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 > 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 > 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 > 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 > 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 > 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 #completely untested data = [] for line in the_file: if line.startswith("!"): continue fields = line.strip().split() datapoint = [int(fields[0]), complex(float(fields[1]), float(fields[2])), complex(float(fields[3]), float(fields[4]))] data.append(datapoint) Cheers, Chris -- http://blog.rebertia.com From nathan.charles.summer at gmail.com Mon Jun 1 15:16:06 2009 From: nathan.charles.summer at gmail.com (nathan.charles.summer at gmail.com) Date: Mon, 1 Jun 2009 12:16:06 -0700 (PDT) Subject: How can I install a newer version of python Message-ID: I am on MacOS 10.5. It has python 2.5.1 installed. How can I install a newer version of python (e.g. 3.1) without breaking my current environment (I am not sure what programs/scripts are using the python comes with MacOS). I just want to use the newer version of python for my own project. I found this "http://wiki.python.org/moin/MacPython/Leopard", but i have no idea what that is related to my situation. Thank you for any tip. From clp2 at rebertia.com Mon Jun 1 15:34:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 12:34:07 -0700 Subject: How can I install a newer version of python In-Reply-To: References: Message-ID: <50697b2c0906011234sf3b95eev3f4a6fce2a12ed25@mail.gmail.com> On Mon, Jun 1, 2009 at 12:16 PM, nathan.charles.summer at gmail.com wrote: > I am on MacOS 10.5. It has python 2.5.1 installed. > > How can I install a newer version of python (e.g. 3.1) without > breaking my current environment (I am not sure what programs/scripts > are using the python comes with MacOS). I just want to use the newer > version of python for my own project. > > I found this "http://wiki.python.org/moin/MacPython/Leopard", but i > have no idea what that is related to my situation. > > Thank you for any tip. I think you can just use the normal Mac installer from http://www.python.org/download/. As it says on http://wiki.python.org/moin/MacPython/Leopard, this doesn't clobber the default Apple Python install. Cheers, Chris -- http://blog.rebertia.com From david at boddie.org.uk Mon Jun 1 16:05:18 2009 From: david at boddie.org.uk (David Boddie) Date: Mon, 01 Jun 2009 22:05:18 +0200 Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On Monday 01 June 2009 16:16, dudekksoft at gmail.com wrote: > On 31 Maj, 02:32, David Boddie wrote: >> So, you only want to handle certain links, and pass on to WebKit those >> which you can't handle? Is that correct? > > Yes, I want to handle external links (out of my host) and links > starting with download://... (my specific protocol). If you want to handle them in a different way to normal Web pages, it seems that calling setForwardUnsupportedContent(True) on the QWebPage is the way to do it. However, if you want to handle those links and present the content for the browser to render then you may need to override the browser's network access manager, as discussed in this message: http://lists.trolltech.com/pipermail/qt-interest/2009-March/004279.html I experimented a little and added an example to the PyQt Wiki: http://www.diotavelli.net/PyQtWiki/Using a Custom Protocol with QtWebKit I hope it helps to get you started with your own custom protocol. David From ubuntu.exe at gmail.com Mon Jun 1 16:21:23 2009 From: ubuntu.exe at gmail.com (ubuntu.exe at gmail.com) Date: Mon, 1 Jun 2009 13:21:23 -0700 (PDT) Subject: screen scraping Message-ID: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> Hello, does anybody have a simple tutorial for screen scrapping? I want to extract IP addresses from particular web page, reading documentation for a couple of days and writing some really simple scripts, but cant get it to work. Did anybody see any manual explicittly for screen scraping? Thanks. From 2myemailaddress at gmail.com Mon Jun 1 16:29:00 2009 From: 2myemailaddress at gmail.com (babypython) Date: Mon, 1 Jun 2009 13:29:00 -0700 (PDT) Subject: Parsing Data In-Reply-To: <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> References: <23820003.post@talk.nabble.com> <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> Message-ID: <23821445.post@talk.nabble.com> Thanks a lot. That works for me. Chris Rebert-6 wrote: > > On Mon, Jun 1, 2009 at 11:45 AM, babypython <2myemailaddress at gmail.com> > wrote: >> >> I am trying to parse through ?this data for analysis. I am new to python >> and >> wondering what would be the quickest way to extract the data from this >> file. >> The data files consists of comments (starting with ! and #). Then, the >> data >> follows. All I want is the data in array ( I don't care about the >> comments),and the data format is ?freq[], s11[real], s11[imag], >> s21[real],s21[imag] >> >> ?Any help will be appreciated. Thanks. >> >> >> !Date: Jan 29, 2008 14:40:26 >> !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) >> !Measurements: S11, S21: >> ! Freq ?S11[real, imag] ?S21[real,imag] >> 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 >> 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 >> 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 >> 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 >> 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 >> 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 >> 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 >> 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 >> 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 >> 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 >> 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 > > #completely untested > data = [] > for line in the_file: > if line.startswith("!"): continue > fields = line.strip().split() > datapoint = [int(fields[0]), complex(float(fields[1]), > float(fields[2])), complex(float(fields[3]), float(fields[4]))] > data.append(datapoint) > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Parsing-Data-tp23820003p23821445.html Sent from the Python - python-list mailing list archive at Nabble.com. From philr at aspexconsulting.co.nz Mon Jun 1 16:30:53 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 2 Jun 2009 08:30:53 +1200 Subject: which database is suitable for small applications In-Reply-To: References: <8ca278430905260133n3cdd12dcq667a5cdeada29e1e@mail.gmail.com> <52801358-c037-458d-8857-a78c2d881ddb@z16g2000prd.googlegroups.com> Message-ID: Hi Lawrence, I appreciate your remarks. However database engines cache their table/views to support sequential accessing within a set. With a good accessing scheme and with enough cache memory you will have all your small tables in memory. So the simplest thing is let the DBMS do its thing. The good ones will cope quite happily. You then have the advantage that the app can grow without program changes. It is a long time since I delved into DBMS internals (25 years) but I cannot see that they will have changed from what I have said above, however I am sure to be corrected if I am wrong. ;-) Cheers, phil -----Original Message----- From: Lawrence D'Oliveiro [mailto:ldo at geek-central.gen.new_zealand] Sent: Sunday, 31 May 2009 11:21 p.m. To: python-list at python.org Subject: Re: which database is suitable for small applications In message <52801358-c037-458d-8857- a78c2d881ddb at z16g2000prd.googlegroups.com>, Ankit wrote: > If your application does not require you to add very heavy data then > you can also use flat files to do your stuff. > Its always a better to use Databases ... It's not always better to use databases. By definition, data for a ?small? application is bound to fit entirely in RAM. So certainly the simplest thing to do is read a whole data file in at the start, and write the entire updated data structure back out again at the end. From kdawg44 at gmail.com Mon Jun 1 17:23:19 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 1 Jun 2009 17:23:19 -0400 Subject: Urllib2 proxy settings Message-ID: <5caea3690906011423t538cbb5bg2fe02ee03bf11108@mail.gmail.com> Hello, I am having trouble with an application running on a linux server. It keeps reverting to old proxy settings and messing up the web application. I have checked everything I can think of, and since the application is written in Python and uses urllib to call a web service (which is where the error is occurring) I thought that I could open up the interpreter, import URLLib2 and then see what it thinks the proxy is. How can I just echo this in the interpreter? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Mon Jun 1 17:28:16 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 01 Jun 2009 23:28:16 +0200 Subject: how to get the path of a module (myself) ? Message-ID: <4A2447F0.2050905@gmail.com> hello, I've pictures stored in a path relative to my python source code. To get a picture, I need to know what path I'm on in each python module. I thought __file__ would do the job, but apparently I didn't read the documentation carefully enough, because file is the path to the module that called my module. Any ways to get the path of "myself" ? thanks, Stef Mientki From nick at craig-wood.com Mon Jun 1 17:29:44 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 01 Jun 2009 16:29:44 -0500 Subject: Ah, ctypes References: Message-ID: David Bolen wrote: > Nick Craig-Wood writes: > > > ctypes could potentially note that function types don't have enough > > references to them when passed in as arguments to C functions? It > > might slow it down microscopically but it would fix this problem. > > Except that ctypes can't know the lifetime needed for the callbacks. If > the callbacks are only used while the called function is executing (say, > perhaps for a progress indicator or internal completion callback) then > it's safe to create the function wrapper just within the function > call. Good point... However I wouldn't mind if ctypes emitted a warning or even threw an exception in this case too though as the other case is so invidious. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From david.lyon at preisshare.net Mon Jun 1 18:23:04 2009 From: david.lyon at preisshare.net (David Lyon) Date: Mon, 01 Jun 2009 18:23:04 -0400 Subject: how to get the path of a module (myself) =?UTF-8?Q?=3F?= In-Reply-To: <4A2447F0.2050905@gmail.com> References: <4A2447F0.2050905@gmail.com> Message-ID: <662715f21fdf486785783086cec9cda3@preisshare.net> On Mon, 01 Jun 2009 23:28:16 +0200, Stef Mientki wrote: > hello, > > I've pictures stored in a path relative to my python source code. > To get a picture, I need to know what path I'm on in each python module. > I thought __file__ would do the job, > but apparently I didn't read the documentation carefully enough, > because file is the path to the module that called my module. > > Any ways to get the path of "myself" ? This ain't the official way... but the hackers way..... Check site.path (import site)... If your module got loaded, and it's own succinct directory or .egg, then it will have been added to site.path. You might have to parse the values in site.path but we're only talking a few lines of code because you already know the package name. If not, there's another way through pkg_utils... Regards David From python at mrabarnett.plus.com Mon Jun 1 18:37:04 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Jun 2009 23:37:04 +0100 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A2447F0.2050905@gmail.com> References: <4A2447F0.2050905@gmail.com> Message-ID: <4A245810.4090704@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I've pictures stored in a path relative to my python source code. > To get a picture, I need to know what path I'm on in each python module. > I thought __file__ would do the job, > but apparently I didn't read the documentation carefully enough, > because file is the path to the module that called my module. > > Any ways to get the path of "myself" ? > I'm not sure what you mean. I just did a quick test. # File: C:\Quick test\child.py print "name is %s" % __name__ print "file is %s" % __file__ # File: C:\Quick test\parent.py import child print "name is %s" % __name__ print "file is %s" % __file__ # Output: name is child file is C:\Quick test\child.py name is __main__ file is C:\Quick test\parent.py From ldo at geek-central.gen.new_zealand Mon Jun 1 18:52:35 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:52:35 +1200 Subject: Ah, ctypes References: Message-ID: In message , Nick Craig- Wood wrote: > As a ctypes user I found this an interesting story - thanks for > posting it! By the way, I hate wildcard imports. In the ctypes docs, they recommend you do this from ctypes import * but I prefer this: import ctypes as ct which explains the "ct." prefixes in my sample code, in case you were wondering. From ldo at geek-central.gen.new_zealand Mon Jun 1 18:53:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:53:42 +1200 Subject: What text editor is everyone using for Python References: Message-ID: In message , Albert van der Horst wrote: > You can carry vim (or Edwin's editor for that matter) on a FAT > [USB] stick. > (As they say: "Speak softly, and carry a large stick.") I like that. :) From ldo at geek-central.gen.new_zealand Mon Jun 1 18:54:48 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:54:48 +1200 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: In message , Albert van der Horst wrote: > An indication of how one can see one is in emacs is also appreciated. How about, hit CTRL/G and see if the word "Quit" appears somewhere. From seattlehanks at yahoo.com Mon Jun 1 19:05:30 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 16:05:30 -0700 (PDT) Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: On Jun 1, 2:38?am, Piet van Oostrum wrote: > >>>>> LittleGrasshopper (L) wrote: > >L> On May 31, 3:59?pm, Carl Banks wrote: > >>> On May 31, 3:52?pm, LittleGrasshopper wrote: > > >>> > This is some simple code which I got from Guido's paper on the > >>> > unification of classes and types, which Arnaud suggested to improve my > >>> > knowledge of metaclasses: > > >>> > class M1(type): > >>> > ? ? pass > >>> > class M2(M1): > >>> > ? ? pass > >>> > class M3(M2): > >>> > ? ? pass > >>> > class C1: > >>> > ? ? __metaclass__ = M1 > >>> > class C2(C1): > >>> > ? ? __metaclass__ = M2 > >>> > class C3(C1, C2): > >>> > ? ? __metaclass__ = M3 > > >>> > It is failing when processing C3: > >>> > Traceback (most recent call last): > >>> > ? File "metaerror.py", line 18, in > >>> > ? ? class C3(C1, C2): > >>> > TypeError: Error when calling the metaclass bases > >>> > ? ? Cannot create a consistent method resolution > >>> > order (MRO) for bases C2, C1 > > [snip] > > >L> I guess the resulting MROs do not satisfy monotonicity, I > >L> just have to find out how to derive the MRO. I had the notion that it > >L> was constructed by listing the current class, followed by the MROs of > >L> each base in order, and then retaining the rightmost instance of each > >L> class in the MRO list, but I think that might be an > >L> oversimplification, since in this case that would be: > >L> (C1, object) > >L> (C2, C1, object) > >L> (C3, C2, C1, object) > >L> And I don't see any issues. But I'll read the paper to figure out what > >L> the problem is, thanks. > > Here is exactly the problem. Merging the two MRO's as you state would > give C3, C2, C1, object, i.e. C2 before C1. > > But your class definition: > > class C3(C1, C2): > says that C1 should be before C2. Conflict!! > Change it to class C3(C2, C1): > > You see it has nothing to do with the metaclasses. The following code > gives the same error: > > class C1(object): > ? ? pass > class C2(C1): > ? ? pass > class C3(C1, C2): > ? ? pass > > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org Thank you, Piet. You are correct. I actually went through the whole C3 MRO paper from Michele and I realized the issue (local precedence is not maintained.) And, like you said, the way to fix it is to change the order of the bases in C3. From david at abbottdavid.com Mon Jun 1 19:10:24 2009 From: david at abbottdavid.com (David) Date: Mon, 01 Jun 2009 19:10:24 -0400 Subject: screen scraping In-Reply-To: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> References: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> Message-ID: <4A245FE0.4010409@abbottdavid.com> ubuntu.exe at gmail.com wrote: > Hello, > does anybody have a simple tutorial for screen scrapping? > > I want to extract IP addresses from particular web page, reading > documentation for a couple of days and writing some really simple > scripts, but cant get it to work. > > Did anybody see any manual explicittly for screen scraping? > > Thanks. How about this: http://iwiwdsmp.blogspot.com/2007/02/how-to-use-python-and-beautiful-soup-to.html -- Powered by Gentoo GNU/Linux http://linuxcrazy.com From seattlehanks at yahoo.com Mon Jun 1 19:14:05 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 16:14:05 -0700 (PDT) Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: On Jun 1, 3:44?am, Piet van Oostrum wrote: > >>>>> Piet van Oostrum (I) wrote: > >I> But your class definition: > >I> class C3(C1, C2): > >I> says that C1 should be before C2. Conflict!! > >I> Change it to class C3(C2, C1): > > Of course the C1 is then superfluous. > > I wonder why you want this. What is the problem you want to solve? > > Apart from the metaclasses (that you still can use with `class C3(C2)') > I could think of the following use case: > > class C1(object): > ? ? ? def m1(self): > ? ? ? ? ? return 'C1.m1' > > class C2(C1): > ? ? ? # override m1 > ? ? ? def m1(self): > ? ? ? ? ? return 'C2.m1' > ? ? ? def m2(self): > ? ? ? ? ? return 'C2.m2'+self.m1() > > class C3(C1, C2): > ? ? ? def test(self): > ? ? ? ? ? print self.m1()+self.m2() > > i.e. in C3 we `ignore' the override of m1 in C2 but still want to make > use of the m2 from C2. > > The question that arises then is: the self.m1() inside m2, which m1 > should it use? For an instance of C3 it would use C1.m1, but for an > instance of C2 it would use C2.m2. > > However, every instance of C3 can also be considered an instance of C2, > (Liskov substitution principle), therefore there is a conflict. That is > exactly the conflict that the MRO signals. > > If you want that kind of behaviour it can be solved by using a mixin > class for the m2 method: > > class C1(object): > ? ? ?__metaclass__ = M1 > ? ? ?def m1(self): > ? ? ? ? ?return 'C1.m1' > class Cmix(object): > ? ? ?def m2(self): > ? ? ? ? ?return 'C2.m2'+self.m1() > class C2(C1, Cmix): > ? ? ?__metaclass__ = M2 > ? ? ?# override m1 > ? ? ?def m1(self): > ? ? ? ? ?return 'C2.m1' > class C3(C1, Cmix): > ? ? ?__metaclass__ = M3 > ? ? ?def test(self): > ? ? ? ? ?print self.m1()+self.m2() > > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org Your discussion of this scenario, why it justifiably fails, and the alternative solution using a mixing, is all excellent. I am going to keep this for future reference. I am at a stage of my Python journey that some of these things seem rather mysterious, so I especially appreciate this very detailed discussion. To answer your question, I actually got this hierarchy directly from Guido's paper on class unification that came out with 2.2.3. From norseman at hughes.net Mon Jun 1 19:24:28 2009 From: norseman at hughes.net (norseman) Date: Mon, 01 Jun 2009 16:24:28 -0700 Subject: Python, Tkinter and popen problem In-Reply-To: <4A242295.1040704@mrabarnett.plus.com> References: <4A241D4C.6010700@hughes.net> <4A242295.1040704@mrabarnett.plus.com> Message-ID: <4A24632C.3050106@hughes.net> MRAB wrote: > norseman wrote: >> Piet van Oostrum wrote: >>> norseman (n) wrote: > [snip] >>>> n> Some questions: >>>> n> 1) "...], stdout=PIPE).stdout >>>> n> ^ ^ why the double use? >>> >>> It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen >>> object, not a file object. If you add .stdout you get the stdout >>> attribute of the Popen object of which you just before stated that it >>> should be a pipe. So the stdout=PIPE parameter makes it create a pipe, >>> and the .stdout returns you that pipe. >>> >> >> I rather thought it might be something like the military: >> Company - Dress Right - Dress >> Get the attention, state what is to be done, order it done. :) >> >> Python goes to great lengths to "be helpful" but drops the ball on the >> obvious. stdout=PIPE means the user wants stdout piped back so it >> should be helpful and do the obvious rather than have the user be >> redundant. >> > What if the user requests both stdin and stdout? and what about all the > other useful bits which the returned object provides? --------------------------- "... stdin and stdout?..." I tried that - results were even worse. Have to kill the window to get out. (both redirects are to master who is not running, until child dies. meanwhile keyboard is effectively locked out) "... other useful bits..." Beauty is in the eye of the beholder. Or so the saying goes. "Useful" to one may not be so to another. It is kinda like this: I have been in some beautifully painted cars. Really great workmanship. They had lots of 'extras' too. Soft leather seats, built in two way radios and built in mobile phones and built in ice makers and the list goes on. But in the USofA Western States that have lots of dirt and gravel roads they are a complete waste of time, effort and money. Two weeks and they look like any other beat up jalopy. The dust gets into everything. Ever wanted to put ice cubes full of frozen dust and grit into your favorite drink? The ice maker had been installed into a friend's old pickup a week or so earlier. A month or so later I noticed it had been removed. "Useful" is a vague measurement at best. By the way - bits and pieces as told by yourself and Peter and Piet have accomplished painting a useful picture for me. My thanks to all three of you. Steve From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 19:40:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jun 2009 23:40:33 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> Message-ID: <0234597b$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > I believe the name you're looking for is combinations_with_replacement. > It is one of the features being added to 3.1 which should give all the > subsets of the Cartesian Product: > > permutations_with_replacement: product() > combinations_with_replacement: combinations_with_replacement() > permutations_without_replacement: permutations() > combinations_without_replacement: combinations() What, no partitions? http://en.wikipedia.org/wiki/Partition_of_a_set -- Steven From stef.mientki at gmail.com Mon Jun 1 19:46:23 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 01:46:23 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A245810.4090704@mrabarnett.plus.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <4A24684F.3090109@gmail.com> MRAB wrote: > Stef Mientki wrote: >> hello, >> >> I've pictures stored in a path relative to my python source code. >> To get a picture, I need to know what path I'm on in each python module. >> I thought __file__ would do the job, >> but apparently I didn't read the documentation carefully enough, >> because file is the path to the module that called my module. >> >> Any ways to get the path of "myself" ? >> > I'm not sure what you mean. I just did a quick test. > > # File: C:\Quick test\child.py > print "name is %s" % __name__ > print "file is %s" % __file__ > > # File: C:\Quick test\parent.py > import child > > print "name is %s" % __name__ > print "file is %s" % __file__ > > # Output: > name is child > file is C:\Quick test\child.py > name is __main__ > file is C:\Quick test\parent.py Yes, that's what I (and many others) thought, but now put your code in a file, let's say the file "test.py", and now run this file by : execfile ( 'test.py' ) cheers, Stef From stef.mientki at gmail.com Mon Jun 1 19:46:37 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 01:46:37 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <662715f21fdf486785783086cec9cda3@preisshare.net> References: <4A2447F0.2050905@gmail.com> <662715f21fdf486785783086cec9cda3@preisshare.net> Message-ID: <4A24685D.5000500@gmail.com> Thanks David, but .... David Lyon wrote: > On Mon, 01 Jun 2009 23:28:16 +0200, Stef Mientki > wrote: > >> hello, >> >> I've pictures stored in a path relative to my python source code. >> To get a picture, I need to know what path I'm on in each python module. >> I thought __file__ would do the job, >> but apparently I didn't read the documentation carefully enough, >> because file is the path to the module that called my module. >> >> Any ways to get the path of "myself" ? >> > > This ain't the official way... but the hackers way..... > > Check site.path (import site)... > always return None in my case > If your module got loaded, and it's own succinct directory or .egg, then > it will have been added to site.path. > > You might have to parse the values in site.path but we're only talking > a few lines of code because you already know the package name. > > If not, there's another way through pkg_utils... > I don't seem to have pkg_utils, only pkgutil, which doesn't have an apropiate function. But I found another way, don't know if that's reliable: import inspect print inspect.currentframe().f_code.co_filename cheers, Stef > Regards > > David > > From eric.pruitt at gmail.com Mon Jun 1 19:54:21 2009 From: eric.pruitt at gmail.com (Eric Pruitt) Date: Mon, 1 Jun 2009 18:54:21 -0500 Subject: Creating a Google Code project for GSoC Message-ID: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> Hello everyone, I am a student working on GSoC 2009 for PSF. My proposal involves making changes to the subprocess module and subprocess.Popen. I wish to create a Google Code project to host my changes so that I can receive feedback from the community. Some of the code I have incorporated falls under an MIT license. Python's license is not GPL but is GPL compatible. What license should the Google Code project fall under? MIT, GPL or something else? Eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 19:57:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jun 2009 23:57:38 GMT Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: <02345d7c$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 10:54:48 +1200, Lawrence D'Oliveiro wrote: > In message , Albert van der Horst wrote: > >> An indication of how one can see one is in emacs is also appreciated. > > How about, hit CTRL/G and see if the word "Quit" appears somewhere. Ah, one has to love user interfaces designed with mnemonic keyboard commands so as to minimize the burden of rote learning on the user. Presumably it is G for "Get me the frack outta here!". Having noted that the word "Quit" does appear, how do you then *actually* Quit? Apart from taunting the user, what is it that Ctrl-G is actually doing when it displays the word "Quit" in what seems to be some sort of status bar? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 20:00:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 00:00:49 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <02345e3a$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 01:46:23 +0200, Stef Mientki wrote: > MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. To >>> get a picture, I need to know what path I'm on in each python module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, but now put your code in a > file, let's say the file "test.py", and now run this file by : > execfile ( 'test.py' ) In that case, test.py is not a module. It's just a file that by accident has a .py extension, which is read into memory and executed. If you bypass the module mechanism, don't be surprised that you've bypassed the module mechanism :) What are you trying to do? Using execfile is probably not the right solution. -- Steven From davea at ieee.org Mon Jun 1 20:10:28 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 01 Jun 2009 20:10:28 -0400 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A24684F.3090109@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <4A24684F.3090109@gmail.com> Message-ID: <4A246DF4.4@ieee.org> Stef Mientki wrote: >
MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. >>> To get a picture, I need to know what path I'm on in each python >>> module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > execfile ( 'test.py' ) > > cheers, > Stef > >
> Your original post asked about "what path I'm on in each python module". Now it turns out you're using execfile(), which doesn't create a module, it shortcircuits most of that. So why not import the file as a module instead of using execfile? Maybe using __import__() ? From emile at fenx.com Mon Jun 1 20:13:53 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Jun 2009 17:13:53 -0700 Subject: What text editor is everyone using for Python In-Reply-To: <02345d7c$0$8244$c3e8da3@news.astraweb.com> References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 6/1/2009 4:57 PM Steven D'Aprano said... > Having noted that the word "Quit" does appear, how do you then *actually* > Quit? Apart from taunting the user, what is it that Ctrl-G is actually > doing when it displays the word "Quit" in what seems to be some sort of > status bar? Ahhh.. memories of discovering that F7 gets you out of WordPerfect... Emile From python at mrabarnett.plus.com Mon Jun 1 20:14:22 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 01:14:22 +0100 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A24684F.3090109@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <4A24684F.3090109@gmail.com> Message-ID: <4A246EDE.80802@mrabarnett.plus.com> Stef Mientki wrote: > MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. >>> To get a picture, I need to know what path I'm on in each python module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > execfile ( 'test.py' ) > You didn't say you were using execfile. # File: C:\Quick test\main.py parent_path = r"C:\Quick test\parent.py" execfile(parent_path, {"__file__": parent_path}) # Output: name is child file is C:\Quick test\child.pyc name is __builtin__ file is C:\Quick test\parent.py Notice how the extension of the child is now .pyc because it has already been compiled. From python at mrabarnett.plus.com Mon Jun 1 20:19:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 01:19:42 +0100 Subject: What text editor is everyone using for Python In-Reply-To: References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A24701E.8050304@mrabarnett.plus.com> Emile van Sebille wrote: > On 6/1/2009 4:57 PM Steven D'Aprano said... >> Having noted that the word "Quit" does appear, how do you then >> *actually* Quit? Apart from taunting the user, what is it that Ctrl-G >> is actually doing when it displays the word "Quit" in what seems to be >> some sort of status bar? > > Ahhh.. memories of discovering that F7 gets you out of WordPerfect... > And if you need help, just press F1, uh, I mean F3... :-) From mensanator at aol.com Mon Jun 1 20:24:49 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 17:24:49 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> Message-ID: <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> On Jun 1, 6:40?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > > I believe the name you're looking for is combinations_with_replacement. > > It is one of the features being added to 3.1 which should give all the > > subsets of the Cartesian Product: > > > permutations_with_replacement: ? ?product() > > combinations_with_replacement: ? ?combinations_with_replacement() > > permutations_without_replacement: permutations() > > combinations_without_replacement: combinations() > > What, no partitions? Itertools does partitions? > > http://en.wikipedia.org/wiki/Partition_of_a_set I didn't see any reference to Cartesian Product there. > > -- > Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 20:40:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 00:40:26 GMT Subject: Absolute imports in Python 2.4 Message-ID: <02346783$0$8244$c3e8da3@news.astraweb.com> I have a package which includes a module which shadows a module in the standard library. For example: package +-- __init__.py +-- ham.py +-- spam.py +-- sys.py Inside that package, I want to import the standard library sys. In other words, I want an absolute import. In Python 2.7, absolute imports will be the default, and "import sys" will import the standard library module. To get to the package.sys module, I'll need "from . import sys". In Python 2.5 and 2.6, relative imports are the default, and package.sys will shadow the std lib version. I can say: from __future__ import absolute_import to use the Python 2.7 behaviour. What can I do in Python 2.4 to get an absolute import? I've read PEP 328 and googled, but haven't found any useful advice other than "well don't do that then". Plenty of pages complaining about relative imports, but I haven't found any work-arounds others than renaming the offending module. Are there any other ways around this? http://www.python.org/dev/peps/pep-0328/ -- Steven From stef.mientki at gmail.com Mon Jun 1 20:55:13 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 02:55:13 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <02345e3a$0$8244$c3e8da3@news.astraweb.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A247871.5090804@gmail.com> Steven D'Aprano wrote: > On Tue, 02 Jun 2009 01:46:23 +0200, Stef Mientki wrote: > > >> MRAB wrote: >> >>> Stef Mientki wrote: >>> >>>> hello, >>>> >>>> I've pictures stored in a path relative to my python source code. To >>>> get a picture, I need to know what path I'm on in each python module. >>>> I thought __file__ would do the job, >>>> but apparently I didn't read the documentation carefully enough, >>>> because file is the path to the module that called my module. >>>> >>>> Any ways to get the path of "myself" ? >>>> >>>> >>> I'm not sure what you mean. I just did a quick test. >>> >>> # File: C:\Quick test\child.py >>> print "name is %s" % __name__ >>> print "file is %s" % __file__ >>> >>> # File: C:\Quick test\parent.py >>> import child >>> >>> print "name is %s" % __name__ >>> print "file is %s" % __file__ >>> >>> # Output: >>> name is child >>> file is C:\Quick test\child.py >>> name is __main__ >>> file is C:\Quick test\parent.py >>> >> Yes, that's what I (and many others) thought, but now put your code in a >> file, let's say the file "test.py", and now run this file by : >> execfile ( 'test.py' ) >> > > In that case, test.py is not a module. It's just a file that by accident > has a .py extension, which is read into memory and executed. > > If you bypass the module mechanism, don't be surprised that you've > bypassed the module mechanism :) > > What are you trying to do? Using execfile is probably not the right > solution. > > Maybe you're right, and it's not the best solution for my problem. I've written a program, that contains many files, both python files and data files, and I would like to distribute the program. For Linux, I'll just bundle the files in a zip-file, but for windows I want to make a one button installer, and the files generated by Py2Exe, don't work at all. Through this discussion, I discovered another problem, because __file__ isn't the current file, I can't run 1 module(file) from another module (file) . The structure of my files is something like this: Base_Path Main_Program_Path Main_Program_1.py Main_Program_2.py Brick_Path Brick_1.py Brick_2.py Support_Libraries Support_Library_1.py Support_Library_2.py Sounds_Path Sound_1.wav Sound_2.wav Picture_Path Picture_1.png Picture_2.bmp The Main_Programs, should be able to "run/launch" other Main_Programs and Support_Libraries, in several ways (wait / nowait, fetch output or not, ... ). So each Support_Libraries will have a "main-section". Everything is highly dynamical, just dumping a new py-file in the Brick_Path, will make the py-files available ( i.e. directly visible and usable to the user) in all Main_Programs. Moving the complete file-structure to Linux or Windows works good. Distributing the files through Py2Exe doesn't work at all. So I was thinking of a hack: - make dummy programs, that will start Main_Program_x.py through a execfile function - Create executables with Py2Exe of the dummy programs - add manually the whole directory structure to the files generated by Py2Exe - automate the above process by Inno setup Any suggestions ? thanks, Stef > > From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 21:28:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 01:28:53 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> Message-ID: <023472dd$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > On Jun 1, 6:40?pm, Steven D'Aprano cybersource.com.au> wrote: >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: >> > I believe the name you're looking for is >> > combinations_with_replacement. It is one of the features being added >> > to 3.1 which should give all the subsets of the Cartesian Product: >> >> > permutations_with_replacement: ? ?product() >> > combinations_with_replacement: ? ?combinations_with_replacement() >> > permutations_without_replacement: permutations() >> > combinations_without_replacement: combinations() >> >> What, no partitions? > > Itertools does partitions? Er, no. That's why I asked "What, no partitions?" instead of saying "Look, itertools also does partitions!" >> http://en.wikipedia.org/wiki/Partition_of_a_set > > I didn't see any reference to Cartesian Product there. Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it in if you think it needs to be there. While you're at it, there is no mention of Cartesian Product in any of http://en.wikipedia.org/wiki/Permutations http://en.wikipedia.org/wiki/Combinations http://mathworld.wolfram.com/Permutation.html http://mathworld.wolfram.com/k-Subset.html either. Are you sure that permutations and combinations are subsets of the Cartesian Product? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 21:51:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 01:51:20 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> Message-ID: <0234781f$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 02:55:13 +0200, Stef Mientki wrote: >> What are you trying to do? Using execfile is probably not the right >> solution. >> >> > Maybe you're right, and it's not the best solution for my problem. I've > written a program, that contains many files, both python files and data > files, > and I would like to distribute the program. For Linux, I'll just bundle > the files in a zip-file, but for windows I want to make a one button > installer, and the files generated by Py2Exe, don't work at all. Define "don't work at all". > Through this discussion, I discovered another problem, because __file__ > isn't the current file, I can't run 1 module(file) from another module > (file) . ... It sounds like you are trying to fight Python's module system instead of working with it. In Python programs, you don't "run" other modules, you import them, then call functions inside the module. You treat the modules you write exactly the same as standard library modules. As a general rule, you would never say: execfile('/usr/lib/python2.5/os.py') Instead you would say: import os os.some_function() The same rule applies for your modules. As a general rule, NEVER say: execfile('mymodule.py') instead do: import mymodule mymodule.some_function() mymodule.another_function() (There are exceptions, but if you need to ask what they are, you're not ready to learn them! *wink*) > The structure of my files is something like this: > > Base_Path > Main_Program_Path > Main_Program_1.py > Main_Program_2.py > Brick_Path > Brick_1.py > Brick_2.py > Support_Libraries > Support_Library_1.py > Support_Library_2.py > Sounds_Path > Sound_1.wav > Sound_2.wav > Picture_Path > Picture_1.png > Picture_2.bmp Are these packages? Or just random folders with random files in them? > The Main_Programs, should be able to "run/launch" other Main_Programs > and Support_Libraries, > in several ways (wait / nowait, fetch output or not, ... ). So each > Support_Libraries will have a "main-section". Sounds like a horribly fragile, complicated and complex way of doing things. > Everything is highly > dynamical, just dumping a new py-file in the Brick_Path, will make the > py-files available ( i.e. directly visible and usable to the user) in > all Main_Programs. Sounds like you're trying to implement plugins. For that, __import__() is your friend. execfile() is *not* your friend -- you might think it is, but don't listen to it. It's like one of those guys who calls you "buddy" and talks you into doing things that you regret the next day. Trust me, use execfile() and you'll end up waking up naked in an alleyway in Vegas married to someone called Lula-Mae, with no memory of the last three days and a tattoo of Paris Hilton on your butt. > Distributing the files through Py2Exe doesn't work at all. So I was > thinking of a hack: As soon as you start thinking of using a hack in production code, go take a cold shower and lie down until the urge goes away. > Any suggestions ? Have you tried to find out why Py2Exe is broken and fix that? -- Steven From jyoung79 at kc.rr.com Mon Jun 1 22:15:20 2009 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Tue, 2 Jun 2009 2:15:20 +0000 Subject: Installing 3.1 questions Message-ID: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> Can anyone give me info on what and where Python installs on OS X? I ran the installers for version 2.6 and 3.0 and only installed Python (not IDLE, etc). I then added this to my .profile: PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}" PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" PATH="/System/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" export PATH Seems to work, but I'd like to know where Python installs its items. I'm wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' file (not sure of the difference between it and the 'Gzipped' one). Do I need to run some sort of 'install' command from the Terminal to get 3.1 to work? Or can I manually drag the items to a correct location and then update my .profile? Thanks for taking the time to look at my questions. Jay From pavlovevidence at gmail.com Mon Jun 1 22:25:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Jun 2009 19:25:41 -0700 (PDT) Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <43095f7e-3111-4b0f-baf8-540047bc687a@l32g2000vba.googlegroups.com> On Jun 1, 4:46?pm, Stef Mientki wrote: > MRAB wrote: > > Stef Mientki wrote: > >> hello, > > >> I've pictures stored in a path relative to my python source code. > >> To get a picture, I need to know what path I'm on in each python module. > >> I thought __file__ would do the job, > >> but apparently I didn't read the documentation carefully enough, > >> because file is the path to the module that called my module. > > >> Any ways to get the path of "myself" ? > > > I'm not sure what you mean. I just did a quick test. > > > # File: C:\Quick test\child.py > > print "name is %s" % __name__ > > print "file is %s" % __file__ > > > # File: C:\Quick test\parent.py > > import child > > > print "name is %s" % __name__ > > print "file is %s" % __file__ > > > # Output: > > name is child > > file is C:\Quick test\child.py > > name is __main__ > > file is C:\Quick test\parent.py > > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > ? ? execfile ( 'test.py' ) How can you execfile test.py without knowing the path to it? Whatever path you used to locate test.py is where the file is. If you're just execfiling a bare filename, then it's in the current directory, so just construct a relative pathname. Carl Banks From python.list at tim.thechases.com Mon Jun 1 22:35:00 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Jun 2009 21:35:00 -0500 Subject: Not going to let this drop ... In-Reply-To: <4A23B15C.3090403@holdenweb.com> References: <4A23B15C.3090403@holdenweb.com> Message-ID: <4A248FD4.8030902@tim.thechases.com> > If anyone who reads this email has anything to offer - time, > money, equipment, whatever, I'd be *really* grateful to hear > from them. I can put you in touch with people who know about > things like the range of interface devices available for > paraplegic and quadriplegic people. Ideally the program would > be adaptable to a wide range of hardware accommodating a broad > spectrum of disability, but many quadriplegics use equipment > that emulates a standard keyboard and/or mouse, so that would > be a great start. While I don't have too much to offer, I'll pass along what I do have: A) An OLPC (mostly Python-based kit) project[1] to provide simple icons-to-speech that sounds a bit like what you're describing. My addition to the thread is about Dasher[2], posted as Gumnos. A Dasher-like interface may allow for a greater range of expression with minimal "2-axis plus sip-puff" selection. If I were mobility-impaired, I'd use Dasher to communicate & code (perhaps even coding Python atoms/tokens as their own entities for ease of entry :) B) There are also groups of folks such as the IGDA (Independent Game Developers Association)'s SIG-Access[3] which focuses on promoting accessibility in gaming. Robert Florio[4] is one of the folks in the SIG and has a vested interest in improving accessibility for mobility-impaired gamers (others on the list have particular interests/focii in visual, auditory or mental challenges). I mention this group first because they have some innovative solutions for taking existing applications/games and either retrofitting accessibility solutions as well as exploring new design goals to make applications/games accessible upon launch. Other similar groups exist for things like web-accessibility (WCAG WG[5], WAG[6]) but that seems a little outside your focus. Hope this gives you some ideas/connections that help you out. -tkc [1] http://www.olpcnews.com/software/applications/free_icon-to-speech_open-source_speech_for_disabled.html [2] http://www.inference.phy.cam.ac.uk/dasher/ [3] http://www.igda.org/wiki/index.php/Game_Accessibility_SIG [4] http://www.robertflorio.com [5] http://www.w3.org/WAI/PA/ [6] http://www.bristol.ac.uk/webaccessibility/ From wuwei23 at gmail.com Mon Jun 1 23:00:01 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Jun 2009 20:00:01 -0700 (PDT) Subject: Is there any module for sea tides? References: Message-ID: "alejandro" wrote: > I found some in C but could not find in Python.... The best I could find was a reference to some in-house code used by the US National Oceanoic & Atmospheric Association: http://tinyurl.com/mct9zz You might be able to contact the email address at the bottom and inquire about the code. Another alternative is to look into using the ctypes module to create bindings for the C libs you found... From benjamin.kaplan at case.edu Tue Jun 2 00:32:36 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 2 Jun 2009 00:32:36 -0400 Subject: Installing 3.1 questions In-Reply-To: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> References: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> Message-ID: On Mon, Jun 1, 2009 at 10:15 PM, wrote: > Can anyone give me info on what and where Python installs on OS X? > I ran the installers for version 2.6 and 3.0 and only installed Python > (not IDLE, etc). I then added this to my .profile: > > PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}" > PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" > > PATH="/System/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" > export PATH > > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? Or can I manually drag the items to a correct location and > then update my .profile? > > Thanks for taking the time to look at my questions. > I take it you've never compiled anything yourself before, so I'll go through it step by step. The bzip and gzip are just two different compression methods, so it doesn't matter which tarball you download. In order to go further, you'll need to register at developer.apple.com and download Xcode. You won't need to use Xcode itself, but you need the compilers that come with it. It's a pretty big download, so this will take a while. Once you install Xcode, open up a terminal (/Applications/Utilities/Terminal.app) and cd (change directory) to wherever you put the extracted tarball. In that directory, run the configure file. Since your on OS X, you probably want a framework build (installed to /Library/Frameworks) instead of a normal build, which installs to /usr/local. To do this, execute the command "./configure --enable-framework". If you want to look up the other options, run "./configure --help". You'll probably get an error about missing dependencies. The easiest place to find these is in a package manager such as fink (www.finkproject.org) or macports (www.macports.org). Fink is easier and faster, but macports is usually more up-to-date and flexible since it compiles everything locally. Both of them will work. Just don't forget to add the paths (macports is in /opt/local/ and fink is in /sw/) Once the configure command works successfully, run the commands "make" and "sudo make install". The first one will compile everything, the second will put it where it's supposed to be. After running the latter, you'll be prompted to enter your password. That should install it to /Library/Frameworks/Python.framework/versions/3.1. I haven't installed 3.1 myself but assuming it does the same thing as 3.0, it should a python3.1 executable (symlink actually) to /usr/local/bin so you shouldn't need to add anything to the path. > > Jay > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jun 2 00:51:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 01:51:35 -0300 Subject: Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser escribi?: > I can examine the inherited slots to see which special methods are > there, and to implement my own __deepcopy__ accordingly. But to do > so well seems to essentially require reimplementing the complicated > logic of the copy.deepcopy function. That is, if my new class is > the first to be implementing an explicit __deepcopy__ function, I > seem to have no easy way to invoke the inherited version of > "deepcopy(self)". Yes, that's a problem. But there is a workaround: since __deepcopy__ is searched *in the instance* (unlike many other __special__ methods, that are usually searched in the class itself) you can fool the copy logic into thinking there is no __deepcopy__ method defined, just by (temporarily) setting an instance attribute __deepcopy__ to None. (It's a hack, anyway) import copy class A(object): def __init__(self, x, y): self.x = x self.y = y # these two methods implement copy and pickle behaviour # we can't change them def __reduce__(self): return (self.__newobj__, (), self.__dict__) @classmethod def __newobj__(cls, *args): return cls.__new__(cls, *args) class B(A): def __init__(self, x, y, filename): A.__init__(self, x, y) self.file = open(filename, "at") def __deepcopy__(self, memo): # Problem: how to call the inherited __deepcopy__ implementation # when there is none? # The logic is inside the copy.deepcopy function, not in # object.__deepcopy__ # hack: make deepcopy() think this method doesn't exist self.__deepcopy__ = None try: dup = copy.deepcopy(self, memo) del dup.__deepcopy__ finally: del self.__deepcopy__ # now, do the special stuff dup.file = open(self.file.name, "at") return dup obj = B(1, 2, "testfile") print "obj", obj, vars(obj) dup = copy.deepcopy(obj) print "obj", obj, vars(obj) print "dup", dup, vars(dup) obj <__main__.B object at 0x00BEC0F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46C00>} obj <__main__.B object at 0x00BEC0F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46C00>} dup <__main__.B object at 0x00BEC7F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46CA0>} > I wonder if the logic inherent in the copy.deepcopy function could > instead be implemented directly within object.__deepcopy__ (rather > than the current model in which object does not have __deepcopy__). > Then I would always have a means for simulating a call to > deepcopy(self) based upon the super.__deepcopy__ logic. > I wouldn't be surprised if I'm overlooking some undesirable > consequence of such a major change in the model, but I don't see one > upon first thought. This deserves to be looked at with more detail. Try the python-ideas list, or submit a RFE to http://bugs.python.org/ -- Gabriel Genellina From lepto.python at gmail.com Tue Jun 2 01:18:25 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 13:18:25 +0800 Subject: Dabo 0.9.2 released Message-ID: <6a4f17690906012218v45f4e8b8of300c08b1ea9cbc8@mail.gmail.com> I have to say: please let dabo use english if it does not find any langauge resource! I have 'e:\prg\py\sap-24\python e:\prg\py\pure_pylib\_dabo\tools\remove_dLocalize.py .', but then the scripts says 'I don't know _" From mensanator at aol.com Tue Jun 2 01:20:16 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 22:20:16 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: On Jun 1, 8:28?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > > On Jun 1, 6:40?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > >> > I believe the name you're looking for is > >> > combinations_with_replacement. It is one of the features being added > >> > to 3.1 which should give all the subsets of the Cartesian Product: > > >> > permutations_with_replacement: ? ?product() > >> > combinations_with_replacement: ? ?combinations_with_replacement() > >> > permutations_without_replacement: permutations() > >> > combinations_without_replacement: combinations() > > >> What, no partitions? > > > Itertools does partitions? > > Er, no. That's why I asked "What, no partitions?" instead of saying > "Look, itertools also does partitions!" > > >>http://en.wikipedia.org/wiki/Partition_of_a_set > > > I didn't see any reference to Cartesian Product there. > > Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it > in if you think it needs to be there. While you're at it, there is no > mention of Cartesian Product in any of > > http://en.wikipedia.org/wiki/Permutationshttp://en.wikipedia.org/wiki/Combinations > > http://mathworld.wolfram.com/Permutation.htmlhttp://mathworld.wolfram.com/k-Subset.html > > either. You might have better luck with Google. > Are you sure that permutations and combinations are subsets of > the Cartesian Product? Sure looks that way (SQL examples): Cartesian Product (Permutaions w/replacement) SELECT B.q, A.p FROM A, B; q p a a a b b a b b Permutaions wo/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)<>[B].[q])); q p a b b a Combinations w/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)>=[B].[q])); q p a a a b b b Combinations wo/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)>[B].[q])); q p a b I couldn't do that if they weren't subsets. > > -- > Steven From tonal at promsoft.ru Tue Jun 2 01:25:36 2009 From: tonal at promsoft.ru (Alexandr N Zamaraev) Date: Tue, 02 Jun 2009 12:25:36 +0700 Subject: Why date do not construct from date? Message-ID: <4A24B7D0.501@promsoft.ru> Simple example: [code] Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 >>> import datetime as dt >>> dt.date(2009, 10, 15) datetime.date(2009, 10, 15) >>> d = dt.date(2009, 10, 15) >>> dt.date(d) Traceback (most recent call last): File "", line 1, in TypeError: function takes exactly 3 arguments (1 given) >>> [/code] Why int form int, str from str, Decumal from Decumal can construct bat date from date not? From gagsl-py2 at yahoo.com.ar Tue Jun 2 01:37:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 02:37:04 -0300 Subject: Absolute imports in Python 2.4 References: <02346783$0$8244$c3e8da3@news.astraweb.com> Message-ID: En Mon, 01 Jun 2009 21:40:26 -0300, Steven D'Aprano escribi?: > I have a package which includes a module which shadows a module in the > standard library. For example: > > package > +-- __init__.py > +-- ham.py > +-- spam.py > +-- sys.py > > Inside that package, I want to import the standard library sys. In other > words, I want an absolute import. [...] > What can I do in Python 2.4 to get an absolute import? sys = __import__("sys", {}) The import statement uses the global namespace to determine which package it is called on; if you pass an empty namespace, it cannot infer package information. Anyway, the best move would be to rename the offending module... -- Gabriel Genellina From mensanator at aol.com Tue Jun 2 01:45:27 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 22:45:27 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: <70591a8c-4213-461f-8952-e0a69dca9678@z9g2000yqi.googlegroups.com> On Jun 1, 8:28?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > > On Jun 1, 6:40?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > >> > I believe the name you're looking for is > >> > combinations_with_replacement. It is one of the features being added > >> > to 3.1 which should give all the subsets of the Cartesian Product: > > >> > permutations_with_replacement: ? ?product() > >> > combinations_with_replacement: ? ?combinations_with_replacement() > >> > permutations_without_replacement: permutations() > >> > combinations_without_replacement: combinations() > > >> What, no partitions? > > > Itertools does partitions? > > Er, no. That's why I asked "What, no partitions?" instead of saying > "Look, itertools also does partitions!" > > >>http://en.wikipedia.org/wiki/Partition_of_a_set > > > I didn't see any reference to Cartesian Product there. > > Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it > in if you think it needs to be there. While you're at it, there is no > mention of Cartesian Product in any of > > http://en.wikipedia.org/wiki/Permutationshttp://en.wikipedia.org/wiki/Combinations > > http://mathworld.wolfram.com/Permutation.htmlhttp://mathworld.wolfram.com/k-Subset.html > > either. Are you sure that permutations and combinations are subsets of > the Cartesian Product? Didn't notice this before - it says so in the docs! itertools.product(*iterables[, repeat])? Cartesian product of input iterables. The code for permutations() can be also expressed as a subsequence of product(), filtered to exclude entries with repeated elements (those from the same position in the input pool): The code for combinations() can be also expressed as a subsequence of permutations() after filtering entries where the elements are not in sorted order (according to their position in the input pool): > > -- > Steven From martin at v.loewis.de Tue Jun 2 02:01:07 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Tue, 02 Jun 2009 08:01:07 +0200 Subject: Installing 3.1 questions In-Reply-To: References: Message-ID: <4A24C023.7070208@v.loewis.de> > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? You need to build it. Read the README file in the source distribution. If you don't know what a "tar ball" is, read tar(1). Regards, Martin From martin at v.loewis.de Tue Jun 2 02:01:07 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Tue, 02 Jun 2009 08:01:07 +0200 Subject: Installing 3.1 questions In-Reply-To: References: Message-ID: <4A24C023.7070208@v.loewis.de> > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? You need to build it. Read the README file in the source distribution. If you don't know what a "tar ball" is, read tar(1). Regards, Martin From clp2 at rebertia.com Tue Jun 2 02:14:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 23:14:22 -0700 Subject: Why date do not construct from date? In-Reply-To: <4A24B7D0.501@promsoft.ru> References: <4A24B7D0.501@promsoft.ru> Message-ID: <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev wrote: > Simple example: > [code] > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] > on win32 >>>> import datetime as dt >>>> dt.date(2009, 10, 15) > datetime.date(2009, 10, 15) >>>> d = dt.date(2009, 10, 15) >>>> dt.date(d) > Traceback (most recent call last): > ?File "", line 1, in > TypeError: function takes exactly 3 arguments (1 given) >>>> > [/code] > Why int form int, str from str, Decumal from Decumal can construct bat date > from date not? Probably because the function signatures would be so different. str(), int(), etc *always* take *exactly one* argument -- the object to convert. In contrast, date() takes several integers corresponding to the year, month, and day. Adding a second signature to it that took exactly one argument (of type `date`) and copied it would be significantly different from its other signature; in idiomatic Python, one would typically make a separate, new function for this drastically different signature. However, the `date` type is immutable, so there's no reason at all to try and copy a new instance from an existing one anyway, thus a single-argument copy-constructor is completely unnecessary, hence why there isn't one. Cheers, Chris -- http://blog.rebertia.com From pataphor at gmail.com Tue Jun 2 02:53:34 2009 From: pataphor at gmail.com (pataphor) Date: Tue, 02 Jun 2009 08:53:34 +0200 Subject: Generating all combinations In-Reply-To: References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: Mensanator wrote: > I couldn't do that if they weren't subsets. Right. Sometimes one just has to assume things are different even if they look the same on the surface. That is because else one wouldn't be able to produce the other generators. I guess it would also work the other way around, assuming things are the same even when they look different. For example see my two functions: def repeat_each(seq,n): while True: for x in seq: for i in range(n): yield x def repeat_all(seq,n): while True: for i in range(n): for x in seq: yield x (I should probably not smoke stuff before posting, but anyway) They are the same, except for switching two lines of code. But for the second one ('repeat_all') the argument 'n' seems redundant. What does it even mean to repeat a sequence n times, and do that forever? Isn't that the same as just repeating the sequence itself, forever? So that's how we arrive at itertools.cycle . The second argument is there, but it would be foolish to include it, so it is left out. But now let's look at how itertools.repeat should really be. It should look like 'repeat_each' above. Here second argument ('n') *is* necessary, or else the generator would just infinitely repeat only the first element of the sequence, which is obviously nonsense. But that is exactly why itertools.repeat does not accept a sequence (like cycle, its virtual brother) but instead it has degenerated into something that just repeats only one thing n times, which is stupid. So to set things right one has to forget everything and just write complete balderdash if necessary, if it only leads to finally understanding how the two are related. Then one can see that itertools.repeat should be an infinite generator *on sequences* that however still needs a second argument specifying how many times each individual item should be repeated, and that itertools.cycle's second argument is there but hidden. P. From gagsl-py2 at yahoo.com.ar Tue Jun 2 03:05:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 04:05:08 -0300 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert escribi?: > On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev > wrote: >>>>> import datetime as dt >>>>> d = dt.date(2009, 10, 15) >>>>> dt.date(d) >> Traceback (most recent call last): >> ?File "", line 1, in >> TypeError: function takes exactly 3 arguments (1 given) >> Why int form int, str from str, Decumal from Decumal can construct bat >> date from date not? > > Probably because the function signatures would be so different. str(), > int(), etc *always* take *exactly one* argument -- the object to > convert. In contrast, date() takes several integers corresponding to > the year, month, and day. Adding a second signature to it that took > exactly one argument (of type `date`) and copied it would be > significantly different from its other signature; in idiomatic Python, > one would typically make a separate, new function for this drastically > different signature. That doesn't convince me. It's not very consistent along the various types: int("3ab0",16) is rather different than int(3.2) but they're the same function... > However, the `date` type is immutable, so there's no reason at all to > try and copy a new instance from an existing one anyway, thus a > single-argument copy-constructor is completely unnecessary, hence why > there isn't one. Isn't the same for all other examples (int, float, str, Decimal...)? They're all immutable types, and some have several and rather different constructor signatures: py> Decimal((0, (1, 5, 0, 0), -3)) Decimal('1.500') py> Decimal(Decimal('1.500')) Decimal('1.500') If one can say float(3.0), str("hello"), etc -- what's so wrong with date(another_date)? -- Gabriel Genellina From __peter__ at web.de Tue Jun 2 03:45:19 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Jun 2009 09:45:19 +0200 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > If one can say float(3.0), str("hello"), etc -- what's so wrong with > date(another_date)? You can do x = float(x) when you don't know whether x is a float, int, or str. Not terribly useful, but sometimes convenient because making the float() call idempotent allows you to skip the type check. def subtract(a, b): if isinstance(a, str): a = float(b) if isinstance(b, str): b = float(b) return a - b becomes def subtract(a, b): return float(a) - float(b) For date you'd have to make the type check anyway, e. g. if isinstance(x, tuple): x = date(*x) else: x = date(x) # useless will only succeed if x already is a date as there would be no other way to create a date from a single value. So the date() call in the else branch is completely redundant unless you change date() to accept multiple types via the same signature: for x in "2000-01-01", datetime.now(), (2000, 1, 1): print date(x) Peter From cdsd at d.com Tue Jun 2 03:51:29 2009 From: cdsd at d.com (ssd) Date: Tue, 2 Jun 2009 09:51:29 +0200 Subject: python 2.6 packages in python 3.0 Message-ID: Hi, I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. When is planned that these packages are supported in Python 3.0? Seen this i would say that is not recommendable to use Python 3.0 at the moment? most of 2.6 packages are not available, not working in python 3.0. Thanks, Bye, From clp2 at rebertia.com Tue Jun 2 04:01:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Jun 2009 01:01:52 -0700 Subject: python 2.6 packages in python 3.0 In-Reply-To: References: Message-ID: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> On Tue, Jun 2, 2009 at 12:51 AM, ssd wrote: > Hi, > > I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. > > When is planned that these packages are supported in Python 3.0? That would depend on the individual packages and their maintainers. Check their respective websites. There is not, as of yet, any concerted/coordinated effort to port third-party libraries to 3.0. > Seen this i would say that is not recommendable to use Python 3.0 at the > moment? most of 2.6 packages are not available, not working in python 3.0. Yes, that's basically the state of things at the moment. We're in a transitional phase while people port everything to Python 3.0 and/or wait for the libraries they require to be ported to 3.0. Cheers, Chris -- http://blog.rebertia.com From tiskanto at gmail.com Tue Jun 2 05:04:49 2009 From: tiskanto at gmail.com (Teguh Iskanto) Date: Tue, 2 Jun 2009 19:04:49 +1000 Subject: No subject In-Reply-To: References: Message-ID: how about this : - dump those data with sort enabled - use diff to those two dumps , eg: diff dump_a dump_b if you don't know what diff is , try : man diff HTH On Tue, Jun 2, 2009 at 2:50 AM, Kiran Siddiqui wrote: > hi have to parse a very complex dumps(whatever it is), i have done the > parsing thruogh python.since the parsed data is very huge in amount, i have > to feed it in the database (SQL), I have also done this... now the thing is > i have to compare the data now present in the sql. > > > > in actual i have to compare the data of 1st dump with the data of the 2nd > dump..... the both dump have the same fields(attributes) but the values of > their field may be change... so i have to detect this change.. for this i > have to do the comparison... > > > > i.e, let i have a tableA ,its 1st row carry the data of dump1 and then on > the 2nd day the data comes from dump2 go into the next row of tableA. and i > have to compare both rows. > > > > but i dont have the idea how to do this all using python as my front end. > > > > plz plzzzz anyone help me:( > > > > ------------------------------ > See all the ways you can stay connected to friends and family > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Tue Jun 2 05:11:30 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 2 Jun 2009 11:11:30 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A247871.5090804@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <4A247871.5090804@gmail.com> Message-ID: <9fdb569a0906020211t2c4c5d3w7df511570ee41640@mail.gmail.com> 2009/6/2 Stef Mientki : ... > and the files generated by Py2Exe, don't work at all. > > Through this discussion, I discovered another problem, > because __file__ isn't the current file, > I can't run 1 module(file) from another module (file) . > > -- > http://mail.python.org/mailman/listinfo/python-list > There are already answers regarding other more topical issues with the initial problem; but just in case the main problem would be the use of __file__ ... It seems, that the exe files generated from py2exe don't recognise this variable; sometimes I used code like try: __file__ except NameError: # py2exe __file__ = sys.path[0] cf. e.g. http://mail.python.org/pipermail/python-list/2001-May/085384.html I'm not sure, whether there are any drawbacks, but it works in the respective context (accessing text and image files in parallel directories). vbr From HeinTest at web.de Tue Jun 2 05:28:43 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 02 Jun 2009 11:28:43 +0200 Subject: Seach for encrypted socket wrapper Message-ID: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Hello experts, I'm looking for secure way to pass messages from a python program to a c-library in both ways. This scenario is given: display client Calculation module in COBOL (yes, big, old but it works well) (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with display client The network connection should be encrypted. And fail save. Has someone an idea what to use ? I have had a short look on xml rpc which can run over a https server but this seems quite fat. Better ideas ?! Importand is also that the C-Lib on the cobol side should be coded as simple as possible. Platforms: Windows, *ix Thanks a lot. Hans From tjreedy at udel.edu Tue Jun 2 05:29:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Jun 2009 05:29:40 -0400 Subject: python 2.6 packages in python 3.0 In-Reply-To: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> References: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Tue, Jun 2, 2009 at 12:51 AM, ssd wrote: >> Hi, >> >> I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. >> >> When is planned that these packages are supported in Python 3.0? > > That would depend on the individual packages and their maintainers. > Check their respective websites. There is not, as of yet, any > concerted/coordinated effort to port third-party libraries to 3.0. That is more likely to happen after 3.1 final is released in a month or less. >> Seen this i would say that is not recommendable to use Python 3.0 at the >> moment? most of 2.6 packages are not available, not working in python 3.0. If you need the packages, then 3.0 is not for you. > Yes, that's basically the state of things at the moment. We're in a > transitional phase while people port everything to Python 3.0 and/or > wait for the libraries they require to be ported to 3.0. I expect people to port directly to 3.1 and not worry about whether there are minor incompatibilities with 3.0. tjr From lie.1296 at gmail.com Tue Jun 2 06:34:43 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 20:34:43 +1000 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: Gabriel Genellina wrote: > En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser > escribi?: > >> I can examine the inherited slots to see which special methods are >> there, and to implement my own __deepcopy__ accordingly. But to do >> so well seems to essentially require reimplementing the complicated >> logic of the copy.deepcopy function. That is, if my new class is >> the first to be implementing an explicit __deepcopy__ function, I >> seem to have no easy way to invoke the inherited version of >> "deepcopy(self)". > > Yes, that's a problem. But there is a workaround: since __deepcopy__ is > searched *in the instance* (unlike many other __special__ methods, that > are usually searched in the class itself) you can fool the copy logic > into thinking there is no __deepcopy__ method defined, just by > (temporarily) setting an instance attribute __deepcopy__ to None. (It's > a hack, anyway) I've never really used pickle before but maybe you could try pickling then unpickling? It is a hack, but for some objects that does not have __deepcopy__ it might be sufficient. From roy at panix.com Tue Jun 2 06:55:20 2009 From: roy at panix.com (Roy Smith) Date: Tue, 02 Jun 2009 06:55:20 -0400 Subject: Is there any module for sea tides? References: Message-ID: In article , alex23 wrote: > "alejandro" wrote: > > I found some in C but could not find in Python.... > > The best I could find was a reference to some in-house code used by > the US National Oceanoic & Atmospheric Association: > > http://tinyurl.com/mct9zz > > You might be able to contact the email address at the bottom and > inquire about the code. > > Another alternative is to look into using the ctypes module to create > bindings for the C libs you found... This is really off-topic for a Python group, but... http://www.flaterco.com/xtide/index.html From lie.1296 at gmail.com Tue Jun 2 07:07:32 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 11:07:32 GMT Subject: Why date do not construct from date? In-Reply-To: References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert > escribi?: > >> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >> wrote: > >>>>>> import datetime as dt >>>>>> d = dt.date(2009, 10, 15) >>>>>> dt.date(d) >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: function takes exactly 3 arguments (1 given) > >>> Why int form int, str from str, Decumal from Decumal can construct >>> bat date from date not? >> >> Probably because the function signatures would be so different. str(), >> int(), etc *always* take *exactly one* argument -- the object to >> convert. In contrast, date() takes several integers corresponding to >> the year, month, and day. Adding a second signature to it that took >> exactly one argument (of type `date`) and copied it would be >> significantly different from its other signature; in idiomatic Python, >> one would typically make a separate, new function for this drastically >> different signature. > > That doesn't convince me. It's not very consistent along the various > types: int("3ab0",16) is rather different than int(3.2) but they're the > same function... Strictly speaking int("3ab0",16) does not create an int from an int, instead it creates an int from a string. Maybe you want to say int(3) -> 3 ? >> However, the `date` type is immutable, so there's no reason at all to >> try and copy a new instance from an existing one anyway, thus a >> single-argument copy-constructor is completely unnecessary, hence why >> there isn't one. > > Isn't the same for all other examples (int, float, str, Decimal...)? > They're all immutable types, and some have several and rather different > constructor signatures: int(ob), float(ob), and str(ob) are type casting (strictly speaking it is not a type casting, but you get the idea); while date() is a constructor for the date object. Strictly speaking int(ob), float(ob), and str(ob) merely calls the special ob.__int__, ob.__float__, and ob.__str__. These special functions are there to convert the current object into int, float, or str wherever defined. It just happens that calling int.__int__, float.__float__, and str.__str__ just returns themselves. For Decimal, (I think) it is as a symmetry to float since Decimal is intended to be used whenever IEEE 764 behavior does not suit you. From lepto.python at gmail.com Tue Jun 2 07:10:18 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 19:10:18 +0800 Subject: do replacement evenly Message-ID: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> I have some strings, and I want to write them into a text files, one string one line but there is a requirement: every line has a max length of a certain number(for example, 10), so I have to replace extra SPACE*3 with SPACE*2, at the same time, I want to make the string looks good, so, for "I am123456line123456three"(to show the SPACE clearly, I type it with a number), the first time, I replace the first SPACE, and get "I am23456line123456three", then I must replace at the second SPACE block, so I get "I am23456line23456three", and so on, if no SPACE*3 is found, I have to aString.replace(SPACE*2, SPACE). I hope I have stated my case clear. Then the question is, is there a nice solution? thanx From lie.1296 at gmail.com Tue Jun 2 07:23:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 11:23:27 GMT Subject: Why date do not construct from date? In-Reply-To: References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Lie Ryan wrote: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert >> escribi?: >> >>> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >>> wrote: >>>>>>> import datetime as dt >>>>>>> d = dt.date(2009, 10, 15) >>>>>>> dt.date(d) >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: function takes exactly 3 arguments (1 given) >>>> Why int form int, str from str, Decumal from Decumal can construct >>>> bat date from date not? >>> Probably because the function signatures would be so different. str(), >>> int(), etc *always* take *exactly one* argument -- the object to >>> convert. In contrast, date() takes several integers corresponding to >>> the year, month, and day. Adding a second signature to it that took >>> exactly one argument (of type `date`) and copied it would be >>> significantly different from its other signature; in idiomatic Python, >>> one would typically make a separate, new function for this drastically >>> different signature. >> That doesn't convince me. It's not very consistent along the various >> types: int("3ab0",16) is rather different than int(3.2) but they're the >> same function... > > Strictly speaking int("3ab0",16) does not create an int from an int, > instead it creates an int from a string. > > Maybe you want to say int(3) -> 3 ? > >>> However, the `date` type is immutable, so there's no reason at all to >>> try and copy a new instance from an existing one anyway, thus a >>> single-argument copy-constructor is completely unnecessary, hence why >>> there isn't one. >> Isn't the same for all other examples (int, float, str, Decimal...)? >> They're all immutable types, and some have several and rather different >> constructor signatures: > > int(ob), float(ob), and str(ob) are type casting (strictly speaking it > is not a type casting, but you get the idea); while date() is a > constructor for the date object. Strictly speaking int(ob), float(ob), > and str(ob) merely calls the special ob.__int__, ob.__float__, and > ob.__str__. These special functions are there to convert the current > object into int, float, or str wherever defined. It just happens that > calling int.__int__, float.__float__, and str.__str__ just returns > themselves. > > For Decimal, (I think) it is as a symmetry to float since Decimal is > intended to be used whenever IEEE 764 behavior does not suit you. In fact, the doc of int and float says "Convert a string or number to an integer, if possible" and "Convert a string or number to a floating point number, if possible" respectively. There is no mention that they are constructors at all... While the doc for str says "Return a nice string representation of the object." the argument still holds since the "nice string representation" for a string is the string itself... Decimal is the rotten apple here since it just mimics float(). But that is why Decimal is in separate module and there is no decimal() built-in. Classes in modules are free to do anything they want to do... including mimicking float() or deciding not to accept its own self as a valid initializer. From iainking at gmail.com Tue Jun 2 07:33:56 2009 From: iainking at gmail.com (Iain King) Date: Tue, 2 Jun 2009 04:33:56 -0700 (PDT) Subject: do replacement evenly References: Message-ID: <27432761-1f86-4996-852d-34324526f303@q14g2000vbn.googlegroups.com> On Jun 2, 12:10?pm, oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get ?"I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? > > thanx Assuming you want to crush all spaces into single space, you can: while " " in s: s = s.replace(" ", " ") readable but not efficient. Better: s = " ".join((x for x in s.split(" ") if x)) Note that this will strip leading and trailing spaces. Or you can use regexps: import re s = re.sub(" {2,}", " ", s) Iain From nadiasvertex at gmail.com Tue Jun 2 08:20:11 2009 From: nadiasvertex at gmail.com (Christopher) Date: Tue, 2 Jun 2009 05:20:11 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: On May 25, 1:35?pm, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, and why. I normally use vi, and just got > into Python, so I am looking for suitable syntax files for it, and > extra utilities. I dabbled with emacs at some point, but couldn't get > through the key bindings for commands. I've never tried emacs with vi > keybindings (I forgot the name of it) but I've been tempted. > > So what do you guys use, and why? Hopefully we can keep this civil. I use Eclipse with PyDev for serious projects. However, when that is too heavy or not available I use: 1) nano over ssh with syntax highlighting for python turned on 2) notepad++ on standalone Windows systems where I need to do quick edits or fixes. I used to use Crimson Editor, but it is not being developed anymore, and notepad++ does everything crimson used to do and more. -={C}=- From john.center at villanova.edu Tue Jun 2 08:25:42 2009 From: john.center at villanova.edu (John Center) Date: Tue, 2 Jun 2009 05:25:42 -0700 (PDT) Subject: Problem building 64-bit python 2.6.2 on Solaris 10 References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> <4a23fe33$0$20453$9b622d9e@news.freenet.de> Message-ID: Hi Martin, I was able to compile ctypes with gcc4sparc without many changes to the CFLAGS, etc. I had another weird error, but upgrading to the latest gcc4sparc fixed it. One thing I'm not clear about is how extensions are built. I noticed that my CFLAGS are not being passed to gcc when building the extensions, so some of them are failing to find the correct includes & libraries. How does one pass these flags? Thanks. -John From mk.fraggod at gmail.com Tue Jun 2 08:42:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 2 Jun 2009 18:42:55 +0600 Subject: do replacement evenly In-Reply-To: References: Message-ID: <20090602184255.1abf7948@coercion> On Tue, 2 Jun 2009 19:10:18 +0800 oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get "I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? Not so nice, but it should be faster than whole lot of string manipulations, especially on longer lines: len_line = 55 line = 'Thats a whole line of some utter nonsense ;)' words = line.split() count_space = len_line - len(''.join(words)) count_span = len(words) - 1 span_min = (count_space // count_span) * ' ' count_span_max = count_space - (count_span * len(span_min)) line = buffer(words[0]) for word in words[1:]: if count_span_max: count_span_max -= 1 line += span_min + ' ' else: line += span_min line += word print '%d chars: %r'%(len(line), line) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lepto.python at gmail.com Tue Jun 2 08:45:57 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 20:45:57 +0800 Subject: do replacement evenly In-Reply-To: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> References: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> Message-ID: <6a4f17690906020545w22508949g765fb0f14cd11e27@mail.gmail.com> here is what I get [code] import re reSplitObj=re.compile('([ \t]*)|([^ \t]*)') def evenReplace(aStr, length): aStr=aStr.rstrip() tmp=reSplitObj.split(aStr) tmp=[i for i in tmp if i not in ['', None]] lenStr=[[0, len(i)][i.strip()!=''] for i in tmp] lenSpc=[[0, len(i)][i.strip()==''] for i in tmp] while sum(lenStr)+sum(lenSpc)>length: if sum(lenSpc): lenSpc[lenSpc.index(max(lenSpc))]-=1 else: break newSpc=[' '*i for i in lenSpc] _=[] for i in range(len(tmp)): item=tmp[i] if item.strip()!='': _.append(item+newSpc[i]) else: _.append(newSpc[i]) return ''.join(_) if __name__=='__main__': a='hello world' b= evenReplace(a, 5) print 'a="%s", len=%0i' %(a, len(a)) print 'b="%s", len=%0i' %(b, len(b)) print a='hello world yeah event even ' b= evenReplace(a, 27) print 'a="%s", len=%0i' %(a, len(a)) print 'b="%s", len=%0i' %(b, len(b)) print [/code] 2009/6/2 oyster : > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get ?"I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? > > thanx > From Scott.Daniels at Acm.Org Tue Jun 2 09:18:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 02 Jun 2009 06:18:53 -0700 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: Michael H. Goldwasser wrote: > On Monday June 1, 2009, Scott David Daniels wrote: > >> Michael H. Goldwasser wrote: >> > .... I'll accept the "small price for flexibility" that you >> > note, if necessary. However, I still desire a cleaner solution. >> >> You seem to think that "deepcopy" is a well-defined concept. .... > > It is clear from my original statement of the question that there is > a need for classes to be able to customize their own semantics for > supporting the deepcopy function. That is why the deepcopy function > looks for a __deepcopy__ method within a class as a hook. > > My concern involves the challenge of providing a valid > implementation for __deepcopy__ at one level of inheritance without > being overly dependent on the internal mechanism used by ancestor > classes in supporting deepcopy. I don't see how your comments > address that question. I only meant to say, if you are looking for something neater, consider whether there is such a thing. Issues with deepcopy may be (and I suspect are) inherently messy. Further, inheritance usually provides (in practice) a "built from" relationship, not an "is a" relationship. "Liskov Substitutability," is a design goal, honored except in corner cases and where inconvenient. --Scott David Daniels Scott.Daniels at Acm.Org From petshmidt at googlemail.com Tue Jun 2 09:32:46 2009 From: petshmidt at googlemail.com (someone) Date: Tue, 2 Jun 2009 06:32:46 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres Message-ID: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> Hi, I'm using pyPgSQL for accessing Postgres and do some update and select queries. and getting WARNING: there is already a transaction in progress if I run runUpdate more than once. So, what happens is following: 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- __existRecord 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- again __existRecord and here I'm getting the warning. Can anyone explain me please what the problem is? I do select, then delete transaction and then select again which doesn't work Regards, Pet class Bla: def __init__: pass def runUpdate(self, number=5): data = {} data = self.__getUpdateItems(number) for row in data: try: if self.__existRecord(row['q']): self.__delQuery(row['q']) except Exception, e: print "Exception", e def __delQuery(self, name): query = """ BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; """ try: self.db.execute(query, name) except Exception, e: print "Exception: ", e return True def __existRecord(self, search): query = """ SELECT address FROM address WHERE LOWER(address) = LOWER (%s); """ try: self.db.execute(query, search) except Exception, e: print "Exception: ", e return self.db.fetchall() def __getUpdateItems(self,number=5): values = [number] query = """ SELECT * FROM failed WHERE id IS NULL ORDER BY up DESC LIMIT %s; """ result = [] try: self.db.execute(query, *values) result = self.db.fetchall() except Exception, e: print "Exception getUpdateItems: ", e return result From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Jun 2 09:44:40 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 2 Jun 2009 13:44:40 +0000 (UTC) Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: Hans M?ller wrote: > Hello experts, > > I'm looking for secure way to pass messages from a python program to a c-library in both ways. > > This scenario is given: > > display client Calculation module in COBOL (yes, big, old but it works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. > Has someone an idea what to use ? > > I have had a short look on xml rpc which can run over a https server but this seems quite fat. > Better ideas ?! Standard TCP connection, forwarded via stunnel or ssh, Should be no brainer if the COBOL side is running on a reasonably modern unix. -- ----------------------------------------------------------- | 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 Scott.Daniels at Acm.Org Tue Jun 2 09:55:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 02 Jun 2009 06:55:48 -0700 Subject: do replacement evenly In-Reply-To: References: Message-ID: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number ... If you are doing this to fill and justify text, I seem to remember a research result stating that filled text (with smooth left and right margins) works well for proportional fonts, but decreases readability for fixed pitch fonts, where ragged right (or ragged left) works better. Sadly, I have no idea where I read that as it is only in the recesses of my somewhat addled brain. --Scott David Daniels Scott.Daniels at Acm.Org From paul at boddie.org.uk Tue Jun 2 09:58:53 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 2 Jun 2009 06:58:53 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> Message-ID: <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> On 2 Jun, 15:32, someone wrote: > Hi, > I'm using pyPgSQL for accessing Postgres and do some update and select > queries. > and getting WARNING: ?there is already a transaction in progress if I > run runUpdate more than once. I think this is because you're using explicit transaction statements amongst the SQL statements you're sending to the database system, whereas pyPgSQL probably starts transactions on your behalf if you've not enabled autocommit. > So, what happens is following: > > 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > __existRecord > 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery > 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > again __existRecord > and here I'm getting the warning. Here, statement #3 may well start a new transaction - a convenience introduced by pyPgSQL in order to provide DB-API compliance and automatic transactions - and when __delQuery is invoked, PostgreSQL will complain that you are trying to start another transaction. Really, you should use the commit method on the cursor object (self.db, I presume) and the rollback method when you want to start a new transaction without changing anything. Alternatively, you could set autocommit to true on the connection object and be sure to always use transaction statements (BEGIN, COMMIT, ROLLBACK) where appropriate. Paul From rustompmody at gmail.com Tue Jun 2 10:15:36 2009 From: rustompmody at gmail.com (rustom) Date: Tue, 2 Jun 2009 07:15:36 -0700 (PDT) Subject: what I would like python.el to do (and maybe it does) References: Message-ID: <6193e4aa-9bcf-4ef4-a9bb-097f83008f0b@b1g2000vbc.googlegroups.com> > But since i like to do it The Right Way, I would > like to let the python-mode worry about this... > > Sorry if this is just a bunch of obvious thoughts to most of you. > > Regards, > Giovanni I dont see whats the problem. Heres my attempt to show you my emacs windows using python-mode (python.el never worked for me) ## Window 1 file foo.py (python mode) x = 1 y = 2 ## Window 2 python interpreter >>> #### Goto the python file (foo.py) Select the x=1 line C-c | (which is py-execute-region) Goto python interpreter window >>> x 1 >>> y ... NameError: y not defined What more/less/else do you want? Are you using python-mode.el or python.el? From python at bdurham.com Tue Jun 2 10:44:04 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 02 Jun 2009 10:44:04 -0400 Subject: do replacement evenly In-Reply-To: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> References: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> Message-ID: <1243953844.12516.1318388745@webmail.messagingengine.com> Here's how we normalize whitespace in multiline blocks of text. Perhaps you can adapt this routine to your needs? Watch for line wrap. # clean up duplicate whitespace, leading/trailing whitespace, triple CRLF's def fixwhitespace( text ): output = [] lastLine = '' # split text into list of individual lines lines = text.strip().splitlines() for line in lines: # remove leading, trailing, and duplicate whitespace within a line line = ' '.join( line.split( None ) ) # ignore multiple blank lines if not line and not lastLine: pass else: output.append( line ) lastLine = line return '\n'.join( output ) Regards, Malcolm From petshmidt at googlemail.com Tue Jun 2 10:49:02 2009 From: petshmidt at googlemail.com (Tep) Date: Tue, 2 Jun 2009 07:49:02 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> Message-ID: On Jun 2, 3:58?pm, Paul Boddie wrote: > On 2 Jun, 15:32, someone wrote: > > > Hi, > > I'm using pyPgSQL for accessing Postgres and do some update and select > > queries. > > and getting WARNING: ?there is already a transaction in progress if I > > run runUpdate more than once. > > I think this is because you're using explicit transaction statements > amongst the SQL statements you're sending to the database system, > whereas pyPgSQL probably starts transactions on your behalf if you've > not enabled autocommit. > > > So, what happens is following: > > > 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > > __existRecord > > 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery > > 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > > again __existRecord > > and here I'm getting the warning. > > Here, statement #3 may well start a new transaction - a convenience > introduced by pyPgSQL in order to provide DB-API compliance and > automatic transactions - and when __delQuery is invoked, PostgreSQL > will complain that you are trying to start another transaction. Ok, that make sense > > Really, you should use the commit method on the cursor object You mean connection object, do you? I've tried that, but forgotten to remove BEGIN;COMMIT; statements from my queries Now, I do commit on connection object after _each_ query and it seems to work :) > (self.db, I presume) and the rollback method when you want to start a > new transaction without changing anything. Alternatively, you could > set autocommit to true on the connection object and be sure to always > use transaction statements (BEGIN, COMMIT, ROLLBACK) where > appropriate. In that way it works too, which means, everything is clear now Thanks for help! > > Paul From icanbob at gmail.com Tue Jun 2 11:23:49 2009 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 2 Jun 2009 08:23:49 -0700 (PDT) Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: <413087c0-bca7-4f43-98cf-b31221a47962@e24g2000vbe.googlegroups.com> On Jun 2, 5:28 am, Hans M?ller wrote: > Hello experts, > > I'm looking for secure way to pass messages from a python program to a c-library in both ways. > > This scenario is given: > > display client Calculation module in COBOL (yes, big, old but it works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. > Has someone an idea what to use ? > > I have had a short look on xml rpc which can run over a https server but this seems quite fat. > Better ideas ?! > Importand is also that the C-Lib on the cobol side should be coded as simple as possible. > Platforms: Windows, *ix > > Thanks a lot. > > Hans The SIMPL toolkit is quite lightweight (http://www.icanprogram.com/ simpl). It can be used to join a Python program to a C program. However, SIMPL messages are treated as blocks of bytes from the prespective of the toolkit. It should be quite straightforward to graft an encription layer above this to do what you want. If you want some "hello world" level Python-SIMPL examples you can look here: http://www.icanprogram.com/06py/main.html bob From aahz at pythoncraft.com Tue Jun 2 11:27:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 08:27:02 -0700 Subject: hash and __eq__ References: <003e1491$0$9723$c3e8da3@news.astraweb.com> Message-ID: In article <003e1491$0$9723$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sun, 31 May 2009 07:24:09 +0100, Arnaud Delobelle wrote: >> >> AFAIK, 'complexity' means 'worst case complexity' unless otherwise >> stated. > >No, it means "average or typical case" unless otherwise specified. >Consult almost any comp sci text book and you'll see hash tables with >chaining (like Python dicts) described as O(1) rather than O(N), >Quicksort as O(N log N) instead of O(N**2), and similar. If the default >was "worst case unless otherwise specified", then Quicksort would be >called "Slower than Bubblesort Sort". > >(Both are O(N**2), but Quicksort does more work.) > >Here's a quote on-line: > >"You should be clear about which cases big-oh notation describes. By >default it usually refers to the average case, using random data. >However, the characteristics for best, worst, and average cases can be >very different..." > >http://leepoint.net/notes-java/algorithms/big-oh/bigoh.html When talking about big-oh, I prefer to define "worst-case" as "real world likely worst-case" -- for example, feeding an already-sorted list to Quicksort. However, the kind of worst-case that causes a dict to have O(N) behavior I would call "pathological case". I generally try to define big-oh in terms of what I call worst-case, because I think it's important to keep track of where your algorithm is likely to run into problems, but I don't think it's worth the effort in most cases to worry about pathological cases. In the case of dicts, it's important to remember that pathological cases are far more likely to arise from poorly designed hashable user classes than from data problems per se; Python's hashing of built-in types has almost twenty years of tuning. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From paul at boddie.org.uk Tue Jun 2 13:38:09 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 2 Jun 2009 10:38:09 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> Message-ID: <64e2243a-4270-4b4d-a4d8-5c09a1bbbf3c@h23g2000vbc.googlegroups.com> On 2 Jun, 16:49, Tep wrote: > On Jun 2, 3:58?pm, Paul Boddie wrote: > > Really, you should use the commit method on the cursor object > > You mean connection object, do you? Yes, I meant the connection object. :-) > I've tried that, but forgotten to remove BEGIN;COMMIT; statements from > my queries > Now, I do commit on connection object after _each_ query and it seems > to work :) You should probably use rollback in order to close transactions just in case you've issued a statement which changes the database. Think of it as kind of a synchronisation operation. [...] > In that way it works too, which means, everything is clear now Great! Paul From robert.kern at gmail.com Tue Jun 2 13:42:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 12:42:47 -0500 Subject: Creating a Google Code project for GSoC In-Reply-To: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> References: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> Message-ID: On 2009-06-01 18:54, Eric Pruitt wrote: > Hello everyone, > > I am a student working on GSoC 2009 for PSF. My proposal involves making > changes to the subprocess module and subprocess.Popen. I wish to create > a Google Code project to host my changes so that I can receive feedback > from the community. Some of the code I have incorporated falls under an > MIT license. Python's license is not GPL but is GPL compatible. What > license should the Google Code project fall under? MIT, GPL or something > else? You should talk to your mentor and the PSF GSoC coordinator, but generally code intended for inclusion in Python itself needs to be licensed under the Apache License v2.0 or the Academic Free License v2.1: http://www.python.org/psf/contrib/ You will also need to sign a contributor agreement. But talk to your mentor. -- 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 stef.mientki at gmail.com Tue Jun 2 15:24:28 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 21:24:28 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <0234781f$0$8244$c3e8da3@news.astraweb.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A257C6C.4080502@gmail.com> > The same rule applies for your modules. As a general rule, NEVER say: > > execfile('mymodule.py') > > instead do: > > import mymodule > mymodule.some_function() > mymodule.another_function() > > > (There are exceptions, but if you need to ask what they are, you're not > ready to learn them! *wink*) > > > hi Steven, maybe you hit the nail right on his head. But I finally want to release my program, with or without proper imports, but working correctly. And I'll leave the "import details" to some other guru. thanks, Stef From mrstevegross at gmail.com Tue Jun 2 15:40:56 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 2 Jun 2009 12:40:56 -0700 (PDT) Subject: Safe to import __builtin__ ? Message-ID: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Is it generally safe to explicitly import __builtin__ in python? That is, my code reads like this: === foo.py === import __builtin__ ... print __builtin__.type('a') === EOF === It seems like it should be a safe import, but I just want to make sure. Thanks, --Steve From robert.kern at gmail.com Tue Jun 2 15:52:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 14:52:04 -0500 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A257C6C.4080502@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: On 2009-06-02 14:24, Stef Mientki wrote: > >> The same rule applies for your modules. As a general rule, NEVER say: >> >> execfile('mymodule.py') >> >> instead do: >> >> import mymodule >> mymodule.some_function() >> mymodule.another_function() >> >> >> (There are exceptions, but if you need to ask what they are, you're >> not ready to learn them! *wink*) >> >> > hi Steven, > maybe you hit the nail right on his head. > But I finally want to release my program, with or without proper > imports, but working correctly. > And I'll leave the "import details" to some other guru. Getting the "import details" right is how you get it to work correctly. -- 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 Tue Jun 2 16:44:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 21:44:58 +0100 Subject: Safe to import __builtin__ ? In-Reply-To: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <4A258F4A.6040402@mrabarnett.plus.com> mrstevegross wrote: > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: > > === foo.py === > import __builtin__ > ... > print __builtin__.type('a') > === EOF === > > It seems like it should be a safe import, but I just want to make > sure. > Why do you want to import it? See http://docs.python.org/library/__builtin__.html From joseph.h.garvin at gmail.com Tue Jun 2 16:50:24 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Tue, 2 Jun 2009 15:50:24 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) Message-ID: So I was curious whether it's possible to use the ctypes module with C++ and if so how difficult it is. I figure in principal it's possible if ctypes knows about each compiler's name mangling scheme. So I searched for "ctypes c++" on Google. The third link will be "Using ctypes to Wrap C++ Libraries". If you follow the link, it's broken. If you view the cache of the link, it's someone pointing to another blog, retrograde-orbit.blogspot.com, saying they discovered a way to do it easily. If you follow that link, you get taken a page does not exist error. Clearly there's some way to use ctypes with C++ and there's a vast conspiracy preventing it from reaching the masses ;) What's even stranger is that this link, despite being broken, has seemingly been near the top of google's results for these terms for a couple weeks (that's when I last tried), as if there were some underground group of rebels trying to hint the truth to us... ;) More seriously -- how difficult is it to use ctypes instead of saying, boost::python, and why isn't this in a FAQ somewhere? ;) From deets at nospam.web.de Tue Jun 2 17:11:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 02 Jun 2009 23:11:58 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78lit5F1mviblU1@mid.uni-berlin.de> Joseph Garvin schrieb: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) Because it's much more needed than name-mangling. Name mangling is (amongst other things) one thing to prevent C++-inter-compiler-interoperability which results from differing C++ ABIs. I'm not an expert on this, but AFAIK no common ABI exists, especially not amongst VC++ & G++. Which means that to work for C++, ctypes would need to know about the internals of both compilers, potentially in several versions, and possibly without prior notice to changes. Instead of dealing with this truly daunting task, tools such as SIP and SWIG or boost::python deal with this by utilizing the one tool that really knows about the ABI in use - the compiler itself. So while I'd loved to be proven wrong, I fear your curiosity won't be satisfied - or at least not in the positive sense you certainly envisioned. Diez From gagsl-py2 at yahoo.com.ar Tue Jun 2 17:23:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 18:23:03 -0300 Subject: Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: En Tue, 02 Jun 2009 07:34:43 -0300, Lie Ryan escribi?: > Gabriel Genellina wrote: >> En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser >> escribi?: >> >>> I can examine the inherited slots to see which special methods are >>> there, and to implement my own __deepcopy__ accordingly. But to do >>> so well seems to essentially require reimplementing the complicated >>> logic of the copy.deepcopy function. That is, if my new class is >>> the first to be implementing an explicit __deepcopy__ function, I >>> seem to have no easy way to invoke the inherited version of >>> "deepcopy(self)". >> >> Yes, that's a problem. But there is a workaround: since __deepcopy__ is >> searched *in the instance* (unlike many other __special__ methods, that >> are usually searched in the class itself) you can fool the copy logic >> into thinking there is no __deepcopy__ method defined, just by >> (temporarily) setting an instance attribute __deepcopy__ to None. (It's >> a hack, anyway) > > I've never really used pickle before but maybe you could try pickling > then unpickling? It is a hack, but for some objects that does not have > __deepcopy__ it might be sufficient. deepcopy essencially does that, without the intermediate storage. The problem is, how to customize deepcopy(something) in a derived class, if there is no way to call the inherited behavior from its base class. -- Gabriel Genellina From sh00le1 at gmail.com Tue Jun 2 17:39:59 2009 From: sh00le1 at gmail.com (sh00le) Date: Tue, 2 Jun 2009 14:39:59 -0700 (PDT) Subject: Creating Mac OS X app Message-ID: Hi, This is my first post here, hope this is the right group, and sorry for my broken English. So, let's start. I have created small PyQt application Simple Task Timer (http://code.google.com/p/simpletasktimer/). Also I created windows binary distro with py2exe, and Linux packages (.rpm and .deb). I would like to have Mac OS X .app binary distro but I don't have Mac OS, and I can't install Mac OS as guest on Virtual Box. Now, I'm searching for some volunteers with Mac OS who would like to test application on Mac OS, and (if it's possible) to create .app binary for Simple Task Timer. Any help would be appreciated. Tnx for reading. From mrstevegross at gmail.com Tue Jun 2 17:45:17 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 2 Jun 2009 14:45:17 -0700 (PDT) Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <3a22049a-6da3-4650-a90e-d355a026eb87@s16g2000vbp.googlegroups.com> > Why do you want to import it? > > Seehttp://docs.python.org/library/__builtin__.html I'm using a weird python environment that overloads a few builtin functions. In order to run them, I need to explicitly invoke "__builtin__.foo()" to make sure I get the real builtin version, not the overloaded one. --Steve From trhaynes at gmail.com Tue Jun 2 17:56:42 2009 From: trhaynes at gmail.com (trhaynes) Date: Tue, 2 Jun 2009 14:56:42 -0700 (PDT) Subject: py2app and OpenGL, "No module named util" in ctypes References: <4b5d6a4d-975e-4459-af9a-926b19aaa7d4@y10g2000prc.googlegroups.com> Message-ID: On May 28, 6:28?pm, Carl Banks wrote: > On May 28, 11:06?am, trhaynes wrote: > > > > > I'm trying to use py2app to package an OpenGL app, so first I tried to > > build the example here > > >http://svn.pythonmac.org/py2app/py2app/trunk/examples/PyOpenGL/ > > > and I get the error: > > > > ?File "/opt/local/lib/python2.5/site-packages/PyOpenGL-3.0.0c1-py2.5.egg/OpenGL/platform/darwin.py", line 24, in > > > ? ?import ctypes, ctypes.util > > >ImportError: No module named util > > >2009-05-28 13:55:06.819 lesson5[19965:10b] lesson5 Error > > >2009-05-28 13:55:06.821 lesson5[19965:10b] lesson5 Error > > >An unexpected error has occurred during execution of the main script > > > >ImportError: No module named util > > > But when I open up my python interactive interpreter and "import > > ctypes.util", it works fine (using lesson5.app/Contents/MacOS/python, > > too). > > > Thanks for the help. > > What has happened is that py2app didn't bundle ctypes.util with the > app, because py2app failed to detect that it was imported for some > reason. > > A typical workaround is to imported in maually in your main script to > make it explicit to py2app that it should be packaged. > > A word of caution: PyOpenGL uses entry hooks and that can cause a lot > of trouble for application builder utilities like py2exe and py2app. > In fact, I decided to stop using PyOpenGL in my projects in large part > because of that issue (I use my own OpenGL wrapper now). ?It's > possible py2app has learned to deal with entry hooks by now, but these > days I refuse to use packages that require entry hooks so I wouldn't > know. > > Carl Banks Thanks all. I had to add ctypes.util to the list of includes for it to work. From BrianVanderburg2 at aim.com Tue Jun 2 18:02:47 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Tue, 02 Jun 2009 18:02:47 -0400 Subject: Copying objects and multiple inheritance Message-ID: <4A25A187.3050908@aim.com> What is the best way to copy an object that has multiple inheritance with the copy module. Particularly, some of the instances in the hierarchy use the __copy__ method to create a copy (because even for shallow copies they need some information updated a little differently), so how can I make sure all the information is copied as it is supposed to be even for the base classes that have special requirements. Brian Vanderburg II From rtw at freenet.co.uk Tue Jun 2 18:13:59 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 02 Jun 2009 17:13:59 -0500 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) References: Message-ID: '2+ wrote in news:mailman.1017.1243932401.8015.python-list at python.org in comp.lang.python: > would like to take advantage of the wave module > found a good example here: > http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 > > hmm .. i don't get how to write a stereo .. i mean i can set nchannels > .. but how do i actually take control of each ch individually? Interleave the channels, one sample for the left then one sample for the right (or maybe its the other way around). > and what's the range(in float) of the data i can set in The range of a signed 16 bit int, -2**15 to 2**15 - 1. > wav_file.writeframes(struct.pack('h', data))? Example: import wave from StringIO import StringIO out = StringIO() AMPLITUDE = 2 ** 15 w = wave.open( out, "w" ) w.setnchannels( 2 ) w.setsampwidth( 2 ) #BYTES w.setframerate( 22000 ) from array import array import math F = 261.626 F2 = F * (2 ** (5 / 12.)) ang = 0.0 ang2 = 0.0 delta = ( math.pi * 2 * F ) / 22000.0 delta2 = ( math.pi * 2 * F2 ) / 22000.0 for cycle in xrange( 4 ): data = array( 'h' ) for pos in xrange( 22000 ): amp = AMPLITUDE * (pos / 22000.0) amp2 = AMPLITUDE - amp if cycle & 1: amp, amp2 = amp2, amp data.append( int( ( amp * math.sin( ang ) ) ) ) data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) ang += delta ang2 += delta2 w.writeframes( data.tostring() ) w.close() sample = out.getvalue() out.close() #a wx player import wx app = wx.PySimpleApp() class Frame( wx.Dialog ): def __init__( self, *args ): wx.Dialog.__init__( self, *args ) b = wx.Button( self, -1, "Ok" ) b.Bind( wx.EVT_BUTTON, self.button ) def button( self, event ): self.sound = wx.SoundFromData( sample ) self.sound.Play( wx.SOUND_ASYNC ) frame = Frame( None ) frame.Show() app.MainLoop() Rob. -- http://www.victim-prime.dsl.pipex.com/ From nick at craig-wood.com Tue Jun 2 18:29:43 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 02 Jun 2009 17:29:43 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Joseph Garvin schrieb: > > So I was curious whether it's possible to use the ctypes module with > > C++ and if so how difficult it is. I figure in principal it's possible > > if ctypes knows about each compiler's name mangling scheme. So I > > searched for "ctypes c++" on Google. [snip] > > More seriously -- how difficult is it to use ctypes instead of saying, > > boost::python, and why isn't this in a FAQ somewhere? ;) > > Because it's much more needed than name-mangling. Name mangling is > (amongst other things) one thing to prevent > C++-inter-compiler-interoperability which results from differing C++ ABIs. > > I'm not an expert on this, but AFAIK no common ABI exists, especially > not amongst VC++ & G++. Which means that to work for C++, ctypes would > need to know about the internals of both compilers, potentially in > several versions, and possibly without prior notice to changes. Probably depends on how far you want to dig into C++. I'm sure it will work fine for simple function calls, passing classes as anonymous pointers etc. If you want to dig into virtual classes with multiple bases or the STL then you are probably into the territory you describe. That said I've used C++ with ctypes loads of times, but I always wrap the exported stuff in extern "C" { } blocks. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From a.cavallo at mailsnare.com Tue Jun 2 18:58:34 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Tue, 2 Jun 2009 23:58:34 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906022358.35256.a.cavallo@mailsnare.com> Mmmm, not really a conspiracy but it is not that trivial.... In wrapping c++ you might find useful the commands nm with c++filt although they work under linux there is the same pair for every platform (under windows I remember there is objdump): they should only you need to wrap a c++ library. I've been wrapping in the past c++ using boost and it was trivial although I haven't tried enough to break it. swig, in older versions, is really bad: I can't comment on newer versions but I'd have a look to the generated code before using it. sip it looks quite difficult to use, but is well maintained. If you have a moderate control on the library design the ctype is the best approach IMHO. Regards, Antonio On Tuesday 02 June 2009 21:50:24 Joseph Garvin wrote: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) From stef.mientki at gmail.com Tue Jun 2 19:00:15 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Jun 2009 01:00:15 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: <4A25AEFF.5030506@gmail.com> Robert Kern wrote: > On 2009-06-02 14:24, Stef Mientki wrote: >> >>> The same rule applies for your modules. As a general rule, NEVER say: >>> >>> execfile('mymodule.py') >>> >>> instead do: >>> >>> import mymodule >>> mymodule.some_function() >>> mymodule.another_function() >>> >>> >>> (There are exceptions, but if you need to ask what they are, you're >>> not ready to learn them! *wink*) >>> >>> >> hi Steven, >> maybe you hit the nail right on his head. >> But I finally want to release my program, with or without proper >> imports, but working correctly. >> And I'll leave the "import details" to some other guru. > > Getting the "import details" right is how you get it to work correctly. > Sorry, but I realy don't understand the difference between the documents on my desk and a python file in a subpath. cheers, Stef From basti.wiesner at gmx.net Tue Jun 2 19:11:39 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Wed, 03 Jun 2009 01:11:39 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: > Diez B. Roggisch wrote: >> Joseph Garvin schrieb: >> > So I was curious whether it's possible to use the ctypes module with >> > C++ and if so how difficult it is. I figure in principal it's possible >> > if ctypes knows about each compiler's name mangling scheme. So I >> > searched for "ctypes c++" on Google. > [snip] >> > More seriously -- how difficult is it to use ctypes instead of saying, >> > boost::python, and why isn't this in a FAQ somewhere? ;) >> >> Because it's much more needed than name-mangling. Name mangling is >> (amongst other things) one thing to prevent >> C++-inter-compiler-interoperability which results from differing C++ >> ABIs. >> >> I'm not an expert on this, but AFAIK no common ABI exists, especially >> not amongst VC++ & G++. Which means that to work for C++, ctypes would >> need to know about the internals of both compilers, potentially in >> several versions, and possibly without prior notice to changes. > > Probably depends on how far you want to dig into C++. I'm sure it > will work fine for simple function calls, passing classes as anonymous > pointers etc. If you want to dig into virtual classes with multiple > bases or the STL then you are probably into the territory you > describe. Name mangeling starts with namespaces, and namespaces are a thing often seen in well-designed C++-libraries. So even a simple C++-function call could become rather difficult to do using ctypes ... > That said I've used C++ with ctypes loads of times, but I always wrap > the exported stuff in extern "C" { } blocks. No wonder, you have never actually used C++ with C types. An extern "C" clause tells the compiler to generate C functions (more precisely, functions that conform to the C ABI conventions), so effectively you're calling into C, not into C++. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From robert.kern at gmail.com Tue Jun 2 19:19:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 18:19:41 -0500 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A25AEFF.5030506@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> <4A25AEFF.5030506@gmail.com> Message-ID: On 2009-06-02 18:00, Stef Mientki wrote: > Robert Kern wrote: >> On 2009-06-02 14:24, Stef Mientki wrote: >>> >>>> The same rule applies for your modules. As a general rule, NEVER say: >>>> >>>> execfile('mymodule.py') >>>> >>>> instead do: >>>> >>>> import mymodule >>>> mymodule.some_function() >>>> mymodule.another_function() >>>> >>>> >>>> (There are exceptions, but if you need to ask what they are, you're >>>> not ready to learn them! *wink*) >>>> >>>> >>> hi Steven, >>> maybe you hit the nail right on his head. >>> But I finally want to release my program, with or without proper >>> imports, but working correctly. >>> And I'll leave the "import details" to some other guru. >> >> Getting the "import details" right is how you get it to work correctly. >> > Sorry, > but I realy don't understand the difference between the documents on my > desk and a python file in a subpath. I really don't understand what relevance you think that has to writing correct Python programs. Yes, Python files are, indeed, files. But the correct way to write Python programs in multiple Python files is to organize them into modules and packages and use Python's import mechanism to make them reference each other. Please read the tutorial: http://docs.python.org/tutorial/modules.html -- 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 davea at ieee.org Tue Jun 2 19:43:04 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 02 Jun 2009 19:43:04 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <4A25B908.5090807@ieee.org> Joseph Garvin wrote: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) > > There are two possibilities here. You might have an existing DLL, written entirely in C++, with thoroughly mangled exports. Or you might have a body of code, to which you're willing to make modifications for the interface. It's only the second I would attack with ctypes. In fact, the name mangling itself varies between versions of the same compiler, never mind between different brands. You should be able to export a class factory, defined as an extern("c"), and use that to get into the DLL. Once you have that, you can call any virtual functions of the class without any additional exports or name mangling needed. As long as the methods you're using are virtual, and singly inherited, it's just a question of walking the vtable. So you should be able to build wrappers, using ctypes, for each of those methods. Note: I haven't actually done it, as the machine with the C++ compiler installed as been down for longer than I've had Python, and I haven't wanted C++ enough to want to install it on my notebook computer. But this is the approach I'd try. From sam at samuelwan.com Tue Jun 2 19:44:40 2009 From: sam at samuelwan.com (Samuel Wan) Date: Tue, 2 Jun 2009 16:44:40 -0700 Subject: "Exploding" (**myvariable) a dict with unicode keys Message-ID: <1d3db2990906021644j5228355l8fb347ca7f39f1d1@mail.gmail.com> I started using python last week and ran into exceptions thrown when unicode dictionary keys are exploded into function arguments. In my case, decoded json dictionaries did not work as function arguments. There was a thread from Oct 2008 (http://www.gossamer-threads.com/lists/python/python/684379) about the same problem. Here is my workaround: ------------------ start code --------------- def safe_dict(d): """Recursively clone json structure with UTF-8 dictionary keys""" if isinstance(d, dict): return dict([(k.encode('utf-8'), safe_dict(v)) for k,v in d.iteritems()]) elif isinstance(d, list): return [safe_dict(x) for x in d] else: return d #Example foo = { 'a':1, 'b':{'b1':2, 'b2':3}, 'c':[ 4, {'D1':2, 'D2':3}, ] } #generate and re-parse json to simulate dictionary with unicode keys dictionary = json.loads(json.dumps(foo)) # shows unicode keys, like u"a" print dictionary # shows utf8 keys, like "a" converted_dictionary = safe_dict(dictionary) fun(**converted_dictionary) ------------------ end code --------------- I really like python! Hope this contributes to the thread. -Sam On Oct 3, 1:57 pm, Peter Otten <__pete... at web.de> wrote: > "Martin v. L?wis" wrote: > > Devin wrote: > >> So Python can have unicode variable names but you can't > >> "explode" (**myvariable) a dict with unicode keys? WTF? > > > That works fine for me. > > The OP probably means > > >>> def f(a=1): return a > ... > >>> f(**{"a": 42}) > 42 > >>> f(**{u"a": 42}) > > Traceback (most recent call last): > File "", line 1, in > TypeError: f() keywords must be strings > > Peter Yes, that's exactly what I mean. From roy at panix.com Tue Jun 2 19:56:06 2009 From: roy at panix.com (Roy Smith) Date: Tue, 02 Jun 2009 19:56:06 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In article <78lit5F1mviblU1 at mid.uni-berlin.de>, "Diez B. Roggisch" wrote: > > More seriously -- how difficult is it to use ctypes instead of saying, > > boost::python, and why isn't this in a FAQ somewhere? ;) > > Because it's much more needed than name-mangling. Name mangling is > (amongst other things) one thing to prevent > C++-inter-compiler-interoperability which results from differing C++ ABIs. Indeed. Name mangling is the most trivial way in which different C++ compilers do not interoperate. Some other thorny issues include exception handling, template instantiation, physical layout of struct and class elements (i.e. padding/alignment), and how references are returned (i.e. Return Value Optimization). I'm sure I've left out several critical items. It's an ugly world out there. From Eric_Dexter at msn.com Tue Jun 2 21:52:32 2009 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: Tue, 2 Jun 2009 18:52:32 -0700 (PDT) Subject: is anyone using text to speech to read python documentation Message-ID: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> I wrote a small pre-processor for python documentation and I am looking for advice on how to get the most natural sounding reading. I uploaded an example of a reading of lxml documentation as a podcast1 http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. From samwyse at gmail.com Tue Jun 2 22:15:50 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 2 Jun 2009 19:15:50 -0700 (PDT) Subject: Missing codecs in Python 3.0 Message-ID: I have a Python 2.6 program (a code generator, actually) that tries several methods of compressing a string and chooses the most compact. It then writes out something like this: { encoding='bz2_codec', data = '...'} I'm having two problems converting this to Py3. First is the absence of the bz2_codec, among others. It was very convenient for my program to delay selection of the decoding method until run-time and then have an easy way to load the appropriate code. Is this gone forever from the standard libraries? Second, I would write my data out using the 'string_escape' codec. It, too, has been removed; there's a 'unicode_escape' codec which is similar, but I would rather use a 'byte_escape' codec to produce literals of the form b'asdf'. Unfortunately, there isn't one that I can find. I could use the repr function, but that seems less efficient. Does anyone have any ideas? Thanks. From ben+python at benfinney.id.au Tue Jun 2 22:16:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Jun 2009 12:16:54 +1000 Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <87fxeirrhl.fsf@benfinney.id.au> mrstevegross writes: > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: > > === foo.py === > import __builtin__ > ... > print __builtin__.type('a') > === EOF === > > It seems like it should be a safe import, but I just want to make > sure. Yes, it's safe (and this is what the ?__builtin__? module is intended for: ). Be careful, though: there's a separate name, ?__builtins__?, that is *not* meant to be imported. It's also implementation-specific, so shouldn't be relied upon. My advice: don't use ?__builtins__? at all, but be aware that it exists so you spell ?__builtin__? correctly. -- \ ?This world in arms is not spending money alone. It is spending | `\ the sweat of its laborers, the genius of its scientists, the | _o__) hopes of its children.? ?Dwight Eisenhower, 1953-04-16 | Ben Finney From aahz at pythoncraft.com Tue Jun 2 22:23:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 19:23:50 -0700 Subject: how to find the last decorator of a chain References: Message-ID: In article , Gabriel wrote: > >I have something like this: > >@render(format="a") >@render(format="b") >@.... >def view(format, data): > return data > >Each render will do something with 'data' if format match, and nothing >if not. > >But if there is no more renders to eval, the last one is the default, >and must run even if the format doesn't match. My inclination would be to make this explicit with something like this: def make_render(func, format_list): def tmp(format, data): for f in format_list: if MATCH(format, f): render(data) break else: render(data) return tmp def view(format, data): return data view = make_render(view, ['a', 'b']) IOW, just because we have decorators doesn't mean that they're the best solution for all function-wrapping problems. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From clp2 at rebertia.com Tue Jun 2 22:35:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Jun 2009 19:35:23 -0700 Subject: Missing codecs in Python 3.0 In-Reply-To: References: Message-ID: <50697b2c0906021935o417a5907re53abbaecbc72629@mail.gmail.com> On Tue, Jun 2, 2009 at 7:15 PM, samwyse wrote: > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > ?{ encoding='bz2_codec', data = '...'} > > I'm having two problems converting this to Py3. ?First is the absence > of the bz2_codec, among others. ?It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. ?Is this gone forever from > the standard libraries? That appears to be the case. "bz2" is not listed on http://docs.python.org/3.0/library/codecs.html , but it is listed on the counterpart 2.6 doc page. You can always use the `bz2` module instead. Or write your own encoder/decoder for bz2 and register it with the `codecs` module. > Second, I would write my data out using the 'string_escape' codec. > It, too, has been removed; there's a 'unicode_escape' codec which is > similar, but I would rather use a 'byte_escape' codec to produce > literals of the form b'asdf'. ?Unfortunately, there isn't one that I > can find. ?I could use the repr function, but that seems less > efficient. ?Does anyone have any ideas? ?Thanks. Well, if you can guarantee the string contains only ASCII, you can just unicode_escape it, and then prepend a "b". On the other hand, I don't see any reason why repr() would be inefficient as compared to the codec method. Cheers, Chris -- http://blog.rebertia.com From aahz at pythoncraft.com Tue Jun 2 22:51:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 19:51:19 -0700 Subject: Challenge supporting custom deepcopy with inheritance References: Message-ID: In article , Michael H. Goldwasser wrote: > >Assume that class B inherits from class A, and that class A has >legitimately customized its deepcopy semantics (but in a way that is >not known to class B). If we want a deepcopy of B to be defined so >that relevant state inherited from A is copied as would be done for >class A, and with B able to control how to deepcopy the extra state >that it introduces. I cannot immediately find a general way to >properly implement the deepcopy of B. > > [...] > >class A(object): > def __init__(self, aTag): > self.__aTag = aTag > self.__aList = [] IMO, your problem starts right here. Not only are you using customized attributes for each class, you're using class-private identifiers. You would vastly simplify your work if you switch to single-underscore attributes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From pavlovevidence at gmail.com Tue Jun 2 22:59:06 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Jun 2009 19:59:06 -0700 (PDT) Subject: Missing codecs in Python 3.0 References: Message-ID: <471fae80-b732-4db3-8ca8-155130346c25@s21g2000vbb.googlegroups.com> On Jun 2, 7:35?pm, Chris Rebert wrote: > On Tue, Jun 2, 2009 at 7:15 PM, samwyse wrote: > > I have a Python 2.6 program (a code generator, actually) that tries > > several methods of compressing a string and chooses the most compact. > > It then writes out something like this: > > ?{ encoding='bz2_codec', data = '...'} > > > I'm having two problems converting this to Py3. ?First is the absence > > of the bz2_codec, among others. ?It was very convenient for my program > > to delay selection of the decoding method until run-time and then have > > an easy way to load the appropriate code. ?Is this gone forever from > > the standard libraries? > > That appears to be the case. "bz2" is not listed onhttp://docs.python.org/3.0/library/codecs.html, but it is listed on > the counterpart 2.6 doc page. > You can always use the `bz2` module instead. Or write your own > encoder/decoder for bz2 and register it with the `codecs` module. IIRC, they decided the codecs would only be used for bytes<->unicode encodings in Python 3.0 (which was their intended use all along), moving other mappings (like bz2) elsewhere. Not sure where they all went, though. It was convenient, admittedly, but also confusing to throw all the other codecs in with Unicode codecs. Carl Banks From ldo at geek-central.gen.new_zealand Tue Jun 2 23:51:56 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 15:51:56 +1200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In message , Sebastian Wiesner wrote: > > >> That said I've used C++ with ctypes loads of times, but I always wrap >> the exported stuff in extern "C" { } blocks. > > No wonder, you have never actually used C++ with C types. An extern "C" > clause tells the compiler to generate C functions (more precisely, > functions that conform to the C ABI conventions), so effectively you're > calling into C, not into C++. Seems like the only sane way to do it. In all other directions lies madness. From ldo at geek-central.gen.new_zealand Tue Jun 2 23:54:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 15:54:23 +1200 Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: In message <4a24f0cc$0$3278$8e6e7893 at newsreader.ewetel.de>, Hans M?ller wrote: > display client Calculation module in COBOL (yes, big, old but it > works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from > COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. Not sure what you mean by "fail save". But I have used protocols built on this sort of framework in several projects now. From martin at v.loewis.de Wed Jun 3 00:46:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 06:46:07 +0200 Subject: Missing codecs in Python 3.0 In-Reply-To: References: Message-ID: <4A26000F.5060703@v.loewis.de> samwyse wrote: > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > { encoding='bz2_codec', data = '...'} > > I'm having two problems converting this to Py3. First is the absence > of the bz2_codec, among others. It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. Is this gone forever from > the standard libraries? bz2 compression is certainly not gone from the standard library; it is still available from the bz2 module. I recommend that you write it like { decompressor = bz2.decompress, data = '...'} Then you can still defer invocation of the decompressor until you need the data. > Second, I would write my data out using the 'string_escape' codec. > It, too, has been removed; there's a 'unicode_escape' codec which is > similar, but I would rather use a 'byte_escape' codec to produce > literals of the form b'asdf'. Unfortunately, there isn't one that I > can find. I could use the repr function, but that seems less > efficient. Does anyone have any ideas? Why does the repr() function seem less efficient? Did you measure anything to make it seem so? I would recommend to use repr() exactly. Regards, Martin From kay at fiber-space.de Wed Jun 3 00:52:22 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Tue, 2 Jun 2009 21:52:22 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: On 3 Jun., 05:51, Lawrence D'Oliveiro wrote: > In message , Sebastian Wiesner wrote: > > > > > >> That said I've used C++ with ctypes loads of times, but I always wrap > >> the exported stuff in extern "C" { } blocks. > > > No wonder, you have never actually used C++ with C types. An extern "C" > > clause tells the compiler to generate C functions (more precisely, > > functions that conform to the C ABI conventions), so effectively you're > > calling into C, not into C++. > > Seems like the only sane way to do it. In all other directions lies madness. Yes but creating C stubs is also hard in presence of everything that is not basic C++. How would you wrap the STL? I suspect one ends up in creating a variant of SWIG and I wonder if it's not a good idea to just use SWIG then. From thebiggestbangtheory at gmail.com Wed Jun 3 00:54:02 2009 From: thebiggestbangtheory at gmail.com (thebiggestbangtheory at gmail.com) Date: Tue, 2 Jun 2009 21:54:02 -0700 (PDT) Subject: problem with sockets and transferring binary files Message-ID: Dear all, I am a python newbie. I am now progressing to writing a network app in python to learn more about it. I have a client and a server in python. The client sends a msg to the server asking it to tar a binary .dbxml file and then send it over to it. The steps are: from the 1. Client sends msg to server 2. Server tars up binary file and Encrypts it using ezpycrypto 3. Server sends it to client 4. Client receives file and decrypts it and untars it Surprisingly, the sha1 hash of the encrypted data before it is sent from server is different from the encrypted file data received by the client. I post some code below to provide more info about what I am doing. [code] #client after sending initial msg #get server replywhich sends back the .dbxml file myHost = '127.0.0.1' myPort = 20001 s1 = socket(AF_INET, SOCK_STREAM) # create a TCP socket s1.bind((myHost, myPort)) # bind it to the server port s1.listen(1) # allow 1 simultaneous # pending connections connection, address = s1.accept() # connection is a new socket while 1: data = connection.recv(10000000) # receive up to 10000000 bytes if data: info=decryptfile(data) #we have recieved a compressed .tar.gz file #write out info to a file buf = open(currentpath+'received-container.tar.gz', 'w') buf.write(info) buf.close() #testing code: must be removed os.system('sudo sha1sum '+currentpath+'received-xml- container.tar.gz') #uncompress os.system('sudo tar -xvzf '+currentpath+'received-xml- container.tar.gz') [/code] [code] #the server after receiving the msg from client #dump the binary file os.system('sudo cp '+'/'+path+'1.binary '+currentpath +'1.binary') #compress the file os.system('sudo tar -cvzf '+currentpath+'1.bin.tar.gz '+currentpath+'1.binary') #encrypt the file specified in command line cipher=encryptfile(secretkey, currentpath+'1.bin.tar.gz') #send it over to sender send_to_sender(cipher, senderaddress) #testing code: needs to be removed buf = open(currentpath+'cipher', 'w') buf.write(cipher) buf.close() os.system('sudo sha1sum '+currentpath+'cipher') [/code] [code] #function code def send_to_sender(cipher, servername): PORT = 20001 BUFF = 10000000 clientSocket = socket(AF_INET, SOCK_STREAM) HOST = servername ADDR = (HOST, PORT) clientSocket.connect(ADDR) clientSocket.send(cipher) clientSocket.close() [/code] What I see at the client side is 7105b60d3167f2424d9e2806c49cca86c00577ba received-container.tar.gz gzip: stdin: unexpected end of file tar: Unexpected EOF in archive tar: Unexpected EOF in archive tar: Error is not recoverable: exiting now da39a3ee5e6b4b0d3255bfef95601890afd80709 received-container.tar.gz gzip: stdin: unexpected end of file tar: Child returned status 1 tar: Error exit delayed from previous errors It seems two file pieces are received! but why? The buffer size is big enough to accept the whole thing in one go. The binary file is about 460K in size. Any pointers, comments will be greatly appreciated :-). Thanks From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:29:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:29:55 -0300 Subject: problem with sockets and transferring binary files References: Message-ID: En Wed, 03 Jun 2009 01:54:02 -0300, escribi?: > I am a python newbie. I am now progressing to writing a > network app in python to learn more about it. [...] > Surprisingly, the sha1 hash of the encrypted data before it is sent > from server is different from the encrypted file data received by the > client. > data = connection.recv(10000000) # receive up to 10000000 > bytes recv returns *up* *to* 10000000 bytes: maybe only one byte. You'll have to keep recv'ing the pieces until you get an empty string (when client closes the connection), or send the file size first and then the actual data. > buf = open(currentpath+'received-container.tar.gz', 'w') > buf.write(info) > buf.close() If you're on Linux it doesn't matter, but the 'w' above should be 'wb' for a binary file. > def send_to_sender(cipher, servername): > ... > clientSocket.send(cipher) Similar to recv above: send() might not send the whole string at once (try sendall instead). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:32:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:32:03 -0300 Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <4A247871.5090804@gmail.com> <9fdb569a0906020211t2c4c5d3w7df511570ee41640@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 06:11:30 -0300, Vlastimil Brom escribi?: > [...] just in case the main problem would be the > use of __file__ ... > It seems, that the exe files generated from py2exe don't recognise > this variable; > sometimes I used code like > > try: > __file__ > except NameError: # py2exe > __file__ = sys.path[0] I think you meant __file__ = sys.argv[0] > cf. e.g. > http://mail.python.org/pipermail/python-list/2001-May/085384.html That's a rather old post. The "right" way to obtain a resource from a package is using pkgutil.get_data(), and py2exe should support it by now. (I haven't tested, but I think it does). http://docs.python.org/library/pkgutil.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:44:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:44:34 -0300 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 08:07:32 -0300, Lie Ryan escribi?: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert >> escribi?: >>> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >>> wrote: >> >>>>>>> import datetime as dt >>>>>>> d = dt.date(2009, 10, 15) >>>>>>> dt.date(d) >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: function takes exactly 3 arguments (1 given) >> >>>> Why int form int, str from str, Decumal from Decumal can construct >>>> bat date from date not? >>> >>> Probably because the function signatures would be so different. str(), >>> int(), etc *always* take *exactly one* argument -- the object to >>> convert. In contrast, date() takes several integers corresponding to >>> the year, month, and day. Adding a second signature to it that took >>> exactly one argument (of type `date`) and copied it would be >>> significantly different from its other signature; in idiomatic Python, >>> one would typically make a separate, new function for this drastically >>> different signature. >> >> That doesn't convince me. It's not very consistent along the various >> types: int("3ab0",16) is rather different than int(3.2) but they're the >> same function... > > Strictly speaking int("3ab0",16) does not create an int from an int, > instead it creates an int from a string. > Maybe you want to say int(3) -> 3 ? I was replying to the argument "different signature => separate function". >>> However, the `date` type is immutable, so there's no reason at all to >>> try and copy a new instance from an existing one anyway, thus a >>> single-argument copy-constructor is completely unnecessary, hence why >>> there isn't one. >> >> Isn't the same for all other examples (int, float, str, Decimal...)? >> They're all immutable types, and some have several and rather different >> constructor signatures: > > int(ob), float(ob), and str(ob) are type casting (strictly speaking it > is not a type casting, but you get the idea); while date() is a > constructor for the date object. Strictly speaking int(ob), float(ob), > and str(ob) merely calls the special ob.__int__, ob.__float__, and > ob.__str__. Well, not really: py> "10".__int__ Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute '__int__' py> "10".__float__ Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute '__float__' int() and float() do the work themselves when given a string (they look more like "true" constructors than str(), which delegates to __str__ as you already said) En Tue, 02 Jun 2009 08:23:27 -0300, Lie Ryan escribi?: > In fact, the doc of int and float says "Convert a string or number to an > integer, if possible" and "Convert a string or number to a floating > point number, if possible" respectively. There is no mention that they > are constructors at all... I think this comes from the prehistoric ages when int/float/str were functions, not built-in types. En Tue, 02 Jun 2009 04:45:19 -0300, Peter Otten <__peter__ at web.de> escribi?: > For date you'd have to make the type check anyway, e. g. > > if isinstance(x, tuple): > x = date(*x) > else: > x = date(x) # useless will only succeed if x already is a date > > as there would be no other way to create a date from a single value. > > So the date() call in the else branch is completely redundant unless you > change date() to accept multiple types via the same signature: > > for x in "2000-01-01", datetime.now(), (2000, 1, 1): > print date(x) That's a more pragmatic response, in the line "because it isn't very useful". I can accept this other too: "because whoever wrote the datetime module didn't care to provide such constructor". -- Gabriel Genellina From thebiggestbangtheory at gmail.com Wed Jun 3 01:52:40 2009 From: thebiggestbangtheory at gmail.com (thebiggestbangtheory at gmail.com) Date: Tue, 2 Jun 2009 22:52:40 -0700 (PDT) Subject: problem with sockets and transferring binary files References: Message-ID: On Jun 2, 10:29?pm, "Gabriel Genellina" wrote: > En Wed, 03 Jun 2009 01:54:02 -0300, ? > escribi?: > > > ? ? ? ? ? ?I am a python newbie. I am now progressing to writing a > > network app in python to learn more about it. [...] > > Surprisingly, the sha1 hash of the encrypted data before it is sent > > from server is different ?from the encrypted file data received by the > > client. > > ? ? ? ? ? data = connection.recv(10000000) # receive up to 10000000 > > bytes > > recv returns *up* *to* 10000000 bytes: maybe only one byte. > You'll have to keep recv'ing the pieces until you get an empty string ? > (when client closes the connection), or send the file size first and then ? > the actual data. > > > ? ? ? ? ? ? buf = open(currentpath+'received-container.tar.gz', 'w') > > ? ? ? ? ? ? buf.write(info) > > ? ? ? ? ? ? buf.close() > > If you're on Linux it doesn't matter, but the 'w' above should be 'wb' for ? > a binary file. > > > def send_to_sender(cipher, servername): > > ? ? ... > > ? ? clientSocket.send(cipher) > > Similar to recv above: send() might not send the whole string at once (try ? > sendall instead). > > -- > Gabriel Genellina Thanks! :-) very helpful From kochhar.mw at gmail.com Wed Jun 3 02:15:49 2009 From: kochhar.mw at gmail.com (shailesh) Date: Tue, 2 Jun 2009 23:15:49 -0700 (PDT) Subject: Wrapping methods of built-in dict References: <6f21d89b-755d-40b8-a42b-0510e5580f93@g22g2000pra.googlegroups.com> Message-ID: <4fce42a0-894c-485f-b1f3-c83340ff1358@a7g2000yqk.googlegroups.com> On May 21, 10:13?pm, George Sakkis wrote: > On May 21, 5:55?pm, shailesh wrote: > > > There doesn't seem to be a predicate returning method wrappers. Is > > there an alternate way to query an object for attributes that are of > > method wrappers? > > Sure:>>> MethodWrapper = type({}.__init__) > >>> isinstance([].__len__, MethodWrapper) > > True > > But you're better off catching everything by checking with callable() > (or equivalently hasattr(obj, '__call__')). > > > This exercise also makes me question if I'm going about this > > correctly. If I want to add functionality to the methods of a class or > > an object are decorators and the inspect module the pythonic way to go > > about it? I can think of alternative implementations either through > > metaclasses or proxy objects. > > In my experience, it's quite unlikely to really want to decorate > indiscriminately *all* methods of a class/instance, let alone all the > special methods (e.g. __getattribute__ very rarely needs to be > overridden). Do you have an actual use case or are you just playing > around ? The use case I'm exploring is automatic lock acquisition and release. I've been trying to create a decorator which protects objects against concurrent modification by placing all attribute behind a mutex. More fine grained locking will probably perform better, but the convenience and reliability of auto-locking is nice. Suggestions for alternate implementations are most welcome. - Shailesh From pete at shinners.org Wed Jun 3 02:24:24 2009 From: pete at shinners.org (peteshinners) Date: Tue, 2 Jun 2009 23:24:24 -0700 (PDT) Subject: Python reimport Message-ID: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> I've implemented a working reimport that, "does what you want". After a bit of testing with friends, I'm releasing version 1.0 tonight. http://code.google.com/p/reimport/ There's still work to do, but this already does a bit of fancy transmuting to push the reimport changes into the runtime. This is not a fully solveable problem, but this also allows modules to define callbacks that can assist the process. Looking for a wider audience to test with. At minimum, my friends and I are using this as a huge relief to alternative workarounds. At best this release will spur wider adoption and further development. From martin at v.loewis.de Wed Jun 3 02:49:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 08:49:37 +0200 Subject: Problem building 64-bit python 2.6.2 on Solaris 10 In-Reply-To: References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> <4a23fe33$0$20453$9b622d9e@news.freenet.de> Message-ID: <4A261D01.1080001@v.loewis.de> > I was able to compile ctypes with gcc4sparc without many changes to > the CFLAGS, etc. I had another weird error, but upgrading to the > latest gcc4sparc fixed it. One thing I'm not clear about is how > extensions are built. I noticed that my CFLAGS are not being passed > to gcc when building the extensions, so some of them are failing to > find the correct includes & libraries. How does one pass these flags? The most reliable strategy is to edit Modules/Setup, and uncomment the modules where you want to pass flags. These will then not be built through setup.py (but become builtin by default). Regards, Martin From ben+python at benfinney.id.au Wed Jun 3 02:54:32 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Jun 2009 16:54:32 +1000 Subject: Python reimport References: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> Message-ID: <87hbyxremv.fsf@benfinney.id.au> peteshinners writes: > I've implemented a working reimport that, "does what you want". After > a bit of testing with friends, I'm releasing version 1.0 tonight. When making an announcement of a new version of a project, please summarise in the announcement what that project is (i.e. what the program does), in a way that makes clear why it's relevant for the forum where you announce it. -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so (hiccup), but Kevin Costner with an English accent?? ?_Pinky | _o__) and The Brain_ | Ben Finney From martin at v.loewis.de Wed Jun 3 02:55:42 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 08:55:42 +0200 Subject: FILE object in Python3.0 extension modules In-Reply-To: References: Message-ID: <4A261E6E.5010005@v.loewis.de> > The purpose is to dump the contents of a Python extension type to disk > as binary data using C's fwrite() function. This isn't really possible anymore - the Python IO library has stopped using stdio. There are a couple of alternatives: 1. don't use fwrite(3) to write the binary data, but instead use PyObject_CallMethod to call .write on the file object. 2. don't use fwrite(3), but write(2). To do so, fetch the file descriptor from the Python file object, and use that. Make sure you flush the stream before writing to it, or else you may get the data in the wrong order. 3. use fdopen to obtain a FILE*; the comments for 2) apply. In addition, make sure to flush and discard the FILE* before letting Python continue to write to the file. Regards, Martin From gagsl-py2 at yahoo.com.ar Wed Jun 3 02:57:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 03:57:20 -0300 Subject: Copying objects and multiple inheritance References: <4A25A187.3050908@aim.com> Message-ID: En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II escribi?: > What is the best way to copy an object that has multiple inheritance > with the copy module. Particularly, some of the instances in the > hierarchy ("...some of the classes in...", I presume?) > use the __copy__ method to create a copy (because even for shallow > copies they need some information updated a little differently), so how > can I make sure all the information is copied as it is supposed to be > even for the base classes that have special requirements. If you don't control all the clases involved, there is little hope for a method like __copy__ to work at all... All classes must be written with cooperation in mind, using super() the "right" way. See "Python's Super Considered Harmful" [1] and "Things to Know About Python Super" [2][3][4] That said, and since multiple inheritance is the heart of the problem, maybe you can redesign your solution *without* using MI? Perhaps using delegation instead? [1] http://fuhm.net/super-harmful/ [2] http://www.artima.com/weblogs/viewpost.jsp?thread=236275 [3] http://www.artima.com/weblogs/viewpost.jsp?thread=236278 [4] http://www.artima.com/weblogs/viewpost.jsp?thread=237121 -- Gabriel Genellina From zhiyongfore at gmail.com Wed Jun 3 03:08:03 2009 From: zhiyongfore at gmail.com (fuzziy) Date: Wed, 3 Jun 2009 00:08:03 -0700 (PDT) Subject: why does my python's program die after change computer system time? Message-ID: <843f1445-4c15-4c9b-aa83-50ea3321eba3@z19g2000vbz.googlegroups.com> Microsoft windowsXP ???python2.6?????????????????????????????????????? ????????????????????????????after(200, tick)??????????????????????????? ???? import Tkinter import time curtime = '' clock_label = Tkinter.Label() clock_label.pack() def tick(): global curtime #print("1:") newtime = time.strftime('%Y-%m-%d %H:%M:%S') if newtime != curtime: curtime = newtime clock_label.config(text=curtime) clock_label.config(text=newtime) clock_label.after(200, tick) #print(curtime) tick() clock_label.mainloop() From deets at nospam.web.de Wed Jun 3 04:19:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 10:19:59 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78mq1fF1mjiv1U1@mid.uni-berlin.de> A. Cavallo schrieb: > Mmmm, > not really a conspiracy but it is not that trivial.... > > In wrapping c++ you might find useful the commands nm with c++filt > although they work under linux there is the same pair for every platform > (under windows I remember there is objdump): they should only you need to wrap > a c++ library. > > I've been wrapping in the past c++ using boost and it was trivial although I > haven't tried enough to break it. > > swig, in older versions, is really bad: I can't comment on newer versions but > I'd have a look to the generated code before using it. > > sip it looks quite difficult to use, but is well maintained. I don't think it's (more) difficult. It's just stripping down the c++-header-file for the easy cases,providing explicit type-marshalling code for complex arguments, and potentially writing explicit method/function-bodies for certain hard cases. All of this is done pretty much alike in boost. Diez From dksreddy at gmail.com Wed Jun 3 04:25:23 2009 From: dksreddy at gmail.com (Sandy) Date: Wed, 3 Jun 2009 01:25:23 -0700 (PDT) Subject: How to get a window ID in linux using python? Message-ID: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> Hi all, Is there a way to get window ID in linux using python by just using the window name (say 'VPython')? This can be done in (Microsoft) windows (got it from somewhere else, not tested). import win32gui self.VP = win32gui.FindWindow ( None, 'VPython' ) In Linux, we can get window info by executing 'xwininfo' and then selecting the desired window manually. Can this be done automatically in python? Thanks, Sandy From martin at v.loewis.de Wed Jun 3 04:58:51 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 10:58:51 +0200 Subject: How to get a window ID in linux using python? In-Reply-To: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> References: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> Message-ID: <4a263b4b$0$20458$9b622d9e@news.freenet.de> > In Linux, we can get window info by executing 'xwininfo' and then > selecting the desired window manually. Can this be done automatically > in python? You can run "xwininfo -tree -root", and then parse the output. HTH, Martin From ldo at geek-central.gen.new_zealand Wed Jun 3 05:13:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 21:13:01 +1200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In message , Kay Schluehr wrote: > On 3 Jun., 05:51, Lawrence D'Oliveiro central.gen.new_zealand> wrote: > >> In message , Sebastian Wiesner wrote: >> >> > >> >> >> That said I've used C++ with ctypes loads of times, but I always wrap >> >> the exported stuff in extern "C" { } blocks. >> >> > No wonder, you have never actually used C++ with C types. An extern >> > "C" clause tells the compiler to generate C functions (more precisely, >> > functions that conform to the C ABI conventions), so effectively you're >> > calling into C, not into C++. >> >> Seems like the only sane way to do it. In all other directions lies >> madness. > > Yes but creating C stubs is also hard in presence of everything that > is not basic C++. How would you wrap the STL? What does the STL offer that Python doesn't already do more flexibly and more simply? From 42flicks at gmail.com Wed Jun 3 05:21:10 2009 From: 42flicks at gmail.com (Mike) Date: Wed, 3 Jun 2009 21:21:10 +1200 Subject: unittest - what is the best way to reuse test data? Message-ID: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Hello, I'm writing an application that needs to fetch a json file from a webserver. I'm writing the tests and have a question: if I have the following methods: def test_headers(self): headers = libary.get_data(data) check header status def test_get_info info = libary.get_info(libary.get_data(data)) This way I call the url twice, even though I have the data available from the first test. my application would just variables such as: h = libary.get_data(data) i = libary.get_info(h) so only one call. What is the best way to set up tests to resuse the data more? I'm new to using the testing framework so I'm not sure on best practises and such. Is introducing persistance by using sql lite the best way? I should be able to just reuse data within the object. Or is my design wrong? Any tips or suggestions would be appreciated! - Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.cavallo at mailsnare.com Wed Jun 3 06:10:38 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 11:10:38 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031110.38489.a.cavallo@mailsnare.com> > >> > No wonder, you have never actually used C++ with C types. An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively > >> > you're calling into C, not into C++. > >> > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? Couldn't agree more:) The following is the STL equivalent of: print [ x*2 for range(10) in data if (x%2 == 0) ] It will take more than digging into the STL documentation..... #include #include #include #include #include #include using __gnu_cxx::compose1; class Range { public: Range(int start=0) : m_start(start) {} virtual ~Range() {} int operator()() { return m_start++; } private: int m_start; }; class Times { public: Times(int val) : m_val(val) {} int operator()(int x) const { return x*m_val; } private: int m_val; }; int main(int argc, char * argv[]) { std::vector data(10); std::generate(data.begin(), data.end(), Range(0)); std::vector::iterator new_end = std::remove_if(data.begin(), data.end(), compose1(std::bind2nd(std::equal_to(), 0), std::bind2nd(std::modulus(), 2))); data.erase(new_end, data.end()); std::transform(data.begin(), data.end(), data.begin(), Times(2)); std::copy(data.begin(), data.end(), std::ostream_iterator(std::cout, "\n")); return 0; } From anthra.norell at bluewin.ch Wed Jun 3 06:16:13 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 03 Jun 2009 12:16:13 +0200 Subject: OT: Can;'t find a Mozilla user group Message-ID: <4A264D6D.8030002@bluewin.ch> I can't run Firefox and Thunderbird without getting these upgrade ordering windows. I don't touch them, because I have reason to suspect that they are some (Russian) virus that hijacks my traffic. Occasionally one of these window pops up the very moment I hit a key and next a confirmation message appears "reassuring" me that the upgrade will be installed the next time I start. I meant to ask Mozilla about their upgrade policy and facilities but for all the googling I do I can't find a contact address, nor an active user group. Hints will be greatly appreciated. Thanks! Frederic From gagsl-py2 at yahoo.com.ar Wed Jun 3 06:18:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 07:18:54 -0300 Subject: why does my python's program die after change computer system time? References: <843f1445-4c15-4c9b-aa83-50ea3321eba3@z19g2000vbz.googlegroups.com> Message-ID: En Wed, 03 Jun 2009 04:08:03 -0300, fuzziy escribi?: > [why does my python's program die after change computer system time?] > def tick(): > ...show current time... > clock_label.after(200, tick) What do you mean by "die"? Did you set the system time to an earlier value? Suppose now it is 09:15:00.000; your program says after(200, tick), that means that at 09:15:00.200 the tick() function will be called. If you set the time back to 09:00:00 your program has 15 minutes still to wait. It hasn't died, it's just waiting for the right time to arrive. I'm not sure if this can be considered a bug, or not, or who's responsible (tcl? tk? tkinter? python?...) -- Gabriel Genellina From paul at boddie.org.uk Wed Jun 3 06:39:42 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Wed, 3 Jun 2009 03:39:42 -0700 (PDT) Subject: How to get a window ID in linux using python? References: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> <4a263b4b$0$20458$9b622d9e@news.freenet.de> Message-ID: <64c5d275-27fe-4242-883e-14ccb4dfbd07@k8g2000yqn.googlegroups.com> On 3 Jun, 10:58, "Martin v. L?wis" wrote: > > In Linux, we can get window info by executing 'xwininfo' and then > > selecting the desired window manually. Can this be done automatically > > in python? > > You can run "xwininfo -tree -root", and then parse the output. The desktop.windows module provides some support for inspecting windows under X11. Here's the repository for the desktop package: https://hg.boddie.org.uk/desktop Looking at the time since the last release, maybe it's time to make another release with the most recent fixes, especially since I've just spotted something which would probably obstruct the operation of the module when performing the work required in this case. Paul From kay at fiber-space.de Wed Jun 3 08:35:05 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Wed, 3 Jun 2009 05:35:05 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: On 3 Jun., 11:13, Lawrence D'Oliveiro wrote: > In message c0e4-479a-85ed-91c26d3bf... at c36g2000yqn.googlegroups.com>, Kay Schluehr > wrote: > > > > > On 3 Jun., 05:51, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > > >> In message , Sebastian Wiesner wrote: > > >> > > > >> >> That said I've used C++ with ctypes loads of times, but I always wrap > >> >> the exported stuff in extern "C" { } blocks. > > >> > No wonder, you have never actually used C++ with C types. An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively you're > >> > calling into C, not into C++. > > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? I do not quite understand your concern? Wasn't the whole point of Josephs post that he intended to create C++ bindings effectively s.t. ctypes can be used? From roy at panix.com Wed Jun 3 09:05:35 2009 From: roy at panix.com (Roy Smith) Date: Wed, 03 Jun 2009 09:05:35 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: Message-ID: In article , "A. Cavallo" wrote: > The following is the STL equivalent of: > > print [ x*2 for range(10) in data if (x%2 == 0) ] Are you sure about that? I haven't tested the following code, but I believe it is a much more direct match the the behavior of your Python code (at least on Python 2.5.1). #include int main(int argc, char * argv[]) { std::cout << "SyntaxError: can't assign to function call"; std::cout << endl; } From BrianVanderburg2 at aim.com Wed Jun 3 09:20:35 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Wed, 03 Jun 2009 09:20:35 -0400 Subject: Copying objects and multiple inheritance In-Reply-To: References: <4A25A187.3050908@aim.com> Message-ID: <4A2678A3.1080602@aim.com> Gabriel Genellina wrote: > En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II > escribi?: > >> What is the best way to copy an object that has multiple inheritance >> with the copy module. Particularly, some of the instances in the >> hierarchy > > ("...some of the classes in...", I presume?) > >> use the __copy__ method to create a copy (because even for shallow >> copies they need some information updated a little differently), so >> how can I make sure all the information is copied as it is supposed >> to be even for the base classes that have special requirements. > > If you don't control all the clases involved, there is little hope for > a method like __copy__ to work at all... All classes must be written > with cooperation in mind, using super() the "right" way. See "Python's > Super Considered Harmful" [1] and "Things to Know About Python Super" > [2][3][4] > > That said, and since multiple inheritance is the heart of the problem, > maybe you can redesign your solution *without* using MI? Perhaps using > delegation instead? > > [1] http://fuhm.net/super-harmful/ > [2] http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > [3] http://www.artima.com/weblogs/viewpost.jsp?thread=236278 > [4] http://www.artima.com/weblogs/viewpost.jsp?thread=237121 > I do control the classes involved. A problem I was having, but I think I now got solved, is if using super, the copy would not have the same class type. Also, a problem was if using super, but some class in the hierarchy didn't implement __copy__, then it's data would not be copied at all. This was also fixed by copying the entire __dict__ in the base __copy__. This is an idea of what I got, it seems to be working fine: import copy class _empty(object): pass class Base(object): def __init__(self): pass def __copy__(self): // don't use copy = Base() // Also don't call self.__class__() because it may have a custom // __init__ which take additional parameters copy = _empty() copy.__class__ = self.__class__ // In case a class does not have __copy__ (such as B below), make // sure all items are copied copy.__dict__.update(self.__dict__) return copy class A(Base): def __init__(self): super(A, self).__init__() self.x = 13 def __copy__(self): copy = super(A, self).__copy__() copy.x = self.x * 2 return copy class B(Base): def __init__(self): super(B, self).__init__() self.y = 14 #def __copy__(self): # copy = super(B, self).__copy__() # copy.y = self.y / 2 # return copy class C(A, B): def __init__(self): super(C, self).__init__() self.z = 64 def __copy__(self): copy = super(C, self).__copy__() copy.z = self.z * self.z return copy o1 = C() o2 = copy.copy(o1) print type(o1), o1.x, o1.y, o1.z print type(o2), o2.x, o2.y, o2.z From a.cavallo at mailsnare.com Wed Jun 3 10:13:00 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 15:13:00 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031513.00920.a.cavallo@mailsnare.com> On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > In article , > > "A. Cavallo" wrote: > > The following is the STL equivalent of: > > > > print [ x*2 for range(10) in data if (x%2 == 0) ] > > Are you sure about that? I haven't tested the following code, but I > believe it is a much more direct match the the behavior of your Python code > (at least on Python 2.5.1). > > #include > int main(int argc, char * argv[]) > { > std::cout << "SyntaxError: can't assign to function call"; > std::cout << endl; > } Ahahaha you're right! print [ x*2 for range(10) in data if (x%2 == 0) ] and it should work just fine: I've still left 9 minutes to match what I've spent in order to write the C++ version including wandering through the STL docs, compiling, fix the syntax errors, finding the gnu STL hasn't compose1 in the expected header file........ Regards, Antonio btw. From a.cavallo at mailsnare.com Wed Jun 3 10:14:44 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 15:14:44 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031514.44302.a.cavallo@mailsnare.com> On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > #include > int main(int argc, char * argv[]) > { > std::cout << "SyntaxError: can't assign to function call"; > std::cout << endl; > } Ops, I've forgotten .... a.cpp: In function ?int main(int, char**)?: a.cpp:5: error: ?endl? was not declared in this scope Oh C++ joy! Regards, Antonio From Eric_Dexter at msn.com Wed Jun 3 10:32:12 2009 From: Eric_Dexter at msn.com (edexter) Date: Wed, 3 Jun 2009 07:32:12 -0700 (PDT) Subject: is anyone using text to speech to read python documentation References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <31ce59b5-19fe-41dd-a207-ba8ec0fddefb@f16g2000vbf.googlegroups.com> On Jun 2, 7:52?pm, "Eric_Dex... at msn.com" wrote: > ? ? ?I wrote a small pre-processor for python documentation and I am > looking for advice on how to get the most natural sounding reading. ?I > uploaded an example of a reading of lxml documentation as a podcast1 > > http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. I take it identifing html tags and changing the wording would help : ( I will fix that.. From pecora at anvil.nrl.navy.mil Wed Jun 3 11:19:29 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 03 Jun 2009 11:19:29 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Sebastian Wiesner wrote: > > > > > > >> That said I've used C++ with ctypes loads of times, but I always wrap > >> the exported stuff in extern "C" { } blocks. > > > > No wonder, you have never actually used C++ with C types. An extern "C" > > clause tells the compiler to generate C functions (more precisely, > > functions that conform to the C ABI conventions), so effectively you're > > calling into C, not into C++. > > Seems like the only sane way to do it. In all other directions lies madness. Agreed. I've done this several times and it works fine. Once I'm in C I'm really in C++ and can use all my C++ code and libraries. Not a big problem really. But maybe I'm missing something. -- -- Lou Pecora From pete at shinners.org Wed Jun 3 11:27:05 2009 From: pete at shinners.org (peteshinners) Date: Wed, 3 Jun 2009 08:27:05 -0700 (PDT) Subject: Python reimport References: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> <87hbyxremv.fsf@benfinney.id.au> Message-ID: On Jun 2, 11:54?pm, Ben Finney wrote: > When making an announcement of a new version of a project, please > summarise in the announcement what that project is (i.e. what the > program does) This module has a reimport function that works as a replacement for the reload builtin. It does a respectable job of updating the changes into the interpreter runtime. It also includes a function to find all changed python modules on disk. From wjxiaoshen at gmail.com Wed Jun 3 11:29:57 2009 From: wjxiaoshen at gmail.com (Jianli Shen) Date: Wed, 3 Jun 2009 10:29:57 -0500 Subject: float("1,009.67") error Message-ID: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> I want to converter a string 1,009.67 to float, I got: python ValueError: invalid literal for float() how do I handle this. 1,009.67 is generated by some other program. It could be 2,898.88 3,554,545.66 etc. Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From giles.thomas at resolversystems.com Wed Jun 3 11:36:34 2009 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Wed, 3 Jun 2009 08:36:34 -0700 (PDT) Subject: ANN: Resolver One 1.5 released Message-ID: We are proud to announce the release of Resolver One, version 1.5. Resolver One is a Windows-based spreadsheet that integrates Python deeply into its recalculation loop, making the models you build more reliable and more maintainable. For version 1.5, we've added a console; this new command-line window gives you a way to interact with your spreadsheet using Python statements. Here's a screencast showing why this is worth doing: We have a 31-day free trial version, so if you would like to take a look, you can download it from our website: If you want to use Resolver One in an Open Source project, we offer free licenses for that: Best regards, Giles -- Giles Thomas giles.thomas at resolversystems.com +44 (0) 20 7253 6372 Win up to $17,000 for a spreadsheet: 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From clp2 at rebertia.com Wed Jun 3 11:42:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Jun 2009 08:42:26 -0700 Subject: float("1,009.67") error In-Reply-To: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> References: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> Message-ID: <50697b2c0906030842j39e8379exd6bb02a81ed0f8cf@mail.gmail.com> On Wed, Jun 3, 2009 at 8:29 AM, Jianli Shen wrote: > I want to converter a string 1,009.67 to float, I got: > python ValueError: invalid literal for float() > how do I handle this. > > 1,009.67 is generated by some other program. It could be 2,898.88 > 3,554,545.66 etc. Python's literal float syntax does not allow the use of commas as a thousands separator. Eliminate the commas before passing the string to float(). This can be done by calling .replace(',','') on the string and passing the result to float(). You would also be well advised to read the Python tutorial if you haven't already. Cheers, Chris -- http://blog.rebertia.com From ebonak at hotmail.com Wed Jun 3 11:53:35 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 11:53:35 -0400 Subject: easiest way to plot x,y graphically during run-time? Message-ID: Hi all, I am trying to visualize a number of small objects moving over a 2D surface during run-time. I was wondering what would the easiest way to accomplish this using Python? Ideally I am looking for a shallow learning curve and efficient implementation :-) These objects may be graphically represented as dots, or preferably as small arrow heads/pointy triangles moving about as their x,y coordinates change during run-time. Thanks, Esmail From aahz at pythoncraft.com Wed Jun 3 11:58:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 08:58:45 -0700 Subject: How do I change the behavior of the 'python-docs' action in IDLE? References: <166e0bf0-cb84-405c-84fb-d10abcd8d241@p4g2000vba.googlegroups.com> <16b92b10-95cf-49ed-868c-8f66c8160e31@r3g2000vbp.googlegroups.com> Message-ID: In article <16b92b10-95cf-49ed-868c-8f66c8160e31 at r3g2000vbp.googlegroups.com>, samwyse wrote: > >I just installed Python 3.0.1 via the Windows 32-bit installer. >Opening "Python Docs" takes me to http://docs.python.org/dev/3.0/, >which doesn't exist. Renaming python301.chm to python30.chm or >python300.chm doesn't seem to help find that file. HELP! IIRC, there's a bug report on this and it's fixed for 3.1 -- please be patient (you can look at bugs.python.org if you want to check the status). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From gokhansever at gmail.com Wed Jun 3 12:03:41 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 3 Jun 2009 11:03:41 -0500 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: Message-ID: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> It seems like you want to animate your data. You may want to take a look at Matplotlib examples or Mayavi for 3D animations ( http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab_animating.html?highlight=animation ) G?khan On Wed, Jun 3, 2009 at 10:53 AM, Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. > > Thanks, > Esmail > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jun 3 12:05:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 18:05:00 +0200 Subject: easiest way to plot x,y graphically during run-time? References: Message-ID: <78nl48F1n46o4U1@mid.uni-berlin.de> Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. pygame certainly suited, but also Tk with it's canvas-object. Diez From ebonak at hotmail.com Wed Jun 3 12:15:02 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 12:15:02 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> Message-ID: <4A26A186.90900@hotmail.com> G?khan SEVER wrote: > It seems like you want to animate your data. > > You may want to take a look at Matplotlib examples or Mayavi for 3D I've used Matplotlib to plot points that were saved during runtime to a file. I wonder if I could skip that step and directly plot during runtime updating the graph as values changed .. I've only heard about Mayavi, so I'll check it out. Thanks G?khan, Esmail From aljosa.mohorovic at gmail.com Wed Jun 3 12:16:13 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Wed, 3 Jun 2009 09:16:13 -0700 (PDT) Subject: private pypi repository Message-ID: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> i'm looking for a effective way to setup private pypi repository, i've found: - PloneSoftwareCenter - http://code.google.com/p/pypione/ - http://pypi.python.org/pypi/haufe.eggserver what are you using? what would you recommend? Aljosa Mohorovic From ebonak at hotmail.com Wed Jun 3 12:16:57 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 12:16:57 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78nl48F1n46o4U1@mid.uni-berlin.de> References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A26A1F9.1070803@hotmail.com> Hello Diez, Diez B. Roggisch wrote: > > pygame certainly suited, but also Tk with it's canvas-object. I used pygame a long time ago, barely remember it, but I think it was pretty easy to use. Tk seems a bit more complex .. but I really don't know much about it and its interface with Python to make any sort of judgments as to which option would be better. Thanks for the suggestions, I'll take a look, Esmail From gokhansever at gmail.com Wed Jun 3 12:20:06 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 3 Jun 2009 11:20:06 -0500 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78nl48F1n46o4U1@mid.uni-berlin.de> References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> I don't know how easy to use pygame or pyOpenGL for data animation comparing to Mayavi. Mayavi uses VTK as its visualization engine which is an OpenGL based library. I would like to learn more about how alternative tools might be beneficial say for example atmospheric particle simulation or realistic cloud simulation. Esmail, you may ask your question in Matplotlib users group for more detailed input. G?khan On Wed, Jun 3, 2009 at 11:05 AM, Diez B. Roggisch wrote: > Esmail wrote: > > pygame certainly suited, but also Tk with it's canvas-object. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jun 3 12:33:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:33:19 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <200906031110.38489.a.cavallo@mailsnare.com> References: <200906031110.38489.a.cavallo@mailsnare.com> Message-ID: A. Cavallo wrote: > > print [ x*2 for range(10) in data if (x%2 == 0) ] I hope you meant print [ x*2 for x in range(10) if (x%2 == 0) ] From tjreedy at udel.edu Wed Jun 3 12:40:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:40:51 -0400 Subject: unittest - what is the best way to reuse test data? In-Reply-To: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Message-ID: Mike wrote: > Hello, > > I'm writing an application that needs to fetch a json file from a > webserver. I'm writing the tests and have a question: > > if I have the following methods: > > def test_headers(self): > headers = libary.get_data(data) > check header status With no json experience specifically.... Checking I/O is nasty since the test running correctly depends on external resources running correctly and not just your program. I would separate I/O tests from 'process the data' checks and do the latter with canned data. If the canned data built into the test is the same as that on the test server, then testing the fetch is an equality test. > > def test_get_info > info = libary.get_info(libary.get_data(data)) > > This way I call the url twice, even though I have the data available > from the first test. > > my application would just variables such as: > h = libary.get_data(data) > i = libary.get_info(h) > > so only one call. > > What is the best way to set up tests to resuse the data more? I'm new to > using the testing framework so I'm not sure on best practises and such. > > Is introducing persistance by using sql lite the best way? I should be > able to just reuse data within the object. Or is my design wrong? > > Any tips or suggestions would be appreciated! > > - Mike > From tjreedy at udel.edu Wed Jun 3 12:43:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:43:52 -0400 Subject: How do I change the behavior of the 'python-docs' action in IDLE? In-Reply-To: References: <166e0bf0-cb84-405c-84fb-d10abcd8d241@p4g2000vba.googlegroups.com> <16b92b10-95cf-49ed-868c-8f66c8160e31@r3g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > In article <16b92b10-95cf-49ed-868c-8f66c8160e31 at r3g2000vbp.googlegroups.com>, > samwyse wrote: >> I just installed Python 3.0.1 via the Windows 32-bit installer. >> Opening "Python Docs" takes me to http://docs.python.org/dev/3.0/, >> which doesn't exist. Renaming python301.chm to python30.chm or >> python300.chm doesn't seem to help find that file. HELP! > > IIRC, there's a bug report on this and it's fixed for 3.1 -- please be > patient (you can look at bugs.python.org if you want to check the > status). Or switch now to 3.1rc1, which should have fewer bugs than 3.0.1. From deets at nospam.web.de Wed Jun 3 13:11:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 19:11:36 +0200 Subject: private pypi repository References: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> Message-ID: <78np13F1moin0U1@mid.uni-berlin.de> Aljosa Mohorovic wrote: > i'm looking for a effective way to setup private pypi repository, i've > found: > - PloneSoftwareCenter > - http://code.google.com/p/pypione/ > - http://pypi.python.org/pypi/haufe.eggserver > > what are you using? what would you recommend? We use eggbasket [1], in an actually rather heavily patched local incarnation that adds support for version sets. [1] http://www.chrisarndt.de/projects/eggbasket/ Diez From ebonak at hotmail.com Wed Jun 3 13:28:07 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 13:28:07 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> Message-ID: <4A26B2A7.7000606@hotmail.com> G?khan SEVER wrote: > I don't know how easy to use pygame or pyOpenGL for data animation > comparing to Mayavi. > > Mayavi uses VTK as its visualization engine which is an OpenGL based > library. I would like to learn more about how alternative tools might be > beneficial say for example atmospheric particle simulation or realistic > cloud simulation. I've just started to read more about Particle Swarm Optimization and since I plan to implement this in Python, I thought it would be nice to visualize the process too, without spending too much on the nitty gritty details of graphics. > Esmail, you may ask your question in Matplotlib users group for more > detailed input. good idea, thanks, Esmail From bblais at bryant.edu Wed Jun 3 13:32:13 2009 From: bblais at bryant.edu (Brian Blais) Date: Wed, 03 Jun 2009 13:32:13 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <4A26A186.90900@hotmail.com> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> <4A26A186.90900@hotmail.com> Message-ID: <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> On Jun 3, 2009, at 12:15 , Esmail wrote: > G?khan SEVER wrote: >> It seems like you want to animate your data. >> You may want to take a look at Matplotlib examples or Mayavi for 3D > > I've used Matplotlib to plot points that were saved during runtime to > a file. I wonder if I could skip that step and directly plot during > runtime updating the graph as values changed .. here is a sample. again, direct questions to the matplotlib list for possible better ideas. from pylab import * # initial positions x0=rand(5) y0=rand(5) ion() # interactive on for t in linspace(0,10,100): x=x0+0.1*cos(t) y=y0+0.1*sin(t) if t==0: # first time calling h=plot(x,y,'o') else: h[0].set_data(x,y) draw() bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From mabdelkader at gmail.com Wed Jun 3 13:54:39 2009 From: mabdelkader at gmail.com (ma) Date: Wed, 3 Jun 2009 13:54:39 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <4A26B2A7.7000606@hotmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> <4A26B2A7.7000606@hotmail.com> Message-ID: <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> Try out PyChart, it's a very complete and has a great interface. I use it to generate statistics for some of our production machines: http://home.gna.org/pychart/ On Wed, Jun 3, 2009 at 1:28 PM, Esmail wrote: > G?khan SEVER wrote: >> >> I don't know how easy to use pygame or pyOpenGL for data animation >> comparing to Mayavi. >> >> Mayavi uses VTK as its visualization engine which is an OpenGL based >> library. I would like to learn more about how alternative tools might be >> beneficial say for example atmospheric particle simulation or realistic >> cloud simulation. > > I've just started to read more about Particle Swarm Optimization and > since I plan to implement this in Python, I thought it would be nice > to visualize the process too, without spending too much on the nitty > gritty details of graphics. > >> Esmail, you may ask your question in Matplotlib users group for more >> detailed input. > > good idea, thanks, > > Esmail > > -- > http://mail.python.org/mailman/listinfo/python-list > From mensanator at aol.com Wed Jun 3 14:09:45 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 11:09:45 -0700 (PDT) Subject: easiest way to plot x,y graphically during run-time? References: Message-ID: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> On Jun 3, 10:53?am, Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Try Turtle Graphics using goto's. With pen up! :-) > Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. > > Thanks, > Esmail From pavlovevidence at gmail.com Wed Jun 3 14:26:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Jun 2009 11:26:19 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: <914d66d1-3b75-4a10-8948-e10577918b50@f10g2000vbf.googlegroups.com> On Jun 3, 2:13?am, Lawrence D'Oliveiro wrote: > In message c0e4-479a-85ed-91c26d3bf... at c36g2000yqn.googlegroups.com>, Kay Schluehr > wrote: > > > > > > > On 3 Jun., 05:51, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > > >> In message , Sebastian Wiesner wrote: > > >> > > > >> >> That said I've used C++ with ctypes loads of times, but I always wrap > >> >> the exported stuff in extern "C" { } blocks. > > >> > No wonder, you have never actually used C++ with C types. ?An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively you're > >> > calling into C, not into C++. > > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? The opportunity to type several lines of ASCII line noise just to do something really simple like iterate through a vector. Carl Banks From stef.mientki at gmail.com Wed Jun 3 14:28:40 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Jun 2009 20:28:40 +0200 Subject: is anyone using text to speech to read python documentation In-Reply-To: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <4A26C0D8.1000304@gmail.com> Eric_Dexter at msn.com wrote: > I wrote a small pre-processor for python documentation and I am > looking for advice on how to get the most natural sounding reading. I > uploaded an example of a reading of lxml documentation as a podcast1 > > http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. > > Depends what OS you want to use, on Windows it's very easy: import win32com.client s = win32com.client.Dispatch("SAPI.SpVoice") s.Speak('Is this punthoofd ') cheers, Stef From ebonak at hotmail.com Wed Jun 3 14:33:02 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 14:33:02 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> References: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> Message-ID: Mensanator wrote: > On Jun 3, 10:53 am, Esmail wrote: >> Hi all, >> >> I am trying to visualize a number of small objects moving over >> a 2D surface during run-time. I was wondering what would the easiest >> way to accomplish this using Python? > > Try Turtle Graphics using goto's. With pen up! :-) hehe .. yes, I briefly considered this too ... From ebonak at hotmail.com Wed Jun 3 14:36:16 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 14:36:16 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> <4A26B2A7.7000606@hotmail.com> <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> Message-ID: <4A26C2A0.3030602@hotmail.com> ma wrote: > Try out PyChart, it's a very complete and has a great interface. I use > it to generate statistics for some of our production machines: > http://home.gna.org/pychart/ Thanks for the suggestion and link, I'm not familiar with this, but will check it out. If I can get matlibplot to work it would be fine since I've already used it a bit before - so there would be less of a learning curve. Regards, Esmail From kiorky at cryptelium.net Wed Jun 3 14:52:59 2009 From: kiorky at cryptelium.net (kiorky) Date: Wed, 03 Jun 2009 20:52:59 +0200 Subject: private pypi repository In-Reply-To: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> References: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> Message-ID: <4A26C68B.3010805@cryptelium.net> Aljosa Mohorovic a ?crit : > i'm looking for a effective way to setup private pypi repository, i've > found: > - PloneSoftwareCenter > - http://code.google.com/p/pypione/ > - http://pypi.python.org/pypi/haufe.eggserver > > what are you using? what would you recommend? > > Aljosa Mohorovic You have also http://pypi.python.org/pypi/ClueReleaseManager -- -- Cordialement, KiOrKY GPG Key FingerPrint: 0x1A1194B7681112AF From allen.fowler at yahoo.com Wed Jun 3 14:54:52 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Wed, 3 Jun 2009 11:54:52 -0700 (PDT) Subject: Project source code layout? Message-ID: <159391.58127.qm@web45611.mail.sp1.yahoo.com> Hello, I'm new to Python, and am looking for some suggestions as to the source code layout for a new project. The project will be a tg/pylons daemon, a static website, and a collection of other scripts that will interact with the app and DB. Here is what I am thinking so far: root_folder/ - app/ -- Code for pylons/TG web app - web/ -- Public static web files (and wsgi / fastCGI connector files) - db/ -- SQlite DB - scripts/ -- Various custom programs that will also interact with the DB / app. (Some cron, some interactive.) - config/ -- 3-rd party API tokens, DB parameters, etc. However, I am still wondering about a few items: 1) Where to create the virtualpython installation that will be used by both the app and the scripts. 2) Where to put our in-house created python modules so that they can be imported by both the TG app and our own scripts. 3) How to cleanly provide the various config settings to both the web app and scripts. Any suggestions? ideas? fwiw, I am planing on keeping the whole thing in a Mercurial repository. Thank you, Allen :) From benjamin at python.org Wed Jun 3 14:57:29 2009 From: benjamin at python.org (Benjamin Peterson) Date: Wed, 3 Jun 2009 18:57:29 +0000 (UTC) Subject: Safe to import =?utf-8?b?X19idWlsdGluX18=?= ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: mrstevegross gmail.com> writes: > > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: ... > > It seems like it should be a safe import, but I just want to make > sure. Yes, that's fine. I'm not sure why you don't just use type(), though. From gregturn at mindspring.com Wed Jun 3 15:09:32 2009 From: gregturn at mindspring.com (Goldfish) Date: Wed, 3 Jun 2009 12:09:32 -0700 (PDT) Subject: Spring Python 1.0.0-RC2 has been released Message-ID: Spring Python takes the concepts implemented by the Java-based Spring Framework, and applies them to Python. This provides a powerful library of functionality to help you get back to writing the code that makes you money. It includes features like data access, transaction management, remoting, security, a command-line tool, and an IoC container. Today, release 1.0.0 (RC2) has been released. See http://blog.springpython.webfactional.com/2009/06/03/spring-python-100-rc2-is-released/ for more details about this release, including release notes, links, and other information. From benjamin at python.org Wed Jun 3 15:16:41 2009 From: benjamin at python.org (Benjamin Peterson) Date: Wed, 3 Jun 2009 19:16:41 +0000 (UTC) Subject: Missing codecs in Python 3.0 References: Message-ID: samwyse gmail.com> writes: > > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > { encoding='bz2_codec', data = '...'} In 3.x, all codecs which don't directly map between unicode and bytestrings have been removed. > > I'm having two problems converting this to Py3. First is the absence > of the bz2_codec, among others. It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. Is this gone forever from > the standard libraries? No, just use the bz2 module in the stdlib. > > Second, I would write my data out using the 'string_escape' codec. Why does the repr seem less efficient? From ebonak at hotmail.com Wed Jun 3 15:32:24 2009 From: ebonak at hotmail.com (esmail bonakdarian) Date: Wed, 3 Jun 2009 15:32:24 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> <4A26A186.90900@hotmail.com> <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> Message-ID: Hi Brian, Thanks for the code sample, that looks quite promising. I can run it and understand most of it - my knowledge of pylab/matplotlib is still quite rudimentary. I wish there was a good manual/tutorial that could be printed off (or for that matter a book) on this as it seems quite cabable and feature rich. Esmail --- here is a sample. again, direct questions to the matplotlib list for possible better ideas. from pylab import * # initial positions x0=rand(5) y0=rand(5) ion() # interactive on for t in linspace(0,10,100): x=x0+0.1*cos(t) y=y0+0.1*sin(t) if t==0: # first time calling h=plot(x,y,'o') else: h[0].set_data(x,y) draw() bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais _________________________________________________________________ Windows Live? SkyDrive?: Get 25 GB of free online storage. http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009 From aahz at pythoncraft.com Wed Jun 3 15:36:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 12:36:40 -0700 Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Message-ID: In article <7c93031a-235e-4e13-bd37-7c9dbc6e889c at r16g2000vbn.googlegroups.com>, wrote: >Should I open a bug report for this? > >Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > >Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> os.popen('cat','w') >Traceback (most recent call last): > File "", line 1, in > File "/Python-3.1rc1/Lib/os.py", line 641, in popen > return _wrap_close(io.TextIOWrapper(proc.stdin), proc) >IOError: [Errno 29] Illegal seek What happens in 2.6 and 3.0? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From me at nikosapi.org Wed Jun 3 15:44:05 2009 From: me at nikosapi.org (Nick Nobody) Date: Wed, 03 Jun 2009 15:44:05 -0400 Subject: urllib.FancyURLopener.redirect_internal behavior Message-ID: Hello, I've recently been playing around with urllib.FancyURLopener and noticed that under certain conditions it can block after calling open() on a url. It only happens on specific servers and when the "Range" HTTP header is in use. The server doesn't close the connection and redirect_internal gets stuck while trying to do a read (it's gets stuck at the line containing "void = fp.read()"). Here is a simple example that demonstrates this problem: #!/usr/bin/env python import urllib # A url which causes a 302 on the server. url = 'http://chkpt.zdnet.com/chkpt/1pcast.bole/http://podcast' url += '-files.cnet.com/podcast/cnet_buzzoutloud_060209.mp3' d = urllib.FancyURLopener() # This header causes this particular server (most servers behave # normally) to keep the connection open for whatever reason... d.addheader('Range', 'bytes=100-') # The program will block here as we wait for redirect_internal to # do it's "void = fp.read()" but since the server doesn't close the # connection we end up waiting for the connection to timeout. d.open(url) To work around this, I subclass FancyURLopener and define my own version of redirect_internal that has the "void = fp.read()" line commented out. What I'd like to know is what's the point of doing the read() and not using the result? Is this a bug in urllib? Or am I simply doing something wrong? Thanks, nick From Scott.Daniels at Acm.Org Wed Jun 3 16:29:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 03 Jun 2009 13:29:35 -0700 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > ... Tk seems a bit more complex .. but I really don't know much about > it and its interface with Python to make any sort of judgments as > to which option would be better. This should look pretty easy: import Tkinter as tk class Mover(object): def __init__(self, canvas, tag_or_id): self.canvas = canvas self.ident = tag_or_id self.x = self.y = 0 def start(self, event): self.x = event.x self.y = event.y def move(self, event): if event.x != self.x or event.y != self.y: dx = event.x - self.x dy = event.y - self.y self.x = event.x self.y = event.y self.canvas.move(self.ident, dx, dy) def setup(root=None): if root is None: root = tk.Tk() root.geometry('400x400+5+5') # experiment: -- place and size canvas = tk.Canvas(root) canvas.pack(expand=1, fill=tk.BOTH) # ovals are x1, y1, x2, y2 a = canvas.create_oval((50, 100, 70, 140), fill='red') b = canvas.create_oval((100, 200, 140, 290), fill='blue') c = canvas.create_oval((300, 300, 390, 330), fill='green') canvas.itemconfig(a, fill='#55AADD') # using internet colors canvas.move(a, 5, 5) # move a down right 5 pixels mover = [Mover(canvas, ident) for ident in (a, b, c)] canvas.bind("", mover[0].move) canvas.bind("", mover[0].start) canvas.bind("", mover[1].move) canvas.bind("", mover[1].start) canvas.bind("", mover[2].move) canvas.bind("", mover[2].start) return canvas, mover if __name__ == '__main__': c, m = setup() tk.mainloop() If you want to experiment, use something like: python -m idlelib.idle -n or $ python /Lib/idlelib/idle.py -n or C:\> C:\Python25\python C:\Python25\Lib\idlelib\idle.py -n To get an idle window with the -n switch on (so you are using the idle "in-process") to see the effects of each Tkinter operation as you go. You can then run these operations in place, seeing results and effects. --Scott David Daniels Scott.Daniels at Acm.Org From paul.blast.walker at googlemail.com Wed Jun 3 16:38:58 2009 From: paul.blast.walker at googlemail.com (tooshiny) Date: Wed, 3 Jun 2009 13:38:58 -0700 (PDT) Subject: accessing the XML attribute value noNamespaceSchemaLocation thru Python 2.5 Message-ID: I am currently successfully using lxml and ElementTree to validate and to access the XML contained data. I can however not find any functional call to access the schema location ie the attribute value noNamespaceSchemaLocation. A simple function call would be so much nicer than the other route of file reading / string chopping etc Can anybody help Many thanks From goldwamh at slu.edu Wed Jun 3 16:45:07 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Wed, 3 Jun 2009 15:45:07 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: Message-ID: <18982.57555.922256.416888@Michael-Goldwassers-Computer.local> On June 2, 2009, Aahz wrote: > >class A(object): > > def __init__(self, aTag): > > self.__aTag = aTag > > self.__aList = [] > > IMO, your problem starts right here. Not only are you using customized > attributes for each class, you're using class-private identifiers. You > would vastly simplify your work if you switch to single-underscore > attributes. Hi Aahz, I intentionally chose the class-private identifiers in my artificial example to emphasize that I was looking for a solution in which class B did not have to rely on particular knowledge of class A's implementation. That said, switching to single-underscores does not address the issue raised in the original post. Michael From gagsl-py2 at yahoo.com.ar Wed Jun 3 16:50:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 17:50:32 -0300 Subject: Copying objects and multiple inheritance References: <4A25A187.3050908@aim.com> <4A2678A3.1080602@aim.com> Message-ID: En Wed, 03 Jun 2009 10:20:35 -0300, Brian Allen Vanderburg II escribi?: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II >> escribi?: >> >>> What is the best way to copy an object that has multiple inheritance >>> with the copy module. Particularly, some of the instances in the >>> hierarchy >>> use the __copy__ method to create a copy (because even for shallow >>> copies they need some information updated a little differently) >> > I do control the classes involved. A problem I was having, but I think > I now got solved, is if using super, the copy would not have the same > class type. Normally, one would use type(self)(...init arguments...) to create an instance of the same type. But if the __init__ signature may change, use type(self).__new__(type(self)) to bypass __init__ (should not matter in this case). > Also, a problem was if using super, but some class in the hierarchy > didn't implement __copy__, then it's data would not be copied at all. > This was also fixed by copying the entire __dict__ in the base > __copy__. This is an idea of what I got, it seems to be working fine: Looks fine. See also a very recent thread about __deepcopy__ for another generic version. -- Gabriel Genellina From starglider101 at gmail.com Wed Jun 3 16:58:20 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 3 Jun 2009 21:58:20 +0100 Subject: Get the hard disk hardware serial number Message-ID: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Hi there, I need to know how to get the hardware serial number of a hard disk in python. Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Jun 3 17:09:10 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Jun 2009 22:09:10 +0100 Subject: Get the hard disk hardware serial number In-Reply-To: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <4A26E676.6070209@mrabarnett.plus.com> Jorge wrote: > Hi there, > > I need to know how to get the hardware serial number of a hard disk in > python. > > Thank you in advance. > For Windows, see http://www.daniweb.com/forums/thread187326.html From tjreedy at udel.edu Wed Jun 3 17:13:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 17:13:51 -0400 Subject: Get the hard disk hardware serial number In-Reply-To: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: Jorge wrote: > Hi there, > > I need to know how to get the hardware serial number of a hard disk in > python. That will be system specific. One semi-general approacy using CPython would be to ask "How would I do this with C on this specific system" and then use ctypes. From 42flicks at gmail.com Wed Jun 3 17:27:33 2009 From: 42flicks at gmail.com (Mike) Date: Thu, 4 Jun 2009 09:27:33 +1200 Subject: unittest - what is the best way to reuse test data? In-Reply-To: References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Message-ID: <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy wrote: > Mike wrote: > >> Hello, >> >> I'm writing an application that needs to fetch a json file from a >> webserver. I'm writing the tests and have a question: >> >> if I have the following methods: >> >> def test_headers(self): >> headers = libary.get_data(data) >> check header status >> > > With no json experience specifically.... > > Checking I/O is nasty since the test running correctly depends on external > resources running correctly and not just your program. I would separate I/O > tests from 'process the data' checks and do the latter with canned data. If > the canned data built into the test is the same as that on the test server, > then testing the fetch is an equality test. > > Thanks, I think I need to separate the tests. The way JSON works is: Open a url with a request <- this returns a file like object, the JSON libary reads the file like object and returns a list of dictionary objects. So first I want to make sure when I do the request I get a 200 OK response, second I want to make sure the JSON object matches my predefined object for it (to ensure no API changes). I think I'll have an external test, which will do two calls (unless I can use the result of the response check test). And if this test passes I will then run my mock test which tests for functionality (and can be run offline). If the first fails then its an indication that the api may have changed and I need to change my mocks. Is this a good testing method/ approach? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrstevegross at gmail.com Wed Jun 3 17:33:02 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Wed, 3 Jun 2009 14:33:02 -0700 (PDT) Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> <87fxeirrhl.fsf@benfinney.id.au> Message-ID: > Yes, it's safe (and this is what the ?__builtin__? module is intended > for: ). > > Be careful, though: there's a separate name, ?__builtins__?, that is > *not* meant to be imported. It's also implementation-specific, so > shouldn't be relied upon. My advice: don't use ?__builtins__? at all, > but be aware that it exists so you spell ?__builtin__? correctly. > Thanks --Steve From news123 at free.fr Wed Jun 3 17:55:04 2009 From: news123 at free.fr (News123) Date: Wed, 03 Jun 2009 23:55:04 +0200 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: References: Message-ID: <4a26f138$0$6545$426a74cc@news.free.fr> Anthra Norell wrote: > I can't run Firefox and Thunderbird without getting these upgrade > ordering windows. I don't touch them, because I have reason to suspect > that they are some (Russian) virus that hijacks my traffic. Occasionally > one of these window pops up the very moment I hit a key and next a > confirmation message appears "reassuring" me that the upgrade will be > installed the next time I start. I meant to ask Mozilla about their > upgrade policy and facilities but for all the googling I do I can't find > a contact address, nor an active user group. Hints will be greatly > appreciated. Thanks! > > Frederic > I don't know a Mozilla news group, but in Settings Advanced -> Settings -> Updates you can choose if updats will be installed automatically or if you want to be asked. Additionally you could check your SW version in the Help->About Menu and then go to the Firefox / Thunderbird web site and look at which version they are? So you know at least whether there is a pending update From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 18:54:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jun 2009 22:54:30 GMT Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <0236f1a1$0$8244$c3e8da3@news.astraweb.com> On Wed, 03 Jun 2009 18:57:29 +0000, Benjamin Peterson wrote: > mrstevegross gmail.com> writes: > > >> Is it generally safe to explicitly import __builtin__ in python? That >> is, my code reads like this: > ... >> >> It seems like it should be a safe import, but I just want to make sure. > > Yes, that's fine. I'm not sure why you don't just use type(), though. I'm not sure why you think type() is a substitute for __builtin__. Here's a typical use-case for __builtin__: import __builtin__ def map(*args): # shadow a built-in # pre-processing goes here result = __builtin__.map(*args) # post-processing goes here return result How does type() help you? -- Steven From robert.kern at gmail.com Wed Jun 3 19:11:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Jun 2009 18:11:51 -0500 Subject: Safe to import __builtin__ ? In-Reply-To: <0236f1a1$0$8244$c3e8da3@news.astraweb.com> References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> <0236f1a1$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 2009-06-03 17:54, Steven D'Aprano wrote: > On Wed, 03 Jun 2009 18:57:29 +0000, Benjamin Peterson wrote: > >> mrstevegross gmail.com> writes: >> >> >>> Is it generally safe to explicitly import __builtin__ in python? That >>> is, my code reads like this: >> ... >>> It seems like it should be a safe import, but I just want to make sure. >> Yes, that's fine. I'm not sure why you don't just use type(), though. > > I'm not sure why you think type() is a substitute for __builtin__. Here's > a typical use-case for __builtin__: > > > import __builtin__ > def map(*args): # shadow a built-in > # pre-processing goes here > result = __builtin__.map(*args) > # post-processing goes here > return result > > > How does type() help you? It doesn't in that sense. The example that Benjamin elided used __builtin__.type() for no discernible reason (unlike your example which creates a shadow function that overrides the builtin version). Benjamin was asking what the motivation was, since it was not evident. -- 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 Wed Jun 3 19:22:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 19:22:20 -0400 Subject: unittest - what is the best way to reuse test data? In-Reply-To: <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> Message-ID: Mike wrote: > > > On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy > wrote: > > Mike wrote: > > Hello, > > I'm writing an application that needs to fetch a json file from > a webserver. I'm writing the tests and have a question: > > if I have the following methods: > > def test_headers(self): > headers = libary.get_data(data) > check header status > > > With no json experience specifically.... > > Checking I/O is nasty since the test running correctly depends on > external resources running correctly and not just your program. I > would separate I/O tests from 'process the data' checks and do the > latter with canned data. If the canned data built into the test is > the same as that on the test server, then testing the fetch is an > equality test. > > Thanks, I think I need to separate the tests. > > The way JSON works is: Open a url with a request <- this returns a file > like object, the JSON libary reads the file like object and returns a > list of dictionary objects. > > So first I want to make sure when I do the request I get a 200 OK > response, second I want to make sure the JSON object matches my > predefined object for it (to ensure no API changes). > > I think I'll have an external test, which will do two calls (unless I > can use the result of the response check test). And if this test passes > I will then run my mock test which tests for functionality (and can be > run offline). If the first fails then its an indication that the api may > have changed and I need to change my mocks. > > Is this a good testing method/ approach? Let us back up a bit. The purpose of a unit test is to test a unit of functionality that you have written code for -- usually with the assumption, possibly false, that the interpreter and libraries are bug-free with respect to your usage. Without knowing what you have written, and therefore, what you should be testing, I am reluctant to say more than that you seem to be on the right track. But some of what you say above seems to be describing higher level integration testing, in particular, interfacing with a changing environment. One thing I will say: once you have tests passing, you can change either your code or the system-code-data it works with, but should not do both (lest you drive yourself mad). The point of mock objects is to have a stable environment in which to work. So I would try to separate 'testing my code (which I control)' from 'testing for undisclosed changes in external servers (that I do not control)'. Terry Jan Reedy From tjreedy at udel.edu Wed Jun 3 19:31:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 19:31:11 -0400 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: <4a26f138$0$6545$426a74cc@news.free.fr> References: <4a26f138$0$6545$426a74cc@news.free.fr> Message-ID: News123 wrote: > > Anthra Norell wrote: >> I can't run Firefox and Thunderbird without getting these upgrade >> ordering windows. I don't touch them, because I have reason to suspect >> that they are some (Russian) virus that hijacks my traffic. Occasionally >> one of these window pops up the very moment I hit a key and next a >> confirmation message appears "reassuring" me that the upgrade will be >> installed the next time I start. I meant to ask Mozilla about their >> upgrade policy and facilities but for all the googling I do I can't find >> a contact address, nor an active user group. Hints will be greatly >> appreciated. Thanks! >> >> Frederic >> > > I don't know a Mozilla news group, > but in Settings Advanced -> Settings -> Updates > you can choose if updats will be installed automatically or if you want > to be asked. In my copies of Firefox and Thunderbird: Tools - Options - Advanced - Update I have 'ask me' checked because auto updates do not seem to work in non-admin accounts. So at my convenience, I switch to admin, go to Help - Check for Updates, and when it finds it, click install. > Additionally you could check your SW version in the Help->About Menu and > then go to the Firefox / Thunderbird web site and look at which version > they are? > > So you know at least whether there is a pending update From aahz at pythoncraft.com Wed Jun 3 19:45:39 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 16:45:39 -0700 Subject: Challenge supporting custom deepcopy with inheritance References: Message-ID: In article , Michael H. Goldwasser wrote: >On June 2, 2009, Aahz wrote: >>Michael Goldwasser: >>> >>>class A(object): >>> def __init__(self, aTag): >>> self.__aTag = aTag >>> self.__aList = [] >> >> IMO, your problem starts right here. Not only are you using customized >> attributes for each class, you're using class-private identifiers. You >> would vastly simplify your work if you switch to single-underscore >> attributes. > > I intentionally chose the class-private identifiers in my artificial > example to emphasize that I was looking for a solution in which > class B did not have to rely on particular knowledge of class A's > implementation. That said, switching to single-underscores does not > address the issue raised in the original post. Not directly, but it does simplify possible solutions. For example, you could use a straightforward getattr() approach where the class contains an attribute listing all the deep-copyable attributes. You could even use name-munging so that attributes can have an accompanying ATTR_deepcopy() method for custom code so that your main __deepcopy__ method stays the same in subclasses. (Obviously, this trick does in fact still work if you use private attributes and do the name-mangling yourself, but I find that distasteful for production code unless it's absolutely required.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 19:57:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jun 2009 23:57:06 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: <0237004c$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 22:20:16 -0700, Mensanator wrote: >> Are you sure that permutations and combinations are subsets of the >> Cartesian Product? > > Sure looks that way (SQL examples): [snip] > I couldn't do that if they weren't subsets. Permutations and combinations are arrangements of a single set. The Cartesian product, on the other hand, are the arrangements of multiple sets, one item from each set. As a general rule, for arbitrary arguments, the items you get from product() aren't even the same size as the items you get from permutations(): >>> data = (0, 1, 2) >>> set(itertools.product(data)) {(2,), (0,), (1,)} >>> set(itertools.permutations(data)) {(2, 1, 0), (0, 1, 2), (1, 0, 2), (2, 0, 1), (0, 2, 1), (1, 2, 0)} Perhaps you mean that, in the special case of the Cartesian product of a set with itself sufficient times, the permutations and combinations of that set are subsets of the product? I could live with that: >>> S = set(itertools.product(data, data, data)) >>> s = set(itertools.permutations(data)) >>> s.issubset(S) True >>> s = set(itertools.combinations(data, 3)) >>> s.issubset(S) True Oh, there's another type of arrangement missing from the collection... dearrangements. That's the arrangements where every item appears in the "wrong" place, i.e. in a position where it *didn't* start off: e.g. given (1, 2, 3), the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: you have N addressed letters and envelopes, but someone has shuffled the letters before putting them into the envelopes. How many ways are there such that no letter will be delivered to the intended recipient? -- Steven From roy at panix.com Wed Jun 3 20:02:51 2009 From: roy at panix.com (Roy Smith) Date: Wed, 03 Jun 2009 20:02:51 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: Message-ID: In article , "A. Cavallo" wrote: > On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > > #include > > int main(int argc, char * argv[]) > > { > > std::cout << "SyntaxError: can't assign to function call"; > > std::cout << endl; > > } > > Ops, > I've forgotten .... > > a.cpp: In function ???int main(int, char**)???: > a.cpp:5: error: ???endl??? was not declared in this scope > > Oh C++ joy! I suppose I *did* deserve that :-) From 42flicks at gmail.com Wed Jun 3 20:03:39 2009 From: 42flicks at gmail.com (Mike) Date: Thu, 4 Jun 2009 12:03:39 +1200 Subject: unittest - what is the best way to reuse test data? In-Reply-To: References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> Message-ID: <2b54d4370906031703h7d7990c6mfbdde9d9440ebac3@mail.gmail.com> On Thu, Jun 4, 2009 at 11:22 AM, Terry Reedy wrote: > Mike wrote: > > >> >> On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy > tjreedy at udel.edu>> wrote: >> >> Mike wrote: >> >> Hello, >> >> I'm writing an application that needs to fetch a json file from >> a webserver. I'm writing the tests and have a question: >> >> if I have the following methods: >> >> def test_headers(self): >> headers = libary.get_data(data) >> check header status >> >> >> With no json experience specifically.... >> >> Checking I/O is nasty since the test running correctly depends on >> external resources running correctly and not just your program. I >> would separate I/O tests from 'process the data' checks and do the >> latter with canned data. If the canned data built into the test is >> the same as that on the test server, then testing the fetch is an >> equality test. >> >> Thanks, I think I need to separate the tests. >> >> The way JSON works is: Open a url with a request <- this returns a file >> like object, the JSON libary reads the file like object and returns a list >> of dictionary objects. >> >> So first I want to make sure when I do the request I get a 200 OK >> response, second I want to make sure the JSON object matches my predefined >> object for it (to ensure no API changes). >> >> I think I'll have an external test, which will do two calls (unless I can >> use the result of the response check test). And if this test passes I will >> then run my mock test which tests for functionality (and can be run >> offline). If the first fails then its an indication that the api may have >> changed and I need to change my mocks. >> >> Is this a good testing method/ approach? >> > > Let us back up a bit. The purpose of a unit test is to test a unit of > functionality that you have written code for -- usually with the assumption, > possibly false, that the interpreter and libraries are bug-free with respect > to your usage. Without knowing what you have written, and therefore, what > you should be testing, I am reluctant to say more than that you seem to be > on the right track. But some of what you say above seems to be describing > higher level integration testing, in particular, interfacing with a changing > environment. > > One thing I will say: once you have tests passing, you can change either > your code or the system-code-data it works with, but should not do both > (lest you drive yourself mad). The point of mock objects is to have a > stable environment in which to work. So I would try to separate 'testing my > code (which I control)' from 'testing for undisclosed changes in external > servers (that I do not control)'. > > Terry Jan Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks Terry, I appreciate your assistance. I was mixing my application tests with integration tests (testing against a changing system). My new method will be: Run the integration test, this will save a JSON file to my machine. A successful run will pass all tests and leave me with a file on my machine. When running application tests the setup will load the JSON file from the machine and my tests will be based on this. This will give me the separation required. I'm writing a basic twitter interfacing application :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 20:21:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 00:21:32 GMT Subject: Absolute imports in Python 2.4 References: <02346783$0$8244$c3e8da3@news.astraweb.com> Message-ID: <02370606$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 02:37:04 -0300, Gabriel Genellina wrote: > En Mon, 01 Jun 2009 21:40:26 -0300, Steven D'Aprano > escribi?: > >> I have a package which includes a module which shadows a module in the >> standard library. For example: >> >> package >> +-- __init__.py >> +-- ham.py >> +-- spam.py >> +-- sys.py >> >> Inside that package, I want to import the standard library sys. In >> other words, I want an absolute import. [...] What can I do in Python >> 2.4 to get an absolute import? > > sys = __import__("sys", {}) > > The import statement uses the global namespace to determine which > package it is called on; if you pass an empty namespace, it cannot infer > package information. Oh that's very cunning! Nice trick. > Anyway, the best move would be to rename the offending module... I agree. But it's nice to know the work-around if I need it. -- Steven From ebonak at hotmail.com Wed Jun 3 21:03:59 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 21:03:59 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A271D7F.3070802@hotmail.com> Scott David Daniels wrote: > Esmail wrote: >> ... Tk seems a bit more complex .. but I really don't know much about >> it and its interface with Python to make any sort of judgments as >> to which option would be better. > > This should look pretty easy: Thanks Scott for taking the time to share this code with me, it will give me something to study. I'm not sure if I'd say it looks easy (but then again I am not very familiar with Tk :-) Best, Esmail From mensanator at aol.com Wed Jun 3 21:21:37 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 18:21:37 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> On Jun 3, 6:57?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 22:20:16 -0700, Mensanator wrote: > >> Are you sure that permutations and combinations are subsets of the > >> Cartesian Product? > > > Sure looks that way (SQL examples): > [snip] > > I couldn't do that if they weren't subsets. > > Permutations and combinations are arrangements of a single set. The OP *did* say combinations, didn't he? So the thread *was* in the context of a single set, wasn't it? > The > Cartesian product, on the other hand, are the arrangements of multiple > sets, one item from each set. And the Cartesian Product of a set with itself gives you permutations with replacement. > As a general rule, for arbitrary arguments, > the items you get from product() aren't even the same size as the items > you get from permutations(): But I wasn't talking about that case. What I *was* talking about is this quote from the 3.1 What's New page: The itertools.combinations_with_replacement() function is one of four for generating combinatorics including permutations and Cartesian products. Is there some reason I *shouldn't* assume that the "four for generating combinatorics" are not permutations vs combinations & with vs without replacement? Does the fact that product() can do more than operate on a single set change that? I never said it couldn't. > > Perhaps you mean that, in the special case of the Cartesian product of a > set with itself sufficient times, the permutations and combinations of > that set are subsets of the product? I could live with that: That *is*, in fact, what I was refering to. I never intended my comment to be a complete tutorial on all that can be done with itertools. I was replying to pataphor's bitching about the itertools being incomplete, that that issue has been addressed. What did I say wrong? Was *I* the one who was complaing? (I try not to do that anymore.) > > Oh, there's another type of arrangement missing from the collection... > dearrangements. Is that "one of four for generating combinatorics"? Maybe you should be talking to the itertools developers? > That's the arrangements where every item appears in the > "wrong" place, i.e. in a position where it *didn't* start off: e.g. given > (1, 2, 3), the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: > you have N addressed letters and envelopes, but someone has shuffled the > letters before putting them into the envelopes. How many ways are there > such that no letter will be delivered to the intended recipient? Ok, but isn't that not within the scope of what we're discussing? > > -- > Steven From python at rcn.com Wed Jun 3 22:21:36 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 19:21:36 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> Message-ID: <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> > What, no partitions? > > http://en.wikipedia.org/wiki/Partition_of_a_set Seems like you could roll your own (using combinations as a starting point): def pairwise(iterable): a, b = tee(iterable) next(b, None) return izip(a, b) def partition(s): n = len(s) for i in range(n): for div in combinations(range(1,n), i): yield map(s.__getitem__, starmap(slice, pairwise(chain ([0], div, [n])))) pprint(list(partition('abcd'))) [['abcd'], ['a', 'bcd'], ['ab', 'cd'], ['abc', 'd'], ['a', 'b', 'cd'], ['a', 'bc', 'd'], ['ab', 'c', 'd'], ['a', 'b', 'c', 'd']] From python at rcn.com Wed Jun 3 23:27:56 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 20:27:56 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> Message-ID: <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> > > What, no partitions? > > >http://en.wikipedia.org/wiki/Partition_of_a_set Simpler version: def partition(s): n = len(s) parts = range(1, n) for i in range(n): for div in combinations(parts, i): print map(s.__getslice__, chain([0], div), chain(div, [n])) >>> partition('abcd') ['abcd'] ['a', 'bcd'] ['ab', 'cd'] ['abc', 'd'] ['a', 'b', 'cd'] ['a', 'bc', 'd'] ['ab', 'c', 'd'] ['a', 'b', 'c', 'd'] From steven at REMOVE.THIS.cybersource.com.au Wed Jun 3 23:48:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 03:48:11 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: On Wed, 03 Jun 2009 20:27:56 -0700, Raymond Hettinger wrote: >> > What, no partitions? >> >> >http://en.wikipedia.org/wiki/Partition_of_a_set > > Simpler version: > > def partition(s): > n = len(s) > parts = range(1, n) > for i in range(n): > for div in combinations(parts, i): > print map(s.__getslice__, chain([0], div), chain(div, > [n])) Nice one! Raymond, as perhaps *the* principle contributor to itertools, do you feel that the combinatorics-related tools should be in their own module? Or is that dividing the module too fine? Would you consider moving permutations() and friends into a module together with functions for calculating the number of permutations etc? e.g. permutations(iterable[, r]) --> permutations object nPr(n, r) --> int and similar. -- Steven From mnordhoff at mattnordhoff.com Wed Jun 3 23:52:40 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Thu, 04 Jun 2009 03:52:40 +0000 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: <4A264D6D.8030002@bluewin.ch> References: <4A264D6D.8030002@bluewin.ch> Message-ID: <4A274508.608@mattnordhoff.com> Anthra Norell wrote: > I can't run Firefox and Thunderbird without getting these upgrade > ordering windows. I don't touch them, because I have reason to suspect > that they are some (Russian) virus that hijacks my traffic. Occasionally > one of these window pops up the very moment I hit a key and next a > confirmation message appears "reassuring" me that the upgrade will be > installed the next time I start. I meant to ask Mozilla about their > upgrade policy and facilities but for all the googling I do I can't find > a contact address, nor an active user group. Hints will be greatly > appreciated. Thanks! > > Frederic Mozilla software updates automatically by default, so that Joe User won't run some out-of-date, insecure version. Mozilla's newsgroups are available on , or you can subscribe to the mailing list gateways at . -- From steven at REMOVE.THIS.cybersource.com.au Wed Jun 3 23:53:45 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 03:53:45 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> Message-ID: On Wed, 03 Jun 2009 18:21:37 -0700, Mensanator wrote: [mass snippage] > What I *was* talking about is this quote from the 3.1 What's New page: > > > The itertools.combinations_with_replacement() function is one of four > for generating combinatorics including permutations and Cartesian > products. > > > Is there some reason I *shouldn't* assume that the "four for generating > combinatorics" are not permutations vs combinations & with vs without > replacement? Does the fact that product() can do more than operate on a > single set change that? I never said it couldn't. Settle down Mensanator! Don't take it so personally! You're sounding awfully agitated. The quoted doc doesn't imply that there are only four combinatorics functions, only that there are four *in itertools*. Nor does it say that permutations etc are subsets of the Cartesian Product, because *without clarification* that is a fairly dubious thing to say. Remember, these are terms with very precise technical meanings, and if you say to a mathematician "the permutations P of some set S are a subset of the Cartesian Product with no specified arguments", they'll probably react just as I did -- with confusion. Now that I've narrowed down what you actually meant, I'm happy to agree with you, at least informally. >> Perhaps you mean that, in the special case of the Cartesian product of >> a set with itself sufficient times, the permutations and combinations >> of that set are subsets of the product? I could live with that: > > > > That *is*, in fact, what I was refering to. I never intended my comment > to be a complete tutorial on all that can be done with itertools. Dear me. Did I say it was? > I was > replying to pataphor's bitching about the itertools being incomplete, > that that issue has been addressed. What did I say wrong? Was *I* the > one who was complaing? (I try not to do that anymore.) The only thing you did "wrong" was to be less pedantic than me. All I was trying to do was narrow down in exactly what sense you meant that arrangements of a single set are subsets of the product of two or more sets. >> Oh, there's another type of arrangement missing from the collection... >> dearrangements. > > Is that "one of four for generating combinatorics"? Obviously not. If it's *missing* how could it be one of the four? > Maybe you should be talking to the itertools developers? If I had a good use-case for dearrangements, or a fast, reliable implementation, then maybe I would. >> That's the arrangements where every item appears in the "wrong" place, >> i.e. in a position where it *didn't* start off: e.g. given (1, 2, 3), >> the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: you have >> N addressed letters and envelopes, but someone has shuffled the letters >> before putting them into the envelopes. How many ways are there such >> that no letter will be delivered to the intended recipient? > > Ok, but isn't that not within the scope of what we're discussing? In the context of Pataphor complaining about itertools having an incomplete set of combinatorics tools, missing partions() and dearrangements() are certainly within the scope. Whether they are serious lacks is another question. -- Steven From ldo at geek-central.gen.new_zealand Thu Jun 4 00:13:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Jun 2009 16:13:50 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > I'm new to Python, and am looking for some suggestions as to the source > code layout for a new project. Is this the development layout or the deployment layout? The two need not bear any resemblance. From allen.fowler at yahoo.com Thu Jun 4 01:00:19 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Wed, 3 Jun 2009 22:00:19 -0700 (PDT) Subject: Project source code layout? In-Reply-To: References: Message-ID: <127570.41907.qm@web45615.mail.sp1.yahoo.com> > > I'm new to Python, and am looking for some suggestions as to the source > > code layout for a new project. > > Is this the development layout or the deployment layout? The two need not > bear any resemblance. > Looking for suggestions on both. I was hoping to keep the dev layout as close to deployment possible. Thank you, :) From mensanator at aol.com Thu Jun 4 01:00:26 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 22:00:26 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> Message-ID: On Jun 3, 10:53?pm, Steven D'Aprano wrote: > On Wed, 03 Jun 2009 18:21:37 -0700, Mensanator wrote: > > [mass snippage] > Settle down Mensanator! Don't take it so personally! You're sounding > awfully agitated. Don't worry, I'm not. > > Now that I've narrowed down what you actually meant, I'm happy to agree > with you, at least informally. Ok. End of thread. > > If I had a good use-case for dearrangements, or a fast, reliable > implementation, then maybe I would. *I* happen to have a good user-case for "partitions of DEPTH indistinguishable items into WIDTH ordered bins such that DEPTH >= WIDTH and each bin must contain at least 1 item". That comes up in the Collatz Conjecture, specifically, a list of WIDTH integers that sums to DEPTH such that the list cannot be empty nor contain any number less than 1. Horribly important. For example, 7 items into 4 bins would be: import collatz_functions as cf for i in cf.partition_generator(7,4): print i ## [1, 1, 1, 4] ## [1, 1, 2, 3] ## [1, 1, 3, 2] ## [1, 1, 4, 1] ## [1, 2, 1, 3] ## [1, 2, 2, 2] ## [1, 2, 3, 1] ## [1, 3, 1, 2] ## [1, 3, 2, 1] ## [1, 4, 1, 1] ## [2, 1, 1, 3] ## [2, 1, 2, 2] ## [2, 1, 3, 1] ## [2, 2, 1, 2] ## [2, 2, 2, 1] ## [2, 3, 1, 1] ## [3, 1, 1, 2] ## [3, 1, 2, 1] ## [3, 2, 1, 1] ## [4, 1, 1, 1] But, as you can see, I already know how to calculate it and I doubt anyone but me would be interested in such a thing. From willgun at live.cn Thu Jun 4 01:15:39 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 13:15:39 +0800 Subject: import sqlite3 Message-ID: Hi,everyone! When i run the following in IDLE: IDLE 2.6.1 >>> import sqlite3 >>> con =sqlite3.connect (r'g:\db1') >>> everything goes well,but when i save these to a .py file and run it: >>> Traceback (most recent call last): File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in import sqlite3 File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in con=sqlite3.connect(r'g:\db1') AttributeError: 'module' object has no attribute 'connect' Anyone can tell me why? Thanks first! From gagsl-py2 at yahoo.com.ar Thu Jun 4 01:53:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 02:53:40 -0300 Subject: import sqlite3 References: Message-ID: En Thu, 04 Jun 2009 02:15:39 -0300, willgun escribi?: > Traceback (most recent call last): > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in > import sqlite3 > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in > con=sqlite3.connect(r'g:\db1') > AttributeError: 'module' object has no attribute 'connect' > > Anyone can tell me why? Your own script is named sqlite3, right? When you execute "import sqlite3" you end up importing your own script, not the library module... -- Gabriel Genellina From andrewm at object-craft.com.au Thu Jun 4 01:55:36 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 15:55:36 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: <344386A5-EC20-45D1-BA49-9E9988522950@object-craft.com.au> On 04/06/2009, at 3:15 PM, willgun wrote: > > When i run the following in IDLE: > IDLE 2.6.1 >>>> import sqlite3 >>>> con =sqlite3.connect (r'g:\db1') >>>> > everything goes well,but when i save these to a .py file and run it: > >>>> > Traceback (most recent call last): > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in > import sqlite3 > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in > con=sqlite3.connect(r'g:\db1') > AttributeError: 'module' object has no attribute 'connect' > > Anyone can tell me why? What did you call the .py file? sqlite3.py? If so, you've just imported your own module again. 8-) After the import, try "print sqlite3.__file__", which will tell you where the module came from. From willgun at live.cn Thu Jun 4 02:10:37 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 14:10:37 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Gabriel Genellina ??: > En Thu, 04 Jun 2009 02:15:39 -0300, willgun escribi?: > >> Traceback (most recent call last): >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in >> import sqlite3 >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in >> con=sqlite3.connect(r'g:\db1') >> AttributeError: 'module' object has no attribute 'connect' >> >> Anyone can tell me why? > > Your own script is named sqlite3, right? When you execute "import > sqlite3" you end up importing your own script, not the library module... > Thanks,I am quiet surprised to be applied so soon. From willgun at live.cn Thu Jun 4 02:14:18 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 14:14:18 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Andrew McNamara ??: > > On 04/06/2009, at 3:15 PM, willgun wrote: >> >> When i run the following in IDLE: >> IDLE 2.6.1 >>>>> import sqlite3 >>>>> con =sqlite3.connect (r'g:\db1') >>>>> >> everything goes well,but when i save these to a .py file and run it: >> >>>>> >> Traceback (most recent call last): >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in >> import sqlite3 >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in >> con=sqlite3.connect(r'g:\db1') >> AttributeError: 'module' object has no attribute 'connect' >> >> Anyone can tell me why? > > What did you call the .py file? sqlite3.py? If so, you've just imported > your own module again. 8-) > > After the import, try "print sqlite3.__file__", which will tell you > where the module came from. Thank you all the same. I'm a student from China.It's painful for us to read python documentation entirely due to poor english.So I often make these mistakes. From python at rcn.com Thu Jun 4 02:27:50 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 23:27:50 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: > Nice one! It only does partitions of a sequence. I haven't yet looked at a way to do partitions of a set. Any ideas? > Raymond, as perhaps *the* principle contributor to itertools, do you feel > that the combinatorics-related tools should be in their own module? Or is > that dividing the module too fine? I like having them in itertools because they form part of the "iterator algebra" for splitting, filtering, joining, and combining streams of iterators. > Would you consider moving permutations() and friends into a module > together with functions for calculating the number of permutations etc? > > e.g. permutations(iterable[, r]) --> permutations object > ? ? ?nPr(n, r) --> int Looked at this a while back. If the nPr style functions go in, they will probably be in the math module (or a new module for integer functions like gcd and whatnot). The reason for not keeping them together is that the use cases are likely disjoint -- when I go to my calculator for nCr I don't expect a listing -- when I need to loop over permutations, I typically only care about the contents of the permutation, not the total number of them (except for purposes of estimating how long a search will take). People look to the math module for things they find on their calculator and to the itertools module for high-speed looping constructs. Also, there is a issue of naming the functions. For combinations, you you might think to look for ncombs() or somesuch, but binomial_coefficient() is what someone else may be searching for. What would be nice is to turn the itertool combinatorics into classes with a len() method, an ability to index to the n-th iteration, or to find at an arbitrary iteration: >>> c = combinations('monte', 3) >>> len(c) 10 >>> c[2] ('m', 'o', 'e') >>> c.find(('m', 't', 'e')) 5 >>> random.choice(c) ('o', 'n', 'e') If the input iterable contains repeats, the find() method would find the first match. These things are interesting and fun, but they also smell of feeping-creaturism. Raymond From gagsl-py2 at yahoo.com.ar Thu Jun 4 02:31:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 03:31:24 -0300 Subject: how to get rid of pyc files ? References: <26252295-7cd9-4c36-a966-c63b5250be8f@j18g2000yql.googlegroups.com> <6cf0f5dc-e9c6-4cf6-b6f7-d8f3814222da@n21g2000vba.googlegroups.com> Message-ID: [please keep the discussion on the list] > may be python need a parameter to regenerate .pyo/pyc explicit ,not > depending on magic number and modification time. > but i just wander if you simply just clear all .pyc than generate in > one system manually, can than program run without error in another > system? Yes, you can always remove the .pyc files before starting, forcing a recompile. Also, see the compileall module. Provided that both systems use the same Python version, you can precompile .pyc files on one and copy them to the other. Even more, some people deploy only .pyc files. -- Gabriel Genellina From andrewm at object-craft.com.au Thu Jun 4 02:33:23 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 16:33:23 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: <7A248558-5530-4D96-9B89-2333FB7B2AB6@object-craft.com.au> On 04/06/2009, at 4:14 PM, willgun wrote: >> What did you call the .py file? sqlite3.py? If so, you've just >> imported your own module again. 8-) >> After the import, try "print sqlite3.__file__", which will tell you >> where the module came from. > Thank you all the same. > I'm a student from China.It's painful for us to read python > documentation entirely due to poor english.So I often make these > mistakes. Don't worry - even experienced Python coders get caught by this one. Just remember the "print module.__file__" trick for next time something odd happens. When you import a module in python, it is only imported the first time you request it (which is why your import did not become recursive and raise an error). From anthra.norell at bluewin.ch Thu Jun 4 03:13:32 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Thu, 04 Jun 2009 09:13:32 +0200 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: References: <4a26f138$0$6545$426a74cc@news.free.fr> Message-ID: <4A27741C.70007@bluewin.ch> Terry Reedy wrote: > News123 wrote: >> >> Anthra Norell wrote: >>> I can't run Firefox and Thunderbird without getting these upgrade >>> ordering windows. I don't touch them, because I have reason to suspect >>> that they are some (Russian) virus that hijacks my traffic. >>> Occasionally >>> one of these window pops up the very moment I hit a key and next a >>> confirmation message appears "reassuring" me that the upgrade will be >>> installed the next time I start. I meant to ask Mozilla about their >>> upgrade policy and facilities but for all the googling I do I can't >>> find >>> a contact address, nor an active user group. Hints will be greatly >>> appreciated. Thanks! >>> >>> Frederic >>> >> >> I don't know a Mozilla news group, >> but in Settings Advanced -> Settings -> Updates >> you can choose if updats will be installed automatically or if you want >> to be asked. > > In my copies of Firefox and Thunderbird: > Tools - Options - Advanced - Update > > I have 'ask me' checked because auto updates do not seem to work in > non-admin accounts. So at my convenience, I switch to admin, go to > Help - Check for Updates, and when it finds it, click install. > >> Additionally you could check your SW version in the Help->About Menu and >> then go to the Firefox / Thunderbird web site and look at which version >> they are? >> >> So you know at least whether there is a pending update > Thank you all! Great advice! Frederic From mail at microcorp.co.za Thu Jun 4 03:25:35 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 09:25:35 +0200 Subject: Winter Madness - Passing Python objects as Strings Message-ID: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> When the days get colder and the nights longer, then evil things are hatched. A can is like a pickle, in that it is a string, but anything can be canned. Unlike a pickle, a can cannot leave the process, though, unless the object it points to lives in shared memory. Here is the output of a test session: > python -i cantest.py dir(Can) yields: ['__doc__', '__file__', '__name__', 'can', 'uncan'] Testing string object s is: The quick brown fox jumps over the lazy dog id(s) is: 47794404772392 ps = can(s) : 47794404772392 t = uncan(ps): The quick brown fox jumps over the lazy dog t is s gives: True Testing q = Queue.Queue() q is: id(q) is: 47794404845616 pq = can(q) : 47794404845616 r = uncan(pq): r is q gives: True Testing banana class object b = banana() <__main__.banana object at 0x73d190> id(b) is: 7590288 pb = can(c) : 7590288 c = uncan(pb): <__main__.banana object at 0x73d190> c is b gives: True That's it, folks! >>> pcan = can(Can.can) >>> pcan '47794404843816' >>> griz = uncan(pcan) >>> griz is can True >>> z = 'foo' >>> griz(z) '7557840' >>> uncan(_) 'foo' >>> griz >>> # uncanny! >>> Now I have only tested it on my system, which is 64 bit SuSe Linux. I suspect it is fragile. I know it is dangerous - if you uncan a random number, then if you are lucky, you will get a segfault. If you are not lucky, your life will be completely changed. If you have any interest, contact me and I will send you the source. - Hendrik From nick at craig-wood.com Thu Jun 4 04:29:42 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 03:29:42 -0500 Subject: easiest way to plot x,y graphically during run-time? References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > Scott David Daniels wrote: > > Esmail wrote: > >> ... Tk seems a bit more complex .. but I really don't know much about > >> it and its interface with Python to make any sort of judgments as > >> to which option would be better. > > > > This should look pretty easy: > > Thanks Scott for taking the time to share this code with me, it > will give me something to study. I'm not sure if I'd say it looks > easy (but then again I am not very familiar with Tk :-) Here is a demo with pygame... import pygame from pygame.locals import * from random import randrange size = width, height = 640, 480 background_colour = 0x00, 0x00, 0x00 foreground_colour = 0x51, 0xd0, 0x3c def main(): pygame.init() screen = pygame.display.set_mode(size, 0, 32) pygame.display.set_caption("A test of Pygame - press Up and Down") pygame.mouse.set_visible(0) clock = pygame.time.Clock() dots = [ (randrange(width), randrange(height)) for _ in range(100) ] radius = 10 while True: clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: raise SystemExit(0) elif event.type == KEYDOWN: if event.key == K_ESCAPE: raise SystemExit(0) elif event.key == K_UP: radius += 1 elif event.key == K_DOWN: radius -= 1 screen.fill(background_colour) for dot in dots: pygame.draw.circle(screen, foreground_colour, dot, radius, 1) dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in dots ] pygame.display.flip() if __name__ == "__main__": main() -- Nick Craig-Wood -- http://www.craig-wood.com/nick From theller at python.net Thu Jun 4 04:43:57 2009 From: theller at python.net (Thomas Heller) Date: Thu, 04 Jun 2009 10:43:57 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78pfqeF1n4jf3U1@mid.individual.net> Joseph Garvin schrieb: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. There have been some attempts to use ctypes to access C++ objects. We (Roman Yakovenko and myself) made some progress. We were able to handle C++ name mangling, the special C++ calling convention, access virtual, non-virtual, overloaded functions, but finally gave up because the binary layout (function tables, member variables, and so on) of C++ objects is way too complicated and undocumented. Our attempts are documented in posts to the ctypes-users mailing list, most of them have the word 'cpptypes' in the subject line. Thomas From jonas.esp at googlemail.com Thu Jun 4 05:01:52 2009 From: jonas.esp at googlemail.com (Kless) Date: Thu, 4 Jun 2009 02:01:52 -0700 (PDT) Subject: Access from a class attribute Message-ID: Why can not to access from a class attribute to a function of that class? ----------------- class Foo(object): attr = __class__.__name__ attr = self.__class__.__name__ ----------------- From ben+python at benfinney.id.au Thu Jun 4 05:24:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Jun 2009 19:24:19 +1000 Subject: Access from a class attribute References: Message-ID: <87hbywnygs.fsf@benfinney.id.au> Kless writes: > Why can not to access from a class attribute to a function of that > class? > > ----------------- > class Foo(object): > attr = __class__.__name__ > attr = self.__class__.__name__ > ----------------- The ?self? name is not magical. If you want it bound to something, you have to bind it explicitly; it's exactly like any other name. You will have noticed this being done in methods of a class: class Foo(object): attr = 'spam' def frobnicate(self, bar): self.attr = str(bar) The statements in the method are evaluated in the context of a specific call to that method, where the parameters have been passed and bound to the parameter names. -- \ ?I got some new underwear the other day. Well, new to me.? ?Emo | `\ Philips | _o__) | Ben Finney From electriclightheads at gmail.com Thu Jun 4 05:28:35 2009 From: electriclightheads at gmail.com ('2+) Date: Thu, 4 Jun 2009 18:28:35 +0900 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) In-Reply-To: References: Message-ID: <20090604092835.GA3388@buyobuyo.sarigama.net> thanx for the example! somehow on juanty gui comes up but no sound .. anyway i shortened the script this way and could aplay it import wave AMPLITUDE = 2 ** 15 w = wave.open( "out.wav", "w" ) w.setnchannels( 2 ) w.setsampwidth( 2 ) #BYTES w.setframerate( 22000 ) from array import array import math F = 261.626 F2 = F * (2 ** (5 / 12.)) ang = 0.0 ang2 = 0.0 delta = ( math.pi * 2 * F ) / 22000.0 delta2 = ( math.pi * 2 * F2 ) / 22000.0 for cycle in xrange( 4 ): data = array( 'h' ) for pos in xrange( 22000 ): amp = AMPLITUDE * (pos / 22000.0) amp2 = AMPLITUDE - amp if cycle & 1: amp, amp2 = amp2, amp data.append( int( ( amp * math.sin( ang ) ) ) ) data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) ang += delta ang2 += delta2 w.writeframes( data.tostring() ) w.close() On Tue, Jun 02, 2009 at 05:13:59PM -0500, Rob Williscroft wrote: > '2+ wrote in news:mailman.1017.1243932401.8015.python-list at python.org in > comp.lang.python: > > > would like to take advantage of the wave module > > found a good example here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 > > > > hmm .. i don't get how to write a stereo .. i mean i can set nchannels > > .. but how do i actually take control of each ch individually? > > Interleave the channels, one sample for the left then one sample > for the right (or maybe its the other way around). > > > and what's the range(in float) of the data i can set in > > The range of a signed 16 bit int, -2**15 to 2**15 - 1. > > > wav_file.writeframes(struct.pack('h', data))? > > Example: > > import wave > from StringIO import StringIO > > out = StringIO() > > AMPLITUDE = 2 ** 15 > > w = wave.open( out, "w" ) > w.setnchannels( 2 ) > w.setsampwidth( 2 ) #BYTES > w.setframerate( 22000 ) > > from array import array > import math > > F = 261.626 > F2 = F * (2 ** (5 / 12.)) > ang = 0.0 > ang2 = 0.0 > delta = ( math.pi * 2 * F ) / 22000.0 > delta2 = ( math.pi * 2 * F2 ) / 22000.0 > > for cycle in xrange( 4 ): > data = array( 'h' ) > for pos in xrange( 22000 ): > amp = AMPLITUDE * (pos / 22000.0) > amp2 = AMPLITUDE - amp > if cycle & 1: > amp, amp2 = amp2, amp > > data.append( int( ( amp * math.sin( ang ) ) ) ) > data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) > > ang += delta > ang2 += delta2 > > w.writeframes( data.tostring() ) > > w.close() > > sample = out.getvalue() > out.close() > > #a wx player > > import wx > > app = wx.PySimpleApp() > > class Frame( wx.Dialog ): > def __init__( self, *args ): > wx.Dialog.__init__( self, *args ) > b = wx.Button( self, -1, "Ok" ) > b.Bind( wx.EVT_BUTTON, self.button ) > > def button( self, event ): > self.sound = wx.SoundFromData( sample ) > self.sound.Play( wx.SOUND_ASYNC ) > > frame = Frame( None ) > frame.Show() > > app.MainLoop() > > Rob. > -- > http://www.victim-prime.dsl.pipex.com/ -- '2+ http://sarigama.namaste.jp/ is podcasting his microtuned music http://www002.upp.so-net.ne.jp/buyobuyo/micro/rss.xml From nick at craig-wood.com Thu Jun 4 05:29:42 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 04:29:42 -0500 Subject: Get the hard disk hardware serial number References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: MRAB wrote: > Jorge wrote: > > I need to know how to get the hardware serial number of a hard disk in > > python. > > > For Windows, see http://www.daniweb.com/forums/thread187326.html For linux I'd run this and parse the results. # smartctl -i /dev/sda smartctl version 5.38 [i686-pc-linux-gnu] Copyright (C) 2002-8 Bruce Allen Home page is http://smartmontools.sourceforge.net/ === START OF INFORMATION SECTION === Model Family: Seagate Momentus 7200.2 Device Model: ST9200420AS Serial Number: 7QW138AK Firmware Version: 3.AAA User Capacity: 200,049,647,616 bytes Device is: In smartctl database [for details use: -P show] ATA Version is: 7 ATA Standard is: Exact ATA specification draft version not indicated Local Time is: Thu Jun 4 09:30:23 2009 BST SMART support is: Available - device has SMART capability. SMART support is: Enabled According to the man page smartctl also runs under windows/mac/solaris etc -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ldo at geek-central.gen.new_zealand Thu Jun 4 05:33:13 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Jun 2009 21:33:13 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > I was hoping to keep the dev layout as close to deployment possible. Completely different purposes. For example, the actual production database and config files form no part of your development project, do they? And conversely, utility scripts that might be used, for example, to set up a database, should not be part of the production installation. Here's one layout I used in a production system for an online shop: /home/shop/bin -- binaries (CGI and daemon) /home/shop/lib -- common libraries for binaries /home/shop/config -- configuration files, incl format templates /home/shop/state -- socket for interprocess communication, log files From bruno.42.desthuilliers at websiteburo.invalid Thu Jun 4 06:00:59 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Jun 2009 12:00:59 +0200 Subject: Access from a class attribute In-Reply-To: References: Message-ID: <4a279b4f$0$20805$426a34cc@news.free.fr> Kless a ?crit : > Why can not to access from a class attribute to a function of that > class? > > ----------------- > class Foo(object): > attr = __class__.__name__ > attr = self.__class__.__name__ > ----------------- "class" is an executable statement that instanciate a new class object and bind it to the class name in the current namespace. The class object doesn't yet exists when the body of the class statement is eval'd, so you can't access it, obviously - nor any of it's instances FWIW. Also, there's nothing magical wrt/ 'self' - it's just a naming convention for the "current instance" argument of functions that are intented to be used as methods (Python's 'methods' being just thin wrappers around the function, the class and the instance). If you want to mess with the class attributes, you can either do so after the class is created (that is, after the end of the class statement's body), or use a custom metaclass. From wiggly at wiggly.org Thu Jun 4 07:23:49 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 12:23:49 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <4A27AEC5.8010809@wiggly.org> Hendrik van Rooyen wrote: > > If you have any interest, contact me and I will > send you the source. Maybe you could tell people what the point is... n From noone at example.com Thu Jun 4 07:30:35 2009 From: noone at example.com (Jon Bendtsen) Date: Thu, 04 Jun 2009 13:30:35 +0200 Subject: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers In-Reply-To: <4A1E4D09.60402@example.com> References: <4A1E4D09.60402@example.com> Message-ID: <4A27B05B.9040102@example.com> Jon Bendtsen wrote: > Dennis Lee Bieber wrote: >> On Wed, 27 May 2009 14:25:58 +0200, Jon Bendtsen >> declaimed the following in gmane.comp.python.general: >> >>> 'From: root at laerdal.dk\nSubject: testing\nNewsgroups: test\nBody: >>> \n\n\nfoobar\n\n\n.\n\n\n' >>> >> I believe NNTP, like SMTP, requires \r\n line termination. > > I will try it, but why does it then work when it posts the file? The > file is a std. unix file, so it should also only have \n line > termination. I have now tried adding \r infront of all \n. That didnt help. I tried making a tempfile.TemporaryFile(dir='/tmp') which did not work either. Message is still: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers From willgun at live.cn Thu Jun 4 07:42:01 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 19:42:01 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Andrew McNamara ??: > > On 04/06/2009, at 4:14 PM, willgun wrote: > >>> What did you call the .py file? sqlite3.py? If so, you've just >>> imported your own module again. 8-) >>> After the import, try "print sqlite3.__file__", which will tell you >>> where the module came from. > >> Thank you all the same. >> I'm a student from China.It's painful for us to read python >> documentation entirely due to poor english.So I often make these >> mistakes. > > Don't worry - even experienced Python coders get caught by this one. > Just remember the "print module.__file__" trick for next time something > odd happens. > > When you import a module in python, it is only imported the first time > you request it (which is why your import did not become recursive and > raise an error). I know it well now.Thanks.It seems that the mailing list is much greater than most forums in China. From willgun at live.cn Thu Jun 4 07:45:49 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 19:45:49 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: By the way ,what does 'best regards' means at the end of a mail? From noone at example.com Thu Jun 4 07:58:30 2009 From: noone at example.com (Jon Bendtsen) Date: Thu, 04 Jun 2009 13:58:30 +0200 Subject: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers In-Reply-To: <4A27B05B.9040102@example.com> References: <4A1E4D09.60402@example.com> <4A27B05B.9040102@example.com> Message-ID: Jon Bendtsen wrote: > Jon Bendtsen wrote: >> Dennis Lee Bieber wrote: >>> On Wed, 27 May 2009 14:25:58 +0200, Jon Bendtsen >>> declaimed the following in gmane.comp.python.general: >>> >>>> 'From: root at laerdal.dk\nSubject: testing\nNewsgroups: test\nBody: >>>> \n\n\nfoobar\n\n\n.\n\n\n' >>>> >>> I believe NNTP, like SMTP, requires \r\n line termination. >> I will try it, but why does it then work when it posts the file? The >> file is a std. unix file, so it should also only have \n line >> termination. > > I have now tried adding \r infront of all \n. That didnt help. > > I tried making a tempfile.TemporaryFile(dir='/tmp') which did not > work either. Message is still: > > nntplib.NNTPTemporaryError: 441 Article has no body -- just headers with the help of #python on Freenode i found the problem. I didnt seek back to 0. With seeking stringio works, and then i will use that. From mail at microcorp.co.za Thu Jun 4 08:53:41 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 14:53:41 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> Message-ID: <003d01c9e513$893597e0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > > > If you have any interest, contact me and I will > > send you the source. > > Maybe you could tell people what the point is... Well its a long story, but you did ask... I am working on an i/o system, running in an ebox - it is basically a 486 with 128 meg running slackware, and its job is to serve as an i/o server, reading inputs and setting relay and other outputs. A nice slow 300 Mhz machine - not fast at all. Now the thread that does the i/o gets commands over a queue from a socket , so they are strings, and they look like this: "A,10101010,00010010" where the "A" means its an I/O command, and the ascii binary is stuff that must be written. The response looks the same, but it has more fields as it reflects both the state of the current inputs and the current outputs. The responses are written to an output queue that is serviced by another thread. Now I did not want to waste any cycles deciding how to unpack the incoming stuff, so I just use split(','). So then I wanted to add a command to change masters, passing an alternate output queue, so that the changeover is confirmed. But a queue is not a string, and you can also not pickle it. So I messed around for a while passing the name of the new queue, and doing exec magic. This worked, but only if the new queue was a global, which was kind of yucky. So then I started thinking - why can't I just pass a simple pointer to the object, and the can was the result. It is not really something that is all that useful - only if you want to pass the reference "as part of a string". It is now working in the ebox too, but it does not look as good - the strings look like negative numbers, but they uncan fine. - Hendrik From andrewm at object-craft.com.au Thu Jun 4 09:07:42 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 23:07:42 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: On 04/06/2009, at 9:45 PM, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? The correspondent is wishing you well. You'll also see things like "kind regards", "best wishes" and so on. "Regard" essentially means respect. From pdpinheiro at gmail.com Thu Jun 4 09:12:32 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 4 Jun 2009 06:12:32 -0700 (PDT) Subject: import sqlite3 References: Message-ID: On Jun 4, 12:45?pm, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? "regard" means roughly "care". Its use as "best regards" closing a letter (or, in this case, email), means that you care for the person you're saying goodbye to. It's just a polite way to end a letter :) From news at schwertberger.de Thu Jun 4 09:15:25 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Thu, 04 Jun 2009 15:15:25 +0200 Subject: Get the hard disk hardware serial number In-Reply-To: References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <78pvnhF1n1gpeU1@mid.individual.net> MRAB schrieb: > Jorge wrote: >> I need to know how to get the hardware serial number of a hard disk in >> python. >> > For Windows, see http://www.daniweb.com/forums/thread187326.html This recipe uses the function GetVolumeInformation(), which does not return the hardware serial number. From the microsoft documentation: This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber. The WMI method is e.g. described here: http://www.velocityreviews.com/forums/t359670-wmi-help.html import wmi c = wmi.WMI() for pm in c.Win32_PhysicalMedia(): print pm.Tag, pm.SerialNumber or to retrieve the serial number for the installation drive: serial = c.Win32_PhysicalMedia(["SerialNumber"], Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip() Regards, Dietmar From wiggly at wiggly.org Thu Jun 4 09:18:44 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 14:18:44 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <003d01c9e513$893597e0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> Message-ID: <4A27C9B4.4070302@wiggly.org> Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> Hendrik van Rooyen wrote: >>> If you have any interest, contact me and I will >>> send you the source. >> Maybe you could tell people what the point is... > > Well its a long story, but you did ask... [snip] Maybe I should have said "why should people care" or "why would someone use this" or "what problem does this solve" Your explanation doesn't make a whole lot of sense to me, I'm sure it does to you. Why, for example, would someone use your system to pass objects between processes (I think this is the main thing you are providing?) rather than POSH or some other system? Regards, n From philip at semanchuk.com Thu Jun 4 09:21:56 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 09:21:56 -0400 Subject: import sqlite3 In-Reply-To: References: Message-ID: <81EE3446-0180-4B8D-A973-9AF4DFE3F4B7@semanchuk.com> On Jun 4, 2009, at 7:45 AM, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? "regards" is just respectful (and slightly formal) goodbye. Have a look at the definition: http://dictionary.reference.com/search?q=regards It's used much more in written communication than in spoken. At the end of a letter (or email), you might also see simply "regards", or "warm regards" (which is especially friendly) or "kind regards". At the end of a meeting of two friends A and B, A might say to B, "Give my regards to X" where X is a person that both A and B know that B will soon see. A is asking B to "carry" good wishes to X. Instead, A could have said to B, "When you see X, please tell her I'm thinking of her fondly". One can also say, "I hold him in high regard", meaning, "I respect and admire him". I'm in the USA; other English speakers might see this differently. bye Philip From pataphor at gmail.com Thu Jun 4 09:37:45 2009 From: pataphor at gmail.com (pataphor) Date: Thu, 4 Jun 2009 13:37:45 +0000 (UTC) Subject: Making the case for repeat Message-ID: This probably has a snowballs change in hell of ending up in builtins or even some in some module, but such things should not prevent one to try and present the arguments for what one thinks is right. Else one would end up with consequentialism and that way lies madness and hyperreality. So here is my proposed suggestion for a once and for all reconciliation of various functions in itertools that can not stand on their own and keep a straight face. Because of backwards compatibility issues we cannot remove them but we can boldly jump forward and include the right repeat in the builtin namespace, which I think would be the best thing. Alternatively -- the second best solution -- would be to give this function its own namespace where it can supersede the old incongruencies in itertools. Combiniter or combinator? P. from itertools import count from functools import partial def repeat(iterable, cycles = None, times = 1): L = [] for x in iterable: for i in xrange(times): yield x L.append(x) counter = count if cycles is None else partial(xrange,cycles-1) for _ in counter(): for x in L: for i in xrange(times): yield x def test(): #making the case for repeat from itertools import islice, cycle times = 2 n = 3 cycles = 2 L = range(n) #look ma, no islice! print list(repeat(L, cycles)) print list(repeat(L, cycles, times)) #repeat without extra args works like itertools.cycle: print list(islice(repeat(L),len(L)*cycles)) print list(islice(cycle(L),len(L)*cycles)) #enclosing a single item in a list emulates #itertools.repeat functionality: print list(repeat(['Mr. Anderson'],cycles)) if __name__ == '__main__': test() From albert at spenarnc.xs4all.nl Thu Jun 4 09:41:37 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 04 Jun 2009 13:41:37 GMT Subject: hash and __eq__ References: <003e1491$0$9723$c3e8da3@news.astraweb.com> <0233137f$0$8244$c3e8da3@news.astraweb.com> Message-ID: In article <0233137f$0$8244$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sun, 31 May 2009 12:08:33 +0100, Arnaud Delobelle wrote: > >> Anyway, it's good to know that quicksort is O(n^2) in the worst case - >> and that this worst case can crop up very easily in some situations, >> especially if not too much care has been taken implementing it. > >The naive quicksort algorithm, where you recursively split the list into >two halves, performs badly if the list is already sorted (or nearly so). No it isn't (in general). It only does so if you use the first element as a pivot, resulting in a set with one element and a set with n-1 elements. It is an incredible long time ago that someone implemented qsort this very naive way, especially since in the 80's Knuth warned about it. A current naive way is use element (m+n)/2 when sorting the range m..n. This is nearly optimal for a sorted set. For a random set the chance for a consistent bad choice is astronomically low. I have a QSORT implemented in the library for my lina Forth and didn't bother to do better than this. (Used in some of the demanding problems in projecteuler.net). More sophisticated qsorts select three elements at random and use best of three. The worst behaviour is still O(n^2) but the multiplication factor is lower and the chance is astronomically low to the third power. >It's easy to fix that: randomise the list before you sort! You can do >that with a single pass of the list. That has the advantage of ensuring >that no specific input can cause degraded performance, so an attacker >can't DOS your application by passing sorted lists to be sorted. >Another strategy is to randomly exchange the pivot element when sorting. choose? A good sort utility with facilities for records with fields (using a modified heap sort, and using disk base merge sort for very large sets) can be find on my site below (called ssort). Because of the heap sort even the worst case is O(Nlog(N)) if the O(N^2) behaviour of qsort is your worry. >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From Scott.Daniels at Acm.Org Thu Jun 4 09:52:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 06:52:21 -0700 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > Scott David Daniels wrote: >> Esmail wrote: >>> ... Tk seems a bit more complex .. but I really don't know much about >>> it and its interface with Python to make any sort of judgments as >>> to which option would be better. >> >> This should look pretty easy: > > Thanks Scott for taking the time to share this code with me, it > will give me something to study. I'm not sure if I'd say it looks > easy (but then again I am not very familiar with Tk :-) I threw in too much, I think. The reason for the "idle -n" trick is to share the Tkinter mainloop with idle itself, so you can experiment with using Tkinter and see the effects of a single command, just after you type it in (and thus get a nice intuitive feel for the possibilities). The tricky part to understand is the switch from imperative programming to interrupt driven programming. gui stuff has to switch to interrupt driven so that it can respond to things like mouse drags, windows repaints, and so on when they happen, rather than when the software asks for them. Typically, a GUI program sets some stuff up (in imperative mode), and then switches to event-driven code and drops into an event loop. It is also typical of most GUI programs that the display manipulating code (the actual painting) must all be done in a single thread (the display thread) where the events happen. Small calculations can occur inside these events, but slow calculations leave your GUI unresponsive and unable to do things like restore hidden parts as you drag another window across it. So, big or slow calculations are either done in a separate threads (or single calculation thread) that communicate back with the display thread, or the big slow calculation are done in bite-sized pieces in the display thread, doing a piece and moving the rest on to another event. A Tkinter canvas is nice to use because you can draw things on it, move those things around (separately or in groups), change their shape or color, make them visible or invisible, and the canvas keeps track of drawing them. import Tkinter as tk # First set up Tkinter and a root window (idle -n fakes part) root = tk.Tk() # Set that window's size (400x400) and loc (5,5) root.geometry('400x400+5+5') # make a canvas (2-D drawing area) in that window canvas = tk.Canvas(root) #make the canvas fill the window (even as the window is resized) canvas.pack(expand=1, fill=tk.BOTH) # draw a red filled oval on the canvas bounded by (50,100), (70,140) a = canvas.create_oval((50, 100, 70, 140), fill='red') # the hard-to-get part about the example is that the Mover class # takes a canvas element or tag (such as a above), and provides a # couple of methods (.start(event) and .move(event)) for associating # with the mouse. ".start" when the button goes down, and ".move" # as the button is dragged with the mouse down. canvas.itemconfig(a, fill='#55AADD') # Change to oval to near cyan canvas.move(a, 5, 5) # move it down right 5 pixels single_mover = Mover(canvas, a) # associate motion with our oval # make the "left button down" on canvas call our start method # which just gives u a point to move around from. canvas.bind("", single_mover.start) # make motion while left button is down call our move method. # there we will compare the mouse position to our saved location, # move our oval (in this case) a corresponding distance, and # update the saved location. canvas.bind("", single_mover.move) # at this point we have our behavior wired up. If in idle, "just # try it", but if not: tk.mainloop() # stays there until you click the close window. Also, a Tkinter Canvas can be saved as an encapsulated postscript file, thus allowing you pretty pictures into PDFs. --Scott David Daniels Scott.Daniels at Acm.Org From fuzzyman at gmail.com Thu Jun 4 09:52:32 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 4 Jun 2009 06:52:32 -0700 (PDT) Subject: Replacing module with a stub for unit testing References: <852e3d2d-80a5-4de8-b948-f545e4bbcf9e@e21g2000yqb.googlegroups.com> Message-ID: <4fca99cf-dd1b-44bb-a5f5-a4a5cc949e07@l28g2000vba.googlegroups.com> On May 23, 2:00?pm, pigmart... at gmail.com wrote: > Hi, > > I'm working on a unit test framework for a module. ?The module I'm > testing indirectly calls another module which is expensive to access > --- CDLLs whose functions access a database. > > ? ? test_MyModule --->MyModule--->IntermediateModule--- > > >ExpensiveModule > > I want to create a stub of ExpensiveModule and have that be accessed > by IntermediateModule instead of the real version > > ? ? test_MyModule --->MyModule--->IntermediateModule--- > > >ExpensiveModuleStub > > I tried the following in my unittest: > > ? ? import ExpensiveModuleStub > ? ? sys.modules['ExpensiveModule'] = ExpensiveModuleStub # Doesn't > work > > But, import statements in the IntermediateModule still access the real > ExpensiveModule, not the stub. > > The examples I can find of creating and using Mock or Stub objects > seem to all follow a pattern where the fake objects are passed in as > arguments to the code being tested. ?For example, see the "Example > Usage" section here:http://python-mock.sourceforge.net. ?But that > doesn't work in my case as the module I'm testing doesn't directly use > the module that I want to replace. > > Can anybody suggest something? > My Mock module, and in particular the patch decorator is designed explicitly to do this. You need to be careful because modules and module level globals (including things your module imports) are global state. If you change them for the purpose of a test you must *guarantee* to restore them after the test. http://www.voidspace.org.uk/python/mock/ http://www.voidspace.org.uk/python/mock/patch.html In your case if you are testing a module which imports ExpensiveModule then by ExpensiveModule lives in the *namespace of the module under test*. You could patch it like this: from mock import patch import module @patch('module.ExpensiveModule) def testModule(self, mockExpensiveModule): .... Whilst the test is running 'module' has'ExpensiveModule' mocked out (replaced) with a Mock instance. This is passed into your test so that you can setup behaviour and make assertions about how it is used. After the test is completed the patching is undone. All the best, Michael Foord -- http://www.ironpythoninaction.com/ From steve at REMOVE-THIS-cybersource.com.au Thu Jun 4 09:53:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 13:53:21 GMT Subject: Making the case for repeat References: Message-ID: <0043ac60$0$9686$c3e8da3@news.astraweb.com> On Thu, 04 Jun 2009 13:37:45 +0000, pataphor wrote: > This probably has a snowballs change in hell of ending up in builtins or > even some in some module, but such things should not prevent one to try > and present the arguments for what one thinks is right. Else one would > end up with consequentialism and that way lies madness and hyperreality. It would be cruel of me to say "Too late", so I shall merely ask, what on earth are you going on about? > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Because of backwards compatibility issues we > cannot remove them but we can boldly jump forward and include the right > repeat in the builtin namespace, which I think would be the best thing. What is "the right repeat"? What's wrong with the old one? If you're going to make a proposal, you have to actually *make the proposal* and not just say "Here, have some code, now put it in the builtins because the rest of itertools is teh suxor!!!". That rarely goes down well. (I don't know if that's exactly what you're trying to say, but it seems that way to me.) I've run your test code, and I don't know what I'm supposed to be impressed by. -- Steven From vincent at vincentdavis.net Thu Jun 4 10:08:31 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 08:08:31 -0600 Subject: import _sqlite3 no module named error Message-ID: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> I volunteered to help Marijo Mihel?i? who was looking for someone with a mac the help him build a mac binary using py2app for his simpletasktimer http://code.google.com/p/simpletasktimer/wiki/Installation when I try to run his app I get the no module named _sqlite3 , I am not sure what this is caused by as it looks to me like sqlite3 is trying to import it. Any idea how to fix this? Other than the obvious of getting _sqlite3 somehow, or maby it is that simple. here is what i get Traceback (most recent call last): File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/KTaskTimer.py", line 13, in from lib import KTaskEditDialog, KTaskReport, KTaskTimerDB File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/lib/KTaskReport.py", line 10, in from lib import KTaskTimerDB File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/lib/KTaskTimerDB.py", line 8, in import sqlite3 as lite File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/sqlite3/__init__.py", line 24, in from dbapi2 import * File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named _sqlite3 logout Thanks Vincent Davis 720-301-3003 From python at mrabarnett.plus.com Thu Jun 4 10:18:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Jun 2009 15:18:48 +0100 Subject: import sqlite3 In-Reply-To: References: Message-ID: <4A27D7C8.9020001@mrabarnett.plus.com> Andrew McNamara wrote: > > On 04/06/2009, at 9:45 PM, willgun wrote: > >> By the way ,what does 'best regards' means at the end of a mail? > > The correspondent is wishing you well. You'll also see things like "kind > regards", "best wishes" and so on. "Regard" essentially means respect. There's also "high regard", which means "much admiration or respect", and the phrase "to hold someone in high regard" means to admire and respect that person greatly, for example, "we hold Guido in high regard". :-) From albert at spenarnc.xs4all.nl Thu Jun 4 10:20:45 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 04 Jun 2009 14:20:45 GMT Subject: What text editor is everyone using for Python References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In article , Emile van Sebille wrote: >On 6/1/2009 4:57 PM Steven D'Aprano said... >> Having noted that the word "Quit" does appear, how do you then *actually* >> Quit? Apart from taunting the user, what is it that Ctrl-G is actually >> doing when it displays the word "Quit" in what seems to be some sort of >> status bar? > >Ahhh.. memories of discovering that F7 gets you out of WordPerfect... Memories of Atari 260/520/1040 that had a keyboard with a key actually marked ... HELP. (Sometimes hitting it provided you with help...) > >Emile > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From abeGong at gmail.com Thu Jun 4 10:27:52 2009 From: abeGong at gmail.com (Abe) Date: Thu, 4 Jun 2009 07:27:52 -0700 (PDT) Subject: Compiling and transporting modules/libraries in python References: <249dbf4f-ef3e-495e-975e-05d848279d39@u10g2000vbd.googlegroups.com> <69a7961c-c394-4df1-bcb7-cc18aa162817@z14g2000yqa.googlegroups.com> Message-ID: <52803436-9726-4331-96aa-332f02308464@o30g2000vbc.googlegroups.com> alex23 - Thanks for the tips. I'm using portable python and it's working great so far. I'll come back and try virtualenv if I get stuck again. - Abe From pataphor at gmail.com Thu Jun 4 10:34:53 2009 From: pataphor at gmail.com (pataphor) Date: Thu, 4 Jun 2009 14:34:53 +0000 (UTC) Subject: Making the case for repeat References: <0043ac60$0$9686$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I've run your test code, and I don't know what I'm supposed to be > impressed by. Thank you for trying out the code. That you're unimpressed actually is a huge encouragement because code should just run the way people expect, without unnecessary surprises. P. From aahz at pythoncraft.com Thu Jun 4 10:45:27 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 07:45:27 -0700 Subject: "Exploding" (**myvariable) a dict with unicode keys References: Message-ID: In article , Samuel Wan wrote: > >I started using python last week and ran into exceptions thrown when >unicode dictionary keys are exploded into function arguments. In my >case, decoded json dictionaries did not work as function arguments. >There was a thread from Oct 2008 >(http://www.gossamer-threads.com/lists/python/python/684379) about the >same problem. Here is my workaround: When posting to threads like this, please make sure to specify which version(s) of Python you're using -- this is a Python 2.x issue. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From mail at microcorp.co.za Thu Jun 4 10:49:42 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 16:49:42 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> Message-ID: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > "Nigel Rantor" wrote: > > > >> Hendrik van Rooyen wrote: > >>> If you have any interest, contact me and I will > >>> send you the source. > >> Maybe you could tell people what the point is... > > > > Well its a long story, but you did ask... > > [snip] > > Maybe I should have said > > "why should people care" > > or > > "why would someone use this" > > or > > "what problem does this solve" > > Your explanation doesn't make a whole lot of sense to me, I'm sure it > does to you. > > Why, for example, would someone use your system to pass objects between > processes (I think this is the main thing you are providing?) rather > than POSH or some other system? > I can see that my explanation passes you by completely. I said, in my original post, that a can could not leave a process. A can is exactly the same as a C pointer, only its value has been converted to a string, so that you can pass it "in band" as part of a string. That is all it does. No more, no less. Passing it to an outside process makes no sense, unless it points at an object in shared memory - else it guarantees a segfault. It is not something that would find common use - in fact, I have never, until I started struggling with my current problem, ever even considered the possibility of converting a pointer to a string and back to a pointer again, and I would be surprised if anybody else on this list has done so in the past, in a context other than debugging. Which is why I posted. This is supposed to be a newsgroup, and this is a rare occurrence, and hence news. - Hendrik From allen.fowler at yahoo.com Thu Jun 4 11:12:44 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Thu, 4 Jun 2009 08:12:44 -0700 (PDT) Subject: Project source code layout? In-Reply-To: References: Message-ID: <64186.34279.qm@web45614.mail.sp1.yahoo.com> > > I was hoping to keep the dev layout as close to deployment possible. > > Completely different purposes. For example, the actual production database > and config files form no part of your development project, do they? And > conversely, utility scripts that might be used, for example, to set up a > database, should not be part of the production installation. > The data will certainly be different. Good point. (Though for now even the production DB will be sqlite.) > Here's one layout I used in a production system for an online shop: > > /home/shop/bin -- binaries (CGI and daemon) > /home/shop/lib -- common libraries for binaries > /home/shop/config -- configuration files, incl format templates > /home/shop/state -- socket for interprocess communication, log files > > Thank you. Couple of questions: 1) Do you use virtualpython? 2) How do you load the modules in your lib directory? 3) How do you reference your configuration directives from within your modules and CGI/daemon scripts? Thank you, Allen From daniel.cotton at gmail.com Thu Jun 4 11:41:18 2009 From: daniel.cotton at gmail.com (Daniel Cotton) Date: Thu, 4 Jun 2009 16:41:18 +0100 Subject: PEP 315: Enhanced While Loop Message-ID: <965c376b0906040841n1ad4cdb8r4a82903731536231@mail.gmail.com> During some random surfing I became interested in the below piece of code: > while : > > and while : > > and while : > > else: It strikes me that the 'and while' syntax has some power that you may not have considered. Consider that if an 'and while' were to be executed under some condition: if : and while : you would then have a live loop condition that applied to subsequent iterations only if conditionX was met. Under this circumstance I wondered if you might also want a method of cancelling while conditions? For example: cancel while : where the 'cancel while' command removes conditionY from the list of conditions that the loop will terminate on. You could then also use this syntax to cancel the initial while condition. I also wondered if 'or while' might be better, so that you could add different types of prefix to a while condition, i.e. 'and while'. I'm a python novice so this could well be something you want to ignore but I wasn't doing anything anyway. Let me know what you think. --Daniel. From exarkun at divmod.com Thu Jun 4 12:04:49 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 4 Jun 2009 12:04:49 -0400 Subject: Project source code layout? In-Reply-To: Message-ID: <20090604160449.22176.786488841.divmod.quotient.1898@henry.divmod.com> On Thu, 04 Jun 2009 21:33:13 +1200, Lawrence D'Oliveiro wrote: >In message , Allen >Fowler wrote: > >> I was hoping to keep the dev layout as close to deployment possible. > >Completely different purposes. For example, the actual production database >and config files form no part of your development project, do they? And >conversely, utility scripts that might be used, for example, to set up a >database, should not be part of the production installation. If you don't use the "utility scripts" in your development environment, how do you know they work with the code you're developing? If production has a completely different set of configuration files from your development env, how do you know how your code will work when combined with them? Any time there is a difference, there is the potential for bugs which you cannot catch until you deploy your code, and that's a recipe for failure. Minimizing differences between development and deployment is a *great* thing. There are certainly cases where differences are necessary, but one should strive to make them the exception, not the rule. Jean-Paul From exarkun at divmod.com Thu Jun 4 12:23:33 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 4 Jun 2009 12:23:33 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <20090604162333.22176.668277797.divmod.quotient.1904@henry.divmod.com> On Thu, 4 Jun 2009 16:49:42 +0200, Hendrik van Rooyen wrote: > [snip] > >It is not something that would find common use - in fact, I have >never, until I started struggling with my current problem, ever even >considered the possibility of converting a pointer to a string and >back to a pointer again, and I would be surprised if anybody else >on this list has done so in the past, in a context other than debugging. So, do you mind sharing your current problem? Maybe then it'll make more sense why one might want to do this. Jean-Paul From iamelgringo at gmail.com Thu Jun 4 12:42:27 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Thu, 4 Jun 2009 09:42:27 -0700 (PDT) Subject: Feedparser problem Message-ID: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> I'm trying to add a feedreader element to my django project. I'm using Mark Pilgrim's great feedparser library. I've used it before without any problems. I'm getting a TypeError I can't figure out. I've tried searching google, bing, google groups to no avail. Here's the dpaste of what I'm trying to do and the result I'm getting: http://dpaste.com/51406/ I've tried checking my firewall settings. I'm using Windows 7 and Python 2.6. Win 7 is allowing other Python programs through. I've tried several different RSS urls with the same result. Any thoughts would be greatly appreciated. From xahlee at gmail.com Thu Jun 4 12:46:44 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Jun 2009 09:46:44 -0700 (PDT) Subject: multi-core software Message-ID: Of interest: ? Why Must Software Be Rewritten For Multi-Core Processors? http://xahlee.org/UnixResource_dir/writ/multi-core_software.html plain text version follows. -------------------------------------------------- Why Must Software Be Rewritten For Multi-Core Processors? Xah Lee, 2009-06-04 I had a revelation today, namely, that it is necessary to rewrite software to use multi-processor in order to benefit from it. This may sound stupid, but is a revelation to me. For the past decade, the question has been on my mind, about why should software needs to be rewritten to take advantage of multi-processors. Because, in my mind, i thought that software are at some fundamental level just algorithms, and algorithms, have nothing to do with hardware implementation aspects such as number of processors. I always felt, that those talks about the need or difficulty of rewriting software for multi-processor (or multi-core these days) must be the product of idiocy of industrial imperative coding monkies. In particular, some languages such as java, the way they deal with it, seems to me extremely stupid. e.g. the concept of threads. In my mind, there should be a layer between the software and the hardware, such as the operating system, or the compiler, that should be able to automatically handle or compile the software so that it FULLY use the multi-processors when present. In short, i thought that a algorithm really has nothing to do with hardware details. I never really thought hard about this issue, but today, since i got a quad-core PC, so i looked into the issue, and thought about it, and i realized the answer. The gist is that, algorithm, fundamentally means manipulating some hardware, in fact, algorithm is a step by step instruction about some form of hardware, even the hardware may be abstract or virtual. For example, let's say the simplest case of 1+1. It is a algorithm, but where is the hardware? You may say it's abstract concept, or it being a mathematical model. What you call 1+1 depends on the context, but in our context, those numbers are the hardware. To see this, lets say more complex example of listing primes by sieve. Again, it comes down to ?what is a number?? Here, numbers can be stones, or arrangement of beads on abacus, it's hardware! As another example, say sorting. To begin with, you have to have some something to sort, that's hardware. Another way to see this is that, for a given computing problem, there are infinite number of algorithms to achieve the same thing. Some, will be better ones, requiring less steps, or requiring less storage. All these are concrete manipulation issues, and the thing being manipulated, ultimately we have to call it hardware. So, when hardware changes, say from one cpu to multi-cpu, there's no way for the algorithm to magically change and adopt the changed hardware. If you need a algorithm that is catered to the new hardware, you need a new algorithm. One might think that there might be algorithm Omega, such that it takes input of old hardware O, new hardware N, and a algorithm A, and output a algorithm B, such that B has the same behavior as A, but N+B performs better than O+A. This is like asking for Strong AI. One thing we often forgot is that algorithms ultimately translates to manipulating hardware. In a modern digital computer, that means software algorithms ultimately becomes machine instructions in CPU, which manipulate the 1s and 0s in register, or electricity voltage in transisters. In a more mundane point of view, a automatic system for software to work on multi-processors is a problem of breaking a problem into discrete units (so that they can be computed in parallel). The problem of finding a algorithm is entirely different from the problem of breaking a problem into distinct units. The problem of breaking a problem into distinct units is a entire new branch of mathematics. For example, let's say factoring. Factoring is a well defined mathematical problem. There are millions algorithms to do it, each class has different properties such as number of steps or storage units. However, if we look at these algorithms from the point of view of distinct units, it's a new perspective on classification of algorithms. Software are in general too ill-defined and fuzzy and complex, the software we use on personal computers such as email, browsers, games, don't even have mathematical models. They don't even have mathematical models of their inputs and outputs. To talk about automatic system of unitizing software, would be more like a AI fantasy. Roughly, a term that describes this aspect of research is Parallel computing. In the Wikipedia article, it talks about types of parallelism: Bit- level parallelism, Instruction-level parallelism, Data parallelism, Task parallelism. Then it also discusses hardware aspects classes: multicore, symmetric multiprocessing, distributed computing, cluster, grid. The subjects mentioned there more close to this essay are ?data parallelism? and ?task parallelism?. However, neither are high level enough as i discussed here. The issue discussed here would be like ?algorithmic parallelism?. Indeed, Wikipedia mentioned ?Automatic parallelization?, which is exactly what i'm talking about here. Quote: Automatic parallelization of a sequential program by a compiler is the holy grail of parallel computing. Despite decades of work by compiler researchers, automatic parallelization has had only limited success.[40] Mainstream parallel programming languages remain either explicitly parallel or (at best) partially implicit, in which a programmer gives the compiler directives for parallelization. A few fully implicit parallel programming languages exist ? SISAL, Parallel Haskell, and (for FPGAs) Mitrion-C. It says ?A few fully implicit parallel programming languages exist?. If you are a comp lang nutcase, don't get carried away by what those words might seem to mean. (Note: Wikipedia has a dedicated article on the subject: Automatic parallelization) Xah ? http://xahlee.org/ ? From mensanator at aol.com Thu Jun 4 12:47:05 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Jun 2009 09:47:05 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> On Jun 4, 1:27?am, Raymond Hettinger wrote: > > Nice one! > > It only does partitions of a sequence. ?I haven't yet looked at a way > to > do partitions of a set. ?Any ideas? > > > Raymond, as perhaps *the* principle contributor to itertools, do you feel > > that the combinatorics-related tools should be in their own module? Or is > > that dividing the module too fine? > > I like having them in itertools because they form part of the > "iterator algebra" > for splitting, filtering, joining, and combining streams of iterators. > > > Would you consider moving permutations() and friends into a module > > together with functions for calculating the number of permutations etc? > > > e.g. permutations(iterable[, r]) --> permutations object > > ? ? ?nPr(n, r) --> int > > Looked at this a while back. ?If the nPr style functions go in, they > will > probably be in the math module (or a new module for integer functions > like gcd and whatnot). ?The reason for not keeping them together is > that > the use cases are likely disjoint -- when I go to my calculator for > nCr > I don't expect a listing -- when I need to loop over permutations, I > typically only care about the contents of the permutation, not the > total > number of them (except for purposes of estimating how long a search > will > take). ?People look to the math module for things they find on their > calculator and to the itertools module for high-speed looping > constructs. > > Also, there is a issue of naming the functions. ?For combinations, you > you might think to look for ncombs() or somesuch, but > binomial_coefficient() > is what someone else may be searching for. > > What would be nice is to turn the itertool combinatorics into > classes with a len() method, an ability to index to the n-th > iteration, or to find at an arbitrary iteration: > > >>> c = combinations('monte', 3) > >>> len(c) > 10 > >>> c[2] > ('m', 'o', 'e') > >>> c.find(('m', 't', 'e')) > 5 > >>> random.choice(c) > > ('o', 'n', 'e') > > If the input iterable contains repeats, the find() method > would find the first match. > > These things are interesting and fun, but they also smell > of feeping-creaturism. After all, everybody knows that for m items taken n at a time, the counts are perm w/repl = m**n comb w/repl = (m+n-1)!/(n!(m-1)!) perm wo/repl = m!/(m-n)! comb wo/repl = m!/(n!(m-n)!) > > Raymond From skip at pobox.com Thu Jun 4 12:58:48 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 4 Jun 2009 11:58:48 -0500 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <18983.64840.555702.403634@montanaro.dyndns.org> Hendrik> A can is like a pickle, in that it is a string, but anything Hendrik> can be canned. Unlike a pickle, a can cannot leave the Hendrik> process, though, unless the object it points to lives in shared Hendrik> memory. Got some use cases? Thx, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From stefan_ml at behnel.de Thu Jun 4 13:41:13 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Jun 2009 19:41:13 +0200 Subject: accessing the XML attribute value noNamespaceSchemaLocation thru Python 2.5 In-Reply-To: References: Message-ID: <4a280739$0$31337$9b4e6d93@newsspool4.arcor-online.net> tooshiny wrote: > I am currently successfully using lxml and ElementTree to validate and > to access the XML contained data. I can however not find any > functional call to access the schema location ie the attribute value > noNamespaceSchemaLocation. > > A simple function call would be so much nicer than the other route of > file reading / string chopping etc I'm not quite sure what you are trying to do here, but to access an attribute of an Element object, you can use its get() method, as in root.get("{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation") Or did you mean to do something else? Stefan From tjreedy at udel.edu Thu Jun 4 13:48:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 13:48:17 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > I can see that my explanation passes you by completely. > > I said, in my original post, that a can could not leave a process. > A can is exactly the same as a C pointer, only its value has been > converted to a string, so that you can pass it "in band" as > part of a string. That is all it does. No more, no less. If I understand correctly, your problem and solution was this: You have multiple threads within a long running process. One thread repeatedly reads a socket. You wanted to be able to occasionally send an object to that thread. Rather than rewrite the thread to also poll a queue.Queue(), which for CPython sends objects by sending a pointer, you converted pointers to strings and sent (multiplex) them via the text stream the thread was already reading -- and modified the thread to decode and act on the new type of message. And you are willing to share the can code with someone who has a similar rare need and understands the danger of interpreting ints as addresses. Correct? tjr From chris.morisset at gmail.com Thu Jun 4 13:53:23 2009 From: chris.morisset at gmail.com (Chris) Date: Thu, 4 Jun 2009 10:53:23 -0700 (PDT) Subject: "where" in python Message-ID: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> I am a newby in Python and I'm first looking for equivalent to things I already manage: IDL. For example, I want to plot a sub-set of points, selected from a bigger set by applying some filter. In my example, I want to select only the values > 0. I succeed to write 5 different ways to do this, which one is the more efficient, the quicker, the more Python? It seems the 4th method give wrong results, but I don't know why... Thanks for your tips, Christophe ------------------------------------------------------------------------------------------ import pylab as pylab import numpy as numpy #Read the data d=pylab.load('Tabla_General2.cvs',comments='#',delimiter=';') # Define the columns to plot i_x = 10 i_y = 5 # Select the points to plot, 1rst method b_where = (d[:,i_x]>0) & (d[:,i_y]>0) xb = d[b_where,i_x] yb = d[b_where,i_y] # 2nd method xb2=pylab.compress(b_where,d[:,i_x]) yb2=pylab.compress(b_where,d[:,i_y]) # 3rd method i_where = pylab.where((d[:,i_x]>0) & (d[:,i_y]>0),1,0) xi = d[i_where,i_x] yi = d[i_where,i_y] # 4th method xi2=pylab.compress(i_where,d[:,i_x]) yi2=pylab.compress(i_where,d[:,i_y]) #5th method in_where = numpy.transpose(numpy.where((d[:,i_x]>0) & (d[:,i_y]>0))) xin = d[in_where,i_x] yin = d[in_where,i_y] ------------------------------------------------------------------------------ From monogeo at gmail.com Thu Jun 4 13:55:28 2009 From: monogeo at gmail.com (monogeo) Date: Thu, 4 Jun 2009 10:55:28 -0700 (PDT) Subject: python way to automate IE8's File Download dialog Message-ID: <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3@n4g2000vba.googlegroups.com> Hello, I am able to use PAMIE 2.0 to automate IE7's File Download dialog, but the same approach/code fails on IE8. You can see the details and code at http://tech.groups.yahoo.com/group/Pamie_UsersGroup/message/675 Please help if you are able to automate IE8's File Download dialog (with three buttons; Open, Save, Cancel) via python script. Thanks in advance. Jimmy From tjreedy at udel.edu Thu Jun 4 14:02:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 14:02:33 -0400 Subject: Get the hard disk hardware serial number In-Reply-To: <78pvnhF1n1gpeU1@mid.individual.net> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> <78pvnhF1n1gpeU1@mid.individual.net> Message-ID: Dietmar Schwertberger wrote: > The WMI method is e.g. described here: > http://www.velocityreviews.com/forums/t359670-wmi-help.html > > > import wmi Not in the stdlib, but available here: http://pypi.python.org/pypi/WMI/1.3 and requires in turn pywin32: http://pypi.python.org/pypi/pywin32/210 > c = wmi.WMI() > for pm in c.Win32_PhysicalMedia(): > print pm.Tag, pm.SerialNumber > > or to retrieve the serial number for the installation drive: > > serial = c.Win32_PhysicalMedia(["SerialNumber"], > Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip() > > > Regards, > > Dietmar From wiggly at wiggly.org Thu Jun 4 14:16:48 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 19:16:48 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <4A280F90.7050506@wiggly.org> Hendrik van Rooyen wrote: > It is not something that would find common use - in fact, I have > never, until I started struggling with my current problem, ever even > considered the possibility of converting a pointer to a string and > back to a pointer again, and I would be surprised if anybody else > on this list has done so in the past, in a context other than debugging. Okay, well, I think that's probably because it sounds like a fairly good way of making things slower and hard to port to another interpreter. Obviously depending on how you're achieving this. If you need to pass infomation to a thread then I would suggest there's better, quicker, more reliable, portable and comprehensible ways of doing it. It just smells to me that you've created this elaborate and brittle hack to work around the fact that you couldn't think of any other way of getting the thread to change it's behaviour whilst waiting on input. Just my 0.02p n From paul at boddie.org.uk Thu Jun 4 14:24:02 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 4 Jun 2009 11:24:02 -0700 (PDT) Subject: Get the hard disk hardware serial number References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <7ffc43b2-63e2-468c-bcb5-ae3260cf1a75@g37g2000yqn.googlegroups.com> On 4 Jun, 11:29, Nick Craig-Wood wrote: > > For linux I'd run this and parse the results. > > # smartctl -i /dev/sda Also useful is hdparm, particularly with the drive identification and detailed information options shown respectively below: # hdparm -i /dev/sda # hdparm -I /dev/sda Paul From nad at acm.org Thu Jun 4 14:33:17 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 11:33:17 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> Message-ID: In article <77e831100906040708l1a8bf638n19bbff05607b3d4a at mail.gmail.com>, Vincent Davis wrote: > I volunteered to help Marijo Mihel?i? who was looking for someone with > a mac the help him build a mac binary using py2app for his > simpletasktimer > http://code.google.com/p/simpletasktimer/wiki/Installation > > when I try to run his app I get the no module named _sqlite3 , I am > not sure what this is caused by as it looks to me like sqlite3 is > trying to import it. Any idea how to fix this? Other than the obvious > of getting _sqlite3 somehow, or maby it is that simple. > > here is what i get [...] > "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/s > qlite3/dbapi2.py", > line 27, in > from _sqlite3 import * > ImportError: No module named _sqlite3 > logout >From the path names, it appears you are using the MacPorts python2.5. Try: sudo port install py25-sqlite3 which will bring along sqlite3 if not already installed. It should be that simple. -- Ned Deily, nad at acm.org From see_website at mindprod.com.invalid Thu Jun 4 14:35:03 2009 From: see_website at mindprod.com.invalid (Roedy Green) Date: Thu, 04 Jun 2009 11:35:03 -0700 Subject: multi-core software References: Message-ID: On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee wrote, quoted or indirectly quoted someone who said : >? Why Must Software Be Rewritten For Multi-Core Processors? Threads have been part of Java since Day 1. Using threads complicates your code, but even with a single core processor, they can improve performance, particularly if you are doing something like combing multiple websites. The nice thing about Java is whether you are on a single core processor or a 256 CPU machine (We got to run our Athena Integer Java spreadsheet engine on such a beast), does not concern your code. You just have to make sure your threads don't interfere with each other, and Java/the OS, handle exploiting all the CPUs available. -- Roedy Green Canadian Mind Products http://mindprod.com Never discourage anyone... who continually makes progress, no matter how slow. ~ Plato 428 BC died: 348 BC at age: 80 From avazquezr at grm.uci.cu Thu Jun 4 14:51:38 2009 From: avazquezr at grm.uci.cu (Ariel Vazquez Riveron) Date: Thu, 04 Jun 2009 14:51:38 -0400 Subject: DUDA !!!!!!!!!! Message-ID: <20090604145138.17384ek58glbpi80@correo.grm.uci.cu> Hola: Hoy en d?a me encuentro iniciandome dentro del python, en estos momentos quiero saber de que forma puedo eliminar un archivo de un compactado, ya sea zip, rar o cualquier otro. Estudie las librer?as zipfile pero no tiene ninguna funcion que me permita hacerlo. Trabajo con python 2.5 salu2 Ariel ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From vincent at vincentdavis.net Thu Jun 4 14:51:49 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 12:51:49 -0600 Subject: import _sqlite3 no module named error In-Reply-To: References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> Message-ID: <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> >> when I try to run his app I get the no module named _sqlite3 , I am >> not sure what this is caused by as it looks to me like sqlite3 is >> trying to import it. Any idea how to fix this? Other than the obvious >> of getting _sqlite3 somehow, or maby it is that simple >> ? "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/s >> ? qlite3/dbapi2.py", >> line 27, in >> ? ? from _sqlite3 import * >> ImportError: No module named _sqlite3 >> logout > >From the path names, it appears you are using the MacPorts python2.5. > Try: > > ? ?sudo port install py25-sqlite3 > > which will bring along sqlite3 if not already installed. Yes I am using macports I think sqlite is installed? here is what I get when I run sudo port install py25-sqlite3 vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 Skipping org.macports.activate (py25-sqlite3 ) since this port is already active ---> Cleaning py25-sqlite3 vincent-daviss-macbook-pro-2:~ vmd$ From theller at ctypes.org Thu Jun 4 15:35:21 2009 From: theller at ctypes.org (Thomas Heller) Date: Thu, 04 Jun 2009 21:35:21 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> Message-ID: <4A2821F9.6080901@ctypes.org> [Please keep the discussion on the list] Joseph Garvin schrieb: > On Thu, Jun 4, 2009 at 3:43 AM, Thomas Heller wrote: >> There have been some attempts to use ctypes to access C++ objects. >> We (Roman Yakovenko and myself) made some progress. We were able to >> handle C++ name mangling, the special C++ calling convention, >> access virtual, non-virtual, overloaded functions, but finally gave up >> because the binary layout (function tables, member variables, and so on) >> of C++ objects is way too complicated and undocumented. > > Have you read the book Inside The C++ Object Model?: I haven't, but considered to buy it ;-) > http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545/ref=sr_1_1?ie=UTF8&s=books&qid=1244139929&sr=8-1 > > It's probably out of date now, but I'm about halfway through it and it > documents a ton of the little unexpected optimizations and such that > cause the binary layout to be complex. How did you get as far as you > did without having figured out the layout? (e.g. if you could access > virtual functions you must have known how to get at the virtual table) I found a lot of material on the web, also I used the (very good) visual studio debugger, and finally I did a lot of experimentation. We were only able to access some very simple C++ objects. There is also a patent or patents from MS about the vtable. All in all, as I said, IMO it is too complicated to figure out the binary layout of the C++ objects (without using a C++ compiler), also there are quite some Python packages for accessing them. -- Thanks, Thomas From kkylheku at gmail.com Thu Jun 4 15:37:59 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Thu, 4 Jun 2009 19:37:59 +0000 (UTC) Subject: multi-core software References: Message-ID: <20090616103324.200@gmail.com> ["Followup-To:" header set to comp.lang.lisp.] On 2009-06-04, Roedy Green wrote: > On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee > wrote, quoted or indirectly quoted someone who said : > >>? Why Must Software Be Rewritten For Multi-Core Processors? > > Threads have been part of Java since Day 1. Unfortunately, not sane threads designed by people who actually understand multithreading. > The nice thing about Java is whether you are on a single core > processor or a 256 CPU machine (We got to run our Athena Integer Java > spreadsheet engine on such a beast), does not concern your code. You are dreaming if you think that there are any circumstances (other than circumstances in which performance doesn't matter) in which you don't have to concern yourself about the difference between a uniprocessor and a 256 CPU machine. From nad at acm.org Thu Jun 4 15:41:15 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 12:41:15 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> Message-ID: In article <77e831100906041151g70868dbre1546cdb01082ba3 at mail.gmail.com>, Vincent Davis wrote: > Yes I am using macports I think sqlite is installed? here is what I > get when I run > sudo port install py25-sqlite3 > > vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 > Skipping org.macports.activate (py25-sqlite3 ) since this port is already > active > ---> Cleaning py25-sqlite3 > vincent-daviss-macbook-pro-2:~ vmd$ Hmm! This is on 10.5.7, BTW. $ sudo port version Version: 1.710 $ sudo port info py25-sqlite3 py25-sqlite3 @2.5.4 (python, databases) [...] $ /opt/local/bin/python2.5 Python 2.5.4 (r254:67916, May 4 2009, 01:40:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from _sqlite3 import * >>> A quick web search shows that there were apparently some issues with MacPort's py25-sqlite3 in the not too distant past. Perhaps your ports need to be upgraded? $ sudo port selfupdate or $ sudo port sync $ sudo port upgrade installed -- Ned Deily, nad at acm.org From mgarrana at mantrac.com.eg Thu Jun 4 15:42:23 2009 From: mgarrana at mantrac.com.eg (Mohamed Garrana) Date: Thu, 4 Jun 2009 22:42:23 +0300 Subject: Is socket.shutdown(1) useless Message-ID: <2D121496476B834D87FEF0AFA9A78A2538E9D4@MAN-EXCL-02.mantrac.win2k.dom> Hello This is is in answer for Is socket.shutdown(1) useless Shutdown(1) , forces the socket no to send any more data This is usefull in Buffer flushing Strange error detection Safe guarding Let me explain more , when you send a data , it's not guaranteed to be sent to your peer , it's only guaranteed to be sent to the os buffer , which in turn sends it to the peer os buffer So by doing shutdown(1) , you flush your buffer and an error is raised if the buffer is not empty ie: data has not been sent to the peer yet Howoever this is irrevesable , so you can do that after you completely sent all your data and you want to be sure that it's atleast at the peer os buffer Everything's ok in the end...if it's not ok, then its not the end. P save paper... -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Thu Jun 4 15:50:25 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 15:50:25 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <4A2821F9.6080901@ctypes.org> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <2510655A-6F23-4B27-A5CD-AE8EC0D3587D@semanchuk.com> On Jun 4, 2009, at 3:35 PM, Thomas Heller wrote: > [Please keep the discussion on the list] > > Joseph Garvin schrieb: >> On Thu, Jun 4, 2009 at 3:43 AM, Thomas Heller >> wrote: >>> There have been some attempts to use ctypes to access C++ objects. >>> We (Roman Yakovenko and myself) made some progress. We were able to >>> handle C++ name mangling, the special C++ calling convention, >>> access virtual, non-virtual, overloaded functions, but finally >>> gave up >>> because the binary layout (function tables, member variables, and >>> so on) >>> of C++ objects is way too complicated and undocumented. >> >> Have you read the book Inside The C++ Object Model?: > It's probably out of date now, but I'm about halfway through it and it >> >> documents a ton of the little unexpected optimizations and such that >> cause the binary layout to be complex. How did you get as far as you >> did without having figured out the layout? (e.g. if you could access >> virtual functions you must have known how to get at the virtual >> table) > > I found a lot of material on the web, also I used the (very good) > visual > studio debugger, and finally I did a lot of experimentation. We > were only > able to access some very simple C++ objects. > > There is also a patent or patents from MS about the vtable. > > All in all, as I said, IMO it is too complicated to figure out the > binary > layout of the C++ objects (without using a C++ compiler), also there > are > quite some Python packages for accessing them. Hi Thomas, We're weighing options for accessing C++ objects via Python. I know of SIWG and Boost; are there others that you think deserve consideration? I've been happy with ctypes in my limited exposure to it and would love to find a way to make that work. This thread has been very interesting to me. Thanks Philip From theller at python.net Thu Jun 4 16:07:10 2009 From: theller at python.net (Thomas Heller) Date: Thu, 04 Jun 2009 22:07:10 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <78qnreF1nkqu7U1@mid.individual.net> Philip Semanchuk schrieb: > Hi Thomas, > We're weighing options for accessing C++ objects via Python. I know of > SIWG and Boost; are there others that you think deserve consideration? I haven't used any of them myself. A common suggestion is SIP, less known are pybindgen and Robin. But there may be many more, and others with more experience might have much more to say about them. Also there is Roman Yokavenko's pygccxml which has a lot of stuff. > I've been happy with ctypes in my limited exposure to it and would > love to find a way to make that work. This thread has been very > interesting to me. Unfortunately there is no solution in sight, with ctypes. From gagsl-py2 at yahoo.com.ar Thu Jun 4 16:14:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 17:14:26 -0300 Subject: import sqlite3 References: Message-ID: En Thu, 04 Jun 2009 03:14:18 -0300, willgun escribi?: > I'm a student from China.It's painful for us to read python > documentation entirely due to poor english.So I often make these > mistakes. Try "chinese python group" at Google - I see some promising results at least... -- Gabriel Genellina From pruebauno at latinmail.com Thu Jun 4 16:17:35 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 4 Jun 2009 13:17:35 -0700 (PDT) Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Message-ID: <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> On Jun 3, 3:36?pm, a... at pythoncraft.com (Aahz) wrote: > In article <7c93031a-235e-4e13-bd37-7c9dbc6e8... at r16g2000vbn.googlegroups.com>, > > > > ? wrote: > >Should I open a bug report for this? > > >Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> import os > >>>> os.popen('cat','w') > > > > >Python 3.1rc1 (r31rc1:73054, Jun ?1 2009, 10:49:24) [C] on aix5 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> os.popen('cat','w') > >Traceback (most recent call last): > > ?File "", line 1, in > > ?File "/Python-3.1rc1/Lib/os.py", line 641, in popen > > ? ?return _wrap_close(io.TextIOWrapper(proc.stdin), proc) > >IOError: [Errno 29] Illegal seek > > What happens in 2.6 and 3.0? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "Given that C++ has pointers and typecasts, it's really hard to have a > serious conversation about type safety with a C++ programmer and keep a > straight face. ?It's kind of like having a guy who juggles chainsaws > wearing body armor arguing with a guy who juggles rubber chickens wearing > a T-shirt about who's in more danger." ?--Roy Smith, c.l.py, 2004.05.23 Python 2.6.2 (r262:71600, Jun 4 2009, 16:07:26) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') >>> Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') So it seems to be something in 3.1 that causes it to fail. BTW it is not like I use os.popen a lot. I found this problem while trying to use help(). Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> help(open) Traceback (most recent call last): File "", line 1, in File "/Python-3.1rc1/Lib/site.py", line 429, in __call__ return pydoc.help(*args, **kwds) File "/Python-3.1rc1/Lib/pydoc.py", line 1709, in __call__ self.help(request) File "/Python-3.1rc1/Lib/pydoc.py", line 1756, in help else: doc(request, 'Help on %s:') File "/Python-3.1rc1/Lib/pydoc.py", line 1505, in doc pager(render_doc(thing, title, forceload)) File "/Python-3.1rc1/Lib/pydoc.py", line 1320, in pager pager(text) File "/Python-3.1rc1/Lib/pydoc.py", line 1340, in return lambda text: pipepager(text, 'less') File "/Python-3.1rc1/Lib/pydoc.py", line 1359, in pipepager pipe = os.popen(cmd, 'w') File "/Python-3.1rc1/Lib/os.py", line 641, in popen return _wrap_close(io.TextIOWrapper(proc.stdin), proc) IOError: [Errno 29] Illegal seek >>> From Brian.Mingus at colorado.edu Thu Jun 4 16:23:36 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 14:23:36 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <78qnreF1nkqu7U1@mid.individual.net> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> Message-ID: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> What is the goal of this conversation that goes above and beyond what Boost.Python + pygccxml achieve? Boost has published a variety of libraries that will be included into the next c++ standard. It's hard to imagine a better designed python/c++ interface library than Boost.Python. Further, pygccxml is amazing with regards to scanning your source code using gcc itself and then using that xml representation to write out the Boost.Python code. What more do people in this conversation want? On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller wrote: > Philip Semanchuk schrieb: > > > Hi Thomas, > > We're weighing options for accessing C++ objects via Python. I know of > > SIWG and Boost; are there others that you think deserve consideration? > > I haven't used any of them myself. A common suggestion is SIP, > less known are pybindgen and Robin. But there may be many more, > and others with more experience might have much more to say about them. > Also there is Roman Yokavenko's pygccxml which has a lot of stuff. > > > I've been happy with ctypes in my limited exposure to it and would > > love to find a way to make that work. This thread has been very > > interesting to me. > > Unfortunately there is no solution in sight, with ctypes. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Thu Jun 4 16:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 15:29:41 -0500 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 02 Jun 2009 10:54:48 +1200, Lawrence D'Oliveiro wrote: > > > In message , Albert van der Horst wrote: > > > >> An indication of how one can see one is in emacs is also appreciated. > > > > How about, hit CTRL/G and see if the word "Quit" appears somewhere. > > Ah, one has to love user interfaces designed with mnemonic keyboard > commands so as to minimize the burden of rote learning on the user. > Presumably it is G for "Get me the frack outta here!". > > Having noted that the word "Quit" does appear, how do you then *actually* > Quit? Apart from taunting the user, what is it that Ctrl-G is actually > doing when it displays the word "Quit" in what seems to be some sort of > status bar? I love the idea of emacs taunting the user - it is like all that lisp code suddenly became self aware and decided to join in ;-) Ctrl-G is the emacs interrupt sequence. It cancels what you are doing. Kind of like Ctrl-C in the shell. You quit emacs with Ctrl-X Ctrl-C. Save a document with Ctrl-X Ctrl-S that that is probably enough for the emacs survival guide! If you run emacs in a windowing environment (eg X-Windows or Windows) you actually get menus you can choose save and quit off! Anyway, wrenching the thread back on topic - I use emacs for all my python editing needs (on linux, windows and mac) with pymacs or python-mode (depending on distro). I use the subversion integration extensively. The interactive features of emacs are really useful for testing python code - even more useful than the python interactive prompt for bits of code longer than a line or too. (Open a new window in python mode, type stuff, press Ctrl-C Ctrl-C and have the output shown in a different window. If you messed up, clicking on the error will put the cursor in the right place in the code). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From tjreedy at udel.edu Thu Jun 4 16:41:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 16:41:31 -0400 Subject: Illegal seek with os.popen In-Reply-To: <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> Message-ID: pruebauno at latinmail.com wrote: > Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > > So it seems to be something in 3.1 that causes it to fail. > BTW it is not like I use os.popen a lot. I found this problem while > trying to use help(). > > Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 > Type "help", "copyright", "credits" or "license" for more information. >>>> help(open) On Windows xp, this works fine. > Traceback (most recent call last): > File "", line 1, in > File "/Python-3.1rc1/Lib/site.py", line 429, in __call__ > return pydoc.help(*args, **kwds) > File "/Python-3.1rc1/Lib/pydoc.py", line 1709, in __call__ > self.help(request) > File "/Python-3.1rc1/Lib/pydoc.py", line 1756, in help > else: doc(request, 'Help on %s:') > File "/Python-3.1rc1/Lib/pydoc.py", line 1505, in doc > pager(render_doc(thing, title, forceload)) > File "/Python-3.1rc1/Lib/pydoc.py", line 1320, in pager > pager(text) > File "/Python-3.1rc1/Lib/pydoc.py", line 1340, in > return lambda text: pipepager(text, 'less') > File "/Python-3.1rc1/Lib/pydoc.py", line 1359, in pipepager > pipe = os.popen(cmd, 'w') > File "/Python-3.1rc1/Lib/os.py", line 641, in popen > return _wrap_close(io.TextIOWrapper(proc.stdin), proc) > IOError: [Errno 29] Illegal seek Now is the time to file a bug report for this and os.popen problem;) From python at mrabarnett.plus.com Thu Jun 4 16:49:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Jun 2009 21:49:01 +0100 Subject: multi-core software In-Reply-To: <20090616103324.200@gmail.com> References: <20090616103324.200@gmail.com> Message-ID: <4A28333D.6030304@mrabarnett.plus.com> Kaz Kylheku wrote: > ["Followup-To:" header set to comp.lang.lisp.] > On 2009-06-04, Roedy Green wrote: >> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >> wrote, quoted or indirectly quoted someone who said : >> >>> ? Why Must Software Be Rewritten For Multi-Core Processors? >> Threads have been part of Java since Day 1. > > Unfortunately, not sane threads designed by people who actually understand > multithreading. > >> The nice thing about Java is whether you are on a single core >> processor or a 256 CPU machine (We got to run our Athena Integer Java >> spreadsheet engine on such a beast), does not concern your code. > > You are dreaming if you think that there are any circumstances (other than > circumstances in which performance doesn't matter) in which you don't have to > concern yourself about the difference between a uniprocessor and a 256 CPU > machine. If you're interested in parallel programming, have a look at Flow-Based Programming: http://www.jpaulmorrison.com/fbp/ From philip at semanchuk.com Thu Jun 4 16:54:01 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 16:54:01 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> On Jun 4, 2009, at 4:23 PM, Brian wrote: > What is the goal of this conversation that goes above and beyond what > Boost.Python + pygccxml achieve? Boost has published a variety of > libraries > that will be included into the next c++ standard. It's hard to > imagine a > better designed python/c++ interface library than Boost.Python. > Further, > pygccxml is amazing with regards to scanning your source code using > gcc > itself and then using that xml representation to write out the > Boost.Python > code. What more do people in this conversation want? Hi Brian, I've only experimented with SWIG (and ctypes for wrapping a C library). We're not yet sold on using SWIG to wrap our C++ libraries and so we're exploring alternatives. Before I started with SWIG, I did some research to see what other folks were using. The arguments I recall reading that swayed me to try SWIG before Boost were -- - Boost involves more "magic" than SWIG which means it does a bit more work for you, but when things go wrong (i.e. interface won't compile or doesn't work as expected) it is very difficult to debug. - Boost-ed code requires a Boost runtime library. This isn't a showstopper problem, obviously, but it's a mark against since it adds yet another prerequisite to our install process. - Boost's generated code can take a long time to compile. I don't know what pygccxml adds to the equation, so perhaps some of those disadvantages disappear with Boost.Python + pygccxml versus just plain Boost.Python. If you'd like to expound on this, feel free. I'd appreciate the education. I don't know about what Boost (or any other tool) generates, but the interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm amazed at what it can do. Nevertheless the generated interface has all the charm of a Babelfish translation. I imagine lots of autogenerated code looks "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are lost and it's eminently clear that it was not created by a native speaker. Until there's an interface generation tool that can build an interface that makes the wrapped library look completely Pythonic, then choosing a tool will be a matter of choosing which compromises you want to make. As long as that's true, I think there's room for multiple library-wrapping packages, just like there's room for more than one programming language in the world. Cheers Philip > > > On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller > wrote: > >> Philip Semanchuk schrieb: >> >>> Hi Thomas, >>> We're weighing options for accessing C++ objects via Python. I >>> know of >>> SIWG and Boost; are there others that you think deserve >>> consideration? >> >> I haven't used any of them myself. A common suggestion is SIP, >> less known are pybindgen and Robin. But there may be many more, >> and others with more experience might have much more to say about >> them. >> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >> >>> I've been happy with ctypes in my limited exposure to it and would >>> love to find a way to make that work. This thread has been very >>> interesting to me. >> >> Unfortunately there is no solution in sight, with ctypes. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From Brian.Mingus at colorado.edu Thu Jun 4 17:01:17 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 15:01:17 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> Message-ID: <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> Well you'll just have to try Boost.Python. There is a pygccxml gui gets you started in about 15 minutes. You'll be able to see how well it groks your code and what that generated code is. Boost is the best. People complain about it because they don't understand C++ templates and they don't realize how incredibly well designed it is. If you don't know the basics it's this: Boost.Python uses meta template programming. This allows it to use the C++ preprocessor for what other binding systems generally write a custom tool for. Long compile times are not a real problem for anyone - it's easy to set up a compile farm and the benefit is that your runtime code is blazing fast. In my opinion Boost is more sophisticated, SWIG, etc.. is more of a hack. Of course they all help you get the job done. On Thu, Jun 4, 2009 at 2:54 PM, Philip Semanchuk wrote: > > On Jun 4, 2009, at 4:23 PM, Brian wrote: > > What is the goal of this conversation that goes above and beyond what >> Boost.Python + pygccxml achieve? Boost has published a variety of >> libraries >> that will be included into the next c++ standard. It's hard to imagine a >> better designed python/c++ interface library than Boost.Python. Further, >> pygccxml is amazing with regards to scanning your source code using gcc >> itself and then using that xml representation to write out the >> Boost.Python >> code. What more do people in this conversation want? >> > > Hi Brian, > I've only experimented with SWIG (and ctypes for wrapping a C library). > We're not yet sold on using SWIG to wrap our C++ libraries and so we're > exploring alternatives. Before I started with SWIG, I did some research to > see what other folks were using. The arguments I recall reading that swayed > me to try SWIG before Boost were -- > - Boost involves more "magic" than SWIG which means it does a bit more work > for you, but when things go wrong (i.e. interface won't compile or doesn't > work as expected) it is very difficult to debug. > - Boost-ed code requires a Boost runtime library. This isn't a showstopper > problem, obviously, but it's a mark against since it adds yet another > prerequisite to our install process. > - Boost's generated code can take a long time to compile. > > I don't know what pygccxml adds to the equation, so perhaps some of those > disadvantages disappear with Boost.Python + pygccxml versus just plain > Boost.Python. If you'd like to expound on this, feel free. I'd appreciate > the education. > > I don't know about what Boost (or any other tool) generates, but the > interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm > amazed at what it can do. Nevertheless the generated interface has all the > charm of a Babelfish translation. I imagine lots of autogenerated code looks > "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are > lost and it's eminently clear that it was not created by a native speaker. > > Until there's an interface generation tool that can build an interface that > makes the wrapped library look completely Pythonic, then choosing a tool > will be a matter of choosing which compromises you want to make. As long as > that's true, I think there's room for multiple library-wrapping packages, > just like there's room for more than one programming language in the world. > > Cheers > Philip > > > > > >> >> On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller wrote: >> >> Philip Semanchuk schrieb: >>> >>> Hi Thomas, >>>> We're weighing options for accessing C++ objects via Python. I know of >>>> SIWG and Boost; are there others that you think deserve consideration? >>>> >>> >>> I haven't used any of them myself. A common suggestion is SIP, >>> less known are pybindgen and Robin. But there may be many more, >>> and others with more experience might have much more to say about them. >>> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >>> >>> I've been happy with ctypes in my limited exposure to it and would >>>> love to find a way to make that work. This thread has been very >>>> interesting to me. >>>> >>> >>> Unfortunately there is no solution in sight, with ctypes. >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> -- >> 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 Brian.Mingus at colorado.edu Thu Jun 4 17:27:11 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 15:27:11 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> Message-ID: <9839a05c0906041427l270b9be8m94e7dcc89b18d9af@mail.gmail.com> Just to expound a bit on pygccxml, which really makes boost worth it. pygccxml enables you to do all of your binding work from within Python. It calls gccxml, which is an xml backend to gcc that outputs the parse tree in an xml format. Pygccxml provides a very high level interface between the gcc xml representation and the pygccxml boost code generator. It's really a great thing. You just have to learn to read the code that pygccxml outputs for boost, and then go back to python and use the high level interface to modify the code that it outputs. It has all sorts of selectors so you can operate on all code that has certain arbitrary properties all at the same time. Play with it before deciding on swig. It's frikkin' cool :) On Thu, Jun 4, 2009 at 3:01 PM, Brian wrote: > Well you'll just have to try Boost.Python. There is a pygccxml gui gets you > started in about 15 minutes. You'll be able to see how well it groks your > code and what that generated code is. > > Boost is the best. People complain about it because they don't understand > C++ templates and they don't realize how incredibly well designed it is. > > If you don't know the basics it's this: Boost.Python uses meta template > programming. This allows it to use the C++ preprocessor for what other > binding systems generally write a custom tool for. Long compile times are > not a real problem for anyone - it's easy to set up a compile farm and the > benefit is that your runtime code is blazing fast. > > In my opinion Boost is more sophisticated, SWIG, etc.. is more of a hack. > Of course they all help you get the job done. > > > On Thu, Jun 4, 2009 at 2:54 PM, Philip Semanchuk wrote: > >> >> On Jun 4, 2009, at 4:23 PM, Brian wrote: >> >> What is the goal of this conversation that goes above and beyond what >>> Boost.Python + pygccxml achieve? Boost has published a variety of >>> libraries >>> that will be included into the next c++ standard. It's hard to imagine a >>> better designed python/c++ interface library than Boost.Python. Further, >>> pygccxml is amazing with regards to scanning your source code using gcc >>> itself and then using that xml representation to write out the >>> Boost.Python >>> code. What more do people in this conversation want? >>> >> >> Hi Brian, >> I've only experimented with SWIG (and ctypes for wrapping a C library). >> We're not yet sold on using SWIG to wrap our C++ libraries and so we're >> exploring alternatives. Before I started with SWIG, I did some research to >> see what other folks were using. The arguments I recall reading that swayed >> me to try SWIG before Boost were -- >> - Boost involves more "magic" than SWIG which means it does a bit more >> work for you, but when things go wrong (i.e. interface won't compile or >> doesn't work as expected) it is very difficult to debug. >> - Boost-ed code requires a Boost runtime library. This isn't a showstopper >> problem, obviously, but it's a mark against since it adds yet another >> prerequisite to our install process. >> - Boost's generated code can take a long time to compile. >> >> I don't know what pygccxml adds to the equation, so perhaps some of those >> disadvantages disappear with Boost.Python + pygccxml versus just plain >> Boost.Python. If you'd like to expound on this, feel free. I'd appreciate >> the education. >> >> I don't know about what Boost (or any other tool) generates, but the >> interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm >> amazed at what it can do. Nevertheless the generated interface has all the >> charm of a Babelfish translation. I imagine lots of autogenerated code looks >> "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are >> lost and it's eminently clear that it was not created by a native speaker. >> >> Until there's an interface generation tool that can build an interface >> that makes the wrapped library look completely Pythonic, then choosing a >> tool will be a matter of choosing which compromises you want to make. As >> long as that's true, I think there's room for multiple library-wrapping >> packages, just like there's room for more than one programming language in >> the world. >> >> Cheers >> Philip >> >> >> >> >> >>> >>> On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller >>> wrote: >>> >>> Philip Semanchuk schrieb: >>>> >>>> Hi Thomas, >>>>> We're weighing options for accessing C++ objects via Python. I know of >>>>> SIWG and Boost; are there others that you think deserve consideration? >>>>> >>>> >>>> I haven't used any of them myself. A common suggestion is SIP, >>>> less known are pybindgen and Robin. But there may be many more, >>>> and others with more experience might have much more to say about them. >>>> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >>>> >>>> I've been happy with ctypes in my limited exposure to it and would >>>>> love to find a way to make that work. This thread has been very >>>>> interesting to me. >>>>> >>>> >>>> Unfortunately there is no solution in sight, with ctypes. >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >>>> >>>> -- >>> 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 aahz at pythoncraft.com Thu Jun 4 17:28:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 14:28:07 -0700 Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> Message-ID: [posted & e-mailed] In article <5edde6ee-4446-4f53-91ee-ad3aea4b5603 at q37g2000vbi.googlegroups.com>, wrote: > >Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > >So it seems to be something in 3.1 that causes it to fail. >BTW it is not like I use os.popen a lot. I found this problem while >trying to use help(). Please file a report on bugs.python.org and send a note to python-dev. Thanks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From reagle at mit.edu Thu Jun 4 17:30:58 2009 From: reagle at mit.edu (Joseph Reagle) Date: Thu, 04 Jun 2009 17:30:58 -0400 Subject: MultiReplace (performance and unordered dicts) Message-ID: I have programs that do lots of string-to-string replacements, so I'm trying to create a speedy implementation (tons of .replace statements has become unwieldy). My MultiReplace object does as well as the function regexp, which both do better than the for loop function, any other suggestions? def multi_repl(text, subs): for ori, sub in subs: text = text.replace(ori, sub) return text import string latex_esc_dic = dict(latex_esc) latex_esc_ori, latex_esc_rep = zip(*latex_esc) def symbol_replace(match, get=latex_esc_dic.get): return get(match.group(1), "") symbol_pattern = re.compile( "(" + string.join(map(re.escape, latex_esc_ori), "|") + ")" ) class MultiReplace(object): """ Replace multiple instances from a list of ori/rep pairs. I use an object for performance: compiled regexes persist. Table is a list of pairs, I have to convert to dict for regex replace function, don't use a dict natively since they aren't ordered. """ def __init__(self, table): print "initing object" self.originals, self.replacements = zip(*table) self.pattern = re.compile( "(" + string.join(map(re.escape, self.originals), "|") + ")" ) self.table_dic = dict(table) def _get_replacement(self, match): # passed match #print "replacing %s with %s" % (match.group(1), self.table_dic.get(match.group(1), "")) return self.table_dic.get(match.group(1), "") # use match to return replacement def replace(self, line): return self.pattern.sub(self._get_replacement, line) # pass replacement function mr = MultiReplace(latex_esc) ... #line = multi_repl(line, latex_esc) # 0.406 #line = symbol_pattern.sub(symbol_replace, line) #0.385 line = mr.replace(line) #0.385 From brian at sweetapp.com Thu Jun 4 17:40:07 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 14:40:07 -0700 Subject: Odd closure issue for generators Message-ID: <4A283F37.3020703@sweetapp.com> This is from Python built from the py3k branch: >>> c = (lambda : i for i in range(11, 16)) >>> for q in c: ... print(q()) ... 11 12 13 14 15 >>> # This is expected >>> c = (lambda : i for i in range(11, 16)) >>> d = list(c) >>> for q in d: ... print(q()) ... 15 15 15 15 15 >>> # I was very surprised Looking at the implementation, I see why this happens: >>> c = (lambda : i for i in range(11, 16)) >>> for q in c: ... print(id(q.__closure__[0])) ... 3847792 3847792 3847792 3847792 3847792 >>> # The same closure is used by every lambda But it seems very odd to me and it can lead to some problems that are a real pain in the ass to debug. Cheers, Brian From joseph.h.garvin at gmail.com Thu Jun 4 18:16:07 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Thu, 4 Jun 2009 17:16:07 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: On Thu, Jun 4, 2009 at 3:23 PM, Brian wrote: > What is the goal of this conversation that goes above and beyond what > Boost.Python + pygccxml achieve? I can't speak for others but the reason I was asking is because it's nice to be able to define bindings from within python. At a minimum, compiling bindings means a little extra complexity to address with whatever build tools you're using. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:19:57 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:19:57 +1200 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In message , Nick Craig- Wood wrote: > You quit emacs with Ctrl-X Ctrl-C. That's "save-buffers-kill-emacs". If you don't want to save buffers, the exit sequence is alt-tilde, f, e. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:20:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:20:26 +1200 Subject: What text editor is everyone using for Python References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In message , Albert van der Horst wrote: > Memories of Atari 260/520/1040 that had a keyboard with a key actually > marked ... HELP. And the OLPC machines have a key marked "reveal source". From joseph.h.garvin at gmail.com Thu Jun 4 18:23:45 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Thu, 4 Jun 2009 17:23:45 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <4A2821F9.6080901@ctypes.org> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: On Thu, Jun 4, 2009 at 2:35 PM, Thomas Heller wrote: > [Please keep the discussion on the list] > > All in all, as I said, IMO it is too complicated to figure out the binary > layout of the C++ objects (without using a C++ compiler), also there are > quite some Python packages for accessing them. Requiring that the C++ compiler used to make the dll's/so's to be the same one Python is compiled with wouldn't be too burdensome would it? Because then you could have it run a bunch of configure tests to determine information exposing the layout. I don't know if everything is testable, but you can for example (I learned this from the object model book btw) write a C++ program that determines whether the virtual function table is stored at the beginning or the end of an object by comparing the address of an object with a virtual function to the address of its first data member. If they're different, it's because the vptr is stored there, otherwise it's on the end (theoretically it could be in the middle but there's no reason for compiler writers to do that). cpptypes could then use information generated by tests like this that are run when the interpreter is compiled. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:26:34 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:26:34 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > 1) Do you use virtualpython? No idea what that is. > 2) How do you load the modules in your lib directory? At the beginning of my scripts, I have a sequence like test_mode = False # True for testing, False for production if test_mode : home_dir = "/home/shop-test" else : home_dir = "/home/shop" #end if sys.path.append(home_dir + "/lib") import common [etc] I have an installation script that looks for that "test_mode = True/False" assignment and edits it accordingly. That flag is used to select the top- level directory (as above) as well as the database name, etc. This allows me to run two complete parallel sets of code and data, so I can mess around with the testing version without impacting the production system. > 3) How do you reference your configuration directives from within your > modules and CGI/daemon scripts? For my last project using the above system, I used XML as the config file format. From robert.kern at gmail.com Thu Jun 4 18:44:43 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Jun 2009 17:44:43 -0500 Subject: "where" in python In-Reply-To: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> References: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-04 12:53, Chris wrote: > I am a newby in Python and I'm first looking for equivalent to things > I already manage: IDL. > For example, I want to plot a sub-set of points, selected from a > bigger set by applying some filter. In my example, I want to select > only the values> 0. > I succeed to write 5 different ways to do this, which one is the more > efficient, the quicker, the more Python? You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists The 1st method. The rest just do a lot of extra work or use old APIs. > It seems the 4th method give wrong results, but I don't know why... > Thanks for your tips, > Christophe > ------------------------------------------------------------------------------------------ > import pylab as pylab > import numpy as numpy You don't need to use "as" unless if you are renaming the modules. -- 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 gagsl-py2 at yahoo.com.ar Thu Jun 4 19:02:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 20:02:35 -0300 Subject: Odd closure issue for generators References: <4A283F37.3020703@sweetapp.com> Message-ID: En Thu, 04 Jun 2009 18:40:07 -0300, Brian Quinlan escribi?: > This is from Python built from the py3k branch: It's not new; same thing happens with 2.x A closure captures (part of) the enclosing namespace, so names are resolved in that environment even after the enclosing block has finished execution. As always, the name->value evaluation happens when it is required at runtime, not earlier ("late binding"). So, in the generator expression (lambda : i for i in range(11, 16)) the 'i' is searched in the enclosing namespace when the lambda is evaluated, not when the lambda is created. Your first example: > [1] >>> c = (lambda : i for i in range(11, 16)) > [2] >>> for q in c: > [3] ... print(q()) > ... > 11 > 12 > 13 > 14 > 15 > >>> # This is expected This code means: [1] create a generator expression and name it `c` [2] ask `c` for an iterator. A generator is its own iterator, so returns itself. Loop begins: Ask the iterator a new item (the first one, in fact). So the generator executes one cycle, yields a lambda expression, and freezes. Note that the current value of `i` (in that frozen environment) is 11. Name the yielded object (the lambda) `q`. [3] Call the q object. That means, execute the lambda. It returns the current value of i, 11. Print it. Back to [2]: ask the iterator a new item. The generator resumes, executes another cycle, yields another lambda expression, and freezes. Now, i is 12 inside the frozen environment. [3] execute the lambda -> 12 etc. Your second example: > [4] >>> c = (lambda : i for i in range(11, 16)) > [5] >>> d = list(c) > [6] >>> for q in d: > [7] ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 > >>> # I was very surprised [4] creates a generator expression same as above. [5] ask for an iterator (c itself). Do the iteration NOW until exhaustion, and collect each yielded object into a list. Those objects will be lambdas. The current (and final) value of i is 15, because the range() iteration has finished. [6] iterate over the list... [7] ...and execute each lambda. At this time, `i` is always 15. > Looking at the implementation, I see why this happens: > >>> c = (lambda : i for i in range(11, 16)) > >>> for q in c: > ... print(id(q.__closure__[0])) > ... > 3847792 > 3847792 > 3847792 > 3847792 > 3847792 > >>> # The same closure is used by every lambda ...because all of them refer to the same `i` name. > But it seems very odd to me and it can lead to some problems that are a > real pain in the ass to debug. Yes, at least if one is not aware of the consequences. I think this (or a simpler example) should be explained in the FAQ. The question comes in this list again and again... -- Gabriel Genellina From Scott.Daniels at Acm.Org Thu Jun 4 19:07:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 16:07:54 -0700 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: Joseph Garvin wrote: > On Thu, Jun 4, 2009 at 2:35 PM, Thomas Heller wrote: >> [Please keep the discussion on the list] >> >> All in all, as I said, IMO it is too complicated to figure out the binary >> layout of the C++ objects (without using a C++ compiler), also there are >> quite some Python packages for accessing them. > > Requiring that the C++ compiler used to make the dll's/so's to be the > same one Python is compiled with wouldn't be too burdensome would it? And what gave you then impression that Python is compiled with a C++ compiler? --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Thu Jun 4 19:18:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 4 Jun 2009 16:18:32 -0700 (PDT) Subject: Odd closure issue for generators References: Message-ID: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> On Jun 4, 2:40?pm, Brian Quinlan wrote: > This is from Python built from the py3k branch: > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> for q in c: > ... ? ? print(q()) > ... > 11 > 12 > 13 > 14 > 15 > ?>>> # This is expected > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> d = list(c) > ?>>> for q in d: > ... ? ? print(q()) > ... > 15 > 15 > 15 > 15 > 15 > ?>>> # I was very surprised > > Looking at the implementation, I see why this happens: > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> for q in c: > ... ? ? print(id(q.__closure__[0])) > ... > 3847792 > 3847792 > 3847792 > 3847792 > 3847792 > ?>>> # The same closure is used by every lambda > > But it seems very odd to me and it can lead to some problems that are a > real pain in the ass to debug. It's really the only sane way to handle it, odd though it may seem in this narrow case. In Python nested functions have to be able to reference the current value of a variable because of use cases like this: def func(): def printx(): print x x = 1 printx() x = 2 printx() Referencing a nonlocal variable always uses the current (or last) value of that variable, not the value it had when the nested function was defined. The way to handle the issue you are seeing is to create a new scope with a variable the remains at the value you want to close upon: create_const_function(value): def func(): return value c = (create_const_function(i) for i in range(11, 16)) Or you can do it the slacker way and use a default argument: c = (lambda i=i: i for i in range(11, 16)) Carl Banks From ppearson at nowhere.invalid Thu Jun 4 19:24:46 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 4 Jun 2009 23:24:46 GMT Subject: easiest way to plot x,y graphically during run-time? References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <78r3dtF1nmabfU1@mid.individual.net> On Thu, 04 Jun 2009 03:29:42 -0500, Nick Craig-Wood wrote: [snip] > Here is a demo with pygame... [snip] And just for completeness, here is a demo with PyGUI, written in similar style. (I'm a PyGUI newbie, so constructive criticism would be appreciated.) from GUI import Window, View, application, Color, Task from random import randrange class Brownian( View ): def __init__( self, **kwargs ): View.__init__( self, **kwargs ) width, height = self.size self.dots = [ (randrange(width), randrange(height)) for _ in range( 100 ) ] def step( self ): self.dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in self.dots ] self.invalidate() def draw( self, canvas, rectangle ): canvas.set_backcolor( Color( 0, 0, 0 ) ) canvas.set_forecolor( Color( 0.3, 0.85, 0.25 ) ) radius = 10 canvas.erase_rect( rectangle ) for dot in self.dots: canvas.stroke_oval( ( dot[0]-radius, dot[1]-radius, dot[0]+radius, dot[1]+radius ) ) def main(): size = 640, 480 win = Window( size = size, title = "A test of PyGUI" ) b = Brownian( size = size ) win.add( b ) win.show() t = Task( b.step, interval = 0.02, repeat = True, start = True ) application().run() if __name__ == "__main__": main() -- To email me, substitute nowhere->spamcop, invalid->net. From Scott.Daniels at Acm.Org Thu Jun 4 19:42:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 16:42:07 -0700 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: Brian Quinlan wrote: > This is from Python built from the py3k branch: > >>> c = (lambda : i for i in range(11, 16)) > >>> for q in c: > ... print(q()) > ... > 11 > 12 > 13 > 14 > 15 > >>> # This is expected > >>> c = (lambda : i for i in range(11, 16)) > >>> d = list(c) > >>> for q in d: > ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 > >>> # I was very surprised You are entitled to be surprised. Then figure out what is going on. Hint: it is the moral equivalent of what is happening here: >>> c = [] >>> for i in range(11, 16): c.append(lambda: i) >>> i = 'Surprise!' >>> print([f() for f in c]) ['Surprise!', 'Surprise!', 'Surprise!', 'Surprise!', 'Surprise!'] >>> i = 0 >>> print([f() for f in c]) [0, 0, 0, 0, 0] The body of your lambda is an un-evaluated expression with a reference, not an expression evaluated at the time of loading c. TO get what you expected, try this: >>> c = [] >>> for i in range(11, 16): c.append(lambda i=i: i) >>> i = 'Surprise!' >>> print([f() for f in c]) [11, 12, 13, 14, 15] When you evaluate a lambda expression, the default args are evaluated, but the expression inside the lambda body is not. When you apply that evaluated lambda expression, the expression inside the lambda body is is evaluated and returned. --Scott David Daniels Scott.Daniels at Acm.Org From ebonak at hotmail.com Thu Jun 4 19:49:18 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:49:18 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Nick Craig-Wood wrote: > > Here is a demo with pygame... > Thanks Nick, I'll be studying this too :-) Esmail From ebonak at hotmail.com Thu Jun 4 19:49:43 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:49:43 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78r3dtF1nmabfU1@mid.individual.net> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <78r3dtF1nmabfU1@mid.individual.net> Message-ID: Peter Pearson wrote: > On Thu, 04 Jun 2009 03:29:42 -0500, Nick Craig-Wood wrote: > [snip] >> Here is a demo with pygame... > [snip] > > And just for completeness, here is a demo with PyGUI, written > in similar style. Thanks for this too! Esmail From ebonak at hotmail.com Thu Jun 4 19:52:38 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:52:38 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A285E46.1090704@hotmail.com> Scott David Daniels wrote: > Esmail wrote: >> Scott David Daniels wrote: >>> Esmail wrote: >>>> ... Tk seems a bit more complex .. but I really don't know much about >>>> it and its interface with Python to make any sort of judgments as >>>> to which option would be better. >>> >>> This should look pretty easy: >> >> Thanks Scott for taking the time to share this code with me, it >> will give me something to study. I'm not sure if I'd say it looks >> easy (but then again I am not very familiar with Tk :-) > > I threw in too much, I think. :-) Tk seems quite capable, perhaps a bit more than I need for my simple visualization task at the moment (visualizing a PSO), but I'll probably investigate it when I have more ambitious GUI needs or am doing more than plotting the movement of particles on a 2D surface. Thanks again for sharing your code and explanations with me, a great way to learn. Esmail From vincent at vincentdavis.net Thu Jun 4 20:18:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 18:18:32 -0600 Subject: import _sqlite3 no module named error In-Reply-To: References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> Message-ID: <77e831100906041718k4b4f54d9v29729449c50f3cb@mail.gmail.com> On Thu, Jun 4, 2009 at 1:41 PM, Ned Deily wrote: > In article > <77e831100906041151g70868dbre1546cdb01082ba3 at mail.gmail.com>, > ?Vincent Davis wrote: >> Yes I am using macports I think sqlite is installed? here is what I >> get when I run >> sudo port install py25-sqlite3 >> >> vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 >> Skipping org.macports.activate (py25-sqlite3 ) since this port is already >> active >> ---> ?Cleaning py25-sqlite3 >> vincent-daviss-macbook-pro-2:~ vmd$ > > Hmm! ?This is on 10.5.7, BTW. > > $ sudo port version > Version: 1.710 > $ sudo port info py25-sqlite3 > py25-sqlite3 @2.5.4 (python, databases) > [...] > $ /opt/local/bin/python2.5 > Python 2.5.4 (r254:67916, May ?4 2009, 01:40:08) > [GCC 4.0.1 (Apple Inc. build 5490)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from _sqlite3 import * >>>> > > A quick web search shows that there were apparently some issues with > MacPort's py25-sqlite3 in the not too distant past. ?Perhaps your ports > need to be upgraded? > > $ sudo port selfupdate > or > $ sudo port sync > > $ sudo port upgrade installed Also 10.5.7 my self, I have completely removed and reinstall macport and all the ports. All befor posting this thread... here is what i get, jhgfjhgfjhg it is working now, I have no clue. I went on a bike ride and now it works? Thanks for you help. What do you know about python_select, .bash_profile and .profile? From johnnyz86 at gmail.com Thu Jun 4 20:37:42 2009 From: johnnyz86 at gmail.com (Johnny Chang) Date: Thu, 4 Jun 2009 17:37:42 -0700 (PDT) Subject: Printing list/tuple elements on separate lines Message-ID: I have a large list of strings that I am unpacking and splitting, and I want each one to be on a new line. Someone showed me how to do it and I got it working, except it is not printing each on its own separate line as his did, making it incredibly hard to read. He did it without adding a new line for anything. I can't get in touch with him right now. An example: recs = 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' [(rec.split('f')) for rec in recs] output: [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] desired output: [['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', '']] From apt.shansen at gmail.com Thu Jun 4 20:46:33 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 4 Jun 2009 17:46:33 -0700 Subject: Printing list/tuple elements on separate lines In-Reply-To: References: Message-ID: <7a9c25c20906041746m3a27ac3fxe0ff6c40bc5020af@mail.gmail.com> On Thu, Jun 4, 2009 at 5:37 PM, Johnny Chang wrote: > I have a large list of strings that I am unpacking and splitting, and > I want each one to be on a new line. Someone showed me how to do it > and I got it working, except it is not printing each on its own > separate line as his did, making it incredibly hard to read. He did > it without adding a new line for anything. I can't get in touch with > him right now. > How about-- import pprint > recs = 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' > pprint.pprint([(rec.split('f')) for rec in recs]) > --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Thu Jun 4 21:08:20 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 4 Jun 2009 18:08:20 -0700 (PDT) Subject: unladen swallow: python and llvm Message-ID: I am very excited by this project (as well as by pypy) and I read all their plan, which looks quite practical and impressive. But I must confess that I can't understand why LLVM is so great for python and why it will make a difference. AFAIK, LLVM is alot of things at the same time (a compiler infrastructure, a compilation strategy, a virtual instruction set, etc). I am also confussed at their use of the term "jit" (is LLVM a jit? Can it be used to build a jit?). Is it something like the .NET or JAVA jit? Or it can be used to implement a custom jit (ala psyco, for example)? Also, as some pypy folk said, it seems they intend to do "upfront compilation". How? Is it something along the lines of the V8 javascript engine (no interpreter, no intermediate representation)? Or it will be another interpreter implementation? If so, how will it be any better...? Well, these are a lot of questions and they only show my confussion... I would highly appreciate if someone knowledgeable sheds some light on this for me... Thanks in advance! Luis From emile at fenx.com Thu Jun 4 21:15:09 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 04 Jun 2009 18:15:09 -0700 Subject: What text editor is everyone using for Python In-Reply-To: References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > In message , Nick Craig- > Wood wrote: > >> You quit emacs with Ctrl-X Ctrl-C. > > That's "save-buffers-kill-emacs". If you don't want to save buffers, the > exit sequence is alt-tilde, f, e. > Ha ha ha ha ha! No -- really? Emile From rNOSPAMon at flownet.com Thu Jun 4 21:18:24 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 04 Jun 2009 18:18:24 -0700 Subject: Yet another unicode WTF Message-ID: Python 2.6.2 on OS X 10.5.7: [ron at mickey:~]$ echo $LANG en_US.UTF-8 [ron at mickey:~]$ cat frob.py #!/usr/bin/env python print u'\u03BB' [ron at mickey:~]$ ./frob.py ? [ron at mickey:~]$ ./frob.py > foo Traceback (most recent call last): File "./frob.py", line 2, in print u'\u03BB' UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in position 0: ordinal not in range(128) (That's supposed to be a small greek lambda, but I'm using a brain-damaged news reader that won't let me set the character encoding. It shows up correctly in my terminal.) According to what I thought I knew about unix (and I had fancied myself a bit of an expert until just now) this is impossible. Python is obviously picking up a different default encoding when its output is being piped to a file, but I always thought one of the fundamental invariants of unix processes was that there's no way for a process to know what's on the other end of its stdout. Clues appreciated. Thanks. rg From ben+python at benfinney.id.au Thu Jun 4 21:22:35 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 11:22:35 +1000 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <87r5xzmq3o.fsf@benfinney.id.au> Emile van Sebille writes: > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > > In message , Nick Craig- > > Wood wrote: > > > >> You quit emacs with Ctrl-X Ctrl-C. > > > > That's "save-buffers-kill-emacs". If you don't want to save buffers, > > the exit sequence is alt-tilde, f, e. This is an invocation of the menu system, driven by the keyboard. (Also, it's not Alt+tilde (which would be Alt+Shift+`), it's Alt+` i.e. no Shift.) It's an alternate command, and IMO is just adding confusion to the discussion. > Ha ha ha ha ha! > > No -- really? Not really. If you don't want to save buffers, you just answer ?No? when prompted by ?save-buffers-kill-emacs?, so Ctrl+X Ctrl+C is all you need to know to exit Emacs. -- \ ?Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff.? ?Jack Handey | _o__) | Ben Finney From emailamit at gmail.com Thu Jun 4 21:22:44 2009 From: emailamit at gmail.com (Amit Gupta) Date: Thu, 4 Jun 2009 18:22:44 -0700 (PDT) Subject: ctype question Message-ID: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> Hi, I have been using ctype.cdll to load a library, but I am unable to figure out how to load multiple libraries that depends on each other. E.g. I have two libraries A.so and B.so. A.so has some undefined references, and those symbols are defined in B.so. When I try to load ctypes.cdll.LoadLibrary("A.so"), it gives errors about the undefined Symbols. Even if I load B.so before loading A.so, the error remains the same (which is expected). Can someone help me to find out, how to load A.so by telling it to look for undefined symbols in B.so as well? Thanks, Amit From zac256 at gmail.com Thu Jun 4 21:24:48 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 4 Jun 2009 18:24:48 -0700 Subject: __file__ access extremely slow Message-ID: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> The section of code below, which simply gets the __file__ attribute of the imported modules, takes more than 1/3 of the total startup time. Given that many modules are complicated and even have dynamic population this figure seems very high to me. it would seem very high if one just considered the time it would take to load the pyc files off the disk vs... whatever happens when module.__file__ happens. The calculation appears to be cached though, so a subsequent check does not take very long. >From once python starts and loads the main module to after all the imports occur and this section executes takes 1.3sec. This section takes 0.5sec. Total module count is ~800. Python version is 2.5.1 Code: ################################ for module in sys.modules: try: path = module.__file__ except (AttributeError, ImportError): return ################################ -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From cdalten at gmail.com Thu Jun 4 21:26:49 2009 From: cdalten at gmail.com (chad) Date: Thu, 4 Jun 2009 18:26:49 -0700 (PDT) Subject: How do I continue after the error? Message-ID: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Let's say I have a list of 5 files. Now lets say that one of the files reads nude333.txt instead of nude3.txt. When this happens, the program generates an error and quits. What I want it to do is just skip over the bad file and continue on with the next one. Below is the actual code. It only works on the local bbs that I hang out on. Sorry. I couldn't think of the simple case that could isolate my problem. #!/usr/bin/python #The original code was written by Mr.Pardue, which sounds a lot like #fuck you import telnetlib, os import time import glob my_porn_collection = ["nude.txt", "nude2.txt", "nude333.txt", "nude4.txt", "nude5.txt"] path = 'porn/' #my_porn_collection = [] def get_files(): for infile in glob.glob( os.path.join(path, '*.txt*')): my_porn_collection.append(infile) def generate(some_naked_bitches): try: f = open(some_naked_bitches, "r") except: pass art = f.read() f.close() return art def get_name(): user = raw_input("\nUsername: ") password = raw_input("Password: ") enter_party(user, password) def enter_party(user, password): now = telnetlib.Telnet("m-net.arbornet.org") now.read_until("login: ") print "\nEntered username.." now.write(user + "\n") now.read_until("Password:") now.write(password + "\n" ) print "Entered pass.." now.read_until("m-net%") now.write("party\n") print "Entered into party.." scroll_some_porn(now) def scroll_some_porn(now): while 1: for some_titty_porn in my_porn_collection: now.write(" \n") bitch_please = generate(some_titty_porn) now.write(bitch_please) time.sleep(10) now.write(" \n") if __name__ == "__main__": #get_files() get_name() From zac256 at gmail.com Thu Jun 4 21:29:45 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 4 Jun 2009 18:29:45 -0700 Subject: __file__ access extremely slow In-Reply-To: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: <333edbe80906041829x74f51caene02a3a949ea855d7@mail.gmail.com> Sorry, there is a typo. The code should read as below to repro the problem: ################################ for module in sys.modules.itervalues(): try: path = module.__file__ except (AttributeError, ImportError): return ################################ -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jun 4, 2009 at 6:24 PM, Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > > The calculation appears to be cached though, so a subsequent check > does not take very long. > > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > ? ? ? ?try: > ? ? ? ? ? ? ? ?path = module.__file__ > ? ? ? ?except (AttributeError, ImportError): > ? ? ? ? ? ? ? ?return > ################################ > > > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From brian at sweetapp.com Thu Jun 4 21:34:41 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 18:34:41 -0700 Subject: Odd closure issue for generators In-Reply-To: References: <4A283F37.3020703@sweetapp.com> Message-ID: <4A287631.6090904@sweetapp.com> Gabriel Genellina wrote: > En Thu, 04 Jun 2009 18:40:07 -0300, Brian Quinlan > escribi?: > >> This is from Python built from the py3k branch: > > It's not new; same thing happens with 2.x > > A closure captures (part of) the enclosing namespace, so names are > resolved in that environment even after the enclosing block has finished > execution. > As always, the name->value evaluation happens when it is required at > runtime, not earlier ("late binding"). So, in the generator expression > (lambda : i for i in range(11, 16)) the 'i' is searched in the enclosing > namespace when the lambda is evaluated, not when the lambda is created. OK, I talked myself into agreeing that it is better for the generator comprehension to share a context amongst every enclosed generator expression (rather than having one context per generator expression) for consistency reasons. Thanks! Cheers, Brian From greg at cosc.canterbury.ac.nz Thu Jun 4 21:35:07 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 05 Jun 2009 13:35:07 +1200 Subject: What text editor is everyone using for Python In-Reply-To: References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <78ravuF1nbh1pU1@mid.individual.net> Albert van der Horst wrote: > Memories of Atari 260/520/1040 that had a keyboard with a key actually > marked ... HELP. Modern day Mac keyboards have one of those, too. -- Greg From jnoller at gmail.com Thu Jun 4 21:41:43 2009 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 4 Jun 2009 21:41:43 -0400 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <4222a8490906041841q6d89d5c9x623a6d9ab7ff168c@mail.gmail.com> You can email these questions to the unladen-swallow mailing list. They're very open to answering questions. 2009/6/4 Luis M. Gonz?lez : > I am very excited by this project (as well as by pypy) and I read all > their plan, which looks quite practical and impressive. > But I must confess that I can't understand why LLVM is so great for > python and why it will make a difference. > > AFAIK, LLVM is alot of things at the same time (a compiler > infrastructure, a compilation strategy, a virtual instruction set, > etc). > I am also confussed at their use of the term "jit" (is LLVM a jit? Can > it be used to build a jit?). > Is it something like the .NET or JAVA jit? Or it can be used to > implement a custom jit (ala psyco, for example)? > > Also, as some pypy folk said, it seems they intend to do "upfront > compilation". How? > Is it something along the lines of the V8 javascript engine (no > interpreter, no intermediate representation)? > Or it will be another interpreter implementation? If so, how will it > be any better...? > > Well, these are a lot of questions and they only show my confussion... > I would highly appreciate if someone knowledgeable sheds some light on > this for me... > > Thanks in advance! > Luis > -- > http://mail.python.org/mailman/listinfo/python-list > From gagsl-py2 at yahoo.com.ar Thu Jun 4 21:44:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 22:44:58 -0300 Subject: Making the case for repeat References: Message-ID: En Thu, 04 Jun 2009 10:37:45 -0300, pataphor escribi?: > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Because of backwards compatibility issues we > cannot remove them but we can boldly jump forward and include the right > repeat in the builtin namespace, which I think would be the best thing. > Alternatively -- the second best solution -- would be to give this > function its own namespace where it can supersede the old incongruencies > in itertools. Combiniter or combinator? Ok, you're proposing a "bidimensional" repeat. I prefer to keep things simple, and I'd implement it in two steps. First, something similar to your repeat_each function in another post: py> thing = ['1','2','3','4'] py> chain.from_iterable(repeat(elem, 3) for elem in thing) py> list(_) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] Note that this doesn't require any additional storage. Second step would be to build a bidimensional repeat: py> one = chain.from_iterable(repeat(elem, 3) for elem in thing) py> two = chain.from_iterable(tee(one, 2)) py> list(two) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] Short and simple, but this one requires space for one complete run (3*4 items in the example). Another variant that only requires space for freezing the original iterable (4 items in the example) is: >>> thing = ['1','2','3','4'] >>> items = list(thing) # ok, silly in this case, but not for a generic >>> iterable >>> chain.from_iterable(chain.from_iterable(repeat(elem, 3) for elem in >>> items) f or rownumber in range(2)) >>> list(_) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] All of them run at full speed, using the optimized itertools machinery written in C. -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Thu Jun 4 21:47:03 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 13:47:03 +1200 Subject: Yet another unicode WTF References: Message-ID: In message , Ron Garret wrote: > Python 2.6.2 on OS X 10.5.7: Same result, Python 2.6.1-3 on Debian Unstable. My $LANG is en_NZ.UTF-8. > ... I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. Well, there have long been functions like isatty(3). That's probably what's involved here. From TrevorOKennedy at gmail.com Thu Jun 4 21:49:10 2009 From: TrevorOKennedy at gmail.com (Trevor) Date: Thu, 4 Jun 2009 18:49:10 -0700 (PDT) Subject: 2d barcode library? References: <0d33db03-cc89-4057-bbc6-5a76dd4b8045@s20g2000vbp.googlegroups.com> Message-ID: > > Christian > > [1]https://cybernetics.hudora.biz/projects/wiki/huBarcode Thanks guys! huBarcode will work.. From ben+python at benfinney.id.au Thu Jun 4 21:53:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 11:53:19 +1000 Subject: Yet another unicode WTF References: Message-ID: <87my8nmoog.fsf@benfinney.id.au> Ron Garret writes: > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. It certainly can. If you're using GNU and a terminal that declares support for colour, examine the difference between these two: $ ls --color=auto $ ls --color=auto > foo ; cat foo > Clues appreciated. Thanks. Research ?man 3 isatty? for the function most commonly used to determine whether a file descriptor represents a terminal. -- \ ?If you are unable to leave your room, expose yourself in the | `\ window.? ?instructions in case of fire, hotel, Finland | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Jun 4 22:01:56 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:01:56 +1000 Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: <87iqjbmoa3.fsf@benfinney.id.au> chad writes: > Let's say I have a list of 5 files. Now lets say that one of the files > reads nude333.txt instead of nude3.txt. When this happens, the program > generates an error and quits. What I want it to do is just skip over > the bad file and continue on with the next one. Have you worked thoroughly through the Python tutorial ? You will exercise many fundamental concepts, including the exception handling system. > Below is the actual code. It only works on the local bbs that I hang > out on. Sorry. I couldn't think of the simple case that could isolate > my problem. You achieve this by one of two methods: * start with a program that does extermely little, and add as little as possible until you have a very small program which demonstrates the behaviour. Once you have this, continue below. * remove apparently-irrelevant parts from the program until the behaviour stops occuring; the most recent removal, then, is at least related to the behaviour. Add it back in. Repeat these until you have aprogram which can't have any part of it removed without losing the behaviour that's confusing you. Once you have that, post it here with your question. -- \ ?Good morning, Pooh Bear?, said Eeyore gloomily. ?If it is a | `\ good morning?, he said. ?Which I doubt?, said he. ?A. A. Milne, | _o__) _Winnie-the-Pooh_ | Ben Finney From rNOSPAMon at flownet.com Thu Jun 4 22:06:25 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 04 Jun 2009 19:06:25 -0700 Subject: Yet another unicode WTF References: Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Ron > Garret wrote: > > > Python 2.6.2 on OS X 10.5.7: > > Same result, Python 2.6.1-3 on Debian Unstable. My $LANG is en_NZ.UTF-8. > > > ... I always thought one of the fundamental > > invariants of unix processes was that there's no way for a process to > > know what's on the other end of its stdout. > > Well, there have long been functions like isatty(3). That's probably what's > involved here. Oh. Right. Duh. I am having an unbelievably bad day involving lawyers. (And not language lawyers, real ones.) Found the answer here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=415968 rg From ben+python at benfinney.id.au Thu Jun 4 22:06:27 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:06:27 +1000 Subject: Yet another unicode WTF References: Message-ID: <87eitzmo2k.fsf@benfinney.id.au> Ron Garret writes: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's certainly not desirable; the terminal, the shell, and the filesystem are all using UTF-8 so it should work fine. You might be best advised to report this as a bug to the Python bug tracker . -- \ ?I fly Air Bizarre. You buy a combination one-way round-trip | `\ ticket. Leave any Monday, and they bring you back the previous | _o__) Friday. That way you still have the weekend.? ?Steven Wright | Ben Finney From gagsl-py2 at yahoo.com.ar Thu Jun 4 22:09:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 23:09:47 -0300 Subject: Yet another unicode WTF References: Message-ID: En Thu, 04 Jun 2009 22:18:24 -0300, Ron Garret escribi?: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) > > > (That's supposed to be a small greek lambda, but I'm using a > brain-damaged news reader that won't let me set the character encoding. > It shows up correctly in my terminal.) > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. It may be hard to know *who* is at the other end of the pipe, but it's easy to know *what* kind of file it is. Lots of programs detect whether stdout is a tty or not (using isatty(3)) and adapt their output accordingly; ls is one example. Python knows the terminal encoding (or at least can make a good guess), but a file may use *any* encoding you want, completely unrelated to your terminal settings. So when stdout is redirected, Python refuses to guess its encoding; see the PYTHONIOENCODING environment variable. -- Gabriel Genellina From ben+python at benfinney.id.au Thu Jun 4 22:20:40 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:20:40 +1000 Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> <87iqjbmoa3.fsf@benfinney.id.au> Message-ID: <87ab4nmnev.fsf@benfinney.id.au> Ben Finney writes: > You achieve this by one of two methods: Failed to update this statement after an edit. That should be ?by following this method?. -- \ ?I used to be a proofreader for a skywriting company.? ?Steven | `\ Wright | _o__) | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:21:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:21:07 GMT Subject: __file__ access extremely slow References: Message-ID: On Thu, 04 Jun 2009 18:24:48 -0700, Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. How do you know? What are you using to time it? [...] > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section takes > 0.5sec. Total module count is ~800. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > try: > path = module.__file__ > except (AttributeError, ImportError): > return > ################################ You corrected this to: for module in sys.modules.itervalues(): try: path = module.__file__ except (AttributeError, ImportError): return (1) You're not importing anything inside the try block. Why do you think ImportError could be raised? (2) This will stop processing on the first object in sys.modules that doesn't have a __file__ attribute. Since these objects aren't *guaranteed* to be modules, this is a subtle bug waiting to bite you. -- Steven From benjamin.kaplan at case.edu Thu Jun 4 22:28:13 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 4 Jun 2009 22:28:13 -0400 Subject: Yet another unicode WTF In-Reply-To: <87eitzmo2k.fsf@benfinney.id.au> References: <87eitzmo2k.fsf@benfinney.id.au> Message-ID: On Thu, Jun 4, 2009 at 10:06 PM, Ben Finney > wrote: > Ron Garret writes: > > > Python 2.6.2 on OS X 10.5.7: > > > > [ron at mickey:~]$ echo $LANG > > en_US.UTF-8 > > [ron at mickey:~]$ cat frob.py > > #!/usr/bin/env python > > print u'\u03BB' > > > > [ron at mickey:~]$ ./frob.py > > ? > > [ron at mickey:~]$ ./frob.py > foo > > Traceback (most recent call last): > > File "./frob.py", line 2, in > > print u'\u03BB' > > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > > position 0: ordinal not in range(128) > > I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's > certainly not desirable; the terminal, the shell, and the filesystem are > all using UTF-8 so it should work fine. > > You might be best advised to report this as a bug to the Python bug > tracker . > Please don't. This isn't a bug- it's actually a good default. If the user doesn't specify an encoding, Python refuses to guess. In the case of the terminal, python doesn't have to guess because the environment variables give the encoding. When it's writing to a file, there is no way to know what encoding to use so it just sticks with ascii. > > -- > \ ?I fly Air Bizarre. You buy a combination one-way round-trip | > `\ ticket. Leave any Monday, and they bring you back the previous | > _o__) Friday. That way you still have the weekend.? ?Steven Wright | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Thu Jun 4 22:31:12 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 19:31:12 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> <77e831100906041718k4b4f54d9v29729449c50f3cb@mail.gmail.com> Message-ID: In article <77e831100906041718k4b4f54d9v29729449c50f3cb at mail.gmail.com>, Vincent Davis wrote: > On Thu, Jun 4, 2009 at 1:41 PM, Ned Deily wrote: >[...] > > $ /opt/local/bin/python2.5 > > Python 2.5.4 (r254:67916, May ?4 2009, 01:40:08) > > [GCC 4.0.1 (Apple Inc. build 5490)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > >>>> from _sqlite3 import * > >>>> >[...] > Also 10.5.7 my self, I have completely removed and reinstall macport > and all the ports. All befor posting this thread... > > here is what i get, jhgfjhgfjhg it is working now, I have no clue. I > went on a bike ride and now it works? Thanks for you help. Good. Wish I could claim to have magic powers that made it all work. > What do you know about python_select, .bash_profile and .profile? python_select is a shell script to manage multiple versions of MacPorts-supplied pythons. MacPorts allows you to install multiple versions of python, say python2.4 and python2.5. With python_select, you can select which version will be invoked by default, i.e. by /opt/local/bin/python. It does this by creating the proper symlinks within /opt/local which is the directory sub-tree containing MacPorts-installed files. There is more information in its man page. Things get even more complicated with python.org-installed pythons, each version of which has its own bin directory within a framework and which may have symlinks to it from /usr/local/bin. .bash_profile and .profile are two of the various startup files read by the various shells out there. In general, when dealing with multiple versions of the same command name, you can add commands to the appropriate shell startup files to modify the value of the PATH environment variable, which is what specifies the search path for commands. For example, if /opt/local/bin comes before /usr/bin in $PATH, the command "python" will invoke the MacPorts default python rather than the Apple-supplied python. PATH and shell startup files are all garden-variety Unix-y topics; there is plenty of info about them out there on the web. Another way to deal with multiple versions is to avoid ambiguity by always specifying the absolute path to the desired python, as in my earlier example above. There are other tactics, too, like defining shell aliases. Of course, each approach has its pluses and minuses. Hope that helps. -- Ned Deily, nad at acm.org From gagsl-py2 at yahoo.com.ar Thu Jun 4 22:33:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 23:33:52 -0300 Subject: __file__ access extremely slow References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: En Thu, 04 Jun 2009 22:24:48 -0300, Zac Burns escribi?: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > Code: [fixed] > ################################ > for module in sys.modules.itervalues(): > try: > path = module.__file__ > except (AttributeError, ImportError): > return > ################################> __file__ is just an instance attribute of module objects. Although a custom importer *might* define a special module type which *could* use a special computed attribute, I doubt so... module.__file__ just returns a string, when it exists. Built-in modules have no __file__ attribute set, and some entries in sys.modules may be set to None. These should be the only exceptions. > The calculation appears to be cached though, so a subsequent check > does not take very long. > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. Are you sure you posted the actual code? That "return" statement would stop the iteration as soon as it hits a builtin module, or a None flag. I'd say the time is spent somewhere else, or you're misinterpreting your results. BTW, what's the point of all this? -- Gabriel Genellina From michele.simionato at gmail.com Thu Jun 4 22:35:59 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Jun 2009 19:35:59 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> Message-ID: <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> On Jun 5, 1:18?am, Carl Banks wrote: > It's really the only sane way to handle it, odd though it may seem in > this narrow case. ?In Python nested functions have to be able to > reference the current value of a variable because of use cases like > this: > > def func(): > ? ? def printx(): > ? ? ? ? print x > ? ? x = 1 > ? ? printx() > ? ? x = 2 > ? ? printx() > > Referencing a nonlocal variable always uses the current (or last) > value of that variable, not the value it had when the nested function > was defined. This is not a good argument. Counter example: Scheme works exactly like Python (define (func) (define x 1) (define (printx) (display x) (newline)) (printx) (set! x 2) (printx)) ;; prints 1 and 2 but it is still possible to have a list comprehension working as the OP wants: (list-of (lambda () i) (i in (range 11 16))) Actually, in Scheme one would have to fight to define a list comprehension (more in general loops) working as in Python: the natural definition works as the OP wants. See http://www.artima.com/weblogs/viewpost.jsp?thread=251156 and the comments below for the details. From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:36:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:36:13 GMT Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote: > Let's say I have a list of 5 files. Now lets say that one of the files > reads nude333.txt instead of nude3.txt. When this happens, the program > generates an error and quits. What I want it to do is just skip over the > bad file and continue on with the next one. This should give you some hints. import errno for name in list_of_file_names: try: f = open(name, 'r') except IOError, e: if e.errno == errno.ENOENT: # or just use 2 if you're lazy # no such file, skip continue # some other more serious error, re-raise the exception raise do_something_with(f) [...] > def scroll_some_porn(now): > while 1: > for some_titty_porn in my_porn_collection: > now.write(" \n") > bitch_please = generate(some_titty_porn) > now.write(bitch_please) > time.sleep(10) > now.write(" \n") Shouldn't you have some way of escaping from the infinite loop other than typing Ctrl-C at the console? I imagine your hands will be busy. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:40:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:40:01 GMT Subject: __file__ access extremely slow References: Message-ID: On Fri, 05 Jun 2009 02:21:07 +0000, Steven D'Aprano wrote: > You corrected this to: > > for module in sys.modules.itervalues(): > try: > path = module.__file__ > except (AttributeError, ImportError): > return > > (1) You're not importing anything inside the try block. Why do you think > ImportError could be raised? > > (2) This will stop processing on the first object in sys.modules that > doesn't have a __file__ attribute. Since these objects aren't > *guaranteed* to be modules, this is a subtle bug waiting to bite you. In fact, not all modules have a __file__ attribute. >>> import errno >>> errno.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' -- Steven From rcdailey at gmail.com Thu Jun 4 22:42:29 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Thu, 4 Jun 2009 19:42:29 -0700 (PDT) Subject: urlretrieve() failing on me Message-ID: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Hey guys, try using urlretrieve() in Python 3.0.1 on the following URL: http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip Have it save the ZIP to any destination directory. For me, this only downloads about 40KB before it stops without any error at all. Any reason why this isn't working? From tjreedy at udel.edu Thu Jun 4 22:53:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 22:53:37 -0400 Subject: __file__ access extremely slow In-Reply-To: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > > The calculation appears to be cached though, so a subsequent check > does not take very long. > >>From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. Perhaps some of the modules use a delayed import mechanism. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > try: > path = module.__file__ > except (AttributeError, ImportError): > return If any modules lack the attribute, you will not scan them all. Perhaps you meant 'continue'? > ################################ > > > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games From nad at acm.org Thu Jun 4 22:56:17 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 19:56:17 -0700 Subject: Yet another unicode WTF References: Message-ID: In article , Ron Garret wrote: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) > > > (That's supposed to be a small greek lambda, but I'm using a > brain-damaged news reader that won't let me set the character encoding. > It shows up correctly in my terminal.) > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. > > Clues appreciated. Thanks. $ python2.6 -c 'import sys; print sys.stdout.encoding, \ sys.stdout.isatty()' UTF-8 True $ python2.6 -c 'import sys; print sys.stdout.encoding, \ sys.stdout.isatty()' > foo ; cat foo None False -- Ned Deily, nad at acm.org From aahz at pythoncraft.com Thu Jun 4 23:00:26 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 20:00:26 -0700 Subject: Feedparser problem References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: In article <89d21aec-5d39-4d1f-91b9-776da3506145 at i6g2000yqj.googlegroups.com>, Jonathan Nelson wrote: > >I'm trying to add a feedreader element to my django project. I'm >using Mark Pilgrim's great feedparser library. I've used it before >without any problems. I'm getting a TypeError I can't figure out. >I've tried searching google, bing, google groups to no avail. > >Here's the dpaste of what I'm trying to do and the result I'm >getting: > >http://dpaste.com/51406/ You're lucky that I felt like taking a look -- that's short enough you should have just posted it here. Anyway, that's pretty clearly not a firewall issue, and the only thing I can think of to figure it out given the lack of a real traceback is to poke around in the feedparser internals. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From cdalten at gmail.com Thu Jun 4 23:10:50 2009 From: cdalten at gmail.com (chad) Date: Thu, 4 Jun 2009 20:10:50 -0700 (PDT) Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: <571b6d7e-c9cb-4fcd-9977-38f47aeccf19@o18g2000yqi.googlegroups.com> On Jun 4, 7:36?pm, Steven D'Aprano wrote: > On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote: > > Let's say I have a list of 5 files. Now lets say that one of the files > > reads nude333.txt instead of nude3.txt. When this happens, the program > > generates an error and quits. What I want it to do is just skip over the > > bad file and continue on with the next one. > > This should give you some hints. > > import errno > > for name in list_of_file_names: > ? ? try: > ? ? ? ? f = open(name, 'r') > ? ? except IOError, e: > ? ? ? ? if e.errno == errno.ENOENT: ?# or just use 2 if you're lazy > ? ? ? ? ? ? # no such file, skip > ? ? ? ? ? ? continue > ? ? ? ? # some other more serious error, re-raise the exception > ? ? ? ? raise > ? ? do_something_with(f) > > [...] > > > def scroll_some_porn(now): > > ? ? while 1: > > ? ? ? ? for some_titty_porn in my_porn_collection: > > ? ? ? ? ? ? now.write(" \n") > > ? ? ? ? ? ? bitch_please = generate(some_titty_porn) > > ? ? ? ? ? ? now.write(bitch_please) > > ? ? ? ? ? ? time.sleep(10) > > ? ? ? ? ? ? now.write(" \n") > > Shouldn't you have some way of escaping from the infinite loop other than > typing Ctrl-C at the console? I imagine your hands will be busy. > Like what? All the program is meant to do is scroll ASCII art in a chat room. From sjmachin at lexicon.net Thu Jun 4 23:12:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 5 Jun 2009 03:12:25 +0000 (UTC) Subject: =?utf-8?b?X19maWxlX18=?= access extremely slow References: Message-ID: Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes: > > On Fri, 05 Jun 2009 02:21:07 +0000, Steven D'Aprano wrote: > > > You corrected this to: > > > > for module in sys.modules.itervalues(): > > try: > > path = module.__file__ > > except (AttributeError, ImportError): > > return > > > > (1) You're not importing anything inside the try block. Why do you think > > ImportError could be raised? > > > > (2) This will stop processing on the first object in sys.modules that > > doesn't have a __file__ attribute. Since these objects aren't > > *guaranteed* to be modules, Definitely not guaranteed to be modules. Python itself drops non-modules in there! Python 2.3 introduced four keys mapped to None -- one of these was dropped in 2.4, but the other three are still there in 2.5 and 2.6: C:\junk>\python23\python -c "import sys; print [k for (k, v) in sys.modules.items() if v is None]" ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', 'encodings.types'] C:\junk>\python24\python -c "import sys; print [k for (k, v) in sys.modules.items() if v is None]" ['encodings.codecs', 'encodings.exceptions', 'encodings.types'] > this is a subtle bug waiting to bite you. > > In fact, not all modules have a __file__ attribute. > > >>> import errno > >>> errno.__file__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute '__file__' Yep, none of the built-in modules has a __file__ attribute. So, as already pointed out, the loop is likely to stop rather early, making the huge 0.5 seconds look even more suspicious. Looking forward to seeing the OP's timing code plus a count of the actual number of loop gyrations ... Cheers, John From vincent at vincentdavis.net Thu Jun 4 23:12:43 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 21:12:43 -0600 Subject: How to develop a python application? Message-ID: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> This might be a off topic but this also seemed like a good place to ask. I have an application (several) I would like to develop. Parts of it I can do but parts I would like to outsource. I am thinking mostly of outsourcing most of my django (or similar) work and otherwise have some custom classes written. I would like to do this small bits (that is the out sourcing) at a time for many reasons but I realize there are down sides to doing this (I probably don't know all them) I have a this specific project in mind but don't mind this topic being rather broad. I would like to read and learn more about developing software (commercial or open source) My questions How do I find programs interested in small projects. How do they expect to be paid or how should I pay. Are sites like elance.com good? What do I not know to ask? That is what should I be considering? Any suggestions would be appreciated. Very brief description of the project. The app would take GPS, Heartrate, Power(bicycle) data from a Garmin GPS and other devises and upload it to a database. After that I have several calculations and analysis of the data. Then display graphs and other statistics. This is a very brief explanation. There are several examples of similar python projects, but not web based. Granola pygarmin garmin-sync The closest web based example would be Training Peaks http://home.trainingpeaks.com/personal-edition/training-log-and-food-diary.aspx Thanks Vincent Davis 720-301-3003 From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 23:25:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 03:25:16 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 09:47:05 -0700, Mensanator wrote: > After all, everybody knows that for m items taken n at a time, the > counts are > > perm w/repl = m**n > comb w/repl = (m+n-1)!/(n!(m-1)!) > perm wo/repl = m!/(m-n)! > comb wo/repl = m!/(n!(m-n)!) "Everybody" knows? Be careful with those sweeping generalizations. Combinatorics is a fairly specialized area not just of programming but mathematics as well. I've done a spot poll of four developers here (two juniors and two seniors) and *not one* could give all four formulae correctly first go. One guy didn't recognize the terms (although on being reminded, he got two of the four formula). Another one, a self-professed maths-geek, worked them out from first principles. -- Steven From brian at sweetapp.com Thu Jun 4 23:25:47 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 20:25:47 -0700 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: <4A28903B.4020301@sweetapp.com> Scott David Daniels wrote: [snipped] > When you evaluate a lambda expression, the default args are evaluated, > but the expression inside the lambda body is not. When you apply that > evaluated lambda expression, the expression inside the lambda body is > is evaluated and returned. But that's not really the issue. I knew that the lambda was not evaluated but thought each generator expression got its own context rather than sharing one. Taken in isolation, having one context per expression has more compelling semantics but it is inconsistent with the obvious transliteration of the generator into a loop. Cheers, Brian From ben+python at benfinney.id.au Thu Jun 4 23:31:13 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 13:31:13 +1000 Subject: Yet another unicode WTF References: Message-ID: <8763fbmk5a.fsf@benfinney.id.au> Ned Deily writes: > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > sys.stdout.isatty()' > UTF-8 True > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > sys.stdout.isatty()' > foo ; cat foo > None False So shouldn't the second case also detect UTF-8? The filesystem knows it's UTF-8, the shell knows it too. Why doesn't Python know it? -- \ ?When I was born I was so surprised I couldn't talk for a year | `\ and a half.? ?Gracie Allen | _o__) | Ben Finney From davea at ieee.org Thu Jun 4 23:56:33 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Jun 2009 23:56:33 -0400 Subject: Project source code layout? In-Reply-To: References: Message-ID: <4A289771.1050009@ieee.org> Lawrence D'Oliveiro wrote: > In message , Allen > Fowler wrote: > > >> 1) Do you use virtualpython? >> > > No idea what that is. > > >> 2) How do you load the modules in your lib directory? >> > > At the beginning of my scripts, I have a sequence like > > test_mode = False # True for testing, False for production > > if test_mode : > home_dir = "/home/shop-test" > else : > home_dir = "/home/shop" > #end if > > sys.path.append(home_dir + "/lib") > > import common > [etc] > > I have an installation script that looks for that "test_mode = True/False" > assignment and edits it accordingly. That flag is used to select the top- > level directory (as above) as well as the database name, etc. This allows me > to run two complete parallel sets of code and data, so I can mess around > with the testing version without impacting the production system. > > >> 3) How do you reference your configuration directives from within your >> modules and CGI/daemon scripts? >> > > For my last project using the above system, I used XML as the config file > format. > > > Rather than editing the source files at install time, consider just using an environment variable in your testing environment, which would be missing in production environment. Each command shell has its own set of environment variables, so this would make testing pretty easy, without the risk of things getting out of synch. Alternatively, if the script is located in a fixed place, relative to the home directory, just do some manipulation of the __file__ string. From davea at ieee.org Fri Jun 5 00:06:38 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 05 Jun 2009 00:06:38 -0400 Subject: Odd closure issue for generators In-Reply-To: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> Message-ID: <4A2899CE.1060809@ieee.org> Carl Banks wrote: > > > The way to handle the issue you are seeing is to create a new scope > with a variable the remains at the value you want to close upon: > > create_const_function(value): > def func(): > return value > c =create_const_function(i) for i in range(11, 16)) > > Or you can do it the slacker way and use a default argument: > > c =lambda i=i: i for i in range(11, 16)) > > > Carl Banks > > I agree with most of what you say, but I think you missed the last line of the function: create_const_function(value): def func(): return value return func From no.email at please.post Fri Jun 5 00:07:19 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 04:07:19 +0000 (UTC) Subject: how to iterate over several lists? Message-ID: Suppose I have two lists, list_a and list_b, and I want to iterate over both as if they were a single list. E.g. I could write: for x in list_a: foo(x) for x in list_b: foo(x) But is there a less cumbersome way to achieve this? I'm thinking of something in the same vein as Perl's: for $x in (@list_a, @list_b) { foo($x); } TIA! kynn -- From clp2 at rebertia.com Fri Jun 5 00:13:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Jun 2009 21:13:18 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <50697b2c0906042113x2e6355afm382cc8d5a11e3d22@mail.gmail.com> On Thu, Jun 4, 2009 at 9:07 PM, kj wrote: > > > Suppose I have two lists, list_a and list_b, and I want to iterate > over both as if they were a single list. ?E.g. I could write: > > for x in list_a: > ? ?foo(x) > for x in list_b: > ? ?foo(x) > > But is there a less cumbersome way to achieve this? ?I'm thinking > of something in the same vein as Perl's: > > for $x in (@list_a, @list_b) { > ?foo($x); > } Just add the lists together. for x in list_a + list_b: foo(x) Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Fri Jun 5 00:28:26 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 04:28:26 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: On Wed, 03 Jun 2009 01:00:15 +0200, Stef Mientki wrote: > Sorry, > but I realy don't understand the difference between the documents on my > desk and a python file in a subpath. Let's say you have a file called "parrot", containing some arbitrary data. You read it with open('parrot').read(), and then you can do anything you want with the data inside: If the data is a JPEG image, you can pass the data to a graphics program and display it. If the data is plain text, you can manipulate the text. If the data is Perl code, you can pass it to the Perl interpreter and run it. And if the data is Python code, you can call "exec data" and execute it. execfile() does just that. It doesn't care that the file name you pass is "myfile.py" instead of "parrot" -- it's just a file. You could call it "flooble.TIFF" and it wouldn't care: >>> open('flooble.TIFF', 'w').write('print "FLOOBLE!!!"\n') >>> execfile('flooble.TIFF') FLOOBLE!!! On the other hand, modules are special. A module is an actual Python data type, like str, int, list and so forth, on more complex. All sorts of magic takes place when you say "import module_name". The most important is that, unlike execfile, an actual module object is created, complete with __file__ and __name__ attributes. (Usually -- built-in modules don't have a __file__ attribute.) If you don't go through the import mechanism, you don't get a module. -- Steven From ben+python at benfinney.id.au Fri Jun 5 00:30:05 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 14:30:05 +1000 Subject: how to iterate over several lists? References: Message-ID: <871vpzmhf6.fsf@benfinney.id.au> Chris Rebert writes: > On Thu, Jun 4, 2009 at 9:07 PM, kj wrote: > > > > > > Suppose I have two lists, list_a and list_b, and I want to iterate > > over both as if they were a single list. [?] > Just add the lists together. > > for x in list_a + list_b: > foo(x) Which, more precisely, creates a *new* list as the concatenation of the two existing lists. -- \ ?A good politician is quite as unthinkable as an honest | `\ burglar.? ?Henry L. Mencken | _o__) | Ben Finney From no.email at please.post Fri Jun 5 00:31:24 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 04:31:24 +0000 (UTC) Subject: how to iterate over several lists? References: Message-ID: In Chris Rebert writes: >Just add the lists together. >for x in list_a + list_b: > foo(x) Cool! Thanks! kynn -- From metolone+gmane at gmail.com Fri Jun 5 00:35:12 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 4 Jun 2009 21:35:12 -0700 Subject: import sqlite3 References: Message-ID: "willgun" wrote in message news:h08c5e$aub$1 at news.cn99.com... > By the way ,what does 'best regards' means at the end of a mail? I think ?? may be a good translation. -Mark From gallium.arsenide at gmail.com Fri Jun 5 00:36:05 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 4 Jun 2009 21:36:05 -0700 (PDT) Subject: Printing list/tuple elements on separate lines References: Message-ID: On Jun 4, 8:37?pm, Johnny Chang wrote: > I have a large list of strings that I am unpacking > and splitting, and I want each one to be on a new line. > > An example: > > recs = > 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' > [(rec.split('f')) for rec in recs] > > output: > > [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', > 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] > > desired output: > > [['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', '']] Your friend may have used pprint: >>> from pprint import pprint >>> pprint(recs) [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] John From fetchinson at googlemail.com Fri Jun 5 00:44:07 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 4 Jun 2009 21:44:07 -0700 Subject: Printing list/tuple elements on separate lines In-Reply-To: References: Message-ID: >> I have a large list of strings that I am unpacking >> and splitting, and I want each one to be on a new line. >> >> An example: >> >> recs = >> 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' >> [(rec.split('f')) for rec in recs] >> >> output: >> >> [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', >> 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] >> >> desired output: >> >> [['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', '']] By slightly modifying your requirements this might be good too: print '\n'.join( [ 'aaaaaa', 'bbbbbbb', 'cccccccc', 'dddddddd', 'eeeeeeee' ] ) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From aahz at pythoncraft.com Fri Jun 5 00:49:15 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 21:49:15 -0700 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: In article <05937a34-5490-4b31-9f07-a319b44ddb09 at r33g2000yqn.googlegroups.com>, Michele Simionato wrote: > >Actually, in Scheme one would have to fight to define >a list comprehension (more in general loops) working as >in Python: the natural definition works as the OP wants. See >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156 and the >comments below for the details. This URL isn't working for me, gives 500. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From stefan_ml at behnel.de Fri Jun 5 00:52:57 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 05 Jun 2009 06:52:57 +0200 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <4a28a4a9$0$31340$9b4e6d93@newsspool4.arcor-online.net> kj wrote: > Suppose I have two lists, list_a and list_b, and I want to iterate > over both as if they were a single list. E.g. I could write: > > for x in list_a: > foo(x) > for x in list_b: > foo(x) > > But is there a less cumbersome way to achieve this? Take a look at the itertools module, especially itertools.chain(). Stefan From ldo at geek-central.gen.new_zealand Fri Jun 5 01:47:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:47:53 +1200 Subject: Project source code layout? References: Message-ID: In message , Dave Angel wrote: > Rather than editing the source files at install time, consider just > using an environment variable in your testing environment, which would > be missing in production environment. I'd still need to define that environment variable in a wrapper script, which means editing that script at install time ... back to square one ... From ldo at geek-central.gen.new_zealand Fri Jun 5 01:50:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:50:17 +1200 Subject: Yet another unicode WTF References: Message-ID: In message , Gabriel Genellina wrote: > Python knows the terminal encoding (or at least can make a good guess), > but a file may use *any* encoding you want, completely unrelated to your > terminal settings. It should still respect your localization settings, though. From ldo at geek-central.gen.new_zealand Fri Jun 5 01:51:49 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:51:49 +1200 Subject: python way to automate IE8's File Download dialog References: <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3@n4g2000vba.googlegroups.com> Message-ID: In message <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3 at n4g2000vba.googlegroups.com>, monogeo wrote: > I am able to use PAMIE 2.0 to automate IE7's File Download dialog, but > the same approach/code fails on IE8. I don't understand why you need to automate a GUI front-end, meant for human use, to a function that can be directly performed without that front-end anyway. From ldo at geek-central.gen.new_zealand Fri Jun 5 01:52:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:52:42 +1200 Subject: Project source code layout? References: Message-ID: In message , Jean-Paul Calderone wrote: > On Thu, 04 Jun 2009 21:33:13 +1200, Lawrence D'Oliveiro > wrote: > >>In message , Allen >>Fowler wrote: >> >>> I was hoping to keep the dev layout as close to deployment possible. >> >>Completely different purposes. For example, the actual production database >>and config files form no part of your development project, do they? And >>conversely, utility scripts that might be used, for example, to set up a >>database, should not be part of the production installation. > > If you don't use the "utility scripts" in your development environment, > how do you know they work with the code you're developing? Because they're used during development. From theller at python.net Fri Jun 5 01:54:10 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 07:54:10 +0200 Subject: ctype question In-Reply-To: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> References: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> Message-ID: <78rq82F1mu5vtU1@mid.individual.net> Amit Gupta schrieb: > Hi, > > I have been using ctype.cdll to load a library, but I am unable to > figure out how to load multiple libraries that depends on each other. > E.g. I have two libraries A.so and B.so. A.so has some undefined > references, and those symbols are defined in B.so. > > When I try to load ctypes.cdll.LoadLibrary("A.so"), it gives errors > about the undefined Symbols. Even if I load B.so before loading A.so, > the error remains the same (which is expected). Can someone help me to > find out, how to load A.so by telling it to look for undefined symbols > in B.so as well? You could try to pass ctypes.RTLD_GLOBAL as the 'mode' parameter to ctypes.CDLL when you load the library. Thomas From nad at acm.org Fri Jun 5 01:58:13 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 22:58:13 -0700 Subject: Odd closure issue for generators References: <4A28903B.4020301@sweetapp.com> Message-ID: In article <4A28903B.4020301 at sweetapp.com>, Brian Quinlan wrote: > Scott David Daniels wrote: > [snipped] > > When you evaluate a lambda expression, the default args are evaluated, > > but the expression inside the lambda body is not. When you apply that > > evaluated lambda expression, the expression inside the lambda body is > > is evaluated and returned. > > But that's not really the issue. I knew that the lambda was not > evaluated but thought each generator expression got its own context > rather than sharing one. Each? Maybe that's a source of confusion. There is only one generator expression in your example. >>> c = (lambda : i for i in range(11, 16)) >>> c at 0x114e90> >>> d = list(c) >>> d [ at 0x119348>, at 0x119390>, at 0x1193d8>, at 0x119420>, at 0x119468>] -- Ned Deily, nad at acm.org From xahlee at gmail.com Fri Jun 5 02:07:39 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Jun 2009 23:07:39 -0700 (PDT) Subject: The Complexity And Tedium of Software Engineering References: Message-ID: On Jun 3, 11:50 pm, Xah Lee wrote: > Of interest: > ? The Complexity And Tedium of Software Engineering > http://xahlee.org/UnixResource_dir/writ/programer_frustration.html Addendum: The point in these short examples is not about software bugs or problems. It illustrates, how seemingly trivial problems, such as networking, transferring files, running a app on Mac or Windwos, upgrading a app, often involves a lot subtle complexities. For mom and pop users, it simply stop them dead. For a senior industrial programer, it means some conceptually 10-minutes task often ends up in hours of tedium. In some ?theoretical? sense, all these problems are non-problems. But in practice, these are real, non-trivial problems. These are complexities that forms a major, multi-discipline, almost unexplored area of software research. I'm trying to think of a name that categorize this issue. I think it is a mix of software interface, version control, release control, formal software specification, automated upgrade system, etc. The ultimate scenario is that, if one needs to transfer files from one machine to another, one really should just press a button and expect everything to work. Software upgrade should be all automatic behind the scenes, to the degree that users really don't need fucking to know what so-called ?version? of software he is using. Today, with so-called ?exponential? scientific progress, and software has progress tremendously too. In our context, that means there are a huge proliferation of protocols and standards. For example, unicode, gazillion networking related protocols, version control systems, automatic update technologies, all comes into play here. However, in terms of the above visionary ideal, these are only the beginning. There needs to be more protocols, standards, specifications, and more strict ones, and unified ones, for the ideal scenario to take place. Xah ? http://xahlee.org/ ? On Jun 3, 11:50 pm, Xah Lee wrote: > Of interest: > ? The Complexity And Tedium of Software Engineering > http://xahlee.org/UnixResource_dir/writ/programer_frustration.html > > in particular, there are 2 issues with emacs that might be interesting > here. > > plain text version follows > -------------------------------------------------- > > The Complexity And Tedium of Software Engineering > > Xah Lee, 2009-06-02 > > This page is a blog of a experience of few examples that illustrates > some seemingly trivial task can become quite tedius and complicated in > the software industry. > > A Complexity with Emacs > > Discovered a emacs problem. > > Summary: > > ? Seems that emacs 23 will have a problem loading a css-mode written > by Stefan Monnier > > ? The css-mode.el file does not contain any sort of version number, > which makes the problem worse. > > Detail: I have a Mac running emacs 22 with OS X, and i have PC running > emacs 23 and Windows Vista. When i use the emacs 23 to load css mode, > it gives this error: ?if: Wrong type argument: integerp, (0 . 8)?. > > The problem seems simple in retrospect, but wasn't simple at all when > you trying to get things done and things don't work as expected. > Here's the story. > > Emacs 22 does not have a css mode, emacs 23 does. There's one css mode > written by Stefan. I've been using it on the Mac for the past couple > of years. The same package is now bundled into emacs 23, which i'm > using on PC. However, the code in the 2 files are not identical. I > have my emacs setup to load css mode. Since i am migrating to PC, > alone with my whole emacs system, and am setting up a Mac and PC and > network that'd let me work with either machine harmoniously. On the > PC, when i start css mode, it gives error, but not always. You don't > know what's wrong. It could be a fuckup in the emacs distro i'm using > on PC (which is emacsW32), or it could be emacs 23 problem (emacs 23 > is still in beta), or it could be something in my emacs customization > that works perfectly well on the Mac but not on the PC with whole new > environment. Eventually, i realized that's because sometimes i started > plain emacs 23 without loading my own setup, it was using the bundled > css mode, so no error, but when i loaded my own emacs setup, it gives > error. This seems still simple in retrospect, but wasn't then. I added > a version check to my emacs init file(s), so that if emacs is 23, > don't load my css mode. The next day, same symptom occurs. Eventually > I realized that's because the load path is set so that my own version > of css mode comes before the bundled css mode, so that, when i load > css, again my old version is loaded. Eventually, the solution is to > check if css mode bundled with emacsW32 runs ok on emacs 22 on my Mac; > if so, simply use that as the single source for my Mac and PC. When > doing this work on checking what versions are the files, i realized > that the 2 css mode's files don't contain version number at all. All > this takes 5 minutes to read, but was one of the gazillion seemingly > trivial issues and problems when setting my Mac/PC networking > environment with cygwin and all. This took me one week, and haven't > gotten to wholly converting my Mac files to PC. Added the time to > google for for the answer, possibly write a report to the emacsers, > etc, all in all, i'd say this problem caused me 4 hours. > > Here's the emacs version i'm using. On the Mac: ?GNU Emacs 22.2.1 > (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of 2008-04-05 on > g5.tokyo.stp.isas.jaxa.jp?. On Windows ?GNU Emacs 23.0.94.1 (i386- > mingw-nt6.0.6001) of 2009-05-28 on LENNART-69DE564 (patched)? > > -------------------------------------------------- > URL Encoding > > Discovered a subtle issue with automating url encoding. In url, if you > have the ampersand ?&? char, and if this url is to be inside a html > doc as a link, then, there's no automated procedure that determines > correctly whether the char should be encoded as ?%26? or ?&?. If > the char is used as part of the file name or path, then it should be > encoded as ?&?, but if it is used as a separator for CGI > parameters, then it should be encoded as ?%26?. > > The rule for Percent encoding the char is that the ampersand is a > reserved char, therefore it must be percent encoded if it is used for > normal file path names. So, when it is NOT used as part of path names, > but used as CGI parameter separaters, with GET method of HTTP request, > then it must be left as it is. Now, in html, the ampersand char must > be encoded as html entities ?&? when adjacent chars are not space > (basically). So, it becomes ?&?. > > In summary, if the url in html link contains ?&?, and the char is a > CGI param separator, then encode it to ?&?, else, encode it as > ?%26?, and my discovery is that the purpose of the char used in url > cannot be syntactically determined with 100% accuracy. > > Of course, in practice, all this matters shit. Just use ?&? plainly > and it all works in 99.999% of situations. > > -------------------------------------------------- > Unicode File Names > > Unison and Unicode File Names > > Summary: Unison does not support unicode chars. > > When using Unison version 2.27, to sync files from Mac to PC, the file > name on the mac is ???_flag.jpg?, it is copied to PC using Unison > 2.27, and the file name became ?????-?_flag.jpg? when viewed under > Windows, but the file name shows up correctly when viewed in EmacsW32. > > Mac version: 10.4.11, Windows Vista SP1. > > This may indicate that Unison encode file names in utf8, or just > ascii. Indeed, it is said on Wikipedia that unicode have problems with > non-ascii file names. > > When the file is copied from Mac to Windows or Windows to Mac, > operating either on Windows or Mac as the local machine, using either > OS's file manager, the file name is copied correctly. > > Setting up Unison itself is not so trivial. It is trivial in concept, > but actually took hours. I have Unison on my Mac installed, and use it > few times a year, since about 2006, so i'm familiar with it. On PC, > first you have to install cygwin. I know there are Unison binaries for > Windows but since i use cygwin, so my first choice is staying with > cygwin, since it contains the whole unix environment. Installing > cygwin is another story, but once you installed Unison in cygwin, and > tried to test sync my Mac and PC, you run into the problem that sshd > must be turned on in one of the machines. Namely, sshd should run on > the ?remote? machine. (setting up a local network among Win and Mac is > another complex and tedious story) Then, there's the issue of deciding > which machine you want sshd to run or both. On the Mac, i can turn on > sshd in a minute. On Windows, i'm not sure. I'm not sure if Windows > Vista home edition provide ssh server, and am not sure how to turn it > on if so. As far as i know, Windows Vista Home does not come with a > ssh client. In the process, also realize that firewall must be turned > off for ssh port. So, you spend 30 min or possibly hours (here and > there) reading or probing with Windows Firewall control panel and > whatnot other admin tools. After a while, i decided it's easier just > to turn on sshd on the Mac then Unison from the Windows side to the > Mac. At least, have this direction work first, and when that works, i > can play with the other direction. After all this done, i tried to > Unison, but Unison reports that the Unison version on my Mac and PC is > not the same, so it doesn't work. Geeze. The one on my Mac turns out > to be Unison 2.13.x, and the one i have in Cygwin is 2.31.x. Now, i > figured that with each release of Unison, it probably obsolete some > older versions. So, back to digging Unison docs and the web. The > simplest solution comes to mind is to update my Unison on my Mac to > latest, of which, the unison on fink haven't been updated for a couple > of years. I use Fink, and am fairly familiar with using Fink. However, > after ?fink selfupdate? etc, then ?fink desc Unison?, the version > there reported seems to be 2.13. Then, searching web on fink home page > indicates they have unisone-2.27.57-1007, for my OS 10.4 PowerPC. So, > why doesn't it show up in my fink? I remember i had a case last year > where fink had obsolete mirror databases, a fault entirely on their > end. After spending maybe some more 30 min, i decided to install > Unison from a website, binary download. After that done, i got Unison > 2.27.x on the Mac. I tried to sync again, still no go. So, it seems > like that the Unison version number must be the same or very close. > Checking on Unison website, it looks like the current stable release > is 2.27.x, so, my cygwin's 2.31.x is actually a beta. Damn. So, now > back to cygwin. Luckily, it appears there are several version of > Unison there to be installed, and i easily installed 2.27. Then, > finally, test sync is successful. Now, i go back to get my files ready > in a state to be synced. (long story there. See: Perl Script for > Removing Mac Resource Fork and Switching from Mac/Unix To PC/Windows ) > When finally i'm ready to Unison, then there's the Chinese character > problem! > > -------------------------------------------------- > Emacs on Windows and Unicode File Names > > When using emacsW32, dired has problem dealing with files with chinese > char on remote machine. Consequently, when trying to copy, delete, > etc, the behavior may be dangerous. > > e.g. i have this file ???.jpg on a Mac. I use emacsW32 on Windows to > view it thru network. (e.g. the path is //169.254.145.104/xah/ > web/ ... ) the file name shows up as ?_viu0y~a.jpg? in dired. > > ?GNU Emacs 23.0.94.1 (i386-mingw-nt6.0.6001) of 2009-05-28 on > LENNART-69DE564 (patched)?, Mac version: 10.4.11, Windows Vista SP1. > > Xah > ?http://xahlee.org/ > > ? From mensanator at aol.com Fri Jun 5 02:10:33 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Jun 2009 23:10:33 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Jun 4, 10:25?pm, Steven D'Aprano wrote: > On Thu, 04 Jun 2009 09:47:05 -0700, Mensanator wrote: > > After all, everybody knows that for m items taken n at a time, the > > counts are > > > perm ?w/repl = m**n > > comb ?w/repl = (m+n-1)!/(n!(m-1)!) > > perm wo/repl = m!/(m-n)! > > comb wo/repl = m!/(n!(m-n)!) > > "Everybody" knows? Be careful with those sweeping generalizations. > Combinatorics is a fairly specialized area not just of programming but > mathematics as well. I would expect that. That was supposed to be funny. :-) > > I've done a spot poll of four developers here (two juniors and two > seniors) and *not one* could give all four formulae correctly first go. > One guy didn't recognize the terms (although on being reminded, he got > two of the four formula). Another one, a self-professed maths-geek, > worked them out from first principles. I didn't know all of them either. I had to look them up in the source code of the combinatorics library I wrote for myself (I use that stuff a lot in my research). BTW, I really appreciate the links posted a while ago on how to search for text in .py files on Windows. Could not have found them otherwise. I must have a dozen copies of the module on each of 4 disks (two hard & 2 flash) but the comments containing those formulae was only in a single place. There was a subtle point. A function that would return such counts is fine - provided you don't have to actually count them! I'm sure Mr. Hettinger knows that. > > -- > Steven From ben+python at benfinney.id.au Fri Jun 5 02:11:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 16:11:54 +1000 Subject: Yet another unicode WTF References: Message-ID: <87skifky51.fsf@benfinney.id.au> "Gabriel Genellina" writes: > Python knows the terminal encoding (or at least can make a good > guess), but a file may use *any* encoding you want, completely > unrelated to your terminal settings. It may, yes, and the programmer is free to specify any encoding. > So when stdout is redirected, Python refuses to guess its encoding; But Python doesn't have to guess; the terminal encoding is as specified in either case, no? > see the PYTHONIOENCODING environment variable. For the standard streams, the specified terminal encoding available to every program makes the most sense ? certainly more sense than a Python-specific variable, or the ?default to ASCII? of the current behaviour. -- \ ?Holy uncanny photographic mental processes, Batman!? ?Robin | `\ | _o__) | Ben Finney From command.bbs at alexbbs.twbbs.org Fri Jun 5 02:16:06 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 05 Jun 2009 06:16:06 GMT Subject: how to create a big list of list Message-ID: <4gI9c7$wD1@alexbbs.twbbs.org> if i want to create a list of list which size is 2**25 how should i do it? i have try [ [] for x in xrange(2**25) ] but it take too long to initial the list is there any suggestion? Thanks a lot! -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From ldo at geek-central.gen.new_zealand Fri Jun 5 02:53:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 18:53:51 +1200 Subject: Odd closure issue for generators References: Message-ID: In message , Brian Quinlan wrote: > >>> c = (lambda : i for i in range(11, 16)) > >>> d = list(c) > >>> for q in d: > ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 Try >>> c = ((lambda i : lambda : i)(i) for i in range(11, 16)) >>> d = list(c) >>> for q in d : ... print q() ... 11 12 13 14 15 From michele.simionato at gmail.com Fri Jun 5 02:55:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Jun 2009 23:55:32 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <5539c26b-c39c-4ee2-88e6-5953ad21fe2b@r37g2000yqd.googlegroups.com> On Jun 5, 6:49?am, a... at pythoncraft.com (Aahz) wrote: > In article <05937a34-5490-4b31-9f07-a319b44dd... at r33g2000yqn.googlegroups.com>, > Michele Simionato ? wrote: > > > > >Actually, in Scheme one would have to fight to define > >a list comprehension (more in general loops) working as > >in Python: the natural definition works as the OP wants. See > >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156and the > >comments below for the details. > > This URL isn't working for me, gives 500. This happens sometimes with Artima. Usually it is just a matter of waiting a few minutes. From nad at acm.org Fri Jun 5 03:03:30 2009 From: nad at acm.org (Ned Deily) Date: Fri, 05 Jun 2009 00:03:30 -0700 Subject: Yet another unicode WTF References: <8763fbmk5a.fsf@benfinney.id.au> Message-ID: In article <8763fbmk5a.fsf at benfinney.id.au>, Ben Finney wrote: > Ned Deily writes: > > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > > sys.stdout.isatty()' > > UTF-8 True > > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > > sys.stdout.isatty()' > foo ; cat foo > > None False > > So shouldn't the second case also detect UTF-8? The filesystem knows > it's UTF-8, the shell knows it too. Why doesn't Python know it? The filesystem knows what is UTF-8? While the setting of the locale environment variables may influence how the file system interprets the *name* of a file, it has no direct influence on what the *contents* of a file is or is supposed to be. Remember in python 2.x, a file is a just sequence of bytes. If you want to write encode Unicode to the file, you need to use something like codecs.open to wrap the file object with the proper streamwriter encoder. What confuses matters in 2.x is the print statement's under-the-covers implicit Unicode encoding for files connected to a terminal: http://bugs.python.org/issue612627 http://bugs.python.org/issue4947 http://wiki.python.org/moin/PrintFails >>> x = u'\u0430\u0431\u0432' >>> print x [nice looking characters here] >>> sys.stdout.write(x) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> sys.stdout.encoding 'UTF-8' In python 3.x, of course, the encoding happens automatically but you still have to tell python, via the "encoding" argument to open, what the encoding of the file's content is (or accept python's default which may not be very useful): >>> open('foo1','w').encoding 'mac-roman' WTF, indeed. -- Ned Deily, nad at acm.org From michele.simionato at gmail.com Fri Jun 5 03:04:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 00:04:11 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> On Jun 5, 6:49?am, a... at pythoncraft.com (Aahz) wrote: > In article <05937a34-5490-4b31-9f07-a319b44dd... at r33g2000yqn.googlegroups.com>, > Michele Simionato ? wrote: > > > > >Actually, in Scheme one would have to fight to define > >a list comprehension (more in general loops) working as > >in Python: the natural definition works as the OP wants. See > >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156and the > >comments below for the details. > > This URL isn't working for me, gives 500. Anyway, the point is that to explain Python behavior with closures in list/generator comprehension it is not enough to invoke late bindings (Scheme has late bindings too but list comprehension works differently). The crux is in the behavior of the for loop: in Python there is a single scope and the loop variable is *mutated* at each iteration, whereas in Scheme (or Haskell or any other functional language) a new scope is generated at each iteration and there is actually a new loop variable at each iteration: no mutation is involved. Common Lisp works like Python. It is a design decision which at the end comes down to personal preference and different languages make different choices with no clear cut winner (I personally prefer the more functional way). From mobiledreamers at gmail.com Fri Jun 5 03:16:42 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Fri, 5 Jun 2009 00:16:42 -0700 Subject: unified way or cookbook to access cheetah from other frameworks django/webpy/pylons Message-ID: can you or tavis or one of the cheetah masters please show us how to use cheetah from webpy the only useful thing webpy cheetah.py does is replace the #include with the content of the files Can you share a simple snippet/cookbook example on how to hook up cheetah from other frameworks such as django/webpy/pylons, if there is a unified way to access the cheetah template then the problems will be easier to fix? Thanks a lot... for trying to help... -- Bidegg worlds best auction site http://bidegg.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jun 5 03:22:30 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Jun 2009 09:22:30 +0200 Subject: Feedparser problem References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: Jonathan Nelson wrote: > I'm trying to add a feedreader element to my django project. I'm > using Mark Pilgrim's great feedparser library. I've used it before > without any problems. I'm getting a TypeError I can't figure out. > I've tried searching google, bing, google groups to no avail. > > Here's the dpaste of what I'm trying to do and the result I'm > getting: > >>>import feedparser > >>>url='http://feeds.nytimes.com/nyt/rss/Technology' > >>>d=feedparser.parse(url) > >>>d > {'bozo':1, > 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), > 'encoding': 'utf-8', > 'entries': [], > 'feed':{}, > 'version': None} > I've tried checking my firewall settings. I'm using Windows 7 and > Python 2.6. Win 7 is allowing other Python programs through. I've > tried several different RSS urls with the same result. > > Any thoughts would be greatly appreciated. Which version of feedparser are you using? In the 4.1 source 'timeout' occurs only in a comment. Peter From davea at ieee.org Fri Jun 5 03:29:59 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 05 Jun 2009 03:29:59 -0400 Subject: Project source code layout? In-Reply-To: References: Message-ID: <4A28C977.2040303@ieee.org> Lawrence D'Oliveiro wrote: > In message , Dave Angel > wrote: > > >> Rather than editing the source files at install time, consider just >> using an environment variable in your testing environment, which would >> be missing in production environment. >> > > I'd still need to define that environment variable in a wrapper script, > which means editing that script at install time ... back to square one ... > > > No, the whole point is it's an environment variable which is *missing" in production environment. Make sure you make it an obscure name, like set MyProductName_TestingMode=1 So the way you know you're in a production environment is that you do not have such an environment variable. From ldo at geek-central.gen.new_zealand Fri Jun 5 03:31:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 19:31:23 +1200 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> Message-ID: In message <78180b4c-68b2-4a0c-8594-50fb1ea2f414 at c19g2000yqc.googlegroups.com>, Michele Simionato wrote: > The crux is in the behavior of the for loop: > in Python there is a single scope and the loop variable is > *mutated* at each iteration, whereas in Scheme (or Haskell or any > other functional language) a new scope is generated at each > iteration and there is actually a new loop variable at each iteration: > no mutation is involved. I think it's a bad design decision to have the loop index be a variable that can be assigned to in the loop. From jpthing at online.no Fri Jun 5 03:32:05 2009 From: jpthing at online.no (John Thingstad) Date: Fri, 05 Jun 2009 09:32:05 +0200 Subject: The Complexity And Tedium of Software Engineering References: Message-ID: P? Fri, 05 Jun 2009 08:07:39 +0200, skrev Xah Lee : > On Jun 3, 11:50 pm, Xah Lee wrote: > The point in these short examples is not about software bugs or > problems. It illustrates, how seemingly trivial problems, such as > networking, transferring files, running a app on Mac or Windwos, > upgrading a app, often involves a lot subtle complexities. For mom and > pop users, it simply stop them dead. For a senior industrial > programer, it means some conceptually 10-minutes task often ends up in > hours of tedium. What on earth gave you the idea that this is a trivial problem? Networks have been researched and improved for the last 40 years! It is a marvel of modern engineering that they work as well as they do. > > In some ?theoretical? sense, all these problems are non-problems. But > in practice, these are real, non-trivial problems. These are > complexities that forms a major, multi-discipline, almost unexplored > area of software research. Again, it is it not a trivial problem theoretically. Unexplored? What world are you on? > I'm trying to think of a name that > categorize this issue. I think it is a mix of software interface, > version control, release control, formal software specification, > automated upgrade system, etc. The ultimate scenario is that, if one > needs to transfer files from one machine to another, one really should > just press a button and expect everything to work. Software upgrade > should be all automatic behind the scenes, to the degree that users > really don't need fucking to know what so-called ?version? of software > he is using. > Actually they mostly are. At least on my machine. (I use Windows XP and Ubuntu Linux.) > Today, with so-called ?exponential? scientific progress, and software > has progress tremendously too. In our context, that means there are a > huge proliferation of protocols and standards. For example, unicode, > gazillion networking related protocols, version control systems, > automatic update technologies, all comes into play here. However, in > terms of the above visionary ideal, these are only the beginning. > There needs to be more protocols, standards, specifications, and more > strict ones, and unified ones, for the ideal scenario to take place. > No, there are already to many protocols and the ideas of how a network infrastructure should be built are mostly in place. I think we would benefit from "cleaning up" the existing interface. That is by removing redundancy. What does need further research is distributed processing. Again this is a highly complex problem and a lot of work has been put into trying to make simpler and more manageable interfaces and protocol's. See for example the languages Erlang and Oz to get an idea. --------------------- John Thingstad From Eric_Dexter at msn.com Fri Jun 5 03:52:49 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 5 Jun 2009 00:52:49 -0700 (PDT) Subject: is anyone using text to speech to read python documentation References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <758cd757-d63e-493c-b460-f9488751da76@r33g2000yqn.googlegroups.com> On Jun 3, 12:28?pm, Stef Mientki wrote: > Eric_Dex... at msn.com wrote: > > ? ? ?I wrote a small pre-processor for python documentation and I am > > looking for advice on how to get the most natural sounding reading. ?I > > uploaded an example of a reading of lxml documentation as a podcast1 > > >http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. > > Depends what OS you want to use, on Windows it's very easy: > > import win32com.client ? ? ? ? ? ? ? ? ? ? ? ? ? > s = win32com.client.Dispatch("SAPI.SpVoice") ? ? > s.Speak('Is this punthoofd ') ? ? ? ? ? ? ? ? ? ? > > cheers, > Stef That is intresting and might be useful but isn't what I am doing. alot of the time you will see stuff like >>> that needs to be changed into other wording so you have one file that gets transformed into another text that makes more sense when read. I haven't changed html tags into something that makes more sense when spoken so my example is a little defective.... From theller at python.net Fri Jun 5 04:03:59 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 10:03:59 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: <78s1rgF1narmcU1@mid.individual.net> Joseph Garvin schrieb: > On Thu, Jun 4, 2009 at 3:23 PM, Brian wrote: >> What is the goal of this conversation that goes above and beyond what >> Boost.Python + pygccxml achieve? > > I can't speak for others but the reason I was asking is because it's > nice to be able to define bindings from within python. At a minimum, > compiling bindings means a little extra complexity to address with > whatever build tools you're using. AFAIU, pybindgen takes this approach. And, AFAIK, pygccxml can generate pybindgen code. From jeremiah.dodds at gmail.com Fri Jun 5 04:25:50 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Fri, 5 Jun 2009 09:25:50 +0100 Subject: How to develop a python application? In-Reply-To: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> References: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> Message-ID: <12cbbbfc0906050125m570a0692waf299fb33456e465@mail.gmail.com> On Fri, Jun 5, 2009 at 4:12 AM, Vincent Davis wrote: > This might be a off topic but this also seemed like a good place to ask. > > I have an application (several) I would like to develop. Parts of it I > can do but parts I would like to outsource. I am thinking mostly of > outsourcing most of my django (or similar) work and otherwise have > some custom classes written. > I would like to do this small bits (that is the out sourcing) at a > time for many reasons but I realize there are down sides to doing this > (I probably don't know all them) > > I have a this specific project in mind but don't mind this topic being > rather broad. I would like to read and learn more about developing > software (commercial or open source) > > My questions > How do I find programs interested in small projects. > How do they expect to be paid or how should I pay. > Are sites like elance.com good? > What do I not know to ask? That is what should I be considering? > > Any suggestions would be appreciated. > > > > Very brief description of the project. > The app would take GPS, Heartrate, Power(bicycle) data from a Garmin > GPS and other devises and upload it to a database. After that I have > several calculations and analysis of the data. Then display graphs and > other statistics. This is a very brief explanation. > > There are several examples of similar python projects, but not web based. > Granola > pygarmin > garmin-sync > The closest web based example would be Training Peaks > > http://home.trainingpeaks.com/personal-edition/training-log-and-food-diary.aspx > > Thanks > Vincent Davis > 720-301-3003 > -- > http://mail.python.org/mailman/listinfo/python-list > With regards to sites like elance, I can only offer advice here from a coder's perspective, so I may be missing some things, but here goes: You can probably find people on elance or rentacoder, or similar sites to work on your app. You will need to be very careful about who you hire though - the sites are filled with incompetent coders, and bots that represent _teams_ of incompetent programmers. I used to do a good bit of work on sites like that, and a lot of my work was fixing apps that got written by other people on those sites that had no idea what they were doing. We're talking about 10,000 lines of PHP that got changed into ~2500 with simple, mostly automated refactoring because the people who wrote it had apparently never heard of a for loop. Payment is normally done through an escrow service. The price you're willing to pay generally gets decided on before work begins, and the people who want to work on it can make bids saying how much they want for the work, and you can talk to them - make sure they know what they're talking about, haggle price, etc. There tends to be protection for both the person paying and the person working to avoid you not paying them if they did what they were supposed to, and to avoid you having to pay them if they didn't. All in all, using sites like elance can get your work done, and it can get it done well and on the cheap - but you'll have to spend a significant amount of time weeding through automated responses and making sure you're getting the right person to work on your stuff. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Fri Jun 5 04:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 05 Jun 2009 03:29:41 -0500 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> <87r5xzmq3o.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Emile van Sebille writes: > > > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > > > In message , Nick Craig- > > > Wood wrote: > > > > > >> You quit emacs with Ctrl-X Ctrl-C. > > > > > > That's "save-buffers-kill-emacs". If you don't want to save buffers, > > > the exit sequence is alt-tilde, f, e. > > This is an invocation of the menu system, driven by the keyboard. (Also, > it's not Alt+tilde (which would be Alt+Shift+`), it's Alt+` i.e. no > Shift.) It's an alternate command, and IMO is just adding confusion to > the discussion. Also, according to my emacs e==>Exit Emacs (C-x C-c) so Alt-` f e is exactly the same as Ctrl-x Ctrl-c anyway! If the OP really want to quit emacs without being prompted to save any buffes then run the 'kill-emacs' command which isn't bound to a key by default. You would do this with Alt-X kill-emacs But the fact that it isn't bound to a key by default means that it isn't recommended (and I've never used it in 10 years of using emacs!) - just use Ctrl-X Ctrl-C as Richard Stallman intended ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ben+python at benfinney.id.au Fri Jun 5 04:34:26 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 18:34:26 +1000 Subject: how to create a big list of list References: <4gI9c7$wD1@alexbbs.twbbs.org> Message-ID: <87k53rkrjh.fsf@benfinney.id.au> command.bbs at alexbbs.twbbs.org (???M???v???@????) writes: > if i want to create a list of list which size is 2**25 > > how should i do it? > > i have try [ [] for x in xrange(2**25) ] > > but it take too long to initial the list > > is there any suggestion? What is it you want to do with the result? If you want to lazy-evaluate the expression, what you're looking for is a generator. You can get one easily by writing a generator expression: >>> foo = ([] for x in xrange(2**25)) >>> foo >>> for item in foo: ... do_interesting_stuff_with(item) If what you want is to have a huge multi-dimensional array for numerical analysis, lists may not be the best option. Instead, install the third-party NumPy library and use its types. You don't show what kind of data you want in your array, but assuming you want integers initialised to zero: >>> import numpy >>> foo = numpy.zeros((2**25, 0), int) >>> foo array([], shape=(33554432, 0), dtype=int32) Other quick ways of constructing NumPy arrays exist, see . -- \ ?Prediction is very difficult, especially of the future.? | `\ ?Niels Bohr | _o__) | Ben Finney From gagsl-py2 at yahoo.com.ar Fri Jun 5 04:47:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 05:47:41 -0300 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey escribi?: > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > URL: > > http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip > > Have it save the ZIP to any destination directory. For me, this only > downloads about 40KB before it stops without any error at all. Any > reason why this isn't working? I could not reproduce it. I downloaded about 300K without error (Python 3.0.1 on Windows) -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 04:54:47 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 10:54:47 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <18983.64840.555702.403634@montanaro.dyndns.org> Message-ID: <002d01c9e5bf$aaead240$0d00a8c0@Hendrik> wrote: > Got some use cases? plural cases - no. I did it for the reason already described. to elucidate, the code looks something like this: rec = input_q.get() # <=== this has its origen in a socket, as a netstring. reclist = rec.split(',') if reclist[0] == 'A': do something with the outputs get hold of the latest inputs return the result by putting a message on the normal output q. continue # up to here this is the code that is done in 99.9999% of cases. # note that it has to run as fast as possible, in a very cripple processor. if reclist[0] == "B": # This means we have to change state, # it comes from another thread that did # not exist before an event. new_output_q = uncan(reclist[1]) # <== This is where it is used while True: do similar stuff until normality is re established, discarding the incoming "A" records, using new "C" records and new_output_q. Terminated by a "D" record. It is simply a different way of saying "use this one", in an in band way. In the above, it avoids a double unpacking step - once to get to the record type, and then to get to the actual data. It only makes sense here because I know that the stuff that comes in is basically an unending stream of more of the same, and it happens - I would say thousands of times a second, but it is more like a hundred or so, given the lack of speed of the processor. So I am quite prepared to trade off the slight inefficiency during the seldom occurring changeover for the railroad like chugging along in the vast majority of cases. "seldom" here is like once a day for a few minutes. And it sure beats the hell out of passing the queue name as a string and mucking around with exec or eval - That is what I did first, and I liked it even less, as the queue passed in such a way had to be a global for the exec to work. It all started because I was not prepared to waste precious cycles in an extra unpacking stage. So I wrote the Can extension module, and I thought it weird enough to make it public: - Hands up those who have ever passed a pointer as a string ! - Hendrik From steven at REMOVE.THIS.cybersource.com.au Fri Jun 5 04:55:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 08:55:50 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 23:10:33 -0700, Mensanator wrote: >> "Everybody" knows? Be careful with those sweeping generalizations. >> Combinatorics is a fairly specialized area not just of programming but >> mathematics as well. > > I would expect that. That was supposed to be funny. I knew that! I was just testing to see if everyone else did... *wink* -- Steven From cournape at gmail.com Fri Jun 5 04:56:05 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 5 Jun 2009 17:56:05 +0900 Subject: PYTHONPATH and multiple python versions Message-ID: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> Hi, As I don't have admin privileges on my main dev machine, I install a good deal of python modules somewhere in my $HOME, using PYTHONPATH to point my python intepreter to the right location. I think PEP370 (per-user site-packages) does exactly what I need, but it works only for python 2.6 and above. Am I out of luck for versions below ? David From paul at boddie.org.uk Fri Jun 5 05:11:22 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 5 Jun 2009 02:11:22 -0700 (PDT) Subject: Yet another unicode WTF References: Message-ID: On 5 Jun, 03:18, Ron Garret wrote: > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. ?Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. The only way to think about this (in Python 2.x, at least) is to consider stream and file objects as things which only understand plain byte strings. Consequently, use of the codecs module is required if receiving/sending Unicode objects from/to streams and files. Paul From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:15:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:15:43 -0300 Subject: __file__ access extremely slow References: Message-ID: En Fri, 05 Jun 2009 00:12:25 -0300, John Machin escribi?: >> > (2) This will stop processing on the first object in sys.modules that >> > doesn't have a __file__ attribute. Since these objects aren't >> > *guaranteed* to be modules, > > Definitely not guaranteed to be modules. Python itself drops non-modules > in > there! Python 2.3 introduced four keys mapped to None -- one of these was > dropped in 2.4, but the other three are still there in 2.5 and 2.6: In case someone wonders what all those None are: they're a "flag" telling the import machinery that those modules don't exist (to avoid doing a directory scan over and over, because Python<2.7 attempts first to do a relative import, and only if unsuccessful attempts an absolute one) > C:\junk>\python23\python -c "import sys; print [k for (k, v) in > sys.modules.items() if v is None]" > ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', > 'encodings.types'] In this case, somewhere inside the encodings package, there are statements like "import types" or "from types import ...", and Python could not find types.py in the package directory. -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 05:24:52 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 11:24:52 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> Message-ID: <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > It just smells to me that you've created this elaborate and brittle hack > to work around the fact that you couldn't think of any other way of > getting the thread to change it's behaviour whilst waiting on input. I am beginning to think that you are a troll, as all your comments are haughty and disparaging, while you either take no trouble to follow, or are incapable of following, my explanations. In the event that this is not the case, please try to understand my reply to Skip, and then suggest a way that will perform better in my use case, out of your vast arsenal of better, quicker, more reliable, portable and comprehensible ways of doing it. - Hendrik From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:26:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:26:11 -0300 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: En Fri, 05 Jun 2009 01:49:15 -0300, Aahz escribi?: > In article > <05937a34-5490-4b31-9f07-a319b44ddb09 at r33g2000yqn.googlegroups.com>, > Michele Simionato wrote: >> >> Actually, in Scheme one would have to fight to define >> a list comprehension (more in general loops) working as >> in Python: the natural definition works as the OP wants. See >> http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156 > > This URL isn't working for me, gives 500. Mmm, the URL ends with: thread, an equals sign, and the number 251156 If you see =3D -- that's the "=" encoded as quoted-printable... -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 05:29:14 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 11:29:14 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <20090604162333.22176.668277797.divmod.quotient.1904@henry.divmod.com> Message-ID: <001201c9e5c0$1e853e20$0d00a8c0@Hendrik> "Jean-Paul Calderone" wrote: > So, do you mind sharing your current problem? Maybe then it'll make more > sense why one might want to do this. Please see my reply to Skip that came in and was answered by email. - Hendrik From nick at craig-wood.com Fri Jun 5 05:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 05 Jun 2009 04:29:41 -0500 Subject: unladen swallow: python and llvm References: Message-ID: Luis M Gonz?lez wrote: > I am very excited by this project (as well as by pypy) and I read all > their plan, which looks quite practical and impressive. > But I must confess that I can't understand why LLVM is so great for > python and why it will make a difference. CPython uses a C compiler to compile the python code (written in C) into native machine code. unladen-swallow uses an llvm-specific C compiler to compile the CPython code (written in C) into LLVM opcodes. The LLVM virtual machine executes those LLVM opcodes. The LLVM virtual machine also has a JIT (just in time compiler) which converts the LLVM op-codes into native machine code. So both CPython and unladen-swallow compile C code into native machine code in different ways. So why use LLVM? This enables unladen swallow to modify the python virtual machine to target LLVM instead of the python vm opcodes. These can then be run using the LLVM JIT as native machine code and hence run all python code much faster. The unladen swallow team have a lot more ideas for optimisations, but this seems to be the main one. It is an interesting idea for a number of reasons, the main one as far as I'm concerned is that it is more of a port of CPython to a new architecture than a complete re-invention of python (like PyPy / IronPython / jython) so stands a chance of being merged back into CPython. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jonas.esp at googlemail.com Fri Jun 5 05:39:31 2009 From: jonas.esp at googlemail.com (Kless) Date: Fri, 5 Jun 2009 02:39:31 -0700 (PDT) Subject: Uppercase/Lowercase on unicode Message-ID: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Is there any librery that works ok with unicode at converting to uppercase or lowercase? -------------- >>> foo = u'??????' >>> print(foo.upper()) ???????????? -------------- From ben+python at benfinney.id.au Fri Jun 5 05:51:03 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 19:51:03 +1000 Subject: Yet another unicode WTF References: Message-ID: <878wk7knzs.fsf@benfinney.id.au> Paul Boddie writes: > The only way to think about this (in Python 2.x, at least) is to > consider stream and file objects as things which only understand plain > byte strings. Consequently, use of the codecs module is required if > receiving/sending Unicode objects from/to streams and files. Actually strings in Python 2.4 or later have the ?encode? method, with no need for importing extra modules: ===== $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' ? $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > foo ; cat foo ? ===== -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From ben+python at benfinney.id.au Fri Jun 5 05:54:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 19:54:25 +1000 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: <874ouvknu6.fsf@benfinney.id.au> Kless writes: > Is there any librery that works ok with unicode at converting to > uppercase or lowercase? > > -------------- > >>> foo = u'??????' > > >>> print(foo.upper()) > ???????????? > -------------- Works fine for me. What do you get when trying to replicate this: >>> import sys >>> sys.version '2.5.4 (r254:67916, Feb 18 2009, 04:30:07) \n[GCC 4.3.3]' >>> sys.stdout.encoding 'UTF-8' >>> foo = u'??????' >>> print(foo.upper()) ?????? -- \ ?I was sad because I had no shoes, until I met a man who had no | `\ feet. So I said, ?Got any shoes you're not using??? ?Steven | _o__) Wright | Ben Finney From redforks at gmail.com Fri Jun 5 05:56:35 2009 From: redforks at gmail.com (Red Forks) Date: Fri, 5 Jun 2009 17:56:35 +0800 Subject: multi-core software In-Reply-To: <4A28333D.6030304@mrabarnett.plus.com> References: <20090616103324.200@gmail.com> <4A28333D.6030304@mrabarnett.plus.com> Message-ID: <3f18b3f10906050256w791ba4ecj67969252ea6824ef@mail.gmail.com> Single - thread programming is great! clean, safe!!! I'm trying schedual task to several work process (not thread). On Fri, Jun 5, 2009 at 4:49 AM, MRAB wrote: > Kaz Kylheku wrote: > >> ["Followup-To:" header set to comp.lang.lisp.] >> On 2009-06-04, Roedy Green wrote: >> >>> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >>> wrote, quoted or indirectly quoted someone who said : >>> >>> ? Why Must Software Be Rewritten For Multi-Core Processors? >>>> >>> Threads have been part of Java since Day 1. >>> >> >> Unfortunately, not sane threads designed by people who actually understand >> multithreading. >> >> The nice thing about Java is whether you are on a single core >>> processor or a 256 CPU machine (We got to run our Athena Integer Java >>> spreadsheet engine on such a beast), does not concern your code. >>> >> >> You are dreaming if you think that there are any circumstances (other than >> circumstances in which performance doesn't matter) in which you don't have >> to >> concern yourself about the difference between a uniprocessor and a 256 CPU >> machine. >> > > If you're interested in parallel programming, have a look at Flow-Based > Programming: > > http://www.jpaulmorrison.com/fbp/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:59:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:59:07 -0300 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: En Fri, 05 Jun 2009 06:39:31 -0300, Kless escribi?: > Is there any librery that works ok with unicode at converting to > uppercase or lowercase? > > -------------- >>>> foo = u'??????' > >>>> print(foo.upper()) > ???????????? > -------------- Looks like Python thinks your terminal uses utf-8, but it actually uses another encoding (latin1?) Or, you saved the script as an utf-8 file but the encoding declaration says otherwise. This works fine for me: py> foo = u'??????' py> print foo ?????? py> print foo.upper() ?????? -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 06:00:24 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 12:00:24 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org><002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> "Terry Reedy" wrote: > If I understand correctly, your problem and solution was this: > > You have multiple threads within a long running process. One thread > repeatedly reads a socket. Yes and it puts what it finds on a queue. - it is a pre defined simple comma delimited record. > You wanted to be able to occasionally send > an object to that thread. Close - to another thread that reads the queue, actually. > Rather than rewrite the thread to also poll a > queue.Queue(), which for CPython sends objects by sending a pointer, It is in fact reading a queue, and what it gets out in the vast majority of cases is the record that came from the socket. >you > converted pointers to strings and sent (multiplex) them via the text > stream the thread was already reading -- and modified the thread to > decode and act on the new type of message. Basically yes - the newly created thread just puts a special text string onto the queue. As I pointed out in my reply to Skip, this makes the unpacking at the output of the queue standard, just using split(','), and it is this simplicity that I wanted to preserve, as it happens almost all of the time. > And you are willing to share the can code with someone who has a similar > rare need and understands the danger of interpreting ints as addresses. > Correct? Absolutely right on - I do not think that it is the kind of thing that should be in the std lib, except as a kind of Hara Kiri bomb - uncan(a random number string), and die! It would also help if someone who is more knowledgable about python would have a look at the C code to make it more robust. There are only 2 routines that matter - it is about a screenfull. - Hendrik From redforks at gmail.com Fri Jun 5 06:04:50 2009 From: redforks at gmail.com (Red Forks) Date: Fri, 5 Jun 2009 18:04:50 +0800 Subject: PYTHONPATH and multiple python versions In-Reply-To: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> References: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> Message-ID: <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> maybe a shell script to switch PYTHONPATH, like: start-python-2.5 start-python-2.4 ... On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau wrote: > Hi, > > As I don't have admin privileges on my main dev machine, I install a > good deal of python modules somewhere in my $HOME, using PYTHONPATH to > point my python intepreter to the right location. I think PEP370 > (per-user site-packages) does exactly what I need, but it works only > for python 2.6 and above. Am I out of luck for versions below ? > > David > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.esp at googlemail.com Fri Jun 5 06:09:49 2009 From: jonas.esp at googlemail.com (Kless) Date: Fri, 5 Jun 2009 03:09:49 -0700 (PDT) Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: On 5 jun, 09:59, "Gabriel Genellina" wrote: > En Fri, 05 Jun 2009 06:39:31 -0300, Kless ? > escribi?: > > > Is there any librery that works ok with unicode at converting to > > uppercase or lowercase? > > > -------------- > >>>> foo = u'??????' > > >>>> print(foo.upper()) > > ???????????? > > -------------- > > Looks like Python thinks your terminal uses utf-8, but it actually uses ? > another encoding (latin1?) > Or, you saved the script as an utf-8 file but the encoding declaration ? > says otherwise. > > This works fine for me: > > py> foo = u'??????' > py> print foo > ?????? > py> print foo.upper() > ?????? > > -- > Gabriel Genellina I just to check it in the python shell and it's correct. Then the problem is by iPython that I was testing it from there. From michele.simionato at gmail.com Fri Jun 5 06:20:24 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 03:20:24 -0700 (PDT) Subject: a problem with concurrency Message-ID: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> At work we have a Web application acting as a front-end to a database (think of a table-oriented interface, similar to an Excel sheet). The application is accessed simultaneously by N people (N < 10). When a user posts a requests he changes the underlying database table. The issue is that if more users are editing the same set of rows the last user will override the editing of the first one. Since this is an in-house application with very few users, we did not worry to solve this issue, which happens very rarely. However, I had a request from the people using the application, saying that this issue indeed happens sometimes and that they really would like to be able to see if some other user is editing a row. In that case, the web interface should display the row as not editable, showing the name of the user which is editing it. Moreover, when posting a request involving non-editable rows, there should be a clear error message and the possibility to continue anyway (a message such as "do you really want to override the editing made by user XXX?"). Looks like a lot of work for an application which is very low priority for us. Also, I do not feel too confident with managing concurrency directly. However, just for the sake of it I have written a prototype with the basic functionality and I am asking here for some advice, since I am sure lots of you have already solved this problem. My constraint are: the solution must work with threads (the web app uses the Paste multithreaded server) but also with processes (while the server is running a batch script could run and set a few rows). It also must be portable across databases, since we use both PostgreSQL and MS SQLServer. The first idea that comes to my mind is to add a field 'lockedby' to the database table, containing the name of the user which is editing that row. If the content of 'lockedby' is NULL, then the row is editable. The field is set at the beginning (the user will click a check button to signal - via Ajax - that he is going to edit that row) to the username and reset to NULL after the editing has been performed. This morning I had a spare hour, so I wrote a 98 lines prototype which has no web interface and does not use an ORM, but has the advantage of being easy enough to follow; you can see the code here: http://pastebin.com/d1376ba05 The prototype uses SQLite and works in autocommit mode (the real application works in autocommit mode too, even if with different databases). I have modelled the real tables with a simple table like this: CREATE TABLE editable_data ( rowid INTEGER PRIMARY KEY, text VARCHAR(256), lockedby VARCHAR(16)) There is thread for each user. The test uses 5 threads; there is no issue of scalability, since I will never have more than 10 users. The basic idea is to use a RowLock object with signature RowLock(connection, username, tablename, primarykeydict) with __enter__ and __exit__ methods setting and resetting the lockedby field of the database table respectively. It took me more time to write this email than to write the prototype, so I do not feel confident with it. Will it really work for multiple threads and multiple processes? I have always managed to stay away from concurrency in my career ;-) Michele Simionato From michele.simionato at gmail.com Fri Jun 5 06:22:26 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 03:22:26 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <52fa32e4-d946-4c27-80b0-62a13e1ce624@k38g2000yqh.googlegroups.com> On Jun 5, 11:26?am, "Gabriel Genellina" wrote: > Mmm, the URL ends with: thread, an equals sign, and the number 251156 > If you see =3D -- that's the "=" encoded as quoted-printable... Actually this is the right URL: http://www.artima.com/weblogs/viewpost.jsp?thread=251156 From thudfoo at opensuse.us Fri Jun 5 06:29:41 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Fri, 5 Jun 2009 03:29:41 -0700 Subject: Feedparser problem In-Reply-To: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: <3d881a310906050329h54560f21u4f0047b7598b4eb0@mail.gmail.com> On 6/4/09, Jonathan Nelson wrote: > I'm trying to add a feedreader element to my django project. I'm > using Mark Pilgrim's great feedparser library. I've used it before > without any problems. I'm getting a TypeError I can't figure out. > I've tried searching google, bing, google groups to no avail. > > Here's the dpaste of what I'm trying to do and the result I'm > getting: > > http://dpaste.com/51406/ > > I've tried checking my firewall settings. I'm using Windows 7 and > Python 2.6. Win 7 is allowing other Python programs through. I've > tried several different RSS urls with the same result. > > Any thoughts would be greatly appreciated. > from feedparser 4.1 documentation: bozo_exception The exception raised when attempting to parse a non-well-formed feed. I suspect that unexpected keyword "timeout" appears in the feed's xml document. You could download the document yourself and have a look. > -- > http://mail.python.org/mailman/listinfo/python-list > From tkjthingone at gmail.com Fri Jun 5 06:35:25 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 5 Jun 2009 03:35:25 -0700 Subject: Am I doing this the python way? (list of lists + file io) Message-ID: Hello, I'm a fairly new python programmer (aren't I unique!) and a somewhat longer C/++ programmer (4 classes at a city college + lots and lots of tinkering on my own). I've started a pet project (I'm really a blacksheep!); the barebones of it is reading data from CSV files. Each CSV file is going to be between 1 and ~500 entries/lines, I can't see them being much bigger than that, though 600 entries/lines might be possible. As for the total number of CSV files I will be reading in, I can't see my self going over several hundred (200-300), though 500 isn't to much of a stretch and 1000 files *could* happen in the distant future. So, I read the data in from the CSV file and store each line as an entry in a list, like this (I have slightly more code, but this is basically what I'm doing) *FilepathVar = "my/file/path/csv.txt" import csv reader = csv.reader(open(FilepathVar,"rb"), delimiter=',') entryGrouping = [] # create a list for entry in reader: entryGrouping.append(entry)* This produces a list (entryGrouping) where I can do something like ( *print entryGrouping[0]* ) and get the first row/entry of the CSV file. I could also do ( *print entryGrouping[0][0]* ) and get the first item in the first row. All is well and good, codewise, I hope? Then, since I wanted to be able to write in multiple CSV files (they have the same structure, the data relates to different things) I did something like this to store multiple entryGroupings... *masterList = [] # create a list masterList.append(entryGrouping) # ... # load another CSV file into entryGrouping # ... masterList.append(entryGrouping)* Which lets me write code like this... * print masterList[0] # prints an entire entryGrouping print masterList[0][0] # prints the first entry in entryGrouping print masterList[0][0][0] # prints the first item in the first row of the first entryGrouping... * So, my question (because I did have one!) is thus: I'm I doing this in a pythonic way? Is a list of lists (of lists?) a good way to handle this? As I start adding more CSV files, will my program grind to a halt? To answer that, you might need some more information, so I'll try and provide a little right now as to what I expect to be doing... (It's still very much in the planning phases, and a lot of it is all in my head) So, Example: I'll read in a CSV file (just one, for now.) and store it into a list. Sometime later, I'll get another CSV file, almost identical/related to the first. However, a few values might have changed, and there might be a few new lines (entries) or maybe a few less. I would want to compare the CSV file I have in my list (in memory) to new CSV file (which I would probably read into a temporary list). I would then want to track and log the differences between the two files. After I've figured out what's changed, I would either update the original CSV file with the new CSV's information, or completely discard the original and replace it with the new one (whichever involves less work). Basically, lots of iterating through each entry of each CSV file and comparing to other information (either hard coded or variable). So, to reiterate, are lists what I want to use? Should I be using something else? (even if that 'something else' only really comes into play when storing and operating on LOTS of data, I would still love to hear about it!) Thank you for taking the time to read this far. I apologize if I've mangled any accepted terminology in relation to python or CSV files. - Ira (P.S. I've read this through twice now and tried to catch as many errors as I could. It's late (almost 4AM) so I'm sure to have missed some. If something wasn't clear, point it out please. See you in the morning! - er, more like afternoon!) -------------- next part -------------- An HTML attachment was scrubbed... URL: From javier.collado at gmail.com Fri Jun 5 06:37:27 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 5 Jun 2009 12:37:27 +0200 Subject: PYTHONPATH and multiple python versions In-Reply-To: <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> References: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> Message-ID: Hello, I think that virtualenv could also do the job. Best regards, Javier 2009/6/5 Red Forks : > maybe a shell script to switch PYTHONPATH, like: > start-python-2.5 > start-python-2.4 ... > On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau wrote: >> >> Hi, >> >> As I don't have admin privileges on my main dev machine, I install a >> good deal of python modules somewhere in my $HOME, using PYTHONPATH to >> point my python intepreter to the right location. I think PEP370 >> (per-user site-packages) does exactly what I need, but it works only >> for python 2.6 and above. Am I out of luck for versions below ? >> >> David >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From gagsl-py2 at yahoo.com.ar Fri Jun 5 06:54:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 07:54:30 -0300 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: En Fri, 05 Jun 2009 07:00:24 -0300, Hendrik van Rooyen escribi?: > "Terry Reedy" wrote: > >> You have multiple threads within a long running process. One thread >> repeatedly reads a socket. > > Yes and it puts what it finds on a queue. - it is a pre defined simple > comma > delimited record. > >> You wanted to be able to occasionally send >> an object to that thread. > > Close - to another thread that reads the queue, actually. > >> Rather than rewrite the thread to also poll a >> queue.Queue(), which for CPython sends objects by sending a pointer, > > It is in fact reading a queue, and what it gets out in the vast majority > of > cases is the record that came from the socket. Ah... I had the same impression as Mr. Reedy, that you were directly reading from a socket and processing right there, so you *had* to use strings for everything. But if you already have a queue, you may put other objects there (instead of "canning" them). Testing the object type with isinstance(msg, str) is pretty fast, and if you bind locally those names I'd say the overhead is negligible. -- Gabriel Genellina From pataphor at gmail.com Fri Jun 5 07:04:37 2009 From: pataphor at gmail.com (pataphor) Date: Fri, 5 Jun 2009 11:04:37 +0000 (UTC) Subject: Making the case for repeat References: Message-ID: Gabriel Genellina wrote: > Ok, you're proposing a "bidimensional" repeat. I prefer to keep things > simple, and I'd implement it in two steps. But what is simple? I am currently working on a universal feature creeper that could replace itertools.cycle, itertools.repeat, itertools.chain and reverse and also helps to severely cut down on itertools.islice usage. All within virtually the same parameter footprint as the last function I posted. The problem is posting *this* function would kill my earlier repeat for sure. And it already had a problem with parameters < 0 (Hint: that last bug has now become a feature in the unpostable repeat implementation) > Note that this doesn't require any additional storage. Second step would > be to build a bidimensional repeat: Thanks for reminding me, but the storage savings only work for a 'single cycle' function call. But I guess one could special case for that. > py> one = chain.from_iterable(repeat(elem, 3) for elem in thing) > py> two = chain.from_iterable(tee(one, 2)) > py> list(two) > ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', > '1', '2', > '2', '2', '3', '3', '3', '4', '4', '4'] > > Short and simple, but this one requires space for one complete run (3*4 > items in the example). Really? I count 4 nested functions and an iterator comprehension. I guess it's a tradeoff between feature creep and function nesting creep. P. From paul at boddie.org.uk Fri Jun 5 07:06:50 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 5 Jun 2009 04:06:50 -0700 (PDT) Subject: Yet another unicode WTF References: <878wk7knzs.fsf@benfinney.id.au> Message-ID: On 5 Jun, 11:51, Ben Finney wrote: > > Actually strings in Python 2.4 or later have the ?encode? method, with > no need for importing extra modules: > > ===== > $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > ? > > $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > foo ; cat foo > ? > ===== Those are Unicode objects, not traditional Python strings. Although strings do have decode and encode methods, even in Python 2.3, the former is shorthand for the construction of a Unicode object using the stated encoding whereas the latter seems to rely on the error-prone automatic encoding detection in order to create a Unicode object and then encode the result - in effect, recoding the string. As I noted, if one wants to remain sane and not think about encoding everything everywhere, creating a stream using a codecs module function or class will permit the construction of something which deals with Unicode objects satisfactorily. Paul From ldo at geek-central.gen.new_zealand Fri Jun 5 07:17:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:17:25 +1200 Subject: Project source code layout? References: Message-ID: In message , Dave Angel wrote: > Lawrence D'Oliveiro wrote: > >> In message , Dave >> Angel wrote: >> >>> Rather than editing the source files at install time, consider just >>> using an environment variable in your testing environment, which would >>> be missing in production environment. >>> >> >> I'd still need to define that environment variable in a wrapper script, >> which means editing that script at install time ... back to square one >> ... >> > No, the whole point is it's an environment variable which is *missing" > in production environment. Make sure you make it an obscure name, like > set MyProductName_TestingMode=1 > > So the way you know you're in a production environment is that you do > not have such an environment variable. Sounds like a very roundabout solution to the wrong problem. From jeanmichel at sequans.com Fri Jun 5 07:23:23 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Jun 2009 13:23:23 +0200 Subject: Messing up with classes and their namespace Message-ID: <4A29002B.4070100@sequans.com> Hello world, I had recently a very nasty bug in my python application. The context is quite complex, but in the end the problem can be resume as follow: 2 files in the same directory : lib.py: >import foo >foo.Foo.BOOM='lib' foo.py: >class Foo: > BOOM = 'Foooo' > >if __name__=='__main__': > import lib # I'm expecting BOOM to be set to 'lib' > print Foo.BOOM I was expecting 'lib' as output, but I got 'Fooo'. I don't really understand what python mechanism I'm messing with but I have the feeling I've misunderstood a very basic concept about class, namespace or whatever import notion. This is how I made it work: >if __name__=='__main__': > from lib import Foo # make sure Foo comes from lib > print Foo.BOOM I guess there is 2 different objects for the same class Foo. How I do I make both Foo objects the same object ? Jean-Michel From ldo at geek-central.gen.new_zealand Fri Jun 5 07:25:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:25:51 +1200 Subject: Adding a Par construct to Python? References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <02200d22$0$20645$c3e8da3@news.astraweb.com> <_vidnQW0dJoGg43XnZ2dnUVZ_hpi4p2d@posted.usinternet> <0220260f$0$20645$c3e8da3@news.astraweb.com> <77as23F1fhj3uU1@mid.uni-berlin.de> Message-ID: In message <77as23F1fhj3uU1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: >> But reduce()? I can't see how you can parallelize reduce(). By its >> nature, it has to run sequentially: it can't operate on the nth item >> until it is operated on the (n-1)th item. > > That depends on the operation in question. Addition for example would > work. My math-skills are a bit too rusty to qualify the exact nature of > the operation, commutativity springs to my mind. Associativity: ((A op B) op C) = (A op (B op C)) So for example A op B op C op D could be grouped into (A op B) op (C op D) and the two parenthesized subexpressions evaluated concurrently. But this would only give you a speedup that was logarithmic in the number of op's. From ldo at geek-central.gen.new_zealand Fri Jun 5 07:35:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:35:07 +1200 Subject: Adding a Par construct to Python? References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <1e6e1616-c888-43a3-a5b5-0739b8f77236@m24g2000vbp.googlegroups.com> <477992d9-271f-4c0c-a7f8-b0c98bdefe55@q14g2000vbn.googlegroups.com> Message-ID: In message , Steven D'Aprano wrote: > threads = [PMapThread(datapool) for i in xrange(numthreads)] Shouldn?t that ?PMapThread? be ?thread?? From no.email at please.post Fri Jun 5 07:50:50 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 11:50:50 +0000 (UTC) Subject: fastest way to test file for string? Message-ID: Hi. I need to implement, within a Python script, the same functionality as that of Unix's grep -rl some_string some_directory I.e. find all the files under some_directory that contain the string "some_string". I imagine that I can always resort to the shell for this, but is there an efficient way of doing it within Python? (BTW, portability is not high on my list here; this will run on a Unix system, and non-portable Unix-specific solutions are fine with me.) TIA! -- From enleverLesX_XXmcX at XmclavXeauX.com Fri Jun 5 08:46:25 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Fri, 05 Jun 2009 13:46:25 +0100 Subject: python way to automate IE8's File Download dialog References: Message-ID: <4a290592$0$17084$ba4acef3@news.orange.fr> Hi! Suppose that the (web) site give the file only after several seconds, and after the user click a confirm (example: RapidFile). Suppose that the (web) site give the file only after the user input a code, controled by a javascript script. @-salutations -- Michel Claveau From ebonak at hotmail.com Fri Jun 5 08:50:48 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 05 Jun 2009 08:50:48 -0400 Subject: pylint naming conventions? Message-ID: Hi, as someone who is still learning a lot about Python I am making use of all the tools that can help me, such as pyflakes, pychecker and pylint. I am confused by pylint's naming conventions, I don't think the are in tune with Python's style recommendations (PEP 8?) Anyone else think this? Is there an easy way to get this in compliance? Or lacking this just turn this off (I'd rather not turn it off if it's easy to get in tune with the standards). Or am I wrong about my assertion with regard to the naming conventions? Thanks, Esmail ps: if anyone else wants to toss in some other recommendations for useful tools feel free to do so! From skip at pobox.com Fri Jun 5 08:54:16 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 07:54:16 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <18985.5496.307567.338917@montanaro.dyndns.org> >> Requiring that the C++ compiler used to make the dll's/so's to be the >> same one Python is compiled with wouldn't be too burdensome would it? Scott> And what gave you then impression that Python is compiled with a Scott> C++ compiler? I don't think it's too much to expect that a C++ compiler be available for the configure step if Python is being built in a C++ shop. The C compiler used to build Python proper should be compatible with the C++ compiler available to build C++ extension modules or C++ libraries dynamically linked into Python. If there is no C++ compiler available then the proposed layout sniffing just wouldn't be done and either a configure error would be emitted or a run-time exception raised if a program attempted to use that feature. (Or the sniffing could be explicitly enabled/disabled by a configure flag.) -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From python.list at tim.thechases.com Fri Jun 5 08:59:22 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Jun 2009 07:59:22 -0500 Subject: a problem with concurrency In-Reply-To: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> References: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> Message-ID: <4A2916AA.1000501@tim.thechases.com> > When a user posts a requests he changes the underlying database > table. The issue is that if more users are editing the > same set of rows the last user will override the editing of the > first one. Since this is an in-house application with very few > users, we did not worry to solve this issue, which happens > very rarely. However, I had a request from the people using > the application, saying that this issue indeed happens sometimes > and that they really would like to be able to see if some other > user is editing a row. In that case, the web interface should > display the row as not editable, showing the name of the user > which is editing it. Moreover, when posting a request involving > non-editable rows, there should be a clear error message and > the possibility to continue anyway (a message such as > "do you really want to override the editing made by user XXX?"). The common way to do this is to not bother with the "somebody else is editing this record" because it's nearly impossible with the stateless web to determine when somebody has stopped browsing a web page. Instead, each record simply has a "last modified on $TIMESTAMP by $USERID" pair of field. When you read the record to display to the user, you stash these values into the page as $EXPECTED_TIMESTAMP and $EXPECTED_USERID. If, when the user tries to save the record, your web-server app updates the record only if the timestamp+username+rowid match: cursor.execute(""" UPDATE MyTable SET Field1=?, Field2=?, Field3=? WHERE id=? AND LastModified=? AND LastModifiedBy=?""", (field1, field2, field3, rowid, expected_lastmodified, expecteduserid) ) if cursor.rowcount: cursor.commit() print "Yay!" else: cursor.execute(""" SELECT u.name, t.lastmodified FROM MyTable t INNER JOIN MyUsers u ON u.id = t.LastModifiedBy WHERE t.id = ?""", (rowid,)) # maybe a little try/except around this in case # the record was deleted instead of modified? name, when = cursor.fetchone() print "This information has been modified " \ "(by %s at %s) since you last viewed it (at %s)" % ( name, when, expected_lastmodified) If you wanted to be really snazzy, you could pull up the existing new record alongside the data they tried to submit, and allow them to choose the correct value for each differing field. This also encourages awareness of conflicting edits and hopefully increases communication between your users ("Why is Pat currently editing this record...I'm working on it?!" [calls/IMs/emails Pat to get matters straight]) > The first idea that comes to my mind is to add a field 'lockedby' > to the database table, containing the name of the user which is > editing that row. If the content of 'lockedby' is NULL, then the > row is editable. The field is set at the beginning (the user will > click a check button to signal - via Ajax - that he is going > to edit that row) to the username and reset to NULL after the > editing has been performed. Locking is the easy part -- it's knowing when to *unlock* that it becomes a problem. What happens if a user locks a record at 4:59pm on Friday afternoon and then goes on vacation for a week preventing folks from editing this record? If the locks are scoped to a single request, they do no good. The locks have to span multiple requests. I'd just ignore locking. -tkc From willgun at live.cn Fri Jun 5 09:00:44 2009 From: willgun at live.cn (willgun) Date: Fri, 05 Jun 2009 21:00:44 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Mark Tolonen ??: > > "willgun" wrote in message > news:h08c5e$aub$1 at news.cn99.com... >> By the way ,what does 'best regards' means at the end of a mail? > > I think ?? may be a good translation. > > -Mark > > O(?_?)O?? Glad to meet a foreigner know Chinese, :-) . But in my opinion,?? means congratulation,while ? means best regards. From xahlee at gmail.com Fri Jun 5 09:03:45 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 5 Jun 2009 06:03:45 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: On May 25, 10:35 am, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, and why. I normally use vi, and just got > into Python, so I am looking for suitable syntax files for it, and > extra utilities. I dabbled with emacs at some point, but couldn't get > through the key bindings for commands. I've never tried emacs with vi > keybindings (I forgot the name of it) but I've been tempted. > > So what do you guys use, and why? Hopefully we can keep this civil. I use emacs. If you never tried emacs, you might check out: ? Xah's Emacs Tutorial http://xahlee.org/emacs/emacs.html ? Xah's Emacs Lisp Tutorial http://xahlee.org/emacs/elisp.html you can use python to write emacs commands: ? Elisp Wrapper For Perl Scripts http://xahlee.org/emacs/elisp_perl_wrapper.html Emacs keyboard shortcuts is problematic indeed. See: ? Why Emacs's Keyboard Shortcuts Are Painful http://xahlee.org/emacs/emacs_kb_shortcuts_pain.html However, you can completely fix that. See: ? Ergoemacs Keybindings http://xahlee.org/emacs/ergonomic_emacs_keybinding.html Xah ? http://xahlee.org/ ? From willgun at live.cn Fri Jun 5 09:04:49 2009 From: willgun at live.cn (willgun) Date: Fri, 05 Jun 2009 21:04:49 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Gabriel Genellina ??: > En Thu, 04 Jun 2009 03:14:18 -0300, willgun escribi?: > >> I'm a student from China.It's painful for us to read python >> documentation entirely due to poor english.So I often make these >> mistakes. > > Try "chinese python group" at Google - I see some promising results at > least... > Good idea. But I try to improve my english via visiting english ones. 15 days later,I'll go up for my english examination. From michele.simionato at gmail.com Fri Jun 5 09:08:46 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 15:08:46 +0200 Subject: a problem with concurrency In-Reply-To: <4A2916AA.1000501@tim.thechases.com> References: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> <4A2916AA.1000501@tim.thechases.com> Message-ID: <4edc17eb0906050608v509ef337n89dcf009d9821bab@mail.gmail.com> On Fri, Jun 5, 2009 at 2:59 PM, Tim Chase wrote: > The common way to do this is to not bother with the "somebody else is > editing this record" because it's nearly impossible with the stateless web > to determine when somebody has stopped browsing a web page. ?Instead, each > record simply has a "last modified on $TIMESTAMP by $USERID" pair of field. > ?When you read the record to display to the user, you stash these values > into the page as $EXPECTED_TIMESTAMP and $EXPECTED_USERID. ?If, when the > user tries to save the record, your web-server app updates the record only > if the timestamp+username+rowid match This is much easier to implement than the locking mechanism since I already have the fields $EXPECTED_TIMESTAMP and $EXPECTED_USERID in the db! It looks quite sufficient for my use case. From ben+python at benfinney.id.au Fri Jun 5 09:12:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 23:12:54 +1000 Subject: pylint naming conventions? References: Message-ID: <87skiekend.fsf@benfinney.id.au> Esmail writes: > I am confused by pylint's naming conventions, I don't think the are in > tune with Python's style recommendations (PEP 8?) > > Anyone else think this? It's hard to know, without examples. Can you give some output of pylint that you think doesn't agree with PEP 8? -- \ ?Are you thinking what I'm thinking, Pinky?? ?Uh... yeah, | `\ Brain, but where are we going to find rubber pants our size?? | _o__) ?_Pinky and The Brain_ | Ben Finney From python.list at tim.thechases.com Fri Jun 5 09:14:36 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Jun 2009 08:14:36 -0500 Subject: fastest way to test file for string? In-Reply-To: References: Message-ID: <4A291A3C.2010904@tim.thechases.com> > Hi. I need to implement, within a Python script, the same > functionality as that of Unix's > > grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". I'd do something like this untested function: def find_files_containing(base_dir, string_to_find): for path, files, dirs in os.walk(base_dir): for fname in files: full_name = os.path.join(path, fname) f = file(full_name) for line in f: if string_to_find in line: f.close() yield full_name break else: f.close() for filename in find_files_containing( "/path/to/wherever/", "some_string" ): print filename It's not very gracious regarding binary files, but caveat coder. -tkc From aahz at pythoncraft.com Fri Jun 5 09:24:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 06:24:38 -0700 Subject: Odd closure issue for generators References: <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> Message-ID: In article , Lawrence D'Oliveiro wrote: >In message ><78180b4c-68b2-4a0c-8594-50fb1ea2f414 at c19g2000yqc.googlegroups.com>, Michele >Simionato wrote: >> >> The crux is in the behavior of the for loop: in Python there is a >> single scope and the loop variable is *mutated* at each iteration, >> whereas in Scheme (or Haskell or any other functional language) a new >> scope is generated at each iteration and there is actually a new loop >> variable at each iteration: no mutation is involved. > >I think it's a bad design decision to have the loop index be a variable >that can be assigned to in the loop. Why? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From python at mrabarnett.plus.com Fri Jun 5 09:38:11 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Jun 2009 14:38:11 +0100 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: References: Message-ID: <4A291FC3.7010808@mrabarnett.plus.com> John Thingstad wrote: > P? Fri, 05 Jun 2009 08:07:39 +0200, skrev Xah Lee : > >> On Jun 3, 11:50 pm, Xah Lee wrote: > >> The point in these short examples is not about software bugs or >> problems. It illustrates, how seemingly trivial problems, such as >> networking, transferring files, running a app on Mac or Windwos, >> upgrading a app, often involves a lot subtle complexities. For mom and >> pop users, it simply stop them dead. For a senior industrial >> programer, it means some conceptually 10-minutes task often ends up in >> hours of tedium. > > What on earth gave you the idea that this is a trivial problem? > Networks have been researched and improved for the last 40 years! > It is a marvel of modern engineering that they work as well as they do. > [snip] The actual phrase was "/seemingly/ trivial problems", ie it /looks/ simple at first glance. From pruebauno at latinmail.com Fri Jun 5 09:54:15 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 5 Jun 2009 06:54:15 -0700 (PDT) Subject: fastest way to test file for string? References: Message-ID: On Jun 5, 7:50?am, kj wrote: > Hi. ?I need to implement, within a Python script, the same > functionality as that of Unix's > > ? ?grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". > > I imagine that I can always resort to the shell for this, but is > there an efficient way of doing it within Python? > > (BTW, portability is not high on my list here; this will run on a > Unix system, and non-portable Unix-specific solutions are fine with > me.) > > TIA! > -- You can write your own version of grep in python using os.walk, open, read and find. I don't know why one would want to do that unless for portability reasons. It will be pretty hard to beat grep in efficiency and succinctness. The most sensible thing IMHO is a shell script or call grep using os.system (or using subprocess). From theller at python.net Fri Jun 5 10:13:22 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 16:13:22 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <78sng2F1lbbekU1@mid.individual.net> skip at pobox.com schrieb: > >> Requiring that the C++ compiler used to make the dll's/so's to be the > >> same one Python is compiled with wouldn't be too burdensome would it? > > Scott> And what gave you then impression that Python is compiled with a > Scott> C++ compiler? > > I don't think it's too much to expect that a C++ compiler be available for > the configure step if Python is being built in a C++ shop. The C compiler > used to build Python proper should be compatible with the C++ compiler > available to build C++ extension modules or C++ libraries dynamically linked > into Python. > > If there is no C++ compiler available then the proposed layout sniffing just > wouldn't be done and either a configure error would be emitted or a run-time > exception raised if a program attempted to use that feature. (Or the > sniffing could be explicitly enabled/disabled by a configure flag.) > Hm, on Linux, gccxml (if its version is compatible with that of the C++ compiler) can probably help a lot. At runtime, no configure step needed. Unfortunately not on Windows. Thomas From rcdailey at gmail.com Fri Jun 5 10:30:26 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 07:30:26 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: On Jun 5, 3:47?am, "Gabriel Genellina" wrote: > En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey ? > escribi?: > > > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > > URL: > > >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > > Have it save the ZIP to any destination directory. For me, this only > > downloads about 40KB before it stops without any error at all. Any > > reason why this isn't working? > > I could not reproduce it. I downloaded about 300K without error ?(Python ? > 3.0.1 on Windows) > > -- > Gabriel Genellina Can you show me your test code please? From brian at sweetapp.com Fri Jun 5 10:36:32 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 05 Jun 2009 07:36:32 -0700 Subject: Odd closure issue for generators In-Reply-To: References: <4A28903B.4020301@sweetapp.com> Message-ID: <4A292D70.9020801@sweetapp.com> Ned Deily wrote: > In article <4A28903B.4020301 at sweetapp.com>, > Brian Quinlan wrote: >> Scott David Daniels wrote: >> [snipped] >>> When you evaluate a lambda expression, the default args are evaluated, >>> but the expression inside the lambda body is not. When you apply that >>> evaluated lambda expression, the expression inside the lambda body is >>> is evaluated and returned. >> But that's not really the issue. I knew that the lambda was not >> evaluated but thought each generator expression got its own context >> rather than sharing one. > > Each? Maybe that's a source of confusion. There is only one generator > expression in your example. > >>>> c = (lambda : i for i in range(11, 16)) >>>> c > at 0x114e90> >>>> d = list(c) >>>> d > [ at 0x119348>, at 0x119390>, > at 0x1193d8>, at 0x119420>, > at 0x119468>] > Sorry, I wasn't as precise as I should have been. If you consider this example: ( for x in y) I thought that every time that was evaluated, it would be done in a new closure with x bound to the value of x at the time that the closure was created. Instead, a new closure is created for the entire generator expression and x is updated inside that closure. Cheers, Brian From iamelgringo at gmail.com Fri Jun 5 10:39:11 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Fri, 5 Jun 2009 07:39:11 -0700 (PDT) Subject: Feedparser Problem Message-ID: <985f7729-c301-40d9-b712-d671c136dd1e@k38g2000yqh.googlegroups.com> I'm working with Feedparser on months old install of Windows 7, and now programs that ran before are broken, and I'm getting wierd messages that are rather opaque to me. Google, Bing, News groups have all left me empty handed. I was wondering if I could humbly impose upon the wizards of comp.lang.python to lend me their wisdom and insight to this problem that is too difficult for my little mind. Here's what I'm going through: >>>from feedparser import parse >>>url='http://feeds.nytimes.com/nyt/rss/Technology' >>>url2='http://feeds.washingtonpost.com/wp-dyn/rss/technology/index_xml' >>>d = parse(url) >>>d2= parse(url2) >>>d {'bozo':1, 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), 'encoding': 'utf-8', 'entries': [], 'feed':{}, 'version': None} >>>d2 {'bozo': 1, 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), 'encoding': 'utf-8', 'entries': [], 'feed': {}, 'version': None} I've checked my firewall settings, and python is allowed. Other python programs can get data from the web. I know that the 'bozo' is for malformed xml. I've searched through both of those rss feeds, and I can't find the argument 'timeout' anywhere in them. Any ideas, thoughts or directions in which I might go? Thanks to all in advance, Jonathan From philip at semanchuk.com Fri Jun 5 11:21:28 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Jun 2009 11:21:28 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <78sng2F1lbbekU1@mid.individual.net> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78sng2F1lbbekU1@mid.individual.net> Message-ID: <218BBFD2-2F5A-4FD5-8BEC-9D89622CAB18@semanchuk.com> On Jun 5, 2009, at 10:13 AM, Thomas Heller wrote: > skip at pobox.com schrieb: >>>> If there is no C++ compiler available then the proposed layout >>>> sniffing just >> wouldn't be done and either a configure error would be emitted or a >> run-time >> exception raised if a program attempted to use that feature. (Or the >> sniffing could be explicitly enabled/disabled by a configure flag.) >> > > Hm, on Linux, gccxml (if its version is compatible with that of the C > ++ compiler) > can probably help a lot. At runtime, no configure step needed. > Unfortunately not on Windows. I'm not a gccxml user, but its install page has a section for Windows: http://www.gccxml.org/HTML/Install.html HTH P From __peter__ at web.de Fri Jun 5 11:31:43 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Jun 2009 17:31:43 +0200 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: Robert Dailey wrote: > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey >> escribi?: >> >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following >> > URL: >> >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... >> >> > Have it save the ZIP to any destination directory. For me, this only >> > downloads about 40KB before it stops without any error at all. Any >> > reason why this isn't working? >> >> I could not reproduce it. I downloaded about 300K without error (Python >> 3.0.1 on Windows) >> >> -- >> Gabriel Genellina > > Can you show me your test code please? Here's mine: $ cat retriever.py import urllib.request import os def report(*args): print(args) url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip" filename = url.rsplit("/")[-1] urllib.request.urlretrieve(url, filename=filename, reporthook=report) print(os.path.getsize(filename)) $ If you had shown your code in the first place the problem might have been solved by now... Peter From theller at python.net Fri Jun 5 11:33:01 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 17:33:01 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78sng2F1lbbekU1@mid.individual.net> Message-ID: <78ss5dF1nntrpU1@mid.individual.net> Philip Semanchuk schrieb: > On Jun 5, 2009, at 10:13 AM, Thomas Heller wrote: > >> skip at pobox.com schrieb: >>>>> If there is no C++ compiler available then the proposed layout >>>>> sniffing just >>> wouldn't be done and either a configure error would be emitted or a >>> run-time >>> exception raised if a program attempted to use that feature. (Or the >>> sniffing could be explicitly enabled/disabled by a configure flag.) >>> >> >> Hm, on Linux, gccxml (if its version is compatible with that of the C >> ++ compiler) >> can probably help a lot. At runtime, no configure step needed. >> Unfortunately not on Windows. > > I'm not a gccxml user, but its install page has a section for Windows: > http://www.gccxml.org/HTML/Install.html Yes, it runs on Windows (*). However, there are two problems: 1. gccxml refuses to parse quite some include files from the Window SDK. That's probably not the fault of gccxml but MS using non-standard C++ constructs. (There is a workaround inside gccxml: it installs patched Windows header files, but the patches must be created first by someone) 2. You cannot expect gccxml (which is mostly GCC inside) to use the MSVC algorithm for C++ object layout, so unfortuately it does not help in the most important use-case. Thomas (*) And there is even use for it on Windows to parse C header files and generate ctypes wrappers, in the ctypeslib project. From mail at microcorp.co.za Fri Jun 5 11:33:04 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 17:33:04 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: <004201c9e5f3$c6809920$0d00a8c0@Hendrik> "Gabriel Genellina" wrote: >Ah... I had the same impression as Mr. Reedy, that you were directly >reading from a socket and processing right there, so you *had* to use >strings for everything. not "had to" - "chose to" - to keep the most used path as short as I could. > >But if you already have a queue, you may put other objects there (instead >of "canning" them). Testing the object type with isinstance(msg, str) is >pretty fast, and if you bind locally those names I'd say the overhead is >negligible. Maybe you are right and I am pre optimising - but the heart of this box really is that silly loop and the processor really is not fast at all. I felt it was right to keep the processing of the stuff coming out of the queue standard with the split(','), as the brainless way seemed to be the best - anything else I could think of just added overhead. I thought of putting the string in a list, with the record type being the first item, and the string the second, with a queue replacing the string for the state change record. I basically rejected this as it would have added extra processing both at the entry and the exit of the critical queue, for every record. I admit that I did not think of testing the type with isinstance, but even if the overhead is minimal, it does add extra cycles to the innermost loop, for every one of the thousands of times that nothing of importance is detected. This is what I was trying to avoid, as it is important to get as much performance out of the box as I can (given that I am using Python to get the job done fast, because that is also important). So it is a kind of juggling with priorities - "make it fast" would imply do not use python, but "get it done quickly" implies using python, and it looks to me that if I am careful and think more like an assembler programmer, the real time performance will be adequate. And I do not want to do anything that could conceivably compromise that. Even if it means jumping through a funny hoop like I am doing now, and inventing a weird way to pass an object. "adequate" here is up to now quite good - if I set up a client on the LAN and I reflect the inputs back to the outputs, then to my human senses there is no difference in the way the output relays chatter and bounce when I play with a wire on the inputs, to what I would expect of a locally hard wired setup. So to a large extent I think that I am doing the job as fast as it is possible - the comma delimited input string is a fact, decided on between myself and the customer a long time ago, and it comes over a socket, so it has to be a string. The least I can do with it is nothing before I put it on the critical queue. Then when it comes out of the queue, I have to break it up into its constituent parts, and I would think that split is the canonical way of doing that. Then there follows some jiggery pokery to get the outputs out and the inputs in, that involves some ctypes stuff to address the real hardware, and then the input results have to be sent back to the client(s), over and over. That is basically what the box does, until another connection is made (from a control room) and the local "master" client is pre empted and the outputs from the new "master" must be obeyed, and the results reflected back to the new connection too. It is a fairly simple state machine, and it has to be as fast as possible, as twice its loop time plus the network round trip time defines its responsiveness. I would really appreciate it if someone can dream up a faster way of getting round this basic loop. (even if it involves other equally weird constructs as "canning") - Hendrik From wiggly at wiggly.org Fri Jun 5 11:35:38 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Fri, 05 Jun 2009 16:35:38 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> Message-ID: <4A293B4A.1090000@wiggly.org> Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> It just smells to me that you've created this elaborate and brittle hack >> to work around the fact that you couldn't think of any other way of >> getting the thread to change it's behaviour whilst waiting on input. > > I am beginning to think that you are a troll, as all your comments are > haughty and disparaging, while you either take no trouble to follow, > or are incapable of following, my explanations. > > In the event that this is not the case, please try to understand my > reply to Skip, and then suggest a way that will perform better > in my use case, out of your vast arsenal of better, quicker, > more reliable, portable and comprehensible ways of doing it. Well, why not have a look at Gabriel's response. That seems like a much more portable way of doing it if nothing else. I'm not trolling, you just seem to be excited about something that sounds like a fundamentally bad idea. n From gdamjan at gmail.com Fri Jun 5 11:37:11 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Fri, 05 Jun 2009 17:37:11 +0200 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: <7mqnf6-q09.ln1@archaeopteryx.softver.org.mk> > I just to check it in the python shell and it's correct. > Then the problem is by iPython that I was testing it from there. yes, iPython has a bug like that https://bugs.launchpad.net/ipython/+bug/339642 -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of conversation. Q: Why is top posting frowned upon? From mail at microcorp.co.za Fri Jun 5 11:37:25 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 17:37:25 +0200 Subject: fastest way to test file for string? References: Message-ID: <004301c9e5f3$c75acc80$0d00a8c0@Hendrik> "kj" wrote: > > Hi. I need to implement, within a Python script, the same > functionality as that of Unix's > > grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". > > I imagine that I can always resort to the shell for this, but is > there an efficient way of doing it within Python? > > (BTW, portability is not high on my list here; this will run on a > Unix system, and non-portable Unix-specific solutions are fine with > me.) Use grep. You will not beat it's performance. - Hendrik From nrook at wesleyan.edu Fri Jun 5 12:14:10 2009 From: nrook at wesleyan.edu (Nathaniel Rook) Date: Fri, 05 Jun 2009 12:14:10 -0400 Subject: numpy 00 character bug? Message-ID: Hello, all! I've recently encountered a bug in NumPy's string arrays, where the 00 ASCII character ('\x00') is not stored properly when put at the end of a string. For example: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> print numpy.version.version 1.3.0 >>> arr = numpy.empty(1, 'S2') >>> arr[0] = 'ab' >>> arr array(['ab'], dtype='|S2') >>> arr[0] = 'c\x00' >>> arr array(['c'], dtype='|S2') It seems that the string array is using the 00 character to pad strings smaller than the maximum size, and thus is treating any 00 characters at the end of a string as padding. Obviously, as long as I don't use smaller strings, there is no information lost here, but I don't want to have to re-add my 00s each time I ask the array what it is holding. Is this a well-known bug already? I couldn't find it on the NumPy bug tracker, but I could have easily missed it, or it could be triaged, deemed acceptable because there's no better way to deal with arbitrary-length strings. Is there an easy way to avoid this problem? Pretty much any performance-intensive part of my program is going to be dealing with these arrays, so I don't want to just replace them with a slower dictionary instead. I can't imagine this issue hasn't come up before; I encountered it by using NumPy arrays to store Python structs, something I can imagine is done fairly often. As such, I apologize for bringing it up again! Nathaniel From mail at microcorp.co.za Fri Jun 5 12:16:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 18:16:37 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> <4A293B4A.1090000@wiggly.org> Message-ID: <000a01c9e5f9$19e18fc0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Well, why not have a look at Gabriel's response. I have, and have responded at some length, further explaining what I am doing, and why. > That seems like a much more portable way of doing it if nothing else. There is nothing portable in what I am doing - it is aimed at the eBox, as the i/o stuff is specific to the Vortex processor. Even without the can and uncan, if you were to try to run it on any other machine, it would segfault because of the underlying C routines called via ctypes to access the non standard parallel port. > I'm not trolling, you just seem to be excited about something that > sounds like a fundamentally bad idea. Glad to hear it, and I am aware of the dangers, but I am aiming at a very specific speed objective, and I really cannot think of a way that achieves the result in fewer machine cycles than this weird way of passing an object, in a case such as mine. (barring of course writing the whole thing in C, which would never get the job done in time) - Hendrik From aahz at pythoncraft.com Fri Jun 5 12:37:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 09:37:09 -0700 Subject: numpy 00 character bug? References: Message-ID: In article , Nathaniel Rook wrote: > >I've recently encountered a bug in NumPy's string arrays, where the 00 >ASCII character ('\x00') is not stored properly when put at the end of a >string. You should ask about this on the NumPy mailing lists and/or report it on the NumPy tracker: http://scipy.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From Scott.Daniels at Acm.Org Fri Jun 5 12:47:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 09:47:44 -0700 Subject: Messing up with classes and their namespace In-Reply-To: References: Message-ID: Jean-Michel Pichavant wrote: > Hello world, > > I had recently a very nasty bug in my python application. The context is > quite complex, but in the end the problem can be resume as follow: > > 2 files in the same directory : > > lib.py: > >import foo > >foo.Foo.BOOM='lib' > > foo.py: > >class Foo: > > BOOM = 'Foooo' > > > >if __name__=='__main__': > > import lib # I'm expecting BOOM to be set to 'lib' > > print Foo.BOOM > > I was expecting 'lib' as output, but I got 'Fooo'. I don't really > understand what python mechanism I'm messing with but I have the feeling > I've misunderstood a very basic concept about class, namespace or > whatever import notion. > > I guess there is 2 different objects for the same class Foo. How I do I > make both Foo objects the same object ? OK, here is one solution (from which you may infer the problem): lib.py: import __main__ __main__.Foo.BOOM = 'lib' foo.py: class Foo: BOOM = 'Foooo' if __name__ == '__main__': import lib # I'm expecting BOOM to be set to 'lib' print(Foo.BOOM) Here is another solution: lib.py: import foo foo.Foo.BOOM = 'lib' foo.py: class Foo: BOOM = 'Foooo' if __name__ == '__main__': import sys sys.modules['foo'] = sys.modules['__main__'] import lib # I'm expecting BOOM to be set to 'lib' print(Foo.BOOM) Here is a demo of what is actually going wrong: foo.py: class Foo: inside = __name__ import foo if __name__ == '__main__': print(Foo is foo.Foo) print(Foo.inside, foo.Foo.inside) And here is a fix foo.py: if __name__ == '__main__': import sys sys.modules['foo'] = sys.modules['__main__'] class Foo: inside = __name__ import foo if __name__ == '__main__': print(Foo is foo.Foo) print(Foo.inside, foo.Foo.inside) --Scott David Daniels Scott.Daniels at Acm.Org From inVINCEable667 at gmail.com Fri Jun 5 13:02:59 2009 From: inVINCEable667 at gmail.com (inVINCable) Date: Fri, 5 Jun 2009 10:02:59 -0700 (PDT) Subject: Way to use proxies & login to site? References: <36bb20c2-2199-42bb-a123-171bf380182c@y10g2000prc.googlegroups.com> <629c75b1-9e67-44fb-9de0-0a23ff6c306b@v23g2000pro.googlegroups.com> Message-ID: On May 5, 12:51?pm, Kushal Kumaran wrote: > On Wed, Apr 29, 2009 at 8:21 AM, inVINCable wrote: > > On Apr 27, 7:40?pm, inVINCable wrote: > >> Hello, > > >> I have been using ClientForm to log in to sites & ClientCookie so I > >> can automatically log into my site to do some penetration testing, > >> although, I cannot figure out a solution to use proxies with this > >> logging in automatically. Does anyone have any solutions? > > >> Thanks :) > > >> Vince > > > Any ideas? > > If, like the example athttp://wwwsearch.sourceforge.net/ClientForm/, > you are using urllib2, you can read the documentation for that module. > ?It also has examples for working with proxies. > > -- > kushal Ok, I gotcha. Sounds neat, but the problem is, do you know if I can work with proxies and then connect to a site? From sevenbark at gmail.com Fri Jun 5 13:20:12 2009 From: sevenbark at gmail.com (Tom) Date: Fri, 05 Jun 2009 12:20:12 -0500 Subject: how to iterate over several lists? References: Message-ID: On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj wrote: > > >Suppose I have two lists, list_a and list_b, and I want to iterate >over both as if they were a single list. E.g. I could write: > >for x in list_a: > foo(x) >for x in list_b: > foo(x) > >But is there a less cumbersome way to achieve this? I'm thinking >of something in the same vein as Perl's: > >for $x in (@list_a, @list_b) { > foo($x); >} > >TIA! > >kynn def chain(*args): return (item for seq in args for item in seq) for x in chain(list_a, list_b): foo(x) From Scott.Daniels at Acm.Org Fri Jun 5 13:21:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 10:21:09 -0700 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > "Gabriel Genellina" wrote: > >> Ah... I had the same impression as Mr. Reedy, that you were directly >> reading from a socket and processing right there, so you *had* to use >> strings for everything. > > not "had to" - "chose to" - to keep the most used path as short as I could. > >> But if you already have a queue, you may put other objects there (instead >> of "canning" them). Testing the object type with isinstance(msg, str) is >> pretty fast, and if you bind locally those names I'd say the overhead is >> negligible. I can think of use cases for can, and from that use an alternate construct. The use case is passing a reference out over a wire (TCP port?) that will be used later. Sub cases: (1) Handing work over the wire along with a callback to invoke with the results. (2) Handing work over the wire along with a progress callback. (3) Handing work over the wire along with a pair of result functions, where the choice of functions is made on the far side of the wire. The "can" can be used to send the function(s) out. Alternatively, for use case 1: class Holder(object): def __init__(self): self.key = 0 self.holds = {} def handle(self, something): key = str(self.key) # may need to lock w/ next for threads self.key += 1 self.holds[key] = something return key def use(self, handle): return self.holds.pop(handle) Otherwise a simple dictionary with separate removal may be needed. If you might abandon an element w/o using it, use a weakref dictionary, but then you need a scheme to keep the thing alive long enough for needed operations (as you also need with a can). In use case 1, the dictionary becomes that holding point. The counter-as-key idea allows you to keep separate references to the same thing, so the reference is held for precisely as long as needed. It (counter-as-key) beats the str(id(obj)) of can because it tracks the actual object, not simply the id that can be reused. --Scott David Daniels Scott.Daniels at Acm.Org From nad at acm.org Fri Jun 5 13:22:41 2009 From: nad at acm.org (Ned Deily) Date: Fri, 05 Jun 2009 10:22:41 -0700 Subject: Yet another unicode WTF References: <8763fbmk5a.fsf@benfinney.id.au> Message-ID: In article , Ned Deily wrote: > In python 3.x, of course, the encoding happens automatically but you > still have to tell python, via the "encoding" argument to open, what the > encoding of the file's content is (or accept python's default which may > not be very useful): > > >>> open('foo1','w').encoding > 'mac-roman' > > WTF, indeed. BTW, I've opened a 3.1 release blocker issue about 'mac-roman' as a default on OS X. Hard to believe none of us has noticed this up to now! http://bugs.python.org/issue6202 -- Ned Deily, nad at acm.org From vend82 at virgilio.it Fri Jun 5 13:26:20 2009 From: vend82 at virgilio.it (Vend) Date: Fri, 5 Jun 2009 10:26:20 -0700 (PDT) Subject: multi-core software References: Message-ID: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> On Jun 4, 8:35?pm, Roedy Green wrote: > On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee > wrote, quoted or indirectly quoted someone who said : > > >? Why Must Software Be Rewritten For Multi-Core Processors? > > Threads have been part of Java since Day 1. ?Using threads complicates > your code, but even with a single core processor, they can improve > performance, particularly if you are doing something like combing > multiple websites. > > The nice thing about Java is whether you are on a single core > processor or a 256 CPU machine (We got to run our Athena Integer Java > spreadsheet engine on such a beast), does not concern your code. > > You just have to make sure your threads don't interfere with each > other, and Java/the OS, handle exploiting all the CPUs available. You need to decompose your problem in 256 independent tasks. It can be trivial for some problems and difficult or perhaps impossible for some others. From pruebauno at latinmail.com Fri Jun 5 13:38:51 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 5 Jun 2009 10:38:51 -0700 (PDT) Subject: DUDA !!!!!!!!!! References: Message-ID: <8ba8824a-11af-4a7a-9b2d-1d562a0bb9bd@l32g2000vba.googlegroups.com> On Jun 4, 2:51?pm, "Ariel Vazquez Riveron" wrote: > Hola: > ? Hoy en d?a me encuentro iniciandome dentro del python, en estos ? > momentos quiero saber de que forma puedo eliminar un archivo de un ? > compactado, ya sea zip, rar o cualquier otro. Estudie las librer?as ? > zipfile pero no tiene ninguna funcion que me permita hacerlo. Trabajo ? > con python 2.5 > > salu2 Ariel > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. En esta lista la mayoria no entiende castellano sino ingles. Mejor pregunta en esta lista: http://dir.gmane.org/gmane.org.user-groups.python.argentina From hdreschhoff at gmail.com Fri Jun 5 14:10:38 2009 From: hdreschhoff at gmail.com (Jan-Heiner Dreschhoff) Date: Fri, 5 Jun 2009 20:10:38 +0200 Subject: [wxpython] change the language of a menubar Message-ID: Hi Guys, i am new to wxpython an i have trouble with the menubar. i tried to write a dynamic menubar that can read the itemnames from an sqlite3 database, so i can change the language very easy. like this. def MakeMenuBar(self): self.dbCursor.execute("SELECT " + self.lang[self.langSelect] +" FROM menu") self.menuwords = self.dbCursor.fetchall() menu = wx.Menu() ##Filemenu item = menu.Append(ID_CONNECT, "%s" %self.menuwords[3]) . . . this works fine, when i draw the menu for the first time, when i want to change language in runtime, i can not get the menu to redraw. can someone help me out on this one? thanks heiner -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Jun 5 14:14:13 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Jun 2009 20:14:13 +0200 Subject: Messing up with classes and their namespace In-Reply-To: References: Message-ID: <4A296075.8090501@sequans.com> Scott David Daniels wrote: > Jean-Michel Pichavant wrote: >> Hello world, >> >> I had recently a very nasty bug in my python application. The context >> is quite complex, but in the end the problem can be resume as follow: >> >> 2 files in the same directory : >> >> lib.py: >> >import foo >> >foo.Foo.BOOM='lib' >> >> foo.py: >> >class Foo: >> > BOOM = 'Foooo' >> > >> >if __name__=='__main__': >> > import lib # I'm expecting BOOM to be set to 'lib' >> > print Foo.BOOM >> >> I was expecting 'lib' as output, but I got 'Fooo'. I don't really >> understand what python mechanism I'm messing with but I have the >> feeling I've misunderstood a very basic concept about class, >> namespace or whatever import notion. >> > >> I guess there is 2 different objects for the same class Foo. How I do >> I make both Foo objects the same object ? > > OK, here is one solution (from which you may infer the problem): > > lib.py: > import __main__ > __main__.Foo.BOOM = 'lib' > > foo.py: > class Foo: > BOOM = 'Foooo' > > if __name__ == '__main__': > import lib # I'm expecting BOOM to be set to 'lib' > print(Foo.BOOM) > > Here is another solution: > > lib.py: > import foo > foo.Foo.BOOM = 'lib' > > foo.py: > class Foo: > BOOM = 'Foooo' > > if __name__ == '__main__': > import sys > sys.modules['foo'] = sys.modules['__main__'] > import lib # I'm expecting BOOM to be set to 'lib' > print(Foo.BOOM) > > Here is a demo of what is actually going wrong: > > foo.py: > class Foo: > inside = __name__ > > import foo > > if __name__ == '__main__': > print(Foo is foo.Foo) > print(Foo.inside, foo.Foo.inside) > > And here is a fix > foo.py: > if __name__ == '__main__': > import sys > sys.modules['foo'] = sys.modules['__main__'] > > class Foo: > inside = __name__ > > import foo > > if __name__ == '__main__': > print(Foo is foo.Foo) > print(Foo.inside, foo.Foo.inside) > > > --Scott David Daniels > Scott.Daniels at Acm.Org Thanks for the explanation. I'll have to give it a second thought, I'm still missing something but I'll figure it out. Jean-Michel From kkylheku at gmail.com Fri Jun 5 14:15:00 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Fri, 5 Jun 2009 18:15:00 +0000 (UTC) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> Message-ID: <20090617091529.242@gmail.com> On 2009-06-05, Vend wrote: > On Jun 4, 8:35?pm, Roedy Green > wrote: >> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >> wrote, quoted or indirectly quoted someone who said : >> >> >? Why Must Software Be Rewritten For Multi-Core Processors? >> >> Threads have been part of Java since Day 1. ?Using threads complicates >> your code, but even with a single core processor, they can improve >> performance, particularly if you are doing something like combing >> multiple websites. >> >> The nice thing about Java is whether you are on a single core >> processor or a 256 CPU machine (We got to run our Athena Integer Java >> spreadsheet engine on such a beast), does not concern your code. >> >> You just have to make sure your threads don't interfere with each >> other, and Java/the OS, handle exploiting all the CPUs available. > > You need to decompose your problem in 256 independent tasks. > > It can be trivial for some problems and difficult or perhaps > impossible for some others. Even for problems where it appears trivial, there can be hidden issues, like false cache coherency communication where no actual sharing is taking place. Or locks that appear to have low contention and negligible performance impact on ``only'' 8 processors suddenly turn into bottlenecks. Then there is NUMA. A given address in memory may be RAM attached to the processor accessing it, or to another processor, with very different access costs. From minesh at gmail.com Fri Jun 5 14:37:49 2009 From: minesh at gmail.com (Minesh Patel) Date: Fri, 5 Jun 2009 11:37:49 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: On Fri, Jun 5, 2009 at 10:20 AM, Tom wrote: > On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj > wrote: > >> >> >>Suppose I have two lists, list_a and list_b, and I want to iterate >>over both as if they were a single list. ?E.g. I could write: >> >>for x in list_a: >> ? ?foo(x) >>for x in list_b: >> ? ?foo(x) >> >>But is there a less cumbersome way to achieve this? ?I'm thinking >>of something in the same vein as Perl's: >> >>for $x in (@list_a, @list_b) { >> ?foo($x); >>} >> >>TIA! >> >>kynn > > def chain(*args): > ?return (item for seq in args for item in seq) > > for x in chain(list_a, list_b): > ? ?foo(x) > -- > http://mail.python.org/mailman/listinfo/python-list > If they are the same length, you can try the zip built-in function. -- Thanks, --Minesh From grenander at gmail.com Fri Jun 5 15:04:47 2009 From: grenander at gmail.com (Art) Date: Fri, 5 Jun 2009 12:04:47 -0700 (PDT) Subject: distutils extension configuration problem References: Message-ID: On May 26, 11:10?pm, Ron Garret wrote: > I'm trying to build PyObjC on an Intel Mac running OS X 10.5.7. ?The > build is breaking because distutils seems to want to build extension > modules as universal binaries, but some of the libraries it depends on > are built for intel-only, i.e.: > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ python2.6 > setup.py build > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils > /dist.py:266: UserWarning: Unknown distribution option: 'options' > ? warnings.warn(msg) > running build > running build_py > running build_ext > building 'ScreenSaver._inlines' extension > gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g > -bundle -undefined dynamic_lookup > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o -o > build/lib.macosx-10.3-i386-2.6/ScreenSaver/_inlines.so -framework > ScreenSaver > ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file > is not of required architecture for architecture ppc > collect2: ld returned 1 exit status > lipo: can't open input file: > /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-//ccMFYRkt.out (No such > file or directory) > error: command 'gcc' failed with exit status 1 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o: Mach-O > universal binary with 2 architectures > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture ppc): Mach-O object ppc > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture i386): ? Mach-O object i386 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > /usr/local/lib/libtiff.dylib > /usr/local/lib/libtiff.dylib: Mach-O dynamically linked shared library > i386 > > How do I get distutils to stop trying to build extensions as universal > binaries? > > Thanks, > rg I have the same questions but haven't found anything. I got this idea from the apple site: http://developer.apple.com/releasenotes/OpenSource/PerlExtensionsRelNotes/index.html so I tried: env CFLAGS='-arch i386' LDFLAGS='-arch i386' python setup.py build and this removes the -arch ppc flags at least for the compiles but not the links. Maybe something in this direction will work. This didn't work: env ARCHFLAGS='-arch i386' python setup.py install Art From Scott.Daniels at Acm.Org Fri Jun 5 15:20:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 12:20:37 -0700 Subject: fastest way to test file for string? In-Reply-To: References: Message-ID: <79KdncqfhecO87TXnZ2dnUVZ_oGdnZ2d@pdx.net> Tim Chase wrote: >> Hi. I need to implement, within a Python script, [functionality like]: >> grep -rl some_string some_directory > > I'd do something like this untested function: > > def find_files_containing(base_dir, string_to_find): > for path, files, dirs in os.walk(base_dir): Note order wrong here > ... > > for filename in find_files_containing( > "/path/to/wherever/", > "some_string" > ): > print filename I like results in a nice order, so I do something more like: def find_files_containing(base_dir, string_to_find): for path, dirs, files in os.walk(base_dir): # note order for fname in sorted(files): # often endswith in here full_name = os.path.join(path, fname) try: with open(full_name) as f: for line in f: if string_to_find in line: yield full_name break except IOError, why: print ("On %s in %s: %s' % (fname, path, why)) # usually several subdirs to avoid dirs[:] = sorted([d for d in dirs if d[0] != '.' and d not in ('RCS', 'CVS')]) --Scott David Daniels Scott.Daniels at Acm.Org From skip at pobox.com Fri Jun 5 15:20:40 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 14:20:40 -0500 (CDT) Subject: Programming language comparison examples? Message-ID: <20090605192040.C5A6310ED608@montanaro.dyndns.org> I thought there was a website which demonstrated how to program a bunch of small problems in a number of different languages. I know about the Programming Language Shootout: http://shootout.alioth.debian.org/ but that's not what I was thinking of. I thought there was a site with a bunch of smaller examples. I'm looking for a site with this sort of information to pass along to my son who's entering his sophomore year of college, has one Java course under his belt, and will take a second course in the fall. I'm hoping to reach him before his brain turns to mush. ;-) Thx, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From dudekksoft at gmail.com Fri Jun 5 15:33:26 2009 From: dudekksoft at gmail.com (dudekksoft at gmail.com) Date: Fri, 5 Jun 2009 12:33:26 -0700 (PDT) Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On 1 Cze, 22:05, David Boddie wrote: > On Monday 01 June 2009 16:16, dudekks... at gmail.com wrote: > > > On 31 Maj, 02:32, David Boddie wrote: > >> So, you only want to handle certain links, and pass on to WebKit those > >> which you can't handle? Is that correct? > > > Yes, I want to handle external links (out of my host) and links > > starting with download://... (my specific protocol). > > If you want to handle them in a different way to normal Web pages, it seems > that calling setForwardUnsupportedContent(True) on the QWebPage is the way > to do it. > > However, if you want to handle those links and present the content for the > browser to render then you may need to override the browser's network access > manager, as discussed in this message: > > ?http://lists.trolltech.com/pipermail/qt-interest/2009-March/004279.html > > I experimented a little and added an example to the PyQt Wiki: > > ?http://www.diotavelli.net/PyQtWiki/Usinga Custom Protocol with QtWebKit > > I hope it helps to get you started with your own custom protocol. > > David Thank You David for Your help. You made a piece of good work :) From philip.groeger at googlemail.com Fri Jun 5 15:35:29 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Fri, 5 Jun 2009 21:35:29 +0200 Subject: Create multiple variables (with a loop?) Message-ID: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Hi, I need to create multiple variables (lets say 10x10x10 positions of atoms). Is it possible to create them through a loop with some kind of indexing like atom000, atom001, etc? Or is this a very bad idea? Thing is ... i want to create a grid of atoms in vpython and then calculate the forces for each of them (to their neighbours). Don't know how else I could do that. Maybe a huuuge matrix? Thx for your help! - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikle3 at gmail.com Fri Jun 5 15:42:02 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 12:42:02 -0700 (PDT) Subject: MD6 in Python Message-ID: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> As every one related to security probably knows, Rivest (and his friends) have a new hashing algorithm which is supposed to have none of the weaknesses of MD5 (and as a side benefit - not too many rainbow tables yet). His code if publicly available under the MIT license. Is there a reason not to add it to the standard lib, following the hashlib "protocol"? From clp2 at rebertia.com Fri Jun 5 15:43:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:43:15 -0700 Subject: Create multiple variables (with a loop?) In-Reply-To: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Message-ID: <50697b2c0906051243t36d0e6d0nc9b9c444484ca7a2@mail.gmail.com> On Fri, Jun 5, 2009 at 12:35 PM, Philip Gr?ger wrote: > Hi, > I need to create multiple variables (lets say 10x10x10 positions of atoms). > Is it possible to create them through a loop with some kind of indexing like > atom000, atom001, etc? > Or is this a very bad idea? Yes, very bad idea. Use a collection of some sort instead (list, dict, set). Dynamic variable names are usually evil. > Thing is ... i want to create a grid of atoms in vpython and then calculate > the forces for each of them (to their neighbours). Don't know how else I > could do that. Maybe a huuuge matrix? Yup, that sounds like a promising possibility. You might want to look at NumPy - http://numpy.scipy.org/ Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Fri Jun 5 15:45:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:45:48 -0700 Subject: Programming language comparison examples? In-Reply-To: <20090605192040.C5A6310ED608@montanaro.dyndns.org> References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: <50697b2c0906051245s42a3f5b8wba296c610607b1dc@mail.gmail.com> On Fri, Jun 5, 2009 at 12:20 PM, wrote: > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. ?I know about the > Programming Language Shootout: > > ? ?http://shootout.alioth.debian.org/ > > but that's not what I was thinking of. ?I thought there was a site with a > bunch of smaller examples. PLEAC (Programming Language Examples Alike Cookbook) is one option: http://pleac.sourceforge.net/ Cheers, Chris -- Hope my brain doesn't turn to mush. http://blog.rebertia.com From clp2 at rebertia.com Fri Jun 5 15:46:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:46:54 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <50697b2c0906051246u78bf7d46uc79191e58b6a1eba@mail.gmail.com> On Fri, Jun 5, 2009 at 11:37 AM, Minesh Patel wrote: > On Fri, Jun 5, 2009 at 10:20 AM, Tom wrote: >> On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj >> wrote: >> >>> >>> >>>Suppose I have two lists, list_a and list_b, and I want to iterate >>>over both as if they were a single list. ?E.g. I could write: >>> >>>for x in list_a: >>> ? ?foo(x) >>>for x in list_b: >>> ? ?foo(x) >>> >>>But is there a less cumbersome way to achieve this? ?I'm thinking >>>of something in the same vein as Perl's: >>> >>>for $x in (@list_a, @list_b) { >>> ?foo($x); >>>} >>> >>>TIA! >>> >>>kynn >> >> def chain(*args): >> ?return (item for seq in args for item in seq) >> >> for x in chain(list_a, list_b): >> ? ?foo(x) >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > If they are the same length, you can try the zip built-in function. But he doesn't want to iterate over them in parallel... Cheers, Chris -- http://blog.rebertia.com From bearophileHUGS at lycos.com Fri Jun 5 15:55:59 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 5 Jun 2009 12:55:59 -0700 (PDT) Subject: Programming language comparison examples? References: Message-ID: someone: > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. http://www.rosettacode.org/wiki/Main_Page http://en.literateprograms.org/LiteratePrograms:Welcome http://www.codecodex.com/wiki/index.php?title=Main_Page http://merd.sourceforge.net/pixel/language-study/scripting-language/ http://pleac.sourceforge.net/ http://www.angelfire.com/tx4/cus/shapes/index.html Bye, bearophile From kentilton at gmail.com Fri Jun 5 16:03:33 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Fri, 05 Jun 2009 16:03:33 -0400 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: References: Message-ID: <4a297a08$0$31258$607ed4bc@cv.net> Xah Lee wrote: > On Jun 3, 11:50 pm, Xah Lee wrote: >> Of interest: >> ? The Complexity And Tedium of Software Engineering >> http://xahlee.org/UnixResource_dir/writ/programer_frustration.html > > Addendum: > > The point in these short examples is not about software bugs or > problems. It illustrates, how seemingly trivial problems, such as > networking, transferring files, running a app on Mac or Windwos, > upgrading a app, often involves a lot subtle complexities. For mom and > pop users, it simply stop them dead. For a senior industrial > programer, it means some conceptually 10-minutes task often ends up in > hours of tedium. Quibble: those are not /tedious/. Those are as fascinating as an episode of House, trying not only to get new information but how to get it and how to figure out when some information already in hand is actually misinformation, a classic solution to hard problems. Also figuring out coincidences mistaken for cause and effect. But that is just a quibble, ie, I think you need a different word, and it is OK if it still conveys some form of unleasantness. Hair-pulling? Head-banging? > > In some ?theoretical? sense, all these problems are non-problems. But > in practice, these are real, non-trivial problems. These are > complexities that forms a major, multi-discipline, almost unexplored > area of software research. I'm trying to think of a name that > categorize this issue. I think it is a mix of software interface, > version control, release control, formal software specification, > automated upgrade system, etc. The ultimate scenario is that, if one > needs to transfer files from one machine to another, one really should > just press a button and expect everything to work. Software upgrade > should be all automatic behind the scenes, to the degree that users > really don't need fucking to know what so-called ?version? of software > he is using. I think you are looking for an immaculate road system on a volcanic island still growing ten feet a day. > > Today, with so-called ?exponential? scientific progress, and software > has progress tremendously too. In our context, that means there are a > huge proliferation of protocols and standards. For example, unicode, > gazillion networking related protocols, version control systems, > automatic update technologies, all comes into play here. However, in > terms of the above visionary ideal, these are only the beginning. > There needs to be more protocols, standards, specifications, and more > strict ones, and unified ones, for the ideal scenario to take place. But when would we write the software? Even with all the head-banging, look what we have been able to do with computers, leaving aside for the moment the flight control algorithms of the Airbus? When progress stops we will have time to polish our systems, not before. But then you will be able to use the word "tedium". kt From cylix at solace.info Fri Jun 5 16:04:45 2009 From: cylix at solace.info (Frederick Reeve) Date: Fri, 5 Jun 2009 15:04:45 -0500 Subject: python 3.1 - io.BufferedReader.peek() incomplete or change of behaviour. Message-ID: <20090605150445.417b3ecb@cylix> Hello, I have sent this message to the authors as well as to this list. If this is the wrong list please let me know where I should be sending it... dev perhaps? First the simple questions: The versions of io.BufferedReader.peek() have different behavior which one is going to stay long term? Is the C version of the reader incomplete or simply changing the behavior? lastly will you consider my input on the api (see below)? Now a full explanation. I am working on writing a multipart parser for html returns in python 3.1. The email parser being used by cgi does not work currently and cgi is broken at the moment especially when used with the wsgiref.simple_server as it is currently implemented. This is what has pushed me to write my own implementation to _part_ of cgi.py. My thinking being that if it works well in the end I might submit a patch as it needs one anyway. My questions revolve around io.BufferedReader.peek(). There are two implementations one writen in python and one in C. At least in python3.1 C is used by default. The version written in python behaves as follows: want = min(n, self.buffer_size) have = len(self._read_buf) - self._read_pos if have < want or have <= 0: to_read = self.buffer_size - have current = self.raw.read(to_read) if current: self._read_buf = self._read_buf[self._read_pos:] + current self._read_pos = 0 return self._read_buf[self._read_pos:] This basically means it will always return the requested number of bytes up to buffersize and will preform a read on the underlying stream to get extra data if the buffer has less than requested (upto full buffersize). It also will not return a longer buffer than the number of bytes requested. I have verified this is the behaviour of this. The C version works a little different. The C version works as follows: Py_ssize_t have, r; have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t); /* Constraints: 1. we don't want to advance the file position. 2. we don't want to lose block alignment, so we can't shift the buffer to make some place. Therefore, we either return `have` bytes (if > 0), or a full buffer. */ if (have > 0) { return PyBytes_FromStringAndSize(self->buffer + self->pos, have); } /* Fill the buffer from the raw stream, and copy it to the result. */ _BufferedReader_reset_buf(self); r = _BufferedReader_fill_buffer(self); if (r == -1) return NULL; if (r == -2) r = 0; self->pos = 0; return PyBytes_FromStringAndSize(self->buffer, r); Which basically means it returns what ever is in the buffer period. It will not fill the buffer any more from the raw stream to allow us to peek up to one buffersize like the python version and it always returns whats in the buffer regardless of how much you request. The only exception to this is if the buffer is empty. In that case it will read it full then return it. So it can be said this function is guaranteed to return 1 byte unless a raw read is not possible. The author says they cannot shift the buffer. This is true to retain file alignment. Double buffers maybe a solution if the python versions behavior is wanted. I have not yet checked how buffering is implemented fully. In writing the parser I found that being able to peek a number of bytes was helpful but I need to be able to peek more than 1 consistently (70 in my case) to meet the rfc I am implementing. This meant the C version of peek would not work. Fine I wrote a wrapper class that adds a buffer... This seemed dumb as I was already using a buffered reader so I detach the stream and use my wrapper. But now the logic and buffer handling is in the slower python where I would rather not have it. This defeats the purpose of the C buffer reader implementation almost. The C version still has a valid use for being able to read arbitrary size reads but that is really all the buffer reader is doing and I can do block oriented reads and buffering in my wrapper since I have to buffer anyway. Unless I only need a guaranteed peek of 1 byte (baring EOF, etc.) the c version doesn't seem very useful other than for random read cases. This is not a full explanation of course but may give you the picture as I see it. In light of the above and my questions I would like to give my input, hopefully to be constructive. This is what I think the api _should_ be the peek impementation. I may have missed things of course but none the less here it is: --------------------- read(n): Current be behavior read1(n): If n is greater than 0 return n or upto current buffer contents bytes advancing the stream position. If n is less than 0 or None return the the buffer contents and advance the position. If the buffer is empty and EOF has not been reached return None. If the buffer is empty and EOF has been reached return b''. peek(n): If n is less than 0 or None return buffer contents with out advancing stream position. Return n bytes up to _buffer size_(not contents) with out advancing the stream position. If the buffer contents is less than n, buffer an additional block from the "raw" stream before hand. This may require a double buffer or such. If EOF is encountered during the raw read then return return as much as we can upto n. leftover(): Return the number (an int) of bytes in the buffer. This is not strictly necessary with the new implementations of peek and read1 being like above but I thought still useful. I could be wrong and am not tied to this idea personally. --------------------- I feel that what I and possibly others would want from a _buffered reader_ is a best try behaviour. So the functions give you what you want except when its very bad or impossible to do so. Very bad meaning losing block alignment and imposible in this case being reading past EOF (or stream out of data). I'm sorry I'm probably not very good at explaining but I do try. I would love to here your input and I would be willing to work on patches for the C version of the buffered reader to implement this _if_ these changes are supported by the authors and the community and _if_ the authors will not will not write the changes but but still support them. Regardless I would need my questions answered if possible. Thanks so much! Frederick Reeve From geoff.bache at gmail.com Fri Jun 5 16:07:26 2009 From: geoff.bache at gmail.com (geoff.bache at gmail.com) Date: Fri, 5 Jun 2009 13:07:26 -0700 (PDT) Subject: A simpler logging configuration file format? Message-ID: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Hi all, I wonder if there are others out there who like me have tried to use the logging module's configuration file and found it bloated and over- complex for simple usage (i.e. a collection of loggers writing to files) At the moment, if I want to add a new logger "foo" writing to its own file "foo" to my config file, I have to repeat the name 7(!) times, editing 3 different sections in the process: 1) Add "foo" to [loggers] and [handlers]. (These seem completely pointless and were apparently added in anticipation of new functionality that never happened). 2) Create the section [logger_foo] handler:foo qualname:foo level:INFO 3) Create the section [handler_foo] class: FileHandler args:("foo", "a") Wondering how it got like this, I found this blog from soon after it was released in 2004: http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Python_s_logging_module Some of the verdicts are "full of dead chickens and error prone", "horribly complicated" , "over-engineered". So along comes the "basicConfig" method in 2005 which is supposed to address thes concerns. But this can only be applied globally, not even to individual loggers, so is only helpful for extremely basic usage (everything to one target) as far as I can see. The config file is still much as it was then. I'd really like to see the concept extended to encompass multiple loggers and the config file. Allowing Logger.basicConfig should be trivial. Writing a configuration format which took a section and passed all the options in it to basicConfig would in my view lead to a much friendlier syntax for normal usage. From lists at cheimes.de Fri Jun 5 16:46:02 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 05 Jun 2009 22:46:02 +0200 Subject: MD6 in Python In-Reply-To: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: mikle3 at gmail.com schrieb: > As every one related to security probably knows, Rivest (and his > friends) have a new hashing algorithm which is supposed to have none > of the weaknesses of MD5 (and as a side benefit - not too many rainbow > tables yet). His code if publicly available under the MIT license. > > Is there a reason not to add it to the standard lib, following the > hashlib "protocol"? Somebody has to write and add a md6 wrapper to the standard library. It's going to take some time, at least 18 months until Python 2.8 and 3.2 are going to be released. Do you need a wrapper for md6? I could easily write one in about an hour. Christian From david at boddie.org.uk Fri Jun 5 16:51:10 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 05 Jun 2009 22:51:10 +0200 Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On Friday 05 June 2009 21:33, dudekksoft at gmail.com wrote: > On 1 Cze, 22:05, David Boddie wrote: >> I experimented a little and added an example to the PyQt Wiki: >> >> http://www.diotavelli.net/PyQtWiki/Usinga Custom Protocol with QtWebKit >> >> I hope it helps to get you started with your own custom protocol. >> >> David > > Thank You David for Your help. You made a piece of good work :) No problem. I've since found some issues with another example I've been working on, so I may well update that page soon. :-) David From tjreedy at udel.edu Fri Jun 5 17:07:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 17:07:39 -0400 Subject: Messing up with classes and their namespace In-Reply-To: <4A296075.8090501@sequans.com> References: <4A296075.8090501@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Thanks for the explanation. I'll have to give it a second thought, I'm > still missing something but I'll figure it out. Perhaps it is this: 1. When you run foo.py as a script, the interpreter creates module '__main__' by executing the code in foo.py. 2. When that code does 'import lib', the interpreter looks for an existing module named 'lib', does not find it, and creates module 'lib' by executing the code in lib.py. 3. When that code does 'import foo', the interpreter looks for an existing module named 'foo', does not find it, and creates module 'foo' by executing (again) the code in foo.py. Module 'foo' is slightly different from module '__main__', created from the same code, because of the section conditioned by 'if __name__ == '__main__', that being the purpose of that incantation. But each of the two modules have their own class Foo. You sort of guessed this ... > I guess there is 2 different objects for the same class Foo. They are the same in content, but not in identify, until you change one of then. > How I do I make both Foo objects the same object ? As Scott hinted, by not making two of them, and you do that by not making two modules from the same file. Terry Jan Reedy From mikle3 at gmail.com Fri Jun 5 17:09:59 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 14:09:59 -0700 (PDT) Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: On Jun 5, 11:46?pm, Christian Heimes wrote: > mik... at gmail.com schrieb: > > > As every one related to security probably knows, Rivest (and his > > friends) have a new hashing algorithm which is supposed to have none > > of the weaknesses of MD5 (and as a side benefit - not too many rainbow > > tables yet). His code if publicly available under the MIT license. > > > Is there a reason not to add it to the standard lib, following the > > hashlib "protocol"? > > Somebody has to write and add a md6 wrapper to the standard library. > It's going to take some time, at least 18 months until Python 2.8 and > 3.2 are going to be released. > > Do you need a wrapper for md6? I could easily write one in about an hour. > > Christian It's not that I need it, I can sure use it. I can also write a wrapper myself. My secret agenda is too see if other people want it and write it as an addition to the standard lib, thus wetting my feet in Python Core Development without actually breaking anything :) From FSet.SLB at gmail.com Fri Jun 5 17:24:26 2009 From: FSet.SLB at gmail.com (Scott Burson) Date: Fri, 5 Jun 2009 14:24:26 -0700 (PDT) Subject: multi-core software References: Message-ID: On Jun 4, 9:46?am, Xah Lee wrote: > Of interest: > > ? Why Must Software Be Rewritten For Multi-Core Processors? > ?http://xahlee.org/UnixResource_dir/writ/multi-core_software.html > > plain text version follows. > > -------------------------------------------------- > Why Must Software Be Rewritten For Multi-Core Processors? > > Xah Lee, 2009-06-04 > > I had a revelation today, namely, that it is necessary to rewrite > software to use multi-processor in order to benefit from it. > > This may sound stupid, but is a revelation to me. For the past decade, > the question has been on my mind, about why should software needs to > be rewritten to take advantage of multi-processors. Because, in my > mind, i thought that software are at some fundamental level just > algorithms, and algorithms, have nothing to do with hardware > implementation aspects such as number of processors. I always felt, > that those talks about the need or difficulty of rewriting software > for multi-processor (or multi-core these days) must be the product of > idiocy of industrial imperative coding monkies. In particular, some > languages such as java, the way they deal with it, seems to me > extremely stupid. e.g. the concept of threads. In my mind, there > should be a layer between the software and the hardware, such as the > operating system, or the compiler, that should be able to > automatically handle or compile the software so that it FULLY use the > multi-processors when present. In short, i thought that a algorithm > really has nothing to do with hardware details. > > I never really thought hard about this issue, but today, since i got a > quad-core PC, so i looked into the issue, and thought about it, and i > realized the answer. The gist is that, algorithm, fundamentally means > manipulating some hardware, in fact, algorithm is a step by step > instruction about some form of hardware, even the hardware may be > abstract or virtual. For example, let's say the simplest case of 1+1. > It is a algorithm, but where is the hardware? You may say it's > abstract concept, or it being a mathematical model. What you call 1+1 > depends on the context, but in our context, those numbers are the > hardware. To see this, lets say more complex example of listing primes > by sieve. Again, it comes down to ?what is a number?? Here, numbers > can be stones, or arrangement of beads on abacus, it's hardware! As > another example, say sorting. To begin with, you have to have some > something to sort, that's hardware. > > Another way to see this is that, for a given computing problem, there > are infinite number of algorithms to achieve the same thing. Some, > will be better ones, requiring less steps, or requiring less storage. > All these are concrete manipulation issues, and the thing being > manipulated, ultimately we have to call it hardware. So, when hardware > changes, say from one cpu to multi-cpu, there's no way for the > algorithm to magically change and adopt the changed hardware. If you > need a algorithm that is catered to the new hardware, you need a new > algorithm. > > One might think that there might be algorithm Omega, such that it > takes input of old hardware O, new hardware N, and a algorithm A, and > output a algorithm B, such that B has the same behavior as A, but N+B > performs better than O+A. This is like asking for Strong AI. > > One thing we often forgot is that algorithms ultimately translates to > manipulating hardware. In a modern digital computer, that means > software algorithms ultimately becomes machine instructions in CPU, > which manipulate the 1s and 0s in register, or electricity voltage in > transisters. > > In a more mundane point of view, a automatic system for software to > work on multi-processors is a problem of breaking a problem into > discrete units (so that they can be computed in parallel). The problem > of finding a algorithm is entirely different from the problem of > breaking a problem into distinct units. The problem of breaking a > problem into distinct units is a entire new branch of mathematics. For > example, let's say factoring. Factoring is a well defined mathematical > problem. There are millions algorithms to do it, each class has > different properties such as number of steps or storage units. > However, if we look at these algorithms from the point of view of > distinct units, it's a new perspective on classification of > algorithms. Software are in general too ill-defined and fuzzy and > complex, the software we use on personal computers such as email, > browsers, games, don't even have mathematical models. They don't even > have mathematical models of their inputs and outputs. To talk about > automatic system of unitizing software, would be more like a AI > fantasy. Roughly, a term that describes this aspect of research is > Parallel computing. > > In the Wikipedia article, it talks about types of parallelism: Bit- > level parallelism, Instruction-level parallelism, Data parallelism, > Task parallelism. Then it also discusses hardware aspects classes: > multicore, symmetric multiprocessing, distributed computing, cluster, > grid. The subjects mentioned there more close to this essay are ?data > parallelism? and ?task parallelism?. However, neither are high level > enough as i discussed here. The issue discussed here would be like > ?algorithmic parallelism?. Indeed, Wikipedia mentioned ?Automatic > parallelization?, which is exactly what i'm talking about here. Quote: > > ? ? Automatic parallelization of a sequential program by a compiler is > the holy grail of parallel computing. Despite decades of work by > compiler researchers, automatic parallelization has had only limited > success.[40] > > ? ? Mainstream parallel programming languages remain either explicitly > parallel or (at best) partially implicit, in which a programmer gives > the compiler directives for parallelization. A few fully implicit > parallel programming languages exist ? SISAL, Parallel Haskell, and > (for FPGAs) Mitrion-C. > > It says ?A few fully implicit parallel programming languages exist?. > If you are a comp lang nutcase, don't get carried away by what those > words might seem to mean. > > (Note: Wikipedia has a dedicated article on the subject: Automatic > parallelization) > > ? Xah > ?http://xahlee.org/ > > ? From tjreedy at udel.edu Fri Jun 5 17:38:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 17:38:19 -0400 Subject: Adding a Par construct to Python? In-Reply-To: References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <02200d22$0$20645$c3e8da3@news.astraweb.com> <_vidnQW0dJoGg43XnZ2dnUVZ_hpi4p2d@posted.usinternet> <0220260f$0$20645$c3e8da3@news.astraweb.com> <77as23F1fhj3uU1@mid.uni-berlin.de> Message-ID: Lawrence D'Oliveiro wrote: > In message <77as23F1fhj3uU1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: > >>> But reduce()? I can't see how you can parallelize reduce(). By its >>> nature, it has to run sequentially: it can't operate on the nth item >>> until it is operated on the (n-1)th item. >> That depends on the operation in question. Addition for example would >> work. My math-skills are a bit too rusty to qualify the exact nature of >> the operation, commutativity springs to my mind. > > Associativity: > > ((A op B) op C) = (A op (B op C)) > > So for example > > A op B op C op D > > could be grouped into > > (A op B) op (C op D) > > and the two parenthesized subexpressions evaluated concurrently. But this > would only give you a speedup that was logarithmic in the number of op's. It is worth noting, I think, that many realistic operations are not associative. If op combines a summary and an item to create an updated summary, it will probably croak or give a wrong answer when given a summary and a summary. Combining two summaries might be possible, but would be a different operation. For a specific example, consider list.append(some_list, some_item) versus list.extend(some_list, another_list). Imagine for that moment that these methods returned some_list. Then [].append(a).append(b).append(c).append(d) # parentheses left out would have to be conceptually converted to the associative [].extend([a]).extend([b]).extend([c]).extend([d]) before being grouped something like (([].extend([a])).extend([b].extend([c]))).extend([d]) Of course, one would not do the conversion to the slower associative operation unless one knew that there would be a compensating speedup due to the grouping. Terry Jan Reedy From robert.kern at gmail.com Fri Jun 5 17:38:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Jun 2009 16:38:56 -0500 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: On 2009-06-05 16:09, mikle3 at gmail.com wrote: > On Jun 5, 11:46 pm, Christian Heimes wrote: >> mik... at gmail.com schrieb: >> >>> As every one related to security probably knows, Rivest (and his >>> friends) have a new hashing algorithm which is supposed to have none >>> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >>> tables yet). His code if publicly available under the MIT license. >>> Is there a reason not to add it to the standard lib, following the >>> hashlib "protocol"? >> Somebody has to write and add a md6 wrapper to the standard library. >> It's going to take some time, at least 18 months until Python 2.8 and >> 3.2 are going to be released. >> >> Do you need a wrapper for md6? I could easily write one in about an hour. >> >> Christian > > It's not that I need it, I can sure use it. I can also write a wrapper > myself. > My secret agenda is too see if other people want it and write it as an > addition to the standard lib, thus wetting my feet in Python Core > Development without actually breaking anything :) My gut feeling is that it's too new. In a year, the current round of the SHA-3 competition will be over, you will have much more information about how MD6 fares against its competitors, and you will still have some time to get it into Python 2.8/3.2. We don't actually *know* that it doesn't have equivalent weaknesses until the cryptanalysts try to break it for a year or so. :-) -- 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 Fri Jun 5 17:57:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Jun 2009 14:57:20 -0700 (PDT) Subject: numpy 00 character bug? References: Message-ID: <971181bd-062f-481c-8e71-fd566edeb49a@s21g2000vbb.googlegroups.com> On Jun 5, 9:14?am, Nathaniel Rook wrote: > Hello, all! > > I've recently encountered a bug in NumPy's string arrays, where the 00 > ASCII character ('\x00') is not stored properly when put at the end of a > string. > > For example: > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import numpy > ?>>> print numpy.version.version > 1.3.0 > ?>>> arr = numpy.empty(1, 'S2') > ?>>> arr[0] = 'ab' > ?>>> arr > array(['ab'], > ? ? ? ?dtype='|S2') > ?>>> arr[0] = 'c\x00' > ?>>> arr > array(['c'], > ? ? ? ?dtype='|S2') > > It seems that the string array is using the 00 character to pad strings > smaller than the maximum size, and thus is treating any 00 characters at > the end of a string as padding. ?Obviously, as long as I don't use > smaller strings, there is no information lost here, but I don't want to > have to re-add my 00s each time I ask the array what it is holding. I am going to guess that it is done this way for the sake of interoperability with Fortran, and that it is deliberate behavior. Also, if it were accidental behavior, then it would probably happen for internal nul bytes, but it doesn't. The workaround I recommend is to add a superfluous character on the end: >>> numpy.array(['a\0x'],'S3') array(['a\x00x'], dtype='|S3') Then chop off the last character. (However it might turn out that padding as necessary performs better.) > Is this a well-known bug already? ?I couldn't find it on the NumPy bug > tracker, but I could have easily missed it, or it could be triaged, > deemed acceptable because there's no better way to deal with > arbitrary-length strings. ?Is there an easy way to avoid this problem? > Pretty much any performance-intensive part of my program is going to be > dealing with these arrays, so I don't want to just replace them with a > slower dictionary instead. > > I can't imagine this issue hasn't come up before; I encountered it by > using NumPy arrays to store Python structs, something I can imagine is > done fairly often. ?As such, I apologize for bringing it up again! I doubt a very high percentage of people who use numpy do character manipulation, so I could see it as something that hasn't come up before. Carl Banks From tjreedy at udel.edu Fri Jun 5 18:06:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:06:09 -0400 Subject: Odd closure issue for generators In-Reply-To: <4A292D70.9020801@sweetapp.com> References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> Message-ID: Brian Quinlan wrote: > > Sorry, I wasn't as precise as I should have been. > > If you consider this example: > ( for x in y) > > I thought that every time that was evaluated, it would be done in > a new closure with x bound to the value of x at the time that the > closure was created. > > Instead, a new closure is created for the entire generator expression > and x is updated inside that closure. Thanks you for explaining your confusion. Knowing what sort of other-language-baggage people are being mislead by can only help in explaining Python. But here is my question. In Python, g = ( for x in iterable) is essentially an abbreviation for, and means the same as def _(it): for x in it: yield g = _(iterable) del _ Are there language in which a similar construct has an essentially different meaning? Terry Jan Reedy From castironpi at gmail.com Fri Jun 5 18:43:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 5 Jun 2009 15:43:55 -0700 (PDT) Subject: fastest way to test file for string? References: Message-ID: <084363ef-d2ee-41bd-910b-fdb1c920c9c6@m19g2000yqk.googlegroups.com> On Jun 5, 5:50?am, kj wrote: > Hi. ?I need to implement, within a Python script, the same > functionality as that of Unix's > > ? ?grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". snip The 'mmap.mmap' class has a 'find' method. Not what you asked for, put possibly an alternative. No regex 'search' method either. From tjreedy at udel.edu Fri Jun 5 18:50:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:50:53 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Christian Heimes wrote: > mikle3 at gmail.com schrieb: >> As every one related to security probably knows, Rivest (and his >> friends) have a new hashing algorithm which is supposed to have none >> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >> tables yet). His code if publicly available under the MIT license. >> >> Is there a reason not to add it to the standard lib, following the >> hashlib "protocol"? > > Somebody has to write and add a md6 wrapper to the standard library. > It's going to take some time, at least 18 months until Python 2.8 and 2.7 is next From tjreedy at udel.edu Fri Jun 5 18:53:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:53:21 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Robert Kern wrote: > On 2009-06-05 16:09, mikle3 at gmail.com wrote: >> It's not that I need it, I can sure use it. I can also write a wrapper >> myself. >> My secret agenda is too see if other people want it and write it as an >> addition to the standard lib, thus wetting my feet in Python Core >> Development without actually breaking anything :) > > My gut feeling is that it's too new. In a year, the current round of the > SHA-3 competition will be over, you will have much more information > about how MD6 fares against its competitors, and you will still have A wrapper could go on PyPI now so it can be tested in use *before* going in the stdlib. No commit or pre-review needed either. From iamelgringo at gmail.com Fri Jun 5 19:17:36 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Fri, 5 Jun 2009 16:17:36 -0700 (PDT) Subject: Feedparser Problem References: <985f7729-c301-40d9-b712-d671c136dd1e@k38g2000yqh.googlegroups.com> Message-ID: Thanks for the responses. I've tried the same script on a Server 2003 install, and Python 2.5 and it ran without a hitch. So, it's either a problem with Python 2.6 or with Windows 7. Thanks for all the responses. You've been great. Best, Jonathan On Jun 5, 7:39?am, Jonathan Nelson wrote: > I'm working with Feedparser on months old install of Windows 7, and > now programs that ran before are broken, and I'm getting wierd > messages that are rather opaque to me. ? Google, Bing, News groups > have all left me empty handed. > > I was wondering if I could humbly impose upon the wizards of > comp.lang.python to lend me their wisdom and insight to this problem > that is too difficult for my little mind. > > Here's what I'm going through: > > >>>from feedparser import parse > >>>url='http://feeds.nytimes.com/nyt/rss/Technology' > >>>url2='http://feeds.washingtonpost.com/wp-dyn/rss/technology/index_xml' > >>>d = parse(url) > >>>d2= parse(url2) > >>>d > > {'bozo':1, > 'bozo_exception': TypeError("__init__() got an unexpected keyword > argument 'timeout'",), > 'encoding': 'utf-8', > 'entries': [], > 'feed':{}, > 'version': None}>>>d2 > > {'bozo': 1, > ?'bozo_exception': TypeError("__init__() got an unexpected keyword > argument 'timeout'",), > ?'encoding': 'utf-8', > ?'entries': [], > ?'feed': {}, > ?'version': None} > > I've checked my firewall settings, and python is allowed. ?Other > python programs can get data from the web. ?I know that the 'bozo' is > for malformed xml. ?I've searched through both of those rss feeds, and > I can't find the argument 'timeout' anywhere in them. > > Any ideas, thoughts or directions in which I might go? > > Thanks to all in advance, > Jonathan From see_website at mindprod.com.invalid Fri Jun 5 19:26:37 2009 From: see_website at mindprod.com.invalid (Roedy Green) Date: Fri, 05 Jun 2009 16:26:37 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> Message-ID: <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku wrote, quoted or indirectly quoted someone who said : >Even for problems where it appears trivial, there can be hidden >issues, like false cache coherency communication where no actual >sharing is taking place. Or locks that appear to have low contention and >negligible performance impact on ``only'' 8 processors suddenly turn into >bottlenecks. Then there is NUMA. A given address in memory may be >RAM attached to the processor accessing it, or to another processor, >with very different access costs. Could what you are saying be summed up by saying, "The more threads you have the more important it is to keep your threads independent, sharing as little data as possible." -- Roedy Green Canadian Mind Products http://mindprod.com Never discourage anyone... who continually makes progress, no matter how slow. ~ Plato 428 BC died: 348 BC at age: 80 From lists at cheimes.de Fri Jun 5 19:46:28 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 01:46:28 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy schrieb: > Christian Heimes wrote: >> mikle3 at gmail.com schrieb: >>> As every one related to security probably knows, Rivest (and his >>> friends) have a new hashing algorithm which is supposed to have none >>> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >>> tables yet). His code if publicly available under the MIT license. >>> >>> Is there a reason not to add it to the standard lib, following the >>> hashlib "protocol"? >> >> Somebody has to write and add a md6 wrapper to the standard library. >> It's going to take some time, at least 18 months until Python 2.8 and > > 2.7 is next > 2.7rc1 is already out. There is no way a new piece of code will land in the 2.7 release. Christian From lists at cheimes.de Fri Jun 5 19:47:21 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 01:47:21 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy wrote: > A wrapper could go on PyPI now so it can be tested in use *before* going > in the stdlib. No commit or pre-review needed either. Here you go http://pypi.python.org/pypi/md6 It's still a bit rough, totally untested but it should work. Christian From aahz at pythoncraft.com Fri Jun 5 20:01:31 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 17:01:31 -0700 Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: In article , Christian Heimes wrote: >Terry Reedy schrieb: >> Christian Heimes wrote: >>> >>> Somebody has to write and add a md6 wrapper to the standard library. >>> It's going to take some time, at least 18 months until Python 2.8 and >> >> 2.7 is next > >2.7rc1 is already out. There is no way a new piece of code will land in >the 2.7 release. Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is that 2.7 is mostly restricted to code landed in 3.1, so your second statement is roughly correct. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From Scott.Daniels at Acm.Org Fri Jun 5 20:14:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 17:14:47 -0700 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Christian Heimes wrote: > ... > 2.7rc1 is already out. There is no way a new piece of code will land in > the 2.7 release. > > Christian 3.1rc1 is out, but 2.7 is not even in alpha. See pep 373 for the 2.7 schedule; 3.1's schedule is on pep 375. --Scott David Daniels Scott.Daniels at Acm.Org From lists at cheimes.de Fri Jun 5 20:17:39 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 02:17:39 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is > that 2.7 is mostly restricted to code landed in 3.1, so your second > statement is roughly correct. Oh, d...! Of course you are right, Aahz. As far as I can remember 2.7 will only contain backports of 3.1 features or features related to 2to3 migration. Christian From tjreedy at udel.edu Fri Jun 5 20:30:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 20:30:55 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is > that 2.7 is mostly restricted to code landed in 3.1, so your second > statement is roughly correct. My understanding is that 2.7 will come out about the same time as 3.2 and will contain 3.2 backports also. New features are being marked on the issue tracker as for 2.7/3.2. There may or may not be a 2.8. (It was once intended that 2.7 come out with 3.1, but that changed when it was decided to cut the life of 3.0 and bring out 3.1 after 6 months.) tjr From vend82 at virgilio.it Fri Jun 5 20:49:38 2009 From: vend82 at virgilio.it (Vend) Date: Fri, 5 Jun 2009 17:49:38 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <1489cda9-cb03-4159-8cfe-021895da251f@j18g2000yql.googlegroups.com> On Jun 6, 1:26?am, Roedy Green wrote: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : > > >Even for problems where it appears trivial, there can be hidden > >issues, like false cache coherency communication where no actual > >sharing is taking place. Or locks that appear to have low contention and > >negligible performance impact on ``only'' 8 processors suddenly turn into > >bottlenecks. Then there is NUMA. A given address in memory may be > >RAM attached to the processor accessing it, or to another processor, > >with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." Besides technical issues such as cache conflicts and synchronization latencies, there are more theoretical issues of task decomposability. It seems it is not always feasible to decompose an algorithm into subprograms that can be executed in parallel. From rcdailey at gmail.com Fri Jun 5 20:53:50 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 17:53:50 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> On Jun 5, 10:31?am, Peter Otten <__pete... at web.de> wrote: > Robert Dailey wrote: > > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: > >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey > >> escribi?: > > >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > >> > URL: > > >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > >> > Have it save the ZIP to any destination directory. For me, this only > >> > downloads about 40KB before it stops without any error at all. Any > >> > reason why this isn't working? > > >> I could not reproduce it. I downloaded about 300K without error ?(Python > >> 3.0.1 on Windows) > > >> -- > >> Gabriel Genellina > > > Can you show me your test code please? > > Here's mine: > > $ cat retriever.py > import urllib.request > import os > > def report(*args): > ? ? print(args) > > url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1..." > filename = url.rsplit("/")[-1] > > urllib.request.urlretrieve(url, filename=filename, reporthook=report) > print(os.path.getsize(filename)) > $ > > If you had shown your code in the first place the problem might have been solved by now... > > Peter Well I did not post the code because it is fairly complex and its hard to give you the whole picture without giving you too much code. But here you go, you get what you ask for: def Download( self ): PrintSubStatus( 'Downloading...' ) destination = normalize( '{0}/{1}'.format( self._info.outdir, self._info.file_ext ) ) print( self._info.url ) print( destination ) urlretrieve( self._info.url, destination ) Both print statements are shown as below: http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip I really can't figure out why this isn't working. From michele.simionato at gmail.com Fri Jun 5 21:24:19 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 18:24:19 -0700 (PDT) Subject: Odd closure issue for generators References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> Message-ID: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> On Jun 6, 12:06?am, Terry Reedy wrote: > Brian Quinlan wrote: > > > Sorry, I wasn't as precise as I should have been. > > > If you consider this example: > > ( for x in y) > > > I thought that every time that was evaluated, it would be done in > > a new closure with x bound to the value of x at the time that the > > closure was created. > > > Instead, a new closure is created for the entire generator expression > > and x is updated inside that closure. > > Thanks you for explaining your confusion. ?Knowing what sort of > other-language-baggage people are being mislead by can only help in > explaining Python. ?But here is my question. ?In Python, > > g = ( for x in iterable) > > is essentially an abbreviation for, and means the same as > > def _(it): > ? ?for x in it: > ? ? ?yield > g = _(iterable) > del _ > > Are there language in which a similar construct has an essentially > different meaning? > > Terry Jan Reedy Yes, most functional languages have the concept of streams. You can even define a stream-comprehension that looks like Python generator comprehension but it is an essentially different thing. See for instance http://www.artima.com/weblogs/viewpost.jsp?thread=251159 From skip at pobox.com Fri Jun 5 21:32:43 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 20:32:43 -0500 Subject: Programming language comparison examples? In-Reply-To: References: Message-ID: <18985.51003.874220.895047@montanaro.dyndns.org> >> http://www.rosettacode.org/wiki/Main_Page >> http://en.literateprograms.org/LiteratePrograms:Welcome >> http://www.codecodex.com/wiki/index.php?title=Main_Page >> http://merd.sourceforge.net/pixel/language-study/scripting-language/ >> http://pleac.sourceforge.net/ >> http://www.angelfire.com/tx4/cus/shapes/index.html Thanks for the extensive list of sites! Skip From rcdailey at gmail.com Fri Jun 5 21:34:00 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 18:34:00 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: On Jun 5, 7:53?pm, Robert Dailey wrote: > On Jun 5, 10:31?am, Peter Otten <__pete... at web.de> wrote: > > > > > > > Robert Dailey wrote: > > > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: > > >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey > > >> escribi?: > > > >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > > >> > URL: > > > >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > > >> > Have it save the ZIP to any destination directory. For me, this only > > >> > downloads about 40KB before it stops without any error at all. Any > > >> > reason why this isn't working? > > > >> I could not reproduce it. I downloaded about 300K without error ?(Python > > >> 3.0.1 on Windows) > > > >> -- > > >> Gabriel Genellina > > > > Can you show me your test code please? > > > Here's mine: > > > $ cat retriever.py > > import urllib.request > > import os > > > def report(*args): > > ? ? print(args) > > > url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1..." > > filename = url.rsplit("/")[-1] > > > urllib.request.urlretrieve(url, filename=filename, reporthook=report) > > print(os.path.getsize(filename)) > > $ > > > If you had shown your code in the first place the problem might have been solved by now... > > > Peter > > Well I did not post the code because it is fairly complex and its hard > to give you the whole picture without giving you too much code. But > here you go, you get what you ask for: > > ? ?def Download( self ): > ? ? ? PrintSubStatus( 'Downloading...' ) > ? ? ? destination = normalize( '{0}/{1}'.format( self._info.outdir, > self._info.file_ext ) ) > ? ? ? print( self._info.url ) > ? ? ? print( destination ) > ? ? ? urlretrieve( self._info.url, destination ) > > Both print statements are shown as below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10... > D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip > > I really can't figure out why this isn't working. Wow how stupid... I was using: mxMSW-2.8.10.zip There is an "m" at the front, and it needs to be "w". wxMSW-2.8.10.zip This URL isn't even valid, can't believe I didn't get an exception! From gokhansever at gmail.com Fri Jun 5 21:44:29 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Fri, 5 Jun 2009 20:44:29 -0500 Subject: Create multiple variables (with a loop?) In-Reply-To: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Message-ID: <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> You could use locals() for dynamic variable names creation. Additionally, you can give to Mayavi a try for visualization of your data: http://code.enthought.com/projects/mayavi/ G?khan On Fri, Jun 5, 2009 at 2:35 PM, Philip Gr?ger wrote: > Hi, > I need to create multiple variables (lets say 10x10x10 positions of atoms). > Is it possible to create them through a loop with some kind of indexing like > atom000, atom001, etc? > Or is this a very bad idea? > > Thing is ... i want to create a grid of atoms in vpython and then calculate > the forces for each of them (to their neighbours). Don't know how else I > could do that. Maybe a huuuge matrix? > > Thx for your help! > - Philip > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rcdailey at gmail.com Fri Jun 5 21:56:52 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 18:56:52 -0700 (PDT) Subject: Scope objects Message-ID: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Is it possible to create an object in Python that will clean itself up at function exit? I realize destruction of objects may not occur immediately and can be garbage collected, but this functionality would still be great to have. Consider the following function: def do_stuff(): foo = scope_object() # Do stuff... foo.Cleanup() It would be nice to avoid the explicit "Cleanup()" call above, and have 'foo' just act as if it has a C++ destructor and evoke some method at the exit point of a function. From clp2 at rebertia.com Fri Jun 5 21:57:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 18:57:52 -0700 Subject: Create multiple variables (with a loop?) In-Reply-To: <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> Message-ID: <50697b2c0906051857j9e95b61r57701a23b1ae4bd@mail.gmail.com> On Fri, Jun 5, 2009 at 6:44 PM, G?khan SEVER wrote: > You could use locals() for dynamic variable names creation. Not really. Quoting http://docs.python.org/library/functions.html#locals (emphasis mine): locals() Update and return a dictionary representing the current local symbol table. Note: The contents of this dictionary should not be modified; **changes may not affect the values of local variables used by the interpreter**. It does happen to work it certain cases, but it should not be relied upon. Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Fri Jun 5 22:06:26 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 06 Jun 2009 14:06:26 +1200 Subject: urlretrieve() failing on me In-Reply-To: References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: <78u16mF1l5n4qU1@mid.individual.net> Robert Dailey wrote: > This URL isn't even valid, can't believe I didn't get an exception! My guess is that if you look at the data it downloaded, you'll find it's a 404 response page or something similar. -- Greg From apt.shansen at gmail.com Fri Jun 5 22:07:03 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Jun 2009 19:07:03 -0700 Subject: Scope objects In-Reply-To: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <7a9c25c20906051907p34369d4ak1da12107ae4bdb14@mail.gmail.com> On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > foo = scope_object() > # Do stuff... > foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. Generally, in CPython at least, 'foo' -would- be destroyed immediately with the Reference Counting semantics, and thus you could just do whatever cleanup you needed to in __del__. This isn't the case for other Python implementations. Its sorta best to not rely on reference counting, but.. sometimes its nice. Otherwise your only option is the "with statement" in 2.5 (using "from __future__ import with_statement") or 2.6. In that, you would do: def do_stuff(): with scope_object(): stuff The object returned by scope_object() would have its __enter__() and __exit__() methods called right away. That's the official way to do 'cleaning up code' really these days. If you need to access the scope object, you'd do "with scope_object() as foo:" HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jun 5 22:07:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 19:07:58 -0700 Subject: Scope objects In-Reply-To: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <50697b2c0906051907w64b45969hf54b155f51f2394e@mail.gmail.com> On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > ? ?foo = scope_object() > ? ?# Do stuff... > ? ?foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. This is exactly what the new `with` statement lets you do. You just need to define an appropriate context manager. With one, you can code that as: def do_stuff(): with scope_object() as foo: #do stuff More info: http://www.python.org/dev/peps/pep-0343/ Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:16:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:16:27 GMT Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: <0045ac0e$0$9732$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 01:47:21 +0200, Christian Heimes wrote: > Terry Reedy wrote: >> A wrapper could go on PyPI now so it can be tested in use *before* >> going in the stdlib. No commit or pre-review needed either. > > Here you go http://pypi.python.org/pypi/md6 > > It's still a bit rough, totally untested but it should work. Oh you're a cruel, cruel man! The OP wanted to do that :) -- Steven From sjmachin at lexicon.net Fri Jun 5 22:16:53 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 5 Jun 2009 19:16:53 -0700 (PDT) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: On Jun 6, 5:45?am, Chris Rebert wrote: > PLEAC (Programming Language Examples Alike Cookbook) is one option:http://pleac.sourceforge.net/ """The latest version of Python is 2.4""" Appears to be a translation of parts of the Perl Cookbook: """Examples which translate the original Perl closely but which are unPythonic are prefixed with a comment stating "DON'T DO THIS".""" From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:19:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:19:20 GMT Subject: how to iterate over several lists? References: Message-ID: <0045acbb$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 11:37:49 -0700, Minesh Patel wrote: >> def chain(*args): >> ?return (item for seq in args for item in seq) >> >> for x in chain(list_a, list_b): >> ? ?foo(x) >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > If they are the same length, you can try the zip built-in function. Which does something *completely different* from what the Original Poster was asking for. Given alist = [1, 2, 3], blist = [4, 5, 6], the OP wants to process: 1, 2, 3, 4, 5, 6 but zip will give: (1, 3), (2, 5), (3, 6) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:19:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:19:45 GMT Subject: fastest way to test file for string? References: Message-ID: <0045acd4$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 17:37:25 +0200, Hendrik van Rooyen wrote: > "kj" wrote: >> >> Hi. I need to implement, within a Python script, the same >> functionality as that of Unix's >> >> grep -rl some_string some_directory >> >> I.e. find all the files under some_directory that contain the string >> "some_string". >> >> I imagine that I can always resort to the shell for this, but is there >> an efficient way of doing it within Python? >> >> (BTW, portability is not high on my list here; this will run on a Unix >> system, and non-portable Unix-specific solutions are fine with me.) > > Use grep. You will not beat it's performance. What makes you think that performance of the find itself is the only, or even the main, consideration? -- Steven From greg at cosc.canterbury.ac.nz Fri Jun 5 22:20:03 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 06 Jun 2009 14:20:03 +1200 Subject: how to create a big list of list In-Reply-To: <4gI9c7$wD1@alexbbs.twbbs.org> References: <4gI9c7$wD1@alexbbs.twbbs.org> Message-ID: <78u20aF1npma3U1@mid.individual.net> command.bbs at alexbbs.twbbs.org wrote: > i have try [ [] for x in xrange(2**25) ] Are you really going to be adding data to all of those sublists? If you're only using them sparsely, it may be better to use a dictionary in place of the top level list, and only add sublists as and when necessary. Recent Python versions have a built-in type called defaultdict that makes this kind of thing easy. -- Greg From gagsl-py2 at yahoo.com.ar Fri Jun 5 22:21:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 23:21:40 -0300 Subject: Making the case for repeat References: Message-ID: En Fri, 05 Jun 2009 08:04:37 -0300, pataphor escribi?: > But what is simple? I am currently working on a universal feature > creeper that could replace itertools.cycle, itertools.repeat, > itertools.chain and reverse and also helps to severely cut down on > itertools.islice usage. All within virtually the same parameter > footprint as the last function I posted. The problem is posting *this* > function would kill my earlier repeat for sure. And it already had a > problem with parameters < 0 (Hint: that last bug has now become a > feature in the unpostable repeat implementation) Plans to conquer the world, second desk, over there. -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:32:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:32:48 GMT Subject: Making the case for repeat References: Message-ID: <0045afe3$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 23:21:40 -0300, Gabriel Genellina wrote: > En Fri, 05 Jun 2009 08:04:37 -0300, pataphor > escribi?: > >> But what is simple? I am currently working on a universal feature >> creeper that could replace itertools.cycle, itertools.repeat, >> itertools.chain and reverse and also helps to severely cut down on >> itertools.islice usage. All within virtually the same parameter >> footprint as the last function I posted. The problem is posting *this* >> function would kill my earlier repeat for sure. And it already had a >> problem with parameters < 0 (Hint: that last bug has now become a >> feature in the unpostable repeat implementation) > > Plans to conquer the world, second desk, over there. He'll have to go to the end of the queue though. Why is it that it's (almost) always newbies with about five minutes' worth of experience with Python that come up with these grandiose plans to replace entire modules with a single function? -- Steven From gagsl-py2 at yahoo.com.ar Fri Jun 5 22:39:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 23:39:02 -0300 Subject: python way to automate IE8's File Download dialog References: <4a290592$0$17084$ba4acef3@news.orange.fr> Message-ID: En Fri, 05 Jun 2009 09:46:25 -0300, <""Michel Claveau - MVP"> escribi?: > Suppose that the (web) site give the file only after several seconds, > and after the user click a confirm (example: RapidFile). > Suppose that the (web) site give the file only after the user input a > code, controled by a javascript script. The (web) site only receives HTTP requests; javascript runs only on the client side. If you generate an equivalent HTTP request in code, you're done. By example, the wait timer and captcha of rapidshare can be easily skipped; but the "no more than one download per IP" limitation cannot, because it is enforced on the server side. Of course, figuring out how to do that in each particular case has a cost (time and required skills), and it may be more convenient to do browser automation as you imply. -- Gabriel Genellina From pavlovevidence at gmail.com Fri Jun 5 23:05:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Jun 2009 20:05:08 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <858c9c29-ce01-4707-869e-9cf9754fc72c@l28g2000vba.googlegroups.com> On Jun 4, 6:44?pm, "Gabriel Genellina" wrote: > En Thu, 04 Jun 2009 10:37:45 -0300, pataphor escribi?: > > > So here is my proposed suggestion for a once and for all reconciliation > > of various functions in itertools that can not stand on their own and > > keep a straight face. Because of backwards compatibility issues we > > cannot remove them but we can boldly jump forward and include the right > > repeat in the builtin namespace, which I think would be the best thing. > > Alternatively -- the second best solution -- would be to give this > > function its own namespace where it can supersede the old incongruencies > > in itertools. Combiniter or combinator? > > Ok, you're proposing a "bidimensional" repeat. I prefer to keep things > simple, and I'd implement it in two steps. That's brings up a good software engineering question: What is better, to have one function with lots of functionality, or many functions with a single functionality? Before anyone follows up with the obvious answer, hear me out. Small functions that do one thing well are almost always a good thing, but there is a significant benefit to cramming a lot of functionality into one function: it forces you to hit all corners of a problem. That is, at least for problems where it makes sense to hit all the corners of the input space. The subprocess module is the best example of this. Pretty much any combination of arguments to subprocess.Popen makes sense. If I want to spawn a process with pipes to standard input and standard error, but not standard output, that allows me to specify a custom environment, that uses no buffering, and that goes through the shell... I can! Not so with the mish-mash of other calls. By having a single function doing all that it enabled all those combinations, something that wouldn't have happened with lots of small functions. (I suddenly wonder what other languages have such easy versatilty in spawning subprocesses.) So... there is something to be said for pataphor's unified repeat function. Having said that, the nature of iterators is that they are easily recombinable. This is very much unlike the different options with subprocesses. It's not like you can make an extra call just to tack on some behavior to a simple subprocess-spawning function, but with iterators you can. In fact, iterators are (almost) orthogonally recombinable; the whole input space of a problem can be spanned simply by combining simple iterators. So, I will have to ultimately agree with Gabriel: itertools are best kept simple and complex interator behavior like you suggest is best done by combining simple iterators. Carl Banks From rcdailey at gmail.com Fri Jun 5 23:16:31 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 20:16:31 -0700 (PDT) Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: On Jun 5, 9:07?pm, Chris Rebert wrote: > On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > > Is it possible to create an object in Python that will clean itself up > > at function exit? I realize destruction of objects may not occur > > immediately and can be garbage collected, but this functionality would > > still be great to have. Consider the following function: > > > def do_stuff(): > > ? ?foo = scope_object() > > ? ?# Do stuff... > > ? ?foo.Cleanup() > > > It would be nice to avoid the explicit "Cleanup()" call above, and > > have 'foo' just act as if it has a C++ destructor and evoke some > > method at the exit point of a function. > > This is exactly what the new `with` statement lets you do. You just > need to define an appropriate context manager. With one, you can code > that as: > > def do_stuff(): > ? ? with scope_object() as foo: > ? ? ? ? #do stuff > > More info: ?http://www.python.org/dev/peps/pep-0343/ > > Cheers, > Chris > --http://blog.rebertia.com Thanks! This is PERFECT! From mikle3 at gmail.com Sat Jun 6 00:11:19 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 21:11:19 -0700 (PDT) Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> <0045ac0e$0$9732$c3e8da3@news.astraweb.com> Message-ID: On Jun 6, 5:16?am, Steven D'Aprano wrote: > On Sat, 06 Jun 2009 01:47:21 +0200, Christian Heimes wrote: > > Terry Reedy wrote: > >> A wrapper could go on PyPI now so it can be tested in use *before* > >> going in the stdlib. ?No commit or pre-review needed either. > > > Here you gohttp://pypi.python.org/pypi/md6 > > > It's still a bit rough, totally untested but it should work. > > Oh you're a cruel, cruel man! The OP wanted to do that :) > > -- > Steven Hehe, well I sure did learn my lesson here :) I guess I can still say it was my idea, and the fact that someone done is good for the community. I'll just have to find something else and not tell you bastards about it. From gagsl-py2 at yahoo.com.ar Sat Jun 6 00:43:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 01:43:37 -0300 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> <004201c9e5f3$c6809920$0d00a8c0@Hendrik> Message-ID: En Fri, 05 Jun 2009 12:33:04 -0300, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > >> But if you already have a queue, you may put other objects there >> (instead >> of "canning" them). Testing the object type with isinstance(msg, str) is >> pretty fast, and if you bind locally those names I'd say the overhead is >> negligible. > > Maybe you are right and I am pre optimising - but the heart of this > box really is that silly loop and the processor really is not fast at > all. From your description of the problem, it seems you are acting upon messages received from a serial port. You have to process the message *before* the next one arrives -- but you gain nothing doing that much faster. In other words, even with a blazingly fast processor, you can't do things faster than the rate of incoming messages. In any case, you have to test-and-branch in the code. Either with isinstance(rec,str), either with rec_list[0]=="B", or something. I'm unsure if this is the fastest approach - intuition doesn't play well with timings in Python, better to actually measure times. > This is what I was trying to avoid, as it is important to get as much > performance out of the box as I can (given that I am using Python to > get the job done fast, because that is also important). So it is a kind > of > juggling with priorities - "make it fast" would imply do not use python, > but "get it done quickly" implies using python, and it looks to me that > if I am careful and think more like an assembler programmer, the > real time performance will be adequate. And I do not want to do > anything that could conceivably compromise that. Even if it means > jumping through a funny hoop like I am doing now, and inventing > a weird way to pass an object. If it works and you feel it's adequate, that's fine. I cannot count how many times I've used an integer property to attach a pointer to another object (in other languages), but I felt "dirty" doing that. And never did something like that in Python... > So to a large extent I think that I am doing the job as fast as it is > possible - the comma delimited input string is a fact, decided on > between myself and the customer a long time ago, and it comes over > a socket, so it has to be a string. The least I can do with it is > nothing > before I put it on the critical queue. Then when it comes out of the > queue, I have to break it up into its constituent parts, and I would > think > that split is the canonical way of doing that. Ok, what if you split *before* putting in the queue? In the receiving side of the queue, just remove the split(",") part (it's already done). This does not add anything to the critical path - the split must be done anyway. Now, instead of building a fake string "B,cannedobject" and uncanning on the other side, you can simply put a tuple in the queue ("B", the_object) and just get the object on the other side. If I'm not misunderstanding your problem, I think this is the cleanest way to do that. -- Gabriel Genellina From ajith at iuac.res.in Sat Jun 6 01:34:10 2009 From: ajith at iuac.res.in (Ajith Kumar) Date: Sat, 06 Jun 2009 11:04:10 +0530 Subject: Error in linalg.inv ?? Message-ID: <4A29FFD2.1030609@iuac.res.in> Hello, I ran the following code (Using Debian 5.0) from numpy import * a = arange(1.,10.) b = reshape(a, [3,3]) c = linalg.inv(b) print b print c print dot(b,c) print dot(c,b) And the result is [[ 1. 2. 3.] [ 4. 5. 6.] [ 7. 8. 9.]] [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] [[-0.5 -1. -1. ] [-1. -2. 2. ] [-1.5 -3. 1. ]] [[ 5.5 8. 10.5] [ 3. 0. -3. ] [ -1. 0. -3. ]] NOT the identity matrix. Any help ? Thanks Ajith Kumar From s0suk3 at gmail.com Sat Jun 6 02:03:34 2009 From: s0suk3 at gmail.com (s0suk3 at gmail.com) Date: Fri, 5 Jun 2009 23:03:34 -0700 (PDT) Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <78711541-1fe7-4201-9bee-c31747e86d7c@k2g2000yql.googlegroups.com> On Jun 5, 8:56?pm, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > ? ? foo = scope_object() > ? ? # Do stuff... > ? ? foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. I don't know what you mean by: "I realize destruction of objects may not occur immediately and can be garbage collected" Aren't you just missing ordinary destructors (__del__() methods)? These are closest to C++ destructors AFAICS. As far as I know, these are guaranteed to be called when an object goes out of scope. (Note that destruction and garbage collection are different operations; an object may be destructed without being immediately garbage-collected afterwards.) >>> import sys >>> class Simple: ... def __init__(self): sys.stdout.write("Simple.__init__()\n") ... def __del__(self): sys.stdout.write("Simple.__del__()\n") ... >>> def f(): ... s = Simple() ... sys.stdout.write("f()\n") ... # 's' now going out of scope... ... >>> f() Simple.__init__() f() Simple.__del__() >>> Sebastian From gagsl-py2 at yahoo.com.ar Sat Jun 6 02:15:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 03:15:39 -0300 Subject: python 3.1 - io.BufferedReader.peek() incomplete or change of behaviour. References: <20090605150445.417b3ecb@cylix> Message-ID: En Fri, 05 Jun 2009 17:04:45 -0300, Frederick Reeve escribi?: > I have sent this message to the authors as well as to this list. If > this is the wrong list please let me know where I should be sending > it... dev perhaps? I think the best place is the bug tracker: http://bugs.python.org/ -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Sat Jun 6 02:44:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 18:44:01 +1200 Subject: spammers on pypi References: Message-ID: In message , joep wrote: > Is there a way to ban spammers from pypi? Yes, but it doesn't work. From sanal.vikram at gmail.com Sat Jun 6 02:58:27 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Fri, 5 Jun 2009 23:58:27 -0700 (PDT) Subject: openhook Message-ID: Can anybody tell me what is meant by 'openhook' ? From zac256 at gmail.com Sat Jun 6 03:08:42 2009 From: zac256 at gmail.com (Zac Burns) Date: Sat, 6 Jun 2009 00:08:42 -0700 Subject: __file__ access extremely slow In-Reply-To: References: Message-ID: <333edbe80906060008r6f9dea51jc674988148cff6f9@mail.gmail.com> I think I have figured this out, thanks for your input. The time comes from lazy modules related to e-mail importing on attribute access, which is acceptable. Hence of course why ImportError was sometime raised. I originally was thinking that accessing __file__ was triggering some mechanism that caused an attempt at importing other modules, but the lazy import explanation makes much more sense. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Fri, Jun 5, 2009 at 2:15 AM, Gabriel Genellina wrote: > En Fri, 05 Jun 2009 00:12:25 -0300, John Machin > escribi?: > >>> > (2) This will stop processing on the first object in sys.modules that >>> > doesn't have a __file__ attribute. Since these objects aren't >>> > *guaranteed* to be modules, >> >> Definitely not guaranteed to be modules. Python itself drops non-modules >> in >> there! Python 2.3 introduced four keys mapped to None -- one of these was >> dropped in 2.4, but the other three are still there in 2.5 and 2.6: > > In case someone wonders what all those None are: they're a "flag" telling > the import machinery that those modules don't exist (to avoid doing a > directory scan over and over, because Python<2.7 attempts first to do a > relative import, and only if unsuccessful attempts an absolute one) > >> C:\junk>\python23\python -c "import sys; print [k for (k, v) in >> sys.modules.items() if v is None]" >> ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', >> 'encodings.types'] > > In this case, somewhere inside the encodings package, there are statements > like "import types" or "from types import ...", and Python could not find > types.py in the package directory. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From sjmachin at lexicon.net Sat Jun 6 03:15:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 6 Jun 2009 00:15:36 -0700 (PDT) Subject: Error in linalg.inv ?? References: Message-ID: <34f2bdc6-353d-48dd-a3af-cf3dd43fe41d@3g2000yqk.googlegroups.com> On Jun 6, 3:34?pm, Ajith Kumar wrote: > Hello, > ?I ran the following code (Using Debian 5.0) > > from numpy import * > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. ?2. ?3.] > ?[ 4. ?5. ?6.] > ?[ 7. ?8. ?9.]] > > [[ ?3.15221191e+15 ?-6.30442381e+15 ? 3.15221191e+15] > ?[ -6.30442381e+15 ? 1.26088476e+16 ?-6.30442381e+15] > ?[ ?3.15221191e+15 ?-6.30442381e+15 ? 3.15221191e+15]] > > [[-0.5 -1. ?-1. ] > ?[-1. ?-2. ? 2. ] > ?[-1.5 -3. ? 1. ]] > > [[ ?5.5 ? 8. ? 10.5] > ?[ ?3. ? ?0. ? -3. ] > ?[ -1. ? ?0. ? -3. ]] > > NOT the identity matrix. Any help ? It's a longer time than I care to divulge since I took courses in matrix algebra, but I do have a vague recollection that if determinant (B) is zero, inverse(B) is not defined ... seeing the rows and columns in B are linear (as are those of C), IIRC that means the determinants are zero, and you are out of luck. Are you ignoring exceptions? Is that _exactly_ what you typed in? Try running it again, print the calculated determinants of B and C, and tell what version of (a) numpy (b) Python you are using. Isn't there a mailing list for numpy? HTH, John From nick at craig-wood.com Sat Jun 6 03:29:40 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 02:29:40 -0500 Subject: Error in linalg.inv ?? References: Message-ID: Ajith Kumar wrote: > I ran the following code (Using Debian 5.0) > > from numpy import * > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > [[-0.5 -1. -1. ] > [-1. -2. 2. ] > [-1.5 -3. 1. ]] > > [[ 5.5 8. 10.5] > [ 3. 0. -3. ] > [ -1. 0. -3. ]] > > NOT the identity matrix. Any help ? The matrix you are trying to invert is singular (can't be inverted), ie its determinant is zero. >> a = arange(1.,10.) >>> b = reshape(a, [3,3]) >>> linalg.det(b) -9.5171266700777579e-16 >>> Which is zero but with a bit of rounding errors which I guess numpy doesn't notice. Double checking like this >>> a,b,c,d,e,f,g,h,i=range(1,10) >>> a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g 0 >>> So I guess it is a bug that numpy didn't throw numpy.linalg.linalg.LinAlgError("Singular matrix") Like it does normally -- Nick Craig-Wood -- http://www.craig-wood.com/nick From verec at mac.com Sat Jun 6 03:34:45 2009 From: verec at mac.com (verec) Date: Sat, 6 Jun 2009 08:34:45 +0100 Subject: The Complexity And Tedium of Software Engineering References: <4a297a08$0$31258$607ed4bc@cv.net> Message-ID: <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> On 2009-06-05 21:03:33 +0100, Kenneth Tilton said: > When progress stops we will have time to polish our systems, not before. Is that an endorsement of mediocrity? -- JFB From __peter__ at web.de Sat Jun 6 04:00:04 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Jun 2009 10:00:04 +0200 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: Robert Dailey wrote: >> Well I did not post the code because it is fairly complex and its hard >> to give you the whole picture without giving you too much code. But >> here you go, you get what you ask for: >> >> def Download( self ): >> PrintSubStatus( 'Downloading...' ) >> destination = normalize( '{0}/{1}'.format( self._info.outdir, >> self._info.file_ext ) ) >> print( self._info.url ) >> print( destination ) >> urlretrieve( self._info.url, destination ) >> >> Both print statements are shown as >> below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10... >> D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip >> >> I really can't figure out why this isn't working. > > Wow how stupid... I was using: > > mxMSW-2.8.10.zip > > There is an "m" at the front, and it needs to be "w". Time and again posting the code does help ;) > wxMSW-2.8.10.zip > > This URL isn't even valid, can't believe I didn't get an exception! Sourceforge is (un)helpfully redirecting your request and Python is (un)helpfully following. I looks like you can avoid this by using a URLopener instead of the FancyURLopener implicitly used by urlretrieve(): >>> URLopener().retrieve("http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip", filename="tmp.zip") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.0/urllib/request.py", line 1476, in retrieve fp = self.open(url, data) File "/usr/lib/python3.0/urllib/request.py", line 1444, in open return getattr(self, name)(url) File "/usr/lib/python3.0/urllib/request.py", line 1622, in open_http return self._open_generic_http(http.client.HTTPConnection, url, data) File "/usr/lib/python3.0/urllib/request.py", line 1618, in _open_generic_http response.status, response.reason, response.msg, data) File "/usr/lib/python3.0/urllib/request.py", line 1638, in http_error return self.http_error_default(url, fp, errcode, errmsg, headers) File "/usr/lib/python3.0/urllib/request.py", line 1644, in http_error_default raise HTTPError(url, errcode, errmsg, headers, None) urllib.error.HTTPError: HTTP Error 302: Found Peter From kushal.kumaran+python at gmail.com Sat Jun 6 04:16:09 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 6 Jun 2009 13:46:09 +0530 Subject: Way to use proxies & login to site? In-Reply-To: References: <36bb20c2-2199-42bb-a123-171bf380182c@y10g2000prc.googlegroups.com> <629c75b1-9e67-44fb-9de0-0a23ff6c306b@v23g2000pro.googlegroups.com> Message-ID: <1e364c4e0906060116u31bed4e9x71155fe7e36d9f68@mail.gmail.com> On Fri, Jun 5, 2009 at 10:32 PM, inVINCable wrote: > On May 5, 12:51?pm, Kushal Kumaran wrote: >> On Wed, Apr 29, 2009 at 8:21 AM, inVINCable wrote: >> > On Apr 27, 7:40?pm, inVINCable wrote: >> >> Hello, >> >> >> I have been using ClientForm to log in to sites & ClientCookie so I >> >> can automatically log into my site to do some penetration testing, >> >> although, I cannot figure out a solution to use proxies with this >> >> logging in automatically. Does anyone have any solutions? >> >> >> Thanks :) >> >> >> Vince >> >> > Any ideas? >> >> If, like the example athttp://wwwsearch.sourceforge.net/ClientForm/, >> you are using urllib2, you can read the documentation for that module. >> ?It also has examples for working with proxies. >> > > Ok, I gotcha. Sounds neat, but the problem is, do you know if I can > work with proxies and then connect to a site? You can, if you read the examples section in the urllib2 documentation. http://docs.python.org/library/urllib2.html -- kushal From milesck at umich.edu Sat Jun 6 04:23:44 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 6 Jun 2009 04:23:44 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: > A can is like a pickle, in that it is a string, but anything > can be canned. > Unlike a pickle, a can cannot leave the process, though, > unless the object it points to lives in shared memory. > > If you have any interest, contact me and I will > send you the source. Sounds like di(), which can be written: import _ctypes di = _ctypes.PyObj_FromPtr def can(o): return str(id(o)) def uncan(s): return di(int(s)) http://www.friday.com/bbum/2007/08/24/python-di/ -Miles From raw at RawMBP.local Sat Jun 6 04:59:06 2009 From: raw at RawMBP.local (Raymond Wiker) Date: Sat, 06 Jun 2009 10:59:06 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Roedy Green writes: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : > >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." Absolutely... not a new observation, either, as it follows directly from Amdahl's law. From mail at microcorp.co.za Sat Jun 6 05:37:50 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 11:37:50 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: <00ac01c9e699$a79340c0$0d00a8c0@Hendrik> "Scott David Daniels" wrote: > I can think of use cases for can, and from that use an alternate > construct. The use case is passing a reference out over a wire > (TCP port?) that will be used later. This will work, provided the thing is still alive and in the same place when the can eventually finds its way back and gets uncanned. As it is now, no attempt has been made to handle refcounting issues. > Sub cases: > (1) Handing work over the wire along with a callback to invoke > with the results. > (2) Handing work over the wire along with a progress callback. > (3) Handing work over the wire along with a pair of result functions, > where the choice of functions is made on the far side of the wire. > > The "can" can be used to send the function(s) out. > Alternatively, for use case 1: > > class Holder(object): > def __init__(self): > self.key = 0 > self.holds = {} > def handle(self, something): > key = str(self.key) # may need to lock w/ next for threads > self.key += 1 > self.holds[key] = something > return key > def use(self, handle): > return self.holds.pop(handle) This is nice - you are making a simple index. Dammit! why did I not think of something like this - It keeps it all in Python, without a C extension. In my case I would need a global so that I would know where to look it up in, but that is a non issue as it can be made at startup. I really should keep the maxim in mind: There is no problem in computer science that can not be solved by means of the introduction of another layer of indirection. :-) Thanks for this post Scott - it has helped to straighten out my one track minded thinking - I got hung up on the idea of passing the reference, to the extent that I expended what was for me heroic effort to get it across. What causes me real chagrin is that I am already keeping a list of queues - the active queue list that keeps the list of output queues for the various clients that have connected. And I am too dim witted to think of a dict... > > Otherwise a simple dictionary with separate removal may be needed. > If you might abandon an element w/o using it, use a weakref dictionary, > but then you need a scheme to keep the thing alive long enough > for needed operations (as you also need with a can). In my use case the queue would have stayed alive because the thread that created it would have kept it going until it was no longer needed, as would the reference created by the binding of the local name in the thread. > > In use case 1, the dictionary becomes that holding point. > The counter-as-key idea allows you to keep separate references > to the same thing, so the reference is held for precisely as long > as needed. It (counter-as-key) beats the str(id(obj)) of can > because it tracks the actual object, not simply the id that can > be reused. The can just looks like str(id(obj)) - at the C level, it actually comes from the PyObject *, gets stringified, and the uncan returns the original PyObject *. So if I understand it correctly, after the uncanning, it __is__ the original object. (if it is still there) As I said above, I have paid no attention to refcounting issues, - it really needs someone knowledgeable to work over my C code, as this was my first venture into the wonderful world of extending python. But it hardly seems worth while now... - Hendrik From gagsl-py2 at yahoo.com.ar Sat Jun 6 05:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 06:44:47 -0300 Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> <78711541-1fe7-4201-9bee-c31747e86d7c@k2g2000yql.googlegroups.com> Message-ID: En Sat, 06 Jun 2009 03:03:34 -0300, escribi?: > On Jun 5, 8:56?pm, Robert Dailey wrote: >> Is it possible to create an object in Python that will clean itself up >> at function exit? I realize destruction of objects may not occur >> immediately and can be garbage collected, but this functionality would >> still be great to have. > > I don't know what you mean by: > > "I realize destruction of objects may not occur immediately and can be > garbage collected" > > Aren't you just missing ordinary destructors (__del__() methods)? > These are closest to C++ destructors AFAICS. As far as I know, these > are guaranteed to be called when an object goes out of scope. (Note > that destruction and garbage collection are different operations; an > object may be destructed without being immediately garbage-collected > afterwards.) No, that's not how it works in Python (and I think you're mistaken for C++ too). See http://docs.python.org/reference/datamodel.html and specially http://docs.python.org/reference/datamodel.html#object.__del__ "Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether." CPython uses a "reference count" scheme - an object is destroyed as soon as it loses its last reference. Other implementations may choose another strategy - in fact, Jython relies on garbage collection instead; object destruction may be delayed an arbitrary amount of time. (CPython has a garbage collector too, but its purpose is to detect and break object cycles.) So the OP is right - you can't rely on object destruction to perform any cleanup; use try/finally or a with statement instead. >>>> import sys >>>> class Simple: > ... def __init__(self): sys.stdout.write("Simple.__init__()\n") > ... def __del__(self): sys.stdout.write("Simple.__del__()\n") > ... >>>> def f(): > ... s = Simple() > ... sys.stdout.write("f()\n") > ... # 's' now going out of scope... > ... >>>> f() > Simple.__init__() > f() > Simple.__del__() This behaviour isn't guaranteed and you should not rely on it. Also, try again with: def f(): s = Simple() t = Simple() s.x = t t.x = s sys.stdout.write("f()\n") -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Sat Jun 6 06:41:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 22:41:23 +1200 Subject: A simpler logging configuration file format? References: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Message-ID: In message <30db8a0b-5b19-47e4-9364-54cbd7a7cacf at h23g2000vbc.googlegroups.com>, geoff.bache at gmail.com wrote: > At the moment, if I want to add a new logger "foo" writing to its own > file "foo" to my config file, I have to repeat the name 7(!) times, > editing 3 different sections in the process: I suppose there's always the Sendmail solution: stick an m4 wrapper on top to hide the details of the process. :) From ldo at geek-central.gen.new_zealand Sat Jun 6 06:42:14 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 22:42:14 +1200 Subject: Christian Audigier Bikinis References: Message-ID: In message , tanvon19 at gmail.com wrote: > Please check our web ... Wow, you have a web. I always wanted to have one of those. From davea at ieee.org Sat Jun 6 06:45:13 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Jun 2009 06:45:13 -0400 Subject: Messing up with classes and their namespace In-Reply-To: <4A296075.8090501@sequans.com> References: <4A296075.8090501@sequans.com> Message-ID: <4A2A48B9.1050307@ieee.org> Jean-Michel Pichavant wrote: >
Scott > David Daniels wrote: >> Jean-Michel Pichavant wrote: >>> Hello world, >>> >>> I had recently a very nasty bug in my python application. The >>> context is quite complex, but in the end the problem can be resume >>> as follow: >>> >>> 2 files in the same directory : >>> >>> lib.py: >>> >import foo >>> >foo.Foo.BOOM='lib' >>> >>> foo.py: >>> >class Foo: >>> > BOOM = 'Foooo' >>> > >>> >if __name__=='__main__': >>> > import lib # I'm expecting BOOM to be set to 'lib' >>> > print Foo.BOOM >>> >>> I was expecting 'lib' as output, but I got 'Fooo'. I don't really >>> understand what python mechanism I'm messing with but I have the >>> feeling I've misunderstood a very basic concept about class, >>> namespace or whatever import notion. >>> >> >>> I guess there is 2 different objects for the same class Foo. How I >>> do I make both Foo objects the same object ? >> >> OK, here is one solution (from which you may infer the problem): >> >> lib.py: >> import __main__ >> __main__.Foo.BOOM = 'lib' >> >> foo.py: >> class Foo: >> BOOM = 'Foooo' >> >> if __name__ == '__main__': >> import lib # I'm expecting BOOM to be set to 'lib' >> print(Foo.BOOM) >> >> Here is another solution: >> >> lib.py: >> import foo >> foo.Foo.BOOM = 'lib' >> >> foo.py: >> class Foo: >> BOOM = 'Foooo' >> >> if __name__ == '__main__': >> import sys >> sys.modules['foo'] = sys.modules['__main__'] >> import lib # I'm expecting BOOM to be set to 'lib' >> print(Foo.BOOM) >> >> Here is a demo of what is actually going wrong: >> >> foo.py: >> class Foo: >> inside = __name__ >> >> import foo >> >> if __name__ == '__main__': >> print(Foo is foo.Foo) >> print(Foo.inside, foo.Foo.inside) >> >> And here is a fix >> foo.py: >> if __name__ == '__main__': >> import sys >> sys.modules['foo'] = sys.modules['__main__'] >> >> class Foo: >> inside = __name__ >> >> import foo >> >> if __name__ == '__main__': >> print(Foo is foo.Foo) >> print(Foo.inside, foo.Foo.inside) >> >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Thanks for the explanation. I'll have to give it a second thought, I'm > still missing something but I'll figure it out. > > Jean-Michel > >
> In general, two or more modules with mutual imports can cause problems. If modulea.py imports moduleb, and moduleb.py imports modulea, you can end up with difficulties. But even more gross difficulties come from importing the module that started the execution, as it's got another name, "__main__" If you import it again with its traditional name, these two do not get combined, and you end up with multiple instances of things you thought were safe. Scott has given you a solution for the second problem. But the first problem is more general, and should perhaps be the one you try first. The simplest answer in many cases is to factor the script into two separate files. One will have "library" functions and classes, like the Foo in your example. And the other will have the logic for parsing command line arguments and suchlike. The general problem isn't unique to Python. You can also end up with problems in C, where one header includes a second one, which re-includes the first. The workarounds for it are well known, but most of them also contain subtle difficulties. If it's possible, factor out mutual dependencies into a separate module. From mail at microcorp.co.za Sat Jun 6 06:47:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 12:47:39 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik><004201c9e5f3$c6809920$0d00a8c0@Hendrik> Message-ID: <00ad01c9e699$a89fcec0$0d00a8c0@Hendrik> "Gabriel Genellina" wrote: > From your description of the problem, it seems you are acting upon >messages received from a serial port. You have to process the message >*before* the next one arrives -- but you gain nothing doing that much >faster. In other words, even with a blazingly fast processor, you can't do >things faster than the rate of incoming messages. This is what I said, but it is only half of the truth. The actual code is a little bit better. What I have been describing here for simplicity's sake, is the path taken when there is actually something in the queue. The non blocking queue.get() sits in a try except, and if the queue is empty, it actually gathers the inputs and then examines them for change. If there are changes, it makes up response messages to the various clients and puts them on the output queues. If there are no changes, and if it has been a while since the last responses were sent, it sends responses as well. Else it sleeps for a very short time and then examines the incoming queue again. This arrangement minimises the network usage to what is essential, while also reassuring the clients that all is well when nothing is happening. It also uses the time when there is no new output to scan the inputs, and it is this that I was talking about when I defined the responsiveness. > >In any case, you have to test-and-branch in the code. Either with >isinstance(rec,str), either with rec_list[0]=="B", or something. I'm Yes - but this is the second test, that is only reached in the very seldom case that the first one is not true, so it does not add to the normal critical timing path. >unsure if this is the fastest approach - intuition doesn't play well with >timings in Python, better to actually measure times. > You have never said a truer thing - at one stage I was using a loop in C to scan the inputs and put them in memory, but I went back to python because it was faster to use a small time.sleep than the equivalent usleep in C. I still do not understand how that could be, but my oscilloscope does not lie. 8<---------------------------- >If it works and you feel it's adequate, that's fine. I cannot count how >many times I've used an integer property to attach a pointer to another >object (in other languages), but I felt "dirty" doing that. And never did >something like that in Python... I think that the dirty feeling is caused by the FUD that has been created by C's pointer types, and the magic that happens when you add 1 to a pointer and it actually increments by the size of a whole structure, invisibly. It makes one forget that the pointer is just a number representing a memory address. And we have all been bitten in some way or another by pointer arithmetic. And if you look at this thread's title, it is not called Winter Madness by accident... :-) 8<---------------- >Ok, what if you split *before* putting in the queue? In the receiving side >of the queue, just remove the split(",") part (it's already done). This >does not add anything to the critical path - the split must be done anyway. This is good thinking, thank you. It cuts the knot. > >Now, instead of building a fake string "B,cannedobject" and uncanning on >the other side, you can simply put a tuple in the queue ("B", the_object) >and just get the object on the other side. If I'm not misunderstanding >your problem, I think this is the cleanest way to do that. You are spot on, and you are not misunderstanding anything. This will work, and work well. Thank you again. So now I have two viable alternatives to the can - yours, and Scott's. So it looks like it is time to can the Can. So I can have a productive day throwing code away. Thanks again. - Hendrik From mail at microcorp.co.za Sat Jun 6 07:26:09 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 13:26:09 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <00ae01c9e699$a94f48a0$0d00a8c0@Hendrik> "Miles Kaufmann" wrote: > On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: > > > A can is like a pickle, in that it is a string, but anything > > can be canned. > > Unlike a pickle, a can cannot leave the process, though, > > unless the object it points to lives in shared memory. > > > > If you have any interest, contact me and I will > > send you the source. > > Sounds like di(), which can be written: > > import _ctypes > di = _ctypes.PyObj_FromPtr > > def can(o): return str(id(o)) > def uncan(s): return di(int(s)) > > http://www.friday.com/bbum/2007/08/24/python-di/ There is nothing new... Normally it takes a long time before something is re invented. In this case it looks like less than two years. Thank you for the link - Hendrik From mark.dufour at gmail.com Sat Jun 6 08:15:18 2009 From: mark.dufour at gmail.com (srepmub) Date: Sat, 6 Jun 2009 05:15:18 -0700 (PDT) Subject: interval arithmetic libraries Message-ID: <410afd39-e1e0-403d-aa23-e1e85742351c@z14g2000yqa.googlegroups.com> Hi all, I'm looking for libraries that allow one to calculate with sets of (date) intervals. So for example, I'd like to be able to calculate the overlap between two sets of intervals, the union etc. Preferrably, this works with datetime objects, is written in pure Python, and has reasonably good (algorithmic) performance. The neatest library I've found so far is this one: http://members.cox.net/apoco/interval/ >From an API standpoint, it looks rather nice, but the performance could be better (for example, calculating an overlap now involves looping quadratically over both interval sets), and it doesn't work fully with datetime objects (Inf doesn't work). Thanks for any pointers, Mark Dufour. (author of Shedskin, an experimental (restricted-)Python-to-C++ compiler, http://shedskin.googlecode.com) From samwyse at gmail.com Sat Jun 6 08:28:30 2009 From: samwyse at gmail.com (samwyse) Date: Sat, 6 Jun 2009 05:28:30 -0700 (PDT) Subject: py3k printing generators -- not! Message-ID: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> The one thing that's killing me in Python 3000 is that every time I try to print something, it seems like I get at 0x01BAF508>. Googling only found one reference, a posting elsewhere by one Carl Johnson (aka carlj7, http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), which apparently was never answered. Is anyone else finding this bothersome, or is it entirely due to my FP background? Always saying "print(','.join(x))" gets tiresome in a hurry. I've thought about defining my own function "prnt" that wraps print and fixes generators, but that requires me to get their type, which despite the claims of "help(type(x for x in range(0)))" cannot be found in builtins. How are other solving this? From kentilton at gmail.com Sat Jun 6 08:38:10 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Sat, 06 Jun 2009 08:38:10 -0400 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> References: <4a297a08$0$31258$607ed4bc@cv.net> <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> Message-ID: <4a2a6321$0$31269$607ed4bc@cv.net> verec wrote: > On 2009-06-05 21:03:33 +0100, Kenneth Tilton said: > >> When progress stops we will have time to polish our systems, not before. > > Is that an endorsement of mediocrity? No, of General Patton. hth, kt From aahz at pythoncraft.com Sat Jun 6 08:50:12 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Jun 2009 05:50:12 -0700 Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: In article , Terry Reedy wrote: >Aahz wrote: >> >> Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is >> that 2.7 is mostly restricted to code landed in 3.1, so your second >> statement is roughly correct. > >My understanding is that 2.7 will come out about the same time as 3.2 >and will contain 3.2 backports also. New features are being marked on >the issue tracker as for 2.7/3.2. There may or may not be a 2.8. > >(It was once intended that 2.7 come out with 3.1, but that changed when >it was decided to cut the life of 3.0 and bring out 3.1 after 6 months.) Right, but it was my understanding that work on releasing 2.7 would commence immediately after 3.1, and that 3.2 would happen after 2.7. Maybe we should take this to python-dev... ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From pavlovevidence at gmail.com Sat Jun 6 08:58:53 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Jun 2009 05:58:53 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: On Jun 6, 5:28?am, samwyse wrote: > The one thing that's killing me in Python 3000 is that every time I > try to print something, it seems like I get at 0x01BAF508>. ?Googling only found one reference, a > posting elsewhere by one Carl Johnson (aka carlj7,http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), > which apparently was never answered. ?Is anyone else finding this > bothersome, or is it entirely due to my FP background? > > Always saying "print(','.join(x))" gets tiresome in a hurry. ? What about print(list(x)) > I've > thought about defining my own function "prnt" that wraps print and > fixes generators, but that requires me to get their type, which > despite the claims of "help(type(x for x in range(0)))" cannot be > found in builtins. Interestingly, the fact that it wasn't in builtins didn't stop you from being able to pass the type to the help() function. I wonder if you can use the same trick to obtain the type for use in your prnt() function. (Failing that, you could use "from types import GeneratorType".) >?How are other solving this? In my experience, if you want a custom print function that prints things the way you want, you have to write it yourself. People's expectations are too different. Carl Banks From bearophileHUGS at lycos.com Sat Jun 6 08:59:39 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 05:59:39 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: samwyse: > Always saying "print(','.join(x))" gets tiresome in a hurry. ?I've > thought about defining my own function "prnt" that wraps print and > fixes generators, but that requires me to get their type, Why do you need to know their type? Isn't something like this enough? def pr(it): txt = "".join(map(str, it)) print(txt) That little function can be improved in many ways. > despite the claims of "help(type(x for x in range(0)))" > cannot be found in builtins. Python can yield mixed types (nearly never recommended): def foo(): yield 1 yield "hello" yield 1.5 Bye, bearophile From bearophileHUGS at lycos.com Sat Jun 6 09:01:12 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 06:01:12 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: Carl Banks: > What about print(list(x)) Right, better than mine :-) Bye, bearophile From pieterprovoost at gmail.com Sat Jun 6 09:02:26 2009 From: pieterprovoost at gmail.com (Pieter Provoost) Date: Sat, 6 Jun 2009 15:02:26 +0200 Subject: PyQt icon problem Message-ID: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> Hi, My application has a QSystemTrayIcon, which needs to be changed once in a while. The PNG icons are converted into a module using pyrcc4. When I run the Python script on my Windows system everything works fine, but when run it on Ubuntu or when I use py2exe, the icons are not visible (there's only empty space in the tray). Any thoughts? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Sat Jun 6 09:42:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 06:42:12 -0700 Subject: spammers on pypi In-Reply-To: References: Message-ID: Lawrence D'Oliveiro wrote: > In message > , joep > wrote: > >> Is there a way to ban spammers from pypi? > > Yes, but it doesn't work. > And if you ever do discover something that _does_ work: (1) You'll have discovered perpetual motion. (2) You'll probably get terribly rich from selling it. (3) You'll probably advertize your new solution via bulk e-mail to all e-mail addresses you know of that might be interested in learning of your great discovery. :-) --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jun 6 09:47:34 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 06:47:34 -0700 Subject: openhook In-Reply-To: References: Message-ID: Gaudha wrote: > Can anybody tell me what is meant by 'openhook' ? Certainly someone can. From tsangpo.newsgroup at gmail.com Sat Jun 6 11:07:58 2009 From: tsangpo.newsgroup at gmail.com (tsangpo) Date: Sat, 6 Jun 2009 23:07:58 +0800 Subject: can it be shorter? Message-ID: I want to ensure that the url ends with a '/', now I have to do thisa like below. url = url + '' if url[-1] == '/' else '/' Is there a better way? From samwyse at gmail.com Sat Jun 6 11:11:32 2009 From: samwyse at gmail.com (samwyse) Date: Sat, 6 Jun 2009 08:11:32 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: On Jun 6, 7:58?am, Carl Banks wrote: > On Jun 6, 5:28?am, samwyse wrote: > > Always saying "print(','.join(x))" gets tiresome in a hurry. ? > > What about print(list(x)) Yeah, I like that. Or, to save some typing: prnt = lambda x: print(list(x)) > Interestingly, the fact that it wasn't in builtins didn't stop you > from being able to pass the type to the help() function. ?I wonder if > you can use the same trick to obtain the type for use in your prnt() > function. Of course, but it would mean evaluating an expression every time I defined my function. That just seems unhygenic > (Failing that, you could use "from types import GeneratorType".) Ah! I should've thought of that. > In my experience, if you want a custom print function that prints > things the way you want, you have to write it yourself. ?People's > expectations are too different. Well, that's why I rferenced the other article, http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), to show that other people have the same expectations. (In the article, Carl Johnson correctly points out that the real problem is that str() responds to generators differently than do the other collection types.) From akindo01 at hotmail.com Sat Jun 6 11:12:12 2009 From: akindo01 at hotmail.com (akindo) Date: Sat, 6 Jun 2009 16:12:12 +0100 Subject: Iterating Over Dictionary From Arbitrary Location Message-ID: Hi all. I am new to Python and have a problem regarding data structures. In my application I will be having several messages and my own type of IDs (Lamport clocks) to go with these messages. I will need to frequently ask for specific messages based on the ID. Hence a dictionary seems a better choice than a list, as I will be using my own IDs to index into the data structure. However, the problem is that I will also at times ask for a specific message based on the ID key, but then want _all_ messages with a higher ID returned as well. :shock: From my research, there are two problems with a dictionary then: 1. it can't be sorted (only returns a sorted list), 2. even if it was possible to sort a dictionary, it is not possible to iterate over it from a given location. So, it seems I want the best of both worlds: specific indexing using my own IDs/keys (not just by list element location), sorting and the ability to start iterating from a specific location. I am trying to prevent having to scan through a list from the beginning to find the desired ID, and then return all elements after that. Is there another data structure or design pattern which will do what I want? Thanks a lot for any help! :) From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 11:16:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 15:16:38 GMT Subject: can it be shorter? References: Message-ID: <023a7abc$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 23:07:58 +0800, tsangpo wrote: > I want to ensure that the url ends with a '/', now I have to do thisa > like below. > url = url + '' if url[-1] == '/' else '/' > > Is there a better way? if not url.endswith('/'): url += '/' -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 11:19:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 15:19:45 GMT Subject: openhook References: Message-ID: <023a7b76$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote: > Gaudha wrote: >> Can anybody tell me what is meant by 'openhook' ? > Certainly someone can. It's just like closehook, only different. -- Steven From pieterprovoost at gmail.com Sat Jun 6 11:36:06 2009 From: pieterprovoost at gmail.com (Pieter Provoost) Date: Sat, 6 Jun 2009 17:36:06 +0200 Subject: PyQt icon problem In-Reply-To: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> References: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> Message-ID: <944a84700906060836g6837ef0cw4b90e3268b6503a2@mail.gmail.com> Correction: when using py2exe, no icon, empty space or message is visible (the app is running though). On Ubuntu, there is an empty space but messages are not displayed. 2009/6/6 Pieter Provoost > Hi, > > My application has a QSystemTrayIcon, which needs to be changed once in a > while. The PNG icons are converted into a module using pyrcc4. When I run > the Python script on my Windows system everything works fine, but when run > it on Ubuntu or when I use py2exe, the icons are not visible (there's only > empty space in the tray). > > Any thoughts? > Thanks > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sat Jun 6 11:53:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 06 Jun 2009 17:53:54 +0200 Subject: Iterating Over Dictionary From Arbitrary Location In-Reply-To: References: Message-ID: <78vhoiF1oi28oU1@mid.uni-berlin.de> akindo schrieb: > Hi all. I am new to Python and have a problem regarding data structures. > > In my application I will be having several messages and my own type of > IDs (Lamport clocks) to go with these messages. I will need to > frequently ask for specific messages based on the ID. Hence a dictionary > seems a better choice than a list, as I will be using my own IDs to > index into the data structure. However, the problem is that I will also > at times ask for a specific message based on the ID key, but then want > _all_ messages with a higher ID returned as well. :shock: From my > research, there are two problems with a dictionary then: 1. it can't be > sorted (only returns a sorted list), 2. even if it was possible to sort > a dictionary, it is not possible to iterate over it from a given location. > > So, it seems I want the best of both worlds: specific indexing using my > own IDs/keys (not just by list element location), sorting and the > ability to start iterating from a specific location. I am trying to > prevent having to scan through a list from the beginning to find the > desired ID, and then return all elements after that. Is there another > data structure or design pattern which will do what I want? Thanks a lot > for any help! :) you could use a list which is sorted and then use the bisect-module to look up your keys in O(log n). You could also map keys to list-indices. Diez From no.email at please.post Sat Jun 6 11:59:37 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 15:59:37 +0000 (UTC) Subject: can it be shorter? References: Message-ID: In "tsangpo" writes: >I want to ensure that the url ends with a '/', now I have to do thisa like >below. >url = url + '' if url[-1] == '/' else '/' >Is there a better way? It's a pity that in python regexes are an "extra", as it were. Otherwise I'd propose: url = re.sub("/?$", "/", url) kynn (lowest-of-the-low python noob) From bearophileHUGS at lycos.com Sat Jun 6 12:06:26 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 09:06:26 -0700 (PDT) Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: akindo: > So, it seems I want the best of both worlds: specific indexing using ? > my own IDs/keys (not just by list element location), sorting and the ? > ability to start iterating from a specific location. A sorted associative map may be fit. A data structure based on a search tree, like a red-black tree, etc. The Python std lib doesn't contain such data structure. Do you need to add items to your data structure? Diez has suggested a possible solution. You can keep a copy of the items in a sorted list, but this isn't handy if you have to add and remove items frequently. Or you may be able to find somewhere a sorted associative array data structure (tree-based). Bye, bearophile From martin.hellwig at dcuktec.org Sat Jun 6 12:17:37 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 06 Jun 2009 17:17:37 +0100 Subject: openhook In-Reply-To: <023a7b76$0$20636$c3e8da3@news.astraweb.com> References: <023a7b76$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote: > >> Gaudha wrote: >>> Can anybody tell me what is meant by 'openhook' ? >> Certainly someone can. > > It's just like closehook, only different. > > Just like the flipflophook, the quantumhook and captain hook. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From tsangpo.newsgroup at gmail.com Sat Jun 6 12:21:45 2009 From: tsangpo.newsgroup at gmail.com (tsangpo) Date: Sun, 7 Jun 2009 00:21:45 +0800 Subject: can it be shorter? In-Reply-To: References: Message-ID: "kj" ???? news:h0e3p9$85t$1 at reader1.panix.com... > In "tsangpo" > writes: > >>I want to ensure that the url ends with a '/', now I have to do thisa like >>below. >>url = url + '' if url[-1] == '/' else '/' > >>Is there a better way? > > It's a pity that in python regexes are an "extra", as it were. > Otherwise I'd propose: > > url = re.sub("/?$", "/", url) > > kynn (lowest-of-the-low python noob) look nice, but: >>> re.sub('/?$/', '/', 'aaabbb') 'aaabbb' has no effect. what a pity. From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:23:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:23:32 GMT Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: <023a8a69$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 05:28:30 -0700, samwyse wrote: > The one thing that's killing me in Python 3000 Python 3000 was vapourware. When the vapour condensed into liquid, it was renamed Python 3. Right now, the only vapourware is Python4000, which may or may not be created by Guido's heir some time in the 2020s. > is that every time I try > to print something, it seems like I get at > 0x01BAF508>. "Every time"? Really? Even when you print an object which isn't a generator? > Googling only found one reference, a posting elsewhere by > one Carl Johnson (aka carlj7, > http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), > which apparently was never answered. Ignoring Carl's totally pointless "mycond()" function, he apparently wants type(iterable)(i for i in iterable) to give iterable: >>> it = [1, 2] >>> type(it)(i for i in it) [1, 2] But that can't work for arbitrary iterables: >>> it = {1:2, 3:4} >>> type(it)(i for i in it) Traceback (most recent call last): File "", line 1, in TypeError: cannot convert dictionary update sequence element #0 to a sequence Nor will it work for generator objects themselves: >>> it = (1+x for x in range(5)) >>> type(it)(i for i in it) Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'generator' instances So Carl's suggestion can't be applied universally, it can only hold for some iterables. It doesn't even hold for all sequences, with strings a conspicuous example. In fact, that's what Carl is complaining about: >>> it = "abc" >>> type(it)(i for i in it) ' at 0xb7ce3d24>' He apparently would prefer str(i for i in "abc") to return "abc". However, you seem to prefer "a,b,c" instead. So what you would prefer, and what Carl would prefer, are different. Either way though, there's a fatal flaw in the idea: printing an object shouldn't consume the object, but that's what you want. Unlike a list or a tuple, a generator is *code*, not a data type. It produces values when and as asked. So there's no way to peek inside a generator and see the values that it will produce, consequently, for str() to behave as you and Carl want, it has to run the generator to completion, performing an arbitrarily large amount of work (and perhaps, for non-terminating generators, never finishing!) before you can print it. And then, having printed it, the generator is now exhausted. Try to print it again, and you'll get the empty string. Calling list() on a generator is different: it is *designed* to exhaust the generator. I'd be upset if print() and/or str() did the same thing. I'd also be upset if generators looked like a string when they're not: >>> x = (c.lower() for c in "ABC") >>> x 'abc' >>> x.upper() # x looks like a string, but it isn't Traceback (most recent call last): File "", line 1, in AttributeError: 'generator' object has no attribute 'upper' [...] > I've > thought about defining my own function "prnt" that wraps print and fixes > generators, but that requires me to get their type, which despite the > claims of "help(type(x for x in range(0)))" cannot be found in builtins. > How are other solving this? I'm not "solving" this, because I don't think this is a problem that needs solving. But if you want a custom print function, this should work: def print(*values, **kwargs): from builtins import print as pr gen = type(x for x in [1,2]) values = [','.join(str(s) for s in obj) if type(obj) is gen else obj for obj in values] pr(*values, **kwargs) -- Steven From woodchips at rochester.rr.com Sat Jun 6 12:34:34 2009 From: woodchips at rochester.rr.com (woodchips at rochester.rr.com) Date: Sat, 6 Jun 2009 09:34:34 -0700 (PDT) Subject: python repository? Message-ID: Hi, I've written a large body of my work in MATLAB over the years. But it looks like I'll need to move to Python soon. Is there a common resource where people can post files for others to use such as the MATLAB central file exchange? Thanks, John From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:34:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:34:38 GMT Subject: can it be shorter? References: Message-ID: <023a8d04$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: > In "tsangpo" > writes: > >>I want to ensure that the url ends with a '/', now I have to do thisa >>like below. >>url = url + '' if url[-1] == '/' else '/' > >>Is there a better way? > > It's a pity that in python regexes are an "extra", as it were. Otherwise > I'd propose: > > url = re.sub("/?$", "/", url) Thank goodness regexs are an "extra" in Python, because it discourages noobs from pulling out the 80 pound sledgehammer of the regex engine to crack the peanut of a test-and-concatenate: >>> from timeit import Timer >>> min(Timer( ... "if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) 0.70030903816223145 >>> min(Timer( ... "sub('/?$', '/', s)", "from re import sub; s = 'abcd/efgh'").repeat()) 7.6922709941864014 That's more than ten times slower. Really, a regex is massive overkill for a task that simple. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:38:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:38:27 GMT Subject: can it be shorter? References: Message-ID: <023a8de9$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 00:21:45 +0800, tsangpo wrote: > "kj" ???? news:h0e3p9$85t $1 at reader1.panix.com... >> In "tsangpo" >> writes: >> >>>I want to ensure that the url ends with a '/', now I have to do thisa >>>like below. >>>url = url + '' if url[-1] == '/' else '/' >> >>>Is there a better way? >> >> It's a pity that in python regexes are an "extra", as it were. >> Otherwise I'd propose: >> >> url = re.sub("/?$", "/", url) >> >> kynn (lowest-of-the-low python noob) > > look nice, but: > >>>> re.sub('/?$/', '/', 'aaabbb') > 'aaabbb' > > has no effect. what a pity. That's because you're doing it wrong. You've added an extra slash: you're asking the regex engine to match a backslash *after* the end of the string. Obviously that will never match. >>> re.sub('/?$/', '/', 'aaabbb') # extra / 'aaabbb' >>> re.sub('/?$', '/', 'aaabbb') # no extra / 'aaabbb/' But before you get too excited, see my previous post: the regex solution is more than ten times slower than test-and-concatenate. -- Steven From emile at fenx.com Sat Jun 6 12:39:31 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 06 Jun 2009 09:39:31 -0700 Subject: openhook In-Reply-To: References: Message-ID: On 6/6/2009 6:47 AM Scott David Daniels said... > Gaudha wrote: >> Can anybody tell me what is meant by 'openhook' ? > Certainly someone can. OK -- kidding aside, the only python related reference I find is in a proposal and patch [1] made by Anthony Roy for changes to the fileinput module. It's an argument passed into FileInput class initialization and apparently allows for a custom file open routine to be used to open the target file -- ergo openhook - a hook for opening. Emile [1] http://bugs.python.org/issue1613500 From kwatch at gmail.com Sat Jun 6 12:44:42 2009 From: kwatch at gmail.com (kwatch) Date: Sat, 6 Jun 2009 09:44:42 -0700 (PDT) Subject: ANN: pyTenjin 0.8.0 - much faster template engine than Django Message-ID: I have released pyTenjin 0.8.0 http://www.kuwata-lab.com/tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) * Goole AppEngine supported. http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine Changes from 0.7.0 ------------------ * !!IMPORTANT!! HTML helper function 'tagattr()' is renamed to 'tagattrs()'. (Notice that new 'tagattr()' is added. See below.) * 'tagattrs()' is changed to add ' ' (space) at the first character. ex. (0.7.0) tagattr(klass='error') #=> 'class="error"' (0.7.1) tagattrs(klass='error') #=> ' class="error"' * 'tagattrs()' is changed to handle 'checked', 'selected', and 'disabled' attributes. ex. >>> from tenjin.helpers.html import * >>> tagattrs(checked=True, selected='Y', disabled=1) ' checked="checked" selected="selected" disabled="disabled"' >>> tagattrs(checked=False, selected='', disabled=0) '' Bugfix ------ * !!IMPORTANT!! Template caching is changed to keep template file's timestamp instead of create time of cached object. See http://groups.google.com/group/kuwata-lab-products/browse_thread/thread/a0d447c282fb383d#msg_de39557405c9b656 for details. (Thanks Steve) Enhancements ------------ * Add new HTML helper function 'tagattr()'. (Notice that 'tagattr()' in 0.7.0 is renamed into 'tagattrs()'.) ex. >>> from tenjin.helpers.html import * >>> tagattr('size', 20) ' size="20"' >>> tagattr('size', 0) '' >>> tagattr('size', 20, 'large') ' size="large"' >>> size = 20 # you can use tagattrs() instead of tagattr () >>> tagattrs(size=(size and 'large')) ' size="large"' * Add new HTML helper function 'new_cycle()'. ex. >>> from tenjin.helpers.html import * >>> cycle = new_cycle('odd, 'even') >>> cycle() 'odd' >>> cycle() 'even' >>> cycle() 'odd' >>> cycle() 'even' * (experimental) Template converter is changed to add dummy if- statement when first Python statement is indented. (Thanks Steve) ex. $ cat ex.pyhtml
  • ${item}
$ pytenjin -sb ex.pyhtml _buf.extend(('''
    \n''', )); if True: ## dummy for item in items: _buf.extend(('''
  • ''', escape(to_str(item)), '''
  • \n''', )); #end _buf.extend(('''
\n''', )); * Update User's Guide and FAQ. Have fun! -- regards, makoto kuwata From simon at brunningonline.net Sat Jun 6 12:49:31 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sat, 6 Jun 2009 17:49:31 +0100 Subject: Programming language comparison examples? In-Reply-To: References: Message-ID: <8c7f10c60906060949x3586aades12b431a51a3f0571@mail.gmail.com> 2009/6/5 : > someone: >> I thought there was a website which demonstrated how to program a bunch of >> small problems in a number of different languages. > > http://www.rosettacode.org/wiki/Main_Page > http://en.literateprograms.org/LiteratePrograms:Welcome > http://www.codecodex.com/wiki/index.php?title=Main_Page > http://merd.sourceforge.net/pixel/language-study/scripting-language/ > http://pleac.sourceforge.net/ > http://www.angelfire.com/tx4/cus/shapes/index.html And my favorite: http://99-bottles-of-beer.net/ -- Cheers, Simon B. From no.email at please.post Sat Jun 6 13:42:32 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 17:42:32 +0000 (UTC) Subject: can it be shorter? References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: >> In "tsangpo" >> writes: >> >>>I want to ensure that the url ends with a '/', now I have to do thisa >>>like below. >>>url = url + '' if url[-1] == '/' else '/' >> >>>Is there a better way? >> >> It's a pity that in python regexes are an "extra", as it were. Otherwise >> I'd propose: >> >> url = re.sub("/?$", "/", url) >Thank goodness regexs are an "extra" in Python, because it discourages >noobs from pulling out the 80 pound sledgehammer of the regex engine to >crack the peanut of a test-and-concatenate: I was just responding to the OP's subject line. Whatever else one may say about my proposal, it *is* shorter. But thanks for the tip with timeit. That looks like a good module to know. kynn From benjamin.kaplan at case.edu Sat Jun 6 13:44:49 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 6 Jun 2009 13:44:49 -0400 Subject: python repository? In-Reply-To: References: Message-ID: On Saturday, June 6, 2009, wrote: > Hi, > > I've written a large body of my work in MATLAB over the years. But it > looks like I'll need to move to Python soon. Is there a common > resource where people can post files for others to use such as the > MATLAB central file exchange? > > Thanks, > John > -- For small code snippets that solve general problems, look at the recipies on ActiveState's website (code.activestate.com). Large projects are listed on the python package index (pypi.python.org) though they aren't hosted there. > http://mail.python.org/mailman/listinfo/python-list > From nick at craig-wood.com Sat Jun 6 14:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 13:29:41 -0500 Subject: openhook References: Message-ID: Gaudha wrote: > Can anybody tell me what is meant by 'openhook' ? http://docs.python.org/library/fileinput.html?highlight=openhook Maybe ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Sat Jun 6 14:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 13:29:41 -0500 Subject: can it be shorter? References: Message-ID: tsangpo wrote: > > "kj" ???? news:h0e3p9$85t$1 at reader1.panix.com... > > In "tsangpo" > > writes: > > > >>I want to ensure that the url ends with a '/', now I have to do thisa like > >>below. > >>url = url + '' if url[-1] == '/' else '/' > > > >>Is there a better way? > > > > It's a pity that in python regexes are an "extra", as it were. > > Otherwise I'd propose: > > > > url = re.sub("/?$", "/", url) > > > > kynn (lowest-of-the-low python noob) > > look nice, but: > > >>> re.sub('/?$/', '/', 'aaabbb') > 'aaabbb' > > has no effect. what a pity. That is because you typoed what kynn wrote. >>> re.sub('/?$', '/', 'aaabbb') 'aaabbb/' >>> That solution is very perl-ish I'd say, IMHO if not url.endswith("/"): url += "/" is much more pythonic and immediately readable. In fact even someone who doesn't know python could understand what it does, unlike the regexp solution which requires a little bit of thought. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gneuner2 at comcast.net Sat Jun 6 15:46:51 2009 From: gneuner2 at comcast.net (George Neuner) Date: Sat, 06 Jun 2009 15:46:51 -0400 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green wrote: >On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who >said : > >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > >Could what you are saying be summed up by saying, "The more threads >you have the more important it is to keep your threads independent, >sharing as little data as possible." And therein lies the problem of leveraging many cores. There is a lot of potential parallelism in programs (even in Java :) that is lost because it is too fine a grain for threads. Even the lightest weight user space ("green") threads need a few hundred instructions, minimum, to amortize the cost of context switching. Add to that the fact that programmers have shown themselves, on average, to be remarkably bad at figuring out what _should_ be done in parallel - as opposed to what _can_ be done - and you've got a clear indicator that threads, as we know them, are not scalable except under a limited set of conditions. George From pdlemper at earthlink.net Sat Jun 6 15:48:29 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 06 Jun 2009 14:48:29 -0500 Subject: Is it possible to use multidimensional arrays ? Message-ID: All attempts have failed. import WConio import array screen = array.array('H',[0]*75,[0]*24) ERR array takes at most 2 arguments screen = array.array('H',[0]*75[0]*24) TypeErr int object is unsubscriptable screen = array.array('H',[0]*75)('H',[0]*24) ERR object is not callable screen - array.array('H',[0]*75*24) Goes through but results are, of course, unacceptable On-line docs and Programming in Python 3 are no help. Should I give up on arrays and use lists, or go to NumPy ? Thanks From v.donati at email.it Sat Jun 6 16:35:04 2009 From: v.donati at email.it (v.donati at email.it) Date: 6 Jun 2009 22:35:04 +0200 Subject: Servizio aziende : messaggio per python-list@python.org Message-ID: <20090606203144.2A279C041@smtp-out08.email.it>

Offriamo :

Servizi di consulenza  per :  marketing ,  informatica , traduzioni

Assistenza nazionale ed internazionale

Per maggiori informazioni e preventivi clicca qui

Per reclami inviare mail a SMINI

Se non vuoi ricevere altri messaggi invia una mail a SMINI UNSUBSCRIBE

Messaggio per : python-list at python.org



We offer :

Consulting for : marketing , information , translating services

National and international assistance

To ask for further information and estimates click here

To complain send an email to SMINI

In case you do not want to receive further messages, send a mail toSMINI UNSUBSCRIBE

Message for : python-list at python.org

-- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f Sponsor: Legal.email.it: posta elettronica certificata per l'invio di email con valore legale e SMS di notifica Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid?78&d=6-6 From jpthing at online.no Sat Jun 6 16:47:32 2009 From: jpthing at online.no (John Thingstad) Date: Sat, 06 Jun 2009 22:47:32 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: P? Sat, 06 Jun 2009 21:46:51 +0200, skrev George Neuner : > On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green > > Add to that the fact that programmers have shown themselves, on > average, to be remarkably bad at figuring out what _should_ be done in > parallel - as opposed to what _can_ be done - and you've got a clear > indicator that threads, as we know them, are not scalable except under > a limited set of conditions. > > George I find the dataflow model of concurrency on Oz to be interesting and to address many of the issues you just mentioned. See in particular: 'Dataflow variables and declarative concurrency' and onward. http://en.wikipedia.org/wiki/Oz_(programming_language) --------------------- John Thingstad From no.email at please.post Sat Jun 6 17:14:00 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 21:14:00 +0000 (UTC) Subject: Is it possible to use multidimensional arrays ? References: Message-ID: In pdlemper at earthlink.net writes: >All attempts have failed. > import WConio > import array > screen = array.array('H',[0]*75,[0]*24) > ERR array takes at most 2 arguments > screen = array.array('H',[0]*75[0]*24) > TypeErr int object is unsubscriptable > screen = array.array('H',[0]*75)('H',[0]*24) > ERR object is not callable > screen - array.array('H',[0]*75*24) > Goes through but results are, of course, unacceptable >On-line docs and Programming in Python 3 are no help. >Should I give up on arrays and use lists, or go to NumPy ? Thanks I guess you could do something like screen = [array.array('H', [0]*75) for i in range(24)] but I doubt that the resulting structure would be that much more efficient than the pure-list equivalent... kynn -- lowest-of-the-low python noob From robert.kern at gmail.com Sat Jun 6 17:15:01 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 16:15:01 -0500 Subject: Error in linalg.inv ?? In-Reply-To: <4A29FFD2.1030609@iuac.res.in> References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 00:34, Ajith Kumar wrote: > Hello, > I ran the following code (Using Debian 5.0) > > from numpy import * Please ask numpy questions on the numpy mailing list, not here: http://www.scipy.org/Mailing_Lists > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > [[-0.5 -1. -1. ] > [-1. -2. 2. ] > [-1.5 -3. 1. ]] > > [[ 5.5 8. 10.5] > [ 3. 0. -3. ] > [ -1. 0. -3. ]] > > NOT the identity matrix. Any help ? You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it numerically and expect sensible results. -- 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 Jun 6 17:18:00 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 16:18:00 -0500 Subject: Is it possible to use multidimensional arrays ? In-Reply-To: References: Message-ID: On 2009-06-06 14:48, pdlemper at earthlink.net wrote: > All attempts have failed. > > import WConio > import array > > screen = array.array('H',[0]*75,[0]*24) > ERR array takes at most 2 arguments > > screen = array.array('H',[0]*75[0]*24) > TypeErr int object is unsubscriptable > > screen = array.array('H',[0]*75)('H',[0]*24) > ERR object is not callable > > screen - array.array('H',[0]*75*24) > Goes through but results are, of course, unacceptable > On-line docs and Programming in Python 3 are no help. > Should I give up on arrays and use lists, or go to NumPy ? Thanks Go to numpy, probably. -- 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 Sat Jun 6 17:25:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 17:25:05 -0400 Subject: Odd closure issue for generators In-Reply-To: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> Message-ID: Michele Simionato wrote: > Yes, most functional languages have the concept of streams. > You can even define a stream-comprehension that looks like > Python generator comprehension but it is an essentially different > thing. See for instance > > http://www.artima.com/weblogs/viewpost.jsp?thread=251159 I read that. It seems that streams are virtual or lazy linked-lists(1). I think, though, that comparing them to iterators is misleading. They are iterables, but with a different iteration protocol. Python iterables are generally reiterable just like streams. chars = 'abc' for c in chars: print(c,end=' ') for c in chars: print(c,end=' ') produces repeatable output just like your stream example. Python *could* have given iterables .first and .rest methods instead of .__iter__, but that works best for linked lists and awfully for arrays. Anyway, I realize now that having generator comprehensions produce an *iterator* rathar than an *iterable* or *generator function* is something of an anomaly Set, dict, and list comprehensions in Python produce iterables, of course, as does a stream comprehension in Scheme and, I presume, comprehensions in other languages. A generator expression could have been defined in Python to just produce a generator function, without calling it, but the intent of the abbreviation was for one-use situations. Multi-use gfs should be defined with a def statement. Terry Jan Reedy (1) Calling the first and rest methods 'car' and 'cdr' convinces me that schemers really do not want scheme to be popular, but prefer it to remain a small cult language. From no.email at please.post Sat Jun 6 17:56:45 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 21:56:45 +0000 (UTC) Subject: can it be shorter? References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: In kj writes: >In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >>On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: >>> In "tsangpo" >>> writes: >>> >>>>I want to ensure that the url ends with a '/', now I have to do thisa >>>>like below. >>>>url = url + '' if url[-1] == '/' else '/' >>> >>>>Is there a better way? >>> >>> It's a pity that in python regexes are an "extra", as it were. Otherwise >>> I'd propose: >>> >>> url = re.sub("/?$", "/", url) >>Thank goodness regexs are an "extra" in Python, because it discourages >>noobs from pulling out the 80 pound sledgehammer of the regex engine to >>crack the peanut of a test-and-concatenate: >I was just responding to the OP's subject line. Whatever else one >may say about my proposal, it *is* shorter. >But thanks for the tip with timeit. That looks like a good module >to know. And actually, if speed is the criterion, then one should also avoid endswith: >>> from timeit import Timer >>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) 0.18654584884643555 >>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) 0.43395113945007324 kynn From tjreedy at udel.edu Sat Jun 6 18:07:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 18:07:07 -0400 Subject: Error in linalg.inv ?? In-Reply-To: <4A29FFD2.1030609@iuac.res.in> References: <4A29FFD2.1030609@iuac.res.in> Message-ID: Ajith Kumar wrote: > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] Another way to see that this is singular is notice or calculate that (1,2,3) - 2*(4,5,6) + (7,8,9) = (0,0,0) Same is true for the columns. From sjmachin at lexicon.net Sat Jun 6 18:09:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 6 Jun 2009 22:09:57 +0000 (UTC) Subject: Error in linalg.inv ?? References: <4A29FFD2.1030609@iuac.res.in> Message-ID: Robert Kern gmail.com> writes: > > On 2009-06-06 00:34, Ajith Kumar wrote: > > from numpy import * > > Please ask numpy questions on the numpy mailing list, not here: > > http://www.scipy.org/Mailing_Lists > > > a = arange(1.,10.) > > b = reshape(a, [3,3]) > > c = linalg.inv(b) > > > > And the result is > > > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] (gibberish) > > You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it > numerically and expect sensible results. Is raising an exception (as documented (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not a "sensible result"? From python at mrabarnett.plus.com Sat Jun 6 18:24:11 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Jun 2009 23:24:11 +0100 Subject: can it be shorter? In-Reply-To: References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: <4A2AEC8B.2020109@mrabarnett.plus.com> kj wrote: > In kj writes: > >> In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: > >>> On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: > >>>> In "tsangpo" >>>> writes: >>>> >>>>> I want to ensure that the url ends with a '/', now I have to do thisa >>>>> like below. >>>>> url = url + '' if url[-1] == '/' else '/' >>>>> Is there a better way? >>>> It's a pity that in python regexes are an "extra", as it were. Otherwise >>>> I'd propose: >>>> >>>> url = re.sub("/?$", "/", url) > > >>> Thank goodness regexs are an "extra" in Python, because it discourages >>> noobs from pulling out the 80 pound sledgehammer of the regex engine to >>> crack the peanut of a test-and-concatenate: > >> I was just responding to the OP's subject line. Whatever else one >> may say about my proposal, it *is* shorter. > >> But thanks for the tip with timeit. That looks like a good module >> to know. > > > > And actually, if speed is the criterion, then one should also avoid endswith: > >>>> from timeit import Timer >>>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) > 0.18654584884643555 >>>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) > 0.43395113945007324 > If there's any chance that the string could be empty (len(s) == 0) then use: if s[-1 : ] != '/' s += '/' From Scott.Daniels at Acm.Org Sat Jun 6 18:28:16 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 15:28:16 -0700 Subject: can it be shorter? In-Reply-To: References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: <1Z-dnR0WYuSScbfXnZ2dnUVZ_tadnZ2d@pdx.net> kj wrote: > ... And actually, if speed is the criterion, then one should also avoid endswith: > >>>> from timeit import Timer >>>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) > 0.18654584884643555 >>>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) > 0.43395113945007324 _but_, try this with s = '', and you are in trouble. So, try: if s[-1:] != '/': s += '/' To be a trifle more reliable. But, for more normal semantics, you might prefer either: if s[-1:] != '/': s = (s or '.') + '/' or: if s and s[-1] != '/': s += '/' --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Sat Jun 6 18:31:10 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 17:31:10 -0500 Subject: Error in linalg.inv ?? In-Reply-To: References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 17:09, John Machin wrote: > Robert Kern gmail.com> writes: > >> On 2009-06-06 00:34, Ajith Kumar wrote: > >>> from numpy import * >> Please ask numpy questions on the numpy mailing list, not here: >> >> http://www.scipy.org/Mailing_Lists >> >>> a = arange(1.,10.) >>> b = reshape(a, [3,3]) >>> c = linalg.inv(b) >>> >>> And the result is >>> >>> [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] >>> [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] >>> [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > (gibberish) > >> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it >> numerically and expect sensible results. > > Is raising an exception (as documented > (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not > a "sensible result"? That's not the way I was using the phrase, but you have a point. We depend on the underlying LAPACK routine to tell us if the array is singular or not. It will inform us if it stopped prematurely because of singularity. In this case, I think it happens to complete simply because it is so small and the subroutine did not detect the singularity. A (5,5) matrix constructed the same way will raise the exception, for example. However, the condition number of a matrix is not a binary property. A matrix can be poorly conditioned but not precisely singular, and the inversion routine will give you a correct result (within the limits of floating point arithmetic) rather than an exception, but you will still get mostly nonsense out if you try to use that result. You still need to apply care in interpreting the result and not rely on our throwing an exception even if we could catch all singular inputs. -- 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 bearophileHUGS at lycos.com Sat Jun 6 18:46:26 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 15:46:26 -0700 (PDT) Subject: Is it possible to use multidimensional arrays ? References: Message-ID: <087de8e9-4eb1-40f6-a0e8-ee1699c54d95@y7g2000yqa.googlegroups.com> pdlem... at earthlink.net, if you are using Psyco and you aren't using NumPy and you want max speed you may use: NROWS = 24 NCOLS = 75 screen = array("H", [0]) * (NROWS * NCOLS) and then you can use items like this: screen[r * NCOLS + c] (If NCOLS is equal or a bit lower than a power of 2 it's better to use a shift). But in most situations using lists of lists or NumPy is better. Bye, bearophile From mh at pixar.com Sat Jun 6 18:48:14 2009 From: mh at pixar.com (mh at pixar.com) Date: Sat, 06 Jun 2009 22:48:14 GMT Subject: #! to two different pythons? Message-ID: I've got a bunch of python programs on linux that start with: #!/usr/anim/menv/bin/pypix Now I'm moving some to the mac, where I'm changing that to: #!/Users/mh/py/bin/python What's the best way to handle this? I've got an install script that rewrites the first line, but if I could eliminate that step I would be quite happy, since it's the only thing the install step does. TIA!! Mark -- Mark Harrison Pixar Animation Studios From tjreedy at udel.edu Sat Jun 6 18:58:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 18:58:09 -0400 Subject: py3k printing generators -- not! In-Reply-To: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: samwyse wrote: > The one thing that's killing me in Python 3000 py3.0 or py3.1, but the 'problem' you complain about has nothing to do with those versions in particular. > is that every time I try to print something, it seems like I get at 0x01BAF508>. Nor does it have anything is particular to do with generator objects. Str(function/class/module/and-many-others) prints similarly. Since forever, str(ob) == ob.__str__() == type(ob).__str__(ob). And what you see above is the default template filled in for a particular object. Built-in concrete collections over-ride the default and return a string with their contents because they can do that without harm other than possibly producing a very long string. When the collections are large, one might want a custom function that instead formats a string with a limited number of examples and the total count. A 3.0 range object, a virtual collection, could do that too, but since there is a regular pattern, it prints a condensed representation. Aren't you glad, actually, that range(1000000000) prints as "range(0, 1000000000)" instead of listing the billion numbers it produces when iterated, as you seem to be asking for? > Googling only found one reference, a > posting elsewhere by one Carl Johnson (aka carlj7, > http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), A bogus complaint that the constructor for highly specialized class str acts differently from those of the general collection classes set, tuple, and list. Str is actually not a collection class in the way that set, tuple, list, dict, and many others are. Terry Jan Reedy From benjamin at python.org Sat Jun 6 19:01:55 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Jun 2009 23:01:55 +0000 (UTC) Subject: #! to two different pythons? References: Message-ID: pixar.com> writes: > What's the best way to handle this? #!/usr/bin/env python From pavlovevidence at gmail.com Sat Jun 6 19:08:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Jun 2009 16:08:52 -0700 (PDT) Subject: Error in linalg.inv ?? References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On Jun 6, 3:31?pm, Robert Kern wrote: > On 2009-06-06 17:09, John Machin wrote: > > Robert Kern ?gmail.com> ?writes: > >> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it > >> numerically and expect sensible results. > > > Is raising an exception (as documented > > (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv....)) not > > a "sensible result"? > > That's not the way I was using the phrase, but you have a point. > > We depend on the underlying LAPACK routine to tell us if the array is singular > or not. Perhaps the documentation should be updated to say "Raises LinAlgError if inv() detects that 'a' a singular matrix". Anyone with much experience with linear algebra libraries should know that these routines are shaky when ill-conditioned, but it could help newbies and computer science experts to be explicit about it. Carl Banks From robert.kern at gmail.com Sat Jun 6 19:23:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 18:23:56 -0500 Subject: Error in linalg.inv ?? In-Reply-To: References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 18:08, Carl Banks wrote: > On Jun 6, 3:31 pm, Robert Kern wrote: >> On 2009-06-06 17:09, John Machin wrote: >>> Robert Kern gmail.com> writes: >>>> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it >>>> numerically and expect sensible results. >>> Is raising an exception (as documented >>> (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv....)) not >>> a "sensible result"? >> That's not the way I was using the phrase, but you have a point. >> >> We depend on the underlying LAPACK routine to tell us if the array is singular >> or not. > > Perhaps the documentation should be updated to say "Raises LinAlgError > if inv() detects that 'a' a singular matrix". > > Anyone with much experience with linear algebra libraries should know > that these routines are shaky when ill-conditioned, but it could help > newbies and computer science experts to be explicit about it. By all means, please do. http://docs.scipy.org/numpy/Front%20Page/ -- 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 Sat Jun 6 19:30:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Jun 2009 16:30:02 -0700 Subject: Odd closure issue for generators References: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > >(1) Calling the first and rest methods 'car' and 'cdr' convinces me that >schemers really do not want scheme to be popular, but prefer it to >remain a small cult language. What, you don't get a warm, fuzzy feeling from saying, "Today is the car of the cdr of your life"? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From mh at pixar.com Sat Jun 6 19:46:47 2009 From: mh at pixar.com (mh at pixar.com) Date: Sat, 06 Jun 2009 23:46:47 GMT Subject: #! to two different pythons? References: Message-ID: Benjamin Peterson wrote: > #!/usr/bin/env python But how can I handle this with two differently named pythons? #!/usr/anim/menv/bin/pypix #!/Users/mh/py/bin/python Thanks! Mark -- Mark Harrison Pixar Animation Studios From cs at zip.com.au Sat Jun 6 20:09:51 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 7 Jun 2009 10:09:51 +1000 Subject: #! to two different pythons? In-Reply-To: Message-ID: <20090607000951.GA7293@cskk.homeip.net> On 06Jun2009 23:46, mh at pixar.com wrote: | Benjamin Peterson wrote: | > #!/usr/bin/env python | | But how can I handle this with two differently named pythons? | | #!/usr/anim/menv/bin/pypix | #!/Users/mh/py/bin/python Well, it depends _why_ you have a python named "pypix", but two solutions suggest themselves: - Keep the "#!/usr/bin/env python" and then: ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python Presumes no other python, and /usr/local/bin might become ~/bin or something like that. - Write a small wrapper shell script and use: #!/usr/bin/env my-wrapper-script Regarding the first approach, on a personal basis I have two bin directories: ~/bin and ~/bin-local on the machines I use. The former it copied from my home account and is always the same - a bunch of useful scripts. The latter is per-host customisation and is largely symlinks to preferred versions of apps, apps installed out of the main paths, and host-specific wrapper scripts. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Soon, Grasshopper, all will understand. And dispair. The government that defines what is good for you, will also dictate what is bad. - Curt Howland "Ace" DoD#0663 EGFC#011 EFF#569 howland at Priss.com '82 V45 Sabre From mh at pixar.com Sat Jun 6 20:17:20 2009 From: mh at pixar.com (mh at pixar.com) Date: Sun, 07 Jun 2009 00:17:20 GMT Subject: #! to two different pythons? References: Message-ID: Cameron Simpson wrote: > - Keep the "#!/usr/bin/env python" and then: > ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python Ah, that's a good idea. The pypix is a company-wide maintained python, but ln -s python pypix on my local Mac laptop python install makes the env work quite nicely. The ~/bin and ~/bin-local is a great idea too... I've symlinked to my dropbox account for bonus convenience. thanks!!! Mark -- Mark Harrison Pixar Animation Studios From timr at probo.com Sat Jun 6 22:32:31 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Jun 2009 19:32:31 -0700 Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> Message-ID: <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Steven D'Aprano wrote: > >Why is it that it's (almost) always newbies with about five minutes' >worth of experience with Python that come up with these grandiose plans >to replace entire modules with a single function? Well, many great innovations in history have come from people who did not have enough experience to know that what they were doing was impossible... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From http Sat Jun 6 22:58:55 2009 From: http (Paul Rubin) Date: 06 Jun 2009 19:58:55 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: <7xskicoikw.fsf@ruckus.brouhaha.com> George Neuner writes: > Even the lightest weight > user space ("green") threads need a few hundred instructions, minimum, > to amortize the cost of context switching. I thought the definition of green threads was that multiplexing them doesn't require context switches. From massung at gmail.com Sat Jun 6 23:08:29 2009 From: massung at gmail.com (Jeff M.) Date: Sat, 6 Jun 2009 20:08:29 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> Message-ID: On Jun 6, 9:58?pm, Paul Rubin wrote: > George Neuner writes: > > Even the lightest weight > > user space ("green") threads need a few hundred instructions, minimum, > > to amortize the cost of context switching. > > I thought the definition of green threads was that multiplexing them > doesn't require context switches. There's always a context switch. It's just whether or not you are switching in/out a virtual stack and registers for the context or the hardware stack/registers. Jeff M. From tjreedy at udel.edu Sat Jun 6 23:24:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 23:24:22 -0400 Subject: Making the case for repeat In-Reply-To: <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Message-ID: Tim Roberts wrote: > Steven D'Aprano wrote: >> Why is it that it's (almost) always newbies with about five minutes' >> worth of experience with Python that come up with these grandiose plans >> to replace entire modules with a single function? > > Well, many great innovations in history have come from people who did not > have enough experience to know that what they were doing was impossible... Along with many of the great follies and frauds ;-) From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 01:20:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 05:20:51 GMT Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Message-ID: <023b4095$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 19:32:31 -0700, Tim Roberts wrote: > Steven D'Aprano wrote: >> >>Why is it that it's (almost) always newbies with about five minutes' >>worth of experience with Python that come up with these grandiose plans >>to replace entire modules with a single function? > > Well, many great innovations in history have come from people who did > not have enough experience to know that what they were doing was > impossible... So the old saw goes. Like most old saws, it's a load of codswallop. If you scratch beneath the surface, you soon discover that the people who supposedly "didn't know it was impossible" actually had a great deal of experience of what was and wasn't possible in the subject at hand. They might have been outsiders, but they were *knowledgeable* outsiders. e.g. the Wright Brothers weren't lone inventors working at a time when everyone knew powered flight was impossible, they were experienced engineers and glider-pilots who paid a lot of attention to research done by their many competitors. -- Steven From http Sun Jun 7 02:56:52 2009 From: http (Paul Rubin) Date: 06 Jun 2009 23:56:52 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> Message-ID: <7x8wk4351n.fsf@ruckus.brouhaha.com> "Jeff M." writes: > > > Even the lightest weight > > > user space ("green") threads need a few hundred instructions, minimum, > > > to amortize the cost of context switching.... > There's always a context switch. It's just whether or not you are > switching in/out a virtual stack and registers for the context or the > hardware stack/registers. I don't see the hundreds of instructions in that case. http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 shows GHC doing 50 million lightweight thread switches in 8.47 seconds, passing a token around a thread ring. Almost all of that is probably spent acquiring and releasing the token's lock as the token is passed from one thread to another. That simply doesn't leave time for hundreds of instructions per switch. From duncan.booth at invalid.invalid Sun Jun 7 05:43:54 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Jun 2009 09:43:54 GMT Subject: #! to two different pythons? References: Message-ID: mh at pixar.com wrote: > Benjamin Peterson wrote: >> #!/usr/bin/env python > > But how can I handle this with two differently named pythons? > > #!/usr/anim/menv/bin/pypix > #!/Users/mh/py/bin/python > > Thanks! > Mark > If you install using with a setup.py that uses distutils then one of the features is that any script whose first line begins '#!' and contains 'python' has that first line replaced by the current interpreter. So in this example if you install your code with: /usr/anim/menv/bin/pypix setup.py install "#!/usr/bin/env python" would be replaced by your desired "#!/usr/anim/menv/bin/pypix". Of course for your current purposes using setup.py might be overkill. From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 06:42:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 10:42:20 GMT Subject: Is reduce() foldl() or foldr()? Message-ID: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Calling all functional programming fans... is Python's built-in reduce() a left-fold or a right-fold? Wikipedia says it's a left-fold: http://en.wikipedia.org/wiki/Fold_(higher-order_function) but other people say it's a right-fold, e.g.: "... there is a `foldr` in Haskell that just works like `reduce()`" http://mail.python.org/pipermail/python-list/2007-November/638647.html and "Note that Python already has a variation of foldr, called reduce." http://blog.sigfpe.com/2008/02/purely-functional-recursive-types-in.html So which is correct? Or is it that different people have different definitions of foldl() and foldr()? -- Steven From jonas.esp at googlemail.com Sun Jun 7 07:45:26 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 04:45:26 -0700 (PDT) Subject: Properties for several keywords Message-ID: I've to write properties for several keywords with the same code, it only changes the name of each property: ----------------------------- @property def foo(self): return self._foo @foo.setter def foo(self, txt): self._foo = self._any_function(txt) # ---------------- @property def bar(self): return self._bar @bar.setter def bar(self, txt): self._bar = self._any_function(txt) ----------------------------- Is possible to simplify it? From jonas.esp at googlemail.com Sun Jun 7 07:57:09 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 04:57:09 -0700 (PDT) Subject: Properties for several keywords References: Message-ID: <0086478b-536d-4213-b257-690b1040fae4@t11g2000vbc.googlegroups.com> On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > ----------------------------- > @property > ? ?def foo(self): > ? ? ? return self._foo > > @foo.setter > ? ?def foo(self, txt): > ? ? ? self._foo = self._any_function(txt) > > # ---------------- > > @property > ? ?def bar(self): > ? ? ? return self._bar > > @bar.setter > ? ?def bar(self, txt): > ? ? ? self._bar = self._any_function(txt) > ----------------------------- > > Is possible to simplify it? Sorry for indent the decorator. From Scott.Daniels at Acm.Org Sun Jun 7 08:18:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 05:18:48 -0700 Subject: multi-core software In-Reply-To: <7x8wk4351n.fsf@ruckus.brouhaha.com> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Jeff M." writes: >>>> Even the lightest weight >>>> user space ("green") threads need a few hundred instructions, minimum, >>>> to amortize the cost of context switching.... >> There's always a context switch. It's just whether or not you are >> switching in/out a virtual stack and registers for the context or the >> hardware stack/registers. > > I don't see the hundreds of instructions in that case. > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. That simply doesn't leave time > for hundreds of instructions per switch. Remember, he said, "to amortize the cost of the context switch," not to perform the switch itself. I stutter-stepped there myself. One not completely obvious place is in blowing the instruction and likely the data) cache. I suspect it is tough to measure when that cost applies, but I expect he's likely right, except on artificial benchmarks, and the nub of the problem is not on the benchmarks. There is something to be said for the good old daays when you looked up the instruction timings that you used in a little document for your machine, and could know the cost of any loop. We are faster now, but part of the cost of that speed is that timing is a black art. Perhaps modern operating systems need the syyem call that was implemented in the Stanfor AI Lab's operating system -- phase of the moon. --Scott David Daniels Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sun Jun 7 08:20:46 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 05:20:46 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <3f3d0619-76bb-465a-ae91-fda5d293b275@l12g2000yqo.googlegroups.com> pataphor: > The problem is posting *this* > function would kill my earlier repeat for sure. And it already had a > problem with parameters < 0 (Hint: that last bug has now become a > feature in the unpostable repeat implementation) Be bold, kill your precedent ideas, and post the Unpostable :-) Despite people here complaining a bit, you can't hurt posting some lines of safe code here :-) But I agree with Steven D'Aprano, adding some explaining words to your proposals helps. Bye, bearophile From T.P.Northover at sms.ed.ac.uk Sun Jun 7 08:34:26 2009 From: T.P.Northover at sms.ed.ac.uk (Tim Northover) Date: Sun, 07 Jun 2009 13:34:26 +0100 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: <87vdn8dxyl.fsf@hal9000.lan> Steven D'Aprano writes: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? I get: >>> reduce(lambda a, b: a/b, [1.0, 2.0, 3.0]) 0.16666666666666666 which looks like a left fold to me. Tim. From __peter__ at web.de Sun Jun 7 08:41:31 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Jun 2009 14:41:31 +0200 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? > > Wikipedia says it's a left-fold: > > http://en.wikipedia.org/wiki/Fold_(higher-order_function) Wikipedia is correct: >>> from __future__ import division >>> (1/(2/(3/(4/5)))) # right 1.875 >>> ((((1/2)/3)/4)/5) # left 0.0083333333333333332 >>> reduce(lambda x, y: x/y, range(1, 6)) 0.0083333333333333332 > but other people say it's a right-fold, e.g.: > > "... there is a `foldr` in Haskell that just works like `reduce()`" > http://mail.python.org/pipermail/python-list/2007-November/638647.html > > > and > > "Note that Python already has a variation of foldr, called reduce." > http://blog.sigfpe.com/2008/02/purely-functional-recursive-types-in.html The explicit foldr() function given in this blog agrees with Wikipedia's definition: >>> def foldr(a, b, l): ... if l == []: ... return b ... else: ... return a(l[0], foldr(a, b, l[1:])) ... >>> foldr(lambda x, y: x/y, 5, range(1, 5)) 1.875 Peter From no.i.dont at want.mail.from.spammers.com Sun Jun 7 08:49:57 2009 From: no.i.dont at want.mail.from.spammers.com (Fencer) Date: Sun, 07 Jun 2009 14:49:57 +0200 Subject: Keeping console window open Message-ID: <791rbmF1okia2U1@mid.individual.net> Hello, I need to write a simple utility program that will be used under Windows. I want to write the utility in python and it will be run by double-clicking the the .py-file. I put a raw_input('Press enter to exit) at the end so the console window wouldn't just disappear when the program is finished. Anyway, I wrote a few lines of code and when I first tried to run it by double-clicking the .py-file the console window still disappeared right away. So, in order to see what was happening, I ran it from a shell and it turned out to be a missing import. My question is how can I trap errors encountered by the interpreter (if that is the right way to put it) in order to keep the console window open so one has a chance to see the error message? - Fencer From Scott.Daniels at Acm.Org Sun Jun 7 08:53:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 05:53:28 -0700 Subject: Is reduce() foldl() or foldr()? In-Reply-To: <023b8bec$0$20636$c3e8da3@news.astraweb.com> References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? ... > So which is correct? Or is it that different people have different > definitions of foldl() and foldr()? Just test. Floating point addition is not associative, so: >>> a = reduce(float.__add__, (4095 * 2. **n for n in range(100))) >>> b = reduce(float.__add__,(4095*2.**n for n in reversed(range(100)))) >>> a - b 5.7646075230342349e+17 So, since a > b, it must be foldl (the first addition happens to the first of the list). Foldl is the eager-beaver's dream; foldr is the procrastinator's dream. --Scott David Daniels Scott.Daniels at Acm.Org From higerinbeijing at gmail.com Sun Jun 7 08:55:08 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 05:55:08 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code Message-ID: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> My file contains such strings : \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a I want to read the content of this file and transfer it to the corresponding gbk code,a kind of Chinese character encode style. Everytime I was trying to transfer, it will output the same thing no matter which method was used. It seems like that when Python reads it, Python will taks '\' as a common char and this string at last will be represented as "\\xe6\\x97\ \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' output,but that's not what I want to get. Anyone can help me? Thanks in advance. From tomasz.zielinski at pyconsultant.eu Sun Jun 7 08:55:57 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Sun, 7 Jun 2009 05:55:57 -0700 (PDT) Subject: Keeping console window open References: <791rbmF1okia2U1@mid.individual.net> Message-ID: On 7 Cze, 14:49, Fencer wrote: > My question is how can I trap > errors encountered by the interpreter (if that is the right way to put > it) in order to keep the console window open so one has a chance to see > the error message? > Interpreter errors are same beasts as exceptions, so you can try:...except: them. -- Tomasz Zieli?ski http://pyconsultant.eu From xuecan at gmail.com Sun Jun 7 09:14:13 2009 From: xuecan at gmail.com (Can Xue) Date: Sun, 7 Jun 2009 21:14:13 +0800 Subject: Keeping console window open In-Reply-To: <791rbmF1okia2U1@mid.individual.net> References: <791rbmF1okia2U1@mid.individual.net> Message-ID: 2009/6/7 Fencer > Anyway, I wrote a few lines of code and when I first tried to run it by > double-clicking the .py-file the console window still disappeared right > away. So, in order to see what was happening, I ran it from a shell and it > turned out to be a missing import. My question is how can I trap errors > encountered by the interpreter (if that is the right way to put it) in order > to keep the console window open so one has a chance to see the error > message? > > I don't think this (force a console window to be kept openning only for debug purpose) is a good idea. If you just write some lines to learn something, you may run your script in a console window or in an IDE. If you are writing a big project, you'd better catch those exception and store logs in some files. However, if you still need force a console window be kept openning after the script end, you may use module atexit. -- XUE Can -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Sun Jun 7 09:23:01 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 07 Jun 2009 09:23:01 -0400 Subject: pylint naming conventions? In-Reply-To: <87skiekend.fsf@benfinney.id.au> References: <87skiekend.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Esmail writes: > >> I am confused by pylint's naming conventions, I don't think the are in >> tune with Python's style recommendations (PEP 8?) >> >> Anyone else think this? > > It's hard to know, without examples. Can you give some output of pylint > that you think doesn't agree with PEP 8? Sure, I will next time I have a nice self-contained example. Perhaps not that many people are using pylint? I was expecting a bunch of messages either contradicting my observation or agreeing with it :-) .. but perhaps this indicates that there's no issue. I'll try to come up with a nice short code example in the next few days to demonstrate what I think the problem is and post it, thanks for the suggestion. Esmail From Scott.Daniels at Acm.Org Sun Jun 7 09:26:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 06:26:00 -0700 Subject: Keeping console window open In-Reply-To: References: <791rbmF1okia2U1@mid.individual.net> Message-ID: Tomasz Zieli?ski wrote: > On 7 Cze, 14:49, Fencer wrote: >> My question is how can I trap >> errors encountered by the interpreter (if that is the right way to put >> it) in order to keep the console window open so one has a chance to see >> the error message? > > Interpreter errors are same beasts as exceptions, > so you can try:...except: them. To be a trifle more explicit, turn: ... if __name__ == '__main__': main() into: ... if __name__ == '__main__': try: main() except Exception, why: print 'Failed:', why import sys, traceback traceback.print_tb(sys.exc_info()[2]) raw_input('Leaving: ') Note that building your script like this also allows you to open the interpretter, and type: import mymodule mymodule.main() in order to examine how it runs. --Scott David Daniels Scott.Daniels at Acm.Org From jan.persson at gmail.com Sun Jun 7 09:28:16 2009 From: jan.persson at gmail.com (jpersson) Date: Sun, 7 Jun 2009 06:28:16 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken Message-ID: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Hi, >From the description the library pysync seems to be a perfect match for some of the things I would like to accomplish in my own project. The problem is that all the download links seems to be broken, so I cannot download the code. http://freshmeat.net/projects/pysync/ I've also tried to mail the author, but the mail bounces. Is there anyone out there who happens to have a tarball of this library and who could send me a copy I would be very grateful. Cheers //Jan Persson From no.i.dont at want.mail.from.spammers.com Sun Jun 7 09:39:50 2009 From: no.i.dont at want.mail.from.spammers.com (Fencer) Date: Sun, 07 Jun 2009 15:39:50 +0200 Subject: Keeping console window open In-Reply-To: References: <791rbmF1okia2U1@mid.individual.net> Message-ID: <791u96F1onh1qU1@mid.individual.net> Scott David Daniels wrote: > To be a trifle more explicit, turn: > > ... > if __name__ == '__main__': > main() > > into: > ... > if __name__ == '__main__': > try: > main() > except Exception, why: > print 'Failed:', why > import sys, traceback > traceback.print_tb(sys.exc_info()[2]) > raw_input('Leaving: ') > > Note that building your script like this also allows you to > open the interpretter, and type: > import mymodule > mymodule.main() > in order to examine how it runs. Thanks alot, this was exactly what I was looking for! > > --Scott David Daniels > Scott.Daniels at Acm.Org From rdmurray at bitdance.com Sun Jun 7 10:13:45 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Sun, 7 Jun 2009 14:13:45 +0000 (UTC) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: higer wrote: > My file contains such strings : > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a If those bytes are what is in the file (and it sounds like they are), then the data in your file is not in UTF8 encoding, it is in ASCII encoded as hexidecimal escape codes. > I want to read the content of this file and transfer it to the > corresponding gbk code,a kind of Chinese character encode style. You'll have to convert it from hex-escape into UTF8 first, then. Perhaps better would be to write the original input files in UTF8, since it sounds like that is what you were intending to do. -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From massung at gmail.com Sun Jun 7 10:23:56 2009 From: massung at gmail.com (Jeff M.) Date: Sun, 7 Jun 2009 07:23:56 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <9869d28a-1b7e-4190-a69f-ffb68585c794@t11g2000vbc.googlegroups.com> On Jun 7, 1:56?am, Paul Rubin wrote: > "Jeff M." writes: > > > > Even the lightest weight > > > > user space ("green") threads need a few hundred instructions, minimum, > > > > to amortize the cost of context switching.... > > There's always a context switch. It's just whether or not you are > > switching in/out a virtual stack and registers for the context or the > > hardware stack/registers. > > I don't see the hundreds of instructions in that case. ? > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&... > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. ?Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. ?That simply doesn't leave time > for hundreds of instructions per switch. Who said there has to be? Sample code below (just to get the point across): struct context { vir_reg pc, sp, bp, ... ; object* stack; // ... context* next; }; struct vm { context* active_context; }; void switch_context(vm* v) { // maybe GC v->active_context before switching v->active_context = v->active_context->next; } Also, there isn't "hundreds of instructions" with multiplexing, either. It's all done in hardware. Take a look at the disassembly for any application: one that uses native threads on a platform that supports preemption. You won't see any instructions anywhere in the program that perform a context switch. If you did that would be absolutely horrible. Imagine if the compiler did something like this: while(1) { // whatever } do_context_switch_here(); That would suck. ;-) That's not to imply that there isn't a cost; there's always a cost. The example above just goes to show that for green threads, the cost [of the switch] can be reduced down to a single pointer assignment. Jeff M. From piet at cs.uu.nl Sun Jun 7 10:36:24 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 07 Jun 2009 16:36:24 +0200 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> <87vdn8dxyl.fsf@hal9000.lan> Message-ID: >>>>> Tim Northover (TN) escribi?: >TN> Steven D'Aprano writes: >>> Calling all functional programming fans... is Python's built-in reduce() >>> a left-fold or a right-fold? >TN> I get: >>>>> reduce(lambda a, b: a/b, [1.0, 2.0, 3.0]) >TN> 0.16666666666666666 >TN> which looks like a left fold to me. Yes, see the Haskell result: Prelude> foldl (/) 1.0 [1.0, 2.0, 3.0] 0.16666666666666666 Prelude> foldr (/) 1.0 [1.0, 2.0, 3.0] 1.5 -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jon at ffconsultancy.com Sun Jun 7 11:14:56 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:14:56 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Roedy Green wrote: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." I see no problem with mutable shared state. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From noone at lewscanon.com Sun Jun 7 11:16:46 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 11:16:46 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: > the nub of the problem is not on the benchmarks. There is something > to be said for the good old daays when you looked up the instruction > timings that you used in a little document for your machine, and could > know the cost of any loop. We are faster now, but part of the cost of > that speed is that timing is a black art. Those good old days never existed. Those manuals never accounted for things that affected timing even then, like memory latency or refresh time. SRAM cache made things worse, since the published timings never mentioned cache-miss delays. Though memory cache might seem a recent innovation, it's been around a while. It would be challenging to find any published timing since the commercialization of computers that would actually tell the cost of any loop. Things got worse when chips like the '86 family acquired multiple instructions for doing loops, still worse when pre-fetch pipelines became deeper and wider, absolutely Dark Art due to multi-level memory caches becoming universal, and throw-your-hands-up-and-leave-for-the-corner-bar with multiprocessor NUMA systems. OSes and high-level languages complicate the matter - you never know how much time slice you'll get or how your source got compiled or optimized by run-time. So the good old days are a matter of degree and self-deception - it was easier to fool ourselves then that we could at least guess timings proportionately if not absolutely, but things definitely get more unpredictable over evolution. -- Lew From jon at ffconsultancy.com Sun Jun 7 11:20:56 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:20:56 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: George Neuner wrote: > On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green > wrote: >>On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku >> wrote, quoted or indirectly quoted someone who >>said : >>>Even for problems where it appears trivial, there can be hidden >>>issues, like false cache coherency communication where no actual >>>sharing is taking place. Or locks that appear to have low contention and >>>negligible performance impact on ``only'' 8 processors suddenly turn into >>>bottlenecks. Then there is NUMA. A given address in memory may be >>>RAM attached to the processor accessing it, or to another processor, >>>with very different access costs. >> >>Could what you are saying be summed up by saying, "The more threads >>you have the more important it is to keep your threads independent, >>sharing as little data as possible." > > And therein lies the problem of leveraging many cores. There is a lot > of potential parallelism in programs (even in Java :) that is lost > because it is too fine a grain for threads. That will always be true so it conveys no useful information to the practitioner. > Even the lightest weight > user space ("green") threads need a few hundred instructions, minimum, > to amortize the cost of context switching. Work items in Cilk are much faster than that. > Add to that the fact that programmers have shown themselves, on > average, to be remarkably bad at figuring out what _should_ be done in > parallel - as opposed to what _can_ be done - and you've got a clear > indicator that threads, as we know them, are not scalable except under > a limited set of conditions. Parallelism is inherently not scalable. I see no merit in speculating about the ramifications of "average" programmers alleged inabilities. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jon at ffconsultancy.com Sun Jun 7 11:21:58 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:21:58 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Jeff M." writes: >> > > Even the lightest weight >> > > user space ("green") threads need a few hundred instructions, >> > > minimum, to amortize the cost of context switching.... >> There's always a context switch. It's just whether or not you are >> switching in/out a virtual stack and registers for the context or the >> hardware stack/registers. > > I don't see the hundreds of instructions in that case. > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. That simply doesn't leave time > for hundreds of instructions per switch. And Haskell is not exactly fast... -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From sjmachin at lexicon.net Sun Jun 7 11:25:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 08:25:15 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> On Jun 7, 10:55 pm, higer wrote: > My file contains such strings : > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a Are you sure? Does that occupy 9 bytes in your file or 36 bytes? > > I want to read the content of this file and transfer it to the > corresponding gbk code,a kind of Chinese character encode style. > Everytime I was trying to transfer, it will output the same thing no > matter which method was used. > It seems like that when Python reads it, Python will taks '\' as a > common char and this string at last will be represented as "\\xe6\\x97\ > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' > output,but that's not what I want to get. > > Anyone can help me? > try this: utf8_data = your_data.decode('string-escape') unicode_data = utf8_data.decode('utf8') # unicode derived from your sample looks like this ??? is that what you expected? gbk_data = unicode_data.encode('gbk') If that "doesn't work", do three things: (1) give us some unambiguous hard evidence about the contents of your data: e.g. # assuming Python 2.x your_data = open('your_file.txt', 'rb').read(36) print repr(your_data) print len(your_data) print your_data.count('\\') print your_data.count('x') (2) show us the source of the script that you used (3) Tell us what "doesn't work" means in this case Cheers, John From dcest61 at hotmail.com Sun Jun 7 11:35:01 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 15:35:01 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > Roedy Green wrote: >> On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku >> wrote, quoted or indirectly quoted someone who >> said : >>> Even for problems where it appears trivial, there can be hidden >>> issues, like false cache coherency communication where no actual >>> sharing is taking place. Or locks that appear to have low contention and >>> negligible performance impact on ``only'' 8 processors suddenly turn into >>> bottlenecks. Then there is NUMA. A given address in memory may be >>> RAM attached to the processor accessing it, or to another processor, >>> with very different access costs. >> Could what you are saying be summed up by saying, "The more threads >> you have the more important it is to keep your threads independent, >> sharing as little data as possible." > > I see no problem with mutable shared state. > In which case, Jon, you're in a small minority. AHS From Scott.Daniels at Acm.Org Sun Jun 7 11:46:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 08:46:28 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Lew wrote: > Scott David Daniels wrote: >> the nub of the problem is not on the benchmarks. There is something >> to be said for the good old daays when you looked up the instruction >> timings that you used in a little document for your machine, and could >> know the cost of any loop. We are faster now, but part of the cost of >> that speed is that timing is a black art. > > Those good old days never existed. Those manuals never accounted for > things that affected timing even then, like memory latency or refresh > time. Well, as Gilbert and Sullivan wrote: - What, never? - No, never! - What, "Never"? - Well, hardly ever. Look up the LGP-30. It was quite predictable. It has been a while. --Scott David Daniels Scott.Daniels at Acm.Org From luismgz at gmail.com Sun Jun 7 11:53:31 2009 From: luismgz at gmail.com (Neuruss) Date: Sun, 7 Jun 2009 08:53:31 -0700 (PDT) Subject: unladen swallow: python and llvm References: Message-ID: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> On 5 jun, 06:29, Nick Craig-Wood wrote: > Luis M ?Gonz?lez wrote: > > > ?I am very excited by this project (as well as by pypy) and I read all > > ?their plan, which looks quite practical and impressive. > > ?But I must confess that I can't understand why LLVM is so great for > > ?python and why it will make a difference. > > CPython uses a C compiler to compile the python code (written in C) > into native machine code. > > unladen-swallow uses an llvm-specific C compiler to compile the CPython > code (written in C) into LLVM opcodes. > > The LLVM virtual machine executes those LLVM opcodes. ?The LLVM > virtual machine also has a JIT (just in time compiler) which converts > the LLVM op-codes into native machine code. > > So both CPython and unladen-swallow compile C code into native machine > code in different ways. > > So why use LLVM? ?This enables unladen swallow to modify the python > virtual machine to target LLVM instead of the python vm opcodes. > These can then be run using the LLVM JIT as native machine code and > hence run all python code much faster. > > The unladen swallow team have a lot more ideas for optimisations, but > this seems to be the main one. > > It is an interesting idea for a number of reasons, the main one as far > as I'm concerned is that it is more of a port of CPython to a new > architecture than a complete re-invention of python (like PyPy / > IronPython / jython) so stands a chance of being merged back into > CPython. > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Thanks Nick, ok, let me see if I got it: The Python vm is written in c, and generates its own bitecodes which in turn get translated to machine code (one at a time). Unladen Swallow aims to replace this vm by one compiled with the llvm compiler, which I guess will generate different bytecodes, and in addition, supplies a jit for free. Is that correct? It's confussing to think about a compiler which is also a virtual machine, which also has a jit... Another thing that I don't understand is about the "upfront" compilation. Actually, the project plan doesn't mention it, but I read a comment on pypy's blog about a pycon presentation, where they said it would be upfront compilation (?). What does it mean? I guess it has nothing to do with the v8 strategy, because unladen swallow will be a virtual machine, while v8 compiles everything to machine code on the first run. But I still wonder what this mean and how this is different. By the way, I already posted a couple of question on unladen's site. But now I see the discussion is way to "low level" for me, and I wouldn't want to interrupt with my silly basic questions... Luis From stef.mientki at gmail.com Sun Jun 7 12:16:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 07 Jun 2009 18:16:26 +0200 Subject: pyc-files contains absolute paths, is this a bug ? Message-ID: <4A2BE7DA.8060801@gmail.com> hello, AFAIK I read that pyc files can be transferred to other systems. I finally got a windows executable working through py2exe, but still have some troubles, moving the directory around. I use Python 2.5.2. I use py2exe to make a distro I can unpack the distro, on a clean computer, anywhere where I like, and it runs fine. Now when I've run it once, I move the subdirectory to another location, at it doesn't run. Looking with a hex editor into some pyc-files, I see absolute paths to the old directory. Is this normal, or am I doing something completely wrong ? thanks, Stef Mientki From tuomas.vesterinen at iki.fi Sun Jun 7 12:31:07 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 19:31:07 +0300 Subject: Python preprosessor Message-ID: <4a2beb4b$0$24760$9b536df3@news.fv.fi> I am developing a Python application as a Python2.x and Python3.0 version. A common code base would make the work easier. So I thought to try a preprosessor. GNU cpp handles this kind of code correct: #ifdef python2 print u'foo', u'bar' #endif #ifdef python3 print('foo', 'bar') #endif results: > cpp -E -Dpython2 test_cpp.py ... print u'foo', u'bar' Any other suggestions? Tuomas Vesterinen From aahz at pythoncraft.com Sun Jun 7 12:42:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 7 Jun 2009 09:42:11 -0700 Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: In article , akindo wrote: > >So, it seems I want the best of both worlds: specific indexing using >my own IDs/keys (not just by list element location), sorting and the >ability to start iterating from a specific location. I am trying to >prevent having to scan through a list from the beginning to find the >desired ID, and then return all elements after that. Is there another >data structure or design pattern which will do what I want? Thanks a >lot for any help! :) One option is to maintain both a dict and a list; it doesn't cost much memory because the individual elements don't get copied. See various "ordered dictionary" implementations for ideas on coding this. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From __peter__ at web.de Sun Jun 7 12:55:48 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Jun 2009 18:55:48 +0200 Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: Tuomas Vesterinen wrote: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > Any other suggestions? http://docs.python.org/dev/3.1/library/2to3.html From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 12:58:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 16:58:44 GMT Subject: pyc-files contains absolute paths, is this a bug ? References: Message-ID: <023be422$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 18:16:26 +0200, Stef Mientki wrote: > hello, > > AFAIK I read that pyc files can be transferred to other systems. I > finally got a windows executable working through py2exe, but still have > some troubles, moving the directory around. Sounds like a py2exe problem, not a Python problem. Perhaps you should ask them? https://lists.sourceforge.net/lists/listinfo/py2exe-users > I use Python 2.5.2. > I use py2exe to make a distro > I can unpack the distro, on a clean computer, anywhere where I like, and > it runs fine. > > Now when I've run it once, > I move the subdirectory to another location, at it doesn't run. Define "doesn't run". You mean the exe file doesn't launch at all? Does Windows display an error message? Or perhaps it launches, then immediately exists? Launches, then crashes? Does it show up in the process list at all? Or something else? -- Steven From no.email at please.post Sun Jun 7 13:11:41 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 17:11:41 +0000 (UTC) Subject: How to get local copy of docs? Message-ID: What's the best way to get a local copy of the documentation at http://docs.python.org? (The goal is to have access to this documentation even when offline.) TIA! kynn -- From http Sun Jun 7 13:25:41 2009 From: http (Paul Rubin) Date: 07 Jun 2009 10:25:41 -0700 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: <7x63f8dkh6.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? It's a left fold. > but other people say it's a right-fold, e.g.: > "... there is a `foldr` in Haskell that just works like `reduce()`" That is correct in the sense that a coding situation where you'd use reduce in Python would often lead you to use foldr (with its different semantics) in Haskell. This is because of Haskell's lazy evaluation. Example: suppose you have a list of lists, like xss = [[1,2],[3,4,5],[6,7]] and you want to concatenate them all. (++) is Haskell's list concatenation function, like Python uses + for list concatenation. So you could say ys = foldl (++) [] xss but if I have it right, that would have to traverse the entire input list before it gives you any of the answer, which can be expensive for a long list, or fail totally for an infinite list. foldr on the other hand can generate the result lazily, in sync with the way the caller consumes the elements, like writing a generator in Haskell. The tutorial http://learnyouahaskell.com/higher-order-functions#folds explains this a bit more. You might also like the Real World Haskell book: http://book.realworldhaskell.org From python at mrabarnett.plus.com Sun Jun 7 13:34:46 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Jun 2009 18:34:46 +0100 Subject: unladen swallow: python and llvm In-Reply-To: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> References: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> Message-ID: <4A2BFA36.1030305@mrabarnett.plus.com> Neuruss wrote: > On 5 jun, 06:29, Nick Craig-Wood wrote: >> Luis M Gonz?lez wrote: >> >>> I am very excited by this project (as well as by pypy) and I read all >>> their plan, which looks quite practical and impressive. >>> But I must confess that I can't understand why LLVM is so great for >>> python and why it will make a difference. >> CPython uses a C compiler to compile the python code (written in C) >> into native machine code. >> >> unladen-swallow uses an llvm-specific C compiler to compile the CPython >> code (written in C) into LLVM opcodes. >> >> The LLVM virtual machine executes those LLVM opcodes. The LLVM >> virtual machine also has a JIT (just in time compiler) which converts >> the LLVM op-codes into native machine code. >> >> So both CPython and unladen-swallow compile C code into native machine >> code in different ways. >> >> So why use LLVM? This enables unladen swallow to modify the python >> virtual machine to target LLVM instead of the python vm opcodes. >> These can then be run using the LLVM JIT as native machine code and >> hence run all python code much faster. >> >> The unladen swallow team have a lot more ideas for optimisations, but >> this seems to be the main one. >> >> It is an interesting idea for a number of reasons, the main one as far >> as I'm concerned is that it is more of a port of CPython to a new >> architecture than a complete re-invention of python (like PyPy / >> IronPython / jython) so stands a chance of being merged back into >> CPython. >> >> -- >> Nick Craig-Wood --http://www.craig-wood.com/nick > > Thanks Nick, > ok, let me see if I got it: > The Python vm is written in c, and generates its own bitecodes which > in turn get translated to machine code (one at a time). > Unladen Swallow aims to replace this vm by one compiled with the llvm > compiler, which I guess will generate different bytecodes, and in > addition, supplies a jit for free. Is that correct? > [snip] No. CPython is written in C (hence the name). It compiles Python source code to bytecodes. The bytecodes are instructions for a VM which is written in C, and they are interpreted one by one. There's no compilation to machine code. From tuomas.vesterinen at iki.fi Sun Jun 7 14:09:30 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 21:09:30 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: <4a2c025a$0$24756$9b536df3@news.fv.fi> Peter Otten wrote: > Tuomas Vesterinen wrote: > >> I am developing a Python application as a Python2.x and Python3.0 >> version. A common code base would make the work easier. So I thought to >> try a preprosessor. GNU cpp handles this kind of code correct: > >> Any other suggestions? > > http://docs.python.org/dev/3.1/library/2to3.html > > I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the other in py3. When changing the code I have to do things to 2 separate codebase in the repository. There are no patch2to3 or patch3to2, So I thought that for ensuring the common functionality of both version it would be nice to bring both versions into a common codebase. So I can update only one code and automate builds and tests for both versions. Tuomas Vesterinen From nick at craig-wood.com Sun Jun 7 14:29:39 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sun, 07 Jun 2009 13:29:39 -0500 Subject: unladen swallow: python and llvm References: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> Message-ID: Neuruss wrote: > ok, let me see if I got it: > The Python vm is written in c, and generates its own bitecodes which > in turn get translated to machine code (one at a time). > Unladen Swallow aims to replace this vm by one compiled with the llvm > compiler, which I guess will generate different bytecodes, and in > addition, supplies a jit for free. Is that correct? Pretty good I think! > It's confussing to think about a compiler which is also a virtual > machine, which also has a jit... Well the compiler is actually gcc with a llvm opcodes backend. > Another thing that I don't understand is about the "upfront" > compilation. > Actually, the project plan doesn't mention it, but I read a comment on > pypy's blog about a pycon presentation, where they said it would be > upfront compilation (?). What does it mean? I don't know, I'm afraid. > I guess it has nothing to do with the v8 strategy, because unladen > swallow will be a virtual machine, while v8 compiles everything to > machine code on the first run. But I still wonder what this mean and > how this is different. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jon at ffconsultancy.com Sun Jun 7 14:41:43 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 19:41:43 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> I see no problem with mutable shared state. > > In which case, Jon, you're in a small minority. No. Most programmers still care about performance and performance means mutable state. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jon at ffconsultancy.com Sun Jun 7 14:43:25 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 19:43:25 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: > Lew wrote: >> Scott David Daniels wrote: >>> the nub of the problem is not on the benchmarks. There is something >>> to be said for the good old daays when you looked up the instruction >>> timings that you used in a little document for your machine, and could >>> know the cost of any loop. We are faster now, but part of the cost of >>> that speed is that timing is a black art. >> >> Those good old days never existed. Those manuals never accounted for >> things that affected timing even then, like memory latency or refresh >> time. > > Well, as Gilbert and Sullivan wrote: > - What, never? > - No, never! > - What, "Never"? > - Well, hardly ever. > Look up the LGP-30. It was quite predictable. It has been a while. Same for early ARMs. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From no.email at please.post Sun Jun 7 14:44:51 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 18:44:51 +0000 (UTC) Subject: fileinput.input(f,inplace=True,...) preserves perms? Message-ID: Does fileinput.input(files, inplace=True, ...) preserve the permissions of the file? (I.e. does it ensure that the new file has the same permissions as the original file?) TIA! kynn -- From tomasz.zielinski at pyconsultant.eu Sun Jun 7 15:15:22 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Sun, 7 Jun 2009 12:15:22 -0700 (PDT) Subject: How to get local copy of docs? References: Message-ID: <2dbd9a27-78b0-4194-89eb-4b5a953c9e20@x3g2000yqa.googlegroups.com> On 7 Cze, 19:11, kj wrote: > What's the best way to get a local copy of the documentation athttp://docs.python.org??(The goal is to have access to this > documentation even when offline.) They have also CHM version (I'm not not sure where I got it from, but I think it was Windows installer). -- Tomasz Zieli?ski http://pyconsultant.eu From danwgrace at gmail.com Sun Jun 7 15:21:46 2009 From: danwgrace at gmail.com (Daniel) Date: Sun, 7 Jun 2009 12:21:46 -0700 (PDT) Subject: 403 error for python webpage Message-ID: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> I created a page with a ".py" extension but the browser does not like it. Here is what I did: I edited httpd.conf file and added the line: AddHandler cgi-script .cgi .py Then I stopped and restarted apache. Next I created a hello world file as on this page: http://deron.meranda.us/python/webserving/helloworld.html I stored the file in htdocs and then went to the corresponding http://127.0.0.1/python/testhw.py in my browser. But the browser gives a 403 error. I am running from internet explorer on windows xp. From Pidgeot18 at verizon.invalid Sun Jun 7 15:35:34 2009 From: Pidgeot18 at verizon.invalid (Joshua Cranmer) Date: Sun, 07 Jun 2009 15:35:34 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > No. Most programmers still care about performance and performance means > mutable state. [ Citation needed ]. Most programmers I've met could care less about performance. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth From jonas.esp at googlemail.com Sun Jun 7 16:14:49 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 13:14:49 -0700 (PDT) Subject: Get the class name Message-ID: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Is there any way of to get the class name to avoid to have that write it? --------------- class Foo: super(Foo, self) --------------- * Using Py 2.6.2 From dcest61 at hotmail.com Sun Jun 7 16:19:16 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 20:19:16 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <8hVWl.29780$Db2.10968@edtnps83> Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> I see no problem with mutable shared state. >> In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance and performance means > mutable state. Quite apart from performance and mutable state, I believe we were talking about mutable _shared_ state. And this is something that gets a _lot_ of people into trouble. AHS From fossilx at gmail.com Sun Jun 7 16:24:06 2009 From: fossilx at gmail.com (TonyM) Date: Sun, 7 Jun 2009 13:24:06 -0700 (PDT) Subject: How to get local copy of docs? References: Message-ID: On Jun 7, 1:11?pm, kj wrote: > What's the best way to get a local copy of the documentation athttp://docs.python.org??(The goal is to have access to this > documentation even when offline.) > > TIA! > > kynn > -- http://docs.python.org/download.html From bearophileHUGS at lycos.com Sun Jun 7 16:25:48 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 13:25:48 -0700 (PDT) Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: <66d43d81-92c0-4d2f-825f-05d4f0be5736@c9g2000yqm.googlegroups.com> Aahz: > See various "ordered dictionary" implementations > for ideas on coding this. But be careful to not confuse ordered dictionaries with sorted ones :-) Bye, bearophile From bearophileHUGS at lycos.com Sun Jun 7 16:35:33 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 13:35:33 -0700 (PDT) Subject: unladen swallow: python and llvm References: Message-ID: Luis M. Gonz?lez: > it seems they intend to do "upfront > compilation". How? Unladen swallow developers want to try everything (but black magic and necromancy) to increase the speed of Cpython. So they will try to compile up-front if/where they can (for example most regular expressions are known at compile time, so there's no need to compile them at run time. I don't know if Cpython compiles them before running time). What I like of Unladen swallow is that it's a very practical approach, very different in style from ShedSkin and PyPy (and it's more ambitious than Psyco). I also like Unladen swallow because they are the few people that have the boldness to do something to increase the performance of Python for real. They have a set of reference benchmarks that are very real, not synthetic at all, so for example they refuse to use Pystones and the like. What I don't like of Unladen swallow is that integrating LLVM with the CPython codebase looks like a not much probable thing. Another thing I don't like is the name of such project, it's not easy to pronounce for non-English speaking people. Bye, bearophile From tuomas.vesterinen at iki.fi Sun Jun 7 16:41:37 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 23:41:37 +0300 Subject: Get the class name In-Reply-To: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <4a2c2600$0$6277$9b536df3@news.fv.fi> Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > super(Foo, self) > --------------- > > > * Using Py 2.6.2 >>> class Foo(object): ... def cls(self): ... return self.__class__ ... >>> Foo().cls() From aljosa.mohorovic at gmail.com Sun Jun 7 16:54:19 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Sun, 7 Jun 2009 13:54:19 -0700 (PDT) Subject: pypi compatible software Message-ID: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> i've been searching for a recommended way to setup private pypi repository and i've found several options: - PloneSoftwareCenter - http://code.google.com/p/pypione/ - http://pypi.python.org/pypi/haufe.eggserver - http://www.chrisarndt.de/projects/eggbasket/ - http://pypi.python.org/pypi/ClueReleaseManager so now i have a few questions: - is code behind pypi.python.org available and why i can't find some up-to-date official document or howto for private pypi repository (maybe it exists but i just can't find it)? - since python is used in commercial environments i guess they actually have private pypi repositories, where can i find docs that defines what pypi is and how to implement it? - can you recommend 1 option (software providing pypi like service) that can be easily installed and configured as a service running on apache2/mod_wsgi, has an active community and docs howto setup? - i did found http://www.python.org/dev/peps/pep-0381/ - is this the spec that above mentioned software is based upon? any additional info or comments appreciated. Aljosa Mohorovic From pats at acm.org Sun Jun 7 17:04:49 2009 From: pats at acm.org (Patricia Shanahan) Date: Sun, 07 Jun 2009 14:04:49 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> I see no problem with mutable shared state. >> In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance and performance means > mutable state. > I don't see why that would affect whether one thinks there are problems. In my opinion, shared mutable state has a lot of problems. It is also sometimes the best design for performance reasons. Patricia From pengmeister at gmail.com Sun Jun 7 17:06:17 2009 From: pengmeister at gmail.com (=?ISO-8859-1?Q?S=F8ren_=2D_Peng_=2D_Pedersen?=) Date: Sun, 7 Jun 2009 14:06:17 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken References: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Message-ID: I think what you are looking for can be found at: http://www.google.com/codesearch/p?hl=en#RncWxgazS6A/pysync-2.24/test/testdata.py&q=pysync%20package:%22http://minkirri.apana.org.au/~abo/projects/pysync/arc/pysync-2.24.tar.bz2%22%20lang:python or http://shortlink.dk/58664133 I am not affiliated with the project in any way, and I can't find a way to download the entire thing in one go. So if you do salvage a working copy please let me (and the rest of the community) know. //S?ren - Peng - Pedersen From jon at ffconsultancy.com Sun Jun 7 17:29:06 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:29:06 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Jon Harrop wrote: >>>> I see no problem with mutable shared state. >>> >>> In which case, Jon, you're in a small minority. >> >> No. Most programmers still care about performance and performance means >> mutable state. > > Quite apart from performance and mutable state, I believe we were > talking about mutable _shared_ state. And this is something that gets a > _lot_ of people into trouble. Nonsense. Scientists have been writing parallel programs for decades using shared state extensively without whining about it. Databases are mutable shared state but millions of database programmers solve real problems every day without whining about it. Use your common sense and you can write efficient parallel programs today with little difficulty. I do. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jonas.esp at googlemail.com Sun Jun 7 17:33:16 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 14:33:16 -0700 (PDT) Subject: Properties for several keywords References: Message-ID: On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > ----------------------------- > @property > ? ?def foo(self): > ? ? ? return self._foo > > @foo.setter > ? ?def foo(self, txt): > ? ? ? self._foo = self._any_function(txt) > > # ---------------- > > @property > def bar(self): > ? ?return self._bar > > @bar.setter > def bar(self, txt): > ? ?self._bar = self._any_function(txt) > ----------------------------- > > Is possible to simplify it? Please, is there any solution for this problem? From no.email at please.post Sun Jun 7 17:35:49 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 21:35:49 +0000 (UTC) Subject: How to get local copy of docs? References: Message-ID: In TonyM writes: >http://docs.python.org/download.html Perfect. Thanks! kynn -- From jon at ffconsultancy.com Sun Jun 7 17:38:33 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:38:33 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Joshua Cranmer wrote: > Jon Harrop wrote: >> No. Most programmers still care about performance and performance means >> mutable state. > > [ Citation needed ]. > > Most programmers I've met could care less about performance. Then they have no need for parallelism in the first place. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From http Sun Jun 7 17:40:23 2009 From: http (Paul Rubin) Date: 07 Jun 2009 14:40:23 -0700 Subject: unladen swallow: python and llvm References: Message-ID: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> bearophileHUGS at lycos.com writes: > What I like of Unladen swallow is that it's a very practical approach, > very different in style from ShedSkin and PyPy (and it's more > ambitious than Psyco). I also like Unladen swallow because they are > the few people that have the boldness to do something to increase the > performance of Python for real. IMHO the main problem with the Unladen Swallow approach is that it would surprise me if CPython really spends that much of its time interpreting byte code. Is there some profiling output around? My guess is that CPython spends an awful lot of time in dictionary lookups for method calls, plus incrementing and decrementing ref counts and stuff like that. Plus, the absence of a relocating garbage collector may mess up cache hit ratios pretty badly. Shed Skin as I understand it departs in some ways from Python semantics in order to get better compiler output, at the expense of breaking some Python programs. I think that is the right approach, as long as it's not done too often. That's the main reason why I think it's unfortunate that Python 3.0 broke backwards compatibility at the particular time that it did. From massung at gmail.com Sun Jun 7 17:41:39 2009 From: massung at gmail.com (Jeff M.) Date: Sun, 7 Jun 2009 14:41:39 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> Message-ID: <6c5eab9d-a35d-43df-b45c-d2559c7b2623@f10g2000vbf.googlegroups.com> On Jun 7, 3:19?pm, Arved Sandstrom wrote: > Jon Harrop wrote: > > Arved Sandstrom wrote: > >> Jon Harrop wrote: > >>> I see no problem with mutable shared state. > >> In which case, Jon, you're in a small minority. > > > No. Most programmers still care about performance and performance means > > mutable state. > > Quite apart from performance and mutable state, I believe we were > talking about mutable _shared_ state. And this is something that gets a > _lot_ of people into trouble. > Mutable shared state gets _bad_ (err.. perhaps "inexperienced" would be a better adjective) programmers - who don't know what they are doing - in trouble. There are many problem domains that either benefit greatly from mutable shared states or can't [easily] be done without them. Unified memory management being an obvious example... there are many more. Unshared state has its place. Immutable state has its place. Shared immutable state has its place. Shared mutable place has its place. Jeff M. From noone at lewscanon.com Sun Jun 7 17:45:13 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 17:45:13 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: >>>> I see no problem with mutable shared state. >>> In which case, Jon, you're in a small minority. Patricia Shanahan wrote: > In my opinion, shared mutable state has a lot of problems. It is also > sometimes the best design for performance reasons. As Dr. Jon pointed out upthread, one can write decent code with mutable shared state. It is also true that mutable state presents a lot of problems - potential problems, ones that can be solved, but not ones that can be solved thoughtlessly. On the flip side, one can write a tremendous amount of effective multi-threaded code involving shared mutable state with attention to a few rules of thumb, like always synchronize access and don't use different monitors to do so. Unlike some environments (e.g., database management systems), Java's tools to manage concurrency are explicit and low level. The programmer's job is to make sure those tools are used correctly to avoid problems. As long as they do that, then there is no special problem with shared mutable state. There is, however, a cost. Certain things must happen slower when you share mutable state, than when you share immutable state or don't share state. Certain things must happen when you share mutable state, regardless of speed, because without them your code doesn't work. For some reason, concurrent programming is an area often not well understood by a significant percentage of workaday programmers. When problems do arise, they tend to be probabilistic in nature and vary widely with system characteristics like attempted load. So the meeting ground is, yes, concurrent mutable state can present problems if not properly managed. Properly managing such is not necessarily a huge burden, but it must be borne. When done properly, shared mutable state will not present problems in production. -- Lew From jon at ffconsultancy.com Sun Jun 7 17:51:48 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:51:48 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> <6c5eab9d-a35d-43df-b45c-d2559c7b2623@f10g2000vbf.googlegroups.com> Message-ID: Jeff M. wrote: > On Jun 7, 3:19?pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >> > Arved Sandstrom wrote: >> >> Jon Harrop wrote: >> >>> I see no problem with mutable shared state. >> >> In which case, Jon, you're in a small minority. >> >> > No. Most programmers still care about performance and performance means >> > mutable state. >> >> Quite apart from performance and mutable state, I believe we were >> talking about mutable _shared_ state. And this is something that gets a >> _lot_ of people into trouble. > > Mutable shared state gets _bad_ (err.. perhaps "inexperienced" would > be a better adjective) programmers - who don't know what they are > doing - in trouble. There are many problem domains that either benefit > greatly from mutable shared states or can't [easily] be done without > them. Unified memory management being an obvious example... there are > many more. Unshared state has its place. Immutable state has its > place. Shared immutable state has its place. Shared mutable place has > its place. Exactly. I don't believe that shared mutable state is any harder to do correctly than the next solution and it is almost always the most efficient solution and the sole purpose of writing parallel programs to leverage multicores is performance. A bad developer can screw up anything. I see no reason to think that shared mutable state is any more fragile than the next thing a bad developer can screw up. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From martin at v.loewis.de Sun Jun 7 17:54:43 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 07 Jun 2009 23:54:43 +0200 Subject: pypi compatible software In-Reply-To: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> References: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> Message-ID: <4a2c3724$0$13985$9b622d9e@news.freenet.de> > - is code behind pypi.python.org available and why i can't find some > up-to-date official document or howto for private pypi repository > (maybe it exists but i just can't find it)? The code is at https://svn.python.org/packages/ Instructions for installing it are at http://wiki.python.org/moin/CheeseShopDev I don't know why you can't find it, perhaps you didn't search long enough. > - since python is used in commercial environments i guess they > actually have private pypi repositories, where can i find docs that > defines what pypi is and how to implement it? IMO, there can't possibly be a "private pypi repository". By (my) definition, PyPI is *the* Python Package Index - anything else holding packages can't be *the* index. So: pypi is a short name for the machine pypi.python.org, and it is not possible to "implement" it elsewhere, unless you have write access to the nameserver of python.org. Maybe you are asking for a specification of how setuptools and easy_install access the index, to build package repositories other than PyPI. This is specified at http://peak.telecommunity.com/DevCenter/EasyInstall#package-index-api If you are asking for something else, please be more explicit what it is that you ask for. > - can you recommend 1 option (software providing pypi like service) > that can be easily installed and configured as a service running on > apache2/mod_wsgi, has an active community and docs howto setup? If you want a plain package repository, I recommend to use Apache without any additional software. It's possible to provide a package repository completely out of static files - no dynamic code is necessary. > - i did found http://www.python.org/dev/peps/pep-0381/ - is this the > spec that above mentioned software is based upon? No, that's what the title of the document says: a "Mirroring infrastructure for PyPI". Regards, Martin From noone at lewscanon.com Sun Jun 7 18:03:48 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 18:03:48 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > I agree entirely but my statements were about parallelism and not > concurrency. Parallel and concurrent programming have wildly different > characteristics and solutions. I don't believe shared mutable state is > overly problematic in the context of parallelism. Indeed, I think it is > usually the best solution in that context. Interesting distinction. Would it be fair to compare concurrent programming to the bricks used to build the parallel program's edifice? -- Lew From jon at ffconsultancy.com Sun Jun 7 18:03:49 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 23:03:49 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > As Dr. Jon pointed out upthread, one can write decent code with mutable > shared > state. It is also true that mutable state presents a lot of problems - > potential problems, ones that can be solved, but not ones that can be > solved > thoughtlessly. On the flip side, one can write a tremendous amount of > effective multi-threaded code involving shared mutable state with > attention to a few rules of thumb, like always synchronize access and > don't use different monitors to do so. > > Unlike some environments (e.g., database management systems), Java's tools > to > manage concurrency are explicit and low level. The programmer's job is to > make sure those tools are used correctly to avoid problems. As long as > they do that, then there is no special problem with shared mutable state. > > There is, however, a cost. Certain things must happen slower when you > share mutable state, than when you share immutable state or don't share > state. Certain things must happen when you share mutable state, regardless > of speed, > because without them your code doesn't work. For some reason, concurrent > programming is an area often not well understood by a significant > percentage > of workaday programmers. When problems do arise, they tend to be > probabilistic in nature and vary widely with system characteristics like > attempted load. > > So the meeting ground is, yes, concurrent mutable state can present > problems > if not properly managed. Properly managing such is not necessarily a huge > burden, but it must be borne. When done properly, shared mutable state > will not present problems in production. I agree entirely but my statements were about parallelism and not concurrency. Parallel and concurrent programming have wildly different characteristics and solutions. I don't believe shared mutable state is overly problematic in the context of parallelism. Indeed, I think it is usually the best solution in that context. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From nowhere at home.com Sun Jun 7 18:11:11 2009 From: nowhere at home.com (Ken T.) Date: 07 Jun 2009 22:11:11 GMT Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: > So the good old days are a matter of degree and self-deception - it was > easier to fool ourselves then that we could at least guess timings > proportionately if not absolutely, but things definitely get more > unpredictable over evolution. As I recall I could get exact timings on my 6502 based Commodore 64. The issues you speak of simply weren't issues. -- Ken T. http://www.electricsenator.net Never underestimate the power of stupid people in large groups. From Scott.Daniels at Acm.Org Sun Jun 7 18:13:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 15:13:09 -0700 Subject: Properties for several keywords In-Reply-To: References: Message-ID: Kless wrote: > On 7 jun, 11:45, Kless wrote: >> I've to write properties for several keywords with the same code, it >> only changes the name of each property: ... >> Is possible to simplify it? > Please, is there any solution for this problem? Read up on property. It is the core of your answer. That being said, from your recent messages, it looks a lot like you are fighting the language, rather than using it. Pythonic code is clear about what it is doing; avoid tricky automatic stuff. def mangled(name, doc_text=None): funny_name = '_' + name def getter(self): return getattr(self, funny_name) def setter(self, text): setattr(self, funny_name, self._mangle(text)) return property(getter, setter, doc=doc_text) class MangledParts(object): blue = mangled('blue', "our side") red = mangled('red', "their side") white = mangled('white', "the poor civilians") def _mangle(self, text): print text return text.join('<>') --Scott David Daniels Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sun Jun 7 18:31:15 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 15:31:15 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> Message-ID: <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> Paul Rubin: >IMHO the main problem with the Unladen Swallow approach is that it would surprise me if CPython really spends that much of its time interpreting byte code.< Note that Py3 already has a way to speed up byte code interpretation where compiled by GCC or Intel compiler (it's a very old strategy used by Forth compilers, that in Py3 is used only partially. The strongest optimizations used many years ago in Forth aren't used yet in Py3, probably to keep the Py3 virtual machine simpler, or maybe because there are not enough Forth experts among them). Unladen swallow developers are smart and they attack the problem from every side they can think of, plus some sides they can't think of. Be ready for some surprises :-) >Is there some profiling output around?< I am sure they swim every day in profiler outputs :-) But you have to ask to them. >Plus, the absence of a relocating garbage collector may mess up cache hit ratios pretty badly.< I guess they will try to add a relocating GC too, of course. Plus some other strategy. And more. And then some cherries on top, with whipped cream just to be sure. >Shed Skin as I understand it departs in some ways from Python semantics in order to get better compiler output, at the expense of breaking some Python programs. I think that is the right approach, as long as it's not done too often.< ShedSkin (SS) is a beast almost totally different from CPython, SS compiles an implicitly static subset of Python to C++. So it breaks most real Python programs, and it doesn't use the Python std lib (it rebuilds one in C++ or compiled Python), and so on. SS may be useful for people that don't want to mess with the intricacies of Cython (ex-Pyrex) and its tricky reference count, to create compiled python extensions. But so far I think nearly no one is using SS for such purpose, so it may be a failed experiment (SS is also slow in compiling, it's hard to make it compile more than 1000-5000 lines of code). Bye, bearophile From Brian.Mingus at colorado.edu Sun Jun 7 18:40:07 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Sun, 7 Jun 2009 16:40:07 -0600 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> On Fri, Jun 5, 2009 at 3:29 AM, Nick Craig-Wood wrote: > > > It is an interesting idea for a number of reasons, the main one as far > as I'm concerned is that it is more of a port of CPython to a new > architecture than a complete re-invention of python (like PyPy / > IronPython / jython) so stands a chance of being merged back into > CPython. > Blatant fanboyism. PyPy also has a chance of being merged back into Python trunk. -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Sun Jun 7 18:45:09 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 7 Jun 2009 15:45:09 -0700 (PDT) Subject: can it be shorter? References: Message-ID: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> On Jun 6, 8:07?am, "tsangpo" wrote: > I want to ensure that the url ends with a '/', now I have to do thisa like > below. > url = url + '' if url[-1] == '/' else '/' > > Is there a better way? url+= { '/': '' }.get( url[ -1 ], '/' ) Shorter is always better. From Brian.Mingus at colorado.edu Sun Jun 7 18:59:36 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Sun, 7 Jun 2009 16:59:36 -0600 Subject: can it be shorter? In-Reply-To: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <9839a05c0906071559l6103ae9bq5dfd782751b85648@mail.gmail.com> Since extra slashes at the end of a URL are ignored, that means I win! url+='/' On Sun, Jun 7, 2009 at 4:45 PM, Aaron Brady wrote: > On Jun 6, 8:07 am, "tsangpo" wrote: > > I want to ensure that the url ends with a '/', now I have to do thisa > like > > below. > > url = url + '' if url[-1] == '/' else '/' > > > > Is there a better way? > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Shorter is always better. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Jun 7 19:13:58 2009 From: http (Paul Rubin) Date: 07 Jun 2009 16:13:58 -0700 Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <7x63f7iqmh.fsf@ruckus.brouhaha.com> Aaron Brady writes: > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Shorter is always better. url = url.rstrip('/') + '/' From dcest61 at hotmail.com Sun Jun 7 19:21:14 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 23:21:14 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > Jon Harrop wrote: >> I agree entirely but my statements were about parallelism and not >> concurrency. Parallel and concurrent programming have wildly different >> characteristics and solutions. I don't believe shared mutable state is >> overly problematic in the context of parallelism. Indeed, I think it is >> usually the best solution in that context. > > Interesting distinction. Would it be fair to compare concurrent > programming to the bricks used to build the parallel program's edifice? Way too much of a fine distinction. While they are in fact different, the point of concurrent programming is to structure programs as a group of computations, which can be executed in parallel (however that might actually be done depending on how many processors there are). Parallel computing means to carry out many computations simultaneously. These are interleaved definitions. And they are *not* wildly different. If you talk about shared mutable state, it is not as easy to use as Dr Harrop seems to think it is. Maybe in his experience it has been, but in general it's no trivial thing to manage. Lew, you probably summarized it best a few posts upstream. AHS From rogerb at rogerbinns.com Sun Jun 7 19:36:54 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 07 Jun 2009 16:36:54 -0700 Subject: Python preprosessor In-Reply-To: <4a2c025a$0$24756$9b536df3@news.fv.fi> References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> <4a2c025a$0$24756$9b536df3@news.fv.fi> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tuomas Vesterinen wrote: > I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the > other in py3. The expectation would be that you only maintain the py2 code and automatically generate the py3 code on demand using 2to3. It is possible to have the same code run under both versions, but not recommended. As an example I do this for the APSW test suite, mostly because the test code deliberately explores various corner cases that 2to3 could not convert (nor should it try!). Here is how I do the whole Unicode thing: if py3: # defined earlier UPREFIX="" else: UPREFIX="u" def u(x): # use with raw strings return eval(UPREFIX+"'''"+x+"'''") # Example of use u(r"\N${BLACK STAR}\u234") You can pull similar stunts for bytes (I use buffers in py2), long ints (needing L suffix in some py2 versions), the next() builtin from py3, exec syntax differences etc. You can see more details in the first 120 lines of http://code.google.com/p/apsw/source/browse/apsw/trunk/tests.py Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkosTxEACgkQmOOfHg372QS4rQCgl1ymNME2kdHTBUoc7/f2e+W6 cbMAmwf7mArr7hVA8k/US53JE59ChnIt =pQ92 -----END PGP SIGNATURE----- From python at rcn.com Sun Jun 7 19:46:23 2009 From: python at rcn.com (Raymond Hettinger) Date: Sun, 7 Jun 2009 16:46:23 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> [pataphor] > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Interesting phraseology ;-) Enticing and yet fallacious in its presumption of known and accepted usability problems. FWIW, when I designed the module, I started by researching constructs that had proven success in functional languages and then adapted them to the needs of Python applications. That being said, I'm always open to hearing new ideas. After reading this thread a couple times, I have a few thoughts to offer. 1. The Pythonic Way(tm) is to avoid combining too much functionality in a single function, preferring to split when possible. That is why ifilter() and ifilterfalse() are separate functions. (FWIW, the principle is considered pythonic because it was articulated by Guido and has been widely applied throughout the language.) There is a natural inclination to do the opposite. We factor code to eliminate redundancy, but that is not always a good idea with an API. The goal for code factoring is to minimize redundancy. The goal for API design is having simple parts that are easily learned and can be readily combined (i.e. the notion of an iterator algebra). It is not progress to mush the parts together in a single function requiring multiple parameters. 2. I question the utility of some combining repeat() and cycle() because I've not previously seen the two used together. OTOH, there may be some utility to producing a fixed number of cycles (see the ncycles() recipe in the docs). Though, if I thought this need arose very often (it has never been requested), the straight-forward solution would be to add a "times" argument to cycle(), patterned after repeat()'s use of a "times" argument. 3. Looking at the sample code provided in your post, I would suggest rewriting it as a factory function using the existing tools as components. That way, the result of the function will still run at C speed and not be slowed by corner cases or unused parameters. (see the ncycles recipe for an example of how to do this). 4. The suggested combined function seems to emphasize truncated streams (i.e. a fixed number of repetitions or cycles). This is at odds with the notion of a toolset designed to allow lazy infinite iterators to be fed to consumer functions that truncate on the shortest iterable. For example, the toolset supports: izip(mydata, count(), repeat(datetime.now())) in preference to: izip(mydata, islice(count(), len(mydata)), repeat(datetime.now (),times=len(mydata))) To gain a better appreciation for this style (and for the current design of itertools), look at the classic Hughes' paper "Why Functional Programming Matters". http://www.math.chalmers.se/~rjmh/Papers/whyfp.pdf Raymond From sjmachin at lexicon.net Sun Jun 7 19:47:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 16:47:22 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: On Jun 8, 12:13?am, "R. David Murray" wrote: > higer wrote: > > My file contains such strings : > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > If those bytes are what is in the file (and it sounds like they are), > then the data in your file is not in UTF8 encoding, it is in ASCII > encoded as hexidecimal escape codes. OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or r"\xe6" by what mechanism in which parallel universe? From jon at ffconsultancy.com Sun Jun 7 19:59:52 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 00:59:52 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Arved Sandstrom wrote: > Lew wrote: >> Interesting distinction. Would it be fair to compare concurrent >> programming to the bricks used to build the parallel program's edifice? > > Way too much of a fine distinction. While they are in fact different, > the point of concurrent programming is to structure programs as a group > of computations, which can be executed in parallel (however that might > actually be done depending on how many processors there are). No. Concurrent programming is about interleaving computations in order to reduce latency. Nothing to do with parallelism. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From python at mrabarnett.plus.com Sun Jun 7 20:20:43 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 01:20:43 +0100 Subject: how to transfer my utf8 code saved in a file to gbk code In-Reply-To: References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <4A2C595B.3080301@mrabarnett.plus.com> John Machin wrote: > On Jun 8, 12:13 am, "R. David Murray" wrote: >> higer wrote: >>> My file contains such strings : >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a >> If those bytes are what is in the file (and it sounds like they are), >> then the data in your file is not in UTF8 encoding, it is in ASCII >> encoded as hexidecimal escape codes. > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > r"\xe6" by what mechanism in which parallel universe? Maybe he means that the file itself is in ASCII. From jon at ffconsultancy.com Sun Jun 7 20:22:00 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 01:22:00 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > Jon Harrop wrote: >> I agree entirely but my statements were about parallelism and not >> concurrency. Parallel and concurrent programming have wildly different >> characteristics and solutions. I don't believe shared mutable state is >> overly problematic in the context of parallelism. Indeed, I think it is >> usually the best solution in that context. > > Interesting distinction. Would it be fair to compare concurrent > programming to the bricks used to build the parallel program's edifice? Concurrent programming certainly underpins the foundations of almost all parallel programs. Not least at the level of the OS scheduling the threads than run the parallel programs. However, that knowledge is probably more confusing than helpful here. In essence, concurrent programming is concerned with reducing latency (e.g. evading blocking) by interleaving computations whereas parallel programming is concerned with maximizing throughput by performing computations at the same time. Historically, concurrency has been of general interest on single core machines in the context of operating systems and IO and has become more important recently due to the ubiquity of web programming. Parallelism was once only important to computational scientists programming shared-memory supercomputers and enterprise developers programming distributed-memory clusters but the advent of multicore machines on the desktop and in the games console has pushed parallelism into the lime light for ordinary developers when performance is important. Solutions for concurrent and parallel programming are also wildly different. Concurrent programming typically schedules work items that are expected to block on a shared queue for a pool of dozens or even hundreds of threads. Parallel programming typically schedules work items that are expected to not block on wait-free work-stealing queues for a pool of "n" threads where "n" is the number of cores. Solutions for concurrent programming (such as the .NET thread pool and asynchronous workflows in F#) can be used as a poor man's solution for parallel programming but the overheads are huge because they were not designed for this purpose so performance is much worse than necessary. Solutions for parallel programming (e.g. Cilk, the Task Parallel Library) are virtually useless for concurrent programming because you quickly end up with all "n" threads blocked and the whole program stalls. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From pats at acm.org Sun Jun 7 20:31:26 2009 From: pats at acm.org (Patricia Shanahan) Date: Sun, 07 Jun 2009 17:31:26 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <0KGdnabuMMt8xrHXnZ2dnUVZ_jBi4p2d@earthlink.com> Jon Harrop wrote: ... > Historically, concurrency has been of general interest on single core > machines in the context of operating systems and IO and has become more > important recently due to the ubiquity of web programming. Parallelism was > once only important to computational scientists programming shared-memory > supercomputers and enterprise developers programming distributed-memory > clusters but the advent of multicore machines on the desktop and in the > games console has pushed parallelism into the lime light for ordinary > developers when performance is important. ... Parallelism has also been important, for a long time, to multiprocessor operating system developers. I got my first exposure to parallel programming, in the 1980's, working on NCR's VRX operating system. Patricia From sjmachin at lexicon.net Sun Jun 7 20:32:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 17:32:58 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <407c363b-fe3c-4789-9048-4de79de8ac31@t11g2000vbc.googlegroups.com> On Jun 8, 10:20?am, MRAB wrote: > John Machin wrote: > > On Jun 8, 12:13 am, "R. David Murray" wrote: > >> higer wrote: > >>> My file contains such strings : > >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > >> If those bytes are what is in the file (and it sounds like they are), > >> then the data in your file is not in UTF8 encoding, it is in ASCII > >> encoded as hexidecimal escape codes. > > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > > r"\xe6" by what mechanism in which parallel universe? > > Maybe he means that the file itself is in ASCII. Maybe indeed, but only so because hex escape codes are by design in ASCII. "in ASCII" is redundant ... I can't imagine how the OP parsed "ASCII encoded" given that his native tongue's grammar varies from that of English in several interesting ways :-) From mattleftbody at gmail.com Sun Jun 7 20:37:03 2009 From: mattleftbody at gmail.com (mattleftbody at gmail.com) Date: Sun, 7 Jun 2009 17:37:03 -0700 (PDT) Subject: pythoncom and writing file "summary" info on Windows Message-ID: Hello, I was trying to put together a script that would write things like the Author and Title metadata fields of a file under Windows. I got the win32 extensions installed and found a few things that look like they should work, though I'm not getting the result I would expect. Hopefully someone has worked through this area and can point me in the right direction. so after various imports I try the following: file=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0 , pythoncom.IID_IPropertySetStorage) summ=file.Create(pythoncom.FMTID_SummaryInformation, pythoncom.IID_IPropertySetStorage, storagecon.PROPSETFLAG_DEFAULT, storagecon.STGM_READWRITE|storagecon.STGM_CREATE| storagecon.STGM_SHARE_EXCLUSIVE) everything seems fine so far, until I try and write which doesn't seem to do anything. I tried the following three ways: summ.WriteMultiple((storagecon.PIDSI_AUTHOR, storagecon.PIDSI_TITLE), ('Author', 'Title')) summ.WriteMultiple((4,2 ), ('Author', 'Title')) summ.WritePropertyNames((4,2 ), ('Author', 'Title')) Any advice would be most appreciated! Matt From davea at ieee.org Sun Jun 7 20:41:27 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 07 Jun 2009 20:41:27 -0400 Subject: Keeping console window open In-Reply-To: <791u96F1onh1qU1@mid.individual.net> References: <791rbmF1okia2U1@mid.individual.net> <791u96F1onh1qU1@mid.individual.net> Message-ID: <4A2C5E37.1000108@ieee.org> Fencer wrote: >
Scott > David Daniels wrote: >> To be a trifle more explicit, turn: >> >> ... >> if __name__ == '__main__': >> main() >> >> into: >> ... >> if __name__ == '__main__': >> try: >> main() >> except Exception, why: >> print 'Failed:', why >> import sys, traceback >> traceback.print_tb(sys.exc_info()[2]) >> raw_input('Leaving: ') >> >> Note that building your script like this also allows you to >> open the interpretter, and type: >> import mymodule >> mymodule.main() >> in order to examine how it runs. > > Thanks alot, this was exactly what I was looking for! > >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > >
> Notice also that you'd then move all the imports inside main(), rather than putting them at outer scope. Now some imports, such as sys and os, may want to be at outer scope, but if they don't work,. your system is seriously busted. From robert.kern at gmail.com Sun Jun 7 20:59:12 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Jun 2009 19:59:12 -0500 Subject: Get the class name In-Reply-To: <4a2c2600$0$6277$9b536df3@news.fv.fi> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> <4a2c2600$0$6277$9b536df3@news.fv.fi> Message-ID: On 2009-06-07 15:41, Tuomas Vesterinen wrote: > Kless wrote: >> Is there any way of to get the class name to avoid to have that write >> it? >> >> --------------- >> class Foo: >> super(Foo, self) >> --------------- >> >> >> * Using Py 2.6.2 > > >>> class Foo(object): > ... def cls(self): > ... return self.__class__ > ... > >>> Foo().cls() > You definitely don't want to use that for super(). If you actually have an instance of a subclass of Foo, you will be giving the wrong information. Basically, there is no (sane) way to do what the OP wants. If there were, that information would not be necessary to give to super(). -- 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 davea at ieee.org Sun Jun 7 21:00:32 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 07 Jun 2009 21:00:32 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <4A2C62B0.6080602@ieee.org> Lew wrote: >
Scott > David Daniels wrote: >> the nub of the problem is not on the benchmarks. There is something >> to be said for the good old daays when you looked up the instruction >> timings that you used in a little document for your machine, and could >> know the cost of any loop. We are faster now, but part of the cost of >> that speed is that timing is a black art. > > Those good old days never existed. Those manuals never accounted for > things that affected timing even then, like memory latency or refresh > time. SRAM cache made things worse, since the published timings never > mentioned cache-miss delays. Though memory cache might seem a recent > innovation, it's been around a while. It would be challenging to find > any published timing since the commercialization of computers that > would actually tell the cost of any loop. > > Things got worse when chips like the '86 family acquired multiple > instructions for doing loops, still worse when pre-fetch pipelines > became deeper and wider, absolutely Dark Art due to multi-level memory > caches becoming universal, and > throw-your-hands-up-and-leave-for-the-corner-bar with multiprocessor > NUMA systems. OSes and high-level languages complicate the matter - > you never know how much time slice you'll get or how your source got > compiled or optimized by run-time. > > So the good old days are a matter of degree and self-deception - it > was easier to fool ourselves then that we could at least guess timings > proportionately if not absolutely, but things definitely get more > unpredictable over evolution. > Nonsense. The 6502 with static memory was precisely predictable, and many programmers (working in machine language, naturally) counted on it. Similarly the Novix 4000, when programmed in its native Forth. And previous to that, I worked on several machines (in fact, I wrote the assembler and debugger for two of them) where the only variable was the delay every two milliseconds for dynamic memory refresh. Separate control memory and data memory, and every instruction precisely clocked. No instruction prefetch, no cache memory. What you see is what you get. Would I want to go back there? No. Sub-megaherz clocks with much less happening on each clock means we were operating at way under .01% of present day. From jon at ffconsultancy.com Sun Jun 7 21:39:40 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 02:39:40 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> Message-ID: Ken T. wrote: > On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: >> So the good old days are a matter of degree and self-deception - it was >> easier to fool ourselves then that we could at least guess timings >> proportionately if not absolutely, but things definitely get more >> unpredictable over evolution. > > As I recall I could get exact timings on my 6502 based Commodore 64. The > issues you speak of simply weren't issues. Let's not forget Elite for the 6502 exploiting predictable performance in order to switch graphics modes partway down the vsync! -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From dcest61 at hotmail.com Sun Jun 7 21:42:08 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Mon, 08 Jun 2009 01:42:08 GMT Subject: multi-core software In-Reply-To: <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Lew wrote: >>> Interesting distinction. Would it be fair to compare concurrent >>> programming to the bricks used to build the parallel program's edifice? >> Way too much of a fine distinction. While they are in fact different, >> the point of concurrent programming is to structure programs as a group >> of computations, which can be executed in parallel (however that might >> actually be done depending on how many processors there are). > > No. Concurrent programming is about interleaving computations in order to > reduce latency. Nothing to do with parallelism. Jon, I do concurrent programming all the time, as do most of my peers. Way down on the list of why we do it is the reduction of latency. AHS From pavlovevidence at gmail.com Sun Jun 7 22:13:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 7 Jun 2009 19:13:47 -0700 (PDT) Subject: Get the class name References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <5d7ba12e-d9bd-4fd1-bc18-b99629ee03a1@j12g2000vbl.googlegroups.com> On Jun 7, 1:14?pm, Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > ? ?super(Foo, self) > --------------- > > * Using Py 2.6.2 If you are using emacs you can use the put the following elisp code in your .emacs file, defines a command to automatically insert the a super call with the class and method name filled in: http://code.activestate.com/recipes/522990/ Carl Banks From higerinbeijing at gmail.com Sun Jun 7 22:32:59 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 19:32:59 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> <613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> Message-ID: <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> On Jun 7, 11:25 pm, John Machin wrote: > On Jun 7, 10:55 pm, higer wrote: > > > My file contains such strings : > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > Are you sure? Does that occupy 9 bytes in your file or 36 bytes? > It was saved in a file, so it occupy 36 bytes. If I just use a variable to contain this string, it can certainly work out correct result,but how to get right answer when reading from file. > > > > I want to read the content of this file and transfer it to the > > corresponding gbk code,a kind of Chinese character encode style. > > Everytime I was trying to transfer, it will output the same thing no > > matter which method was used. > > It seems like that when Python reads it, Python will taks '\' as a > > common char and this string at last will be represented as "\\xe6\\x97\ > > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' > > output,but that's not what I want to get. > > > Anyone can help me? > > try this: > > utf8_data = your_data.decode('string-escape') > unicode_data = utf8_data.decode('utf8') > # unicode derived from your sample looks like this ??? is that what > you expected? You are right , the result is ?? which I just expect. If you save the string in a variable, you surely can get the correct result. But it is just a sample, so I give a short string, what if so many characters in a file? > gbk_data = unicode_data.encode('gbk') > I have tried this method which you just told me, but unfortunately it does not work(mess code). > If that "doesn't work", do three things: > (1) give us some unambiguous hard evidence about the contents of your > data: > e.g. # assuming Python 2.x My Python versoin is 2.5.2 > your_data = open('your_file.txt', 'rb').read(36) > print repr(your_data) > print len(your_data) > print your_data.count('\\') > print your_data.count('x') > The result is: '\\xe6\\x97\\xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a' 36 9 9 > (2) show us the source of the script that you used def UTF8ToChnWords(): f = open("123.txt","rb") content=f.read() print repr(content) print len(content) print content.count("\\") print content.count("x") pass if __name__ == '__main__': UTF8ToChnWords() > (3) Tell us what "doesn't work" means in this case It doesn't work because no matter in what way we deal with it we often get 36 bytes string not 9 bytes.Thus, we can not get the correct answer. > > Cheers, > John Thank you very much, higer From higerinbeijing at gmail.com Sun Jun 7 22:36:57 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 19:36:57 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: On Jun 8, 8:20?am, MRAB wrote: > John Machin wrote: > > On Jun 8, 12:13 am, "R. David Murray" wrote: > >> higer wrote: > >>> My file contains such strings : > >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > >> If those bytes are what is in the file (and it sounds like they are), > >> then the data in your file is not in UTF8 encoding, it is in ASCII > >> encoded as hexidecimal escape codes. > > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > > r"\xe6" by what mechanism in which parallel universe? > > Maybe he means that the file itself is in ASCII. Yes,my file itself is in ASCII. From jon at ffconsultancy.com Sun Jun 7 22:42:32 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 03:42:32 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Lew wrote: >>>> Interesting distinction. Would it be fair to compare concurrent >>>> programming to the bricks used to build the parallel program's edifice? >>> Way too much of a fine distinction. While they are in fact different, >>> the point of concurrent programming is to structure programs as a group >>> of computations, which can be executed in parallel (however that might >>> actually be done depending on how many processors there are). >> >> No. Concurrent programming is about interleaving computations in order to >> reduce latency. Nothing to do with parallelism. > > Jon, I do concurrent programming all the time, as do most of my peers. > Way down on the list of why we do it is the reduction of latency. What is higher on the list? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From nowhere at home.com Mon Jun 8 00:28:20 2009 From: nowhere at home.com (Ken T.) Date: 08 Jun 2009 04:28:20 GMT Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> Message-ID: <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> On Mon, 08 Jun 2009 02:39:40 +0100, Jon Harrop wrote: > Ken T. wrote: >> On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: >>> So the good old days are a matter of degree and self-deception - it >>> was easier to fool ourselves then that we could at least guess timings >>> proportionately if not absolutely, but things definitely get more >>> unpredictable over evolution. >> >> As I recall I could get exact timings on my 6502 based Commodore 64. >> The issues you speak of simply weren't issues. > > Let's not forget Elite for the 6502 exploiting predictable performance > in order to switch graphics modes partway down the vsync! That actually didn't require predictable timing. You could tell the video chip to send you an interrupt when it got to a given scan line. I used this myself. Elite was cool though. I wasted many hours playing that game. -- Ken T. http://www.electricsenator.net Duct tape is like the force. It has a light side, and a dark side, and it holds the universe together ... -- Carl Zwanzig From dstanek at dstanek.com Mon Jun 8 01:08:10 2009 From: dstanek at dstanek.com (David Stanek) Date: Mon, 8 Jun 2009 01:08:10 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> Message-ID: On Sun, Jun 7, 2009 at 9:23 AM, Esmail wrote: > Ben Finney wrote: >> >> Esmail writes: >> >>> I am confused by pylint's naming conventions, I don't think the are in >>> tune with Python's style recommendations (PEP 8?) >>> >>> Anyone else think this? >> >> It's hard to know, without examples. Can you give some output of pylint >> that you think doesn't agree with PEP 8? > > Sure, I will next time I have a nice self-contained example. Perhaps not > that > many people are using pylint? I was expecting a bunch of messages either > contradicting my observation or agreeing with it :-) .. but perhaps this > indicates that there's no issue. It is my understanding that it does check for PEP8 names. Even if it doesn't it is really easy to change. If you run 'pylint --generate-rcfile' (i think) it will output the configuration that it is using. You can then save this off and customize it. > > I'll try to come up with a nice short code example in the next few days > to demonstrate what I think the problem is and post it, thanks for the > suggestion. If you didn't have an example handy what prompted you to start this thread? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From rdmurray at bitdance.com Mon Jun 8 01:10:28 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 05:10:28 +0000 (UTC) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: John Machin wrote: > On Jun 8, 12:13?am, "R. David Murray" wrote: > > higer wrote: > > > My file contains such strings : > > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > > > If those bytes are what is in the file (and it sounds like they are), > > then the data in your file is not in UTF8 encoding, it is in ASCII > > encoded as hexidecimal escape codes. > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > r"\xe6" by what mechanism in which parallel universe? Well, you are correct that the OP might have had trouble parsing my English. My English is more or less valid ("[the file] is _in_ ASCII", ie: consists of ASCII characters, "encoded as hexideicmal escape codes", which specifies the encoding used). But better perhaps would have been to just say that the data is encoded as hexidecimal escape sequences. --David From rdmurray at bitdance.com Mon Jun 8 01:16:21 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 05:16:21 +0000 (UTC) Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: Tuomas Vesterinen wrote: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > > > #ifdef python2 > print u'foo', u'bar' > #endif > #ifdef python3 > print('foo', 'bar') > #endif > > > results: > > cpp -E -Dpython2 test_cpp.py > ... > print u'foo', u'bar' > > Any other suggestions? There's a Google Summer of Code project to create a 3to2 processor. That would let you maintain the code in 3.x, and have it automatically translated on demand so that it will run under 2.x (where x goes back to at least 5, I think, but I'm not sure). Of course, it isn't finished yet, so it won't do you any good right at the moment :( -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From ben+python at benfinney.id.au Mon Jun 8 01:34:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Jun 2009 15:34:12 +1000 Subject: pylint naming conventions? References: <87skiekend.fsf@benfinney.id.au> Message-ID: <87my8je1bf.fsf@benfinney.id.au> David Stanek writes: > On Sun, Jun 7, 2009 at 9:23 AM, Esmail wrote: > > I'll try to come up with a nice short code example in the next few > > days to demonstrate what I think the problem is and post it, thanks > > for the suggestion. > > If you didn't have an example handy what prompted you to start this > thread? My understanding of Esmail's original message was that, like many of us on first running ?pylint? against an existing code base, the output is astonishingly verbose and tedious to read. By the above I presume he's being a good forum member and trying to find a minimal example that shows the problem clearly :-) -- \ ?Kill myself? Killing myself is the last thing I'd ever do.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From metolone+gmane at gmail.com Mon Jun 8 01:58:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 7 Jun 2009 22:58:16 -0700 Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com><613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> Message-ID: "higer" wrote in message news:0c786326-1651-42c8-ba39-4679f3558660 at r13g2000vbr.googlegroups.com... > On Jun 7, 11:25 pm, John Machin wrote: >> On Jun 7, 10:55 pm, higer wrote: >> >> > My file contains such strings : >> > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a >> > > >> Are you sure? Does that occupy 9 bytes in your file or 36 bytes? >> > > It was saved in a file, so it occupy 36 bytes. If I just use a > variable to contain this string, it can certainly work out correct > result,but how to get right answer when reading from file. Did you create this file? If it is 36 characters, it contains literal backslash characters, not the 9 bytes that would correctly encode as UTF-8. If you created the file yourself, show us the code. > >> >> >> > I want to read the content of this file and transfer it to the >> > corresponding gbk code,a kind of Chinese character encode style. >> > Everytime I was trying to transfer, it will output the same thing no >> > matter which method was used. >> > It seems like that when Python reads it, Python will taks '\' as a >> > common char and this string at last will be represented as "\\xe6\\x97\ >> > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' >> > output,but that's not what I want to get. >> >> > Anyone can help me? >> >> try this: >> >> utf8_data = your_data.decode('string-escape') >> unicode_data = utf8_data.decode('utf8') >> # unicode derived from your sample looks like this ??? is that what >> you expected? > > You are right , the result is ?? which I just expect. If you save the > string in a variable, you surely can get the correct result. But it is > just a sample, so I give a short string, what if so many characters in > a file? > >> gbk_data = unicode_data.encode('gbk') >> > > I have tried this method which you just told me, but unfortunately it > does not work(mess code). How are you determining this is 'mess code'? How are you viewing the result? You'll need to use a viewer that understands GBK encoding, such as "Chinese Window's Notepad". > > >> If that "doesn't work", do three things: >> (1) give us some unambiguous hard evidence about the contents of your >> data: >> e.g. # assuming Python 2.x > > My Python versoin is 2.5.2 > >> your_data = open('your_file.txt', 'rb').read(36) >> print repr(your_data) >> print len(your_data) >> print your_data.count('\\') >> print your_data.count('x') >> > > The result is: > > '\\xe6\\x97\\xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a' > 36 > 9 > 9 > >> (2) show us the source of the script that you used > > def UTF8ToChnWords(): > f = open("123.txt","rb") > content=f.read() > print repr(content) > print len(content) > print content.count("\\") > print content.count("x") Try: utf8data = content.decode('string-escape') unicodedata = utf8data.decode('utf8') gbkdata = unicodedata.encode('gbk') print len(gbkdata),repr(gbkdata) open("456.txt","wb").write(gbkdata) The print should give: 6 '\xc8\xd5\xc6\xda\xa3\xba' This is correct for GBK encoding. 456.txt should contain the 6 bytes of GBK data. View the file with a program that understand GBK encoding. -Mark From kay at fiber-space.de Mon Jun 8 02:00:29 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sun, 7 Jun 2009 23:00:29 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> Message-ID: <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> On 8 Jun., 00:31, bearophileH... at lycos.com wrote: > ShedSkin (SS) is a beast almost totally different from CPython, SS > compiles an implicitly static subset of Python to C++. So it breaks > most real Python programs, and it doesn't use the Python std lib (it > rebuilds one in C++ or compiled Python), and so on. > SS may be useful for people that don't want to mess with the > intricacies of Cython (ex-Pyrex) and its tricky reference count, to > create compiled python extensions. Don't understand your Cython compliant. The only tricky part of Cython is the doublethink regarding Python types and C types. I attempted once to write a ShedSkin like code transformer from Python to Cython based on type recordings but never found the time for this because I have to work on EasyExtend on all fronts at the same time. Maybe next year or when Unladen Swallow becomes a success - never. The advantage of this approach over ShedSkin was that every valid Cython program is also a Python extension module, so one can advance the translator in small increments and still make continuous progress on the execution speed front. From higerinbeijing at gmail.com Mon Jun 8 02:15:39 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 23:15:39 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com><613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> Message-ID: Thank you Mark, that works. Firstly using 'string-escape' to decode the content is the key point,so I can get the Chinese characters now. Regards, -higer From tim.wintle at teamrubber.com Mon Jun 8 02:48:28 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 08 Jun 2009 07:48:28 +0100 Subject: unladen swallow: python and llvm In-Reply-To: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> References: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> Message-ID: <1244443708.593.27.camel@tim-laptop> On Sun, 2009-06-07 at 16:40 -0600, Brian wrote: > On Fri, Jun 5, 2009 at 3:29 AM, Nick Craig-Wood > wrote: > It is an interesting idea for a number of reasons, the main > one as far > as I'm concerned is that it is more of a port of CPython to a > new > architecture than a complete re-invention of python (like > PyPy / > IronPython / jython) so stands a chance of being merged back > into > CPython. > > Blatant fanboyism. PyPy also has a chance of being merged back into > Python trunk. How? I believe that unladen swallow has already had many of it's optimisations back-ported to CPython, but I can't see how backporting a python interpreter written in python into C is going to be as easy as merging from Unladen swallow, which is (until the llvm part) a branch of CPython. Personally, I think that PyPy is a much better interpreter from a theoretical point of view, and opens up massive possibilities for writing interpreters in general. Unladen Swallow on the other hand is something we can use _now_ - on real work, on real servers. It's a more interesting engineering project, and something that shouldn't require re-writing of existing python code. Tim W > > From rossberg at mpi-sws.org Mon Jun 8 04:05:44 2009 From: rossberg at mpi-sws.org (rossberg at mpi-sws.org) Date: Mon, 8 Jun 2009 01:05:44 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> Message-ID: On Jun 8, 6:28?am, "Ken T." wrote: > > > Let's not forget Elite for the 6502 exploiting predictable performance > > in order to switch graphics modes partway down the vsync! > > That actually didn't require predictable timing. ?You could tell the > video chip to send you an interrupt when it got to a given scan line. ?I > used this myself. ? I don't know what Elite did, but I know for sure that it was a common trick on the Atari ST to switch color palettes or graphics mode at a fixed point *in each single scan line* to get more colors, or display graphics on the screen borders. That required "synchronous programming", i.e. counting clock cycles of machine instructions such that for every point in the program you knew exactly where the electron ray would be. The Atari ST had an M68000 with exactly 8 MHz, which made this possible. There were no caches in those times, and clock cycles were entirely predictable. From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 04:09:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 08:09:36 GMT Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> Message-ID: <023cb998$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: > We factor code > to eliminate redundancy, but that is not always a good idea with an API. > The goal for code factoring is to minimize redundancy. The goal for API > design is having simple parts that are easily learned and can be readily > combined (i.e. the notion of an iterator algebra). Wonderfully said! That has articulated something which I only recently came to appreciate, but couldn't put into words. -- Steven From ben+python at benfinney.id.au Mon Jun 8 04:30:37 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Jun 2009 18:30:37 +1000 Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> Message-ID: <87eitvdt5e.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: > > > We factor code to eliminate redundancy, but that is not always a > > good idea with an API. The goal for code factoring is to minimize > > redundancy. The goal for API design is having simple parts that are > > easily learned and can be readily combined (i.e. the notion of an > > iterator algebra). > > Wonderfully said! That has articulated something which I only recently > came to appreciate, but couldn't put into words. As originally defined by Martin Fowler, re-factoring always means the external behaviour is unchanged . So, there's no such thing as a re-factoring that changes the API. Anything that changes an external attribute of the code is a different kind of transformation, not a re-factoring. -- \ ?Better not take a dog on the space shuttle, because if he | `\ sticks his head out when you're coming home his face might burn | _o__) up.? ?Jack Handey | Ben Finney From piet at cs.uu.nl Mon Jun 8 04:35:34 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 08 Jun 2009 10:35:34 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: By the way, there is a series of articles about concurrency on ACM Queue which may be interesting for those participating in or just following this discussion: http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency Here is one introductory paragraph from one of the articles: Parallel programming poses many new challenges to the developer, one of which is synchronizing concurrent access to shared memory by multiple threads. Programmers have traditionally used locks for synchronization, but lock-based synchronization has well-known pitfalls. Simplistic coarse-grained locking does not scale well, while more sophisticated fine-grained locking risks introducing deadlocks and data races. Furthermore, scalable libraries written using fine-grained locks cannot be easily composed in a way that retains scalability and avoids deadlock and data races. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jkn_gg at nicorp.f9.co.uk Mon Jun 8 04:39:45 2009 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 8 Jun 2009 01:39:45 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> Message-ID: <67e28245-7c52-4bc1-b96a-d7e383e52c33@n8g2000vbb.googlegroups.com> On Jun 8, 9:30?am, Ben Finney wrote: [...] > > As originally defined by Martin Fowler, re-factoring always means the > external behaviour is unchanged . > > So, there's no such thing as a re-factoring that changes the API. > Anything that changes an external attribute of the code is a different > kind of transformation, not a re-factoring. ... and Steven was not calling the two things by the same name. He, and Raymond, were distinguishing between refactoring, and API design. That was their point, I think. Jon N From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 05:44:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 09:44:30 GMT Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> Message-ID: <023ccfd6$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 18:30:37 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: >> >> > We factor code to eliminate redundancy, but that is not always a good >> > idea with an API. The goal for code factoring is to minimize >> > redundancy. The goal for API design is having simple parts that are >> > easily learned and can be readily combined (i.e. the notion of an >> > iterator algebra). >> >> Wonderfully said! That has articulated something which I only recently >> came to appreciate, but couldn't put into words. > > As originally defined by Martin Fowler, re-factoring always means the > external behaviour is unchanged . > > So, there's no such thing as a re-factoring that changes the API. > Anything that changes an external attribute of the code is a different > kind of transformation, not a re-factoring. Possibly a *factoring*, without the "re-", just like Raymond said. Also, keep in mind that when creating a new API, you have no existing API to re-factor. -- Steven From jkn_gg at nicorp.f9.co.uk Mon Jun 8 05:56:19 2009 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 8 Jun 2009 02:56:19 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> <023ccfd6$0$20636$c3e8da3@news.astraweb.com> Message-ID: > Possibly a *factoring*, without the "re-", just like Raymond said. > > Also, keep in mind that when creating a new API, you have no existing API > to re-factor. Exactly. I think this has come up before, but I can't remember the answers; any suggestions for pointer to examples of very well-designed APIs, and maybe some background as to how the design was achieved? Thanks jon N From bearophileHUGS at lycos.com Mon Jun 8 06:13:25 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 03:13:25 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> Message-ID: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Kay Schluehr: >Don't understand your Cython compliant. The only tricky part of Cython is the doublethink regarding Python types and C types. I attempted once to write a ShedSkin like code transformer from Python to Cython based on type recordings but never found the time for this because I have to work on EasyExtend on all fronts at the same time.< I have tried to create a certain data structure with a recent version of Pyrex on Windows, and I have wasted lot of time looking for missing reference count updates that didn't happen, or memory that didn't get freed. The C code produced by ShedSkin is a bit hairy but it's 50 times more readable than the C jungle produced by Pyrex, where I have lost lot of time looking for the missing reference counts, etc. In the end I have used D with Pyd to write an extension in a very quick way. For me writing D code is much simpler than writing Pyrex code. Never used Pyrex ever since. I'm sure lot of people like Cython, but I prefer a more transparent language, that doesn't hide me how it works inside. Bye, bearophile From castironpi at gmail.com Mon Jun 8 06:45:59 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 8 Jun 2009 03:45:59 -0700 (PDT) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> Message-ID: <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> On Jun 7, 6:13?pm, Paul Rubin wrote: > Aaron Brady writes: > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > > Shorter is always better. > > url = url.rstrip('/') + '/' I was joking. Sheesh. From mfmdevine at gmail.com Mon Jun 8 07:14:18 2009 From: mfmdevine at gmail.com (Mark Devine) Date: Mon, 8 Jun 2009 12:14:18 +0100 Subject: urllib2.URLError: error using twill with python Message-ID: <8249b1d00906080414w576cbd8bycf6d57cb17fb355d@mail.gmail.com> Hi I wonder if someone could point me in the right direction. I used the following code to access gmail but I got a urllib2.URLError: error when I ran it. I have included the Traceback import twill, string, os b=twill.commands.get_browser() b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() b.go('http://www.gmail.com') f=b.get_form("1") b.showforms() f['Email']= email f['Passwd'] =password b.clicked(f, f) b.submit() When I run the code I get: Traceback (most recent call last): File "", line 1, in ? File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line 115, in go self._journey('open', u) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line 540, in _journey r = func(*args, **kwargs) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 573, in http_response response = self.parent.error( File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 573, in http_response response = self.parent.error( File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/utils.py", line 455, in http_response "refresh", msg, hdrs) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 180, in open response = urlopen(self, req, data) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 381, in _open 'unknown_open', req) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 1053, in unknown_open raise URLError('unknown url type: %s' % type) urllib2.URLError: Thanks M From ebonak at hotmail.com Mon Jun 8 07:30:00 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 08 Jun 2009 07:30:00 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> Message-ID: <4A2CF638.1000503@hotmail.com> Hi David, David Stanek wrote: > > It is my understanding that it does check for PEP8 names. Even if it doesn't > it is really easy to change. If you run 'pylint --generate-rcfile' (i think) > it will output the configuration that it is using. You can then save this > off and customize it. Thanks, I'll see if I can customize it this way. I looked at it once briefly. >> I'll try to come up with a nice short code example in the next few days >> to demonstrate what I think the problem is and post it, thanks for the >> suggestion. > > If you didn't have an example handy what prompted you to start this thread? :-) I have had number of examples, but they are rather long, so I think it will be better if I can provide a short example with the (rather lengthy pylint) output that shows the problem. I thought lots of people are using pylint and I would hear one way or the other about the name checks (ie people agreeing or telling me I'm way off :) .. in which case perhaps my recollection/reading of PEP 8 is not accurate. Esmail From ebonak at hotmail.com Mon Jun 8 07:32:35 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 08 Jun 2009 07:32:35 -0400 Subject: pylint naming conventions? In-Reply-To: <87my8je1bf.fsf@benfinney.id.au> References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> Message-ID: <4A2CF6D3.5010400@hotmail.com> Ben Finney wrote: > > > My understanding of Esmail's original message was that, like many of us > on first running ?pylint? against an existing code base, the output is > astonishingly verbose and tedious to read. By the above I presume he's > being a good forum member and trying to find a minimal example that > shows the problem clearly :-) Yes, that is my intention .. because the code I was checking was rather long, combined with the long pylint output it would make for a rather big posting. I'm going to go back and re-read PEP 8 and see if I perhaps don't recall the right guidelines since no one else here seems to have had the same observation. Esmail From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 07:58:29 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 11:58:29 GMT Subject: urllib2.URLError: error using twill with python References: Message-ID: <023cef3d$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote: > Hi > I wonder if someone could point me in the right direction. I used the > following code to access gmail but I got a > urllib2.URLError: > error when I ran it. I have included the Traceback > > import twill, string, os > b=twill.commands.get_browser() > b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; > rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() > b.go('http://www.gmail.com') > f=b.get_form("1") > b.showforms() > f['Email']= email > f['Passwd'] =password > b.clicked(f, f) > b.submit() My bet is that the above is not the actual code you have run. I bet that the offending line is actually something like the following: b.go("'http://www.gmail.com") Note that there is a single character difference. Consider the last two lines of the traceback: > raise URLError('unknown url type: %s' % type) > urllib2.URLError: It seems to be saying that the url type is 'http -- note the leading single quote. -- Steven From roland.em0001 at googlemail.com Mon Jun 8 08:00:51 2009 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Mon, 8 Jun 2009 15:00:51 +0300 Subject: 403 error for python webpage In-Reply-To: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> References: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> Message-ID: <42dbeab40906080500o24af293ap634524b87efa2115@mail.gmail.com> 2009/6/7 Daniel > I created a page with a ".py" extension but the browser does not like > it. > Here is what I did: I edited httpd.conf file and added the line: > AddHandler cgi-script .cgi .py > Then I stopped and restarted apache. Next I created a hello world file > as on this page: > http://deron.meranda.us/python/webserving/helloworld.html > I stored the file in htdocs and then went to the corresponding > http://127.0.0.1/python/testhw.py in my browser. But the browser gives > a 403 error. > I am running from internet explorer on windows xp. > -- > http://mail.python.org/mailman/listinfo/python-list > This sounds like an setup problem for Apache + CGI. You should study the Apache logs. Don't know their location in WIN32, in Linux there are some files named "error_log" and also "access_log". Typically, Apache writes the reason for error messages there. BR, Roland -------------- next part -------------- An HTML attachment was scrubbed... URL: From tuomas.vesterinen at iki.fi Mon Jun 8 08:10:35 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Mon, 08 Jun 2009 15:10:35 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: <4a2cffbb$0$24772$9b536df3@news.fv.fi> R. David Murray wrote: > Tuomas Vesterinen wrote: >> I am developing a Python application as a Python2.x and Python3.0 >> version. A common code base would make the work easier. So I thought to >> try a preprosessor. GNU cpp handles this kind of code correct: >> >> >> #ifdef python2 >> print u'foo', u'bar' >> #endif >> #ifdef python3 >> print('foo', 'bar') >> #endif >> >> >> results: >> > cpp -E -Dpython2 test_cpp.py >> ... >> print u'foo', u'bar' >> >> Any other suggestions? > > There's a Google Summer of Code project to create a 3to2 processor. > That would let you maintain the code in 3.x, and have it automatically > translated on demand so that it will run under 2.x (where x goes back > to at least 5, I think, but I'm not sure). > > Of course, it isn't finished yet, so it won't do you any good right at > the moment :( > > -- > R. David Murray http://www.bitdance.com > IT Consulting System Administration Python Programming > I found also a ready made py3to2-tool (test/develop/integrate python 3.0 code natively under robust, software-rich python 2.5 environment) at: http://code.activestate.com/recipes/574436/ It seems so complicated that I don't dare to try before some more experienced people has commented it. TV From tuomas.vesterinen at iki.fi Mon Jun 8 08:11:58 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Mon, 08 Jun 2009 15:11:58 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> <4a2c025a$0$24756$9b536df3@news.fv.fi> Message-ID: <4a2d000e$0$24772$9b536df3@news.fv.fi> Roger Binns wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Tuomas Vesterinen wrote: >> I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the >> other in py3. > > The expectation would be that you only maintain the py2 code and > automatically generate the py3 code on demand using 2to3. > > It is possible to have the same code run under both versions, but not > recommended. As an example I do this for the APSW test suite, mostly > because the test code deliberately explores various corner cases that > 2to3 could not convert (nor should it try!). Here is how I do the whole > Unicode thing: > > if py3: # defined earlier > UPREFIX="" > else: > UPREFIX="u" > > def u(x): # use with raw strings > return eval(UPREFIX+"'''"+x+"'''") > > # Example of use > u(r"\N${BLACK STAR}\u234") > > You can pull similar stunts for bytes (I use buffers in py2), long ints > (needing L suffix in some py2 versions), the next() builtin from py3, > exec syntax differences etc. You can see more details in the first 120 > lines of http://code.google.com/p/apsw/source/browse/apsw/trunk/tests.py > > Roger > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkosTxEACgkQmOOfHg372QS4rQCgl1ymNME2kdHTBUoc7/f2e+W6 > cbMAmwf7mArr7hVA8k/US53JE59ChnIt > =pQ92 > -----END PGP SIGNATURE----- > You have interesting solutions. TV From roland.em0001 at googlemail.com Mon Jun 8 08:25:51 2009 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Mon, 8 Jun 2009 15:25:51 +0300 Subject: can it be shorter? In-Reply-To: <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> Message-ID: <42dbeab40906080525l65c76d1dk5b9fd8929d7af860@mail.gmail.com> 2009/6/8 Aaron Brady > On Jun 7, 6:13 pm, Paul Rubin wrote: > > Aaron Brady writes: > > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > > > > Shorter is always better. > > > > url = url.rstrip('/') + '/' > > I was joking. Sheesh. > -- > http://mail.python.org/mailman/listinfo/python-list > my two cents: a solution based on regex: the pattern replaces all slashes at the end of the string with a single one. The * usage matches also the empty group of slashes (example s2) >>> print s1 aaaaa/ >>> print s2 bbbb >>> re.sub('[/]*$','/', s1) 'aaaaa/' >>> re.sub('[/]*$','/', s2) 'bbbb/' -Roland -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Mon Jun 8 08:44:05 2009 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 8 Jun 2009 05:44:05 -0700 (PDT) Subject: spammers on pypi References: Message-ID: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> On Jun 5, 1:39?pm, joep wrote: > Is there a way to ban spammers from pypi? Can you provide some examples? It's possible that we can apply SpamBayes to PyPI submissions in much the same way that we apply it in other non- mail areas. Thx, Skip Montanaro From xkenneth at gmail.com Mon Jun 8 09:35:07 2009 From: xkenneth at gmail.com (xkenneth) Date: Mon, 8 Jun 2009 06:35:07 -0700 (PDT) Subject: Wrapping LabVIEW and DAQmx Libraries for Python Message-ID: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> All, I've started wrapping the DAQmx and other LabVIEW libraries for python using ctypes. I really like doing some things in python and other in LabVIEW, so I'd like to have the same functionality available for both. I've hosted the tiniest bit of code (mostly just proof of concept) on github. Let me know if anyone else would be interested in this. I'd love some help hashing it out. - Ken http://github.com/erdosmiller/pydaqmx/tree/master From pruebauno at latinmail.com Mon Jun 8 10:00:08 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 8 Jun 2009 07:00:08 -0700 (PDT) Subject: interval arithmetic libraries References: <410afd39-e1e0-403d-aa23-e1e85742351c@z14g2000yqa.googlegroups.com> Message-ID: On Jun 6, 8:15?am, srepmub wrote: > Hi all, > > I'm looking for libraries that allow one to calculate with sets of > (date) intervals. So for example, I'd like to be able to calculate the > overlap between two sets of intervals, the union etc. Preferrably, > this works with datetime objects, is written in pure Python, and has > reasonably good (algorithmic) performance. The neatest library I've > found so far is this one: > > http://members.cox.net/apoco/interval/ > > From an API standpoint, it looks rather nice, but the performance > could be better (for example, calculating an overlap now involves > looping quadratically over both interval sets), and it doesn't work > fully with datetime objects (Inf doesn't work). > > Thanks for any pointers, > Mark Dufour. > (author of Shedskin, an experimental (restricted-)Python-to-C++ > compiler,http://shedskin.googlecode.com) For some pointers look at this thread where I posted a similar question: http://groups.google.com/group/comp.lang.python/browse_frm/thread/1a1d2ed9d05d11d0/56684b795fc527cc#56684b795fc527cc I am surprised that libraries to do that are not more common. I guess everybody rolls his own. From skip at pobox.com Mon Jun 8 10:03:50 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 8 Jun 2009 09:03:50 -0500 Subject: unladen swallow: python and llvm In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <18989.6726.518491.972526@montanaro.dyndns.org> bearophile> I'm sure lot of people like Cython, but I prefer a more bearophile> transparent language, that doesn't hide me how it works bearophile> inside. Why not just write extension modules in C then? -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From paul at boddie.org.uk Mon Jun 8 10:07:10 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 8 Jun 2009 07:07:10 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <17551522-51af-49d1-ae8a-5f80624e7773@j20g2000vbp.googlegroups.com> On 8 Jun, 12:13, bearophileH... at lycos.com wrote: > > The C code produced by ShedSkin is a bit hairy but it's 50 times more > readable than the C jungle produced by Pyrex, where I have lost lot of > time looking for the missing reference counts, etc. The C++ code produced by Shed Skin can actually provide an explicit, yet accurate summary of the implicit type semantics present in a program, in the sense that appropriate parameterisations of template classes may be chosen for the C++ program in order to model the data structures used in the original program. The analysis required to achieve this is actually rather difficult, and it's understandable that in languages like OCaml that are widely associated with type inference, one is encouraged (if not required) to describe one's types in advance. People who claim (or imply) that Shed Skin has removed all the dynamicity from Python need to look at how much work the tool still needs to do even with all the restrictions imposed on input programs. Paul From pw at panix.com Mon Jun 8 10:33:36 2009 From: pw at panix.com (Paul Wallich) Date: Mon, 08 Jun 2009 10:33:36 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> Message-ID: rossberg at mpi-sws.org wrote: > On Jun 8, 6:28 am, "Ken T." wrote: >>> Let's not forget Elite for the 6502 exploiting predictable performance >>> in order to switch graphics modes partway down the vsync! >> That actually didn't require predictable timing. You could tell the >> video chip to send you an interrupt when it got to a given scan line. I >> used this myself. > > I don't know what Elite did, but I know for sure that it was a common > trick on the Atari ST to switch color palettes or graphics mode at a > fixed point *in each single scan line* to get more colors, or display > graphics on the screen borders. That required "synchronous > programming", i.e. counting clock cycles of machine instructions such > that for every point in the program you knew exactly where the > electron ray would be. > > The Atari ST had an M68000 with exactly 8 MHz, which made this > possible. There were no caches in those times, and clock cycles were > entirely predictable. The usual trick for these machines was an exact multiple of the NTSC "color clock", which was approx 3.58 MHz. The 8-bit atari video games and home computers all used this technique, as did the C-64/128. 68000-based machines (such as the ST and the Amiga) could not only exploit that synchrony, they could also (this was the days before memory wall) exploit the fact that a 680x0 typically accessed memory only once every 4 clock cycles to do DMA from the same memory when the CPU wasn't using it. High display resolutions would lock the processor out of RAM except during blanking intervals. (Talk about contention and hot spots.) Figuring out how to reuse resources most effectively was pretty much the same as the register-allocation problem for compilers, and was sometimes solved using the same kinds of graph-coloring algorithms... From youssef_edward3000 at yahoo.com Mon Jun 8 10:38:12 2009 From: youssef_edward3000 at yahoo.com (youssef_edward3000 at yahoo.com) Date: Mon, 8 Jun 2009 07:38:12 -0700 (PDT) Subject: 10 Easy Steps to Speed Up Your Computer - Without Upgrading Message-ID: <7204841b-c2f3-4d90-8a5d-76fcf3ca36c3@r16g2000vbn.googlegroups.com> It seems that the longer you own your computer, the slower it gets! A lot of people will keep their computer until it gets so slow that they feel they need a newer, faster model. Some feel like the reason it is getting slower is because it is getting older, when that is just not the case. Your computer should run just as fast as the day you brought it home if you follow these 10 Easy Steps to Speed Up Your Computer. 1. Empty the Temp directory regularly. After a short while, the temp directory fills up with hundreds of temp files that always get scanned over when Windows starts up and when programs launch. This slows everything down immensely. Rule of thumb for Temp Files: If you dont have any programs open (and nothing minimized in the bar below), then you shouldnt have ANY temp files in your temp directory. If you do, delete them. To delete Temp files, make sure NO programs are open, and a. In Windows 95, 98 or Me, go to C:WindowsTemp and delete everything inside the Temp folder. b. In Windows 2000 or XP, it is a little trickier. First, make sure that you can see hidden folders. Double-click My Computer. Click on the Tools pull-down menu, and then on Folder Options. Click on the View tab. Scroll down and click on Show Hidden Files and Folders. Click Ok. Now you can go to the C:Documents and SettingsAdministratorLocal SettingsTemp folder. Delete everything here. 2. Empty the Temporary Internet Files regularly. To empty Temporary Internet Files, go to your Control Panel and double-click the Internet Options icon. Choose to Delete Cookies, and to Delete Files. This will clear all of your Temporary Internet Files. 3. Check your hard disks for problems. a. For Windows 95, 98, or Me, double-click My Computer. Right-click the C-drive and click on Properties. Click on the Tools tab and choose to check the computer for problems. If you choose to do a Thorough Scan, this will do the hardware check for physical disk damage or sector damage. Choose to fix any errors it finds. b. For Windows 2000 and XP, double-click My Computer. Right-click the C-drive and click Properties. Click on the Tools tab and choose to check the computer for problems. Click on Check Now. You will then have two check boxes. The top option is for the file check, and the second option is for the hardware (physical disk) check. Check either one, or both. At least check the top one. Hit ok, and reboot. This may take some time, but let it run. 4. An even more thorough disk check, would be to use a 3rd party utility. One of my favorites is TuneUp Utilities 2004. It does cost $39.99, but they do offer a FREE download trial of 15 days. This program does a really good job of fixing software and physical hard drive problems. It also tunes up your system for increased speed, and streamlines your operating system for peak performance. Download it HERE... http://www.lapeertechgroup.com/downloads.asp 5. Or, you can do a few of the performance tweaks yourself, if you have Windows XP. By default, EVERYTHING is turned on in Windows XP. It isnt very streamlined for performance, but rather for appearance. You can turn off a few of the unnecessary features, and Windows will still work just fine, and maybe a little faster. To do this, right-click on My Computer and click on Properties. Click on the Advanced tab. Under the Performance section, click on the Settings button. On the Visual Effects tab, you will see a list of check boxes. By default, these are all on. You really dont need any of them for Windows to run. Go through the check boxes one by one, and determine which ones you can and cant live without. 6. Turn off Active Desktop. Active Desktop turns your desktop into a web page, and allows you to have things like a real-time calendar, and up-to-the-minute weather or stocks. These are nice, but really slow down your computer. And even if you dont use Active Desktop for anything, just having it active can cause a performance decrease. Turn it off. a. In Windows 95, 98 and Me, right-click on the desktop and in the pop- up menu, choose Active Desktop. Inside that option, uncheck Active Desktop. If there is no check next to it, then it isnt on. Dont choose it. Instead, just click the desktop again to get out of the menu. b. In Windows 2000, right-click on the desktop and in the pop-up menu, choose Active Desktop. Inside that option, uncheck Show Web Content. Again, if there is no check next to it, then it is not on. Do not check it. c. In Windows XP, right-click on the desktop and in the pop-up menu, choose Properties. On the Desktop tab, choose Customize Desktop. Now, on the Web tab, make sure that there are no websites chosen here. If there arent any, then Active Desktop is not on. Cancel and go back to the desktop. 7. Install and run a good AntiVirus program to keep out viruses that can take over your system. One of my favorites is AVG. It is not only a really good AntiVirus program, but it is also FREE! If you dont have any AntiVirus software on your computer, get AVG AntiVirus NOW by downloading HERE... http://www.lapeertechgroup.com/downloads.asp 8. Get rid of Spyware. A lot of computer users have Spyware and dont even know they have it, much less how to get rid of it. If your computer has been taking you to websites that you dont want to go to, or if you get pop-ups when you arent even on the Internet, or if your computer has been running extremely slowly lately, for no reason, you probably have Spyware. On all of the computers that I setup, I install two different AntiSpyware programs: AdAware SE and SpyBot. These two programs are highly recommended by TechTV (G4) and other computer authorities (including my own research on Spyware) and work very well together. They compliment each other and catch Spyware that the other misses, but together, do a very good job. Get SpyBot HERE... http://www.lapeertechgroup.com/downloads.asp. Download all updates and run the Immunize option a couple of times. AdAware SE does a good job when you keep up on the updates and manually scan your system with AdAware. Get it HERE... http://www.lapeertechgroup.com/downloads.asp In some cases, when the Spyware has become too entwined into your system, even a computer repair technician cant get rid of the Spyware. At this point, it is better to just backup only what you need and have the operating system reinstalled. Believe me, when your computer gets to this point, you dont want to just put a band-aid on it. Just start from scratch with a clean system. Its the best way to go. 9. Streamline MSCONFIG. One thing that really causes a HUGE performance decrease is to have unnecessary programs running in the background. Some of these programs can be seen in your System Tray (located next to the clock). These are tiny programs that are robbing you of memory and processing power. Some of them you need, while most you dont. Some of the programs you DONT need are printer icons, CD burning icons, shortcuts to programs (such as video settings), AOL, any Instant Messaging Programs, etc. Just because these programs arent always running, doesnt mean that you still cant print, burn CDs or Instant Message. They can all be run from a shortcut. You can use a utility, called MSCONFIG, to turn OFF unnecessary Start Up items. a. In Windows 98, Me, and XP, click on StartRun and type msconfig. Click on the Startup tab. This is a list of everything that is running in the background, some of which show up in the System Tray. Now, be careful, some of these you do need. Some items to keep are Ctfmon.exe (XP), Scan Registry (Win98, Me), Task Monitor (Win98, Me), System Tray (Win98, Me), LoadPowerProfile (Win98, Me), Rundll.32, any AntiVirus programs (such as McAfee, Norton, or AVG). Others, you can uncheck, such as NeroCheck, ypager, qttask, AOL, and any other Instant Messaging programs, or printing programs. Remember, if something doesnt work, because you turned it off, it can always be turned back on. You just have to reboot every time you make a change here. But, as you uncheck the unnecessary programs that run in the background, you will see that Windows loads much faster, that there are less icons in the System Tray, and that your system is much more snappy and quick to respond. Read more about computers at http://tips-made-easy.info/computer From youssef_edward3000 at yahoo.com Mon Jun 8 10:49:42 2009 From: youssef_edward3000 at yahoo.com (youssef_edward3000 at yahoo.com) Date: Mon, 8 Jun 2009 07:49:42 -0700 (PDT) Subject: Career Track: Computer Programmer Message-ID: <46355271-cd9d-4095-886c-01077360c95f@k20g2000vbp.googlegroups.com> Roles and Responsibilities : The primary role of a Computer Programmer is to write programs according to the instructions determined primarily by computer software engineers and systems analysts. In a nutshell, Computer Programmers are the ones that take the completed designs and convert them into the instructions that the computer can actually follow. The instructions are coded into a programming language. In some cases, programmers are also expected to know platform specific languages used in database programming. Many programmers at the enterprise level are also expected to know platform-specific languages used in database programming. Responsibilities include updating; repairing, modifying and expanding existing programs as well as running tests to authenticate that the program will produce the desired outcome. Applications Programmers are the ones that actually write programs to handle very specific jobs, revise existing software or customize generic applications while Systems Programmers write programs to maintain and control computer systems software such as operating systems, database and/or networked systems. In some smaller organizations, the programmers may also be responsible for systems analysis and the actual programming. In many cases, however, technology is replacing the need to write basic code which doesn't bode well for those considering entering the field. According to the U.S. Department of Labor, however, the "demand for programmers with strong object-oriented programming capabilities and technical specialization in areas such as client/server programming, wireless applications, multimedia technology, and graphic user interface (GUI) should arise from the expansion of intranets, extranets, and Internet applications. Programmers also will be needed to create and maintain expert systems and embed these technologies in more products. Finally, growing emphasis on cyber-security will lead to increased demand for programmers who are familiar with digital security issues and skilled in using appropriate security technology." Advancement Opportunities : The advancement opportunities for computer Programmers are many and usually start with a promotion to a Lead Programmer. A Lead Programmer position will more than likely include supervisory duties. System programming is usually the next career step for Computer Programmers who have completed systems software courses. Programmer Analysts and Systems Analysts are also logical steps. Many programmers are also finding that independent contracting and consulting gives them the freedom to pick and choose their projects. Advancement Opportunities : The advancement opportunities for computer Programmers are many and usually start with a promotion to a Lead Programmer. A Lead Programmer position will more than likely include supervisory duties. System programming is usually the next career step for Computer Programmers who have completed systems software courses. Programmer Analysts and Systems Analysts are also logical steps. Many programmers are also finding that independent contracting and consulting gives them the freedom to pick and choose their projects. Educational Requirements : Although required skills and training will vary dependent upon the position and industry in which you're working, the demand for skill sets is even more driven by technological changes. In some positions, graduate degrees may be required. While traditional language knowledge is still important, C++ and Java are the programming languages of choice. GUI and systems programming skills are also sought after. In addition, general business skills will be an asset in any organization. Systems programmers usually need a 4-year degree in computer science and extensive knowledge of a variety of operating systems. They are usually also expected to be proficient in database systems such as DB2, Sybase and/or Oracle. Salary Potential : (As reported by the U.S. Dept. of Labor) Position Salary Range (2003) Median Average Earnings $60.290 Starting salary for graduates with B.A. in Computer Programming $45,558 Salary range for Applications Development Programmers $51,500 - $80,500 Salary range for Software Developers $55,000 - $87,750 Salary range for Mainframe Programmers $53,250 - $68,750 for more information about programming and computers visit http://tips-made-easy.info/computer From jeanmichel at sequans.com Mon Jun 8 10:50:43 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Jun 2009 16:50:43 +0200 Subject: can it be shorter? In-Reply-To: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <4A2D2543.4020805@sequans.com> Aaron Brady wrote: > Shorter is always better. > > url+= { '/': '' }.get( url[ -1 ], '/' ) Why bother with spaces or 3 letter-wide token, check this :o) : x+={'/':''}.get(x[-1],'/') Apart from joking, the following proposed solution is by **far** the one I prefer > if not url.endswith('/'): > url += '/' Maybe not the shorter, but the most concise and clear to me. Jean-Michel From usernet at ilthio.net Mon Jun 8 11:12:57 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 08 Jun 2009 15:12:57 GMT Subject: GD Library References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: On 2009-06-08, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? GD library has a Python binding: http://www.libgd.org/Main_Page From xahlee at gmail.com Mon Jun 8 11:13:37 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 8 Jun 2009 08:13:37 -0700 (PDT) Subject: is there python image lib that does imagemagick? Message-ID: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> is there a python image library that does pretty much what imagemagick does? all i need is for converting png/jpg, and scaling images. No need other fancy things imagemagick does. i know there's a python wrapper for imagemagick, but i need independent ones that doesn't require shell calls. Basically i have a python script that works in os x that process a dir of html files and generate thumbnails. I'm porting to Windows and wish to get rid of imagemagick dependence. Thanks. Xah ? http://xahlee.org/ ? From usernet at ilthio.net Mon Jun 8 11:16:18 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 08 Jun 2009 15:16:18 GMT Subject: PIL Python Imaging Library References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <6X9Xl.20875$8_3.20375@flpi147.ffdc.sbc.com> On 2009-06-08, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? http://www.pythonware.com/products/pil/ From jan.persson at gmail.com Mon Jun 8 11:18:48 2009 From: jan.persson at gmail.com (jpersson) Date: Mon, 8 Jun 2009 08:18:48 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken References: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Message-ID: <8238ec2e-5e25-40e4-9f64-1f9baf089ec2@z19g2000vbz.googlegroups.com> Thanks for the help. I will let the community know as soon as I have salvaged a working copy. Cheers //Jan Persson On 7 Juni, 23:06, S?ren - Peng - Pedersen wrote: > I think what you are looking for can be found at: > > http://www.google.com/codesearch/p?hl=en#RncWxgazS6A/pysync-2.24/test... > orhttp://shortlink.dk/58664133 > > I am not affiliated with the project in any way, and I can't find a > way to download the entire thing in one go. So if you do salvage a > working copy please let me (and the rest of the community) know. > > //S?ren - Peng - Pedersen From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 11:22:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 15:22:57 GMT Subject: is there python image lib that does imagemagick? References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <023d1f27$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 08:13:37 -0700, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? Python Imaging Library (PIL). http://pypi.python.org/pypi/PIL/1.1.6 -- Steven From gherron at islandtraining.com Mon Jun 8 11:33:26 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Jun 2009 08:33:26 -0700 Subject: Get the class name In-Reply-To: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <4A2D2F46.8030304@islandtraining.com> Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > super(Foo, self) > --------------- > > > * Using Py 2.6.2 > The question does not make sense: "to have WHAT write WHAT", and the code is wrong: the call to super fails But even so, perhaps this will answer your question >>> class Foo: ... pass ... >>> print Foo.__name__ Foo >>> c = Foo >>> print c.__name__ Foo >>> ob = Foo() >>> print ob.__class__.__name__ Foo Gary Herron From python at mrabarnett.plus.com Mon Jun 8 11:50:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 16:50:12 +0100 Subject: can it be shorter? In-Reply-To: <4A2D2543.4020805@sequans.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <4A2D2543.4020805@sequans.com> Message-ID: <4A2D3334.3020708@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Aaron Brady wrote: >> Shorter is always better. >> url+= { '/': '' }.get( url[ -1 ], '/' ) > > Why bother with spaces or 3 letter-wide token, check this :o) : > x+={'/':''}.get(x[-1],'/') > Even shorter: x+='/'*(x[-1]!='/') > Apart from joking, the following proposed solution is by **far** the one > I prefer > >> if not url.endswith('/'): >> url += '/' > > Maybe not the shorter, but the most concise and clear to me. > Definitely. From orsenthil at gmail.com Mon Jun 8 12:07:49 2009 From: orsenthil at gmail.com (Phoe6) Date: Mon, 8 Jun 2009 09:07:49 -0700 (PDT) Subject: problems while using pexpect: pexcept.TIMEOUT always Message-ID: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> I have been trying to use pexpect and I am failing with pexpect.TIMEOUT for all my attempts. In order to troubleshoot, I decided to go with simplest possible one. Here is my ssh to localhost: [21:29:14 senthil]$ssh localhost -l senthil senthil at localhost's password: senthil at ubuntu:~$ And here is my pexpect script: http://paste.pocoo.org/show/121788/ And the output I get is: True None None Traceback (most recent call last): File "4.py", line 17, in print child.read() File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 858, in read self.expect (self.delimiter) # delimiter default is EOF File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1311, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1325, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1409, in expect_loop raise TIMEOUT (str(e) + '\n' + str(self)) pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). Complete Traceback is here: http://paste.pocoo.org/show/121790/ Can someone help me what I am doing wrong here? Why is not working for such a simple thing as ssh to my localhost.? I am getting the same problem while trying to login to remote host also. Thanks, Senthil From francesco.pietra at accademialucchese.it Mon Jun 8 12:13:50 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Mon, 8 Jun 2009 18:13:50 +0200 Subject: Extract value and average Message-ID: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 Density = 0.9896 Ewald error estimate: 0.8252E-05 (in attachment what surely is a correct reproduction of columns) I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. Thanks for giving a possible attack francesco pietra -------------- next part -------------- NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 Density = 0.9896 Ewald error estimate: 0.8252E-05 From deets at nospam.web.de Mon Jun 8 12:15:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Jun 2009 18:15:07 +0200 Subject: pyc-files contains absolute paths, is this a bug ? References: Message-ID: <794rinF1pb3g4U1@mid.uni-berlin.de> Stef Mientki wrote: > hello, > > AFAIK I read that pyc files can be transferred to other systems. > I finally got a windows executable working through py2exe, > but still have some troubles, moving the directory around. > > I use Python 2.5.2. > I use py2exe to make a distro > I can unpack the distro, on a clean computer, anywhere where I like, and > it runs fine. > > Now when I've run it once, > I move the subdirectory to another location, > at it doesn't run. > > Looking with a hex editor into some pyc-files, > I see absolute paths to the old directory. It is normal, because they refer to the location of the source-files, which are needed for stacktraces (or at least something like that) But execution itself is independent from this. > Is this normal, > or am I doing something completely wrong ? Dunno anything about py2exe, but it sure sounds a bit awkward what you do - changing locations of files after installation is calling for trouble in lots of software. But I might not have understood what you actually did - and "doesn't" run isn't helping much in that regard..... Diez From python at mrabarnett.plus.com Mon Jun 8 12:21:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 17:21:38 +0100 Subject: Extract value and average In-Reply-To: References: Message-ID: <4A2D3A92.6080908@mrabarnett.plus.com> Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 > Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 > BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 > 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 > EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 > EAMBER (non-restraint) = -176251.1698 > EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 > Density = 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack > The first thing that comes to mind is a regular expression to extract the DIHED values from the file contents, something like: pattern = re.compile(r'DIHED\s+=\s+(\d+\.\d+)') From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 12:29:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 16:29:12 GMT Subject: Extract value and average References: Message-ID: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. ??? > However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = > 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = > -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED > = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 > VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = > 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = > -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME > = 669299.5681 > Density = > 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack Assuming no DIHED value will ever be split over two lines: data = open(filename) values = [] for line in data: if line and line.strip(): # ignore blanks words = line.strip().split() try: i = words.index("DIHED") except IndexError: continue values.append(float(words[i+2])) mean = sum(values)/len(values) should do the job. -- Steven From python.list at tim.thechases.com Mon Jun 8 12:36:52 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Jun 2009 11:36:52 -0500 Subject: Extract value and average In-Reply-To: References: Message-ID: <4A2D3E24.2060302@tim.thechases.com> > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0 for line in file('file.txt'): m = find_dihed_re.search(line) if m: str_value = m.group(1) try: f = float(str_value) total += f count += 1 except: print "Not a float: %s" % str_value print "Total:", total print "Count:", count if count: print "Average:", total/count If you want a general parser for the file, it takes a bit more work. -tkc From python at mrabarnett.plus.com Mon Jun 8 12:50:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 17:50:15 +0100 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: <4A2D4147.9060104@mrabarnett.plus.com> Steven D'Aprano wrote: > On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > >> I come 'naked', which is unusual and unfair. > > ??? > >> However, I find it >> difficult to give a correct start. The files consist, among other >> things, of a huge number of blocks of the type >> >> >> NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = >> 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = >> -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED >> = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 >> VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = >> 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = >> -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME >> = 669299.5681 >> Density = >> 0.9896 >> Ewald error estimate: 0.8252E-05 >> >> >> >> (in attachment what surely is a correct reproduction of columns) >> >> I would like to extract values corresponding to variable DIHED (here >> 4660.1650) and getting also the mean value from all DIHED. >> >> Thanks for giving a possible attack > > > Assuming no DIHED value will ever be split over two lines: > > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() > try: > i = words.index("DIHED") > except IndexError: > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) > > > should do the job. > str.index raises ValueError, not IndexError. Anyway, your code could be shortened slightly: data = open(filename) values = [] for line in data: words = line.split() try: i = words.index("DIHED") values.append(float(words[i + 2])) except ValueError: pass mean = sum(values) / len(values) From dstanek at dstanek.com Mon Jun 8 12:57:24 2009 From: dstanek at dstanek.com (David Stanek) Date: Mon, 8 Jun 2009 12:57:24 -0400 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: On Thu, Jun 4, 2009 at 7:42 PM, Scott David Daniels wrote: > Brian Quinlan wrote: >> >> This is from Python built from the py3k branch: >> ?>>> c = (lambda : i for i in range(11, 16)) >> ?>>> for q in c: >> ... ? ? print(q()) >> ... >> 11 >> 12 >> 13 >> 14 >> 15 >> ?>>> # This is expected >> ?>>> c = (lambda : i for i in range(11, 16)) >> ?>>> d = list(c) >> ?>>> for q in d: >> ... ? ? print(q()) >> ... >> 15 >> 15 >> 15 >> 15 >> 15 >> ?>>> # I was very surprised > > You are entitled to be surprised. ?Then figure out what is going on. > Hint: it is the moral equivalent of what is happening here: > > ? ?>>> c = [] > ? ?>>> for i in range(11, 16): > ? ? ? ? ? ?c.append(lambda: i) > > ? ?>>> i = 'Surprise!' > ? ?>>> print([f() for f in c]) > ? ?['Surprise!', 'Surprise!', 'Surprise!', 'Surprise!', 'Surprise!'] > > ? ?>>> i = 0 > ? ?>>> print([f() for f in c]) > ? ?[0, 0, 0, 0, 0] > > The body of your lambda is an un-evaluated expression with a reference, > not an expression evaluated at the time of loading c. ?TO get what you > expected, try this: > > ? ?>>> c = [] > ? ?>>> for i in range(11, 16): > ? ? ? ? ? ?c.append(lambda i=i: i) > > ? ?>>> i = 'Surprise!' > ? ?>>> print([f() for f in c]) > ? ?[11, 12, 13, 14, 15] > > When you evaluate a lambda expression, the default args are evaluated, > but the expression inside the lambda body is not. ?When you apply that > evaluated lambda expression, the expression inside the lambda body is > is evaluated and returned. > Getting around this can be pretty easy: c = (lambda i=i: i for i in range(11, 16)) for q in (list(c)): print(q()) -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From rhodri at wildebst.demon.co.uk Mon Jun 8 12:57:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 08 Jun 2009 17:57:41 +0100 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano wrote: > On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > >> I come 'naked', which is unusual and unfair. > > ??? Yeah, I had to go and scrub my brain out :-) > Assuming no DIHED value will ever be split over two lines: > > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() > try: > i = words.index("DIHED") > except IndexError: Should be ValueError, not IndexError. > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) > > > should do the job. You don't need the second strip(), words = line.split() should be sufficient. (And we're back to the 'naked' bit again...) -- Rhodri James *-* Wildebeeste Herder to the Masses From rdmurray at bitdance.com Mon Jun 8 13:19:30 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:19:30 +0000 (UTC) Subject: problems while using pexpect: pexcept.TIMEOUT always References: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> Message-ID: Phoe6 wrote: > I have been trying to use pexpect and I am failing with > pexpect.TIMEOUT for all my attempts. In order to troubleshoot, I > decided to go with simplest possible one. > [...] > > Can someone help me what I am doing wrong here? > Why is not working for such a simple thing as ssh to my localhost.? I would suggest using the 'setlog' method of child to get more debugging information from pexpect. I've found that the best way to diagnose the source of a timeout. -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From Scott.Daniels at Acm.Org Mon Jun 8 13:39:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 08 Jun 2009 10:39:12 -0700 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > ... > Assuming no DIHED value will ever be split over two lines: > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() words = line.split() # does the same as above > try: > i = words.index("DIHED") > except IndexError: > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) Or similarly (with error checks): values = [] with open('/imports/file.txt') as data: for line in data: parts = line.split(' DIHED ') # assume spaces around DIHED if len(parts) > 1: if len(parts) > 2: # make sure only one DIHED found raise ValueError('Line has DIHED twice: %s' % line) # break the post-DIHED part into '=', , words = parts[1].split(None, 2) values.append(float(tokens[1])) mean = sum(values) / len(values) --Scott David Daniels Scott.Daniels at Acm.Org From orsenthil at gmail.com Mon Jun 8 13:40:54 2009 From: orsenthil at gmail.com (Senthil Kumaran) Date: Mon, 8 Jun 2009 10:40:54 -0700 (PDT) Subject: problems while using pexpect: pexcept.TIMEOUT always References: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> Message-ID: <33656c07-ef56-4865-91ee-e42e8433c43d@37g2000yqp.googlegroups.com> On Jun 8, 10:19?pm, "R. David Murray" wrote: > I would suggest using the 'setlog' method of child to get > more debugging information from pexpect. ?I've found that the > best way to diagnose the source of a timeout. > setlog method seems to be deprecated and 'not allowed' too as the help says. But, I just figured out with help from another forum (bangpypers) that I was not closing the ssh session. so doing child.sendline('logout') and then doing child.read() in my script worked out. Thanks, Senthil From rdmurray at bitdance.com Mon Jun 8 13:41:55 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:41:55 +0000 (UTC) Subject: pylint naming conventions? References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> <4A2CF6D3.5010400@hotmail.com> Message-ID: Esmail wrote: > Ben Finney wrote: > > My understanding of Esmail's original message was that, like many of us > > on first running ?pylint? against an existing code base, the output is > > astonishingly verbose and tedious to read. By the above I presume he's > > being a good forum member and trying to find a minimal example that > > shows the problem clearly :-) > > Yes, that is my intention .. because the code I was checking was rather > long, combined with the long pylint output it would make for a rather > big posting. > > I'm going to go back and re-read PEP 8 and see if I perhaps don't > recall the right guidelines since no one else here seems to have had > the same observation. Well, I for one looked at that long pylint output when I first tried it, and switched to another tool :) (pyflakes...but I don't think it does PEP 8) -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From rdmurray at bitdance.com Mon Jun 8 13:51:19 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:51:19 +0000 (UTC) Subject: Am I doing this the python way? (list of lists + file io) References: Message-ID: Horace Blegg wrote: > So, Example: I'll read in a CSV file (just one, for now.) and store it into > a list. Sometime later, I'll get another CSV file, almost identical/related > to the first. However, a few values might have changed, and there might be a > few new lines (entries) or maybe a few less. I would want to compare the CSV > file I have in my list (in memory) to new CSV file (which I would probably > read into a temporary list). I would then want to track and log the > differences between the two files. After I've figured out what's changed, I > would either update the original CSV file with the new CSV's information, or > completely discard the original and replace it with the new one (whichever > involves less work). Basically, lots of iterating through each entry of each > CSV file and comparing to other information (either hard coded or variable). > > So, to reiterate, are lists what I want to use? Should I be using something > else? (even if that 'something else' only really comes into play when > storing and operating on LOTS of data, I would still love to hear about it!) Given your description, I don't see any reason to prefer any alternate data structure. 1000 small CSV files should fit in a modern computer's memory with no problem...and if it does become an issue, worry about it then. One thought, though: you might want to create a list subclass to hold your data, so that you can put useful-to-you methods on the subclass... -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From smacrae319 at live.ca.invalid Mon Jun 8 14:00:41 2009 From: smacrae319 at live.ca.invalid (Seamus MacRae) Date: Mon, 08 Jun 2009 14:00:41 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Piet van Oostrum wrote: > By the way, there is a series of articles about concurrency on ACM Queue > which may be interesting for those participating in or just following > this discussion: > > http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency > > Here is one introductory paragraph from one of the articles: > > Parallel programming poses many new challenges to the developer, one of > which is synchronizing concurrent access to shared memory by multiple > threads. Programmers have traditionally used locks for synchronization, > but lock-based synchronization has well-known pitfalls. Simplistic > coarse-grained locking does not scale well, while more sophisticated > fine-grained locking risks introducing deadlocks and data races. > Furthermore, scalable libraries written using fine-grained locks cannot > be easily composed in a way that retains scalability and avoids deadlock > and data races. Is that the one about transactional memory? From madigreece at yahoo.gr Mon Jun 8 14:02:02 2009 From: madigreece at yahoo.gr (madigreece at yahoo.gr) Date: Mon, 8 Jun 2009 11:02:02 -0700 (PDT) Subject: error: an integer is required Message-ID: I execute my code in linux environment. My code is: from os import * def insert_text_file(self, strng): t=open("elements_file.txt", "a") t.write(strng) t.close() I'm getting this error: : an integer is required Where is the mistake? Help me, please!! From p.f.moore at gmail.com Mon Jun 8 14:07:25 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 8 Jun 2009 11:07:25 -0700 (PDT) Subject: Is it possible to disable readline in the interactive interpreter? Message-ID: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> I run Python on Windows. I have the (pure Python) pyreadline package installed for (occasional) use by IPython. However, when I use the normal Python interactive prompt, the mere fact that the readline module exists means that it gets used. Is there a way of disabling this? (Preferably by default, rather than on a per-session basis). I don't want to get into usability arguments, but the standard Windows command line history and editing is fine for me, and consistency with other apps is more important in this case than configurability (or any other benefits of readline). And yes, the default behaviour of readline *is* different, in small but irritating ways. Paul. From python.list at tim.thechases.com Mon Jun 8 14:08:16 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Jun 2009 13:08:16 -0500 Subject: Extract value and average In-Reply-To: <4A2D3E24.2060302@tim.thechases.com> References: <4A2D3E24.2060302@tim.thechases.com> Message-ID: <4A2D5390.1070505@tim.thechases.com> Tim Chase wrote: >> I would like to extract values corresponding to variable DIHED (here >> 4660.1650) and getting also the mean value from all DIHED. > > To just pull the DIHED values, you can use this: > > import re > find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) > total = count = 0 > for line in file('file.txt'): > m = find_dihed_re.search(line) > if m: > str_value = m.group(1) > try: > f = float(str_value) > total += f > count += 1 > except: > print "Not a float: %s" % str_value > print "Total:", total > print "Count:", count > if count: > print "Average:", total/count > > If you want a general parser for the file, it takes a bit more work. Just because I was a little bored: import re pair_re = re.compile(r'\b([^=:]+)\s*[=:]\s*([-.e\d]+)', re.I) def builder(fname='file.txt'): thing = {} for line in file(fname): if not line.strip(): continue line = line.upper() if 'NSTEP' in line: # 1 # it's a new thing # 1 if thing: # 1 yield thing # 1 thing = {} # 1 thing.update(dict( (k.strip(), float(v)) for k,v in pair_re.findall(line) )) #if 'EWALD' in line: # 2 # # it's a new thing # 2 # if thing: # 2 # yield thing # 2 # thing = {} # 2 if thing: yield thing # average the various values to demo total = count = 0 for thing in builder(): total += thing.get('DIHED', 0) count += 1 print "Total:", total print "Count:", count if count: print "Average:", total/count This makes a more generic parser (comment/uncomment the corresponding "# 1" or "# 2" code based on whether a new block is found by a first line containing "NSTEP" or a last line containing "EWALD"). This yields a dictionary for each item in the input file. You can pull out whichever value(s) you want to manipulate. -tkc From python at mrabarnett.plus.com Mon Jun 8 14:26:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 19:26:23 +0100 Subject: error: an integer is required In-Reply-To: References: Message-ID: <4A2D57CF.6010109@mrabarnett.plus.com> madigreece at yahoo.gr wrote: > I execute my code in linux environment. > My code is: > > from os import * > > def insert_text_file(self, strng): > t=open("elements_file.txt", "a") > t.write(strng) > t.close() > > I'm getting this error: > > : an integer is required > > Where is the mistake? > Help me, please!! The os module has a function called 'open'. When you imported all of the os module you hid the builtin 'open' with the one in the os module. Wildcarded imports are generally not recommended for this reason. Just use "import os" and then prefix with "os." wherever it's needed. From mail at timgolden.me.uk Mon Jun 8 14:31:01 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Jun 2009 19:31:01 +0100 Subject: Is it possible to disable readline in the interactive interpreter? In-Reply-To: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: <4A2D58E5.7040405@timgolden.me.uk> Paul Moore wrote: > I run Python on Windows. I have the (pure Python) pyreadline package > installed for (occasional) use by IPython. However, when I use the > normal Python interactive prompt, the mere fact that the readline > module exists means that it gets used. I used to get round this by installing pyreadline within the iPython package, so it only appeared to exist from that app's POV. TJG From lczancanella at gmail.com Mon Jun 8 14:43:56 2009 From: lczancanella at gmail.com (lczancanella) Date: Mon, 8 Jun 2009 11:43:56 -0700 (PDT) Subject: MD5 hash of object Message-ID: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Hi, in hashlib the hash methods have as parameters just string, i want to know how can i digest an object to get a md5 hash of them. Thankz Luiz From tjreedy at udel.edu Mon Jun 8 14:46:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Jun 2009 14:46:07 -0400 Subject: error: an integer is required In-Reply-To: References: Message-ID: madigreece at yahoo.gr wrote: > I execute my code in linux environment. > My code is: > > from os import * > > def insert_text_file(self, strng): > t=open("elements_file.txt", "a") > t.write(strng) > t.close() > > I'm getting this error: > > : an integer is required > > Where is the mistake? > Help me, please!! Tell us the Python version and give the *full* traceback message, not just the last line. I am pretty sure you also left out an important part of the code you executed to get that message. tjr From p.f.moore at gmail.com Mon Jun 8 14:48:43 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 8 Jun 2009 11:48:43 -0700 (PDT) Subject: Is it possible to disable readline in the interactive interpreter? References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: On Jun 8, 7:31?pm, Tim Golden wrote: > Paul Moore wrote: > > I run Python on Windows. I have the (pure Python) pyreadline package > > installed for (occasional) use by IPython. However, when I use the > > normal Python interactive prompt, the mere fact that the readline > > module exists means that it gets used. > > I used to get round this by installing pyreadline within the > iPython package, so it only appeared to exist from that > app's POV. Interesting approach - I hadn't thought of that. I might give that a try. Nevertheless, if it isn't possible to disable readline, I may just raise a bug report as well... Paul. From theller at python.net Mon Jun 8 15:10:30 2009 From: theller at python.net (Thomas Heller) Date: Mon, 08 Jun 2009 21:10:30 +0200 Subject: Is it possible to disable readline in the interactive interpreter? In-Reply-To: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: <795617F1oa81gU1@mid.individual.net> Paul Moore schrieb: > I run Python on Windows. I have the (pure Python) pyreadline package > installed for (occasional) use by IPython. However, when I use the > normal Python interactive prompt, the mere fact that the readline > module exists means that it gets used. > > Is there a way of disabling this? (Preferably by default, rather than > on a per-session basis). > > I don't want to get into usability arguments, but the standard Windows > command line history and editing is fine for me, and consistency with > other apps is more important in this case than configurability (or any > other benefits of readline). And yes, the default behaviour of > readline *is* different, in small but irritating ways. This has also disturbed me. However, tab-completion is really nice sometimes. I wonder if there is a way to to configure readline to that it behaves on 'up' or 'down' keypresses in the same way as the windows console. Does someone have such a configuration? Thomas From robert.kern at gmail.com Mon Jun 8 15:14:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Jun 2009 14:14:32 -0500 Subject: spammers on pypi In-Reply-To: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: On 2009-06-08 07:44, Skip Montanaro wrote: > On Jun 5, 1:39 pm, joep wrote: >> Is there a way to ban spammers from pypi? > > Can you provide some examples? It's possible that we can apply > SpamBayes > to PyPI submissions in much the same way that we apply it in other non- > mail > areas. I suspect he might talking about all of the "1.0.1" releases of projects on June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" (obfuscated to avoid helping them out). Most of them appear to be removed, now. These chuckleheads even have a blog post complaining about it. I can collect a list from my Cheeseshop RSS history if you like. I don't think a SpamBayes approach will work for this particular guy. It's not like completely fake metadata was uploaded with links to spam sites. There actually is Python code for some of them. Maybe even some that is marginally useful. But only marginally (Linked Lists for Python? Really?). All of the code appears to use their proprietary, unreleased package. -- 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 bearophileHUGS at lycos.com Mon Jun 8 15:28:09 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 12:28:09 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <6272ad2e-bce4-48ad-a729-80400c59e929@z9g2000yqi.googlegroups.com> s... at pobox.com: > Why not just write extension modules in C then? In the past I have used some C for that purpose, but have you tried the D language (used from Python with Pyd)? It's way better, especially if you for example use libs similar to itertools functions, etc :-) Bye, bearophile From bearophileHUGS at lycos.com Mon Jun 8 15:30:59 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 12:30:59 -0700 (PDT) Subject: Am I doing this the python way? (list of lists + file io) References: Message-ID: R. David Murray: > Given your description, I don't see any reason to prefer any alternate > data structure. ?1000 small CSV files should fit in a modern computer's > memory with no problem...and if it does become an issue, worry about it > then. The OP can also try the "diff" command that can be found implemented both on Linux and Windows. Bye, bearophile From jnoller at gmail.com Mon Jun 8 15:32:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 8 Jun 2009 15:32:39 -0400 Subject: spammers on pypi In-Reply-To: References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> On Mon, Jun 8, 2009 at 3:14 PM, Robert Kern wrote: > On 2009-06-08 07:44, Skip Montanaro wrote: >> >> On Jun 5, 1:39 pm, joep ?wrote: >>> >>> Is there a way to ban spammers from pypi? >> >> Can you provide some examples? ?It's possible that we can apply >> SpamBayes >> to PyPI submissions in much the same way that we apply it in other non- >> mail >> areas. > > I suspect he might talking about all of the "1.0.1" releases of projects on > June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" > (obfuscated to avoid helping them out). Most of them appear to be removed, > now. These chuckleheads even have a blog post complaining about it. I can > collect a list from my Cheeseshop RSS history if you like. > > I don't think a SpamBayes approach will work for this particular guy. It's > not like completely fake metadata was uploaded with links to spam sites. > There actually is Python code for some of them. Maybe even some that is > marginally useful. But only marginally (Linked Lists for Python? Really?). > All of the code appears to use their proprietary, unreleased package. > None of the code was useful, and I swear it all seemed like one giant ruse to bump google rankings for his pay-for-play sites and downloads. It was all just series of URLs back linking to his crap-sites. From robert.kern at gmail.com Mon Jun 8 15:39:39 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Jun 2009 14:39:39 -0500 Subject: spammers on pypi In-Reply-To: <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> Message-ID: On 2009-06-08 14:32, Jesse Noller wrote: > On Mon, Jun 8, 2009 at 3:14 PM, Robert Kern wrote: >> On 2009-06-08 07:44, Skip Montanaro wrote: >>> On Jun 5, 1:39 pm, joep wrote: >>>> Is there a way to ban spammers from pypi? >>> Can you provide some examples? It's possible that we can apply >>> SpamBayes >>> to PyPI submissions in much the same way that we apply it in other non- >>> mail >>> areas. >> I suspect he might talking about all of the "1.0.1" releases of projects on >> June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" >> (obfuscated to avoid helping them out). Most of them appear to be removed, >> now. These chuckleheads even have a blog post complaining about it. I can >> collect a list from my Cheeseshop RSS history if you like. >> >> I don't think a SpamBayes approach will work for this particular guy. It's >> not like completely fake metadata was uploaded with links to spam sites. >> There actually is Python code for some of them. Maybe even some that is >> marginally useful. But only marginally (Linked Lists for Python? Really?). >> All of the code appears to use their proprietary, unreleased package. > > None of the code was useful, and I swear it all seemed like one giant > ruse to bump google rankings for his pay-for-play sites and downloads. > It was all just series of URLs back linking to his crap-sites. Come now! I'm sure pyLotto has some measurable (but tiny!) amount of expected value to it. :-) The main point is that the code isn't gibberish. It might even do what it claims to do if one had the dependencies. Only a human examining it could determine that the code was actually useless and part of a spam-like campaign. -- 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 clp2 at rebertia.com Mon Jun 8 15:47:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 12:47:00 -0700 Subject: MD5 hash of object In-Reply-To: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> References: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Message-ID: <50697b2c0906081247m23c6fdf3of876d120f60ac75b@mail.gmail.com> On Mon, Jun 8, 2009 at 11:43 AM, lczancanella wrote: > Hi, > > in hashlib the hash methods have as parameters just string, i want to > know how can i digest an object to get a md5 hash of them. Hashes are only defined to operate on bytestrings. Since Python is a high-level language and doesn't permit you to view the internal binary representation of objects, you're going to have to properly convert the object to a bytestring first, a process called "serialization". The `pickle` and `json` serialization modules are included in the standard library. These modules can convert objects to bytestrings and back again. Once you've done the bytestring conversion, just run the hash method on the bytestring. Be careful when serializing dictionaries and sets though, because they are arbitrarily ordered, so two dictionaries containing the same items and which compare equal may have a different internal ordering, thus different serializations, and thus different hashes. Cheers, Chris -- http://blog.rebertia.com From stef.mientki at gmail.com Mon Jun 8 15:49:59 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 08 Jun 2009 21:49:59 +0200 Subject: Wrapping LabVIEW and DAQmx Libraries for Python In-Reply-To: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> References: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> Message-ID: <4A2D6B67.30803@gmail.com> hi Ketteth, I was waiting for someone, making these available. The hardware modules of NI are very good, and they have a huge range of DAQ cards, even relative cheap ones. We use USB 6009 and 9162 container a lot ( now in Delphi, because the lack of Python drivers :-( I took a biref look at your code, but couldn't find any continous sampling routines. Are you plan to create them ? cheers, Stef xkenneth wrote: > All, > > I've started wrapping the DAQmx and other LabVIEW libraries for > python using ctypes. I really like doing some things in python and > other in LabVIEW, so I'd like to have the same functionality available > for both. I've hosted the tiniest bit of code (mostly just proof of > concept) on github. Let me know if anyone else would be interested in > this. I'd love some help hashing it out. > > - Ken > > http://github.com/erdosmiller/pydaqmx/tree/master > From castironpi at gmail.com Mon Jun 8 15:57:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 8 Jun 2009 12:57:58 -0700 (PDT) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: On Jun 8, 9:50?am, Jean-Michel Pichavant wrote: > Aaron Brady wrote: > > Shorter is always better. > > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Why bother with spaces or 3 letter-wide token, check this ?:o) : > x+={'/':''}.get(x[-1],'/') > > Apart from joking, the following proposed solution is by **far** the one > I prefer > > > if not url.endswith('/'): > > ? ?url += '/' > > Maybe not the shorter, but the most concise and clear to me. Why won't Python permit: url.endswith( '/' ) or url.append( '/' ) ? Should it? Do we find it just as concise and clear? Does it outweigh the priority of the immutability of strings? It works on lists, for example. A sole mutating operation could create a highly and finely tempered compromise with immutability. Would it be 'append'? I like Scott's and MRAB's idea for slicing, not indexing, the last character. The most literal translation of the original natural language is: >>> #ensure that the url ends with a '/' >>> ensure( url, string.endswith, '/' ) (Is it not?) But the parameters aren't sufficient to define 'ensure' generally, and it won't be able to mutate 'url' regardless. From jeff at jmcneil.net Mon Jun 8 16:18:02 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 8 Jun 2009 13:18:02 -0700 (PDT) Subject: Get the class name References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <1141201e-9fe6-4c08-9d85-fcc87e52ffba@o36g2000vbi.googlegroups.com> On Jun 8, 11:33?am, Gary Herron wrote: > Kless wrote: > > Is there any way of to get the class name to avoid to have that write > > it? > > > --------------- > > class Foo: > > ? ?super(Foo, self) > > --------------- > > > * Using Py 2.6.2 > > The question does not make sense: > ? ? "to have WHAT write WHAT", > and the code is wrong: > ? ? the call to super fails > But even so, perhaps this will answer your question > > ?>>> class Foo: > ... ? pass > ... > > ?>>> print Foo.__name__ > Foo > > ?>>> c = Foo > ?>>> print c.__name__ > Foo > > ?>>> ob = Foo() > ?>>> print ob.__class__.__name__ > Foo > > Gary Herron I think the OP wants to call super without having to explicitly name the type. If you use the self.__class__ approach in that scenario, you can enter into a recursion loop with further inheritance. class T(object): """I'm a standard class""" def f(self): print "function" class S(T): """I call super using self.__class__""" def f(self): super(self.__class__, self).f() class J(S): """I don't know about S' odd call.""" j = J() j.f() # <--- Bombs From enleverLesX_XXmcX at XmclavXeauX.com Mon Jun 8 16:45:39 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Mon, 08 Jun 2009 21:45:39 +0100 Subject: is there python image lib that does imagemagick? References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <4a2d6a64$0$12625$ba4acef3@news.orange.fr> Hi! On Windows, you can drive (manage?) ImageMagick from Python, via COM. See: http://www.imagemagick.org/script/api.php#com+ @-salutations -- Michel Claveau From mail at timgolden.me.uk Mon Jun 8 17:19:30 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Jun 2009 22:19:30 +0100 Subject: pythoncom and writing file "summary" info on Windows In-Reply-To: References: Message-ID: <4A2D8062.1040806@timgolden.me.uk> mattleftbody at gmail.com wrote: > Hello, > I was trying to put together a script that would write things like the > Author and Title metadata fields of a file under Windows. I got the > win32 extensions installed and found a few things that look like they > should work, though I'm not getting the result I would expect. > Hopefully someone has worked through this area and can point me in the > right direction. FWIW, this works for me: import os, sys from win32com.shell import shell, shellcon import pythoncom from win32com import storagecon filepath = sys.argv[1] pidl, flags = shell.SHILCreateFromPath (os.path.abspath (filepath), 0) property_set_storage = shell.SHGetDesktopFolder ().BindToStorage ( pidl, None, pythoncom.IID_IPropertySetStorage ) summary_info = property_set_storage.Open ( pythoncom.FMTID_SummaryInformation, storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE ) summary_info.WriteMultiple ([storagecon.PIDSI_TITLE], ["BLAHBLAH2"]) BUT... you need to be aware that working with files -- typically media files such as JPEGs etc. -- can play strange tricks with this info as they implement their own property handlers to provide extra file-specific info. On my system, for example, altho' the Summary tab offers Title and Author and I can fill them in an Apply, nothing happens. They're not there when I come back, and likewise the code above won't affect them. Maybe this is what you're seeing. TJG From mh at pixar.com Mon Jun 8 17:36:51 2009 From: mh at pixar.com (mh at pixar.com) Date: Mon, 08 Jun 2009 21:36:51 GMT Subject: preferring [] or () in list of error codes? Message-ID: Is there any reason to prefer one or the other of these statements? if e.message.code in [25401,25402,25408]: if e.message.code in (25401,25402,25408): I'm currently using [], but only coz I think it's prettier than (). context: these are database errors and e is database exception, so there's probably been zillions of instructions and io's handling that already. Many TIA! Mark -- Mark Harrison Pixar Animation Studios From apt.shansen at gmail.com Mon Jun 8 17:56:24 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Jun 2009 14:56:24 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: <7a9c25c20906081456obcc469by89f5e29d59ee7fc9@mail.gmail.com> On Mon, Jun 8, 2009 at 2:36 PM, wrote: > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). I like to use tuples / () if the sequence literal is ultimately static. Purely because in my mind that just makes it a little more clear-- a list is mutable, so I use it when it should be or may be mutated; if it never would, I use a tuple. It just seems clearer to me that way. But a tuple also takes up a little space in memory, so it's a bit more efficient that way. I have absolutely no idea if reading / checking for contents in a list vs tuple has any performance difference, but would suspect it'd be tiny (and probably irrelevant in a small case like that), but still. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Mon Jun 8 18:15:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 08 Jun 2009 15:15:07 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: mh at pixar.com wrote: > Is there any reason to prefer one or the other of these statements? > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > I'm currently using [], but only coz I think it's prettier > than (). > context: these are database errors and e is database exception, > so there's probably been zillions of instructions and io's > handling that already. I lightly prefer the (a, b, c) -- you do put spaces after the comma, don't you? A tuple can be kept as a constant, but it requires (not very heavy) program analysis to determine that the list need not be constructed each time the statement is executed. In addition, a tuple is allocated as a single block, while a list is a pair of allocations. The cost is tiny, however, and your sense of aesthetics is part of your code. So unless you only very slightly prefer brackets, if I were you I'd go with the list form. --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Mon Jun 8 19:28:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 8 Jun 2009 23:28:42 +0000 (UTC) Subject: preferring [] or () in list of error codes? References: Message-ID: pixar.com> writes: > > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > >From the viewpoint of relative execution speed, in the above case if it matters at all it matters only on Python 2.4 AFAICT: | >>> L=lambda x:x in[25401,25402,25408]; T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (25401) 6 LOAD_CONST 2 (25402) 9 LOAD_CONST 3 (25408) 12 BUILD_LIST 3 15 COMPARE_OP 6 (in) 18 RETURN_VALUE 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 4 ((25401, 25402, 25408)) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE Earlier versions build the list or tuple at run time (as for the list above); later versions detect that the list can't be mutated and generate the same code for both the list and tuple. However there are limits to the analysis that can be performed e.g. if the list is passed to a function, pursuit halts at the county line: [Python 2.6.2] | >>> F=lambda y,z:y in z;L=lambda x:F(x,[25401,25402,25408]); T=lambda x:F(x,(25401,25402,25408));import dis;dis.dis(L);dis.dis(T) 1 0 LOAD_GLOBAL 0 (F) 3 LOAD_FAST 0 (x) 6 LOAD_CONST 0 (25401) 9 LOAD_CONST 1 (25402) 12 LOAD_CONST 2 (25408) 15 BUILD_LIST 3 18 CALL_FUNCTION 2 21 RETURN_VALUE 1 0 LOAD_GLOBAL 0 (F) 3 LOAD_FAST 0 (x) 6 LOAD_CONST 3 ((25401, 25402, 25408)) 9 CALL_FUNCTION 2 12 RETURN_VALUE So in general anywhere I had a "list constant" I'd make it a tuple -- I'm not aware of any way that performance gets worse by doing that, and it can get better. Background: I'm supporting packages that run on 2.1 to 2.6 in one case and 2.4 to 2.6 in the other; every little unobtrusive tweak helps :-) HTH, John From ben+python at benfinney.id.au Mon Jun 8 19:43:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 09:43:45 +1000 Subject: preferring [] or () in list of error codes? References: Message-ID: <87zlcicmvi.fsf@benfinney.id.au> mh at pixar.com writes: > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). Use a list when the semantic meaning of an item doesn't depend on all the other items: it's ?only? a collection of values. Your list of message codes is a good example: if a value appears at index 3, that doesn't make it mean something different from the same value appearing at index 2. Use a tuple when the semantic meaning of the items are bound together, and it makes more sense to speak of all the items as a single structured value. The classic examples are point coordinates and timestamps: rather than a collection of values, it makes more sense to think of each coordinate set or timestamp as a single complex value. The value 7 appearing at index 2 would have a completely different meaning from the value 7 appearing at index 3. James Tauber explains this at . -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so, Brain, but pantyhose are so uncomfortable in the | _o__) summertime.? ?_Pinky and The Brain_ | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 19:44:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 23:44:10 GMT Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <023d949e$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 12:57:58 -0700, Aaron Brady wrote: > Why won't Python permit: > > url.endswith( '/' ) or url.append( '/' ) > > ? Because: (1) Strings are immutable, so that won't work. (2) Even if it did, you're programming by side-effect, which is bad style often leading to bugs, and so should be avoided. > Should it? Heavens no! It's bad enough that similar expressions are allowed for lists. Just because they're allowed, doesn't mean we should use them! > Do we find it just as concise and clear? No. It *looks* like a boolean expression which is produced then thrown away uselessly. If not for append() on lists having a side-effect, I'd call it an expensive no-op. > Does it > outweigh the priority of the immutability of strings? Certainly not. Special cases aren't special enough to break the rules. Strings have nice consistent behaviour. You're suggesting making their behaviour inconsistent. > It works on > lists, for example. A sole mutating operation could create a highly and > finely tempered compromise with immutability. You're not thinking it through. You can't say "strings are immutable, except for append, which mutates them". If you allow *one* mutable operation, then the type is mutable, full stop. > Would it be 'append'? > > I like Scott's and MRAB's idea for slicing, not indexing, the last > character. > > The most literal translation of the original natural language is: > >>>> #ensure that the url ends with a '/' >>>> ensure( url, string.endswith, '/' ) > > (Is it not?) But the parameters aren't sufficient to define 'ensure' > generally, and it won't be able to mutate 'url' regardless. This suggestion appears to be a pie-in-the-sky impractical suggestion. It requires a function ensure() with close to human intelligence to "do what I mean". As such, I can't take it seriously. -- Steven From shaibani at ymail.com Mon Jun 8 20:17:05 2009 From: shaibani at ymail.com (Ala) Date: Tue, 09 Jun 2009 01:17:05 +0100 Subject: Network Simulator Message-ID: <090620090117055672%shaibani@ymail.com> Hello everyone. I plan on starting to write a network simulator on python for testing a modified version of TCP. I am wondering if a python network simulator exists? Also, if anyone tried using simpy for doing a simulation. Thank you From shaibani at ymail.com Mon Jun 8 20:18:13 2009 From: shaibani at ymail.com (Ala) Date: Tue, 09 Jun 2009 01:18:13 +0100 Subject: networking simulator on python Message-ID: <090620090118139750%shaibani@ymail.com> Hello everyone. I plan on starting to write a network simulator on python for testing a modified version of TCP. I am wondering if a python network simulator exists? Also, if anyone tried using simpy for doing a simulation. Thank you From pavlovevidence at gmail.com Mon Jun 8 20:37:28 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Jun 2009 17:37:28 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> On Jun 8, 4:43?pm, Ben Finney wrote: > m... at pixar.com writes: > > Is there any reason to prefer one or the other of these statements? > > > ? ? ? ? if e.message.code in [25401,25402,25408]: > > ? ? ? ? if e.message.code in (25401,25402,25408): > > > I'm currently using [], but only coz I think it's prettier > > than (). > > Use a list when the semantic meaning of an item doesn't depend on all > the other items: it's ?only? a collection of values. > > Your list of message codes is a good example: if a value appears at > index 3, that doesn't make it mean something different from the same > value appearing at index 2. > > Use a tuple when the semantic meaning of the items are bound together, > and it makes more sense to speak of all the items as a single structured > value. If you want to go strictly by the book, I would say he ought to be using a set since his collection of numbers has no meaningful order nor does it make sense to list any item twice. I don't think it's very important, however, to stick to rules like that for objects that don't live for more than a single line of code. Carl Banks From greg at cosc.canterbury.ac.nz Mon Jun 8 20:48:40 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 09 Jun 2009 12:48:40 +1200 Subject: Pyrex and refcounts (Re: unladen swallow: python and llvm) In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <4A2DB168.4050204@cosc.canterbury.ac.nz> bearophileHUGS at lycos.com wrote: > I have tried to create a certain data structure with a recent version > of Pyrex on Windows, and I have wasted lot of time looking for missing > reference count updates that didn't happen, or memory that didn't get > freed. Can you elaborate on those problems? The only way you should be able to get reference count errors in Pyrex code is if you're casting between Python and non-Python types. -- Greg From ptmcg at austin.rr.com Mon Jun 8 20:50:32 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 8 Jun 2009 17:50:32 -0700 (PDT) Subject: networking simulator on python References: <090620090118139750%shaibani@ymail.com> Message-ID: <2e404cd7-2e71-40c1-803e-1432b970bdc1@j32g2000yqh.googlegroups.com> On Jun 8, 7:18?pm, Ala wrote: > Hello everyone. > > I plan on starting to write a network simulator on python for testing a > modified version of TCP. > > I am wondering if a python network simulator exists? Also, if anyone > tried using simpy for doing a simulation. > > Thank you There was an article on just this topic in the April issue of Python Magazine. -- Paul From ben+python at benfinney.id.au Mon Jun 8 21:02:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 11:02:54 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> Message-ID: <87my8icj7l.fsf@benfinney.id.au> Carl Banks writes: > If you want to go strictly by the book, I would say he ought to be > using a set since his collection of numbers has no meaningful order > nor does it make sense to list any item twice. Yes, a set would be best for this specific situation. > I don't think it's very important, however, to stick to rules like > that for objects that don't live for more than a single line of code. It's important to the extent that it's important to express one's *meaning*. Program code should be written primarily as a means of communicating with other programmers, and only incidentally for the computer to execute. -- \ ?Laurie got offended that I used the word ?puke?. But to me, | `\ that's what her dinner tasted like.? ?Jack Handey | _o__) | Ben Finney From ndbecker2 at gmail.com Mon Jun 8 21:09:46 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 08 Jun 2009 21:09:46 -0400 Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> <6272ad2e-bce4-48ad-a729-80400c59e929@z9g2000yqi.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > s... at pobox.com: >> Why not just write extension modules in C then? > > In the past I have used some C for that purpose, but have you tried > the D language (used from Python with Pyd)? It's way better, > especially if you for example use libs similar to itertools functions, > etc :-) > > Bye, > bearophile Is Pyd maintained? I'm interested, but was scared away when I noticed that it had not been updated for some time. (I haven't looked recently). From heweiwei at gmail.com Mon Jun 8 21:15:22 2009 From: heweiwei at gmail.com (BigHand) Date: Mon, 8 Jun 2009 18:15:22 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() Message-ID: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Hi,All I have an embedded python application. which is a MFC app with Python interpreter embedded. In the App, I have a separate thread to execute a Python script (using the PyRun_File), but if the user want to stop the executing script, how should I do? A possible way is terminate the thread of executing the scripts by TerminateThread(). but TerminateThread() is unsafe and not recommended. guys, could you guide me on this? B.R. Harry From pavlovevidence at gmail.com Mon Jun 8 21:28:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Jun 2009 18:28:38 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> On Jun 8, 6:02?pm, Ben Finney wrote: > Carl Banks writes: > > If you want to go strictly by the book, I would say he ought to be > > using a set since his collection of numbers has no meaningful order > > nor does it make sense to list any item twice. > > Yes, a set would be best for this specific situation. > > > I don't think it's very important, however, to stick to rules like > > that for objects that don't live for more than a single line of code. > > It's important to the extent that it's important to express one's > *meaning*. Program code should be written primarily as a means of > communicating with other programmers, and only incidentally for the > computer to execute. Which is precisely why isn't not very important for an object that exists for one line. No programmer is ever going to be confused about the meaning of this: if a in (1,2,3): Carl Banks From charles at declareSub.com Mon Jun 8 21:56:53 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 8 Jun 2009 21:56:53 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> Message-ID: On Jun 8, 2009, at 9:28 PM, Carl Banks wrote: > On Jun 8, 6:02 pm, Ben Finney wrote: >> Carl Banks writes: >>> If you want to go strictly by the book, I would say he ought to be >>> using a set since his collection of numbers has no meaningful order >>> nor does it make sense to list any item twice. >> >> Yes, a set would be best for this specific situation. >> >>> I don't think it's very important, however, to stick to rules like >>> that for objects that don't live for more than a single line of >>> code. >> >> It's important to the extent that it's important to express one's >> *meaning*. Program code should be written primarily as a means of >> communicating with other programmers, and only incidentally for the >> computer to execute. > > Which is precisely why isn't not very important for an object that > exists for one line. No programmer is ever going to be confused about > the meaning of this: > > if a in (1,2,3): > Actually, I might be -- I think of a tuple first as a single thing, as opposed to a list or map, which I see first as a collection of other things. Charles Yeomans From samwyse at gmail.com Mon Jun 8 21:57:34 2009 From: samwyse at gmail.com (samwyse) Date: Mon, 8 Jun 2009 18:57:34 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> Message-ID: <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> On Jun 8, 7:37?pm, Carl Banks wrote: > On Jun 8, 4:43?pm, Ben Finney wrote: > > m... at pixar.com writes: > > > Is there any reason to prefer one or the other of these statements? > > > > ? ? ? ? if e.message.code in [25401,25402,25408]: > > > ? ? ? ? if e.message.code in (25401,25402,25408): > > If you want to go strictly by the book, I would say he ought to be > using a set since his collection of numbers has no meaningful order > nor does it make sense to list any item twice. As the length of the list increases, the increased speeds of looking something up makes using a set makes more sense. But what's the best way to express this? Here are a few more comparisons (using Python 3.0)... >>> S=lambda x:x in set((25401,25402,25408)) >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_GLOBAL 0 (set) 6 LOAD_CONST 3 ((25401, 25402, 25408)) 9 CALL_FUNCTION 1 12 COMPARE_OP 6 (in) 15 RETURN_VALUE >>> S=lambda x:x in{25401,25402,25408} >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 0 (25401) 6 LOAD_CONST 1 (25402) 9 LOAD_CONST 2 (25408) 12 BUILD_SET 3 15 COMPARE_OP 6 (in) 18 RETURN_VALUE >>> S=lambda x:x in{(25401,25402,25408)} >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 3 ((25401, 25402, 25408)) 6 BUILD_SET 1 9 COMPARE_OP 6 (in) 12 RETURN_VALUE I conclude that using constructors is generally a bad idea, since the compiler doesn't know if you're calling the builtin or something with an overloaded name. I presume that the compiler will eventually optimize the second example to match the last, but both of them use the BUILD_SET opcode. I expect that this can be expensive for long lists, so I don't think that it's a good idea to use set constants inside loops. Instead it should be assigned to a global or class variable. From bearophileHUGS at lycos.com Mon Jun 8 22:02:19 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 19:02:19 -0700 (PDT) Subject: Pyrex and refcounts (Re: unladen swallow: python and llvm) References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> <4A2DB168.4050204@cosc.canterbury.ac.nz> Message-ID: Greg: >Can you elaborate on those problems?< I can't, I am sorry, I don't remember the details anymore. Feel free to ignore what I have written about Pyrex, lot of people appreciate it, so it must be good enough, even if I was not smart/ expert enough to use it well. I have even failed in using it on Windows for several days, so probably I am/was quite ignorant. I use Python also because it's handy. For programmers being lazy is sometimes a quality :-) ----------------- This part is almost OT, I hope it will be tolerated. Neal Becker: >Is Pyd maintained? I'm interested, but was scared away when I noticed that it had not been updated for some time. (I haven't looked recently).< I think Pyd works (with no or small changes) with a D1 compiler like DMD, but you have to use the Phobos Standard library, that is worse than Tango. If you have problems with Pyd you will probably find people willing to help you on the D IRC channel. The problem is that the D language isn't used by lot of people, and most libraries are developed by few university students that stop mantaining the libraries once they find a job. So most D libraries are almost abandoned. There is just not enough people in the D community. And some people don't like to develop new libs because the D2 language (currently in Alpha still) makes D1 look like a dead end. On the other hand this is also a good thing, because D1 language has stopped evolving, so you are often able to compile even "old" code. Using Pyd is quite easy, but D1 language is not as simple as Python, despite being three times simpler than C++ :-) The good thing is that it's not difficult to adapt C code to D, it's almost a mechanical translation (probably a tool simpler than 2to3 can be enough to perform such translation of C to D, but of course no one has written such thing). Another problem with Pyd is that it may have scalability problems, that is it may have problems if you want to wrap hundreds of classes and functions. So before using it for real projects it's better to test it well. I have no idea if D will ever have some true success, even if it's nice. The hystory of Informatics is full of thousands of nice dead languages. In the meantime I'll keep using it and writing libs, etc. I have seen than several Python-lovers like D. The new LDC compiler allows D1 code to be most times about as fast as C++. This is more than enough. At the moment it seems that D is appreciated by people that write video games. Bye, bearophile From skip at pobox.com Mon Jun 8 22:15:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 8 Jun 2009 21:15:29 -0500 Subject: spammers on pypi In-Reply-To: References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: <18989.50625.738941.862481@montanaro.dyndns.org> Robert> I don't think a SpamBayes approach will work for this particular Robert> guy. It's not like completely fake metadata was uploaded with Robert> links to spam sites. There actually is Python code for some of Robert> them. Maybe even some that is marginally useful. But only Robert> marginally (Linked Lists for Python? Really?). All of the code Robert> appears to use their proprietary, unreleased package. You might be surprised how well SpamBayes could single out this guy's stuff as spam. In his form submission he has to provide some references to his site. Those URLs (or at least fragments of them like domain names) or product references (seems everything has "vyper" in it) would probably become very spammy clues. I'll contact the PyPI software folks. I've used SpamBayes for similar sorts of things (like RoundUp). Somebody even built a SpamBayes for YouTube browser extension: http://userscripts.org/scripts/show/13839 Skip From lczancanella at gmail.com Mon Jun 8 22:23:03 2009 From: lczancanella at gmail.com (lczancanella) Date: Mon, 8 Jun 2009 19:23:03 -0700 (PDT) Subject: Unbound Method Error Message-ID: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Hi, i am brand new in Python, so sorry if this question is too basic, but i have tried a lot and dont have success... I have the following code... class Funcoes: def CifradorDeCesar(mensagem, chave, funcao): mensagem_encriptada='' if funcao == 1: for byte in mensagem: if byte.isalpha(): byte_encriptado=chr(ord(byte)+chave) if byte.isupper() and ord(byte_encriptado) > 90: byte_encriptado=chr(ord(byte_encriptado)-26) if byte.islower() and ord(byte_encriptado) > 122: byte_encriptado=chr(ord(byte_encriptado)-26) else: byte_encriptado=byte mensagem_encriptada+=byte_encriptado else: for byte in mensagem: if byte.isalpha(): byte_encriptado=chr(ord(byte)-chave) if byte.isupper() and ord(byte_encriptado) < 65: byte_encriptado=chr(ord(byte_encriptado)+26) if byte.islower() and ord(byte_encriptado) < 97: byte_encriptado=chr(ord(byte_encriptado)+26) else: byte_encriptado=byte mensagem_encriptada+=byte_encriptado return mensagem_encriptada class MC(Funcoes, type): def __init__(cls, clsname, bases, ns): def addtrace(f): def t(self, *args, **kwargs): for att in self.__crypt__: atribcripto = getattr(self, att) atribdescripto = Funcoes.CifradorDeCesar (atribcripto, 3, 2) setattr(self, att, atribdescripto) ret = f(self, *args, **kwargs) for att in self.__crypt__: atribdescripto = getattr(self, att) atribcripto = Funcoes.CifradorDeCesar (atribdescripto, 3, 1) setattr(self, att, atribcripto) # aqui seta __signature__ vazio, assina e atribui __signature__ return ret return t from types import FunctionType for name,obj in ns.items(): if type(obj) == FunctionType: setattr(cls, name, addtrace(ns[name])) class C(): __metaclass__ = MC __crypt__ = ["_a", "_b"] _a = 1 _b = 2 def add(self, a, b): _a = a _b = b return a+b then i call >>> i = C() >>> i.add(2,2) and the error: File "C:\Users\Junior\Desktop\Python\T2.py", line 37, in t atribdescripto = Funcoes.CifradorDeCesar(atribcripto, 3, 2) TypeError: unbound method CifradorDeCesar() must be called with Funcoes instance as first argument (got int instance instead) From clp2 at rebertia.com Mon Jun 8 22:30:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 19:30:22 -0700 Subject: Unbound Method Error In-Reply-To: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <50697b2c0906081930w60adeb8elcdb5e49ba18b2c2@mail.gmail.com> On Mon, Jun 8, 2009 at 7:23 PM, lczancanella wrote: > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > ? ?def CifradorDeCesar(mensagem, chave, funcao): > ? ? ? ?mensagem_encriptada='' > ? ? ? ?if funcao == 1: > ? ? ? ? ? ?for byte in mensagem: > ? ? ? ? ? ? ? ?if byte.isalpha(): > ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte)+chave) > ? ? ? ? ? ? ? ? ? ?if byte.isupper() and ord(byte_encriptado) > 90: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)-26) > ? ? ? ? ? ? ? ? ? ?if byte.islower() and ord(byte_encriptado) > 122: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)-26) > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?byte_encriptado=byte > ? ? ? ? ? ? ? ?mensagem_encriptada+=byte_encriptado > ? ? ? ?else: > ? ? ? ? ? ?for byte in mensagem: > ? ? ? ? ? ? ? ?if byte.isalpha(): > ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte)-chave) > ? ? ? ? ? ? ? ? ? ?if byte.isupper() and ord(byte_encriptado) < 65: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)+26) > ? ? ? ? ? ? ? ? ? ?if byte.islower() and ord(byte_encriptado) < 97: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)+26) > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?byte_encriptado=byte > ? ? ? ? ? ? ? ?mensagem_encriptada+=byte_encriptado > > ? ? ? ?return mensagem_encriptada > > class MC(Funcoes, type): > ? ?def __init__(cls, clsname, bases, ns): > ? ? ? ?def addtrace(f): > ? ? ? ? ? ?def t(self, *args, **kwargs): > ? ? ? ? ? ? ? ?for att in self.__crypt__: > ? ? ? ? ? ? ? ? ? ?atribcripto = getattr(self, att) > ? ? ? ? ? ? ? ? ? ?atribdescripto = Funcoes.CifradorDeCesar > (atribcripto, 3, 2) > ? ? ? ? ? ? ? ? ? ?setattr(self, att, atribdescripto) > ? ? ? ? ? ? ? ?ret = f(self, *args, **kwargs) > ? ? ? ? ? ? ? ?for att in self.__crypt__: > ? ? ? ? ? ? ? ? ? ?atribdescripto = getattr(self, att) > ? ? ? ? ? ? ? ? ? ?atribcripto = Funcoes.CifradorDeCesar > (atribdescripto, 3, 1) > ? ? ? ? ? ? ? ? ? ?setattr(self, att, atribcripto) > ? ? ? ? ? ? ? ?# aqui seta __signature__ vazio, assina e atribui > __signature__ > ? ? ? ? ? ? ? ?return ret > ? ? ? ? ? ?return t > ? ? ? ?from types import FunctionType > ? ? ? ?for name,obj in ns.items(): > ? ? ? ? ? ?if type(obj) == FunctionType: > ? ? ? ? ? ? ? ?setattr(cls, name, addtrace(ns[name])) > > class C(): > > ? ?__metaclass__ = MC > ? ?__crypt__ = ["_a", "_b"] > > ? ?_a = 1 > ? ?_b = 2 > > ? ?def add(self, a, b): > ? ? ? ?_a = a > ? ? ? ?_b = b > ? ? ? ?return a+b > > then i call > >>>> i = C() >>>> i.add(2,2) > > and the error: > > File "C:\Users\Junior\Desktop\Python\T2.py", line 37, in t > ? ?atribdescripto = Funcoes.CifradorDeCesar(atribcripto, 3, 2) > TypeError: unbound method CifradorDeCesar() must be called with > Funcoes instance as first argument (got int instance instead) `CifradorDeCesar` is an instance method of the class `Funcoes`, and thus can only be used on instances of the class, *NOT the class itself*. Since it appears to be just a normal function (as suggested by the name of the class and the fact that it lacks `self` as its first parameter), you should scrap the class entirely and just define `CifradorDeCesar` in the toplevel body of the module. Unlike Java, it is *not* good Python style to unnecessarily cram functions into classes. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Jun 8 23:06:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 20:06:19 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <50697b2c0906082006s3531dfccg5f738705fe6849d8@mail.gmail.com> On Mon, Jun 8, 2009 at 6:57 PM, samwyse wrote: > On Jun 8, 7:37?pm, Carl Banks wrote: >> On Jun 8, 4:43?pm, Ben Finney wrote: >> > m... at pixar.com writes: >> > > Is there any reason to prefer one or the other of these statements? >> >> > > ? ? ? ? if e.message.code in [25401,25402,25408]: >> > > ? ? ? ? if e.message.code in (25401,25402,25408): >> >> If you want to go strictly by the book, I would say he ought to be >> using a set since his collection of numbers has no meaningful order >> nor does it make sense to list any item twice. > > As the length of the list increases, the increased speeds of looking > something up makes using a set makes more sense. ?But what's the best > way to express this? ?Here are a few more comparisons (using Python > 3.0)... > >>>> S=lambda x:x in set((25401,25402,25408)) >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_GLOBAL ? ? ? ? ? ? ?0 (set) > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > ? ? ? ? ? ? ?9 CALL_FUNCTION ? ? ? ? ? ?1 > ? ? ? ? ? ? 12 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 15 RETURN_VALUE >>>> S=lambda x:x in{25401,25402,25408} >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 0 (25401) > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 1 (25402) > ? ? ? ? ? ? ?9 LOAD_CONST ? ? ? ? ? ? ? 2 (25408) > ? ? ? ? ? ? 12 BUILD_SET ? ? ? ? ? ? ? ?3 > ? ? ? ? ? ? 15 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 18 RETURN_VALUE >>>> S=lambda x:x in{(25401,25402,25408)} >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > ? ? ? ? ? ? ?6 BUILD_SET ? ? ? ? ? ? ? ?1 > ? ? ? ? ? ? ?9 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 12 RETURN_VALUE > > I conclude that using constructors is generally a bad idea, since the > compiler doesn't know if you're calling the builtin or something with > an overloaded name. ?I presume that the compiler will eventually > optimize the second example to match the last, but both of them use > the BUILD_SET opcode. ?I expect that this can be expensive for long Erm, unless I misunderstand you somehow, the second example will and should *never* match the last. The set {25401,25402,25408}, containing 3 integer elements, is quite distinct from the set {(25401,25402,25408)}, containing one element and that element is a tuple. set(X) != {X}; set([X]) = {X} Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Jun 8 23:18:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 03:18:24 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: On Tue, 09 Jun 2009 11:02:54 +1000, Ben Finney wrote: > Carl Banks writes: > >> If you want to go strictly by the book, I would say he ought to be >> using a set since his collection of numbers has no meaningful order nor >> does it make sense to list any item twice. > > Yes, a set would be best for this specific situation. > >> I don't think it's very important, however, to stick to rules like that >> for objects that don't live for more than a single line of code. > > It's important to the extent that it's important to express one's > *meaning*. Program code should be written primarily as a means of > communicating with other programmers, and only incidentally for the > computer to execute. But practicality beats purity -- there are many scenarios where we make compromises in our meaning in order to get correct, efficient code. E.g. we use floats, despite them being a poor substitute for the abstract Real numbers we mean. In addition, using a tuple or a list in this context: if e.message.code in (25401,25402,25408): is so idiomatic, that using a set in it's place would be distracting. Rather that efficiently communicating the programmer's intention, it would raise in my mind the question "that's strange, why are they using a set there instead of a tuple?". -- Steven From jeff at jmcneil.net Mon Jun 8 23:20:26 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 8 Jun 2009 20:20:26 -0700 (PDT) Subject: MD5 hash of object References: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Message-ID: On Jun 8, 3:47?pm, Chris Rebert wrote: > On Mon, Jun 8, 2009 at 11:43 AM, lczancanella wrote: > > Hi, > > > in hashlib the hash methods have as parameters just string, i want to > > know how can i digest an object to get a md5 hash of them. > > Hashes are only defined to operate on bytestrings. Since Python is a > high-level language and doesn't permit you to view the internal binary > representation of objects, you're going to have to properly convert > the object to a bytestring first, a process called "serialization". > The `pickle` and `json` serialization modules are included in the > standard library. These modules can convert objects to bytestrings and > back again. > Once you've done the bytestring conversion, just run the hash method > on the bytestring. > > Be careful when serializing dictionaries and sets though, because they > are arbitrarily ordered, so two dictionaries containing the same items > and which compare equal may have a different internal ordering, thus > different serializations, and thus different hashes. > > Cheers, > Chris > --http://blog.rebertia.com I'd think that using the hash of the pickled representation of an object might be problematic, no? The pickle protocol handles object graphs in a way that allows it to preserve references back to identical objects. Consider the following (contrived) example: import pickle from hashlib import md5 class Value(object): def __init__(self, v): self._v = v class P1(object): def __init__(self, name): self.name = Value(name) self.other_name = self.name class P2(object): def __init__(self, name): self.name = Value(name) self.other_name = Value(name) h1 = md5(pickle.dumps(P1('sabres'))).hexdigest() h2 = md5(pickle.dumps(P2('sabres'))).hexdigest() print h1 == h2 >>> False Just something to be aware of. Depending on what you're trying to accomplish, it may make sense to simply define a method which generates a byte string representation of your object's state and just return the hash of that value. Thanks, -Jeff mcjeff.blogspot.com From ben+python at benfinney.id.au Mon Jun 8 23:43:08 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 13:43:08 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <87ab4icbsj.fsf@benfinney.id.au> Steven D'Aprano writes: > In addition, using a tuple or a list in this context: > > if e.message.code in (25401,25402,25408): > > is so idiomatic, that using a set in it's place would be distracting. I think a list in that context is fine, and that's the idiom I see far more often than a tuple. > Rather that efficiently communicating the programmer's intention, it > would raise in my mind the question "that's strange, why are they > using a set there instead of a tuple?". The fact that literal set syntax is a relative newcomer is the primary reason for that, I'd wager. -- \ ?If you are unable to leave your room, expose yourself in the | `\ window.? ?instructions in case of fire, hotel, Finland | _o__) | Ben Finney From emile at fenx.com Tue Jun 9 01:30:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 08 Jun 2009 22:30:17 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <87ab4icbsj.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> Message-ID: On 6/8/2009 8:43 PM Ben Finney said... > Steven D'Aprano writes: > >> In addition, using a tuple or a list in this context: >> >> if e.message.code in (25401,25402,25408): >> >> is so idiomatic, that using a set in it's place would be distracting. > > I think a list in that context is fine, and that's the idiom I see far > more often than a tuple. > >> Rather that efficiently communicating the programmer's intention, it >> would raise in my mind the question "that's strange, why are they >> using a set there instead of a tuple?". > > The fact that literal set syntax is a relative newcomer is the primary > reason for that, I'd wager. > Well, no. It really is more, "that's odd... why use set?" Emile From myopc at aaa.com Tue Jun 9 01:50:47 2009 From: myopc at aaa.com (myopc) Date: Tue, 9 Jun 2009 13:50:47 +0800 Subject: multi-thread python interpreaters and c++ program Message-ID: hi, all I am ruuning a c++ program (boost python) , which create many python interpreaters and each run a python script with use multi-thread (threading). when the c++ main program exit, I want to shut down python interpreaters, but it crashed. I have googled a lot but cant get any clue. here is my code, your suggestion will be greatly appreciated. c++ : /**** test multi interpreaters ***/ #include #include #include #include #include using namespace boost::python; static const char* strs[3]={ "m1","m2","m3" }; static void xxx(const char* abc){ fprintf(stderr, "this is xxx %s\n", abc); } PyThreadState* testPy(int i){ char buf[128]; PyThreadState* ts = Py_NewInterpreter(); object main_namespace = import("__main__").attr("__dict__"); main_namespace["xxx"]= xxx; main_namespace["aaa"]= i+1; main_namespace["strs"]= strs[i]; sprintf(buf, "execfile('pyinter/%d.py')",i+1); if(!PyRun_SimpleString(buf)){ return ts; }else return 0; } int main(int argc, char** argv){ PyThreadState *ts[3]; Py_InitializeEx(0); PyEval_InitThreads(); for(int i=0 ; i< 3; i++){ ts[i]= testPy(i); if(! ts[i] ){ printf("run %d error\n",i); } else { printf("run %d ok\n",i); } } PyEval_ReleaseLock(); /// release the lock, interpreaters run Sleep(3500); for(int i=0; i< 3; i++){ if(! ts[i])continue; printf("delete %d ", i); PyEval_AcquireThread(ts[i]); Py_Finalize(); ///shut down interpreaters ,crash here PyEval_ReleaseLock(); Sleep(10); printf(" ok\n"); } Sleep(1500); printf("exit...\n"); } each interpreater uses the same python script: class MyTimer(object): def __init__(self, interval, function, args=[], kwargs={}): self.interval = interval self.function = function self.args = args self.kwargs = kwargs def start(self): self.stop() import threading self._timer = threading.Timer(self.interval, self._run) self._timer.setDaemon(True) self._timer.start() ### start a python thread, keep running def restart(self): self.start() def stop(self): if self.__dict__.has_key("_timer"): self._timer.cancel() del self._timer def _run(self): try: self.function(strs) except: pass self.restart() abc= MyTimer(aaa,xxx); abc.start(); From piet at cs.uu.nl Tue Jun 9 02:00:12 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 08:00:12 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: >>>>> Seamus MacRae (SM) wrote: >SM> Piet van Oostrum wrote: >>> By the way, there is a series of articles about concurrency on ACM Queue >>> which may be interesting for those participating in or just following >>> this discussion: >>> >>> http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency >>> >>> Here is one introductory paragraph from one of the articles: >>> >>> Parallel programming poses many new challenges to the developer, one of >>> which is synchronizing concurrent access to shared memory by multiple >>> threads. Programmers have traditionally used locks for synchronization, >>> but lock-based synchronization has well-known pitfalls. Simplistic >>> coarse-grained locking does not scale well, while more sophisticated >>> fine-grained locking risks introducing deadlocks and data races. >>> Furthermore, scalable libraries written using fine-grained locks cannot >>> be easily composed in a way that retains scalability and avoids deadlock >>> and data races. >SM> Is that the one about transactional memory? Yes -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From alia_khouri at yahoo.com Tue Jun 9 02:30:19 2009 From: alia_khouri at yahoo.com (Alia Khouri) Date: Mon, 8 Jun 2009 23:30:19 -0700 (PDT) Subject: python version in snow leopard? Message-ID: Does anyone know what version of python will appear in snow leopard which is apparently being released in September? From francesco.pietra at accademialucchese.it Tue Jun 9 02:38:44 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Tue, 9 Jun 2009 08:38:44 +0200 Subject: Fwd: Extract value and average In-Reply-To: References: <4A2D3E24.2060302@tim.thechases.com> <4A2D5E54.20403@tim.thechases.com> Message-ID: Sorry, I missed the last part of the message This makes a more generic parser (comment/uncomment the corresponding "# 1" or "# 2" code based on whether a new block is found by a first line containing "NSTEP" or a last line containing "EWALD"). This > yields a dictionary for each item in the input file. You can pull out whichever value(s) you want to manipulate. I recognize now that I did not define "block" correctly. The EWALD line, although separated by a blank line, makes part of the block. The layout of all other blocks in the output file is the same. francesco ---------- Forwarded message ---------- From: Francesco Pietra Date: Mon, Jun 8, 2009 at 11:55 PM Subject: Re: Extract value and average To: Tim Chase On Mon, Jun 8, 2009 at 8:54 PM, Tim Chase wrote: >> Of the various suggestions, of which I am most grateful, I >> first tried this one. I probably fixed a couple of indent >> problems, but I don't understand the last one: > > Since Python considers whitespace valueable, indentation needs to match. > ?When I transfer code into email, I tend to use two-space indentation so > lines don't wrap (in my regular coding, I tend to use hard-tabs with a > tabstop-du-jour of either 2/3/4 spaces-per-tab) and indent it one level to > offset it from the email body text. > > If you use Vim, you can copy/paste my emailed code and simply use > > ?:%s/ ?/\t/g > ?:%s/^\t > > to expand the two-space indents to actual tabs and then the second one > strips off the leading indentation. That done, previous code (for DIHED only) works fine with both the example file.txt francesco at deb32:~/tmp$ python tim.py Total: 4660.165 Count: 1 Average: 4660.165 and a file of 102 instances of DIHED: francesco at deb32:~/tmp1$ python tim.simple.edited.prod1.py Total: 465628.4416 Count: 102 Average: 4564.98472157 francesco at deb32:~/tmp1$ Incidentally, that solves my current problems. Thanks indeed for your generous help. ==================== The more complex parser also worked fine with file.txt: francesco at deb32:~/tmp$ python tim.py Total: 4660.165 Count: 1 Average: 4660.165 while (replacing in the parser 'file.txt' with 'prod1.out') with the 102 count file above it reported: francesco at deb32:~/tmp$ python tim.prod1.py Traceback (most recent call last): ?File "tim.prod1.py", line 27, in ? ?for thing ? in ? ? ?builder(): ?File "tim.prod1.py", line 15, in builder ? ?for k,v ? ? in ? ? ?pair_re.findall(line) ?File "tim.prod1.py", line 15, in ? ?for k,v ? ? in ? ? ?pair_re.findall(line) ValueError: invalid literal for float(): E I did the filename replacement with vim, though it is likely that I did some other mistake. If not, and you are interested in the prod1.out file, I can send it (82 kB). francesco > > From the code you sent, it looks like whitespace didn't get copied into your > script file correctly or your un-indentation didn't take place on every line > (the last 4 lines look like they have an extra space). ?Once you fix the > whitespace, it should run. ?For convenience, I've repasted below with > 4-spaces-per-tab and no offsetting indentation. > > -tkc > > ---------------------------- > import re > find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) > total = count = 0 > for line in file('file.txt'): > ? ?m = find_dihed_re.search(line) > ? ?if m: > ? ? ? ?str_value = m.group(1) > ? ? ? ?try: > ? ? ? ? ? ?f = float(str_value) > ? ? ? ? ? ?total += f > ? ? ? ? ? ?count += 1 > ? ? ? ?except: > ? ? ? ? ? ?print "Not a float: %s" % str_value > print "Total:", total > print "Count:", count > if count: > ? ?print "Average:", total/count > > > > > > From wuwei23 at gmail.com Tue Jun 9 02:39:28 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 8 Jun 2009 23:39:28 -0700 (PDT) Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> <023b4095$0$20636$c3e8da3@news.astraweb.com> Message-ID: <64578fa7-8d5c-462a-b266-ffe3edac8bdb@q14g2000vbn.googlegroups.com> Steven D'Aprano wrote: > e.g. the Wright Brothers weren't lone inventors working at a time when > everyone knew powered flight was impossible, they were experienced > engineers and glider-pilots who paid a lot of attention to research done > by their many competitors. Be careful, the idea that human knowledge is a process of incremental improvements rather than pulled complete and inviolate out of the minds of a handful of individuals is pretty unpopular in this day and age. It's a lot harder to assert the existence of "intellectual property" that way, and there's just no money in *that* ;) cynically y'rs, - alex23 From gagsl-py2 at yahoo.com.ar Tue Jun 9 02:58:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 03:58:10 -0300 Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: En Sun, 07 Jun 2009 13:31:07 -0300, Tuomas Vesterinen escribi?: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > > > #ifdef python2 > print u'foo', u'bar' > #endif > #ifdef python3 > print('foo', 'bar') > #endif > See ifdef.py in the Tools/scripts directory for a pure Python preprocessor. -- Gabriel Genellina From mail at microcorp.co.za Tue Jun 9 03:25:12 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 09:25:12 +0200 Subject: Function/method returning list of chars in string? Message-ID: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> One can go from lb = ['b','a','n','a','n','a'] to s = "banana" by using s = "".join(lb) Is there a way to go the reverse route? I have not been able to find one. It is obviously easy to write a for char in s loop or list comprehension, but there seems to be no function or string method to return a list of characters. using lb = s.split("") would have been nice as a complement to s = "".join(lb). Split is already full of magic, it could do with more. - Hendrik From 4564 at 755189.45 Tue Jun 9 03:28:27 2009 From: 4564 at 755189.45 (Enrico) Date: Tue, 9 Jun 2009 09:28:27 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> "lczancanella" ha scritto nel messaggio news:32bf5ccb-5bfd-49a5-b423-9d41180a0ddb at l28g2000vba.googlegroups.com... > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > def CifradorDeCesar(mensagem, chave, funcao): A quick look to your code suggests to me to rewrite the above lines as: class Funcoes: @classmethod def CifradorDeCesar(self, mensagem, chave, funcao): @classmethod is needed since you call: > atribdescripto = Funcoes.CifradorDeCesar (atribcripto, 3, 2) Best regards, Enrico From clp2 at rebertia.com Tue Jun 9 03:32:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 00:32:46 -0700 Subject: Function/method returning list of chars in string? In-Reply-To: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> Message-ID: <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> On Tue, Jun 9, 2009 at 12:25 AM, Hendrik van Rooyen wrote: > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? lb = list("banana") Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 9 03:32:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Jun 2009 09:32:50 +0200 Subject: Function/method returning list of chars in string? In-Reply-To: References: Message-ID: <796hh2F1p7fpkU1@mid.uni-berlin.de> Hendrik van Rooyen schrieb: > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? > > I have not been able to find one. > > It is obviously easy to write a for char in s loop > or list comprehension, but there seems to be > no function or string method to return a list > of characters. > > using lb = s.split("") would have been nice > as a complement to s = "".join(lb). > > Split is already full of magic, it could do with more. I think lb = list(s) is good enough. Diez From jonvspython at gmail.com Tue Jun 9 03:39:40 2009 From: jonvspython at gmail.com (jon vs. python) Date: Tue, 9 Jun 2009 09:39:40 +0200 Subject: Function/method returning list of chars in string? In-Reply-To: <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Sorry, I didn't realize that you already proposed list comprehension. There is some kind of asymmetry in several areas.I guess that's somehow related to this post: http://www.zedshaw.com/blog/2009-05-29.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Tue Jun 9 03:40:47 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 9 Jun 2009 00:40:47 -0700 (PDT) Subject: python version in snow leopard? References: Message-ID: <998336ef-1156-4493-a2c4-0cddb648fe19@f19g2000yqo.googlegroups.com> On Jun 9, 7:30?am, Alia Khouri wrote: > Does anyone know what version of python will appear in snow leopard > which is apparently being released in September? The python-dev thread starting at http://mail.python.org/pipermail/python-3000/2008-September/014816.html suggests that back in September 2008, there was a 'MajorOS Vendor (tm)' who was interested in getting Python 2.6 into their next OS release, provided that it (Python 2.6) was released by October 1st. Make of that what you will. Mark From glauco.uri at prometeia.it Tue Jun 9 03:45:23 2009 From: glauco.uri at prometeia.it (Glauco) Date: Tue, 09 Jun 2009 09:45:23 +0200 Subject: Extract value and average In-Reply-To: References: Message-ID: Francesco Pietra ha scritto: > I come 'naked', which is unusual and unfair. However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 > Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 > BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 > 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 > EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 > EAMBER (non-restraint) = -176251.1698 > EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 > Density = 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack > > francesco pietra > If this format is fixed... vals = [ float(l.split('=')[-1].strip()) for l in file('file.txt','r') if ' DIHED ' in l ] mean = sum(vals) / len(vals) print vals print mean Glauco From sjmachin at lexicon.net Tue Jun 9 03:50:06 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 9 Jun 2009 07:50:06 +0000 (UTC) Subject: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen microcorp.co.za> writes: > > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? | >>> list('Hendrik') ['H', 'e', 'n', 'd', 'r', 'i', 'k'] Bonus extras: try tuple() and set() > I have not been able to find one. > > It is obviously easy to write a for char in s loop > or list comprehension, Aha! try a functional equivalent of a list comp: | >>> map(None, 'Hendrik') ['H', 'e', 'n', 'd', 'r', 'i', 'k'] > using lb = s.split("") would have been nice > as a complement to s = "".join(lb). object_of_type_X(something) is nicer IMHO. > Split is already full of magic, it could do with more. Both str.split and re.split are /too/ full of magic IMHO. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 9 04:02:33 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 08:02:33 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote: > Use a list when the semantic meaning of an item doesn't depend on all > the other items: it's ?only? a collection of values. > > Your list of message codes is a good example: if a value appears at > index 3, that doesn't make it mean something different from the same > value appearing at index 2. That advice would seem to imply that lists shouldn't be ordered. If a list of values has an order, it implies that "first place" (index 0) is different from "second place", by virtue of the positions they appear in the list. The lists: presidential_candidates_sorted_by_votes = ['Obama', 'McCain'] presidential_candidates_sorted_by_votes = ['McCain', 'Obama'] have very different meanings. Prohibiting the use of lists in the context of ordered data is surely is an unfortunate consequence of your advice. > James Tauber explains this at > python_tuples_are_not_just_constant_lists/>. He doesn't really explain anything though, he merely states it as revealed wisdom. The closest he comes to an explanation is to declare that in tuples "the index in a tuple has an implied semantic. The point of a tuple is that the i-th slot means something specific. In other words, it's a index-based (rather than name based) datastructure." But he gives no reason for why we should accept that as true for tuples but not lists. It may be that that's precisely the motivation Guido had when he introduced tuples into Python, but why should we not overload tuples with more meanings than Guido (hypothetically) imagined? In other words, why *shouldn't* we treat tuples as immutable lists, if that helps us solve a problem effectively? To put it another way, I think the question of whether or not tuples are immutable lists has the answer Mu. Sometimes they are, sometimes they're not. I have no problem with the title of the quoted blog post -- that tuples are not *just* constant lists -- but I do dispute that there is any reason for declaring that tuples must not be used as constant lists. As tuples are defined in Python, they quack like immutable lists, they walk like immutable lists, and they swim like immutable lists. Why shouldn't we treat them as immutable lists? Phillip Eby states that "Lists are intended to be homogeneous sequences, while tuples are heterogeneous data structures." (Notice the subtle shift there: lists are "intended", while tuples "are". But in fact, there's nothing to stop you from putting homogeneous data into a tuple, so Eby is wrong to say that tuples *are* heterogeneous.) Perhaps Eby intends lists to be homogeneous, perhaps Guido does too, but this is Python, where we vigorously defend the right to shoot ourselves in the foot. We strongly discourage class creators from trying to enforce their intentions by using private attributes, and even when we allow such a thing, the nature of Python is that nothing is truly private. Why should homogeneity and heterogeneity of lists and tuples be sacrosanct? Nothing stops me from putting hetereogeneous data into a list, or homogeneous data into a tuple, and there doesn't appear to be any ill- effects from doing so. Why give lose sleep over the alleged lack of purity? -- Steven From piet at cs.uu.nl Tue Jun 9 04:36:02 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 10:36:02 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> Message-ID: >>>>> "Enrico" <4564 at 755189.45> (E) wrote: >E> "lczancanella" ha scritto nel messaggio >E> news:32bf5ccb-5bfd-49a5-b423-9d41180a0ddb at l28g2000vba.googlegroups.com... >>> Hi, i am brand new in Python, so sorry if this question is too basic, >>> but i have tried a lot and dont have success... I have the following >>> code... >>> >>> class Funcoes: >>> def CifradorDeCesar(mensagem, chave, funcao): >E> A quick look to your code suggests to me to rewrite the above lines as: >E> class Funcoes: >E> @classmethod >E> def CifradorDeCesar(self, mensagem, chave, funcao): >E> @classmethod is needed since you call: >>> atribdescripto = Funcoes.CifradorDeCesar (atribcripto, >E> 3, 2) The method doesn't need the class at all, so a staticmethod would be preferable: class Funcoes: @staticmethod def CifradorDeCesar(self, mensagem, chave, funcao): But as been mentioned in this thread before, there might be no reason to use the class anyway. The next thing you will run into is that you call CifradorDeCesar with an int as parameter (mensagem) but it expects a string (or byte string, at least something iterable). -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From alia_khouri at yahoo.com Tue Jun 9 04:47:52 2009 From: alia_khouri at yahoo.com (Alia K) Date: Tue, 9 Jun 2009 01:47:52 -0700 (PDT) Subject: python version in snow leopard? References: <998336ef-1156-4493-a2c4-0cddb648fe19@f19g2000yqo.googlegroups.com> Message-ID: Mark Dickinson wrote: > The python-dev thread starting at > > http://mail.python.org/pipermail/python-3000/2008-September/014816.html > > suggests that back in September 2008, there was a 'MajorOS Vendor > (tm)' > who was interested in getting Python 2.6 into their next OS release, > provided that it (Python 2.6) was released by October 1st. > > Make of that what you will. Thanks for the response/link. Looks like it will be 2.6 then, but I'd even be happy with 2.5.4 (-: AK From jeanmichel at sequans.com Tue Jun 9 04:49:25 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Jun 2009 10:49:25 +0200 Subject: Start the interactive shell within an application Message-ID: <4A2E2215.1090405@sequans.com> I was wondering if there is a way to start an interactive shell within a script/application. I'm sometimes tired of adding prints to scan the current namespace so I'd like to pause the execution and give the user the shell prompt. This is obviously for debugging purpose. I know that I may use the raw_input and eval the captured text but honestly, this requires some coding and I won't benefit from the shell features. Would it be even possible to use a shell like Ipython ? By the way, if anyone has cunning ways for debugging code to share, he would be much welcome. Jean-Michel From eglyph at gmail.com Tue Jun 9 05:22:50 2009 From: eglyph at gmail.com (eGlyph) Date: Tue, 9 Jun 2009 02:22:50 -0700 (PDT) Subject: Start the interactive shell within an application References: Message-ID: On Jun 9, 11:49?am, Jean-Michel Pichavant wrote: > I'm sometimes tired of adding prints to scan the current namespace so > I'd like to pause the execution and give the user the shell prompt. > This is obviously for debugging purpose. This is definitely doable, have look at rhythmbox or gedit - they provide an interactive console. Also, have a look at IPython, they have a recipe and an example of embedding IPython into a user's application. From javier.collado at gmail.com Tue Jun 9 05:29:45 2009 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 9 Jun 2009 11:29:45 +0200 Subject: Start the interactive shell within an application In-Reply-To: References: Message-ID: Take a look either at code.interact or at IPython.ipapi.launch_new_instance. Basically, the only thing that you have to provide is a dictionary object that contains the namespace that you would like to have in your shell once it's launched. Best regards, Javier 2009/6/9 eGlyph : > On Jun 9, 11:49?am, Jean-Michel Pichavant > wrote: >> I'm sometimes tired of adding prints to scan the current namespace so >> I'd like to pause the execution and give the user the shell prompt. >> This is obviously for debugging purpose. > > This is definitely doable, have look at rhythmbox or gedit - they > provide an interactive console. > Also, have a look at IPython, they have a recipe and an example of > embedding IPython into a user's application. > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at microcorp.co.za Tue Jun 9 05:32:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:32:10 +0200 Subject: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: <005301c9e8e7$af006d60$0d00a8c0@Hendrik> jon vs. python wrote: >Sorry, I didn't realize that you already proposed list comprehension. > > >There is some kind of asymmetry in several areas.I guess that's somehow related to this post: >http://www.zedshaw.com/blog/2009-05-29.html Thanks for the link - I am not quite as rabid, but it would be nice. - Hendrik From mail at microcorp.co.za Tue Jun 9 05:42:27 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:42:27 +0200 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> "Chris Rebert" wrote: > lb = list("banana") Aaargh! I should have known - you use a string method to get a list of words, but you have to go to the list to get a list of characters from a string. There is no string method to do it, which is what I am complaining about. Is there a reason for this, or is the lack of symmetry just an historical artefact? The link that jon vs python supplied is interesting. - Hendrik From mail at microcorp.co.za Tue Jun 9 05:47:53 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:47:53 +0200 Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <005501c9e8e7$b24dc3a0$0d00a8c0@Hendrik> "Diez B. Roggisch" wrote: > > I think > > lb = list(s) > > is good enough. It does the job, of course, but it is not a string method. - Hendrik From clp2 at rebertia.com Tue Jun 9 06:02:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 03:02:43 -0700 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: <50697b2c0906090302n74d4a762u77315e721bbc02fb@mail.gmail.com> On Tue, Jun 9, 2009 at 2:42 AM, Hendrik van Rooyen wrote: > "Chris Rebert" wrote: > >> lb = list("banana") > > Aaargh! > > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. > There is no string method to do it, which is what I am complaining > about. > > Is there a reason for this, or is the lack of symmetry just an historical > artefact? I think most would agree that having join() be a method of `str` rather than `list` can be understandably confusing to newbies, so the apparent asymmetry lies on the other side of the list-str boundary (i.e. why don't I use a list method to convert a list of strings to a string?). The reason join() is a method of `str` is so that it doesn't have to be reimplemented for every container type (e.g. tuple, set, list, user-defined containers, etc). You can look at it the same way for why a `str` method isn't used to produce a list of characters -- what would you do for every other container type (i.e. what if I want a set of the characters in a string)? Having the container type rather than the string take care of it solves this problem. Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 9 06:05:14 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Jun 2009 12:05:14 +0200 Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <796q93F1p879rU1@mid.uni-berlin.de> Hendrik van Rooyen wrote: > "Diez B. Roggisch" wrote: > >> >> I think >> >> lb = list(s) >> >> is good enough. > > It does the job, of course, but it is not a string method. And that is a bad thing because of what? Also as list-comps are going away and are replaced by list() I'd say it's much more consistent when faced with the task of creating a list of anything that's iterable one uses the list() idiom. Diez From marco at sferacarta.com Tue Jun 9 06:06:12 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 09 Jun 2009 12:06:12 +0200 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: Hendrik van Rooyen wrote: >> lb = list("banana") > > Aaargh! > > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. As they say, "Python is not Java". Strings support the sequence protocol (aka interface), hence they can be given as input to the list constructor. It would not make much sense to add methods (to the N concrete implementations, mind you) that replicate functionality available by the builtin constructors through implicit interfaces. Would you also ask for '43'.as_int() or stuff like that? From naruvimama at gmail.com Tue Jun 9 06:40:02 2009 From: naruvimama at gmail.com (Chandramouli) Date: Tue, 9 Jun 2009 03:40:02 -0700 (PDT) Subject: using libraries not installed on campus computers (numpy) Message-ID: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> I built and installed Numpy on my campus account, the install couldn't be done on the python install location. So I did it on my local storage location but I am clueless about how to use it I was expecting to see a numpy.py in the install dir so I could I suppose just give import numpy and expect it to work like normal but I am not sure how this works From cournape at gmail.com Tue Jun 9 07:29:52 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 9 Jun 2009 20:29:52 +0900 Subject: using libraries not installed on campus computers (numpy) In-Reply-To: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> References: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> Message-ID: <5b8d13220906090429q6e17147w99009c9cb9023f6c@mail.gmail.com> On Tue, Jun 9, 2009 at 7:40 PM, Chandramouli wrote: > I built and installed Numpy on my campus account, the install couldn't > be done on the python install location. So I did it on my local > storage location but I am clueless about how to use it I was expecting > to see a numpy.py in the install dir > so I could I suppose just give > import numpy > > and expect it to work like normal but I am not sure how this works python expects to find modules (such as numpy) into a list of directories, some of which are hardcoded at installation time for python. You can prepend a directory (or a set of directories) using the PYTHONPATH environment variable. For example, installing numpy insto $HOME/local: python setup.py install --prefix=$HOME/local numpy will be installed in $HOME/local/lib/python2.5/site-packages (for python 2.5), and you should set your PYTHONPATH to $HOME/local/lib/python2.5/site-packages for python to find it: PYTHONPATH=$HOME/local/lib/python2.5/site-packages:$PYTHONPATH python -c "import numpy" David From samwyse at gmail.com Tue Jun 9 07:47:16 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 04:47:16 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <932aa351-a531-49db-904c-22593563b293@r16g2000vbn.googlegroups.com> On Jun 8, 10:06?pm, Chris Rebert wrote: > On Mon, Jun 8, 2009 at 6:57 PM, samwyse wrote: > > On Jun 8, 7:37?pm, Carl Banks wrote: > >> On Jun 8, 4:43?pm, Ben Finney wrote: > >> > m... at pixar.com writes: > >> > > Is there any reason to prefer one or the other of these statements? > > >> > > ? ? ? ? if e.message.code in [25401,25402,25408]: > >> > > ? ? ? ? if e.message.code in (25401,25402,25408): > > >> If you want to go strictly by the book, I would say he ought to be > >> using a set since his collection of numbers has no meaningful order > >> nor does it make sense to list any item twice. > > > As the length of the list increases, the increased speeds of looking > > something up makes using a set makes more sense. ?But what's the best > > way to express this? ?Here are a few more comparisons (using Python > > 3.0)... > > >>>> S=lambda x:x in set((25401,25402,25408)) > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_GLOBAL ? ? ? ? ? ? ?0 (set) > > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > > ? ? ? ? ? ? ?9 CALL_FUNCTION ? ? ? ? ? ?1 > > ? ? ? ? ? ? 12 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 15 RETURN_VALUE > >>>> S=lambda x:x in{25401,25402,25408} > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 0 (25401) > > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 1 (25402) > > ? ? ? ? ? ? ?9 LOAD_CONST ? ? ? ? ? ? ? 2 (25408) > > ? ? ? ? ? ? 12 BUILD_SET ? ? ? ? ? ? ? ?3 > > ? ? ? ? ? ? 15 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 18 RETURN_VALUE > >>>> S=lambda x:x in{(25401,25402,25408)} > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > > ? ? ? ? ? ? ?6 BUILD_SET ? ? ? ? ? ? ? ?1 > > ? ? ? ? ? ? ?9 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 12 RETURN_VALUE > > > I conclude that using constructors is generally a bad idea, since the > > compiler doesn't know if you're calling the builtin or something with > > an overloaded name. ?I presume that the compiler will eventually > > optimize the second example to match the last, but both of them use > > the BUILD_SET opcode. ?I expect that this can be expensive for long > > Erm, unless I misunderstand you somehow, the second example will and > should *never* match the last. > The set {25401,25402,25408}, containing 3 integer elements, is quite > distinct from the set {(25401,25402,25408)}, containing one element > and that element is a tuple. > set(X) != {X}; set([X]) = {X} D'oh! I was thinking about how you can initialize a set from an iterator and for some reason thought that you could do the same with a set constant. From samwyse at gmail.com Tue Jun 9 07:57:48 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 04:57:48 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> On Jun 8, 8:57?pm, samwyse wrote: > I conclude that using constructors is generally a bad idea, since the > compiler doesn't know if you're calling the builtin or something with > an overloaded name. ?I presume that the compiler will eventually > optimize the second example to match the last, but both of them use > the BUILD_SET opcode. ?I expect that this can be expensive for long > lists, so I don't think that it's a good idea to use set constants > inside loops. ?Instead it should be assigned to a global or class > variable. Time to test things! I'm going to compare three things using Python 3.0: X={...}\nS=lambda x: x in X S=lambda x: x in {...} S=lambda x: x in (...) where the ... is replaced by lists of integers of various lengths. Here's the test bed: from random import seed, sample from timeit import Timer maxint = 2**31-1 values = list(map(lambda n: 2**n-1, range(1,16))) def append_numbers(k, setup): seed(1968740928) for i in sample(range(maxint), k): setup.append(str(i)) setup.append(',') print('==', 'separate set constant') for n in values[::2]: print('===', n, 'values') setup = ['X={'] append_numbers(n, setup) setup.append('}\nS=lambda x: x in X') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) print('==', 'in-line set constant') for n in values[:4]: print('===', n, 'values') setup = ['S=lambda x: x in {'] append_numbers(n, setup) setup.append('}') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) print('==', 'in-line list constant') for n in values: print('===', n, 'values') setup = ['S=lambda x: x in ('] append_numbers(n, setup) setup.append(')') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) And here are the results. There's something interesting at the very end. == separate set constant === 1 values [0.26937306277753176, 0.26113626173158877, 0.26000092190487889] === 7 values [0.26583266867716426, 0.27223543774418268, 0.27681646689732919] === 31 values [0.25089725090758752, 0.25562690230182894, 0.25844625504079444] === 127 values [0.32404313956103392, 0.33048948958596691, 0.34487930728626104] === 511 values [0.27574566041214732, 0.26991838348169983, 0.28309016928129083] === 2047 values [0.27826162263639631, 0.27337357122204065, 0.26888752620793976] === 8191 values [0.27479134917985437, 0.27955955295994261, 0.27740676538498654] === 32767 values [0.26189725230441319, 0.25949247739587022, 0.2537356004743625] == in-line set constant === 1 values [0.43579086168772818, 0.4231755711968983, 0.42178740594125852] === 3 values [0.54712875519095228, 0.55325048295244272, 0.54346991028189251] === 7 values [1.1897654590178366, 1.1763383335032813, 1.2009900699669931] === 15 values [1.7661906750718313, 1.7585005915556291, 1.7405896559478933] == in-line list constant === 1 values [0.23651385860493335, 0.24746972031361381, 0.23778469051234197] === 3 values [0.23710750947396875, 0.23205630883254713, 0.23345592805789295] === 7 values [0.24607764394636789, 0.23551903943099006, 0.24241377046524093] === 15 values [0.2279376289444599, 0.22491908887861456, 0.24076747184349045] === 31 values [0.22860084172708994, 0.233022074034551, 0.23138639128715965] === 63 values [0.23671639831319169, 0.23404259479906031, 0.22269394573891077] === 127 values [0.22754176857673158, 0.22818151468971593, 0.22711154629987718] === 255 values [0.23503126794047802, 0.24493699618247788, 0.26690207833677349] === 511 values [0.24518255811842238, 0.23878118587697728, 0.22844830837438934] === 1023 values [0.23285585179122137, 0.24067220833932623, 0.23807439213642922] === 2047 values [0.24206484343680756, 0.24352201187581102, 0.24366253252857462] === 4095 values [0.24624526301527183, 0.23692145230748807, 0.23829956041899081] === 8191 values [0.22246514570986164, 0.22435309515595137, 0.22220114567633331] === 16383 values [194.29462683106374, 193.21789529116128, 193.25843228678508] === 32767 values You will note that testing against a list constant is just as fast as testing against a set. This was surprising for me; apparently the __contains__ operator turns a tuple into a set. You will also note that performance to fall off drastically for the last set of values. I'm not sure what happens there; I guess I'll file a bug report. From brendandetracey at yahoo.com Tue Jun 9 08:38:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:38:46 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: <98d95066-48c4-41c1-ac6e-9d78c1fcd3a0@f16g2000vbf.googlegroups.com> I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought From brendandetracey at yahoo.com Tue Jun 9 08:38:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:38:46 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: <05102193-3c85-4fc6-83ee-9f4b1a32cd26@o20g2000vbh.googlegroups.com> I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought From brendandetracey at yahoo.com Tue Jun 9 08:54:15 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:54:15 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought the process would be analogous to dealing with xml documents or DOM but find myself somewhat lost in the word object reference manual (http://msdn.microsoft.com/en-us/library/ bb244515.aspx) . I was hoping to easily load all document objects into a list so that I could poke around, examine and experiment with them. So far all I have managed to do is load the page content as a string, not particularly helpful. Could someone please point me in the right direction? Also, help, __doc__ and dir do not return anything meaningful(to me anyway) or helpful. There seem to be no exposed methods or properties. e.g. I have a word document object: wd = wordapp.Documents.Open('blah.dic') But: >>> dir(wd) ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__', '__getattr__', '__getitem__', '__init__', '__int__', '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__', '__setitem__', '__str__', '_builtMethods_', '_enum_', '_find_dispatch_type_', '_get_good_object_', '_get_good_single_object_', '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] And: >>> print wd.__doc__ The dynamic class used as a last resort. The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy of using the makepy generated wrapper Python class instead of dynamic.CDispatch if/when possible. Furthermore: >>> help(wd) Help on instance of CDispatch in module win32com.client object: class instance(object) | instance(class[, dict]) | | Create an instance without calling its __init__() method. | The class must be a classic class. | If present, dict must be a dictionary or None. | | Methods defined here: | | __abs__(...) | x.__abs__() <==> abs(x) ~ ~ snip ~ ~ | __truediv__(...) | x.__truediv__(y) <==> x/y | | __xor__(...) | x.__xor__(y) <==> x^y | | next(...) | x.next() -> the next value, or raise StopIteration | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T What gives? From ben+python at benfinney.id.au Tue Jun 9 08:56:17 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 22:56:17 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: <8763f5d0r2.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote: > > > Use a list when the semantic meaning of an item doesn't depend on > > all the other items: it's ?only? a collection of values. > > > > Your list of message codes is a good example: if a value appears at > > index 3, that doesn't make it mean something different from the same > > value appearing at index 2. > > That advice would seem to imply that lists shouldn't be ordered. No such implication. Order is important in a list, it just doesn't change the semantic meaning of the value. > If a list of values has an order, it implies that "first place" (index > 0) is different from "second place", by virtue of the positions they > appear in the list. The lists: > > presidential_candidates_sorted_by_votes = ['Obama', 'McCain'] > presidential_candidates_sorted_by_votes = ['McCain', 'Obama'] > > have very different meanings. But the semantic meaning if each value is unchanged: each is still a presidential candidate's surname. The additional semantic meaning of putting it in a list is no more than the position in the sequence. A list is the right choice, for that reason. Whereas, for example, in this tuple: dodge_city = (1781, 1870, 1823) (population, feet_above_sea_level, establishment_year) = dodge_city each index in the sequence implies something very different about each value. The semantic meaning of each index is *more* than just the position in the sequence; it matters *for interpreting that component*, and that component would not mean the same thing in a different index position. A tuple is the right choice, for that reason. -- \ ?Are you pondering what I'm pondering?? ?Umm, I think so, Don | `\ Cerebro, but, umm, why would Sophia Loren do a musical?? | _o__) ?_Pinky and The Brain_ | Ben Finney From 4564 at 755189.45 Tue Jun 9 10:16:06 2009 From: 4564 at 755189.45 (Enrico) Date: Tue, 9 Jun 2009 16:16:06 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> Message-ID: <4a2e6edd$0$1114$4fafbaef@reader4.news.tin.it> "Piet van Oostrum" ha scritto nel messaggio news:m2ljo1ajnx.fsf at cs.uu.nl... > The method doesn't need the class at all, so a staticmethod would be > preferable: > class Funcoes: > @staticmethod > def CifradorDeCesar(self, mensagem, chave, funcao): Yes, in this case self is not needed. > > But as been mentioned in this thread before, there might be no reason to > use the class anyway. I agree but the code is not very clear about the use of this class as ancestor of MC. >>class MC(Funcoes, type): ? Enrico From brendandetracey at yahoo.com Tue Jun 9 11:17:15 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 08:17:15 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling References: Message-ID: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> On Jun 9, 9:54?am, Brendan wrote: > I was hoping to use pywin32 to automate some rather tedious filling in > of Word forms. I thought the process would be analogous to dealing > with xml documents or DOM but find myself somewhat lost in the word > object reference manual (http://msdn.microsoft.com/en-us/library/ > bb244515.aspx) . ?I was hoping to easily load all document objects > into a list so that I could poke around, examine and experiment with > them. So far all I have managed to do is load the page content as a > string, not particularly helpful. > > Could someone please point me in the right direction? > > Also, help, __doc__ and dir do not return anything meaningful(to me > anyway) or helpful. There seem to be no exposed methods or properties. > e.g. I have a word document object: > wd = wordapp.Documents.Open('blah.dic') > But:>>> dir(wd) > > ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', > '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__', > '__doc__', '__getattr__', '__getitem__', '__init__', '__int__', > '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__', > '__setitem__', '__str__', '_builtMethods_', '_enum_', > '_find_dispatch_type_', '_get_good_object_', > '_get_good_single_object_', '_lazydata_', '_make_method_', > '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', > '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] > > And: > > >>> print wd.__doc__ > > ? ? The dynamic class used as a last resort. > ? ? The purpose of this overriding of dynamic.CDispatch is to > perpetuate the policy > ? ? of using the makepy generated wrapper Python class instead of > dynamic.CDispatch > ? ? if/when possible. > > Furthermore:>>> help(wd) > > Help on instance of CDispatch in module win32com.client object: > > class instance(object) > ?| ?instance(class[, dict]) > ?| > ?| ?Create an instance without calling its __init__() method. > ?| ?The class must be a classic class. > ?| ?If present, dict must be a dictionary or None. > ?| > ?| ?Methods defined here: > ?| > ?| ?__abs__(...) > ?| ? ? ?x.__abs__() <==> abs(x) > > ~ ~ snip ~ ~ > > | ?__truediv__(...) > ?| ? ? ?x.__truediv__(y) <==> x/y > ?| > ?| ?__xor__(...) > ?| ? ? ?x.__xor__(y) <==> x^y > ?| > ?| ?next(...) > ?| ? ? ?x.next() -> the next value, or raise StopIteration > ?| > ?| > ---------------------------------------------------------------------- > ?| ?Data and other attributes defined here: > ?| > ?| ?__new__ = > ?| ? ? ?T.__new__(S, ...) -> a new object with type S, a subtype of T > > What gives? Hmmm. The VB examples in the Word Object Reference give the best idea of how to play with Word documents. No further help required on this although I am still curious about why the python does not return the "real" objects and methods for the COM object. From Scott.Daniels at Acm.Org Tue Jun 9 11:19:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 09 Jun 2009 08:19:13 -0700 Subject: Unbound Method Error In-Reply-To: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: lczancanella wrote: > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > def CifradorDeCesar(mensagem, chave, funcao): > ... > You've gotten some "interesting" advice. You want one of: class Funcoes: @staticmethod def CifradorDeCesar(mensagem, chave, funcao): ... or: class Funcoes: def CifradorDeCesar(self, mensagem, chave, funcao): ... or: class Funcoes: @class_method def CifradorDeCesar(class_, mensagem, chave, funcao): ... --Scott David Daniels Scott.Daniels at Acm.Org From samwyse at gmail.com Tue Jun 9 11:20:04 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 08:20:04 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> Message-ID: <508492d1-7268-417f-bfbc-ecc464bf080c@f16g2000vbf.googlegroups.com> On Jun 9, 12:30?am, Emile van Sebille wrote: > On 6/8/2009 8:43 PM Ben Finney said... > > The fact that literal set syntax is a relative newcomer is the primary > > reason for that, I'd wager. > > Well, no. ?It really is more, "that's odd... why use set?" Until I ran some timing tests this morning, I'd have said that sets could determine membership faster than a list, but that's apparently not true, assuming that the list has less than 8K members. Above 16K members, sets are much faster than lists. I'm not sure where the break is, or even why there's a break. From mail at timgolden.me.uk Tue Jun 9 11:24:52 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Jun 2009 16:24:52 +0100 Subject: pywin32 - word object reference module - automating form filling In-Reply-To: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> References: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> Message-ID: <4A2E7EC4.1000007@timgolden.me.uk> Brendan wrote: > Hmmm. The VB examples in the Word Object Reference give the best idea > of how to play with Word documents. No further help required on this > although I am still curious about why the python does not return the > "real" objects and methods for the COM object. Try doing it this way: import win32com.client word = win32com.client.gencache.EnsureDispatch ("Word.Application") help (word) doc = win32com.client.gencache.EnsureDispatch (word.Documents.Add ()) help (doc) or just run the makepy util first. TJG From pavlovevidence at gmail.com Tue Jun 9 11:37:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 08:37:33 -0700 (PDT) Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <9f6beb7a-c7bd-461f-877e-82e335dfdf06@z7g2000vbh.googlegroups.com> On Jun 9, 2:47?am, "Hendrik van Rooyen" wrote: > "Diez B. Roggisch" wrote: > > > I think > > > lb = list(s) > > > is good enough. > > It does the job, of course, but it is not a string method. A. Your post's subject included the words "function/method" B. Who cares Carl Banks From redplusbluemakespurple at gmail.com Tue Jun 9 11:38:34 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Tue, 9 Jun 2009 08:38:34 -0700 (PDT) Subject: List comprehension and string conversion with formatting Message-ID: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> I'd like to convert a list of floats to a list of strings constrained to one .1f format. These don't work. Is there a better way? [".1f" % i for i in l] or [(".1f" % i) for i in l] StephenB From bcharrow at csail.mit.edu Tue Jun 9 11:40:49 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Tue, 09 Jun 2009 11:40:49 -0400 Subject: Start the interactive shell within an application In-Reply-To: References: Message-ID: <4A2E8281.6000305@csail.mit.edu> If you're looking to debug your program, try "import pdb" and then wherever you want to debug put: pdb.set_trace() Your program will then enter the debugger when it executes that line. It's quite nice really. If you get confused on what to do, just type "help" http://docs.python.org/library/pdb.html Cheers, Ben Javier Collado wrote: > Take a look either at code.interact or at > IPython.ipapi.launch_new_instance. Basically, the only thing that you > have to provide is a dictionary object that contains the namespace > that you would like to have in your shell once it's launched. > > Best regards, > Javier > > 2009/6/9 eGlyph : >> On Jun 9, 11:49 am, Jean-Michel Pichavant >> wrote: >>> I'm sometimes tired of adding prints to scan the current namespace so >>> I'd like to pause the execution and give the user the shell prompt. >>> This is obviously for debugging purpose. >> This is definitely doable, have look at rhythmbox or gedit - they >> provide an interactive console. >> Also, have a look at IPython, they have a recipe and an example of >> embedding IPython into a user's application. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From pavlovevidence at gmail.com Tue Jun 9 11:43:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 08:43:12 -0700 (PDT) Subject: List comprehension and string conversion with formatting References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> Message-ID: <8e203cda-f3e7-41d5-aaff-5fb5fd3dcb39@l28g2000vba.googlegroups.com> On Jun 9, 8:38?am, stephen_b wrote: > I'd like to convert a list of floats to a list of strings constrained > to one .1f format. These don't work. Is there a better way? > > [".1f" % i for i in l] > or > [(".1f" % i) for i in l] You need a % in there, chief. [ "%.1f" % x for x in lst ] BTW, I took the liberty of making a few style choices, highly recommended: not to use "i" for floating points ("i" strongly suggests integer value to many programmers), and not using "l" (the letter ell) as a name, it can be hard to distinguish from a "1" (the number one). Carl Banks From jaime.frio at gmail.com Tue Jun 9 11:48:55 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Tue, 9 Jun 2009 17:48:55 +0200 Subject: List comprehension and string conversion with formatting In-Reply-To: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> Message-ID: <97a8f1a70906090848x5458cd0dn50492fe61ba292bc@mail.gmail.com> On Tue, Jun 9, 2009 at 5:38 PM, stephen_b wrote: > I'd like to convert a list of floats to a list of strings constrained > to one .1f format. These don't work. Is there a better way? > > [".1f" % i for i in l] > or > [(".1f" % i) for i in l] There's a missing %, this does work... ["%.1f" % i for i in l] Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From redplusbluemakespurple at gmail.com Tue Jun 9 11:51:18 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Tue, 9 Jun 2009 08:51:18 -0700 (PDT) Subject: List comprehension and string conversion with formatting References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> <8e203cda-f3e7-41d5-aaff-5fb5fd3dcb39@l28g2000vba.googlegroups.com> Message-ID: <5df04182-d24d-4457-adc7-f0bf4f296c68@21g2000vbk.googlegroups.com> On Jun 9, 10:43?am, Carl Banks wrote: > You need a % in there, chief. > > Carl Banks You are so right. Thanks. From Krzysztof.Retel at googlemail.com Tue Jun 9 11:57:00 2009 From: Krzysztof.Retel at googlemail.com (kretel) Date: Tue, 9 Jun 2009 08:57:00 -0700 (PDT) Subject: Using logging module to log into flash drive Message-ID: Hi All, I am trying to implement the following functionality: 1. log messages to the flash drive 2. if the flash drive is not available, switch handler to the BufferringHandler and log into buffer, 3. once the flash drive is plugged in and available store the logs from BufferHandler into that flash drive and switch the handler into RotateFileHandler. Which approach would you suggest to use while implementing this functionality? One that come into my mind is to have one process or thread to check periodically if the flashdrive is available, and have a flag that will indicate that we can store the logs into the flash drive. But I don't particularly like this approach. Would you do it different way? Any suggestions are appreciated. Cheers, Krzysztof From pavlovevidence at gmail.com Tue Jun 9 12:16:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 09:16:33 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> Message-ID: <4d4f86e5-8a73-4f72-a38c-77be250d15b6@p4g2000vba.googlegroups.com> On Jun 9, 4:57?am, samwyse wrote: > On Jun 8, 8:57?pm, samwyse wrote: > > > I conclude that using constructors is generally a bad idea, since the > > compiler doesn't know if you're calling the builtin or something with > > an overloaded name. ?I presume that the compiler will eventually > > optimize the second example to match the last, but both of them use > > the BUILD_SET opcode. ?I expect that this can be expensive for long > > lists, so I don't think that it's a good idea to use set constants > > inside loops. ?Instead it should be assigned to a global or class > > variable. > > Time to test things! ? I'm going to compare three things using Python > 3.0: > ? X={...}\nS=lambda x: x in X > ? S=lambda x: x in {...} > ? S=lambda x: x in (...) > where the ... is replaced by lists of integers of various lengths. > Here's the test bed: > > from random import seed, sample > from timeit import Timer > maxint = 2**31-1 > values = list(map(lambda n: 2**n-1, range(1,16))) > def append_numbers(k, setup): > ? ? seed(1968740928) > ? ? for i in sample(range(maxint), k): > ? ? ? ? setup.append(str(i)) > ? ? ? ? setup.append(',') > print('==', 'separate set constant') > for n in values[::2]: > ? ? print('===', n, 'values') > ? ? setup = ['X={'] > ? ? append_numbers(n, setup) > ? ? setup.append('}\nS=lambda x: x in X') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) > print('==', 'in-line set constant') > for n in values[:4]: > ? ? print('===', n, 'values') > ? ? setup = ['S=lambda x: x in {'] > ? ? append_numbers(n, setup) > ? ? setup.append('}') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) > print('==', 'in-line list constant') > for n in values: > ? ? print('===', n, 'values') > ? ? setup = ['S=lambda x: x in ('] > ? ? append_numbers(n, setup) > ? ? setup.append(')') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) It looks like you are evaluating the list/set/tuple every pass, and then, for lists and tuples, always indexing the first item. > And here are the results. ?There's something interesting at the very > end. [snip results showing virtually identical performance for list, set, and tuple] > You will note that testing against a list constant is just as fast as > testing against a set. ?This was surprising for me; apparently the > __contains__ operator turns a tuple into a set. Given the way you wrote the test it this is hardly surprising. I would expect "item in list" to have comparable execution time to "item in set" if item is always the first element in list. Furthermore, the Python compiler appears to be optimizing this specific case to always use a precompiled set. Well, almost always.... >?You will also note > that ?performance to fall off drastically for the last set of values. > I'm not sure what happens there; I guess I'll file a bug report. Please don't; it's not a bug. The slowdown is because at sizes above a certain threshold the Python compiler doesn't try to precompile in- line lists, sets, and tuples. The last case was above that limit. Carl Banks From pavlovevidence at gmail.com Tue Jun 9 12:21:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 09:21:25 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> <508492d1-7268-417f-bfbc-ecc464bf080c@f16g2000vbf.googlegroups.com> Message-ID: <7c28e7cd-03d4-4591-99a4-02dd3322333f@o30g2000vbc.googlegroups.com> On Jun 9, 8:20?am, samwyse wrote: > On Jun 9, 12:30?am, Emile van Sebille wrote: > > > On 6/8/2009 8:43 PM Ben Finney said... > > > The fact that literal set syntax is a relative newcomer is the primary > > > reason for that, I'd wager. > > > Well, no. ?It really is more, "that's odd... why use set?" > > Until I ran some timing tests this morning, I'd have said that sets > could determine membership faster than a list, but that's apparently > not true, See my reply to that post. I believe your tests were flawed. > assuming that the list has less than 8K members. ?Above 16K > members, sets are much faster than lists. ?I'm not sure where the > break is, or even why there's a break. The break comes from the compiler, not the objects themselves. Carl Banks From David.Shapiro at sas.com Tue Jun 9 12:22:20 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Tue, 9 Jun 2009 12:22:20 -0400 Subject: python and getopt and spaces in option Message-ID: Hello, I have been trying to find an example of how to deal with options that have spaces in them. I am using jython, which is the same I think as python 2.2.3. I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). The code is as follows: try: (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) except getopt.GetoptError: usage() for opt in opts: (key, value) = opt if (key in ("-v", "--version")): print "Version: " + version sys.exit(1) if (key in ("-h", "--help")): usage() if (key in ("-s", "--server")): server = value if (key in ("-p", "--port")): port = value if (key in ("-n", "--dsName")): dsName = value if (key in ("-j", "--jndiName")): jndiName = value if (key in ("-d", "--driverName")): driverName = value if (key in ("-l", "--driverURL")): driverURL = value if (key in ("-u", "--user")): user = value if (key in ("-c", "--passWD")): passWD = value if (key in ("-t", "--targetServer")): targetServer = value if (key in ("-q", "--testTableName")): testTableName = value if (key in ("-w", "--whereProp")): whereProp = value print "server: " + server print "port: " + port print "dsName: " + dsName print "jndiName: " + jndiName print "driverName: " + driverName print "driverURL: " + driverURL print "user: " + user print "passWD: " + passWD print "testtable: " + testTableName print "targetServer: " + targetServer print "whereProp: " + whereProp The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get it to return the whole thing that is in double quotes? David From mh at pixar.com Tue Jun 9 12:40:42 2009 From: mh at pixar.com (mh at pixar.com) Date: Tue, 09 Jun 2009 16:40:42 GMT Subject: preferring [] or () in list of error codes? References: Message-ID: John Machin wrote: > T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) I've learned a lot from this thread, but this is the niftiest bit I've picked up... thanks! -- Mark Harrison Pixar Animation Studios From lie.1296 at gmail.com Tue Jun 9 12:41:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 09 Jun 2009 16:41:26 GMT Subject: multi-thread python interpreaters and c++ program In-Reply-To: References: Message-ID: myopc wrote: > hi, all > I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python > interpreaters, but it crashed. I have googled a lot but cant get any clue. > here is my code, your suggestion will be greatly appreciated. > There is no clean way to terminate a thread cleanly from outside. You need to let the thread terminates by itself. If it is a pure python code, this can be done by one of: 1) setting a global/thread stop value that is checked by each threads 2) inserting a QUIT event to the event-loop I have never used boost before, so I don't know what it can and cannot do from outside the python's interpreter. However, this should give you an idea of what to do... From a.cavallo at mailsnare.com Tue Jun 9 13:10:18 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Tue, 9 Jun 2009 18:10:18 +0100 Subject: Using logging module to log into flash drive In-Reply-To: References: Message-ID: <200906091810.19234.a.cavallo@mailsnare.com> Hi, the problem screams for a separate thread. Anyway there's a TimedRotatingFileHandler handler in the logging package: you can derive from it and change the emit/doRollover pair to hold the records until a device is not ready. Regards, Antonio On Tuesday 09 June 2009 16:57:00 kretel wrote: > Hi All, > > I am trying to implement the following functionality: > 1. log messages to the flash drive > 2. if the flash drive is not available, switch handler to the > BufferringHandler and log into buffer, > 3. once the flash drive is plugged in and available store the logs > from BufferHandler into that flash drive and switch the handler into > RotateFileHandler. > > Which approach would you suggest to use while implementing this > functionality? One that come into my mind is to have one process or > thread to check periodically if the flashdrive is available, and have > a flag that will indicate that we can store the logs into the flash > drive. But I don't particularly like this approach. > Would you do it different way? > Any suggestions are appreciated. > > Cheers, > Krzysztof From clp2 at rebertia.com Tue Jun 9 13:27:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 10:27:57 -0700 Subject: Unbound Method Error In-Reply-To: References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <50697b2c0906091027l4c285971y90eb5e7ccc985f84@mail.gmail.com> On Tue, Jun 9, 2009 at 8:19 AM, Scott David Daniels wrote: > lczancanella wrote: >> >> Hi, i am brand new in Python, so sorry if this question is too basic, >> but i have tried a lot and dont have success... I have the following >> code... >> >> class Funcoes: >> ? ?def CifradorDeCesar(mensagem, chave, funcao): >> ? ? ? ?... >> > > You've gotten some "interesting" advice. > > You want one of: > > ? ?class Funcoes: > ? ? ? ?@staticmethod > ? ? ? ?def CifradorDeCesar(mensagem, chave, funcao): > ? ? ? ? ? ?... > or: > ? ?class Funcoes: > ? ? ? ?def CifradorDeCesar(self, mensagem, chave, funcao): > ? ? ? ? ? ?... > or: > ? ?class Funcoes: > ? ? ? ?@class_method There's no underscore in "classmethod" last time I checked. > ? ? ? ?def CifradorDeCesar(class_, mensagem, chave, funcao): > ? ? ? ? ? ?... You forgot one more option (the preferred one, IMHO): #module toplevel def CifradorDeCesar(mensagem, chave, funcao): Cheers, Chris -- http://blog.rebertia.com From Krzysztof.Retel at googlemail.com Tue Jun 9 13:37:48 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Tue, 9 Jun 2009 10:37:48 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: <70177935-7b83-4bde-9c89-db51f1690c4f@o36g2000vbi.googlegroups.com> On Jun 9, 6:10?pm, "A. Cavallo" wrote: > Hi, > the problem screams for a separate thread. I was thinking about that, as mentioned in the first post. Although, I was wonder if there is another way to tackle the problem. > Anyway there's a TimedRotatingFileHandler handler in the logging package: > you can derive from it and change the emit/doRollover pair to hold the records > until a device is not ready. Hm, that might be the way to go. Will have a try. If anyone has other thoughts, please share them. Thanks, Krzysztof From toby at telegraphics.com.au Tue Jun 9 13:47:11 2009 From: toby at telegraphics.com.au (toby) Date: Tue, 9 Jun 2009 10:47:11 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On Jun 7, 2:41?pm, Jon Harrop wrote: > Arved Sandstrom wrote: > > Jon Harrop wrote: > >> I see no problem with mutable shared state. > > > In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance Frequently when they shouldn't. > and performance means > mutable state. Hm, not sure Erlangers would wholly agree. > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u From ebonak at hotmail.com Tue Jun 9 13:50:09 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 13:50:09 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> <4A2CF6D3.5010400@hotmail.com> Message-ID: <4A2EA0D1.4050107@hotmail.com> R. David Murray wrote: > > Well, I for one looked at that long pylint output when I first tried it, > and switched to another tool :) > > (pyflakes...but I don't think it does PEP 8) :-) Ok, so I'm not the only one who thinks the output is rather lengthy. I've since dug into the docs and searched on the web and found that --reports=n on the command line will truncate the various tables output at the end. Esmail From ken at jots.org Tue Jun 9 13:52:46 2009 From: ken at jots.org (Ken D'Ambrosio) Date: Tue, 9 Jun 2009 13:52:46 -0400 (EDT) Subject: Unbuffered keyboard input? Message-ID: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> I need to have some non-buffered keyboard interaction with a Python script (on Linux). Back in the day, I fired up Curses to do this in Perl. Any idea if that's still how I have to fly? Or is there a different mechanism? Thanks! -Ken -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From piet at cs.uu.nl Tue Jun 9 14:05:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 20:05:47 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> <4a2e6edd$0$1114$4fafbaef@reader4.news.tin.it> Message-ID: >>>>> "Enrico" <4564 at 755189.45> (E) wrote: >E> "Piet van Oostrum" ha scritto nel messaggio >E> news:m2ljo1ajnx.fsf at cs.uu.nl... >>> The method doesn't need the class at all, so a staticmethod would be >>> preferable: >>> class Funcoes: >>> @staticmethod >>> def CifradorDeCesar(self, mensagem, chave, funcao): >E> Yes, in this case self is not needed. >>> >>> But as been mentioned in this thread before, there might be no reason to >>> use the class anyway. >E> I agree but the code is not very clear about the use of this class as >E> ancestor of MC. >>>> class MC(Funcoes, type): >E> ? I hadn't even noted this peculiarity. Maybe it was thought to be necessary because CifradorDeCesar is used in MC. But as it is explicitly used as Funcoes.CifradorDeCesar the Funcoes in the base classes is useless and therefore confusing. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From Krzysztof.Retel at googlemail.com Tue Jun 9 14:10:08 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Tue, 9 Jun 2009 11:10:08 -0700 (PDT) Subject: Using logging module to log into flash drive References: <70177935-7b83-4bde-9c89-db51f1690c4f@o36g2000vbi.googlegroups.com> Message-ID: <0f4bfca0-ec16-4dbe-8c5d-dbf7ae19292f@e21g2000yqb.googlegroups.com> > > Anyway there's a TimedRotatingFileHandler handler in the logging package: > > you can derive from it and change the emit/doRollover pair to hold the records > > until a device is not ready. > > Hm, that might be the way to go. Will have a try. I had another look at the logging package. The class TimedRotatingFileHandler within the initialisation method uses the FileHandler.__init__. Whereas the FileHandler.__init__ method opens the stream in the 'append' mode (mode='a'). If the flash drive is not available while you start the script, which equals that you can't open a file in the append mode, then the TimedRotatingFileHandler (or FileHandler) fails. In my opinion the only way to go through this is to use two different handlers and once the flash drive is available then start to use the FileHandler. Still not sure if I want to use separate thread for checking the flash drive availability. Probably I need to build it this way. Regards Krzysztof From milesck at umich.edu Tue Jun 9 14:21:30 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 9 Jun 2009 14:21:30 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <796q93F1p879rU1@mid.uni-berlin.de> References: <796hh2F1p7fpkU1@mid.uni-berlin.de> <796q93F1p879rU1@mid.uni-berlin.de> Message-ID: <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> On Jun 9, 2009, at 6:05 AM, Diez B. Roggisch wrote: > Also as list-comps are going away and are replaced by > > list() Where did you hear that? -Miles From mrstevegross at gmail.com Tue Jun 9 14:22:36 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 11:22:36 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? Message-ID: I'm trying to write a try/catch block to handle an "interrupted system call". However, I can't seem to locate information on the actual typename of the exception. Does anyone know what it would be? I want my code to look like this: try: ... except InterruptedSystemCall # what's the right name? ... Thanks, --Steve From tjreedy at udel.edu Tue Jun 9 14:29:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 14:29:47 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: >> James Tauber explains this at >> > python_tuples_are_not_just_constant_lists/>. > > > He doesn't really explain anything though, he merely states it as > revealed wisdom. The closest he comes to an explanation is to declare > that in tuples "the index in a tuple has an implied semantic. The point > of a tuple is that the i-th slot means something specific. In other > words, it's a index-based (rather than name based) datastructure." But he > gives no reason for why we should accept that as true for tuples but not > lists. > > It may be that that's precisely the motivation Guido had when he > introduced tuples into Python, but why should we not overload tuples with > more meanings than Guido (hypothetically) imagined? In other words, why > *shouldn't* we treat tuples as immutable lists, if that helps us solve a > problem effectively? I believe that we should overload tuples with *less* specific meaning than originally. In 3.0, tuples have *all* the general sequence operations and methods, including .index() and .count(). This was not true in 2.5 (don't know about 2.6), which is why tuples are yet not documented as having those two methods (reported in http://bugs.python.org/issue4966 ). Operationally, they are now general immutable sequences. Period. Terry Jan Reedy From tjreedy at udel.edu Tue Jun 9 14:32:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 14:32:17 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: mh at pixar.com wrote: > John Machin wrote: >> T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) > > I've learned a lot from this thread, but this is the > niftiest bit I've picked up... thanks! If you are doing a lot of dissing, starting with from dis import dis saves subsequent typing. tjr From rkmr.em at gmail.com Tue Jun 9 14:38:53 2009 From: rkmr.em at gmail.com (rkmr.em at gmail.com) Date: Tue, 9 Jun 2009 11:38:53 -0700 Subject: spawning a process using os.spawn Message-ID: hi im spawning a script that runs for a long from a web app like this: os.spawnle(os.P_NOWAIT, "../bin/producenotify.py", "producenotify.py", "xx",os.environ) the script is spawned and it runs, but till it gets over i am not able to free the port that is used by the web app, or in other words i am not able to restart the web app. how do i spawn off a process and make it completely independent of the web app? thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Tue Jun 9 14:44:37 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 09 Jun 2009 13:44:37 -0500 Subject: Unbuffered keyboard input? References: Message-ID: On 2009-06-09, Ken D'Ambrosio wrote: > I need to have some non-buffered keyboard interaction with a Python script > (on Linux). Back in the day, I fired up Curses to do this in Perl. Any > idea if that's still how I have to fly? Or is there a different > mechanism? Same as it ever was (in the order I'd probably try): 1. You can switch stdin to raw mode using standard termios calls (just like in C). 2. You can use ncurses. 3. You can use some other UI library like newt/slang, wxWidgets, etc. 4. You can shove long rusty needles through your eyeballs into your brain until you no longer want to do non-buffered keyboard interaction. 5. You can make Xlib calls. Once you've tried #5, #4 doesn't sound so bad... -- Grant Edwards grante Yow! Where's th' DAFFY at DUCK EXHIBIT?? visi.com From malaclypse2 at gmail.com Tue Jun 9 14:52:53 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 9 Jun 2009 14:52:53 -0400 Subject: Unbuffered keyboard input? In-Reply-To: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> References: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> Message-ID: <16651e80906091152g328fdb8fo8fa3358a9a7b0529@mail.gmail.com> On Tue, Jun 9, 2009 at 1:52 PM, Ken D'Ambrosio wrote: > I need to have some non-buffered keyboard interaction with a Python script > (on Linux). Assuming you're running your code from a command prompt, something like this recipe might do the trick: http://code.activestate.com/recipes/134892/ -- Jerry From jeanmichel at sequans.com Tue Jun 9 14:54:32 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Jun 2009 20:54:32 +0200 Subject: What is the actual type of "interrupted system call"? In-Reply-To: References: Message-ID: <4A2EAFE8.40609@sequans.com> mrstevegross wrote: > I'm trying to write a try/catch block to handle an "interrupted system > call". However, I can't seem to locate information on the actual > typename of the exception. Does anyone know what it would be? I want > my code to look like this: > > try: > ... > except InterruptedSystemCall # what's the right name? > ... > > > Thanks, > --Steve > pick up your choice: exceptions.ArithmeticError exceptions.OSError exceptions.UnicodeTranslateError exceptions.AssertionError exceptions.OverflowError exceptions.UserWarning exceptions.AttributeError exceptions.OverflowWarning exceptions.ValueError exceptions.DeprecationWarning exceptions.PendingDeprecationWarning exceptions.Warning exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError exceptions.EnvironmentError exceptions.RuntimeError exceptions.__class__ exceptions.Exception exceptions.RuntimeWarning exceptions.__delattr__ exceptions.FloatingPointError exceptions.StandardError exceptions.__dict__ exceptions.FutureWarning exceptions.StopIteration exceptions.__doc__ exceptions.IOError exceptions.SyntaxError exceptions.__getattribute__ exceptions.ImportError exceptions.SyntaxWarning exceptions.__hash__ exceptions.IndentationError exceptions.SystemError exceptions.__init__ exceptions.IndexError exceptions.SystemExit exceptions.__name__ exceptions.KeyError exceptions.TabError exceptions.__new__ exceptions.KeyboardInterrupt exceptions.TypeError exceptions.__reduce__ exceptions.LookupError exceptions.UnboundLocalError exceptions.__reduce_ex__ exceptions.MemoryError exceptions.UnicodeDecodeError exceptions.__repr__ exceptions.NameError exceptions.UnicodeEncodeError exceptions.__setattr__ exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ CTRL+C (SIG_INT) is KeyboardInterrupt Jean-Michel From pavlovevidence at gmail.com Tue Jun 9 14:57:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 11:57:12 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: On Jun 9, 8:57?am, kretel wrote: > Hi All, > > I am trying to implement the following functionality: > 1. log messages to the flash drive > 2. if the flash drive is not available, switch handler to the > BufferringHandler and log into buffer, > 3. once the flash drive is plugged in and available store the logs > from BufferHandler into that flash drive and switch the handler into > RotateFileHandler. > > Which approach would you suggest to use while implementing this > functionality? One that come into my mind is to have one process or > thread to check periodically if the flashdrive is available, and have > a flag that will indicate that we can store the logs into the flash > drive. But I don't particularly like this approach. > Would you do it different way? > Any suggestions are appreciated. I'd refactor the steps this way: 1. log messages to a buffer 2. periodically flush the buffer to the flash drive, if it's available The "periodically" part could be accomplished with a thread or scheduled delays, however suits your application. It might not be a final if you need to log messages promptly, but that's how I'd begin. Carl Banks From jon at ffconsultancy.com Tue Jun 9 14:59:41 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 09 Jun 2009 19:59:41 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: toby wrote: > On Jun 7, 2:41?pm, Jon Harrop wrote: >> Arved Sandstrom wrote: >> > Jon Harrop wrote: >> >> I see no problem with mutable shared state. >> >> > In which case, Jon, you're in a small minority. >> >> No. Most programmers still care about performance > > Frequently when they shouldn't. I disagree. A lot of software is still far too slow because the programmers failed to pay attention to performance. Blogspot in Firefox being one example: it can barely keep up with my typing! >> and performance means mutable state. > > Hm, not sure Erlangers would wholly agree. Erlang is about concurrency. This thread is about parallelism. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From mrstevegross at gmail.com Tue Jun 9 14:59:43 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 11:59:43 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> > exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError >... > exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ Is there a single parent exception to all those? Or should I just write it as: try: ... catch Exception: ... Thanks, --Steve From jeff at jmcneil.net Tue Jun 9 15:06:00 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 9 Jun 2009 12:06:00 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: On Jun 9, 2:22?pm, mrstevegross wrote: > I'm trying to write a try/catch block to handle an "interrupted system > call". However, I can't seem to locate information on the actual > typename of the exception. Does anyone know what it would be? I want > my code to look like this: > > try: > ? ... > except InterruptedSystemCall # what's the right name? > ? ... > > Thanks, > --Steve You'll get that error when an async. event (signal) is delivered to your application during a system call. It's a result of 'errno' being set to errno.EINTR (4). I check for a few such specific conditions in some of my code and I usually do it like so: try: .... except EnvironmentError, e: if e.errno == errno.EINTR: do_something_with_eintr_error() else: raise That works for me. There isn't an "InterruptedSystemCall" error or equivalent in the standard exception hierarchy. EnvironmentError is the parent of OSError & IOError, which is where you'll most likely be encountering that state. Thanks, Jeff mcjeff.blogspot.com From bretrouse at gmail.com Tue Jun 9 15:09:15 2009 From: bretrouse at gmail.com (Bret) Date: Tue, 9 Jun 2009 12:09:15 -0700 (PDT) Subject: csv.reader has trouble with comma inside quotes inside brackets Message-ID: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> i have a csv file like so: row1,field1,[field2][text in field2 "quote, quote"],field3,field row2,field1,[field2]text in field2 "quote, quote",field3,field using csv.reader to read the file, the first row is broken into two fields: [field2][text in field2 "quote and quote" while the second row is read correctly with: [field2]text in field2 "quote, quote" being one field. any ideas how to make csv.reader work correctly for the first case? the problem is the comma inside the quote inside the brackets, ie: [","] From robert.kern at gmail.com Tue Jun 9 15:27:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 14:27:05 -0500 Subject: Start the interactive shell within an application In-Reply-To: <4A2E2215.1090405@sequans.com> References: <4A2E2215.1090405@sequans.com> Message-ID: On 2009-06-09 03:49, Jean-Michel Pichavant wrote: > I was wondering if there is a way to start an interactive shell within a > script/application. > I'm sometimes tired of adding prints to scan the current namespace so > I'd like to pause the execution and give the user the shell prompt. > This is obviously for debugging purpose. > > I know that I may use the raw_input and eval the captured text but > honestly, this requires some coding and I won't benefit from the shell > features. Would it be even possible to use a shell like Ipython ? http://ipython.scipy.org/doc/stable/html/interactive/reference.html#embedding-ipython > By the way, if anyone has cunning ways for debugging code to share, he > would be much welcome. You would do well to learn to use the standard Python debugger: http://docs.python.org/library/pdb -- 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 mrstevegross at gmail.com Tue Jun 9 15:29:17 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 12:29:17 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: <410f4586-8f45-42eb-ac96-e1d937a71129@o36g2000vbi.googlegroups.com> > That works for me. ?There isn't an "InterruptedSystemCall" error or > equivalent in the standard exception hierarchy. ?EnvironmentError is > the parent of OSError & IOError, which is where you'll most likely be > encountering that state. Thanks! --Steve From tjreedy at udel.edu Tue Jun 9 15:42:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 15:42:49 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. That is symmetry. > There is no string method to do it, which is what I am complaining > about. That would be asymmetry. > > Is there a reason for this, or is the lack of symmetry just an historical > artefact? A lack of perception to see the symmetry that is there. Classes create instances of the class when called. Sometimes alternate constructors are needed when there is more than one possible way to create an instance from a given input. In the case of str(iterable), one could want either a string representing the iterable itself, just as with non-iterables, or a string representing the concatenated contents of the iterable. Str.join implements the second choice, with an added string parameter to allow a constant string to be interpolated between the joined items. > The link that jon vs python supplied is interesting. Yes. Mr. Shaw suffers from the same disease of 'neglect' that he accuses others of. See my other response in this thread. Terry Jan Reedy From tjreedy at udel.edu Tue Jun 9 15:43:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 15:43:02 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: jon vs. python wrote: > Sorry, I didn't realize that you already proposed list comprehension. > > > There is some kind of asymmetry in several areas.I guess that's > somehow related to this post: > http://www.zedshaw.com/blog/2009-05-29.html The premise of this post by Zed the Insightful is that Python developers are like a homegenous bunch of brain-damaged people. Instead, they are a heterogenous group of volunteers, with rotating membership, at least some of whom are aware of the various issues he mentions, but who are constrained by both time limits and back compatibility. The constraint of back compatibility was loosened for 3.0. What contribution did Zed Shaw make toward improving the deficiencies he noted when he had a chance? I do not remember any. His excuse: "If I had the time I would try to fix this stuff, but I realize that none of this will be fixed until there?s a cultural shift in Python away from this habit of Neglect." This bogus excuse is Neglect on his part. I strongly suspect, based on experience with other Professional Critics / Ignored Prophets like him, that efforts to help him contribute would be ignored or rejected. Python and the stdlib is all open source. If he were to submit a patch, and it were ignored or rejected for whatever reason, he could still release it and register it on PyPI. I just checked and NONE of the 6710 submissions are his. "There?s many more places where this kind of neglect is found, but these days I just accept it and move on unless I seriously get pissed off. The last tool I did this to was argparse and optparse which I replaced with a much nicer system in Lamson." Perhaps someday he will share his "improved" version and let others judge and possibly use it. "For the longest time (at least until 2000 when I last looked)" he writes on 2009-05-29, NINE years later. A decent reviewer would look for updated info before criticizing. I happen to agree with the design principle of pairing inverse operations, but 1) starting the presentation of that principle with bogus ad hominen attacks discredits it; 2) there may be more than one way to implement the principle in particular, and people may reasonably disagree on the best way. See my other response in this thread on str.join. Terry Jan Reedy From mh at pixar.com Tue Jun 9 16:06:55 2009 From: mh at pixar.com (mh at pixar.com) Date: Tue, 09 Jun 2009 20:06:55 GMT Subject: setting program name, like $0= in perl? Message-ID: I'm sure this is a FAQ, but I certainly haven't been able to find an answer. Is it possible to set the program name as seen by the operating system or lower-level libraries? I'm connecting to a database, and the runtime helpfully sends some information to the server, such as username, pid, and program name. Unfortunately, all my python programs get the name '/usr/bin/python', and I would like to force that to be the names of the individual scripts. Many TIA! Mark -- Mark Harrison Pixar Animation Studios From gneuner2 at comcast.net Tue Jun 9 16:07:07 2009 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 09 Jun 2009 16:07:07 -0400 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On Tue, 9 Jun 2009 10:47:11 -0700 (PDT), toby wrote: >On Jun 7, 2:41?pm, Jon Harrop wrote: >> Arved Sandstrom wrote: >> > Jon Harrop wrote: >> >> performance means mutable state. > >Hm, not sure Erlangers would wholly agree. Erlang uses quite a bit of mutable state behind the scenes ... the programmers just don't see it. George From robert.kern at gmail.com Tue Jun 9 16:20:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 15:20:56 -0500 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: On 2009-06-09 14:43, Terry Reedy wrote: > jon vs. python wrote: >> Sorry, I didn't realize that you already proposed list comprehension. >> >> >> There is some kind of asymmetry in several areas.I guess that's >> somehow related to this post: http://www.zedshaw.com/blog/2009-05-29.html > > The premise of this post by Zed the Insightful is that Python developers > are like a homegenous bunch of brain-damaged people. Instead, they are a > heterogenous group of volunteers, with rotating membership, at least > some of whom are aware of the various issues he mentions, but who are > constrained by both time limits and back compatibility. > > The constraint of back compatibility was loosened for 3.0. What > contribution did Zed Shaw make toward improving the deficiencies he > noted when he had a chance? I do not remember any. > > His excuse: "If I had the time I would try to fix this stuff, but I > realize that none of this will be fixed until there?s a cultural shift > in Python away from this habit of Neglect." This bogus excuse is Neglect > on his part. I strongly suspect, based on experience with other > Professional Critics / Ignored Prophets like him, that efforts to help > him contribute would be ignored or rejected. > > Python and the stdlib is all open source. If he were to submit a patch, > and it were ignored or rejected for whatever reason, he could still > release it and register it on PyPI. I just checked and NONE of the 6710 > submissions are his. > > "There?s many more places where this kind of neglect is found, but these > days I just accept it and move on unless I seriously get pissed off. The > last tool I did this to was argparse and optparse which I replaced with > a much nicer system in Lamson." > > Perhaps someday he will share his "improved" version and let others > judge and possibly use it. To be fair: http://pypi.python.org/pypi/zapps/ http://pypi.python.org/pypi/lamson/ http://pypi.python.org/pypi/vellum/ http://pypi.python.org/pypi/idiopidae -- 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 Tue Jun 9 16:46:35 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 16:46:35 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> References: <796hh2F1p7fpkU1@mid.uni-berlin.de> <796q93F1p879rU1@mid.uni-berlin.de> <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> Message-ID: Miles Kaufmann wrote: > On Jun 9, 2009, at 6:05 AM, Diez B. Roggisch wrote: > >> Also as list-comps are going away and are replaced by >> >> list() > > Where did you hear that? Perhaps in the discussion of possible changes for 3.0 about 18 months ago. The idea was rejected because set/list/dict(genexp) is too much slower (say 2x) than the direct implementation of set/list/dict comprehensions. tjr From sjmachin at lexicon.net Tue Jun 9 17:03:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 9 Jun 2009 21:03:30 +0000 (UTC) Subject: csv.reader has trouble with comma inside quotes inside brackets References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: Bret gmail.com> writes: > > i have a csv file like so: > row1,field1,[field2][text in field2 "quote, quote"],field3,field > row2,field1,[field2]text in field2 "quote, quote",field3,field > > using csv.reader to read the file, the first row is broken into two > fields: > [field2][text in field2 "quote > and > quote" > > while the second row is read correctly with: > [field2]text in field2 "quote, quote" > being one field. > > any ideas how to make csv.reader work correctly for the first case? > the problem is the comma inside the quote inside the brackets, ie: > [","] I can't reproduce the behaviour that you describe based on these reasonable assumptions: Python 2.6, delimiter=',', quotechar='"': C:\junk\weird_csv>\python26\python Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. |>>> import pprint, csv |>>> open('weird.csv', 'rb').read() 'row1,field1,[field2][text in field2 "quote, quote"],field3,field\r\nrow2,field1 ,[field2]text in field2 "quote, quote",field3,field\r\n' >>> pprint.pprint(list(csv.reader(open('weird.csv', 'rb')))) [['row1', 'field1', '[field2][text in field2 "quote', ' quote"]', 'field3', 'field'], ['row2', 'field1', '[field2]text in field2 "quote', ' quote"', 'field3', 'field']] |>>> As you can see, it treats both lines in the same way. Opening the file with each of Microsoft Excel 2003, OpenOffice.org Calc 3, and Gnumeric has exactly the same effect. The problem is that your data has not been prepared using the generally accepted rules for quoting in CSV files: [pseudocode] if field contains any of quotechar, delimiter, newline, maybe others: field = (quotechar + field.replace(quotechar, quotechar + quotechar) + quotechar) which would change your first line from row1,field1,[field2][text in field2 "quote, quote"],field3,field to row1,field1,"[field2][text in field2 ""quote, quote""]",field3,field There's no option in the csv module to get around this, AFAICT. You'd have to roll your own, something along these lines (assumes no embedded newlines etc): 8<--- parse_unquoted_csv.py def parse_unquoted_csv(line, delimiter=',', quotechar='"'): line = line.strip() inside_quotes = False fields = [] field = '' for c in line: if inside_quotes: if c == quotechar: inside_quotes = False field += c else: if c == delimiter: fields.append(field) field = '' else: if c == quotechar: inside_quotes = True field += c if inside_quotes: print repr(line) print fields print repr(field) raise Exception("Quotes not balanced") fields.append(field) return fields if __name__ == "__main__": tests = [ 'row1,field1,[field2][text in field2 "quote, quote"],field3,field', 'row2,field1,[field2]text in field2 "quote, quote",field3,field', 'a,b,c', 'a,b,', '', 'Look,here"s,a,typo', ] for test in tests: print repr(test) print parse_unquoted_csv(test) print 8<--- HTH, John From bretrouse at gmail.com Tue Jun 9 17:15:14 2009 From: bretrouse at gmail.com (Bret) Date: Tue, 9 Jun 2009 14:15:14 -0700 (PDT) Subject: csv.reader has trouble with comma inside quotes inside brackets References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: <7fcdc208-3a11-4de6-bfb3-06debd56eb75@d31g2000vbm.googlegroups.com> Thanks John, I didn't realize that the quotes were supposed to surround the entire field. I ended up making a quick script to replace comma's outside quotes with tabs. I was just trying to clean this crazy "csv" file to import into msyql. thanks again, bret From fetchinson at googlemail.com Tue Jun 9 17:16:31 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 9 Jun 2009 14:16:31 -0700 Subject: setting program name, like $0= in perl? In-Reply-To: References: Message-ID: > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. I don't know the answer to your question but I would start by trying to figure out what information is really sent to the db. I mean it is probably an environment variable or something like that, and once you figure out exactly what it is, you will know what variable to set. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From emile at fenx.com Tue Jun 9 17:16:49 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 14:16:49 -0700 Subject: setting program name, like $0= in perl? In-Reply-To: References: Message-ID: On 6/9/2009 1:06 PM mh at pixar.com said... > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. If you include the shebang as first line and execute the script directly I think it'll work. ---- test.py---- #!/usr/bin/python import sys print sys.argv[0] ---------------- Emile > > Many TIA! > Mark > From tjreedy at udel.edu Tue Jun 9 17:27:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 17:27:13 -0400 Subject: csv.reader has trouble with comma inside quotes inside brackets In-Reply-To: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: Bret wrote: > i have a csv file like so: > row1,field1,[field2][text in field2 "quote, quote"],field3,field > row2,field1,[field2]text in field2 "quote, quote",field3,field > > using csv.reader to read the file, the first row is broken into two > fields: > [field2][text in field2 "quote > and > quote" > > while the second row is read correctly with: > [field2]text in field2 "quote, quote" > being one field. > > any ideas how to make csv.reader work correctly for the first case? > the problem is the comma inside the quote inside the brackets, ie: > [","] When posting, give version, minimum code that has problem, and actual output. Cut and past latter two. Reports are less credible otherwise. Using 3.1rc1 txt = [ '''row1,field1,[field2][text in field2 "quote, quote"],field3,field''', '''row2,field1,[field2] text in field2 "quote, quote", field3,field''', '''row2,field1, field2 text in field2 "quote, quote", field3,field''', ] import csv for row in csv.reader(txt): print(len(row),row) produces 6 ['row1', 'field1', '[field2][text in field2 "quote', ' quote"]', field3', 'field'] 6 ['row2', 'field1', '[field2] text in field2 "quote', ' quote"', ' field3', 'field'] 6 ['row2', 'field1', ' field2 text in field2 "quote', ' quote"', ' field3', 'field'] In 3.1 at least, the presence or absence of brackets is irrelevant, as I expected it to be. For double quotes to protect the comma delimiter, the *entire field* must be quoted, not just part of it. If you want to escape the delimiter without quoting entire fields, use an escape char and change the dialect. For example txt = [ '''row1,field1,[field2][text in field2 "quote`, quote"],field3,field''', '''row2,field1,[field2] text in field2 "quote`, quote", field3,field''', '''row2,field1, field2 text in field2 "quote`, quote", field3,field''', ] import csv for row in csv.reader(txt, quoting=csv.QUOTE_NONE, escapechar = '`'): print(len(row),row) produces what you desire 5 ['row1', 'field1', '[field2][text in field2 "quote, quote"]', 'field3', 'field'] 5 ['row2', 'field1', '[field2] text in field2 "quote, quote"', ' field3', 'field'] 5 ['row2', 'field1', ' field2 text in field2 "quote, quote"', ' field3', 'field'] Terry Jan Reedy From malkia at mac.com Tue Jun 9 17:28:54 2009 From: malkia at mac.com (Dimiter "malkia" Stanev) Date: Tue, 09 Jun 2009 14:28:54 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: > Erlang uses quite a bit of mutable state behind the scenes ... the > programmers just don't see it. > > George Heh... "The CPUs use quite a bit of mutable state behind the scenes ... the programmers just don't see it." Actually with CPU they see it more, than... say Erlang (that's why you need to use fences/barriers/locked access here and there). From ebonak at hotmail.com Tue Jun 9 17:33:39 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 17:33:39 -0400 Subject: random number including 1 - i.e. [0,1] Message-ID: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I am implementing an algorithm and want to stay as true to the original design specifications as possible though I suppose the difference between the two max values might be minimal. Thanks, Esmail ps: I'm confused by the docs for uniform(): random.uniform(a, b) Return a random floating point number N such that a <= N <= b for a <= b this seems to imply an inclusive range, ie. [a,b] but this seems to contradict it: In [3]: random.uniform? Type: instancemethod Base Class: String Form: > Namespace: Interactive File: /usr/lib/python2.6/random.py Definition: random.uniform(self, a, b) Docstring: Get a random number in the range [a, b). From tjreedy at udel.edu Tue Jun 9 17:34:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 17:34:19 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2009-06-09 14:43, Terry Reedy wrote: >> jon vs. python wrote: >> Python and the stdlib is all open source. If he were to submit a patch, >> and it were ignored or rejected for whatever reason, he could still >> release it and register it on PyPI. I just checked and NONE of the 6710 >> submissions are his. > To be fair: > > http://pypi.python.org/pypi/zapps/ > http://pypi.python.org/pypi/lamson/ > http://pypi.python.org/pypi/vellum/ > http://pypi.python.org/pypi/idiopidae Important correction noted. But how did you find those? When I search for 'Shaw' with the search box (I tried it again), I only get a couple of other, irrelevant hits. Is the search box buggy? tjr From emile at fenx.com Tue Jun 9 17:40:04 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 14:40:04 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On 6/9/2009 11:59 AM Jon Harrop said... > toby wrote: >> On Jun 7, 2:41 pm, Jon Harrop wrote: >>> No. Most programmers still care about performance >> Frequently when they shouldn't. > > I disagree. A lot of software is still far too slow because the programmers > failed to pay attention to performance. For a properly written spec, performance is spec'd and paid for. > Blogspot in Firefox being one > example: it can barely keep up with my typing! There are so many ways that's not the program. Performance,accuracy,cost -- pick two sacrifice one. Emile From steven.klass at gmail.com Tue Jun 9 18:00:51 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 15:00:51 -0700 (PDT) Subject: .pth files and figuring out valid paths.. Message-ID: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> I have a .pth file which has some logic in it - but it isn't quite enough... It started with this.. import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], "tools/python/modules")) But that eventually evolved into.. import os, site; site.addsitedir(os.path.join(os.environ.get ("TECHROOT", "/home/tech"), "tools/python/modules")) But now I want to check to make sure this directory exists or fall back to "/home/tech". That was the point of the environ.get but what if someone sets TECHROOT to /dev/null. Well that will break things... I tried this but no go. Can someone help me out.. import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- packages")) Apparently there is a problem with the if statement??? Thanks From pavlovevidence at gmail.com Tue Jun 9 18:06:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 15:06:21 -0700 (PDT) Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> On Jun 9, 12:42?pm, Terry Reedy wrote: > Hendrik van Rooyen wrote: > > I should have known - you use a string method to get a list of words, > > but you have to go to the list to get a list of characters from a string. > > That is symmetry. > > > There is no string method to do it, which is what I am complaining > > about. > > That would be asymmetry. > > > > > Is there a reason for this, or is the lack of symmetry just an historical > > artefact? > > A lack of perception to see the symmetry that is there. > > Classes create instances of the class when called. > > Sometimes alternate constructors are needed when there is more than one > possible way to create an instance from a given input. ?In the case of > str(iterable), one could want either a string representing the iterable > itself, just as with non-iterables, or a string representing the > concatenated contents of the iterable. ?Str.join implements the second > choice, with an added string parameter to allow a constant string to be > interpolated between the joined items. But then how do you rationalize str.split(), which is a method of str but a constructor of list? Perhaps instead of worrying about symmetry all the time we should just accept the inevitability that things will always be asymmetric and impure from someone's perspective. Terry's symmetry is Hendrik's asymmetry and vice versa. Carl Banks From stef.mientki at gmail.com Tue Jun 9 18:07:12 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 10 Jun 2009 00:07:12 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? Message-ID: <4A2EDD10.6090608@gmail.com> hello, I want to make a distro for Ubuntu, and run under Windows. I packed all sources with zipfile, but the compression doesn't seem to be very good. If run the created file through 7zip, it becomes anout half the size. Is there a way to accomplish the same task with zipfile ( the documentation isn't overwhelming). thanks, Stef Mientki From robert.kern at gmail.com Tue Jun 9 18:11:19 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 17:11:19 -0500 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: On 2009-06-09 16:34, Terry Reedy wrote: > Robert Kern wrote: >> On 2009-06-09 14:43, Terry Reedy wrote: >>> jon vs. python wrote: > >>> Python and the stdlib is all open source. If he were to submit a patch, >>> and it were ignored or rejected for whatever reason, he could still >>> release it and register it on PyPI. I just checked and NONE of the 6710 >>> submissions are his. > >> To be fair: >> >> http://pypi.python.org/pypi/zapps/ >> http://pypi.python.org/pypi/lamson/ >> http://pypi.python.org/pypi/vellum/ >> http://pypi.python.org/pypi/idiopidae > > Important correction noted. But how did you find those? When I search > for 'Shaw' with the search box (I tried it again), I only get a couple > of other, irrelevant hits. Is the search box buggy? I suspect so. I knew of most of them already, and Googling site:pypi.python.org picked up the rest. -- 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 Jun 9 18:17:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 17:17:14 -0500 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: On 2009-06-09 17:06, Carl Banks wrote: > On Jun 9, 12:42 pm, Terry Reedy wrote: >> Hendrik van Rooyen wrote: >>> I should have known - you use a string method to get a list of words, >>> but you have to go to the list to get a list of characters from a string. >> That is symmetry. >> >>> There is no string method to do it, which is what I am complaining >>> about. >> That would be asymmetry. >> >> >> >>> Is there a reason for this, or is the lack of symmetry just an historical >>> artefact? >> A lack of perception to see the symmetry that is there. >> >> Classes create instances of the class when called. >> >> Sometimes alternate constructors are needed when there is more than one >> possible way to create an instance from a given input. In the case of >> str(iterable), one could want either a string representing the iterable >> itself, just as with non-iterables, or a string representing the >> concatenated contents of the iterable. Str.join implements the second >> choice, with an added string parameter to allow a constant string to be >> interpolated between the joined items. > > But then how do you rationalize str.split(), which is a method of str > but a constructor of list? There is a difference between a "constructor of a type" and just "a method that returns a particular type". str.join() and str.split() are really examples of the latter. > Perhaps instead of worrying about symmetry all the time we should just > accept the inevitability that things will always be asymmetric and > impure from someone's perspective. Terry's symmetry is Hendrik's > asymmetry and vice versa. There is much wisdom in 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 emile at fenx.com Tue Jun 9 18:28:23 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 15:28:23 -0700 Subject: .pth files and figuring out valid paths.. In-Reply-To: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: On 6/9/2009 3:00 PM rh0dium said... > I have a .pth file which has some logic in it - but it isn't quite > enough... > > It started with this.. > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], > "tools/python/modules")) > > But that eventually evolved into.. > import os, site; site.addsitedir(os.path.join(os.environ.get > ("TECHROOT", "/home/tech"), "tools/python/modules")) > > But now I want to check to make sure this directory exists or fall > back to "/home/tech". That was the point of the environ.get but what > if someone sets TECHROOT to /dev/null. Well that will break > things... I tried this but no go. Can someone help me out.. > You're not really putting all this on one line are you? If so, that's a problem. > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if > not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > packages")) > Try it this way... import os, site smsc = os.environ.get("TECHROOT", "/home/tech") if not os.path.isdir(smsc): smsc = "/home/tech" site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site-packages")) Emile > Apparently there is a problem with the if statement??? > > Thanks > From mensanator at aol.com Tue Jun 9 19:05:05 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 16:05:05 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. > > Thanks, > Esmail > > ps: I'm confused by the docs for uniform(): > > random.uniform(a, b) > ? ? ?Return a random floating point number N such that a <= N <= b for a <= b That's wrong. Where did you get it? >>> help(random.uniform) Help on method uniform in module random: uniform(self, a, b) method of random.Random instance Get a random number in the range [a, b). > > this seems to imply an inclusive range, ie. [a,b] > > but this seems to contradict it: > > In [3]: random.uniform? > Type: ? ? ? ? ? instancemethod > Base Class: ? ? > String Form: ? ?> > Namespace: ? ? ?Interactive > File: ? ? ? ? ? /usr/lib/python2.6/random.py > Definition: ? ? random.uniform(self, a, b) > Docstring: > ? ? ?Get a random number in the range [a, b). From gagsl-py2 at yahoo.com.ar Tue Jun 9 19:05:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 20:05:45 -0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? I think you shouldn't worry about that - the difference may be as small as 2**-53, or 0.0000000000000001 > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. > > ps: I'm confused by the docs for uniform(): > > random.uniform(a, b) > Return a random floating point number N such that a <= N <= b for a > <= b > > this seems to imply an inclusive range, ie. [a,b] random() guarantees a semi-open interval (could return 0, but never 1). But once you start to operate with the numbers, the limits become fuzzy. a0 => n.a a=10.0 py> b=11.0 py> z = 0.9999999999999999 # assume random.random returned this py> z<1 True py> a+(b-a)*z < b # the expression used for uniform(a,b) False py> a+(b-a)*z 11.0 The docs are already updated to reflect this: http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=68724&r2=68723&pathrev=68724 -- Gabriel Genellina From robert.kern at gmail.com Tue Jun 9 19:12:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 18:12:52 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: On 2009-06-09 18:05, Mensanator wrote: > On Jun 9, 4:33 pm, Esmail wrote: >> Hi, >> >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? >> >> I am implementing an algorithm and want to stay as true to the >> original design specifications as possible though I suppose the >> difference between the two max values might be minimal. >> >> Thanks, >> Esmail >> >> ps: I'm confused by the docs for uniform(): >> >> random.uniform(a, b) >> Return a random floating point number N such that a<= N<= b for a<= b > > That's wrong. Where did you get it? http://docs.python.org/library/random -- 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 milesck at umich.edu Tue Jun 9 19:16:57 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 9 Jun 2009 19:16:57 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> On Jun 9, 2009, at 7:05 PM, Mensanator wrote: > On Jun 9, 4:33 pm, Esmail wrote: >> Hi, >> >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? >> >> I am implementing an algorithm and want to stay as true to the >> original design specifications as possible though I suppose the >> difference between the two max values might be minimal. I'm curious what algorithm calls for random numbers on a closed interval. >> ps: I'm confused by the docs for uniform(): >> >> random.uniform(a, b) >> Return a random floating point number N such that a <= N <= b >> for a <= b > > That's wrong. Where did you get it? http://docs.python.org/library/random.html -Miles From steven.klass at gmail.com Tue Jun 9 19:30:06 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 16:30:06 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> On Jun 9, 3:28?pm, Emile van Sebille wrote: > On 6/9/2009 3:00 PM rh0dium said... > > > > > > > I have a .pth file which has some logic in it - but it isn't quite > > enough... > > > It started with this.. > > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], > > "tools/python/modules")) > > > But that eventually evolved into.. > > import os, site; site.addsitedir(os.path.join(os.environ.get > > ("TECHROOT", "/home/tech"), "tools/python/modules")) > > > But now I want to check to make sure this directory exists or fall > > back to "/home/tech". ?That was the point of the environ.get but what > > if someone sets TECHROOT to /dev/null. ?Well that will break > > things... ?I tried this but no go. ?Can someone help me out.. > > You're not really putting all this on one line are you? ?If so, that's a > problem. > > > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if > > not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir > > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > > packages")) > > Try it this way... > > import os, site > smsc = os.environ.get("TECHROOT", "/home/tech") > if not os.path.isdir(smsc): > ? ? ?smsc = "/home/tech" > site.addsitedir (os.path.join(smsc, > "tools/python/Linux/%arch/lib/python2.5/site-packages")) > > Emile > > > > > Apparently there is a problem with the if statement??? > > > Thanks No for .pth files this needs to be on a single line.. From steve at REMOVE-THIS-cybersource.com.au Tue Jun 9 19:40:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 23:40:04 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> Message-ID: <023ee521$0$20636$c3e8da3@news.astraweb.com> On Tue, 09 Jun 2009 04:57:48 -0700, samwyse wrote: > Time to test things! I'm going to compare three things using Python > 3.0: > X={...}\nS=lambda x: x in X > S=lambda x: x in {...} > S=lambda x: x in (...) > where the ... is replaced by lists of integers of various lengths. > Here's the test bed: [snip] Hmmm... I think your test-bed is unnecessarily complicated, making it difficult to see what is going on. Here's my version, with lists included for completeness. Each test prints the best of five trials of one million repetitions of ten successful searches, then does the same thing again for unsuccessful searches. from timeit import Timer def test(size): global s, l, t, targets print("Testing search with size %d" % size) rng = range(size) s, l, t = set(rng), list(rng), tuple(rng) # Calculate a (more or less) evenly distributed set of ten # targets to search for, including both end points. targets = [i*size//9 for i in range(9)] + [size-1] assert len(targets) == 10 setup = "from __main__ import targets, %s" body = "for i in targets: i in %s" # Run a series of successful searches. for name in "s l t".split(): obj = globals()[name] secs = min(Timer(body % name, setup % name).repeat(repeat=5)) print("Successful search in %s: %f s" % (type(obj), secs)) # Also run unsuccessful tests. targets = [size+x for x in targets] for name in "s l t".split(): obj = globals()[name] secs = min(Timer(body % name, setup % name).repeat(repeat=5)) print("Unsuccessful search in %s: %f s" % (type(obj), secs)) Results are: >>> test(1) Testing search with size 1 Successful search in : 1.949509 s Successful search in : 1.838387 s Successful search in : 1.876309 s Unsuccessful search in : 1.998207 s Unsuccessful search in : 2.148660 s Unsuccessful search in : 2.137041 s >>> >>> >>> test(10) Testing search with size 10 Successful search in : 1.943664 s Successful search in : 3.659786 s Successful search in : 3.569164 s Unsuccessful search in : 1.935553 s Unsuccessful search in : 5.833665 s Unsuccessful search in : 5.573177 s >>> >>> >>> test(100) Testing search with size 100 Successful search in : 1.907839 s Successful search in : 21.704032 s Successful search in : 21.391875 s Unsuccessful search in : 1.916241 s Unsuccessful search in : 41.178029 s Unsuccessful search in : 41.856226 s >>> >>> >>> test(1000) Testing search with size 1000 Successful search in : 2.256150 s Successful search in : 189.991579 s Successful search in : 187.349630 s Unsuccessful search in : 1.869202 s Unsuccessful search in : 398.451284 s Unsuccessful search in : 388.544178 s As expected, lists and tuples are equally as fast (or slow if you prefer). Successful searches are about twice as fast as unsuccessful ones, and performance suffers as the size of the list/tuple increases. However, sets are nearly just as fast no matter the size of the set, or whether the search is successfully or unsuccessful. > You will note that testing against a list constant is just as fast as > testing against a set. This was surprising for me; apparently the > __contains__ operator turns a tuple into a set. I doubt that very much. -- Steven From gagsl-py2 at yahoo.com.ar Tue Jun 9 19:41:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 20:41:25 -0300 Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > I have an embedded python application. which is a MFC app with > Python interpreter embedded. > > In the App, I have a separate thread to execute a Python script > (using the PyRun_File), but if the user want to stop the executing > script, how should I do? > > A possible way is terminate the thread of executing the scripts by > TerminateThread(). but TerminateThread() is unsafe and not > recommended. > > guys, could you guide me on this? You could use PyThreadState_SetAsyncExc (to "inject" an exception), or perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a KeyboardInterrupt). This should work fine for well-behaved scripts, but if it ignores all exceptions like this: try: ... except: pass you'll have to look at ceval.c how to break out of the running loop. (this is yet another argument against indiscriminately using a bare except clause...) -- Gabriel Genellina From ebonak at hotmail.com Tue Jun 9 19:53:22 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:53:22 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: <4A2EF5F2.9080902@hotmail.com> Gabriel Genellina wrote: > En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? > > I think you shouldn't worry about that - the difference may be as small > as 2**-53, or 0.0000000000000001 Ok, that's what I thought ... > random() guarantees a semi-open interval (could return 0, but never 1). > But once you start to operate with the numbers, the limits become fuzzy. > > a0 => n.a > The above holds for real numbers but not always for floating point > arithmetic, so one cannot guarantee the semi-open interval anymore: > > py> a=10.0 > py> b=11.0 > py> z = 0.9999999999999999 # assume random.random returned this > py> z<1 > True > py> a+(b-a)*z < b # the expression used for uniform(a,b) > False > py> a+(b-a)*z > 11.0 > > The docs are already updated to reflect this: > http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=68724&r2=68723&pathrev=68724 Thanks for the information Gabriel, Esmail From ebonak at hotmail.com Tue Jun 9 19:54:15 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:54:15 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Robert Kern wrote: > On 2009-06-09 18:05, Mensanator wrote: >> On Jun 9, 4:33 pm, Esmail wrote: >> >> >> That's wrong. Where did you get it? > > http://docs.python.org/library/random What he said :-) (thanks Robert) From ebonak at hotmail.com Tue Jun 9 19:57:50 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:57:50 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> References: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> Message-ID: <4A2EF6FE.4080506@hotmail.com> Miles Kaufmann wrote: > > I'm curious what algorithm calls for random numbers on a closed interval. I'm implementing a Particle Swarm Optimizer. Depending on what paper you read you'll see mention of required random values "between 0 and 1" which is somewhat ambiguous. I came across one paper that specified the range [0,1], so inclusive 1, which was the reason for my question. (I'm still looking for other papers to see if I can get more information exactly on the range) I think in the end it probably doesn't matter if it's [0, 1) or [0, 1] as the max values for each will probably be very close. Esmail From david.lyon at preisshare.net Tue Jun 9 19:58:37 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 09 Jun 2009 19:58:37 -0400 Subject: .pth files and figuring out valid paths.. In-Reply-To: <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: <77c1ea77978b97f67b133cfe02c7441c@preisshare.net> On Tue, 9 Jun 2009 16:30:06 -0700 (PDT), rh0dium wrote: >> > Apparently there is a problem with the if statement??? >> >> > Thanks > > No for .pth files this needs to be on a single line.. I can't really see why you need conditional code... If you want to add more locations... Simply create another .PTH file..... Having multiple paths or multiple .PTH files isn't a problem for python. David From mensanator at aol.com Tue Jun 9 20:27:13 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 17:27:13 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 6:12?pm, Robert Kern wrote: > On 2009-06-09 18:05, Mensanator wrote: > > > > > > > On Jun 9, 4:33 pm, Esmail ?wrote: > >> Hi, > > >> random.random() will generate a random value in the range [0, 1). > > >> Is there an easy way to generate random values in the range [0, 1]? > >> I.e., including 1? > > >> I am implementing an algorithm and want to stay as true to the > >> original design specifications as possible though I suppose the > >> difference between the two max values might be minimal. > > >> Thanks, > >> Esmail > > >> ps: I'm confused by the docs for uniform(): > > >> random.uniform(a, b) > >> ? ? ? Return a random floating point number N such that a<= N<= b for a<= b > > > That's wrong. Where did you get it? > > http://docs.python.org/library/random Ok, but the 2.6.1 docs say random.uniform(a, b) Return a random floating point number N such that a <= N < b for a <= b and b <= N < a for b < a. Is that a new feature of 2.6.2? > > -- > 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- Hide quoted text - > > - Show quoted text - From ptmcg at austin.rr.com Tue Jun 9 20:39:10 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Jun 2009 17:39:10 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > Are you trying to generate a number in the range [0,n] by multiplying a random function that returns [0,1] * n? If so, then you want to do this using: int(random.random()*(n+1)) This will give equal chance of getting any number from 0 to n. If you had a function that returned a random in the range [0,1], then multiplying by n and then truncating would give only the barest sliver of a chance of giving the value n. You could try rounding, but then you get this skew: 0 for values [0, 0.5) (width of 0.5) 1 for value [0.5, 1.5) (width of 1) ... n for value [n-0.5, n] (width of ~0.50000000000000001) Still not a uniform die roll. You have only about 1/2 the probability of getting 0 or n as any other value. If you want to perform a fair roll of a 6-sided die, you would start with int(random.random() * 6). This gives a random number in the range [0,5], with each value of the same probability. How to get our die roll that goes from 1 to 6? Add 1. Thus: die_roll = lambda : int(random.random() * 6) + 1 Or for a n-sided die: die_roll = lambda n : int(random.random() * n) + 1 This is just guessing on my part, but otherwise, I don't know why you would care if random.random() returned values in the range [0,1) or [0,1]. -- Paul From mensanator at aol.com Tue Jun 9 20:45:05 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 17:45:05 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > > > random.random() will generate a random value in the range [0, 1). > > > Is there an easy way to generate random values in the range [0, 1]? > > I.e., including 1? > > I think you shouldn't worry about that - the difference may be as small as ? > 2**-53, or 0.0000000000000001 > > > I am implementing an algorithm and want to stay as true to the > > original design specifications as possible though I suppose the > > difference between the two max values might be minimal. > > > ps: I'm confused by the docs for uniform(): > > > random.uniform(a, b) > > ? ? ?Return a random floating point number N such that a <= N <= b for a ? > > <= b > > > this seems to imply an inclusive range, ie. [a,b] > > random() guarantees a semi-open interval (could return 0, but never 1). ? > But once you start to operate with the numbers, the limits become fuzzy. > > a0 => n.a > The above holds for real numbers but not always for floating point ? > arithmetic, so one cannot guarantee the semi-open interval anymore: > > py> a=10.0 > py> b=11.0 > py> z = 0.9999999999999999 ?# assume random.random returned this > py> z<1 > True That means the interval is still [0,1). To put it another way: >>> z=0.9999999999999999 >>> z==1 False > py> a+(b-a)*z < b # the expression used for uniform(a,b) > False > py> a+(b-a)*z > 11.0 What you do with the number after it's created is not random's concern. > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... The docs are now wrong. Why would they do that? > > -- > Gabriel Genellina From matt at tplus1.com Tue Jun 9 21:12:59 2009 From: matt at tplus1.com (Matthew Wilson) Date: Wed, 10 Jun 2009 01:12:59 GMT Subject: Where should I store docs in my project? Message-ID: I used paster to create a project named pitz. I'm writing a bunch of user documentation. Where should I put it? The project looks a little like this: /home/matt/projects/pitz setup.py pitz/ __init__.py # has my project code docs/ # has my reST files tests # has some tests Is there a convention for where to put the docs folder? From gallium.arsenide at gmail.com Tue Jun 9 21:28:23 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 18:28:23 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 8:45?pm, Mensanator wrote: > On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > False > > py> a+(b-a)*z > > 11.0 > > What you do with the number after it's created is not > random's concern. Mensanator, you missed Gabriel's point. What he's saying is that, effectively, random.uniform(a, b) returns a + (b - a) * random.random (). So z may not be random()'s concern, but it very much is uniform ()'s concern. > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... > > The docs are now wrong. Why would they do that? The docs are now... sort of correct. For some values of a and b, uniform() can never return b. Notably, I believe uniform(0, 1) is equivalent to random(), and will never return 1. However, uniform(1, 2) CAN return 2, if this is any indication: >>> a=0.0 >>> b=1.0 >>> a+(b-a)*z < b True >>> a=1.0 >>> b=2.0 >>> a+(b-a)*z < b False John From gallium.arsenide at gmail.com Tue Jun 9 21:32:57 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 18:32:57 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> Message-ID: On Jun 9, 8:39?pm, Paul McGuire wrote: > Are you trying to generate a number in the > range [0,n] by multiplying a random function that > returns [0,1] * n? ?If so, then you want to do > this using: int(random.random()*(n+1)) ?This will > give equal chance of getting any number from 0 to n. Better still is simply random.randint(0, n) For other discrete random choices, you may find randrange() or choice () useful. John From myopc at aaa.com Tue Jun 9 21:39:58 2009 From: myopc at aaa.com (myopc) Date: Wed, 10 Jun 2009 09:39:58 +0800 Subject: multi-thread python interpreaters and c++ program References: Message-ID: thanks for your reply! "Lie Ryan" $y61.12599 at news-server.bigpond.net.au... > myopc wrote: >> hi, all >> I am ruuning a c++ program (boost python) , which create many python >> interpreaters and each run a python script with use multi-thread >> (threading). >> when the c++ main program exit, I want to shut down python >> interpreaters, but it crashed. I have googled a lot but cant get any >> clue. >> here is my code, your suggestion will be greatly appreciated. >> > > There is no clean way to terminate a thread cleanly from outside. You > need to let the thread terminates by itself. If it is a pure python > code, this can be done by one of: > 1) setting a global/thread stop value that is checked by each threads > 2) inserting a QUIT event to the event-loop > > > I have never used boost before, so I don't know what it can and cannot > do from outside the python's interpreter. However, this should give you > an idea of what to do... From kongcheng1400 at gmail.com Tue Jun 9 21:44:07 2009 From: kongcheng1400 at gmail.com (kongcheng1400 at gmail.com) Date: Tue, 9 Jun 2009 18:44:07 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: <34c08046-aeae-460f-87e9-dd72e0639b8d@v4g2000vba.googlegroups.com> On Jun 10, 7:41?am, "Gabriel Genellina" wrote: > En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > > > ? ?I have an embedded python application. which is ?a MFC app with > > Python interpreter embedded. > > > ? ?In the App, I have a separate thread to execute a Python script > > (using the PyRun_File), but if the user want to stop the executing > > script, how should I do? > > > A possible way is terminate the thread of executing the scripts by > > TerminateThread(). but TerminateThread() is unsafe and not > > recommended. > > > guys, could you guide me on this? > > You could use PyThreadState_SetAsyncExc (to "inject" an exception), or ? > perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a ? > KeyboardInterrupt). This should work fine for well-behaved scripts, but if ? > it ignores all exceptions like this: > ? ? ? ? try: ... > ? ? ? ? except: pass > you'll have to look at ceval.c how to break out of the running loop. > > (this is yet another argument against indiscriminately using a bare except ? > clause...) > > -- > Gabriel Genellina Thanks Very much, You are always kindly helping me. From dcest61 at hotmail.com Tue Jun 9 22:08:36 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Wed, 10 Jun 2009 02:08:36 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Lew wrote: >>>>> Interesting distinction. Would it be fair to compare concurrent >>>>> programming to the bricks used to build the parallel program's edifice? >>>> Way too much of a fine distinction. While they are in fact different, >>>> the point of concurrent programming is to structure programs as a group >>>> of computations, which can be executed in parallel (however that might >>>> actually be done depending on how many processors there are). >>> No. Concurrent programming is about interleaving computations in order to >>> reduce latency. Nothing to do with parallelism. >> Jon, I do concurrent programming all the time, as do most of my peers. >> Way down on the list of why we do it is the reduction of latency. > > What is higher on the list? Correctness. I'm not being facetious. I write applications that run on application servers, and from time to time I have had to write various special purpose servers. This kind of programming is all about managing concurrent execution of computations. The overarching concern is reliability and correct function. For many corporate situations, even with hundreds of users, the actual load at any instant is low enough that the various servers involved are nowhere close to being stressed out - performance is a secondary issue. AHS From steven at REMOVE.THIS.cybersource.com.au Tue Jun 9 23:24:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 03:24:07 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > The docs are now... sort of correct. For some values of a and b, > uniform() can never return b. Notably, I believe uniform(0, 1) is > equivalent to random(), and will never return 1. However, uniform(1, 2) > CAN return 2, if this is any indication: > > >>>> a=0.0 >>>> b=1.0 >>>> a+(b-a)*z < b > True >>>> a=1.0 >>>> b=2.0 >>>> a+(b-a)*z < b > False But you haven't shown what value z has, so there's no way of interpreting that example. I'd say that uniform(1, 2) should NOT return 2, at least for systems which round correctly. Given a random z such that: 0 <= z < 1 and two floats a, b such that: a < b (b is strictly the larger of the two) then: 0 <= z < 1 Multiply all sides by (b-a): 0 <= (b-a)*z < (b-a) Add a to all sides: a <= a + (b-a)*z < b Hence uniform(a, b) should always return a result less than b, and greater or equal to a. However, there is one proviso: floats are not reals. The above holds true for real numbers, but floats are subject to weird rounding effects. That means that there may be weird edge cases where Bad Things happen and things cancel catastrophically or round incorrectly. A realistic edge case is that a + (b-a) doesn't always give b: >>> a = -1e90 >>> b = 1.0 >>> a < b True >>> a + (b-a) == b False >>> a + (b-a) 0.0 However, even in this case, it merely narrows the range of possible results, it doesn't widen it. -- Steven From mr.william.clifford at gmail.com Tue Jun 9 23:58:54 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Tue, 9 Jun 2009 20:58:54 -0700 (PDT) Subject: graph edge generators Message-ID: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> I've become interested in basic graphs and networks and I'm wondering about what algorithms are there for generating basic regular graphs like the simplex graph or dodecahedron graph, etc (I'm sure there are many). I'm particularly keen on understanding the very basic functions for determining edges in the graphs. If one didn't want the complete graph but just a function generates the edges connected to a given node. I've been surfing around for this sort of info, but I'm having trouble finding stuff at my level. If anyone knows of any resources or tutorials or that sort of thing, I'd like to hear about those too. Thanks! -- William Clifford From wuwei23 at gmail.com Wed Jun 10 00:01:46 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:01:46 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> Message-ID: <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> On Jun 10, 11:32?am, John Yeung wrote: > On Jun 9, 8:39?pm, Paul McGuire wrote: > > Are you trying to generate a number in the > > range [0,n] by multiplying a random function that > > returns [0,1] * n? ?If so, then you want to do > > this using: int(random.random()*(n+1)) ?This will > > give equal chance of getting any number from 0 to n. > > Better still is simply > > ? random.randint(0, n) There's a big difference between randint - which generates _integers_ in the range 0 & n - and the OPs request for generating random floating point values between & inclusive of 0 & n. From rvf0068 at gmail.com Wed Jun 10 00:03:58 2009 From: rvf0068 at gmail.com (Rafael) Date: Tue, 09 Jun 2009 23:03:58 -0500 Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: <87iqj4d9ap.fsfhello@somewhere.com> William Clifford writes: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs > like the simplex graph or dodecahedron graph, etc (I'm sure there are > many). I'm particularly keen on understanding the very basic functions > for determining edges in the graphs. If one didn't want the complete > graph but just a function generates the edges connected to a given > node. probably the SAGE system (www.sagemath.org) would be of interest to you. From mensanator at aol.com Wed Jun 10 00:04:49 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 21:04:49 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 8:28?pm, John Yeung wrote: > On Jun 9, 8:45?pm, Mensanator wrote: > > > On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > > False > > > py> a+(b-a)*z > > > 11.0 > > > What you do with the number after it's created is not > > random's concern. > > Mensanator, you missed Gabriel's point. ?What he's saying is that, > effectively, random.uniform(a, b) returns a + (b - a) * random.random > (). ?So z may not be random()'s concern, but it very much is uniform > ()'s concern. > > > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... > > > The docs are now wrong. Why would they do that? > > The docs are now... sort of correct. ? I'm not actually disputing that. I'm simply puzzled why this issue was swept under the rug by pretending it's supposed to work that way. We're not children here, you can explain that what is supposed to work in theory sometimes has problems in practice. We're not all going to abandon Python and run out and buy Mathematica. Look at how the change of random to the Mersenne Twister was handled. That's what we, the users, want to see. Otherwise, it creates endless confusion. Maybe something along the lines of "Changed in 2.6.2 to reflect the realities of floating point math." That way, when a contradiction arises, we'll know why. > For some values of a and b, > uniform() can never return b. ?Notably, I believe uniform(0, 1) is > equivalent to random(), and will never return 1. ?However, uniform(1, > 2) CAN return 2, if this is any indication: > > >>> a=0.0 > >>> b=1.0 > >>> a+(b-a)*z < b > True > >>> a=1.0 > >>> b=2.0 > >>> a+(b-a)*z < b > > False > > John From danb_83 at yahoo.com Wed Jun 10 00:06:49 2009 From: danb_83 at yahoo.com (AggieDan04) Date: Tue, 9 Jun 2009 21:06:49 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <1243c288-ee59-4110-becc-004b926d6def@i6g2000yqj.googlegroups.com> On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? You could do random.uniform(0, 1.0000000000000002). Due to floating- point rounding, there are TWO original values that would return 1.0: 0.99999999999999978 or 0.99999999999999989; this may give you more 1.0's than you expected, and that's not even considering that Python's PRNG could be non-uniformly-distributed over the 53-bit fractions. If you're nit-picky enough to care about the less-than-winning-the- lottery chance of getting the maximum random value in the first place, this might be a problem. From wuwei23 at gmail.com Wed Jun 10 00:07:27 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:07:27 -0700 (PDT) Subject: Start the interactive shell within an application References: Message-ID: <64a786dd-eb62-40dc-98c9-05ec865546d0@s28g2000vbp.googlegroups.com> On Jun 10, 1:40?am, Ben Charrow wrote: > If you're looking to debug your program, try "import pdb" Another option, if you wish to debug an error, is to run python using the -i parameter. This will leave you inside the interpreter at the point that execution stops. Very handy. - alex23 From 504crank at gmail.com Wed Jun 10 00:13:33 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:13:33 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator Message-ID: By what method would a string be inserted at each instance of a RegEx match? For example: string = '123 abc 456 def 789 ghi' newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Here's the code I started with: >>> rePatt = re.compile('\d+\s') >>> iterator = rePatt.finditer(string) >>> count = 0 >>> for match in iterator: if count < 1: print string[0:match.start()] + ' INSERT ' + string[match.start ():match.end()] elif count >= 1: print ' INSERT ' + string[match.start():match.end()] count = count + 1 My code returns an empty string. I'm new to Python, but I'm finding it really enjoyable (with the exception of this challenging puzzle). Thanks in advance. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 00:15:00 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 04:15:00 GMT Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 20:58:54 -0700, William Clifford wrote: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs like > the simplex graph or dodecahedron graph, etc (I'm sure there are many). > I'm particularly keen on understanding the very basic functions for > determining edges in the graphs. If one didn't want the complete graph > but just a function generates the edges connected to a given node. > > I've been surfing around for this sort of info, but I'm having trouble > finding stuff at my level. If anyone knows of any resources or tutorials > or that sort of thing, I'd like to hear about those too. I'm not sure what your level is, but you might find these helpful: http://www.python.org/doc/essays/graphs/ http://neopythonic.blogspot.com/2009/01/detecting-cycles-in-directed-graph.html -- Steven From roy at panix.com Wed Jun 10 00:19:08 2009 From: roy at panix.com (Roy Smith) Date: Wed, 10 Jun 2009 00:19:08 -0400 Subject: How to insert string in each match using RegEx iterator References: Message-ID: In article , "504crank at gmail.com" <504crank at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' If you want to do what I think you are saying, you should be looking at the join() string method. I'm thinking something along the lines of: groups = match_object.groups() newstring = " INSERT ".join(groups) From wuwei23 at gmail.com Wed Jun 10 00:19:41 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:19:41 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: <45c999ce-ec0d-4470-b337-fd77ea6196b8@j20g2000vbp.googlegroups.com> On Jun 10, 8:00?am, rh0dium wrote: > Apparently there is a problem with the if statement??? Try restructuring the if as a ternary condition: import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); smsc = smsc if os.path.isdir(smsc) else "/home/tech"; site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- packages")) From ebonak at hotmail.com Wed Jun 10 00:23:11 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 10 Jun 2009 00:23:11 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Here is part of the specification of an algorithm I'm implementing that shows the reason for my original query: vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) xid = xid + vid (1b) where c1 and c2 are two positive constants, rand() and Rand() are two random functions in the range [0,1], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and w is the inertia weight. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 00:28:56 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 04:28:56 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 21:04:49 -0700, Mensanator wrote: > On Jun 9, 8:28?pm, John Yeung wrote: >> On Jun 9, 8:45?pm, Mensanator wrote: >> >> > On Jun 9, 6:05?pm, "Gabriel Genellina" >> > wrote: >> > > py> a+(b-a)*z < b # the expression used for uniform(a,b) False >> > > py> a+(b-a)*z >> > > 11.0 >> >> > What you do with the number after it's created is not random's >> > concern. >> >> Mensanator, you missed Gabriel's point. ?What he's saying is that, >> effectively, random.uniform(a, b) returns a + (b - a) * random.random >> (). ?So z may not be random()'s concern, but it very much is uniform >> ()'s concern. >> >> > > The docs are already updated to reflect >> > > this:http://svn.python.org/view/python/trunk/Doc/library/ random.rst?r1=687... >> >> > The docs are now wrong. Why would they do that? >> >> The docs are now... sort of correct. ? > > I'm not actually disputing that. Funny, saying "The docs are now wrong" sure sounds like you're disputing that they're correct to me! > I'm simply puzzled why this issue was > swept under the rug by pretending it's supposed to work that way. I'm completely confused. What is "this issue", and why are we "pretending" that it's supposed to work "that way"? Yes, I've read the thread. I still have no idea what you are complaining about. > We're > not children here, you can explain that what is supposed to work in > theory sometimes has problems in practice. We're not all going to > abandon Python and run out and buy Mathematica. > > Look at how the change of random to the Mersenne Twister was handled. > That's what we, the users, want to see. Speak for yourself. What about the change that you think "we, the users", want to see? > Otherwise, it creates endless confusion. Not as confused as this discussion. -- Steven From steven.klass at gmail.com Wed Jun 10 00:30:09 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 21:30:09 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <45c999ce-ec0d-4470-b337-fd77ea6196b8@j20g2000vbp.googlegroups.com> Message-ID: <2efd72e8-a683-46f3-bfc6-241626f181bf@l12g2000yqo.googlegroups.com> On Jun 9, 9:19?pm, alex23 wrote: > On Jun 10, 8:00?am, rh0dium wrote: > > > Apparently there is a problem with the if statement??? > > Try restructuring the if as a ternary condition: > > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); smsc > = smsc if os.path.isdir(smsc) else "/home/tech"; site.addsitedir > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > packages")) Bingo - Nice Job!! Thanks! I had to look up ternary conditions!! That's new for me (http://en.wikipedia.org/wiki/Ternary_operation) From steven.klass at gmail.com Wed Jun 10 00:33:56 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 21:33:56 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: On Jun 9, 4:58?pm, David Lyon wrote: > On Tue, 9 Jun 2009 16:30:06 -0700 (PDT), rh0dium > wrote: > > >> > Apparently there is a problem with the if statement??? > > >> > Thanks > > > No for .pth files this needs to be on a single line.. > > I can't really see why you need conditional code... > > If you want to add more locations... > > Simply create another .PTH file..... > > Having multiple paths or multiple .PTH files isn't a > problem for python. > > David We use it for our dev tree before we roll to production. Once dev is QA'd then we (integrate) those changes to main and release. From 504crank at gmail.com Wed Jun 10 00:35:37 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:35:37 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 9, 11:19?pm, Roy Smith wrote: > In article > , > > ?"504cr... at gmail.com" <504cr... at gmail.com> wrote: > > By what method would a string be inserted at each instance of a RegEx > > match? > > > For example: > > > string = '123 abc 456 def 789 ghi' > > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > If you want to do what I think you are saying, you should be looking at the > join() string method. ?I'm thinking something along the lines of: > > groups = match_object.groups() > newstring = " INSERT ".join(groups) Fast answer, Roy. Thanks. That would be a graceful solution if it works. I'll give it a try and post a solution. Meanwhile, I know there's a logical problem with the way I was concatenating strings in the iterator loop. Here's a single instance example of what I'm trying to do: >>> string = 'abc 123 def 456 ghi 789' >>> match = rePatt.search(string) >>> print string[0:match.start()] + 'INSERT ' + string[match.end():len(string)] abc INSERT def 456 ghi 789 From david.lyon at preisshare.net Wed Jun 10 00:37:15 2009 From: david.lyon at preisshare.net (David Lyon) Date: Wed, 10 Jun 2009 00:37:15 -0400 Subject: .pth files and figuring out valid paths.. In-Reply-To: References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: <955209ed293fd8185186e966b4b92892@preisshare.net> On Tue, 9 Jun 2009 21:33:56 -0700 (PDT), rh0dium wrote: >> Having multiple paths or multiple .PTH files isn't a >> problem for python. > .. > We use it for our dev tree before we roll to production. Once dev is > QA'd then we (integrate) those changes to main and release. Makes sense... :-) I was just wondering... From 504crank at gmail.com Wed Jun 10 00:52:36 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:52:36 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 9, 11:35?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > On Jun 9, 11:19?pm, Roy Smith wrote: > > > > > In article > > , > > > ?"504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > > match? > > > > For example: > > > > string = '123 abc 456 def 789 ghi' > > > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > > If you want to do what I think you are saying, you should be looking at the > > join() string method. ?I'm thinking something along the lines of: > > > groups = match_object.groups() > > newstring = " INSERT ".join(groups) > > Fast answer, Roy. Thanks. That would be a graceful solution if it > works. I'll give it a try and post a solution. > > Meanwhile, I know there's a logical problem with the way I was > concatenating strings in the iterator loop. > > Here's a single instance example of what I'm trying to do: > > >>> string = 'abc 123 def 456 ghi 789' > >>> match = rePatt.search(string) > >>> print string[0:match.start()] + 'INSERT ' + string[match.end():len(string)] > > abc INSERT def 456 ghi 789 Thanks Roy. A little closer to a solution. I'm still processing how to step forward, but this is a good start: >>> string = 'abc 123 def 456 ghi 789' >>> rePatt = re.compile('\s\d+\s') >>> foundGroup = rePatt.findall(string) >>> newstring = ' INSERT '.join(foundGroup) >>> print newstring 123 INSERT 456 What I really want to do is return the full string, not just the matches -- concatenated around the ' INSERT ' string. From gallium.arsenide at gmail.com Wed Jun 10 01:21:26 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 22:21:26 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 11:24?pm, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > > The docs are now... sort of correct. ?For some values of a and b, > > uniform() can never return b. ?Notably, I believe uniform(0, 1) is > > equivalent to random(), and will never return 1. ?However, uniform(1, 2) > > CAN return 2, if this is any indication: > > >>>> a=0.0 > >>>> b=1.0 > >>>> a+(b-a)*z < b > > True > >>>> a=1.0 > >>>> b=2.0 > >>>> a+(b-a)*z < b > > False > > But you haven't shown what value z has, so there's no way of interpreting > that example. I'm pretty aggressive about snipping. I left off the quote of z from Gabriel. He chose z to be the largest value that random.random() can return; namely, the largest float smaller than 1. I've just carried over that value into my example. The point of my example is, with z < 1, uniform(0, 1) is always less than 1, but with z < 1, uniform(1, 2) can be 2, according to Gabriel's description of uniform(). Therefore, to me the most up-to-date docs (which say that uniform(a, b) returns a float in the closed interval [a, b]) is closer to correct than before, but still fails to point out the full subtlety of the behavior. John From gallium.arsenide at gmail.com Wed Jun 10 01:24:55 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 22:24:55 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> Message-ID: <0581c89e-4e61-4a9b-9032-cfcd1b88ef81@y9g2000yqg.googlegroups.com> On Jun 10, 12:01?am, alex23 wrote: > On Jun 10, 11:32?am, John Yeung wrote: > > > On Jun 9, 8:39?pm, Paul McGuire wrote: > > > Are you trying to generate a number in the > > > range [0,n] by multiplying a random function that > > > returns [0,1] * n? ?If so, then you want to do > > > this using: int(random.random()*(n+1)) ?This will > > > give equal chance of getting any number from 0 to n. > > > Better still is simply > > > ? random.randint(0, n) > > There's a big difference between randint - which generates _integers_ > in the range 0 & n - and the OPs request for generating random > floating point values between & inclusive of 0 & n. Alex, did you bother to read what I quoted? Paul McGuire suggested an alternative in case the OP was choosing integers in a roundabout way. I was merely pointing out that Paul's solution can be more simply achieved using a library function. John From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 01:52:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 05:52:01 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > On Jun 9, 11:24?pm, Steven D'Aprano > wrote: >> On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: >> > The docs are now... sort of correct. ?For some values of a and b, >> > uniform() can never return b. ?Notably, I believe uniform(0, 1) is >> > equivalent to random(), and will never return 1. ?However, uniform(1, >> > 2) CAN return 2, if this is any indication: >> >> >>>> a=0.0 >> >>>> b=1.0 >> >>>> a+(b-a)*z < b >> > True >> >>>> a=1.0 >> >>>> b=2.0 >> >>>> a+(b-a)*z < b >> > False >> >> But you haven't shown what value z has, so there's no way of >> interpreting that example. > > I'm pretty aggressive about snipping. I left off the quote of z from > Gabriel. He chose z to be the largest value that random.random() can > return; namely, the largest float smaller than 1. I've just carried > over that value into my example. > > The point of my example is, with z < 1, uniform(0, 1) is always less > than 1, but with z < 1, uniform(1, 2) can be 2, according to Gabriel's > description of uniform(). Ah, that explains it. And you're right: >>> import random >>> class MyRandom(random.Random): ... def random(self): ... return 1.0 - 2**-53 ... >>> r = MyRandom() >>> r.uniform(1, 2) < 2 False However: >>> r.uniform(1, 10) < 10 True > Therefore, to me the most up-to-date docs (which say that uniform(a, b) > returns a float in the closed interval [a, b]) is closer to correct than > before, but still fails to point out the full subtlety of the behavior. Which is? -- Steven From mensanator at aol.com Wed Jun 10 01:54:21 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 22:54:21 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <6bdfae00-db9a-42f4-865f-500eaf35881a@e21g2000yqb.googlegroups.com> On Jun 9, 11:28?pm, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 21:04:49 -0700, Mensanator wrote: > > On Jun 9, 8:28 pm, John Yeung wrote: > >> On Jun 9, 8:45 pm, Mensanator wrote: > > >> > On Jun 9, 6:05 pm, "Gabriel Genellina" > >> > wrote: > >> > > py> a+(b-a)*z < b # the expression used for uniform(a,b) False > >> > > py> a+(b-a)*z > >> > > 11.0 > > >> > What you do with the number after it's created is not random's > >> > concern. > > >> Mensanator, you missed Gabriel's point. What he's saying is that, > >> effectively, random.uniform(a, b) returns a + (b - a) * random.random > >> (). So z may not be random()'s concern, but it very much is uniform > >> ()'s concern. > > >> > > The docs are already updated to reflect > >> > > this:http://svn.python.org/view/python/trunk/Doc/library/ > > random.rst?r1=687... > > > > >> > The docs are now wrong. Why would they do that? > > >> The docs are now... sort of correct. > > > I'm not actually disputing that. > > Funny, saying "The docs are now wrong" sure sounds like you're disputing > that they're correct to me! Those statements were made over two hours apart. Things can change in two hours. > > > I'm simply puzzled why this issue was > > swept under the rug by pretending it's supposed to work that way. > > I'm completely confused. What is "this issue", [0,1) vs. [0,1] > and why are we > "pretending" that it's supposed to work "that way"? By changing the documentation without explaining why. If the intention was [0,1), as implied by the 2.6.1 docs, but wasn't actually doing that, it should be so stated. This isn't simply fixing a typo. > > Yes, I've read the thread. I still have no idea what you are complaining > about. According to your reply to John Young, you know exactly what the problem is. > > > We're > > not children here, you can explain that what is supposed to work in > > theory sometimes has problems in practice. We're not all going to > > abandon Python and run out and buy Mathematica. > > > Look at how the change of random to the Mersenne Twister was handled. > > That's what we, the users, want to see. > > Speak for yourself. What about the change that you think "we, the users", > want to see? Things like this: "Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence." Is that strictly necessary in the random documentation that defines what the random module does? _I_ appreciate it being there and am glad someone made the effort to put it there. If there is a change from a<=N > > Otherwise, it creates endless confusion. > > Not as confused as this discussion. I thought you said you read the thread? > > -- > Steven From davea at ieee.org Wed Jun 10 01:58:52 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 10 Jun 2009 01:58:52 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <4A2F4B9C.5080205@ieee.org> Steven D'Aprano wrote: > On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > > >> The docs are now... sort of correct. For some values of a and b, >> uniform() can never return b. Notably, I believe uniform(0, 1) is >> equivalent to random(), and will never return 1. However, uniform(1, 2) >> CAN return 2, if this is any indication: >> >> >> >>>>> a=0.0 >>>>> b=1.0 >>>>> a+(b-a)*z < b >>>>> >> True >> >>>>> a=1.0 >>>>> b=2.0 >>>>> a+(b-a)*z < b >>>>> >> False >> > > > But you haven't shown what value z has, so there's no way of interpreting > that example. > > I'd say that uniform(1, 2) should NOT return 2, at least for systems > which round correctly. Given a random z such that: > > 0 <= z < 1 > > and two floats a, b such that: > > a < b > > (b is strictly the larger of the two) then: > > 0 <= z < 1 > > Multiply all sides by (b-a): > 0 <= (b-a)*z < (b-a) > > Add a to all sides: > a <= a + (b-a)*z < b > > > Hence uniform(a, b) should always return a result less than b, and > greater or equal to a. > > However, there is one proviso: floats are not reals. The above holds true > for real numbers, but floats are subject to weird rounding effects. That > means that there may be weird edge cases where Bad Things happen and > things cancel catastrophically or round incorrectly. > > A realistic edge case is that a + (b-a) doesn't always give b: > > >>>> a = -1e90 >>>> b = 1.0 >>>> a < b >>>> > True > >>>> a + (b-a) == b >>>> > False > >>>> a + (b-a) >>>> > 0.0 > > > However, even in this case, it merely narrows the range of possible > results, it doesn't widen it. > > > Did you try to find the edge case for z ? For the following, I'm using Python 2.6.2, running on XP, on a Pentium Core Duo. I figure the highest theoretical value that random.random() should return is a number just under 1.0 The easiest way to generate that value is using the fromhex() method of float. >>> z = float.fromhex("0x1.fffffffffffffp-1") >>> z 0.99999999999999989 >>> z<1.0 True >>> z2 = 1.0 + z >>> z2 2.0 >>> z2 < 2.0 False From debatem1 at gmail.com Wed Jun 10 02:15:07 2009 From: debatem1 at gmail.com (CTO) Date: Tue, 9 Jun 2009 23:15:07 -0700 (PDT) Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: On Jun 9, 11:58?pm, William Clifford wrote: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs > like the simplex graph or dodecahedron graph, etc (I'm sure there are > many). I'm particularly keen on understanding the very basic functions > for determining edges in the graphs. If one didn't want the complete > graph but just a function generates the edges connected to a given > node. > > I've been surfing around for this sort of info, but I'm having trouble > finding stuff at my level. If anyone knows of any resources or > tutorials or that sort of thing, I'd like to hear about those too. > > Thanks! > > -- > William Clifford Depending on how much of a basis you have in CS, you may want to take a look at http://www.amazon.com/Combinatorial-Algorithms-Enumeration-Mathematics-Applications/dp/084933988X which I found to be an excellent book that covers a lot of the ground you're talking about. Also, check out graphine (graphine.org)- I think its a pretty easy-to-use graph package for python, although as the primary author I'm pretty biased. Geremy Condra From __peter__ at web.de Wed Jun 10 02:24:57 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 08:24:57 +0200 Subject: How to insert string in each match using RegEx iterator References: Message-ID: 504crank at gmail.com wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Have a look at re.sub(): >>> s = '123 abc 456 def 789 ghi' >>> re.compile(r"(\d+\s)").sub(r"INSERT \1", s) 'INSERT 123 abc INSERT 456 def INSERT 789 ghi' Peter From gallium.arsenide at gmail.com Wed Jun 10 02:25:39 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 23:25:39 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 10, 1:52?am, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > Therefore, to me the most up-to-date docs (which say > > that uniform(a, b) returns a float in the closed > > interval [a, b]) is closer to correct than before, > > but still fails to point out the full subtlety of > > the behavior. > > Which is? That uniform(a, b) will return a random float in the semi-open interval [a, b) for certain values of a and b; and in the closed interval [a, b] for other values of a and b. (Swap a and b if a > b.) To me, the fact that you sometimes get a semi-open interval and sometimes a closed interval is worth noting in the docs. John From vs at it.uu.se Wed Jun 10 03:07:00 2009 From: vs at it.uu.se (Virgil Stokes) Date: Wed, 10 Jun 2009 09:07:00 +0200 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <4A2F5B94.8010102@it.uu.se> An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Wed Jun 10 03:19:49 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Jun 2009 10:19:49 +0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: Miles Kaufmann writes: [...] > I'm curious what algorithm calls for random numbers on a closed > interval. The Box-Muller transform, polar form. At least Wikipedia says so. From Krzysztof.Retel at googlemail.com Wed Jun 10 03:19:49 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Wed, 10 Jun 2009 00:19:49 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: <8929b4e5-148a-4564-b1aa-20920c297a00@t11g2000vbc.googlegroups.com> On Jun 9, 7:57?pm, Carl Banks wrote: > On Jun 9, 8:57?am, kretel wrote: > > > > > Hi All, > > > I am trying to implement the following functionality: > > 1. log messages to the flash drive > > 2. if the flash drive is not available, switch handler to the > > BufferringHandler and log into buffer, > > 3. once the flash drive is plugged in and available store the logs > > from BufferHandler into that flash drive and switch the handler into > > RotateFileHandler. > > > Which approach would you suggest to use while implementing this > > functionality? One that come into my mind is to have one process or > > thread to check periodically if the flashdrive is available, and have > > a flag that will indicate that we can store the logs into the flash > > drive. But I don't particularly like this approach. > > Would you do it different way? > > Any suggestions are appreciated. > > I'd refactor the steps this way: > > 1. log messages to a buffer > 2. periodically flush the buffer to the flash drive, if it's available > > The "periodically" part could be accomplished with a thread or > scheduled delays, however suits your application. ?It might not be a > final if you need to log messages promptly, but that's how I'd begin. > > Carl Banks Hi Carl, Thanks for the advice. I haven't think about it this way, but it looks like that might be the starting point. Thanks, Krzysztof From gatti at dsdata.it Wed Jun 10 03:22:14 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Wed, 10 Jun 2009 00:22:14 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <4e9b6c1c-46fc-446d-8ed8-38ac038bc606@g19g2000yql.googlegroups.com> On 10 Giu, 06:23, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive constants, > rand() and Rand() are two random functions in the range [0,1], > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > and w is the inertia weight. 1) I second John Yeung's suggestion: use random integers between 0 and N-1 or N inclusive and divide by N to obtain a maximum value of (N-1)/ N or 1 as you prefer. Note that N doesn't need to be very large. 2) I'm not sure a pseudo-closed range is different from a pseudo-open one. You are perturbing vid and xid by random amounts, scaled by arbitrary coefficients c1 and c2: if you multiply or divide these coefficients by (N-1)/N the minimum and maximum results for the two choices can be made identical up to floating point mangling. Regards, Lorenzo Gatti From wuwei23 at gmail.com Wed Jun 10 03:28:31 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Jun 2009 00:28:31 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> <0581c89e-4e61-4a9b-9032-cfcd1b88ef81@y9g2000yqg.googlegroups.com> Message-ID: <247ae78a-961d-494f-a13e-4fa9943ab74e@z19g2000vbz.googlegroups.com> On Jun 10, 3:24?pm, John Yeung wrote: > Alex, did you bother to read what I quoted? ?Paul McGuire suggested an > alternative in case the OP was choosing integers in a roundabout way. > I was merely pointing out that Paul's solution can be more simply > achieved using a library function. My apologies, John. I *did* read the quote, my brain just didn't parse it correctly. Sorry about that :) From andreengels at gmail.com Wed Jun 10 03:30:49 2009 From: andreengels at gmail.com (Andre Engels) Date: Wed, 10 Jun 2009 09:30:49 +0200 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <6faf39c90906100030i7eff28efk5c942156abe5f424@mail.gmail.com> On Wed, Jun 10, 2009 at 8:25 AM, John Yeung wrote: > That uniform(a, b) will return a random float in the semi-open > interval [a, b) for certain values of a and b; and in the closed > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > To me, the fact that you sometimes get a semi-open interval and > sometimes a closed interval is worth noting in the docs. If it is important whether "b" is included or not, apparently the difference between "b" and "the largest float smaller than b" is important. If a difference as small as that makes a difference, you should not be using floats, or random generators giving floats, anyway, but something with a higher precision. In other words, if you do care about the difference between [a, b) and [a, b], the random module is not giving what you meet even if it does give the 'right' one of those. -- Andr? Engels, andreengels at gmail.com From jpiitula at ling.helsinki.fi Wed Jun 10 03:35:01 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Jun 2009 10:35:01 +0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: Esmail writes: > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. You could generate from a larger range and reject the values that you do not want: generate from [0, 2), say, until you get a value in [0, 1]. If you generate from [0, 1 + epsilon) with small epsilon, rejections will be rare. (I didn't notice this suggestion in the thread, so I'm voicing it just in case it's not there yet.) From nick at craig-wood.com Wed Jun 10 04:29:37 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 10 Jun 2009 03:29:37 -0500 Subject: setting program name, like $0= in perl? References: Message-ID: mh at pixar.com wrote: > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. You can use this module http://code.google.com/p/procname/ Just for fun I made a pure python version using ctypes ------------------------------------------------------------ #!/usr/bin/python """ Attempt to set the process name with ctypes """ import os from subprocess import Popen, PIPE from ctypes import pythonapi, c_int, c_char_p, POINTER, addressof, pointer, CDLL, memmove, memset from ctypes.util import find_library Py_GetArgcArgv = pythonapi.Py_GetArgcArgv c_lib = CDLL(find_library("c")) PR_SET_NAME = 15 # linux specific argc_t = POINTER(c_char_p) Py_GetArgcArgv.restype = None Py_GetArgcArgv.argtypes = [POINTER(c_int), POINTER(argc_t)] def set_name(name): argv = c_int(0) argc = argc_t() Py_GetArgcArgv(argv, pointer(argc)) name0 = name+"\0" memset(argc.contents, 0, 256) # could do this better! memmove(argc.contents, name0, len(name0)) # prctl doesn't seem to be needed on linux? c_lib.prctl(PR_SET_NAME, name+"\0", 0, 0, 0) def ps(): print Popen(["ps", "v", str(os.getpid())], stdout=PIPE).communicate()[0] def main(): print "Before" ps() set_name("sausage") print "After" ps() if __name__ == "__main__": main() ------------------------------------------------------------ This prints $ ./procname.py Before PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 9159 pts/7 S+ 0:00 0 1000 5551 3404 0.1 /usr/bin/python ./procname.py After PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 9159 pts/7 S+ 0:00 0 1000 5551 3420 0.1 sausage -- Nick Craig-Wood -- http://www.craig-wood.com/nick From dickinsm at gmail.com Wed Jun 10 05:01:18 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 02:01:18 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> On Jun 10, 7:25?am, John Yeung wrote: > On Jun 10, 1:52?am, Steven D'Aprano > > wrote: > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > Therefore, to me the most up-to-date docs (which say > > > that uniform(a, b) returns a float in the closed > > > interval [a, b]) is closer to correct than before, > > > but still fails to point out the full subtlety of > > > the behavior. > > > Which is? > > That uniform(a, b) will return a random float in the semi-open > interval [a, b) for certain values of a and b; and in the closed > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > To me, the fact that you sometimes get a semi-open interval and > sometimes a closed interval is worth noting in the docs. Do you want to submit a doc patch? For practical purposes, I think you'd be hard-pressed to find a statistical test that could reliably distinguish between a large sample of values from random.uniform(a, b) and a sample from a 'perfect' uniform distribution on the closed interval [a, b]. It's true that there are values of a and b such that random.uniform(a, b) can never produce b. But for given a and b, not too close together, there may be many other values that can't be produced as well, so it hardly seems worth pointing out one particular value that can never be produced. Example: on a typical system there are almost 2**62 floats in the range [0, 1); the vast majority of these can never be produced by random.random(), which can only ever return one of 2**53 distinct values (it essentially just returns a value of the form n/2**53 with n an integer in the range [0, 2**53)). So random.uniform(0, 1) will miss lots of possible values. On the other hand, it's easy to find examples of a and b such that random.uniform(a, b) has a significant chance of producing b. For example, take a = 10**16, b = 10**16 + 4, then there's about a 1 in 4 chance of getting b. Or for a more extreme example, simply take a = b. Hence the doc change. Mark From jeanmichel at sequans.com Wed Jun 10 05:05:46 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Jun 2009 11:05:46 +0200 Subject: What is the actual type of "interrupted system call"? In-Reply-To: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> References: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> Message-ID: <4A2F776A.8040703@sequans.com> mrstevegross wrote: >> exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError >> ... >> exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ >> > > Is there a single parent exception to all those? Or should I just > write it as: > > try: > ... > catch Exception: > ... > > Thanks, > --Steve > You're right, Exception is the parent of (almost) all exceptions. I wouldn't advise writing such block catching all exceptions, it makes error tracking quite difficult. However if you don't know the type of exception involved in a particular case, you can write try: ... except Exception, excInstance: print excInstance.__class__.__name__ print excInstance.__dict__ If you know how to trigger the exception, it should print the class name of the exception, along with its attributes. It will help you then write a more focused except clause. Jean-Michel From dfnsonfsduifb at gmx.de Wed Jun 10 05:29:41 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 11:29:41 +0200 Subject: Compiling Python3.1 Message-ID: <799co4F1pdqgeU1@mid.dfncis.de> Hello group, I just wanted to switch from Py3.0 to Py3.1. No luck here: [...] ar rc libpython3.1.a Python/_warnings.o Python/Python-ast.o Python/asdl.o Python/ast.o Python/bltinmodule.o Python/ceval.o Python/compile.o Python/codecs.o Python/errors.o Python/frozen.o Python/frozenmain.o Python/future.o Python/getargs.o Python/getcompiler.o Python/getcopyright.o Python/getplatform.o Python/getversion.o Python/graminit.o Python/import.o Python/importdl.o Python/marshal.o Python/modsupport.o Python/mystrtoul.o Python/mysnprintf.o Python/peephole.o Python/pyarena.o Python/pyctype.o Python/pyfpe.o Python/pymath.o Python/pystate.o Python/pythonrun.o Python/structmember.o Python/symtable.o Python/sysmodule.o Python/traceback.o Python/getopt.o Python/pystrcmp.o Python/pystrtod.o Python/dtoa.o Python/formatter_unicode.o Python/dynload_shlib.o Python/thread.o ar rc libpython3.1.a Modules/config.o Modules/getpath.o Modules/main.o Modules/gcmodule.o ar rc libpython3.1.a Modules/_threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/errnomodule.o Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o Modules/_weakref.o Modules/_functoolsmodule.o Modules/_localemodule.o Modules/_iomodule.o Modules/iobase.o Modules/fileio.o Modules/bytesio.o Modules/bufferedio.o Modules/textio.o Modules/stringio.o Modules/zipimport.o Modules/symtablemodule.o Modules/xxsubtype.o ranlib libpython3.1.a gcc -pthread -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython3.1.a -lpthread -ldl -lutil -lm Traceback (most recent call last): File "./setup.py", line 1675, in main() File "./setup.py", line 1670, in main "Tools/scripts/2to3"] File "/home/joe/Python-3.1rc1/Lib/distutils/core.py", line 149, in setup dist.run_commands() File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 921, in run_commands self.run_command(cmd) File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 940, in run_command cmd_obj.run() File "/home/joe/Python-3.1rc1/Lib/distutils/command/build.py", line 128, in run self.run_command(cmd_name) File "/home/joe/Python-3.1rc1/Lib/distutils/cmd.py", line 315, in run_command self.distribution.run_command(command) File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 940, in run_command cmd_obj.run() File "/home/joe/Python-3.1rc1/Lib/distutils/command/build_ext.py", line 347, in run self.build_extensions() File "./setup.py", line 102, in build_extensions missing = self.detect_modules() File "./setup.py", line 728, in detect_modules f = open(f).read() File "/home/joe/Python-3.1rc1/Lib/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 917: ordinal not in range(128) make: *** [sharedmods] Fehler 1 What can I do about that? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From deets at nospam.web.de Wed Jun 10 05:30:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 11:30:00 +0200 Subject: Where should I store docs in my project? References: Message-ID: <799ciuF1q5c4mU1@mid.uni-berlin.de> Matthew Wilson wrote: > I used paster to create a project named pitz. I'm writing a bunch of > user documentation. Where should I put it? > > The project looks a little like this: > > /home/matt/projects/pitz > setup.py > pitz/ > __init__.py # has my project code > docs/ # has my reST files > tests # has some tests > > Is there a convention for where to put the docs folder? I wouldn't put it into the pitz-package - because then these get (potentially) installed into site-packages - where no one is going to see them anyway. I'd put the docs-folder one the root-level, besides the setup.py Diez From ptmcg at austin.rr.com Wed Jun 10 06:17:01 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Jun 2009 03:17:01 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > Some might say that using a parsing library for this problem is overkill, but let me just put this out there as another data point for you. Pyparsing (http://pyparsing.wikispaces.com) supports callbacks that allow you to embellish the matched tokens, and create a new string containing the modified text for each match of a pyparsing expression. Hmm, maybe the code example is easier to follow than the explanation... from pyparsing import Word, nums, Regex # an integer is a 'word' composed of numeric characters integer = Word(nums) # or use this if you prefer integer = Regex(r'\d+') # attach a parse action to prefix 'INSERT ' before the matched token integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) # use transformString to search through the input, applying the # parse action to all matches of the given expression test = '123 abc 456 def 789 ghi' print integer.transformString(test) # prints # INSERT 123 abc INSERT 456 def INSERT 789 ghi I offer this because often the simple examples that get posted are just the barest tip of the iceberg of what the poster eventually plans to tackle. Good luck in your Pythonic adventure! -- Paul From dmitrey.kroshko at scipy.org Wed Jun 10 07:01:47 2009 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 10 Jun 2009 04:01:47 -0700 (PDT) Subject: easiest way to check python version? Message-ID: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> hi all, what is easiest way to check python version (to obtain values like 2.4, 2.5, 2.6, 3.0 etc) from Python env? I don't mean "python -V" from command prompt. Thank you in advance, D. From martin.hellwig at dcuktec.org Wed Jun 10 07:18:08 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Jun 2009 12:18:08 +0100 Subject: easiest way to check python version? In-Reply-To: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: dmitrey wrote: > hi all, > what is easiest way to check python version (to obtain values like > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > I don't mean "python -V" from command prompt. > Thank you in advance, D. You don't mean: >>> sys.version either? -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From sjmachin at lexicon.net Wed Jun 10 07:25:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 10 Jun 2009 04:25:22 -0700 (PDT) Subject: easiest way to check python version? References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> On Jun 10, 9:01?pm, dmitrey wrote: > hi all, > what is easiest way ?to check python version (to obtain values like > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > I don't mean "python -V" from command prompt. | >>> import sys | >>> sys.version | '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]' | >>> sys.version_info | (2, 6, 2, 'final', 0) | >>> "easiest" depends on purpose; e.g. version for display or for logging exactly what the customer is running. version_info (or a prefix of it) is the best for things like conditional imports etc E.g. py_version = sys.version_info[:2] if py_version == (2, 3): from sets import Set as set Cheers, John From a.cavallo at mailsnare.com Wed Jun 10 07:38:47 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 10 Jun 2009 12:38:47 +0100 Subject: easiest way to check python version? In-Reply-To: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> Message-ID: <200906101238.48205.a.cavallo@mailsnare.com> A common way to do it is (it is widely accepted): python -c 'import sys; print sys.version[:3]' Regards, Antonio On Wednesday 10 June 2009 12:25:22 John Machin wrote: > On Jun 10, 9:01 pm, dmitrey wrote: > > hi all, > > what is easiest way to check python version (to obtain values like > > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > > I don't mean "python -V" from command prompt. > > > | >>> import sys > | >>> sys.version > | > | '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit > > (Intel)]' > > | >>> sys.version_info > | > | (2, 6, 2, 'final', 0) > > "easiest" depends on purpose; e.g. version for display or for logging > exactly what the customer is running. version_info (or a prefix of it) > is the best for things like conditional imports etc > > E.g. > py_version = sys.version_info[:2] > if py_version == (2, 3): > from sets import Set as set > > Cheers, > John From ken at seehart.com Wed Jun 10 07:40:34 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Jun 2009 04:40:34 -0700 Subject: xmlrpclib and generators Message-ID: <4A2F9BB2.6010005@seehart.com> It would be really cool if an rpc call could return a generator. I know that there are a few reasons why one would not expect it to be part of the library (e.g. the client would need to receive asynchronous messages, and it's not part of the rpc standard), however below I show a possible implementation, given that the client is also able to be a server... I am aware of MultiCall, but that is actually something like the inverse of what I want. I need a consumer. Example: ------------------------------------------------------------------------ # hypothetical client code (running at "http://rpc.myserver.com") from fancyxmlrpc import FancyXMLRPCServer server = FancyXMLRPCServer(('localhost', 9000)) def primes(): n = 2 p = [] while True: if not any( n % f == 0 for f in p ): yield n p.append( n ) n += 1 server.register_generator(primes) server.serve_forever() ------------------------------------------------------------------------ # hypothetical client code (running at http://www.mywebsite.com): from fancyxmlrpc import FancyServerProxy server_url = "http://rpc.myserver.com" local_url = "http://www.mywebsite.com" server = FancyServerProxy(server_url, local_url) g = server.examples.getStateNames() for x in g: print x ------------------------------------------------------------------------ Okay, so to implement this, the trick would be to implement the generator wrapper as a hidden xmlrpc conversation. On the client side, FancyServerProxy would encapsulate a hidden RPC server with a function that receives each item that is yielded by the server and queues them while the client generator consumes the queue and yields the items. The practical constraints of my specific application are: 1. The rpc server is a highly specialized slave system that does heavy duty work. 2. The rpc client is itself a web server that dispatches work requests to the rpc server(s) and displays the current status of work done so far. 3. The generators will typically run for a long time (hours) and yield data periodically (perhaps once a minute). 4. Trusted users will write generators on the server and consumers on the client (web site) and use the web site to make requests. 5. It would be even better if my generator yields numpy arrays rather than lists. 6. It would be nice to be able to scale to allow the web site to dispatch to multiple work servers. So my questions are: 1. Does using xmlrpc make any sense for this? 2. I am missing an easier way to do this? 3. Any good examples of things like this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From floris.bruynooghe at gmail.com Wed Jun 10 07:56:51 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Wed, 10 Jun 2009 04:56:51 -0700 (PDT) Subject: multi-thread python interpreaters and c++ program References: Message-ID: <6deac4c8-b208-4fbf-8098-8dc7af7f881b@r34g2000vba.googlegroups.com> On Jun 9, 6:50?am, "myopc" wrote: > ? I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python interpreaters, > but it crashed. Your threads are daemonic, you could be seeing http://bugs.python.org/issue1856 You'll have to check your stack in a debugger to know. But as said this can be avoided by making the threads finish themself and joining them. Regards Floris From heweiwei at gmail.com Wed Jun 10 08:59:26 2009 From: heweiwei at gmail.com (BigHand) Date: Wed, 10 Jun 2009 05:59:26 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> On Jun 10, 7:41?am, "Gabriel Genellina" wrote: > En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > > > ? ?I have an embedded python application. which is ?a MFC app with > > Python interpreter embedded. > > > ? ?In the App, I have a separate thread to execute a Python script > > (using the PyRun_File), but if the user want to stop the executing > > script, how should I do? > > > A possible way is terminate the thread of executing the scripts by > > TerminateThread(). but TerminateThread() is unsafe and not > > recommended. > > > guys, could you guide me on this? > > You could use PyThreadState_SetAsyncExc (to "inject" an exception), or ? > perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a ? > KeyboardInterrupt). This should work fine for well-behaved scripts, but if ? > it ignores all exceptions like this: > ? ? ? ? try: ... > ? ? ? ? except: pass > you'll have to look at ceval.c how to break out of the running loop. > > (this is yet another argument against indiscriminately using a bare except ? > clause...) > > -- > Gabriel Genellina hello.Gabriel. PyThreadState_SetAsyncExc cause me a win32 exception of "Stack overflow" > msvcr80d.dll!_getptd_noexit() Line 592 C msvcr80d.dll!_getptd() Line 658 + 0x5 bytes C msvcr80d.dll!_LocaleUpdate::_LocaleUpdate(localeinfo_struct * plocinfo=0x00000000) Line 264 + 0x5 bytes C++ msvcr80d.dll!_output_l(_iobuf * stream=0x10311d40, const char * format=0x1e26e0ac, localeinfo_struct * plocinfo=0x00000000, char * argptr=0x000333c4) Line 1028 C++ msvcr80d.dll!fprintf(_iobuf * str=0x10311d40, const char * format=0x1e26e0ac, ...) Line 70 + 0x13 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2000 + 0x19 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C My app is a MFC app, it have the main thread and the sub thread, the sub thread run the script(Py_RunFile), That I am looking for a way to stop the Py_RunFile from the main thread. that looks like I have to use the TerminateThread() . thanks.Gabriel, could you find some example for me? From David.Shapiro at sas.com Wed Jun 10 09:08:56 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 09:08:56 -0400 Subject: getop or optparse with option with spaces? In-Reply-To: <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Hello, I have been trying to find an example of how to deal with options that have spaces in them. I am using jython, which is the same I think as python 2.2.3. I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). The code is as follows: try: (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) except getopt.GetoptError: usage() for opt in opts: (key, value) = opt if (key in ("-v", "--version")): print "Version: " + version sys.exit(1) if (key in ("-h", "--help")): usage() if (key in ("-s", "--server")): server = value if (key in ("-p", "--port")): port = value if (key in ("-n", "--dsName")): dsName = value if (key in ("-j", "--jndiName")): jndiName = value if (key in ("-d", "--driverName")): driverName = value if (key in ("-l", "--driverURL")): driverURL = value if (key in ("-u", "--user")): user = value if (key in ("-c", "--passWD")): passWD = value if (key in ("-t", "--targetServer")): targetServer = value if (key in ("-q", "--testTableName")): testTableName = value if (key in ("-w", "--whereProp")): whereProp = value print "server: " + server print "port: " + port print "dsName: " + dsName print "jndiName: " + jndiName print "driverName: " + driverName print "driverURL: " + driverURL print "user: " + user print "passWD: " + passWD print "testtable: " + testTableName print "targetServer: " + targetServer print "whereProp: " + whereProp The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get it to return the whole thing that is in double quotes? Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. Also, it just seem weird I have to do a work around like that. I could have swore using double quotes should have fixed this issue, but they do not seem to work. David From dickinsm at gmail.com Wed Jun 10 09:13:53 2009 From: dickinsm at gmail.com (dickinsm at gmail.com) Date: 10 Jun 2009 13:13:53 GMT Subject: random number including 1 - i.e. [0,1] References: Message-ID: <4a2fb191$0$90265$14726298@news.sunsite.dk> Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > [...] Here are three recipes, each more pedantic than the last. They all assume that Python floats are IEEE 754 binary64 format (which they almost certainly are on your machine), and that randrange generates all values with equal likelihood (which it almost certainly doesn't, but the assumption should be good enough for government work). import random def random1(): """Random float in [0, 1]. Generates all floats of the form n/2**53, 0 <= n <= 2**53, with equal probability. """ return random.randrange(2**53+1)/2.**53 def random2(): """Random float in [0, 1]. Generates all floats of the forn n/2**53, 0 <= n <= 2**53, with values in (0.0, 1.0) equally likely, and the endpoints 0.0 and 1.0 occuring with half the probability of any other value. This is equivalent to generating a random real number uniformly on the closed interval [0, 1] and then rounding that real number to the nearest float of the form n/2**53. """ return (random.randrange(2**54)+1)//2/2.**53 def random3(): """Random float in [0, 1]. Generates *all* floats in the interval [0.0, 1.0] (including 0.0 and 1.0, but excluding -0.0). Each float is generated with a probability corresponding to the size of the subinterval of [0, 1] that rounds to the given float under round-to-nearest. This is equivalent to generating a random real number uniformly on the closed interval [0, 1] and then rounding that real number to the nearest representable floating-point number. """ m = (random.randrange(2**53)+1)//2 e = 1022 while random.randrange(2) and e: e -= 1 return (m+2**52) * 2.**(e-1075) if e else m*2.**-1074 -- Mark Dickinson From javier.collado at gmail.com Wed Jun 10 09:37:46 2009 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 10 Jun 2009 15:37:46 +0200 Subject: getop or optparse with option with spaces? In-Reply-To: References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Hello, It's strange behaviour. Have you tried argparse (http://code.google.com/p/argparse/)? I've been using it for long time without any problem like that? Best regards, Javier 2009/6/10 David Shapiro : > Hello, > > I have been trying to find an example of how to deal with options that have spaces in them. ?I am using jython, which is the same I think as python 2.2.3. ? I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). ? The code is as follows: > > ? ?try: > ? ? ? ?(opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > ? ?except getopt.GetoptError: > ? ? ? ?usage() > > ? ?for opt in opts: > ? ? ? ?(key, value) = opt > ? ? ? ?if (key in ("-v", "--version")): > ? ? ? ? ? ? ? ?print "Version: " + version > ? ? ? ? ? ? ? ?sys.exit(1) > ? ? ? ?if (key in ("-h", "--help")): > ? ? ? ? ? ? ? ?usage() > ? ? ? ?if (key in ("-s", "--server")): > ? ? ? ? ? ? ? ?server = value > ? ? ? ?if (key in ("-p", "--port")): > ? ? ? ? ? ? ? ?port = value > ? ? ? ?if (key in ("-n", "--dsName")): > ? ? ? ? ? ? ? ?dsName = value > ? ? ? ?if (key in ("-j", "--jndiName")): > ? ? ? ? ? ? ? ?jndiName = value > ? ? ? ?if (key in ("-d", "--driverName")): > ? ? ? ? ? ? ? ?driverName = value > ? ? ? ?if (key in ("-l", "--driverURL")): > ? ? ? ? ? ? ? ?driverURL = value > ? ? ? ?if (key in ("-u", "--user")): > ? ? ? ? ? ? ? ?user = value > ? ? ? ?if (key in ("-c", "--passWD")): > ? ? ? ? ? ? ? ?passWD = value > ? ? ? ?if (key in ("-t", "--targetServer")): > ? ? ? ? ? ? ? ?targetServer = value > ? ? ? ?if (key in ("-q", "--testTableName")): > ? ? ? ? ? ? ? ?testTableName = value > ? ? ? ?if (key in ("-w", "--whereProp")): > ? ? ? ? ? ? ? ?whereProp = value > > > print "server: " + server > print "port: " + port > print "dsName: " + dsName > print "jndiName: " + jndiName > print "driverName: " + driverName > print "driverURL: " + driverURL > print "user: " + user > print "passWD: " + passWD > print "testtable: " + testTableName > print "targetServer: " + targetServer > print "whereProp: " + whereProp > > The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". ?It returns back just SQL. ?How do I get it to return the whole thing that is in double quotes? ?Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? > > If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. ?A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. ?Also, it just seem weird I have to do a work around like that. ?I could have swore using double quotes should have fixed this issue, but they do not seem to work. > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From ptmcg at austin.rr.com Wed Jun 10 09:40:58 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Jun 2009 06:40:58 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <471f2ab3-b210-48d3-b1d5-57b6c3a79808@h11g2000yqb.googlegroups.com> On Jun 9, 11:23?pm, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive constants, > rand() and Rand() are two random functions in the range [0,1], > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > and w is the inertia weight. It is entirely possible that the documentation you have for the original rand() and Rand() functions have misstated their range. In my experience, rand() functions that I have worked with have always been [0,1). -- Paul From eckhardt at satorlaser.com Wed Jun 10 09:41:00 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 10 Jun 2009 15:41:00 +0200 Subject: retrieve bitwise float representation Message-ID: Hi! I need to pack a floating point value into a vector of 32-bit unsigned values in IEEE format. Further, I maintain a CRC32 checksum for integrity checking. For the latter, I actually need the float as integral value. What I currently do is this: tmp = struct.pack("=f", f) (i,) = struct.unpack("=L", tmp) IOW, I pack and unpack the float using the struct module, which works. What I'm wondering is whether there are any better or alternative ways to achieve this, the overhead now seems enormous and unnecessary to me here. Thank you! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From David.Shapiro at sas.com Wed Jun 10 09:47:54 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 09:47:54 -0400 Subject: getop or optparse with option with spaces? In-Reply-To: References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Unfortunately, I had no luck installing argparse, which is really confusing because I would need to use some old version pre-optik to use I think. The Jython I use is like python 2.2.3. I spent all of yesterday trying to get either getopt, argparse, or optparse to work. Even with optparse I had to modify a module. For example, in textwrap.py, they have @ line 124 in the module: if self.replace_whitespace: #if isinstance(text,str): # text = text.translate(self.whitespace_trans) #elif isinstances(text,Unicode): text = text.translate(self.unicode_whitespace_trans) return text I had to comment out the if isinstance(text,str) and elif. Is the double quotes supposed to work? -----Original Message----- From: Javier Collado [mailto:javier.collado at gmail.com] Sent: Wednesday, June 10, 2009 9:38 AM To: David Shapiro Cc: python-list at python.org Subject: Re: getop or optparse with option with spaces? Hello, It's strange behaviour. Have you tried argparse (http://code.google.com/p/argparse/)? I've been using it for long time without any problem like that? Best regards, Javier 2009/6/10 David Shapiro : > Hello, > > I have been trying to find an example of how to deal with options that have spaces in them. ?I am using jython, which is the same I think as python 2.2.3. ? I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). ? The code is as follows: > > ? ?try: > ? ? ? ?(opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > ? ?except getopt.GetoptError: > ? ? ? ?usage() > > ? ?for opt in opts: > ? ? ? ?(key, value) = opt > ? ? ? ?if (key in ("-v", "--version")): > ? ? ? ? ? ? ? ?print "Version: " + version > ? ? ? ? ? ? ? ?sys.exit(1) > ? ? ? ?if (key in ("-h", "--help")): > ? ? ? ? ? ? ? ?usage() > ? ? ? ?if (key in ("-s", "--server")): > ? ? ? ? ? ? ? ?server = value > ? ? ? ?if (key in ("-p", "--port")): > ? ? ? ? ? ? ? ?port = value > ? ? ? ?if (key in ("-n", "--dsName")): > ? ? ? ? ? ? ? ?dsName = value > ? ? ? ?if (key in ("-j", "--jndiName")): > ? ? ? ? ? ? ? ?jndiName = value > ? ? ? ?if (key in ("-d", "--driverName")): > ? ? ? ? ? ? ? ?driverName = value > ? ? ? ?if (key in ("-l", "--driverURL")): > ? ? ? ? ? ? ? ?driverURL = value > ? ? ? ?if (key in ("-u", "--user")): > ? ? ? ? ? ? ? ?user = value > ? ? ? ?if (key in ("-c", "--passWD")): > ? ? ? ? ? ? ? ?passWD = value > ? ? ? ?if (key in ("-t", "--targetServer")): > ? ? ? ? ? ? ? ?targetServer = value > ? ? ? ?if (key in ("-q", "--testTableName")): > ? ? ? ? ? ? ? ?testTableName = value > ? ? ? ?if (key in ("-w", "--whereProp")): > ? ? ? ? ? ? ? ?whereProp = value > > > print "server: " + server > print "port: " + port > print "dsName: " + dsName > print "jndiName: " + jndiName > print "driverName: " + driverName > print "driverURL: " + driverURL > print "user: " + user > print "passWD: " + passWD > print "testtable: " + testTableName > print "targetServer: " + targetServer > print "whereProp: " + whereProp > > The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". ?It returns back just SQL. ?How do I get it to return the whole thing that is in double quotes? ?Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? > > If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. ?A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. ?Also, it just seem weird I have to do a work around like that. ?I could have swore using double quotes should have fixed this issue, but they do not seem to work. > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From flyeng4 at gmail.com Wed Jun 10 09:57:42 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 08:57:42 -0500 Subject: xml application advice Message-ID: <4A2FBBD6.6090806@gmail.com> I am writing a application to calculate pressure drop for a piping network. Namely a building sprinkler system. This will be a command line program at first with the system described in xml (at least that is how I think I want to do it). An important part of this calculation is finding the 'hydraulically most remote' sprinkler. This is something that I could specify with an attribute for now and later think about how to automate it. I need to walk through the dom tree until I find a node of type "sprinkler" that has an attribute of hydraulically_most_remote with a value of True. After I find this I need to break the itterator/for loop and then start walking backwards keeping a running total of the pressure drop until I reach a node that has multiple pipesections and then walk to the end of each branch and calculate the pressure drop, and then add them to the branch that contained the hydraulically most remote sprinkler, and then move on, repeating this until I walk all the way back to the inflow node. I am having trouble finding a decent python/xml resource on the web. I have ordered Python & XML by Jones and Drake, but I am anxious to get something started. The only decent online resource that I can seem to find is http://pyxml.sourceforge.net/topics/howto/xml-howto.html which doesn't seem to be a very comprehensive how-to. Do demonstrate just about everything I know about xml and python I attached t.py and ex.xml. Another thing that is confusing is dir(walker) does not show walker having an attribute currentNode and dir(walker.currentNode) does not show walker.currentNode having an attribute tagName. Bill -------------- next part -------------- A non-text attachment was scrubbed... Name: ex.xml Type: text/xml Size: 572 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: t.py Type: text/x-python Size: 325 bytes Desc: not available URL: From David.Shapiro at sas.com Wed Jun 10 10:11:12 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 10:11:12 -0400 Subject: xml application advice In-Reply-To: <4A2FBBD6.6090806@gmail.com> References: <4A2FBBD6.6090806@gmail.com> Message-ID: How about using web server (tomcat jsp) and then java for the xml part, which would allow you to build a nice gui for you. You can use python for backend work. If you can combine some of the levels of your xml it will be easier to traverse. I am not sure this will work for you, but I put as an example: - - - - - -----Original Message----- From: python-list-bounces+david.shapiro=sas.com at python.org [mailto:python-list-bounces+david.shapiro=sas.com at python.org] On Behalf Of William Purcell Sent: Wednesday, June 10, 2009 9:58 AM To: python-list at python.org Subject: xml application advice I am writing a application to calculate pressure drop for a piping network. Namely a building sprinkler system. This will be a command line program at first with the system described in xml (at least that is how I think I want to do it). An important part of this calculation is finding the 'hydraulically most remote' sprinkler. This is something that I could specify with an attribute for now and later think about how to automate it. I need to walk through the dom tree until I find a node of type "sprinkler" that has an attribute of hydraulically_most_remote with a value of True. After I find this I need to break the itterator/for loop and then start walking backwards keeping a running total of the pressure drop until I reach a node that has multiple pipesections and then walk to the end of each branch and calculate the pressure drop, and then add them to the branch that contained the hydraulically most remote sprinkler, and then move on, repeating this until I walk all the way back to the inflow node. I am having trouble finding a decent python/xml resource on the web. I have ordered Python & XML by Jones and Drake, but I am anxious to get something started. The only decent online resource that I can seem to find is http://pyxml.sourceforge.net/topics/howto/xml-howto.html which doesn't seem to be a very comprehensive how-to. Do demonstrate just about everything I know about xml and python I attached t.py and ex.xml. Another thing that is confusing is dir(walker) does not show walker having an attribute currentNode and dir(walker.currentNode) does not show walker.currentNode having an attribute tagName. Bill From amitds at oversi.com Wed Jun 10 10:19:53 2009 From: amitds at oversi.com (Amit Dor-Shifer) Date: Wed, 10 Jun 2009 17:19:53 +0300 Subject: Printing dictionary values rather than references Message-ID: <4A2FC109.7080709@oversi.com> Hi all. I'd like to print-out a dictionary of objects. The printed values are references. How Do I print the actual objects. class MyClass: def __str__(self): return str(self.__dict__) if __name__ == '__main__': dict = dict() classA = MyClass() setattr(classA, "attr-1", "val-1") dict['a']= classA print classA ''' Desired output: {'attr-1': 'val-1'}''' print dict ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' Thanks, Amit From dickinsm at gmail.com Wed Jun 10 10:24:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 14:24:56 GMT Subject: retrieve bitwise float representation References: Message-ID: <4a2fc238$0$90272$14726298@news.sunsite.dk> Ulrich Eckhardt wrote: > Hi! > > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > [...] You could try using frexp to extract the significand and exponent of the float, and then pack those values directly into an integer, following the IEEE 754 format. For example: Python 2.6.2 (r262:71600, Jun 8 2009, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from struct import pack, unpack >>> from math import frexp, copysign >>> x = -34.125 >>> unpack('>> m, e = frexp(abs(x)) >>> (e+125 << 23) + int(m*2.**24) + (2**31 if x < 0.0 else 0) 3255336960L The above formula works for most x that are exactly representable as an IEEE single-precision value, but extra effort would be required to make it work with nans, infinities, zeros or denormals. I'm not sure whether this is any faster than the pack/unpack route, though. Obviously, if you're going to convert many floats then the 2.**24 and 2**31 constants should be precalculated. If your values aren't already exactly representable as IEEE single-precision floats then you may have a problem with rounding: the call to int() in the above would truncate, while the implicit conversion from double to single precision involved in packing with 'f' is more likely to do a round-to-nearest. -- Mark Dickinson From metalzong at 163.com Wed Jun 10 10:25:24 2009 From: metalzong at 163.com (Metal Zong) Date: Wed, 10 Jun 2009 22:25:24 +0800 Subject: Can not dump class object created on runtime Message-ID: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Hello, Can not dump class object created on runtime. Is there anybody can help me? Thank. Following is testing code: import pickle from new import classobj class A: def __str__(self): return self.__class__.name if __name__ == "__main__": c = classobj('B', (A, ), {}) # create class obj on runtime print c print pickle.dumps(c) # get dump string Bellows are outputs: __main__.B Traceback (most recent call last): File "C:\USERS\train\_work\test\test.py", line 11, in print pickle.dumps(c) File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle : it's not found as __main__.B - Tommy HZ 23026 MP 13958175281 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Samnsparky at gmail.com Wed Jun 10 10:26:22 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 10 Jun 2009 07:26:22 -0700 (PDT) Subject: Connection tester Message-ID: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Hey! I am developing a small application that tests multiple websites and compares their "response time". Some of these sites do not respond to a ping and, for the measurement to be standardized, all sites must have the same action preformed upon them. Another problem is that not all of the sites have the same page size and I am not interested in how long it takes to load a page but instead just how long it takes for the website to respond. Finally, I am looking to keep this script platform independent, if at all possible. Here is the code: try: # Get the starting time origTime = time.time() # Create the socket connection and then close s = socket.socket(AF_INET, SOCK_STREAM) s.connect((targetIP, port)) s.send("GET / HTTP/1.0\r\n\r\n") result = s.recv(1024) s.shutdown(SHUT_RDWR) except: result = "" # Check for problems and report back the time if result == "": return Result((time.time() - origTime) * 1000, True) else: return Result((time.time() - origTime) * 1000, False) Result is just an object that holds the time it took for the method to finish and if there were any errors. What I am worried about is that the socket is potentially closed before the website can finish sending in all the data. Does anyone have any suggestions or is the script fine as it is? From __peter__ at web.de Wed Jun 10 10:26:46 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 16:26:46 +0200 Subject: retrieve bitwise float representation References: Message-ID: Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > What I currently do is this: > > tmp = struct.pack("=f", f) > (i,) = struct.unpack("=L", tmp) > > IOW, I pack and unpack the float using the struct module, which works. > > > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. binascii.crc32() operates on strings, so you don't need to unpack. If you have many float values array.array() should be more effective than struct.pack(). >>> some_floats = map(float, range(5)) >>> binascii.crc32(array.array("f", some_floats)) 1758053516 From briandenzer at gmail.com Wed Jun 10 10:36:33 2009 From: briandenzer at gmail.com (Brian D) Date: Wed, 10 Jun 2009 07:36:33 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 5:17?am, Paul McGuire wrote: > On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put this out there as another data point for > you. ?Pyparsing (http://pyparsing.wikispaces.com) supports callbacks > that allow you to embellish the matched tokens, and create a new > string containing the modified text for each match of a pyparsing > expression. ?Hmm, maybe the code example is easier to follow than the > explanation... > > from pyparsing import Word, nums, Regex > > # an integer is a 'word' composed of numeric characters > integer = Word(nums) > > # or use this if you prefer > integer = Regex(r'\d+') > > # attach a parse action to prefix 'INSERT ' before the matched token > integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) > > # use transformString to search through the input, applying the > # parse action to all matches of the given expression > test = '123 abc 456 def 789 ghi' > print integer.transformString(test) > > # prints > # INSERT 123 abc INSERT 456 def INSERT 789 ghi > > I offer this because often the simple examples that get posted are > just the barest tip of the iceberg of what the poster eventually plans > to tackle. > > Good luck in your Pythonic adventure! > -- Paul Thanks for all of the instant feedback. I have enumerated three responses below: First response: Peter, I wonder if you (or anyone else) might attempt a different explanation for the use of the special sequence '\1' in the RegEx syntax. The Python documentation explains: \number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters. In practice, this appears to be the key to the key device to your clever solution: >>> re.compile(r"(\d+)").sub(r"INSERT \1", string) 'abc INSERT 123 def INSERT 456 ghi INSERT 789' >>> re.compile(r"(\d+)").sub(r"INSERT ", string) 'abc INSERT def INSERT ghi INSERT ' I don't, however, precisely understand what is meant by "the group of the same number" -- or maybe I do, but it isn't explicit. Is this just a shorthand reference to match.group(1) -- if that were valid -- implying that the group match result is printed in the compile execution? Second response: I've encountered a problem with my RegEx learning curve which I'll be posting in a new thread -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 Third response: Paul, Thanks for the referring me to the Pyparsing module. I'm thoroughly enjoying Python, but I'm not prepared right now to say I've mastered the Pyparsing module. As I continue my work, however, I'll be tackling the problem of parsing addresses, exactly as the Pyparsing module example illustrates. I'm sure I'll want to use it then. From 504crank at gmail.com Wed Jun 10 10:39:41 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Wed, 10 Jun 2009 07:39:41 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 5:17?am, Paul McGuire wrote: > On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put this out there as another data point for > you. ?Pyparsing (http://pyparsing.wikispaces.com) supports callbacks > that allow you to embellish the matched tokens, and create a new > string containing the modified text for each match of a pyparsing > expression. ?Hmm, maybe the code example is easier to follow than the > explanation... > > from pyparsing import Word, nums, Regex > > # an integer is a 'word' composed of numeric characters > integer = Word(nums) > > # or use this if you prefer > integer = Regex(r'\d+') > > # attach a parse action to prefix 'INSERT ' before the matched token > integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) > > # use transformString to search through the input, applying the > # parse action to all matches of the given expression > test = '123 abc 456 def 789 ghi' > print integer.transformString(test) > > # prints > # INSERT 123 abc INSERT 456 def INSERT 789 ghi > > I offer this because often the simple examples that get posted are > just the barest tip of the iceberg of what the poster eventually plans > to tackle. > > Good luck in your Pythonic adventure! > -- Paul Thanks for all of the instant feedback. I have enumerated three responses below: First response: Peter, I wonder if you (or anyone else) might attempt a different explanation for the use of the special sequence '\1' in the RegEx syntax. The Python documentation explains: \number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters. In practice, this appears to be the key to the key device to your clever solution: >>> re.compile(r"(\d+)").sub(r"INSERT \1", string) 'abc INSERT 123 def INSERT 456 ghi INSERT 789' >>> re.compile(r"(\d+)").sub(r"INSERT ", string) 'abc INSERT def INSERT ghi INSERT ' I don't, however, precisely understand what is meant by "the group of the same number" -- or maybe I do, but it isn't explicit. Is this just a shorthand reference to match.group(1) -- if that were valid -- implying that the group match result is printed in the compile execution? Second response: I've encountered a problem with my RegEx learning curve which I'll be posting in a new thread -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 Third response: Paul, Thanks for the referring me to the Pyparsing module. I'm thoroughly enjoying Python, but I'm not prepared right now to say I've mastered the Pyparsing module. As I continue my work, however, I'll be tackling the problem of parsing addresses, exactly as the Pyparsing module example illustrates. I'm sure I'll want to use it then. From David.Shapiro at sas.com Wed Jun 10 10:41:36 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 10:41:36 -0400 Subject: Connection tester Message-ID: Not al pages suppost GET. If a page pings and returns does not mean it can be logged into and work (maybe database down). Have you seen soapui? ----- Original Message ----- From: python-list-bounces+david.shapiro=sas.com at python.org To: python-list at python.org Sent: Wed Jun 10 10:26:22 2009 Subject: Connection tester Hey! I am developing a small application that tests multiple websites and compares their "response time". Some of these sites do not respond to a ping and, for the measurement to be standardized, all sites must have the same action preformed upon them. Another problem is that not all of the sites have the same page size and I am not interested in how long it takes to load a page but instead just how long it takes for the website to respond. Finally, I am looking to keep this script platform independent, if at all possible. Here is the code: try: # Get the starting time origTime = time.time() # Create the socket connection and then close s = socket.socket(AF_INET, SOCK_STREAM) s.connect((targetIP, port)) s.send("GET / HTTP/1.0\r\n\r\n") result = s.recv(1024) s.shutdown(SHUT_RDWR) except: result = "" # Check for problems and report back the time if result == "": return Result((time.time() - origTime) * 1000, True) else: return Result((time.time() - origTime) * 1000, False) Result is just an object that holds the time it took for the method to finish and if there were any errors. What I am worried about is that the socket is potentially closed before the website can finish sending in all the data. Does anyone have any suggestions or is the script fine as it is? -- http://mail.python.org/mailman/listinfo/python-list From jon at ffconsultancy.com Wed Jun 10 10:44:05 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 10 Jun 2009 15:44:05 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Jon Harrop wrote: >>>> No. Concurrent programming is about interleaving computations in order >>>> to reduce latency. Nothing to do with parallelism. >>> >>> Jon, I do concurrent programming all the time, as do most of my peers. >>> Way down on the list of why we do it is the reduction of latency. >> >> What is higher on the list? > > Correctness. > > I'm not being facetious. I write applications that run on application > servers, and from time to time I have had to write various special > purpose servers. This kind of programming is all about managing > concurrent execution of computations. The overarching concern is > reliability and correct function. For many corporate situations, even > with hundreds of users, the actual load at any instant is low enough > that the various servers involved are nowhere close to being stressed > out - performance is a secondary issue. In other words, without concurrency the latency would be so high that you would consider the program to be wrong. However you cut it, the real reason is latency. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From mail at microcorp.co.za Wed Jun 10 10:44:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 10 Jun 2009 16:44:10 +0200 Subject: xmlrpclib and generators References: <4A2F9BB2.6010005@seehart.com> Message-ID: <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> Ken Seehart wrote: 8< ------------ implementation -------------- >The practical constraints of my specific application are: >1. The rpc server is a highly specialized slave system that does heavy duty work. >2. The rpc client is itself a web server that dispatches work requests to the rpc server(s) and displays the >current status of work done so far. >3. The generators will typically run for a long time (hours) and yield data periodically (perhaps once a minute). If this "yield" can be made to be, or if it is, supply side driven, instead of yielding on demand like a generator, then I would set up a simple TCP/IP peer to peer socket link and just send the result back when it is ready. If you have to "serve" more than one such link, it is a simple matter to keep a list of queues linking the different socket sets to the "generator", and to iterate over the list, putting a copy of the thing that was just produced into each queue. Of course, the thing you want to pass back must be serializable. Have you looked at Pyro? So my questions are: 1. Does using xmlrpc make any sense for this? I think you are going to have to do some heavy lifting to get it to work. 2. I am missing an easier way to do this? Maybe - see above - depends on how the stuff is generated 3. Any good examples of things like this? Don't know. - Hendrik From 504crank at gmail.com Wed Jun 10 10:47:13 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Wed, 10 Jun 2009 07:47:13 -0700 (PDT) Subject: How to escape # hash character in regex match strings Message-ID: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> I've encountered a problem with my RegEx learning curve -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#abc456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 The correct result should be: 123456 I've tried to escape the hash symbol in the match string without result. Any ideas? Is the answer something I overlooked in my lurching Python schooling? From deets at nospam.web.de Wed Jun 10 10:49:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 16:49:20 +0200 Subject: xml application advice References: Message-ID: <799v9lF1pj8gqU1@mid.uni-berlin.de> William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). > > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. The only decent online resource that I can > seem to find is > > http://pyxml.sourceforge.net/topics/howto/xml-howto.html > > which doesn't seem to be a very comprehensive how-to. > > Do demonstrate just about everything I know about xml and python I > attached t.py and ex.xml. > > Another thing that is confusing is dir(walker) does not show walker > having an attribute currentNode and dir(walker.currentNode) does not > show walker.currentNode having an attribute tagName. Use lxml2 and xpath. http://codespeak.net/lxml/ http://codespeak.net/lxml/xpathxslt.html See the below piece of code to get you started: import lxml.etree as et xml = """ """ project = et.fromstring(xml) hydraulically_most_remote = project.xpath("//node[@hydraulically_most_remote='True']")[0] print hydraulically_most_remote.attrib["id"] # find node with multiple pipesections that's upwards def find_mp_node(node): pipesections = node.xpath("pipesection") if len(pipesections) > 1: return node parent = node.getparent() if parent is not None: return find_mp_node(parent) print find_mp_node(hydraulically_most_remote).attrib["id"] From massung at gmail.com Wed Jun 10 10:50:37 2009 From: massung at gmail.com (Jeff M.) Date: Wed, 10 Jun 2009 07:50:37 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: On Jun 9, 9:08?pm, Arved Sandstrom wrote: > Jon Harrop wrote: > > > > Arved Sandstrom wrote: > >> > >> Jon, I do concurrent programming all the time, as do most of my peers. > >> Way down on the list of why we do it is the reduction of latency. > > > What is higher on the list? > > Correctness. > IMO, that response is a bit of a cop-out. Correctness is _always_ most important, no matter what application you are creating; without it, you don't have a job and the company you work for goes out of business. But, assuming that your program works and does what it's supposed to, I agree with Jon that performance needs to be right near the top of the list of concerns. Why? Performance isn't about looking good as a programmer, or having fun making a function run in 15 cycles instead of 24, or coming up with some neat bit packing scheme so that your app now only uses 20K instead of 200K. Performance is - pure and simple - about one thing only: money. Programs that use more memory require more money for the hardware of every user. Programs that run slower eat more time per day. If you have 100,000 users, all doing an operation once per day that takes 20 seconds, being able to shave 5 seconds off that saves 5.78 man-days of work. Hell, for some applications, that 20 seconds is just startup time spent at a splash screen. Just imagine if every Google search took even 5 seconds to resolve, how much time would be wasted every day around the world - ignoring the fact that Google wouldn't exist if that were the case ;-). Obviously Google engineers work incredibly hard every day to ensure correct results, but performance better be right up there at the top of the list as well. Jeff M. From Scott.Daniels at Acm.Org Wed Jun 10 11:09:15 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 08:09:15 -0700 Subject: easiest way to check python version? In-Reply-To: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> Message-ID: John Machin wrote: > On Jun 10, 9:01 pm, dmitrey wrote: >> hi all, >> what is easiest way to check python version (to obtain values like >> 2.4, 2.5, 2.6, 3.0 etc) from Python env? ... > "easiest" depends on purpose; e.g. version for display or for logging > exactly what the customer is running. version_info (or a prefix of it) > is the best for things like conditional imports etc > > E.g. > py_version = sys.version_info[:2] > if py_version == (2, 3): > from sets import Set as set Note also that the definition of tuple comparison help you here: if (2, 1, 1) < sys.version_info < (2, 3): ... elif (2, 5) <= sys.version_info <= (2, 6, 2, 'final'): ... else: print('Untested') --Scott David Daniels Scott.Daniels at Acm.Org From blume at hana.uchicago.edu Wed Jun 10 11:10:03 2009 From: blume at hana.uchicago.edu (Matthias Blume) Date: Wed, 10 Jun 2009 10:10:03 -0500 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: "Jeff M." writes: > On Jun 9, 9:08?pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >> > >> > Arved Sandstrom wrote: >> >> >> >> Jon, I do concurrent programming all the time, as do most of my peers. >> >> Way down on the list of why we do it is the reduction of latency. >> >> > What is higher on the list? >> >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. Programmer time is vastly more expensive than CPU time, so the money argument often leads to slow ("low performance") solutions as long as they are "good enough" because developing a faster solution would mean spending more valuable programmer time at a cost that cannot be recovered over the life cycle of the product in question. That being said, there are plenty of situations where performance obviously does matter a great deal -- as you correctly pointed out. (It all depends on the above mentioned "product in question" and the nature of its life cycle.) Matthias From dfnsonfsduifb at gmx.de Wed Jun 10 11:10:45 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 17:10:45 +0200 Subject: xml.dom.minidom losing the XML document type attribute Message-ID: <79a0njF1pd0bqU1@mid.dfncis.de> Hello group, when I read in a XML document with the xml.dom.minidom parser and write it out again, an attribute is lost: Input: [...] Output: How can I fix this? Python is Python 3.0rc2 (r30rc2:67114, Nov 16 2008, 15:24:36) Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From __peter__ at web.de Wed Jun 10 11:13:50 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:13:50 +0200 Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I wonder if you (or anyone else) might attempt a different explanation > for the use of the special sequence '\1' in the RegEx syntax. > > The Python documentation explains: > > \number > Matches the contents of the group of the same number. Groups are > numbered starting from 1. For example, (.+) \1 matches 'the the' or > '55 55', but not 'the end' (note the space after the group). This > special sequence can only be used to match one of the first 99 groups. > If the first digit of number is 0, or number is 3 octal digits long, > it will not be interpreted as a group match, but as the character with > octal value number. Inside the '[' and ']' of a character class, all > numeric escapes are treated as characters. > > In practice, this appears to be the key to the key device to your > clever solution: > >>>> re.compile(r"(\d+)").sub(r"INSERT \1", string) > > 'abc INSERT 123 def INSERT 456 ghi INSERT 789' > >>>> re.compile(r"(\d+)").sub(r"INSERT ", string) > > 'abc INSERT def INSERT ghi INSERT ' > > I don't, however, precisely understand what is meant by "the group of > the same number" -- or maybe I do, but it isn't explicit. Is this just > a shorthand reference to match.group(1) -- if that were valid -- > implying that the group match result is printed in the compile > execution? If I understand you correctly you are right. Another example: >>> re.compile(r"([a-z]+)(\d+)").sub(r"number=\2 word=\1", "a1 zzz42") 'number=1 word=a number=42 word=zzz' For every match of "[a-z]+\d+" in the original string "\1" in "number=\2 word=\1" is replaced with the actual match for "[a-z]+" and "\2" is replaced with the actual match for "\d+". The result, e. g. "number=1 word=a", is then used to replace the actual match for group 0, i. e. "a1" in the example. Peter From jeff at jmcneil.net Wed Jun 10 11:15:41 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 10 Jun 2009 08:15:41 -0700 (PDT) Subject: Printing dictionary values rather than references References: Message-ID: On Jun 10, 10:19?am, Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. > > class MyClass: > ? ? def __str__(self): > ? ? ? ? return str(self.__dict__) > > if __name__ == '__main__': > ? ? dict = dict() > ? ? classA = MyClass() > ? ? setattr(classA, "attr-1", "val-1") > > ? ? dict['a']= classA > ? ? print classA > ? ? ''' Desired output: {'attr-1': 'val-1'}''' > ? ? print dict > ? ? ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' > > Thanks, > Amit class MyClass: def __repr__(self): # <--- see http://docs.python.org/library/functions.html#repr return str(self.__dict__) HTH, Jeff mcjeff.blogspot.com From bcharrow at csail.mit.edu Wed Jun 10 11:16:56 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Wed, 10 Jun 2009 11:16:56 -0400 Subject: Printing dictionary values rather than references In-Reply-To: <4A2FC109.7080709@oversi.com> References: <4A2FC109.7080709@oversi.com> Message-ID: <4A2FCE68.2010502@csail.mit.edu> Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. > > Thanks, > Amit How about this: class MyClass: def __str__(self): return str(self.__dict__) def __repr__(self): return str(self.__dict__) if __name__ == '__main__': my_dict = dict() classA = MyClass() setattr(classA, "attr-1", "val-1") my_dict['a']= classA print my_dict ''' Actual output: {'attr-1': 'val-1'}''' Though I'm guessing someone is going to say that this is not how repr is supposed be used. See this for more information: http://docs.python.org/reference/datamodel.html#object.__repr__ Cheers, Ben From http Wed Jun 10 11:22:27 2009 From: http (Paul Rubin) Date: 10 Jun 2009 08:22:27 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Message-ID: <7xmy8gazbg.fsf@ruckus.brouhaha.com> Jon Harrop writes: > > I'm not being facetious. I write applications that run on application > > servers, and from time to time I have had to write various special > > purpose servers. This kind of programming is all about managing > > concurrent execution of computations. The overarching concern is > > reliability and correct function. For many corporate situations, even > > with hundreds of users, the actual load at any instant is low enough > > that the various servers involved are nowhere close to being stressed > > out - performance is a secondary issue. > > In other words, without concurrency the latency would be so high > that you would consider the program to be wrong. However you cut it, > the real reason is latency. I don't think that follows, if there is two-way communication and dependency between the servers, combined with lack of control over when any particular server decides to initiate an outgoing request. Stuff may have to happen concurrently to avoid complete deadlock. From Scott.Daniels at Acm.Org Wed Jun 10 11:24:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 08:24:47 -0700 Subject: retrieve bitwise float representation In-Reply-To: References: Message-ID: Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > What I currently do is ... pack and unpack the float using struct.... > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. If you have just a few values, ignore the overhead. Do you really need more cycles for minesweeper? If you have a vector, look into writing from the array directly -- using cStringIO if you need to get to the result within Python, rather than as an I/O format. --Scott David Daniels Scott.Daniels at Acm.Org From wiggly at wiggly.org Wed Jun 10 11:29:36 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Wed, 10 Jun 2009 16:29:36 +0100 Subject: Connection tester In-Reply-To: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Message-ID: <4A2FD160.6070300@wiggly.org> Sparky wrote: > Hey! I am developing a small application that tests multiple websites > and compares their "response time". Some of these sites do not respond > to a ping and, for the measurement to be standardized, all sites must > have the same action preformed upon them. Another problem is that not > all of the sites have the same page size and I am not interested in > how long it takes to load a page but instead just how long it takes > for the website to respond. Finally, I am looking to keep this script > platform independent, if at all possible. Yes, lots of people block ICMP so you can't use it to reliably tell whether a machine is there or not. At least three possible solutions. 1) Perform a HEAD request against the document root. This is likely to be a static page and making it a HEAD request will make most responses take similar times. 2) Perform an OPTIONS request as specified in the RFC below for the * resource. This doesn't always work. 3) Perform a request you believe will fail so that you are provided with a 4XX error code, the only time this should take any appreciable time is when someone has cute server-generated error pages. HTTP/1.1 RFC - http://www.ietf.org/rfc/rfc2616.txt n From __peter__ at web.de Wed Jun 10 11:31:40 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:31:40 +0200 Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 >>> "".join(re.findall("\d+", "123#abc456")) '123456' > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? re.escape() is used to build the regex from a string that may contain characters that have a special meaning in regular expressions but that you want to treat as literals. You can for example search for r"C:\dir" with >>> re.compile(re.escape(r"C:\dir")).findall(r"C:\dir C:7ir") ['C:\\dir'] Without escaping you'd get >>> re.compile(r"C:\dir").findall(r"C:\dir C:7ir") ['C:7ir'] Peter From __peter__ at web.de Wed Jun 10 11:48:17 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:48:17 +0200 Subject: xml application advice References: Message-ID: William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). > > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. The only decent online resource that I can > seem to find is > > http://pyxml.sourceforge.net/topics/howto/xml-howto.html > > which doesn't seem to be a very comprehensive how-to. > > Do demonstrate just about everything I know about xml and python I > attached t.py and ex.xml. > > Another thing that is confusing is dir(walker) does not show walker > having an attribute currentNode and dir(walker.currentNode) does not > show walker.currentNode having an attribute tagName. I'd probably start with a few python classes representing the sprinkler system. The exact layout may change a few times until you have found one that makes your questions clear and the calculations as easy as possible. You can then add a read_model_from_file() function converting the xml into your model using ElementTree or its close relative lxml. My guess is that it'll be a lot more fun this way... Peter From python-url at phaseit.net Wed Jun 10 12:00:39 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Wed, 10 Jun 2009 16:00:39 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 10) Message-ID: QOTW: "Most power systems math can be summed this way: take a really big number and multiply by the square root of two." - iceowl http://everything2.com/index.pl?node_id=1348321 The chuzer project provides a means for severely disabled people to express their most basic needs. The project desperately needs help, or it will die. http://comments.gmane.org/gmane.comp.python.general/625159 Never heard of this - guys competing to see whose is shorter! http://comments.gmane.org/gmane.comp.python.general/625868 Correctly implementing __copy__ and __deepcopy__ with multiple inheritance: http://comments.gmane.org/gmane.comp.python.general/625072 http://comments.gmane.org/gmane.comp.python.general/625291 An overly complicated proposed function leads to discuss good API design principles: http://comments.gmane.org/gmane.comp.python.general/625433 List, tuple, set: when to use each type: http://comments.gmane.org/gmane.comp.python.general/625942 Comparing programming languages: how to do the same thing on several languages: http://comments.gmane.org/gmane.comp.python.general/625637 Generating a dynamic plot of x-y data: http://comments.gmane.org/gmane.comp.python.general/625346 __hash__, __eq__, dictionaries, and the big-Oh notation: http://comments.gmane.org/gmane.comp.python.general/625034 The unladen-swallow project, the LLVM virtual machine, and how they relate to the future of CPython: http://comments.gmane.org/gmane.comp.python.general/625493 Accessing data located in the filesystem, inside a package directory: http://comments.gmane.org/gmane.comp.python.general/625209 Closures in Python don't work exactly the same as in other languages: http://comments.gmane.org/gmane.comp.python.general/625475 How to iterate over several lists, one after another? http://comments.gmane.org/gmane.comp.python.general/625532 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From jeff at jmcneil.net Wed Jun 10 12:01:02 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 10 Jun 2009 09:01:02 -0700 (PDT) Subject: Connection tester References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Message-ID: <289503b8-090a-4eff-a67f-7d37ee62e250@l32g2000vba.googlegroups.com> On Jun 10, 10:26?am, Sparky wrote: > Hey! I am developing a small application that tests multiple websites > and compares their "response time". Some of these sites do not respond > to a ping and, for the measurement to be standardized, all sites must > have the same action preformed upon them. Another problem is that not > all of the sites have the same page size and I am not interested in > how long it takes to load a page but instead just how long it takes > for the website to respond. Finally, I am looking to keep this script > platform independent, if at all possible. > > Here is the code: > > ? ? try: > ? ? ? ? # Get the starting time > ? ? ? ? origTime = time.time() > > ? ? ? ? # Create the socket connection and then close > ? ? ? ? s = socket.socket(AF_INET, SOCK_STREAM) > ? ? ? ? s.connect((targetIP, port)) > ? ? ? ? s.send("GET / HTTP/1.0\r\n\r\n") > ? ? ? ? result = s.recv(1024) > ? ? ? ? s.shutdown(SHUT_RDWR) > > ? ? except: > ? ? ? ? result = "" > > ? ? # Check for problems and report back the time > ? ? if result == "": > ? ? ? ? return Result((time.time() - origTime) * 1000, True) > ? ? else: > ? ? ? ? return Result((time.time() - origTime) * 1000, False) > > Result is just an object that holds the time it took for the method to > finish and if there were any errors. What I am worried about is that > the socket is potentially closed before the website can finish sending > in all the data. Does anyone have any suggestions or is the script > fine as it is? ICMP and application-level response times are two different animals. Are you interested in simply whether or not a server is up and responding, or do you care about the actual response time and performance of the web site you're checking? I did something like this recently and there were a few different metrics we wound up using. Connect time, first-byte, page download, DNS resolution, and so on. Since you don't care about any of that, just use a HEAD request. It will return the response headers, but as per specification it will not return a message body. Take a look at "http://www.w3.org/Protocols/ rfc2616/rfc2616-sec9.html" for a full primer on the different verbs. A somewhat simplistic alternative would be to connect to port 80 on the destination server and drop the connection once it has been made. This will tell you how long it took to establish a TCP session and that something is indeed listening on the destination port. That's slightly more information than you would get from an ICMP reply. From grahn+nntp at snipabacken.se Wed Jun 10 12:16:46 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 16:16:46 GMT Subject: Career Track: Computer Programmer References: <46355271-cd9d-4095-886c-01077360c95f@k20g2000vbp.googlegroups.com> Message-ID: On Mon, 8 Jun 2009 07:49:42 -0700 (PDT), youssef_edward3000 at yahoo.com wrote: > Roles and Responsibilities : > > The primary role of a Computer Programmer is to write programs > according to the instructions determined primarily by computer > software engineers and systems analysts. I hope this is a direct quote from a 1976 issue of some sleazy business magazine, not something anyone believes in today. Except for the systems analysts, maybe. > In a nutshell, Computer > Programmers are the ones that take the completed designs and convert > them into the instructions that the computer can actually follow. That's not a programmer, that's a compiler. Or (to at least *pretend* to be on topic) that's the Python interpreter. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From flyeng4 at gmail.com Wed Jun 10 12:18:15 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 11:18:15 -0500 Subject: xml application advice In-Reply-To: <799v9lF1pj8gqU1@mid.uni-berlin.de> References: <799v9lF1pj8gqU1@mid.uni-berlin.de> Message-ID: <4A2FDCC7.6090708@gmail.com> Diez B. Roggisch wrote: > William Purcell wrote: > >> I am writing a application to calculate pressure drop for a piping >> network. Namely a building sprinkler system. This will be a >> command line program at first with the system described in xml (at >> least that is how I think I want to do it). > Use lxml2 and xpath. > > http://codespeak.net/lxml/ > http://codespeak.net/lxml/xpathxslt.html > This looks promising. I will start playing around with it and see what I can come up with. Thanks for the example. Peter Otten wrote: > I'd probably start with a few python classes representing the > sprinkler > system. The exact layout may change a few times until you have > found one > that makes your questions clear and the calculations as easy as > possible. > > You can then add a read_model_from_file() function converting the > xml into > your model using ElementTree or its close relative lxml. > > My guess is that it'll be a lot more fun this way... This was my initial plan, but I have never messed with xml and didn't know if it was what I wanted. I have messed around with plistlib on a mac. If I remember correctly the reader in plistlib returns a dict so I thought I would be getting a dict from an xml reader (but maybe xml and plist aren't as close as I thought). Reading xml seems more complicated than I initially expected, but probably rightfully so. But I digress. I will take your advice and start with some classes and then work on getting the data to my classes. From Scott.Daniels at Acm.Org Wed Jun 10 12:23:10 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 09:23:10 -0700 Subject: xml application advice In-Reply-To: References: Message-ID: William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml.... If you are going to be doing a lot of tree walking, try etree. Simple example: import xml.etree.ElementTree as ET # or wherever you get ElementTree def find_remote_and_path(node, path): for child in node: for result in walks(child, path + [node]): yield result if node.tag == 'node' and node.get('hydraulically_most_remote' ) == 'True': yield node, path tree = ET.parse('ex.xml') for node, path in find_remote_and_path(tree.getroot(), []): for t in path: print ' ', t.tag, t.get('id', '-') print node.tag, ', '.join(sorted('%s=%r' % pair for pair in node.items())) --Scott David Daniels Scott.Daniels at Acm.Org From grahn+nntp at snipabacken.se Wed Jun 10 12:34:29 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 16:34:29 GMT Subject: xml application advice References: Message-ID: On Wed, 10 Jun 2009 08:57:42 -0500, William Purcell wrote: ... > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). How about (re)using the dot graph language from Graphviz? It's a file format for describing directed graphs, which I suppose a sprinkler system is. It might fit; it might not. > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. If what you're interested in is to get real work done, why decide to make XML a showstopper? I see two tasks: (a) transforming a text file description of a sprinkler system into a Python data structure, and (b) implementing algorithms to find out important stuff about such a data structure. You do not need (a) before you can do (b). You can even have Python as your input format, and eval() the file. Crude and insecure, but it works, at almost zero cost. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From flyeng4 at gmail.com Wed Jun 10 12:39:33 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 11:39:33 -0500 Subject: xml application advice In-Reply-To: References: Message-ID: <4A2FE1C5.5070604@gmail.com> Scott David Daniels wrote: > William Purcell wrote: >> I am writing a application to calculate pressure drop for a piping >> network. Namely a building sprinkler system. This will be a >> command line program at first with the system described in xml.... > > If you are going to be doing a lot of tree walking, try etree. > Simple example: > > import xml.etree.ElementTree as ET # or wherever you get ElementTree > > def find_remote_and_path(node, path): > for child in node: > for result in walks(child, path + [node]): yield result > if node.tag == 'node' and node.get('hydraulically_most_remote' > ) == 'True': > yield node, path > > > tree = ET.parse('ex.xml') > for node, path in find_remote_and_path(tree.getroot(), []): > for t in path: > print ' ', t.tag, t.get('id', '-') > print node.tag, ', '.join(sorted('%s=%r' % pair > for pair in node.items())) > > > --Scott David Daniels > Scott.Daniels at Acm.Org Scott, Thanks for the reply. I am having a little trouble finding where to import `walks` from. Bill From David.Shapiro at sas.com Wed Jun 10 12:42:44 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 12:42:44 -0400 Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: Maybe a using a Unicode equiv of # would do the trick. -----Original Message----- From: python-list-bounces+david.shapiro=sas.com at python.org [mailto:python-list-bounces+david.shapiro=sas.com at python.org] On Behalf Of Peter Otten Sent: Wednesday, June 10, 2009 11:32 AM To: python-list at python.org Subject: Re: How to escape # hash character in regex match strings 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 >>> "".join(re.findall("\d+", "123#abc456")) '123456' > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? re.escape() is used to build the regex from a string that may contain characters that have a special meaning in regular expressions but that you want to treat as literals. You can for example search for r"C:\dir" with >>> re.compile(re.escape(r"C:\dir")).findall(r"C:\dir C:7ir") ['C:\\dir'] Without escaping you'd get >>> re.compile(r"C:\dir").findall(r"C:\dir C:7ir") ['C:7ir'] Peter -- http://mail.python.org/mailman/listinfo/python-list From Scott.Daniels at Acm.Org Wed Jun 10 13:06:17 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 10:06:17 -0700 Subject: xml application advice In-Reply-To: References: Message-ID: William Purcell wrote: > Scott David Daniels wrote: >> William Purcell wrote: >>> I am writing a application to calculate pressure drop for a piping >>> network. Namely a building sprinkler system. This will be a >>> command line program at first with the system described in xml.... >> If you are going to be doing a lot of tree walking, try etree. >> Simple example: >> >> import xml.etree.ElementTree as ET # or wherever you get ElementTree >> >> def find_remote_and_path(node, path): >> for child in node: >> for result in walks(child, path + [node]): yield result >> if node.tag == 'node' and node.get('hydraulically_most_remote' >> ) == 'True': >> yield node, path >> >> >> tree = ET.parse('ex.xml') >> for node, path in find_remote_and_path(tree.getroot(), []): >> for t in path: >> print ' ', t.tag, t.get('id', '-') >> print node.tag, ', '.join(sorted('%s=%r' % pair >> for pair in node.items())) >> >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Scott, Thanks for the reply. > > I am having a little trouble finding where to import `walks` from. > > Bill Sorry, renamed and forgot to repaste. walks is just find_remote_and_path From mensanator at aol.com Wed Jun 10 13:21:14 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 10:21:14 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> Message-ID: <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> On Jun 10, 4:01?am, Mark Dickinson wrote: > On Jun 10, 7:25?am, John Yeung wrote: > > > > > > > On Jun 10, 1:52?am, Steven D'Aprano > > > wrote: > > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > > Therefore, to me the most up-to-date docs (which say > > > > that uniform(a, b) returns a float in the closed > > > > interval [a, b]) is closer to correct than before, > > > > but still fails to point out the full subtlety of > > > > the behavior. > > > > Which is? > > > That uniform(a, b) will return a random float in the semi-open > > interval [a, b) for certain values of a and b; and in the closed > > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > > To me, the fact that you sometimes get a semi-open interval and > > sometimes a closed interval is worth noting in the docs. > > Do you want to submit a doc patch? > > For practical purposes, I think you'd be hard-pressed to find a > statistical > test that could reliably distinguish between a large sample of values > from > random.uniform(a, b) and a sample from a 'perfect' uniform > distribution on > the closed interval [a, b]. ?It's true that there are values of a and > b > such that random.uniform(a, b) can never produce b. ? So, the 2.6.2 documentation is STILL wrong. Before it implied it was ALWAYS a semi-open interval, and now it says it's ALWAYS a closed interval. But neither is correct. I think a doc patch is definitely warranted. > But for given a and b, > not too close together, there may be many other values that can't be > produced as well, so it hardly seems worth pointing out one particular > value that can never be produced. > > Example: on a typical system there are almost 2**62 floats in the > range [0, 1); ?the vast majority of these can never be produced by > random.random(), which can only ever return one of 2**53 distinct > values > (it essentially just returns a value of the form n/2**53 with n > an integer in the range [0, 2**53)). ?So random.uniform(0, 1) will > miss lots of possible values. > > On the other hand, it's easy to find examples of a and b such that > random.uniform(a, b) has a significant chance of producing b. > For example, take a = 10**16, b = 10**16 + 4, then there's about a 1 > in 4 chance of getting b. Or for a more extreme example, simply > take a = b. ?Hence the doc change. > > Mark From deets at nospam.web.de Wed Jun 10 13:35:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 19:35:24 +0200 Subject: xml application advice References: Message-ID: <79a911F1pth9qU1@mid.uni-berlin.de> > > If what you're interested in is to get real work done, why decide to > make XML a showstopper? > > I see two tasks: (a) transforming a text file description of a sprinkler > system into a Python data structure, and (b) implementing algorithms > to find out important stuff about such a data structure. > > You do not need (a) before you can do (b). You can even have Python as > your input format, and eval() the file. Crude and insecure, but it > works, at almost zero cost. While I certainly agree that XML often means more trouble than it's worth, I don't concur in this concrete case. If the OP has a tree-structure, XPath is a *very* powerful way to operate on that - and as he seems to have questions like "get the one node with the attribute X, then the first one above that having more than one child of kind Y", it can get in handy. Diez From dickinsm at gmail.com Wed Jun 10 13:37:01 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 10:37:01 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> On Jun 10, 6:21?pm, Mensanator wrote: > So, the 2.6.2 documentation is STILL wrong. Before it implied > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > a closed interval. But neither is correct. Exactly which bit of the 2.6.2 documentation do you think is incorrect? The documentation for random.uniform says: """Return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a.""" And that's precisely what it does. Nowhere does the documentation say that *every* floating-point number N in the interval [a, b] can occur. Mark From Samnsparky at gmail.com Wed Jun 10 13:37:59 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 10 Jun 2009 10:37:59 -0700 (PDT) Subject: Connection tester References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> <289503b8-090a-4eff-a67f-7d37ee62e250@l32g2000vba.googlegroups.com> Message-ID: <58c2404d-d5c8-4fa8-9541-a2ead43d288b@e20g2000vbc.googlegroups.com> On Jun 10, 10:01?am, Jeff McNeil wrote: > On Jun 10, 10:26?am, Sparky wrote: > > > > > Hey! I am developing a small application that tests multiple websites > > and compares their "response time". Some of these sites do not respond > > to a ping and, for the measurement to be standardized, all sites must > > have the same action preformed upon them. Another problem is that not > > all of the sites have the same page size and I am not interested in > > how long it takes to load a page but instead just how long it takes > > for the website to respond. Finally, I am looking to keep this script > > platform independent, if at all possible. > > > Here is the code: > > > ? ? try: > > ? ? ? ? # Get the starting time > > ? ? ? ? origTime = time.time() > > > ? ? ? ? # Create the socket connection and then close > > ? ? ? ? s = socket.socket(AF_INET, SOCK_STREAM) > > ? ? ? ? s.connect((targetIP, port)) > > ? ? ? ? s.send("GET / HTTP/1.0\r\n\r\n") > > ? ? ? ? result = s.recv(1024) > > ? ? ? ? s.shutdown(SHUT_RDWR) > > > ? ? except: > > ? ? ? ? result = "" > > > ? ? # Check for problems and report back the time > > ? ? if result == "": > > ? ? ? ? return Result((time.time() - origTime) * 1000, True) > > ? ? else: > > ? ? ? ? return Result((time.time() - origTime) * 1000, False) > > > Result is just an object that holds the time it took for the method to > > finish and if there were any errors. What I am worried about is that > > the socket is potentially closed before the website can finish sending > > in all the data. Does anyone have any suggestions or is the script > > fine as it is? > > ICMP and application-level response times are two different animals. > Are you interested in simply whether or not a server is up and > responding, or do you care about the actual response time and > performance of the web site you're checking? I did something like this > recently and there were a few different metrics we wound up using. > Connect time, first-byte, page download, DNS resolution, and so on. > > Since you don't care about any of that, just use a HEAD request. It > will return the response headers, but as per specification it will not > return a message body. ?Take a look at "http://www.w3.org/Protocols/ > rfc2616/rfc2616-sec9.html" for a full primer on the different verbs. > > A somewhat simplistic alternative would be to connect to port 80 on > the destination server and drop the connection once it has been made. > This will tell you how long it took to establish a TCP session and > that something is indeed listening on the destination port. That's > slightly more information than you would get from an ICMP reply. Thank you all for your responses. I will play with everything but the HEAD request seems to be what I was looking for. Sam From smacrae319 at live.ca.invalid Wed Jun 10 13:49:30 2009 From: smacrae319 at live.ca.invalid (Seamus MacRae) Date: Wed, 10 Jun 2009 13:49:30 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. And when, exactly, did Microsoft go out of business? I hadn't heard it mentioned in the news. :) From mensanator at aol.com Wed Jun 10 13:57:03 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 10:57:03 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> Message-ID: <0a6d1387-c181-4092-82a1-e889458e9a2b@k20g2000vbp.googlegroups.com> On Jun 10, 12:37?pm, Mark Dickinson wrote: > On Jun 10, 6:21?pm, Mensanator wrote: > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > a closed interval. But neither is correct. > > Exactly which bit of the 2.6.2 documentation do you think is > incorrect? ?The documentation for random.uniform says: > > """Return a random floating point number N such that > a <= N <= b for a <= b and b <= N <= a for b < a.""" > > And that's precisely what it does. ? I didn't say it didn't. > Nowhere does the documentation say that *every* Unless qualified otherwise, that statement implies "for all (a,b)". > floating-point number N in the interval [a, b] > can occur. > > Mark From massung at gmail.com Wed Jun 10 14:07:12 2009 From: massung at gmail.com (Jeff M.) Date: Wed, 10 Jun 2009 11:07:12 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: On Jun 10, 12:49?pm, Seamus MacRae wrote: > Jeff M. wrote: > > On Jun 9, 9:08 pm, Arved Sandstrom wrote: > >> Jon Harrop wrote: > >>> Arved Sandstrom wrote: > >>>> Jon, I do concurrent programming all the time, as do most of my peers. > >>>> Way down on the list of why we do it is the reduction of latency. > >>> What is higher on the list? > >> Correctness. > > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > > important, no matter what application you are creating; without it, > > you don't have a job and the company you work for goes out of > > business. > > And when, exactly, did Microsoft go out of business? I hadn't heard it > mentioned in the news. :) Touche. :) Jeff M. From jcherry7 at gatech.edu Wed Jun 10 14:22:22 2009 From: jcherry7 at gatech.edu (jcherry7 at gatech.edu) Date: Wed, 10 Jun 2009 14:22:22 -0400 (EDT) Subject: How do you insert an image into Powerpoint using python/win32? In-Reply-To: <1020484807.3818011244658074185.JavaMail.root@mail8.gatech.edu> Message-ID: <1315873239.3818291244658142466.JavaMail.root@mail8.gatech.edu> I have python 3.0.1, and have downloaded pywin32 for python 3.x, aka build #213. I ran win32com.client.makepy.py on Microsoft Office 12.0 Object Library and Microsoft PowerPoint 12.0 Object Library. The output files were placed in win32com.gen_py. I renamed them as MSO.py and MSPPT.py, respectively. The following code is located in my c:\Python30 folder. Thinkter is used to prompt the user to choose the image that they want to put onto the slide. THe 10 pointed star was an experiment, to try to import something into the image. Here is the code as I currently have it: from tkinter import * import tkinter.filedialog as tkFileDialog import win32com.client # middleman/translator/messanger between windows and python import win32com.gen_py.MSO as MSO # contains constants refering to Microsoft Office Objects import win32com.gen_py.MSPPT as MSPPT # contains constants refering to Microsoft Office Power Point Objects g = globals() # a dictonary of global vlaues, that will be the constants of the two previous imports for c in dir(MSO.constants): g[c] = getattr(MSO.constants, c) # globally define these for c in dir(MSPPT.constants): g[c] = getattr(MSPPT.constants, c) Application = win32com.client.Dispatch("PowerPoint.Application") Application.Visible = True # shows what's happening, not required, but helpful for now Presentation = Application.Presentations.Add() # adds a new presentation Slide1 = Presentation.Slides.Add(1, ppLayoutBlank) # new slide, at beginning TenptStr = Slide1.Shapes.AddShape(msoShape10pointStar, 100, 100, 200, 200) pictName = tkFileDialog.askopenfilename(title="Please Select the Image you wish to load") print(pictName) Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200) this is the error: Traceback (most recent call last): File "C:\Python30\PowerPointEditer.py", line 21, in Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200)#pictName, pictName, 200, 200, 200, 200) File "C:\Python30\lib\site-packages\win32com\gen_py\MSPPT.py", line 8544, in AddPicture , Height) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None) It seems I'm passing AddPictures the wrong varibles Thanks. -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology From malkia at mac.com Wed Jun 10 14:26:24 2009 From: malkia at mac.com (Dimiter "malkia" Stanev) Date: Wed, 10 Jun 2009 11:26:24 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. PC / Video Games definitely fall out of the correctness. As long as the game does not crash your XBOX/PS3/Whatever for certain amount of time, and behaves well then, it's fine. Bugs are already part of the "genre". In reality you can't ship on time, there are always BUGS :) Most important thing in games is (at least for large percent of them) speed of graphics - fluid 60fps, or stable 30fps. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. > > Programs that use more memory require more money for the hardware of > every user. Programs that run slower eat more time per day. If you > have 100,000 users, all doing an operation once per day that takes 20 > seconds, being able to shave 5 seconds off that saves 5.78 man-days of > work. Hell, for some applications, that 20 seconds is just startup > time spent at a splash screen. Just imagine if every Google search > took even 5 seconds to resolve, how much time would be wasted every > day around the world - ignoring the fact that Google wouldn't exist if > that were the case ;-). Obviously Google engineers work incredibly > hard every day to ensure correct results, but performance better be > right up there at the top of the list as well. > > Jeff M. From robert.kern at gmail.com Wed Jun 10 14:47:40 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 13:47:40 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: On 2009-06-09 19:27, Mensanator wrote: > On Jun 9, 6:12 pm, Robert Kern wrote: >> On 2009-06-09 18:05, Mensanator wrote: >> >> >> >> >> >>> On Jun 9, 4:33 pm, Esmail wrote: >>>> Hi, >>>> random.random() will generate a random value in the range [0, 1). >>>> Is there an easy way to generate random values in the range [0, 1]? >>>> I.e., including 1? >>>> I am implementing an algorithm and want to stay as true to the >>>> original design specifications as possible though I suppose the >>>> difference between the two max values might be minimal. >>>> Thanks, >>>> Esmail >>>> ps: I'm confused by the docs for uniform(): >>>> random.uniform(a, b) >>>> Return a random floating point number N such that a<= N<= b for a<= b >>> That's wrong. Where did you get it? >> http://docs.python.org/library/random > > Ok, but the 2.6.1 docs say > > random.uniform(a, b) > Return a random floating point number N such that a<= N< b > for a<= b and b<= N< a for b< a. > > Is that a new feature of 2.6.2? As already pointed out, it's not really a new feature of the method, but rather a fix for the buggy documentation. Because of floating point arithmetic, one cannot guarantee that a+(b-a)*u is strictly in [a,b) even though u is strictly in [0,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 tjreedy at udel.edu Wed Jun 10 14:53:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 14:53:19 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: Mensanator wrote: > So, the 2.6.2 documentation is STILL wrong. Before it implied > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > a closed interval. But neither is correct. If a < x < b is true, then a <= x <= b is true. But docs say that in general end point values might happen. They do not say that in every particular case, they will happen. A full technical discussion does not below in the docs, in my opinion. A wike article would be fine. tjr From dickinsm at gmail.com Wed Jun 10 15:00:45 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 12:00:45 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> <0a6d1387-c181-4092-82a1-e889458e9a2b@k20g2000vbp.googlegroups.com> Message-ID: <933c2e58-108b-49cc-8bfd-412bfae2b93c@x5g2000yqk.googlegroups.com> On Jun 10, 6:57?pm, Mensanator wrote: > On Jun 10, 12:37?pm, Mark Dickinson wrote: > > > On Jun 10, 6:21?pm, Mensanator wrote: > > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > > a closed interval. But neither is correct. > > > Exactly which bit of the 2.6.2 documentation do you think is > > incorrect? ?The documentation for random.uniform says: > > > """Return a random floating point number N such that > > a <= N <= b for a <= b and b <= N <= a for b < a.""" > > > And that's precisely what it does. ? > > I didn't say it didn't. > > > Nowhere does the documentation say that *every* > > Unless qualified otherwise, that statement implies "for all (a,b)". Sure. For all a <= b, it's true that a <= uniform(a, b) <= b. And similarly for b <= a. I really don't see the problem: the documentation is both technically correct and useful in practice. The assertion implicit in the name and description of the random.uniform function is that, to a very good approximation, the values produced by random.uniform(a, b) will be uniformly distributed on the closed interval [a, b]. And that's true (at least within the limits of floating-point arithmetic). Can you think of a single practical situation where it would matter that, for some values of a and b, uniform(a, b) can never produce the value b? Mark From msburson at gmail.com Wed Jun 10 15:01:13 2009 From: msburson at gmail.com (Matt Burson) Date: Wed, 10 Jun 2009 14:01:13 -0500 Subject: Restart the interactive python shell like in IDLE Message-ID: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> Is there a way to reproduce the behavior of IDLE's restart shell ability by using a function? I thought there would be since you can exit python by executing the simple quit() function I thought there would be an equally simple function name something like restart(). I'd prefer something like this as opposed to having to exit the shell and then start it up again to refresh it. -- Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Jun 10 15:15:58 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 14:15:58 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: On 2009-06-10 13:53, Terry Reedy wrote: > Mensanator wrote: > >> So, the 2.6.2 documentation is STILL wrong. Before it implied >> it was ALWAYS a semi-open interval, and now it says it's ALWAYS >> a closed interval. But neither is correct. > > If a < x < b is true, then a <= x <= b is true. > But docs say that in general end point values might happen. They do not > say that in every particular case, they will happen. I'm not so sure. Context is important. When discussing the bounds of random number generators, specifying <= instead of < strongly suggests that the bound is one of the possible results. I've had to read a lot of random number generator documentation in my time. To take the point to absurdity, it would be wrong for the function to return just values within (a+0.25*b, a+0.75*b) even though the docs "just" say that the result will be between a and b. > A full technical discussion does not below in the docs, in my opinion. A > wike article would be fine. True. However, a brief note that "Due to floating point arithmetic, for some values of a and b, b may or may not be one of the possible generated results." might be worthwhile. The actual details of *why* this is the case can be discussed elsewhere. -- 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 Wed Jun 10 15:31:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 15:31:32 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: Carl Banks wrote: >> Sometimes alternate constructors are needed when there is more than one >> possible way to create an instance from a given input. In the case of >> str(iterable), one could want either a string representing the iterable >> itself, just as with non-iterables, or a string representing the >> concatenated contents of the iterable. Str.join implements the second >> choice, with an added string parameter to allow a constant string to be >> interpolated between the joined items. > > But then how do you rationalize str.split(), which is a method of str > but a constructor of list? Str.join takes any iterable of strings and constructs a string. Only str knows how to do that, though it could have a built-in that called a hypothetical .__join__ method. However, Python started with just one string type and there does not seem much use for joining an indefinite number of tuples or lists. (In any case, there is no string equivalent of list.extend, which can be used for joining multiple lists.) Str.split only takes a string arg and splits it up. Only str should know how to split a string. That it returns the pieces as a list is a historical artifact. I could have returned a tuple. It could have been changed in 3.0 to return an iterater, like map and others were. If Python were being designed today with iterators as a basic protocol, and without the baggage of back compatibility, I am fairly sure .split would return an iterator. > Perhaps instead of worrying about symmetry all the time we should just > accept the inevitability that things will always be asymmetric and > impure from someone's perspective. Terry's symmetry is Hendrik's > asymmetry and vice versa. That was one of my implied points ;-). Terry Jan Reedy From manavan.j at gmail.com Wed Jun 10 15:34:56 2009 From: manavan.j at gmail.com (Manavan) Date: Wed, 10 Jun 2009 12:34:56 -0700 (PDT) Subject: object reincarnation Message-ID: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Hello everyone, Since the real world objects often needs to be deleted even if they have some reference from some other object, I am going to use this approach to better model this situation, by cleaning up the attributes and assigning self.__class__ to a different class. Any comment on this approach. class Deleted(object): pass class RealWorldObj(object): def __init__(self, *args): self.attrs = args def getAttrs(self,): return self.attrs def delete(self,): del self.attrs self.__class__ = Deleted >>> a = RealWorldObj(1,2,3) >>> print a.attrs (1, 2, 3) >>> a.delete() >>> a <__main__.Deleted object at 0x893ae2c> >>> a.attrs Traceback (most recent call last): File "", line 1, in AttributeError: 'Deleted' object has no attribute 'attrs' From jon at ffconsultancy.com Wed Jun 10 15:42:09 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 10 Jun 2009 20:42:09 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Matthias Blume wrote: > "Jeff M." writes: >> But, assuming that your program works and does what it's supposed to, >> I agree with Jon that performance needs to be right near the top of >> the list of concerns. Why? Performance isn't about looking good as a >> programmer, or having fun making a function run in 15 cycles instead >> of 24, or coming up with some neat bit packing scheme so that your app >> now only uses 20K instead of 200K. Performance is - pure and simple - >> about one thing only: money. > > Programmer time is vastly more expensive than CPU time, so the > money argument often leads to slow ("low performance") solutions as long > as they are "good enough" because developing a faster solution would > mean spending more valuable programmer time at a cost that cannot > be recovered over the life cycle of the product in question. In the context of commercial software, the money to fund developers to improve performance comes from the huge marketing budget because performance is usually more about marketing than anything else. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From dickinsm at gmail.com Wed Jun 10 15:46:15 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 12:46:15 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> On Jun 10, 8:15?pm, Robert Kern wrote: > On 2009-06-10 13:53, Terry Reedy wrote: > > A full technical discussion does not below in the docs, in my opinion. A > > wike article would be fine. > > True. However, a brief note that "Due to floating point arithmetic, for some > values of a and b, b may or may not be one of the possible generated results." > might be worthwhile. The actual details of *why* this is the case can be > discussed elsewhere. I find it difficult to see how such a disclaimer would have any practical value, without also knowing *which* values of a and b are affected. It can certainly be useful to know that endpoints *aren't* included where that's true. For example, knowing that random.random() can never produce the value 1.0 means that one can safely generate a mean 1 exponential variate with -log(1-random.random()), without worrying about the possibility of taking log of 0. But I don't know why it would be useful to know that endpoints *are* sometimes included, without knowing exactly when. Mark From jcherry7 at gatech.edu Wed Jun 10 15:47:49 2009 From: jcherry7 at gatech.edu (Cherry, Jonathan M) Date: Wed, 10 Jun 2009 15:47:49 -0400 (EDT) Subject: How do you insert an image into Powerpoint using python/win32? In-Reply-To: <1315873239.3818291244658142466.JavaMail.root@mail8.gatech.edu> Message-ID: <1902394141.3844521244663269463.JavaMail.root@mail8.gatech.edu> Never mind, its just that the "choose file" option produces a file path with '/" rather than '\', and python cannot use the former. Thanks anyway ----- Original Message ----- From: jcherry7 at gatech.edu To: python-list at python.org Sent: Wednesday, June 10, 2009 2:22:22 PM GMT -05:00 US/Canada Eastern Subject: How do you insert an image into Powerpoint using python/win32? I have python 3.0.1, and have downloaded pywin32 for python 3.x, aka build #213. I ran win32com.client.makepy.py on Microsoft Office 12.0 Object Library and Microsoft PowerPoint 12.0 Object Library. The output files were placed in win32com.gen_py. I renamed them as MSO.py and MSPPT.py, respectively. The following code is located in my c:\Python30 folder. Thinkter is used to prompt the user to choose the image that they want to put onto the slide. THe 10 pointed star was an experiment, to try to import something into the image. Here is the code as I currently have it: from tkinter import * import tkinter.filedialog as tkFileDialog import win32com.client # middleman/translator/messanger between windows and python import win32com.gen_py.MSO as MSO # contains constants refering to Microsoft Office Objects import win32com.gen_py.MSPPT as MSPPT # contains constants refering to Microsoft Office Power Point Objects g = globals() # a dictonary of global vlaues, that will be the constants of the two previous imports for c in dir(MSO.constants): g[c] = getattr(MSO.constants, c) # globally define these for c in dir(MSPPT.constants): g[c] = getattr(MSPPT.constants, c) Application = win32com.client.Dispatch("PowerPoint.Application") Application.Visible = True # shows what's happening, not required, but helpful for now Presentation = Application.Presentations.Add() # adds a new presentation Slide1 = Presentation.Slides.Add(1, ppLayoutBlank) # new slide, at beginning TenptStr = Slide1.Shapes.AddShape(msoShape10pointStar, 100, 100, 200, 200) pictName = tkFileDialog.askopenfilename(title="Please Select the Image you wish to load") print(pictName) Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200) this is the error: Traceback (most recent call last): File "C:\Python30\PowerPointEditer.py", line 21, in Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200)#pictName, pictName, 200, 200, 200, 200) File "C:\Python30\lib\site-packages\win32com\gen_py\MSPPT.py", line 8544, in AddPicture , Height) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None) It seems I'm passing AddPictures the wrong varibles Thanks. -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology From tjreedy at udel.edu Wed Jun 10 16:00:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:00:36 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: Robert Kern wrote: >> Important correction noted. But how did you find those? When I search >> for 'Shaw' with the search box (I tried it again), I only get a couple >> of other, irrelevant hits. Is the search box buggy? > > I suspect so. I knew of most of them already, and Googling > site:pypi.python.org picked up the rest. Will use that in the future. In the meanwhile, I submitted a bug report. From martin at v.loewis.de Wed Jun 10 16:00:59 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 10 Jun 2009 22:00:59 +0200 Subject: Compiling Python3.1 In-Reply-To: <799co4F1pdqgeU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> Message-ID: <4a3010fb$0$22010$9b622d9e@news.freenet.de> > What can I do about that? Remove the non-ASCII characters from db.h. Regards, Martin From matzke at berkeley.edu Wed Jun 10 16:09:59 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 13:09:59 -0700 Subject: cleaning up an ASCII file? Message-ID: <4A301317.8080607@berkeley.edu> Hi all, So I'm parsing an XML file returned from a database. However, the database entries have occasional non-ASCII characters, and this is crashing my parsers. Is there some handy function out there that will schlep through a file like this, and do something like fix the characters that it can recognize, and delete those that it can't? Basically, like the BBEdit "convert to ASCII" menu option under "Text". I googled some on this, but nothing obvious came up that wasn't specific to fixing one or a few characters. Thanks! Nick -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From tjreedy at udel.edu Wed Jun 10 16:22:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:22:46 -0400 Subject: Printing dictionary values rather than references In-Reply-To: <4A2FC109.7080709@oversi.com> References: <4A2FC109.7080709@oversi.com> Message-ID: Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. You can only print string representations, as defined by type(ob).__str__ and type(ob).__repr__. > > class MyClass: > def __str__(self): > return str(self.__dict__) > > if __name__ == '__main__': > dict = dict() Rebinding built-in names is a bad idea unless you *really* mean to replace the original. > classA = MyClass() > setattr(classA, "attr-1", "val-1") > > dict['a']= classA > print classA > ''' Desired output: {'attr-1': 'val-1'}''' > print dict > ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' > > Thanks, > Amit From robert.kern at gmail.com Wed Jun 10 16:32:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 15:32:05 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-10 14:46, Mark Dickinson wrote: > On Jun 10, 8:15 pm, Robert Kern wrote: >> On 2009-06-10 13:53, Terry Reedy wrote: >>> A full technical discussion does not below in the docs, in my opinion. A >>> wike article would be fine. >> True. However, a brief note that "Due to floating point arithmetic, for some >> values of a and b, b may or may not be one of the possible generated results." >> might be worthwhile. The actual details of *why* this is the case can be >> discussed elsewhere. > > I find it difficult to see how such a disclaimer would have any > practical > value, without also knowing *which* values of a and b are affected. > > It can certainly be useful to know that endpoints *aren't* included > where > that's true. For example, knowing that random.random() can never > produce the > value 1.0 means that one can safely generate a mean 1 exponential > variate with > -log(1-random.random()), without worrying about the possibility of > taking log > of 0. > > But I don't know why it would be useful to know that endpoints *are* > sometimes > included, without knowing exactly when. That's a fair point. However, one issue that hasn't been brought up is that it might be confusing to a user why random.random() returns values in a half-open interval while random.uniform() claims a closed interval. Even for reasonably sophisticated floating point users, it's not necessarily obvious that that is the reasoning behind the different claims. -- 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 Jun 10 16:35:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 15:35:14 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-10 15:32, Robert Kern wrote: > On 2009-06-10 14:46, Mark Dickinson wrote: >> But I don't know why it would be useful to know that endpoints *are* >> sometimes >> included, without knowing exactly when. > > That's a fair point. However, one issue that hasn't been brought up is > that it might be confusing to a user why random.random() returns values > in a half-open interval while random.uniform() claims a closed interval. > Even for reasonably sophisticated floating point users, it's not > necessarily obvious that that is the reasoning behind the different claims. Basically, if we can forestall another tedious thread about imagined asymmetry and "hemispatial neglect" with a single sentence, I'm all for 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 tjreedy at udel.edu Wed Jun 10 16:36:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:36:27 -0400 Subject: object reincarnation In-Reply-To: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: Manavan wrote: > Hello everyone, > Since the real world objects often needs to be deleted even if they > have some reference from some other object, I am going to use this > approach to better model this situation, by cleaning up the attributes > and assigning self.__class__ to a different class. > Any comment on this approach. It might be easier to give the class a status variable so instances can be de-activated without destroying info and perhaps re-activated. > > class Deleted(object): > pass > > class RealWorldObj(object): > def __init__(self, *args): > self.attrs = args > def getAttrs(self,): > return self.attrs > def delete(self,): > del self.attrs > self.__class__ = Deleted > > >>>> a = RealWorldObj(1,2,3) >>>> print a.attrs > (1, 2, 3) >>>> a.delete() >>>> a > <__main__.Deleted object at 0x893ae2c> >>>> a.attrs > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'Deleted' object has no attribute 'attrs' From vlastimil.brom at gmail.com Wed Jun 10 16:39:04 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 10 Jun 2009 22:39:04 +0200 Subject: cleaning up an ASCII file? In-Reply-To: <4A301317.8080607@berkeley.edu> References: <4A301317.8080607@berkeley.edu> Message-ID: <9fdb569a0906101339v7da2d55fob77df2c9e2463f3@mail.gmail.com> 2009/6/10 Nick Matzke : > Hi all, > > So I'm parsing an XML file returned from a database. ?However, the database > entries have occasional non-ASCII characters, and this is crashing my > parsers. > > Is there some handy function out there that will schlep through a file like > this, and do something like fix the characters that it can recognize, and > delete those that it can't? ?Basically, like the BBEdit "convert to ASCII" > menu option under "Text". > > I googled some on this, but nothing obvious came up that wasn't specific to > fixing one or a few characters. > > Thanks! > Nick > > > -- > ==================================================== > Nicholas J. Matzke > Ph.D. Candidate, Graduate Student Researcher > Huelsenbeck Lab > Center for Theoretical Evolutionary Genomics > 4151 VLSB (Valley Life Sciences Building) > Department of Integrative Biology > University of California, Berkeley > > Lab websites: > http://ib.berkeley.edu/people/lab_detail.php?lab=54 > http://fisher.berkeley.edu/cteg/hlab.html > Dept. personal page: > http://ib.berkeley.edu/people/students/person_detail.php?person=370 > Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html > Lab phone: 510-643-6299 > Dept. fax: 510-643-6264 > Cell phone: 510-301-0179 > Email: matzke at berkeley.edu > > Mailing address: > Department of Integrative Biology > 3060 VLSB #3140 > Berkeley, CA 94720-3140 > > ----------------------------------------------------- > "[W]hen people thought the earth was flat, they were wrong. When people > thought the earth was spherical, they were wrong. But if you think that > thinking the earth is spherical is just as wrong as thinking the earth is > flat, then your view is wronger than both of them put together." > > Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, > 14(1), 35-44. Fall 1989. > http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm > ==================================================== > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, depending on the circumstances, there are probably more sophisticated ways (what does "fix the characters" mean?), but do you maybe think something like: >>> u"a??b??c??d".encode("ascii", "ignore") 'abcd' ? It might be important to ensure, that you won't loose any useful information; where are the unexpected characters coming from, or couldn't it possibly be fixed in that source? hth, vbr From tjreedy at udel.edu Wed Jun 10 16:41:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:41:27 -0400 Subject: cleaning up an ASCII file? In-Reply-To: <4A301317.8080607@berkeley.edu> References: <4A301317.8080607@berkeley.edu> Message-ID: Nick Matzke wrote: > Hi all, > > So I'm parsing an XML file returned from a database. However, the > database entries have occasional non-ASCII characters, and this is > crashing my parsers. > > Is there some handy function out there that will schlep through a file > like this, and do something like fix the characters that it can > recognize, and delete those that it can't? Basically, like the BBEdit > "convert to ASCII" menu option under "Text". Lookup str.maketrans and str.translate, which can leave alone, replace, or delete each char. From dickinsm at gmail.com Wed Jun 10 16:54:50 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 20:54:50 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: <4a301d9a$0$90270$14726298@news.sunsite.dk> Robert Kern wrote: > On 2009-06-10 14:46, Mark Dickinson wrote: >> On Jun 10, 8:15 pm, Robert Kern wrote: >>> On 2009-06-10 13:53, Terry Reedy wrote: >>>> A full technical discussion does not below in the docs, in my opinion. A >>>> wike article would be fine. >>> True. However, a brief note that "Due to floating point arithmetic, for some >>> values of a and b, b may or may not be one of the possible generated results." >>> might be worthwhile. The actual details of *why* this is the case can be >>> discussed elsewhere. >> >> I find it difficult to see how such a disclaimer would have any >> practical value >> [lots more badly wrapped text snipped... ] > > That's a fair point. However, one issue that hasn't been brought up is that it > might be confusing to a user why random.random() returns values in a half-open > interval while random.uniform() claims a closed interval. Even for reasonably > sophisticated floating point users, it's not necessarily obvious that that is > the reasoning behind the different claims. True. I guess the original post in this thread is good evidence of that. Though I'm not sure I'm capable of coming up with extra wording for the docs that won't just cause more confusion, so I'll leave that to someone else. I seem to recall that when this originally came up in the tracker (issue 4979) the fun part of the analysis was proving that random.uniform(a, b) can never produce values *outside* the interval [a, b]. :-) -- Mark Dickinson From aaron.watters at gmail.com Wed Jun 10 17:08:09 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Wed, 10 Jun 2009 14:08:09 -0700 (PDT) Subject: free chart lib for Python? References: Message-ID: <70761fe3-1753-44e7-9c65-24d5afae5787@q37g2000vbi.googlegroups.com> On May 7, 10:27 pm, oyster wrote: > I mean chart, not plot. If you don't know the difference, you can > checkwww.advsofteng.com, which is a commercial program > > is there such a thing with many kinds ofchart, i.e. pie-chart, > line-chart, ......? > > A long time ago, I programmed a rmchart interface, however rmchart is > windows only, andwww.rmchart.comdisappeared now > > See you I'm about to announce WHIFF/amChart after some more testing. WHIFF/amCharts generates highly sophisticated interactive charts using Adobe/Flash plug-in applets. Documentation here: http://aaron.oirt.rutgers.edu/myapp/amcharts/doc You can get it from the WHIFF mercurial repository for now. http://aaron.oirt.rutgers.edu/cgi-bin/whiffRepo.cgi I will upload a tarball to http://whiff.sourceforge.net soonish. Thanks in advance for any comments. -- Aaron Watters === I want to achieve immortality by not dieing. -- Woody Allen From robert.kern at gmail.com Wed Jun 10 17:09:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 16:09:47 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <4a301d9a$0$90270$14726298@news.sunsite.dk> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> Message-ID: On 2009-06-10 15:54, Mark Dickinson wrote: > Robert Kern wrote: >> On 2009-06-10 14:46, Mark Dickinson wrote: >>> On Jun 10, 8:15 pm, Robert Kern wrote: >>>> On 2009-06-10 13:53, Terry Reedy wrote: >>>>> A full technical discussion does not below in the docs, in my opinion. A >>>>> wike article would be fine. >>>> True. However, a brief note that "Due to floating point arithmetic, for some >>>> values of a and b, b may or may not be one of the possible generated results." >>>> might be worthwhile. The actual details of *why* this is the case can be >>>> discussed elsewhere. >>> I find it difficult to see how such a disclaimer would have any >>> practical value >>> [lots more badly wrapped text snipped... ] >> That's a fair point. However, one issue that hasn't been brought up is that it >> might be confusing to a user why random.random() returns values in a half-open >> interval while random.uniform() claims a closed interval. Even for reasonably >> sophisticated floating point users, it's not necessarily obvious that that is >> the reasoning behind the different claims. > > True. I guess the original post in this thread is good evidence of > that. Though I'm not sure I'm capable of coming up with extra wording > for the docs that won't just cause more confusion, so I'll leave that > to someone else. I did make a concrete suggestion. > I seem to recall that when this originally came up in the tracker > (issue 4979) the fun part of the analysis was proving that > random.uniform(a, b) can never produce values *outside* the interval > [a, b]. :-) I was a bit worried about that part myself for a little bit. :-) -- 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 dfnsonfsduifb at gmx.de Wed Jun 10 17:33:18 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 23:33:18 +0200 Subject: Compiling Python3.1 In-Reply-To: <4a3010fb$0$22010$9b622d9e@news.freenet.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> Message-ID: <79an4pF1oqpbjU1@mid.dfncis.de> Martin v. L?wis schrieb: >> What can I do about that? > > Remove the non-ASCII characters from db.h. Ehh... $ find -type f | grep -i db.h ./Modules/unicodename_db.h ./Modules/unicodedata_db.h ./Objects/unicodetype_db.h There's no db.h file in the Python-3.1rc1 distribution. The ones above contain thousands of lines (~15k, 5k and 2k) all of which consist of endless arrays of unsigned characters - I really would not know what to remove from those. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From pavlovevidence at gmail.com Wed Jun 10 17:45:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Jun 2009 14:45:41 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 2:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. Well, I guess someone should actually describe a solution to this rather than debate the necessity, if only for academic interest. So, in order to do this for real: Generate a random integer the range [0,2**53+1), probably the easiest thing is to get a 64 bit integer and scale it using integer division (which will also help to minimize selection bias). random.randrange probably does something like this already. If the number is exactly 2**53, return 1.0. Else stuff the bits of the number into the mantissa of a double, along with -1 as the exponent, and return that. Implementation left as exercise, mostly because it really won't make a difference. Carl Banks From dickinsm at gmail.com Wed Jun 10 17:47:53 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 21:47:53 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> Message-ID: <4a302a09$0$90270$14726298@news.sunsite.dk> Robert Kern wrote: > On 2009-06-10 15:54, Mark Dickinson wrote: >> [...] I'm not sure I'm capable of coming up with extra wording >> for the docs that won't just cause more confusion, so I'll leave that >> to someone else. > > I did make a concrete suggestion. Yes, you did. Thank you. Submitted as http://bugs.python.org/issue6261 > >> I seem to recall that when this originally came up in the tracker >> (issue 4979) the fun part of the analysis was proving that >> random.uniform(a, b) can never produce values *outside* the interval >> [a, b]. :-) > > I was a bit worried about that part myself for a little bit. :-) > I think the key was to show that multiplication by (1-2**-53) (the largest possible output of random.random()) always makes any float smaller in magnitude[*], so assuming that a <= b the value of the Python expression random.random()*(b-a) can't be larger than the exact real value of (b-a), which in turn means that a + random.random()*(b-a) can't exceed b. [*] Well, almost. This isn't true for subnormals. But if the result of the subtraction b-a is subnormal then that subtraction was also necessarily exact, so everything works in this case, too. And of course I'm wrong. I shouldn't have said *never*, above: >>> from random import uniform >>> uniform(-1e308, 1e308) inf :-( Somehow this doesn't seem worth either fixing or documenting, though. -- Mark Dickinson From mwilson at the-wire.com Wed Jun 10 17:49:10 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 10 Jun 2009 17:49:10 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy wrote: > Str.join takes any iterable of strings and constructs a string. Only > str knows how to do that, though it could have a built-in that called a > hypothetical .__join__ method. However, Python started with just one > string type and there does not seem much use for joining an indefinite > number of tuples or lists. I can imagine numbers = [655, 583, 675, 456, 496, 239, 888] something = numbers.join (2) but I can't imagine what it could possibly be for. Something in the Goedelization line? Mel. From martin at v.loewis.de Wed Jun 10 18:19:08 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 11 Jun 2009 00:19:08 +0200 Subject: Compiling Python3.1 In-Reply-To: <79an4pF1oqpbjU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> <79an4pF1oqpbjU1@mid.dfncis.de> Message-ID: <4a30315c$0$20515$9b622d9e@news.freenet.de> Johannes Bauer wrote: > Martin v. L?wis schrieb: >>> What can I do about that? >> Remove the non-ASCII characters from db.h. > > Ehh... > > $ find -type f | grep -i db.h > ./Modules/unicodename_db.h > ./Modules/unicodedata_db.h > ./Objects/unicodetype_db.h > > There's no db.h file in the Python-3.1rc1 distribution. Correct. I was referring to the db.h from your operating system. See line 728 of setup.py. Regards, Martin From sjmachin at lexicon.net Wed Jun 10 18:23:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 10 Jun 2009 15:23:32 -0700 (PDT) Subject: cleaning up an ASCII file? References: Message-ID: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> On Jun 11, 6:09?am, Nick Matzke wrote: > Hi all, > > So I'm parsing an XML file returned from a database. ?However, the > database entries have occasional non-ASCII characters, and this is > crashing my parsers. So fix your parsers. google("unicode"). Deleting stuff that you don't understand is an "interesting" approach to academic research :-( Care to divulge what "crash" means? e.g. the full traceback and error message, plus what version of python on what platform, what version of ElementTree or other XML spftware you are using ... > Center for Theoretical Evolutionary Genomics If your .sig evolves much more, it will consume all available bandwidth in the known universe and then some ;-) From grahn+nntp at snipabacken.se Wed Jun 10 18:24:12 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 22:24:12 GMT Subject: Using logging module to log into flash drive References: Message-ID: On Tue, 9 Jun 2009 18:10:18 +0100, A. Cavallo wrote: [top-posting fixed] > On Tuesday 09 June 2009 16:57:00 kretel wrote: >> Hi All, >> >> I am trying to implement the following functionality: >> 1. log messages to the flash drive >> 2. if the flash drive is not available, switch handler to the >> BufferringHandler and log into buffer, >> 3. once the flash drive is plugged in and available store the logs >> from BufferHandler into that flash drive and switch the handler into >> RotateFileHandler. >> >> Which approach would you suggest to use while implementing this >> functionality? First, to ignore the words "flash drive" and think in terms of "can I open the file named so-and-so for writing?". Unless you absolutely must avoid storing your file on a file system based on some other storage technology. >> One that come into my mind is to have one process or >> thread to check periodically if the flashdrive is available, and have >> a flag that will indicate that we can store the logs into the flash >> drive. But I don't particularly like this approach. >> Would you do it different way? >> Any suggestions are appreciated. > Hi, > the problem screams for a separate thread. I don't hear any screaming. It seems simpler to just def log(something): if logging_to_memore() and seconds_since_i_last_checked() > N: try_to_switch_to_file() do_the_actual_logging(something) unless it's vital that as many of these logs as possible survive a crash (in which case I guess the program would also refuse to exit until the user finds the physical flash memory device somewhere and mounts it correctly -- flashback to ancient floppy-based Macs). Yes, I find the requirements quite odd. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From dw at botanicus.net Wed Jun 10 18:24:13 2009 From: dw at botanicus.net (David Wilson) Date: Wed, 10 Jun 2009 15:24:13 -0700 (PDT) Subject: itertools.intersect? Message-ID: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Hi, During a fun coding session yesterday, I came across a problem that I thought was already solved by itertools, but on investigation it seems it isn't. The problem is simple: given one or more ordered sequences, return only the objects that appear in each sequence, without reading the whole set into memory. This is basically an SQL many-many join. I thought it could be accomplished through recursively embedded generators, but that approach failed in the end. After posting the question to Stack Overflow[0], Martin Geisler proposed a wonderfully succinct and reusable solution (see below, or pretty printed at the Stack Overflow URL). It is my opinion that this particular implementation is a wonderful and incredibly valid use of iterators, and something that could be reused by others, certainly least not myself again in the future. With that in mind I thought it, or something very similar, would be a great addition to the itertools module. My question then is, are there better approaches to this? The heapq- based solution at the Stack Overflow page is potentially more useful still, for its ability to operate on orderless sequences, but in that case, it might be better to simply listify each sequence, and sort it before passing to the ordered-only functions. Thanks, David. Stack Overflow page here: http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-integer-yielding-python-iterators Sweet solution: import operator def intersect(sequences): """Compute intersection of sequences of increasing integers. >>> list(intersect([[1, 100, 142, 322, 12312], ... [2, 100, 101, 322, 1221], ... [100, 142, 322, 956, 1222]])) [100, 322] """ iterators = [iter(seq) for seq in sequences] last = [iterator.next() for iterator in iterators] indices = range(len(iterators)) while True: # The while loop stops when StopIteration is raised. The # exception will also stop the iteration by our caller. if reduce(operator.and_, [l == last[0] for l in last]): # All iterators contain last[0] yield last[0] last = [iterator.next() for iterator in iterators] # Now go over the iterators once and advance them as # necessary. To stop as soon as the smallest iterator we # advance each iterator only once per loop iteration. for i in indices[:-1]: if last[i] < last[i+1]: last[i] = iterators[i].next() if last[i] > last[i+1]: last[i+1] = iterators[i+1].next() From grahn+nntp at snipabacken.se Wed Jun 10 18:32:45 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 22:32:45 GMT Subject: python and getopt and spaces in option References: Message-ID: On Tue, 9 Jun 2009 12:22:20 -0400, David Shapiro wrote: > I have been trying to find an example of how to deal with options > that have spaces in them. I am using jython, which is the same I > think as python 2.2.3. I feebly tried to use optparse and argparse > with no success (got gettext, locale, and optparse). The code is as > follows: > > try: > (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > except getopt.GetoptError: > usage() > > for opt in opts: > (key, value) = opt ... > if (key in ("-q", "--testTableName")): ... > The one that gives me trouble is with the -q option, because it can > look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get > it to return the whole thing that is in double quotes? You are probably calling the program incorrectly. A non-broken getopt has no trouble with such things. When executing a program from a normal Unix shell, single or double quotes (like you do above) is enough. I'd expect other environments to behave in the same way. If -q only eats the string "SQL", where does "1 TABLE" go? It cannot just disappear; does it end up in 'args'? /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From cseberino at gmail.com Wed Jun 10 18:38:00 2009 From: cseberino at gmail.com (Chris Seberino) Date: Wed, 10 Jun 2009 15:38:00 -0700 (PDT) Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? Message-ID: How build new elements to replace existing ones using xml.dom.minidom? Specifically, I have an HTML table of numbers. I want to replace those numbers with hyperlinks to create a table of hyperlinks. So I need to build hyperlinks (a elements) with href attribute and replace the text elements (numbers) somehow. How do that? chris From clp2 at rebertia.com Wed Jun 10 19:43:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 16:43:38 -0700 Subject: Can not dump class object created on runtime In-Reply-To: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> References: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Message-ID: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> On Wed, Jun 10, 2009 at 7:25 AM, Metal Zong wrote: > Hello, > > Can not dump class object created on runtime. > > Is there anybody can help me? Thank. > > Following is testing code: > > import pickle > from new import classobj > > class A: > ??? def __str__(self): > ??????? return self.__class__.name > > if __name__ == "__main__": > ??? c = classobj('B', (A, ), {}) # create class obj on runtime > ??? print c > ??? print pickle.dumps(c) # get dump string > > Bellows are outputs: > > __main__.B > Traceback (most recent call last): > ? File "C:\USERS\train\_work\test\test.py", line 11, in > ??? print pickle.dumps(c) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps > ??? Pickler(file, protocol).dump(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump > ??? self.save(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save > ??? f(self, obj) # Call unbound method with explicit self > ? File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global > ??? (obj, module, name)) > pickle.PicklingError: Can't pickle : it's > not found as __main__.B pickle stores classes by storing their fully-qualified name (eg. "foo.bar.Baz") and NOT by storing the internal Python structures that represent the class (as there are apparently various problem associated with this). So when it unpickles, it just imports the fully-qualified name normally and returns the result of that. Since dynamically-created classes have no fully-qualified name, they can't be stored this way; hence, you get an exception when trying to pickle.dump() them. Also, you shouldn't use `classobj` as I believe that's only for old-style classes, which are being phased out. Its replacement is the built-in `type` metaclass, which creates new-style classes. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Jun 10 19:48:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 16:48:42 -0700 Subject: Restart the interactive python shell like in IDLE In-Reply-To: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> References: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> Message-ID: <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> On Wed, Jun 10, 2009 at 12:01 PM, Matt Burson wrote: > Is there a way to reproduce the behavior of IDLE's restart shell ability by > using a function? I thought there would be since you can exit python by > executing the simple quit() function I thought there would be an equally > simple function name something like restart(). I'd prefer something like > this as opposed to having to exit the shell and then start it up again to > refresh it. I believe IDLE itself implements the "restart" capability by killing and re-launching its Python interpreter subprocess, so it's not like it's using some hidden capability of Python to accomplish this. Is doing Ctrl+D, up-arrow, Enter really that hard? It's even fewer keystrokes than "restart()"... Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Wed Jun 10 19:54:18 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 18:54:18 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <4a302a09$0$90270$14726298@news.sunsite.dk> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> <4a302a09$0$90270$14726298@news.sunsite.dk> Message-ID: On 2009-06-10 16:47, Mark Dickinson wrote: > And of course I'm wrong. I shouldn't have said *never*, above: > >>>> from random import uniform >>>> uniform(-1e308, 1e308) > inf > > :-( > > Somehow this doesn't seem worth either fixing or documenting, though. Agreed. -- 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 dcest61 at hotmail.com Wed Jun 10 19:55:00 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Wed, 10 Jun 2009 23:55:00 GMT Subject: multi-core software In-Reply-To: <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon Harrop wrote: >>>>> No. Concurrent programming is about interleaving computations in order >>>>> to reduce latency. Nothing to do with parallelism. >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> >> I'm not being facetious. I write applications that run on application >> servers, and from time to time I have had to write various special >> purpose servers. This kind of programming is all about managing >> concurrent execution of computations. The overarching concern is >> reliability and correct function. For many corporate situations, even >> with hundreds of users, the actual load at any instant is low enough >> that the various servers involved are nowhere close to being stressed >> out - performance is a secondary issue. > > In other words, without concurrency the latency would be so high that you > would consider the program to be wrong. However you cut it, the real reason > is latency. For a certain group of applications and user loads I would concede that point, yes. For quite a few other situations, you could queue up user requests and execute them in order, finishing each before proceeding to the next, and users wouldn't even notice. I wrote a J2SE server a few months ago, to solve a very specific problem associated with an application running on a J2EE server, that could handle dozens of users per second using this strategy. It didn't write it that way because doing so is perverse, but I could have. AHS From jackdied at gmail.com Wed Jun 10 19:59:18 2009 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 10 Jun 2009 19:59:18 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Wed, Jun 10, 2009 at 6:24 PM, David Wilson wrote: > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. After posting the > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > succinct and reusable solution (see below, or pretty printed at the > Stack Overflow URL). > [snip] Here's my version; ?keep a list of (curr_val, iterator) tuples and operate on those. def intersect(seqs): ? ?iter_pairs = [(it.next(), it) for (it) in map(iter, seqs)] ? ?while True: ? ? ? ?min_val = min(iter_pairs)[0] ? ? ? ?max_val = max(iter_pairs)[0] ? ? ? ?if min_val == max_val: ? ? ? ? ? ?yield min_val ? ? ? ? ? ?max_val += 1 # everybody advances ? ? ? ?for i, (val, it) in enumerate(iter_pairs): ? ? ? ? ? ?if val < max_val: ? ? ? ? ? ? ? ?iter_pairs[i] = (it.next(), it) ? ?# end while True Interestingly you don't need to explicitly catch StopIteration and return because only the top level is a generator. ?So both lines where it.next() are called will potentially end the loop. I also tried using a defaultdict(list) as the main structure; it worked but was uglier by far { curr_val => [it1, it2, ..]} with dels and appends. -Jack ps, woops, I forgot to hit reply all the first time. From dcest61 at hotmail.com Wed Jun 10 20:06:08 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Thu, 11 Jun 2009 00:06:08 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. > > Programs that use more memory require more money for the hardware of > every user. Programs that run slower eat more time per day. If you > have 100,000 users, all doing an operation once per day that takes 20 > seconds, being able to shave 5 seconds off that saves 5.78 man-days of > work. Hell, for some applications, that 20 seconds is just startup > time spent at a splash screen. Just imagine if every Google search > took even 5 seconds to resolve, how much time would be wasted every > day around the world - ignoring the fact that Google wouldn't exist if > that were the case ;-). Obviously Google engineers work incredibly > hard every day to ensure correct results, but performance better be > right up there at the top of the list as well. > > Jeff M. Point taken, but I primarily work on internal government and corporate applications. Might be hundreds or thousands of users at any given time, but not typically tens or hundreds of thousands. Hundreds or thousands of users translates to at least an order of magnitude less "simultaneous" users. Ops people that I talk to who monitor apps I've worked on, or similar apps, rarely report any such where the application itself is presenting a sluggish aspect to users because it's stressing out processors, or consuming gargantuan memory. Typically when latency problems come up, it's because the app has to talk to other servers - databases, LDAP, print servers etc. In other words, the network is coming into play. In fact when we do work on performance, it's typically about minimizing calls to the database or other services. AHS From ken at seehart.com Wed Jun 10 20:09:46 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Jun 2009 17:09:46 -0700 Subject: xmlrpclib and generators In-Reply-To: <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> References: <4A2F9BB2.6010005@seehart.com> <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> Message-ID: <4A304B4A.6050802@seehart.com> Hendrik van Rooyen wrote: > Ken Seehart wrote: > > 8< ------------ implementation -------------- > > >> The practical constraints of my specific application are: >> 1. The rpc server is a highly specialized slave system that does heavy duty >> work. >> >> 2. The rpc client is itself a web server that dispatches work requests to the >> rpc server(s) and displays the >current status of work done so far. >> >> 3. The generators will typically run for a long time (hours) and yield data >> periodically (perhaps once a minute). >> > > > If this "yield" can be made to be, or if it is, supply side driven, instead of > yielding on demand like a > generator, then I would set up a simple TCP/IP peer to peer socket link and just > send the result > back when it is ready. If you have to "serve" more than one such link, it is a > simple matter > to keep a list of queues linking the different socket sets to the "generator", > and to iterate over > the list, putting a copy of the thing that was just produced into each queue. > > Of course, the thing you want to pass back must be serializable. > It is supply side driven, and the content would be serializable. The only reason I want something high level like xmlrpc or Pyro instead of rolling my own stuff with TCP/IP is that I want the client and server to be easily customizable. > Have you looked at Pyro? > Not yet. Looking at it now. Thanks, it looks like Pyro may be very relevant. Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From matzke at berkeley.edu Wed Jun 10 20:52:09 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 17:52:09 -0700 Subject: cleaning up an ASCII file? In-Reply-To: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> Message-ID: <4A305539.1050108@berkeley.edu> Apologies, I figured there was some easy, obvious solution, since there is in BBedit. I will explain further... John Machin wrote: > On Jun 11, 6:09 am, Nick Matzke wrote: >> Hi all, >> >> So I'm parsing an XML file returned from a database. However, the >> database entries have occasional non-ASCII characters, and this is >> crashing my parsers. > > So fix your parsers. google("unicode"). Deleting stuff that you don't > understand is an "interesting" approach to academic research :-( Not if it's just weird versions of dash characters and umlauted characters the like, which is what I bet it is. Those sorts of things and the apparent inability of lots of email readers and websites to deal with them have been annoying me for years, so I tend to move straight towards genocidal tactics when I detect their presence. (My database source is GBIF, they get museum specimen submissions from around the planet, there are zillions of records, I am just a user, so fixing it on their end is not a realistic option.) > Care to divulge what "crash" means? e.g. the full traceback and error > message, plus what version of python on what platform, what version of > ElementTree or other XML spftware you are using ... All that is fine, the problem is actually when I try to print to screen in IPython: ============ UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 293: ordinal not in range(128) ============ Probably this is the line in the file which is causing problems (as displayed in BBedit): ====================== - This document contains data shared through the GBIF Network - see http://data.gbif.org/ for more information. All usage of these data must be in accordance with the GBIF Data Use Agreement - see http://www.gbif.org/DataProviders/Agreements/DUA Please cite these data as follows: Jyväskylä University Museum - The Section of Natural Sciences, Vascular plant collection of Jyvaskyla University Museum (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/462, 2009-06-11) Missouri Botanical Garden, Missouri Botanical Garden (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/621, 2009-06-11) Museo Nacional de Costa Rica, herbario (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/566, 2009-06-11) National Science Museum, Japan, Kurashiki Museum of Natural History (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/599, 2009-06-11) The Swedish Museum of Natural History (NRM), Herbarium of Oskarshamn (OHN) (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/1024, 2009-06-11) Tiroler Landesmuseum Ferdinandeum, Tiroler Landesmuseum Ferdinandeum (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/1509, 2009-06-11) UCD, Database Schema for UC Davis [Herbarium Labels] (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/734, 2009-06-11) - ====================== Presumably "Jyväskylä University Museum" is the problem since there are umlauted a's in there. (Note, though, that I have thousands of records to parse, so there is going to be all kinds of other umlauted & accented stuff in these sorts of search results. So the goal is to replace the characters with un-umlauted versions or some such. Cheers! Nick PS: versions I am using: ======== nick$ python -V Python 2.5.2 |EPD Py25 4.1.30101| ======== >> Center for Theoretical Evolutionary Genomics > > If your .sig evolves much more, it will consume all available > bandwidth in the known universe and then some ;-) ...its easier to have a big sig than to try and remember all that stuff ;-)... -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From mensanator at aol.com Wed Jun 10 20:53:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 17:53:59 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 5:24?pm, David Wilson wrote: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > Why not use SQL? import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.executescript(""" create table test1(p INTEGER); """) cur.executescript(""" create table test2(q INTEGER); """) cur.executescript(""" create table test3(r INTEGER); """) for t in ((1,),(100,),(142,),(322,),(12312,)): cur.execute('insert into test1 values (?)', t) for t in ((2,),(100,),(101,),(322,),(1221,)): cur.execute('insert into test2 values (?)', t) for t in ((100,),(142,),(322,),(956,),(1222,)): cur.execute('insert into test3 values (?)', t) cur.execute(""" SELECT p FROM (test1 INNER JOIN test2 ON p = q) INNER JOIN test3 ON p = r; """) sqlintersect = cur.fetchall() for i in sqlintersect: print i[0], print ## ## 100 322 ## From myopc at aaa.com Wed Jun 10 21:40:11 2009 From: myopc at aaa.com (myopc) Date: Thu, 11 Jun 2009 09:40:11 +0800 Subject: multi-thread python interpreaters and c++ program References: <6deac4c8-b208-4fbf-8098-8dc7af7f881b@r34g2000vba.googlegroups.com> Message-ID: thanks, I use gdb to debug, and cant find any symbol in the stack. I wanna to exit from outside python, without tell anything to the interpreator, but it seems impossible "Floris Bruynooghe" :6deac4c8-b208-4fbf-8098-8dc7af7f881b at r34g2000vba.googlegroups.com... On Jun 9, 6:50 am, "myopc" wrote: > I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python interpreaters, > but it crashed. Your threads are daemonic, you could be seeing http://bugs.python.org/issue1856 You'll have to check your stack in a debugger to know. But as said this can be avoided by making the threads finish themself and joining them. Regards Floris From metalzong at 163.com Wed Jun 10 21:55:02 2009 From: metalzong at 163.com (metalzong) Date: Thu, 11 Jun 2009 09:55:02 +0800 (CST) Subject: Can not dump class object created on runtime In-Reply-To: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> References: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Message-ID: <8386134.93891244685302147.JavaMail.coremail@bj163app54.163.com> Thanks a lot. ?2009-06-11?"Chris Rebert" ??? On Wed, Jun 10, 2009 at 7:25 AM, Metal Zong wrote: > Hello, > > Can not dump class object created on runtime. > > Is there anybody can help me? Thank. > > Following is testing code: > > import pickle > from new import classobj > > class A: > ??? def __str__(self): > ??????? return self.__class__.name > > if __name__ == "__main__": > ??? c = classobj('B', (A, ), {}) # create class obj on runtime > ??? print c > ??? print pickle.dumps(c) # get dump string > > Bellows are outputs: > > __main__.B > Traceback (most recent call last): > ? File "C:\USERS\train\_work\test\test.py", line 11, in > ??? print pickle.dumps(c) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps > ??? Pickler(file, protocol).dump(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump > ??? self.save(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save > ??? f(self, obj) # Call unbound method with explicit self > ? File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global > ??? (obj, module, name)) > pickle.PicklingError: Can't pickle : it's > not found as __main__.B pickle stores classes by storing their fully-qualified name (eg. "foo.bar.Baz") and NOT by storing the internal Python structures that represent the class (as there are apparently various problem associated with this). So when it unpickles, it just imports the fully-qualified name normally and returns the result of that. Since dynamically-created classes have no fully-qualified name, they can't be stored this way; hence, you get an exception when trying to pickle.dump() them. Also, you shouldn't use `classobj` as I believe that's only for old-style classes, which are being phased out. Its replacement is the built-in `type` metaclass, which creates new-style classes. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Jun 10 22:05:06 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 19:05:06 -0700 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <50697b2c0906101905w4596ebd5s1e11314f4a052c8a@mail.gmail.com> On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > On Jun 10, 5:24?pm, David Wilson wrote: >> Hi, >> >> During a fun coding session yesterday, I came across a problem that I >> thought was already solved by itertools, but on investigation it seems >> it isn't. >> >> The problem is simple: given one or more ordered sequences, return >> only the objects that appear in each sequence, without reading the >> whole set into memory. This is basically an SQL many-many join. >> > > Why not use SQL? Agreed. I seem to recall the last person asking for such a function wanted to use it to combine SQL results. Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 22:06:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Jun 2009 02:06:16 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On Wed, 10 Jun 2009 15:32:05 -0500, Robert Kern wrote: > That's a fair point. However, one issue that hasn't been brought up is > that it might be confusing to a user why random.random() returns values > in a half-open interval while random.uniform() claims a closed interval. > Even for reasonably sophisticated floating point users, it's not > necessarily obvious that that is the reasoning behind the different > claims. Agreed -- the reasoning that a half-open interval [0, 1) for z (random()) leads to a closed interval [a, b] for a+(b-a)*z (uniform()) is *not* obvious even for people who are aware that floats do funny things. I know I got caught out by it. However, rather than a documentation patch, I'd prefer to see uniform() fixed to return a value in the half-open interval. Something like: def uniform(self, a, b): """Get a random number in the range [a, b).""" r = a + (b-a) * self.random() while r == b: # Guard against (rare) rounding to b. r = a + (b-a) * self.random() return r should do the trick. I think. Earlier, Mark Dickinson wrote: "Can you think of a single practical situation where it would matter that, for some values of a and b, uniform(a, b) can never produce the value b?" I would argue that it is a good thing if uniform never returns b. alist[ int(uniform(0, len(alist))) ] can apparently fail for some lists, but not others. Admittedly, I don't have a good reason for using the above rather than sample(), or for truncating the result of uniform() rather than using randrange(). Hopefully if I don't mention it, nobody will notice it... *wink* -- Steven From matzke at berkeley.edu Wed Jun 10 22:22:27 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 19:22:27 -0700 Subject: cleaning up an ASCII file? In-Reply-To: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> Message-ID: <4A306A63.8050202@berkeley.edu> Looks like this was a solution: 1. Use this guy's unescape function to convert from HTML/XML Entities to unicode http://effbot.org/zone/re-sub.htm#unescape-html 2. Take the unicode and convert to approximate plain ASCII matches with unicodedata (after import unicodedata) ascii_content2 = unescape(line) ascii_content = unicodedata.normalize('NFKD', unicode(ascii_content2)).encode('ascii','ignore') The string "line" would give the error, but ascii_content does not. Cheers! Nick PS: "asciiDammit" is also fun to look at John Machin wrote: > On Jun 11, 6:09 am, Nick Matzke wrote: >> Hi all, >> >> So I'm parsing an XML file returned from a database. However, the >> database entries have occasional non-ASCII characters, and this is >> crashing my parsers. > > So fix your parsers. google("unicode"). Deleting stuff that you don't > understand is an "interesting" approach to academic research :-( > > Care to divulge what "crash" means? e.g. the full traceback and error > message, plus what version of python on what platform, what version of > ElementTree or other XML spftware you are using ... > >> Center for Theoretical Evolutionary Genomics > > If your .sig evolves much more, it will consume all available > bandwidth in the known universe and then some ;-) -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From janssonks at gmail.com Wed Jun 10 22:38:14 2009 From: janssonks at gmail.com (Karl Jansson) Date: Wed, 10 Jun 2009 21:38:14 -0500 Subject: installation in mac os x Message-ID: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> Hi, I was doing the tutorial at http://www.python.org/doc/current/ tutorial/, and I came across some code that did not work, and I got the following error: AttributeError: 'str' object has no attribute 'format'. So I downloaded a .dmg of python 2.6.2 and then I installed it. But it's not working. Running the Python launcher, the "new" command in the file menu is grey, and won't work, so I can't make any scripts. Does anyone know how to make python 2.6.2 work in mac os x? Thanks, Stefan From dw at botanicus.net Wed Jun 10 22:43:51 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 19:43:51 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <082b59d6-8841-40f4-bddd-ea9a243287b4@c36g2000yqn.googlegroups.com> On Jun 11, 3:05?am, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > > On Jun 10, 5:24?pm, David Wilson wrote: > >> Hi, > > >> During a fun coding session yesterday, I came across a problem that I > >> thought was already solved by itertools, but on investigation it seems > >> it isn't. > > >> The problem is simple: given one or more ordered sequences, return > >> only the objects that appear in each sequence, without reading the > >> whole set into memory. This is basically an SQL many-many join. > > > Why not use SQL? > > Agreed. I seem to recall the last person asking for such a function > wanted to use it to combine SQL results. > My original use case was a full text indexer. Here's the code: http://code.google.com/p/ghetto-fts/ Let me invert the question and ask: why would I want to use SQL for this? Or in my own words: what kind of girly-code requires an RDBMS just to join some sequences? =) Given that Google reports 14.132 billion occurrences of "the" on the English web, which is about right, given that some estimate the English web at ~15 billion documents, or about 33.8 bits to uniquely identify each document, let's assume we use a 64bit integer, that's theoretically 111.7GiB of data loaded into SQL just for a single word. Introducing SQL quickly results in artificially requiring a database system, when a 15 line function would have sufficed. It also restricts how I store my data, and prevents, say, using a columnar, variable length, or delta encoding on my sequence of document IDs, which would massively improve the storage footprint (say, saving 48-56 bits per element). I'll avoid mention of the performance aspects altogether. "What the hell are you thinking", David > Cheers, > Chris > --http://blog.rebertia.com From higerinbeijing at gmail.com Wed Jun 10 23:11:50 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 10 Jun 2009 20:11:50 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix Message-ID: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> I just want to compare two files,one from windows and the other from unix. But I do not want to compare them through reading them line by line. Then I found there is a filecmp module which is used as file and directory comparisons. However,when I use two same files (one from unix,one from windows,the content of them is the same) to test its cmp function, filecmp.cmp told me false. Later, I found that windows use '\n\r' as new line flag but unix use '\n', so filecmp.cmp think that they are different,then return false. So, can anyone tell me that is there any method like IgnoreNewline which can ignore the difference of new line flag in diffrent platforms? If not,I think filecmp may be not a good file comparison module. Thanks, higer From clp2 at rebertia.com Wed Jun 10 23:44:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 20:44:21 -0700 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix In-Reply-To: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> Message-ID: <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: > I just want to compare two files,one from windows and the other from > unix. But I do not want to compare them through reading them line by > line. Then I found there is a filecmp module which is used as file and > directory comparisons. However,when I use two same files (one from > unix,one from windows,the content of them is the same) to test its cmp > function, filecmp.cmp told me false. > > Later, I found that windows use '\n\r' as new line flag but unix use > '\n', so filecmp.cmp think that they are different,then return false. > So, can anyone tell me that is there any method like IgnoreNewline > which can ignore the difference of new line flag in diffrent > platforms? If not,I think filecmp may be not a good file comparison Nope, there's no such flag. You could run the files through either `dos2unix` or `unix2dos` beforehand though, which would solve the problem. Or you could write the trivial line comparison code yourself and just make sure to open the files in Universal Newline mode (add 'U' to the `mode` argument to `open()`). You could also file a bug (a patch to add newline insensitivity would probably be welcome). Cheers, Chris -- http://blog.rebertia.com From dw at botanicus.net Wed Jun 10 23:56:55 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 20:56:55 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <9baec91e-a371-4949-b7f7-b134daccaeff@y7g2000yqa.googlegroups.com> On Jun 11, 12:59?am, Jack Diederich wrote: > On Wed, Jun 10, 2009 at 6:24 PM, David Wilson wrote: > > During a fun coding session yesterday, I came across a problem that I > > thought was already solved by itertools, but on investigation it seems > > it isn't. > > > The problem is simple: given one or more ordered sequences, return > > only the objects that appear in each sequence, without reading the > > whole set into memory. This is basically an SQL many-many join. > > > I thought it could be accomplished through recursively embedded > > generators, but that approach failed in the end. After posting the > > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > > succinct and reusable solution (see below, or pretty printed at the > > Stack Overflow URL). > > [snip] > > Here's my version; ?keep a list of (curr_val, iterator) tuples and > operate on those. > > def intersect(seqs): > ? ?iter_pairs = [(it.next(), it) for (it) in map(iter, seqs)] > ? ?while True: > ? ? ? ?min_val = min(iter_pairs)[0] > ? ? ? ?max_val = max(iter_pairs)[0] > ? ? ? ?if min_val == max_val: > ? ? ? ? ? ?yield min_val > ? ? ? ? ? ?max_val += 1 # everybody advances > ? ? ? ?for i, (val, it) in enumerate(iter_pairs): > ? ? ? ? ? ?if val < max_val: > ? ? ? ? ? ? ? ?iter_pairs[i] = (it.next(), it) > ? ?# end while True This version is a lot easier to understand. The implicit StopIteration is a double-edged sword for readability, but I like it. :) David > > Interestingly you don't need to explicitly catch StopIteration and > return because only the top level is a generator. ?So both lines where > it.next() are called will potentially end the loop. > I also tried using a defaultdict(list) as the main structure; it > worked but was uglier by far { curr_val => [it1, it2, ..]} with dels > and appends. > > -Jack > > ps, woops, I forgot to hit reply all the first time. From dw at botanicus.net Thu Jun 11 00:03:10 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 21:03:10 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 11:24?pm, David Wilson wrote: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. After posting the > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > succinct and reusable solution (see below, or pretty printed at the > Stack Overflow URL). > > It is my opinion that this particular implementation is a wonderful > and incredibly valid use of iterators, and something that could be > reused by others, certainly least not myself again in the future. With > that in mind I thought it, or something very similar, would be a great > addition to the itertools module. > > My question then is, are there better approaches to this? The heapq- > based solution at the Stack Overflow page is potentially more useful > still, for its ability to operate on orderless sequences, but in that > case, it might be better to simply listify each sequence, and sort it > before passing to the ordered-only functions. > > Thanks, > > David. > > Stack Overflow page here: > > http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-in... > > Sweet solution: > > ? ? import operator > > ? ? def intersect(sequences): > ? ? ? ? """Compute intersection of sequences of increasing integers. > > ? ? ? ? >>> list(intersect([[1, ? 100, 142, 322, 12312], > ? ? ? ? ... ? ? ? ? ? ? ? ? [2, ? 100, 101, 322, 1221], > ? ? ? ? ... ? ? ? ? ? ? ? ? [100, 142, 322, 956, 1222]])) > ? ? ? ? [100, 322] > > ? ? ? ? """ > ? ? ? ? iterators = [iter(seq) for seq in sequences] > ? ? ? ? last = [iterator.next() for iterator in iterators] > ? ? ? ? indices = range(len(iterators)) > ? ? ? ? while True: > ? ? ? ? ? ? # The while loop stops when StopIteration is raised. The > ? ? ? ? ? ? # exception will also stop the iteration by our caller. > ? ? ? ? ? ? if reduce(operator.and_, [l == last[0] for l in last]): > ? ? ? ? ? ? ? ? # All iterators contain last[0] > ? ? ? ? ? ? ? ? yield last[0] > ? ? ? ? ? ? ? ? last = [iterator.next() for iterator in iterators] > > ? ? ? ? ? ? # Now go over the iterators once and advance them as > ? ? ? ? ? ? # necessary. To stop as soon as the smallest iterator we > ? ? ? ? ? ? # advance each iterator only once per loop iteration. > ? ? ? ? ? ? for i in indices[:-1]: > ? ? ? ? ? ? ? ? if last[i] < last[i+1]: > ? ? ? ? ? ? ? ? ? ? last[i] = iterators[i].next() > ? ? ? ? ? ? ? ? if last[i] > last[i+1]: > ? ? ? ? ? ? ? ? ? ? last[i+1] = iterators[i+1].next() I found my answer: Python 2.6 introduces heap.merge(), which is designed exactly for this. Thanks all, David. From pavlovevidence at gmail.com Thu Jun 11 00:06:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Jun 2009 21:06:50 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 7:05?pm, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > > On Jun 10, 5:24?pm, David Wilson wrote: > >> Hi, > > >> During a fun coding session yesterday, I came across a problem that I > >> thought was already solved by itertools, but on investigation it seems > >> it isn't. > > >> The problem is simple: given one or more ordered sequences, return > >> only the objects that appear in each sequence, without reading the > >> whole set into memory. This is basically an SQL many-many join. > > > Why not use SQL? > > Agreed. I seem to recall the last person asking for such a function > wanted to use it to combine SQL results. Well if the source data is already in a sql database that would make most sense, but if it isn't and since the iterator is pretty simple I'd say just go with that. Unless you have some other things happening downstream that would also benefit from the source data being in a database, or something. Carl Banks From boris.arloff at yahoo.com Thu Jun 11 00:25:25 2009 From: boris.arloff at yahoo.com (Boris Arloff) Date: Wed, 10 Jun 2009 21:25:25 -0700 (PDT) Subject: Metaclasses Demystified Message-ID: <495278.37325.qm@web65315.mail.ac2.yahoo.com> Hi, I have been studying python metaclasses for a few days now and I believe that slowly but surely I am grasping the subject.? The best article I have found on this is "Metaclass Demystified", by J. LaCour, Python Magazine, July 2008 (http://cleverdevil.org/computing/78/). I replicated the article's Enforcer example in python 3.0 and while I understand its functionality I have trouble understanding the behind the scene behavior.? I created a file containing classes Field, EnforcerMeta, Enforcer and Person, in this order.? The file is then imported with the python ide.? To save space I do not replicate the code here since it is available at the above link.? The following describes events when the file is imported and I hope that someone may offer clarifications on my comments/questions: 1.? First, the EnforcerMeta's __init__ method executes at import and its namespace (ns) shows to contain '__module__' and '__setattr__' attributes.? I did not expect __init__ to execute at this point since there has not been an instantiation yet.? Does this happens because we inherit from type and the python engine instantiates metaclasses? 2. Second, the for loop of EnforcerMeta checks the two attributes to be instances of class Field to add them in the _fields dict.? Since Field has not been instantiated with these attributes, they are not added to the dict.? No problem here, this is expected. 3.? Then,? class Person declaration is encountered with two class variables 'name' and 'age' which are defined as Field(str) and Field(int), respectively.? Hence, we have two instances of class Field each with a corresponding instance ftype attribute.? No problem with this either, as expected. 4.? The next events are somewhat puzzling however.? Class EnforcerMeta's __init__ executes again with a ns containing attributes 'age', 'name', and '__module__' .? The for loop executes and this time 'age' and 'name' are added to the _fields dict, while '__module__' understandably is not added.? However, 4.a.? What happened to attribute '__setattr__'?? Why is it not present anymore in the ns? 4.b.? What kind of magic makes EnforcerMeta to instantiate this second time?? I did not expect this to happen at all.? I can try to rationalize its instance in step 1 above, but I cannot come up with any such explanation for this second instantiation.? Is it because Enforcer doing this by inheriting the metaclass, which in turn is inherited by class Person? I tested the code by creating an instance of class Person and then assigning values to its attributes name and age.? The code works correctly as per the article's example. Any clarifications to the above questions will be greatly appreciated.? I am trying to get versed with the black magic of metaclasses and hope to use them in a personal academic research whereby I will try to create class objects on the fly at runtime out of nothing; or almost nothing. I can attach my code if necessary, but as indicated it is identical to LaCour's in the article with the necessary syntax changes for python 3.0. Thanks Boris -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Thu Jun 11 00:32:47 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Jun 2009 00:32:47 -0400 Subject: installation in mac os x In-Reply-To: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> References: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> Message-ID: On Jun 10, 2009, at 10:38 PM, Karl Jansson wrote: > Hi, > > I was doing the tutorial at http://www.python.org/doc/current/tutorial/ > , and I came across some code that did not work, and I got the > following error: AttributeError: 'str' object has no attribute > 'format'. > > So I downloaded a .dmg of python 2.6.2 and then I installed it. But > it's not working. Running the Python launcher, the "new" command in > the file menu is grey, and won't work, so I can't make any scripts. > > Does anyone know how to make python 2.6.2 work in mac os x? Hi Stefan, What's "the Python launcher"? What happens if you instead open a Terminal window (/Applications/Utilities/Terminal) and type "python"? bye P From jackdied at gmail.com Thu Jun 11 00:37:32 2009 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 11 Jun 2009 00:37:32 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: [snip] > I found my answer: Python 2.6 introduces heap.merge(), which is > designed exactly for this. Thanks, I knew Raymond added something like that but I couldn't find it in itertools. That said .. it doesn't help. Aside, heapq.merge fits better in itertools (it uses heaps internally but doesn't require them to be passed in). The other function that almost helps is itertools.groupby() and it doesn't return an iterator so is an odd fit for itertools. More specifically (and less curmudgeonly) heap.merge doesn't help for this particular case because you can't tell where the merged values came from. You want all the iterators to yield the same thing at once but heapq.merge muddles them all together (but in an orderly way!). Unless I'm reading your tokenizer func wrong it can yield the same value many times in a row. If that happens you don't know if four "The"s are once each from four iterators or four times from one. All that said your problem is an edge case so I'm happy to say the ten line composite functions that we've been trading can do what you want to do and in clear prose. The stdlib isn't meant to have a one liner for everything. -Jack From sjmachin at lexicon.net Thu Jun 11 00:58:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Jun 2009 04:58:28 +0000 (UTC) Subject: cleaning up an ASCII file? References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> <4A306A63.8050202@berkeley.edu> Message-ID: Nick Matzke berkeley.edu> writes: > > > Looks like this was a solution: > > 1. Use this guy's unescape function to convert from HTML/XML Entities to > unicode > http://effbot.org/zone/re-sub.htm#unescape-html Looks like you didn't notice "this guy"'s unaccent.py :-) http://effbot.org/zone/unicode-convert.htm [Aside: Has anyone sighted the effbot recently? He's been very quiet.] > 2. Take the unicode and convert to approximate plain ASCII matches with > unicodedata (after import unicodedata) > > ascii_content2 = unescape(line) > > ascii_content = unicodedata.normalize('NFKD', > unicode(ascii_content2)).encode('ascii','ignore') The normalize hack gets you only so far. Many Latin-based characters are not decomposable. Look for the thread in this newsgroup with subject "convert unicode characters to visibly similar ascii characters" around 2008-07-01 or google("hefferon unicode2ascii") Alternative: If you told us which platform you are running on, people familiar with that platform could help you set up your terminal to display non-ASCII characters correctly. HTH, John From sjmachin at lexicon.net Thu Jun 11 01:08:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Jun 2009 05:08:41 +0000 (UTC) Subject: How should I compare two txt files separately coming from =?utf-8?b?CXdpbmRvd3MvZG9z?= and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: Chris Rebert rebertia.com> writes: > > On Wed, Jun 10, 2009 at 8:11 PM, higer gmail.com> wrote: > > I just want to compare two files,one from windows and the other from > > unix. But I do not want to compare them through reading them line by > > line. Then I found there is a filecmp module which is used as file and > > directory comparisons. However,when I use two same files (one from > > unix,one from windows,the content of them is the same) to test its cmp > > function, filecmp.cmp told me false. > > > > Later, I found that windows use '\n\r' as new line flag but unix use > > '\n', so filecmp.cmp think that they are different,then return false. > > So, can anyone tell me that is there any method like IgnoreNewline > > which can ignore the difference of new line flag in diffrent > > platforms? If not,I think filecmp may be not a good file comparison > > Nope, there's no such flag. You could run the files through either > `dos2unix` or `unix2dos` beforehand though, which would solve the > problem. > Or you could write the trivial line comparison code yourself and just > make sure to open the files in Universal Newline mode (add 'U' to the > `mode` argument to `open()`). > You could also file a bug (a patch to add newline insensitivity would > probably be welcome). Or popen diff ... A /very/ /small/ part of the diff --help output: -E --ignore-tab-expansion Ignore changes due to tab expansion. -b --ignore-space-change Ignore changes in the amount of white space. -w --ignore-all-space Ignore all white space. -B --ignore-blank-lines Ignore changes whose lines are all blank. -I RE --ignore-matching-lines=RE Ignore changes whose lines all match RE. --strip-trailing-cr Strip trailing carriage return on input. Cheers, John From stefan_ml at behnel.de Thu Jun 11 02:22:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 08:22:14 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: References: Message-ID: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> Chris Seberino wrote: > How build new elements to replace existing ones using xml.dom.minidom? > > Specifically, I have an HTML table of numbers. I want to replace > those numbers with hyperlinks to create a table of hyperlinks. > > So I need to build hyperlinks (a elements) with href attribute and > replace the text elements (numbers) somehow. Try lxml.html instead. It makes it really easy to do these things. For example, you can use XPath to find all table cells that contain numbers: td_list = doc.xpath("//td[number() >= 0]") or maybe using regular expressions to make sure it's an int: td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", namespaces={'re':'http://exslt.org/regular-expressions'}) and then replace them by a hyperlink: # assuming links = ['http://...', ...] from lxml.html.builder import A for td in td_list: index = int(td.text) a = A("some text", href=links[index]) td.getparent().replace(td, a) Stefan From stefan_ml at behnel.de Thu Jun 11 02:23:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 08:23:23 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79a0njF1pd0bqU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> Message-ID: <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > when I read in a XML document with the xml.dom.minidom parser and write > it out again, an attribute is lost: > > Input: > > > [...] > > Output: > > > How can I fix this? You don't have to. UTF-8 is the default encoding, so the two lines above are equivalent. Stefan From lie.1296 at gmail.com Thu Jun 11 03:01:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 11 Jun 2009 07:01:04 GMT Subject: How to escape # hash character in regex match strings In-Reply-To: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 > > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? As you're not being clear on what you wanted, I'm just guessing this is what you wanted: >>> s = '123#abc456' >>> re.match('\d+', re.sub('#\D+', '', s)).group() '123456' >>> s = '123#this is a comment and is ignored456' >>> re.match('\d+', re.sub('#\D+', '', s)).group() '123456' From higerinbeijing at gmail.com Thu Jun 11 03:09:33 2009 From: higerinbeijing at gmail.com (higer) Date: Thu, 11 Jun 2009 00:09:33 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: On Jun 11, 1:08?pm, John Machin wrote: > Chris Rebert rebertia.com> writes: > > > > > > > On Wed, Jun 10, 2009 at 8:11 PM, higer gmail.com> wrote: > > > I just want to compare two files,one from windows and the other from > > > unix. But I do not want to compare them through reading them line by > > > line. Then I found there is a filecmp module which is used as file and > > > directory comparisons. However,when I use two same files (one from > > > unix,one from windows,the content of them is the same) to test its cmp > > > function, filecmp.cmp told me false. > > > > Later, I found that windows use '\n\r' as new line flag but unix use > > > '\n', so filecmp.cmp think that they are different,then return false. > > > So, can anyone tell me that is there any method like IgnoreNewline > > > which can ignore the difference of new line flag in diffrent > > > platforms? If not,I think filecmp may be not a good file comparison > > > Nope, there's no such flag. You could run the files through either > > `dos2unix` or `unix2dos` beforehand though, which would solve the > > problem. > > Or you could write the trivial line comparison code yourself and just > > make sure to open the files in Universal Newline mode (add 'U' to the > > `mode` argument to `open()`). > > You could also file a bug (a patch to add newline insensitivity would > > probably be welcome). > > Or popen diff ... > > A /very/ /small/ part of the diff --help output: > > ? -E ?--ignore-tab-expansion ?Ignore changes due to tab expansion. > ? -b ?--ignore-space-change ?Ignore changes in the amount of white space. > ? -w ?--ignore-all-space ?Ignore all white space. > ? -B ?--ignore-blank-lines ?Ignore changes whose lines are all blank. > ? -I RE ?--ignore-matching-lines=RE ?Ignore changes whose lines all match RE. > ? --strip-trailing-cr ?Strip trailing carriage return on input. > > Cheers, > John Tool can certainly be used to compare two files,but I just want to compare them using Python code. From higerinbeijing at gmail.com Thu Jun 11 03:12:24 2009 From: higerinbeijing at gmail.com (higer) Date: Thu, 11 Jun 2009 00:12:24 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> Message-ID: <39379946-16f0-448c-a230-3da19449d40e@k19g2000prh.googlegroups.com> On Jun 11, 11:44?am, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: > > I just want to compare two files,one from windows and the other from > > unix. But I do not want to compare them through reading them line by > > line. Then I found there is a filecmp module which is used as file and > > directory comparisons. However,when I use two same files (one from > > unix,one from windows,the content of them is the same) to test its cmp > > function, filecmp.cmp told me false. > > > Later, I found that windows use '\n\r' as new line flag but unix use > > '\n', so filecmp.cmp think that they are different,then return false. > > So, can anyone tell me that is there any method like IgnoreNewline > > which can ignore the difference of new line flag in diffrent > > platforms? If not,I think filecmp may be not a good file comparison > > Nope, there's no such flag. You could run the files through either > `dos2unix` or `unix2dos` beforehand though, which would solve the > problem. > Or you could write the trivial line comparison code yourself and just > make sure to open the files in Universal Newline mode (add 'U' to the > `mode` argument to `open()`). > You could also file a bug (a patch to add newline insensitivity would > probably be welcome). > > Cheers, > Chris > --http://blog.rebertia.com Thank you very much. Adding 'U' argument can perfectly work, and I think it is definitely to report this as a bug to Python.org as you say. Cheers, higer From wuwei23 at gmail.com Thu Jun 11 03:20:57 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Jun 2009 00:20:57 -0700 (PDT) Subject: object reincarnation References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: On Jun 11, 5:34?am, Manavan wrote: > Since the real world objects often needs to be deleted even if they > have some reference from some other object [...] >From this it sounds like you're trying to implement some form of weak referencing. Are you familiar with weakref? "A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. A primary use for weak references is to implement caches or mappings holding large objects, where it?s desired that a large object not be kept alive solely because it appears in a cache or mapping." http://docs.python.org/library/weakref.html From carlos at pepelabs.net Thu Jun 11 04:34:08 2009 From: carlos at pepelabs.net (Carlos Valiente) Date: Thu, 11 Jun 2009 08:34:08 +0000 (UTC) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > url = url.rstrip('/') + '/' That's what I use: It has the (nice) side effect of ending the URL with a *single* slash. C From clp2 at rebertia.com Thu Jun 11 04:44:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 01:44:28 -0700 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: <4A2EDD10.6090608@gmail.com> References: <4A2EDD10.6090608@gmail.com> Message-ID: <50697b2c0906110144g6cfeb6aeq9a6fc91fca14fb3a@mail.gmail.com> On Tue, Jun 9, 2009 at 3:07 PM, Stef Mientki wrote: > hello, > > I want to make a distro for Ubuntu, > and run under Windows. > > I packed all sources with zipfile, > but the compression doesn't seem to be very good. > > If run the created file through 7zip, it becomes anout half the size. Are you sure it's compressing it as a .zip? I know it has its own incompatible .7z format which tends compress things a bit better. > Is there a way to accomplish the same task with zipfile ( the documentation > isn't overwhelming). You can use the `tarfile` module's bz2 compression option; bzip2 tends to compress slightly better than zip. tarfile docs -- http://docs.python.org/library/tarfile.html Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Thu Jun 11 04:59:42 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Jun 2009 10:59:42 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? References: Message-ID: Stef Mientki wrote: > I packed all sources with zipfile, > but the compression doesn't seem to be very good. If you don't specify the compression, the files are not compressed at all. Just in case you didn't know... Peter From pavlovevidence at gmail.com Thu Jun 11 05:11:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Jun 2009 02:11:04 -0700 (PDT) Subject: object reincarnation References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: On Jun 10, 12:34?pm, Manavan wrote: > Hello everyone, > ? ?Since the real world objects often needs to be deleted even if they > have some reference from some other object, I am going to use this > approach to better model this situation, by cleaning up the attributes > and assigning self.__class__ to a different class. > ?Any comment on this approach. > > class Deleted(object): > ? ? pass > > class RealWorldObj(object): > ? ? def __init__(self, *args): > ? ? ? ? self.attrs = args > ? ? def getAttrs(self,): > ? ? ? ? return self.attrs > ? ? def delete(self,): > ? ? ? ? del self.attrs > ? ? ? ? self.__class__ = Deleted > > >>> a = RealWorldObj(1,2,3) > >>> print a.attrs > (1, 2, 3) > >>> a.delete() > >>> a > > <__main__.Deleted object at 0x893ae2c>>>> a.attrs > > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'Deleted' object has no attribute 'attrs' Cute, but let me suggest that changing the class of the object would make it harder to track down the original error. So just delete the attributes. I'd also recommend using self.__dict__.clear() for that, it gets all of them (usually) and doesn't need to be updated with you add a new attribute to a class. Carl Banks From info at egenix.com Thu Jun 11 05:11:05 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 11 Jun 2009 11:11:05 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.9.0-0.9.8k Message-ID: <4A30CA29.8040403@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.9.0-0.9.8k An easy to install and use repackaged distribution of the pyOpenSSL Python interface for OpenSSL - available on Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.9.0-0.9.8k-1-GA.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy to use installer that includes the most recent OpenSSL library versions in pre-compiled form. pyOpenSSL is an open-source Python add-on (http://pyopenssl.sf.net/) that allows writing SSL aware networking applications as well as certificate management tools. OpenSSL is an open-source implementation of the SSL protocol (http://www.openssl.org/). For more information, please see the product page: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included pyOpenSSL version to 0.9, which includes a new fix for a serious problem in pyOpenSSL 0.8 related to threaded applications. It also comes with an important bug-fix update of OpenSSL, now at version 0.9.8k. The problem causes invalid thread states in the Python interpreter which then result in random core dumps and seg faults when using pyOpenSSL 0.8.0 with multi-threaded applications. The new fix is slightly different than the one we included in 0.8.1 and based on a code analysis we did together with Jean-Paul Calderone to track down the cause of the problem. Binaries are available for Linux x86 and x64 as well as Windows x86 and Mac OS X PPC/Intel. They include both pyOpenSSL and the necessary OpenSSL libraries. For Plone users and friends of buildout scripts, we have added pre-built binaries for Windows. They install just like the Linux versions and allow easy integration of the archives into buildout scripts. For our Mac OS X users, we have included new pre-built binaries for Mac OS X PPC and Intel platforms. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 11 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2009-06-29: EuroPython 2009, Birmingham, UK 17 days to go ::: 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 deets at nospam.web.de Thu Jun 11 05:16:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 11 Jun 2009 11:16:25 +0200 Subject: installation in mac os x References: Message-ID: <79c05cF1q46qkU1@mid.uni-berlin.de> Karl Jansson wrote: > Hi, > > I was doing the tutorial at http://www.python.org/doc/current/ > tutorial/, and I came across some code that did not work, and I got > the following error: AttributeError: 'str' object has no attribute > 'format'. > > So I downloaded a .dmg of python 2.6.2 and then I installed it. But > it's not working. Running the Python launcher, the "new" command in > the file menu is grey, and won't work, so I can't make any scripts. > > Does anyone know how to make python 2.6.2 work in mac os x? What happens if you work on the commandline (Terminal)? Python2.6 should be available from (out of my head) /Library/Frameworks/Python.framework/Versions/2.6/bin/python If that's working, it is successfully installed. Diez From stefan_ml at behnel.de Thu Jun 11 05:21:07 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 11:21:07 +0200 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <4a30cc84$0$32668$9b4e6d93@newsspool2.arcor-online.net> Nick Craig-Wood wrote: > Luis M Gonz?lez wrote: >> I am very excited by this project (as well as by pypy) and I read all >> their plan, which looks quite practical and impressive. >> But I must confess that I can't understand why LLVM is so great for >> python and why it will make a difference. > > CPython uses a C compiler to compile the python code (written in C) > into native machine code. That would be Cython: compile Python code to (optimised) C code and then run a C compiler over that to get native machine code. http://cython.org/ CPython compiles Python code to *byte-code* and then *interprets* that in a virtual machine (which happens to be written in C, hence the name). Stefan From walkraft at gmail.com Thu Jun 11 05:28:16 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 02:28:16 -0700 (PDT) Subject: Convert integer to fixed length binary string Message-ID: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Hi, I know the bin function converts an int into a binary string. Unfortunately, I need to know the length of the binary string when it is being read in and len(bin(x)) depends on x. Is there any way to limit it to 4 bytes? Thanks for your assistance, Chris From walkraft at gmail.com Thu Jun 11 05:29:45 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 02:29:45 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: Sorry, I didn't quite make it clear. The issue isn't about limiting the length (as I won't be using integers bigger than this). The problem is that sometimes the output is shorter. From stefan_ml at behnel.de Thu Jun 11 05:53:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 11:53:23 +0200 Subject: unladen swallow: python and llvm In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <4a30d413$0$32674$9b4e6d93@newsspool2.arcor-online.net> bearophileHUGS at lycos.com wrote: > Kay Schluehr: >> Don't understand your Cython compliant. The only tricky part of Cython >> is the doublethink regarding Python types and C types. I attempted once >> to write a ShedSkin like code transformer from Python to Cython based on >> type recordings but never found the time for this because I have to work >> on EasyExtend on all fronts at the same time. > > I have tried to create a certain data structure with a recent version > of Pyrex on Windows, and I have wasted lot of time looking for missing > reference count updates that didn't happen, or memory that didn't get > freed. I wonder what you did then. Apparently, you didn't just compile a Python program, but tried to use Pyrex/Cython to avoid writing C code. That can work, but depends on your C expertise. If you only compile Python code, you will not get in touch with any ref-counting or memory leaks (any more than in CPython, that is). You only have to care about freeing memory if you manually allocate that memory through malloc(), in which case it's your own fault if it doesn't get freed. > I'm sure lot of people like Cython, but I prefer a more transparent > language, that doesn't hide me how it works inside. Cython doesn't hide anything. Most of the magic that happens is done in code tree transformations, which you can look up in the compiler code. The code generation is mostly just mapping the final code tree to C code, with some type specialisations. Cython will even copy your complete source code line-by-line into the C code it writes, so that you can easily read up what your code gets translated to. I admit that the generated C code is not always simple and obvious, as it contains lots of runtime type specialisations and optimisations. But that's the price you pay for fast code. And you can make Cython leave out most of the duplicated code (i.e. the pessimistic fallbacks) by adding type hints to your code. Stefan From dickinsm at gmail.com Thu Jun 11 06:01:43 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Jun 2009 03:01:43 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <493e875f-7975-4e4e-8512-615703e9337a@s21g2000vbb.googlegroups.com> On Jun 11, 10:29?am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. Is this what you're looking for? Python 2.6.2 (r262:71600, Jun 8 2009, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> '{0:032b}'.format(12345) '00000000000000000011000000111001' Mark From dfnsonfsduifb at gmx.de Thu Jun 11 06:18:50 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 11 Jun 2009 12:18:50 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79c404F1psv7kU1@mid.dfncis.de> Stefan Behnel schrieb: > Johannes Bauer wrote: >> when I read in a XML document with the xml.dom.minidom parser and write >> it out again, an attribute is lost: >> >> Input: >> >> >> [...] >> >> Output: >> >> >> How can I fix this? > > You don't have to. UTF-8 is the default encoding, so the two lines above > are equivalent. Can I somehow force Python to generate it anyways? I have software which complains if an explicit encoding is missing... Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From stefan_ml at behnel.de Thu Jun 11 06:54:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 12:54:51 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79c404F1psv7kU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> Message-ID: <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: >> Johannes Bauer wrote: >>> when I read in a XML document with the xml.dom.minidom parser and write >>> it out again, an attribute is lost: >>> >>> Input: >>> >>> >>> [...] >>> >>> Output: >>> >>> >>> How can I fix this? >> You don't have to. UTF-8 is the default encoding, so the two lines above >> are equivalent. > > Can I somehow force Python to generate it anyways? Did you try passing encoding='UTF-8' on serialisation? > I have software which > complains if an explicit encoding is missing... Well, to parse XML, it's best to use an XML parser. ;) Stefan From jeremiah.dodds at gmail.com Thu Jun 11 07:23:10 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Thu, 11 Jun 2009 12:23:10 +0100 Subject: Compiling Python3.1 In-Reply-To: <79an4pF1oqpbjU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> <79an4pF1oqpbjU1@mid.dfncis.de> Message-ID: <12cbbbfc0906110423i1be854f3m12f4f0ff9b0475d4@mail.gmail.com> On Wed, Jun 10, 2009 at 10:33 PM, Johannes Bauer wrote: > Martin v. L?wis schrieb: > >> What can I do about that? > > > > Remove the non-ASCII characters from db.h. > > Ehh... > > $ find -type f | grep -i db.h > OT: find -type f -iname "db.h" -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Thu Jun 11 07:34:51 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 11 Jun 2009 07:34:51 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Thanks everyone, I learned more than I expected about floats :-) and got some good explanations and ideas about all of this. Esmail From eckhardt at satorlaser.com Thu Jun 11 07:40:48 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 11 Jun 2009 13:40:48 +0200 Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <1377g6-4i7.ln1@satorlaser.homedns.org> casebash wrote: > I know the bin function converts an int into a binary string. Binary string sounds ambiguous. Firstly, everything is binary. Secondly, strings are byte strings or Unicode strings. In any case, I'm not 100% sure what you mean - giving an example of input and output would help! > Unfortunately, I need to know the length of the binary string when it > is being read in and len(bin(x)) depends on x. Is there any way to > limit it to 4 bytes? If you need a piece of four bytes which contain a number in a packed format similar to the one used in memory, using bin(x) is the wrong way. Instead, take a look at the struct module: import struct struct.pack('=L', 255) Alternatively, also the array module might help. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From python at mrabarnett.plus.com Thu Jun 11 09:08:45 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Jun 2009 14:08:45 +0100 Subject: OT: Periodic table gets a new element Message-ID: <4A3101DD.70108@mrabarnett.plus.com> Element 112 is to be named. Do you think we could persuade the scientists to name it "Pythonium"? :-) http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm From tpk at kraussfamily.org Thu Jun 11 09:20:27 2009 From: tpk at kraussfamily.org (Tom K.) Date: Thu, 11 Jun 2009 06:20:27 -0700 (PDT) Subject: retrieve bitwise float representation References: Message-ID: On Jun 10, 8:41?am, Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. ... > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. Numpy has support for this: import numpy as np a = np.arange(10.) # an array of floats b = a.view(dtype=np.uint32) print b array([ 0, 0, 1072693248, 0, 1073741824, 0, 1074266112, 0, 1074790400, 0, 1075052544, 0, 1075314688, 0, 1075576832, 0, 1075838976, 0, 1075970048, 0], dtype=uint32) b[0]=5 print a array([ 1.06099790e-313, 1.00000000e+000, 2.00000000e+000, 3.00000000e+000, 4.00000000e+000, 5.00000000e+000, 6.00000000e+000, 7.00000000e+000, 8.00000000e+000, 9.00000000e+000]) From dfnsonfsduifb at gmx.de Thu Jun 11 09:20:54 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 11 Jun 2009 15:20:54 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79celfF1odmrdU1@mid.dfncis.de> Stefan Behnel schrieb: >> Can I somehow force Python to generate it anyways? > > Did you try passing encoding='UTF-8' on serialisation? Uhm... nope - how can I do that? > >> I have software which >> complains if an explicit encoding is missing... > > Well, to parse XML, it's best to use an XML parser. ;) Well, I'm not speaking about my software :-) Actually it's Gnucash which complains if the tag is not explicitly set. This is because they appearently had a ancient version which did not specify the charset, but used a different one than UTF-8. Kind of annoying, but fixing my XML output seems to be easier than convincing the Gnucash people to change their software :-) Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From jeanmichel at sequans.com Thu Jun 11 09:27:46 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Jun 2009 15:27:46 +0200 Subject: OT: Periodic table gets a new element In-Reply-To: <4A3101DD.70108@mrabarnett.plus.com> References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: <4A310652.8030009@sequans.com> Not if this element is to end up in some further ultimate nuclear weapon :-) , unless you are using python to conquer the world (I've been told this is GVR main secret objective). MRAB wrote: > Element 112 is to be named. Do you think we could persuade the > scientists to name it "Pythonium"? :-) > > http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm From stefan_ml at behnel.de Thu Jun 11 09:35:08 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 15:35:08 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79celfF1odmrdU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> Can I somehow force Python to generate it anyways? >> Did you try passing encoding='UTF-8' on serialisation? > > Uhm... nope - how can I do that? Well, depends on what your code currently does. Maybe you could use something like doc.xmlwrite(..., encoding='UTF-8') Stefan From matthew.strax-haber at nasa.gov Thu Jun 11 09:44:24 2009 From: matthew.strax-haber at nasa.gov (Strax-Haber, Matthew (LARC-D320)) Date: Thu, 11 Jun 2009 08:44:24 -0500 Subject: FW: [Tutor] Multi-Threading and KeyboardInterrupt In-Reply-To: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: I sent this to the Tutor mailing list and did not receive a response. Perhaps one of you might be able to offer some sagely wisdom or pointed remarks? Please reply off-list and thanks in advance. Code examples are below in plain text. ------ Forwarded Message > From: Matthew Strax-Haber > Reply-To: Matthew Strax-Haber > Date: Tue, 9 Jun 2009 22:01:33 -0500 > To: Python Tutor > Subject: [Tutor] Multi-Threading and KeyboardInterrupt > > Hey everyone, > > I hope one of you can help me with this. This is my first foray into > multi-threaded programming. I have tried to boil my code down to it's > simplest demonstrative form. > > My program runs interactively by allowing the user to directly > interact with the python prompt. This program has a runAll() method > that runs a series of subprocesses with a cap on how many instances > are running at a time. My intent is to allow the user to use Ctrl-C to > break these subprocesses. Note that while not reflected in the demo > below, each subprocess needs to be able to run clean-up code before > shutting down (in single-threaded mode I just wrap in try-finally). > When I run DB.py, and interrupt it with Ctrl-C, things do not run so > cleanly. Please let me know what I can change to make this work > properly. My intent is to have the following output: > > 'key interrupt 1' > 'key interrupt 2' > 'key interrupt 3' > 'key interrupt 4' > '********* stopped midway ********' > > Here is the code for a demo: > ############################################################################## > DB.py (run this): > ############################################################################## #!/usr/bin/env python from subprocess import Popen from threading import Thread, Semaphore MAX_SUBPROCS = 3 RUN_PERMISSION = Semaphore(MAX_SUBPROCS) def runSingle(i): with RUN_PERMISSION: Popen(['./Sub.py', str(i)]).wait() def runAll(): workers = [ Thread(target = runSingle, args = [i]) for i in xrange(MAX_SUBPROCS + 1) ] try: for w in workers: w.start() except KeyboardInterrupt: ## I want this to be shown on a KeyboardInterrupt print '********* stopped midway ********' for w in workers: w.join() runAll() > ############################################################################## > Sub.py (called by DB.py): > ############################################################################## #!/usr/bin/env python import sys, time try: while True: pass except KeyboardInterrupt: print 'key interrupt %s' % sys.argv[1] raise > ############################################################################## > _______________________________________________ > Tutor maillist - Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor > ------ End of Forwarded Message From motoom at xs4all.nl Thu Jun 11 09:46:03 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 11 Jun 2009 15:46:03 +0200 Subject: OT: Periodic table gets a new element In-Reply-To: <4A3101DD.70108@mrabarnett.plus.com> References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: <4A310A9B.6030709@xs4all.nl> MRAB wrote: > Element 112 is to be named. Do you think we could persuade the > scientists to name it "Pythonium"? :-) What did Python do to deserve this? I think 'Hofmannium' is a more appropriate name ;-) On the other hand, if the scientists used Python on their equipment with which they discovered the new element, the name 'Pythonium' is of course totally acceptable. 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 brousch at gmail.com Thu Jun 11 10:01:55 2009 From: brousch at gmail.com (Ben Rousch) Date: Thu, 11 Jun 2009 14:01:55 +0000 (UTC) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: pobox.com> writes: > > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. I know about the > Programming Language Shootout: > > http://shootout.alioth.debian.org/ > > but that's not what I was thinking of. I thought there was a site with a > bunch of smaller examples. Rosetta Code has examples of common programming tasks in hundreds of languages: http://rosettacode.org/ From briandenzer at gmail.com Thu Jun 11 10:22:44 2009 From: briandenzer at gmail.com (Brian D) Date: Thu, 11 Jun 2009 07:22:44 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> On Jun 11, 2:01?am, Lie Ryan wrote: > 504cr... at gmail.com wrote: > > I've encountered a problem with my RegEx learning curve -- how to > > escape hash characters # in strings being matched, e.g.: > > >>>> string = re.escape('123#abc456') > >>>> match = re.match('\d+', string) > >>>> print match > > > <_sre.SRE_Match object at 0x00A6A800> > >>>> print match.group() > > > 123 > > > The correct result should be: > > > 123456 > > > I've tried to escape the hash symbol in the match string without > > result. > > > Any ideas? Is the answer something I overlooked in my lurching Python > > schooling? > > As you're not being clear on what you wanted, I'm just guessing this is > what you wanted: > > >>> s = '123#abc456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > '123456' > >>> s = '123#this is a comment and is ignored456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456' Sorry I wasn't more clear. I positively appreciate your reply. It provides half of what I'm hoping to learn. The hash character is actually a desirable hook to identify a data entity in a scraping routine I'm developing, but not a character I want in the scrubbed data. In my application, the hash makes a string of alphanumeric characters unique from other alphanumeric strings. The strings I'm looking for are actually manually-entered identifiers, but a real machine-created identifier shouldn't contain that hash character. The correct pattern should be 'A1234509', but is instead often merely entered as '#12345' when the first character, representing an alphabet sequence for the month, and the last two characters, representing a two-digit year, can be assumed. Identifying the hash character in a RegEx match is a way of trapping the string and transforming it into its correct machine- generated form. I'm surprised it's been so difficult to find an example of the hash character in a RegEx string -- for exactly this type of situation, since it's so common in the real world that people want to put a pound symbol in front of a number. Thanks! From briandenzer at gmail.com Thu Jun 11 10:25:18 2009 From: briandenzer at gmail.com (Brian D) Date: Thu, 11 Jun 2009 07:25:18 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: On Jun 11, 9:22?am, Brian D wrote: > On Jun 11, 2:01?am, Lie Ryan wrote: > > > > > 504cr... at gmail.com wrote: > > > I've encountered a problem with my RegEx learning curve -- how to > > > escape hash characters # in strings being matched, e.g.: > > > >>>> string = re.escape('123#abc456') > > >>>> match = re.match('\d+', string) > > >>>> print match > > > > <_sre.SRE_Match object at 0x00A6A800> > > >>>> print match.group() > > > > 123 > > > > The correct result should be: > > > > 123456 > > > > I've tried to escape the hash symbol in the match string without > > > result. > > > > Any ideas? Is the answer something I overlooked in my lurching Python > > > schooling? > > > As you're not being clear on what you wanted, I'm just guessing this is > > what you wanted: > > > >>> s = '123#abc456' > > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456' > > >>> s = '123#this is a comment and is ignored456' > > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > > '123456' > > Sorry I wasn't more clear. I positively appreciate your reply. It > provides half of what I'm hoping to learn. The hash character is > actually a desirable hook to identify a data entity in a scraping > routine I'm developing, but not a character I want in the scrubbed > data. > > In my application, the hash makes a string of alphanumeric characters > unique from other alphanumeric strings. The strings I'm looking for > are actually manually-entered identifiers, but a real machine-created > identifier shouldn't contain that hash character. The correct pattern > should be 'A1234509', but is instead often merely entered as '#12345' > when the first character, representing an alphabet sequence for the > month, and the last two characters, representing a two-digit year, can > be assumed. Identifying the hash character in a RegEx match is a way > of trapping the string and transforming it into its correct machine- > generated form. > > I'm surprised it's been so difficult to find an example of the hash > character in a RegEx string -- for exactly this type of situation, > since it's so common in the real world that people want to put a pound > symbol in front of a number. > > Thanks! By the way, other forms the strings can take in their manually created forms: A#12345 #1234509 Garbage in, garbage out -- I know. I wish I could tell the people entering the data how challenging it is to work with what they provide, but it is, after all, a screen-scraping routine. From 504crank at gmail.com Thu Jun 11 10:29:45 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Thu, 11 Jun 2009 07:29:45 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: On Jun 11, 2:01?am, Lie Ryan wrote: > 504cr... at gmail.com wrote: > > I've encountered a problem with my RegEx learning curve -- how to > > escape hash characters # in strings being matched, e.g.: > > >>>> string = re.escape('123#abc456') > >>>> match = re.match('\d+', string) > >>>> print match > > > <_sre.SRE_Match object at 0x00A6A800> > >>>> print match.group() > > > 123 > > > The correct result should be: > > > 123456 > > > I've tried to escape the hash symbol in the match string without > > result. > > > Any ideas? Is the answer something I overlooked in my lurching Python > > schooling? > > As you're not being clear on what you wanted, I'm just guessing this is > what you wanted: > > >>> s = '123#abc456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > '123456' > >>> s = '123#this is a comment and is ignored456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456'- Hide quoted text - > > - Show quoted text - Sorry I wasn't more clear. I positively appreciate your reply. It provides half of what I'm hoping to learn. The hash character is actually a desirable hook to identify a data entity in a scraping routine I'm developing, but not a character I want in the scrubbed data. In my application, the hash makes a string of alphanumeric characters unique from other alphanumeric strings. The strings I'm looking for are actually manually-entered identifiers, but a real machine-created identifier shouldn't contain that hash character. The correct pattern should be 'A1234509', but is instead often merely entered as '#12345' when the first character, representing an alphabet sequence for the month, and the last two characters, representing a two-digit year, can be assumed. Identifying the hash character in a RegEx match is a way of trapping the string and transforming it into its correct machine- generated form. Other patterns the strings can take in their manually-created form: A#12345 #1234509 Garbage in, garbage out -- I know. I wish I could tell the people entering the data how challenging it is to work with what they provide, but it is, after all, a screen-scraping routine. I'm surprised it's been so difficult to find an example of the hash character in a RegEx string -- for exactly this type of situation, since it's so common in the real world that people want to put a pound symbol in front of a number. Thanks! From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:47:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:47:46 -0300 Subject: spawning a process using os.spawn References: Message-ID: En Tue, 09 Jun 2009 15:38:53 -0300, rkmr.em at gmail.com escribi?: > im spawning a script that runs for a long from a web app like this: > > os.spawnle(os.P_NOWAIT, "../bin/producenotify.py", "producenotify.py", > "xx",os.environ) > > > the script is spawned and it runs, but till it gets over i am not able to > free the port that is used by the web app, or in other words i am not > able > to restart the web app. how do i spawn off a process and make it > completely > independent of the web app? Try subprocess.Popen instead, setting close_fds=True -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:47:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:47:58 -0300 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: En Tue, 09 Jun 2009 05:02:33 -0300, Steven D'Aprano escribi?: > [...] As tuples are defined in Python, they quack like immutable lists, > they > walk like immutable lists, and they swim like immutable lists. Why > shouldn't we treat them as immutable lists? > > Phillip Eby states that "Lists are intended to be homogeneous sequences, > while tuples are heterogeneous data structures." (Notice the subtle shift > there: lists are "intended", while tuples "are". But in fact, there's > nothing to stop you from putting homogeneous data into a tuple, so Eby is > wrong to say that tuples *are* heterogeneous.) > > Perhaps Eby intends lists to be homogeneous, perhaps Guido does too, but > this is Python, where we vigorously defend the right to shoot ourselves > in the foot. We strongly discourage class creators from trying to enforce > their intentions by using private attributes, and even when we allow such > a thing, the nature of Python is that nothing is truly private. Why > should homogeneity and heterogeneity of lists and tuples be sacrosanct? > Nothing stops me from putting hetereogeneous data into a list, or > homogeneous data into a tuple, and there doesn't appear to be any ill- > effects from doing so. Why give lose sleep over the alleged lack of > purity? Yes - but in the past the distinction was very much stronger. I think that tuples didn't have *any* method until Python 2.0 -- so, even if someone could consider a tuple a "read-only list", the illusion disappeared as soon as she tried to write anything more complex that a[i]. Maybe tuples could quack like immutable lists, but they could not swim nor walk... With time, tuples gained more and more methods and are now very similar to lists - they even have an index() method (undocumented but obvious) which is absurd in the original context. Think of tuples as used in relational databases: there is no way in SQL to express the condition "search for this along all values in this tuple", because it usually doesn't make any sense at all (and probably, if it does make sense in a certain case, it's because the database is badly designed.) But *now*, you can express that operation in Python. So I'd say that *now*, the distinction between an "homogeneous container" vs "heterogeneous data structure" has vanished a lot, and it's hard to convince people that tuples aren't just immutable lists. That is, *I* would have used a list in this case: for delay in (0.01, 0.1, 0.5, 1, 2, 5, 10, 30, 60): do_something(delay) but I cannot find a *concrete* reason to support the assertion "list is better". So, for practical purposes, tuples act now as if they were immutable lists -- one should be aware of the different memory allocation strategies, but I see no other relevant differences. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:48:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:48:18 -0300 Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: En Tue, 09 Jun 2009 20:30:06 -0300, rh0dium escribi?: > On Jun 9, 3:28?pm, Emile van Sebille wrote: >> On 6/9/2009 3:00 PM rh0dium said... >> >> > I have a .pth file which has some logic in it - but it isn't quite >> > enough... >> >> > It started with this.. >> > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], >> > "tools/python/modules")) >> >> > But that eventually evolved into.. >> > import os, site; site.addsitedir(os.path.join(os.environ.get >> > ("TECHROOT", "/home/tech"), "tools/python/modules")) >> >> Try it this way... >> >> import os, site >> smsc = os.environ.get("TECHROOT", "/home/tech") >> if not os.path.isdir(smsc): >> ? ? ?smsc = "/home/tech" >> site.addsitedir (os.path.join(smsc, >> "tools/python/Linux/%arch/lib/python2.5/site-packages")) > > No for .pth files this needs to be on a single line.. Try this instead: import os, site; smsc = os.environ.get("TECHROOT", ""); smsc = smsc if smsc and os.path.isdir(smsc) else "/home/tech"; site.addsitedir(...) >> > But now I want to check to make sure this directory exists or fall >> > back to "/home/tech". ?That was the point of the environ.get but what >> > if someone sets TECHROOT to /dev/null. ?Well that will break >> > things... ?I tried this but no go. ?Can someone help me out.. I'd add the directory unconditionally - then, when initializing the application, I'd check that the required modules can be imported, and inform the user of that specific problem if not. -- Gabriel Genellina From s.dornseifer at gmx.net Thu Jun 11 10:50:06 2009 From: s.dornseifer at gmx.net (S. Dornseifer) Date: Thu, 11 Jun 2009 16:50:06 +0200 Subject: install older Python version parallel Message-ID: <4A31199E.7030809@gmx.net> Hi everybody, The situation: I wrote a GUI, based on Python, TkInter and Pmw. It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 and various Linux Distributions. Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug in the installed blt package), also when I use setitems on Pmw.OptionMenu (I guess this is due to another package, associated with tcl/tk). The target: I have to get my GUI work under openSUSE 11.1 (x86_64). My plan: On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. I would like to know, how to install Python 2.4 along with TkInter and Pmw (and packages that are required by them), parallel to the existing Python 2.6. So that I do not break other software that depends on Python 2.6. If you can think of another plan, I would be also glad to discuss it. Cheers, Simon From 504crank at gmail.com Thu Jun 11 11:14:13 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Thu, 11 Jun 2009 08:14:13 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 10:13?am, Peter Otten <__pete... at web.de> wrote: > 504cr... at gmail.com wrote: > > I wonder if you (or anyone else) might attempt a different explanation > > for the use of the special sequence '\1' in the RegEx syntax. > > > The Python documentation explains: > > > \number > > ? ? Matches the contents of the group of the same number. Groups are > > numbered starting from 1. For example, (.+) \1 matches 'the the' or > > '55 55', but not 'the end' (note the space after the group). This > > special sequence can only be used to match one of the first 99 groups. > > If the first digit of number is 0, or number is 3 octal digits long, > > it will not be interpreted as a group match, but as the character with > > octal value number. Inside the '[' and ']' of a character class, all > > numeric escapes are treated as characters. > > > In practice, this appears to be the key to the key device to your > > clever solution: > > >>>> re.compile(r"(\d+)").sub(r"INSERT \1", string) > > > 'abc INSERT 123 def INSERT 456 ghi INSERT 789' > > >>>> re.compile(r"(\d+)").sub(r"INSERT ", string) > > > 'abc INSERT ?def INSERT ?ghi INSERT ' > > > I don't, however, precisely understand what is meant by "the group of > > the same number" -- or maybe I do, but it isn't explicit. Is this just > > a shorthand reference to match.group(1) -- if that were valid -- > > implying that the group match result is printed in the compile > > execution? > > If I understand you correctly you are right. Another example: > > >>> re.compile(r"([a-z]+)(\d+)").sub(r"number=\2 word=\1", "a1 zzz42") > > 'number=1 word=a number=42 word=zzz' > > For every match of "[a-z]+\d+" in the original string "\1" in > "number=\2 word=\1" is replaced with the actual match for "[a-z]+" and > "\2" is replaced with the actual match for "\d+". > > The result, e. g. "number=1 word=a", is then used to replace the actual > match for group 0, i. e. "a1" in the example. > > Peter- Hide quoted text - > > - Show quoted text - Wow! That is so cool. I had to process it for a little while to get it. >>> s = '111bbb333' >>> re.compile('(\d+)([b]+)(\d+)').sub(r'First string: \1 Second string: \2 Third string: \3', s) 'First string: 111 Second string: bbb Third string: 333' MRI scans would no doubt reveal that people who attain a mastery of RegEx expressions must have highly developed areas of the brain. I wonder where the RegEx part of the brain might be located. That was a really clever teaching device. I really appreciate you taking the time to post it, Peter. I'm definitely getting a schooling on this list. Thanks! From gunterhenriksen at gmail.com Thu Jun 11 12:47:42 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 09:47:42 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <8763f5d0r2.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> Message-ID: > [In this tuple] > dodge_city = (1781, 1870, 1823) > (population, feet_above_sea_level, establishment_year) = dodge_city > each index in the sequence implies something very > different about each value. The semantic meaning > of each index is *more* than just the position in > the sequence; it matters *for interpreting that > component*, and that component would not mean the > same thing in a different index position. A tuple > is the right choice, for that reason. I think I would have difficulty holding a position that this should not be a class (or equivalent via namedtuple()) or a dict. It seems to me like a case could be made that there are far more situations where it makes sense to use tuples as immutable sequences than as objects whose attributes are named implicitly by an index. This dodge_city definitely does not seem to me like a good candidate for a plain tuple. From a.cavallo at mailsnare.com Thu Jun 11 12:51:35 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Thu, 11 Jun 2009 17:51:35 +0100 Subject: install older Python version parallel In-Reply-To: <4A31199E.7030809@gmx.net> References: <4A31199E.7030809@gmx.net> Message-ID: <200906111751.35840.a.cavallo@mailsnare.com> Hi, I'm working on a project of mine that does creates python installation under /opt so they can be installed side by side with a system installed one. There's a web page: http://pyvm.sourceforge.net/ With links to the newest build plus all teh accompaining unitests. But you can use the sources rpm to create a version with python 2.4 (see http://download.opensuse.org/repositories/home:/cavallo71:/opt-python- interpreters/openSUSE_11.1/src/) Let me know if you need more help, Regards, Antoino On Thursday 11 June 2009 15:50:06 S. Dornseifer wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon From phil at riverbankcomputing.com Thu Jun 11 12:56:17 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Thu, 11 Jun 2009 17:56:17 +0100 Subject: Changing Hash Values Across Versions Message-ID: How stable should the implementation of, for example, a string's hash across different Python versions? Is it defined that hash("foo") will return the same value for Python 2.5.1, 2.6.1 and 2.6.2? Thanks, Phil From drobinow at gmail.com Thu Jun 11 13:10:10 2009 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Jun 2009 13:10:10 -0400 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79celfF1odmrdU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <4eb0089f0906111010p1a7ba147ua09828532568c8b4@mail.gmail.com> On Thu, Jun 11, 2009 at 9:20 AM, Johannes Bauer wrote: > Well, I'm not speaking about my software :-) Actually it's Gnucash which > complains if the tag is not explicitly set. This is because they > appearently had a ancient version which did not specify the charset, but > used a different one than UTF-8. Kind of annoying, but fixing my XML > output seems to be easier than convincing the Gnucash people to change > their software :-) from the GnuCash web page: How can you help? Testing: Test it and help us discover all bugs that might show up in there. Please enter each and every bug into bugzilla. Translating: The new release comes with some new translation strings. If you consider contributing a translation, we invite you to test this release already. A string freeze will be announced in one of the later 2.3.x releases. Please check http://wiki.gnucash.org/wiki/Translation_Status for updates on this. We would like to encourage people to test this and any further releases as much as possible and submit bug reports in order that we can polish GnuCash to be as stable as possible for the 2.4.0 release in a few weeks. Then post any bugs you find to bugzilla (http://bugzilla.gnome.org/enter_bug.cgi?product=GnuCash) From praveen.kariyanahalli at gmail.com Thu Jun 11 13:48:55 2009 From: praveen.kariyanahalli at gmail.com (Praveen Kariyanahalli) Date: Thu, 11 Jun 2009 10:48:55 -0700 Subject: Issues download 2.4 python (for windows) msi Message-ID: Hi I am having issues downloading any msi prior to the 3.X version. All of them appear to be truncated. My old scripts dont compile on the later versions. Can someone please fix this ASAP ? Thanks -Praveen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Thu Jun 11 14:20:58 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 11:20:58 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <9280e227-f32d-4aca-a48c-3a4ce25c0f11@w9g2000pro.googlegroups.com> On Jun 11, 4:29?am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. This works also: >>> bin(15)[2:].zfill(32) '00000000000000000000000000001111' From mensanator at aol.com Thu Jun 11 14:26:55 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 11:26:55 -0700 (PDT) Subject: OT: Periodic table gets a new element References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: On Jun 11, 8:27?am, Jean-Michel Pichavant wrote: > Not if this element is to end up in some further ultimate nuclear weapon > ? :-) ? Don't worry, a millisecond half-life is kind of a wet blanket as far as weapon design is concerned. > , unless you are using python to conquer the world (I've been > told this is GVR main secret objective). > > > > MRAB wrote: > > Element 112 is to be named. Do you think we could persuade the > > scientists to name it "Pythonium"? :-) > > >http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm- Hide quoted text - > > - Show quoted text - From Scott.Daniels at Acm.Org Thu Jun 11 14:32:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 11 Jun 2009 11:32:24 -0700 Subject: Changing Hash Values Across Versions In-Reply-To: References: Message-ID: Phil Thompson wrote: > How stable should the implementation of, for example, a string's hash > across different Python versions? > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > 2.6.1 and 2.6.2? > > Thanks, > Phil Pretty certain that A.B.* will always hash the same (unacceptable change as a bugfix), and that there has been no recent need to change the string hash (it gets a _lot_ of use), so in practice I suspect that 2.3.* through 2.8.* all produce the same string hashes. However, the language doesn't guarantee a lot about the value, and I would not be surprised to see a non-CPython implementation use a different hash. Generally it is a good idea to keep the result of hash computations inside the program, and off the persistant store, so I'd want a good excuse to use the hash "outside." --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Thu Jun 11 14:40:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 15:40:06 -0300 Subject: Changing Hash Values Across Versions References: Message-ID: En Thu, 11 Jun 2009 13:56:17 -0300, Phil Thompson escribi?: > How stable should the implementation of, for example, a string's hash > across different Python versions? I cannot find any such guarantee in the documentation: http://docs.python.org/reference/datamodel.html > Is it defined that hash("foo") will return the same value for Python > 2.5.1, 2.6.1 and 2.6.2? I've tested and it does, all versions since Python 1.5 up to 3.0.1. But you should not rely on that. What do you want to do exactly? -- Gabriel Genellina From tjreedy at udel.edu Thu Jun 11 14:54:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2009 14:54:13 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: Jack Diederich wrote: > On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: > [snip] >> I found my answer: Python 2.6 introduces heap.merge(), which is >> designed exactly for this. > > Thanks, I knew Raymond added something like that but I couldn't find > it in itertools. > That said .. it doesn't help. Aside, heapq.merge fits better in > itertools (it uses heaps internally but doesn't require them to be > passed in). The other function that almost helps is > itertools.groupby() and it doesn't return an iterator so is an odd fit > for itertools. > > More specifically (and less curmudgeonly) heap.merge doesn't help for > this particular case because you can't tell where the merged values > came from. You want all the iterators to yield the same thing at once > but heapq.merge muddles them all together (but in an orderly way!). > Unless I'm reading your tokenizer func wrong it can yield the same > value many times in a row. If that happens you don't know if four > "The"s are once each from four iterators or four times from one. David is looking to intersect sorted lists of document numbers with duplicates removed in order to find documents that contain worda and wordb and wordc ... . But you are right that duplicate are a possible fly in the ointment to be removed before merging. From brendandetracey at yahoo.com Thu Jun 11 14:54:57 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 11 Jun 2009 11:54:57 -0700 (PDT) Subject: Alter list items within loop Message-ID: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Can someone please explain what is happening in the output below? The number 3 never gets printed. Does Python make a copy of a list before it iterates through it?: >>> e = range(1,5) >>> for i in e: print i if i == 2 : e.remove(i) 1 2 4 >>> e [1, 3, 4] From tjreedy at udel.edu Thu Jun 11 15:04:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2009 15:04:22 -0400 Subject: Restart the interactive python shell like in IDLE In-Reply-To: <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> References: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Wed, Jun 10, 2009 at 12:01 PM, Matt Burson wrote: >> Is there a way to reproduce the behavior of IDLE's restart shell ability by >> using a function? I thought there would be since you can exit python by >> executing the simple quit() function I thought there would be an equally >> simple function name something like restart(). I'd prefer something like >> this as opposed to having to exit the shell and then start it up again to >> refresh it. > > I believe IDLE itself implements the "restart" capability by killing > and re-launching its Python interpreter subprocess, so it's not like > it's using some hidden capability of Python to accomplish this. > Is doing Ctrl+D, up-arrow, Enter really that hard? It's even fewer > keystrokes than "restart()"... This will do part of what you want: >>> a=1 >>> b=1 >>> globals().clear() >>> a Traceback (most recent call last): File "", line 1, in NameError: name 'a' is not defined That will not reset sys.modules, which is the only other thing I can imagine being worried about. The main reason IDLE has a restart is so that when you run a file after editing, you can be sure the behavior you see is what you get when running the file without IDLE, with a fresh interpreter. Another use of refresh is when creating example interactive sessions for doctest or book examples. Again, one wants to make sure that the example does not depend on previous entries not included in the example. For ordinary interactive exploration, refresh is seldom needed. tjr From stef.mientki at gmail.com Thu Jun 11 15:11:52 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Jun 2009 21:11:52 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: References: Message-ID: <4A3156F8.1010900@gmail.com> Peter Otten wrote: > Stef Mientki wrote: > > >> I packed all sources with zipfile, >> but the compression doesn't seem to be very good. >> > > If you don't specify the compression, the files are not compressed at all. > Just in case you didn't know... > .. and would you be willing to tell me how I could set the compression ( at maximum) ? thanks, Stef Mientki > Peter > > From emile at fenx.com Thu Jun 11 15:23:16 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Jun 2009 12:23:16 -0700 Subject: Alter list items within loop In-Reply-To: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Message-ID: On 6/11/2009 11:54 AM Brendan said... > Can someone please explain what is happening in the output below? you delete e[2] before displaying it. The > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: No. Mods to a list while passing it is generally not a good idea. Sometimes passing the list backwards works. Emile >>>> e = range(1,5) >>>> for i in e: > print i > if i == 2 : > e.remove(i) > > > 1 > 2 > 4 >>>> e > [1, 3, 4] From clp2 at rebertia.com Thu Jun 11 15:27:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 12:27:19 -0700 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: <4A3156F8.1010900@gmail.com> References: <4A3156F8.1010900@gmail.com> Message-ID: <50697b2c0906111227r7bd02efdy4f5ec7dc9afa7532@mail.gmail.com> On Thu, Jun 11, 2009 at 12:11 PM, Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >>> I packed all sources with zipfile, >>> but the compression doesn't seem to be very good. >>> >> >> If you don't specify the compression, the files are not compressed at all. >> Just in case you didn't know... >> > > .. and would you be willing to tell me how I could set the compression ( at > maximum) ? If you had glanced @ the docs for 30 seconds: import zipfile z = zipfile.ZipFile(dest_file, "w", zipfile.ZIP_DEFLATED) Cheers, Chris -- http://blog.rebertia.com From usernet at ilthio.net Thu Jun 11 15:32:17 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 19:32:17 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Message-ID: <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> On 2009-06-11, Brendan wrote: > Can someone please explain what is happening in the output below? The > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: You can see what is happening by printing the list as you work through the loop: >>> e = range(1,5) >>> for i in e: ... print e ... print i ... if i == 2 : ... e.remove(i) ... [1, 2, 3, 4] 1 [1, 2, 3, 4] 2 [1, 3, 4] 4 first loop: i = 0 e[i] = e[0] = 1 second loop i = 1 e[i] = e[1] = 2 third loop i = 2 e[i] = e[2] = 4 > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: No, complex types are passed by reference unless explicity copied. You can do what you want by making an explicit copy before entering the loop: >>> e = range(1,5) >>> for i in e[:]: ... print e ... print i ... if i == 2 : ... e.remove(i) ... [1, 2, 3, 4] 1 [1, 2, 3, 4] 2 [1, 3, 4] 3 [1, 3, 4] 4 From __peter__ at web.de Thu Jun 11 15:33:56 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Jun 2009 21:33:56 +0200 Subject: zipfile doesn't compress very good, are there other solutions? References: Message-ID: Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >> >> >>> I packed all sources with zipfile, >>> but the compression doesn't seem to be very good. >>> >> >> If you don't specify the compression, the files are not compressed at >> all. Just in case you didn't know... >> > .. and would you be willing to tell me how I could set the compression ( > at maximum) ? According to the documentation (hint, hint) there is only on and off. zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) Peter From steven.oldner at gmail.com Thu Jun 11 15:44:03 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Thu, 11 Jun 2009 12:44:03 -0700 (PDT) Subject: Blogger Widget web app Message-ID: <7b3f931c-7750-440d-8f91-315c4c04dc72@d2g2000pra.googlegroups.com> Please give me directions on where to start researching for answers. I probably can do the javascript, but I don't know where to start on the Python. 1. Wife has a blogger blog and wants a widget to embed in the posts. 2. Widget will have a form that readers can enter their name and url. 3. Widget also lists in numeric order the name and url of all the readers who signed up in that post. 4. Son has an old PC he turned into a server, and installed Windows IIS on it. What I need to do is to write the cgi scripts to send a list of names and urls for each post on load, validate the input from the form and store the results per blog post. If you have seen Mr. Linky, that's what I'm tring to mimic. This will only be for her blog, so she can have a faster load time and less down time. I have NO intention to build this for more than her. So very simple and easy is the key. I've read the mailing list, I just got the books, Programming Python by Mark Lutz and and Python Web Programming by Steve Holden. There is so much great info I don't know where to start or what I need to start with. Thanks for any pointers. Steve Oldner From madsmaillist at gmail.com Thu Jun 11 15:52:55 2009 From: madsmaillist at gmail.com (Mads Michelsen) Date: Thu, 11 Jun 2009 21:52:55 +0200 Subject: Unhandled exception in thread Message-ID: <5e7a0ce90906111252o484818ckb18a07c55fd693ed@mail.gmail.com> (I'll ask you to bear with the somewhat vague description in advance - I'm a noob in all respects here, with regard to python and the mailing list) I'm getting some error reports sometimes when I quit a script, I've been working on. The reports are extremely uninformative, and I do not notice anything wrong in the script's behaviour, which makes the error very hard to pin down. I'm therefore looking for advice on a way that I can investigate the error. Here's the deal. The script in question is a screen scraping thing which downloads and parses the html in the background using a separate thread (the 'thread' module), while the main program serves up the data to the user, allowing some modicum of interaction. Sometimes, not always (though I cannot see a pattern), when I quit the script, the following error message is printed: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: And that's it! Seems like there's some information missing? What is the error in sys.excepthook? What was the original exception? And where? Any suggestions on how to proceed? - Mads From lists at cheimes.de Thu Jun 11 15:55:40 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Jun 2009 21:55:40 +0200 Subject: Changing Hash Values Across Versions In-Reply-To: References: Message-ID: Phil Thompson schrieb: > How stable should the implementation of, for example, a string's hash > across different Python versions? > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > 2.6.1 and 2.6.2? The hash of an object is an internal implementation detail. The hash() value of an object isn't even stable for the one version of Python. It depends on the architecture (32 vs. 64bit OS, maybe even big vs. little endian). The hash sums of objects like classes may and most likely do change when you restart the interpreter. Python 2.5.4 (r254:67916, Feb 4 2009, 14:25:49) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import struct; struct.calcsize("P") * 8 32 >>> hash("a") -468864544 Python 2.5.4 (r254:67916, Apr 4 2009, 17:56:17) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import struct; struct.calcsize("P") * 8 64 >>> hash("a") 12416037344 $ python2.5 -c "import os; print hash(os)" 140519221134232 $ python2.5 -c "import os; print hash(os)" 139731515618200 $ python2.5 -c "import os; print hash(os)" 140460433757080 $ python2.5 -c "import os; print hash(os)" 140707220554648 From mmrasheed at gmail.com Thu Jun 11 15:56:42 2009 From: mmrasheed at gmail.com (Captain___nemo) Date: Thu, 11 Jun 2009 12:56:42 -0700 (PDT) Subject: =?windows-1252?Q?Voronoi_diagram_algorithm_=28Fortune=92s_sweepline=29?= Message-ID: Hi, I am implementing Voronoi diagram to find out the nearest location in a map visually. Right now I want to do this using integer coordinates (x,y) only in a canvas. Problem is- I am really confused about this algorithm. I read the Computational Geometry book, few more theory on Fortune's algorithm. And I am really confused now. It seems very complex to me when I am going for coding. Please advice me very simple implementation of voronoi diagram (given coordinates). Please advice me simple python code preferably without- hash, multi-threading, Delaunay Traingulation, fancy colors etc (which are confusing). Isn't it possible to implement Voronoi diagram using Fortune's algorithm without multithreading or hash map? Thanks in advance. From aahz at pythoncraft.com Thu Jun 11 15:57:19 2009 From: aahz at pythoncraft.com (Aahz) Date: Thu, 11 Jun 2009 12:57:19 -0700 Subject: EXTENDED: OSCON 2009 early bird (June 23) Message-ID: <20090611195719.GA15733@panix.com> Registration is now open for the O'Reilly Open Source Convention (OSCON). OSCON 2009 will be July 20-24 in San Jose, California. Early registration has been extended and now ends June 23. Use the special discount code 'os09pgm' for an extra 15% off. For more information: http://conferences.oreilly.com/oscon -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From arnodel at googlemail.com Thu Jun 11 16:09:49 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 11 Jun 2009 21:09:49 +0100 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: David Wilson writes: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. As it is a nice little problem I tried to find a solution today. FWIW, here it is (tested extensively only on the example below :): def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(1, len(v)): while v[0] > v[i]: v[i] = nexts[i]() if v[0] < v[i]: break else: yield v[0] v[0] = nexts[0]() >>> list(intersect([[1, 100, 142, 322, 12312], ... [2, 100, 101, 322, 1221], ... [100, 142, 322, 956, 1222]])) [100, 322] From dickinsm at gmail.com Thu Jun 11 16:18:30 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Jun 2009 13:18:30 -0700 (PDT) Subject: Changing Hash Values Across Versions References: Message-ID: <14e293e1-f52b-4865-a7f8-f54b2ddb4832@c18g2000prh.googlegroups.com> On Jun 11, 8:55?pm, Christian Heimes wrote: > Phil Thompson schrieb: > > > How stable should the implementation of, for example, a string's hash > > across different Python versions? > > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > > 2.6.1 and 2.6.2? > > The hash of an object is an internal implementation detail. The hash() > value of an object isn't even stable for the one version of Python. It > depends on the architecture (32 vs. 64bit OS, maybe even big vs. little > endian). The hash sums of objects like classes may and most likely do > change when you restart the interpreter. What he said. I remember at least one recent hash change: the algorithm for computing the hash of a long is different in Python 2.5.x and Python 2.6.x. Mark From swift at mirohost.net Thu Jun 11 16:24:51 2009 From: swift at mirohost.net (Sydoruk Yaroslav) Date: Thu, 11 Jun 2009 20:24:51 +0000 (UTC) Subject: reading from file Message-ID: Hello all, In a text file aword.txt, there is a string: "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc". There is a first script: f = open ("aword.txt", "r") for line in f: print chardet.detect(line) b = line.decode('cp1251') print b _RESULT_ {'confidence': 1.0, 'encoding': 'ascii'} \xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc There is a second script: line = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" print chardet.detect(line) b = line.decode('cp1251') print b _RESULT_ {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} ???+????????? Why is reading from a file into a string variable is defined as ascii, but when it is clearly defined in the script is defined as cp1251. How do I solve this problem. -- Only one 0_o From bearophileHUGS at lycos.com Thu Jun 11 16:28:34 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 13:28:34 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <2438bcbb-80f7-4f20-900b-a3175b6d2e19@a7g2000yqk.googlegroups.com> Captain___nemo: > Isn't it possible to implement Voronoi diagram using Fortune's > algorithm without multithreading or hash map? Multi-threading isn't part of Fortune's algorithm. Multi-threading can be confusing, but it's better for you to learn to feel at home using hash maps (named dicts in Python), because they are both essential in computer science and in Python. Ask if you need some help regarding dicts and sets. Bye, bearophile From stef.mientki at gmail.com Thu Jun 11 16:41:41 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Jun 2009 22:41:41 +0200 Subject: zipfile doesn't compress very good, are there other solutions? In-Reply-To: References: Message-ID: <4A316C05.4080808@gmail.com> Peter Otten wrote: > Stef Mientki wrote: > > >> Peter Otten wrote: >> >>> Stef Mientki wrote: >>> >>> >>> >>>> I packed all sources with zipfile, >>>> but the compression doesn't seem to be very good. >>>> >>>> >>> If you don't specify the compression, the files are not compressed at >>> all. Just in case you didn't know... >>> >>> >> .. and would you be willing to tell me how I could set the compression ( >> at maximum) ? >> > > According to the documentation (hint, hint) there is only on and off. > > zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) > > sorry guys I made a mistake, I did read the doc, but as there was no default value metioned, I did a few tests, and I made a mistake with these experiments. Indeed the compression is much better now, just 15% larger than 7zip, which is quit acceptable. thanks again, Stef > Peter > > From jeff at jmcneil.net Thu Jun 11 16:45:11 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 11 Jun 2009 13:45:11 -0700 (PDT) Subject: reading from file References: Message-ID: On Jun 11, 4:24?pm, Sydoruk Yaroslav wrote: > Hello all, > > In a text file aword.txt, there is a string: > ? ? "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc". > > There is a first script: > f = open ("aword.txt", "r") > for line in f: > ? ? print chardet.detect(line) > ? ? b = line.decode('cp1251') > ? ? print b > > _RESULT_ > {'confidence': 1.0, 'encoding': 'ascii'} > \xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc > > There is a second script: > line = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" > print chardet.detect(line) > b = line.decode('cp1251') > print b > > _RESULT_ > {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} > ???+????????? > > Why is reading from a file into a string variable is defined as ascii, > but when it is clearly defined in the script is defined as cp1251. > How do I solve this problem. > > -- > Only one 0_o Is the string in your text file literally "\xea\xe0\xea+\xef\xee \xe7\xe2\xee\xed\xe8\xf2\xfc" as "plain text?" My assumption is that when you're reading that in, Python is interpreting each byte as an ASCII value (and rightfully so) rather than the corresponding '\x' escapes. As an experiment: (t)jeff at marvin:~/t$ cat test.py import chardet s = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" with open('test.txt', 'w') as f: print >>f, s print chardet.detect(open('test.txt').read()) (t)jeff at marvin:~/t$ python test.py {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} (t)jeff at marvin:~/t$ HTH, Jeff mcjeff.blogspot.com From duncan.booth at invalid.invalid Thu Jun 11 16:45:18 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Jun 2009 20:45:18 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: Tim Harig wrote: >> number 3 never gets printed. Does Python make a copy of a list before >> it iterates through it?: > > No, complex types are passed by reference unless explicity copied. *All* types are passed by reference unless explicitly copied. Python does make special cases for simple and complex types. From clp2 at rebertia.com Thu Jun 11 16:58:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 13:58:43 -0700 Subject: zipfile doesn't compress very good, are there other solutions? In-Reply-To: <4A316C05.4080808@gmail.com> References: <4A316C05.4080808@gmail.com> Message-ID: <50697b2c0906111358u400942f1yb2bcb1b33c1ecabe@mail.gmail.com> On Thu, Jun 11, 2009 at 1:41 PM, Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >>> Peter Otten wrote: >>>> Stef Mientki wrote: >>>>> I packed all sources with zipfile, >>>>> but the compression doesn't seem to be very good. >>>>> >>>> >>>> If you don't specify the compression, the files are not compressed at >>>> all. Just in case you didn't know... >>>> >>> >>> .. and would you be willing to tell me how I could set the compression ( >>> at maximum) ? >>> >> >> According to the documentation (hint, hint) there is only on and off. >> >> zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) >> >> > > sorry guys I made a mistake, > I did read the doc, but as there was no default value metioned, Erm... class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]]) Open a ZIP file [...] compression is the ZIP compression method to use when writing the archive, and should be ZIP_STORED or ZIP_DEFLATED; [...] The default is ZIP_STORED. [...] Though I admit the docs could definitely do with having "compression=ZIP_STORED" in the signature part of the doc. Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Thu Jun 11 17:01:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Jun 2009 16:01:37 -0500 Subject: Voronoi diagram algorithm =?UTF-8?B?KEZvcnR1bmXigJlzIHN3ZWVw?= =?UTF-8?B?bGluZSk=?= In-Reply-To: References: Message-ID: On 2009-06-11 14:56, Captain___nemo wrote: > Hi, > I am implementing Voronoi diagram to find out the nearest location in > a map visually. Right now I want to do this using integer coordinates > (x,y) only in a canvas. > > Problem is- I am really confused about this algorithm. I read the > Computational Geometry book, few more theory on Fortune's algorithm. > And I am really confused now. It seems very complex to me when I am > going for coding. Yup. It is complex. > Please advice me very simple implementation of voronoi diagram (given > coordinates). Please advice me simple python code preferably without- > hash, multi-threading, Delaunay Traingulation, You can't really do the Voronoi diagram without Delaunay Triangulation. They are two ways of looking at the same thing. > fancy colors etc (which > are confusing). You can see a mild modification of Fortune's original C code here: http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/VoronoiDiagramGenerator.cpp > Isn't it possible to implement Voronoi diagram using Fortune's > algorithm without multithreading or hash map? It's possible to do it without multithreading, of course, but Fortune's algorithm does require some sophisticated data structures. Computational geometry is rarely a simple matter. -- 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 aaron.watters at gmail.com Thu Jun 11 17:03:18 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Thu, 11 Jun 2009 14:03:18 -0700 (PDT) Subject: ANN: WHIFF += Flash chart widget support Message-ID: <50bc6bbd-91dd-4dcf-80c9-a101b02ea1a0@w31g2000prd.googlegroups.com> WHIFF.0.3 adds amChart Flash based Charts. The amChart chart widgets [ http://www.amcharts.com ] provide a sophisticated methodology for creating beautiful and interactive statistical charts using Adobe Flash plug-in technology. The WHIFF.0.3 release adds extensive support for embedding amCharts charts in web pages under the ./demo/amcharts demo directory area. Please look at chart examples explained in the documentation at http://aaron.oirt.rutgers.edu/myapp/amcharts/doc Also please try out the "disk usage analysis" pie chart drill down demo at http://aaron.oirt.rutgers.edu/myapp/amcharts/diskUsage Below is more information about WHIFF: === WHIFF -- WSGI/HTTP INTEGRATED FILESYSTEM FRAMES WHIFF is an infrastructure for easily building complex Python/WSGI Web applications by combining smaller and simpler WSGI components organized within file system trees. To DOWNLOAD WHIFF go to the WHIFF project information page at http://sourceforge.net/projects/whiff and follow the download instructions. To GET THE LATEST WHIFF clone the WHIFF Mercurial repository located at http://aaron.oirt.rutgers.edu/cgi-bin/whiffRepo.cgi. To READ ABOUT WHIFF view the WHIFF documentation at http://aaron.oirt.rutgers.edu/myapp/docs/W.intro. To PLAY WITH WHIFF try the demos listed in the demos page at http://aaron.oirt.rutgers.edu/myapp/docs/W1300.testAndDemo. Why WHIFF? ========== WHIFF (WSGI HTTP Integrated Filesystem Frames) is intended to make it easier to create, deploy, and maintain large and complex Python based WSGI Web applications. I created WHIFF to address complexity issues I encounter when creating and fixing sophisticated Web applications which include complex database interactions and dynamic features such as AJAX (Asynchronous JavaScript and XML). The primary tools which reduce complexity are an infrastructure for managing web application name spaces, a configuration template language for wiring named components into an application, and an applications programmer interface for accessing named components from Python and javascript modules. All supporting conventions and tools offered by WHIFF are optional. WHIFF is designed to work well with other modules conformant to the WSGI (Web Service Gateway Interface) standard. Developers and designers are free to use those WHIFF tools that work for them and ignore or replace the others. WHIFF does not provide a "packaged cake mix" for baking a web application. Instead WHIFF is designed to provide a set of ingredients which can be easily combined to make web applications (with no need to refine your own sugar or mill your own wheat). I hope you like it. -- Aaron Watters === less is more From swift at mirohost.net Thu Jun 11 17:06:14 2009 From: swift at mirohost.net (Sydoruk Yaroslav) Date: Thu, 11 Jun 2009 21:06:14 +0000 (UTC) Subject: reading from file References: Message-ID: Jeff McNeil wrote: > Is the string in your text file literally "\xea\xe0\xea+\xef\xee > \xe7\xe2\xee\xed\xe8\xf2\xfc" as "plain text?" My assumption is that > when you're reading that in, Python is interpreting each byte as an > ASCII value (and rightfully so) rather than the corresponding '\x' > escapes. > > As an experiment: > > (t)jeff at marvin:~/t$ cat test.py > import chardet > > s = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" > with open('test.txt', 'w') as f: > print >>f, s > > print chardet.detect(open('test.txt').read()) > (t)jeff at marvin:~/t$ python test.py > {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} > (t)jeff at marvin:~/t$ > > HTH, > > Jeff > mcjeff.blogspot.com Thank you for your reply. You are right, Python reads data form the file in bytes and all data in this case is ASCII I solved the problem, just added line = line.decode('string_escape') f = open ("aword.txt", "r") for line in f: line = line.decode('string_escape') ? ? print chardet.detect(line) ? ? b = line.decode('cp1251') ? ? print b -- Only one 0_o From usernet at ilthio.net Thu Jun 11 17:12:07 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 21:12:07 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: On 2009-06-11, Duncan Booth wrote: > Tim Harig wrote: >>> number 3 never gets printed. Does Python make a copy of a list before >>> it iterates through it?: >> No, complex types are passed by reference unless explicity copied. > *All* types are passed by reference unless explicitly copied. Python does > make special cases for simple and complex types. That is technically true; but, you will not have this issue with simple singlular data types. Technically the difference as to whether you will have this problem depends on whether or not an object is mutable. Simple objects (numbers and strings) are all immutable. Since this issue revolves around changing objects in place, it cannot arise with immutable objects. I am not always conscous of whether I am working with objects that are mutable or immutable; but, I am generally concious of the general complexity of the object. Whenever I am working with objects that are complex, I am reminded to watch out for mutability issues. So, while it is not totally correct to think of it this way, I find it an easier guideline to follow. From bearophileHUGS at lycos.com Thu Jun 11 17:16:47 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 14:16:47 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Robert Kern: > You can see a mild modification of Fortune's original C code here: > > http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/Voro... That's C++; C++ makes simple things hard and hard things possible :-) In Python that code may become much shorter (and slower). Bye, bearophile From jackdied at gmail.com Thu Jun 11 17:27:32 2009 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 11 Jun 2009 17:27:32 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 11, 2009 at 2:54 PM, Terry Reedy wrote: > Jack Diederich wrote: >> >> On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: >> [snip] >>> >>> I found my answer: Python 2.6 introduces heap.merge(), which is >>> designed exactly for this. >> >> Thanks, I knew Raymond added something like that but I couldn't find >> it in itertools. >> That said .. it doesn't help. ?Aside, heapq.merge fits better in >> itertools (it uses heaps internally but doesn't require them to be >> passed in). ?The other function that almost helps is >> itertools.groupby() and it doesn't return an iterator so is an odd fit >> for itertools. >> >> More specifically (and less curmudgeonly) heap.merge doesn't help for >> this particular case because you can't tell where the merged values >> came from. ?You want all the iterators to yield the same thing at once >> but heapq.merge muddles them all together (but in an orderly way!). >> Unless I'm reading your tokenizer func wrong it can yield the same >> value many times in a row. ?If that happens you don't know if four >> "The"s are once each from four iterators or four times from one. > > David is looking to intersect sorted lists of document numbers with > duplicates removed in order to find documents that contain worda and wordb > and wordc ... . ?But you are right that duplicate are a possible fly in the > ointment to be removed before merging. Ah, in that case the heap.merge solution is both useful and succinct: import heapq import itertools def intersect(its): source = heapq.merge(*its) while True: sames = [source.next()] sames.extend(itertools.takewhile(lambda v:v == sames[0], source)) if len(sames) == len(its): yield sames[0] return -Jack From nick at craig-wood.com Thu Jun 11 17:29:36 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 11 Jun 2009 16:29:36 -0500 Subject: unladen swallow: python and llvm References: <4a30cc84$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel wrote: > Nick Craig-Wood wrote: > > Luis M Gonz?lez wrote: > >> I am very excited by this project (as well as by pypy) and I read all > >> their plan, which looks quite practical and impressive. > >> But I must confess that I can't understand why LLVM is so great for > >> python and why it will make a difference. > > > > CPython uses a C compiler to compile the python code (written in C) > > into native machine code. > > That would be Cython: compile Python code to (optimised) C code and then > run a C compiler over that to get native machine code. Actually I meant "compile the python source code" - sorry if I wasn't clear! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From tanner989 at hotmail.com Thu Jun 11 17:33:18 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Thu, 11 Jun 2009 16:33:18 -0500 Subject: help with errror Message-ID: could some one explain this error to me and possibly how to fix it? Traceback (most recent call last): File "C:\Users\brandon\workspace\tanner's workshop\tanner's workshop\src\WxGlade.py", line 458, in Edit = MyDialog2(None, -1, "") File "C:\Users\brandon\workspace\tanner's workshop\tanner's workshop\src\WxGlade.py", line 27, in __init__ self.Name = wx.StaticText(self.panel_41, -1, "Name") File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 8522, in SetName return _core_.Window_SetName(*args, **kwargs) TypeError: String or Unicode type required _________________________________________________________________ Hotmail? has ever-growing storage! Don?t worry about storage limits. http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Thu Jun 11 17:34:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 11 Jun 2009 14:34:27 -0700 Subject: Unhandled exception in thread In-Reply-To: References: Message-ID: Mads Michelsen wrote: > ...I'm getting some error reports ... looking for advice on a way that > I can investigate the error.... The script ... downloads and... > in the background using a separate thread (the 'thread' module), .... > Sometimes, .... when I quit the script, the following error message is printed: > > Unhandled exception in thread started by > Error in sys.excepthook: > > Original exception was: > > And that's it! Seems like there's some information missing? What is > the error in sys.excepthook? What was the original exception? And > where? > > Any suggestions on how to proceed? (1) Generally, use Threading rather than thread. It says so at the top of the thread docs. (2) Sounds like it might be a timing problem while shutting down. Do you tell the thread to stop, and then stop it? That would generally be the best architecture. (3) From above, what you might want is something like: import Threading import Queue ... def code(commands, replies): for element in iter(commands.get, None): # None: stop signal time.sleep(1) # just here to represent processing time. results = repr(element) # and simulating some results" replies.put(results) replies.put(None) # superfluous indication of end ... def main(): ... commands = queue.Queue() replies = queue.Queue() worker = threading.Thread(target=code, args=(commands, replies)) worker.daemon = True # or use .setDaemon(True) for older for n in range(5): commands.put(n) print 'first couple:', results.get(), results.get() commands.put(None) # tell the worker to stop. worker.join() # wait for the worker to shut down. Making the worker a daemon, telling it to stop with a command, and waiting for it to finish with a .join are all belts-and-suspenders related to the thread shutdown, but it sounds like you have a thread shutdown issue. --Scott David Daniels Scott.Daniels#Acm.Org From robert.kern at gmail.com Thu Jun 11 17:42:07 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Jun 2009 16:42:07 -0500 Subject: Voronoi diagram algorithm =?UTF-8?B?KEZvcnR1bmXigJlzIHN3ZWVw?= =?UTF-8?B?bGluZSk=?= In-Reply-To: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: On 2009-06-11 16:16, Bearophile wrote: > Robert Kern: >> You can see a mild modification of Fortune's original C code here: >> >> http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/Voro... > > That's C++; C++ makes simple things hard and hard things possible :-) The actual algorithm implementation is just Fortune's original C code. The C++ is mostly just wrapped around it. > In Python that code may become much shorter (and slower). Doubtful. The algorithm would mostly be the same. The data structure doesn't really translate to Python very well; it's very pointer-based. Yes, I've tried. -- 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 lyndiechiou at gmail.com Thu Jun 11 17:50:32 2009 From: lyndiechiou at gmail.com (lynvie) Date: Thu, 11 Jun 2009 14:50:32 -0700 (PDT) Subject: what does "lost sys.stdin" error mean? Message-ID: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> I have a very simple program from the first chapter of a book on python 3 (I'm a novice). I called the program tmp.py and the data input file is sum.dat (just a list of numbers, 1 per line). When I type into my command shell "tmp.py < sum.dat" I get an error from "line=input()" -- that's line 7 from the code below. The exact error message is: RuntimeError: input(): lost sys.stdin. print("Type integers, each followed by Enter; or ^D or ^Z to finish") total=0 count=0 while True: try: line=input() if line: number=int(line) total += number count += 1 print("number =",number) except ValueError as err: print(err) continue except EOFError: break if count: print("count =", count, "total =", total, "mean =", total/ count) From ben+python at benfinney.id.au Thu Jun 11 17:55:24 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Jun 2009 07:55:24 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> Message-ID: <87eitqa10z.fsf@benfinney.id.au> Gunter Henriksen writes: > I think I would have difficulty holding a position that this should > not be a class (or equivalent via namedtuple()) or a dict. It seems to > me like a case could be made that there are far more situations where > it makes sense to use tuples as immutable sequences than as objects > whose attributes are named implicitly by an index. This dodge_city > definitely does not seem to me like a good candidate for a plain > tuple. It's a fair cop. (I only meant that for this example a tuple was superior to a list, but you're right that a dict would be better than either.) Try, then, this tuple: event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, minute, second) = event_timestamp A list would be wrong for this value, because each position in the sequence has a specific meaning beyond its mere sequential position. Yet it also matters to the reader that these items are in a specific sequence, since that's a fairly standard ordering for those items. In this case, a tuple is superior to a list because it correctly conveys the semantic meaning of the overall value: the items must retain their sequential order to have the intended meaning, and to alter any one of them is conceptually to create a new timestamp value. -- \ ?[The RIAA] have the patience to keep stomping. They're playing | `\ whack-a-mole with an infinite supply of tokens.? ?kennon, | _o__) http://kuro5hin.org/ | Ben Finney From dorzey at googlemail.com Thu Jun 11 18:02:11 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:02:11 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From dorzey at googlemail.com Thu Jun 11 18:02:20 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:02:20 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From dorzey at googlemail.com Thu Jun 11 18:03:34 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:03:34 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From rhodri at wildebst.demon.co.uk Thu Jun 11 18:12:38 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Jun 2009 23:12:38 +0100 Subject: How to escape # hash character in regex match strings In-Reply-To: <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: On Thu, 11 Jun 2009 15:22:44 +0100, Brian D wrote: > I'm surprised it's been so difficult to find an example of the hash > character in a RegEx string -- for exactly this type of situation, > since it's so common in the real world that people want to put a pound > symbol in front of a number. It's a character with no special meaning to the regex engine, so I'm not in the least surprised that there aren't many examples containing it. You could just as validly claim that there aren't many examples involving the letter 'q'. By the way, I don't know what you're doing but I'm seeing all of your posts twice, from two different addresses. This is a little confusing, to put it mildly, and doesn't half break the threading. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Thu Jun 11 18:12:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Jun 2009 23:12:39 +0100 Subject: install older Python version parallel In-Reply-To: <4A31199E.7030809@gmx.net> References: <4A31199E.7030809@gmx.net> Message-ID: On Thu, 11 Jun 2009 15:50:06 +0100, S. Dornseifer wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). You might get more helpful responses if you say more than just "it crashes". What's the traceback? -- Rhodri James *-* Wildebeest Herder to the Masses From hari at pillai.co.uk Thu Jun 11 18:18:24 2009 From: hari at pillai.co.uk (Harry) Date: Thu, 11 Jun 2009 23:18:24 +0100 Subject: command line of a process.exe on another host Message-ID: HI , I have number of process run on different windows servers which run's with different command line parameters. for example "process.exe -input statusurl: http://sss.com "., These parameters can vary from host to host. using Psexec I know the PID and process name which are running on these machines, but how I can read the command line parameters of these process. Is there a way to read these command line of the proess via python pls? any feedback appreciated.. thanks Hari From dfnsonfsduifb at gmx.de Thu Jun 11 18:19:31 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:19:31 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79de78F1pvp5cU1@mid.dfncis.de> Stefan Behnel schrieb: > Johannes Bauer wrote: >> Stefan Behnel schrieb: >> >>>> Can I somehow force Python to generate it anyways? >>> Did you try passing encoding='UTF-8' on serialisation? >> Uhm... nope - how can I do that? > > Well, depends on what your code currently does. > > Maybe you could use something like > > doc.xmlwrite(..., encoding='UTF-8') Yay! Does the trick, thanks a lot! Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From python.list at tim.thechases.com Thu Jun 11 18:19:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Jun 2009 17:19:33 -0500 Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: <4A3182F5.7080106@tim.thechases.com> >> I'm surprised it's been so difficult to find an example of the hash >> character in a RegEx string -- for exactly this type of situation, >> since it's so common in the real world that people want to put a pound >> symbol in front of a number. > > It's a character with no special meaning to the regex engine, so I'm not > in the least surprised that there aren't many examples containing it. > You could just as validly claim that there aren't many examples involving > the letter 'q'. It depends on whether the re.VERBOSE option is passed. If you're using a verbose regexp, you can use "#" to comment portions of it: r = re.compile(r""" \d+ # some digits [aeiou] # some vowels """, re.VERBOSE) -tkc From dfnsonfsduifb at gmx.de Thu Jun 11 18:21:10 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:21:10 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <79deaaF1pvp5cU2@mid.dfncis.de> David Robinow schrieb: > On Thu, Jun 11, 2009 at 9:20 AM, Johannes Bauer wrote: >> Well, I'm not speaking about my software :-) Actually it's Gnucash which >> complains if the tag is not explicitly set. This is because they >> appearently had a ancient version which did not specify the charset, but >> used a different one than UTF-8. Kind of annoying, but fixing my XML >> output seems to be easier than convincing the Gnucash people to change >> their software :-) > > from the GnuCash web page: > How can you help? Well, it's not as if it's a bug of GnuCash. This is a deliberate decision used to ensure backwards compatibility with older versions of GnuCash. So a bug report wouldn't really do good anything at all ("Please remove your backwards compatibility feature, it annoys me and I only use recent versions anyways"). Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From mensanator at aol.com Thu Jun 11 18:23:46 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 15:23:46 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 11, 1:54?pm, Terry Reedy wrote: > Jack Diederich wrote: > > On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: > > [snip] > >> I found my answer: Python 2.6 introduces heap.merge(), which is > >> designed exactly for this. > > > Thanks, I knew Raymond added something like that but I couldn't find > > it in itertools. > > That said .. it doesn't help. ?Aside, heapq.merge fits better in > > itertools (it uses heaps internally but doesn't require them to be > > passed in). ?The other function that almost helps is > > itertools.groupby() and it doesn't return an iterator so is an odd fit > > for itertools. > > > More specifically (and less curmudgeonly) heap.merge doesn't help for > > this particular case because you can't tell where the merged values > > came from. ?You want all the iterators to yield the same thing at once > > but heapq.merge muddles them all together (but in an orderly way!). > > Unless I'm reading your tokenizer func wrong it can yield the same > > value many times in a row. ?If that happens you don't know if four > > "The"s are once each from four iterators or four times from one. > > David is looking to intersect sorted lists of document numbers with > duplicates removed in order to find documents that contain worda and > wordb and wordc ... . ?But you are right that duplicate are a possible > fly in the ointment to be removed before merging. Removing the duplicates could be a big problem. With SQL, the duplicates need not have to be removed. All I have to do is change "SELECT" to "SELECT DISTINCT" to change 100 100 100 322 322 322 322 322 322 322 322 into 100 322 From pavlovevidence at gmail.com Thu Jun 11 18:28:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Jun 2009 15:28:30 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <8d0cb8d0-b7d7-4d12-868b-d0ab6804af7b@p21g2000prn.googlegroups.com> On Jun 11, 2:01?pm, Robert Kern wrote: > On 2009-06-11 14:56, Captain___nemo wrote: > > Please advice me very simple implementation of voronoi diagram (given > > coordinates). Please advice me simple python code preferably without- > > hash, multi-threading, Delaunay Traingulation, > > You can't really do the Voronoi diagram without Delaunay Triangulation. They are > two ways of looking at the same thing. You might not be able to calculate the exact points of a Voronoi without Delaunay triangulation but you can certainly draw one without it. For instance, this code does that: import numpy from PIL import Image def voronoi(points,shape=(500,500)): depthmap = numpy.ones(shape,numpy.float)*1e308 colormap = numpy.zeros(shape,numpy.int) def hypot(X,Y): return (X-x)**2 + (Y-y)**2 for i,(x,y) in enumerate(points): paraboloid = numpy.fromfunction(hypot,shape) colormap = numpy.where(paraboloid < depthmap,i+1,colormap) depthmap = numpy.where(paraboloid < depthmap,paraboloid,depthmap) for (x,y) in points: colormap[x-1:x+2,y-1:y+2] = 0 return colormap def draw_map(colormap): shape = colormap.shape palette = numpy.array([ 0x000000FF, 0xFF0000FF, 0x00FF00FF, 0xFFFF00FF, 0x0000FFFF, 0xFF00FFFF, 0x00FFFFFF, 0xFFFFFFFF, ]) colormap = numpy.transpose(colormap) pixels = numpy.empty(colormap.shape+(4,),numpy.int8) pixels[:,:,3] = palette[colormap] & 0xFF pixels[:,:,2] = (palette[colormap]>>8) & 0xFF pixels[:,:,1] = (palette[colormap]>>16) & 0xFF pixels[:,:,0] = (palette[colormap]>>24) & 0xFF image = Image.fromstring("RGBA",shape,pixels) image.save('voronoi.png') if __name__ == '__main__': draw_map(voronoi(([100,100],[356,301],[400,65],[324,145], [200,399]))) Carl Banks From dfnsonfsduifb at gmx.de Thu Jun 11 18:29:22 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:29:22 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> References: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79depnF1q8o72U1@mid.dfncis.de> Stefan Behnel schrieb: >> So I need to build hyperlinks (a elements) with href attribute and >> replace the text elements (numbers) somehow. > > Try lxml.html instead. It makes it really easy to do these things. For > example, you can use XPath to find all table cells that contain numbers: > > td_list = doc.xpath("//td[number() >= 0]") > > or maybe using regular expressions to make sure it's an int: > > td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", > namespaces={'re':'http://exslt.org/regular-expressions'}) > > and then replace them by a hyperlink: > > # assuming links = ['http://...', ...] > > from lxml.html.builder import A > for td in td_list: > index = int(td.text) > a = A("some text", href=links[index]) > td.getparent().replace(td, a) Oh no! I was looking for something like this for *ages* but always fought with minidom - where this is a real pain :-( Had I only known before that such a wonderful library exists. I'll definitely use lxml from now on. Does it compile with Python3? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From usernet at ilthio.net Thu Jun 11 19:01:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 23:01:16 GMT Subject: what does "lost sys.stdin" error mean? References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> Message-ID: <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> On 2009-06-11, lynvie wrote: > I have a very simple program from the first chapter of a book on > python 3 (I'm a novice). I called the program tmp.py and the data > input file is sum.dat (just a list of numbers, 1 per line). When I > type into my command shell "tmp.py < sum.dat" I get an error from What OS are you using? I know that pipes cause issues when working with interpreters on Windows. You must call the python interpreter directly or it will not be able to handle the pipe directly. I don't remember exacly how the issue manifests but I remember it has bitten me before on Win32. I don't currenlty have a Windows machine to test on. > "line=input()" -- that's line 7 from the code below. The exact error > message is: > RuntimeError: input(): lost sys.stdin. I am working on Linux and I have been unable to produce your error. My Python version identifies itself as: >>> import sys >>> sys.version '3.0.1 (r301:69556, Mar 17 2009, 11:42:03) \n[GCC 4.1.2]' This is what I have done using your same tmp.py file as pasted from a shell session: 17:52,505$ count=0 17:53,506$ while [ $count -lt 20 ]; do echo $RANDOM >> sum.dat; newcount=`echo "$count + 1" | bc`; count=$newcount; done 17:53,507$ python3.0 tmp.py < sum.dat Type integers, each followed by Enter; or ^D or ^Z to finish number = 22657 count = 1 total = 22657 mean = 22657.0 number = 12223 count = 2 total = 34880 mean = 17440.0 number = 10250 count = 3 total = 45130 mean = 15043.3333333 number = 20919 count = 4 total = 66049 mean = 16512.25 number = 20995 count = 5 total = 87044 mean = 17408.8 number = 28988 count = 6 total = 116032 mean = 19338.6666667 number = 13015 count = 7 total = 129047 mean = 18435.2857143 number = 25701 count = 8 total = 154748 mean = 19343.5 number = 6566 count = 9 total = 161314 mean = 17923.7777778 number = 19396 count = 10 total = 180710 mean = 18071.0 number = 16771 count = 11 total = 197481 mean = 17952.8181818 number = 2039 count = 12 total = 199520 mean = 16626.6666667 number = 655 count = 13 total = 200175 mean = 15398.0769231 number = 27417 count = 14 total = 227592 mean = 16256.5714286 number = 5000 count = 15 total = 232592 mean = 15506.1333333 number = 12015 count = 16 total = 244607 mean = 15287.9375 number = 8746 count = 17 total = 253353 mean = 14903.1176471 number = 29487 count = 18 total = 282840 mean = 15713.3333333 number = 3194 count = 19 total = 286034 mean = 15054.4210526 number = 8225 count = 20 total = 294259 mean = 14712.95 As you can see, it seems to be working as prescribed. From usernet at ilthio.net Thu Jun 11 19:25:08 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 23:25:08 GMT Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> Message-ID: On 2009-06-11, Tim Harig wrote: > On 2009-06-11, lynvie wrote: >> I have a very simple program from the first chapter of a book on >> python 3 (I'm a novice). I called the program tmp.py and the data >> input file is sum.dat (just a list of numbers, 1 per line). When I >> type into my command shell "tmp.py < sum.dat" I get an error from > What OS are you using? I know that pipes cause issues when working with > interpreters on Windows. You must call the python interpreter directly or > it will not be able to handle the pipe directly. I don't remember exacly > how the issue manifests but I remember it has bitten me before on Win32. I > don't currenlty have a Windows machine to test on. More info: http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/10d3928277319bef From gunterhenriksen at gmail.com Thu Jun 11 19:34:56 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 16:34:56 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <87eitqa10z.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> Message-ID: > Try, then, this tuple: > > event_timestamp = (2009, 06, 04, 05, 02, 03) > (year, month, day, hour, minute, second) = event_timestamp > > A list would be wrong for this value, because each position in the > sequence has a specific meaning beyond its mere sequential position. Yet > it also matters to the reader that these items are in a specific > sequence, since that's a fairly standard ordering for those items. > > In this case, a tuple is superior to a list because it correctly conveys > the semantic meaning of the overall value: the items must retain their > sequential order to have the intended meaning, and to alter any one of > them is conceptually to create a new timestamp value. I totally agree about anything to do with immutability, I think the relative ordering of the elements in this example may be orthogonal to the concept of a tuple as an object whose elements have a semantic meaning implicitly defined by location in the sequence... in other words knowing that element i+1 is in some sense ordinally smaller than element i does not give me much information about what element i+1 actually is. To me a timestamp could be (date, time), or (days, seconds, microseconds) (as in datetime.timedelta()), so it is not clear to me that using a tuple as something where the semantic meaning of the element at position i should readily apparent would be the best approach for timestamps, or enough to distinguish list and tuple (in other words I am not suggesting a dict or class). In the case of something like (x, y) or (real, imag), or (longitude, latitude), or any case where there is common agreement and understanding, such that using names is arguably superfluous... I think in those cases the concept makes sense of a tuple as a sequence of attributes whose elements have a semantic meaning implicitly defined by position in the sequence. My feeling is the number of cases where tuples are better than lists for that is small relative to the number of cases where tuple adds value as an immutable list. I do not mean to be suggesting that a tuple should only ever be used or thought of as a "frozenlist" though. From bearophileHUGS at lycos.com Thu Jun 11 19:47:30 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 16:47:30 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: <487b006c-f4ab-448b-90eb-9d7450d15f3a@3g2000yqk.googlegroups.com> dorzey: > Found this python implementation: > http://www.oxfish.com/python/voronoi.py Looks very nice, and it may be ShedSkin-compilable too. Bye, bearophile From ben+python at benfinney.id.au Thu Jun 11 19:56:14 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Jun 2009 09:56:14 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> Message-ID: <878wjy8gv5.fsf@benfinney.id.au> Gunter Henriksen writes: > > Try, then, this tuple: > > > > event_timestamp = (2009, 06, 04, 05, 02, 03) > > (year, month, day, hour, minute, second) = event_timestamp > > I totally agree about anything to do with immutability, I think the > relative ordering of the elements in this example may be orthogonal to > the concept of a tuple as an object whose elements have a semantic > meaning implicitly defined by location in the sequence... in other > words knowing that element i+1 is in some sense ordinally smaller than > element i does not give me much information about what element i+1 > actually is. The point of each position having a different semantic meaning is that tuple unpacking works as above. You need to know the meaning of each position in order to unpack it to separate names, as above. So two tuples that differ only in the sequence of their items are different in meaning. This is unlike a list, where the sequence of items does *not* affect the semantic meaning of each item. Note that I'm well aware that the language doesn't impose this as a hard restriction; but that says more about Python's ?consenting adults? philosophy than anything else. -- \ ?I went to a general store. They wouldn't let me buy anything | `\ specifically.? ?Steven Wright | _o__) | Ben Finney From clp2 at rebertia.com Thu Jun 11 20:36:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 17:36:52 -0700 Subject: help with errror In-Reply-To: References: Message-ID: <50697b2c0906111736kc89aceoec7329b294c96478@mail.gmail.com> On Thu, Jun 11, 2009 at 2:33 PM, tanner barnes wrote: > could some one explain this error to me and possibly how to fix it? > > Traceback (most recent call last): > ? File "C:\Users\brandon\workspace\tanner's workshop\tanner's > workshop\src\WxGlade.py", line 458, in > ??? Edit = MyDialog2(None, -1, "") > ? File "C:\Users\brandon\workspace\tanner's workshop\tanner's > workshop\src\WxGlade.py", line 27, in __init__ > ??? self.Name = wx.StaticText(self.panel_41, -1, "Name") > ? File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line > 8522, in SetName > ??? return _core_.Window_SetName(*args, **kwargs) > TypeError: String or Unicode type required Might I suggest you inquire on the WxPython mailinglist: http://www.wxpython.org/maillist.php Cheers, Chris -- http://blog.rebertia.com From gunterhenriksen at gmail.com Thu Jun 11 21:14:35 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 18:14:35 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <878wjy8gv5.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: > > > event_timestamp = (2009, 06, 04, 05, 02, 03) > > > (year, month, day, hour, minute, second) = event_timestamp > > > > [...] > > The point of each position having a different semantic meaning is that > tuple unpacking works as above. You need to know the meaning of each > position in order to unpack it to separate names, as above. > > So two tuples that differ only in the sequence of their items are > different in meaning. This is unlike a list, where the sequence of items > does *not* affect the semantic meaning of each item. I do not feel the above is significantly different enough from event_timestamp = [2009, 06, 04, 05, 02, 03] (year, month, day, hour, minute, second) = event_timestamp event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, minute, second) = event_timestamp event_timestamp = [2009, 06, 04, 05, 02, 03] [year, month, day, hour, minute, second] = event_timestamp to suggest tuples are really adding significant value in this case, especially when I can do something like event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, second, minute) = event_timestamp and not have any indication I have done the wrong thing. I guess to me, fundamentally, the interpretation of tuple as a sequence whose elements have semantic meaning implicitly defined by position is a relatively abstract intrepretation whose value is dubious relative to the value of immutability, since it seems like a shortcut which sacrifices explicitness for the sake of brevity. I would feel differently if seemed unusual to find good Python code which iterates through the elements of a tuple as a variable length homogenous ordered collection. But then I would be wishing for immutable lists... From drentha at gmail.com Thu Jun 11 21:54:56 2009 From: drentha at gmail.com (Oni) Date: Thu, 11 Jun 2009 18:54:56 -0700 (PDT) Subject: Specify the sorting direction for the various columns/ Message-ID: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Managed to get a dictionary to sort on multiple columns using a tuple to set the sort order (see below). However how can I control that column "date" orders descending and the column "name" orders ascending. Thanks import datetime import pprint import operator faUserFormInput = {'DDPageSortOrder': 'PageAge'} mypages = ["PageName","PageAge","PageAge"] gaValidSortOrder = [ {'OrderType': 'PageName', 'SortOrder': ('name')}, {'OrderType': 'PageAge', 'SortOrder': ('date','name')}, {'OrderType': 'PageAuthor', 'SortOrder': ('username','date')} ] entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] sortorderarr = ('name','date') #if ("DDPageSortOrder" in faUserFormInput): for item in gaValidSortOrder: print "1=%s" % (item["OrderType"]) print "2=%s" % (faUserFormInput["DDPageSortOrder"]) if (item["OrderType"] == faUserFormInput["DDPageSortOrder"]): sortorderarr = item["SortOrder"] #sortorderarr = '\','.join(sortorder) print sortorderarr pp = pprint.PrettyPrinter(depth=2) pp.pprint(entries) bob = entries bob.sort(key=operator.itemgetter(*sortorderarr),reverse=True) pp.pprint(bob) From walkraft at gmail.com Thu Jun 11 22:03:46 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 19:03:46 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> <1377g6-4i7.ln1@satorlaser.homedns.org> Message-ID: <3e342702-34d2-41fe-8343-3fbb5bb2f878@y6g2000prf.googlegroups.com> Thanks, this is what I needed On Jun 11, 9:40?pm, Ulrich Eckhardt wrote: > casebash wrote: > > I know the bin function converts an int into a binary string. > > Binary string sounds ambiguous. Firstly, everything is binary. Secondly, > strings are byte strings or Unicode strings. In any case, I'm not 100% sure > what you mean - giving an example of input and output would help! > > > Unfortunately, I need to know the length of the binary string when it > > is being read in and len(bin(x)) depends on x. Is there any way to > > limit it to 4 bytes? > > If you need a piece of four bytes which contain a number in a packed format > similar to the one used in memory, using bin(x) is the wrong way. Instead, > take a look at the struct module: > > ? import struct > ? struct.pack('=L', 255) > > Alternatively, also the array module might help. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jiangsy at gmail.com Thu Jun 11 22:20:27 2009 From: jiangsy at gmail.com (sanyi jiang) Date: Fri, 12 Jun 2009 10:20:27 +0800 Subject: Socket packet timing on Windows 2000 Message-ID: <896de4920906111920h5e2dc687m6b871ab4da0cdc52@mail.gmail.com> hi *Tim Janick,* I encountered same problem, did you ever get some resolution? Brent Jiang, -------------- next part -------------- An HTML attachment was scrubbed... URL: From Nikolaus at rath.org Thu Jun 11 22:28:05 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Thu, 11 Jun 2009 22:28:05 -0400 Subject: Problem with apsw and garbage collection Message-ID: <87tz2mb2yy.fsf@vostro.rath.org> Hi, Please consider this example: -------------- next part -------------- A non-text attachment was scrubbed... Name: vacuum.py Type: text/x-python Size: 1006 bytes Desc: not available URL: -------------- next part -------------- While the first execute("VACUUM") call succeeds, the second does not but raises an apsw.BusyError (meaning that sqlite thinks that it cannot get an exclusive lock on the database). I suspect that the reason for that is that the cursor object that is created in the function is not destroyed when the function is left with raise (rather than return), which in turn prevents sqlite from obtaining the lock. However, if I exchange the VACUUM command by something else (e.g. CREATE TABLE), the program runs fine. I think this casts some doubt on the above explanation, since, AFAIK sqlite always locks the entire file and should therefore have the some problem as before. Can someone explain what exactly is happening here? Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From silverburgh.meryl at gmail.com Thu Jun 11 22:30:14 2009 From: silverburgh.meryl at gmail.com (meryl) Date: Thu, 11 Jun 2009 19:30:14 -0700 (PDT) Subject: Need help in Python regular expression Message-ID: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Hi, I have this regular expression blockRE = re.compile(".*RenderBlock {\w+}") it works if my source is "RenderBlock {CENTER}". But I want it to work with 1. RenderTable {TABLE} So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), but that breaks everything 2. RenderBlock (CENTER) So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), that also breaks everything Can you please tell me how to change my reg exp so that I can support all 3 cases: RenderTable {TABLE} RenderBlock (CENTER) RenderBlock {CENTER} Thank you. From peter at www.pjb.com.au Thu Jun 11 23:32:26 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 12 Jun 2009 03:32:26 GMT Subject: Measuring Fractal Dimension ? Message-ID: Greetings. Are there any modules, packages, whatever, that will measure the fractal dimensions of a dataset, e.g. a time-series ? Like the Correlation Dimension, the Information Dimension, etc... Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From lucius.fox08 at gmail.com Thu Jun 11 23:56:24 2009 From: lucius.fox08 at gmail.com (lucius) Date: Thu, 11 Jun 2009 20:56:24 -0700 (PDT) Subject: TypeError: int argument required Message-ID: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> I am trying to print some values to a file (using c's printf like method). TypeError: int argument required # this works, i see value on screen print w, h, absX, absY # where result is the return value of my regular expression. w, h, absX, absY = result.group(3), result.group(4), result.group (5), result.group(6) w = 100 h = 200 absX = 10.0 absY = 20.0 # this fails, I get "TypeError: int argument required" print >> fo, " " % (absX, absY, w, h) Thank you for any help. From wuwei23 at gmail.com Fri Jun 12 00:01:14 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Jun 2009 21:01:14 -0700 (PDT) Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <1baa40c6-0666-4376-9ad0-47fc2c8326cb@p21g2000prn.googlegroups.com> On Jun 12, 1:56?pm, lucius wrote: > ?w, h, absX, absY = result.group(3), result.group(4), result.group > (5), result.group(6) > > w = 100 > h = 200 > > absX = 10.0 > absY = 20.0 Are you sure those values are ints & floats? I would expect your regexp would be returning strings... Try replacing the %f & %d strsubs with %s and see if that works. (You shouldn't need to typecast the values if you're just reinserting them into a string...) From metolone+gmane at gmail.com Fri Jun 12 00:41:24 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 11 Jun 2009 21:41:24 -0700 Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: "meryl" wrote in message news:2d4d8624-043b-4f5f-ae2d-bf73bca3d51b at p6g2000pre.googlegroups.com... > Hi, > > I have this regular expression > blockRE = re.compile(".*RenderBlock {\w+}") > > it works if my source is "RenderBlock {CENTER}". > > But I want it to work with > 1. RenderTable {TABLE} > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > but that breaks everything > > 2. RenderBlock (CENTER) > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > that also breaks everything > > Can you please tell me how to change my reg exp so that I can support > all 3 cases: > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} [abcd] syntax matches a single character from the set. Use non-grouping parentheses instead: -----------------------code---------------------- import re pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') testdata = '''\ RenderTable {TABLE} RenderBlock (CENTER) RenderBlock {CENTER} RenderTable {TABLE) #shouldn't match ''' print pat.findall(testdata) --------------------------------------------------- Result: ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] -Mark From jstrickler at gmail.com Fri Jun 12 00:47:51 2009 From: jstrickler at gmail.com (John S) Date: Thu, 11 Jun 2009 21:47:51 -0700 (PDT) Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> On Jun 11, 10:30?pm, meryl wrote: > Hi, > > I have this regular expression > blockRE = re.compile(".*RenderBlock {\w+}") > > it works if my source is "RenderBlock {CENTER}". > > But I want it to work with > 1. RenderTable {TABLE} > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > but that breaks everything > > 2. RenderBlock (CENTER) > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > that also breaks everything > > Can you please tell me how to change my reg exp so that I can support > all 3 cases: > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} > > Thank you. Short answer: r = re.compile(r"Render(?:Block|Table)\s+[({](?:TABLE|CENTER)[})]") s = """ blah blah blah blah blah blah RenderBlock {CENTER} blah blah RenderBlock {CENTER} blah blah blah RenderTable {TABLE} blah blah RenderBlock (CENTER) blah blah blah """ print r.findall(s) output: ['RenderBlock {CENTER}', 'RenderBlock {CENTER}', 'RenderTable {TABLE}', 'RenderBlock (CENTER)'] Note that [] only encloses characters, not strings; [foo|bar] matches 'f','o','|','b','a', or 'r', not "foo" or "bar". Use (foo|bar) to match "foo" or "bar"; (?xxx) matches xxx without making a backreference (i.e., without capturing text). HTH -- John Strickler From metolone+gmane at gmail.com Fri Jun 12 00:55:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 11 Jun 2009 21:55:16 -0700 Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Message-ID: "Oni" wrote in message news:018f4fa2-7203-4c98-a313-da5584976bd9 at z20g2000prh.googlegroups.com... > Managed to get a dictionary to sort on multiple columns using a tuple > to set the sort order (see below). However how can I control that > column "date" orders descending and the column "name" orders > ascending. One way is to sort twice...sort on the secondary key first, then the primary key. sort will maintain the order of equal entries. -Mark From stefan_ml at behnel.de Fri Jun 12 01:08:19 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Jun 2009 07:08:19 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: <79depnF1q8o72U1@mid.dfncis.de> References: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79depnF1q8o72U1@mid.dfncis.de> Message-ID: <4a31e2c3$0$30231$9b4e6d93@newsspool1.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> So I need to build hyperlinks (a elements) with href attribute and >>> replace the text elements (numbers) somehow. >> Try lxml.html instead. It makes it really easy to do these things. For >> example, you can use XPath to find all table cells that contain numbers: >> >> td_list = doc.xpath("//td[number() >= 0]") >> >> or maybe using regular expressions to make sure it's an int: >> >> td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", >> namespaces={'re':'http://exslt.org/regular-expressions'}) >> >> and then replace them by a hyperlink: >> >> # assuming links = ['http://...', ...] >> >> from lxml.html.builder import A >> for td in td_list: >> index = int(td.text) >> a = A("some text", href=links[index]) >> td.getparent().replace(td, a) > > Oh no! I was looking for something like this for *ages* but always > fought with minidom - where this is a real pain :-( > > Had I only known before that such a wonderful library exists. I'll > definitely use lxml from now on. Yep, I keep advertising it all over the place, but there are still so many references to minidom on the web that it's hard to become the first hit in Google when you search for "Python XML". ;) Actually, the first hit (for me) is currently PyXML, which is officially unmaintained. Wasn't there 'some' Python developer working for Google? What about fixing their database? > Does it compile with Python3? Sure. :) Stefan From silverburgh.meryl at gmail.com Fri Jun 12 01:20:24 2009 From: silverburgh.meryl at gmail.com (meryl) Date: Thu, 11 Jun 2009 22:20:24 -0700 (PDT) Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: On Jun 11, 9:41?pm, "Mark Tolonen" wrote: > "meryl" wrote in message > > news:2d4d8624-043b-4f5f-ae2d-bf73bca3d51b at p6g2000pre.googlegroups.com... > > > > > > > Hi, > > > I have this regular expression > > blockRE = re.compile(".*RenderBlock {\w+}") > > > it works if my source is "RenderBlock {CENTER}". > > > But I want it to work with > > 1. RenderTable {TABLE} > > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > > but that breaks everything > > > 2. RenderBlock (CENTER) > > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > > that also breaks everything > > > Can you please tell me how to change my reg exp so that I can support > > all 3 cases: > > RenderTable {TABLE} > > RenderBlock (CENTER) > > RenderBlock {CENTER} > > [abcd] syntax matches a single character from the set. ?Use non-grouping > parentheses instead: > > -----------------------code---------------------- > import re > pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') > > testdata = '''\ > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} > RenderTable {TABLE) ? ? ?#shouldn't match > ''' > > print pat.findall(testdata) > --------------------------------------------------- > > Result: > > ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] > > -Mark Thanks for both of your help. How can i modify the RegExp so that both RenderTable {TABLE} and RenderTable {TABLE} [text with a-zA-Z=SPACE0-9] will match I try adding ".*" at the end , but it ends up just matching the second one. Thanks again. From mk.fraggod at gmail.com Fri Jun 12 01:34:34 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 12 Jun 2009 11:34:34 +0600 Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Message-ID: <20090612113434.47a84b00@coercion> On Thu, 11 Jun 2009 18:54:56 -0700 (PDT) Oni wrote: > Managed to get a dictionary to sort on multiple columns using a tuple > to set the sort order (see below). However how can I control that > column "date" orders descending and the column "name" orders > ascending. ... > bob = entries > bob.sort(key=operator.itemgetter(*sortorderarr),reverse=True) > pp.pprint(bob) Note that this accomplishes nothing, since bob and entries are the same object, so entries.sort and bob.sort are the same method of the same object. You can use "copy" module to clone list and it's contents (dict objects) or just use list constructor to clone list structure only, leaving contents essencially the same, but in different order. Or, in this case, you can just use "sorted" function which constructs sorted list from any iterable. As for the question, in addition to Mark's suggestion of doing sub-sorting, you can also construct complex index (code below). Dunno which would be more efficient in the particular case... import datetime import pprint entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] entries.sort(lambda x: (x['name'], -time.mktime(x['date'].timetuple()))) Here time is inversed, yielding reverse sort order by that column. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lyndiechiou at gmail.com Fri Jun 12 02:15:04 2009 From: lyndiechiou at gmail.com (lynvie) Date: Thu, 11 Jun 2009 23:15:04 -0700 (PDT) Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> Message-ID: <602fb38b-abdf-498a-8b3b-99eeb1f388ac@s38g2000prg.googlegroups.com> Thanks for the additional info! I had no idea this was an old Windows problem... I'm using Windows XP and I'm up-to-date on all my patches. The good news is I can invoke the script correctly now, thanks to your help! On Jun 11, 4:25?pm, Tim Harig wrote: > On 2009-06-11, Tim Harig wrote: > > > On 2009-06-11, lynvie wrote: > >> I have a very simple program from the first chapter of a book on > >> python 3 (I'm a novice). I called the program tmp.py and the data > >> input file is sum.dat (just a list of numbers, 1 per line). When I > >> type into my command shell "tmp.py < sum.dat" I get an error from > > What OS are you using? ?I know that pipes cause issues when working with > > interpreters on Windows. ?You must call the python interpreter directly or > > it will not be able to handle the pipe directly. ?I don't remember exacly > > how the issue manifests but I remember it has bitten me before on Win32. ?I > > don't currenlty have a Windows machine to test on. > > More info:http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/1... From prasoonthegreat at gmail.com Fri Jun 12 02:17:36 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:17:36 -0700 (PDT) Subject: EOF problem with ENTER Message-ID: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> I am new to python.... I have written the following program in python.It is the solution of problem ETF in SPOJ..... #Euler Totient Function from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): t=input() while(t): x=input() print str(etf(x)) t-=1 if __name__ == "__main__": main() The problem with my code is that whenever I press an extra "Enter" button instead of getting the cursor moved to the next line.....I get an error _SyntaxError- EOF while parsing and the program terminates.........._ How should the code be modified so that even after pressing an extra "Enter" button the cursor get moved to the next line instead to throwing an exception...... Prasoon From clp2 at rebertia.com Fri Jun 12 02:28:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 23:28:20 -0700 Subject: EOF problem with ENTER In-Reply-To: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <50697b2c0906112328x52e06d64h4ccfa6fdd24a2158@mail.gmail.com> On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > I am new to python.... > I have written the following program in python.It is the solution of > problem ETF in SPOJ..... > > > #Euler Totient Function > > from math import sqrt > def etf(n): > ? i,res =2,n > ? while(i*i<=n): > ? ? ?if(n%i==0): > ? ? ? ? ? ?res-=res/i > ? ? ?while(n%i==0): > ? ? ? ? ? ?n/=i > ? ? ?i+=1 > ? if(n>1): > ? ? ? ?res-=res/n > ? return res > > def main(): > ?t=input() > ?while(t): > ? ?x=input() > ? ?print str(etf(x)) > ? ?t-=1 > > if __name__ == "__main__": > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > button instead of getting the cursor moved to the next line.....I get > an error > > _SyntaxError- EOF while parsing and the program terminates.........._ > > How should ?the code be modified so that even after ?pressing an extra > "Enter" button the cursor get moved to the next line instead to > throwing an exception...... Use raw_input() instead of input() [at least until you switch to Python 3.x]. input() does an implicit eval() of the keyboard input, which is (in part) causing your problem. Note that you'll need to explicitly convert the string raw_input() reads in using either int() or float() as appropriate. Still, you can't just enter extra lines and expect the program to automatically ignore them. You'll have to write the extra code yourself to handle empty input from the user. Cheers, Chris -- http://blog.rebertia.com From graham.dumpleton at gmail.com Fri Jun 12 02:29:10 2009 From: graham.dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 11 Jun 2009 23:29:10 -0700 (PDT) Subject: FW: [Tutor] Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: On Jun 12, 3:35?pm, Dennis Lee Bieber wrote: > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > declaimed the following in > gmane.comp.python.general: > > > I sent this to the Tutor mailing list and did not receive a response. > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > remarks? > > > Please reply off-list and thanks in advance. Code examples are below in > > plain text. > > ? ? ? ? Sorry -- you post to a public forum, expect to get the response on a > public forum... Bbit off topic, but if you are a proponent of public forums, how come your post on Google Groups shows: """Note: The author of this message requested that it not be archived. This message will be removed from Groups in 6 days (Jun 19, 3:35 pm).""" I always find it a tad annoying that people have this, as you loose posts from the record of a discussion and if that post carries useful information, it is lost. Am also curious as to what mechanism for posting you use that allows you to set an expiration time on the post anyway. Are you using old usenet news reader or something? Graham From prasoonthegreat at gmail.com Fri Jun 12 02:48:01 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:48:01 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <2dbcf0eb-39fa-4492-ab70-6f219f3610c9@w9g2000pro.googlegroups.com> On Jun 12, 11:28?am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python.... > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ..... > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > > ? i,res =2,n > > ? while(i*i<=n): > > ? ? ?if(n%i==0): > > ? ? ? ? ? ?res-=res/i > > ? ? ?while(n%i==0): > > ? ? ? ? ? ?n/=i > > ? ? ?i+=1 > > ? if(n>1): > > ? ? ? ?res-=res/n > > ? return res > > > def main(): > > ?t=input() > > ?while(t): > > ? ?x=input() > > ? ?print str(etf(x)) > > ? ?t-=1 > > > if __name__ == "__main__": > > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > > button instead of getting the cursor moved to the next line.....I get > > an error > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > How should ?the code be modified so that even after ?pressing an extra > > "Enter" button the cursor get moved to the next line instead to > > throwing an exception...... > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > input() does an implicit eval() of the keyboard input, which is (in > part) causing your problem. > Note that you'll need to explicitly convert the string raw_input() > reads in using either int() or float() as appropriate. > > Still, you can't just enter extra lines and expect the program to > automatically ignore them. You'll have to write the extra code > yourself to handle empty input from the user. > > Cheers, > Chris > --http://blog.rebertia.com I am using Python 2.6 I have modified that code def main(): t=int(raw_input()) while(t): x=input() print str(etf(x)) t-=1 what should i do to handle new line and space...... We used to get spaces and newline in C using their ASCII values ...can similar things be done here??? Please write the code snippet(by modifying my code) from which i can understand something......!!!!! From prasoonthegreat at gmail.com Fri Jun 12 02:49:25 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:49:25 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> On Jun 12, 11:28?am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python.... > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ..... > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > > ? i,res =2,n > > ? while(i*i<=n): > > ? ? ?if(n%i==0): > > ? ? ? ? ? ?res-=res/i > > ? ? ?while(n%i==0): > > ? ? ? ? ? ?n/=i > > ? ? ?i+=1 > > ? if(n>1): > > ? ? ? ?res-=res/n > > ? return res > > > def main(): > > ?t=input() > > ?while(t): > > ? ?x=input() > > ? ?print str(etf(x)) > > ? ?t-=1 > > > if __name__ == "__main__": > > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > > button instead of getting the cursor moved to the next line.....I get > > an error > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > How should ?the code be modified so that even after ?pressing an extra > > "Enter" button the cursor get moved to the next line instead to > > throwing an exception...... > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > input() does an implicit eval() of the keyboard input, which is (in > part) causing your problem. > Note that you'll need to explicitly convert the string raw_input() > reads in using either int() or float() as appropriate. > > Still, you can't just enter extra lines and expect the program to > automatically ignore them. You'll have to write the extra code > yourself to handle empty input from the user. > > Cheers, > Chris > --http://blog.rebertia.com I am using Python 2.6 I have modified that code def main(): t=int(raw_input()) while(t): x=int(raw_input()) print str(etf(x)) t-=1 what should i do to handle new line and space...... We used to get spaces and newline in C using their ASCII values ...can similar things be done here??? Please write the code snippet(by modifying my code) from which i can understand something......!!!!! From lepto.python at gmail.com Fri Jun 12 03:07:44 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 12 Jun 2009 15:07:44 +0800 Subject: ANN: WHIFF += Flash chart widget support (Aaron Watters) Message-ID: <6a4f17690906120007t9b886efp64cc54a82044d2e7@mail.gmail.com> nice the only pity is that amcharts is not a money-free product From mail at timgolden.me.uk Fri Jun 12 03:24:26 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Jun 2009 08:24:26 +0100 Subject: command line of a process.exe on another host In-Reply-To: References: Message-ID: <4A3202AA.1010305@timgolden.me.uk> Harry wrote: > HI , > I have number of process run on different windows servers which run's > with different command line parameters. for example "process.exe > -input statusurl: http://sss.com "., These parameters can vary from > host to host. using Psexec I know the PID and process name which are > running on these machines, but how I can read the command line > parameters of these process. Is there a way to read these command line > of the proess via python pls? WMI can get this for you. This example uses my WMI module from here: http://timgolden.me.uk/python/wmi.html but it's not hard to do it with "raw" Python / Windows. import wmi c = wmi.WMI ("other_machine") for p in c.Win32_Process (name="process.exe"): print p.CommandLine TJG From Eric_Dexter at msn.com Fri Jun 12 03:27:47 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 12 Jun 2009 00:27:47 -0700 (PDT) Subject: install older Python version parallel References: Message-ID: On Jun 11, 8:50?am, "S. Dornseifer" wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon 0n windows I had multiple versions installed ex python24 python25 i would write a batch file C:\python24\python.exe test.py pause the pause is there just so that I can see an error message if there is one. I have no idea what would work for the mac or linux though... I suspect something simular might work after all why rewrite all your software because someone else wants you to have a particular version of python not with the amount of disk space that is available now-adays.. From Eric_Dexter at msn.com Fri Jun 12 03:30:14 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 12 Jun 2009 00:30:14 -0700 (PDT) Subject: install older Python version parallel References: Message-ID: On Jun 11, 8:50?am, "S. Dornseifer" wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon I suspect you want to install python 2.4 and then reinstall 2.6 I did that in windows and I don't understand why it wouldn't work in linux From lepto.python at gmail.com Fri Jun 12 03:35:19 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 12 Jun 2009 15:35:19 +0800 Subject: RE replace problem too Message-ID: <6a4f17690906120035u9f0aa6ag3631b84dc9e687e6@mail.gmail.com> in my case, I want to replace all the function name with '', that is sin(1) -> (1) sin(pi*(2+4)) -> (pi*(2+4)) how can I use RE in this situation? thanx From bieffe62 at gmail.com Fri Jun 12 03:56:04 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Fri, 12 Jun 2009 00:56:04 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: On 12 Giu, 08:49, Prasoon wrote: > On Jun 12, 11:28?am, Chris Rebert wrote: > > > > > > > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > > I am new to python.... > > > I have written the following program in python.It is the solution of > > > problem ETF in SPOJ..... > > > > #Euler Totient Function > > > > from math import sqrt > > > def etf(n): > > > ? i,res =2,n > > > ? while(i*i<=n): > > > ? ? ?if(n%i==0): > > > ? ? ? ? ? ?res-=res/i > > > ? ? ?while(n%i==0): > > > ? ? ? ? ? ?n/=i > > > ? ? ?i+=1 > > > ? if(n>1): > > > ? ? ? ?res-=res/n > > > ? return res > > > > def main(): > > > ?t=input() > > > ?while(t): > > > ? ?x=input() > > > ? ?print str(etf(x)) > > > ? ?t-=1 > > > > if __name__ == "__main__": > > > ?main() > > > > The problem with my code is that whenever I press an extra "Enter" > > > button instead of getting the cursor moved to the next line.....I get > > > an error > > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > > How should ?the code be modified so that even after ?pressing an extra > > > "Enter" button the cursor get moved to the next line instead to > > > throwing an exception...... > > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > > input() does an implicit eval() of the keyboard input, which is (in > > part) causing your problem. > > Note that you'll need to explicitly convert the string raw_input() > > reads in using either int() or float() as appropriate. > > > Still, you can't just enter extra lines and expect the program to > > automatically ignore them. You'll have to write the extra code > > yourself to handle empty input from the user. > > > Cheers, > > Chris > > --http://blog.rebertia.com > > I am using Python 2.6 > I have modified that code > def main(): > ? t=int(raw_input()) > ? while(t): > ? ? x=int(raw_input()) > ? ? print str(etf(x)) > ? ? t-=1 > > what should i do to handle new line and space...... > We used to get spaces and newline in C using their ASCII values ...can > similar things be done here??? > > Please write the code snippet(by modifying my code) from which i can > understand something......!!!!! > > - Mostra testo citato - You could do: while True: x = raw_input("Enter x=>") if x != "" : break # if you just press enter, raw_input returns an empty string Note that this still leaves out the case when you type something which is not a number. To cover this case, supposing that you need a float, you could do like this (NOT TESTED): while True: x_str = raw_input("Enter x=>") if x_str != "" : # to prevent having the error message on empty imput try: x = float(x_str) break # if it gets here the conversion in float was succesful except ValueError : print "The input '%s' cannot be converted in float" % x_str This code exits from the loop only when you supply a string that represents a floating number Ciao ----- FB From usernet at ilthio.net Fri Jun 12 04:01:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 12 Jun 2009 08:01:44 GMT Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> <602fb38b-abdf-498a-8b3b-99eeb1f388ac@s38g2000prg.googlegroups.com> Message-ID: On 2009-06-12, lynvie wrote: > Thanks for the additional info! I had no idea this was an old Windows > problem... I'm using Windows XP and I'm up-to-date on all my patches. s/problem/feature/ Steve Ballmer, CEO of Microsoft, would prefer that you think of it as a 'feature'. This is a problem that I would suspect has plagued a lot of people because it doesn't seem to be overly documented in any of the popular python learning materials. Even Mark Hammond & Andy Robinson's book _Python Programming on Win32_ doesn't mention the problem directly in its Windowes gotchas section-- though it does mention there are a number of bugs in the Windows implementation of popen(). > The good news is I can invoke the script correctly now, thanks to your > help! Happy Pythoning! From vlastimil.brom at gmail.com Fri Jun 12 04:36:30 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 12 Jun 2009 10:36:30 +0200 Subject: Need help in Python regular expression In-Reply-To: References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: <9fdb569a0906120136o6802769fg6a9c04493904fe1b@mail.gmail.com> 2009/6/12 meryl : > On Jun 11, 9:41?pm, "Mark Tolonen" wrote: >> "meryl" wrote in message >> >> > I have this regular expression >... > I try adding ".*" at the end , but it ends up just matching the second > one. If there can be more matches in a line, maybe the non-greedy quantifier ".*?", and a lookahead assertion can help. You can try something like: (?m)Render(?:Block|Table) (?:\(\w+\)|{\w+})(.+?(?=$|RenderBlock))? (?m) multiline flag - also the end of line can be matched with $ .+? any character - one or more (no greedy, i.e. as little as possible) (?=$|RenderBlock) the lookahead assertion - condition for the following string - not part of the match - here the end of line/string or "RenderBlock" I guess, if you need to add more possibilities or conditions depending on your source data, it might get too complex for a single regular expression to match effectively. hth vbr From higerinbeijing at gmail.com Fri Jun 12 04:55:48 2009 From: higerinbeijing at gmail.com (higer) Date: Fri, 12 Jun 2009 01:55:48 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP Message-ID: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Maybe everyone know that decompyle(hosted on SourceForge.net) is a tool to transfer a .pyc file to .py file and now it does only support Python 2.3 or the below. I have found a project named unpyc which can support Python version 2.5. Unpyc project is build on decompyle which is hosted on google code and if you want you can download it. I build unpyc on Ubuntu successfully and can run it ok. But with some purpose, I just want to use this tool on my WindowsXP, so I tried to build it. I have tried many times and methods, with .net2003 or MingGW, but I failed. So,I come here looking for sombody can help me.I will give the showing error message with different method on the following: 1 Using command : python setup.py install F:\unpyc>python setup.py install running install running build running build_py creating build\lib.win32-2.5 creating build\lib.win32-2.5\unpyc copying unpyc\dis_15.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_16.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_20.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_21.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_22.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_23.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_24.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_25.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_26.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_files.py -> build\lib.win32-2.5\unpyc copying unpyc\magics.py -> build\lib.win32-2.5\unpyc copying unpyc\marshal_files.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_23.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_24.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_25.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_26.py -> build\lib.win32-2.5\unpyc copying unpyc\Parser.py -> build\lib.win32-2.5\unpyc copying unpyc\Scanner.py -> build\lib.win32-2.5\unpyc copying unpyc\spark.py -> build\lib.win32-2.5\unpyc copying unpyc\verify.py -> build\lib.win32-2.5\unpyc copying unpyc\Walker.py -> build\lib.win32-2.5\unpyc copying unpyc\__init__.py -> build\lib.win32-2.5\unpyc running build_ext building 'unpyc/marshal_25' extension creating build\temp.win32-2.5 creating build\temp.win32-2.5\Release creating build\temp.win32-2.5\Release\unpyc f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / nologo /Ox /MD /W3 /GX /DNDEBU G -IF:\Python25\include -IF:\Python25\PC /Tcunpyc/marshal_25.c /Fobuild \temp.win32-2.5\Release\unpyc /marshal_25.obj marshal_25.c unpyc\marshal_25.c(401) : warning C4273: 'PyMarshal_WriteLongToFile' : inconsistent dll linkage unpyc\marshal_25.c(413) : warning C4273: 'PyMarshal_WriteObjectToFile' : inconsistent dll linkage unpyc\marshal_25.c(1004) : warning C4273: 'PyMarshal_ReadShortFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1015) : warning C4273: 'PyMarshal_ReadLongFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1044) : warning C4273: 'PyMarshal_ReadLastObjectFromFile' : inconsistent dll link age unpyc\marshal_25.c(1087) : warning C4273: 'PyMarshal_ReadObjectFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1101) : warning C4273: 'PyMarshal_ReadObjectFromString' : inconsistent dll linkag e unpyc\marshal_25.c(1116) : warning C4273: 'PyMarshal_WriteObjectToString' : inconsistent dll linkage f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe / DLL /nologo /INCREMENTAL:NO /LI BPATH:F:\Python25\libs /LIBPATH:F:\Python25\PCBuild /EXPORT:initunpyc/ marshal_25 build\temp.win32-2. 5\Release\unpyc/marshal_25.obj /OUT:build\lib.win32-2.5\unpyc/ marshal_25.pyd /IMPLIB:build\temp.win3 2-2.5\Release\unpyc\marshal_25.lib marshal_25.obj : error LNK2001: unresolved external symbol initunpyc/ marshal_25 build\temp.win32-2.5\Release\unpyc\marshal_25.lib : fatal error LNK1120: 1 unresolved externals LINK : fatal error LNK1141: failure during build of exports file error: command '"f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe"' failed with e xit status 1141 2 Using command: python setup.py build -c mingw32 F:\unpyc>python setup.py build -c mingw32 running build running build_py running build_ext building 'unpyc/marshal_25' extension F:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IF:\Python25\include - IF:\Python25\PC -c unpyc/mars hal_25.c -o build\temp.win32-2.5\Release\unpyc\marshal_25.o unpyc/marshal_25.c:1087: warning: 'PyMarshal_ReadObjectFromFile' defined locally after being referen ced with dllimport linkage unpyc/marshal_25.c:1101: warning: 'PyMarshal_ReadObjectFromString' defined locally after being refer enced with dllimport linkage writing build\temp.win32-2.5\Release\unpyc\marshal_25.def F:\mingw\bin\gcc.exe -mno-cygwin -shared -s build \temp.win32-2.5\Release\unpyc\marshal_25.o build\te mp.win32-2.5\Release\unpyc\marshal_25.def -LF:\Python25\libs -LF: \Python25\PCBuild -lpython25 -lmsvc r71 -o build\lib.win32-2.5\unpyc/marshal_25.pyd F:\Python25\libs/libpython25.a(dcbbs00336.o):(.text+0x0): multiple definition of `PyMarshal_ReadObje ctFromString' build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text +0x2958): first defined here F:\Python25\libs/libpython25.a(dcbbs00335.o):(.text+0x0): multiple definition of `PyMarshal_ReadObje ctFromFile' build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text +0x28fb): first defined here Cannot export initunpyc/marshal_25: symbol not defined collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 PS: necessary files has been added in proper path: Python25.dll is in windows/system32; python25.lib and libpython25.a is in Python25/libs; Appreciate that you can do me a favor.Thanks From prasoonthegreat at gmail.com Fri Jun 12 04:58:34 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Fri, 12 Jun 2009 01:58:34 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: > You could do: > > while True: > ? ?x = raw_input("Enter x=>") > ? ?if x != "" : break # if you just press enter, raw_input returns an > empty string > > Note that this still leaves out the case when you type something which > is not a number. > To cover this case, supposing that you need a float, you could do like > this (NOT TESTED): > > while True: > ? ?x_str = raw_input("Enter x=>") > ? ?if x_str != "" : # ?to prevent having the error message on empty > imput > ? ? ? try: > ? ? ? ? ?x = float(x_str) > ? ? ? ? ?break # if it gets here the conversion in float was succesful > ? ? ? except ValueError : > ? ? ? ? ?print "The input '%s' cannot be converted in float" % x_str > > This code exits from the loop only when you supply a string that > represents a floating number > I modified my code to #Euler Totient Function import sys from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): while True: t=raw_input() if t!="":break t=int(t) while(t): while True: x=raw_input() if x!="":break x=int(x) print str(etf(x)) t-=1 if __name__ == "__main__": main() Now it is working fine ....thanks!!! From steve at REMOVETHIS.cybersource.com.au Fri Jun 12 05:07:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 12 Jun 2009 19:07:19 +1000 Subject: Exception inside loop wrongly failing doctest Message-ID: <02420d02$0$20639$c3e8da3@news.astraweb.com> One of my doctests is failing, and I suspect a bug. The test involves matching an exception in a for-loop. Here are two simplified versions of the test, both should pass but only the first does. As a doctest, this passes: >>> for x in [3, 2, 1]: ... print (x, 1.0/x) ... (3, 0.33333333333333331) (2, 0.5) (1, 1.0) However, this fails: >>> for x in [3, 2, 1, 0]: ... print (x, 1.0/x) ... (3, 0.33333333333333331) (2, 0.5) (1, 1.0) Traceback (most recent call last): ... ZeroDivisionError: float division Attached is a simple test script which runs doctest.testmod(). Both tests should pass, with no output printing. However, it does this: $ python doctest_error.py ********************************************************************** File "doctest_error.py", line 14, in __main__ Failed example: for x in [3, 2, 1, 0]: print (x, 1.0/x) Exception raised: Traceback (most recent call last): File "/usr/lib/python2.5/doctest.py", line 1212, in __run compileflags, 1) in test.globs File "", line 2, in print (x, 1.0/x) ZeroDivisionError: float division ********************************************************************** 1 items had failures: 1 of 2 in __main__ ***Test Failed*** 1 failures. I've tested this in Python 2.4, 2.5 and 2.6 and get the same result for all three. Have I missed something, or should I report this as a bug? -- Steven -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: doctest_error.py URL: From lie.1296 at gmail.com Fri Jun 12 05:13:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 09:13:50 GMT Subject: Exception inside loop wrongly failing doctest In-Reply-To: <02420d02$0$20639$c3e8da3@news.astraweb.com> References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > One of my doctests is failing, and I suspect a bug. > > The test involves matching an exception in a for-loop. Here are two > simplified versions of the test, both should pass but only the first does. > tell me, what's the result of 1/0? From lie.1296 at gmail.com Fri Jun 12 05:45:11 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 09:45:11 GMT Subject: Exception inside loop wrongly failing doctest In-Reply-To: References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: Lie Ryan wrote: > Steven D'Aprano wrote: >> One of my doctests is failing, and I suspect a bug. >> >> The test involves matching an exception in a for-loop. Here are two >> simplified versions of the test, both should pass but only the first does. >> > > tell me, what's the result of 1/0? Whooopss.. replied too fast... This seems to work: >>> for i in [3, 2, 1, 0]: ... print (i, 1.0/i) ... Traceback (most recent call last): ... ZeroDivisionError: float division it seems that if the expected result is a traceback, the doc result must starts with the traceback keyword: """ The expected output for an exception must *start* with a traceback header, which may be either of the following two lines, indented the same as the first line of the example: Traceback (most recent call last): Traceback (innermost last): """ (emphasizes added) From Simon212 at gmx.de Fri Jun 12 05:54:55 2009 From: Simon212 at gmx.de (Simon212 at gmx.de) Date: Fri, 12 Jun 2009 11:54:55 +0200 Subject: install older Python version parallel In-Reply-To: References: <4A31199E.7030809@gmx.net> Message-ID: <20090612095455.20140@gmx.net> > > Hi everybody, > > > > The situation: > > I wrote a GUI, based on Python, TkInter and Pmw. > > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > > and various Linux Distributions. > > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > > > in the installed blt package), also when I use setitems on > > Pmw.OptionMenu (I guess this is due to another package, associated with > > tcl/tk). > > You might get more helpful responses if you say more than just "it > crashes". > What's the traceback? > Thanks for the suggestion. 1. Here is what it says when I try to use setitems on a Pmw.OptionMenu to refresh its contents: com.read_config_file ./.mWIN/profiles/last.profile Traceback (most recent call last): File "./startMW.py", line 1323, in frontEnd = FrontEnd(root) File "./startMW.py", line 854, in __init__ self.loadProfile() File "./startMW.py", line 1216, in loadProfile self.profileList.setitems(self.com.profile_names) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Pmw/Pmw_1_3/lib/PmwOptionMenu.py", line 67, in setitems self._menu.delete(0, 'end') File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 2675, in delete self.deletecommand(c) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 358, in deletecommand self.tk.deletecommand(name) _tkinter.TclError: can't delete Tcl command 2. In case of the activation of a Pmw.Diaog it just gives me a segmentation vault. -- GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und Telefonanschluss f?r nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02 From vs at it.uu.se Fri Jun 12 05:55:14 2009 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 12 Jun 2009 11:55:14 +0200 Subject: matplotlib installation Message-ID: <4A322602.7090302@it.uu.se> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows Vista platform? --V From steve at REMOVETHIS.cybersource.com.au Fri Jun 12 06:45:41 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 12 Jun 2009 20:45:41 +1000 Subject: Exception inside loop wrongly failing doctest References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: <0242240f$0$21875$c3e8da3@news.astraweb.com> Lie Ryan wrote: > Lie Ryan wrote: >> Steven D'Aprano wrote: >>> One of my doctests is failing, and I suspect a bug. ... > it seems that if the expected result is a traceback, the doc result must > starts with the traceback keyword: Ah, that would be it. Not a bug then, a limitation of the doctest module. Thanks, -- Steven From gnewsg at gmail.com Fri Jun 12 06:47:53 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 12 Jun 2009 03:47:53 -0700 (PDT) Subject: command line of a process.exe on another host References: Message-ID: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> On 12 Giu, 00:18, "Harry" wrote: > HI , > I have number of process run on different windows servers which run's with > different command line parameters. for example "process.exe -input > statusurl:http://sss.com"., These parameters can vary from host to host. > using Psexec I know the PID and process name which are running on these > machines, but how I can read the command line parameters of these process. > Is there a way to read these command line of the proess via python pls? > > any feedback appreciated.. > > thanks > Hari You can easily do this with psutil [1]: >>> import psutil, os >>> p = psutil.Process(os.getpid()) >>> p.cmdline ['/usr/bin/python2.4'] >>> Since psutil uses the native Windows calls to retrieve such kind of info it's a lot faster than using any WMI-based solution. [1] http://code.google.com/p/psutil/ --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From mail at timgolden.me.uk Fri Jun 12 07:02:52 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Jun 2009 12:02:52 +0100 Subject: command line of a process.exe on another host In-Reply-To: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> References: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> Message-ID: <4A3235DC.2070504@timgolden.me.uk> Giampaolo Rodola' wrote: > On 12 Giu, 00:18, "Harry" wrote: >> HI , >> I have number of process run on different windows servers which run's with >> different command line parameters. > You can easily do this with psutil [1]: > Since psutil uses the native Windows calls to retrieve such kind of > info it's a lot faster than using any WMI-based solution. Looks great (and it's certainly fast). Can you pick up processes on a different server? The docs don't seem to say so. Did I miss something? (It's not clear that the OP actually wants that altho' I read it that way). TJG From alan.isaac at gmail.com Fri Jun 12 07:33:36 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 12 Jun 2009 11:33:36 GMT Subject: matplotlib installation In-Reply-To: References: Message-ID: On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: > Any suggestions on installing matplotlib for Python 2.6.2 on a Windows > Vista platform? Maintainers for some packages have run into a wall compiling for 2.6. Matplotlib is one of these: http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html Another package I care about is SimpleParse, which also found compiling for 2.6 to be impossible. I do not know if this was the same problem or not, but it means that SimpleParse is *still* not available as an installer for 2.6. I assume this is of great concern to the Python community, but I do not know where the discussion is taking place. Alan Isaac From khemeia at gmail.com Fri Jun 12 07:51:42 2009 From: khemeia at gmail.com (khemeia at gmail.com) Date: Fri, 12 Jun 2009 04:51:42 -0700 (PDT) Subject: trying to understand dictionaries Message-ID: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Hi. As the subject says, I'm a newbie trying to learn python and now dictionaries. I can create a dict, understand it and use it for simple tasks. But the thing is that I don't really get the point on how to use these in real life programing. For example I tryed to create a very simple phonebook code: d = {'fname': [], 'ename': []} name1 = 'ricky' name2 = 'martin' d['fname'].append(name1) d['ename'].append(name2) name1 = 'britney' name2 = 'spears' d['fname'].append(name1) d['ename'].append(name2) This gives me: {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} I wonder if this is a correct usage and thinking about dictioaries in python. Everything in my example is based on a serval lists in a dictionary, and person 1 is == ename[0] & fname[0] and person 2 is == ename[1] & fname[1], it's based on position and indexing. Is this correct if no, how would you do it? if yes, how can I print the result out in a nice way? I need a for- loop that prints: all [0] in all lists all [0] in all lists and so on. thanks /jonas From anthra.norell at bluewin.ch Fri Jun 12 07:56:38 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 12 Jun 2009 13:56:38 +0200 Subject: CAD file format specifications? Message-ID: <4A324276.80804@bluewin.ch> Hi, Anyone working with CAD who knows about numeric data entry? I have 3d coordinates of a construction site on a slope (borders, setbacks and isometric elevation lines). Someone made me aware of Google's Sketch Up. It looks very attractive for the purpose of architectural planning, especially suited to create visual impressions. Doodling seems easy. But I have to start with modeling the terrain and the envelope and the only way to do that seems to be in one of several CAD file formats (skp, dwg, dxf, 3ds, ddf and dem). So I need to cast my numbers into one of these formats. Any suggestions? Thanks Frederic From jeanmichel at sequans.com Fri Jun 12 08:01:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:01:14 +0200 Subject: Need help in Python regular expression In-Reply-To: <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> Message-ID: <4A32438A.5070003@sequans.com> To the OP, I suggest if you haven't yet Kodos, to get it here http://kodos.sourceforge.net/. It's a python regexp debugger, a lifetime saver. Jean-Michel John S wrote: > On Jun 11, 10:30 pm, meryl wrote: > >> Hi, >> >> I have this regular expression >> blockRE = re.compile(".*RenderBlock {\w+}") >> >> it works if my source is "RenderBlock {CENTER}". >> >> But I want it to work with >> 1. RenderTable {TABLE} >> >> So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), >> but that breaks everything >> >> 2. RenderBlock (CENTER) >> >> So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), >> that also breaks everything >> >> Can you please tell me how to change my reg exp so that I can support >> all 3 cases: >> RenderTable {TABLE} >> RenderBlock (CENTER) >> RenderBlock {CENTER} >> >> Thank you. >> > > Short answer: > > r = re.compile(r"Render(?:Block|Table)\s+[({](?:TABLE|CENTER)[})]") > > s = """ > blah blah blah > blah blah blah RenderBlock {CENTER} blah blah RenderBlock {CENTER} > blah blah blah RenderTable {TABLE} blah blah RenderBlock (CENTER) > blah blah blah > """ > > print r.findall(s) > > > > output: > ['RenderBlock {CENTER}', 'RenderBlock {CENTER}', 'RenderTable > {TABLE}', 'RenderBlock (CENTER)'] > > > > Note that [] only encloses characters, not strings; [foo|bar] matches > 'f','o','|','b','a', or 'r', not "foo" or "bar". > Use (foo|bar) to match "foo" or "bar"; (?xxx) matches xxx without > making a backreference (i.e., without capturing text). > > HTH > > -- John Strickler > From jeanmichel at sequans.com Fri Jun 12 08:25:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:25:37 +0200 Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: <4A324941.4010408@sequans.com> Basically, dictionaries are a bunch of couples of key and value where key is an immutable object. In fact you'll find a more accurate definition in any python book or online tutorial. The thing is that keys are usually used as an easy and quick way the search and index items. You can see dict as a list that can use strings instead of integers to index its values. phonebook = { 'ricky' : ('ricky', 'martin', 'male'), 'britney' : ('britney', 'spears', 'female'), 'myBestBuddy' : ('barack', 'obama', 'male'), 42 : ('bob', 'bib', 'male'), # you can use 42 as index, like strings integers are not mutable True: ('', '', ''), # meaningless example just to show that any immutable object will fit as index } fname, ename, gender = phonebook['myBestBuddy'] fname, ename, gender = phonebook[42] Keys are unique among the dictionary. Jean-Michel khemeia at gmail.com wrote: > Hi. > As the subject says, I'm a newbie trying to learn python and now > dictionaries. I can create a dict, understand it and use it for simple > tasks. But the thing is that I don't really get the point on how to > use these in real life programing. > > For example I tryed to create a very simple phonebook > > code: > > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} > > I wonder if this is a correct usage and thinking about dictioaries in > python. > Everything in my example is based on a serval lists in a dictionary, > and person 1 is == ename[0] & fname[0] > and person 2 is == ename[1] & fname[1], it's based on position and > indexing. > > Is this correct if no, how would you do it? > if yes, how can I print the result out in a nice way? I need a for- > loop that prints: > all [0] in all lists > all [0] in all lists and so on. > > > thanks > /jonas > > From alan.isaac at gmail.com Fri Jun 12 08:32:57 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 12 Jun 2009 12:32:57 GMT Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: On 6/12/2009 7:51 AM khemeia at gmail.com apparently wrote: > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} Trying to stick close to your example, reverse the use of lists and dicts. worst_musicians = list() entry = dict(fname='ricky',lname='martin') worst_musicians.append(entry) entry = dict(fname='britney',lname='spears') worst_musicians.append(entry) for musician in worst_musicians: print "%(fname)s %(lname)s"%musician hth, Alan Isaac From marduk at letterboxes.org Fri Jun 12 08:34:57 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 12 Jun 2009 08:34:57 -0400 Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: <1244810097.10675.7.camel@blackwidow.nbk> On Fri, 2009-06-12 at 04:51 -0700, khemeia at gmail.com wrote: > Hi. > As the subject says, I'm a newbie trying to learn python and now > dictionaries. I can create a dict, understand it and use it for simple > tasks. But the thing is that I don't really get the point on how to > use these in real life programing. > > For example I tryed to create a very simple phonebook > > code: > > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} > > I wonder if this is a correct usage and thinking about dictioaries in > python. > Everything in my example is based on a serval lists in a dictionary, > and person 1 is == ename[0] & fname[0] > and person 2 is == ename[1] & fname[1], it's based on position and > indexing. > > Is this correct if no, how would you do it? > if yes, how can I print the result out in a nice way? I need a for- > loop that prints: > all [0] in all lists > all [0] in all lists and so on. That's probably not the data model I'd use for a phone book. The following isn't either, but is better: d = dict() d[('martin', 'ricky')] = '555-1212' d[('spears', 'britney')] = '555-1213' for last, first in d: phone_number = d[(last, first)] print ... From mblume at socha.net Fri Jun 12 08:36:47 2009 From: mblume at socha.net (mblume) Date: 12 Jun 2009 12:36:47 GMT Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <4a324bdf$0$9117$5402220f@news.sunrise.ch> Am Thu, 11 Jun 2009 20:56:24 -0700 schrieb lucius: > I am trying to > print some values to a file (using c's printf like method). TypeError: > int argument required > # this works, i see value on screen > print w, h, absX, absY > Are you sure that w or h are not returned as strings? Hint: try this in an interpreter: w="100" print "%d" % (w) > > # this fails, I get "TypeError: int argument required" > print >> fo, " style=\"fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke- > opacity:0.9\"/> " % (absX, absY, w, h) > You could simplify such as an expression by writing: print 'x="%f"' % (x) HTH Martin From jeanmichel at sequans.com Fri Jun 12 08:39:04 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:39:04 +0200 Subject: EOF problem with ENTER In-Reply-To: References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: <4A324C68.1010905@sequans.com> Prasoon wrote: > I modified my code to > > #Euler Totient Function > import sys > from math import sqrt > def etf(n): > i,res =2,n > while(i*i<=n): > if(n%i==0): > res-=res/i > while(n%i==0): > n/=i > i+=1 > if(n>1): > res-=res/n > return res > > def main(): > while True: > t=raw_input() > if t!="":break > t=int(t) > while(t): > while True: > x=raw_input() > if x!="":break > x=int(x) > print str(etf(x)) > t-=1 > > if __name__ == "__main__": > main() > > Now it is working fine ....thanks!!! > Hello Prasoon, there's still a major issue with your code, check out http://tottinge.blogsome.com/meaningfulnames/ If your code is a private script targeted at your personal use, well I guess you can just ignore my comment. But I'm still impressed by how some of the python-list users have dived into your code with such ease. Regards, Jean-Michel From exarkun at divmod.com Fri Jun 12 08:50:21 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 12 Jun 2009 08:50:21 -0400 Subject: matplotlib installation In-Reply-To: Message-ID: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >> Vista platform? > > >Maintainers for some packages have run into a wall >compiling for 2.6. Matplotlib is one of these: >http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html > >Another package I care about is SimpleParse, which also >found compiling for 2.6 to be impossible. I do not know >if this was the same problem or not, but it means that >SimpleParse is *still* not available as an installer for 2.6. > >I assume this is of great concern to the Python community, >but I do not know where the discussion is taking place. Some discussion has occurred in the issue tracker: http://bugs.python.org/issue3308 http://bugs.python.org/issue6007 In general, the people responsible for how CPython builds on Windows don't seem to consider this an issue. Jean-Paul From lie.1296 at gmail.com Fri Jun 12 09:02:03 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 13:02:03 GMT Subject: RE replace problem too In-Reply-To: References: Message-ID: oyster wrote: > in my case, I want to replace all the function name with '', that is > sin(1) -> (1) > sin(pi*(2+4)) -> (pi*(2+4)) > how can I use RE in this situation? thanx this works if there is no implicit multiplication: re.sub('\w+\(', '(', 'sin(pi*(2+4))') this one might be more robust: re.sub('[a-zA-Z]\w*\s*\(', '(', 'sin(pi*cos(2+4))') From gnewsg at gmail.com Fri Jun 12 09:03:53 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 12 Jun 2009 06:03:53 -0700 (PDT) Subject: command line of a process.exe on another host References: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> Message-ID: On 12 Giu, 13:02, Tim Golden wrote: > Giampaolo Rodola' wrote: > > On 12 Giu, 00:18, "Harry" wrote: > >> HI , > >> I have number of process run on different windows servers which run's with > >> different command line parameters. > > You can easily do this with psutil [1]: > > Since psutil uses the native Windows calls to retrieve such kind of > > info it's a lot faster than using any WMI-based solution. > > Looks great (and it's certainly fast). Can you pick up processes > on a different server? The docs don't seem to say so. Did I miss > something? (It's not clear that the OP actually wants that altho' > I read it that way). > > TJG Sorry, I didn't notice the OP meant to retrieve information from a remote machine. And no, psutil can't do anything like that. --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From simon212 at gmx.de Fri Jun 12 09:31:14 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 15:31:14 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: Message-ID: <4A3258A2.1040204@gmx.de> edexter wrote: > simon wrote: >> Hi everybody, >> >> The situation: >> I wrote a GUI, based on Python, TkInter and Pmw. >> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >> and various Linux Distributions. >> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >> in the installed blt package), also when I use setitems on >> Pmw.OptionMenu (I guess this is due to another package, associated with >> tcl/tk). >> >> The target: >> I have to get my GUI work under openSUSE 11.1 (x86_64). >> >> My plan: >> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >> I would like to know, how to install Python 2.4 along with TkInter and >> Pmw (and packages that are required by them), parallel to the existing >> Python 2.6. So that I do not break other software that depends on Python >> 2.6. >> >> If you can think of another plan, I would be also glad to discuss it. >> >> Cheers, >> Simon > > I suspect you want to install python 2.4 and then reinstall 2.6 I did > that in windows and I don't understand why it wouldn't work in linux I'm afraid, installation is quit different under UNIX based systems and Windows. I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within openSUSE 11.1 x86_64) via 'make altinstall'. First, I tried to configure with the following flags: --prefix=/opt/python-24 --enable-framework --with-pydebug This provoked an error during compilation via make (sorry, the list was so long, but I will post it, if it helps). Second, configured again without any flags. The installation by 'make altinstall' to /usr/local was a success. Python2.6 seams unaffected, too. So, I got my parallel installation. However, I cannot import modules like Tkinter or readline within python2.4. For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk sys.path says: ['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages'] sys.prefix and sys.exec_prefix say: '/usr/local' my bash's PATH variable says: /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin Which configuration step did I miss after my Python2.4 installation? What did I do wrong? Cheers, Simon From tim.wintle at teamrubber.com Fri Jun 12 09:32:03 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Jun 2009 14:32:03 +0100 Subject: command line of a process.exe on another host In-Reply-To: References: Message-ID: <1244813523.3718.153.camel@tim-laptop> On Thu, 2009-06-11 at 23:18 +0100, Harry wrote: > HI , > I have number of process run on different windows servers which run's with > different command line parameters. for example "process.exe -input > statusurl: http://sss.com "., These parameters can vary from host to host. > using Psexec I know the PID and process name which are running on these > machines, but how I can read the command line parameters of these process. > Is there a way to read these command line of the proess via python pls? I'm not sure how well this will work, but it might be worth looking at fabric - which lets you run through ssh onto lots of different machines (so I assume you'll need openssh on those machines) http://docs.fabfile.org/ Haven't used it myself, but I keep meaning to. > > any feedback appreciated.. > > thanks > Hari > From tim.wintle at teamrubber.com Fri Jun 12 09:40:52 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Jun 2009 14:40:52 +0100 Subject: install older Python version parallel In-Reply-To: References: Message-ID: <1244814052.3718.158.camel@tim-laptop> On Fri, 2009-06-12 at 00:30 -0700, edexter wrote: > I suspect you want to install python 2.4 and then reinstall 2.6 I did > that in windows and I don't understand why it wouldn't work in linux It won't normally work on linux these days because most distributions of gnu/linux need python to run the GUI. Put another way it means if something doesn't work how you want it, it's just some python somewhere to change :-) (Trust me, you don't want to remove the system version of python on most linux distributions or on macs) Tim From cournape at gmail.com Fri Jun 12 09:54:14 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 12 Jun 2009 22:54:14 +0900 Subject: matplotlib installation In-Reply-To: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: <5b8d13220906120654t41e0f33alb80f690be3df12cb@mail.gmail.com> On Fri, Jun 12, 2009 at 9:50 PM, Jean-Paul Calderone wrote: > On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >> >> On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >>> >>> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >>> Vista platform? >> >> >> Maintainers for some packages have run into a wall >> compiling for 2.6. ?Matplotlib is one of these: >> >> http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html >> >> Another package I care about is SimpleParse, which also >> found compiling for 2.6 to be impossible. ?I do not know >> if this was the same problem or not, but it means that >> SimpleParse is *still* not available as an installer for 2.6. >> >> I assume this is of great concern to the Python community, >> but I do not know where the discussion is taking place. > > Some discussion has occurred in the issue tracker: > > ?http://bugs.python.org/issue3308 > ?http://bugs.python.org/issue6007 > > In general, the people responsible for how CPython builds on Windows > don't seem to consider this an issue. We got the same problem with numpy. The good news is it is solvable (at least partially). http://projects.scipy.org/numpy/browser/trunk/numpy/random/mtrand/randomkit.c Basically, there are some functions which are erroneously "declared" in the .lib, but they don't actually exist in the MS C runtime. We detect when the .C code is built under mingw, and add an hack to redirect the function to the "real" function, _ftime64 (see around line 75). cheers, David From aotto1968 at t-online.de Fri Jun 12 09:54:45 2009 From: aotto1968 at t-online.de (Andreas Otto) Date: Fri, 12 Jun 2009 15:54:45 +0200 Subject: ANNOUNCE: libmsgque 3.3 Message-ID: ANNOUNCE a majorfeature improvement of libmsgque ... What is LibMsgque ================= LibMsgque is an OS independent, Programming Language independent and Hardware independent solution to link applications together to act like a single application. Or with other words, LibMsgque is an Application-Server toolkit. Highlights of the current Release: ================================= This release introduce the C# port and the long waiting "managed" code interface to "libmsgque". This interface allow writing language-bindings to libmsgque without using an addition C library as "translator" between the native language and "libmsgque". The skip of this "translation" library introduce a new performance leader using C# together with the "mono" tools and outperform JAVA, TCL, PYTHON. On windows the "mono" tool and the "microsoft" native C# is supported. The performance-comparison between "c", "tcl", "python", "C#" and "java" was updated: -> results: http://libmsgque.sourceforge.net/performance.htm The Web-Site was updated: ========================= -> http://libmsgque.sourceforge.net For a fast introduction use the following URL: -> http://libmsgque.sourceforge.net/features.htm mfg Andreas Otto From paul.lafollette at gmail.com Fri Jun 12 10:05:29 2009 From: paul.lafollette at gmail.com (Paul LaFollette) Date: Fri, 12 Jun 2009 10:05:29 -0400 Subject: Question about None Message-ID: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Kind people, Using Python 3.0 on a Gatesware machine (XP). I am building a class in which I want to constrain the types that can be stored in various instance variables. For instance, I want to be certain that self.loc contains an int. This is straightforward (as long as I maintain the discipline of changing loc through a method rather than just twiddling it directly. def setLoc(lo): assert isinstance(lo, int), "loc must be an int" self.loc = lo does the trick nicely. However, I also want to constrain self.next to be either an instance of class Node, or None. I would think that the following should work but it doesn't. def setNext(nxt): assert isinstance(nxt, (Node, NoneType)), "next must be a Node" self.next = nxt since type(Node) responds with but the assertion above gives "name 'NoneType' is not defined" suggesting that NoneType is some sort of quasi-class. def setNext(nxt): assert nxt==None or isinstance(nxt, Node), "next must be a Node" self.next = nxt works ok, but it's uglier than it ought to be. So, I have three questions. 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? 2) is their a less ugly alternative that what I am using? 3) (this is purely philosophical but I am curious) Would it not be more intuitive if isinstance(None, ) returned true? Thank you for your kind attention. Paul From javier.collado at gmail.com Fri Jun 12 10:22:05 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Jun 2009 16:22:05 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Hello, This should work for you: In [1]: import types In [2]: isinstance(None, types.NoneType) Out[2]: True Best regards, Javier 2009/6/12 Paul LaFollette : > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. ?For instance, I want to be > certain that self.loc contains an int. ?This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > ?def setLoc(lo): > ? ?assert isinstance(lo, int), "loc must be an int" > ? ?self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. ?I would think that the following should work > but it doesn't. > > ?def setNext(nxt): > ? ?assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > ? ?self.next = nxt > > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. > > ?def setNext(nxt): > ? ?assert nxt==None or isinstance(nxt, Node), "next must be a Node" > ? ?self.next = nxt > > works ok, but it's uglier than it ought to be. > > So, I have three questions. > > 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? > 2) is their a less ugly alternative that what I am using? > 3) (this is purely philosophical but I am curious) ?Would it not be > more intuitive if > isinstance(None, ) returned true? > > Thank you for your kind attention. > Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From simon212 at gmx.de Fri Jun 12 10:24:49 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 16:24:49 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: <4A326531.50502@gmx.de> Simon wrote: > edexter wrote: >> simon wrote: >>> Hi everybody, >>> >>> The situation: >>> I wrote a GUI, based on Python, TkInter and Pmw. >>> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >>> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >>> and various Linux Distributions. >>> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >>> in the installed blt package), also when I use setitems on >>> Pmw.OptionMenu (I guess this is due to another package, associated with >>> tcl/tk). >>> >>> The target: >>> I have to get my GUI work under openSUSE 11.1 (x86_64). >>> >>> My plan: >>> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >>> I would like to know, how to install Python 2.4 along with TkInter and >>> Pmw (and packages that are required by them), parallel to the existing >>> Python 2.6. So that I do not break other software that depends on Python >>> 2.6. >>> >>> If you can think of another plan, I would be also glad to discuss it. >>> >>> Cheers, >>> Simon >> >> I suspect you want to install python 2.4 and then reinstall 2.6 I did >> that in windows and I don't understand why it wouldn't work in linux > > I'm afraid, installation is quit different under UNIX based systems and > Windows. > > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was > so long, but I will post it, if it helps). > > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, > too. So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', > '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > > Which configuration step did I miss after my Python2.4 installation? > What did I do wrong? > > Cheers, > Simon OK, I found an 'Ansatzpunkt' where I can start from: _tkinter.so is missing in /usr/local/lib/python2.4/lib-dynload so I guess my python is not configured for using Tcl? I found the following from http://mail.python.org/pipermail/python-list/2001-December/117984.html Install Tcl, Tk and Python as peers of each other ... 1. run configure in Python 2. make and make install Tcl (unless you're using binary dist)make and 3. make install Tk (unless you're using binary dist) 4. edit Setup 5. make and make install Python I guess, I will try that next. Maybe somebody knows a more detailed instruction. My problems: a) I don't know if I have to set special flags to make the three packages aware of each other during 'configure', 'make', and 'make altinstall'. b) Also, I don't know, which setup do I have to edit during step 4. c) Which Tcl and Tk versions do I need, don't I need tcl-devel in addition? Sorry for so many questions, but this stuff is new for me, Simon From lists at cheimes.de Fri Jun 12 10:32:27 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Jun 2009 16:32:27 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Paul LaFollette schrieb: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > def setLoc(lo): > assert isinstance(lo, int), "loc must be an int" > self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. I would think that the following should work > but it doesn't. > > def setNext(nxt): > assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > self.next = nxt How about the canonical way to check if an object is None? assert Node is None None is a singleton. Python guarantees that there is exactly one None object and on this account only one instance of NoneType. In Python 3.x you can't even overwrite the global variable None. User code shouldn't use NoneType at all. >>> type(None) >>> type(None)() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> None = 1 File "", line 1 SyntaxError: assignment to keyword The singletons True and False have a similar behavior. It's not possible to overwrite them as well. The bool type always returns either the singleton True or the singleton False. >>> True = False File "", line 1 SyntaxError: assignment to keyword >>> type(True) >>> type(True) is bool True >>> bool(42) True From exarkun at divmod.com Fri Jun 12 10:44:19 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 12 Jun 2009 10:44:19 -0400 Subject: matplotlib installation In-Reply-To: <5b8d13220906120654t41e0f33alb80f690be3df12cb@mail.gmail.com> Message-ID: <20090612144419.22176.1455202359.divmod.quotient.4784@henry.divmod.com> On Fri, 12 Jun 2009 22:54:14 +0900, David Cournapeau wrote: >On Fri, Jun 12, 2009 at 9:50 PM, Jean-Paul Calderone wrote: >> On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >>> >>> On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >>>> >>>> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >>>> Vista platform? >>> >>> >>> Maintainers for some packages have run into a wall >>> compiling for 2.6. ?Matplotlib is one of these: >>> >>> http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html >>> >>> Another package I care about is SimpleParse, which also >>> found compiling for 2.6 to be impossible. ?I do not know >>> if this was the same problem or not, but it means that >>> SimpleParse is *still* not available as an installer for 2.6. >>> >>> I assume this is of great concern to the Python community, >>> but I do not know where the discussion is taking place. >> >> Some discussion has occurred in the issue tracker: >> >> ?http://bugs.python.org/issue3308 >> ?http://bugs.python.org/issue6007 >> >> In general, the people responsible for how CPython builds on Windows >> don't seem to consider this an issue. > >We got the same problem with numpy. The good news is it is solvable >(at least partially). > >http://projects.scipy.org/numpy/browser/trunk/numpy/random/mtrand/randomkit.c > >Basically, there are some functions which are erroneously "declared" >in the .lib, but they don't actually exist in the MS C runtime. We >detect when the .C code is built under mingw, and add an hack to >redirect the function to the "real" function, _ftime64 (see around >line 75). Thanks for pointing out one possible workaround. I don't think this is always applicable, though. For example, pyOpenSSL can't be built for Python 2.6 because OpenSSL uses localtime, another function with a similar problem as the one with ftime. To redirect its usage, OpenSSL itself needs to be changed and then distributed along with pyOpenSSL. Jean-Paul From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 12 10:45:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Jun 2009 16:45:28 +0200 Subject: Question about None In-Reply-To: References: Message-ID: <4a3269ef$0$23850$426a74cc@news.free.fr> Paul LaFollette a ?crit : > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. This somehow goes against the whole philosophy of dynamic typing Python is based upon... But there are indeed cases where it makes sense and I assume you know what you're doing !-) > For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > def setLoc(lo): > assert isinstance(lo, int), "loc must be an int" > self.loc = lo > > does the trick nicely. Did you considered using properties (or custom descriptors) instead ? (snip - others already answered) From lists at cheimes.de Fri Jun 12 10:49:04 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Jun 2009 16:49:04 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: Simon wrote: > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was > so long, but I will post it, if it helps). --enable-framework is for Mac OS X only. > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, > too. So, I got my parallel installation. You have chosen the correct and canonical way to install a parallel installation of Python. > However, I cannot import modules like Tkinter or readline within python2.4. You must install the development library of tk, readline, zlib and libbz2 prior to configure && make. Try this on your box: zypper install gcc make autoconf automake libtool zlib-devel readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel libopenssl-devel From jeff at jmcneil.net Fri Jun 12 10:55:41 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Fri, 12 Jun 2009 07:55:41 -0700 (PDT) Subject: Question about None References: Message-ID: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> On Jun 12, 10:05?am, Paul LaFollette wrote: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. ?For instance, I want to be > certain that self.loc contains an int. ?This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > ? def setLoc(lo): > ? ? assert isinstance(lo, int), "loc must be an int" > ? ? self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. ?I would think that the following should work > but it doesn't. > > ? def setNext(nxt): > ? ? assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > ? ? self.next = nxt > > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. > > ? def setNext(nxt): > ? ? assert nxt==None or isinstance(nxt, Node), "next must be a Node" > ? ? self.next = nxt > > works ok, but it's uglier than it ought to be. > > So, I have three questions. > > 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? > 2) is their a less ugly alternative that what I am using? > 3) (this is purely philosophical but I am curious) ?Would it not be > more intuitive if > isinstance(None, ) returned true? > > Thank you for your kind attention. > Paul 1. The problem is described clearly by that Exception. The 'NoneType' name isn't bound to any objects at that current scope. I know that with 2.6, you can import 'types.NoneType' but I don't believe the 3.0 types module includes NoneType. Someone else will have to clarify that as I don't have 3.0 installed. 2. A less ugly alternative? You could use the accepted method of testing against None: if var is None: do_stuff() The use of the 'is' operator checks whether objects are exactly the same (id(var) == id(None)) as opposed to 'isinstance' or '==.' You might also try defining descriptors in order to make your type checks slightly more transparent. That might be confusing to other users of your class, though. Not many people expect a TypeError from an attribute assignment. 3. None is an instance of NoneType. Why should isinstance return True when it's tested against other types? HTH, Jeff mcjeff.blogspot.com From benjamin.kaplan at case.edu Fri Jun 12 11:07:13 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 12 Jun 2009 11:07:13 -0400 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: On Fri, Jun 12, 2009 at 9:31 AM, Simon wrote: > edexter wrote: > >> simon wrote: >> >>> Hi everybody, >>> >>> The situation: >>> I wrote a GUI, based on Python, TkInter and Pmw. >>> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >>> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >>> and various Linux Distributions. >>> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >>> in the installed blt package), also when I use setitems on >>> Pmw.OptionMenu (I guess this is due to another package, associated with >>> tcl/tk). >>> >>> The target: >>> I have to get my GUI work under openSUSE 11.1 (x86_64). >>> >>> My plan: >>> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >>> I would like to know, how to install Python 2.4 along with TkInter and >>> Pmw (and packages that are required by them), parallel to the existing >>> Python 2.6. So that I do not break other software that depends on Python >>> 2.6. >>> >>> If you can think of another plan, I would be also glad to discuss it. >>> >>> Cheers, >>> Simon >>> >> >> I suspect you want to install python 2.4 and then reinstall 2.6 I did >> that in windows and I don't understand why it wouldn't work in linux >> > > I'm afraid, installation is quit different under UNIX based systems and > Windows. > > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was so > long, but I will post it, if it helps). > The --enable-framework option is for creating Framework builds on OS X. It won't work on Linux. > > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, too. > So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > Which configuration step did I miss after my Python2.4 installation? What > did I do wrong? > Again, give us the error message. We can't help if we don't know exactly what's going on. > > Cheers, > Simon > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bborcic at gmail.com Fri Jun 12 11:12:58 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 12 Jun 2009 17:12:58 +0200 Subject: Making the case for repeat In-Reply-To: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> Message-ID: <4a3270b8$1_7@news.bluewin.ch> Raymond Hettinger wrote: > There is a natural inclination to do the opposite. We factor code > to eliminate redundancy, but that is not always a good idea with > an API. The goal for code factoring is to minimize redundancy. > The goal for API design is having simple parts that are easily > learned and can be readily combined (i.e. the notion of an > iterator algebra). This reminds me of an early programming experience that left me with a fascination. At a time where code had to fit in a couple dozens kilobytes, I once had to make significant room in what was already very tight and terse code. Code factoring *did* provide the room in the end, but the fascinating part came before. There was strictly no redundancy apparent at first, and finding a usable one involved contemplating code execution paths for hours until some degree of similarity was apparent between two code path families. And then, the fascinating part, was to progressively mutate both *away* from minimality of code, in order to enhance the similarity until it could be factored out. I was impressed; in various ways. First; that the effort could be characterized quite mechanically and in a sense stupidly as finding a shortest equivalent program, while the subjective feeling was that the task exerted perceptive intelligence to the utmost. Second; by the notion that a global constraint of code minimization could map more locally to a constraint that drew code to expand. Third; that the process resulted in bottom-up construction of what's usually constructed top-down, mimicking the willful design of the latter case, eg. an API extension, as we might call it nowadays. Cheers, BB -- "hope achieves the square root of the impossible" From javier.collado at gmail.com Fri Jun 12 11:26:15 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Jun 2009 17:26:15 +0200 Subject: Question about None In-Reply-To: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> References: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> Message-ID: Hello, You're right, types.NoneType is not available in python 3.0, I wasn't aware of that change. Thanks for pointing it out. Best regards, Javier 2009/6/12 Jeff McNeil : > On Jun 12, 10:05?am, Paul LaFollette > wrote: >> Kind people, >> >> Using Python 3.0 on a Gatesware machine (XP). >> I am building a class in which I want to constrain the types that can >> be stored in various instance variables. ?For instance, I want to be >> certain that self.loc contains an int. ?This is straightforward (as >> long as I maintain the discipline of changing loc through a method >> rather than just twiddling it directly. >> >> ? def setLoc(lo): >> ? ? assert isinstance(lo, int), "loc must be an int" >> ? ? self.loc = lo >> >> does the trick nicely. >> >> However, I also want to constrain self.next to be either an instance >> of class Node, or None. ?I would think that the following should work >> but it doesn't. >> >> ? def setNext(nxt): >> ? ? assert isinstance(nxt, (Node, NoneType)), "next must be a Node" >> ? ? self.next = nxt >> >> since type(Node) responds with but the assertion >> above gives "name 'NoneType' is not defined" suggesting that NoneType >> is some sort of quasi-class. >> >> ? def setNext(nxt): >> ? ? assert nxt==None or isinstance(nxt, Node), "next must be a Node" >> ? ? self.next = nxt >> >> works ok, but it's uglier than it ought to be. >> >> So, I have three questions. >> >> 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? >> 2) is their a less ugly alternative that what I am using? >> 3) (this is purely philosophical but I am curious) ?Would it not be >> more intuitive if >> isinstance(None, ) returned true? >> >> Thank you for your kind attention. >> Paul > > 1. The problem is described clearly by that Exception. The 'NoneType' > name isn't bound to any objects at that current scope. ?I know that > with 2.6, you can import 'types.NoneType' but I don't believe the 3.0 > types module includes NoneType. ?Someone else will have to clarify > that as I don't have 3.0 installed. > > 2. A less ugly alternative? You could use the accepted method of > testing against None: > > if var is None: > ? ?do_stuff() > > The use of the 'is' operator checks whether objects are exactly the > same (id(var) == id(None)) as opposed to 'isinstance' or '==.' > > You might also try defining descriptors in order to make your type > checks slightly more transparent. That might be confusing to other > users of your class, though. Not many people expect a TypeError from > an attribute assignment. > > 3. None is an instance of NoneType. Why should isinstance return True > when it's tested against other types? > > HTH, > > Jeff > mcjeff.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > From jeanmichel at sequans.com Fri Jun 12 11:36:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 17:36:37 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: <4A327605.4020203@sequans.com> > def setNext(nxt): > assert nxt==None or isinstance(nxt, Node), "next must be a Node" > self.next = nxt > > works ok, but it's uglier than it ought to be. > > I don't find it that ugly. It's accurate, easy to read and understand. "What else ?" would say a famous coffee representative. If you like perfection, replace nxt==None by nxt is None. Jean-Michel From simon212 at gmx.de Fri Jun 12 11:49:54 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 17:49:54 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> Message-ID: <4A327922.9080202@gmx.de> Benjamin Kaplan wrote: > > > On Fri, Jun 12, 2009 at 9:31 AM, Simon > wrote: > > edexter wrote: > > simon wrote: > > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter > and Pmw are > installed). But it crashes with Python 2.6. I tried this on > MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is > due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, > associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by > default. > I would like to know, how to install Python 2.4 along with > TkInter and > Pmw (and packages that are required by them), parallel to > the existing > Python 2.6. So that I do not break other software that > depends on Python > 2.6. > > If you can think of another plan, I would be also glad to > discuss it. > > Cheers, > Simon > > > I suspect you want to install python 2.4 and then reinstall 2.6 > I did > that in windows and I don't understand why it wouldn't work in linux > > > I'm afraid, installation is quit different under UNIX based systems > and Windows. > > I installed Python-2.4.4.tar.bz2 from python.org > , using gcc-4.3 (within openSUSE 11.1 x86_64) via > 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list > was so long, but I will post it, if it helps). > > > The --enable-framework option is for creating Framework builds on OS X. > It won't work on Linux. > > > > Second, configured again without any flags. The installation by > 'make altinstall' to /usr/local was a success. Python2.6 seams > unaffected, too. So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within > python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', > '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > Which configuration step did I miss after my Python2.4 installation? > What did I do wrong? > > > > Again, give us the error message. We can't help if we don't know exactly > what's going on. > > > Sorry, here it comes: Python 2.4.4 (#1, Jun 12 2009, 14:11:55) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "/etc/pythonstart", line 7, in ? import readline ImportError: No module named readline >>> import Tkinter Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter Right know, I'm following Christian's hint, to "install the development library of tk, readline, zlib and libbz2 prior to configure && make", because the following essential packages were not installed on my system: autoconf automake libbz2-devel libopenssl-devel libtool ncurses-devel readline-devel sqlite2-devel tack tcl-devel tk-devel zlib-devel I will let you know about the result, soon. Cheers, Simon From tjreedy at udel.edu Fri Jun 12 12:32:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Jun 2009 12:32:25 -0400 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Paul LaFollette wrote: > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. add NoneType = type(None) before using Nonetype From simon212 at gmx.de Fri Jun 12 13:05:53 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 19:05:53 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> Message-ID: <4A328AF1.8090205@gmx.de> Christian Heimes wrote: > Simon wrote: >> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >> openSUSE 11.1 x86_64) via 'make altinstall'. >> >> First, I tried to configure with the following flags: >> --prefix=/opt/python-24 --enable-framework --with-pydebug >> This provoked an error during compilation via make (sorry, the list was >> so long, but I will post it, if it helps). > > --enable-framework is for Mac OS X only. > >> Second, configured again without any flags. The installation by 'make >> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >> too. So, I got my parallel installation. > > You have chosen the correct and canonical way to install a parallel > installation of Python. > >> However, I cannot import modules like Tkinter or readline within python2.4. > > You must install the development library of tk, readline, zlib and > libbz2 prior to configure && make. > > Try this on your box: > > zypper install gcc make autoconf automake libtool zlib-devel > readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel > libopenssl-devel > Unfortunately, I got the following errors, while compiling via make. Please, see attached text file for details about everything I did from installing the missing packages via zypper until make. [...] gcc -pthread -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -I. -I/home/simon/Python-2.4.4/./Include -I/usr/local/include -I/home/simon/Python-2.4.4/Include -I/home/simon/Python-2.4.4 -c /home/simon/Python-2.4.4/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.4/_curses_panel.o /home/simon/Python-2.4.4/Modules/_curses_panel.c:17:19: error: panel.h: No such file or directory [...] building '_tkinter' extension gcc -pthread -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11/include -I. -I/home/simon/Python-2.4.4/./Include -I/usr/local/include -I/home/simon/Python-2.4.4/Include -I/home/simon/Python-2.4.4 -c /home/simon/Python-2.4.4/Modules/_tkinter.c -o build/temp.linux-x86_64-2.4/_tkinter.o In file included from /home/simon/Python-2.4.4/Modules/_tkinter.c:67: /usr/include/tk.h:78:23: error: X11/Xlib.h: No such file or directory [...] X11 says: Program 'X11' is present in package 'xorg-x11', which is installed on your system. Absolute path to 'X11' is '/usr/bin/X11'. Please check your $PATH variable to see whether it contains the mentioned path. and it is on the path rpm -q xorg-x11 says: xorg-x11-7.4-8.18 Cheers, Simon -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: install.error.log URL: From rdmurray at bitdance.com Fri Jun 12 13:13:47 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Fri, 12 Jun 2009 17:13:47 +0000 (UTC) Subject: zipfile doesn't compress very good, are there other solutions? References: <4A316C05.4080808@gmail.com> <50697b2c0906111358u400942f1yb2bcb1b33c1ecabe@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jun 11, 2009 at 1:41 PM, Stef Mientki wrote: > > Peter Otten wrote: > >> Stef Mientki wrote: > >>> Peter Otten wrote: > >>>> Stef Mientki wrote: > >>>>> I packed all sources with zipfile, > >>>>> but the compression doesn't seem to be very good. > >>>>> > >>>> > >>>> If you don't specify the compression, the files are not compressed at > >>>> all. Just in case you didn't know... > >>>> > >>> > >>> .. and would you be willing to tell me how I could set the compression ( > >>> at maximum) ? > >>> > >> > >> According to the documentation (hint, hint) there is only on and off. > >> > >> zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) > >> > >> > > > > sorry guys I made a mistake, > > I did read the doc, but as there was no default value metioned, > > Erm... > > class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]]) > > Open a ZIP file [...] compression is the ZIP compression method to > use when writing the archive, and should be ZIP_STORED or > ZIP_DEFLATED; [...] The default is ZIP_STORED. [...] > > Though I admit the docs could definitely do with having > "compression=ZIP_STORED" in the signature part of the doc. Georg's been fixing the method signatures bit by bit to use keyword style. Doc patches would be welcome to help speed up the conversion process. --David From sandra.bunn at thecarreraagency.com Fri Jun 12 13:22:36 2009 From: sandra.bunn at thecarreraagency.com (Sandra Bunn) Date: Fri, 12 Jun 2009 10:22:36 -0700 Subject: ANNOUNCE: TIB/Rendezvous module for python Message-ID: <007501c9eb82$61d2ca90$6601a8c0@SANDRALAPTOP> Hi Thomas, My name is Sandra with The Carrera Agency. I saw an online article by you regarding Tibco Rendezvous with Python. I am currently looking for a Python/Tibco developer for a remote position. Below is a description of what they are trying to do: Summary: Need the ability to connect to a TIBCO server natively using Python. The Python TICBO interface must be able to query for available servers and server clusters, create connections and sessions, and feed messages to queues and topics. The implementation must be fault tolerant and inform calling libraries of errors and / or throw consistent exceptions that can be caught and handled by higher level libraries. Functional Requirements The module must be able to: . connect to a TIBCO server using TIBCO's URL format . create a session to a named queue on the server. . create a message producer with a given session. . easily fill a TIBCO EMS Map Message with key value pairs. . send a filled Map Message to a TIBCO server. . shut down a connection. . work with TIBCO's built in failover and load balancing functionality. TIBCO C Native Equivalents The following are the native equivalents that need to successfully connect to a TIBCO server. These functions should only be used as guidelines for understanding which portions of TIBCO functionality are being used, and should not be considered requirements for 1:1 equivalency. Simplifications of TIBCO's C based functionality is expected. . Functions 1. tibemsConnectionFactory_Create 2. tibemsConnectionFactor_SetServerURL 3. tibemsConnectionFactory_CreateConnection 4. tibemsConnectionFactory_Destroy 5. tibemsQueue_Create 6. tibemsConnection_CreateSession 7. tibemsConnection_Stop 8. tibemsConnection_Close 9. tibemsSession_CreateProducer 10. tibemsMsgProducer_Close 11. tibemsMsgProducer_SendEx 12. tibemsDestination_Destroy 13. tibemsMsg_Destroy 14. tibemsMapMsg_Create 15. tibemsMapMsg_Set* Structures 1. tibemsMapMsg 2. tibemsConnectionFactory 3. tibemsConnection 4. tibemsDestination 5. tibemsSession 6. tibemsMsgProducer Basic assessment (not set in stone) of project level of effort to work against: . Phase One - 1 week o Discovery o Architectural documentation for to the C TIBCO level commands. Validation with internal engineering teams of architectural documentation and high level project plan. . Phase Two - 1.5 weeks o Coding - Wrapping C code with Boost or an equivalent wrapper system for python. . Phase Three - 1.5 weeks o Test and debug the implementation to assure the appropriate error conditions, performance, and other requirements set forth. . Phase Four - .5 week o Finalize documentation and cross train team on implementation If you or someone you know might be interested, please contact me. I look forward to hearing from you. Regards, Sandra Sandra Bunn The Carrera Agency 65 Enterprise Aliso Viejo, CA 92656 (310) 370-4778 - Ofc. (310) 499-5653 - Fax We've changed our look, not the quality of our service - www.thecarreraagency.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Fri Jun 12 14:20:16 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 12 Jun 2009 19:20:16 +0100 Subject: Need help in Python regular expression In-Reply-To: References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: On Fri, 12 Jun 2009 06:20:24 +0100, meryl wrote: > On Jun 11, 9:41?pm, "Mark Tolonen" wrote: >> "meryl" wrote in message >> >> > Hi, >> >> > I have this regular expression >> > blockRE = re.compile(".*RenderBlock {\w+}") >> >> > it works if my source is "RenderBlock {CENTER}". [snip] >> -----------------------code---------------------- >> import re >> pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') >> >> testdata = '''\ >> RenderTable {TABLE} >> RenderBlock (CENTER) >> RenderBlock {CENTER} >> RenderTable {TABLE) ? ? ?#shouldn't match >> ''' >> >> print pat.findall(testdata) >> --------------------------------------------------- >> >> Result: >> >> ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] >> >> -Mark > > Thanks for both of your help. How can i modify the RegExp so that > both > RenderTable {TABLE} > and > RenderTable {TABLE} [text with a-zA-Z=SPACE0-9] > will match > > I try adding ".*" at the end , but it ends up just matching the second > one. Curious, it should work (and match rather more than you want, but that's another matter. Try adding this instead: '(?: \[[a-zA-Z= 0-9]*\])?' Personally I'd replace all those spaces with \s* or \s+, but I'm paranoid when it comes to whitespace. -- Rhodri James *-* Wildebeest Herder to the Masses From robert.kern at gmail.com Fri Jun 12 14:20:44 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Jun 2009 13:20:44 -0500 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: On 2009-06-12 09:05, Paul LaFollette wrote: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. You may want to consider using Enthought's Traits package (disclosure: I work for Enthought). http://pypi.python.org/pypi/Traits/ Type-checking attributes is not my favorite feature of Traits (I try to avoid using this feature if I can avoid it), but it is designed for precisely your use cases. In [2]: %cpaste Pasting code; enter '--' alone on the line to stop. :from enthought.traits.api import Float, HasTraits, Instance, Int, This : :class FancyClass(HasTraits): : """ An example traited class. : """ : x = Float(10.0) : y = Int(-20) : :class Node(HasTraits): : """ A node in a single-linked list. : """ : : # The location of this Node. : loc = Int(0) : : # The next Node. This() is a special trait that accepts instances of : # this class, or None. : next = This() : : # The data attached to the Node. It will accept instances of FancyClass : # or None. : data = Instance(FancyClass) : : :-- In [3]: n = Node() In [4]: n.next In [5]: n.data In [6]: n.loc Out[6]: 0 In [7]: fc = FancyClass(x=15.0) In [8]: fc.x Out[8]: 15.0 In [9]: fc.y Out[9]: -20 In [10]: fc.y = 'a string' --------------------------------------------------------------------------- TraitError Traceback (most recent call last) /Users/rkern/ in () /Users/rkern/svn/et/Traits/enthought/traits/trait_handlers.pyc in error(self, object, name, value) 173 """ 174 raise TraitError( object, name, self.full_info( object, name, value ), --> 175 value ) 176 177 def arg_error ( self, method, arg_num, object, name, value ): TraitError: The 'y' trait of a FancyClass instance must be an integer, but a value of 'a string' was specified. In [11]: n.data = fc In [12]: n.data = None In [13]: n.data = n --------------------------------------------------------------------------- TraitError Traceback (most recent call last) /Users/rkern/ in () /Users/rkern/svn/et/Traits/enthought/traits/trait_handlers.pyc in error(self, object, name, value) 173 """ 174 raise TraitError( object, name, self.full_info( object, name, value ), --> 175 value ) 176 177 def arg_error ( self, method, arg_num, object, name, value ): TraitError: The 'data' trait of a Node instance must be a FancyClass or None, but a value of <__main__.Node object at 0x17999c0> was specified. In [14]: n.next = Node(loc=1) In [15]: n.next Out[15]: <__main__.Node at 0x1892e70> -- 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 rhodri at wildebst.demon.co.uk Fri Jun 12 14:42:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 12 Jun 2009 19:42:17 +0100 Subject: TypeError: int argument required In-Reply-To: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Fri, 12 Jun 2009 04:56:24 +0100, lucius wrote: > I am trying to > print some values to a file (using c's printf like method). > TypeError: int argument required > # this works, i see value on screen > print w, h, absX, absY > > # where result is the return value of my regular expression. > > w, h, absX, absY = result.group(3), result.group(4), result.group > (5), result.group(6) > > w = 100 > h = 200 > > absX = 10.0 > absY = 20.0 > > # this fails, I get "TypeError: int argument required" > print >> fo, " style=\"fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke- > opacity:0.9\"/> " % (absX, absY, w, h) > > Thank you for any help. 1. This has to be the most incoherent help request that I've seen that included actual information. Figuring out what you were actually doing was quite a challenge. 2. That output string has severe "leaning toothpick" syndrome. Python accepts both single and double quotes to help avoid creating something so unreadable: use them. 3. matchobject.group(n) returns a string, not an int or float. -- Rhodri James *-* Wildebeest Herder to the Masses From aahz at pythoncraft.com Fri Jun 12 16:23:24 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Jun 2009 13:23:24 -0700 Subject: How to insert string in each match using RegEx iterator References: Message-ID: In article , 504crank at gmail.com <504crank at gmail.com> wrote: > >MRI scans would no doubt reveal that people who attain a mastery of >RegEx expressions must have highly developed areas of the brain. I >wonder where the RegEx part of the brain might be located. You want Friedl: http://www.powells.com/biblio/2-9780596528126-0 -- 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 piet at cs.uu.nl Fri Jun 12 16:24:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 12 Jun 2009 22:24:47 +0200 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <39379946-16f0-448c-a230-3da19449d40e@k19g2000prh.googlegroups.com> Message-ID: >>>>> higer (h) wrote: >h> On Jun 11, 11:44?am, Chris Rebert wrote: >>> On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: >>> > I just want to compare two files,one from windows and the other from >>> > unix. But I do not want to compare them through reading them line by >>> > line. Then I found there is a filecmp module which is used as file and >>> > directory comparisons. However,when I use two same files (one from >>> > unix,one from windows,the content of them is the same) to test its cmp >>> > function, filecmp.cmp told me false. >>> >>> > Later, I found that windows use '\n\r' as new line flag but unix use >>> > '\n', so filecmp.cmp think that they are different,then return false. >>> > So, can anyone tell me that is there any method like IgnoreNewline >>> > which can ignore the difference of new line flag in diffrent >>> > platforms? If not,I think filecmp may be not a good file comparison >>> >>> Nope, there's no such flag. You could run the files through either >>> `dos2unix` or `unix2dos` beforehand though, which would solve the >>> problem. >>> Or you could write the trivial line comparison code yourself and just >>> make sure to open the files in Universal Newline mode (add 'U' to the >>> `mode` argument to `open()`). >>> You could also file a bug (a patch to add newline insensitivity would >>> probably be welcome). >>> >>> Cheers, >>> Chris >>> --http://blog.rebertia.com >h> Thank you very much. Adding 'U' argument can perfectly work, and I >h> think it is definitely to report this as a bug to Python.org as you >h> say. Filecmp does a binary compare, not a text compare. So it starts by comparing the sizes of the files and if they are different the files must be different. If equal it compares the bytes by reading large blocks. Comparing text files would be quite different especially when ignoring line separators. Maybe comparing text files should be added as a new feature. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From emile at fenx.com Fri Jun 12 16:51:24 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Jun 2009 13:51:24 -0700 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix In-Reply-To: References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: On 6/11/2009 12:09 AM higer said... > Tool can certainly be used to compare two files,but I just want to > compare them using Python code. > difflib? Emile From niels.egberts at gmail.com Fri Jun 12 16:58:42 2009 From: niels.egberts at gmail.com (Niels Egberts) Date: Fri, 12 Jun 2009 22:58:42 +0200 Subject: uncompress base64-gzipped string Message-ID: I'm creating a game in python and I want to a level editor called 'tiled'. It ouputs a .xml file with base64-gzipped information. Then every 4 bytes represents a number. See the following link: http://www.mapeditor.org/wiki/Examining_the_map_format To start I tried: code = base64.b64decode("H4sIAAAAAAAAAO3NoREAMAgEsLedAfafE4+s6l0jolNJiif18tt/Fj8AAMC9ARtYg28AEAAA") code = zlib.decompress(code) But I get: zlib.error: Error -3 while decompressing data: incorrect header check How can I solve this? Thanks, Niels. From aaron.watters at gmail.com Fri Jun 12 17:30:56 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 12 Jun 2009 14:30:56 -0700 (PDT) Subject: ANN: WHIFF += Flash chart widget support (Aaron Watters) References: Message-ID: <19839370-3b23-4efd-bbdf-75877639aceb@c19g2000prh.googlegroups.com> Regarding: http://aaron.oirt.rutgers.edu/myapp/amcharts/doc On Jun 12, 3:07 am, oyster wrote: > nice > the only pity is that amcharts is not a money-free product It is if you don't mind the little link in the corner. (which I think is only fair). I found a totally free one that looked pretty good too, which I may add sometime. http://teethgrinder.co.uk/open-flash-chart/ -- Aaron Watters === an apple every 8 hours will keep 3 doctors away. -- kliban From Nikolaus at rath.org Fri Jun 12 18:33:13 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Fri, 12 Jun 2009 18:33:13 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> Message-ID: <873aa5m6ae.fsf@vostro.rath.org> Nikolaus Rath writes: > Hi, > > Please consider this example: [....] I think I managed to narrow down the problem a bit. It seems that when a function returns normally, its local variables are immediately destroyed. However, if the function is left due to an exception, the local variables remain alive: ---------snip--------- #!/usr/bin/env python import gc class testclass(object): def __init__(self): print "Initializing" def __del__(self): print "Destructing" def dostuff(fail): obj = testclass() if fail: raise TypeError print "Calling dostuff" dostuff(fail=False) print "dostuff returned" try: print "Calling dostuff" dostuff(fail=True) except TypeError: pass gc.collect() print "dostuff returned" ---------snip--------- Prints out: ---------snip--------- Calling dostuff Initializing Destructing dostuff returned Calling dostuff Initializing dostuff returned Destructing ---------snip--------- Is there a way to have the obj variable (that is created in dostuff()) destroyed earlier than at the end of the program? As you can see, I already tried to explicitly call the garbage collector, but this does not help. Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From ben+python at benfinney.id.au Fri Jun 12 20:14:15 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Jun 2009 10:14:15 +1000 Subject: Exception inside loop wrongly failing doctest References: <02420d02$0$20639$c3e8da3@news.astraweb.com> <0242240f$0$21875$c3e8da3@news.astraweb.com> Message-ID: <87ws7h6ld4.fsf@benfinney.id.au> Steven D'Aprano writes: > Ah, that would be it. Not a bug then, a limitation of the doctest module. The doctest module is good for narrative tests (ensuring that examples in documentation actually work as written), but poor for unit testing. Both functions are useful, but each should use a different tool . Not entirely related to the limitation you've found, and I don't know from your explanation whether you're mixing the two purposes, but it's worth pointing out in case you are. -- \ ?I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.? ?Emo Philips | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Fri Jun 12 21:05:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 13 Jun 2009 13:05:31 +1200 Subject: OT: Periodic table gets a new element References: Message-ID: So, is this only accessible with Python 3.x, or will it be backported to 2.x as well? From lists at cheimes.de Fri Jun 12 21:06:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Jun 2009 03:06:38 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A328AF1.8090205@gmx.de> References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> Message-ID: Simon schrieb: > Christian Heimes wrote: >> Simon wrote: >>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >>> openSUSE 11.1 x86_64) via 'make altinstall'. >>> >>> First, I tried to configure with the following flags: >>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>> This provoked an error during compilation via make (sorry, the list was >>> so long, but I will post it, if it helps). >> >> --enable-framework is for Mac OS X only. >> >>> Second, configured again without any flags. The installation by 'make >>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>> too. So, I got my parallel installation. >> >> You have chosen the correct and canonical way to install a parallel >> installation of Python. >> >>> However, I cannot import modules like Tkinter or readline within >>> python2.4. >> >> You must install the development library of tk, readline, zlib and >> libbz2 prior to configure && make. >> >> Try this on your box: >> >> zypper install gcc make autoconf automake libtool zlib-devel >> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >> libopenssl-devel >> > > > Unfortunately, I got the following errors, while compiling via make. > Please, see attached text file for details about everything I did from > installing the missing packages via zypper until make. zypper should have installed all necessary dependencies, including a whole bunch of X11 headers. Something seems to be wrong on your system or SuSE's package dependencies. I know why I dislike SuSE. :) Although I started my Linux career 12 years ago with SuSE I prefer Debian based systems since Woody came out in 2002. :) > X11 says: > Program 'X11' is present in package 'xorg-x11', which is installed on > your system. zypper search X11 | grep devel ... zypper install xorg-x11-devel That should (hopefully) do the trick. On a Debian based systems it's much easier to install all Python dependencies with "apt-get build-dep python2.5" To quote SuSE: "Have a lot of fun ..." Und viel Gl?ck! Christian From python at mrabarnett.plus.com Fri Jun 12 21:26:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Jun 2009 02:26:50 +0100 Subject: Exceptions and Object Destruction In-Reply-To: <873aa5m6ae.fsf@vostro.rath.org> References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <4A33005A.9070208@mrabarnett.plus.com> Nikolaus Rath wrote: > Nikolaus Rath writes: >> Hi, >> >> Please consider this example: > [....] > > I think I managed to narrow down the problem a bit. It seems that when > a function returns normally, its local variables are immediately > destroyed. However, if the function is left due to an exception, the > local variables remain alive: > > ---------snip--------- > #!/usr/bin/env python > import gc > > class testclass(object): > def __init__(self): > print "Initializing" > > def __del__(self): > print "Destructing" > > def dostuff(fail): > obj = testclass() > > if fail: > raise TypeError > > print "Calling dostuff" > dostuff(fail=False) > print "dostuff returned" > > try: > print "Calling dostuff" > dostuff(fail=True) > except TypeError: > pass > > gc.collect() > print "dostuff returned" > ---------snip--------- > > > Prints out: > > > ---------snip--------- > Calling dostuff > Initializing > Destructing > dostuff returned > Calling dostuff > Initializing > dostuff returned > Destructing > ---------snip--------- > > > Is there a way to have the obj variable (that is created in dostuff()) > destroyed earlier than at the end of the program? As you can see, I > already tried to explicitly call the garbage collector, but this does > not help. > Are the objects retained because there's a reference to the stack frame(s) in the traceback? From sjmachin at lexicon.net Fri Jun 12 22:38:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 02:38:05 +0000 (UTC) Subject: uncompress base64-gzipped string References: Message-ID: Niels Egberts gmail.com> writes: > zlib.error: Error -3 while decompressing data: incorrect header check > > How can I solve this? The link you quoted says "you need to first base64 decode the string, then gunzip the resulting data" ... so gunzip it: | >>> s0 = "H4sIAAAAA......" | >>> import base64 | >>> s1 = base64.b64decode(s0) | >>> len(s0) | 72 | >>> len(s1) | 54 | >>> import StringIO # or cStringIO or io depending on what # Python versions you want to support | >>> sio = StringIO.StringIO(s1) | >>> import gzip | >>> gzf = gzip.GzipFile(fileobj=sio) | >>> guff = gzf.read() | >>> len(guff) | 4096 | >>> guff[:100] | '\x1b\x00\x00\x00\x1b\x00\x00\x00\x1b\x00\x00\x00 [snip] What a long journey: parse xml, base64 decode, gunzip, and you're still not home; next stop is struct.unpack ... HTH, John From higerinbeijing at gmail.com Fri Jun 12 23:29:41 2009 From: higerinbeijing at gmail.com (higer) Date: Fri, 12 Jun 2009 20:29:41 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP References: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Message-ID: <1c4c5f48-bcce-4d25-9517-f78a8a0c72eb@d25g2000prn.googlegroups.com> On Jun 12, 4:55?pm, higer wrote: > Maybe everyone know that decompyle(hosted on SourceForge.net) is a > tool to transfer a .pyc file to .py file and now it does only support > Python 2.3 or the below. I have found a project named unpyc which can > support Python version 2.5. Unpyc project is build on decompyle which > is hosted on google code and if you want you can download it. > > I build unpyc on Ubuntu successfully and can run it ok. But with some > purpose, I just want to use this tool on my WindowsXP, so I tried to > build it. I have tried many times and methods, with .net2003 or > MingGW, but I failed. So,I come here looking for sombody can help me.I > will give the showing error message with different method on the > following: > > 1 ? ? Using command : python setup.py install > F:\unpyc>python setup.py install > running install > running build > running build_py > creating build\lib.win32-2.5 > creating build\lib.win32-2.5\unpyc > copying unpyc\dis_15.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_16.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_20.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_21.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_22.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_23.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_24.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_25.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_26.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_files.py -> build\lib.win32-2.5\unpyc > copying unpyc\magics.py -> build\lib.win32-2.5\unpyc > copying unpyc\marshal_files.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_23.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_24.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_25.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_26.py -> build\lib.win32-2.5\unpyc > copying unpyc\Parser.py -> build\lib.win32-2.5\unpyc > copying unpyc\Scanner.py -> build\lib.win32-2.5\unpyc > copying unpyc\spark.py -> build\lib.win32-2.5\unpyc > copying unpyc\verify.py -> build\lib.win32-2.5\unpyc > copying unpyc\Walker.py -> build\lib.win32-2.5\unpyc > copying unpyc\__init__.py -> build\lib.win32-2.5\unpyc > running build_ext > building 'unpyc/marshal_25' extension > creating build\temp.win32-2.5 > creating build\temp.win32-2.5\Release > creating build\temp.win32-2.5\Release\unpyc > f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / > nologo /Ox /MD /W3 /GX /DNDEBU > G -IF:\Python25\include -IF:\Python25\PC /Tcunpyc/marshal_25.c /Fobuild > \temp.win32-2.5\Release\unpyc > /marshal_25.obj > marshal_25.c > unpyc\marshal_25.c(401) : warning C4273: 'PyMarshal_WriteLongToFile' : > inconsistent dll linkage > unpyc\marshal_25.c(413) : warning C4273: > 'PyMarshal_WriteObjectToFile' : inconsistent dll linkage > unpyc\marshal_25.c(1004) : warning C4273: > 'PyMarshal_ReadShortFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1015) : warning C4273: > 'PyMarshal_ReadLongFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1044) : warning C4273: > 'PyMarshal_ReadLastObjectFromFile' : inconsistent dll link > age > unpyc\marshal_25.c(1087) : warning C4273: > 'PyMarshal_ReadObjectFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1101) : warning C4273: > 'PyMarshal_ReadObjectFromString' : inconsistent dll linkag > e > unpyc\marshal_25.c(1116) : warning C4273: > 'PyMarshal_WriteObjectToString' : inconsistent dll linkage > > f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe / > DLL /nologo /INCREMENTAL:NO /LI > BPATH:F:\Python25\libs /LIBPATH:F:\Python25\PCBuild /EXPORT:initunpyc/ > marshal_25 build\temp.win32-2. > 5\Release\unpyc/marshal_25.obj /OUT:build\lib.win32-2.5\unpyc/ > marshal_25.pyd /IMPLIB:build\temp.win3 > 2-2.5\Release\unpyc\marshal_25.lib > marshal_25.obj : error LNK2001: unresolved external symbol initunpyc/ > marshal_25 > build\temp.win32-2.5\Release\unpyc\marshal_25.lib : fatal error > LNK1120: 1 unresolved externals > LINK : fatal error LNK1141: failure during build of exports file > error: command '"f:\Program Files\Microsoft Visual Studio .NET > 2003\Vc7\bin\link.exe"' failed with e > xit status 1141 > > 2 ? ?Using command: ? python setup.py build -c mingw32 > > F:\unpyc>python setup.py build -c mingw32 > running build > running build_py > running build_ext > building 'unpyc/marshal_25' extension > F:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IF:\Python25\include - > IF:\Python25\PC -c unpyc/mars > hal_25.c -o build\temp.win32-2.5\Release\unpyc\marshal_25.o > unpyc/marshal_25.c:1087: warning: 'PyMarshal_ReadObjectFromFile' > defined locally after being referen > ced with dllimport linkage > unpyc/marshal_25.c:1101: warning: 'PyMarshal_ReadObjectFromString' > defined locally after being refer > enced with dllimport linkage > writing build\temp.win32-2.5\Release\unpyc\marshal_25.def > F:\mingw\bin\gcc.exe -mno-cygwin -shared -s build > \temp.win32-2.5\Release\unpyc\marshal_25.o build\te > mp.win32-2.5\Release\unpyc\marshal_25.def -LF:\Python25\libs -LF: > \Python25\PCBuild -lpython25 -lmsvc > r71 -o build\lib.win32-2.5\unpyc/marshal_25.pyd > F:\Python25\libs/libpython25.a(dcbbs00336.o):(.text+0x0): multiple > definition of `PyMarshal_ReadObje > ctFromString' > build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text > +0x2958): first defined here > F:\Python25\libs/libpython25.a(dcbbs00335.o):(.text+0x0): multiple > definition of `PyMarshal_ReadObje > ctFromFile' > build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text > +0x28fb): first defined here > Cannot export initunpyc/marshal_25: symbol not defined > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > PS: necessary files has been added in proper path: Python25.dll is in > windows/system32; python25.lib and libpython25.a is in Python25/libs; > > Appreciate that you can do me a favor.Thanks There is nobody can help me? From rylesny at gmail.com Sat Jun 13 00:55:14 2009 From: rylesny at gmail.com (ryles) Date: Fri, 12 Jun 2009 21:55:14 -0700 (PDT) Subject: Unhandled exception in thread References: Message-ID: <9bc92125-7e9b-448a-a501-a4c2ee93e849@k2g2000yql.googlegroups.com> On Jun 11, 3:52?pm, Mads Michelsen wrote: > Here's the deal. The script in question is a screen scraping thing > which downloads and parses the html in the background using a separate > thread (the 'thread' module), while the main program serves up the > data to the user, allowing some modicum of interaction. Sometimes, not > always (though I cannot see a pattern), when I quit the script, the > following error message is printed: > > ? ? Unhandled exception in thread started by > ? ? Error in sys.excepthook: > > ? ? Original exception was: Are you using daemon threads? There are some issues with CPython when exiting with daemon threads: http://bugs.python.org/issue1722344 http://bugs.python.org/issue1856 http://bugs.python.org/issue4106 It's possible you are encountering this kind of problem. I have had to deal with issue4106, the workaround being to explicitly join the thread of multiprocessing.Queue before exiting. I would follow Scott's advice and explicitly request and wait for your threads to exit before terminating the process. From ajsavige at yahoo.com.au Sat Jun 13 01:02:53 2009 From: ajsavige at yahoo.com.au (Andrew Savige) Date: Fri, 12 Jun 2009 22:02:53 -0700 (PDT) Subject: Lexical scope: converting Perl to Python Message-ID: <447038.54682.qm@web56406.mail.re3.yahoo.com> I'd like to convert the following Perl code to Python: ?use strict; ?{ ?? my %private_hash = ( A=>42, B=>69 ); ?? sub public_fn { ???? my $param = shift; ???? return $private_hash{$param}; ?? } ?} ?print public_fn("A");??????? # good:? prints 42 ?my $x = $private_hash{"A"};? # error: good, hash not in scope The real code is more complex; the above is a simplified example. Notice that this code uses Perl's lexical scope to hide the %private_hash variable, but not the public_fn() function. While I could convert this code to the following Python code: ?private_hash = dict( A=42, B=69 ) ?def public_fn(param): ?? return private_hash[param] ?print public_fn("A")???? # good:? prints 42 ?x = private_hash["A"]??? # works: oops, hash is in scope I'm not happy with that because I'd like to limit the scope of the private_hash variable so that it is known only inside public_fn. Of course, I could hide the hash like so: ?def public_fn(param): ?? private_hash = dict( A=42, B=69 ) ?? return private_hash[param] yet I'm not happy with that either because of the repeated initialization the hash each time the function is called. What is the Pythonic equivalent of Perl's lexical scope, as illustrated by the code snippet above? Thanks, /-\ Need a Holiday? Win a $10,000 Holiday of your choice. Enter now.http://us.lrd.yahoo.com/_ylc=X3oDMTJxN2x2ZmNpBF9zAzIwMjM2MTY2MTMEdG1fZG1lY2gDVGV4dCBMaW5rBHRtX2xuawNVMTEwMzk3NwR0bV9uZXQDWWFob28hBHRtX3BvcwN0YWdsaW5lBHRtX3BwdHkDYXVueg--/SIG=14600t3ni/**http%3A//au.rd.yahoo.com/mail/tagline/creativeholidays/*http%3A//au.docs.yahoo.com/homepageset/%3Fp1=other%26p2=au%26p3=mailtagline From mk.fraggod at gmail.com Sat Jun 13 01:25:45 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 11:25:45 +0600 Subject: [Tutor] Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: <20090613112545.2ce188af@coercion> On Thu, 11 Jun 2009 22:35:15 -0700 Dennis Lee Bieber wrote: > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > declaimed the following in > gmane.comp.python.general: > > > I sent this to the Tutor mailing list and did not receive a response. > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > remarks? > > > > Please reply off-list and thanks in advance. Code examples are below in > > plain text. > > > Sorry -- you post to a public forum, expect to get the response on a > public forum... > > > > My program runs interactively by allowing the user to directly > > > interact with the python prompt. This program has a runAll() method > > > that runs a series of subprocesses with a cap on how many instances > > > are running at a time. My intent is to allow the user to use Ctrl-C to > > > break these subprocesses. Note that while not reflected in the demo > > Are they subprocesses or threads? Your sample code seems to be using > threads. > > When using threads, there is no assurance that any thread other than > the main program will receive a keyboard interrupt. In fact, no thread other than the main will get interrupt. > > def runAll(): > > workers = [ Thread(target = runSingle, args = [i]) > > for i in xrange(MAX_SUBPROCS + 1) ] > > try: > > for w in workers: > > w.start() > > except KeyboardInterrupt: > > ## I want this to be shown on a KeyboardInterrupt > > print '********* stopped midway ********' > > You are unlikely to see that... After you start the defined worker > /threads/ (which doesn't take very long -- all threads will be started, > but some may immediately block on the semaphore) this block will exit > and you will be at... > > > for w in workers: > > w.join() > > ... a .join() call, which is the most likely position at which the > keyboard interrupt will be processed, killing the main program thread > and probably generating some errors as dangling active threads are > forceably killed. There was quite interesting explaination of what happens when you send ^C with threads, posted on concurrency-sig list recently: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf Can be quite shocking, but my experience w/ threads only confirms that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From apt.shansen at gmail.com Sat Jun 13 01:35:57 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 12 Jun 2009 22:35:57 -0700 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: <7a9c25c20906122235y44795758pb96abe547464f98@mail.gmail.com> > > private_hash = dict( A=42, B=69 ) > def public_fn(param): > return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"] # works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. > A common idiom to do that would be this: def public_fn(param, __private_hash=dict(A=42, B=69)): return __private_hash[param] People often squint when they see that but it is useful in several ways. Python initializes the default arguments -once-, at definition. If they are mutable-- a dictionary, list or such-- that same dict is used everytime the function is called. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Jun 13 01:43:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Jun 2009 01:43:29 -0400 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: Andrew Savige wrote: > I'd like to convert the following Perl code to Python: > > use strict; > { > my %private_hash = ( A=>42, B=>69 ); > sub public_fn { > my $param = shift; > return $private_hash{$param}; > } > } > print public_fn("A"); # good: prints 42 > my $x = $private_hash{"A"}; # error: good, hash not in scope > > The real code is more complex; the above is a simplified example. > > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. > > While I could convert this code to the following Python code: > > private_hash = dict( A=42, B=69 ) > def public_fn(param): > return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"] # works: oops, hash is in scope Why would you do that if you do not want to do that? > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. def public_fn(): private_hash = dict( A=42, B=69 ) def public_fn(param): return private_hash[param] return public_fn public_fn = public_fn() print (public_fn("A")) x = private_hash["A"] # outputs 42 Traceback (most recent call last): File "C:\Programs\Python31\misc\t1", line 8, in x = private_hash["A"] NameError: name 'private_hash' is not defined Terry Jan Reedy From mk.fraggod at gmail.com Sat Jun 13 01:44:31 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 11:44:31 +0600 Subject: Lexical scope: converting Perl to Python References: Message-ID: <20090613114431.6f4893c7@coercion> On Fri, 12 Jun 2009 22:02:53 -0700 (PDT) Andrew Savige wrote: > I'd like to convert the following Perl code to Python: > > ?use strict; > ?{ > ?? my %private_hash = ( A=>42, B=>69 ); > ?? sub public_fn { > ???? my $param = shift; > ???? return $private_hash{$param}; > ?? } > ?} > ?print public_fn("A");??????? # good:? prints 42 > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > ... > > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? If you're using scope for garbage-collecting purposes, there's "with" statement and contextlib: from contextlib import contextmanager @contextmanager def get_hash(): complex_hash = dict(A=42, B-69) try: yield complex_hash except Exception as ex: del complex_hash # complex destructor ;) raise ex with get_hash() as hash: # do stuff with hash Note that this only makes sense if you need to implement some complex operation on hash destruction, and do that whatever-happens-inside-with to close the object, obviously not the case with simple dict above. And if you want to obfuscate one part of your code from another, you'll probably have better luck with languages like java, since no one seem to care about such stuff with python, so it'd be a hack against the language, at best. Why would you want to hide the code from itself, anyway? It's not like you'd be able to accomplish it - code can easily grep it's process body in memory and harvest all the "private" values, so I'd suggest getting some fresh air when you start to feel like doing that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 02:29:34 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 16:29:34 +1000 Subject: Question about None References: Message-ID: <02433982$0$20629$c3e8da3@news.astraweb.com> Paul LaFollette wrote: > 3) (this is purely philosophical but I am curious) Would it not be > more intuitive if > isinstance(None, ) returned true? Good grief no!!! None is an object. It has a type, NoneType. It's *not* a string, or a float, or an int, or a list, so why would you want isinstance() to *lie* and say that it is? Python is good for testing these sorts of ideas: >>> _isinstance = isinstance >>> def isinstance(obj, type): ... if obj is None: return True ... return _isinstance(obj, type) ... >>> x = "parrot" >>> if isinstance(x, str): ... print x.upper() ... PARROT >>> x = None >>> if isinstance(x, str): print x.upper() ... Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'upper' -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 02:34:00 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 16:34:00 +1000 Subject: Question about None References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: <02433a8b$0$20629$c3e8da3@news.astraweb.com> Jean-Michel Pichavant wrote: > >> def setNext(nxt): >> assert nxt==None or isinstance(nxt, Node), "next must be a Node" >> self.next = nxt >> >> works ok, but it's uglier than it ought to be. >> >> > I don't find it that ugly. It's accurate, easy to read and understand. Actually, it's inaccurate. There are *three* bugs in that code, two in the same line. (Admittedly, one of the three is closer to a nitpick than a bug.) You already allude to one of them: > "What else ?" would say a famous coffee representative. > If you like perfection, replace nxt==None by nxt is None. Delete the "if you like perfection" part. Testing for equality against None in this case is simply *wrong*. Arbitrary objects can be made to test equal to None -- for instance, the Null object pattern. Unless you wish to allow such "null" objects as well as None, then "nxt == None" does not do what you want to do: it fails to reject some things that should be rejected. The second bug is that the line uses assert for runtime value/type testing. That's bad, because asserts are disabled when you run Python with the optimisation flag. That means that your program will stop performing the necessary test. assert is for testing program logic[1], not argument testing. If you're ever tempted to write an if...elif...else block that includes the comment, "this should never happen, but just in case" then you have a good candidate for an assert. A good use for assert is for checking that your program logic is correct, not for testing user-arguments: def process(text): for word in text.split(): word = somefunction(word) # say that it's important that word contains no newlines # you're sure that somefunction() *won't* introduce any, # but you want to be positive assert "\n" not in word do_something_with(word) In this case, assert is appropriate: the code *should* work if the assert is disabled, but it will give you some protection from bugs in your code. Whenever you're tempted to use assert, ask yourself "if I deleted this test from my code, would the program still run correctly?". If the answer is "possibly not", then don't use an assert. The third bug (the nitpick) is a bug in the API: you name the argument "nxt" with no e, but in the error message, you call it "next" with an e. The fact that any intelligent person should be able to guess what parameter the error is referring to doesn't make it less wrong. So, fixing the three issues: def setNext(next): if not (next is None or isinstance(next, Node)): raise ValueError("next must be a Node") self.next = next [1] Arguably, it's also good for poor-man's unit testing when you're too lazy to write proper tests. -- Steven From randall at tnr.cc Sat Jun 13 03:23:37 2009 From: randall at tnr.cc (Randall Smith) Date: Sat, 13 Jun 2009 02:23:37 -0500 Subject: moving Connection/PipeConnection between processes Message-ID: I've got a situation in which I'd like to hand one end of a pipe to another process. First, in case you ask why, a spawner process is created early before many modules are imported. That spawner process is responsible for creating new processes and giving a proxy to the parent process. (h1-1 <-- Pipe() --> h1-2) |------------------------> child1 |(s1 < Pipe() > s2) parent -> spawner -> |--> child2 |(h2-1) <-- Pipe() --> (h2-2) |----------------------| |------------------------> child3 (h3-1 <-- Pipe() --> h3-2) When I try to pass Connection h1-1 to the parent using Connection s1, I get an error: TypeError: Required argument 'handle' (pos 1) not found This error is from unpickling the Connection h1-1. You can duplicate the error like this: pickled_connection = pickle.dumps(h1-1, 2) pickle.loads(pickled_connection) # raises the same error Looking at the pickle docs, I wonder if this could be resolved by adding a __getnewargs__ method to _multiprocessing.Connection. But even if that would work I couldn't do it now since it's an extension module. I've thought about trying to recreate the Connection. Looks like it should be possible with Connection.fileno(). The Unix portion looks easy, but the win32 portion does not. So if it's possible, what's the best way to pass a Connection to another process? Randall From mk.fraggod at gmail.com Sat Jun 13 04:11:47 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 14:11:47 +0600 Subject: moving Connection/PipeConnection between processes References: Message-ID: <20090613141147.1ed3667d@coercion> On Sat, 13 Jun 2009 02:23:37 -0500 Randall Smith wrote: > I've got a situation in which I'd like to hand one end of a pipe to > another process. First, in case you ask why, a spawner process is > created early before many modules are imported. That spawner process is > responsible for creating new processes and giving a proxy to the parent > process. > ... > > Looking at the pickle docs, I wonder if this could be resolved by adding > a __getnewargs__ method to _multiprocessing.Connection. But even if > that would work I couldn't do it now since it's an extension module. > I've thought about trying to recreate the Connection. Looks like it > should be possible with Connection.fileno(). The Unix portion looks > easy, but the win32 portion does not. > > So if it's possible, what's the best way to pass a Connection to another > process? Pickle has nothing to do with the problem since it lay much deeper: in the OS. From kernel point of view, every process has it's own "descriptor table" and the integer id of the descriptor is all the process gets, so when you say "os.pipe()" kernel actually gives you a number which is completely meaningless for any other process - it either doesn't exists in it's descriptor table or points to something else. So, what you actually need is to tell the kernel to duplicate underlying object in another process' table (with it's own numbering), which is usually done via special flag for sendmsg(2) in C, so you should probably look out for py implementation of this call, which I haven't stumbled upon, but, admittely, never looked for. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jenigirly at gmail.com Sat Jun 13 04:39:27 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:39:27 -0700 (PDT) Subject: distutils extension configuration problem References: Message-ID: <41e1431c-d486-41d1-a5ac-7514f7df7743@d2g2000pra.googlegroups.com> On May 27, 2:10?am, Ron Garret wrote: > I'm trying to build PyObjC on an Intel Mac running OS X 10.5.7. ?The > build is breaking because distutils seems to want to build extension > modules as universal binaries, but some of the libraries it depends on > are built for intel-only, i.e.: > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ python2.6 > setup.py build > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils > /dist.py:266: UserWarning: Unknown distribution option: 'options' > ? warnings.warn(msg) > running build > running build_py > running build_ext > building 'ScreenSaver._inlines' extension > gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk-g > -bundle -undefined dynamic_lookup > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o -o > build/lib.macosx-10.3-i386-2.6/ScreenSaver/_inlines.so -framework > ScreenSaver > ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file > is not of required architecture for architecture ppc > collect2: ld returned 1 exit status > lipo: can't open input file: > /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-//ccMFYRkt.out (No such > file or directory) > error: command 'gcc' failed with exit status 1 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o: Mach-O > universal binary with 2 architectures > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture ppc): Mach-O object ppc > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture i386): ? Mach-O object i386 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > /usr/local/lib/libtiff.dylib > /usr/local/lib/libtiff.dylib: Mach-O dynamically linked shared library > i386 > > How do I get distutils to stop trying to build extensions as universal > binaries? > > Thanks, > rg Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:39:45 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:39:45 -0700 (PDT) Subject: Can't run PyQt apps with MacPython References: <25cdb69b-689c-4cfe-a378-3016b3d50e50@s21g2000vbb.googlegroups.com> Message-ID: <684fce61-7e9d-4f9d-a4dd-0fa6637f4d47@u9g2000prd.googlegroups.com> On May 13, 8:53?pm, Morad wrote: > I recently got a new MacBook Pro with Leopard, and would like to > develop using Python and PyQt. I installed the latest QtSDK, updated > MacPython to V 2.5.4 and then proceeded to install SIP and PyQt as > described in Mark Summerfield's book on PyQt Programming. Everything > went fine and none of the scripts complained. However when I want to > run a demo app, I get the error message "Fatal Python error: > Interpreter not initialized (version mismatch?) / Abort Trap". Anybody > can help? Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:40:00 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:40:00 -0700 (PDT) Subject: Help AIX 5.3 build on Python-3.1a2 References: Message-ID: <97dae51e-4020-448f-90db-d9fdccdfaf99@k19g2000prh.googlegroups.com> On Apr 26, 2:14?pm, Jeroen Ruigrok van der Werven wrote: > -On [20090425 19:17], Aahz (a... at pythoncraft.com) wrote: > > >In article , > > wrote: > >>"Include/token.h", line 42.9: 1506-213 (S) Macro name TILDE cannot be > >>redefined. > >>"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line > >>250 of /usr/include/sys/ioctl.h. > > >Can you try trimming down the compilation to a small reproducible case? > > I thought it was already clear from what was provided? > > Include/token.h has a #define for TILDE and apparently AIX has a #define for > TILDE in /usr/include/sys/ioctl.h as well. So you can a redefinition. > > One way around it, depending how AIX protects headers might be to change > Include/token.h to either: > > #if defined(_SYS_IOCTL_H_) > #undef TILDE > #define TILDE ? ? ? ? ? 32 > #endif > > or > > #if defined(aix) > #undef TILDE > #define TILDE ? ? ? ? ? 32 > #endif > > -- > Jeroen Ruigrok van der Werven / asmodai > ????? ?????? ??? ?? ??????http://www.in-nomine.org/|http://www.rangaku.org/| GPG: 2EAC625B > A rose is a rose is a rose is a rose... Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:42:22 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:42:22 -0700 (PDT) Subject: moving Connection/PipeConnection between processes References: <20090613141147.1ed3667d@coercion> Message-ID: On Jun 13, 1:11?pm, Mike Kazantsev wrote: > On Sat, 13 Jun 2009 02:23:37 -0500 > > > > > > Randall Smith wrote: > > I've got a situation in which I'd like to hand one end of a pipe to > > another process. ?First, in case you ask why, a spawner process is > > created early before many modules are imported. ?That spawner process is > > responsible for creating new processes and giving a proxy to the parent > > process. > > ... > > > Looking at the pickle docs, I wonder if this could be resolved by adding > > a __getnewargs__ method to _multiprocessing.Connection. ?But even if > > that would work I couldn't do it now since it's an extension module. > > I've thought about trying to recreate the Connection. ?Looks like it > > should be possible with Connection.fileno(). ?The Unix portion looks > > easy, but the win32 portion does not. > > > So if it's possible, what's the best way to pass a Connection to another > > process? > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:42:38 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:42:38 -0700 (PDT) Subject: Lexical scope: converting Perl to Python References: <20090613114431.6f4893c7@coercion> Message-ID: On Jun 13, 10:44?am, Mike Kazantsev wrote: > On Fri, 12 Jun 2009 22:02:53 -0700 (PDT) > > > > > > Andrew Savige wrote: > > I'd like to convert the following Perl code to Python: > > > ?use strict; > > ?{ > > ?? my %private_hash = ( A=>42, B=>69 ); > > ?? sub public_fn { > > ???? my $param = shift; > > ???? return $private_hash{$param}; > > ?? } > > ?} > > ?print public_fn("A");??????? # good:? prints 42 > > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > > ... > > > What is the Pythonic equivalent of Perl's lexical scope, as > > illustrated by the code snippet above? > > If you're using scope for garbage-collecting purposes, there's "with" > statement and contextlib: > > ? from contextlib import contextmanager > > ? @contextmanager > ? def get_hash(): > ? ? complex_hash = dict(A=42, B-69) > ? ? try: yield complex_hash > ? ? except Exception as ex: > ? ? ? del complex_hash # complex destructor ;) > ? ? ? raise ex > > ? with get_hash() as hash: > ? ? # do stuff with hash > > Note that this only makes sense if you need to implement some complex > operation on hash destruction, and do that whatever-happens-inside-with > to close the object, obviously not the case with simple dict above. > > And if you want to obfuscate one part of your code from another, you'll > probably have better luck with languages like java, since no one seem > to care about such stuff with python, so it'd be a hack against the > language, at best. > Why would you want to hide the code from itself, anyway? It's not like > you'd be able to accomplish it - code can easily grep it's process body > in memory and harvest all the "private" values, so I'd suggest getting > some fresh air when you start to feel like doing that. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Check http://www.voipsipsdk.com its a good one. From piet at cs.uu.nl Sat Jun 13 04:46:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 13 Jun 2009 10:46:09 +0200 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: >>>>> Emile van Sebille (EvS) wrote: >EvS> On 6/11/2009 12:09 AM higer said... >>> Tool can certainly be used to compare two files,but I just want to >>> compare them using Python code. >>> >EvS> difflib? If I understand correctly the OP just wanted to know whether two files were equal, not what the differences would be. In that case difflib is overkill. On the other hand `equal' has many meanings. Ignoring line endings is one option, ignoring trailing whitespace could be another one. Yet another one could be normalizing the character encoding, etc. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From niels.egberts at gmail.com Sat Jun 13 05:02:20 2009 From: niels.egberts at gmail.com (Niels Egberts) Date: Sat, 13 Jun 2009 11:02:20 +0200 Subject: uncompress base64-gzipped string In-Reply-To: References: Message-ID: On Sat, Jun 13, 2009 at 4:38 AM, John Machin wrote: > | >>> guff[:100] > | '\x1b\x00\x00\x00\x1b\x00\x00\x00\x1b\x00\x00\x00 [snip] > > What a long journey: parse xml, base64 decode, gunzip, > and you're still not home; next stop is struct.unpack ... > > HTH, > John Thanks for the help! I dont think I could have done that. And thanks for the tip on struct.unpack I managed to get a list of integers to work with. Niels From simon212 at gmx.de Sat Jun 13 05:12:02 2009 From: simon212 at gmx.de (Simon) Date: Sat, 13 Jun 2009 11:12:02 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> Message-ID: <4A336D62.6070302@gmx.de> Christian Heimes wrote: > Simon schrieb: >> Christian Heimes wrote: >>> Simon wrote: >>>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >>>> openSUSE 11.1 x86_64) via 'make altinstall'. >>>> >>>> First, I tried to configure with the following flags: >>>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>>> This provoked an error during compilation via make (sorry, the list was >>>> so long, but I will post it, if it helps). >>> --enable-framework is for Mac OS X only. >>> >>>> Second, configured again without any flags. The installation by 'make >>>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>>> too. So, I got my parallel installation. >>> You have chosen the correct and canonical way to install a parallel >>> installation of Python. >>> >>>> However, I cannot import modules like Tkinter or readline within >>>> python2.4. >>> You must install the development library of tk, readline, zlib and >>> libbz2 prior to configure && make. >>> >>> Try this on your box: >>> >>> zypper install gcc make autoconf automake libtool zlib-devel >>> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >>> libopenssl-devel >>> >> >> Unfortunately, I got the following errors, while compiling via make. >> Please, see attached text file for details about everything I did from >> installing the missing packages via zypper until make. > > zypper should have installed all necessary dependencies, including a > whole bunch of X11 headers. Something seems to be wrong on your system > or SuSE's package dependencies. > I know why I dislike SuSE. :) Although I started my Linux career 12 > years ago with SuSE I prefer Debian based systems since Woody came out > in 2002. :) > >> X11 says: >> Program 'X11' is present in package 'xorg-x11', which is installed on >> your system. > > zypper search X11 | grep devel > ... > zypper install xorg-x11-devel > > That should (hopefully) do the trick. On a Debian based systems it's > much easier to install all Python dependencies with "apt-get build-dep > python2.5" > > To quote SuSE: "Have a lot of fun ..." > > Und viel Gl?ck! > > Christian > Danke :) On Monday, I will be able to tell if it worked out, or if I have to try a new strategy, e.g. to convince the admin about (K)ubuntu. From anthra.norell at bluewin.ch Sat Jun 13 05:30:37 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 13 Jun 2009 11:30:37 +0200 Subject: CAD file format specifications? In-Reply-To: <4A32AD8D.2010000@geniusdv.com> References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> Message-ID: <4A3371BD.70508@bluewin.ch> Andres Acosta wrote: > HI there Anthara have you checked out www.Blender.org, It is open > source and accepts a lot of your formats. for import and export. > Anrdres > Anthra Norell wrote: >> Hi, >> Anyone working with CAD who knows about numeric data entry? I have >> 3d coordinates of a construction site on a slope (borders, setbacks >> and isometric elevation lines). Someone made me aware of Google's >> Sketch Up. It looks very attractive for the purpose of architectural >> planning, especially suited to create visual impressions. Doodling >> seems easy. But I have to start with modeling the terrain and the >> envelope and the only way to do that seems to be in one of several >> CAD file formats (skp, dwg, dxf, 3ds, ddf and dem). So I need to cast >> my numbers into one of these formats. Any suggestions? >> >> Thanks >> >> Frederic >> > > Andres, Thanks for the tip. I wasn't aware of Blender. The web page looks promising. I downloaded it and am going to have a look at it. Frederic From koranthala at gmail.com Sat Jun 13 07:42:16 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 04:42:16 -0700 (PDT) Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> Message-ID: <5c4984a4-bd51-424b-8165-7b226eaddb96@o5g2000prh.googlegroups.com> On Jun 13, 10:25?am, Mike Kazantsev wrote: > On Thu, 11 Jun 2009 22:35:15 -0700 > Dennis Lee Bieber wrote: > > > > > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > > declaimed the following in > > gmane.comp.python.general: > > > > I sent this to the Tutor mailing list and did not receive a response. > > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > > remarks? > > > > Please reply off-list and thanks in advance. Code examples are below in > > > plain text. > > > ? ?Sorry -- you post to a public forum, expect to get the response on a > > public forum... > > > > > My program runs interactively by allowing the user to directly > > > > interact with the python prompt. This program has a runAll() method > > > > that runs a series of subprocesses with a cap on how many instances > > > > are running at a time. My intent is to allow the user to use Ctrl-C to > > > > break these subprocesses. Note that while not reflected in the demo > > > ? ?Are they subprocesses or threads? Your sample code seems to be using > > threads. > > > ? ?When using threads, there is no assurance that any thread other than > > the main program will receive a keyboard interrupt. > > In fact, no thread other than the main will get interrupt. > > > > > > def runAll(): > > > ? ? workers = [ Thread(target = runSingle, args = [i]) > > > ? ? ? ? ? ? for i in xrange(MAX_SUBPROCS + 1) ] > > > ? ? try: > > > ? ? ? ? for w in workers: > > > ? ? ? ? ? ? w.start() > > > ? ? except KeyboardInterrupt: > > > ? ? ? ? ## I want this to be shown on a KeyboardInterrupt > > > ? ? ? ? print '********* stopped midway ********' > > > ? ?You are unlikely to see that... After you start the defined worker > > /threads/ (which doesn't take very long -- all threads will be started, > > but some may immediately block on the semaphore) this block will exit > > and you will be at... > > > > ? ? for w in workers: > > > ? ? ? ? w.join() > > > ? ?... a .join() call, which is the most likely position at which the > > keyboard interrupt will be processed, killing the main program thread > > and probably generating some errors as dangling active threads are > > forceably killed. > > There was quite interesting explaination of what happens when you send > ^C with threads, posted on concurrency-sig list recently: > > ?http://blip.tv/file/2232410 > ?http://www.dabeaz.com/python/GIL.pdf > > Can be quite shocking, but my experience w/ threads only confirms that. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Thank you very much for the link Mike. Are there other videos/audio like this? I am learning more from these videos than by experience alone. I did find one - http://www.awaretek.com/python/ - are there other links? From ivlenin at gmail.com Sat Jun 13 07:48:28 2009 From: ivlenin at gmail.com (I V) Date: 13 Jun 2009 13:48:28 +0200 Subject: Lexical scope: converting Perl to Python References: Message-ID: <4a33920c@news.x-privat.org> On Fri, 12 Jun 2009 22:02:53 -0700, Andrew Savige wrote: > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. You might try: def public_fn(param): private_hash = publicfn.private_hash return private_hash[param] public_fn.private_hash = {'A':42, 'B':69} (You don't have to assign public_fn.private_hash to a local variable, but you might want to, to avoid extra typing, if you refer to private_hash more than a couple of times in the function). From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 08:15:21 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 22:15:21 +1000 Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <4a3270b8$1_7@news.bluewin.ch> Message-ID: <02438a8b$0$20617$c3e8da3@news.astraweb.com> Boris Borcic wrote: > This reminds me of an early programming experience that left me with a > fascination. At a time where code had to fit in a couple dozens kilobytes, > I once had to make significant room in what was already very tight and > terse code. Code factoring *did* provide the room in the end, but the > fascinating part came before. > > There was strictly no redundancy apparent at first, and finding a usable > one involved contemplating code execution paths for hours until some > degree of similarity was apparent between two code path families. And > then, the fascinating part, was to progressively mutate both *away* from > minimality of code, in order to enhance the similarity until it could be > factored out. > > I was impressed; in various ways. First; that the effort could be > characterized quite mechanically and in a sense stupidly as finding a > shortest equivalent program, while the subjective feeling was that the > task exerted perceptive intelligence to the utmost. Second; by the notion > that a global constraint of code minimization could map more locally to a > constraint that drew code to expand. Third; that the process resulted in > bottom-up construction of what's usually constructed top-down, mimicking > the willful design of the latter case, eg. an API extension, as we might > call it nowadays. This is much the same that happens in maximisation problems: the value gets trapped in a local maximum, and the only way to reach a greater global maximum is to go downhill for a while. I believe that hill-climbing algorithms allow some downhill movement for just that reason. Genetic algorithms allow "mutations" -- and of course real evolution of actual genes also have mutation. -- Steven From nick at craig-wood.com Sat Jun 13 08:29:35 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 13 Jun 2009 07:29:35 -0500 Subject: Lexical scope: converting Perl to Python References: Message-ID: Andrew Savige wrote: > > I'd like to convert the following Perl code to Python: > > ?use strict; > ?{ > ?? my %private_hash = ( A=>42, B=>69 ); > ?? sub public_fn { > ???? my $param = shift; > ???? return $private_hash{$param}; > ?? } > ?} > ?print public_fn("A");??????? # good:? prints 42 > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > > The real code is more complex; the above is a simplified example. > > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. > > While I could convert this code to the following Python code: > > ?private_hash = dict( A=42, B=69 ) > ?def public_fn(param): > ?? return private_hash[param] > ?print public_fn("A")???? # good:? prints 42 > ?x = private_hash["A"]??? # works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. > > Of course, I could hide the hash like so: > > ?def public_fn(param): > ?? private_hash = dict( A=42, B=69 ) > ?? return private_hash[param] > > yet I'm not happy with that either because of the repeated > initialization the hash each time the function is called. > > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? Either _private_hash = dict( A=42, B=69) def public_fn(param): return _private_hash[param] Or def public_fn(param, _private_hash = dict( A=42, B=69)): return _private_hash[param] Is probably the pythonic equivalents. Note that private_hash starts with an underscore which means it won't be exported from a module by default and it is a convention that it is private and shouldn't be fiddled with. I'd probably go with the latter of the two examples. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mk.fraggod at gmail.com Sat Jun 13 08:35:48 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 18:35:48 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <5c4984a4-bd51-424b-8165-7b226eaddb96@o5g2000prh.googlegroups.com> Message-ID: <20090613183548.017849b5@coercion> On Sat, 13 Jun 2009 04:42:16 -0700 (PDT) koranthala wrote: > Are there other videos/audio like this? I am learning more from these > videos than by experience alone. Indeed, it is a very interesting presentation, but I'm afraid I've stumbled upon it just as you did, but on concurrency-sig mailing list. It's a relatively new list (now hosted on mail.python.org), not specifically dedicated to podcasts or, for that matter, any implementation details. I haven't seen any other material like this there. > I did find one - http://www.awaretek.com/python/ - are there other > links? Thanks for sharing this link, although I prefer such information in written form - it's easier/faster to work with and much more accessible. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From piet at cs.uu.nl Sat Jun 13 09:06:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 13 Jun 2009 15:06:09 +0200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: >>>>> Nikolaus Rath (NR) wrote: >NR> Is there a way to have the obj variable (that is created in dostuff()) >NR> destroyed earlier than at the end of the program? As you can see, I >NR> already tried to explicitly call the garbage collector, but this does >NR> not help. The exact time of the destruction of objects is an implementation detail and should not be relied upon. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From bborcic at gmail.com Sat Jun 13 09:48:54 2009 From: bborcic at gmail.com (K4NTICO) Date: Sat, 13 Jun 2009 06:48:54 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <4a3270b8$1_7@news.bluewin.ch> <02438a8b$0$20617$c3e8da3@news.astraweb.com> Message-ID: <6efc3531-dbf2-4b8c-a2f0-a756ef2411f5@c36g2000yqn.googlegroups.com> On 13 juin, 14:15, Steven D'Aprano wrote: > Boris Borcic wrote: > > This reminds me of an early programming experience that left me with a > > fascination. At a time where code had to fit in a couple dozens kilobytes, > > I once had to make significant room in what was already very tight and > > terse code. Code factoring *did* provide the room in the end, but the > > fascinating part came before. > > > There was strictly no redundancy apparent at first, and finding a usable > > one involved contemplating code execution paths for hours until some > > degree of similarity was apparent between two code path families. And > > then, the fascinating part, was to progressively mutate both *away* from > > minimality of code, in order to enhance the similarity until it could be > > factored out. > > > I was impressed; in various ways. First; that the effort could be > > characterized quite mechanically and in a sense stupidly as finding a > > shortest equivalent program, while the subjective feeling was that the > > task exerted perceptive intelligence to the utmost. Second; by the notion > > that a global constraint of code minimization could map more locally to a > > constraint that drew code to expand. Third; that the process resulted in > > bottom-up construction of what's usually constructed top-down, mimicking > > the willful design of the latter case, eg. an API extension, as we might > > call it nowadays. > > This is much the same that happens in maximisation problems: the value gets > trapped in a local maximum, and the only way to reach a greater global > maximum is to go downhill for a while. > > I believe that hill-climbing algorithms allow some downhill movement for > just that reason. Genetic algorithms allow "mutations" -- and of course > real evolution of actual genes also have mutation. > > -- > Steven Indeed exactly. But it wasn't quite the same to think through it first hand, as I said that the subjective feeling was "perceptive intelligence got exercized to the utmost". To illustrate, it is very much the memory of that experience - the perceptive training - that made me notice, for another high point, what I think to be a common factor worthy of capture between the sociology of Archimedes' Eureka and that of Einstein's E=mc^2, let's just describe Archimedes' case in the right manner: There is a trading port city, and thus citizens who are experts in both floating ships on the seas and of weighting goods on the scale in the markets. And then comes Archimedes who says : "hey, experts, I show you that these two aeras of your expertise that of course you think have nothing to do with each other except for what you know so well and clear - they are in fact two faces of a single coin that you ignore." And thus a codeful question : "What does F(Syracuse) hear if F(Eureka) is the = in E=mc^2 ?" And a more serious one : what happens to the potential for similar discoveries, when society specializes expertise to the point that there isn't any more any community of "simultaneous experts" ? Cheers, BB -- "Hope achieves the square root of the impossible" From benjamin at python.org Sat Jun 13 10:46:28 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Jun 2009 09:46:28 -0500 Subject: [RELEASED] Python 3.1 Release Candidate 2 Message-ID: <1afaf6160906130746v2d951486v7a52d7b838070189@mail.gmail.com> On behalf of the Python development team, I'm happy to announce the second release candidate of Python 3.1. Python 3.1 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/dev/py3k/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a release candidate, and as such, we do not recommend use in production environments. However, please take this opportunity to test the release with your libraries or applications. This will hopefully discover bugs before the final release and allow you to determine how changes in 3.1 might impact you. If you find things broken or incorrect, please submit a bug report at http://bugs.python.org For more information and downloadable distributions, see the Python 3.1 website: http://www.python.org/download/releases/3.1/ See PEP 375 for release schedule details: http://www.python.org/dev/peps/pep-0375/ Enjoy, -- Benjamin Benjamin Peterson benjamin at python.org Release Manager (on behalf of the entire python-dev team and 3.1's contributors) From mwilson at the-wire.com Sat Jun 13 11:25:27 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 13 Jun 2009 11:25:27 -0400 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: Gunter Henriksen wrote: [ ... ] > I guess to me, fundamentally, the interpretation of > tuple as a sequence whose elements have semantic meaning > implicitly defined by position is a relatively abstract > intrepretation whose value is dubious relative to the > value of immutability, since it seems like a shortcut > which sacrifices explicitness for the sake of brevity. The immutability makes it easier to talk about the semantic meanings. After you do > event_timestamp = (2009, 06, 04, 05, 02, 03) there's nothing that can happen to the tuple to invalidate > (year, month, day, hour, minute, second) = event_timestamp even though, as you say, there's nothing in the tuple to inform anybody about the year, month, day, ... interpretation. And of course there's nothing in a C struct object that isn't in the equivalent Python tuple. The difference is that the C compiler has arranged all the outside code that uses the struct object to use it in the correct way. The only object I've found in Python that truly replaces a struct object in C is a dict with string keys -- or an object that uses such a dict as its __dict__. Mel. From emailkgnow at gmail.com Sat Jun 13 11:26:24 2009 From: emailkgnow at gmail.com (Khalid) Date: Sat, 13 Jun 2009 08:26:24 -0700 (PDT) Subject: Python 3.1 Release Candidate 2 References: Message-ID: <94c36f68-b537-4bb2-a139-a9397d25bf6e@k17g2000prn.googlegroups.com> On Jun 13, 5:46?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy to announce the second > release candidate of Python 3.1. > > Python 3.1 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/dev/py3k/whatsnew/3.1.htmlor Misc/NEWS in the Python > distribution. > > This is a release candidate, and as such, we do not recommend use in production > environments. ?However, please take this opportunity to test the release with > your libraries or applications. ?This will hopefully discover bugs before the > final release and allow you to determine how changes in 3.1 might impact you. > If you find things broken or incorrect, please submit a bug report at > > ? ? ?http://bugs.python.org > > For more information and downloadable distributions, see the Python 3.1 website: > > ? ? ?http://www.python.org/download/releases/3.1/ > > See PEP 375 for release schedule details: > > ? ? ?http://www.python.org/dev/peps/pep-0375/ > > Enjoy, > -- Benjamin > > Benjamin Peterson > benjamin at python.org > Release Manager > (on behalf of the entire python-dev team and 3.1's contributors) GOOD NEWS ... THANKS From koranthala at gmail.com Sat Jun 13 11:49:52 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 08:49:52 -0700 (PDT) Subject: Good books in computer science? Message-ID: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Hi all, I do understand that this is not a python question and I apologize for that straight up. But I am a full time follower of this group and I have seen very very brilliant programmers and solutions. I also want to be a good programmer - so this question. Which are the classic books in computer science which one should peruse? I have (a) Code Complete (b) GOF (c) Art of programming. Art of programming was too tough for me - and I couldnt understand much. The other two were good books - I understood and implemented quite a bit from both. What are the other books which I should peruse? Regards K From python at bdurham.com Sat Jun 13 12:27:22 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 13 Jun 2009 12:27:22 -0400 Subject: Good books in computer science? In-Reply-To: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <1244910442.4624.1320224723@webmail.messagingengine.com> Timeless classics - highly recommended: Software Tools by Plaugher Mythical Man Month by Brooks Malcolm From tjreedy at udel.edu Sat Jun 13 12:27:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Jun 2009 12:27:45 -0400 Subject: Question about None In-Reply-To: <02433a8b$0$20629$c3e8da3@news.astraweb.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> <02433a8b$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: [ snip excellent discussion of proper use of assert] > The third bug (the nitpick) is a bug in the API: you name the argument "nxt" > with no e, but in the error message, you call it "next" with an e. The fact > that any intelligent person should be able to guess what parameter the > error is referring to doesn't make it less wrong. > > So, fixing the three issues: > > def setNext(next): > if not (next is None or isinstance(next, Node)): > raise ValueError("next must be a Node") > self.next = next [counternit] Of course, next() is a builtin function and some consider reusing builtin names as bare names (versus attribute names) a bad habit. I think the OP had a good idea in using a variation, but should have been consistent. From Scott.Daniels at Acm.Org Sat Jun 13 12:29:02 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 13 Jun 2009 09:29:02 -0700 Subject: uncompress base64-gzipped string In-Reply-To: References: Message-ID: Niels Egberts wrote: > On Sat, Jun 13, 2009 at 4:38 AM, John Machin wrote: > ... > And thanks for the tip on struct.unpack I managed to get a list of > integers to work with. You might make do with array.fromstring (perhaps using .byteswap afterwards) to get your numbers if you are talking more than a handful. --Scott David Daniels Scott.Daniels at Acm.Org From http Sat Jun 13 12:56:18 2009 From: http (Paul Rubin) Date: 13 Jun 2009 09:56:18 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <7xocssvzrh.fsf@ruckus.brouhaha.com> koranthala writes: > Which are the classic books in computer science which one should > peruse? > I have (a) Code Complete (b) GOF (c) Art of programming. > > Art of programming was too tough for me - and I couldnt understand > much. The other two were good books - I understood and implemented > quite a bit from both. > What are the other books which I should peruse? Code Complete and GOF are software engineering books but not really CS books. TAOCP is a CS book but a bit old fashioned. Other classics: Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman (online at mitpress.mit.edu/sicp) From gallium.arsenide at gmail.com Sat Jun 13 13:23:38 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 10:23:38 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> Message-ID: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> On Jun 13, 2:29 am, Steven D'Aprano wrote: > Paul LaFollette wrote: > > 3) (this is purely philosophical but I am curious) > > Would it not be more intuitive if > > isinstance(None, ) returned true? > > Good grief no!!! > > None is an object. It has a type, NoneType. It's *not* a > string, or a float, or an int, or a list, so why would > you want isinstance() to *lie* and say that it is? Because you might want None to behave as though it were nothing at all. Paul LaFollette is probably thinking along the lines of formal logic or set theory. It's a little bit confused because programming isn't quite the same as math, and so it's a common question when designing and implementing programming languages how far to take certain abstractions. In some languages, nil, null, or none will try to behave as mathematically close to "nothing" (complete absence of anything) as possible, even though in reality they have to have some concrete implementation, such as perhaps being a singleton object. But mathematically speaking, it's intuitive that "nothing" would match any type. I find that it's somewhat like the confusion that often occurs regarding the all() function. Some people are surprised that all([]) returns True, but it's the same logic behind the truth of the statement "every element of the empty set is an integer". It's also true that every element of the empty set is a float. Or an elephant. John From koranthala at gmail.com Sat Jun 13 13:37:13 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 10:37:13 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: > Code Complete and GOF are software engineering books but not really > CS books. I understand and concur. Since I am a software engineer - coming in to software from a different background - what I am looking for is self- improvement books for a software engineer. This can include both CS and Software books - even though I found that CS books are much less understandable to me :-) From http Sat Jun 13 13:49:12 2009 From: http (Paul Rubin) Date: 13 Jun 2009 10:49:12 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <7xr5xovxbb.fsf@ruckus.brouhaha.com> John Yeung writes: > Because you might want None to behave as though it were nothing at all. Sure, you might also want strings to behave as if they were ints, but wishing doesn't make it so. > But mathematically speaking, it's intuitive that "nothing" would match > any type. Completely wrong. The concept you're thinking of in denotational semantics is called "bottom", but bottom is not a value that functions can compute and return. It is really the absence of a value. We would say that a function semantically returns bottom, if calling does something like loop forever (never return), or it makes the program crash, or something like that. None is a value which in Haskell has a particular type. In some other languages, there are None-like values in more than one type, like in Haskell, for any type there is a Nothing for the Maybe of that type, but they all are of differing types, just like Python has an integer 0 and a floating point 0 that are of differing types. > I find that it's somewhat like the confusion that often occurs > regarding the all() function. It's the other way though, all([])=True makes sense, isinstance(None,int) does not. From http Sat Jun 13 13:55:01 2009 From: http (Paul Rubin) Date: 13 Jun 2009 10:55:01 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xr5xovxbb.fsf@ruckus.brouhaha.com> Message-ID: <7xiqj0vx1m.fsf@ruckus.brouhaha.com> Paul Rubin writes: > crash, or something like that. None is a value which in Haskell has a I got ahead of myself, of course I meant Python (the *next* sentence was going to mention Haskell). The corresponding concept in Haskell is called Nothing, which lives in a type functor called Maybe. I don't have time to go into it right now but there is a notion among language weenies these days that the presence of something like None (in Python) or Null (in Java, SQL, etc) is a wart in a language and that it's preferable to have something like Maybe. From randall at tnr.cc Sat Jun 13 14:02:24 2009 From: randall at tnr.cc (Randall Smith) Date: Sat, 13 Jun 2009 13:02:24 -0500 Subject: moving Connection/PipeConnection between processes In-Reply-To: <20090613141147.1ed3667d@coercion> References: <20090613141147.1ed3667d@coercion> Message-ID: Mike Kazantsev wrote: > On Sat, 13 Jun 2009 02:23:37 -0500 > Randall Smith wrote: > >> I've got a situation in which I'd like to hand one end of a pipe to >> another process. First, in case you ask why, a spawner process is >> created early before many modules are imported. That spawner process is >> responsible for creating new processes and giving a proxy to the parent >> process. >> > ... >> Looking at the pickle docs, I wonder if this could be resolved by adding >> a __getnewargs__ method to _multiprocessing.Connection. But even if >> that would work I couldn't do it now since it's an extension module. >> I've thought about trying to recreate the Connection. Looks like it >> should be possible with Connection.fileno(). The Unix portion looks >> easy, but the win32 portion does not. >> >> So if it's possible, what's the best way to pass a Connection to another >> process? > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > As I was referring to earlier, Unix is easy. fd = mycon.fileno() new_con = _multiprocessing.Connection(os.dup(fd)) But Windows? The implementation of the pipe creation is on line 167 of connection.py. I don't know where to start. Randall From no.email at please.post Sat Jun 13 14:11:11 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 18:11:11 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? Message-ID: Switching from Perl here, and having a hard time letting go... Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, second, and last element in that array. In Perl I could write: my @wanted = @foo[3, 7, 1, -1]; I was a bit surprised when I got this in Python: >>> wanted = foo[3, 7, 1, -1] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers Granted, Perl's syntax is often obscure and hard-to-read, but in this particular case I find it quite transparent and unproblematic, and the fictional "pythonized" form above even more so. The best I've been able to come up with in Python are the somewhat Perl-like-in-its-obscurity: >>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) or the clearer but unaccountably sesquipedalian >>> wanted = [foo[i] for i in 3, 7, 1, -1] >>> wanted = [foo[3], foo[7], foo[7], foo[-1]] Are these the most idiomatically pythonic forms? Or am I missing something better? TIA! kynn From nate at nathanstoddard.com Sat Jun 13 14:13:15 2009 From: nate at nathanstoddard.com (Nathan Stoddard) Date: Sat, 13 Jun 2009 18:13:15 +0000 (UTC) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: On Sat, 13 Jun 2009 08:49:52 -0700, koranthala wrote: > Hi all, > I do understand that this is not a python question and I apologize > for that straight up. > But I am a full time follower of this group and I have seen very > very brilliant programmers and solutions. > I also want to be a good programmer The best way to become a good programmer is to program. Write a lot of code; work on some large projects. This will improve your skill more than anything else. It's also important to learn new languages regularly. I recommend to learn C, Python, and Lisp first. > Which are the classic books in computer science which one should > peruse? A list of some good books is at steve.yegge.googlepages.com/ten-great- books. Also read programming blogs. -- Nathan Stoddard, http://nathanstoddard.com From jackdied at gmail.com Sat Jun 13 15:17:56 2009 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Jun 2009 15:17:56 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: On Sat, Jun 13, 2009 at 2:11 PM, kj wrote: > > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. ?In Perl I could write: > > ?my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > >>>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > ?File "", line 1, in > TypeError: list indices must be integers > > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > >>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > >>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? ?Or am I missing > something better? > There is only so much room in the syntax for common cases before you end up with ... perl (no offense intended, I'm a perl monk[1]). The Python grammar isn't as context sensitive or irregular as the perl grammar so mylist[1,2,3] so the "1,2,3" tuple is always interpreted as a tuple and the square brackets always expect an int or a slice. Not including special cases everywhere means there isn't a short way to handle special cases but it also means human readers have to remember fewer special cases. Perl and Python make different tradeoffs in that respect. -Jack [1] http://www.perlmonks.org/?node_id=111952 From nick at craig-wood.com Sat Jun 13 15:29:34 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 13 Jun 2009 14:29:34 -0500 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: kj wrote: > > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > > >>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers You've just tried to index a list with a tuple... If foo was a dictionary then this might make sense. > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > > >>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > > >>> wanted = [foo[i] for i in 3, 7, 1, -1] > >>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? Or am I missing > something better? Firstly run "import this" at the python interactive interpreter to remind youself of the philosophical differences between perl and python. I think the philosophy of python is the major reason why it is such a good language. As I transitioned from perl to python it took me a while to let go of perlisms, and get used to writing a little bit more code (usually of the order of a few characters only) but which was much much clearer. Perl is full of cleverness which give you great pleasure to write as a programmer. However when you or someone else looks at that code later they don't get that same pleasure - horror is more likely the reaction! Python just isn't like that. I'd probably write wanted = foo[3], foo[7], foo[1], foo[-1] (assuming you didn't mind having a tuple rather than a list) or maybe this wanted = [ foo[i] for i in 3, 7, 1, -1 ] However I can't think of the last time I wanted to do this - array elements having individual purposes are usually a sign that you should be using a different data structure. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From brian at sweetapp.com Sat Jun 13 15:44:02 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 20:44:02 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <4A340182.5070609@sweetapp.com> kj wrote: > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; Could you explain your use case? It could be that a list isn't the appropriate data structure. Cheers, Brian From arnodel at googlemail.com Sat Jun 13 15:59:49 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 13 Jun 2009 20:59:49 +0100 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: kj writes: > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > >>>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers > > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > >>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > >>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? Or am I missing > something better? You're missing operator.itemgetter: >>> from operator import itemgetter >>> foo = "spam & eggs" >>> itemgetter(3, 7, 1, -1)(foo) ('m', 'e', 'p', 's') >>> -- Arnaud From travisaltman at gmail.com Sat Jun 13 16:05:32 2009 From: travisaltman at gmail.com (Travis Altman) Date: Sat, 13 Jun 2009 16:05:32 -0400 Subject: https post request Message-ID: i'm trying to make a https post request, i'm following the example linked below. http://www.java2s.com/Tutorial/Python/0420__Network/SendinganHTTPPOSTRequestfromaPythonScript.htm i'm trying to make the https post request to netflix.com, below is my code 1 import httplib 2 3 # def statement used to parse response from web server 4 def printText(txt): 5 lines = txt.split('\n') 6 for lines in lines: 7 print line.strip() 8 9 # connect to web server 10 httpServ = httplib.HTTPSConnection("https://www.netflix.com", 443) 11 print httpServ 12 httpServ.connect() 13 14 # specifying the exact login URL 15 16 request = "test" 17 18 httpServ.request('POST', \ 19 '/Login', \ 20 'nextpage=http%3A%2F%2Fwww.netflix.com %2F&SubmitButton=Click+Here+to+Continue&movieid=&trkid=&email=email% 40gmail.com&password1=supersecret % request') 21 22 # response 23 24 response = httpServ.getresponse() 25 26 print response 27 if response.status == httplib.OK: 28 printText (response.read()) 29 30 httpServ.close() getting the following errors, any suggestions? Traceback (most recent call last): File "printerPythonScript.py", line 12, in httpServ.connect() File "/usr/lib/python2.5/httplib.py", line 1130, in connect sock.connect((self.host, self.port)) File "", line 1, in connect socket.gaierror: (-5, 'No address associated with hostname') -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstrickler at gmail.com Sat Jun 13 16:11:46 2009 From: jstrickler at gmail.com (John S) Date: Sat, 13 Jun 2009 13:11:46 -0700 (PDT) Subject: Lexical scope: converting Perl to Python References: Message-ID: On Jun 13, 8:29?am, Nick Craig-Wood wrote: > Andrew Savige wrote: > > > ?I'd like to convert the following Perl code to Python: > > > ??use strict; > > ??{ > > ??? my %private_hash = ( A=>42, B=>69 ); > > ??? sub public_fn { > > ????? my $param = shift; > > ????? return $private_hash{$param}; > > ??? } > > ??} > > ??print public_fn("A");??????? # good:? prints 42 > > ??my $x = $private_hash{"A"};? # error: good, hash not in scope > > > ?The real code is more complex; the above is a simplified example. > > > ?Notice that this code uses Perl's lexical scope to hide the > > ?%private_hash variable, but not the public_fn() function. > > > ?While I could convert this code to the following Python code: > > > ??private_hash = dict( A=42, B=69 ) > > ??def public_fn(param): > > ??? return private_hash[param] > > ??print public_fn("A")???? # good:? prints 42 > > ??x = private_hash["A"]??? # works: oops, hash is in scope > > > ?I'm not happy with that because I'd like to limit the scope of the > > ?private_hash variable so that it is known only inside public_fn. > > > ?Of course, I could hide the hash like so: > > > ??def public_fn(param): > > ??? private_hash = dict( A=42, B=69 ) > > ??? return private_hash[param] > > > ?yet I'm not happy with that either because of the repeated > > ?initialization the hash each time the function is called. > > > ?What is the Pythonic equivalent of Perl's lexical scope, as > > ?illustrated by the code snippet above? > > Either > > _private_hash = dict( A=42, B=69) > > def public_fn(param): > ? ? return _private_hash[param] > > Or > > def public_fn(param, _private_hash = dict( A=42, B=69)): > ? ? return _private_hash[param] > > Is probably the pythonic equivalents. ?Note that private_hash starts > with an underscore which means it won't be exported from a module by > default and it is a convention that it is private and shouldn't be > fiddled with. ?I'd probably go with the latter of the two examples. > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Another approach is to just use a class to hold the data, and a class method (AKA classmethod) to access the data: # class definition class my_util(object): _private_hash = { 'A':42,'B':69 } @classmethod def public_fn(cls,index): return cls._private_hash[index] # usage print my_util.public_fn('A') print my_util.public_fn('B') This keeps pretty close to the OP's intention. It does require you to use the class name, but that's.....OK, and better than an anonymous block IMHO. Note: I'm a recovering Perl hacker. From gallium.arsenide at gmail.com Sat Jun 13 16:25:28 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 13:25:28 -0700 (PDT) Subject: Question about None References: 7xr5xovxbb.fsf@ruckus.brouhaha.com Message-ID: On Jun 13, 1:49?pm, Paul Rubin wrote: > John Yeung writes: > > Because you might want None to behave as though it were > > nothing at all. > > Sure, you might also want strings to behave as if they > were ints, but wishing doesn't make it so. I'm not saying that the OP, as a programmer using Python, would wish that Python's None behaves like nothing. I'm saying that as a philosophical question, which is how he phrased it, one might want one's language (perhaps one is designing this language) to have something that behaves like "nothing", and then call this "None". I don't think he's saying that the wrong choice was made for Python; I'm certainly not saying that; it was just a musing. > > But mathematically speaking, it's intuitive that > > "nothing" would match any type. > > Completely wrong. ?The concept you're thinking of in > denotational semantics is called "bottom", but bottom > is not a value that functions can compute and return. >?It is really the absence of a value. I've never heard a mathematician use the term "bottom". It certainly could be that I just haven't talked to the right types of mathematicians. I'm not sure it's even relevant. "Denotational semantics" is specific to computer science. My point was simply that even an elementary understanding of mathematics (and I'll grant a naive understanding of computer science as well) might lead someone to think that it *might* make sense for None to be the name for nothing. > > I find that it's somewhat like the confusion that often > > occurs regarding the all() function. > > It's the other way though, all([])=True makes sense, > isinstance(None,int) does not. Look, even a lot of the people on this very list, who answer questions as if they are experts, have been tripped up by all(). I am not here to say they are stupid. I also do not mean to present myself as an expert, whether in math, computer science, or Python in particular. I'm just trying to present the reasoning someone (however naive) might have to even bring up the possibility that it might make sense for isinstance(None, foo) to be True for any foo. I probably would not have been prompted to respond in the first place if Steven D'Aprano hadn't deemed the notion to require three exclamation points to shoot down. I think it is enough to say that None is an object and it has a specific type, thus it shouldn't match any other type; which is what he then said, albeit excitedly. ;) John From rhodri at wildebst.demon.co.uk Sat Jun 13 16:52:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 21:52:09 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 13 Jun 2009 18:37:13 +0100, koranthala wrote: > >> Code Complete and GOF are software engineering books but not really >> CS books. > > I understand and concur. Since I am a software engineer - coming in to > software from a different background - what I am looking for is self- > improvement books for a software engineer. In that case The Mythical Man-Month (Brooks) is a must. -- Rhodri James *-* Wildebeest Herder to the Masses From no.email at please.post Sat Jun 13 16:56:54 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 20:56:54 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In Jack Diederich writes: >There is only so much room in the syntax for common cases before you >end up with ... perl (no offense intended, I'm a perl monk[1]). The >Python grammar isn't as context sensitive or irregular as the perl >grammar so mylist[1,2,3] so the "1,2,3" tuple is always interpreted >as a tuple and the square brackets always expect an int or a slice. >Not including special cases everywhere means there isn't a short way >to handle special cases but it also means human readers have to >remember fewer special cases. Perl and Python make different >tradeoffs in that respect. OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be ambiguous: does it mean the fourth element of foo, or the tuple consisting of this element alone? I suppose that's good enough reason to veto this idea... Thanks for all the responses. kynn From rhodri at wildebst.demon.co.uk Sat Jun 13 16:58:10 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 21:58:10 +0100 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: On Sat, 13 Jun 2009 06:02:53 +0100, Andrew Savige wrote: > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? The useful (to you) pythonic answer depends rather a lot on why you want to do something like that. While you've been given several possibilities, the "correct" answer might well be "don't do that at all" :-) -- Rhodri James *-* Wildebeest Herder to the Masses From no.email at please.post Sat Jun 13 17:00:34 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 21:00:34 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In Nick Craig-Wood writes: >However I can't think of the last time I wanted to do this - array >elements having individual purposes are usually a sign that you should >be using a different data structure. In the case I was working with, was a stand-in for the value returned by some_match.groups(). The match comes from a standard regexp defined elsewhere and that captures more groups than I need. (This regexp is applied to every line of a log file.) kj From jstrickler at gmail.com Sat Jun 13 17:08:27 2009 From: jstrickler at gmail.com (John S) Date: Sat, 13 Jun 2009 14:08:27 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 10, 12:13?am, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > Here's the code I started with: > > >>> rePatt = re.compile('\d+\s') > >>> iterator = rePatt.finditer(string) > >>> count = 0 > >>> for match in iterator: > > ? ? ? ? if count < 1: > ? ? ? ? ? ? ? ? print string[0:match.start()] + ' INSERT ' + string[match.start > ():match.end()] > ? ? ? ? elif count >= 1: > ? ? ? ? ? ? ? ? print ' INSERT ' + string[match.start():match.end()] > ? ? ? ? count = count + 1 > > My code returns an empty string. > > I'm new to Python, but I'm finding it really enjoyable (with the > exception of this challenging puzzle). > > Thanks in advance. I like using a *callback* function instead of *plain text* with the re.sub() method. To do this, call the sub() function in the normal way, but instead of specifying a string as the replacement, specify a function. This function expects the same match object returned by re.search() or re.match(). The text matched by your RE is replaced by the return value of the function. This gives you a lot of flexibility; you can use the matched text to look up values in files or databases, or online, for instance, and you can do any sort of text manipulation desired. ----8<----------------------------------------------------------------------- import re # original string oldstring = '123 abc 456 def 789 ghi' # RE to match a sequence of 1 or more digits rx_digits = re.compile(r"\d+") # callback function -- expects a Match object, returns the replacement string def repl_func(m): return 'INSERT ' + m.group(0) # do the substitution newstring = rx_digits.sub(repl_func,oldstring) print "OLD:",oldstring print "NEW:",newstring --------------------------------------------------------------------------------- Output: OLD: 123 abc 456 def 789 ghi NEW: INSERT 123 abc INSERT 456 def INSERT 789 ghi You could also do it with a lambda function if you didn't want to write a separate function: newstring = rx_digits.sub(lambda m: 'INSERT ' + m.group(0),oldstring) I understand that for this simple case, ' 'INSERT ' + \1 is sufficient, and a callback is overkill; I wanted to show the OP a more generic approach to complex substitutions. From rhodri at wildebst.demon.co.uk Sat Jun 13 17:22:14 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 22:22:14 +0100 Subject: Question about None In-Reply-To: References: Message-ID: On Sat, 13 Jun 2009 21:25:28 +0100, John Yeung wrote: >> > But mathematically speaking, it's intuitive that >> > "nothing" would match any type. >> >> Completely wrong. ?The concept you're thinking of in >> denotational semantics is called "bottom", but bottom >> is not a value that functions can compute and return. >> ?It is really the absence of a value. > > I've never heard a mathematician use the term "bottom". It certainly > could be that I just haven't talked to the right types of > mathematicians. I'm not sure it's even relevant. "Denotational > semantics" is specific to computer science. My point was simply that > even an elementary understanding of mathematics (and I'll grant a > naive understanding of computer science as well) might lead someone to > think that it *might* make sense for None to be the name for nothing. Such an understanding would be clearly wrong in the context in which we were talking (and denotational semantics is a branch of category theory, which is not specific to computer science if you don't mind). If None is nothing, then it can't be a string, int, float or anything else, because they're all something. -- Rhodri James *-* Wildebeest Herder to the Masses From skip at pobox.com Sat Jun 13 17:22:51 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 13 Jun 2009 16:22:51 -0500 (CDT) Subject: Generating a unique filename in the face of unicode filename Message-ID: <20090613212251.A3F0D110830A@montanaro.dyndns.org> In my lockfile module I generate a unique name like so: self.path = path self.lock_file = os.path.abspath(path) + ".lock" self.hostname = socket.gethostname() self.pid = os.getpid() if threaded: name = threading.current_thread().get_name() tname = "%s-" % quote(name, safe="") else: tname = "" dirname = os.path.dirname(self.lock_file) self.unique_name = os.path.join(dirname, "%s.%s%s" % (self.hostname, tname, self.pid)) where path is the file which is to be locked. Frank Niessink uses lockfile in his Task Coach application and reported a problem to me one of his Windows users encountered: ... File "taskcoachlib\persistence\taskfile.pyo", line 266, in acquire_lock File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 537, in FileLock File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 296, in __init__ File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 175, in __init__ File "ntpath.pyo", line 102, in join UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal not in range(128) where line 175 is the assignment to self.unique_name. After a little back-and-forth with his user it turns out that her computer's hostname contains non-ASCII data, so presumably self.hostname is a unicode object. I tried to replicate this on my Mac but can't: >>> dirname = "/tmp" >>> h = u"\xef" >>> tname = threading.currentThread().getName() >>> os.path.join(dirname, "%s.%s.%s" % (h, tname, os.getpid())) u'/tmp/\xef.MainThread.11004' It works for Frank on his Windows box as well. Any ideas how to properly Unicode-proof this code? Thanks, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From gallium.arsenide at gmail.com Sat Jun 13 17:27:37 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 14:27:37 -0700 (PDT) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: <9cce24bf-2f3b-438f-91da-7fbf202fbf1d@r31g2000prh.googlegroups.com> On Jun 13, 3:59?pm, Arnaud Delobelle wrote: > kj writes: > > Are these the most idiomatically pythonic forms? ?Or am > > I missing something better? > > You're missing operator.itemgetter: > > >>> from operator import itemgetter > >>> foo = "spam & eggs" > >>> itemgetter(3, 7, 1, -1)(foo) > > ('m', 'e', 'p', 's') That looks to me like the best solution to the OP's specific question. It's amazing how many cool things are tucked into the standard library. While it's easy to miss these things, I appreciate the effort to keep Python's core relatively small. (Not knowing about itemgetter, I would have gone with the list comprehension.) John From pdlemper at earthlink.net Sat Jun 13 17:48:43 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 16:48:43 -0500 Subject: frustrating failure of 'break' statement ( novice ) Message-ID: In my programs the 'break' fails to work. I've studied the docs for 3.0 and Programming in Python, neither of which are illuminating. Simplest example : while True : num = int(input()) print(num) if num == 0 : break print('done') SyntaxError : invalid syntax ( pointing to end of break ) This happens whether the 'break' is put on same line as the conditional, flush with while, flush with if, or appropriately indented 4 spaces. " I saw the number 4 in gold " -Guido with apologies to Wm Carlos Williams From gallium.arsenide at gmail.com Sat Jun 13 17:49:34 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 14:49:34 -0700 (PDT) Subject: Question about None References: Message-ID: On Jun 13, 5:22?pm, "Rhodri James" wrote: > Such an understanding would be clearly wrong in the context > in which we were talking (and denotational semantics is a > branch of category theory, which is not specific to computer > science if you don't mind). ?If None is nothing, then it can't > be a string, int, float or anything else, because they're all > something. I appreciate your explanation, and your politeness. And I accept your answer, as well as Steven's and Paul's for that matter. I still think it is understandable (and people may choose to understand in a condescending way, if they wish) that someone might not get the difference between what you are saying and the statement that all elements of the empty set are floats. I mean, what's in the empty set? Nothing. But you've said that floats are something. How is it that nothing is something? Please, I do not wish to extend this thread. My last question was rhetorical. It's not a challenge. I accept your answer, as well as the others. To be clear, I find it very intuitive that None does not match the other types. But just as the devil seems to have plenty of advocates, I guess I am a naive person's advocate, of sorts. (I must stress I'm not the OP's advocate, nor do I consider him naive.) John From brian at sweetapp.com Sat Jun 13 17:59:18 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 22:59:18 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <4A342136.5010909@sweetapp.com> kj wrote: > In Nick Craig-Wood writes: > >> However I can't think of the last time I wanted to do this - array >> elements having individual purposes are usually a sign that you should >> be using a different data structure. > > In the case I was working with, was a stand-in for the value returned > by some_match.groups(). The match comes from a standard regexp > defined elsewhere and that captures more groups than I need. (This > regexp is applied to every line of a log file.) > > kj The common idiom for this sort of thing is: _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() Cheers, Brian From dickinsm at gmail.com Sat Jun 13 18:07:10 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 13 Jun 2009 15:07:10 -0700 (PDT) Subject: frustrating failure of 'break' statement ( novice ) References: Message-ID: On Jun 13, 10:48?pm, pdlem... at earthlink.net wrote: > In my programs the 'break' fails to work. ?I've studied the docs for > 3.0 and Programming in Python, neither of which are illuminating. > Simplest example : > > while True : > ? ? num = int(input()) > ? ? print(num) > ? ? if num == 0 : > ? ? ? ? break > > print('done') > > SyntaxError : invalid syntax ? ?( pointing to end of break ) > [...] Are you mixing tabs and spaces in your code at all? Check that the 'break' line is indented with 8 spaces rather than a tab character. Mark From python at mrabarnett.plus.com Sat Jun 13 18:15:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Jun 2009 23:15:17 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A342136.5010909@sweetapp.com> References: <4A342136.5010909@sweetapp.com> Message-ID: <4A3424F5.7010901@mrabarnett.plus.com> Brian Quinlan wrote: > kj wrote: >> In Nick Craig-Wood >> writes: >> >>> However I can't think of the last time I wanted to do this - array >>> elements having individual purposes are usually a sign that you should >>> be using a different data structure. >> >> In the case I was working with, was a stand-in for the value returned >> by some_match.groups(). The match comes from a standard regexp >> defined elsewhere and that captures more groups than I need. (This >> regexp is applied to every line of a log file.) >> >> kj > > The common idiom for this sort of thing is: > > _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() > Alternatively: val1, val2, val3 = some_match.group(4, 8, something) From rhodri at wildebst.demon.co.uk Sat Jun 13 18:15:47 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 23:15:47 +0100 Subject: frustrating failure of 'break' statement ( novice ) In-Reply-To: References: Message-ID: On Sat, 13 Jun 2009 22:48:43 +0100, wrote: > In my programs the 'break' fails to work. I've studied the docs for > 3.0 and Programming in Python, neither of which are illuminating. > Simplest example : > > while True : > num = int(input()) > print(num) > if num == 0 : > break > > print('done') > > > SyntaxError : invalid syntax ( pointing to end of break ) > This happens whether the 'break' is put on same line as the > conditional, flush with while, flush with if, or appropriately > indented 4 spaces. It works for me, running it from file. It fails with "invalid syntax" (pointing to the end of *print*) if I cut and paste the program exactly into a Python shell, presumably because the shell gets unhappy about having more command input when it wants to be executing the while loop. Does this match what you see? -- Rhodri James *-* Wildebeest Herder to the Masses From brian at sweetapp.com Sat Jun 13 18:22:56 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 23:22:56 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3424F5.7010901@mrabarnett.plus.com> References: <4A342136.5010909@sweetapp.com> <4A3424F5.7010901@mrabarnett.plus.com> Message-ID: <4A3426C0.2040509@sweetapp.com> MRAB wrote: > Brian Quinlan wrote: >> kj wrote: >>> In Nick Craig-Wood >>> writes: >>> >>>> However I can't think of the last time I wanted to do this - array >>>> elements having individual purposes are usually a sign that you should >>>> be using a different data structure. >>> >>> In the case I was working with, was a stand-in for the value returned >>> by some_match.groups(). The match comes from a standard regexp >>> defined elsewhere and that captures more groups than I need. (This >>> regexp is applied to every line of a log file.) >>> >>> kj >> >> The common idiom for this sort of thing is: >> >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() >> > Alternatively: > > val1, val2, val3 = some_match.group(4, 8, something) Actually, now that I think about it, naming the groups seems like it would make this code a lot less brittle. Cheers, Brian From piet at cs.uu.nl Sat Jun 13 18:38:30 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 00:38:30 +0200 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xr5xovxbb.fsf@ruckus.brouhaha.com> <7xiqj0vx1m.fsf@ruckus.brouhaha.com> Message-ID: >>>>> Paul Rubin (PR) wrote: >PR> Paul Rubin writes: >>> crash, or something like that. None is a value which in Haskell has a >PR> I got ahead of myself, of course I meant Python (the *next* sentence >PR> was going to mention Haskell). The corresponding concept in Haskell >PR> is called Nothing, which lives in a type functor called Maybe. I >PR> don't have time to go into it right now but there is a notion among >PR> language weenies these days that the presence of something like None >PR> (in Python) or Null (in Java, SQL, etc) is a wart in a language and >PR> that it's preferable to have something like Maybe. The reason is that in Haskell the type system doesn't have union types. Instead it has the disjoint sum, and Maybe is just one of them. Otherwise you could have used the union of Nothing and any other type. In Python there is no reason to use a disjoint sum as Python doesn't use static typing. You can use unions of types at your hearts desire. So I don't think there is not much difference between None and Nothing, except for the type system. Java, on the other hand does have static typing but does not have disjoint sums. So they have not much choice but to put null in every class-based type. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From no.email at please.post Sat Jun 13 19:01:04 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 23:01:04 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In kj writes: >OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be >ambiguous: does it mean the fourth element of foo, or the tuple >consisting of this element alone? I suppose that's good enough >reason to veto this idea... Hmmm, come to think of it, this argument is weaker than I thought at first. Python already has cases where it has to deal with this sort of ambiguity, and does so with a trailing comma. So the two cases could be disambiguated: foo[3] for the single element, and foo[3,] for the one-element tuple. Also, the association of this idiom with Perl is a bit unfair: tuple-index is very common in other languages, and in pure math as well. As I said in my original post, Perl code often has very obscure expressions, but I would never describe tuple indexing as one of them. By the same token, the desing of Python does not entirely disregard considerations of ease of writing. Who could argue that foo[:] is intrinsically clearer, or easier to read than foo[0:len(foo)] ? Please don't misunderstand me here. I don't want to critize, let alone change, Python. I'm sure there is a good reason for why Python doesn't support foo[3,7,1,-1], but I have not figured it out yet. I still find it unconvincing that it would be for the sake of keeping the code easy to read, because I don't see how foo[3,7,1,-1] is any more confusing than foo[:]. kj From piet at cs.uu.nl Sat Jun 13 19:02:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 01:02:16 +0200 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: >>>>> kj (k) wrote: >k> Switching from Perl here, and having a hard time letting go... >k> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >k> second, and last element in that array. In Perl I could write: >k> my @wanted = @foo[3, 7, 1, -1]; >k> I was a bit surprised when I got this in Python: >>>>> wanted = foo[3, 7, 1, -1] >k> Traceback (most recent call last): >k> File "", line 1, in >k> TypeError: list indices must be integers >k> Granted, Perl's syntax is often obscure and hard-to-read, but in >k> this particular case I find it quite transparent and unproblematic, >k> and the fictional "pythonized" form above even more so. >k> The best I've been able to come up with in Python are the somewhat >k> Perl-like-in-its-obscurity: >>>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) >k> or the clearer but unaccountably sesquipedalian >>>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] >k> Are these the most idiomatically pythonic forms? Or am I missing >k> something better? Do it yourself: class MyList(list): def __getitem__(self, indx): if isinstance (indx, tuple): return [self[i] for i in indx] else: return list.__getitem__(self, indx) l = MyList((range(10))) print l[3, 7, 1, -1] print l[3] print l[3:7] # and now for something completely different print l[3, (7, 1), -1] duck :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jeremy.cowles at gmail.com Sat Jun 13 19:07:41 2009 From: jeremy.cowles at gmail.com (Jeremy Cowles) Date: Sat, 13 Jun 2009 16:07:41 -0700 Subject: Distributed computing & sending the interpreter Message-ID: <373cf0740906131607k4cf6ac79ncc09e174fde13a22@mail.gmail.com> Hi all, I'm working on a distributed computing project (PyMW and BOINC) where we are sending Python scripts to client machines. Currently, we make two very unlikely assumptions: that Python 2.5 is installed and that the interpreter is available on the PATH. We are looking at our options to remove this assumption and the two most likely are redistributing the entire Python installation (for each supported platform) and embedding the interpreter in a custom executable and sending select parts of the standard library with it (to reduce size). It seems like we would have to pre-compile for each different platform, which is a pain and sending the entire installation could be tricky. I am looking for alternatives, comments and suggestions. Any help would be greatly appreciated. Also, please let me know if there is a better list to post this question to; would the python-dev list be appropriate? Thanks, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Jun 13 20:05:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Jun 2009 17:05:09 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In article <873aa5m6ae.fsf at vostro.rath.org>, Nikolaus Rath wrote: > >I think I managed to narrow down the problem a bit. It seems that when >a function returns normally, its local variables are immediately >destroyed. However, if the function is left due to an exception, the >local variables remain alive: Correct. You need to get rid of the stack trace somehow; the simplest way is to wrap things in layers of functions (i.e. return from the function with try/except and *don't* save the traceback). Note that if your goal is to ensure finalization rather than recovering memory, you need to do that explicitly rather than relying on garbage collection. -- 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 pdlemper at earthlink.net Sat Jun 13 20:20:17 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 19:20:17 -0500 Subject: Persistent failure of 'break' statement ( novice ) References: Message-ID: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Thanks Mark & Rhodri. Neither works. I'm using Notepad2 as editor. Don't use the tab. Each space counted with spacebar & recounted. Rewrote the block from scratch as new script and eliminated the print line in the loop. Now no error message, but it will go on forever despite repeatedly entering 0. Have to get out with ctrl-c . while True : num = int(input()) if num == 0 : break print('done') Frusting: I'm missing something fundamental. Dave WB3DWE From ben+python at benfinney.id.au Sat Jun 13 20:24:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 10:24:48 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: <87d49764rz.fsf@benfinney.id.au> Mel writes: > The immutability makes it easier to talk about the semantic meanings. > After you do > > event_timestamp = (2009, 06, 04, 05, 02, 03) > there's nothing that can happen to the tuple to invalidate > > (year, month, day, hour, minute, second) = event_timestamp > even though, as you say, there's nothing in the tuple to inform anybody > about the year, month, day, ... interpretation. Also note that the stdlib ?collections.namedtuple? implementation essentially acknowledges this: the names are assigned in advance to index positions, tying a specific semantic meaning to each position. -- \ ?Prediction is very difficult, especially of the future.? | `\ ?Niels Bohr | _o__) | Ben Finney From contact at xavierho.com Sat Jun 13 21:15:03 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 14 Jun 2009 11:15:03 +1000 Subject: Persistent failure of 'break' statement ( novice ) In-Reply-To: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Message-ID: <2d56febf0906131815n30acb7a1i2b2629691698894c@mail.gmail.com> I don't see any error in that code except the fact HTML ate one space from the code you pasted. It worked fine and perfectly as expected, even with print(num) present. I think you have either a run-time environment problem, or an editor encoding problem. Try a different editor, and/or different ways of launching the program. And share with us what you did to run this to begin with, that might help as well. Best regards, 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 Sun, Jun 14, 2009 at 10:20 AM, wrote: > Thanks Mark & Rhodri. Neither works. > > I'm using Notepad2 as editor. Don't use the tab. Each space > counted with spacebar & recounted. Rewrote the block from > scratch as new script and eliminated the print line in the loop. > Now no error message, but it will go on forever despite repeatedly > entering 0. Have to get out with ctrl-c . > > while True : > num = int(input()) > if num == 0 : > break > > print('done') > > Frusting: I'm missing something fundamental. Dave WB3DWE > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Sat Jun 13 22:03:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 19:03:38 -0700 (PDT) Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Message-ID: <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > Now no error message, but it will go on forever despite repeatedly > entering 0. ?Have to get out with ctrl-c . ? ? > ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE After you hit the zero key, do you hit the Enter key? If the answer is yes, then our crystal balls have proved useless. You'll have to supply some meaningful detail. If you are pasting your script into a Python interactive prompt, stop doing that, save your script as a file, and run it from the command line. Here's a script for you to use. It has some diagnostic print() calls in it so that we can see what is going wrong. 8<----- cut here import sys print(sys.version) assert sys.version.startswith('3.') while True : text = input('Enter a number -> ') print('You entered', ascii(text)) if text != "0": print('That is NOT the digit zero!') num = int(text) print('Value:', num) if num == 0: break print('done') 8<----- cut here And when you run it, copy the outout and paste it into your return message/posting, like I've done below: [I called my copy break_fail.py] C:\junk>\python30\python break_fail.py 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] Enter a number -> 9 You entered '9' That is NOT the digit zero! Value: 9 Enter a number -> 0 You entered '0' Value: 0 done C:\junk> Hoping this helps, John From roy at panix.com Sat Jun 13 22:21:07 2009 From: roy at panix.com (Roy Smith) Date: Sat, 13 Jun 2009 22:21:07 -0400 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In article , "Rhodri James" wrote: > The Mythical Man-Month (Brooks) is a must. What's amazing about this book is just how relevant it is today, 35 years after it was written. Some of the technical details have changed (how many of us still keep our project notes on microfiche?), but cross out "microfiche" and write in "wiki" and what he's saying is just as valid today. It's not about computer science. It's not really even about software engineering. It's more about general project management than anything else. In the same vein, Death March, by Ed Yourdon. From pdlemper at earthlink.net Sat Jun 13 22:27:51 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 21:27:51 -0500 Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> Message-ID: <3pn8355ojbd09nlb5bv2f0ucp2qkvttstj@4ax.com> On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin wrote: >On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > >> Now no error message, but it will go on forever despite repeatedly >> entering 0. ?Have to get out with ctrl-c . ? ? > >> ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE > >After you hit the zero key, do you hit the Enter key? > >If the answer is yes, then our crystal balls have proved useless. >You'll have to supply some meaningful detail. If you are pasting your >script into a Python interactive prompt, stop doing that, save your >script as a file, and run it from the command line. > >Here's a script for you to use. It has some diagnostic print() calls >in it so that we can see what is going wrong. > >8<----- cut here >import sys >print(sys.version) >assert sys.version.startswith('3.') >while True : > text = input('Enter a number -> ') > print('You entered', ascii(text)) > if text != "0": > print('That is NOT the digit zero!') > num = int(text) > print('Value:', num) > if num == 0: > break >print('done') >8<----- cut here > >And when you run it, copy the outout and paste it into your return >message/posting, like I've done below: > >[I called my copy break_fail.py] > >C:\junk>\python30\python break_fail.py >3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] >Enter a number -> 9 >You entered '9' >That is NOT the digit zero! >Value: 9 >Enter a number -> 0 >You entered '0' >Value: 0 >done > >C:\junk> > >Hoping this helps, >John John : Hitting Enter solved it. Thanks so much. I was treating input() as getch() or getche() . Dave WB3DWE From http Sat Jun 13 22:34:34 2009 From: http (Paul Rubin) Date: 13 Jun 2009 19:34:34 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Roy Smith writes: > In the same vein, Death March, by Ed Yourdon. I've been wanting to read "Antipatterns". From research at johnohagan.com Sat Jun 13 23:17:45 2009 From: research at johnohagan.com (John O'Hagan) Date: Sun, 14 Jun 2009 03:17:45 +0000 Subject: Question about None In-Reply-To: References: Message-ID: <200906140317.46479.research@johnohagan.com> On Sat, 13 Jun 2009, John Yeung wrote: > On Jun 13, 5:22 pm, "Rhodri James" > > wrote: > > Such an understanding would be clearly wrong in the context > > in which we were talking (and denotational semantics is a > > branch of category theory, which is not specific to computer > > science if you don't mind). If None is nothing, then it can't > > be a string, int, float or anything else, because they're all > > something. > > I appreciate your explanation, and your politeness. > > And I accept your answer, as well as Steven's and Paul's for that > matter. I still think it is understandable (and people may choose to > understand in a condescending way, if they wish) that someone might > not get the difference between what you are saying and the statement > that all elements of the empty set are floats. I mean, what's in the > empty set? Nothing. But you've said that floats are something. How > is it that nothing is something? [...] Also accepting that Python's implementation of None and all() are well-defined and practical, I would add that philosophically these matters of emptiness and nothingness are far from concluded. Bertrand Russell, for one, would have disputed the behaviour of all([]), although he may have appreciated its usefulness. Regards, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Jun 14 00:22:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Jun 2009 21:22:58 -0700 Subject: Off-topic: Usenet archiving history (was Re: FW: [Tutor] Multi-Threading and KeyboardInterrupt) References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: In article , Dennis Lee Bieber wrote: > > As for the use of X-Noarchive headers... Back before Google, most >NNTP servers had automatic expiration of messages (on my ISP at the >time, the binary groups expired after 24 hours!, most messages expired >after one or two weeks). I never used X-Noarchive -- in truth, I didn't >even know about it. > > THEN... Google started doing Google Groups with no automatic >expiration. That is when the subject of X-Noarchive headers came up in >some of the groups I'd been following. I and a fair number of others >immediately took advantage of it. Actually, it's not really fair to blame Google for this, they were only following the design of DejaNews, which they purchased in 2001. Google did create some additional value by finding old Usenet archives that predated DejaNews. (Google Groups, which I normally refer to as Gooja in deference to the history, debuted the archive on Dec 10, 2001.) -- 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 koranthala at gmail.com Sun Jun 14 01:38:32 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 22:38:32 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On Jun 14, 1:52?am, "Rhodri James" wrote: > On Sat, 13 Jun 2009 18:37:13 +0100, koranthala ? > wrote: > > > > >> Code Complete and GOF are software engineering books but not really > >> CS books. > > > I understand and concur. Since I am a software engineer - coming in to > > software from a different background - what I am looking for is self- > > improvement books for a software engineer. > > In that case The Mythical Man-Month (Brooks) is a must. > > -- > Rhodri James *-* Wildebeest Herder to the Masses Thank you Rhodri. I do have Mythical Man-Month - a great book indeed. I was looking for more technical books - I have now got a good set - Putting it across so that others can also use maybe - Code Complete, GOF, Mythical Man-Month, SICP - Thank you Paul - I have downloaded it from Web Site, Introduction to algorithm - I have placed an order for the same, The Pragmatic Programmer - Planning to buy, Refactoring: Improving the Design of Existing Code - again planning to buy, The C Programming Language - I had this, lost it, now I will buy again, The Little Schemer - I am not sure about buying this - I dont know scheme Software Tools - Seems to be a classic - not sure whether I will buy. Regards K From mk.fraggod at gmail.com Sun Jun 14 01:55:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 11:55:09 +0600 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <20090614115509.437d46b2@coercion> On Fri, 12 Jun 2009 18:33:13 -0400 Nikolaus Rath wrote: > Nikolaus Rath writes: > > Hi, > > > > Please consider this example: > [....] > > I think I managed to narrow down the problem a bit. It seems that when > a function returns normally, its local variables are immediately > destroyed. However, if the function is left due to an exception, the > local variables remain alive: > ... > > Is there a way to have the obj variable (that is created in dostuff()) > destroyed earlier than at the end of the program? As you can see, I > already tried to explicitly call the garbage collector, but this does > not help. Strange thing is that no one suggested contextlib, which made _exactly_ for this purpose: #!/usr/bin/env python import gc class testclass(object): def __init__(self): self.alive = True # just for example print "Initializing" def __del__(self): if self.alive: # try..except wrapper would suffice here, # so destruction won't raise ex, if already done print "Destructing" self.alive = False def __enter__(self): pass def __exit__(self, ex_type, ex_val, ex_trace): self.__del__() if not ex_type is None: raise RuntimeError(ex_val) def dostuff(fail): with testclass() as obj: # some stuff if fail: raise TypeError # some more stuff print "success" print "Calling dostuff" dostuff(fail=False) print "dostuff returned" try: print "Calling dostuff" dostuff(fail=True) except TypeError: pass gc.collect() print "dostuff returned" And it doesn't matter where you use "with", it creates a volatile context, which destructs before anything else happens on higher level. Another simplified case, similar to yours is file objects: with open(tmp_path, 'w') as file: # write_ops os.rename(tmp_path, path) So whatever happens inside "with", file should end up closed, else os.rename might replace valid path with zero-length file. It should be easy to use cursor with contextlib, consider using contextmanager decorator: from contextlib import contextmanager @contextmanager def get_cursor(): try: cursor = conn.cursor() yield cursor except Exception as ex: raise ex finally: cursor.close() with get_cursor() as cursor: # whatever ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From rustompmody at gmail.com Sun Jun 14 02:37:38 2009 From: rustompmody at gmail.com (rustom) Date: Sat, 13 Jun 2009 23:37:38 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <49565374-8f7f-4703-8d5e-41190f0373b2@i28g2000prd.googlegroups.com> On Jun 14, 10:38?am, koranthala wrote: > Software Tools - Seems to be a classic - not sure whether I will buy. In that vein but more modern -- Art of Unix Programming by Eric Raymond (available online) Some of my old favorites: Intro to functional programming by Bird and Wadler TAOCP slightly more modernized more heady and less programmer oriented -- Concrete Mathematics by Knuth and... Science of Programming by David Gries; again more modernized to Logical Approach to Discrete Mathematics Bentley's Wriiting Efficient Programs and Programming pearls Dijkstra's writings -- http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html -- are not kind to software engineers [His defn of SE -- How to program if you cannot]. Seemingly irrelevant -- Good programmers are very good with their editors -- someone mentioned yegge. Read him for inspiration on emacs. Of course you can use something else but its important to get good at it. From sjmachin at lexicon.net Sun Jun 14 02:51:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 23:51:44 -0700 (PDT) Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> <3pn8355ojbd09nlb5bv2f0ucp2qkvttstj@4ax.com> Message-ID: On Jun 14, 12:27?pm, pdlem... at earthlink.net wrote: > On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin > > > > wrote: > >On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > > >> Now no error message, but it will go on forever despite repeatedly > >> entering 0. ?Have to get out with ctrl-c . ? ? > > >> ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE > > >After you hit the zero key, do you hit the Enter key? > [snip] > > John : Hitting Enter solved it. ?Thanks so much. ?I was treating > input() as getch() or getche() . ? ? ? ? ? ? ? Dave WB3DWE Here's a tip: when all else fails, read the manual. In this case: http://docs.python.org/3.0/library/functions.html#input """The function then reads a line from input, converts it to a string (stripping a trailing newline)""" If you are desperate for getch() and getche(), see here: http://docs.python.org/3.0/library/msvcrt.html?highlight=msvcrt#console-i-o HTH, John From zak.mc.kraken at libero.it Sun Jun 14 02:55:30 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sun, 14 Jun 2009 08:55:30 +0200 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: Jack Diederich wrote: > the square brackets always expect an int or a slice. true only for lists :) In [1]: mydict = {} In [2]: mydict[1,2,3] = 'hi' In [3]: print mydict[1,2,3] ------> print(mydict[1,2,3]) hi -- By ZeD From db3l.net at gmail.com Sun Jun 14 03:33:10 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 14 Jun 2009 03:33:10 -0400 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: Dennis Lee Bieber writes: > Either way -- it was still a change from "expiration at some > date"... Though since (Netcom/Mindspring)Earthlink seems to have > subcontracted NNTP service to Giganews (or some such) it wouldn't > surprise me to learn that service also keeps a mammoth archive... I'm not sure it's really a change, or if it is, it certainly isn't a change from how things were originally. "Expiration at some date" was never any sort of global policy for Usenet - just an aspect of a individual news server. Some servers held messages for long periods, particularly for the big seven groups - it's true that alt.* and in particular the binaries, might expire quickly. I know I certainly ran some servers that didn't bother expiring - or had expiration times in years - of the big seven. My experience post-dates the great renaming, so I can't speak to before that, but don't think behavior was very different. Individual messages could include an Expires: header if they wished, but even that was just a suggestion. Any actual expiration was due to local configuration on each news server, which while it could take Expires: headers into account, was just as often driven by local storage availability or the whims of the local news admin :-) I think Deja News was providing web access to their archive from the mid-90s on (so quite a while before Google even existed) so certainly by that point everyone had access to a rather complete archive even if messages had expired on their local server. I think Deja was also the first to introduce X-No-Archive. But other archives certainly existed pre-Deja, which I'm sure is, in large part, how Google was able to locate and incorporate the older messages into their system after their acquisition of the Deja archive. -- David From lie.1296 at gmail.com Sun Jun 14 03:34:12 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 14 Jun 2009 07:34:12 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: Piet van Oostrum wrote: >>>>>> kj (k) wrote: > >> k> Switching from Perl here, and having a hard time letting go... > >> k> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >> k> second, and last element in that array. In Perl I could write: > >> k> my @wanted = @foo[3, 7, 1, -1]; > >> k> I was a bit surprised when I got this in Python: > >>>>>> wanted = foo[3, 7, 1, -1] >> k> Traceback (most recent call last): >> k> File "", line 1, in >> k> TypeError: list indices must be integers > >> k> Granted, Perl's syntax is often obscure and hard-to-read, but in >> k> this particular case I find it quite transparent and unproblematic, >> k> and the fictional "pythonized" form above even more so. > >> k> The best I've been able to come up with in Python are the somewhat >> k> Perl-like-in-its-obscurity: > >>>>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > >> k> or the clearer but unaccountably sesquipedalian > >>>>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > >> k> Are these the most idiomatically pythonic forms? Or am I missing >> k> something better? > > Do it yourself: > > class MyList(list): > def __getitem__(self, indx): > if isinstance (indx, tuple): > return [self[i] for i in indx] > else: > return list.__getitem__(self, indx) > > l = MyList((range(10))) > > print l[3, 7, 1, -1] > print l[3] > print l[3:7] > > # and now for something completely different > > print l[3, (7, 1), -1] > even better: print l[3, 4:10:2, 7] From mk.fraggod at gmail.com Sun Jun 14 03:46:18 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 13:46:18 +0600 Subject: Make upof Computer References: <11c7c592-12cb-4d6c-b964-96782da39690@s38g2000prg.googlegroups.com> Message-ID: <20090614134618.19f03efd@coercion> On Sun, 14 Jun 2009 00:46:16 -0700 (PDT) "Mr . Waqar Akbar" wrote: ... Judging by the typo in the last subject, someone indeed types all this crap in manually! Oh my god... -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From ben+python at benfinney.id.au Sun Jun 14 03:46:26 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 17:46:26 +1000 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: <87r5xn45rh.fsf@benfinney.id.au> David Bolen writes: > Individual messages could include an Expires: header if they wished, Since we're already well off-topic: NNTP, HTTP, and email, and probably other protocols as well, all deal with messages. They are all consistent in defining a message [0] as having *exactly one* header. Every time you call a field from the header ?a header?, or refer to the plural ?headers of a message?, the IETF kills a kitten. You don't want to hurt a kitten, do you? [0] Okay, NNTP calls a message an ?article?, and the header is composed of ?lines? where other protocols call them ?fields? (since there can be multiple lines per field), but that's no excuse. -- \ ?If I held you any closer I would be on the other side of you.? | `\ ?Groucho Marx | _o__) | Ben Finney From lie.1296 at gmail.com Sun Jun 14 03:48:38 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 14 Jun 2009 07:48:38 GMT Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: Brian D wrote: > On Jun 11, 9:22 am, Brian D wrote: >> On Jun 11, 2:01 am, Lie Ryan wrote: >> >> >> >>> 504cr... at gmail.com wrote: >>>> I've encountered a problem with my RegEx learning curve -- how to >>>> escape hash characters # in strings being matched, e.g.: >>>>>>> string = re.escape('123#abc456') >>>>>>> match = re.match('\d+', string) >>>>>>> print match >>>> <_sre.SRE_Match object at 0x00A6A800> >>>>>>> print match.group() >>>> 123 >>>> The correct result should be: >>>> 123456 >>>> I've tried to escape the hash symbol in the match string without >>>> result. >>>> Any ideas? Is the answer something I overlooked in my lurching Python >>>> schooling? >>> As you're not being clear on what you wanted, I'm just guessing this is >>> what you wanted: >>>>>> s = '123#abc456' >>>>>> re.match('\d+', re.sub('#\D+', '', s)).group() >>> '123456' >>>>>> s = '123#this is a comment and is ignored456' >>>>>> re.match('\d+', re.sub('#\D+', '', s)).group() >>> '123456' >> Sorry I wasn't more clear. I positively appreciate your reply. It >> provides half of what I'm hoping to learn. The hash character is >> actually a desirable hook to identify a data entity in a scraping >> routine I'm developing, but not a character I want in the scrubbed >> data. >> >> In my application, the hash makes a string of alphanumeric characters >> unique from other alphanumeric strings. The strings I'm looking for >> are actually manually-entered identifiers, but a real machine-created >> identifier shouldn't contain that hash character. The correct pattern >> should be 'A1234509', but is instead often merely entered as '#12345' >> when the first character, representing an alphabet sequence for the >> month, and the last two characters, representing a two-digit year, can >> be assumed. Identifying the hash character in a RegEx match is a way >> of trapping the string and transforming it into its correct machine- >> generated form. >> >> I'm surprised it's been so difficult to find an example of the hash >> character in a RegEx string -- for exactly this type of situation, >> since it's so common in the real world that people want to put a pound >> symbol in front of a number. >> >> Thanks! > > By the way, other forms the strings can take in their manually created > forms: > > A#12345 > #1234509 > > Garbage in, garbage out -- I know. I wish I could tell the people > entering the data how challenging it is to work with what they > provide, but it is, after all, a screen-scraping routine. perhaps it's like this? >>> # you can use re.search if that suits better >>> a = re.match('([A-Z]?)#(\d{5})(\d\d)?', 'A#12345') >>> b = re.match('([A-Z]?)#(\d{5})(\d\d)?', '#1234509') >>> a.group(0) 'A#12345' >>> a.group(1) 'A' >>> a.group(2) '12345' >>> a.group(3) >>> b.group(0) '#1234509' >>> b.group(1) '' >>> b.group(2) '12345' >>> b.group(3) '09' From ben+python at benfinney.id.au Sun Jun 14 03:55:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 17:55:48 +1000 Subject: Make-up of computer References: Message-ID: <87my8b45bv.fsf@benfinney.id.au> "Mr . Waqar Akbar" writes: > A computer is a collection of modular electronic components, i.e. > components that can be replaced by other components that may have > different characteristics that are capable of running computer > programs. And also storing and manipulating all sorts of other digital information, not just programs. > Thus, the term "hardware" refers to all the material elements of a > computer and "software" refers to the program parts. Rather, ?software? refers to *all* the streams of bits. Whether a bit stream is interpreted as a program, a graphic image, a document, or all three simultaneously ? or any of countless other potential interpretations for a bit stream ? is transitory, and doesn't affect its nature as ?software?. Or, as the aphorism goes: The hardware is the parts of the computer you can kick, and the software is everything else in the computer. -- \ ?I spilled spot remover on my dog. Now he's gone.? ?Steven | `\ Wright | _o__) | Ben Finney From kwatch at gmail.com Sun Jun 14 04:06:36 2009 From: kwatch at gmail.com (kwatch) Date: Sun, 14 Jun 2009 01:06:36 -0700 (PDT) Subject: ANN: pyTenjin 0.8.1 - much faster template engine than Django Message-ID: <58230bc0-97d5-476c-9a69-5bf60a21f304@c18g2000prh.googlegroups.com> I released pyTenjin 0.8.1. http://www.kuwata-lab.com/tenjin/ http://pypi.python.org/pypi/Tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) This is a bug fix release. See CHANGES for details. http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Bugfix from 0.8.1 ----------------- * Fix bugs on CacheStorage#unset(). (thanks Steve) * Fix tenjin.helpers.html.new_cycle() to work on Python 3.0. Changes from 0.8.1 ------------------ * Update 'doc/faq.html' and add new section. 'Is it possible to change indent restriction more flexible?' http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-flexibleindent Documents --------- * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * FAQ http://www.kuwata-lab.com/tenjin/pytenjin-faq.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Have fun! -- regards, makoto kuwata From ldo at geek-central.gen.new_zealand Sun Jun 14 04:18:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 20:18:12 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In message , koranthala wrote: > I do have Mythical Man-Month - a great book indeed. > I was looking for more technical books ... No-one has mentioned Andrew Tanenbaum's "Computer Networks". So much of programming seems to involve networking these days, I think the current (4th) edition is a great introduction to how to think in network terms, particularly about security issues. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:23:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:23:31 +1200 Subject: Measuring Fractal Dimension ? References: Message-ID: In message , Peter Billam wrote: > Are there any modules, packages, whatever, that will > measure the fractal dimensions of a dataset, e.g. a time-series ? I don't think any countable set, even a countably-infinite set, can have a fractal dimension. It's got to be uncountably infinite, and therefore uncomputable. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:32:46 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:32:46 +1200 Subject: random number including 1 - i.e. [0,1] References: Message-ID: In message , Jussi Piitulainen wrote: > Miles Kaufmann writes: > >> I'm curious what algorithm calls for random numbers on a closed >> interval. > > The Box-Muller transform, polar form. At least Wikipedia says so. Doesn't seem to be necessary, if I interpret the following correctly : Given u and v, independent and uniformly distributed in the closed interval [?1, +1], set s = R2 = u2 + v2. (Clearly \scriptstyle R = \sqrt{s}.) If s = 0 or s > 1, throw u and v away and try another pair (u, v). Continue until a pair with s in the open interval (0, 1) is found. Since s is supposed to be in an open interval, I don't see how it makes any difference if u and v are chosen from an open or semiopen interval. The probability of hitting the exact endpoints is 0, after all. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:36:39 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:36:39 +1200 Subject: random number including 1 - i.e. [0,1] References: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> Message-ID: In message , Esmail wrote: > I'm implementing a Particle Swarm Optimizer. Depending on what paper you > read you'll see mention of required random values "between 0 and 1" > which is somewhat ambiguous. I came across one paper that specified > the range [0,1], so inclusive 1, which was the reason for my question. Sounds like some of their descriptions are a bit sloppy. Maybe best to clear it up by trying to think what a value of exactly or exactly 1 for the random value might mean: are those boundaries meant to be inside the set, or outside? Is it meaningful to concatenate two adjacent intervals? In that case any point can only belong to one of the intervals, not both. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:38:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:38:59 +1200 Subject: random number including 1 - i.e. [0,1] References: Message-ID: In message , Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) Are the terms meant to be clamped to a particular range of values? Otherwise it probably doesn't matter. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:43:30 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:43:30 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > 2. That output string has severe "leaning toothpick" syndrome. Python > accepts both single and double quotes to help avoid creating something > so unreadable: use them. Backslashes are more scalable. From madigreece at yahoo.gr Sun Jun 14 06:31:43 2009 From: madigreece at yahoo.gr (jeni) Date: Sun, 14 Jun 2009 03:31:43 -0700 (PDT) Subject: error: an integer is required References: Message-ID: <0319e22c-6b6a-4165-91cd-2813dcfa1e58@y17g2000yqn.googlegroups.com> On 8 ????, 21:46, Terry Reedy wrote: > madigre... at yahoo.gr wrote: > > I execute my code in linux environment. > > My code is: > > > from os import * > > > def insert_text_file(self, strng): > > ? ? ?t=open("elements_file.txt", "a") > > ? ? ?t.write(strng) > > ? ? ?t.close() > > > I'm getting this error: > > > : an integer is required > > > Where is the mistake? > > Help me, please!! > > Tell us the Python version and give the *full* traceback message, not > just the last line. ?I am pretty sure you also left out an important > part of the code you executed to get that message. > > tjr- ???????? ???????? ?? ???????? - > > - ???????? ???????? ?? ???????? - With both import os and os.open there is the same error. I have developed in python a game for OPLC. When I run the game in Python 2.5.2 at Windows there is no problem. But after I play a game at OLPC I get the following message: Traceback (most recent call last) /home/olpc/Activities/Kremala.activity/Kremala.py in add_letter (self=, widget=, grama='i') --> self.find_w() self.find_w=> /home/Activities/Kremala.activity/Kremala.py in find_w (self=) self.show_gr() --> self.sosti_leksi() self.sosti_leksi==> /home/Activities/Kremala.activity/Kremala.py in sosti_leksi (self=) s=self.categ+":"+str(1)+" nikh me "+str(6-self.m)+"prospatheies \n" --> self.insert_text_file(s) self.insert_text_file===> /home/Activities/Kremala.activity/Kremala.py in insert_text_file (self=, strng='geografia:1 nikh me 2 prospatheies\n') --> t=open("elements_file.txt", "a") global open= t.write(strng) t.close() : an integer is required OLPC's software is important? From kindly at gmail.com Sun Jun 14 07:02:47 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 04:02:47 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. Message-ID: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> I am sure people have thought of this before, but I cant find where. I think that python should adapt a way of defining different types of mapping functions by proceeding a letter before the curly brackets. i.e ordered = o{}, multidict = m{} (like paste multidict). So you could define an ordered dict by newordered = o{"llvm" : "ptyhon", "parrot" : "perl"} . (they should also probably have there own comprehensions as well o{foo for bar in foobar}). People nowadays think in terms of hashes and lists (especially with jsons and javascript not going away} and most of my time seems to be spent in different ways to store bits of data in memory in this way. It also seems to be the way to think in python (an object or a class object are just mappings themselves) Most packages that I have seen re- implement these different container types at one point anyway. It seems a shame they are not brought up to the top level, with potentially new, cleverer ones that have not been thought of yet. There will be potential to add different letters to the start when it seems that a certain mapping pattern seems in popular use. Am I crazy to think this is a good idea? I have not looked deeply pythons grammer to see if it conflicts with anything, but on the surface it looks fine. From mk.fraggod at gmail.com Sun Jun 14 07:25:10 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 17:25:10 +0600 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <20090614172510.5299448e@coercion> On Sun, 14 Jun 2009 04:02:47 -0700 (PDT) kindly wrote: > Am I crazy to think this is a good idea? I have not looked deeply > pythons grammer to see if it conflicts with anything, but on the > surface it looks fine. I'd say "on the surface it looks like perl" ;) I'd prefer to use dict() to declare a dict, not some mix of letters and incomprehensible symbols, thank you. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From kindly at gmail.com Sun Jun 14 07:36:17 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 04:36:17 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <20090614172510.5299448e@coercion> Message-ID: On Jun 14, 12:25?pm, Mike Kazantsev wrote: > On Sun, 14 Jun 2009 04:02:47 -0700 (PDT) > > kindly wrote: > > Am I crazy to think this is a good idea? ?I have not looked deeply > > pythons grammer to see if it conflicts with anything, but on the > > surface it looks fine. > > I'd say "on the surface it looks like perl" ;) > I'd prefer to use dict() to declare a dict, not some mix of letters and > incomprehensible symbols, thank you. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Python already has it for strings r"foo" or u"bar". So I do not think its going against the grain. From stefan_ml at behnel.de Sun Jun 14 07:45:48 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 14 Jun 2009 13:45:48 +0200 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Hi, this kind of stuff is commonly discussed on the python-ideas mailing list. You might want to search that list and/or repost this over there. Stefan kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ordered = o{}, multidict = m{} (like paste multidict). So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . (they should also probably have there own > comprehensions as well o{foo for bar in foobar}). > > People nowadays think in terms of hashes and lists (especially with > jsons and javascript not going away} and most of my time seems to be > spent in different ways to store bits of data in memory in this way. > It also seems to be the way to think in python (an object or a class > object are just mappings themselves) Most packages that I have seen re- > implement these different container types at one point anyway. It > seems a shame they are not brought up to the top level, with > potentially new, cleverer ones that have not been thought of yet. > There will be potential to add different letters to the start when it > seems that a certain mapping pattern seems in popular use. > > Am I crazy to think this is a good idea? I have not looked deeply > pythons grammer to see if it conflicts with anything, but on the > surface it looks fine. From roy at panix.com Sun Jun 14 07:59:32 2009 From: roy at panix.com (Roy Smith) Date: Sun, 14 Jun 2009 07:59:32 -0400 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: In article <7x4ouj7dc5.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Roy Smith writes: > > In the same vein, Death March, by Ed Yourdon. > > I've been wanting to read "Antipatterns". I didn't think that was so great. It had a lot of hype, which lead to be believe it would be something wonderful, but I wasn't so impressed. From db3l.net at gmail.com Sun Jun 14 07:59:58 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 14 Jun 2009 07:59:58 -0400 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <87r5xn45rh.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > David Bolen writes: > >> Individual messages could include an Expires: header if they wished, > > Since we're already well off-topic: NNTP, HTTP, and email, and probably > other protocols as well, all deal with messages. They are all consistent > in defining a message [0] as having *exactly one* header. Heh, I'm not sure it's quite as consistent as you may think, particularly with older RFCs, which are relevant in this discussion since we're talking about historical artifacts. For example, while more recent mail RFCs like 2822 may specifically talk about header fields as the "header" (singular) of the message, the older RFC 822 instead refers to a "headers" (plural) section. > Every time you call a field from the header ?a header?, or refer to > the plural ?headers of a message?, the IETF kills a kitten. You > don't want to hurt a kitten, do you? Heaven forbid - though I'd think I could hold my own with the IETF. My reference to "header" was in lieu of "header line", something that the Usenet RFCs (1036, and the older 850) do extensively themselves. But I'll be more careful in the future - need to ensure kitten safety! -- David From arnodel at googlemail.com Sun Jun 14 08:04:39 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 14 Jun 2009 13:04:39 +0100 Subject: Measuring Fractal Dimension ? References: Message-ID: Lawrence D'Oliveiro writes: > In message , Peter Billam wrote: > >> Are there any modules, packages, whatever, that will >> measure the fractal dimensions of a dataset, e.g. a time-series ? > > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. I think there are attempts to estimate the fractal dimension of a set using a finite sample from this set. But I can't remember where I got this thought from! -- Arnaud From http Sun Jun 14 08:27:33 2009 From: http (Paul Rubin) Date: 14 Jun 2009 05:27:33 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: <7xy6rvuhje.fsf@ruckus.brouhaha.com> Roy Smith writes: > > I've been wanting to read "Antipatterns". > > I didn't think that was so great. It had a lot of hype, which lead to be > believe it would be something wonderful, but I wasn't so impressed. Hmm, good to know. Thanks. From http Sun Jun 14 08:30:11 2009 From: http (Paul Rubin) Date: 14 Jun 2009 05:30:11 -0700 Subject: Measuring Fractal Dimension ? References: Message-ID: <7xtz2juhf0.fsf@ruckus.brouhaha.com> Arnaud Delobelle writes: > I think there are attempts to estimate the fractal dimension of a set > using a finite sample from this set. But I can't remember where I got > this thought from! There are image data compression schemes that work like that, trying to detect self-similarity in the data. It can go the reverse way too. There was a program called Genuine Fractals that tried to increase the apparent resolution of photographs by adding artificial detail constructed from detected self-similarity. Its results were mixed, as I remember. From mk.fraggod at gmail.com Sun Jun 14 08:30:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 18:30:35 +0600 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <20090614172510.5299448e@coercion> Message-ID: <20090614183035.737adc84@coercion> On Sun, 14 Jun 2009 04:36:17 -0700 (PDT) kindly wrote: > Python already has it for strings r"foo" or u"bar". So I do not think > its going against the grain. Yes, and there's other syntactic sugar like ";" (barely used), mentioned string types, "(element,)", "%s"%var or curly braces themselves. Some of them might even seem as unnecessary and redundant, but they should there to support legacy code, at least, and I don't think it's a good idea to add any more. In fact, py3 will drop "%s"%var syntax in favor of "{0}".format(var) and I think it's a good call. There's only so much sugar to add before it'll transform into salt and you'll start seeing lines like these: s**'@z!~;()=~$x>;%x>l;$(,'*e;y*%z),$;@=!;h(l~;*punch jokers;halt;*;print; I'm happy to use python because it discourages such syntax, among other things. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 08:59:24 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 22:59:24 +1000 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <0244e656$0$20638$c3e8da3@news.astraweb.com> Stefan Behnel wrote: > Hi, > > this kind of stuff is commonly discussed on the python-ideas mailing list. > You might want to search that list and/or repost this over there. Please don't top-post here. If the OP takes this idea to python-ideas, chances are he'll be told to take the concept here first, for feedback, before python-ideas. More comments below: > kindly wrote: >> I am sure people have thought of this before, but I cant find where. >> I think that python should adapt a way of defining different types of >> mapping functions by proceeding a letter before the curly brackets. >> i.e ordered = o{}, multidict = m{} (like paste multidict). So you >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", >> "parrot" : "perl"} . (they should also probably have there own >> comprehensions as well o{foo for bar in foobar}). You can do that more readably: data = OrderedDict() data = SortedDict() data = MultiDict() etc. The advantages are: * no new syntax is needed; * you can have as many different types of mappings as needed, without needing to change the compiler or worry about clashes between letters; * not all mapping types necessarily have the same initialiser signature; * the mapping type doesn't need to be a built-in type. The analogy with raw strings is faulty: r"" changes the way the compiler interprets the characters between the quotes, it doesn't create a different type of object. There's nothing explicitly *wrong* with the idea of o{} m{} etc for a *small* number of built-in mapping types. If ordered dicts (say) ever become built-ins, rather than a type that you have to import from a module, then maybe we'll be looking for syntax for them, in which case there's worse ideas than o{}. But even then, a disadvantage would be that it's awfully perlish. There's already two uses for {}, namely dicts and sets, and I don't know that adding a third or more is a good idea. -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:01:30 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:01:30 +1000 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> kj wrote: > OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be > ambiguous: does it mean the fourth element of foo, or the tuple > consisting of this element alone? I suppose that's good enough > reason to veto this idea... There's nothing ambiguous about it. obj.__getitem__(x) already accepts two different sorts of objects for x: ints and slice-objects: >>> range(8)[3] 3 >>> range(8)[slice(3)] [0, 1, 2] >>> range(8)[slice(3, None)] [3, 4, 5, 6, 7] >>> range(8)[slice(3, 4)] [3] Allowing tuple arguments need not be ambiguous: range(8)[3] => 3 range(8)[(3,)] => [3] range(8)[(3,5,6)] => [3, 5, 6] I've rarely needed to grab arbitrary items from a list in this fashion. I think a more common case would be extracting fields from a tuple. In any case, there are a few alternatives: Grab them all, and ignore some of them (ugly for more than one or two ignorable items): _, x, _, _, y, _, _, _, z, _ = range(10) # x=1, y=4, z=9 Subclass list to allow tuple slices: >>> class MyList(list): ... def __getitem__(self, obj): ... if type(obj) is tuple: ... return [self[i] for i in obj] ... else: ... return list.__getitem__(self, obj) ... >>> L = MyList(range(10)) >>> L[(1, 4, 8)] [1, 4, 8] Write a helper function: def getitems(L, *indexes): if len(indexes) == 1: indexes = indexes[0] return [L[i] for i in indexes] But I think this is an obvious enough extension to the __getitem__ protocol that I for one would vote +1 on it being added to Python sequence objects (lists, tuples, strings). -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:04:02 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:04:02 +1000 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <0244e76b$0$20638$c3e8da3@news.astraweb.com> Nathan Stoddard wrote: > The best way to become a good programmer is to program. Write a lot of > code; work on some large projects. This will improve your skill more than > anything else. I think there are about 100 million VB code-monkeys who prove that theory wrong. Seriously, and without denigrating any specific language, you can program by (almost) mindlessly following a fixed number of recipes and patterns. This will get the job done, but it won't make you a good programmer. -- Steven From cjw at ncf.ca Sun Jun 14 09:05:49 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 14 Jun 2009 09:05:49 -0400 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Stefan Behnel wrote: > Hi, > > this kind of stuff is commonly discussed on the python-ideas mailing list. > You might want to search that list and/or repost this over there. > > Stefan > > kindly wrote: >> I am sure people have thought of this before, but I cant find where. >> I think that python should adapt a way of defining different types of >> mapping functions by proceeding a letter before the curly brackets. >> i.e ordered = o{}, multidict = m{} (like paste multidict). So you >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", >> "parrot" : "perl"} . (they should also probably have there own >> comprehensions as well o{foo for bar in foobar}). >> >> People nowadays think in terms of hashes and lists (especially with >> jsons and javascript not going away} and most of my time seems to be >> spent in different ways to store bits of data in memory in this way. >> It also seems to be the way to think in python (an object or a class >> object are just mappings themselves) Most packages that I have seen re- >> implement these different container types at one point anyway. It >> seems a shame they are not brought up to the top level, with >> potentially new, cleverer ones that have not been thought of yet. >> There will be potential to add different letters to the start when it >> seems that a certain mapping pattern seems in popular use. >> >> Am I crazy to think this is a good idea? I have not looked deeply >> pythons grammer to see if it conflicts with anything, but on the >> surface it looks fine. This has some appeal in the light of Python 3.1's ordered dictionary. Colin W. From graham.ashton at gmail.com Sun Jun 14 09:13:54 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:13:54 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-14 03:34:34 +0100, Paul Rubin said: > Roy Smith writes: >> In the same vein, Death March, by Ed Yourdon. > > I've been wanting to read "Antipatterns". I bought it but couldn't get into it. Light on meat, heavy on boredom (for me - these things are always somewhat subjective). From deets at nospam.web.de Sun Jun 14 09:14:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 14 Jun 2009 15:14:49 +0200 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <0244e656$0$20638$c3e8da3@news.astraweb.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> Message-ID: <79kbe9F1qt9u4U2@mid.uni-berlin.de> > The analogy with raw strings is faulty: r"" changes the way the compiler > interprets the characters between the quotes, it doesn't create a different > type of object. But u"" does, as does the new bytestring-literal in Python3. So there is precedent. Diez From graham.ashton at gmail.com Sun Jun 14 09:15:56 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:15:56 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-14 06:38:32 +0100, koranthala said: > > The Pragmatic Programmer - Planning to buy, > Refactoring: Improving the Design of Existing Code - again planning to > buy, These are my top two recommendations for people who can already code a bit, but who want to get really really good. The first few chapters of Refactoring hold the key insights, the rest is examples. > The Little Schemer - I am not sure about buying this - I dont know > scheme If you want to learn functional programming, that's excellent. From graham.ashton at gmail.com Sun Jun 14 09:19:13 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:19:13 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On 2009-06-14 14:04:02 +0100, Steven D'Aprano said: > Nathan Stoddard wrote: > >> The best way to become a good programmer is to program. Write a lot of >> code; work on some large projects. This will improve your skill more than >> anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. Really? So you don't think that the best way to get good at something is to practice? I think I'm paraphrasing Richard Feynman here, but the only way to truly understand something is to do it. Obviously a bit of guided learning is a major boon, but you can't be practice. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:25:20 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:25:20 +1000 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> John Yeung wrote: > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. I think you're wrong. Mathematically, you can't mix types like real numbers and sets: while 1+0 = 1, you can't expect to get a sensible result from 1+{} or {1}?0. (If that character between the set and zero ends up missing, it's meant to be INTERSECTION u'\u2229'.) Similarly, you can't add a scalar to a vector or matrix, even if one or the other is null. > I find that it's somewhat like the confusion that often occurs > regarding the all() function. Some people are surprised that all([]) > returns True, but it's the same logic behind the truth of the > statement "every element of the empty set is an integer". It's also > true that every element of the empty set is a float. Or an elephant. So-called "vacuous truth". It's often useful to have all([]) return true, but it's not *always* useful -- there are reasonable cases where the opposite behaviour would be useful: if all(the evidence points to the Defendant's guilt) then: the Defendant is guilty execute(the Defendant) sadly means that if there is no evidence that a crime has been committed, the person accused of committing the imaginary crime will be executed. -- Steven From cd at okunah.de Sun Jun 14 09:27:25 2009 From: cd at okunah.de (Christof Donat) Date: Sun, 14 Jun 2009 15:27:25 +0200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: Hi, > Which are the classic books in computer science which one should > peruse? >From having read this discussion up to now I'd recomend you to read code written by good programmers. Christof From castironpi at gmail.com Sun Jun 14 09:27:32 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 06:27:32 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <09cf0ce3-0bfa-4300-89ba-1233fb90dd83@3g2000yqk.googlegroups.com> On Jun 14, 4:02?am, kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ? ordered = o{}, ?multidict = m{} ?(like paste multidict). ?So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . ?(they should also probably have there own > comprehensions as well o{foo for bar in foobar}). That kind of stuff is highly explosive, unfortunately. o{ }, m{ }, d [ ], and q[ ] are just a few. But 'collections' is kind of sparse. I expect you would also want users to be able to define their own prefixes, no? As is, the syntax is not atrocious: oA= OrderedDict( [ ( pair1 ), ( pair2 ) ] oA= o{ pair1, pair2 } At least you can still include literals, and are not restricted to per- line additions as in C. snip > Most packages that I have seen re- > implement these different container types at one point anyway. It > seems a shame they are not brought up to the top level, with > potentially new, cleverer ones that have not been thought of yet. snip Do you merely want to populate the 'collections' module, or are the prefixes essential to your idea? From kindly at gmail.com Sun Jun 14 09:30:59 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 06:30:59 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4f168d3e-1c4e-4157-9469-7ee9c3b14c01@k19g2000prh.googlegroups.com> On Jun 14, 1:59?pm, Steven D'Aprano wrote: > Stefan Behnel wrote: > > Hi, > > > this kind of stuff is commonly discussed on the python-ideas mailing list. > > You might want to search that list and/or repost this over there. > > Please don't top-post here. > > If the OP takes this idea to python-ideas, chances are he'll be told to take > the concept here first, for feedback, before python-ideas. > > More comments below: > > > kindly wrote: > >> I am sure people have thought of this before, but I cant find where. > >> I think that python should adapt a way of defining different types of > >> mapping functions by proceeding a letter before the curly brackets. > >> i.e ? ordered = o{}, ?multidict = m{} ?(like paste multidict). ?So you > >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", > >> "parrot" : "perl"} . ?(they should also probably have there own > >> comprehensions as well o{foo for bar in foobar}). > > You can do that more readably: > > data = OrderedDict() > data = SortedDict() > data = MultiDict() etc. > > The advantages are: > > * no new syntax is needed; > > * you can have as many different types of mappings as needed, without > needing to change the compiler or worry about clashes between letters; > > * not all mapping types necessarily have the same initialiser signature; > > * the mapping type doesn't need to be a built-in type. > > The analogy with raw strings is faulty: r"" changes the way the compiler > interprets the characters between the quotes, it doesn't create a different > type of object. > > There's nothing explicitly *wrong* with the idea of o{} m{} etc for a > *small* number of built-in mapping types. If ordered dicts (say) ever > become built-ins, rather than a type that you have to import from a module, > then maybe we'll be looking for syntax for them, in which case there's > worse ideas than o{}. But even then, a disadvantage would be that it's > awfully perlish. There's already two uses for {}, namely dicts and sets, > and I don't know that adding a third or more is a good idea. > > -- > Steven Thank you all for your feedback. I have never actually used perl, but I imagine if I did, I imagine I would have more disgust at the suger. I think my point is more that I think python should consider having more useful top level data structures and less to do with how they are created. There has been a big shift in the way people pass around structures and this is mainly due to the dict(hash) type, that python uses so well. I am glad the ordered dict will be in 2.7 and 3.1. I was just imagining what would be the next step in definition of structures. New languages like clojure have adopted the dict as top level. I imagine immutable/thread safe/transactional dicts to be around soon in other languages to help with concurrency. It would be nice if python was ahead of the game in this. From castironpi at gmail.com Sun Jun 14 09:36:12 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 06:36:12 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> <4f168d3e-1c4e-4157-9469-7ee9c3b14c01@k19g2000prh.googlegroups.com> Message-ID: <73c4e8eb-b018-4f01-bcac-0c9af171d144@37g2000yqp.googlegroups.com> On Jun 14, 6:30?am, kindly wrote: > On Jun 14, 1:59?pm, Steven D'Aprano snip > I am glad the ordered dict will be in 2.7 and 3.1. I > was just imagining what would be the next step in definition of > structures. New languages like clojure have adopted the dict as top > level. ?I imagine immutable/thread safe/transactional dicts to be > around soon in other languages to help with concurrency. ?It would be > nice if python was ahead of the game in this. Just not ahead of its /time/. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 10:00:56 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 00:00:56 +1000 Subject: Measuring Fractal Dimension ? References: Message-ID: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Lawrence D'Oliveiro wrote: > In message , Peter Billam wrote: > >> Are there any modules, packages, whatever, that will >> measure the fractal dimensions of a dataset, e.g. a time-series ? > > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. Incorrect. Koch's snowflake, for example, has a fractal dimension of log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial triangle, and a perimeter given by lim n->inf (4/3)**n. Although the perimeter is infinite, it is countably infinite and computable. Strictly speaking, there's not one definition of "fractal dimension", there are a number of them. One of the more useful is the "Hausdorf dimension", which relates to the idea of how your measurement of the size of a thing increases as you decrease the size of your yard-stick. The Hausdorf dimension can be statistically estimated for finite objects, e.g. the fractal dimension of the coast of Great Britain is approximately 1.25 while that of Norway is 1.52; cauliflower has a fractal dimension of 2.33 and crumpled balls of paper of 2.5; the surface of the human brain and lungs have fractal dimensions of 2.79 and 2.97. -- Steven From Scott.Daniels at Acm.Org Sun Jun 14 10:10:11 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 14 Jun 2009 07:10:11 -0700 Subject: Question about None In-Reply-To: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > ... or {1}?0. (If that character between the set and zero ends up missing, > it's meant to be INTERSECTION u'\u2229'.) Note that you can write this in a quite readable way in ASCII: "it's meant to be the character u'\N{INTERSECTION}'." --Scott David Daniels Scott.Daniels at Acm.Org From mwilson at the-wire.com Sun Jun 14 10:21:22 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 14 Jun 2009 10:21:22 -0400 Subject: Question about None References: Message-ID: John Yeung wrote: > And I accept your answer, as well as Steven's and Paul's for that > matter. I still think it is understandable (and people may choose to > understand in a condescending way, if they wish) that someone might > not get the difference between what you are saying and the statement > that all elements of the empty set are floats. I mean, what's in the > empty set? Nothing. But you've said that floats are something. How > is it that nothing is something? It's sort of a logic equivalent of divide-by-zero. All elements of the empty set are floats. All elements of the empty set are ints. Ints are not floats. Therefore all elements of the empty set are not floats. You elaborate your logic to talk around this problem, and you quit when you get tired. Mel. From castironpi at gmail.com Sun Jun 14 10:27:29 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 07:27:29 -0700 (PDT) Subject: persistent composites Message-ID: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Hi, please forgive the multi-posting on this general topic. Some time ago, I recommended a pursuit of keeping 'persistent composite' types on disk, to be read and updated at other times by other processes. Databases provide this functionality, with the exception that field types in any given table are required to be uniform. Python has no such restriction. I tried out an implementation of composite collections, specifically lists, sets, and dicts, using 'sqlite3' as a persistence back-end. It's significantly slower, but we might argue that attempting to do it by hand classifies as a premature optimization; it is easy to optimize debugged code. The essentials of the implementation are: - each 'object' gets its own table. = this includes immutable types - a reference count table = when an object's ref. count reaches zero, its table is dropped - a type-map table = maps object's table ID to a string of its type - a single 'entry point' table, with the table ID of the entry-point object = the entry point is the only data structure available to new connections. (I imagine it will usually be a list or dict.) I will be sure to kill any interest you might have by now, by "revealing" a snippet of code. The object creation procedure: def new_table( self, type ): ''' 'type' is a string, the name of the class the object is an instance of ''' cur= self.conn.cursor( ) recs= cur.execute( '''SELECT max( tableid ) FROM refcounts''' ) rec= cur.fetchone( ) if rec[ 0 ] is None: obid= 0 else: obid= rec[ 0 ]+ 1 cur.execute( '''INSERT INTO types VALUES( ?, ? )''', ( obid, type ) ) cur.execute( '''INSERT INTO refcounts VALUES( ?, ? )''', ( obid, 1 ) ) The increment ref. count procedure: def incref( self, obid ): cur= self.conn.cursor( ) recs= cur.execute( '''SELECT count FROM refcounts WHERE tableid = ?''', ( obid, ) ) rec= recs.fetchone( ) newct= rec[ 0 ]+ 1 cur.execute( '''UPDATE refcounts SET count = ? WHERE tableid = ?''', ( newct, obid ) ) The top-level structure contains these two procedures, as well as 'setentry', 'getentry', and 'revive' procedures. Most notably, user-defined types are possible. The dict is merely a persistent dict. 'revive' checks the global namespace by name for the original type, subject to the same restrictions that we all know and love that 'pickle' has. As usual, deadlocks and cyclic garbage pose the usual problems. The approach I used last time was to maintain a graph of acquired locks, and merely check for cycles to avert deadlocks, which would go in a separate table. For garbage, I can't find a better solution than Python already uses. >From the 3.0 docs: gc.garbage A list of objects which the collector found to be unreachable but could not be freed (uncollectable objects). ... Python doesn?t collect such [garbage] cycles automatically because, in general, it isn?t possible for Python to guess a safe order in which to run the __del__() methods. If you know a safe order, you can force the issue by examining the garbage list, and explicitly breaking cycles due to your objects within the list. Before I go and flesh out the entire interfaces for the provided types, does anyone have a use for it? From kindly at gmail.com Sun Jun 14 10:54:12 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 07:54:12 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Jun 14, 3:27?pm, Aaron Brady wrote: > Hi, please forgive the multi-posting on this general topic. > > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. ?Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. ?Python has no such restriction. > > I tried out an implementation of composite collections, specifically > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > It's significantly slower, but we might argue that attempting to do it > by hand classifies as a premature optimization; it is easy to optimize > debugged code. > > The essentials of the implementation are: > ? - each 'object' gets its own table. > ? ? = this includes immutable types > ? - a reference count table > ? ? = when an object's ref. count reaches zero, its table is dropped > ? - a type-map table > ? ? = maps object's table ID to a string of its type > ? - a single 'entry point' table, with the table ID of the entry-point > object > ? ? = the entry point is the only data structure available to new > connections. ?(I imagine it will usually be a list or dict.) > > I will be sure to kill any interest you might have by now, by > "revealing" a snippet of code. > > The object creation procedure: > > def new_table( self, type ): > ? ''' 'type' is a string, the name of the class the object is an > instance of ''' > ? cur= self.conn.cursor( ) > ? recs= cur.execute( '''SELECT max( tableid ) FROM refcounts''' ) > ? rec= cur.fetchone( ) > ? if rec[ 0 ] is None: > ? ? obid= 0 > ? else: > ? ? obid= rec[ 0 ]+ 1 > ? cur.execute( '''INSERT INTO types VALUES( ?, ? )''', ( obid, > type ) ) > ? cur.execute( '''INSERT INTO refcounts VALUES( ?, ? )''', ( obid, > 1 ) ) > > The increment ref. count procedure: > > def incref( self, obid ): > ? cur= self.conn.cursor( ) > ? recs= cur.execute( '''SELECT count FROM refcounts WHERE tableid > = ?''', ( obid, ) ) > ? rec= recs.fetchone( ) > ? newct= rec[ 0 ]+ 1 > ? cur.execute( '''UPDATE refcounts SET count = ? WHERE tableid = ?''', > ( newct, obid ) ) > > The top-level structure contains these two procedures, as well as > 'setentry', 'getentry', and 'revive' procedures. > > Most notably, user-defined types are possible. ?The dict is merely a > persistent dict. ?'revive' checks the global namespace by name for the > original type, subject to the same restrictions that we all know and > love that 'pickle' has. > > As usual, deadlocks and cyclic garbage pose the usual problems. ?The > approach I used last time was to maintain a graph of acquired locks, > and merely check for cycles to avert deadlocks, which would go in a > separate table. ?For garbage, I can't find a better solution than > Python already uses. > > From the 3.0 docs: > gc.garbage > > ? ? A list of objects which the collector found to be unreachable but > could not be freed (uncollectable objects). > ... > Python doesn?t collect such [garbage] cycles automatically because, in > general, it isn?t possible for Python to guess a safe order in which > to run the __del__() methods. If you know a safe order, you can force > the issue by examining the garbage list, and explicitly breaking > cycles due to your objects within the list. > > Before I go and flesh out the entire interfaces for the provided > types, does anyone have a use for it? I like it as a concept, have not got any use for it this minute, but I am sure it will be useful someday. From rustompmody at gmail.com Sun Jun 14 11:00:17 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 14 Jun 2009 08:00:17 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Jun 14, 6:04?pm, Steven D'Aprano wrote: > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > > Seriously, and without denigrating any specific language, you can program by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. When Dijkstra was asked what next programming language to learn he would typically recommend Latin :-) > Really? So you don't think that the best way to get good at something > is to practice? I think I'm paraphrasing Richard Feynman here, but the > only way to truly understand something is to do it. > Obviously a bit of guided learning is a major boon, but you can't be practice. For every one Horowitz there are a thousand wannbes thumping on the piano trying to become Horowitz. The traction that practice gives is maximal only in the beginning. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 11:07:56 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 01:07:56 +1000 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Graham Ashton wrote: > On 2009-06-14 14:04:02 +0100, Steven D'Aprano > said: > >> Nathan Stoddard wrote: >> >>> The best way to become a good programmer is to program. Write a lot of >>> code; work on some large projects. This will improve your skill more >>> than anything else. >> >> I think there are about 100 million VB code-monkeys who prove that theory >> wrong. > > Really? So you don't think that the best way to get good at something > is to practice? Shame on you for deliberately cutting out my more serious and nuanced answer while leaving a silly quip. As I went on to say: "... you can program by (almost) mindlessly following a fixed number of recipes and patterns. This will get the job done, but it won't make you a good programmer." There are huge numbers (millions?) of lousy programmers who program every single day and never become good programmers. "Practice makes perfect" only works for mechanical skills and rote learning, neither of which are especially applicable to good programming. (Although rote learning is helpful for reducing the time taken to look up syntax and library functions.) Without some level of understanding and creativity, as soon as you hit a problem that can't be efficiently solved by one of the patterns or recipes you've learned, you're in trouble. All the practice in the world won't give you the discipline to write appropriate comments, or to test your code thoroughly. Practice won't *necessarily* make you creative -- you can't be creative in a field you know nothing about, but having learned the language and the libraries doesn't necessarily mean you can apply the tools to solve novel problems. Many programmers know a few good tricks, and try to hammer every problem into a form that can be solved by one of the few tricks they know, no matter whether it is appropriate or not. Witness how many people try to write regexes to parse bracketed expressions, a problem which requires a proper parser. (This is not necessarily a bad thing, but it often is.) You could write a piece of code like: s = "" for word in some_data: s += " " + word a thousand times a day, and *never* learn that this is Bad Code, because you never profile it with more than a few thousand words and so never discover that it's O(n**2). Eventually when it gets released into the real world, somebody reports that it takes eight hours to process 100MB of words, and then *some other guy* re-writes your code to use s = " ".join(words), and you remain in blissful ignorance, happily writing your bad code every single time. > I think I'm paraphrasing Richard Feynman here, but the > only way to truly understand something is to do it. An amazingly inappropriate quote for a *theoretical* physicist to have said. Whether Feynman did or didn't say that, it's clearly untrue: many people do without understanding. Many people can cook, some people are expert cooks, but few people understand precisely what takes place when you cook food. People can catch and throw balls, and have little or no understanding of gravity, air-resistance, and the mechanics of their own bodies. In fact... just before you hit Delete on this post, how about you explain *how* you make your finger reach out and press the Delete key? You probably move bits of your body a million times a day, and the chances are very high that until now, you've never once noticed that you have no idea how you do it. I think that simple fact blows out of the water the concept that doing implies understanding. > Obviously a bit of guided learning is a major boon, but you can't be > practice. I didn't say that practice was useless. Arguably, it may even be necessary to be a good programmer. (Although less so for an unsurprising language like Python, where it is very common to write code which works correctly the first time.) But practice is clearly not *sufficient* to be a good programmer. -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 11:24:48 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 01:24:48 +1000 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <02450869$0$20636$c3e8da3@news.astraweb.com> Aaron Brady wrote: > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. Python has no such restriction. ... > I will be sure to kill any interest you might have by now, by > "revealing" a snippet of code. How about telling us what problem you're trying to solve? Giving us your implementation isn't useful if we don't even know what it's for. Persistent data on disk, okay, I get that -- but how is it different from (say) XML, or INI files, or pickles, or similar? Is the idea to have *live* data stored on disk, updated by multiple processes simultaneously? Don't assume that people will remember your recommendation from "some time ago". -- Steven From piet at cs.uu.nl Sun Jun 14 11:37:04 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 17:37:04 +0200 Subject: Question about None References: Message-ID: >>>>> John Yeung (JY) wrote: >JY> I've never heard a mathematician use the term "bottom". It certainly >JY> could be that I just haven't talked to the right types of >JY> mathematicians. "Bottom" is a term from lattice theory, which is a branch of mathematics. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From spam.helmut.hard at gmail.com Sun Jun 14 11:42:23 2009 From: spam.helmut.hard at gmail.com (Helmut Fritz) Date: Sun, 14 Jun 2009 17:42:23 +0200 Subject: shoehorn c-structured data into Numpy Message-ID: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Hello there everyone, I used to be on this a long time ago but then I got so much spam I gave up. But this strategy has come a little unstuck. I have binary output from a Fortran program that is in a big-endian C-structured binary file. The output can be very variable and many options create different orderings in the binary file. So I'd like to keep the header-reading in python. Anyhoo, I've so far been able to read the output with the struct module. But my question is how do I create numpy arrays from the bits of the file I want? So far I've been able to scan through to the relevant sections and I've tried all maner of idiotic combinations... The floats are 4 bytes for sinngle percision, and it's a unstructured grid from a finite difference scheme so I know the number of cells (ncells) for the property I am looking to extract. So I've tried: TC1 = np.frombuffer(struct.unpack(">%df" % ncells, data.read(4*ncells))[0], dtype=float) Only to get a very logical: >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 239, in spmapdat >>> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, data.read(4*ncells))[0], dtype=float) >>> AttributeError: 'float' object has no attribute '__buffer__' ok... so I'll feed frombuffer my data file... And then tried: TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 240, in spmapdat >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) >>> ValueError: buffer is smaller than requested size And THEN I tried: TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 240, in spmapdat >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) >>> ValueError: buffer is smaller than requested size But it's the right size - honest. (In general) I should be able to put these arrays into memory with no problems. Certainly given the rate at which I'm turning around this code... Memory may be in the terabytes once I'm done. Anyone got a Sesame Street answer for this? Many thanks! Helmut. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Sun Jun 14 11:49:42 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 17:49:42 +0200 Subject: Question about None In-Reply-To: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <6faf39c90906140849v37c0f5dfu251c4e678db9483@mail.gmail.com> On Sat, Jun 13, 2009 at 7:23 PM, John Yeung wrote: > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. ?It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. ?In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. I don't see why that would be the case. Something of the type "thingy" is ONE thingy. Nothing is ZERO thingies, so it is not something of the type "thingy". A car is a single car. Nothing is zero cars, which is not a car, just like two cars is not a car. -- Andr? Engels, andreengels at gmail.com From martin at v.loewis.de Sun Jun 14 11:52:32 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 14 Jun 2009 17:52:32 +0200 Subject: Generating a unique filename in the face of unicode filename In-Reply-To: References: Message-ID: <4a351cc1$0$20516$9b622d9e@news.freenet.de> > where line 175 is the assignment to self.unique_name. After a little > back-and-forth with his user it turns out that her computer's hostname > contains non-ASCII data, so presumably self.hostname is a unicode object. Most likely, it is not. It's rather the hostname encoded in the ANSI code page. > It works for Frank on his Windows box as well. Any ideas how to properly > Unicode-proof this code? You should first decode the gethostname result, using the locale's encoding; expect this decoding to fail possibly, so the "ignore" error handler might be your best choice. Regards, Martin From koranthala at gmail.com Sun Jun 14 12:01:26 2009 From: koranthala at gmail.com (koranthala) Date: Sun, 14 Jun 2009 09:01:26 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: <33972035-e5fd-4b5b-ac9b-128cb15ee2d0@d7g2000prl.googlegroups.com> > There are huge numbers (millions?) of lousy programmers who program every > single day and never become good programmers. I think I can attest to that. I was a programmer (in a low level language) in a huge MNC code monkey shop for > 7 years. I consider myself to be Ok - not great, but not very poor either. I had written a lot of code in those 7 years, but due to lack of exposure and laziness, never knew that I have to read books. As I mentioned before, I come in from a non-computing engineering degree, so I did not even know which books to read etc. I had seen many of the frameworks written by others, and was extremely impressed. I considered those people who wrote those frameworks to be geniuses - until I accidently came across one site where I read about GOF. I bought it and read it - and straight away understood that whatever I learned in the last 7 years, I could have learned most of them in 6 months, provided I had read the right books. All the frameworks were just amalgamation of these patterns. Now, I voraciously purchase and read books - both in the domain of my work and on computer science in general. Even though I am not going to be recruited by google any time soon :-), I think I have become a much better programmer over the last one year. I see my code before 1 year and I am horrified :-). Practice makes perfect only if you push yourself - and you need exposure to know that. From cjns1989 at gmail.com Sun Jun 14 12:15:59 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 14 Jun 2009 12:15:59 -0400 Subject: Good books in computer science? In-Reply-To: <0244e76b$0$20638$c3e8da3@news.astraweb.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <20090614161559.GB2558@turki.gavron.org> On Sun, Jun 14, 2009 at 09:04:02AM EDT, Steven D'Aprano wrote: > Nathan Stoddard wrote: > > > The best way to become a good programmer is to program. Write a lot of > > code; work on some large projects. This will improve your skill more than > > anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > > Seriously, and without denigrating any specific language, you can program by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. Vivaldi vs. Mozart And the latter especially had definitely mastered his editor. Just think of the sheer volume of the coding he managed during his short life. Not many bugs either? CJ From fsb at thefsb.org Sun Jun 14 12:35:24 2009 From: fsb at thefsb.org (tom) Date: Sun, 14 Jun 2009 09:35:24 -0700 (PDT) Subject: waling a directory with very many files Message-ID: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for example, in c, perl or php one can use opendir() and then repeatedly readdir() until getting to the end of the file list. it seems this could be more efficient in some applications. is there a way to do this in python? i'm relatively new to the language. i looked through the documentation and tried googling but came up empty. From castironpi at gmail.com Sun Jun 14 12:41:06 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 09:41:06 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <02450869$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Jun 14, 8:24?am, Steven D'Aprano wrote: > Aaron Brady wrote: > > Some time ago, I recommended a pursuit of keeping 'persistent > > composite' types on disk, to be read and updated at other times by > > other processes. ?Databases provide this functionality, with the > > exception that field types in any given table are required to be > > uniform. ?Python has no such restriction. > ... > > I will be sure to kill any interest you might have by now, by > > "revealing" a snippet of code. > > How about telling us what problem you're trying to solve? Giving us your > implementation isn't useful if we don't even know what it's for. Persistent > data on disk, okay, I get that -- but how is it different from (say) XML, > or INI files, or pickles, or similar? Is the idea to have *live* data > stored on disk, updated by multiple processes simultaneously? Don't assume > that people will remember your recommendation from "some time ago". > > -- > Steven It was no time at all in the Usenet world, I suppose. There are lots of strategies for storing data on a disk, and lots of strategies for storing data in memory. I was trying on disk what Python uses on memory. If you want to argue that Python isn't useful, you're in the wrong place. If you want to argue that Python's strategy is useful on disks, you're talking to the right person. I'll draw an analogy. static data structures : sql & co. :: Python data structures : this undertaking. It has all the advantages over SQL & XML structures that Python has over C structures: sort of a 'worst of neither' combination. I haven't written a textbook on DSs, though, so I don't quite know where to begin. In my eyes, you're practically asking, "What's your use case for Python?" Either that, or I don't know enough other languages. I have nothing to use it for, but someone might, and it might be just plumb interesting to fellow Pythoneers. If I did, I'd have somewhere to start. From paul.lafollette at gmail.com Sun Jun 14 12:49:56 2009 From: paul.lafollette at gmail.com (Paul LaFollette) Date: Sun, 14 Jun 2009 12:49:56 -0400 Subject: Question about None Message-ID: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Thank you all for your thoughtful and useful comments. Since this has largely morphed into a discussion of my 3rd question, perhaps it would interest you to hear my reason for asking it. John is just about spot on. Part of my research involves the enumeration and generation of various combinatorial objects using what are called "loopless" or "constant time" algorithms. (This means that the time required to move from one object to the next is bounded by a constant that is independent of the size of the object. It is related to following idea: If I generate all of the possible patterns expressible with N bits by simply counting in binary, as many as N bits may change from one pattern to the next. On the other hand if I use Gray code only one bit changes from each pattern to the next. If you are interested in this essentially useless (but fun) subject, the seminal paper by Gideon Ehrlich is here: http://portal.acm.org/citation.cfm?id=321781 ) Now, suppose that I want to generate, say, the set of all ordered trees with N nodes. I need to be able to represent the empty ordered tree, i.e. the tree with with zero nodes. There are a lot of ways I could do this. The problem is that I might tomorrow be looking instead at rooted trees, or free trees, or Young tableaux and in each case I will need to represent the empty rooted tree, or the empty free tree, or the empty Young tableau. In a very real sense, the empty Young tableau IS a Young tableau and the empty ordered tree IS an ordered tree. But in an equally real sense they are the same "ghost of a thing" looked at in different universes of discourse. So, what I would like is some sort of object that is a "kind of" everything but contains nothing, a unique minimal element of the partial ordering imposed on the set of classes by the inheritance heierarchy. Whilst I am not naive mathematically, I am relatively naive in the area of language design. In my naivete, it seemed to me that None could have been designed to be such a thing. Apparently that is incorrect. The matter is not urgent, there are oodles of workarounds. Indeed, having once found a particular loopless algorithm I don't necessarily publish an implementation of it, but rather a formal description and proof of correctness. Still, before I submit things for publication I generally prefer to implement them for myself just to convince myself that what I have proved correct in fact works at least for modest values of N. Paul ____________________________________ paul[dot]lafollette[at]gmail.com http://www.cis.temple.edu/~lafollet From arnodel at googlemail.com Sun Jun 14 13:02:54 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 14 Jun 2009 18:02:54 +0100 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > So-called "vacuous truth". It's often useful to have all([]) return true, > but it's not *always* useful -- there are reasonable cases where the > opposite behaviour would be useful: > > if all(the evidence points to the Defendant's guilt) then: > the Defendant is guilty > execute(the Defendant) > > sadly means that if there is no evidence that a crime has been committed, > the person accused of committing the imaginary crime will be executed. This is a bad example. Someone is not convicted of a crime just because all the available evidence points towards their guilt. There may be very little evidence altogether, or it might just be circumstancial, or unconvincing. Even though it may all point towards the defendent's guilt, it doesn't mean they will be convicted. There needs to be enough evidence to convince the jury. So it would be something like: if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: the defendant is guilty ... -- Arnaud From python at mrabarnett.plus.com Sun Jun 14 13:17:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 18:17:17 +0100 Subject: shoehorn c-structured data into Numpy In-Reply-To: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> References: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Message-ID: <4A35309D.5040005@mrabarnett.plus.com> Helmut Fritz wrote: > > Hello there everyone, I used to be on this a long time ago but then I > got so much spam I gave up. > > But this strategy has come a little unstuck. I have binary output from > a Fortran program that is in a big-endian C-structured binary file. The > output can be very variable and many options create different orderings > in the binary file. So I'd like to keep the header-reading in python. > > Anyhoo, I've so far been able to read the output with the struct > module. But my question is how do I create numpy arrays from the bits > of the file I want? > > So far I've been able to scan through to the relevant sections and I've > tried all maner of idiotic combinations... > > The floats are 4 bytes for sinngle percision, and it's a unstructured > grid from a finite difference scheme so I know the number of cells > (ncells) for the property I am looking to extract. > > So I've tried: > TC1 = np.frombuffer(struct.unpack(">%df" % ncells, > data.read(4*ncells))[0], dtype=float) > Only to get a very logical: > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 239, in spmapdat > >>> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, > data.read(4*ncells))[0], dtype=float) > >>> AttributeError: 'float' object has no attribute '__buffer__' > This: struct.unpack(">%df" % ncells, data.read(4*ncells)) unpacks to a tuple of floats, from which you get the first (actually the zeroth) float. You probably didn't want to do that! :-) Try: TC1 = np.array(struct.unpack(">%df" % ncells, data.read(4 * ncells)), dtype=float) > ok... so I'll feed frombuffer my data file... > > And then tried: > TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 240, in spmapdat > >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) > >>> ValueError: buffer is smaller than requested size > > And THEN I tried: > TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 240, in spmapdat > >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, > count=4*ncells) > >>> ValueError: buffer is smaller than requested size > > But it's the right size - honest. > > (In general) I should be able to put these arrays into memory with no > problems. Certainly given the rate at which I'm turning around this > code... Memory may be in the terabytes once I'm done. > > Anyone got a Sesame Street answer for this? > > Many thanks! Helmut. > From jaime.frio at gmail.com Sun Jun 14 13:18:53 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Sun, 14 Jun 2009 19:18:53 +0200 Subject: persistent composites In-Reply-To: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <97a8f1a70906141018r6a2fd83es388262b764f9229b@mail.gmail.com> On Sun, Jun 14, 2009 at 4:27 PM, Aaron Brady wrote: > > Before I go and flesh out the entire interfaces for the provided > types, does anyone have a use for it? A real-world application of persistent data structures can be found here: http://stevekrenzel.com/persistent-list Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From andreengels at gmail.com Sun Jun 14 13:26:31 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 19:26:31 +0200 Subject: Question about None In-Reply-To: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Message-ID: <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> On Sun, Jun 14, 2009 at 6:49 PM, Paul LaFollette wrote: > Now, suppose that I want to generate, say, the set of all ordered > trees with N nodes. ? I need to be able to represent the empty ordered > tree, i.e. the tree with with zero nodes. ?There are a lot of ways I > could do this. ?The problem is that I might tomorrow be looking > instead at rooted trees, or free trees, or Young tableaux and in each > case I will need to represent the empty rooted tree, or the empty free > tree, or the empty Young tableau. > > In a very real sense, the empty Young tableau IS a Young tableau and > the empty ordered tree IS an ordered tree. ?But in an equally real > sense they are the same "ghost of a thing" looked at in different > universes of discourse. But do you also want the empty Young tableau to BE an ordered tree? A number? A diddlewoodaddy? It seems much more logical to me to define your Young tableaus such that the definition includes the empty one as well. -- Andr? Engels, andreengels at gmail.com From mail at timgolden.me.uk Sun Jun 14 13:35:23 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 14 Jun 2009 18:35:23 +0100 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A3534DB.5080604@timgolden.me.uk> tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). TJG From python at mrabarnett.plus.com Sun Jun 14 14:00:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 19:00:26 +0100 Subject: Question about None In-Reply-To: <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> Message-ID: <4A353ABA.7030206@mrabarnett.plus.com> Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:49 PM, Paul > LaFollette wrote: >> Now, suppose that I want to generate, say, the set of all ordered >> trees with N nodes. I need to be able to represent the empty ordered >> tree, i.e. the tree with with zero nodes. There are a lot of ways I >> could do this. The problem is that I might tomorrow be looking >> instead at rooted trees, or free trees, or Young tableaux and in each >> case I will need to represent the empty rooted tree, or the empty free >> tree, or the empty Young tableau. >> >> In a very real sense, the empty Young tableau IS a Young tableau and >> the empty ordered tree IS an ordered tree. But in an equally real >> sense they are the same "ghost of a thing" looked at in different >> universes of discourse. > > But do you also want the empty Young tableau to BE an ordered tree? A > number? A diddlewoodaddy? It seems much more logical to me to define > your Young tableaus such that the definition includes the empty one as > well. > For strings there's the empty string with the same methods. It's not the same as None. For lists there's the empty list with the same methods. It's not the same as None. For dicts there's the empty dict with the same methods. It's not the same as None. For sets there's the empty set with the same methods. It's not the same as None. etc. From fsb at thefsb.org Sun Jun 14 14:32:12 2009 From: fsb at thefsb.org (tom) Date: Sun, 14 Jun 2009 11:32:12 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> On Jun 14, 1:35?pm, Tim Golden wrote: > > If you're on Windows, you can use the win32file.FindFilesIterator > function from the pywin32 package. (Which wraps the Win32 API > FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd and os x. From castironpi at gmail.com Sun Jun 14 14:32:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 11:32:35 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: <9638ebf3-a8df-4113-9dbc-d941eede562c@i28g2000prd.googlegroups.com> On Jun 14, 10:02?am, Arnaud Delobelle wrote: snip > guilt, it doesn't mean they will be convicted. ?There needs to be enough > evidence to convince the jury. ?So it would be something like: > > if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: > ? ?the defendant is guilty > ? ?... > > -- > Arnaud You all are only two months late. http://groups.google.com/group/comp.lang.python/msg/7b63d0d11246ecad Can't argue with results. From CGenie at gmail.com Sun Jun 14 14:43:17 2009 From: CGenie at gmail.com (CoolGenie) Date: Sun, 14 Jun 2009 11:43:17 -0700 (PDT) Subject: efficient undo/redo in pyqt Message-ID: Hello, I'm writing a small component for drawing, in PyQt4. Currently I'm implementing undo/redo through Qt's framework. I create a list which contains points, lines, etc. which appear as the user draws on the screen. On every paint event the list is read, processed and drawn. This way doing is just adding elements, and undoing is popping them from the list. My question: is this an efficient way or could this be done any better? The code is here http://sourceforge.net/svn/?group_id=252201 if anyone is interested. Best regards, Przemek From jeremy.r.fishman at gmail.com Sun Jun 14 15:00:33 2009 From: jeremy.r.fishman at gmail.com (Jeremy) Date: Sun, 14 Jun 2009 12:00:33 -0700 (PDT) Subject: weakrefs, threads,, and object ids Message-ID: <84397edd-4830-4c90-9fb6-f72c74028f6e@i28g2000prd.googlegroups.com> Hello, I'm using weakrefs in a small multi-threaded application. I have been using object IDs as dictionary keys with weakrefs to execute removal code, and was glad to find out that this is in fact recommended practice (http://docs.python.org/library/weakref.html) > This simple example shows how an application can use objects IDs to retrieve > objects that it has seen before. The IDs of the objects can then be used in other > data structures without forcing the objects to remain alive, but the objects can > still be retrieved by ID if they do. After reading this, I realized it made no explicit mention of thread safety in this section, whereas other sections made a note of correct practice with threads. The docs for the id() function specify > Return the identity of an object. This is guaranteed to be unique among > simultaneously existing objects. (Hint: it's the object's memory address.) While guaranteed unique for simultaneously existing objects, how often will an object assume an ID previously held by former object? Given that the ID is a memory address in Python's heap, I assume the answer is either not often, or very often. Specifically, I'm wondering if the case can occur that the callback for a weakref is executed after another object has been allocated with the same object identifier as a previous object. If such an object is inserted into a module-level dictionary, could it over-write a previous entry with the same identifier and then get deleted whenever the weakref callback happens to fire? On a related note, what is a recommended way to obtain a weak reference to a thread? From pataphor at gmail.com Sun Jun 14 15:14:55 2009 From: pataphor at gmail.com (pataphor) Date: Sun, 14 Jun 2009 21:14:55 +0200 Subject: left brain and right brain permutations Message-ID: left brain: Generate permutations by index, see previous newsgroup posts. Code not now available here. They are very pragmatic and practical, can start right away, and can be efficiently spread over many independent computing cores. right brain: from itertools import izip, chain from math import factorial def expand(i,n): for _ in xrange(i+1): yield i+1 for _ in xrange(n-i): yield i def firstrow(n): for i in xrange(n+1): for _ in xrange(factorial(n)): yield i def otherrow(x,n): return chain(*izip(*(expand(i,n) for i in x))) def nextperm(L,n): yield firstrow(n) for x in L: yield otherrow(x,n) def perm(n): L = [[0]] for i in xrange(1,n): L = nextperm(L,i) return izip(*L) They are very hard to understand but can yield deep insights, once one gets into them they hint at hidden regularities and symmetries, maybe even parallel worlds. Unfortunately they are very impractical because they generate their future out of previous results. Until someone invents a quantum computer. From that point on though they leave every left brain piece of code behind as if that old code would stand still on its spot. So, its not like I don't understand the functional mind, believe me, I would like nothing more than to go that way, but until quantum computing is there this stuff won't be able to compete. (Background, ignore this post, it is just for future reference, comments are still welcome though) P. From benjamin.kaplan at case.edu Sun Jun 14 15:16:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 14 Jun 2009 15:16:04 -0400 Subject: Good books in computer science? In-Reply-To: <0244e76b$0$20638$c3e8da3@news.astraweb.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Sun, Jun 14, 2009 at 9:04 AM, Steven D'Aprano < steve at removethis.cybersource.com.au> wrote: > Nathan Stoddard wrote: > > > The best way to become a good programmer is to program. Write a lot of > > code; work on some large projects. This will improve your skill more than > > anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > There aren't 100 million VB code-monkeys. There are 100 million VB drag-and-drop monkeys, but they never actually wrote any program by themselves- Daddy Microsoft wrote a lot of it for them. > > Seriously, and without denigrating any specific language, you can program > by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Sun Jun 14 15:21:51 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 14 Jun 2009 20:21:51 +0100 Subject: waling a directory with very many files In-Reply-To: <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: <4A354DCF.8070105@timgolden.me.uk> tom wrote: > On Jun 14, 1:35 pm, Tim Golden wrote: >> If you're on Windows, you can use the win32file.FindFilesIterator >> function from the pywin32 package. (Which wraps the Win32 API >> FindFirstFile / FindNextFile pattern). > > thanks, tim. > > however, i'm not using windows. freebsd and os x. Presumably, if Perl etc. can do it then it should be simple enough to drop into ctypes and call the same library code, no? (I'm not a BSD / OS X person, I'm afraid, so perhaps this isn't so easy...) TJG From http Sun Jun 14 15:37:34 2009 From: http (Paul Rubin) Date: 14 Jun 2009 12:37:34 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Andre Engels writes: > I don't see why that would be the case. Something of the type "thingy" > is ONE thingy. Nothing is ZERO thingies, so it is not something of the > type "thingy". A car is a single car. Nothing is zero cars, which is > not a car, just like two cars is not a car. That seems to confuse values with collections of them. A car is not the same as a one-element list of cars. Nothing is not the same as a zero-element list of cars. From andreengels at gmail.com Sun Jun 14 16:11:18 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:11:18 +0200 Subject: Question about None In-Reply-To: <7xfxe2ehdt.fsf@ruckus.brouhaha.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: <6faf39c90906141311x779d459dhbe87a63b2b7b65a8@mail.gmail.com> On Sun, Jun 14, 2009 at 9:37 PM, Paul Rubin wrote: > Andre Engels writes: >> I don't see why that would be the case. Something of the type "thingy" >> is ONE thingy. Nothing is ZERO thingies, so it is not something of the >> type "thingy". A car is a single car. Nothing is zero cars, which is >> not a car, just like two cars is not a car. > > That seems to confuse values with collections of them. ?A car is not > the same as a one-element list of cars. ?Nothing is not the same as a > zero-element list of cars. So you are of the opinion that "nothing" _is_ a car? -- Andr? Engels, andreengels at gmail.com From http Sun Jun 14 16:21:14 2009 From: http (Paul Rubin) Date: 14 Jun 2009 13:21:14 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: <7xprd6o9c5.fsf@ruckus.brouhaha.com> Andre Engels writes: > > That seems to confuse values with collections of them. ??A car is not > > the same as a one-element list of cars. ??Nothing is not the same as a > > zero-element list of cars. > > So you are of the opinion that "nothing" _is_ a car? Eh? No of course not. a != b and b != c does not mean a==c. I don't understand what you're getting at. From andreengels at gmail.com Sun Jun 14 16:30:32 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:30:32 +0200 Subject: Question about None In-Reply-To: <7xprd6o9c5.fsf@ruckus.brouhaha.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> <7xprd6o9c5.fsf@ruckus.brouhaha.com> Message-ID: <6faf39c90906141330pc4cce2ai3dba204eefdb72d2@mail.gmail.com> On Sun, Jun 14, 2009 at 10:21 PM, Paul Rubin wrote: > Andre Engels writes: >> > That seems to confuse values with collections of them. ??A car is not >> > the same as a one-element list of cars. ??Nothing is not the same as a >> > zero-element list of cars. >> >> So you are of the opinion that "nothing" _is_ a car? > > Eh? ?No of course not. ?a != b and b != c does not mean a==c. > I don't understand what you're getting at. I was making a point that I don't agree that "nothing" would match any type. The reason was that anything of the type car is one car, not two cars or zero cars, but "nothing" is zero cars. You don't agree with me, so apparently you are of the opinion that "nothing" would be a car. -- Andr? Engels, andreengels at gmail.com From Scott.Daniels at Acm.Org Sun Jun 14 16:32:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 14 Jun 2009 13:32:07 -0700 Subject: shoehorn c-structured data into Numpy In-Reply-To: References: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Message-ID: MRAB wrote: > Helmut Fritz wrote: >> I have binary output >> from a Fortran program that is in a big-endian C-structured binary >> file. The output can be very variable and many options create >> different orderings in the binary file. So I'd like to keep the >> header-reading in python. >> >> Anyhoo, I've so far been able to read the output with the struct >> module. But my question is how do I create numpy arrays from the bits >> of the file I want? >> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, >> data.read(4*ncells))[0], dtype=float) Note both struct and numpy.frombuffer unpack data from a buffer. Do it only once: If you are going to a numpy array: TC1 = np.frombuffer(data.read(4*ncells)), dtype=float) # and possibly: TC1.byteswap(True) # True to byteswap in place. Or (even better -- less copying): TC1 = np.fromfile(data, count=ncells, dtype=float) # and again, possibly: TC1.byteswap(True) # True to byteswap in place. --Scott David Daniels Scott.Daniels at Acm.Org From andreengels at gmail.com Sun Jun 14 16:35:50 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:35:50 +0200 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. What kind of directories are those that just a list of files would result in a "very large" object? I don't think I have ever seen directories with more than a few thousand files... -- Andr? Engels, andreengels at gmail.com From wayne.dads.bell at gmail.com Sun Jun 14 16:47:52 2009 From: wayne.dads.bell at gmail.com (dads) Date: Sun, 14 Jun 2009 13:47:52 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> I'm wanting to purchase some of the titles that have been raised in this thread. When I look they are very expensive books which is understandable. Do you think getting earlier editions that are cheaper is a daft thing or should I fork out the extra ?10-?30 to get the latest edition? From http Sun Jun 14 17:18:22 2009 From: http (Paul Rubin) Date: 14 Jun 2009 14:18:22 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> Message-ID: <7xljnu1plt.fsf@ruckus.brouhaha.com> dads writes: > I'm wanting to purchase some of the titles that have been raised in > this thread. When I look they are very expensive books which is > understandable. Do you think getting earlier editions that are cheaper > is a daft thing or should I fork out the extra ?10-?30 to get the > latest edition? It depends on the book. Also, keep in mind that quite a few good books these days are online where you can read them for free. SICP (mentioned in my earlier post) is one of them. From http Sun Jun 14 17:19:37 2009 From: http (Paul Rubin) Date: 14 Jun 2009 14:19:37 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> <7xprd6o9c5.fsf@ruckus.brouhaha.com> Message-ID: <7xhbyi1pjq.fsf@ruckus.brouhaha.com> Andre Engels writes: > I was making a point that I don't agree that "nothing" would match any > type. The reason was that anything of the type car is one car, not two > cars or zero cars, but "nothing" is zero cars. You don't agree with > me, so apparently you are of the opinion that "nothing" would be a car. I don't agree that "nothing" is "zero cars". Just like I don't agree that the empty set, the empty list, and the empty string are the same thing. From kay at fiber-space.de Sun Jun 14 17:29:04 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sun, 14 Jun 2009 14:29:04 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Message-ID: <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> On 14 Jun., 16:00, Steven D'Aprano wrote: > Incorrect. Koch's snowflake, for example, has a fractal dimension of log > 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial triangle, > and a perimeter given by lim n->inf (4/3)**n. Although the perimeter is > infinite, it is countably infinite and computable. No, the Koch curve is continuous in R^2 and uncountable. Lawrence is right and one can trivially cover a countable infinite set with disks of the diameter 0, namely by itself. The sum of those diameters to an arbitrary power is also 0 and this yields that the Hausdorff dimension of any countable set is 0. From org.python.pythonlist at pooryorick.com Sun Jun 14 17:41:47 2009 From: org.python.pythonlist at pooryorick.com (Poor Yorick) Date: Sun, 14 Jun 2009 17:41:47 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored Message-ID: <4A356E9B.30806@pooryorick.com> The following code produces an error (python-2.6.2). Either of the following eliminates the error: . assign something besides mod1 (the newly-created module) to d1 . remove the call to shelve.open Why is there an error produced in the first place? What is the interaction between d1, mod1, and shelve about? This code runs without error in python-3.1 $ cat test1.py import test2 newmodule = test2.load() $ cat test2.py import imp import shelve def load(): text='import test2\n' text += '''print('hello from test3')\n''' code = compile(text,'', 'exec') mod1 = imp.new_module('newmodule') newdict = mod1.__dict__ #newdict = {} exec(code,newdict) mod1 mode = mod1 d1['unique'] = mod1 #d1['unique'] = '' return mod1 print('hello from test2') d1 = {} cache = shelve.open('persist') $ python2.6 test1.py hello from test2 hello from test3 Exception TypeError: "'NoneType' object is not callable" in ignored Exception TypeError: "'NoneType' object is not callable" in ignored -- Yorick From rhodri at wildebst.demon.co.uk Sun Jun 14 18:23:06 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:23:06 +0100 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 12:02:47 +0100, kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ordered = o{}, multidict = m{} (like paste multidict). So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . (they should also probably have there own > comprehensions as well o{foo for bar in foobar}). -1. And before you ask, that would have been my reaction to the 'u' and 'b' string prefixes as well. Python has perfectly good constructors for any class already, and it's perfectly obvious what they're doing because they involve the class name. Obfuscating this by using one character modifiers on existing literal syntax and expecting the result to be (a) obvious and (b) meaningful in the face of an ever-extending collection of basic types is optimistic in the extreme. Even Perl doesn't expect that much memory of you! -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Jun 14 18:28:44 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:28:44 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton wrote: > On 2009-06-14 14:04:02 +0100, Steven D'Aprano > said: > >> Nathan Stoddard wrote: >> >>> The best way to become a good programmer is to program. Write a lot of >>> code; work on some large projects. This will improve your skill more >>> than >>> anything else. >> I think there are about 100 million VB code-monkeys who prove that >> theory >> wrong. > > Really? So you don't think that the best way to get good at something is > to practice? Self-evidently. If what you practice is bad practice, it doesn't matter how much you practice it you'll still be no good at good practice in practice. Practically speaking, that is :-) -- Rhodri James *-* Wildebeest Herder to the Masses From ldo at geek-central.gen.new_zealand Sun Jun 14 18:39:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 10:39:50 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: In message <0050ecf7$0$9684$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > Graham Ashton wrote: > >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: >> >>> Nathan Stoddard wrote: >>> >>>> The best way to become a good programmer is to program. Write a lot of >>>> code; work on some large projects. This will improve your skill more >>>> than anything else. >>> >>> I think there are about 100 million VB code-monkeys who prove that >>> theory wrong. >> >> Really? So you don't think that the best way to get good at something >> is to practice? > > Shame on you for deliberately cutting out my more serious and nuanced > answer while leaving a silly quip. Can't have been very "serious and nuanced" if it could be summed up by such a "silly quip" though, could it? From ldo at geek-central.gen.new_zealand Sun Jun 14 18:42:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 10:42:50 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: In message , Chris Jones wrote: > Vivaldi vs. Mozart > > And the latter especially had definitely mastered his editor. Just think > of the sheer volume of the coding he managed during his short life. > > Not many bugs either? I thought Vivaldi did more. The style of music was such that they could virtually sketch it out in shorthand, and leave it to the copyists to expand to proper notation for the musicians to play. I imagine that it was also the job of copyists to fix the typos. In other words, high productivity was a direct consequence of adoption of a cookie-cutter style. From python at mrabarnett.plus.com Sun Jun 14 18:52:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 23:52:15 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4A357F1F.6060407@mrabarnett.plus.com> Rhodri James wrote: > On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton > wrote: > >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: >> >>> Nathan Stoddard wrote: >>> >>>> The best way to become a good programmer is to program. Write a lot of >>>> code; work on some large projects. This will improve your skill more >>>> than >>>> anything else. >>> I think there are about 100 million VB code-monkeys who prove that >>> theory >>> wrong. >> >> Really? So you don't think that the best way to get good at something >> is to practice? > > Self-evidently. If what you practice is bad practice, it doesn't matter > how much you practice it you'll still be no good at good practice in > practice. Practically speaking, that is :-) > True. And there's no point in practising if you don't understand what you're doing or why you're doing it that way. There are plenty of good tutorials for Python, for example, but if you can't follow any of them (assuming that it's not just a language problem), or can't be bothered to read any of them, then you probably shouldn't be a programmer. From rhodri at wildebst.demon.co.uk Sun Jun 14 18:52:19 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:52:19 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> 2. That output string has severe "leaning toothpick" syndrome. Python >> accepts both single and double quotes to help avoid creating something >> so unreadable: use them. > > Backslashes are more scalable. Yes, yes, you can print them at any size. That doesn't excuse sprinkling several million backslashes through literal constants when there's a more readable alternative. -- Rhodri James *-* Wildebeest Herder to the Masses From peter at www.pjb.com.au Sun Jun 14 19:06:49 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 14 Jun 2009 23:06:49 GMT Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Message-ID: >> In message , Peter Billam wrote: >>> Are there any modules, packages, whatever, that will >>> measure the fractal dimensions of a dataset, e.g. a time-series ? > Lawrence D'Oliveiro wrote: >> I don't think any countable set, even a countably-infinite set, can >> have a fractal dimension. It's got to be uncountably infinite, and >> therefore uncomputable. You need a lot of data-points to get a trustworthy answer. Of course edge-effects step in as you come up against the spacing betwen the points; you'd have to weed those out. On 2009-06-14, Steven D'Aprano wrote: > Strictly speaking, there's not one definition of "fractal dimension", there > are a number of them. One of the more useful is the "Hausdorf dimension", They can be seen as special cases of Renyi's generalised entropy; the Hausdorf dimension (D0) is easy to compute because of the box-counting-algorithm: http://en.wikipedia.org/wiki/Box-counting_dimension Also easy to compute is the Correlation Dimension (D2): http://en.wikipedia.org/wiki/Correlation_dimension Between the two, but much slower, is the Information Dimension (D1) http://en.wikipedia.org/wiki/Information_dimension which most closely corresponds to physical entropy. Multifractals are very common in nature (like stock exchanges, if that counts as nature :-)) http://en.wikipedia.org/wiki/Multifractal_analysis but there you really need _huge_ datasets to get useful answers ... There have been lots of papers published (these are some refs I have: G. Meyer-Kress, "Application of dimension algorithms to experimental chaos," in "Directions in Chaos", Hao Bai-Lin ed., (World Scientific, Singapore, 1987) p. 122 S. Ellner, "Estmating attractor dimensions for limited data: a new method, with error estimates" Physi. Lettr. A 113,128 (1988) P. Grassberger, "Estimating the fractal dimensions and entropies of strange attractors", in "Chaos", A.V. Holden, ed. (Princeton University Press, 1986, Chap 14) G. Meyer-Kress, ed. "Dimensions and Entropies in Chaotic Systems - Quantification of Complex Behaviour", vol 32 of Springer series in Synergetics (Springer Verlag, Berlin, 1986) N.B. Abraham, J.P. Gollub and H.L. Swinney, "Testing nonlinear dynamics," Physica 11D, 252 (1984) ) but I haven't chased these up and I don't think they contain any working code. But the work has been done, so the code must be there still, on some computer somwhere... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From tjreedy at udel.edu Sun Jun 14 19:14:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:14:10 -0400 Subject: Question about None In-Reply-To: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > So-called "vacuous truth". It's often useful to have all([]) return > true, but it's not *always* useful -- there are reasonable cases > where the opposite behaviour would be useful: > > if all(the evidence points to the Defendant's guilt) then: the > Defendant is guilty execute(the Defendant) > > sadly means that if there is no evidence that a crime has been > committed, the person accused of committing the imaginary crime will > be executed. It seems to me that the absurd conclusion implied by the theorem invalidates the theorem rather than supporting your point. No evidence is only the endpoint of a continuum. Suppose that 'all' is one teensy weensy bit of evidence. A drunked bystander gives a vague description that fits. Or twenty years before, the defendent argued with the deceased and said 'I wish you were dead'. Should the person be executed? I say not. You? Of course, a person would only be a defendant in the absence of evidence under a depraved regime that would not much care if there were. Try finding another 'reasonable case'. Terry Jan Reedy From tjreedy at udel.edu Sun Jun 14 19:27:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:27:46 -0400 Subject: Question about None In-Reply-To: References: Message-ID: Mel wrote: > John Yeung wrote: > >> And I accept your answer, as well as Steven's and Paul's for that >> matter. I still think it is understandable (and people may choose to >> understand in a condescending way, if they wish) that someone might >> not get the difference between what you are saying and the statement >> that all elements of the empty set are floats. I mean, what's in the >> empty set? Nothing. But you've said that floats are something. How >> is it that nothing is something? > > It's sort of a logic equivalent of divide-by-zero. > > All elements of the empty set are floats. > All elements of the empty set are ints. > Ints are not floats. > Therefore all elements of the empty set are not floats. If x in e => x in floats x in e => x in ints x in ints => x not in floats Then x in e => x not in floats, a contradition, So not(x in e), the definition of empty set. > You elaborate your logic to talk around this problem, and you quit when you > get tired. No problem. Colloquial English is not the same as careful logic. 2 minutes, tired? Nah. tjr From tjreedy at udel.edu Sun Jun 14 19:36:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:36:11 -0400 Subject: Question about None In-Reply-To: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Message-ID: Paul LaFollette wrote: > Thank you all for your thoughtful and useful comments. Since this has > largely morphed into a discussion of my 3rd question, perhaps it would > interest you to hear my reason for asking it. > > John is just about spot on. Part of my research involves the > enumeration and generation of various combinatorial objects using what > are called "loopless" or "constant time" algorithms. (This means that > the time required to move from one object to the next is bounded by a > constant that is independent of the size of the object. It is related > to following idea: If I generate all of the possible patterns > expressible with N bits by simply counting in binary, as many as N > bits may change from one pattern to the next. On the other hand if I > use Gray code only one bit changes from each pattern to the next. But the number of bits you must examine to determine which to change is bounded by N and increases with N. From lists at cheimes.de Sun Jun 14 19:47:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 01:47:03 +0200 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: tom schrieb: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. Some time ago we had a discussion about turning os.listdir() into a generator. No conclusion was agreed on. We also thought about exposing the functions opendir(), readdir(), closedir() and friends but as far as I know and as far as I've checked the C code in Modules/posixmodule.c none of the functions as been added. For now you are on your own to implement wrappers for the system calls. For the distant future you may see the appropriate functions in the os module. A mail to the python ideas list may increase your chances. ;) Christian From tjreedy at udel.edu Sun Jun 14 19:48:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:48:15 -0400 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. tjr From sjmachin at lexicon.net Sun Jun 14 19:48:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 14 Jun 2009 23:48:21 +0000 (UTC) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not =?utf-8?b?Y2FsbGFibGUiCWlu?= ignored References: <4A356E9B.30806@pooryorick.com> Message-ID: Poor Yorick pooryorick.com> writes: > > The following code produces an error (python-2.6.2). Either of the following > eliminates the error: > > . assign something besides mod1 (the newly-created module) to d1 > > . remove the call to shelve.open [snip] > > $ python2.6 test1.py > hello from test2 > hello from test3 > Exception TypeError: "'NoneType' object is not callable" in ignored > Exception TypeError: "'NoneType' object is not callable" in ignored Take your error message, paste it into a search box in a browser, delete punctuation characters (especially "), and hit the search button. Limiting your search to this newsgroup is a good idea. From tjreedy at udel.edu Sun Jun 14 19:49:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:49:36 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <4A356E9B.30806@pooryorick.com> References: <4A356E9B.30806@pooryorick.com> Message-ID: Poor Yorick wrote: > The following code produces an error (python-2.6.2). You forgot to post the error traceback. From lists at cheimes.de Sun Jun 14 19:50:02 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 01:50:02 +0200 Subject: waling a directory with very many files In-Reply-To: <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> Message-ID: Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I've seen directories with several hundreds of thousand files. Depending on the file system and IO capacity it can take about one to several minute until 'ls' even starts to print out files names. It's no fun on directories on a CIFS storage or ext3 w/o a btree dir index. Christian From lists at cheimes.de Sun Jun 14 20:06:18 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 02:06:18 +0200 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: Terry Reedy wrote: > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. ython 3.1rc1+ (py3k:73396, Jun 12 2009, 22:45:18) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> type(os.listdir(".")) Christian From python at mrabarnett.plus.com Sun Jun 14 20:06:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Jun 2009 01:06:20 +0100 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A35907C.5010400@mrabarnett.plus.com> Christian Heimes wrote: > tom schrieb: >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. for example, in c, perl or php one can >> use opendir() and then repeatedly readdir() until getting to the end >> of the file list. it seems this could be more efficient in some >> applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > Some time ago we had a discussion about turning os.listdir() into a > generator. No conclusion was agreed on. We also thought about exposing > the functions opendir(), readdir(), closedir() and friends but as far as > I know and as far as I've checked the C code in Modules/posixmodule.c > none of the functions as been added. > Perhaps if there's a generator it should be called iterdir(). Or would it be unPythonic to have listdir() and iterdir()? Probably. > For now you are on your own to implement wrappers for the system calls. > For the distant future you may see the appropriate functions in the os > module. A mail to the python ideas list may increase your chances. ;) > From ldo at geek-central.gen.new_zealand Sun Jun 14 20:33:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 12:33:50 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro > wrote: > >> In message , Rhodri >> James wrote: >> >>> 2. That output string has severe "leaning toothpick" syndrome. Python >>> accepts both single and double quotes to help avoid creating something >>> so unreadable: use them. >> >> Backslashes are more scalable. > > That doesn't excuse sprinkling several million backslashes through literal > constants when there's a more readable alternative. Perl allows just about any printable character as a quote. I tried alternative quotes for many years, and decided making that choice was a waste of brain cells. So no, using alternative quotes does not make things more readable. From ldo at geek-central.gen.new_zealand Sun Jun 14 20:45:43 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 12:45:43 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: In message , Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. I suppose it depends how well-liked it is. Nerdy lists may work better, but they tend not to be liked. > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I worked on an application system which, at one point, routinely dealt with directories containing hundreds of thousands of files. But even that kind of directory contents only adds up to a few megabytes. From castironpi at gmail.com Sun Jun 14 21:26:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 18:26:55 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: On Jun 14, 12:37?pm, Paul Rubin wrote: > Andre Engels writes: snip > > type "thingy". A car is a single car. Nothing is zero cars, which is > > not a car, just like two cars is not a car. > > That seems to confuse values with collections of them. ?A car is not > the same as a one-element list of cars. ?Nothing is not the same as a > zero-element list of cars. Collections are a mathematical (ideal, cognitive) construct. From davea at ieee.org Sun Jun 14 21:39:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Jun 2009 21:39:19 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <4A356E9B.30806@pooryorick.com> References: <4A356E9B.30806@pooryorick.com> Message-ID: <4A35A647.2020006@ieee.org> Poor Yorick wrote: >
The > following code produces an error (python-2.6.2). Either of the following > eliminates the error: > > . assign something besides mod1 (the newly-created module) to d1 > > . remove the call to shelve.open > > Why is there an error produced in the first place? What is the > interaction > between d1, mod1, and shelve about? This code runs without error in > python-3.1 > > $ cat test1.py > import test2 > newmodule = test2.load() > > $ cat test2.py > > import imp > import shelve > > def load(): > text='import test2\n' > text += '''print('hello from test3')\n''' > code = compile(text,'', 'exec') > mod1 = imp.new_module('newmodule') > > newdict = mod1.__dict__ > #newdict = {} > > exec(code,newdict) > mod1 > mode = mod1 > d1['unique'] = mod1 > #d1['unique'] = '' > return mod1 > > print('hello from test2') > d1 = {} > cache = shelve.open('persist') > > $ python2.6 test1.py > hello from test2 > hello from test3 > Exception TypeError: "'NoneType' object is not callable" in ignored > Exception TypeError: "'NoneType' object is not callable" in ignored > You don't need all those lines to trigger these exception messages. All you need in test1.py is the import statement. And in test2.py: import shelve cache = shelve.open('persist') To cure it, just close the cache: cache.close() I don't have any idea what the exception means, but this seems like a logical thing, to close it. From python.list at tim.thechases.com Sun Jun 14 22:07:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Jun 2009 21:07:25 -0500 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A35ACDD.1020803@tim.thechases.com> >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. for example, in c, perl or php one can >> use opendir() and then repeatedly readdir() until getting to the end >> of the file list. it seems this could be more efficient in some >> applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. Since at least 2.4, os.walk has itself been a generator. However, the contents of the directory (the 3rd element of the yielded tuple) is a list produced by listdir() instead of a generator. Unless listdir() has been changed to a generator instead of a list (which other respondents seem to indicate has not been implemented), this doesn't address the OP's issue of "lots of files in a single directory". -tkc From org.python.pythonlist at pooryorick.com Sun Jun 14 22:19:28 2009 From: org.python.pythonlist at pooryorick.com (Poor Yorick) Date: Sun, 14 Jun 2009 22:19:28 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: References: <4A356E9B.30806@pooryorick.com> Message-ID: <4A35AFB0.10803@pooryorick.com> Terry Reedy wrote: > Poor Yorick wrote: >> The following code produces an error (python-2.6.2). > > You forgot to post the error traceback. > There was no traceback, but following John Machin's prodding, I read back through some older posts (including one of yours) which I hadn't guessed were relevant the first time around. It seems that the program itself was functioning properly, but when the interpreter exited, objects were being deleted in an order which did not permit orderly teardown of other objects. I hadn't thought to look, before, but despite the warnings, the exit status of the interpreter was 0. The solution to the errors was to register a teardown function in the module: import atexit def teardown(): del globals()['d1'] atexit.register(teardown) -- Yorick From ldo at geek-central.gen.new_zealand Sun Jun 14 22:26:13 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 14:26:13 +1200 Subject: uncompress base64-gzipped string References: Message-ID: In message , John Machin wrote: > What a long journey: parse xml, base64 decode, gunzip, > and you're still not home; next stop is struct.unpack ... Binary data in an XML file?? Were these the same folks who worked on OOXML, by any chance? From ldo at geek-central.gen.new_zealand Sun Jun 14 22:32:35 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 14:32:35 +1200 Subject: matplotlib installation References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: In message , David Cournapeau wrote: > Basically, there are some functions which are erroneously "declared" > in the .lib, but they don't actually exist in the MS C runtime. Isn't this a MinGW bug? From asimsaeed.2006 at gmail.com Sun Jun 14 22:49:11 2009 From: asimsaeed.2006 at gmail.com (Asim Saeed) Date: Sun, 14 Jun 2009 19:49:11 -0700 (PDT) Subject: Cisco certification Message-ID: if you wnat to know about cisco certification it books and dump http://ciscocity.blogspot.com From philr at aspexconsulting.co.nz Sun Jun 14 23:38:20 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Mon, 15 Jun 2009 15:38:20 +1200 Subject: Good books in computer science? In-Reply-To: <4A357F1F.6060407@mrabarnett.plus.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: >Rhodri James wrote: >> On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton >> wrote: >> >>> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >>> said: >>> >>>> Nathan Stoddard wrote: >>>> >>>>> The best way to become a good programmer is to program. Write a lot of >>>>> code; work on some large projects. This will improve your skill more >>>>> than >>>>> anything else. >>>> I think there are about 100 million VB code-monkeys who prove that >>>> theory >>>> wrong. >>> >>> Really? So you don't think that the best way to get good at something >>> is to practice? >> >> Self-evidently. If what you practice is bad practice, it doesn't matter >> how much you practice it you'll still be no good at good practice in >> practice. Practically speaking, that is :-) >> >True. And there's no point in practising if you don't understand what >you're doing or why you're doing it that way. There are plenty of good >tutorials for Python, for example, but if you can't follow any of them >(assuming that it's not just a language problem), or can't be bothered >to read any of them, then you probably shouldn't be a programmer. If you are given to depression then programming is possibly not for you. Keep tackling problems that are beyond your current capabilities. Think about what you are doing... this is more subtle that you might grasp at first. Know there is always a better way and seek it. Prime your thinking by reading Edsgar Dijkstra. Dijkstra's "Notes on Structured Programming" are a good read and are probably available on the 'Net by now. You will see that his concerns had practically nothing to do with "Goto Considered Harmful". That was a later observation made as a result of checking students programs. His notes were knocking around in the UK back in 1966 and earlier. His co-authored book on "Structure Programming" is good reading even now. (O-J Dahl, EW Dijkstra, and CAR Hoare). See http://www.cs.utexas.edu/users/EWD/transcriptions/transcriptions.html for his famous EWD series of notes. Gain access to one of the IEEE or ACM web sites and their resources. I used to sneak into my local university library before the 'Net to read this stuff. Beyond that I check up on the reading lists for CS students from time to time. This often throws up real gems and prevents me from being blind-sided. Beware any "programmer" who only knows one computer language and only one OS, especially if this is either windows or a version of UNIX. My 2c worth From steven at REMOVE.THIS.cybersource.com.au Sun Jun 14 23:48:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 03:48:16 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: >> Shame on you for deliberately cutting out my more serious and nuanced >> answer while leaving a silly quip. > > Can't have been very "serious and nuanced" if it could be summed up by > such a "silly quip" though, could it? But it can't be summed up by the silly quip, which is why I'm complaining that the silly quip on its own fails to include the more serious and nuanced elements of my post. -- Steven From drentha at gmail.com Sun Jun 14 23:53:39 2009 From: drentha at gmail.com (Oni) Date: Sun, 14 Jun 2009 20:53:39 -0700 (PDT) Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> <20090612113434.47a84b00@coercion> Message-ID: <3fb7c945-744c-4f6e-82f6-0d895afba239@s38g2000prg.googlegroups.com> Thanks for the answers. My goal was to try to avoid hard coding and add a little shine to the code I have inherited. But its too far gone already and time is short. So have used Mike's answer. Mike answer with minor changes: import datetime import pprint import operator import time entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2007, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ3', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] entries.sort(key = lambda x: (x['name'], -time.mktime(x ['date'].timetuple()) )) pp = pprint.PrettyPrinter(depth=2) pp.pprint(entries) From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:27:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:27:18 GMT Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 18:02:54 +0100, Arnaud Delobelle wrote: > Steven D'Aprano writes: >> So-called "vacuous truth". It's often useful to have all([]) return >> true, but it's not *always* useful -- there are reasonable cases where >> the opposite behaviour would be useful: >> >> if all(the evidence points to the Defendant's guilt) then: >> the Defendant is guilty >> execute(the Defendant) >> >> sadly means that if there is no evidence that a crime has been >> committed, the person accused of committing the imaginary crime will be >> executed. > > This is a bad example. Someone is not convicted of a crime just because > all the available evidence points towards their guilt. There may be > very little evidence altogether, or it might just be circumstancial, or > unconvincing. Even though it may all point towards the defendent's > guilt, it doesn't mean they will be convicted. There needs to be enough > evidence to convince the jury. So it would be something like: > > if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: > the defendant is guilty > ... Not all trials are jury trials, and not all cultures have a presumption of innocence. There are, in fact, many places where the government and police think little of falsifying evidence to convict innocent people, including people that they know are innocent of any crime (an extreme case was Stalin's show trials). But as far as I know, nobody ever argues that people are guilty based on the principle of Vacuous Truth: everybody agrees that if there is no evidence of a crime, the person should be considered innocent rather than guilty. Even Stalin manufactured evidence of crimes. (In most cases, that evidence was to torture people into confessing to crimes that did not, in fact, take place.) To put it another way, logically: all(the evidence is true) not any(the evidence is false) should be considered identical, but in practice, we treat: evidence = [] # evidence of a crime all(evidence) as false instead of true, even in places with no presumption of innocence. While: not any(map(operator.not_, evidence)) is also treated as false. In any case, I'm not arguing against vacuous truth -- it's clearly the right way to deal with empty sets *nearly always*. But it isn't entirely straight-forward, and leads to some difficulties, such as a vacuous truth X implies both Y and not Y at the same time. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:50:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:50:27 GMT Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > Steven D'Aprano wrote: >> >> So-called "vacuous truth". It's often useful to have all([]) return >> true, but it's not *always* useful -- there are reasonable cases where >> the opposite behaviour would be useful: [...] > It seems to me that the absurd conclusion implied by the theorem > invalidates the theorem rather than supporting your point. I wouldn't go so far as to say the vacuous truth theorem ("empty statements are true") is invalidated. The Wikipedia article discusses various reasons why it's more correct (or at least more useful) to treat vacuous statements as true: http://en.wikipedia.org/wiki/Vacuous_truth But it's not without difficulties -- however those difficulties are smaller than those if you take vacuous statements as false in general. [...] > Try finding another 'reasonable case'. Any time you do something like: if not x and all(x): process(x) instead of just: if all(x): process(x) I can't think of a real world example off the top of my head, but here's a contrived example demonstrating that vacuous truths imply both a fact and it's opposite: def startswith(s, chars): """Return True if s starts with any of chars.""" for c in chars: if s.startswith(c): return True return False if all([startswith(w, "aeiou") for w in words]): print "All the words start with vowels." if all([startswith(w, "bcdfghjklmnpqrstvwxyz") for w in words]): print "All of the words start with consonants." If words is empty, this code claims that all of the words start with vowels as well as starting with consonants. There are, of course, ways to work around that other than rejecting vacuous truths. One is to simply use an "elif" for the second test. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:55:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:55:03 GMT Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > On 14 Jun., 16:00, Steven D'Aprano > wrote: > >> Incorrect. Koch's snowflake, for example, has a fractal dimension of >> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial >> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the >> perimeter is infinite, it is countably infinite and computable. > > No, the Koch curve is continuous in R^2 and uncountable. I think we're talking about different things. The *number of points* in the Koch curve is uncountably infinite, but that's nothing surprising, the number of points in the unit interval [0, 1] is uncountably infinite. But the *length* of the Koch curve is not, it's given by the above limit, which is countably infinite (it's a rational number for all n). > Lawrence is > right and one can trivially cover a countable infinite set with disks of > the diameter 0, namely by itself. The sum of those diameters to an > arbitrary power is also 0 and this yields that the Hausdorff dimension > of any countable set is 0. Nevertheless, the Hausdorff dimension (or a close approximation thereof) can be calculated from the scaling properties of even *finite* objects. To say that self-similar objects like broccoli or the inner surface of the human lungs fails to nest at all scales is pedantically correct but utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good enough for me. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:56:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:56:06 GMT Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking a >> directory as a liked list. for example, in c, perl or php one can use >> opendir() and then repeatedly readdir() until getting to the end of the >> file list. it seems this could be more efficient in some applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... You haven't looked very hard :) $ pwd /home/steve/.thumbnails/normal $ ls | wc -l 33956 And I periodically delete thumbnails, to prevent the number of files growing to hundreds of thousands. -- Steven From deostroll at gmail.com Mon Jun 15 01:45:38 2009 From: deostroll at gmail.com (deostroll) Date: Sun, 14 Jun 2009 22:45:38 -0700 (PDT) Subject: parsing json using simplejson Message-ID: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> I need to be able to parse a json data object using the simplejson package. First of all I need to know all the task needed for this job. --deostroll From randall at tnr.cc Mon Jun 15 01:58:42 2009 From: randall at tnr.cc (Randall Smith) Date: Mon, 15 Jun 2009 00:58:42 -0500 Subject: moving Connection/PipeConnection between processes In-Reply-To: <20090613141147.1ed3667d@coercion> References: <20090613141147.1ed3667d@coercion> Message-ID: Now that I've done some homework, everything you said is clear. Mike Kazantsev wrote: > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > sendmsg is a missing feature of the socket module. http://bugs.python.org/issue1194378 And this implements it: http://pypi.python.org/pypi/python-eunuchs/0.0.0 From bob.martin at excite.com Mon Jun 15 02:26:05 2009 From: bob.martin at excite.com (Bob Martin) Date: Mon, 15 Jun 2009 06:26:05 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <1QlZl.42661$OO7.9021@text.news.virginmedia.com> in 117455 20090615 044816 Steven D'Aprano wrote: >On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: > >>> Shame on you for deliberately cutting out my more serious and nuanced >>> answer while leaving a silly quip. >> >> Can't have been very "serious and nuanced" if it could be summed up by >> such a "silly quip" though, could it? > >But it can't be summed up by the silly quip, which is why I'm complaining >that the silly quip on its own fails to include the more serious and >nuanced elements of my post. Lots of references to "good programmer" but no attempt to define the term. Who is the better programmer - one who writes lousy code but produces good programs or one who obeys all the rules of coding but whose programs break all the time? (Yes, I know there are two other categories!) In almost 50 years programming I have met all types but I tended to judge them by the end results, not on their style. From lie.1296 at gmail.com Mon Jun 15 03:14:46 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 15 Jun 2009 07:14:46 GMT Subject: Good books in computer science? In-Reply-To: <1QlZl.42661$OO7.9021@text.news.virginmedia.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <1QlZl.42661$OO7.9021@text.news.virginmedia.com> Message-ID: Bob Martin wrote: > in 117455 20090615 044816 Steven D'Aprano wrote: >> On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: >> >>>> Shame on you for deliberately cutting out my more serious and nuanced >>>> answer while leaving a silly quip. >>> Can't have been very "serious and nuanced" if it could be summed up by >>> such a "silly quip" though, could it? >> But it can't be summed up by the silly quip, which is why I'm complaining >> that the silly quip on its own fails to include the more serious and >> nuanced elements of my post. > > Lots of references to "good programmer" but no attempt to define the term. > > Who is the better programmer - one who writes lousy code but produces good programs > or one who obeys all the rules of coding but whose programs break all the time? > (Yes, I know there are two other categories!) > In almost 50 years programming I have met all types but I tended to judge them > by the end results, not on their style. A programmer that just follows the recipes for the so-called "rules of coding" is just, as Steven says, a bad programmers. Unless you write a program that works, you are not a programmer; once you've written one that works, we'll see whether you're a good or bad by your style. Points is taken when the so-called rules are followed mindlessly. Bonus Points if you can justify your breaking rules. No point for program that doesn't work. From python at rcn.com Mon Jun 15 03:45:13 2009 From: python at rcn.com (Raymond Hettinger) Date: Mon, 15 Jun 2009 00:45:13 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: [David Wilson] > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. FWIW, this is equivalent to the Welfare Crook problem in David Gries book, The Science of Programming, http://tinyurl.com/mzoqk4 . > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. Translated into Python, David Gries' solution looks like this: def intersect(f, g, h): i = j = k = 0 try: while True: if f[i] < g[j]: i += 1 elif g[j] < h[k]: j += 1 elif h[k] < f[i]: k += 1 else: print(f[i]) i += 1 except IndexError: pass streams = [sorted(sample(range(50), 30)) for i in range(3)] for s in streams: print(s) intersect(*streams) Raymond From cassian at free.fr Mon Jun 15 03:57:49 2009 From: cassian at free.fr (Cassian Braconnier) Date: Mon, 15 Jun 2009 09:57:49 +0200 Subject: Impossible to reinstall python-opensync which made unusable my package installation tools Message-ID: <4A35FEFD.9050603@free.fr> Hi, Recently, I decided to install a package for python-opensync on my Ubuntu 9.04 (Jaunty). This package was here : http://www.progweb.com/modules/blackberry/opensync/ (I was said later that this package was for Debian SID) This was a very bad idea : it completely broke Synaptic, and made it impossible to install any (other, non python) package with apt-get or dpkg commands. Any attempt to remove or reinstall python-opensync with dpkg or apt-get commands, used with various 'force' options, gave no result, for instance : ============= root at tux-laptop# dpkg -P --force-remove-reinstreq python-opensync dpkg - avertissement, probl?me contourn? ? cause de --force : Le paquet est dans un ?tat incoh?rent - vous devriez le r?installer avant d'essayer de le supprimer. (Lecture de la base de donn?es... 236922 fichiers et r?pertoires d?j? install?s.) Suppression de python-opensync ... Usage: update-python-modules [-v] [-c] package_directory [...] update-python-modules [-v] [-c] package.dirs [...] update-python-modules [-v] [-a|-f|-p] update-python-modules: error: /usr/share/python-support/python-opensync.public is not a directory dpkg : erreur de traitement de python-opensync (--purge) : le sous-processus pre-removal script a retourn? une erreur de sortie d'?tat 2 Usage: update-python-modules [-v] [-c] package_directory [...] update-python-modules [-v] [-c] package.dirs [...] update-python-modules [-v] [-a|-f|-p] update-python-modules: error: /usr/share/python-support/python-opensync.public is not a directory dpkg : erreur lors du nettoyage : le sous-processus post-installation script a retourn? une erreur de sortie d'?tat 2 Des erreurs ont ?t? rencontr?es pendant l'ex?cution : python-opensync ==================== The pre and post removal scripts are respectively : /var/lib/dpkg/info/python-opensync.prerm : ================= #!/bin/sh set -e # Automatically added by dh_pysupport if which update-python-modules >/dev/null 2>&1; then update-python-modules -c python-opensync.public fi # End automatically added section ========================= /var/lib/dpkg/info/python-opensync.postinst : ================== #!/bin/sh set -e # Automatically added by dh_pysupport if which update-python-modules >/dev/null 2>&1; then update-python-modules python-opensync.public fi # End automatically added section ========================== For the time being I cannot install anything using dpkg or apt-get (nor synaptic) : I get an error message saying that "python-opensync should be reinstalled but that its archive is unavailable", and as I said, any attempt to reinstall python-opensync fails. So far I could not get any useful advice on the french ubuntu users forum, it is the reason why, though I am in no way a python-guy, I turned to this list. Thank you for any advice. Idoin From lie.1296 at gmail.com Mon Jun 15 04:00:11 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 15 Jun 2009 08:00:11 GMT Subject: Alter list items within loop In-Reply-To: References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: Tim Harig wrote: > On 2009-06-11, Duncan Booth wrote: >> Tim Harig wrote: >>>> number 3 never gets printed. Does Python make a copy of a list before >>>> it iterates through it?: >>> No, complex types are passed by reference unless explicity copied. >> *All* types are passed by reference unless explicitly copied. Python does >> make special cases for simple and complex types. > > That is technically true; but, you will not have this issue with simple > singlular data types. Technically the difference as to whether you will > have this problem depends on whether or not an object is mutable. > Simple objects (numbers and strings) are all immutable. Since this issue > revolves around changing objects in place, it cannot arise with immutable > objects. I am not always conscous of whether I am working with objects > that are mutable or immutable; but, I am generally concious of the general > complexity of the object. Whenever I am working with objects that are > complex, I am reminded to watch out for mutability issues. So, while it is not > totally correct to think of it this way, I find it an easier guideline to > follow. Everything is passed as an object[1], no matter how simple or complex, mutable or immutable. This can be seen: >>> def foo(a): ... print id(a) ... >>> b = 10 >>> id(b) 8578336 >>> foo(b) 8578336 [1] internally as PyObject pointer but that's implementation detail From sjmachin at lexicon.net Mon Jun 15 04:11:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Jun 2009 01:11:39 -0700 (PDT) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored References: <4A356E9B.30806@pooryorick.com> Message-ID: <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> On Jun 15, 9:49?am, Terry Reedy wrote: > Poor Yorick wrote: > > The following code produces an error (python-2.6.2). > > You forgot to post the error traceback. The exception was IGNORED ... so no traceback. From deets at nospam.web.de Mon Jun 15 04:21:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 10:21:09 +0200 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> Message-ID: <79medbF1qu45cU1@mid.uni-berlin.de> deostroll wrote: > I need to be able to parse a json data object using the simplejson > package. First of all I need to know all the task needed for this job. - install simplejson - read documentation of simplejson - use simplejson as documented - ??? - profit! Diez From nick at craig-wood.com Mon Jun 15 04:29:34 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 03:29:34 -0500 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: tom wrote: > On Jun 14, 1:35?pm, Tim Golden wrote: > > > > If you're on Windows, you can use the win32file.FindFilesIterator > > function from the pywin32 package. (Which wraps the Win32 API > > FindFirstFile / FindNextFile pattern). > > thanks, tim. > > however, i'm not using windows. freebsd and os x. Here is a ctypes generator listdir for unix-like OSes. I tested it under linux. #!/usr/bin/python """ An equivalent os.listdir but as a generator using ctypes """ from ctypes import CDLL, c_char_p, c_int, c_long, c_ushort, c_byte, c_char, Structure, POINTER from ctypes.util import find_library class c_dir(Structure): """Opaque type for directory entries, corresponds to struct DIR""" c_dir_p = POINTER(c_dir) class c_dirent(Structure): """Directory entry""" # FIXME not sure these are the exactly correct types! _fields_ = ( ('d_ino', c_long), # inode number ('d_off', c_long), # offset to the next dirent ('d_reclen', c_ushort), # length of this record ('d_type', c_byte), # type of file; not supported by all file system types ('d_name', c_char * 4096) # filename ) c_dirent_p = POINTER(c_dirent) c_lib = CDLL(find_library("c")) opendir = c_lib.opendir opendir.argtypes = [c_char_p] opendir.restype = c_dir_p # FIXME Should probably use readdir_r here readdir = c_lib.readdir readdir.argtypes = [c_dir_p] readdir.restype = c_dirent_p closedir = c_lib.closedir closedir.argtypes = [c_dir_p] closedir.restype = c_int def listdir(path): """ A generator to return the names of files in the directory passed in """ dir_p = opendir(".") while True: p = readdir(dir_p) if not p: break name = p.contents.d_name if name not in (".", ".."): yield name closedir(dir_p) if __name__ == "__main__": for name in listdir("."): print name -- Nick Craig-Wood -- http://www.craig-wood.com/nick From eckhardt at satorlaser.com Mon Jun 15 04:38:02 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Jun 2009 10:38:02 +0200 Subject: Impossible to reinstall python-opensync which made unusable my package installation tools References: Message-ID: Cassian Braconnier wrote: > [...] completely broke Synaptic, and made it impossible to install any > (other, non python) package with apt-get or dpkg commands. This is not a Python error and it doesn't actually belong here. > So far I could not get any useful advice on the french ubuntu users > forum, it is the reason why, though I am in no way a python-guy, > I turned to this list. Fire up an IRC client, connect to freenode and join the channel #ubuntu, #debian or #debian-fr, there you should be able to find people who can help you. Otherwise, it seems that the package is in a half-installed state and that it fails to configure. What you can do is remove the content of the failing post-installation script and then retry configuring it. Obviously it might cause the package itself to break, but it shouldn't affect the whole package management system. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From dfnsonfsduifb at gmx.de Mon Jun 15 05:14:56 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Mon, 15 Jun 2009 11:14:56 +0200 Subject: Mysterious hang Message-ID: <79mhogF1rhob9U1@mid.dfncis.de> Hello group, I'm pretty despereate right now and apologize for my diffuse question in advance - but I do not know how to continue right now. I'm writing a GUI client (pygtk) which talks to a server (TCP/IP), fetches pictures (FITS format) and displays them. This works nicely. Now I have a plugin which is called from a menu. The plugin also talks to the server, then fetches a picture. However, when trying to fetch a picture this way, the Python program hangs - every time, always at the same position - and I have not the least clue why. File "./guiclient.py", line 368, in on_Focus self.__plugin_instances[0].run() File "plugins/Focus.py", line 57, in run img = result.fetch() File "/home/joe/client/imgproto/Connection.py", line 54, in fetch return self.__device.conn().getbindata() File "/home/joe/client/imgproto/TransportLayerConnection.py", line 100, in getbindata copied = self.__s.recv_into(result[pos:], remaining) The debug output of my program indicates that *always* the last 1023 bytes are waited for. Wireshark however tells me they are sent! Done, fetching '2009_06_15_11_12_12_picture' Fetching... Fetching remaining 659520 bytes 15360 bytes fetched Fetching remaining 644160 bytes 16384 bytes fetched Fetching remaining 627776 bytes 16384 bytes fetched Fetching remaining 611392 bytes 16384 bytes fetched Fetching remaining 595008 bytes 16384 bytes fetched Fetching remaining 578624 bytes 16384 bytes fetched Fetching remaining 562240 bytes 147456 bytes fetched Fetching remaining 414784 bytes 49152 bytes fetched Fetching remaining 365632 bytes 49152 bytes fetched Fetching remaining 316480 bytes 49152 bytes fetched Fetching remaining 267328 bytes 98304 bytes fetched Fetching remaining 169024 bytes 49152 bytes fetched Fetching remaining 119872 bytes 49152 bytes fetched Fetching remaining 70720 bytes 49152 bytes fetched Fetching remaining 21568 bytes 20545 bytes fetched Fetching remaining 1023 bytes I then tried to multithread that, which did not work either (showed even more confusing behaviour). What in the world could possibly cause such an error? How can I trace it? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From madigreece at yahoo.gr Mon Jun 15 06:37:27 2009 From: madigreece at yahoo.gr (jeni) Date: Mon, 15 Jun 2009 03:37:27 -0700 (PDT) Subject: : an integer is required Message-ID: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> I have developed in python a game for OPLC. When I run the game in Python 2.5.2 at Windows there is no problem. But after I play a game at OLPC I get the following message: Traceback (most recent call last) /home/olpc/Activities/Kremala.activity/Kremala.py in add_letter (self=, widget=, grama='i') --> self.find_w() self.find_w=> /home/Activities/Kremala.activity/Kremala.py in find_w (self=) self.show_gr() --> self.sosti_leksi() self.sosti_leksi==> /home/Activities/Kremala.activity/Kremala.py in sosti_leksi (self=) s=self.categ+":"+str(1)+" nikh me "+str(6-self.m)+"prospatheies \n" --> self.insert_text_file(s) self.insert_text_file===> /home/Activities/Kremala.activity/Kremala.py in insert_text_file (self=, strng='geografia:1 nikh me 2 prospatheies\n') --> t=open("elements_file.txt", "a") global open= t.write(strng) t.close() : an integer is required OLPC's software is important? From rhodri at wildebst.demon.co.uk Mon Jun 15 07:02:32 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 15 Jun 2009 12:02:32 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro >> wrote: >> >>> In message , >>> Rhodri >>> James wrote: >>> >>>> 2. That output string has severe "leaning toothpick" syndrome. >>>> Python >>>> accepts both single and double quotes to help avoid creating something >>>> so unreadable: use them. >>> >>> Backslashes are more scalable. >> >> That doesn't excuse sprinkling several million backslashes through >> literal >> constants when there's a more readable alternative. > > Perl allows just about any printable character as a quote. I tried > alternative quotes for many years, and decided making that choice was a > waste of brain cells. > > So no, using alternative quotes does not make things more readable. I find it odd that you consider qquoting less scalable than backslashes. I also find it odd that you dislike two visuals stutters (at the start and end of string) so much that you'll put up with a dozen visual stutters in the string to avoid them. Particular since my years of Perl-bashing lead me to the opposite conclusion. -- Rhodri James *-* Wildebeest Herder to the Masses From pdpinheiro at gmail.com Mon Jun 15 07:14:14 2009 From: pdpinheiro at gmail.com (pdpi) Date: Mon, 15 Jun 2009 04:14:14 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: <7e7a22a6-1aaa-4605-b254-60e08c39e141@j18g2000yql.googlegroups.com> On Jun 15, 5:55?am, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > > On 14 Jun., 16:00, Steven D'Aprano > > wrote: > > >> Incorrect. Koch's snowflake, for example, has a fractal dimension of > >> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial > >> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the > >> perimeter is infinite, it is countably infinite and computable. > > > No, the Koch curve is continuous in R^2 and uncountable. > > I think we're talking about different things. The *number of points* in > the Koch curve is uncountably infinite, but that's nothing surprising, > the number of points in the unit interval [0, 1] is uncountably infinite. > But the *length* of the Koch curve is not, it's given by the above limit, > which is countably infinite (it's a rational number for all n). > > > Lawrence is > > right and one can trivially cover a countable infinite set with disks of > > the diameter 0, namely by itself. The sum of those diameters to an > > arbitrary power is also 0 and this yields that the Hausdorff dimension > > of any countable set is 0. > > Nevertheless, the Hausdorff dimension (or a close approximation thereof) > can be calculated from the scaling properties of even *finite* objects. > To say that self-similar objects like broccoli or the inner surface of > the human lungs fails to nest at all scales is pedantically correct but > utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good > enough for me. > > -- > Steven You're mixing up the notion of countability. It only applies to set sizes. Unless you're saying that there an infinite series has a countable number of terms (a completely trivial statement), to say that the length is "countably finite" simply does not parse correctly (let alone being semantically correct or not). This said, I agree with you: I reckon that the Koch curve, while composed of uncountable cardinality, is completely described by the vertices, so a countable set of points. It follows that you must be able to correctly calculate the Hausdorff dimension of the curve from those control points alone, so you should also be able to estimate it from a finite sample (you can arguably infer self-similarity from a limited number of self- similar generations). From eckhardt at satorlaser.com Mon Jun 15 07:25:14 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Jun 2009 13:25:14 +0200 Subject: : an integer is required References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: jeni wrote: [ ..large backtrace.. ] For your own sake and that of your readers, try next time to reduce the code that causes the problems to a minimal example. This prevents people from guessing or simply ignoring your problems. > /home/Activities/Kremala.activity/Kremala.py in insert_text_file > (self=>, strng='geografia:1 nikh me 2 prospatheies\n') > --> t=open("elements_file.txt", "a") > global open= open() doesn't take a string as second parameter, see 'help(open)'. Instead, it takes one of the integers which are defined as symbols in the os module, see 'dir(os)'. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From newsgroup at silveraxe.de Mon Jun 15 07:45:03 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Mon, 15 Jun 2009 13:45:03 +0200 Subject: Error in Pango while using cairo/librsvg Message-ID: <4a363441$0$30238$9b4e6d93@newsspool1.arcor-online.net> Hi, I try using Python (on Windows) with Cairo and librsvg to convert a svg file to a png image. I got some help from the German python newsgroup to get this running but now I run into some problems with pango I don't know how to solve. Running the python script in the console it tells me: (python.exe:4908): Pango-CRITICAL **: pango_win32_font_map_get_font_cache: assertion `font_map != NULL' failed ** Pango:ERROR:pangowin32.c:838:pango_win32_font_finalize: assertion failed: (win32font->fontmap != NULL) This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. The script I run is: > #!/usr/bin/python > > from ctypes import * > import cairo > from rsvg_wrapper import rsvgClass > from sys import argv > from os.path import exists > import getopt > > if __name__ == "__main__": > opts, args = getopt.getopt (argv[1:], 'o:h', > ['width=', 'height=', 'output=', 'help']) > file = args[0] > > rsvg = rsvgClass() > > svg = rsvg.Handle (file = file) > svgDimensionData=svg.get_dimension_data() > > if file[-4:] == ".svg": > file = file[:-4] > output = "%s.png" % file > base = "%s%d.png" > i = 1 > while exists (output): > output = base % (file, i) > i += 1 > > width = svgDimensionData[0] > height = svgDimensionData[1] > > surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height) > cr = cairo.Context (surface) > > wscale = float (width) / svgDimensionData[0] > hscale = float (height) / svgDimensionData[1] > > cr.scale (wscale, hscale) > > svg.render_cairo (cr) > > surface.write_to_png (output) and the rsvg_wrapper.py is: > #some code to give rsvg.render_cairo(ctx) ability > #on windows. > import os > try: > import rsvg > WINDOWS=False > except ImportError: > print"Warning, could not import 'rsvg'" > if os.name == 'nt': > print "Detected windows, creating rsvg." > #some workarounds for windows > > from ctypes import * > > l=CDLL('librsvg-2-2.dll') > g=CDLL('libgobject-2.0-0.dll') > g.g_type_init() > > class rsvgHandle(): > class RsvgDimensionData(Structure): > _fields_ = [("width", c_int), > ("height", c_int), > ("em",c_double), > ("ex",c_double)] > > class PycairoContext(Structure): > _fields_ = [("PyObject_HEAD", c_byte * object.__basicsize__), > ("ctx", c_void_p), > ("base", c_void_p)] > > def __init__(self, path): > self.path = path > error = '' > self.handle = l.rsvg_handle_new_from_file(self.path,error) > > > def get_dimension_data(self): > svgDim = self.RsvgDimensionData() > l.rsvg_handle_get_dimensions(self.handle,byref(svgDim)) > return (svgDim.width,svgDim.height) > > def render_cairo(self, ctx): > ctx.save() > z = self.PycairoContext.from_address(id(ctx)) > l.rsvg_handle_render_cairo(self.handle, z.ctx) > ctx.restore() > > > > class rsvgClass(): > def Handle(self,file): > return rsvgHandle(file) > I have the GIMP 2.6 bin folder in my path so all DLLs are used from that folder. I have no idea why the error is raised. I also tried to "import pango" in the script but then it tells me: > Traceback (most recent call last): > File "svg2png2.py", line 41, in > svg.render_cairo (cr) > File "...\rsvg_wrapper.py", line 45, in render_cairo > l.rsvg_handle_render_cairo(self.handle, z.ctx) > WindowsError: exception: access violation reading 0x00000008 Can anybody help my with the svg2png conversion here? Thanks, Hilmar From hniksic at xemacs.org Mon Jun 15 07:47:08 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Jun 2009 13:47:08 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <87k53d4t37.fsf@busola.homelinux.net> Terry Reedy writes: > You did not specify version. In Python3, os.walk has become a > generater function. So, to answer your question, use 3.1. os.walk has been a generator function all along, but that doesn't help OP because it still uses os.listdir internally. This means that it both creates huge lists for huge directories, and holds on to those lists until the iteration over the directory (and all subdirectories) is finished. In fact, os.walk is not suited for this kind of memory optimization because yielding a *list* of files (and a separate list of subdirectories) is specified in its interface. This hasn't changed in Python 3.1: dirs, nondirs = [], [] for name in names: if isdir(join(top, name)): dirs.append(name) else: nondirs.append(name) if topdown: yield top, dirs, nondirs From hniksic at xemacs.org Mon Jun 15 08:00:02 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Jun 2009 14:00:02 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: <87fxe14shp.fsf@busola.homelinux.net> Nick Craig-Wood writes: > Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or for hacks one needs right now, but can anyone seriously propose using this kind of code in a Python program? For example, this seems much more "Linux-only", or possibly even "32-bit-Linux-only", than "unix-like": > class c_dirent(Structure): > """Directory entry""" > # FIXME not sure these are the exactly correct types! > _fields_ = ( > ('d_ino', c_long), # inode number > ('d_off', c_long), # offset to the next dirent > ('d_reclen', c_ushort), # length of this record > ('d_type', c_byte), # type of file; not supported by all file system types > ('d_name', c_char * 4096) # filename > ) From deets at nospam.web.de Mon Jun 15 08:15:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 14:15:25 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <79ms4jF1r4ja4U1@mid.uni-berlin.de> tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. if we assume the number of files to be a million (which certainly qualifies as one of the larger directory sizes one encounters...), and the average filename length with 20, you'd end up with 20 megs of data. Is that really a problem on nowadays several gigabyte machines? And we are talking a rather freakish case here. Diez From Olivier.Darge at gmail.com Mon Jun 15 08:37:14 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 15 Jun 2009 05:37:14 -0700 (PDT) Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> Message-ID: <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> On 13 juin, 07:25, Mike Kazantsev wrote: > There was quite interesting explaination of what happens when you send > ^C with threads, posted on concurrency-sig list recently: > > ?http://blip.tv/file/2232410 > ?http://www.dabeaz.com/python/GIL.pdf > > Can be quite shocking, but my experience w/ threads only confirms that. Hi there, please read this package page (in 2.6), this is very interesting. http://docs.python.org/library/multiprocessing.html I tested it : it works. Multi-core cpu's are happy :-) me too, Olivier From vs at it.uu.se Mon Jun 15 08:43:46 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 15 Jun 2009 14:43:46 +0200 Subject: On the property function Message-ID: <4A364202.2050700@it.uu.se> Does anyone have a good example (or examples) of when "property(...)" can be useful? Thank you, --V. Stokes From deets at nospam.web.de Mon Jun 15 08:45:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 14:45:37 +0200 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <79mtt7F1r4807U1@mid.uni-berlin.de> Aaron Brady wrote: > Hi, please forgive the multi-posting on this general topic. > > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. Python has no such restriction. > > I tried out an implementation of composite collections, specifically > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > It's significantly slower, but we might argue that attempting to do it > by hand classifies as a premature optimization; it is easy to optimize > debugged code. Sounds like you are re-inventing the ZODB. Diez From willgun at live.cn Mon Jun 15 08:58:55 2009 From: willgun at live.cn (willgun) Date: Mon, 15 Jun 2009 20:58:55 +0800 Subject: How to get the total size of a local hard disk? Message-ID: Hi,everyone! How to get the total size of a local hard disk? I mean total size,not free space. Thanks in advance! From bearophileHUGS at lycos.com Mon Jun 15 09:23:47 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Mon, 15 Jun 2009 06:23:47 -0700 (PDT) Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <8f84c845-396e-4ed9-a7ad-9f80070d9c1f@z9g2000yqi.googlegroups.com> Lawrence D'Oliveiro: >So no, using alternative quotes does not make things more readable.< You think that this: ' ' Isn't a bit more readable and simpler to write than: " " I think lot of doesn't agree with you. In such situation it can also be positive to split such string in two or more parts, for example (untested): style = ("fill:blue; stroke:pink; stroke-width:5; " "fill-opacity:0.1; stroke-opacity:0.9") print >> fo, ' ' % (abs_x, abs_y, w, h, style) Bye, bearophile From gh at ghaering.de Mon Jun 15 09:44:07 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 15 Jun 2009 15:44:07 +0200 Subject: Observer implementations In-Reply-To: References: Message-ID: Tobias Weber wrote: > Hi, > how to use the Observer pattern in Python? Implement it in your classes? > I found PubSub and PyDispatcher, both of which are abandoned. [...] I haven't searched for these, but googling for "python observer pattern" yields http://code.activestate.com/recipes/131499/ and this seems like a good inspiritation for owns own implementation. -- Gerhard From travisaltman at gmail.com Mon Jun 15 09:46:01 2009 From: travisaltman at gmail.com (Travis Altman) Date: Mon, 15 Jun 2009 09:46:01 -0400 Subject: unsuccessful post request hangs, what gives? Message-ID: i'm trying to use a post request to authenticate to a web application. let's say username = alice is valid but username = bob does not exits. making the request with alice works like a charm but when i try username = bob it hangs? any suggestions? -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.org.uk Mon Jun 15 09:48:17 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 15 Jun 2009 06:48:17 -0700 (PDT) Subject: How to get the total size of a local hard disk? References: Message-ID: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> On 15 Jun, 14:58, willgun wrote: > > How to get the total size of a local hard disk? > I mean total size,not free space. Which platform are you using? On a Linux-based system you might look at the contents of /proc/partitions and then, presumably with Python, parse the contents to yield a number of blocks for the hard disk in question. This quantity would then be converted into a more familiar measure. One might expect something like PSI to support this kind of activity... http://bitbucket.org/chrismiles/psi/ ...but I think it only really provides process-related information. Paul From willgun at live.cn Mon Jun 15 09:53:17 2009 From: willgun at live.cn (willgun) Date: Mon, 15 Jun 2009 21:53:17 +0800 Subject: How to get the total size of a local hard disk? In-Reply-To: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: Unfortunately,I'm on win32. Actually,I prefer a cross-platform method. Thanks. From mail at timgolden.me.uk Mon Jun 15 09:53:57 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Jun 2009 14:53:57 +0100 Subject: How to get the total size of a local hard disk? In-Reply-To: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <4A365275.3010706@timgolden.me.uk> Paul Boddie wrote: > On 15 Jun, 14:58, willgun wrote: >> How to get the total size of a local hard disk? >> I mean total size,not free space. > > Which platform are you using? On a Linux-based system you might look > at the contents of /proc/partitions and then, presumably with Python, > parse the contents to yield a number of blocks for the hard disk in > question. This quantity would then be converted into a more familiar > measure. > > One might expect something like PSI to support this kind of > activity... > > http://bitbucket.org/chrismiles/psi/ > > ...but I think it only really provides process-related information. On Windows, WMI is nearly always the answer to these kind of things (altho' since WMI is nearly always a shell around other APIs there's usually some other way). http://timgolden.me.uk/python/wmi_cookbook.html#percentage_free TJG From mail at timgolden.me.uk Mon Jun 15 10:04:08 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Jun 2009 15:04:08 +0100 Subject: How to get the total size of a local hard disk? In-Reply-To: References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <4A3654D8.2080804@timgolden.me.uk> willgun wrote: > Unfortunately,I'm on win32. > Actually,I prefer a cross-platform method. > Thanks. These kind of things tend to be fairly platform specific. Obviously, nothing's stopping anyone writing a module which does some platform-sniffing and conditional imports and provides a consistent interface. Far as I know, though, there's no such thing for Python at the mo. Think of it as a market opportunity! TJG From nick at craig-wood.com Mon Jun 15 10:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 09:29:33 -0500 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> <87fxe14shp.fsf@busola.homelinux.net> Message-ID: Hrvoje Niksic wrote: > Nick Craig-Wood writes: > > > Here is a ctypes generator listdir for unix-like OSes. > > ctypes code scares me with its duplication of the contents of system > headers. I understand its use as a proof of concept, or for hacks one > needs right now, but can anyone seriously propose using this kind of > code in a Python program? For example, this seems much more > "Linux-only", or possibly even "32-bit-Linux-only", than > "unix-like": It was a proof of concept certainly.. It can be done properly with gccxml though which converts structures into ctypes definitions. That said the dirent struct is specified by POSIX so if you get the correct types for all the individual members then it should be correct everywhere. Maybe ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From exarkun at divmod.com Mon Jun 15 10:38:44 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 10:38:44 -0400 Subject: waling a directory with very many files In-Reply-To: Message-ID: <20090615143844.22176.641726464.divmod.quotient.5585@henry.divmod.com> On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: >Hrvoje Niksic wrote: >> Nick Craig-Wood writes: >> >> > Here is a ctypes generator listdir for unix-like OSes. >> >> ctypes code scares me with its duplication of the contents of system >> headers. I understand its use as a proof of concept, or for hacks one >> needs right now, but can anyone seriously propose using this kind of >> code in a Python program? For example, this seems much more >> "Linux-only", or possibly even "32-bit-Linux-only", than >> "unix-like": > >It was a proof of concept certainly.. > >It can be done properly with gccxml though which converts structures >into ctypes definitions. > >That said the dirent struct is specified by POSIX so if you get the >correct types for all the individual members then it should be correct >everywhere. Maybe ;-) > The problem is that POSIX specifies the fields with types like off_t and ino_t. Since ctypes doesn't know anything about these types, application code has to specify their size and other attributes. As these vary from platform to platform, you can't get it correct without asking a real C compiler. In other words, POSIX talks about APIs and ctypes deals with ABIs. http://pypi.python.org/pypi/ctypes_configure/0.1 helps with the problem, and is a bit more accessible than gccxml. It is basically correct to say that using ctypes without using something like gccxml or ctypes_configure will give you non-portable code. Jean-Paul From andrew.henshaw at gtri.gatech.edu Mon Jun 15 10:40:24 2009 From: andrew.henshaw at gtri.gatech.edu (Andrew Henshaw) Date: Mon, 15 Jun 2009 10:40:24 -0400 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: "Raymond Hettinger" wrote in message news:fb1feeeb-c430-4ca7-9e76-fea02ea3ef6f at v23g2000pro.googlegroups.com... > [David Wilson] >> The problem is simple: given one or more ordered sequences, return >> only the objects that appear in each sequence, without reading the >> whole set into memory. This is basically an SQL many-many join. > > FWIW, this is equivalent to the Welfare Crook problem in David Gries > book, The Science of Programming, http://tinyurl.com/mzoqk4 . > > >> I thought it could be accomplished through recursively embedded >> generators, but that approach failed in the end. > > Translated into Python, David Gries' solution looks like this: > > def intersect(f, g, h): > i = j = k = 0 > try: > while True: > if f[i] < g[j]: > i += 1 > elif g[j] < h[k]: > j += 1 > elif h[k] < f[i]: > k += 1 > else: > print(f[i]) > i += 1 > except IndexError: > pass > > streams = [sorted(sample(range(50), 30)) for i in range(3)] > for s in streams: > print(s) > intersect(*streams) > > > Raymond Here's my translation of your code to support variable number of streams: def intersect(*s): num_streams = len(s) indices = [0]*num_streams try: while True: for i in range(num_streams): j = (i + 1) % num_streams if s[i][indices[i]] < s[j][indices[j]]: indices[i] += 1 break else: print(s[0][indices[0]]) indices[0] += 1 except IndexError: pass From ken at seehart.com Mon Jun 15 10:54:27 2009 From: ken at seehart.com (Ken Seehart) Date: Mon, 15 Jun 2009 07:54:27 -0700 Subject: unsuccessful post request hangs, what gives? In-Reply-To: References: Message-ID: <4A3660A3.4090001@seehart.com> Travis Altman wrote: > i'm trying to use a post request to authenticate to a web > application. let's say username = alice is valid but username = bob > does not exits. making the request with alice works like a charm but > when i try username = bob it hangs? any suggestions? Can you show us the relevant code? - Ken From jcd at sdf.lonestar.org Mon Jun 15 11:05:59 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 15 Jun 2009 11:05:59 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> References: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> Message-ID: <1245078359.10076.13.camel@aalcdl07> On Sun, 2009-06-14 at 23:01 +1000, Steven D'Aprano wrote: > Write a helper function: > > def getitems(L, *indexes): > if len(indexes) == 1: > indexes = indexes[0] > return [L[i] for i in indexes] > Whoops! Your example is broken: >>> cars = ['Ford', 'Toyota', 'Edsel'] >>> getitems(cars, 1) Traceback (most recent call last): File "", line 1, in File "", line 4, in getitems TypeError: 'int' object is not iterable >>> I think you meant to apply that [0] to the created list instead. Something like: def getitems(L, *indexes): new_list = [L[i] for i in indexes] if len(indexes) == 1: new_list = new_list[0] return new_list But I'm not sure that would be the best idea anyway. Just let getitems always return a list. That way the caller doesn't have to test the length to figure out what to do with it. If you know you want a single item, you can use regular old .__getitem__ (or .get) methods, or direct indexing. Then getitems can just be: def getitems(L, *indexes): return [L[i] for i in indexes] > > But I think this is an obvious enough extension to the __getitem__ protocol > that I for one would vote +1 on it being added to Python sequence objects > (lists, tuples, strings). > I'd be +0. It won't change my life, but it seems like a decent idea. > > -- > Steven > Cheers, Cliff From roop at forwardbias.in Mon Jun 15 11:08:20 2009 From: roop at forwardbias.in (roop) Date: Mon, 15 Jun 2009 08:08:20 -0700 (PDT) Subject: ImageEnhance.Contrast - is this fishy or what? Message-ID: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> I was browsing ImageEnhace.py, and found something that I thought was odd in class Contrast: class Contrast(_Enhance): "Adjust image contrast" def __init__(self, image): self.image = image mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/ 256.0 self.degenerate = Image.new("L", image.size, mean).convert (image.mode) Isn't reduce(lambda a,b: a+b, image.convert("L").histogram()) the same as (image.size[0] * image.size[1]) - just count the number of pixels in the image? (Afaik, the histogram is a list of 256 elements where the ith element gives the number of pixels with i as the pixel value (0 <= i < 256)). Is this actually fishy or have I got it all muddled up? Thanks, roop From Juergen.Hermann at 1und1.de Mon Jun 15 11:33:58 2009 From: Juergen.Hermann at 1und1.de (jh) Date: Mon, 15 Jun 2009 15:33:58 +0000 (UTC) Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <662715f21fdf486785783086cec9cda3@preisshare.net> <4A24685D.5000500@gmail.com> Message-ID: Stef Mientki gmail.com> writes: > I don't seem to have pkg_utils, > only pkgutil, which doesn't have an apropiate function. > > But I found another way, don't know if that's reliable: > import inspect > print inspect.currentframe().f_code.co_filenameE Eeek. > head -999 foo/* ==> foo/__init__.py <== import pkg_resources print pkg_resources.resource_string(__name__, "bar") ==> foo/bar <== bar > python -c "import foo" bar Make a "def load_resource" from that print line and you're done. From aahz at pythoncraft.com Mon Jun 15 11:37:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Jun 2009 08:37:19 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: In article <79mtt7F1r4807U1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: >Aaron Brady wrote: >> >> Some time ago, I recommended a pursuit of keeping 'persistent >> composite' types on disk, to be read and updated at other times by >> other processes. Databases provide this functionality, with the >> exception that field types in any given table are required to be >> uniform. Python has no such restriction. >> >> I tried out an implementation of composite collections, specifically >> lists, sets, and dicts, using 'sqlite3' as a persistence back-end. >> It's significantly slower, but we might argue that attempting to do it >> by hand classifies as a premature optimization; it is easy to optimize >> debugged code. > >Sounds like you are re-inventing the ZODB. ...or SQLAlchemy or pickles in a SQL BLOB or... -- 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 vadim.pestovnikov at gmail.com Mon Jun 15 11:37:32 2009 From: vadim.pestovnikov at gmail.com (VP) Date: Mon, 15 Jun 2009 08:37:32 -0700 (PDT) Subject: Please advise me for a right solution Message-ID: <15b1e25c-2bb4-425e-974f-be3d686b5931@p21g2000prn.googlegroups.com> Hi all, Please advise me for a right solution based on your experience. I need to create a web based inventory tool with specific requirements such as: * More then one group is going to use it. * Authentication and authorization system based on user and group privileges. For example based on a group privileges group can add/edit/delete their own stuff and having a read only access to other groups stuff. etc. What solution is better for that? * CGI implementation from the scratch. It seems to much work and I am not sure that this is right way. * WSGI based frameworks such as Werkzeug, Pylons, repoze.bg for HTTP requests and responds plus different components like AuthKit, repoze.who and repoze.what, SQLAlchemy or raw SQL I was trying to get those thing done by Django, but realized that every time I have to extend Django admin interface or to extend user profile etc.. I am not telling that Django is not good for this, just personal fillings. May be I am wrong. Well, what you recommend me? From usernet at ilthio.net Mon Jun 15 11:40:53 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Jun 2009 15:40:53 GMT Subject: cross platform method Re: How to get the total size of a local hard disk? References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> On 2009-06-15, Tim Golden wrote: > These kind of things tend to be fairly platform specific. There is however a way to do it in a cross platform manner which will return an appoximation of the available space. 1. delete all of the files (and folders) on the partition that you want to test. 2. create a file as large as the drive will permit. 3. repeat two with as many files as the drive will allow to be written. This needs to be done on filesystems with file size limits (ie, FAT file systems will only allow files as large as 4G). 4. Once all the files have been written, calculate the total size of all of the files to get your answer. This method is a little descructive and slow; but, it should work on all platforms. This is a joke. Do not take it seriously. I do not actually suggest anybody use this method to measure the size of their drive. I do not take any responsibility for any damages incurred by using this method. I will laugh at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands. From aahz at pythoncraft.com Mon Jun 15 11:47:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Jun 2009 08:47:45 -0700 Subject: weakrefs, threads,, and object ids References: <84397edd-4830-4c90-9fb6-f72c74028f6e@i28g2000prd.googlegroups.com> Message-ID: In article <84397edd-4830-4c90-9fb6-f72c74028f6e at i28g2000prd.googlegroups.com>, Jeremy wrote: > >While guaranteed unique for simultaneously existing objects, how often >will an object assume an ID previously held by former object? Given >that the ID is a memory address in Python's heap, I assume the answer >is either not often, or very often. Very often: Python 2.4 (#1, Jan 17 2005, 14:59:14) [GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2 Type "help", "copyright", "credits" or "license" for more information. >>> x = id(object()) >>> y = id(object()) >>> x == y True Sorry, can't help you with your other questions; I'm not familiar with weakrefs. -- 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 rridge at csclub.uwaterloo.ca Mon Jun 15 11:48:14 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Mon, 15 Jun 2009 11:48:14 -0400 Subject: matplotlib installation References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: David Cournapeau wrote: > Basically, there are some functions which are erroneously "declared" > in the .lib, but they don't actually exist in the MS C runtime. Lawrence D'Oliveiro wrote: > Isn't this a MinGW bug? No, MinGW runtime library isn't supposed to be fully compatible with the Microsoft runtime library. While MinGW happens to use part of an older Microsoft runtime library (MSVCRT.DLL) the goal of the MinGW has never been to make a compiler that was 100% compatible with any version of the Microsoft C compiler. There also isn't anything wrong with the Microsoft runtime. A library that mixes both objects and import records is perfectly legitimate. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From dmitrey.kroshko at scipy.org Mon Jun 15 11:49:24 2009 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Mon, 15 Jun 2009 08:49:24 -0700 (PDT) Subject: ANN: openopt 0.24 - free numerical optimization framework Message-ID: Hi all, OpenOpt 0.24, a free Python-written numerical optimization framework with some own solvers and connections to tens of 3rd party ones, has been released. BSD license allows to use it in both free opensource and commercial closed-code software. Currently we have ~80 unique visitors daily, 15% of the ones visit installation webpage, and some more install it via PYPI, Debian and Alt Linux repository, mac.softpedia.com, darwinports.com, pythonxy.com, mloss.org. Our homepage: http://openopt.org Introduction to the framework: http://openopt.org/Foreword All release details are here: http://openopt.org/Changelog or http://forum.openopt.org/viewtopic.php?id=110 Regards, OpenOpt developers. From mk.fraggod at gmail.com Mon Jun 15 11:53:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Mon, 15 Jun 2009 21:53:35 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> Message-ID: <20090615215335.4cb26673@coercion> On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) OdarR wrote: > On 13 juin, 07:25, Mike Kazantsev wrote: > > There was quite interesting explaination of what happens when you send > > ^C with threads, posted on concurrency-sig list recently: > > > > ?http://blip.tv/file/2232410 > > ?http://www.dabeaz.com/python/GIL.pdf > > > > Can be quite shocking, but my experience w/ threads only confirms that. > > Hi there, > please read this package page (in 2.6), this is very interesting. > http://docs.python.org/library/multiprocessing.html > > I tested it : it works. Multi-core cpu's are happy :-) I'd certainly prefer using processes because they indeed work flawlessly in that respect, but threads are way simplier and much more integrated into the language, so I can avoid re-imlementing tons of shared stuff, IPC and locking by using threads which bassically run in the same context. That might mean 90% of code for trivial but parallel task. Alas, they don't work flawlessly in all cases, but there is still million and one use for them. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From s.dornseifer at gmx.net Mon Jun 15 11:55:00 2009 From: s.dornseifer at gmx.net (S. Dornseifer) Date: Mon, 15 Jun 2009 17:55:00 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A336D62.6070302@gmx.de> References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> <4A336D62.6070302@gmx.de> Message-ID: <4A366ED4.4030004@gmx.net> Simon wrote: > Christian Heimes wrote: >> Simon schrieb: >>> Christian Heimes wrote: >>>> Simon wrote: >>>>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 >>>>> (within >>>>> openSUSE 11.1 x86_64) via 'make altinstall'. >>>>> >>>>> First, I tried to configure with the following flags: >>>>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>>>> This provoked an error during compilation via make (sorry, the list >>>>> was >>>>> so long, but I will post it, if it helps). >>>> --enable-framework is for Mac OS X only. >>>> >>>>> Second, configured again without any flags. The installation by 'make >>>>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>>>> too. So, I got my parallel installation. >>>> You have chosen the correct and canonical way to install a parallel >>>> installation of Python. >>>> >>>>> However, I cannot import modules like Tkinter or readline within >>>>> python2.4. >>>> You must install the development library of tk, readline, zlib and >>>> libbz2 prior to configure && make. >>>> >>>> Try this on your box: >>>> >>>> zypper install gcc make autoconf automake libtool zlib-devel >>>> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >>>> libopenssl-devel >>>> >>> >>> Unfortunately, I got the following errors, while compiling via make. >>> Please, see attached text file for details about everything I did from >>> installing the missing packages via zypper until make. >> >> zypper should have installed all necessary dependencies, including a >> whole bunch of X11 headers. Something seems to be wrong on your system >> or SuSE's package dependencies. >> I know why I dislike SuSE. :) Although I started my Linux career 12 >> years ago with SuSE I prefer Debian based systems since Woody came out >> in 2002. :) >> >>> X11 says: >>> Program 'X11' is present in package 'xorg-x11', which is installed on >>> your system. >> >> zypper search X11 | grep devel >> ... >> zypper install xorg-x11-devel >> >> That should (hopefully) do the trick. On a Debian based systems it's >> much easier to install all Python dependencies with "apt-get build-dep >> python2.5" >> >> To quote SuSE: "Have a lot of fun ..." >> >> Und viel Gl?ck! >> >> Christian >> > > Danke :) > > On Monday, I will be able to tell if it worked out, or if I have to try > a new strategy, e.g. to convince the admin about (K)ubuntu. Problem is solved, thanks again :) From Juergen.Hermann at 1und1.de Mon Jun 15 11:56:14 2009 From: Juergen.Hermann at 1und1.de (Juergen Hermann) Date: Mon, 15 Jun 2009 15:56:14 +0000 (UTC) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: pobox.com> writes: > but that's not what I was thinking of. I thought there was a site with a > bunch of smaller examples. http://langref.org/ is another one. From castironpi at gmail.com Mon Jun 15 11:56:20 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 08:56:20 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: <8021c688-c2d0-44be-87a9-a4dcfba8909a@s1g2000prd.googlegroups.com> On Jun 15, 5:45?am, "Diez B. Roggisch" wrote: > Aaron Brady wrote: > > Hi, please forgive the multi-posting on this general topic. > > > Some time ago, I recommended a pursuit of keeping 'persistent > > composite' types on disk, to be read and updated at other times by > > other processes. ?Databases provide this functionality, with the > > exception that field types in any given table are required to be > > uniform. ?Python has no such restriction. > > > I tried out an implementation of composite collections, specifically > > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > > It's significantly slower, but we might argue that attempting to do it > > by hand classifies as a premature optimization; it is easy to optimize > > debugged code. > > > > Sounds like you are re-inventing the ZODB. > > Diez Alright, Diez. Here is some private consulting for free. ''Section 2.6.1: The most common idiom that isn't caught by the ZODB is mutating a list or dictionary'' My approach performs this for free. The docs also don't mention interprocess communication, which is one of the two primary functions that I satisfy in my approach. The syntax is different, non-trivially so, and mine is more Pythonic. From castironpi at gmail.com Mon Jun 15 11:56:57 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 08:56:57 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> On Jun 14, 10:18?am, Jaime Fernandez del Rio wrote: > On Sun, Jun 14, 2009 at 4:27 PM, Aaron Brady wrote: > > > Before I go and flesh out the entire interfaces for the provided > > types, does anyone have a use for it? > > A real-world application of persistent data structures can be found here: > > http://stevekrenzel.com/persistent-list > > Jaime Jaime, thanks for the link. I contacted its author. From mk.fraggod at gmail.com Mon Jun 15 12:03:44 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Mon, 15 Jun 2009 22:03:44 +0600 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> Message-ID: <20090615220344.7585cb9b@coercion> On Sun, 14 Jun 2009 22:45:38 -0700 (PDT) deostroll wrote: > I need to be able to parse a json data object using the simplejson > package. First of all I need to know all the task needed for this job. Note that py2.6 has a bundled json module. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From castironpi at gmail.com Mon Jun 15 12:10:56 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 09:10:56 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: <9c0fd2d2-7a26-44bc-9e51-2a6126c2c312@v35g2000pro.googlegroups.com> On Jun 14, 9:50?pm, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > > Steven D'Aprano wrote: > > >> So-called "vacuous truth". It's often useful to have all([]) return > >> true, but it's not *always* useful -- there are reasonable cases where > >> the opposite behaviour would be useful: > [...] > > It seems to me that the absurd conclusion implied by the theorem > > invalidates the theorem rather than supporting your point. > > I wouldn't go so far as to say the vacuous truth theorem ("empty > statements are true") is invalidated. The Wikipedia article discusses > various reasons why it's more correct (or at least more useful) to treat > vacuous statements as true: > > http://en.wikipedia.org/wiki/Vacuous_truth > > But it's not without difficulties -- however those difficulties are > smaller than those if you take vacuous statements as false in general. snip Those difficulties are pretty gaping. I would start by dividing the natural language 'use cases' of 'if' statements into imperative and declarative. Declarative: If it's raining, it's cloudy. In this case, the assertion is meant to convey a general, non- concrete, observation trend across space and time. Its content is a claim of 100% correlation between two statuses of the real world. Imperative: If you're out of bread, go buy some. Here, the speaker is in a position of authority over the audience, who will be following his/er commands, and acting under the speaker's authority. The speaker is meaning to convey conditional instructions, for a possible circumstance. There is no component of observation or assertion. We see this distinction in programming too. Is the user merely asserting a relation, or defining a procedure? Implies( Raining( x ), Cloudy( x ) ) or if OutOfBread( x ): BuyBread( ) The 'if' statement is counterfactual in its native environment. As such, natural speakers never use it in vacuous cases, and it's not naturally defined. In a mathematical (ideal) environment, its semantics are artificially constructed like any other math predicate, and proofs involving it will define its vacuous case, or fail. From castironpi at gmail.com Mon Jun 15 12:18:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 09:18:48 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: On Jun 15, 8:37?am, a... at pythoncraft.com (Aahz) wrote: > In article <79mtt7F1r480... at mid.uni-berlin.de>, > Diez B. Roggisch wrote: > > >Aaron Brady wrote: > > >> Some time ago, I recommended a pursuit of keeping 'persistent > >> composite' types on disk, to be read and updated at other times by > >> other processes. ?Databases provide this functionality, with the > >> exception that field types in any given table are required to be > >> uniform. ?Python has no such restriction. > > >> I tried out an implementation of composite collections, specifically > >> lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > >> It's significantly slower, but we might argue that attempting to do it > >> by hand classifies as a premature optimization; it is easy to optimize > >> debugged code. > > >Sounds like you are re-inventing the ZODB. > > ...or SQLAlchemy or pickles in a SQL BLOB or... I recognize your aversion to my claim of making a new approach on something. I suppose an austere review of literature would compare with the existing alternatives. My approach does not define tables, so it is not SQL Alchemy; it is not mere sugar for SQL. It defines a 'set' class and a 'tuple' class, so some of the functionality may (and probably should be expected to) overlap. http://www.sqlalchemy.org/docs/05/ormtutorial.html#define-and-create-a-table My approach does not pickle objects, so it is not a mere BLOB pickle. If a user writes, listA[ 50 ].append( "abcde" ), one addition is made to an existing structure, and the remaining contents of 'listA' are unread and unchanged. From thephantom6969 at hotmail.com Mon Jun 15 13:02:54 2009 From: thephantom6969 at hotmail.com (Mikie) Date: Mon, 15 Jun 2009 10:02:54 -0700 (PDT) Subject: twisted server Message-ID: I am setting up a simple twisted server looks like this ___________________________________________________- It will respond on port 8007 of the local host With a predefined greeting. """ print greeting from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor class QOTD(Protocol): def connectionMade(self): self.transport.write(""" Twisted TCP Server Example

HELLO WORLD!

This is a TCP/IP Server written in Python using
the Twisted networking framework.

Further instruction can be found here:

	Twisted Documentation: Writing Servers


This server will respond on port 8007 of the local host
With a predefined greeting.
		
""") self.transport.loseConnection() # Then lines are Twisted magic: factory = Factory() factory.protocol = QOTD # Running under :8007 # Should be > :1024 reactor.listenTCP(8007, factory) reactor.run() ______________________________________________-- I would like to have an image loaded in the html page, but when I use the port is inserted and the image will not load. Is there a way to load the image? Thanx From http Mon Jun 15 14:10:22 2009 From: http (Paul Rubin) Date: 15 Jun 2009 11:10:22 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> Message-ID: <7xeitlv04x.fsf@ruckus.brouhaha.com> Aaron Brady writes: > > A real-world application of persistent data structures can be found here: > > http://stevekrenzel.com/persistent-list > > Jaime, thanks for the link. I contacted its author. You might also look at www.couchdb.org . From wayne.dads.bell at gmail.com Mon Jun 15 14:38:58 2009 From: wayne.dads.bell at gmail.com (dads) Date: Mon, 15 Jun 2009 11:38:58 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: I remember someone earlier in the thread mentioning reading source code from good coders. I've been wanting to give this a go as it makes perfect sense, I suppose the standard library would be a good start. What would your recommendations be, something not too too hard, so I don't understand. From chulusjo at franticfilms.com Mon Jun 15 14:58:59 2009 From: chulusjo at franticfilms.com (Christoffer Hulusjo) Date: Mon, 15 Jun 2009 11:58:59 -0700 Subject: catch/block assertion pop-up? Message-ID: <4A3699F3.8020709@franticfilms.com> Hi. I'm using a 32bit Python module to control a graphics application (Eyeon Fusion), that the developer of the application has released to allow python scripting. The module is known to have a bunch of bugs and the company that made it tells me that there is not a scheduled update anytime soon. I'm using simple commands that allows me to access the applications function, it looks something like this. .... fusionApp.Connect() settingsTable = fusionApp.GetSettings() .... The problem is that on some specific functions (which actually works and returns the requested data), it outputs assertion errors, which is a pop-up window like this... "Fusion Assert" (title) "File: FusionScript.cpp" "Line: 361" "Condition: false" "Debug, Disable, Skip" (buttons) So I'm getting all the data I need, but the popup error assertion makes my application useless as it could halt for user interaction at any time. By the looks of the error message it seems to be something actually happening in a c++ dll that the python module wraps to connect to the host application. I can't wait for the developer to update the library so my question is, Are there any way to suppress/block/catch dialogs that are poping up or assertions? it doesn't trigger any exception so I cant use try, catch. I'm using Python 2.5.2 32bit build on Windows XP 64bit OS. Best regards Christoffer From exarkun at divmod.com Mon Jun 15 15:01:24 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 15:01:24 -0400 Subject: twisted server In-Reply-To: Message-ID: <20090615190124.22176.1787062085.divmod.quotient.5697@henry.divmod.com> On Mon, 15 Jun 2009 10:02:54 -0700 (PDT), Mikie wrote: >I am setting up a simple twisted server looks like this > > [snip] > >I would like to have an image loaded in the html page, but when I use > the port is inserted and the image will not >load. Is there a way to load the image? This isn't a good way to make a web server with Twisted. Take a look at http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.html Jean-Paul From daniel.watrous at gmail.com Mon Jun 15 15:14:28 2009 From: daniel.watrous at gmail.com (Daniel) Date: Mon, 15 Jun 2009 12:14:28 -0700 (PDT) Subject: Limit (max) connections SimpleHTTPServer Message-ID: <310b1ad4-879e-4e4f-8244-9bfc6f4ebfc7@y10g2000prc.googlegroups.com> Hello, I would like to know if there is some way to limit the maximum number of connections to my SimpleHTTPServer. I have built a system that sends out work from one box to worker boxes and am using SimpleHTTPServer to send the work. The files are very large (sometimes as much as 20-30MB). When the system gets backed up, there can be as many as 500 requests coming in. After about 100 connections, the whole system starts to get sluggish. When they get over 250 or so some requests will begin to fail "error: (10054, 'Connection reset by peer')" or "error: (10053, 'Software caused connection abort')" Any help and suggestions appreciated. Thanks. From exarkun at divmod.com Mon Jun 15 15:30:55 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 15:30:55 -0400 Subject: Limit (max) connections SimpleHTTPServer In-Reply-To: <310b1ad4-879e-4e4f-8244-9bfc6f4ebfc7@y10g2000prc.googlegroups.com> Message-ID: <20090615193055.22176.273946368.divmod.quotient.5708@henry.divmod.com> On Mon, 15 Jun 2009 12:14:28 -0700 (PDT), Daniel wrote: >Hello, > >I would like to know if there is some way to limit the maximum number >of connections to my SimpleHTTPServer. I have built a system that >sends out work from one box to worker boxes and am using >SimpleHTTPServer to send the work. The files are very large >(sometimes as much as 20-30MB). When the system gets backed up, there >can be as many as 500 requests coming in. After about 100 >connections, the whole system starts to get sluggish. When they get >over 250 or so some requests will begin to fail > >"error: (10054, 'Connection reset by peer')" > >or "error: (10053, 'Software caused connection abort')" > >Any help and suggestions appreciated. For a server that has to deal with this kind of load, you might want to look at Twisted instead of SimpleHTTPServer. You can certainly impose a limit on the number of connections SimpleHTTPServer handles at once, but you'll get better performance with Twisted, due to less thread overhead and because you probably won't have to impose such a limit, or if you do, it can be much higher. Check it out: http://twistedmatrix.com/trac/ http://twistedmatrix.com/projects/core/documentation/howto/servers.html Jean-Paul From tjreedy at udel.edu Mon Jun 15 15:35:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 15:35:04 -0400 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: Christian Heimes wrote: > Terry Reedy wrote: >> You did not specify version. In Python3, os.walk has become a generater >> function. So, to answer your question, use 3.1. > > I'm sorry to inform you that Python 3.x still returns a list, not a > generator. >>> type(os.walk('.')) However, it is a generator of directory tuples that include a filename list produced by listdir, rather than a generator of filenames themselves, as I was thinking. I wish listdir had been changed in 3.0 along with map, filter, and range, but I made no effort and hence cannot complain. tjr From hellzfury at gmail.com Mon Jun 15 15:43:13 2009 From: hellzfury at gmail.com (Matt) Date: Mon, 15 Jun 2009 15:43:13 -0400 Subject: Multi-Threading and KeyboardInterrupt In-Reply-To: <20090615215335.4cb26673@coercion> References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> <20090615215335.4cb26673@coercion> Message-ID: <4C03B3DE-1DFC-4514-AC33-12BE334AC268@gmail.com> I'm going to use the multipocessing library from here forward so I can take advantage of multiple cores and clusters. Either one should work for my use, since in my non-demonstration code each thread spends most of it's time waiting for a separate non-Python subprocess (created with subprocess.Popen) to finish anyway. (I guess Python would see this as IO-blocking) Therefore, if you can fix my toy example with threading, that's fine. DB.py, followed by a KeyboardInterrupt yields the output in a.out. I want roughly the output in desired.out. What do I need to do to modify this code to get my desired output and corresponding functionality? It would be a shame if this wasn't possible in any pure-Python way. ~Matt On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote: > On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) > OdarR wrote: > >> On 13 juin, 07:25, Mike Kazantsev wrote: >>> There was quite interesting explaination of what happens when you >>> send >>> ^C with threads, posted on concurrency-sig list recently: >>> >>> http://blip.tv/file/2232410 >>> http://www.dabeaz.com/python/GIL.pdf >>> >>> Can be quite shocking, but my experience w/ threads only confirms >>> that. >> >> Hi there, >> please read this package page (in 2.6), this is very interesting. >> http://docs.python.org/library/multiprocessing.html >> >> I tested it : it works. Multi-core cpu's are happy :-) > > I'd certainly prefer using processes because they indeed work > flawlessly in that respect, but threads are way simplier and much more > integrated into the language, so I can avoid re-imlementing tons of > shared stuff, IPC and locking by using threads which bassically run in > the same context. > That might mean 90% of code for trivial but parallel task. > > Alas, they don't work flawlessly in all cases, but there is still > million and one use for them. > > -- > Mike Kazantsev // fraggod.net > -- > http://mail.python.org/mailman/listinfo/python-list I'm going to use the multipocessing library from here forward so I can take advantage of multiple cores and clusters. Either one should work for my use, since in my non-demonstration code each thread spends most of it's time waiting for a separate non-Python subprocess (created with subprocess.Popen) to finish anyway. (I guess Python would see this as IO-blocking) DB.py, followed by a KeyboardInterrupt yields the output in a.out. I want roughly the output in desired.out. What do I need to do to modify this code to get my desired output and corresponding functionality? It would be a shame if this wasn't possible in any pure-Python way. ~Matt On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote: > On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) > OdarR wrote: > >> On 13 juin, 07:25, Mike Kazantsev wrote: >>> There was quite interesting explaination of what happens when you >>> send >>> ^C with threads, posted on concurrency-sig list recently: >>> >>> http://blip.tv/file/2232410 >>> http://www.dabeaz.com/python/GIL.pdf >>> >>> Can be quite shocking, but my experience w/ threads only confirms >>> that. >> >> Hi there, >> please read this package page (in 2.6), this is very interesting. >> http://docs.python.org/library/multiprocessing.html >> >> I tested it : it works. Multi-core cpu's are happy :-) > > I'd certainly prefer using processes because they indeed work > flawlessly in that respect, but threads are way simplier and much more > integrated into the language, so I can avoid re-imlementing tons of > shared stuff, IPC and locking by using threads which bassically run in > the same context. > That might mean 90% of code for trivial but parallel task. > > Alas, they don't work flawlessly in all cases, but there is still > million and one use for them. > > -- > Mike Kazantsev // fraggod.net > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: a.out Type: application/octet-stream Size: 2780 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: desired.out Type: application/octet-stream Size: 142 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Sub.py Type: text/x-python-script Size: 165 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: DB.py Type: text/x-python-script Size: 604 bytes Desc: not available URL: From tjreedy at udel.edu Mon Jun 15 16:00:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:00:42 -0400 Subject: Question about None In-Reply-To: References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > >> Steven D'Aprano wrote: >>> So-called "vacuous truth". It's often useful to have all([]) return >>> true, but it's not *always* useful -- there are reasonable cases where >>> the opposite behaviour would be useful: > [...] >> It seems to me that the absurd conclusion implied by the theorem >> invalidates the theorem rather than supporting your point. > > I wouldn't go so far as to say the vacuous truth theorem ("empty > statements are true") is invalidated. The Wikipedia article discusses > various reasons why it's more correct (or at least more useful) to treat > vacuous statements as true: > > http://en.wikipedia.org/wiki/Vacuous_truth > > But it's not without difficulties -- however those difficulties are > smaller than those if you take vacuous statements as false in general. > > [...] >> Try finding another 'reasonable case'. > > Any time you do something like: > > if not x and all(x): > process(x) > > > instead of just: > > if all(x): > process(x) > > > I can't think of a real world example off the top of my head, but here's > a contrived example demonstrating that vacuous truths imply both a fact > and it's opposite: > > > def startswith(s, chars): > """Return True if s starts with any of chars.""" > for c in chars: > if s.startswith(c): return True > return False > > > if all([startswith(w, "aeiou") for w in words]): > print "All the words start with vowels." > > if all([startswith(w, "bcdfghjklmnpqrstvwxyz") for w in words]): > print "All of the words start with consonants." > If words is empty, this code claims that all of the words start with > vowels as well as starting with consonants. So? These are true and non-contradictory. They are NOT 'opposites'. Together they imply that there are are no words in words, which is true. To paraphrase my response to mel, I believe it was: [(x in words => x.startswith(vowel)) and (x in words => x.startswith(nonvowel)) and x.startswith(vowel) <=> not(x.startswith(nonvowel)] => not(x in words) which is the definition of 'words is the empty set' by the law of contradiction. The negation of 'all words starts with vowel' is 'there exists a word that starts with a non-vowel', which is different from 'all words start with consonants' since the latter is true when there are no words whereas the former is not. Terry Jan Reedy From tjreedy at udel.edu Mon Jun 15 16:06:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:06:36 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> Message-ID: John Machin wrote: > On Jun 15, 9:49 am, Terry Reedy wrote: >> Poor Yorick wrote: >>> The following code produces an error (python-2.6.2). >> You forgot to post the error traceback. > > The exception was IGNORED ... so no traceback. Yes, I forgot that Exception TypeError: "'NoneType' object is not callable" in ignored should be parsed as '''Exception TypeError: "'NoneType' object is not callable" in''' [was] ignored rather than read as Exception TypeError: "'NoneType' object is not callable" in ignored From arnodel at googlemail.com Mon Jun 15 16:10:04 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Jun 2009 21:10:04 +0100 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: "Andrew Henshaw" writes: > "Raymond Hettinger" wrote in message > news:fb1feeeb-c430-4ca7-9e76-fea02ea3ef6f at v23g2000pro.googlegroups.com... >> [David Wilson] >>> The problem is simple: given one or more ordered sequences, return >>> only the objects that appear in each sequence, without reading the >>> whole set into memory. This is basically an SQL many-many join. >> >> FWIW, this is equivalent to the Welfare Crook problem in David Gries >> book, The Science of Programming, http://tinyurl.com/mzoqk4 . >> >> >>> I thought it could be accomplished through recursively embedded >>> generators, but that approach failed in the end. >> >> Translated into Python, David Gries' solution looks like this: >> >> def intersect(f, g, h): >> i = j = k = 0 >> try: >> while True: >> if f[i] < g[j]: >> i += 1 >> elif g[j] < h[k]: >> j += 1 >> elif h[k] < f[i]: >> k += 1 >> else: >> print(f[i]) >> i += 1 >> except IndexError: >> pass >> >> streams = [sorted(sample(range(50), 30)) for i in range(3)] >> for s in streams: >> print(s) >> intersect(*streams) >> >> >> Raymond > > Here's my translation of your code to support variable number of streams: > > def intersect(*s): > num_streams = len(s) > indices = [0]*num_streams > try: > while True: > for i in range(num_streams): > j = (i + 1) % num_streams > if s[i][indices[i]] < s[j][indices[j]]: > indices[i] += 1 > break > else: > print(s[0][indices[0]]) > indices[0] += 1 > except IndexError: > pass I posted this solution earlier on: def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(1, len(v)): while v[0] > v[i]: v[i] = nexts[i]() if v[0] < v[i]: break else: yield v[0] v[0] = nexts[0]() It's quite similar but not as clever as the solution proposed by R. Hettinger insofar as it doesn't exploit the fact that if a, b, c are members of a totally ordered set, then: if a >= b >= c >= a then a = b = c. However it can be easily modified to do so: def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(-1, len(v)-1): if v[i] < v[i+1]: v[i] = nexts[i]() break else: yield v[0] v[0] = nexts[0]() I haven't really thought about it too much, but there may be cases where the original version terminates faster (I guess when it is expected that the intersection is empty). -- Arnaud From tjreedy at udel.edu Mon Jun 15 16:14:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:14:33 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: Phil Runciman wrote: > > Gain access to one of the IEEE or ACM web sites and their resources. > I used to sneak into my local university library before the 'Net to > read this stuff. > > Beyond that I check up on the reading lists for CS students from time > to time. This often throws up real gems and prevents me from being > blind-sided. For those who are not rich, MIT has put a lot of courseware on the web, including in particular, CS, for free. And there is lots more put up by professors and departments elsewhere. There are free language manuals and interpreters/compilers for those who want to stretch their brain that way. From tjreedy at udel.edu Mon Jun 15 16:25:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:25:46 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: A classic that I found valuable is Science of Programming David Gries, 1981 http://www.amazon.com/gp/product/0387964800 It is still in print as a paperback. Several ssed copies are $11 shipped to US - a bargain. Gries is a died-in-the-wool iterationist. His cursory discussion of recursion is not worth much, but he really knows iteration with while. From james at biosci.utexas.edu Mon Jun 15 16:51:46 2009 From: james at biosci.utexas.edu (james at biosci.utexas.edu) Date: Mon, 15 Jun 2009 15:51:46 -0500 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <20090615155146.4oifsimqdc08sg4k@webmail.utexas.edu> this mit course in the open courseware catalog is focused specifically on python: http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/Syllabus/index.htm Quoting Terry Reedy : > Phil Runciman wrote: >> >> Gain access to one of the IEEE or ACM web sites and their resources. >> I used to sneak into my local university library before the 'Net to >> read this stuff. >> >> Beyond that I check up on the reading lists for CS students from time >> to time. This often throws up real gems and prevents me from being >> blind-sided. > > For those who are not rich, MIT has put a lot of courseware on the web, > including in particular, CS, for free. And there is lots more put up > by professors and departments elsewhere. There are free language > manuals and interpreters/compilers for those who want to stretch their > brain that way. > > -- > http://mail.python.org/mailman/listinfo/python-list From Scott.Daniels at Acm.Org Mon Jun 15 17:05:05 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 15 Jun 2009 14:05:05 -0700 Subject: ImageEnhance.Contrast - is this fishy or what? In-Reply-To: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> Message-ID: roop wrote: > I was browsing ImageEnhace.py, and found something that I thought was > odd in class Contrast: > > class Contrast(_Enhance): > "Adjust image contrast" > def __init__(self, image): > self.image = image > mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/ > 256.0 > self.degenerate = Image.new("L", image.size, mean).convert > (image.mode) > > Isn't reduce(lambda a,b: a+b, image.convert("L").histogram()) the same > as (image.size[0] * image.size[1]) - just count the number of pixels > in the image? (Afaik, the histogram is a list of 256 elements where > the ith element gives the number of pixels with i as the pixel value > (0 <= i < 256)). Is this actually fishy or have I got it all muddled > up? > > Thanks, > roop Good catch [I'll send a copy to the imaging sig]. If you replace class Contrast like this: class Contrast(ImageEnhance._Enhance): "Adjust image contrast" def __init__(self, image): self.image = image w, h = image.size mean = sum(n * c for n, c in enumerate( image.convert("L").histogram()) ) / float(w * h) self.degenerate = Image.new("L", image.size, mean).convert(image.mode) You should get a working Contrast class. There _is_ another possibility: class Contrast(ImageEnhance._Enhance): "Adjust image contrast" def __init__(self, image): self.image = image clone = image.copy() clone.thumbnail((1, 1)) self.degenerate = clone.resize(image.size) The former goes to a grey point, while the latter goes to the picture's color center. I'm not quite sure which one is more properly called "contrast," as I can see wanting either one. --Scott David Daniels Scott.Daniels at Acm.Org From nick at craig-wood.com Mon Jun 15 17:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 16:29:33 -0500 Subject: waling a directory with very many files References: Message-ID: Jean-Paul Calderone wrote: > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: > >Hrvoje Niksic wrote: > >> Nick Craig-Wood writes: > >> > >> > Here is a ctypes generator listdir for unix-like OSes. > >> > >> ctypes code scares me with its duplication of the contents of system > >> headers. I understand its use as a proof of concept, or for hacks one > >> needs right now, but can anyone seriously propose using this kind of > >> code in a Python program? For example, this seems much more > >> "Linux-only", or possibly even "32-bit-Linux-only", than > >> "unix-like": > > > >It was a proof of concept certainly.. > > > >It can be done properly with gccxml though which converts structures > >into ctypes definitions. > > > >That said the dirent struct is specified by POSIX so if you get the > >correct types for all the individual members then it should be correct > >everywhere. Maybe ;-) > > The problem is that POSIX specifies the fields with types like off_t and > ino_t. Since ctypes doesn't know anything about these types, application > code has to specify their size and other attributes. As these vary from > platform to platform, you can't get it correct without asking a real C > compiler. These types could be part of ctypes. After all ctypes knows how big a long is on all platforms, and it knows that a uint32_t is the same on all platforms, it could conceivably know how big an off_t or an ino_t is too. > In other words, POSIX talks about APIs and ctypes deals with ABIs. > > http://pypi.python.org/pypi/ctypes_configure/0.1 helps with the problem, > and is a bit more accessible than gccxml. I haven't seen that before - looks interesting. > It is basically correct to say that using ctypes without using something > like gccxml or ctypes_configure will give you non-portable code. Well it depends on if the API is specified in types that ctypes understands. Eg, short, int, long, int32_t, uint64_t etc. A lot of interfaces are specified exactly like that and work just fine with ctypes in a portable way. I agree with you that struct dirent probably isn't one of those though! I think it would be relatively easy to implent the code I demonstrated in a portable way though... I'd do it by defining dirent as a block of memory and then for the first run, find a known filename in the block, establishing the offset of the name field since that is all we are interested in for the OPs problem. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ISF (Computer Scientists without Frontiers, Mon Jun 15 18:05:17 2009 From: ISF (Computer Scientists without Frontiers, (ISF (Computer Scientists without Frontiers,) Date: Mon, 15 Jun 2009 15:05:17 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <6101ec18-168f-4449-81ee-6f6808e22367@v35g2000pro.googlegroups.com> Hello All, good readings can be found among free e-books too: I'd like to share with you feeds to following free directories http://feeds2.feedburner.com/E-booksDirectory http://www.freetechbooks.com/rss.php warmest regards, Aldo From rick.arnett at gmail.com Mon Jun 15 18:07:22 2009 From: rick.arnett at gmail.com (the_ricka) Date: Mon, 15 Jun 2009 15:07:22 -0700 (PDT) Subject: Why is os.stat so slow? Message-ID: <9b2b9630-9895-447a-a147-8098a9efdf21@w3g2000yqf.googlegroups.com> Hi all, Fairly new to python but have programmed in other languages (C, Java) before. I was experimenting with a python program that needed to take a directory tree and get the total disk usage of every file (and subfolder) underneath it. This solution also has to run on Windows Server 2003 for work and it is accessing a NAS shared via CIFS. A sample folder I'm using contains about 26,000 subfolders and 435,000 files. The original solution I came up with was elegant, but extremely slow (compared to doing a right click in Windowsexplorer on the folder tree and clicking properties). It looked something like this: import os folder = r'Z:\foldertree' folder_size = 0 for (path, dirs, files) in os.walk(folder): for file in files: folder_size += os.path.getsize(os.path.join(path,file)) I profiled the above code and os.stat was taking up roughly 90% of the time. After digging around, I found some code in another post to use win32api to use API calls to speed this up (if you are interested, search for supper fast walk, yes super is misspelled). To my surprise, the average time is now about 1/7th of what it used to be. I believe the problem is that my simple solution had to call os.stat twice (once in the os.walk and once by me calling os.path.getsize) for every file and folder in the tree. I understand that os.stat can work on any OS. However, the expense should not be that dramatic of a difference (in my opinion). Is there an OS agnostic way to get this functionality to work faster? Also, if I wanted to port this to Linux or some other OS, is os.stat as expensive? If so, are there other libraries (like win32api) to assist in doing these operations faster? From thudfoo at opensuse.us Mon Jun 15 18:23:09 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 15 Jun 2009 15:23:09 -0700 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <3d881a310906151523v12f07101l7192c083c9f5e3fc@mail.gmail.com> On 6/15/09, Terry Reedy wrote: > Phil Runciman wrote: > > > > > Gain access to one of the IEEE or ACM web sites and their resources. > > I used to sneak into my local university library before the 'Net to > > read this stuff. > > > > Beyond that I check up on the reading lists for CS students from time > > to time. This often throws up real gems and prevents me from being > > blind-sided. > > > > For those who are not rich, MIT has put a lot of courseware on the web, > including in particular, CS, for free. And there is lots more put up by > professors and departments elsewhere. There are free language manuals and > interpreters/compilers for those who want to stretch their brain that way. > > The MIT Online Course Ware starts here: http://ocw.mit.edu/OcwWeb/web/help/start/index.htm I downloaded the Mathematics for Computer Science course: ~9MB. Looks to be excellent! Do you have links to share for the other materials? From mk.fraggod at gmail.com Mon Jun 15 19:31:53 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 05:31:53 +0600 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <20090616053154.1379a057@coercion> On Mon, 15 Jun 2009 15:35:04 -0400 Terry Reedy wrote: > Christian Heimes wrote: > > Terry Reedy wrote: > >> You did not specify version. In Python3, os.walk has become a generater > >> function. So, to answer your question, use 3.1. > > > > I'm sorry to inform you that Python 3.x still returns a list, not a > > generator. > > >>> type(os.walk('.')) > > > However, it is a generator of directory tuples that include a filename > list produced by listdir, rather than a generator of filenames > themselves, as I was thinking. I wish listdir had been changed in 3.0 > along with map, filter, and range, but I made no effort and hence cannot > complain. Why? We have itertools.imap, itertools.ifilter and xrange already. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From songkai.sk at gmail.com Mon Jun 15 19:36:21 2009 From: songkai.sk at gmail.com (kai) Date: Mon, 15 Jun 2009 16:36:21 -0700 (PDT) Subject: Build problem on Solaris 9 Message-ID: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> Hi All, When I run make after successively running ./configure, I got the following Error message: ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl /usr/bin/env: No such file or directory make: *** [Python/Python-ast.c] Error 127 /usr/bin/env deos exist.... Can anyone help me with this? Kai From castironpi at gmail.com Mon Jun 15 19:56:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 16:56:58 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> Message-ID: On Jun 15, 11:10?am, Paul Rubin wrote: > Aaron Brady writes: > > > A real-world application of persistent data structures can be found here: > > >http://stevekrenzel.com/persistent-list > > > Jaime, thanks for the link. ?I contacted its author. > > You might also look atwww.couchdb.org. I'm not much for the interface. But the back end might match what I'm doing. From ldo at geek-central.gen.new_zealand Mon Jun 15 20:57:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Jun 2009 12:57:31 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro > wrote: > >> Perl allows just about any printable character as a quote. I tried >> alternative quotes for many years, and decided making that choice was a >> waste of brain cells. >> >> So no, using alternative quotes does not make things more readable. > > I find it odd that you consider qquoting less scalable than backslashes. Backslashes are scalable because they can be nested to any depth, without having to decide beforehand which quotes to use at which level. And yes, I do write things like this: out.write \ ( "function JSString(Str)\n" # /* returns a JavaScript string literal that evaluates to Str. */ " {\n" " var Result = \"\\\"\"\n" " for (var i = 0; i < Str.length; ++i)\n" " {\n" " var ThisCh = Str.charAt(i)\n" " if (ThisCh == \"\\\\\")\n" " {\n" " ThisCh = \"\\\\\\\\\"\n" " }\n" " else if (ThisCh == \"\\\"\")\n" " {\n" " ThisCh = \"\\\\\\\"\"\n" " }\n" " else if (ThisCh == \"\\t\")\n" " {\n" " ThisCh = \"\\\\t\"\n" " }\n" " else if (ThisCh == \"\\n\")\n" " {\n" " ThisCh = \"\\\\n\"\n" " } /*if*/\n" " Result += ThisCh\n" " } /*for*/\n" " return Result + \"\\\"\"\n" "} /*JSString*/\n" ) > I also find it odd that you dislike two visuals stutters (at the start > and end of string) so much that you'll put up with a dozen visual > stutters in the string to avoid them. Particular since my years of > Perl-bashing lead me to the opposite conclusion. I find it odd you should think so. From pavlovevidence at gmail.com Mon Jun 15 21:49:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 18:49:16 -0700 (PDT) Subject: Observer implementations References: Message-ID: On Jun 15, 5:22?pm, Tobias Weber wrote: > In article , > ?Gerhard H?ring wrote: > > > Implement it in your classes? > > No time to reinvent the wheel Hmm, observer pattern seems to be one of those things simple enough that reimplementing the wheel might actually be less work than adapting a third-party implementation. But I'll leave that decision to you. > I'd still need to know how to weakref a classmethod I can't imagine why you would need to weak reference a class method, since they usually live forever along with the class. But again, you are doing it so you would know. I can't think of an easy way to do it without metaclass programming. Unless you are trying to create a weakref to a bound classmethod. I'd say that's still pretty useless: bound classmethods only keep alive classes and classmethods, which both live forever, and bound classmethods are lightweight and hardly worth the effort. Maybe show us what you need to weak reference classmethods for and we can help you better. Carl Banks From sjmachin at lexicon.net Mon Jun 15 22:50:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Jun 2009 19:50:02 -0700 (PDT) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> Message-ID: <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> On Jun 16, 6:06?am, Terry Reedy wrote: > John Machin wrote: > > On Jun 15, 9:49 am, Terry Reedy wrote: > >> Poor Yorick wrote: > >>> The following code produces an error (python-2.6.2). > >> You forgot to post the error traceback. > > > The exception was IGNORED ... so no traceback. > > Yes, I forgot that > Exception TypeError: "'NoneType' object is not callable" in ?ignored > > should be parsed as > > '''Exception TypeError: "'NoneType' object is not callable" in''' [was] > ? ?ignored > > rather than read as > > Exception TypeError: "'NoneType' object is not callable" in ignored Yep, it's not the clearest message I've ever seen, and it gives no clue as to who or what is doing the ignoring. Here's a suggestion for your enhancement request: Shutdown ignored this exception: TypeError: "'NoneType' object is not callable" From steve at nospam.au Mon Jun 15 22:56:19 2009 From: steve at nospam.au (steve) Date: Tue, 16 Jun 2009 12:56:19 +1000 Subject: python tutorial Message-ID: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> I was just looking at the python tutorial, and I noticed these lines: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files "Windows makes a distinction between text and binary files; "the end-of-line characters in text files are automatically altered "slightly when data is read or written. I don't see any obvious way to at docs.python.org to get that corrected: Is there some standard procedure? Steve From deostroll at gmail.com Mon Jun 15 23:01:58 2009 From: deostroll at gmail.com (deostroll) Date: Mon, 15 Jun 2009 20:01:58 -0700 (PDT) Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> Message-ID: <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> I want to be able to parse it into python objects. Any ideas? --deostroll From ivlenin at gmail.com Mon Jun 15 23:11:18 2009 From: ivlenin at gmail.com (I V) Date: 16 Jun 2009 05:11:18 +0200 Subject: Observer implementations References: Message-ID: <4a370d56$1@news.x-privat.org> On Mon, 15 Jun 2009 15:29:34 +0200, Tobias Weber wrote: > Despite the confusion all those are useable, but I ran into the problem > that I can't register a @classmethod because weakref doesn't like them. What do you mean by weakref not liking class methods? This seems to work OK on python 2.6 class C(object): @classmethod def cm(cls): return "Class method of " + str(cls) cm = C.cm print cm() # Outputs: # Class method of w = weakref.ref(cm) print w # Outputs: # print w() # Outputs: # > print w()() # Outputs: # Class method of del cm print w # Outputs: # From pavlovevidence at gmail.com Mon Jun 15 23:58:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 20:58:47 -0700 (PDT) Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> On Jun 15, 7:56?pm, "steve" wrote: > I was just looking at the python tutorial, and I noticed these lines: > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > "Windows makes a distinction between text and binary files; > "the end-of-line characters in text files are automatically altered > "slightly when data is read or written. > > I don't see any obvious way to at docs.python.org to get that corrected: Is > there some standard procedure? What's wrong with it? Carl Banks From pavlovevidence at gmail.com Tue Jun 16 00:04:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 21:04:08 -0700 (PDT) Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: <639fccd8-d5a1-4bee-a2db-ccf63d7786d2@a5g2000pre.googlegroups.com> On Jun 15, 8:01?pm, deostroll wrote: > I want to be able to parse it into python objects. Any ideas? 1. If applicable, pay better attention in class. 2. Install simplejson and try to use it, then, if you still need help, come back and post your question along with your honest attempt to do it. P.S. Someone will be by to post the "How to ask smart questions" essay shortly. Carl Banks From davea at ieee.org Tue Jun 16 00:06:13 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 00:06:13 -0400 Subject: : an integer is required In-Reply-To: References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: <4A371A35.7040809@ieee.org> Ulrich Eckhardt wrote: > open() doesn't take a string as second parameter, see 'help(open)'. Instead, > it takes one of the integers which are defined as symbols in the os module, > see 'dir(os)'. > > > Where'd you get that misinformation? The second parameter to the builtin function open() is a string, such as 'r', 'wb', etc. help(open) doesn't say much in 2.6, but in 3.1, it spells it out. For 2.6, look at the non-interactive documentation, such as the chm file in Windows. Now perhaps you're referring to open() in some other module, such as os.open(). If so, it behooves you to specify that, as an unqualified open() can only refer to the one in builltin. From msdark at archlinux.cl Tue Jun 16 00:11:12 2009 From: msdark at archlinux.cl (Matias Hernandez Arellano) Date: Tue, 16 Jun 2009 00:11:12 -0400 Subject: Label (or other widget) auto refresh? Message-ID: <4A371B60.7080505@archlinux.cl> Hi list... I have a question for you.. First... sorry for my english, but i speak spanish xD.. I have a little GUI made with Glade and GtkBuilder... in his gui when i click on a button i show a dialog window.. in this dialog i put a label.. this label show some value.. this value was reading from serial port. The PC is connected to a Basic Stamp (a microcontroller), the Basic Stamp write in the serial port a binary value every time when a some sensor change.. I need to show this value in the label in the dialog window at the same time when the basic stamp write to the serial port... How can i refresh the text in the label to show the change of the value every time... instantaniely? I think in a threads, but i can't get it... Thanks a lot!!!! -- Matias Hern?ndez (Msdark) www.msdark.archlinux.cl ArchLinux-CL - WikiAdmin MSN: matiasfh at gmail.com Twitter : www.twitter.com/msdark Plurk : www.plurk.com/msdark Linux User: #445065 http://keys.gnupg.net/pks/lookup?op=get&search=0xEA3EEC672189419C From clp2 at rebertia.com Tue Jun 16 00:19:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Jun 2009 21:19:59 -0700 Subject: On the property function In-Reply-To: <4A364202.2050700@it.uu.se> References: <4A364202.2050700@it.uu.se> Message-ID: <50697b2c0906152119x7d30e5a1xb88175d0295de442@mail.gmail.com> On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: > Does anyone have a good example (or examples) of when "property(...)" can be > useful? Erm, when you want to create a property (i.e. computed attribute). from __future__ import division class TimeDelta(object): def __init__(self, secs): self. seconds =secs @property def minutes(self): return self.seconds/60 @property def hours(self): return self.minutes/60 @property def days(self): return self.hours/24 td = TimeDelta(55555555555) print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" Cheers, Chris -- http://blog.rebertia.com From philr at aspexconsulting.co.nz Tue Jun 16 00:26:29 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 16 Jun 2009 16:26:29 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: FWIW I actually dislike this book! Gasp... Much of the material is excellent but IBM got into the huge mess with the 360. Brooks observed failure from the inside and IMHO did a great job of it. Project managers can never rescue stuffed concepts especially if a lot of money has been spent! Such projects have momentum and roll over anyone who gets in the way. Brilliant architects are worth their weight in gold. I believe that ICL's VME/B OS began as a skunk works project.* It had such an architect. The latter was the official OS and was pretty good too. I think Warboys took over later once VME/B became official... if anyone out there knows better then please let us know and correct Wikipedia too. The Wikipedia item on VME is too sanitised for my taste. The "truth" is generally far more interesting. If the software you are developing is going to be used by many people then remaining sharp and on top of your game is so important. Do not program if you are tired or you will spend your life debugging. ;-) I stop coding at 3pm for this reason. I come right again around 10pm! Yes, despite the above, do read the book, but remember that among the content is a cautionary tale! Ooops, the above is a bit away from Python. ;-) Phil *I was told this by the leader an ICL research team, no less than Alan Sutcliffe himself... many years ago now. (c. May/June 1970) -----Original Message----- From: Roy Smith [mailto:roy at panix.com] Sent: Sunday, 14 June 2009 2:21 p.m. Subject: Re: Good books in computer science? In article , "Rhodri James" wrote: > The Mythical Man-Month (Brooks) is a must. What's amazing about this book is just how relevant it is today, 35 years after it was written. Some of the technical details have changed (how many of us still keep our project notes on microfiche?), but cross out "microfiche" and write in "wiki" and what he's saying is just as valid today. It's not about computer science. It's not really even about software engineering. It's more about general project management than anything else. In the same vein, Death March, by Ed Yourdon. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 00:29:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Jun 2009 04:29:13 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: On Mon, 15 Jun 2009 20:58:47 -0700, Carl Banks wrote: > On Jun 15, 7:56?pm, "steve" wrote: >> I was just looking at the python tutorial, and I noticed these lines: >> >> http://docs.python.org/tutorial/inputoutput.html#reading-and- writing-... >> >> "Windows makes a distinction between text and binary files; "the >> end-of-line characters in text files are automatically altered >> "slightly when data is read or written. >> >> I don't see any obvious way to at docs.python.org to get that >> corrected: Is there some standard procedure? > > What's wrong with it? Perhaps because it's unclear whether it is Windows, or Python, or both, which is automatically altering the data. As for getting the docs changed, you can submit a bug request at the bug tracker: http://bugs.python.org/ -- Steven From mk.fraggod at gmail.com Tue Jun 16 00:31:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 10:31:09 +0600 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: <20090616103109.4b4ee4ff@coercion> On Mon, 15 Jun 2009 20:01:58 -0700 (PDT) deostroll wrote: > I want to be able to parse it into python objects. Any ideas? JSON objects behave like python dicts (key:val pairs), so why not just use them? Both simplejson and py2.6-json (which is quite similar to the former) do just that, but if you like JS attribute-like key access model you can use it by extending the builtin dict class: import types, collections class AttrDict(dict): '''AttrDict - dict with JS-like key=attr access''' def __init__(self, *argz, **kwz): if len(argz) == 1 and not kwz and isinstance(argz[0], types.StringTypes): super(AttrDict, self).__init__(open(argz[0])) else: super(AttrDict, self).__init__(*argz, **kwz) for k,v in self.iteritems(): setattr(self, k, v) # re-construct all values via factory def __val_factory(self, val): return AttrDict(val) if isinstance(val, collections.Mapping) else val def __getattr__(self, k): return super(AttrDict, self).__getitem__(k) __getitem__ = __getattr__ def __setattr__(self, k, v): return super(AttrDict, self).__setitem__(k, self.__val_factory(v)) __setitem__ = __setattr__ if __name__ == '__main__': import json data = AttrDict(json.loads('{"host": "docs.python.org",' ' "port": 80,' ' "references": [ "collections",' ' "json",' ' "types",' ' "data model" ],' ' "see_also": { "UserDict": "similar, although' ' less flexible dict implementation." } }')) print data.references # You can always use it as a regular dict print 'port' in data print data['see_also'] # Data model propagnates itself to any sub-mappings data.see_also.new_item = dict(x=1, y=2) print data.see_also.keys() data.see_also.new_item['z'] = 3 print data.see_also.new_item.z -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From philr at aspexconsulting.co.nz Tue Jun 16 00:33:31 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 16 Jun 2009 16:33:31 +1200 Subject: FW: Good books in computer science? Message-ID: Oh dear the "latter" referred to VME/K but got lost in my editing. Sorry about that. Phil > -----Original Message----- > From: Phil Runciman > Sent: Tuesday, 16 June 2009 4:26 p.m. > To: python-list at python.org > Subject: RE: Good books in computer science? > > FWIW I actually dislike this book! Gasp... > > Much of the material is excellent but IBM got into the huge mess with > the 360. Brooks observed failure from the inside and IMHO did a great > job of it. > > Project managers can never rescue stuffed concepts especially if a > lot of money has been spent! Such projects have momentum and roll > over anyone who gets in the way. > > Brilliant architects are worth their weight in gold. I believe that > ICL's VME/B OS began as a skunk works project.* It had such an > architect. The LATTER was the official OS and was pretty good too. I > think Warboys took over later once VME/B became official... if anyone > out there knows better then please let us know and correct Wikipedia > too. The Wikipedia item on VME is too sanitised for my taste. The > "truth" is generally far more interesting. > > If the software you are developing is going to be used by many people > then remaining sharp and on top of your game is so important. Do not > program if you are tired or you will spend your life debugging. ;-) I > stop coding at 3pm for this reason. I come right again around 10pm! > > Yes, despite the above, do read the book, but remember that among the > content is a cautionary tale! > > Ooops, the above is a bit away from Python. ;-) > > > Phil > > > *I was told this by the leader an ICL research team, no less than > Alan Sutcliffe himself... many years ago now. (c. May/June 1970) > > > -----Original Message----- > From: Roy Smith [mailto:roy at panix.com] > Sent: Sunday, 14 June 2009 2:21 p.m. > Subject: Re: Good books in computer science? > > In article , > "Rhodri James" wrote: > > > The Mythical Man-Month (Brooks) is a must. > > What's amazing about this book is just how relevant it is today, 35 > years > after it was written. Some of the technical details have changed > (how many > of us still keep our project notes on microfiche?), but cross out > "microfiche" and write in "wiki" and what he's saying is just as > valid > today. It's not about computer science. It's not really even about > software engineering. It's more about general project management > than > anything else. > > In the same vein, Death March, by Ed Yourdon. From ldo at geek-central.gen.new_zealand Tue Jun 16 00:45:43 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Jun 2009 16:45:43 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In message , Piet van Oostrum wrote: > The exact time of the destruction of objects is an implementation detail > and should not be relied upon. That may be true in Java and other corporate-herd-oriented languages, but we know that dynamic languages like Perl and Python make heavy use of reference-counting wherever they can. If it's easy to satisfy yourself that the lifetime of an object will be delimited in this way, I don't see why you can't rely upon it. From girish.cfc at gmail.com Tue Jun 16 01:09:57 2009 From: girish.cfc at gmail.com (Girish) Date: Mon, 15 Jun 2009 22:09:57 -0700 (PDT) Subject: Error in reg dll Message-ID: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Hello. I am not able to register DLL generated from py2exe I have written following code to generate the DLL: ################################################################################## from distutils.core import setup import py2exe import sys # If run without args, build executables, in quiet mode. if len(sys.argv) == 1: sys.argv.append("py2exe") sys.argv.append("-q") class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "2.8.9" self.name = "DSPACE API" # a COM server dll, modules is required # interp = Target( description = "COM server module", modules = ["Dspace"], create_exe = True, ) excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs", "pywin.dialogs.list"] options = { "bundle_files": 1, "ascii": 1, # to make a smaller executable, don't include the encodings "compressed": 1, # compress the library archive "excludes": excludes, # COM stuff we don't want } setup( options = {"py2exe": options}, zipfile = None, # append zip-archive to the executable. com_server = [interp], ) #######################################END######################################## When I try to register the dll using the commant: regsve32 dspace.dll, I am getting error saying :"DLLRegisterServer in dspace.dll failed. Return code was: 0xc0000005" Please help me to solve this issue. Thanks, Girish... From mk.fraggod at gmail.com Tue Jun 16 01:12:17 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 11:12:17 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> <20090615215335.4cb26673@coercion> Message-ID: <20090616111217.321e2c50@coercion> On Mon, 15 Jun 2009 15:43:13 -0400 Matt wrote: > I'm going to use the multipocessing library from here forward so I can > take advantage of multiple cores and clusters. Either one should work > for my use, since in my non-demonstration code each thread spends most > of it's time waiting for a separate non-Python subprocess (created > with subprocess.Popen) to finish anyway. (I guess Python would see > this as IO-blocking) Therefore, if you can fix my toy example with > threading, that's fine. > > DB.py, followed by a KeyboardInterrupt yields the output in a.out. I > want roughly the output in desired.out. > > What do I need to do to modify this code to get my desired output and > corresponding functionality? It would be a shame if this wasn't > possible in any pure-Python way. I don't know how complex task you have, but solving trivial IO blocks with threads or subprocesses look either like ugly hack or an overkill to me. Why not just use I/O without blocking? It's not 80s or 90s anymore, where you had to create subprocess to handle every non-synchronous task, and since the main burden will be pushed into non-py subprocesses already, why not implement controller as a nice, clean and simple single-threaded event loop? Consider this recipe: http://code.activestate.com/recipes/576759/ And if the task before you is complex indeed, involving more than just two to five child processes with a simple "while True: ..." loop, consider using twisted framework - it'll allow you to do incredible stuff with any number of sockets with just few lines of code in a clean, abstracted way. Latter would also mean that you can always replace os pipes with network sockets just by changing transport name, distributing your app to any number of machines. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From davea at ieee.org Tue Jun 16 01:30:00 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 01:30:00 -0400 Subject: python tutorial In-Reply-To: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4A372DD8.5030102@ieee.org> steve wrote: > I was just looking at the python tutorial, and I noticed these lines: > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files > > "Windows makes a distinction between text and binary files; > "the end-of-line characters in text files are automatically altered > "slightly when data is read or written. > > I don't see any obvious way to at docs.python.org to get that corrected: Is > there some standard procedure? > > Steve > > It's not clear from your question what you want corrected. Are you saying that the tutorial leaves out some detail? Or are you upset that reading the data gets "automatically altered" data? If it's the former, just lookup the function in the reference documentation (eg. the chm file in a Windows installation). The way to control the behavior is with the 'mode' parameter to open(). If mode has a 'b' in it, the file is considered binary, which means no translation is done. If the mode has a 'u' in it, or neither 'b' nor 'u', then some translation is done. The purpose of the translation is to let the program always use \n to mean end of line, for code that'll be portable between the various operating system conventions. Windows typically does text files with \r\n at the end of each line. Some Macs do just a \r, and Unix and Linux use a \n. One reason a programmer has to be aware of it is that he/she may be reading or writing a file from a different operating environment, for example, a script that'll be uploaded to a web server running a different OS. From hniksic at xemacs.org Tue Jun 16 03:03:43 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 16 Jun 2009 09:03:43 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> <87fxe14shp.fsf@busola.homelinux.net> Message-ID: <87fxe0fynk.fsf@busola.homelinux.net> Nick Craig-Wood writes: > It can be done properly with gccxml though which converts structures > into ctypes definitions. That sounds interesting. > That said the dirent struct is specified by POSIX so if you get the > correct types for all the individual members then it should be > correct everywhere. Maybe ;-) AFAIK POSIX specifies the names and types of the members, but not their order in the structure, nor alignment. From eckhardt at satorlaser.com Tue Jun 16 03:08:12 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 16 Jun 2009 09:08:12 +0200 Subject: : an integer is required References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: Dave Angel wrote: > Ulrich Eckhardt wrote: >> open() doesn't take a string as second parameter, see 'help(open)'. >> Instead, it takes one of the integers which are defined as symbols in the >> os module, see 'dir(os)'. > > [...]The second parameter to the builtin function open() is a string[...] > Now perhaps you're referring to open() in some other module, such as > os.open(). True, mixed those up, as perhaps did the OP. > an unqualified open() can only refer to the one in builltin. ...unless you explicitly imported an 'open' from somewhere else. Thanks for the correction. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From Joachim at Strombergson.com Tue Jun 16 03:12:40 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Tue, 16 Jun 2009 09:12:40 +0200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4A3745E8.3080600@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! dads wrote: > I remember someone earlier in the thread mentioning reading source > code from good coders. I've been wanting to give this a go as it makes > perfect sense, I suppose the standard library would be a good start. > What would your recommendations be, something not too too hard, so I > don't understand. When people wants to know what (good) Python code looks like, I usually point them to Trac: http://trac.edgewall.org/ Trac is not only a good tool for development written in Python. Trac also uses Trac to develop Trac (cudos for eating your own dogfood) and Trac allows easy browsing of the source code. I still consider myself a Python-n00b and my judgement might be all wrong. But I believe that the Trac developers follows Pythonic code rules and the result a prime example of what well written, well document Python code looks like. Check for yourself though at: http://trac.edgewall.org/browser/trunk/trac - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko3RegACgkQZoPr8HT30QEMVwCgrNkOYMGFmhMYunwZqlTFpAkt He8AoOEXIC/QXkRu+sHtzIz+1+JQZp2F =o+g8 -----END PGP SIGNATURE----- From martin at v.loewis.de Tue Jun 16 03:15:33 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 16 Jun 2009 09:15:33 +0200 Subject: Build problem on Solaris 9 In-Reply-To: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> References: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> Message-ID: <4a374695$0$11163$9b622d9e@news.freenet.de> > When I run make after successively running ./configure, I got the > following Error message: > ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl > /usr/bin/env: No such file or directory > make: *** [Python/Python-ast.c] Error 127 > > /usr/bin/env deos exist.... > > Can anyone help me with this? It's probably rather that "python" does not exist on the path, which asdl_c.py requires. touch Include/Python-ast.h Python/Python-ast.c should work around. Regards, Martin From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 03:34:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Jun 2009 07:34:35 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > In message , Piet van Oostrum wrote: > >> The exact time of the destruction of objects is an implementation >> detail and should not be relied upon. > > That may be true in Java and other corporate-herd-oriented languages, > but we know that dynamic languages like Perl and Python make heavy use > of reference-counting wherever they can. If it's easy to satisfy > yourself that the lifetime of an object will be delimited in this way, I > don't see why you can't rely upon it. Reference counting is an implementation detail used by CPython but not IronPython or Jython. I don't know about the dozen or so other minor/new implementations, like CLPython, PyPy, Unladen Swallow or CapPython. In other words, if you want to write *Python* code rather than CPython code, don't rely on ref-counting. -- Steven From zeal_goswami at yahoo.com Tue Jun 16 04:35:41 2009 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Tue, 16 Jun 2009 14:05:41 +0530 (IST) Subject: Regarding GUI Message-ID: <736213.33022.qm@web94916.mail.in2.yahoo.com> Hi, I have a very basic question about GUI programming as i am beginner into Python. You are providing many enviroment for GUI programming in python. But could you guide me which is better or frequently used Abhishek Goswami Chennai Phone No -0996227099 Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From banibrata.dutta at gmail.com Tue Jun 16 04:46:34 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 16 Jun 2009 14:16:34 +0530 Subject: Regarding GUI In-Reply-To: <736213.33022.qm@web94916.mail.in2.yahoo.com> References: <736213.33022.qm@web94916.mail.in2.yahoo.com> Message-ID: <3de8e1f70906160146k11ad35adu131de2fd0ed5b66e@mail.gmail.com> Kindly search the archives of this mailing list... this is a fairly FAQ, and you should find a relevant thread which isn't older than 2-3 months, IIRC. In brief, you have several options, as you've probably already found, most one of the most popular is wxPython but then there are several other alternatives, and best fit depends on your specific requirements, constraints and background. On Tue, Jun 16, 2009 at 2:05 PM, abhishek goswami wrote: > Hi, > I have a very basic question about GUI programming as i am beginner into > Python. > > You are providing many enviroment for GUI programming in python. But could > you guide me > > which is better or frequently used > > > Abhishek Goswami > Chennai > Phone No -0996227099 > ------------------------------ > Bollywood news, movie reviews, film trailers and more! Click here. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From starglider101 at gmail.com Tue Jun 16 04:48:46 2009 From: starglider101 at gmail.com (Jorge) Date: Tue, 16 Jun 2009 09:48:46 +0100 Subject: Need to know if a file as only ASCII charaters Message-ID: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Hi there, I'm making a application that reads 3 party generated ASCII files, but some times the files are corrupted totally or partiality and I need to know if it's a ASCII file with *nix line terminators. In linux I can run the file command but the applications should run in windows. Any help will be great. Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Tue Jun 16 05:16:54 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 16 Jun 2009 02:16:54 -0700 (PDT) Subject: On the property function References: <4A364202.2050700@it.uu.se> Message-ID: On Jun 16, 9:19?am, Chris Rebert wrote: > On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: > > Does anyone have a good example (or examples) of when "property(...)" can be > > useful? > > Erm, when you want to create a property (i.e. computed attribute). > > from __future__ import division > class TimeDelta(object): > ? ? def __init__(self, secs): > ? ? ? ? self. seconds =secs > > ? ? @property > ? ? def minutes(self): > ? ? ? ? return self.seconds/60 > > ? ? @property > ? ? def hours(self): > ? ? ? ? return self.minutes/60 > > ? ? @property > ? ? def days(self): > ? ? ? ? return self.hours/24 > > td = TimeDelta(55555555555) > print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" > > Cheers, > Chris > --http://blog.rebertia.com To add a little more, this link _ http://dirtsimple.org/2004/12/python-is-not-java.html _ might help. - Search for 'Getters and setters' and you will reach the place where property is explained more. From prasoonthegreat at gmail.com Tue Jun 16 05:32:31 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 02:32:31 -0700 (PDT) Subject: Input problem Message-ID: I am new to python....and using python 2.6 I want to know when to use raw_input( ) and when to use input( )??? According to my interpretation one should use input( ) when entering numbers etc and raw_input( ) when a string is too be entered..... Correct me if I am wrong.... Also if I want to enter two numbers 'a' and b such that while entering them through the keyboard there is a space between the two... For example: >>>Enter two numbers: .....12 15 Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? I mean how to handle spaces???/ From mjohnson at cfi.co.ug Tue Jun 16 05:32:40 2009 From: mjohnson at cfi.co.ug (Johnson Mpeirwe) Date: Tue, 16 Jun 2009 12:32:40 +0300 Subject: PSP Text Editor Message-ID: <4A3766B8.7000507@cfi.co.ug> Hi all, Does anyone know of any good Python Server Pages text editor that can provide indentation, syntax highlighting, etc.. Thank you. Regards, Johnson From lie.1296 at gmail.com Tue Jun 16 06:14:13 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 10:14:13 GMT Subject: On the property function In-Reply-To: References: <4A364202.2050700@it.uu.se> Message-ID: Chris Rebert wrote: > On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: >> Does anyone have a good example (or examples) of when "property(...)" can be >> useful? > > Erm, when you want to create a property (i.e. computed attribute). > > from __future__ import division > class TimeDelta(object): > def __init__(self, secs): > self. seconds =secs > > @property > def minutes(self): > return self.seconds/60 > > @property > def hours(self): > return self.minutes/60 > > @property > def days(self): > return self.hours/24 > > td = TimeDelta(55555555555) > print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" > > Cheers, > Chris Python's property is better than just that... from __future__ import division class TimeDelta(object): def __init__(self, secs): self. seconds =secs @property def minutes(self): return self.seconds @minutes.setter def minutes(self, value self.seconds = 60 * value @property def hours(self): return self.minutes/60 @hours.setter def hours(self, value): self.minutes = 60 * value @property def days(self): return self.hours/24 @days.setter def days(self, value): self.hours = 24 * value From bearophileHUGS at lycos.com Tue Jun 16 06:16:15 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 16 Jun 2009 03:16:15 -0700 (PDT) Subject: Input problem References: Message-ID: <87eb235f-83a8-401d-845a-1237530ed959@h18g2000yqj.googlegroups.com> Prasoon: > I am new to python....and using python 2.6 > I want to know when to use raw_input( ) and when to use input( )??? I think it's better to always use raw_input(), and then convert the string to the data to work on. Once in a while you may want to use input() to input expressions (like formulas) in your program in a quick, simple and unsafe way... In Python3+ they have removed input() and they have renamed raw_input () as input(). You can have the functionality of 2.x input() with eval (input()). (I think Python3 developers have taken the right choices here). Bye, bearophile From bieffe62 at gmail.com Tue Jun 16 06:34:02 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 16 Jun 2009 03:34:02 -0700 (PDT) Subject: Input problem References: Message-ID: On 16 Giu, 11:32, Prasoon wrote: > I am new to python....and using python 2.6 > I want to know when to use raw_input( ) and when to use input( )??? > > According to my interpretation one should use input( ) when entering > numbers etc and > raw_input( ) when a string is too be entered..... > > Correct me if I am wrong.... > You should almost always use raw_input and write your own code to validate the input and convert it. input (wich is roughly equivalent of veval (raw:_input()) is officially considered a Bad Choice and as such has been changed in Python 3.x ( that is, python 3.x 'input' is equivalent to python 2.x raw_input ). P.S : if you are new to python and don't expect to use external libraries for the next months (one year?) you might consider to start directly with python 3.x. > Also if I want to enter two numbers 'a' and b such that while entering > them through the keyboard > there is a space between the two... > > For example:>>>Enter two numbers: > > ?.....12 15 > > Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? > > I mean how to handle spaces???/ For instance: map( int, raw_input.split() ) splits the input string using blanks as separator, then try to convert each piece in an integer and returns a list of integer. Of course if the input string is not a list of integer you get an exception. You could also do: a, b = map( int, raw_input.split() ) but in this case you get an exception also if the input strings cobntains less or more than two integers. Ciao ----- FB From sanal.vikram at gmail.com Tue Jun 16 07:30:02 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Tue, 16 Jun 2009 04:30:02 -0700 (PDT) Subject: how to stop a function execution like... Message-ID: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Is there any built-in function to stop execution of a function similar to stop the program execution by sys.exit? In the example below, I want to skip statement 2... if the 'if' condition is satisfied. Don't advice me to put statement 2 in 'else' block. That's not my intention. May be this a simple task. Sorry to say I'm novice in Python, gentlemen... def funct : if (.....) : statement 1 statement 2 From prasoonthegreat at gmail.com Tue Jun 16 07:36:07 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 04:36:07 -0700 (PDT) Subject: Input problem References: Message-ID: On Jun 16, 3:34?pm, Francesco Bochicchio wrote: > On 16 Giu, 11:32, Prasoon wrote:> I am new to python....and using python 2.6 > > I want to know when to use raw_input( ) and when to use input( )??? > > > According to my interpretation one should use input( ) when entering > > numbers etc and > > raw_input( ) when a string is too be entered..... > > > Correct me if I am wrong.... > > You should almost always use raw_input and write your own code to > validate the > input and convert it. input (wich is roughly equivalent of veval > (raw:_input()) > is officially considered a Bad Choice and as such has been changed in > Python 3.x > ( that is, python 3.x 'input' is equivalent to python 2.x raw_input ). > > P.S : if you are new to python and don't expect to use external > libraries for the next > months (one year?) you might consider to start directly with python > 3.x. > > > Also if I want to enter two numbers 'a' and b such that while entering > > them through the keyboard > > there is a space between the two... > > > For example:>>>Enter two numbers: > > > ?.....12 15 > > > Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? > > > I mean how to handle spaces???/ > > For instance: map( int, raw_input.split() ) splits the > input string using blanks as separator, then try to convert each piece > in an integer > and returns a list of integer. Of course if the input string is not a > list of integer > you get an exception. > > You could also do: > > a, b = ?map( int, raw_input.split() ) > > but in this case you get an exception also if the input strings > cobntains less or more than two integers. > > Ciao > ----- > FB I think you meant a, b = map( int, raw_input().split() ) Prasoon From aaron.watters at gmail.com Tue Jun 16 07:44:32 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 16 Jun 2009 04:44:32 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> Message-ID: <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> On Jun 14, 4:47 pm, dads wrote: > I'm wanting to purchase some of the titles that have been raised in > this thread. When I look they are very expensive books which is > understandable. Do you think getting earlier editions that are cheaper > is a daft thing or should I fork out the extra ?10-?30 to get the > latest edition? This is the best book ever written on computer science and the first edition is free. http://www.math.upenn.edu/~wilf/AlgComp3.html -- Aaron Watters http://aaron.oirt.rutgers.edu/myapp/amcharts/doc === less is more. From deets at nospam.web.de Tue Jun 16 07:45:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Jun 2009 13:45:16 +0200 Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Message-ID: <79penvF1qrnigU1@mid.uni-berlin.de> Gaudha wrote: > Is there any built-in function to stop execution of a function similar > to stop the program execution by sys.exit? > In the example below, I want to skip statement 2... if the 'if' > condition is satisfied. > Don't advice me to put statement 2 in 'else' block. That's not my > intention. Why not? It's from all you tell us perfectly the right thing to do. > May be this a simple task. Sorry to say I'm novice in Python, > gentlemen... > > def funct : > if (.....) : statement 1 > statement 2 def funct(): if ...: statement 1 return statement 2 would also work. But it is not really "better" than using else. Diez From prasoonthegreat at gmail.com Tue Jun 16 07:49:32 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 04:49:32 -0700 (PDT) Subject: Input problem References: Message-ID: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> What is the difference between z=int(raw_input()) and z=eval(raw_input())????(I thought them to be the same in case of integers) I mean when an integer is entered in that case are they same and when an integer in not entered,in that case how are they different????? From sanal.vikram at gmail.com Tue Jun 16 08:22:06 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Tue, 16 Jun 2009 05:22:06 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> Message-ID: <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> On Jun 16, 4:45?pm, "Diez B. Roggisch" wrote: > Gaudha wrote: > > Is there any built-in function to stop execution of a function similar > > to stop the program execution by sys.exit? > > In the example below, I want to skip statement 2... if the 'if' > > condition is satisfied. > > Don't advice me to put statement 2 in 'else' block. That's not my > > intention. > > Why not? It's from all you tell us perfectly the right thing to do. > > > May be this a simple task. Sorry to say I'm novice in Python, > > gentlemen... > > > def funct : > > ? ? if (.....) : statement 1 > > ? ? statement 2 > > def funct(): > ? ? if ...: > ? ? ? ?statement 1 > ? ? ? ?return > ? ? statement 2 > > would also work. But it is not really "better" than using else. > > Diez I considered 'return' as meant only for returning any value. Thank you sir... From phil at riverbankcomputing.com Tue Jun 16 08:28:53 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 16 Jun 2009 13:28:53 +0100 Subject: SIP v4.8.1 Released Message-ID: <25d841a7520e2a394970782902ef5892@localhost> SIP v4.8.1 has been released and can be downloaded from http://www.riverbankcomputing.com/software/sip/. SIP is a tool for generating Python modules that wrap C or C++ libraries. It is similar to SWIG. It is used to generate PyQt and PyKDE. SIP is licensed under the Python License and runs on Windows, UNIX, Linux and MacOS/X. SIP requires Python v2.3 or later. The main focus of this release is support for Python v3. Other features of SIP include: - extension modules are implemented as a single binary .pyd or .so file (no Python stubs) - support for Python new-style classes - the ability to specify the super-type and meta-type used to wrap instances - generated modules are quick to import, even for large libraries - thread support - the ability to re-implement C++ abstract and virtual methods in Python - the ability to define Python classes that derive from abstract C++ classes - the ability to spread a class hierarchy across multiple Python modules - support for C++ namespaces - support for C++ exceptions - support for C++ operators - an extensible build system written in Python that supports over 50 platform/compiler combinations - the generation of API files for IDEs that support autocompletion and call tips. From lukepadawan at gmail.com Tue Jun 16 08:48:41 2009 From: lukepadawan at gmail.com (Lucas P Melo) Date: Tue, 16 Jun 2009 09:48:41 -0300 Subject: Tool for browsing python code Message-ID: <4A3794A9.5080309@gmail.com> Is there any tool for browsing python code? (I'm having a hard time trying to figure this out) Anything like cscope with vim would be great. From stef.mientki at gmail.com Tue Jun 16 08:54:08 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 14:54:08 +0200 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: <4A3795F0.3020009@gmail.com> Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time > trying to figure this out) > Anything like cscope with vim would be great. maybe a good IDE like PyScripter would do ? cheers, Stef From banibrata.dutta at gmail.com Tue Jun 16 08:55:00 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 16 Jun 2009 18:25:00 +0530 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> On Tue, Jun 16, 2009 at 6:18 PM, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time trying > to figure this out) > Anything like cscope with vim would be great. > -- > http://mail.python.org/mailman/listinfo/python-list > If you are not averse to GUI's, there are lot of options... IDLE, PyScripter, BOA, PyDev(Eclipse)... not sure if there are any "curses" base TUI's (!) for Python. -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdpinheiro at gmail.com Tue Jun 16 08:55:35 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 16 Jun 2009 05:55:35 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> Message-ID: On Jun 16, 12:45?pm, "Diez B. Roggisch" wrote: > Gaudha wrote: > > Is there any built-in function to stop execution of a function similar > > to stop the program execution by sys.exit? > > In the example below, I want to skip statement 2... if the 'if' > > condition is satisfied. > > Don't advice me to put statement 2 in 'else' block. That's not my > > intention. > > Why not? It's from all you tell us perfectly the right thing to do. > If I understood his post correctly, it's because he really wants to exit the function early. If that is the case, in his real situation rather than the tiny example he posted, using the else clause would translate into: def funct(params): if a: something else: rest of the function goes here and it goes on for a while so you just burnt through an indentation level needlessly Now we can have a nice philosophical discussion about how using the else version makes the execution outline more obvious :) From phil at riverbankcomputing.com Tue Jun 16 09:09:33 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 16 Jun 2009 14:09:33 +0100 Subject: PyQt v4.5.1 Released (Python bindings for Qt) Message-ID: PyQt v4.5.1 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/. PyQt is a comprehensive set of bindings for the Qt application and UI framework from Nokia. It supports the same platforms as Qt (Windows, Linux and MacOS/X). The highlights of this release include: - support for Python v3 - support for Qt v4.5 - a new Pythonic API for connecting signals and slots that doesn't require any knowledge of C++ data types - support for the GTK+ theme engine. Windows installers are provided for the GPL version of PyQt which contains everything needed for PyQt development (including Qt, Qt Designer and QScintilla) except Python itself. PyQt v4 is implemented as a set of 18 extension modules containing over 400 classes and over 6,000 functions and methods. QtCore The non-GUI infrastructure including event loops, threads, i18n, Unicode, signals and slots, user and application settings, mapped files and shared memory. QtDesigner A set of classes that allow the Qt Designer GUI design tool to be extended with PyQt. QtGui A rich collection of GUI widgets. QtHelp A set of classes for creating and viewing searchable documentation and being able to integrate online help with PyQt applications. It includes the C++ port of the Lucene text search engine. QtNetwork A set of classes to support TCP and UDP socket programming and higher level protocols (eg. HTTP, SSL). QtOpenGL A set of classes that allows PyOpenGL to render onto Qt widgets. QtScript A set of classes that implements a JavaScript interpreter. Python objects may be exposed in the interpreter as JavaScript objects. QtScriptTools A debugger for the JavaScript interpreter. QtSql A set of classes that implement SQL data models and interfaces to industry standard databases. The Windows installers include support for SQLite, MySQL, PostgreSQL and ODBC. QtSvg A set of classes to render SVG files onto Qt widgets. QtTest A set of classes to automate unit testing of PyQt applications and GUIs. QtWebKit This implements a web browser engine based on the WebKit engine used by Apple's Safari browser. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages. QtXML A set of classes that implement DOM and SAX parsers. QtXMLPatterns A set of classes that implement XQuery and XPath support for XML and custom data models. QtAssistant A set of classes that enables the Qt Assistant online help browser to be integrated with an application. QAxContainer A set of classes for Windows that allows the integration of ActiveX controls and COM objects. phonon A cross-platform multimedia framework that enables the use of audio and video content in PyQt applications. DirectX is used as the Windows backend, QuickTime as the MacOS/X backend, and GStreamer as the Linux backend. DBus PyQt includes dbus.mainloop.qt that allows the Qt event loop to be used with the standard DBus Python bindings. PyQt includes the pyuic4 utility which generates Python code to implement user interfaces created with Qt Designer in the same way that the uic utility generates C++ code. It is also able to load Designer XML files dynamically. PyQt is available under the GPL and a commercial license. Unlike Qt, PyQt is not available under the LGPL. The commercial PyQt license allows GPL applications to be relicensed at any time. From davea at ieee.org Tue Jun 16 09:17:42 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 09:17:42 -0400 Subject: Need to know if a file as only ASCII charaters In-Reply-To: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A379B76.9060801@ieee.org> Jorge wrote: > Hi there, > I'm making a application that reads 3 party generated ASCII files, but some > times > the files are corrupted totally or partiality and I need to know if it's a > ASCII file with *nix line terminators. > In linux I can run the file command but the applications should run in > windows. > > Any help will be great. > > Thank you in advance. > > So, which is the assignment: 1) determine if a file has non-ASCII characters 2) determine whether the line-endings are crlf or just lf In the former case, look at translating the file contents to Unicode, specifying ASCII as source. If it fails, you have non-ASCII In the latter case, investigate the 'u' attribute of the mode parameter in the open() function. You also need to ask yourself whether you're doing a validation of the file, or doing a "best guess" like the file command. From davea at ieee.org Tue Jun 16 09:29:28 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 09:29:28 -0400 Subject: how to stop a function execution like... In-Reply-To: <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> Message-ID: <4A379E38.3080200@ieee.org> Gaudha wrote: > On Jun 16, 4:45 pm, "Diez B. Roggisch" wrote: > >> Gaudha wrote: >> >>> Is there any built-in function to stop execution of a function similar >>> to stop the program execution by sys.exit? >>> In the example below, I want to skip statement 2... if the 'if' >>> condition is satisfied. >>> Don't advice me to put statement 2 in 'else' block. That's not my >>> intention. >>> >> Why not? It's from all you tell us perfectly the right thing to do. >> >> >>> May be this a simple task. Sorry to say I'm novice in Python, >>> gentlemen... >>> >>> def funct : >>> if (.....) : statement 1 >>> statement 2 >>> >> def funct(): >> if ...: >> statement 1 >> return >> statement 2 >> >> would also work. But it is not really "better" than using else. >> >> Diez >> > > I considered 'return' as meant only for returning any value. Thank you > sir... > > return with no arguments will return a value of None, same as falling off the end of the function. That can be important to know, as the caller can therefore test for None. From jsanga at cox.net Tue Jun 16 09:43:55 2009 From: jsanga at cox.net (mzdude) Date: Tue, 16 Jun 2009 06:43:55 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Message-ID: <8c2b6de8-60a1-49b7-8a69-622b9849856a@g15g2000pra.googlegroups.com> On Jun 16, 7:30?am, Gaudha wrote: > Is there any built-in function to stop execution of a function similar > to stop the program execution by sys.exit? > In the example below, I want to skip statement 2... if the 'if' > condition is satisfied. > Don't advice me to put statement 2 in 'else' block. That's not my > intention. > May be this a simple task. Sorry to say I'm novice in Python, > gentlemen... > > def funct : > ? ? if (.....) : statement 1 > ? ? statement 2 sys.exit is a pretty harsh way to stop execution. It usually means unable to continue. There is nothing that stops you from putting that in a function. Another possiblity would be def funct : if( .... ) : statement 1 raise UserWarning, "precondition X in funct not met" statement 2 ... statement n Check out the try / except docs. From mcfletch at vrplumber.com Tue Jun 16 09:53:21 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 16 Jun 2009 09:53:21 -0400 Subject: Observer implementations In-Reply-To: References: Message-ID: <4A37A3D1.7050901@vrplumber.com> Tobias Weber wrote: ... > No time to reinvent the wheel > > I'd still need to know how to weakref a classmethod > See PyDispatcher for code to do this. PyDispatcher, at least, is not abandoned, it would be more accurate to say "finished". I use it in OpenGLContext (extensively), but I haven't had to change anything in a rather long time. It pretty much just works. Enjoy, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From castironpi at gmail.com Tue Jun 16 09:57:13 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 16 Jun 2009 06:57:13 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> Message-ID: <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> On Jun 15, 4:56?pm, Aaron Brady wrote: > On Jun 15, 11:10?am, Paul Rubin wrote: > > > Aaron Brady writes: > > > > A real-world application of persistent data structures can be found here: > > > >http://stevekrenzel.com/persistent-list > > > > Jaime, thanks for the link. ?I contacted its author. > > > You might also look atwww.couchdb.org. > > I'm not much for the interface. ?But the back end might match what I'm > doing. Making the charitable interpretation that this was the extent of c-l- py's support and enthusiasm for my idea, I will now go into mourning. Death occurred at oh-eight-hundred. Rest in peace, support & enthusiasm. From pdpinheiro at gmail.com Tue Jun 16 10:17:27 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 16 Jun 2009 07:17:27 -0700 (PDT) Subject: Need to know if a file as only ASCII charaters References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <639ae03a-3808-422e-acbf-97b0c4eb9bb7@e21g2000yqb.googlegroups.com> On Jun 16, 2:17?pm, Dave Angel wrote: > Jorge wrote: > > Hi there, > > I'm making ?a application that reads 3 party generated ASCII files, but some > > times > > the files are corrupted totally or partiality and I need to know if it's a > > ASCII file with *nix line terminators. > > In linux I can run the file command but the applications should run in > > windows. > > > Any help will be great. > > > Thank you in advance. > > So, which is the assignment: > ? ?1) determine if a file has non-ASCII characters > ? ?2) determine whether the line-endings are crlf or just lf > > In the former case, look at translating the file contents to Unicode, > specifying ASCII as source. ?If it fails, you have non-ASCII > In the latter case, investigate the 'u' attribute of the mode parameter > in the open() function. > > You also need to ask yourself whether you're doing a validation of the > file, or doing a "best guess" like the file command. >From your requisites, you're already assuming something that _should_ be ASCII, so it's easiest to check for ASCIIness at the binary level: Open the file as binary Loop at the bytes exit with error upon reading a byte outside the printable range (32-126 decimal) or any of a number of lower-range exceptions (\n, \t -- not \r since you want UNIX-style linefeeds) exit with success if the loop ended cleanly This supposes you're dealing strictly with ASCII, and not a full 8 bit codepage, of course. From shuantsu at gmail.com Tue Jun 16 10:20:00 2009 From: shuantsu at gmail.com (Filipe Teixeira) Date: Tue, 16 Jun 2009 07:20:00 -0700 (PDT) Subject: simple GUI for my application? Message-ID: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Hi, I'm really struggling to find the best GUI to make a simple application. I'm doing a program to load all the ini files in the current folder, or the folder that the user chooses and list the specifics entries in it. So, the program would be like this: Som tabs here like: ( Load | Edit | Options) In the [ Load ] tab: A folder tree in the left, and two labels or edit boxes showing some specific entries in the ini file. In the [ Edit ] tab: really straight-forward, Edit boxes of the entries so the user can edit in the [ options ] tab: More edits to specifie the default folder, etc. Basically I will use a lot of edit boxes and some tabs, and a folder tree, any tips so I can search in the right place? From usernet at ilthio.net Tue Jun 16 10:23:54 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 16 Jun 2009 14:23:54 GMT Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <_VNZl.32463$yr3.10126@nlpi068.nbdc.sbc.com> On 2009-06-16, Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. http://www.python.org/doc/faq/gui/ From HeinTest at web.de Tue Jun 16 10:41:09 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 16:41:09 +0200 Subject: Funny xmlrpc / linux problem Message-ID: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Hello, I found a timing problem while playing with the xmlrpx stuff. I created a very simple server, running on a network node on windows. The client runs on windows or linux. It runs a very simple test function on the server which just echos a passed string. The trip time is beeing measured. When I use a 1024 char test string I get a trip time in the 10-20ms range on windows and linux. But for small arguments the trip time explodes - why on earth ?! May be this problem is here off topic and tcp/ip stack related. Here is the very very simply test server: #!/usr/bin/python # -*- coding: cp1250 -*- # xmlrpc test server import SimpleXMLRPCServer import xmlrpclib import time # the test function - justs echos the argument def RunTest(buffer): return buffer print "Starting RPC Server..." # Create server server = SimpleXMLRPCServer.SimpleXMLRPCServer(("node01", 10000)) server.register_function(RunTest) # Run the server's main loop server.serve_forever() This is the test client: #!/usr/bin/python # -*- coding: cp1250 -*- # Test for Roundtrip Time xmlrpc calls import SimpleXMLRPCServer import xmlrpclib import datetime print "started..." s = xmlrpclib.ServerProxy('http://laptvm:10000') # place here your server address for scale in (100240, 10240, 1024, 512, 256, 128, 64, 32, 16, 10, 1): print "Checking with", scale buffer = "0123456789" * scale now = datetime.datetime.now() for i in range(10): res = s.RunTest(buffer) if buffer != res: print "data error" later = datetime.datetime.now() dt = later - now print "time for 10 loops: %f" % (dt.seconds + (0.000001 * dt.microseconds)) Some results from my tests here: started... Checking with 100240 time for 10 loops: 3.282000 Checking with 10240 time for 10 loops: 0.360000 Checking with 1024 time for 10 loops: 0.078000 Checking with 512 time for 10 loops: 0.047000 Checking with 256 time for 10 loops: 0.046000 Checking with 128 time for 10 loops: 0.047000 Checking with 64 time for 10 loops: 1.985000 ' Whats this ?! - smaler packets, more time ?! Checking with 32 time for 10 loops: 2.000000 Checking with 16 time for 10 loops: 2.000000 Checking with 10 time for 10 loops: 2.000000 Checking with 1 time for 10 loops: 2.000000 Tanks a lot, Hans From dcm6293 at rit.edu Tue Jun 16 10:42:08 2009 From: dcm6293 at rit.edu (Daniel Merboth (RIT Student)) Date: Tue, 16 Jun 2009 10:42:08 -0400 Subject: Getting a processes' name? Message-ID: <4CD74416FB9F204EA1258409610E5626AD127A@svits27.main.ad.rit.edu> Hello, My college uses a program called AccessGrid for video conferencing, and it runs through pythonw.exe. It comes with a python script to kill all processes and exit the program. The problem is, the script kills everything related to pythonw.exe, including my open scripts. I'm looking for a way to get the name of the window or the processname, or something, to differentiate between the running versions of pythonw.exe. This is critical to a script I'm writing that grabs a bunch of the computer's information, populates an HTML table with it, then uploads it to an internal webpage. The goal is to make my (and my co-worker's) job easier on AccessGrid node maintenance. We use VNC to remotely access and having a table that automatically updates when a DNS or IP changes would be an incredible asset to us. The script also includes some basic information about AccessGrid, so if a staffmember emails us a node isn't working, we can quickly diagnose and repair the problem. The scripts both overlap in getting the name of a running process. I'm also kind of teaching myself python to write this. I have coding experience in java though. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From HeinTest at web.de Tue Jun 16 10:51:57 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 16:51:57 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Small addition: While tracing the network data I found the server to be the problem, the answer to a request is beeing delayed by about 180ms - no idea why. From stef.mientki at gmail.com Tue Jun 16 10:58:05 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 16:58:05 +0200 Subject: simple GUI for my application? In-Reply-To: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <4A37B2FD.6010006@gmail.com> Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. > > I'm doing a program to load all the ini files in the current folder, > or the folder that the user chooses and list the specifics entries in > it. > > So, the program would be like this: > > Som tabs here like: > ( Load | Edit | Options) > > In the [ Load ] tab: > A folder tree in the left, and two labels or edit boxes showing some > specific entries in the ini file. > > In the [ Edit ] tab: > really straight-forward, Edit boxes of the entries so the user can > edit > > in the [ options ] tab: > More edits to specifie the default folder, etc. > > Basically I will use a lot of edit boxes and some tabs, and a folder > tree, any tips so I can search in the right place? > mayby this will do: http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html cheers, Stef From HeinTest at web.de Tue Jun 16 11:06:27 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 17:06:27 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37b4f3$0$3279$8e6e7893@newsreader.ewetel.de> Another addendum... while running again the server code on a linux host, the times are as expected. started... Checking with 100240 time for 10 loops: 2.844000 Checking with 10240 time for 10 loops: 0.390000 Checking with 1024 time for 10 loops: 0.078000 Checking with 512 time for 10 loops: 0.063000 Checking with 256 time for 10 loops: 0.063000 Checking with 128 time for 10 loops: 0.062000 Checking with 64 time for 10 loops: 0.063000 Checking with 32 time for 10 loops: 0.063000 Checking with 16 time for 10 loops: 0.062000 Checking with 10 time for 10 loops: 0.063000 Checking with 1 time for 10 loops: 0.063000 The problem seems to be on the windows side. Any ideas ? Thanks, greetings Hans From gnapalm at gmail.com Tue Jun 16 11:07:42 2009 From: gnapalm at gmail.com (gnapalm) Date: Tue, 16 Jun 2009 17:07:42 +0200 Subject: Python module problem under QNX Message-ID: Hello, I'm trying to solve an issue with custom Python module at QNX 6.4.0 and Python 2.5.2. I have simple Python module (A.so) written in c++ which is linked against some other c++ library (B.so) both build by autotools. On Linux all works fine with PYTHONPATH pointed to A.so directory when dynamic linker loads B.so afterwards. On QNX there is no inter-library dependency support in libtools and Python can not find symbols from B.so. I'm not using dlopen in Python module and I would like to keep it that way. What is the workaround for this issue? Thanks in advance. g. From mk.fraggod at gmail.com Tue Jun 16 11:09:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 21:09:09 +0600 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> Message-ID: <20090616210909.10eb439c@coercion> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) Aaron Brady wrote: > Making the charitable interpretation that this was the extent of c-l- > py's support and enthusiasm for my idea, I will now go into mourning. > Death occurred at oh-eight-hundred. Rest in peace, support & > enthusiasm. I've read this thread from the beginning, being tempted to insert remarks about shelve module or ORMs like SQLAlchemy, but that'd be meaningless without the problem description, which I haven't seen anywhere. Is it some trick idea like "let's walk on our heads"? -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From gnapalm at gmail.com Tue Jun 16 11:19:29 2009 From: gnapalm at gmail.com (gnapalm) Date: Tue, 16 Jun 2009 17:19:29 +0200 Subject: Python so module dependency problem under QNX Message-ID: Hello, I'm trying to solve an issue with custom Python module at QNX 6.4.0 and Python 2.5.2. I have simple Python module (A.so) written in c++ which is linked against some other c++ library (B.so) both build by autotools. On Linux all works fine with PYTHONPATH pointed to A.so directory when dynamic linker loads B.so afterwards. On QNX there is no inter-library dependency support in libtools and Python can not find symbols from B.so. I'm not using dlopen in Python module and I would like to keep it that way. What is the workaround for this issue? Thanks in advance. g. From brian at sweetapp.com Tue Jun 16 11:19:36 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Tue, 16 Jun 2009 16:19:36 +0100 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4A37B808.1080202@sweetapp.com> Hey Hans, Try reversing the list of numbers and see if anything changes. Cheers, Brian Hans M?ller wrote: > Hello, > > I found a timing problem while playing with the xmlrpx stuff. > > I created a very simple server, running on a network node on windows. > The client runs on windows or linux. It runs a very simple test function > on the server > which just echos a passed string. The trip time is beeing measured. > When I use a 1024 char test string I get a trip time in the 10-20ms > range on windows and linux. > But for small arguments the trip time explodes - why on earth ?! > > May be this problem is here off topic and tcp/ip stack related. > > Here is the very very simply test server: > > #!/usr/bin/python > # -*- coding: cp1250 -*- > # xmlrpc test server > > import SimpleXMLRPCServer > import xmlrpclib > import time > > # the test function - justs echos the argument > def RunTest(buffer): > return buffer > > > print "Starting RPC Server..." > > # Create server > server = SimpleXMLRPCServer.SimpleXMLRPCServer(("node01", 10000)) > server.register_function(RunTest) > > # Run the server's main loop > server.serve_forever() > > > This is the test client: > > #!/usr/bin/python > # -*- coding: cp1250 -*- > # Test for Roundtrip Time xmlrpc calls > > import SimpleXMLRPCServer > import xmlrpclib > import datetime > > print "started..." > > > s = xmlrpclib.ServerProxy('http://laptvm:10000') # place here > your server address > > for scale in (100240, 10240, 1024, 512, 256, 128, 64, 32, 16, 10, 1): > print "Checking with", scale > buffer = "0123456789" * scale > now = datetime.datetime.now() > for i in range(10): > res = s.RunTest(buffer) > if buffer != res: > print "data error" > later = datetime.datetime.now() > dt = later - now > > print "time for 10 loops: %f" % (dt.seconds + (0.000001 * > dt.microseconds)) > > > > Some results from my tests here: > > started... > Checking with 100240 > time for 10 loops: 3.282000 > Checking with 10240 > time for 10 loops: 0.360000 > Checking with 1024 > time for 10 loops: 0.078000 > Checking with 512 > time for 10 loops: 0.047000 > Checking with 256 > time for 10 loops: 0.046000 > Checking with 128 > time for 10 loops: 0.047000 > Checking with 64 > time for 10 loops: 1.985000 ' Whats this ?! - smaler packets, more > time ?! > Checking with 32 > time for 10 loops: 2.000000 > Checking with 16 > time for 10 loops: 2.000000 > Checking with 10 > time for 10 loops: 2.000000 > Checking with 1 > time for 10 loops: 2.000000 > > > > Tanks a lot, > Hans From R.Brodie at rl.ac.uk Tue Jun 16 11:22:27 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 16 Jun 2009 16:22:27 +0100 Subject: Funny xmlrpc / linux problem References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: "Hans M?ller" wrote in message news:4a37b18d$0$3283$8e6e7893 at newsreader.ewetel.de... > Small addition: > > While tracing the network data I found the server to be the problem, > the answer to a request is beeing delayed by about 180ms - no idea why. Nagle's algorithm: you've unintentionally produced a textbook demonstration. From darcy at druid.net Tue Jun 16 11:23:23 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 16 Jun 2009 11:23:23 -0400 Subject: Tool for browsing python code In-Reply-To: <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: <20090616112323.4dc759e2.darcy@druid.net> On Tue, 16 Jun 2009 18:25:00 +0530 Banibrata Dutta wrote: > not sure if there are any "curses" base TUI's (!) for Python. vi -- 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 gabriel.rossetti at arimaz.com Tue Jun 16 11:41:08 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Tue, 16 Jun 2009 17:41:08 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? Message-ID: <4A37BD14.5010807@arimaz.com> Hello everyone, I get an OperationalError with sqlite3 if I put the wrong column name, but shouldn't that be a ProgrammingError instead? I read PEP 249 and it says : " OperationalError Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. It must be a subclass of DatabaseError. ProgrammingError Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc. It must be a subclass of DatabaseError. " and to me it sounds more like a programming error than an operational error. Thank you, Gabriel From esnow at verio.net Tue Jun 16 11:59:40 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 08:59:40 -0700 (PDT) Subject: doctests and decorators Message-ID: Apparently there is a known issue with doctests, in which tests in functions using externally defined decorators are ignored. The recommended fix is to update the order of checks in the _from_module method of DocTestFinder in the doctest module. The bug and fix are discussed at the following URLs (and several places in this group): http://bugs.python.org/issue1108 http://mail.python.org/pipermail/python-list/2007-September/627866.html The fix implies that the inpect.getmodule function will find the module of the function object and not of the decorator. However, in 2.4 the inspect.getmodule function returns the module of the decorator. I have subsequently tested this in 2.5 and 2.6, and it also returns the module of the decorator. As such, the fix for doctests does not work in my tests. Below is the test code that I used: test1.py ++++++++++++++++++++++++++++ def decorator(function): def new_function(*args, **kwargs): return function(*args, **kwargs) return new_function test2.py ++++++++++++++++++++++++++++ import test1 import inspect class Test(object): @test1.decorator def test2(self): pass def run_tests(): test = Test() test.test2() print("Test is class, test is instance, test2 is method of Test (has decorator)") print("test's module: %s" % inspect.getmodule(test)) print("Test's module: %s" % inspect.getmodule(Test)) print("test.test2's module: %s" % inspect.getmodule (test.test2)) print("Test.test2's module: %s" % inspect.getmodule (Test.test2)) print("test.test2's func_name: %s" % test.test2.func_name) print("Test.test2's func_name: %s" % Test.test2.func_name) if __name__ == "__main__": run_tests() Here is the output that I got in 2.4, 2.5, and 2.6: Test is class, test is instance, test2 is method of Test (has decorator) test's module: Test's module: test.test2's module: Test.test2's module: test.test2's func_name: new_function Test.test2's func_name: new_function If things were working right, then the module for test.test2 would be the same as the module for test. I must be missing something, as the referenced discussion suggests a simple conclusion. Any ideas? -eric From shaibani at ymail.com Tue Jun 16 12:00:02 2009 From: shaibani at ymail.com (Ala) Date: Tue, 16 Jun 2009 17:00:02 +0100 Subject: ODE, GUI, plotter in Python Message-ID: <160620091700027246%shaibani@ymail.com> Hello everyone. I am starting on implementing a simulator using python, and since it's the first time I code in python would appreciate a few pointers: The simulator will use a coupled ODE for the most part of the simulation, I plan to use scipy. (Anything considered faster/better than scipy for solving coupled ODEs? ) I plan for a GUI program with network graph plotting. I am leaning towards using Qt for the GUI (internet forums seem to recommend it, anyone got other preferences? ) Since the GUI application will contain few buttons and a plot, I am planning to implement matplotlib into the GUI. But does anyone know if matplotlib allows for interaction with the graph plot? (say for a network simulation, allowing to right click on nodes and disable them for instance, or alter some other properties of nodes and/or links across them). I am just starting out, hence I'd rather get some advice and experiment a bit for my self as I go along. Thank you. From esnow at verio.net Tue Jun 16 12:19:03 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 09:19:03 -0700 (PDT) Subject: doctests and decorators References: Message-ID: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> On Jun 16, 9:59?am, Eric Snow wrote: > Apparently there is a known issue with doctests, in which tests in > functions using externally defined decorators are ignored. ?The > recommended fix is to update the order of checks in the _from_module > method of DocTestFinder in the doctest module. ?The bug and fix are > discussed at the following URLs (and several places in this group): > > http://bugs.python.org/issue1108http://mail.python.org/pipermail/python-list/2007-September/627866.html > > The fix implies that the inpect.getmodule function will find the > module of the function object and not of the decorator. ?However, in > 2.4 the inspect.getmodule function returns the module of the > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > also returns the module of the decorator. ?As such, the fix for > doctests does not work in my tests. ?Below is the test code that I > used: > > > > test1.py > ++++++++++++++++++++++++++++ > def decorator(function): > ? ? def new_function(*args, **kwargs): > ? ? ? ? return function(*args, **kwargs) > ? ? return new_function > > test2.py > ++++++++++++++++++++++++++++ > import test1 > import inspect > > class Test(object): > ? ? @test1.decorator > ? ? def test2(self): pass > > def run_tests(): > ? ? test = Test() > ? ? test.test2() > > ? ? print("Test is class, test is instance, test2 is method of Test > (has decorator)") > ? ? print("test's module: ? ? ? ? ?%s" % inspect.getmodule(test)) > ? ? print("Test's module: ? ? ? ? ?%s" % inspect.getmodule(Test)) > ? ? print("test.test2's module: ? ?%s" % inspect.getmodule > (test.test2)) > ? ? print("Test.test2's module: ? ?%s" % inspect.getmodule > (Test.test2)) > ? ? print("test.test2's func_name: %s" % test.test2.func_name) > ? ? print("Test.test2's func_name: %s" % Test.test2.func_name) > > if __name__ == "__main__": > ? ? run_tests() > > > > Here is the output that I got in 2.4, 2.5, and 2.6: > > Test is class, test is instance, test2 is method of Test (has > decorator) > test's module: ? ? ? ? ? > Test's module: ? ? ? ? ? > test.test2's module: ? ? > Test.test2's module: ? ? > test.test2's func_name: new_function > Test.test2's func_name: new_function > > If things were working right, then the module for test.test2 would be > the same as the module for test. ?I must be missing something, as the > referenced discussion suggests a simple conclusion. ?Any ideas? > > -eric One work-around I found is the following change in example: test1.py ++++++++++++++++++++++++++++ def decorator(function): def new_function(*args, **kwargs): return function(*args, **kwargs) new_function.__module__ = function.__module__ new_function.__doc__ = function.__doc__ new_function.__name__ = function.__name__ return new_function However, this seems pretty lame. The doctest module should be able to figure out that the docstring belongs is there in the module. -eric From lists at cheimes.de Tue Jun 16 12:31:21 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Jun 2009 18:31:21 +0200 Subject: doctests and decorators In-Reply-To: References: Message-ID: Eric Snow schrieb: > Apparently there is a known issue with doctests, in which tests in > functions using externally defined decorators are ignored. The > recommended fix is to update the order of checks in the _from_module > method of DocTestFinder in the doctest module. The bug and fix are > discussed at the following URLs (and several places in this group): > > http://bugs.python.org/issue1108 > http://mail.python.org/pipermail/python-list/2007-September/627866.html > > The fix implies that the inpect.getmodule function will find the > module of the function object and not of the decorator. However, in > 2.4 the inspect.getmodule function returns the module of the > decorator. I have subsequently tested this in 2.5 and 2.6, and it > also returns the module of the decorator. As such, the fix for > doctests does not work in my tests. Below is the test code that I > used: It's not an issue with the doctest module but with your code. You want to use functools.wraps(). http://docs.python.org/library/functools.html#functools.wraps Christian From esnow at verio.net Tue Jun 16 12:39:16 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 09:39:16 -0700 (PDT) Subject: doctests and decorators References: Message-ID: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> On Jun 16, 10:31?am, Christian Heimes wrote: > Eric Snow schrieb: > > > > > Apparently there is a known issue with doctests, in which tests in > > functions using externally defined decorators are ignored. ?The > > recommended fix is to update the order of checks in the _from_module > > method of DocTestFinder in the doctest module. ?The bug and fix are > > discussed at the following URLs (and several places in this group): > > >http://bugs.python.org/issue1108 > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > The fix implies that the inpect.getmodule function will find the > > module of the function object and not of the decorator. ?However, in > > 2.4 the inspect.getmodule function returns the module of the > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > also returns the module of the decorator. ?As such, the fix for > > doctests does not work in my tests. ?Below is the test code that I > > used: > > It's not an issue with the doctest module but with your code. You want > to use functools.wraps(). > > http://docs.python.org/library/functools.html#functools.wraps > > Christian Unfortunately, I am stuck on 2.4 for now, which does not have the functools. -eric From sjmachin at lexicon.net Tue Jun 16 12:41:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 16 Jun 2009 09:41:03 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: Message-ID: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> On Jun 17, 1:41?am, Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > [snip] > and to me it sounds more like a programming error than an operational > error. How about showing us the code you used and the exact error message and traceback? From deets at nospam.web.de Tue Jun 16 12:48:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Jun 2009 18:48:47 +0200 Subject: ODE, GUI, plotter in Python References: <160620091700027246%shaibani@ymail.com> Message-ID: <79q0h0F1s3d9dU1@mid.uni-berlin.de> > you should take a look at > http://pyode.sourceforge.net/ I think he's talking about "ordinary differential equations". While these are part of physics-simulations (and the ODE-libraries' name might be a PUN), PyODE is not what the OP is after. Diez From Scott.Daniels at Acm.Org Tue Jun 16 12:49:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 09:49:40 -0700 Subject: Input problem In-Reply-To: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: <0rydnXBLEZ8DVqrXnZ2dnUVZ_gudnZ2d@pdx.net> Prasoon wrote: > What is the difference between > > z=int(raw_input()) and z=eval(raw_input())????(I thought them to be > the same in case of integers) Note that you can (and probably should) provide a prompt as an arg to input and raw_input. > I mean when an integer is entered in that case are they same and when > an integer in not entered,in that case how are they different????? In response to an input() call in Python 2.x, you can type sys.exit() Generally it gives your user enough rope to shoot himself in the foot. And here is the code running under 3.0 and 3.1rc2 (release candidate #2) a, b = (int(t) for t in input('Numbers: ').split()) --Scott David Daniels Scott.Daniels at Acm.Org From wiggly at wiggly.org Tue Jun 16 12:50:48 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Tue, 16 Jun 2009 17:50:48 +0100 Subject: cross platform method Re: How to get the total size of a local hard disk? In-Reply-To: <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> Message-ID: <4A37CD68.90708@wiggly.org> Tim Harig wrote: > > This is a joke. Do not take it seriously. I do not actually suggest > anybody use this method to measure the size of their drive. I do not take any > responsibility for any damages incurred by using this method. I will laugh > at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands. > Like most jokes it's not really funny if you have to explain it. But I appreciate that you're worried that anyone who would actually follow the advice would also probably be rabidly litigious even if they were one of those rare-breed of living brain-donors. n From HeinTest at web.de Tue Jun 16 12:51:32 2009 From: HeinTest at web.de (=?ISO-8859-15?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 18:51:32 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37cd94$0$3284$8e6e7893@newsreader.ewetel.de> Richard, thanks a lot for your hint, that was completely new for me. Nagle's optimisation is definitely a good idea in most cases. By the way, do you have an idea how to access the underlying socket to modify the behavier via the setsockopt function to disable Nagle's algorythm in my special case (i need speed for small packets) ? Thanks a lot Hans From lie.1296 at gmail.com Tue Jun 16 12:51:57 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 16:51:57 GMT Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro >> wrote: >> >>> Perl allows just about any printable character as a quote. I tried >>> alternative quotes for many years, and decided making that choice was a >>> waste of brain cells. >>> >>> So no, using alternative quotes does not make things more readable. >> I find it odd that you consider qquoting less scalable than backslashes. > > Backslashes are scalable because they can be nested to any depth, without > having to decide beforehand which quotes to use at which level. And yes, I > do write things like this: Scalable for the computers, not the eye... >> I also find it odd that you dislike two visuals stutters (at the start >> and end of string) so much that you'll put up with a dozen visual >> stutters in the string to avoid them. Particular since my years of >> Perl-bashing lead me to the opposite conclusion. > > I find it odd you should think so. > If found it odd that you think that is more readable and scalable than this: out.write ( ''' function JSString(Str) { var Result = '\"' for (var i = 0; i < Str.length; ++i) { var ThisCh = Str.charAt(i) if (ThisCh == '\\') { ThisCh = '\\\\' } else if (ThisCh == '\"') { ThisCh = '\\\"' } else if (ThisCh == '\t') { ThisCh = '\\t' } else if (ThisCh == '\n') { ThisCh = '\\n' } /*if*/ Result += ThisCh } /*for*/ return Result + '\"' } /*JSString*/ ''' ) I might go even further: out.write ( ''' function JSString(Str) { const dq = '\"' const slash = '\\' var Result = dq for (var i = 0; i < Str.length; ++i) { var ThisCh = Str.charAt(i) if (ThisCh == slash) { ThisCh = slash + slash } else if (ThisCh == dq) { ThisCh = slash + dq } else if (ThisCh == '\t') { ThisCh = slash + 't' } else if (ThisCh == '\n') { ThisCh = slash + 'n' } /*if*/ Result += ThisCh } /*for*/ return Result + dq } /*JSString*/ ''' ) From jholloway7 at gmail.com Tue Jun 16 12:52:43 2009 From: jholloway7 at gmail.com (Joe Holloway) Date: Tue, 16 Jun 2009 11:52:43 -0500 Subject: strptime issue in multi-threaded application Message-ID: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> We recently uplifted our web application to run on Python 2.6.2. We've noticed on a couple occasions that calls into time.strptime have failed with this exception: ImportError: Failed to import _strptime because the import lockis [sic] held by another thread. I poked around the source code enough to realize that this is apparently due to time.strptime using PyImport_ImportModuleNoBlock which potentially raises an ImportError rather than waiting for the "import lock" to be released [1]. This appears to have been introduced as a workaround for other thread safety concerns [2]. Does this indicate that strptime and any other library function that uses the non-blocking import call in this fashion are not thread safe? Is there an idiomatic way of dealing with this error in multi-threaded applications? Like I mentioned, it's only happened on a couple occasions because the right conditions have to be in place, but something doesn't seem right about it. I thought I'd ask on the mailing list before going so far as to open a ticket, but feel free to direct me there if that's the appropriate place for this. Thanks, Joe [1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock [2] http://svn.python.org/view?view=rev&revision=59678 From joncle at googlemail.com Tue Jun 16 13:09:36 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 16 Jun 2009 10:09:36 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: Message-ID: <36eb5d87-fad7-4966-a57b-305f879488d8@z9g2000yqi.googlegroups.com> On Jun 16, 4:41?pm, Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > > " ? ? ? ?OperationalError > > ? ? ? ? ? ? Exception raised for errors that are related to the > ? ? ? ? ? ? database's operation and not necessarily under the control > ? ? ? ? ? ? of the programmer, e.g. an unexpected disconnect occurs, > ? ? ? ? ? ? the data source name is not found, a transaction could not > ? ? ? ? ? ? be processed, a memory allocation error occurred during > ? ? ? ? ? ? processing, etc. ?It must be a subclass of DatabaseError. > > ? ? ? ? ProgrammingError > > ? ? ? ? ? ? Exception raised for programming errors, e.g. table not > ? ? ? ? ? ? found or already exists, syntax error in the SQL > ? ? ? ? ? ? statement, wrong number of parameters specified, etc. ?It > ? ? ? ? ? ? must be a subclass of DatabaseError. > " > > and to me it sounds more like a programming error than an operational > error. > > Thank you, > Gabriel I would agree. With v2.5.2 of Python, I'm getting OperationalError from sqlite3 and ProgrammingError from the psycopg2 (for postgres) library. (Trying to create a table that already exists, trying to 'create tabel' and trying to select from non-existant tables) I don't have time to go through code but looking at http://www.sqlite.org/c3ref/c_abort.html, it would appear that there's enough error results to distinguish between Operational and Programming exceptions. Perhaps result != SQLITE_OK raises OperationalError, or I'm looking at the wrong C spec for the version in various Python versions etc... Or perhaps there's some chosen rationale... or, perhaps, for an embedded engine, no one cares how it failed, it just did... Jon From wuerzner at gmail.com Tue Jun 16 13:11:52 2009 From: wuerzner at gmail.com (kmw) Date: Tue, 16 Jun 2009 10:11:52 -0700 (PDT) Subject: strange behavior with os.system Message-ID: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Hi, I wanted to write a simple script (in 5 minutes or so) which replaces the option '+1' given to the command 'sort' by '-k 2' and than runs 'sort' with the modified argument list. After two hours I am giving up and ask you for help. This is what I tried (please excuse the verbose code, it is due to my various efforts to understand the error): #!/usr/bin/python import sys, os, re arguments = sys.argv[0] for i in sys.argv[1:]: arguments += " " + i p = re.compile ( "(\+(\d+))" ) m = p.search ( arguments ) print type ( m ) m_list = list ( m.groups () ) print type ( m_list ) from1 = str ( m_list[0] ) to1 = "-k " + str ( int ( m_list[1] ) + 1 ) cmd1 = str ( arguments.replace ( from1, to1 ) ) print cmd1 os.system ( cmd1 ) Now, this is what I get (on three different machines with different versions of python): ./sort -F -k 2 -e Traceback (most recent call last): File "./sort", line 9, in m_list = list ( m.groups () ) AttributeError: 'NoneType' object has no attribute 'groups' Please note the unrequested output of ''. The strange thing about this all is the fact that the whole thing works as expected when typed into the interpreter. I would be glad if anyone could help. Best regards, Kay From python at mrabarnett.plus.com Tue Jun 16 13:18:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:18:49 +0100 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: <4A37D3F9.9090503@mrabarnett.plus.com> Joe Holloway wrote: > We recently uplifted our web application to run on Python 2.6.2. > We've noticed on a couple occasions that calls into time.strptime have > failed with this exception: > > ImportError: Failed to import _strptime because the import lockis > [sic] held by another thread. > > I poked around the source code enough to realize that this is > apparently due to time.strptime using PyImport_ImportModuleNoBlock > which potentially raises an ImportError rather than waiting for the > "import lock" to be released [1]. This appears to have been > introduced as a workaround for other thread safety concerns [2]. > > Does this indicate that strptime and any other library function that > uses the non-blocking import call in this fashion are not thread safe? > Is there an idiomatic way of dealing with this error in > multi-threaded applications? > > Like I mentioned, it's only happened on a couple occasions because the > right conditions have to be in place, but something doesn't seem right > about it. I thought I'd ask on the mailing list before going so far > as to open a ticket, but feel free to direct me there if that's the > appropriate place for this. > > Thanks, > Joe > > [1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock > [2] http://svn.python.org/view?view=rev&revision=59678 A simple workaround might be to sleep a short time and then retry. From michele.simionato at gmail.com Tue Jun 16 13:24:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 16 Jun 2009 10:24:39 -0700 (PDT) Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> Message-ID: <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> On Jun 16, 6:39?pm, Eric Snow wrote: > On Jun 16, 10:31?am, Christian Heimes wrote: > > > > > Eric Snow schrieb: > > > > Apparently there is a known issue with doctests, in which tests in > > > functions using externally defined decorators are ignored. ?The > > > recommended fix is to update the order of checks in the _from_module > > > method of DocTestFinder in the doctest module. ?The bug and fix are > > > discussed at the following URLs (and several places in this group): > > > >http://bugs.python.org/issue1108 > > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > > The fix implies that the inpect.getmodule function will find the > > > module of the function object and not of the decorator. ?However, in > > > 2.4 the inspect.getmodule function returns the module of the > > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > > also returns the module of the decorator. ?As such, the fix for > > > doctests does not work in my tests. ?Below is the test code that I > > > used: > > > It's not an issue with the doctest module but with your code. You want > > to use functools.wraps(). > > >http://docs.python.org/library/functools.html#functools.wraps > > > Christian > > Unfortunately, I am stuck on 2.4 for now, which does not have the > functools. > > -eric But you can always use the decorator module: http://pypi.python.org/pypi/decorator From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 13:25:19 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 10:25:19 -0700 (PDT) Subject: how to import a name from a module-path? Message-ID: I'm storing the path to functions in a database and now I'd like to get a reference so I can execute them. I looked briefly at the imp module and got very confused... Currently I'm doing this: def import_object(path): module, obj = path.rsplit('.', 1) exec "from rootpkg.%s import %s as fn" % (module, obj) return fn function = import_object('mypackage.mymodule.myfunction') this is happening in a trusted environment, so I'm not worried about malicious code. Are there more elegant ways of doing this (ie. without exec)? -- bjorn From hypertaos at gmail.com Tue Jun 16 13:27:47 2009 From: hypertaos at gmail.com (Humberto) Date: Tue, 16 Jun 2009 10:27:47 -0700 (PDT) Subject: mac text files & for line Message-ID: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Greetings. This is probably a v. basic question, but my apologies as I'm relatively new w/ this. But I am attempting to use for line to iterate through a text file, but I am working on a Mac and am getting a single block of text. I assume this is because of the Mac {CR} usage vs. line feed. Is there a programmatic way to use for line to interpret the carriage return character as a new line? Otherwise, what are the easiest ways to be able to force a replacement of the {CR} character w/ the line feed? I've attempted the method using tr, but receive an illegal byte sequence error when running the tr '\r' '\n' < file1.txt > file2.txt command on my Mac. Any help would be greatly appreciated and thanks! From python at mrabarnett.plus.com Tue Jun 16 13:29:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:29:17 +0100 Subject: strange behavior with os.system In-Reply-To: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: <4A37D66D.7070001@mrabarnett.plus.com> kmw wrote: > Hi, > > I wanted to write a simple script (in 5 minutes or so) which replaces > the option '+1' given to the command 'sort' by '-k 2' and than runs > 'sort' with the modified argument list. After two hours I am giving up > and ask you for help. This is what I tried (please excuse the verbose > code, it is due to my various efforts to understand the error): > > #!/usr/bin/python > import sys, os, re > arguments = sys.argv[0] > for i in sys.argv[1:]: > arguments += " " + i Shorter: arguments = " ".join(sys.argv) > p = re.compile ( "(\+(\d+))" ) This looks for a "+" followed by digits. > m = p.search ( arguments ) > print type ( m ) > m_list = list ( m.groups () ) > print type ( m_list ) > from1 = str ( m_list[0] ) > to1 = "-k " + str ( int ( m_list[1] ) + 1 ) > cmd1 = str ( arguments.replace ( from1, to1 ) ) > print cmd1 > os.system ( cmd1 ) > > Now, this is what I get (on three different machines with different > versions of python): > > > ./sort -F -k 2 -e No "+"s, so the p.search(arguments) returns None. > > Traceback (most recent call last): > File "./sort", line 9, in > m_list = list ( m.groups () ) > AttributeError: 'NoneType' object has no attribute 'groups' > > Please note the unrequested output of ''. The strange > thing about this all is the fact that the whole thing works as > expected when typed into the interpreter. I would be glad if anyone > could help. > From jeff at jmcneil.net Tue Jun 16 13:33:57 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 16 Jun 2009 10:33:57 -0700 (PDT) Subject: Funny xmlrpc / linux problem References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> <4a37cd94$0$3284$8e6e7893@newsreader.ewetel.de> Message-ID: <63b91f3f-c7c3-4e92-8ff1-a1c1caffae87@r33g2000yqn.googlegroups.com> On Jun 16, 12:51?pm, Hans M?ller wrote: > Richard, > > thanks a lot for your hint, that was completely new for me. > Nagle's optimisation is definitely a good idea in most cases. > > By the way, do you have an idea how to access the underlying socket to modify the behavier > via the setsockopt function to disable Nagle's algorythm in my special case (i need speed for small > packets) ? > > Thanks a lot > > Hans Something like this ought to work. SimpleXMLRPCServer uses SocketServer.TCPServer to handle all of the network-layer stuff. Also, ironically, see http://bugs.python.org/issue6192. import socket from SimpleXMLRPCServer import SimpleXMLRPCServer class MyXMLServer(SimpleXMLRPCServer): def server_bind(self): self.socket.setsockopt( socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) SimpleXMLRPCServer.server_bind(self) s = MyXMLServer(('127.0.0.1', 8080)) print s.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) HTH, Jeff From esnow at verio.net Tue Jun 16 13:36:00 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 10:36:00 -0700 (PDT) Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: On Jun 16, 11:24?am, Michele Simionato wrote: > On Jun 16, 6:39?pm, Eric Snow wrote: > > > > > On Jun 16, 10:31?am, Christian Heimes wrote: > > > > Eric Snow schrieb: > > > > > Apparently there is a known issue with doctests, in which tests in > > > > functions using externally defined decorators are ignored. ?The > > > > recommended fix is to update the order of checks in the _from_module > > > > method of DocTestFinder in the doctest module. ?The bug and fix are > > > > discussed at the following URLs (and several places in this group): > > > > >http://bugs.python.org/issue1108 > > > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > > > The fix implies that the inpect.getmodule function will find the > > > > module of the function object and not of the decorator. ?However, in > > > > 2.4 the inspect.getmodule function returns the module of the > > > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > > > also returns the module of the decorator. ?As such, the fix for > > > > doctests does not work in my tests. ?Below is the test code that I > > > > used: > > > > It's not an issue with the doctest module but with your code. You want > > > to use functools.wraps(). > > > >http://docs.python.org/library/functools.html#functools.wraps > > > > Christian > > > Unfortunately, I am stuck on 2.4 for now, which does not have the > > functools. > > > -eric > > But you can always use the decorator module:http://pypi.python.org/pypi/decorator Thanks to both of you. Very helpful. So in general should decorators always hide themselves? I am guessing not, otherwise this would already be part of their behavior. Still, is it the common case to camouflage the decorator like this? If so, I would expect it to be the default behavior of decorators. -eric From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 13:39:44 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 10:39:44 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> On Jun 15, 6:56?am, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > >> i can traverse a directory using os.listdir() or os.walk(). but if a > >> directory has a very large number of files, these methods produce very > >> large objects talking a lot of memory. > > >> in other languages one can avoid generating such an object by walking a > >> directory as a liked list. for example, in c, perl or php one can use > >> opendir() and then repeatedly readdir() until getting to the end of the > >> file list. it seems this could be more efficient in some applications. > > >> is there a way to do this in python? i'm relatively new to the > >> language. i looked through the documentation and tried googling but > >> came up empty. > > > What kind of directories are those that just a list of files would > > result in a "very large" object? I don't think I have ever seen > > directories with more than a few thousand files... > > You haven't looked very hard :) > > $ pwd > /home/steve/.thumbnails/normal > $ ls | wc -l > 33956 > > And I periodically delete thumbnails, to prevent the number of files > growing to hundreds of thousands. > > Steven Not proud of this, but...: [django] www4:~/datakortet/media$ ls bfpbilder|wc -l 174197 all .jpg files between 40 and 250KB with the path stored in a database field... *sigh* Oddly enough, I'm a relieved that others have had similar folder sizes (I've been waiting for this burst to the top of my list for a while now). Bjorn From python at mrabarnett.plus.com Tue Jun 16 13:39:52 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:39:52 +0100 Subject: mac text files & for line In-Reply-To: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: <4A37D8E8.3050106@mrabarnett.plus.com> Humberto wrote: > Greetings. > > This is probably a v. basic question, but my apologies as I'm > relatively new w/ this. > > But I am attempting to use for line to iterate through a text > file, but I am working on a Mac and am getting a single block of text. > I assume this is because of the Mac {CR} usage vs. line feed. > > Is there a programmatic way to use for line to interpret the carriage > return character as a new line? Otherwise, what are the easiest ways > to be able to force a replacement of the {CR} character w/ the line > feed? I've attempted the method using tr, but receive an > illegal byte sequence error when running the tr '\r' '\n' < file1.txt >> file2.txt command on my Mac. > > Any help would be greatly appreciated and thanks! Open the file with mode 'U' for universal newline support ('\n', '\r' or '\r\n'). From Scott.Daniels at Acm.Org Tue Jun 16 13:42:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 10:42:58 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Dave Angel wrote: > Jorge wrote: >> Hi there, >> I'm making a application that reads 3 party generated ASCII files, >> but some >> times >> the files are corrupted totally or partiality and I need to know if >> it's a >> ASCII file with *nix line terminators. >> In linux I can run the file command but the applications should run in >> windows. >> >> Any help will be great. >> >> Thank you in advance. >> >> > So, which is the assignment: > 1) determine if a file has non-ASCII characters > 2) determine whether the line-endings are crlf or just lf > > In the former case, look at translating the file contents to Unicode, > specifying ASCII as source. If it fails, you have non-ASCII > In the latter case, investigate the 'u' attribute of the mode parameter > in the open() function. > > You also need to ask yourself whether you're doing a validation of the > file, or doing a "best guess" like the file command. > > Also, realize that ASCII is a 7-bit code, with printing characters all greater than space, and very few people use delete ('\x7F'), so you can define a function to determine if a file contains only printing ASCII and a few control characters. This one is False unless some ink would be printed. Python 3.X: def ascii_file(name, controls=b'\t\n'): ctrls = set(controls + b' ') with open(name, 'rb') as f: chars = set(f.read()) return min(chars) >= min(ctrls) ord('~') >= max(chars) ) and min(chars - ctrls) > ord(' ') Python 2.X: def ascii_file(name, controls='\t\n'): ctrls = set(controls + ' ') with open(name, 'rb') as f: chars = set(f.read()) return min(chars) >= min(ctrls) and '~' >= max(chars ) and min(chars - ctrls) > ' ' For potentially more performance (at least on 2.X), you could do min and max on the data read, and only do the set(data) if the min and max are OK. --Scott David Daniels Scott.Daniels at Acm.Org From gherron at islandtraining.com Tue Jun 16 13:43:33 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Jun 2009 10:43:33 -0700 Subject: how to import a name from a module-path? In-Reply-To: References: Message-ID: <4A37D9C5.5060800@islandtraining.com> thebjorn wrote: > I'm storing the path to functions in a database and now I'd like to > get a reference so I can execute them. > > I looked briefly at the imp module and got very confused... Currently > I'm doing this: > > def import_object(path): > module, obj = path.rsplit('.', 1) > exec "from rootpkg.%s import %s as fn" % (module, obj) > return fn > > function = import_object('mypackage.mymodule.myfunction') > > this is happening in a trusted environment, so I'm not worried about > malicious code. > > Are there more elegant ways of doing this (ie. without exec)? > Yes. Look at the __import__ builtin function, and if that's not enough functionality, look at the module names imp, which provides documentation starting with this bit: DESCRIPTION This module provides the components needed to build your own __import__ function. Both are available in Python2.x and Python3.x Gary Herron > -- bjorn > From kyosohma at gmail.com Tue Jun 16 13:58:12 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 16 Jun 2009 10:58:12 -0700 (PDT) Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> On Jun 16, 9:20?am, Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. > > I'm doing a program to load all the ini files in the current folder, > or the folder that the user chooses and list the specifics entries in > it. > > So, the program would be like this: > > Som tabs here like: > ( Load | Edit | Options) > > In the [ Load ] tab: > A folder tree in the left, and two labels or edit boxes showing some > specific entries in the ini file. > > In the [ Edit ] tab: > really straight-forward, Edit boxes of the entries so the user can > edit > > in the [ options ] tab: > More edits to specifie the default folder, etc. > > Basically I will use a lot of edit boxes and some tabs, and a folder > tree, any tips so I can search in the right place? wxPython has all the widgets you've described built into it. They also have a very helpful mailing list. However, you should try the various toolkits and see which one makes the most sense to you. When I was first looking at GUIs, I tried Tkinter first. But it just couldn't replicate the stupid UIs I needed to reimplement, so I went with wxPython. I've heard good things about pyQT. If you want the ultimate look-and-feel for Windows, you should go with IronPython. - Mike From Scott.Daniels at Acm.Org Tue Jun 16 14:09:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 11:09:35 -0700 Subject: doctests and decorators In-Reply-To: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> References: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> Message-ID: Eric Snow wrote: > ... > One work-around I found is the following change in example: > test1.py > ++++++++++++++++++++++++++++ > def decorator(function): > def new_function(*args, **kwargs): > return function(*args, **kwargs) > new_function.__module__ = function.__module__ > new_function.__doc__ = function.__doc__ > new_function.__name__ = function.__name__ > return new_function > > However, this seems pretty lame. The doctest module should be able to > figure out that the docstring belongs is there in the module. would the following look better? import functools ... def decorator(function): @functools.wraps(function) def new_function(*args, **kwargs): return function(*args, **kwargs) return new_function --Scott David Daniels Scott.Daniels at Acm.Org From norseman at hughes.net Tue Jun 16 14:12:14 2009 From: norseman at hughes.net (norseman) Date: Tue, 16 Jun 2009 11:12:14 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A37E07E.60709@hughes.net> Scott David Daniels wrote: > Dave Angel wrote: >> Jorge wrote: >>> Hi there, >>> I'm making a application that reads 3 party generated ASCII files, >>> but some >>> times >>> the files are corrupted totally or partiality and I need to know if >>> it's a >>> ASCII file with *nix line terminators. >>> In linux I can run the file command but the applications should run in >>> windows. you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) combination. If present you have Microsoft compatibility. If not you don't. If you think High Bits might be part of the corruption, filter each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) then check for the \x0D \x0A combination. Run the test on a known text setup. Intel uses one order and the SUN and the internet another. The BIG/Little ending confuses many. Intel reverses the order of multibyte numerics. Thus - Small machine has big ego or largest byte value last. Big Ending. Big machine has small ego. Little Ending. Some coders get the 0D0A backwards, some don't. You might want to test both. (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending Intel stores them (2^8)(2^16)(2^24)(2^32) big ending SUN/Internet stores them in correct math order. Python will use \r\n (0D0A) and \n\r (0A0D) correctly. HTH Steve >>> >>> Any help will be great. >>> >>> Thank you in advance. >>> >>> >> So, which is the assignment: >> 1) determine if a file has non-ASCII characters >> 2) determine whether the line-endings are crlf or just lf >> >> In the former case, look at translating the file contents to Unicode, >> specifying ASCII as source. If it fails, you have non-ASCII >> In the latter case, investigate the 'u' attribute of the mode >> parameter in the open() function. >> >> You also need to ask yourself whether you're doing a validation of the >> file, or doing a "best guess" like the file command. >> >> > Also, realize that ASCII is a 7-bit code, with printing characters all > greater than space, and very few people use delete ('\x7F'), so you > can define a function to determine if a file contains only printing > ASCII and a few control characters. This one is False unless some ink > would be printed. > > Python 3.X: > def ascii_file(name, controls=b'\t\n'): > ctrls = set(controls + b' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) ord('~') >= max(chars) > ) and min(chars - ctrls) > ord(' ') > > Python 2.X: > def ascii_file(name, controls='\t\n'): > ctrls = set(controls + ' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) and '~' >= max(chars > ) and min(chars - ctrls) > ' ' > > For potentially more performance (at least on 2.X), you could do min > and max on the data read, and only do the set(data) if the min and > max are OK. > > --Scott David Daniels > Scott.Daniels at Acm.Org From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 14:19:26 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 11:19:26 -0700 (PDT) Subject: how to import a name from a module-path? References: Message-ID: <0a546aed-c1e8-41fa-be8b-336568ad89d3@m19g2000yqk.googlegroups.com> On Jun 16, 7:43?pm, Gary Herron wrote: > thebjorn wrote: > > I'm storing the path to functions in a database and now I'd like to > > get a reference so I can execute them. > > > I looked briefly at the imp module and got very confused... ?Currently > > I'm doing this: > > > ? def import_object(path): > > ? ? ? module, obj = path.rsplit('.', 1) > > ? ? ? exec "from rootpkg.%s import %s as fn" % (module, obj) > > ? ? ? return fn > > > ? function = import_object('mypackage.mymodule.myfunction') > > > this is happening in a trusted environment, so I'm not worried about > > malicious code. > > > Are there more elegant ways of doing this (ie. without exec)? > > Yes. ?Look at the __import__ builtin function, [...] Thanks, that is much better: def import_object(path): module, obj = path.rsplit('.', 1) m = __import__(module, fromlist=['rootpkg']) return getattr(m, obj) function = import_object('mypackage.mymodule.myfunction') > Gary Herron Bjorn From http Tue Jun 16 14:22:46 2009 From: http (Paul Rubin) Date: 16 Jun 2009 11:22:46 -0700 Subject: Measuring Fractal Dimension ? References: Message-ID: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. I think the idea is you assume uniform continuity of the set (as expressed by a parametrized curve). That should let you approximate the fractal dimension. As for countability, remember that the reals are a separable metric space, so the value of a continuous function any dense subset of the reals (e.g. on the rationals, which are countable) completely determines the function, iirc. From usernet at ilthio.net Tue Jun 16 14:24:21 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 16 Jun 2009 18:24:21 GMT Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: On 2009-06-16, Mike Driscoll wrote: > On Jun 16, 9:20?am, Filipe Teixeira wrote: >> Hi, I'm really struggling to find the best GUI to make a simple >> application. [SNIP] >> Basically I will use a lot of edit boxes and some tabs, and a folder >> tree, any tips so I can search in the right place? > When I was first looking at GUIs, I tried Tkinter first. But it just > ultimate look-and-feel for Windows, you should go with IronPython. IronPython is not a GUI toolkit per se. It is a python implementation build on top of .Net like Jython is built on top of Java. I therefore has access to the MFCs which can be used to create native Windows GUIs. This can also be done from Cpython using the pywin extensions. From chrisspen at gmail.com Tue Jun 16 14:24:51 2009 From: chrisspen at gmail.com (Chris) Date: Tue, 16 Jun 2009 11:24:51 -0700 (PDT) Subject: Python WSDL Support Message-ID: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Is there any modern support for WSDL? The only projects I could find are ZSI and SOAPpy, and both have been dead for several years. From stef.mientki at gmail.com Tue Jun 16 14:27:12 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 20:27:12 +0200 Subject: [ANN] first full alpha release of PyLab_Works v0.3 Message-ID: <4A37E400.4080305@gmail.com> hello, I am pleased to announce the first full alpha release of PyLab_Works, v0.3. PyLab_Works is a modular Visual Development Environment, based on data-flow programming technics. PyLab_Works is specially aimed at Education, Engineering and Science. The ideas behind PyLab_Works are, that the final user should not be burdened with programming details and domain details, whereas the domain expert should be able to implement the specific domain knowledge without being a full educated programmer. You can always find my notes on PyLab_Works on http://pic.flappie.nl Most of these pages are also collected in a single pdf document, which can be found here: http://pylab-works.googlecode.com/files/pw_manual.pdf The source code and a one-button-Windows-Installer can be found on codegoogle: http://code.google.com/p/pylab-works/ The files are rather large, because they contain some data samples. The Windows-Installer contains everything you need to get started with PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. Although the PyLab_Works programs are compiled with Py2Exe, all the source files are explicitly included. have fun, Stef Mientki From python at mrabarnett.plus.com Tue Jun 16 14:35:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 19:35:49 +0100 Subject: Need to know if a file as only ASCII charaters In-Reply-To: <4A37E07E.60709@hughes.net> References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> <4A37E07E.60709@hughes.net> Message-ID: <4A37E605.3040405@mrabarnett.plus.com> norseman wrote: > Scott David Daniels wrote: >> Dave Angel wrote: >>> Jorge wrote: >>>> Hi there, >>>> I'm making a application that reads 3 party generated ASCII files, >>>> but some >>>> times >>>> the files are corrupted totally or partiality and I need to know if >>>> it's a >>>> ASCII file with *nix line terminators. >>>> In linux I can run the file command but the applications should run in >>>> windows. > > you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) > combination. If present you have Microsoft compatibility. If not you > don't. If you think High Bits might be part of the corruption, filter > each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) > then check for the \x0D \x0A combination. > Run the test on a known text setup. Intel uses one order and the SUN and > the internet another. The BIG/Little ending confuses many. Intel > reverses the order of multibyte numerics. Thus - Small machine has big > ego or largest byte value last. Big Ending. Big machine has small ego. > Little Ending. Some coders get the 0D0A backwards, some don't. You > might want to test both. > In an ASCII file endianness is irrelevant. From Scott.Daniels at Acm.Org Tue Jun 16 14:52:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 11:52:01 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: norseman wrote: > Scott David Daniels wrote: >> Dave Angel wrote: >>> Jorge wrote: ... >>>> I'm making a application that reads 3 party generated ASCII files, >>>> but some times the files are corrupted totally or partiality and >>>> I need to know if it's a ASCII file with *nix line terminators. >>>> In linux I can run the file command but the applications should run in >>>> windows. > you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) > combination. If present you have Microsoft compatibility. If not you > don't. If you think High Bits might be part of the corruption, filter > each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) > then check for the \x0D \x0A combination. Well ASCII defines a \x0D as the return code, and \x0A as line feed. It is unix that is wrong, not Microsoft (don't get me wrong, I know Microsoft has often redefined what it likes invalidly). If you open the file with 'U', Python will return lines w/o the \r character whether or not they started with it, equally well on both unix and Microsoft systems. Many moons ago the high order bit was used as a parity bit, but few communication systems do that these days, so anything with the high bit set is likely corruption. > .... Intel uses one order and the SUN and the internet another. The > BIG/Little ending confuses many. Intel reverses the order of multibyte > numerics. Thus- Small machine has big ego or largest byte value last. > Big Ending. Big machine has small ego. > Little Ending. Some coders get the 0D0A backwards, some don't. You > might want to test both. > (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending > Intel stores them (2^8)(2^16)(2^24)(2^32) big ending > SUN/Internet stores them in correct math order. > Python will use \r\n (0D0A) and \n\r (0A0D) correctly. This is the most confused summary of byte sex I've ever read. There is no such thing as "correct math order" (numbers are numbers). The '\n\r' vs. '\r\n' has _nothing_ to do with little-endian vs. big-endian. By the way, there are great arguments for each order, and no clear winner. Network order was defined for sending numbers across a wire, the idea was that you'd unpack them to native order as you pulled the data off the wire. The '\n\r' vs. '\r\n' differences harken back to the days when they were format effectors (carriage return moved the carriage to the extreme left, line feed advanced the paper). You needed both to properly position the print head. ASCII uses the pair, and defined the effect of each. As ASCII was being worked out, MIT even defined a "line starve" character to move up one line just as line feed went down one. The order of the format effectors most used was '\r\n' because the carriage return involved the most physical motion on many devices, and the vertical motion time of the line feed could happen while the carriage was moving. After that, you often added padding bytes (typically ASCII NUL ('\x00') or DEL ('\x7F')) to allow the hardware time to finish before you the did spacing and printing. --Scott David Daniels Scott.Daniels at Acm.Org From ullrich at math.okstate.edu Tue Jun 16 14:57:57 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Tue, 16 Jun 2009 13:57:57 -0500 Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: On 15 Jun 2009 04:55:03 GMT, Steven D'Aprano wrote: >On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > >> On 14 Jun., 16:00, Steven D'Aprano >> wrote: >> >>> Incorrect. Koch's snowflake, for example, has a fractal dimension of >>> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial >>> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the >>> perimeter is infinite, it is countably infinite and computable. >> >> No, the Koch curve is continuous in R^2 and uncountable. > >I think we're talking about different things. The *number of points* in >the Koch curve is uncountably infinite, but that's nothing surprising, >the number of points in the unit interval [0, 1] is uncountably infinite. >But the *length* of the Koch curve is not, it's given by the above limit, >which is countably infinite (it's a rational number for all n). No, the length of the perimeter is infinity, period. Calling it "countably infinite" makes no sense. You're confusing two different sorts of "infinity". A set has a cardinality - "countably infinite" is the smallest infinite cardinality. Limits, as in calculus, as in that limit above, are not cardinailities. > >> Lawrence is >> right and one can trivially cover a countable infinite set with disks of >> the diameter 0, namely by itself. The sum of those diameters to an >> arbitrary power is also 0 and this yields that the Hausdorff dimension >> of any countable set is 0. > >Nevertheless, the Hausdorff dimension (or a close approximation thereof) >can be calculated from the scaling properties of even *finite* objects. >To say that self-similar objects like broccoli or the inner surface of >the human lungs fails to nest at all scales is pedantically correct but >utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good >enough for me. From Scott.Daniels at Acm.Org Tue Jun 16 15:04:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:04:32 -0700 Subject: doctests and decorators In-Reply-To: References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: Eric Snow wrote: > In general should decorators always hide themselves? I am guessing > not, otherwise this would already be part of their behavior. Still, > is it the common case to camouflage the decorator like this? If so, I > would expect it to be the default behavior of decorators. The Python goal is "no magic". So, if you want the stuff wrapped, you do it (as the default traceback shows where the code actually goes). It would be far more complicated to display the truth if decorators defaulted to modifying the builtins, and you had to do magic to remove that part of the decoration. A decorator has _very_ simple semantics, while anything that automatically copied attributes would have funny semantics indeed for use by funny decorators like: abi = [] def indexed(function): result = len(abi) abi.append(function) return result @indexed def first_function(...): ... @indexed def second_function(...): ... --Scott David Daniels Scott.Daniels at Acm.Org From kyosohma at gmail.com Tue Jun 16 15:05:05 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 16 Jun 2009 12:05:05 -0700 (PDT) Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: On Jun 16, 1:24?pm, Tim Harig wrote: > On 2009-06-16, Mike Driscoll wrote: > > > On Jun 16, 9:20?am, Filipe Teixeira wrote: > >> Hi, I'm really struggling to find the best GUI to make a simple > >> application. > [SNIP] > >> Basically I will use a lot of edit boxes and some tabs, and a folder > >> tree, any tips so I can search in the right place? > > When I was first looking at GUIs, I tried Tkinter first. But it just > > ultimate look-and-feel for Windows, you should go with IronPython. > > IronPython is not a GUI toolkit per se. ?It is a python implementation > build on top of .Net like Jython is built on top of Java. ?I therefore has > access to the MFCs which can be used to create native Windows GUIs. ?This > can also be done from Cpython using the pywin extensions. That is true...I was just referring to IronPython's ability to hook a GUI created using Visual Studio easily. Going about it through pywin and ctypes is probably above the OP's current needs...although I think Greg Ewing's pyGUI wraps that stuff. I suppose the OP might find that useful: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ - Mike From Scott.Daniels at Acm.Org Tue Jun 16 15:09:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:09:06 -0700 Subject: strptime issue in multi-threaded application In-Reply-To: References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: MRAB wrote: > Joe Holloway wrote: >> We recently uplifted our web application to run on Python 2.6.2. >> We've noticed on a couple occasions that calls into time.strptime have >> failed with this exception: >> [2] http://svn.python.org/view?view=rev&revision=59678 > > A simple workaround might be to sleep a short time and then retry. Can you just import and use time.strptime once before you start the threads? --Scott David Daniels Scott.Daniels at Acm.Org From rlnewman at ucsd.edu Tue Jun 16 15:13:58 2009 From: rlnewman at ucsd.edu (Rob Newman) Date: Tue, 16 Jun 2009 12:13:58 -0700 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes Message-ID: Hi All, I am new to Python, and have a very specific task to accomplish. I have a command line shell script that takes two arguments: create_graphs.sh -v --sta=STANAME where STANAME is a string 4 characters long. create_graphs creates a series of graphs using Matlab (among other 3rd party packages). Right now I can run this happily by hand, but I have to manually execute the command for each STANAME. What I want is to have a Python script that I pass a list of STANAMEs to, and it acts like a daemon and spawns as many child processes as there are processors on my server (64), until it goes through all the STANAMES (about 200). I posted a message on Stack Overflow (ref: http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro) and was recommended to use the multiprocessing and subprocess packages. In the Stack Overflow answers, it was suggested that I use the process pool class in multiprocessing. However, the server I have to use is a Sun Sparc (T5220, Sun OS 5.10) and there is a known issue with sem_open() (ref: http://bugs.python.org/issue3770), so it appears I cannot use the process pool class. So, below is my script (controller.py) that I have attempted to use as a test, that just calls the 'ls' command on a file I know exists rather than firing off my shell script (which takes ~ 10 mins to run per STANAME): #!/path/to/python import sys import os import json import multiprocessing import subprocess def work(verbose,staname): print 'function:',staname print 'parent process:', os.getppid() print 'process id:', os.getpid() print "ls /path/to/file/"+staname+"_info.pf" # cmd will eventually get replaced with the shell script with the verbose and staname options cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] return subprocess.call(cmd, shell=False) if __name__ == '__main__': report_sta_list = ['B10A','B11A','BNLO'] # Print out the complete station list for testing print report_sta_list # Get the number of processors available num_processes = multiprocessing.cpu_count() print 'Number of processes: %s' % (num_processes) print 'Now trying to assign all the processors' threads = [] len_stas = len(report_sta_list) print "+++ Number of stations to process: %s" % (len_stas) # run until all the threads are done, and there is no data left while len(threads) < len(report_sta_list): # if we aren't using all the processors AND there is still data left to # compute, then spawn another thread print "+++ Starting to set off all child processes" if( len(threads) < num_processes ): this_sta = report_sta_list.pop() print "+++ Station is %s" % (this_sta) p = multiprocessing.Process(target=work,args=['v',this_sta]) p.start() print p, p.is_alive() threads.append(p) else: for thread in threads: if not thread.is_alive(): threads.remove(thread) However, I seem to be running into a whole series of errors: myhost{rt}62% controller.py ['B10A', 'B11A', 'BNLO'] Number of processes: 64 Now trying to assign all the processors +++ Number of stations to process: 3 +++ Starting to set off all child processes +++ Station is BNLO True +++ Starting to set off all child processes +++ Station is B11A function: BNLO parent process: 22341 process id: 22354 ls /path/to/file/BNLO_info.pf True function: B11A parent process: 22341 process id: 22355 ls /path/to/file/B11A_info.pf Process Process-1: Traceback (most recent call last): File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in _bootstrap self.run() File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "controller.py", line 104, in work return subprocess.call(cmd, shell=False) File "/opt/csw/lib/python/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ errread, errwrite) File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory Process Process-2: Traceback (most recent call last): File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in _bootstrap self.run() File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "controller.py", line 104, in work return subprocess.call(cmd, shell=False) File "/opt/csw/lib/python/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ errread, errwrite) File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory The files are there: mhost{me}11% ls -la /path/to/files/BNLO_info.pf -rw-rw-r-- 1 me group 391 May 19 22:40 /path/to/files/ BNLO_info.pf myhost{me}12% ls -la /path/to/file/B11A_info.pf -rw-rw-r-- 1 me group 391 May 19 22:27 /path/to/files/ B11A_info.pf I might be doing this completely wrong, but I thought this would be the way to list the files dynamically. Admittedly this is just a stepping stone to running the actual shell script I want to run. Can anyone point me in the right direction or offer any advice for using these packages? Thanks in advance for any help or insight. - Rob From Scott.Daniels at Acm.Org Tue Jun 16 15:19:02 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:19:02 -0700 Subject: mac text files & for line In-Reply-To: References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: MRAB wrote: > Humberto wrote: >> But I am attempting to use for line to iterate through a text >> file, but I am working on a Mac and am getting a single block of text. >> I assume this is because of the Mac {CR} usage vs. line feed. >> >> Is there a programmatic way to use for line to interpret the carriage >> return character as a new line? Otherwise, what are the easiest ways >> to be able to force a replacement of the {CR} character w/ the line >> feed? I've attempted the method using tr, but receive an >> illegal byte sequence error when running the tr '\r' '\n' < file1.txt >>> file2.txt command on my Mac. Read http://www.catb.org/~esr/faqs/smart-questions.html Show code, inputs, and output and explain what you expected. This could be one of dozens of problems. > Open the file with mode 'U' for universal newline support ('\n', '\r' or > '\r\n'). A good guess of what might be going wrong. Another could be using read. --Scott David Daniels Scott.Daniels at Acm.Org From aahz at pythoncraft.com Tue Jun 16 15:33:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 16 Jun 2009 12:33:33 -0700 Subject: Please advise me for a right solution References: <15b1e25c-2bb4-425e-974f-be3d686b5931@p21g2000prn.googlegroups.com> Message-ID: In article <15b1e25c-2bb4-425e-974f-be3d686b5931 at p21g2000prn.googlegroups.com>, VP wrote: > >I need to create a web based inventory tool with specific requirements >such as: > >* More then one group is going to use it. >* Authentication and authorization system based on user and group >privileges. > >For example based on a group privileges group can add/edit/delete >their own stuff and having a read only access to other groups stuff. Maybe this would help? http://code.google.com/p/django-inventory/ I do think you should plan on using a framework of some kind, to handle the authentication system at least. -- 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 Scott.Daniels at Acm.Org Tue Jun 16 15:38:52 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:38:52 -0700 Subject: ImageEnhance.Contrast - is this fishy or what? In-Reply-To: References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> Message-ID: <-OadnW9hvbHbbqrXnZ2dnUVZ_s-dnZ2d@pdx.net> Scott David Daniels wrote: > roop wrote: >> I was browsing ImageEnhace.py, and found something that I thought was >> odd in class Contrast: >> >> class Contrast(_Enhance): >> "Adjust image contrast" >> >> > ... > Good catch [I'll send a copy to the imaging sig]. If you replace class > ... Over on image-sig, Fredrik Lundh responded: > And the award for finding the oldest bug in PIL goes to... (that code > was last touched in 1996). > > I've checked in a last-second fix for 1.1.7 (to be frozen any day soon > now, promise). > > Thanks /F Congrats, roop, on getting this discovered just in the nick of time. The code he uses is: class Contrast(_Enhance): "Adjust image contrast" def __init__(self, image): self.image = image mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5) self.degenerate = Image.new("L", image.size, mean).convert(image.mode) --Scott David Daniels Scott.Daniels at Acm.Org From aahz at pythoncraft.com Tue Jun 16 15:44:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 16 Jun 2009 12:44:10 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> Message-ID: In article <8f093893-310a-4f0f-9e67-61393c234299 at f38g2000pra.googlegroups.com>, Aaron Watters wrote: > >This is the best book ever written on computer science >and the first edition is free. > >http://www.math.upenn.edu/~wilf/AlgComp3.html Thanks! -- 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 HellZFury+Python at gmail.com Tue Jun 16 15:47:37 2009 From: HellZFury+Python at gmail.com (Matt) Date: Tue, 16 Jun 2009 15:47:37 -0400 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes In-Reply-To: References: Message-ID: Try replacing: cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] with: cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] Basically, the first is the conceptual equivalent of executing the following in BASH: ?ls /path/to/file/FOO_info.pf? The second is this: ?ls? ?/path/to/file/FOO_info.pf? The first searches for a command in your PATH named ?ls /path...?. The second searches for a command names ?ls? and gives it the argument ?/path...? Also, I think this is cleaner (but it?s up to personal preference): cmd = [ "ls", "/path/to/file/%s_info.pf" % staname] ________________________ ~Matthew Strax-Haber Northeastern University, CCIS & CBA Co-op, NASA Langley Research Center Student Government Association, Special Interest Senator Resident Student Association, SGA Rep & General Councilor Chess Club, Treasurer E-mail: strax-haber.m=AT=neu.edu On Tue, Jun 16, 2009 at 3:13 PM, Rob Newman wrote: > Hi All, > > I am new to Python, and have a very specific task to accomplish. I have a > command line shell script that takes two arguments: > > create_graphs.sh -v --sta=STANAME > > where STANAME is a string 4 characters long. > > create_graphs creates a series of graphs using Matlab (among other 3rd party > packages). > > Right now I can run this happily by hand, but I have to manually execute the > command for each STANAME. What I want is to have a Python script that I pass > a list of STANAMEs to, and it acts like a daemon and spawns as many child > processes as there are processors on my server (64), until it goes through > all the STANAMES (about 200). > > I posted a message on Stack Overflow (ref: > http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro)?and > was recommended to use the multiprocessing and subprocess packages. In the > Stack Overflow answers, it was suggested that I use the process pool class > in multiprocessing. However, the server I have to use is a Sun Sparc (T5220, > Sun OS 5.10) and there is a known issue with sem_open() (ref: > http://bugs.python.org/issue3770), so it appears I cannot use the process > pool class. > > So, below is my script (controller.py) that I have attempted to use as a > test, that just calls the 'ls' command on a file I know exists rather than > firing off my shell script (which takes ~ 10 mins to run per STANAME): > > #!/path/to/python > > import sys > import os > import json > import multiprocessing > import subprocess > > def work(verbose,staname): > ?print 'function:',staname > ?print 'parent process:', os.getppid() > ?print 'process id:', os.getpid() > ?print "ls /path/to/file/"+staname+"_info.pf" > ?# cmd will eventually get replaced with the shell script with the verbose > and staname options > ?cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > ?return subprocess.call(cmd, shell=False) > > if __name__ == '__main__': > > ?report_sta_list = ['B10A','B11A','BNLO'] > > ?# Print out the complete station list for testing > ?print report_sta_list > > ?# Get the number of processors available > ?num_processes = multiprocessing.cpu_count() > > ?print 'Number of processes: %s' % (num_processes) > > ?print 'Now trying to assign all the processors' > > ?threads = [] > > ?len_stas = len(report_sta_list) > > ?print "+++ Number of stations to process: %s" % (len_stas) > > ?# run until all the threads are done, and there is no data left > ?while len(threads) < len(report_sta_list): > > ? ?# if we aren't using all the processors AND there is still data left to > ? ?# compute, then spawn another thread > > ? ?print "+++ Starting to set off all child processes" > > ? ?if( len(threads) < num_processes ): > > ? ? ?this_sta = report_sta_list.pop() > > ? ? ?print "+++ Station is %s" % (this_sta) > > ? ? ?p = multiprocessing.Process(target=work,args=['v',this_sta]) > > ? ? ?p.start() > > ? ? ?print p, p.is_alive() > > ? ? ?threads.append(p) > > ? ?else: > > ? ? ?for thread in threads: > > ? ? ? ?if not thread.is_alive(): > > ? ? ? ? ?threads.remove(thread) > > However, I seem to be running into a whole series of errors: > > myhost{rt}62% controller.py > ['B10A', 'B11A', 'BNLO'] > Number of processes: 64 > Now trying to assign all the processors > +++ Number of stations to process: 3 > +++ Starting to set off all child processes > +++ Station is BNLO > True > +++ Starting to set off all child processes > +++ Station is B11A > function: BNLO > parent process: 22341 > process id: 22354 > ls /path/to/file/BNLO_info.pf > True > function: B11A > parent process: 22341 > process id: 22355 > ls /path/to/file/B11A_info.pf > Process Process-1: > Traceback (most recent call last): > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in > _bootstrap > ? ?self.run() > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run > ? ?self._target(*self._args, **self._kwargs) > ?File "controller.py", line 104, in work > ? ?return subprocess.call(cmd, shell=False) > ?File "/opt/csw/lib/python/subprocess.py", line 444, in call > ? ?return Popen(*popenargs, **kwargs).wait() > ?File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ > ? ?errread, errwrite) > ?File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child > ? ?raise child_exception > OSError: [Errno 2] No such file or directory > Process Process-2: > Traceback (most recent call last): > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in > _bootstrap > ? ?self.run() > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run > ? ?self._target(*self._args, **self._kwargs) > ?File "controller.py", line 104, in work > ? ?return subprocess.call(cmd, shell=False) > ?File "/opt/csw/lib/python/subprocess.py", line 444, in call > ? ?return Popen(*popenargs, **kwargs).wait() > ?File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ > ? ?errread, errwrite) > ?File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child > ? ?raise child_exception > OSError: [Errno 2] No such file or directory > > The files are there: > > mhost{me}11% ls -la /path/to/files/BNLO_info.pf > -rw-rw-r-- ? 1 me ? ? ? group ? ? 391 May 19 22:40 > /path/to/files/BNLO_info.pf > myhost{me}12% ls -la /path/to/file/B11A_info.pf > -rw-rw-r-- ? 1 me ? ? ? group ? ? 391 May 19 22:27 > /path/to/files/B11A_info.pf > > I might be doing this completely wrong, but I thought this would be the way > to list the files dynamically. Admittedly this is just a stepping stone to > running the actual shell script I want to run. Can anyone point me in the > right direction or offer any advice for using these packages? > > Thanks in advance for any help or insight. > - Rob > -- > http://mail.python.org/mailman/listinfo/python-list > From piet at cs.uu.nl Tue Jun 16 15:47:42 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 21:47:42 +0200 Subject: Input problem References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: >>>>> Prasoon (P) wrote: >P> What is the difference between >P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >P> the same in case of integers) >P> I mean when an integer is entered in that case are they same and when >P> an integer in not entered,in that case how are they different????? >>> z=eval(raw_input()) 3+4 >>> z 7 >>> z=int(raw_input()) 3+4 Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '3+4' -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 15:51:57 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 21:51:57 +0200 Subject: PSP Text Editor References: Message-ID: >>>>> Johnson Mpeirwe (JM) wrote: >JM> Hi all, >JM> Does anyone know of any good Python Server Pages text editor that can >JM> provide indentation, syntax highlighting, etc.. A text editor in a web context doesn't run on the server but in the browser. Therefore it should use client-side scripting (which probably means Javascript or flash (shudder!)) Including that in a PSP web page isn't so much different from its inclusion in any other framework. You must just choose one of the existing editors. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 16:07:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 22:07:17 +0200 Subject: PSP Text Editor References: Message-ID: Reading your question again I think I have probably misunderstood it. You want to an editor to edit Python Server Pages? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 16:16:56 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 22:16:56 +0200 Subject: strange behavior with os.system References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: >>>>> kmw (k) wrote: >k> Hi, >k> I wanted to write a simple script (in 5 minutes or so) which replaces >k> the option '+1' given to the command 'sort' by '-k 2' and than runs >k> 'sort' with the modified argument list. After two hours I am giving up >k> and ask you for help. This is what I tried (please excuse the verbose >k> code, it is due to my various efforts to understand the error): [snip] >k> Please note the unrequested output of ''. The strange >k> thing about this all is the fact that the whole thing works as >k> expected when typed into the interpreter. I would be glad if anyone >k> could help. MRAB has already given you some insight, I hope. But are you aware that you are calling your own program again? Or did you want to call the standard sort program? In that case you shouldn't call ./sort as it is in argv[0], but just sort (assuming '.' is not in your PATH) or the full path, like /usr/bin/sort. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From arnodel at googlemail.com Tue Jun 16 16:22:12 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Jun 2009 21:22:12 +0100 Subject: Tool for browsing python code References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: "D'Arcy J.M. Cain" writes: > On Tue, 16 Jun 2009 18:25:00 +0530 > Banibrata Dutta wrote: >> not sure if there are any "curses" base TUI's (!) for Python. > > vi emacs :) -- Arnaud From lie.1296 at gmail.com Tue Jun 16 16:27:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 20:27:06 GMT Subject: mac text files & for line In-Reply-To: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: Humberto wrote: > Greetings. > > This is probably a v. basic question, but my apologies as I'm > relatively new w/ this. > > But I am attempting to use for line to iterate through a text > file, but I am working on a Mac and am getting a single block of text. > I assume this is because of the Mac {CR} usage vs. line feed. > > Is there a programmatic way to use for line to interpret the carriage > return character as a new line? Otherwise, what are the easiest ways > to be able to force a replacement of the {CR} character w/ the line > feed? I've attempted the method using tr, but receive an > illegal byte sequence error when running the tr '\r' '\n' < file1.txt >> file2.txt command on my Mac. > > Any help would be greatly appreciated and thanks! I guess this is how you write your code: f = open('myfile.txt', 'r').read() for line in f: print line # stream of characters... if that's the case, change the code into: f = open('myfile.txt', 'r') for line in f: print line If you .read() the file yourself, you'll get a single string of the whole file content; '\n' (of whatever real type) inside a string is not used as delimiter for a for-loop. From nick at craig-wood.com Tue Jun 16 16:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 16 Jun 2009 15:29:33 -0500 Subject: waling a directory with very many files References: Message-ID: Nick Craig-Wood wrote: > Jean-Paul Calderone wrote: > > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: > > >Hrvoje Niksic wrote: > > >> Nick Craig-Wood writes: > > >> > > >> > Here is a ctypes generator listdir for unix-like OSes. > > >> > > >> ctypes code scares me with its duplication of the contents of system > > >> headers. I understand its use as a proof of concept, or for hacks one > > >> needs right now, but can anyone seriously propose using this kind of > > >> code in a Python program? For example, this seems much more > > >> "Linux-only", or possibly even "32-bit-Linux-only", than > > >> "unix-like": > > > > > >It was a proof of concept certainly.. Just in case anyone is interested here is an implementation using cython. Compile with python setup.py build_ext --inplace And run listdir.py This would have been much easier if cython supported yield, but unfortunately it doesn't (yet - I think it is in the works). This really should work on any platform! --setup.py---------------------------------------------------------- from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( cmdclass = {'build_ext': build_ext}, ext_modules = [Extension("directory", ["directory.pyx"])] ) --directory.pyx---------------------------------------------------------- # Cython interface for listdir # python setup.py build_ext --inplace import cython cdef extern from "dirent.h": struct dirent: char d_name[0] struct dir_handle: pass ctypedef dir_handle DIR "DIR" DIR *opendir(char *name) int closedir(DIR *dirp) dirent *readdir(DIR *dirp) cdef class Directory: """Represents an open directory""" cdef DIR *handle def __init__(self, path): self.handle = opendir(path) def readdir(self): cdef dirent *p p = readdir(self.handle) if p is NULL: return None return p.d_name def close(self): closedir(self.handle) --listdir.py---------------------------------------------------------- from directory import Directory def listdir(path): """ A generator to return the names of files in the directory passed in """ d = Directory(".") while True: name = d.readdir() if not name: break if name not in (".", ".."): yield name d.close() if __name__ == "__main__": for name in listdir("."): print name ------------------------------------------------------------ -- Nick Craig-Wood -- http://www.craig-wood.com/nick From hypertaos at gmail.com Tue Jun 16 16:31:56 2009 From: hypertaos at gmail.com (Humberto) Date: Tue, 16 Jun 2009 13:31:56 -0700 (PDT) Subject: mac text files & for line References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: On Jun 16, 1:39?pm, MRAB wrote: > Humberto wrote: > > Greetings. > > > This is probably a v. basic question, but my apologies as I'm > > relatively new w/ this. > > > But I am attempting to use for line to iterate through a text > > file, but I am working on a Mac and am getting a single block of text. > > I assume this is because of the Mac {CR} usage vs. line feed. > > > Is there a programmatic way to use for line to interpret the carriage > > return character as a new line? Otherwise, what are the easiest ways > > to be able to force a replacement of the {CR} character w/ the line > > feed? I've attempted the method using tr, but receive an > > illegal byte sequence error when running the tr '\r' '\n' < file1.txt > >> file2.txt command on my Mac. > > > Any help would be greatly appreciated and thanks! > > Open the file with mode 'U' for universal newline support ('\n', '\r' or > '\r\n'). Precisely my problem. Thanks so much. I'd overlooked the references to U in the entry for the open function. To the other fellow, I think the question was reasonably specific in the second paragraph...I sense the helpful response bore that out. I certainly acknowledge my mistake in having overlooked the reference in the documentation. So my apologies for any inconvenience and thanks again. From darcy at druid.net Tue Jun 16 16:38:21 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 16 Jun 2009 16:38:21 -0400 Subject: Tool for browsing python code In-Reply-To: References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: <20090616163821.c3c9d48d.darcy@druid.net> On Tue, 16 Jun 2009 21:22:12 +0100 Arnaud Delobelle wrote: > "D'Arcy J.M. Cain" writes: > >> not sure if there are any "curses" base TUI's (!) for Python. > > vi > > emacs :) Hey, it was all pretty civil up till now. ;) -- 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 lie.1296 at gmail.com Tue Jun 16 16:50:25 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 20:50:25 GMT Subject: Input problem In-Reply-To: References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: Piet van Oostrum wrote: >>>>>> Prasoon (P) wrote: > >> P> What is the difference between >> P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >> P> the same in case of integers) > >> P> I mean when an integer is entered in that case are they same and when >> P> an integer in not entered,in that case how are they different????? >>> z=eval(raw_input()) # or z = input() in py-2 import subprocess; subprocess.Popen(['killuser', 'now', '-j20', '-O3']) eocaioewurf4fcrejcomefvweracv >>> _ From mrstevegross at gmail.com Tue Jun 16 16:54:01 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 16 Jun 2009 13:54:01 -0700 (PDT) Subject: Guidance on initialization code in a module Message-ID: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Is there a common way to initialize various stuff in a module? That is, I have some code in my module that I want to run whenever the module is imported. Currently, my module looks like this: === foo.py === def something(): ... def somethingelse(): ... something() === EOF === Is the 'something()' line at the end in an ok location? I just put it at the end. Maybe there's some special __init__() mechanism for modules? Or should I use the 'if __name__ != '__main__'' trick? Thanks, --Steve From waldemar.osuch at gmail.com Tue Jun 16 16:57:53 2009 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Tue, 16 Jun 2009 13:57:53 -0700 (PDT) Subject: Python WSDL Support References: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Message-ID: <38dbd285-b55e-4577-8bb4-698253c100b0@l12g2000yqo.googlegroups.com> On Jun 16, 12:24?pm, Chris wrote: > Is there any modern support for WSDL? The only projects I could find > are ZSI and SOAPpy, and both have been dead for several years. https://fedorahosted.org/suds/ is actively maintained From piet at cs.uu.nl Tue Jun 16 17:02:23 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:02:23 +0200 Subject: Python WSDL Support References: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Message-ID: >>>>> Chris (C) wrote: >C> Is there any modern support for WSDL? The only projects I could find >C> are ZSI and SOAPpy, and both have been dead for several years. That is not necessarily bad. But for the client side there is also suds (https://fedorahosted.org/suds/). And you may also look for soaplib (http://trac.optio.webfactional.com/) but it is probably also `dead'. There is a fork soaplib-lxml, however, that is being actively developed. SOAP is not very popular in the Python world, I think. SOAP is a mammoth and that fits better in the Java and Microsoft worlds :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From songkai.sk at gmail.com Tue Jun 16 17:02:40 2009 From: songkai.sk at gmail.com (kai) Date: Tue, 16 Jun 2009 14:02:40 -0700 (PDT) Subject: Build problem on Solaris 9 References: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> <4a374695$0$11163$9b622d9e@news.freenet.de> Message-ID: On Jun 16, 12:15?am, "Martin v. L?wis" wrote: > > When I run make after successively running ./configure, I got the > > following Error message: > > ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl > > /usr/bin/env: No such file or directory > > make: *** [Python/Python-ast.c] Error 127 Thank you so much!!! It compiles now. Kai > > > /usr/bin/env deos exist.... > > > Can anyone help me with this? > > It's probably rather that "python" does not exist on the path, > which asdl_c.py requires. > > touch Include/Python-ast.h Python/Python-ast.c > > should work around. > > Regards, > Martin From rlnewman at ucsd.edu Tue Jun 16 17:11:00 2009 From: rlnewman at ucsd.edu (Rob Newman) Date: Tue, 16 Jun 2009 14:11:00 -0700 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes In-Reply-To: References: Message-ID: Thanks Matt - that worked. Kind regards, - Rob On Jun 16, 2009, at 12:47 PM, Matt wrote: > Try replacing: > cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > with: > cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] > > Basically, the first is the conceptual equivalent of executing the > following in BASH: > ?ls /path/to/file/FOO_info.pf? > The second is this: > ?ls? ?/path/to/file/FOO_info.pf? > > The first searches for a command in your PATH named ?ls /path...?. The > second searches for a command names ?ls? and gives it the argument > ?/path...? > > Also, I think this is cleaner (but it?s up to personal preference): > cmd = [ "ls", "/path/to/file/%s_info.pf" % staname] > > ________________________ > ~Matthew Strax-Haber > Northeastern University, CCIS & CBA > Co-op, NASA Langley Research Center > Student Government Association, Special Interest Senator > Resident Student Association, SGA Rep & General Councilor > Chess Club, Treasurer > E-mail: strax-haber.m=AT=neu.edu > > On Tue, Jun 16, 2009 at 3:13 PM, Rob Newman wrote: >> Hi All, >> >> I am new to Python, and have a very specific task to accomplish. I >> have a >> command line shell script that takes two arguments: >> >> create_graphs.sh -v --sta=STANAME >> >> where STANAME is a string 4 characters long. >> >> create_graphs creates a series of graphs using Matlab (among other >> 3rd party >> packages). >> >> Right now I can run this happily by hand, but I have to manually >> execute the >> command for each STANAME. What I want is to have a Python script >> that I pass >> a list of STANAMEs to, and it acts like a daemon and spawns as many >> child >> processes as there are processors on my server (64), until it goes >> through >> all the STANAMES (about 200). >> >> I posted a message on Stack Overflow (ref: >> http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro) >> and >> was recommended to use the multiprocessing and subprocess packages. >> In the >> Stack Overflow answers, it was suggested that I use the process >> pool class >> in multiprocessing. However, the server I have to use is a Sun >> Sparc (T5220, >> Sun OS 5.10) and there is a known issue with sem_open() (ref: >> http://bugs.python.org/issue3770), so it appears I cannot use the >> process >> pool class. >> >> So, below is my script (controller.py) that I have attempted to use >> as a >> test, that just calls the 'ls' command on a file I know exists >> rather than >> firing off my shell script (which takes ~ 10 mins to run per >> STANAME): >> >> #!/path/to/python >> >> import sys >> import os >> import json >> import multiprocessing >> import subprocess >> >> def work(verbose,staname): >> print 'function:',staname >> print 'parent process:', os.getppid() >> print 'process id:', os.getpid() >> print "ls /path/to/file/"+staname+"_info.pf" >> # cmd will eventually get replaced with the shell script with the >> verbose >> and staname options >> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] >> return subprocess.call(cmd, shell=False) >> >> if __name__ == '__main__': >> >> report_sta_list = ['B10A','B11A','BNLO'] >> >> # Print out the complete station list for testing >> print report_sta_list >> >> # Get the number of processors available >> num_processes = multiprocessing.cpu_count() >> >> print 'Number of processes: %s' % (num_processes) >> >> print 'Now trying to assign all the processors' >> >> threads = [] >> >> len_stas = len(report_sta_list) >> >> print "+++ Number of stations to process: %s" % (len_stas) >> >> # run until all the threads are done, and there is no data left >> while len(threads) < len(report_sta_list): >> >> # if we aren't using all the processors AND there is still data >> left to >> # compute, then spawn another thread >> >> print "+++ Starting to set off all child processes" >> >> if( len(threads) < num_processes ): >> >> this_sta = report_sta_list.pop() >> >> print "+++ Station is %s" % (this_sta) >> >> p = multiprocessing.Process(target=work,args=['v',this_sta]) >> >> p.start() >> >> print p, p.is_alive() >> >> threads.append(p) >> >> else: >> >> for thread in threads: >> >> if not thread.is_alive(): >> >> threads.remove(thread) >> >> However, I seem to be running into a whole series of errors: >> >> myhost{rt}62% controller.py >> ['B10A', 'B11A', 'BNLO'] >> Number of processes: 64 >> Now trying to assign all the processors >> +++ Number of stations to process: 3 >> +++ Starting to set off all child processes >> +++ Station is BNLO >> True >> +++ Starting to set off all child processes >> +++ Station is B11A >> function: BNLO >> parent process: 22341 >> process id: 22354 >> ls /path/to/file/BNLO_info.pf >> True >> function: B11A >> parent process: 22341 >> process id: 22355 >> ls /path/to/file/B11A_info.pf >> Process Process-1: >> Traceback (most recent call last): >> File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in >> _bootstrap >> self.run() >> File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in >> run >> self._target(*self._args, **self._kwargs) >> File "controller.py", line 104, in work >> return subprocess.call(cmd, shell=False) >> File "/opt/csw/lib/python/subprocess.py", line 444, in call >> return Popen(*popenargs, **kwargs).wait() >> File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ >> errread, errwrite) >> File "/opt/csw/lib/python/subprocess.py", line 1092, in >> _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> Process Process-2: >> Traceback (most recent call last): >> File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in >> _bootstrap >> self.run() >> File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in >> run >> self._target(*self._args, **self._kwargs) >> File "controller.py", line 104, in work >> return subprocess.call(cmd, shell=False) >> File "/opt/csw/lib/python/subprocess.py", line 444, in call >> return Popen(*popenargs, **kwargs).wait() >> File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ >> errread, errwrite) >> File "/opt/csw/lib/python/subprocess.py", line 1092, in >> _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> >> The files are there: >> >> mhost{me}11% ls -la /path/to/files/BNLO_info.pf >> -rw-rw-r-- 1 me group 391 May 19 22:40 >> /path/to/files/BNLO_info.pf >> myhost{me}12% ls -la /path/to/file/B11A_info.pf >> -rw-rw-r-- 1 me group 391 May 19 22:27 >> /path/to/files/B11A_info.pf >> >> I might be doing this completely wrong, but I thought this would be >> the way >> to list the files dynamically. Admittedly this is just a stepping >> stone to >> running the actual shell script I want to run. Can anyone point me >> in the >> right direction or offer any advice for using these packages? >> >> Thanks in advance for any help or insight. >> - Rob From lenz at joinville.udesc.br Tue Jun 16 17:12:10 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 16 Jun 2009 14:12:10 -0700 Subject: ODE, GUI, plotter in Python In-Reply-To: <160620091700027246%shaibani@ymail.com> References: <160620091700027246%shaibani@ymail.com> Message-ID: <200906161412.11404.lenz@joinville.udesc.br> Em Ter 16 Jun 2009, ?s 09:00:02, Ala escreveu: > Hello everyone. > > I am starting on implementing a simulator using python, and since it's > the first time I code in python would appreciate a few pointers: > > The simulator will use a coupled ODE for the most part of the > simulation, I plan to use scipy. (Anything considered faster/better > than scipy for solving coupled ODEs? ) > > I plan for a GUI program with network graph plotting. I am leaning > towards using Qt for the GUI (internet forums seem to recommend it, > anyone got other preferences? ) > > Since the GUI application will contain few buttons and a plot, I am > planning to implement matplotlib into the GUI. But does anyone know if > matplotlib allows for interaction with the graph plot? (say for a > network simulation, allowing to right click on nodes and disable them > for instance, or alter some other properties of nodes and/or links > across them). > > I am just starting out, hence I'd rather get some advice and experiment > a bit for my self as I go along. > > Thank you. you should take a look at http://pyode.sourceforge.net/ and pygame. []'s Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From lists at cheimes.de Tue Jun 16 17:19:53 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Jun 2009 23:19:53 +0200 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: Joe Holloway schrieb: > We recently uplifted our web application to run on Python 2.6.2. > We've noticed on a couple occasions that calls into time.strptime have > failed with this exception: > > ImportError: Failed to import _strptime because the import lockis > [sic] held by another thread. The error message is my fault. The cause of the mistake is obvious: PyErr_Format(PyExc_ImportError, "Failed to import %.200s because the import lock" "is held by another thread.", name); > I poked around the source code enough to realize that this is > apparently due to time.strptime using PyImport_ImportModuleNoBlock > which potentially raises an ImportError rather than waiting for the > "import lock" to be released [1]. This appears to have been > introduced as a workaround for other thread safety concerns [2]. Without PyImport_ImportModuleNoBlock() your application would block forever. > Does this indicate that strptime and any other library function that > uses the non-blocking import call in this fashion are not thread safe? > Is there an idiomatic way of dealing with this error in > multi-threaded applications? It's not a matter of thread safety per se. I've added the function to work around a dead lock situation. Python allows you to import a module in a subthread but the entire import system is protected by a lock. > Like I mentioned, it's only happened on a couple occasions because the > right conditions have to be in place, but something doesn't seem right > about it. I thought I'd ask on the mailing list before going so far > as to open a ticket, but feel free to direct me there if that's the > appropriate place for this. I have an idea what might happen in your application. Is an import triggering the start of a thread? You can get around the issue by decoupling imports from thread startups. Your application should import all modules before it starts its threaded components. For now you can decrease the severity of your issue by placing "import _strptime" next to "import time" somewhere in your code. Once it a module is loaded PyImport_ImportModuleNoBlock() will not fail to import it a second time. Christian From piet at cs.uu.nl Tue Jun 16 17:20:05 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:20:05 +0200 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes References: Message-ID: >>>>> Matt (M) wrote: >M> Try replacing: >M> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] >M> with: >M> cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] In addition I would like to remark that -- if the only thing you want to do is to start up a new command with subprocess.Popen -- the use of the multiprocessing package is overkill. You could use threads as well. Moreover, if you don't expect any output from these processes and don't supply input to them through pipes there isn't even a need for these threads. You could just use os.wait() to wait for a child to finish and then start a new process if necessary. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From hobesh at gmail.com Tue Jun 16 17:36:05 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 14:36:05 -0700 Subject: Executing a python script while it is running Message-ID: Hi everybody, Here's my situation: I have a batch file that calls a python script. This batch file is triggered by an outside application when the application completes a task. The problem is that while the batch file (and pythons script) is running, the application will complete the next task, and try to call the batch file again (while it is already running) Hopefully that's not too confusing. I'm not sure what direction to go with this, any help or nudges in the RIGHT direction would be greatly appreciated. From piet at cs.uu.nl Tue Jun 16 17:39:03 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:39:03 +0200 Subject: Input problem References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: >>>>> Lie Ryan (LR) wrote: >LR> Piet van Oostrum wrote: >>>>>>>> Prasoon (P) wrote: >>> >P> What is the difference between >P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >P> the same in case of integers) >>> >P> I mean when an integer is entered in that case are they same and when >P> an integer in not entered,in that case how are they different????? >>>>> z=eval(raw_input()) # or z = input() in py-2 >LR> import subprocess; subprocess.Popen(['killuser', 'now', '-j20', '-O3']) >LR> eocaioewurf4fcrejcomefvweracv >>>>> _ SyntaxError: invalid syntax eval will not accept statements like import, only expressions. But as Scott David Daniels already had mentioned you can shoot yourself in the foot easily with input() or eval() if you can't trust the input. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From gherron at islandtraining.com Tue Jun 16 17:47:02 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Jun 2009 14:47:02 -0700 Subject: Executing a python script while it is running In-Reply-To: References: Message-ID: <4A3812D6.7000507@islandtraining.com> Zach Hobesh wrote: > Hi everybody, > > Here's my situation: > > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. > > I'm not sure what direction to go with this, any help or nudges in the > RIGHT direction would be greatly appreciated. > You haven't defined a problem. It's perfectly fine for two (or more) processes to be running the same script at the same time. Unless, of course, the script is doing something which should not be run in duplicate. But then, you'll have to tell us what *that* is, and why it's a problem. Then we'll have some problem for which we can ponder a solution. From invalid at invalid Tue Jun 16 17:53:09 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 16 Jun 2009 16:53:09 -0500 Subject: Executing a python script while it is running References: Message-ID: On 2009-06-16, Zach Hobesh wrote: > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. No, though you haven't explained why that's a problem. > I'm not sure what direction to go with this, any help or > nudges in the RIGHT direction would be greatly appreciated. First, you have to explain what your problem is. -- Grant Edwards grante Yow! It's a hole all the at way to downtown Burbank! visi.com From Scott.Daniels at Acm.Org Tue Jun 16 18:05:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 15:05:06 -0700 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ... > > def somethingelse(): > ... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Seems fine there. I'd add a comment like: something() #initialize the frambus so the whatzies are set up. Perhaps I'd choose better names :-) --Scott David Daniels Scott.Daniels at Acm.Org From fetchinson at googlemail.com Tue Jun 16 18:15:06 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 16 Jun 2009 15:15:06 -0700 Subject: Tool for browsing python code In-Reply-To: <20090616163821.c3c9d48d.darcy@druid.net> References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> <20090616163821.c3c9d48d.darcy@druid.net> Message-ID: >> "D'Arcy J.M. Cain" writes: >> >> not sure if there are any "curses" base TUI's (!) for Python. >> > vi >> >> emacs :) > > Hey, it was all pretty civil up till now. ;) I've heard from my cousin that his former high school classmate's uncle did a research on a large statistical sample of programmers and found that emacs users' brains are about 12% smaller than vi users' :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Tue Jun 16 18:31:44 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 18:31:44 -0400 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: <4A381D50.1010406@ieee.org> mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ... > > def somethingelse(): > ... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Maybe there's some special __init__() mechanism for > modules? Or should I use the 'if __name__ != '__main__'' trick? > > Thanks, > --Steve > > You're doing fine. Everything in the module is run when it's imported. Running a definition, of course, compiles it, and adds its name to the module's namespace. But anything outside of a definition or class, or other qualifier will just be run. If the module will never be used as a script, the if __name__ == logic isn't needed. If you want this initialization code to be run *only* if it's not being run as a script, then you'd do as you suggest, if __name__ != "__main__" But usually, the initialization code wants to be run whether it's being used as a script, or as a library module. So leave the conditional off, till you actually decide what behavior should be conditional. From dstanek at dstanek.com Tue Jun 16 18:40:44 2009 From: dstanek at dstanek.com (David Stanek) Date: Tue, 16 Jun 2009 18:40:44 -0400 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: On Tue, Jun 16, 2009 at 4:54 PM, mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ?... > > def somethingelse(): > ?... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Maybe there's some special __init__() mechanism for > modules? Or should I use the 'if __name__ != '__main__'' trick? > I think what you are doing is fine. The only thing that I would do differently is rename 'something' to 'initialize'. That way your intent is really obvious. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From davea at ieee.org Tue Jun 16 18:42:06 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 18:42:06 -0400 Subject: Executing a python script while it is running In-Reply-To: References: Message-ID: <4A381FBE.9040003@ieee.org> Zach Hobesh wrote: > Hi everybody, > > Here's my situation: > > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. > > I'm not sure what direction to go with this, any help or nudges in the > RIGHT direction would be greatly appreciated. > > A lot more information would be useful. What version of Python, and what operating system environment? Exactly what would you like to happen when the batch file is invoked a second time? Possibilities that occur to me: 1) ignore the second run 2) let them both run as separate processes 3) abort the first run, as the second one will replace it 4) queue something to be processed when the first run finishes What provisions does this existing application have for long-running batch files? Seems the synchronization ought to happen there. Do you have any constraints on how long your script might take, worst case? What if the application finishes its tasks at a faster average rate than your script can process them? From hobesh at gmail.com Tue Jun 16 18:48:56 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 15:48:56 -0700 Subject: Executing a python script while it is running In-Reply-To: <4A381FBE.9040003@ieee.org> References: <4A381FBE.9040003@ieee.org> Message-ID: > A lot more information would be useful. ?What version of Python, and what > operating system environment? ?Exactly what would you like to happen when > the batch file is invoked a second time? I'm running Python 2.6.2 on Windows. I'm passing filenames to the batch files and I need all filenames to be processed. I can't have any fails. I'm working on logging any fails I do have so that I can maybe batch process at the end of the day. > ?2) let them both run as separate processes This sounds like a good option, but I'm not totally sure on how to go about this? > ?4) queue something to be processed when the first run finishes I had the same idea, but I believe it would involve having another python script run all day long, which wouldn't necessarily be a bad thing, but I'd like to explore other options as well. > What provisions does this existing application have for long-running batch > files? ?Seems the synchronization ought to happen there. ?Do you have any > constraints on how long your script might take, worst case? ?What if the > application finishes its tasks at a faster average rate than your script can > process them? The batch file is moving large video files. Duration probably ranges from 10 sec to 45 mins. On average, the application takes longer to process the files than it does the batch file/python script takes to copy them, but I'm concerned about the occasional time that the application finishes a small file right after finishing a large file. Thanks for your response! -Zach From norseman at hughes.net Tue Jun 16 19:07:06 2009 From: norseman at hughes.net (norseman) Date: Tue, 16 Jun 2009 16:07:06 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A38259A.6010406@hughes.net> Scott David Daniels wrote: > norseman wrote: >> Scott David Daniels wrote: >>> Dave Angel wrote: >>>> Jorge wrote: ... >>>>> I'm making a application that reads 3 party generated ASCII files, >>>>> but some times the files are corrupted totally or partiality and I >>>>> need to know if it's a ASCII file with *nix line terminators. >>>>> In linux I can run the file command but the applications should run in >>>>> windows. >> you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) >> combination. If present you have Microsoft compatibility. If not you >> don't. If you think High Bits might be part of the corruption, filter >> each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) >> then check for the \x0D \x0A combination. > > Well ASCII defines a \x0D as the return code, and \x0A as line feed. > It is unix that is wrong, not Microsoft (don't get me wrong, I know > Microsoft has often redefined what it likes invalidly). If you > open the file with 'U', Python will return lines w/o the \r character > whether or not they started with it, equally well on both unix and > Microsoft systems. Yep - but if you are on Microsoft systems you will usually need the \r. Remove them and open the file in Notepad to see what I mean. Wordpad handles the lack of \r OK. Handles larger files too. > Many moons ago the high order bit was used as a > parity bit, but few communication systems do that these days, so > anything with the high bit set is likely corruption. > OH? How did one transfer binary files over the phone? I used PIP or Kermit and it got there just fine, high bits and all. Mail and other so called "text only" programs CAN (but not necessarily do) use 7bit transfer protocols. Can we say MIME? FTP transfers high bit just fine too. Set protocols to 8,1 and none. (8bit, 1 stop, no parity) As to how his 3rd party ASCII files are generated? He does not know, I do not know, we do not know (or care), so test before use. Filter out the high bits, remove all control characters except cr,lf and perhaps keep the ff too, then test what's left. ASCII cr - carriage return ^M x0D \r lf - line feed ^J x0A \n ff - form feed (new page) ^L x0C \f >> .... Intel uses one order and the SUN and the internet another. The > > BIG/Little ending confuses many. Intel reverses the order of multibyte > > numerics. Thus- Small machine has big ego or largest byte value last. > > Big Ending. Big machine has small ego. >> Little Ending. Some coders get the 0D0A backwards, some don't. You >> might want to test both. >> (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending >> Intel stores them (2^8)(2^16)(2^24)(2^32) big ending >> SUN/Internet stores them in correct math order. >> Python will use \r\n (0D0A) and \n\r (0A0D) correctly. > > This is the most confused summary of byte sex I've ever read. > There is no such thing as "correct math order" (numbers are numbers). "...number are numbers..." Nope! Numbers represented as characters may be in ASCII but you should take a look at at IBM mainframes. They use EBCDIC and the 'numbers' are different bit patterns. Has anyone taken the time to read the IEEE floating point specs? To an electronic calculating machine, internally everything is a bit. Bytes are a group of bits and the CPU structure determines what a given bit pattern is. The computer has no notion of number, character or program instruction. It only knows what it is told. Try this - set the next instruction (jump) to a data value and watch the machine try to execute it as a program instruction. (I assume you can program in assembly. If not - don't tell because 'REAL programmers do assembly'. I think the last time I used it was 1980 or so. The program ran until the last of the hardware died and replacements could not be found. The client hired another to write for the new machines and closed shop shortly after. I think the owner was tired and found an excuse to retire. :) > The '\n\r' vs. '\r\n' has _nothing_ to do with little-endian vs. > big-endian. By the way, there are great arguments for each order, > and no clear winner. I don't care. Not the point. Point is some people get it fouled up and cause others problems. Test for both. You will save yourself a great deal of trouble in the long run. > Network order was defined for sending numbers > across a wire, the idea was that you'd unpack them to native order > as you pulled the data off the wire. "... sending BINARY FORMATTED numbers..." (verses character - type'able) Network order was defined to reduce machine time. Since the servers that worked day in and day out were SUN, SUN order won. I haven't used EBCDIC in so long I really don't remember for sure but it seems to me they used SUN order before SUN was around. Same for the VAX, I think. > > The '\n\r' vs. '\r\n' differences harken back to the days when they were > format effectors (carriage return moved the carriage to the extreme > left, line feed advanced the paper). You needed both to properly > position the print head. Yep. There wasn't enough intelligence in the old printers to 'cook" the stream. > ASCII uses the pair, and defined the effect > of each. Actually the Teletype people defined most of the \x00 - \x1f concepts. If I remember the trivia correctly - original teletype was 6 bit bytes. Bit pattern was neither ASCII nor EBCDIC. Both of those adopted the teletype control-character concept. > As ASCII was being worked out, MIT even defined a "line > starve" character to move up one line just as line feed went down one. > The order of the format effectors most used was '\r\n' because the > carriage return involved the most physical motion on many devices, and > the vertical motion time of the line feed could happen while the > carriage was moving. True. My experiment with reversing the two instructions would sometimes cause the printer to malfunction. One of my first 'black boxes' (filters) included instructions to see and correct the "wrong" pattern. Then I had to modify it to allow pure binary to get 'pictures' on the dot matrix types. > After that, you often added padding bytes > (typically ASCII NUL ('\x00') or DEL ('\x7F')) to allow the hardware > time to finish before you the did spacing and printing. > If I remember correctly: ASCII NULL x00 In my opinion, NULL should be none set :) IBM NULL x80 IBM card 80 Cols Sperry-Rand x90 S/R Card 90 Cols Trivia question: Why is a byte 8 bits? Ans: people have 10 fingers and the hardware to handle morse code (single wire - serial transfers) needed timers. 1-start, 8 data, 1-stop makes it a count by ten. Burroughs had 10 bits but counting by 12s just didn't come 'naturally'. That was the best answer I've heard to date. In reality - who knows? '...padding...' I never did. Never had to. Printers I used had enough buffer to void that practice. Thirty two character buffer seemed to be enough to disallow overflow. Of course we were using 300 to 1200 BAUD and DTR (pin 19 in most cases) -OR- the RTS and CTS pair of wires to control flow since ^S/^Q could be a valid dot matrix byte(s). Same for hardwired PIP or Kermit transfers. > --Scott David Daniels > Scott.Daniels at Acm.Org > From tjreedy at udel.edu Tue Jun 16 20:02:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Jun 2009 20:02:31 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> Message-ID: John Machin wrote: >> Yes, I forgot that >> Exception TypeError: "'NoneType' object is not callable" in ignored >> >> should be parsed as >> >> '''Exception TypeError: "'NoneType' object is not callable" in''' [was] >> ignored >> >> rather than read as >> >> Exception TypeError: "'NoneType' object is not callable" in ignored > > Yep, it's not the clearest message I've ever seen, and it gives no > clue as to who or what is doing the ignoring. Here's a suggestion for > your enhancement request: > > Shutdown ignored this exception: TypeError: "'NoneType' object is not > callable" http://bugs.python.org/issue6294 From davea at ieee.org Tue Jun 16 20:06:30 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 20:06:30 -0400 Subject: Executing a python script while it is running In-Reply-To: References: <4A381FBE.9040003@ieee.org> Message-ID: <4A383386.10409@ieee.org> Zach Hobesh wrote: >> A lot more information would be useful. What version of Python, and what >> operating system environment? Exactly what would you like to happen when >> the batch file is invoked a second time? >> > > I'm running Python 2.6.2 on Windows. I'm passing filenames to the > batch files and I need all filenames to be processed. I can't have > any fails. I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > > >> 2) let them both run as separate processes >> > > This sounds like a good option, but I'm not totally sure on how to go > about this? > > >> 4) queue something to be processed when the first run finishes >> > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. > > >> What provisions does this existing application have for long-running batch >> files? Seems the synchronization ought to happen there. Do you have any >> constraints on how long your script might take, worst case? What if the >> application finishes its tasks at a faster average rate than your script can >> process them? >> > > The batch file is moving large video files. Duration probably ranges > from 10 sec to 45 mins. On average, the application takes longer to > process the files than it does the batch file/python script takes to > copy them, but I'm concerned about the occasional time that the > application finishes a small file right after finishing a large file. > > Thanks for your response! > > -Zach > > Option 2 is what you get by default. Naturally it depends on what the application is using to launch the batch file, but the most common cases will launch a separate process. That means most of python will work fine; the only likely conflict you'll have is if one script is trying to move or copy the same file the other one is doing. So I'd suggest you do a rename (which I believe is atomic on all the platforms) of the source file, then do the move. Notice that if the destination is on the same physical volume, you can just "rename" it directly to the final location, at least on Windows. Such a rename is essentially instantaneous, regardless of file size. For option 4, you could just have the batch file launch a script that moves the file locally into a standard place, then the all-day-long (background) script will actually do the slow move on any file it spots in the special directory. If you need more information, you could add also create a text file that identifies the other parameters to go with the file. In any case, the background script would poll the directory for work to do, do it, then check again. Any time the poll fails, just sleep for 30 seconds or so. From mdaglow at daglowconsulting.com Tue Jun 16 20:21:49 2009 From: mdaglow at daglowconsulting.com (Marta Daglow) Date: Tue, 16 Jun 2009 20:21:49 -0400 Subject: Looking for top web engineers In-Reply-To: References: Message-ID: Hi, One of my clients is looking for three top web developers (engineers) to build a new video platform from scratch. Wouldn't it be nice to build this system without having to work with legacy code or systems? They are part of a major organization and have deep funding. We're looking for someone who is team player and who loves to work with other very smart engineers. Top pay, benefits and cool SF Bay Area location. Are you interested or know of someone who would be? If you would like to know more, please email me and we can set up a time to talk. Kind Regards, Marta Daglow | Managing Partner - HR Consulting Daglow Consulting Group | 415.461.5845 mdaglow at daglowconsulting.com Recruit - Retain - Inspire From Eric_Dexter at msn.com Tue Jun 16 20:56:34 2009 From: Eric_Dexter at msn.com (edexter) Date: Tue, 16 Jun 2009 17:56:34 -0700 (PDT) Subject: first full alpha release of PyLab_Works v0.3 References: Message-ID: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> On Jun 16, 12:27?pm, Stef Mientki wrote: > hello, > > I am pleased to announce the first full alpha release of PyLab_Works, v0.3. > > PyLab_Works is a modular Visual Development Environment, based on > data-flow programming technics. PyLab_Works is specially aimed at > Education, Engineering and Science. The ideas behind PyLab_Works are, > that the final user should not be burdened with programming details and > domain details, whereas the domain expert should be able to implement > the specific ?domain knowledge without being a full educated programmer. > > You can always find my notes on PyLab_Works on > ? ?http://pic.flappie.nl > Most of these pages are also collected in a single pdf document, which > can be found here: > ?http://pylab-works.googlecode.com/files/pw_manual.pdf > > The source code and a one-button-Windows-Installer can be found on > codegoogle: > ?http://code.google.com/p/pylab-works/ > The files are rather large, because they contain some data samples. > The Windows-Installer contains everything you need to get started with > PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, ? > Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, > Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. > Although the PyLab_Works programs are compiled with Py2Exe, all the > source files are explicitly included. > > have fun, > Stef Mientki program didn't start because .dll is missing (sorry I don't have the name)... I don't know if that is just an issue with the installer with vista or not (missing msv something 71. dll) From hobesh at gmail.com Tue Jun 16 21:21:56 2009 From: hobesh at gmail.com (hobesh at gmail.com) Date: Wed, 17 Jun 2009 01:21:56 +0000 Subject: Executing a python script while it is running In-Reply-To: <4A383386.10409@ieee.org> Message-ID: <001636456fe6019056046c811e8c@google.com> Hey Dave, Thanks for the helpful responses. > Option 2 is what you get by default. Naturally it depends on what the > application is using to launch the batch file, but the most common cases > will launch a separate process. The app ended up delaying starting the second batch file until it finished the first. I had the app trigger an infinite loop on completion, and sent two files through at the same time. The second file finished seconds after the first, but the batch file didn't trigger until I closed the first one. > For option 4, you could just have the batch file launch a script that > moves the file locally into a standard place, then the all-day-long > (background) script will actually do the slow move on any file it spots > in the special directory. If you need more information, you could add > also create a text file that identifies the other parameters to go with > the file. In any case, the background script would poll the directory for > work to do, do it, then check again. Any time the poll fails, just sleep > for 30 seconds or so. I just tried a simple test with this basic outline, and it seemed to work fine. I had the app write a batch file and throw that batch file into the special directory. The background script grabbed the batch files and ran them in order of time created. Still not sure what the best option is. I'm not sure what will happen if I just let the app regulate itself, so I may go with option 4. Thanks again! -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jun 16 21:37:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Jun 2009 18:37:53 -0700 Subject: Executing a python script while it is running In-Reply-To: <001636456fe6019056046c811e8c@google.com> References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> Message-ID: <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> On Tue, Jun 16, 2009 at 6:21 PM, wrote: > Hey Dave, > > Thanks for the helpful responses. > >> Option 2 is what you get by default. ?Naturally it depends on what the >> application ?is using to launch the batch file, but the most common cases >> will launch a separate process. > > The app ended up delaying starting the second batch file until it finished > the first. I had the app trigger an infinite loop on completion, and sent > two files through at the same time. The second file finished seconds after > the first, but the batch file didn't trigger until I closed the first one. Are you sure you aren't unknowingly having the app wait on the first batch file process until it terminates? How exactly are you launching the batch files? Cheers, Chris -- http://blog.rebertia.com From alan.isaac at gmail.com Tue Jun 16 21:50:55 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 01:50:55 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> On 6/13/2009 2:11 PM kj apparently wrote: > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a[[3,7,1,-1]] array([3, 7, 1, 9]) hth, Alan Isaac From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:14:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:14:34 GMT Subject: Perl's @foo[3,7,1,-1] ? References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> Message-ID: On Wed, 17 Jun 2009 01:50:55 +0000, Alan G Isaac wrote: > On 6/13/2009 2:11 PM kj apparently wrote: >> Switching from Perl here, and having a hard time letting go... >> >> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >> second, and last element in that array. In Perl I could write: >> >> my @wanted = @foo[3, 7, 1, -1]; > >>>> a = np.arange(10) >>>> a > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>>> a[[3,7,1,-1]] > array([3, 7, 1, 9]) > > hth, > Alan Isaac What's np.arange? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:20:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:20:27 GMT Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: On Tue, 16 Jun 2009 12:04:32 -0700, Scott David Daniels wrote: > Eric Snow wrote: >> In general should decorators always hide themselves? I am guessing >> not, otherwise this would already be part of their behavior. Still, is >> it the common case to camouflage the decorator like this? If so, I >> would expect it to be the default behavior of decorators. > > The Python goal is "no magic". So, if you want the stuff wrapped, you > do it (as the default traceback shows where the code actually goes). It > would be far more complicated to display the truth if decorators > defaulted to modifying the builtins, and you had to do magic to remove > that part of the decoration. I'm afraid I can't understand what you're saying. What do you consider "magic"? What's a "default traceback"? What do you mean, "display the truth"? > A decorator has _very_ simple semantics, > while anything that automatically copied attributes would have funny > semantics indeed for use by funny decorators like: [...] functools.wraps() automatically copies attributes: >>> import functools >>> def dec(func): ... @functools.wraps(func) ... def inner(*args): ... return func(args) + 1 ... return inner ... >>> def f(x): ... return 1 ... >>> f.attr = "Attribute" >>> f = dec(f) >>> f(3) 2 >>> f.attr 'Attribute' -- Steven From Nikolaus at rath.org Tue Jun 16 22:22:31 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Tue, 16 Jun 2009 22:22:31 -0400 Subject: Logging multiple lines Message-ID: <87tz2fa9aw.fsf@vostro.rath.org> Hi, Are there any best practices for handling multi-line log messages? For example, the program, main = logging.getLogger() handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) main.addHandler(handler) main.setLevel(logging.DEBUG) main.info("Starting") try: bla = 42/0 except: main.exception("Oops...") generates the log messages 2009-06-16 22:19:57,515 INFO Starting 2009-06-16 22:19:57,518 ERROR Oops... Traceback (most recent call last): File "/home/nikratio/lib/EclipseWorkspace/playground/src/mytests.py", line 27, in bla = 42/0 ZeroDivisionError: integer division or modulo by zero which are a mess in any logfile because they make it really difficult to parse. How do you usually handle multi-line messages? Do you avoid them completely (and therefore also the exception logging facilities provided by logging)? Or is it possible to tweak the formatter so that it inserts the prefix at the beginning of every line? Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From mk.fraggod at gmail.com Tue Jun 16 22:33:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 08:33:55 +0600 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes References: Message-ID: <20090617083355.37db565a@malediction> On Tue, 16 Jun 2009 23:20:05 +0200 Piet van Oostrum wrote: > >>>>> Matt (M) wrote: > > >M> Try replacing: > >M> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > >M> with: > >M> cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] > > In addition I would like to remark that -- if the only thing you want > to do is to start up a new command with subprocess.Popen -- the use > of the multiprocessing package is overkill. You could use threads as > well. > > Moreover, if you don't expect any output from these processes and > don't supply input to them through pipes there isn't even a need for > these threads. You could just use os.wait() to wait for a child to > finish and then start a new process if necessary. And even if there is need to read/write data from/to the pipes more than once (aka communicate), using threads or any more python subprocesses seem like hammering a nail with sledgehammer - just _read_ or _write_ to pipes asynchronously. -- Mike Kazantsev // fraggod.net From lie.1296 at gmail.com Tue Jun 16 22:49:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 02:49:06 GMT Subject: Executing a python script while it is running In-Reply-To: References: <4A381FBE.9040003@ieee.org> Message-ID: Zach Hobesh wrote: >> A lot more information would be useful. What version of Python, and what >> operating system environment? Exactly what would you like to happen when >> the batch file is invoked a second time? > > I'm running Python 2.6.2 on Windows. I'm passing filenames to the > batch files and I need all filenames to be processed. I can't have > any fails. I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > >> 2) let them both run as separate processes > > This sounds like a good option, but I'm not totally sure on how to go > about this? For that one, you don't really have to do anything special as long as both program doesn't try to modify the same file at the same time. If the two program need to modify the same file, you need to arrange some coordination, the specifics of which highly depends on what you're trying to do. >> 4) queue something to be processed when the first run finishes > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. You don't necessarily have to have daemon process, cron/scheduled task can do it as well. 5) detect for another process; if there is, sleep until the it terminates, then do the job. If there is a good possibility of 3 or more process, it might be necessary to use a lock file, if the lock file exists, sleep, else create a lock file and do the job. >> What provisions does this existing application have for long-running batch >> files? Seems the synchronization ought to happen there. Do you have any >> constraints on how long your script might take, worst case? What if the >> application finishes its tasks at a faster average rate than your script can >> process them? > > The batch file is moving large video files. Duration probably ranges > from 10 sec to 45 mins. On average, the application takes longer to > process the files than it does the batch file/python script takes to > copy them, but I'm concerned about the occasional time that the > application finishes a small file right after finishing a large file. > > Thanks for your response! > > -Zach From ldo at geek-central.gen.new_zealand Tue Jun 16 22:50:28 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 14:50:28 +1200 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > Lawrence D'Oliveiro writes: > >> I don't think any countable set, even a countably-infinite set, can have >> a fractal dimension. It's got to be uncountably infinite, and therefore >> uncomputable. > > I think the idea is you assume uniform continuity of the set (as > expressed by a parametrized curve). That should let you approximate > the fractal dimension. Fractals are, by definition, not uniform in that sense. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:51:23 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:51:23 GMT Subject: Need to know if a file as only ASCII charaters References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: On Tue, 16 Jun 2009 10:42:58 -0700, Scott David Daniels wrote: > Dave Angel wrote: >> Jorge wrote: >>> Hi there, >>> I'm making a application that reads 3 party generated ASCII files, >>> but some >>> times >>> the files are corrupted totally or partiality and I need to know if >>> it's a >>> ASCII file with *nix line terminators. In linux I can run the file >>> command but the applications should run in windows. >>> >>> Any help will be great. >>> >>> Thank you in advance. >>> >>> >> So, which is the assignment: >> 1) determine if a file has non-ASCII characters 2) determine whether >> the line-endings are crlf or just lf >> >> In the former case, look at translating the file contents to Unicode, >> specifying ASCII as source. If it fails, you have non-ASCII In the >> latter case, investigate the 'u' attribute of the mode parameter in the >> open() function. >> >> You also need to ask yourself whether you're doing a validation of the >> file, or doing a "best guess" like the file command. >> >> > Also, realize that ASCII is a 7-bit code, with printing characters all > greater than space, and very few people use delete ('\x7F'), so you can > define a function to determine if a file contains only printing ASCII > and a few control characters. This one is False unless some ink would > be printed. > > Python 3.X: > def ascii_file(name, controls=b'\t\n'): > ctrls = set(controls + b' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) ord('~') >= max(chars) > ) and min(chars - ctrls) > ord(' ') > > Python 2.X: > def ascii_file(name, controls='\t\n'): > ctrls = set(controls + ' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) and '~' >= max(chars > ) and min(chars - ctrls) > ' ' > > For potentially more performance (at least on 2.X), you could do min and > max on the data read, and only do the set(data) if the min and max are > OK. You're suggesting that running through the entire data three times instead of once is an optimization? Boy, I'd hate to see what you consider a pessimation! *wink* I think the best solution will probably be a lazy function which stops processing as soon as it hits a character that isn't ASCII. # Python 2.5, and untested def ascii_file(name): from string import printable with open(name, 'rb') as f: for c in f.read(1): if c not in printable: return False return True This only reads the entire file if it needs to, and only walks the data once if it is ASCII. In practice, you may actually get better performance by reading in a block at a time, rather than a byte at a time: # Python 2.5, and still untested def ascii_file(name, bs=65536): # 64K default blocksize from string import printable with open(name, 'rb') as f: text = f.read(bs) while text: for c in text: if c not in printable: return False text = f.read(bs) return True -- Steven From ldo at geek-central.gen.new_zealand Tue Jun 16 22:52:28 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 14:52:28 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> Message-ID: In message <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, thebjorn wrote: > Not proud of this, but...: > > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l > 174197 > > all .jpg files between 40 and 250KB with the path stored in a database > field... *sigh* Why not put the images themselves into database fields? > Oddly enough, I'm a relieved that others have had similar folder sizes ... One of my past projects had 400000-odd files in a single folder. They were movie frames, to allow assembly of movie sequences on demand. From wolfgang at rohdewald.de Tue Jun 16 23:13:11 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Jun 2009 05:13:11 +0200 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <200906170513.11804.wolfgang@rohdewald.de> On Wednesday, 17. June 2009, Steven D'Aprano wrote: > while text: > for c in text: > if c not in printable: return False that is one loop per character. wouldn't it be faster to apply a regex to text? something like while text: if re.search(r'\W',text): return False -- Wolfgang From mk.fraggod at gmail.com Tue Jun 16 23:18:58 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 09:18:58 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> Message-ID: <20090617091858.432f89ca@malediction> On Wed, 17 Jun 2009 14:52:28 +1200 Lawrence D'Oliveiro wrote: > In message > <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, > thebjorn wrote: > > > Not proud of this, but...: > > > > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l > > 174197 > > > > all .jpg files between 40 and 250KB with the path stored in a > > database field... *sigh* > > Why not put the images themselves into database fields? > > > Oddly enough, I'm a relieved that others have had similar folder > > sizes ... > > One of my past projects had 400000-odd files in a single folder. They > were movie frames, to allow assembly of movie sequences on demand. For both scenarios: Why not use hex representation of md5/sha1-hashed id as a path, arranging them like /path/f/9/e/95ea4926a4 ? That way, you won't have to deal with many-files-in-path problem, and, since there's thousands of them anyway, name readability shouldn't matter. In fact, on modern filesystems it doesn't matter whether you accessing /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea with only hundred of them in each path. Former case (all-in-one-path) would even outperform the latter with ext3 or reiserfs by a small margin. Sadly, that's not the case with filesystems like FreeBSD ufs2 (at least in sixth branch), so it's better to play safe and create subdirs if the app might be run on different machines than keeping everything in one path. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From mk.fraggod at gmail.com Tue Jun 16 23:24:13 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 09:24:13 +0600 Subject: Logging multiple lines References: <87tz2fa9aw.fsf@vostro.rath.org> Message-ID: <20090617092413.7da4f164@malediction> On Tue, 16 Jun 2009 22:22:31 -0400 Nikolaus Rath wrote: > How do you usually handle multi-line messages? Do you avoid them > completely (and therefore also the exception logging facilities > provided by logging)? Or is it possible to tweak the formatter so > that it inserts the prefix at the beginning of every line? I'd log exception name and timestamp (or id) only, pushing the full message with the same id to another log or facility (like mail it to some dedicated bug-report box). -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lie.1296 at gmail.com Tue Jun 16 23:30:29 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:30:29 GMT Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Scott David Daniels wrote: > norseman wrote: >> Scott David Daniels wrote: >>> Dave Angel wrote: >>>> Jorge wrote: ... >>>>> I'm making a application that reads 3 party generated ASCII files, >>>>> but some times the files are corrupted totally or partiality and I >>>>> need to know if it's a ASCII file with *nix line terminators. >>>>> In linux I can run the file command but the applications should run in >>>>> windows. >> you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) >> combination. If present you have Microsoft compatibility. If not you >> don't. If you think High Bits might be part of the corruption, filter >> each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) >> then check for the \x0D \x0A combination. > > Well ASCII defines a \x0D as the return code, and \x0A as line feed. > It is unix that is wrong, not Microsoft (don't get me wrong, I know > Microsoft has often redefined what it likes invalidly). The \r\n was originally a hack because teletype machines can only do one thing at a time (i.e. do a line feed NAND carriage return) and trying to do both at the same time or the wrong order would trigger a bug that sends a HCF instruction on many ancient teletypes. Unix decided that in virtual terminal, \r\n is unnecessary and redundant since VTs can do both in a single instruction. We can argue that Microsoft is "foolish consistency" here or Unix is changing standards just for saving a few bytes, but objectively neither side is right or wrong since the problem was a hack in the first place. If anyone is wrong, it is Mac that decided to use \r when Unix have already decided which characters to abandon (or maybe it's their usual reason: "different just because we want to be different") From lie.1296 at gmail.com Tue Jun 16 23:34:51 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:34:51 GMT Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Wolfgang Rohdewald wrote: > On Wednesday, 17. June 2009, Steven D'Aprano wrote: >> while text: >> for c in text: >> if c not in printable: return False > > that is one loop per character. unless printable is a set > wouldn't it be faster to apply a regex to text? > something like > > while text: > if re.search(r'\W',text): return False > regex? Don't even start... Anyway, only cProfile and profile would know who is the fastest... And, is speed really that important for this case? Seems like premature optimization to me. From higerinbeijing at gmail.com Tue Jun 16 23:40:00 2009 From: higerinbeijing at gmail.com (higer) Date: Tue, 16 Jun 2009 20:40:00 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? Message-ID: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> My Python version is 2.5.2; When I reading the bytecode of some pyc file, I always found that there are many jump command from different position,but to the same position. You can see this situation in following code(this bytecode is just from one .pyc file and I don't have its source .py file): ..... 526 POP_TOP '' 527 LOAD_FAST 'imeHandle' 530 LOAD_ATTR 'isCnInput' 533 CALL_FUNCTION_0 '' 536 JUMP_IF_FALSE '574' 539 POP_TOP '' 540 LOAD_FAST 'GUIDefine' 543 LOAD_ATTR 'CandidateIsOpen' 546 JUMP_IF_TRUE '574' 549 POP_TOP '' 550 LOAD_FAST 'GUIDefine' 553 LOAD_ATTR 'CompositionWndIsOpen' 556 JUMP_IF_TRUE '574' 559 POP_TOP '' 560 LOAD_FAST 'isWanNengWB' 563 JUMP_IF_FALSE '574' 566 POP_TOP '' 567 LOAD_FAST 'state' 570 LOAD_CONST 1 573 BINARY_AND '' 574_0 COME_FROM '' 574_1 COME_FROM '' 574_2 COME_FROM '' 574_3 COME_FROM '' ... >From the above bytecode,we know that line 574 is the point that many position jumps to.So,it just looks like the 'goto' function in C, but we know that there is none such function in Python. One 'JUMP**' command is companied with a 'COME_FROM' command,so more than one 'COME_FROM' OPs are listed on line 574... But ,the question is, I have tried a lot of ways(e.g.for loop,while loop and mixed) to re-present 'goto' style bytecodes like this, but the result depressed me. So,I think maybe it is just a compiler optimization in Python2.5? I'm not sure,so I'm appreciated that if anyone can help me. From lie.1296 at gmail.com Tue Jun 16 23:42:02 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:42:02 GMT Subject: walking a directory with very many files In-Reply-To: <20090617091858.432f89ca@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >>> Not proud of this, but...: >>> >>> [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >>> 174197 >>> >>> all .jpg files between 40 and 250KB with the path stored in a >>> database field... *sigh* >> Why not put the images themselves into database fields? >> >>> Oddly enough, I'm a relieved that others have had similar folder >>> sizes ... >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > > That way, you won't have to deal with many-files-in-path problem, and, > since there's thousands of them anyway, name readability shouldn't > matter. > > In fact, on modern filesystems it doesn't matter whether you accessing > /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea > with only hundred of them in each path. Former case (all-in-one-path) > would even outperform the latter with ext3 or reiserfs by a small > margin. > Sadly, that's not the case with filesystems like FreeBSD ufs2 (at least > in sixth branch), so it's better to play safe and create subdirs if the > app might be run on different machines than keeping everything in one > path. > It might not matter for the filesystem, but the file explorer (and ls) would still suffer. Subfolder structure would be much better, and much easier to navigate manually when you need to. From lie.1296 at gmail.com Tue Jun 16 23:47:00 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:47:00 GMT Subject: Logging multiple lines In-Reply-To: <87tz2fa9aw.fsf@vostro.rath.org> References: <87tz2fa9aw.fsf@vostro.rath.org> Message-ID: Nikolaus Rath wrote: > Hi, > > Are there any best practices for handling multi-line log messages? > > For example, the program, > > main = logging.getLogger() > handler = logging.StreamHandler() > handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) > main.addHandler(handler) > main.setLevel(logging.DEBUG) > main.info("Starting") > try: > bla = 42/0 > except: > main.exception("Oops...") > > generates the log messages > > 2009-06-16 22:19:57,515 INFO Starting > 2009-06-16 22:19:57,518 ERROR Oops... > Traceback (most recent call last): > File "/home/nikratio/lib/EclipseWorkspace/playground/src/mytests.py", line 27, in > bla = 42/0 > ZeroDivisionError: integer division or modulo by zero > > > which are a mess in any logfile because they make it really difficult to > parse. > > > How do you usually handle multi-line messages? Do you avoid them > completely (and therefore also the exception logging facilities provided > by logging)? Or is it possible to tweak the formatter so that it inserts > the prefix at the beginning of every line? > > The next line that starts with a timestamp is part of the next log. If you added timestamp on every line, that would be much more difficult to parse. You could do something like: import re timestamp_re = '...' messages = [] for line in open('log.log'): if timestamp_re.match(line): messages.append([line]) else: messages[-1].append(line) From delroth at gmail.com Tue Jun 16 23:47:47 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Wed, 17 Jun 2009 05:47:47 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> Message-ID: <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > What's np.arange? import numpy as np -- Pierre "delroth" Bourdon ?tudiant ? l'EPITA / Student at EPITA From warhammer1805 at gmail.com Wed Jun 17 00:05:43 2009 From: warhammer1805 at gmail.com (python-newbie113) Date: Tue, 16 Jun 2009 21:05:43 -0700 (PDT) Subject: Newbie question about method options Message-ID: I am new to python and have a question about using methods. Here is the link i am looking at: http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm If i use, create_arc(bbox, options) => id what is id? and how do i find the parameter list representing options? Thanks for help in advance Andrew From usernet at ilthio.net Wed Jun 17 00:32:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Jun 2009 04:32:16 GMT Subject: Newbie question about method options References: Message-ID: On 2009-06-17, python-newbie113 wrote: > If i use, create_arc(bbox, options) => id > what is id? and how do i find the parameter list representing options? I am not familiar with tkinker; but, the expression is just showing a function prototype. The function part should be self-explanitory. Judging from statements below like: canvasx(screenx) => float, canvasy(screeny) => float and bbox(items) => tuple, bbox() => tuple and the fact that "id" is mentioned for all of the functions that return a handle, I suspect that the "=>" and what comes after it is just a typographical notation to tell the reader what kind of datatype they can expect the function to return. From mk.fraggod at gmail.com Wed Jun 17 01:07:05 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 11:07:05 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: <20090617110705.7e7c423f@malediction> On Wed, 17 Jun 2009 03:42:02 GMT Lie Ryan wrote: > Mike Kazantsev wrote: > > In fact, on modern filesystems it doesn't matter whether you > > accessing /path/f9e95ea4926a4 with million files in /path > > or /path/f/9/e/95ea with only hundred of them in each path. Former > > case (all-in-one-path) would even outperform the latter with ext3 > > or reiserfs by a small margin. > > Sadly, that's not the case with filesystems like FreeBSD ufs2 (at > > least in sixth branch), so it's better to play safe and create > > subdirs if the app might be run on different machines than keeping > > everything in one path. > > It might not matter for the filesystem, but the file explorer (and ls) > would still suffer. Subfolder structure would be much better, and much > easier to navigate manually when you need to. It's an insane idea to navigate any structure with hash-based names and hundreds of thousands files *manually*: "What do we have here? Hashies?" ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jaime.frio at gmail.com Wed Jun 17 01:35:35 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Wed, 17 Jun 2009 07:35:35 +0200 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <97a8f1a70906162235g6a31eb2fia9683ef9e2c19075@mail.gmail.com> On Wed, Jun 17, 2009 at 4:50 AM, Lawrence D'Oliveiro wrote: > In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, ?wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). ?That should let you approximate >> the fractal dimension. > > Fractals are, by definition, not uniform in that sense. I had my doubts on this statement being true, so I've gone to my copy of Gerald Edgar's "Measure, Topology and Fractal Geometry" and Proposition 2.4.10 on page 69 states: "The sequence (gk), in the dragon construction of the Koch curve converges uniformly." And uniform continuity is a very well defined concept, so there really shouldn't be an interpretation issue here either. Would not stick my head out for it, but I am pretty sure that a continuous sequence of curves that converges to a continuous curve, will do so uniformly. Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From hobesh at gmail.com Wed Jun 17 01:42:44 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 22:42:44 -0700 Subject: Executing a python script while it is running In-Reply-To: <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> Message-ID: On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > On Tue, Jun 16, 2009 at 6:21 PM, wrote: >> Hey Dave, >> >> Thanks for the helpful responses. >> >>> Option 2 is what you get by default. ?Naturally it depends on what the >>> application ?is using to launch the batch file, but the most common cases >>> will launch a separate process. >> >> The app ended up delaying starting the second batch file until it finished >> the first. I had the app trigger an infinite loop on completion, and sent >> two files through at the same time. The second file finished seconds after >> the first, but the batch file didn't trigger until I closed the first one. > > Are you sure you aren't unknowingly having the app wait on the first > batch file process until it terminates? How exactly are you launching > the batch files? > > Cheers, > Chris > -- > http://blog.rebertia.com Hey Chris, I actually think that's what's happening, which is fine in my case (for now anyway) as I just need them all to complete, we don't need them running at the same time. I'm using a job management system, and they have the option of triggering a command line after completing a job. A better/safer solution might be spawning another job and re-inserting to the jms queue. Thanks again, Zach From tkjthingone at gmail.com Wed Jun 17 01:43:08 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Tue, 16 Jun 2009 22:43:08 -0700 Subject: Tool for browsing python code In-Reply-To: References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> <20090616163821.c3c9d48d.darcy@druid.net> Message-ID: On Tue, Jun 16, 2009 at 3:15 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > >> "D'Arcy J.M. Cain" writes: > >> >> not sure if there are any "curses" base TUI's (!) for Python. > >> > vi > >> > >> emacs :) > > > > Hey, it was all pretty civil up till now. ;) > > I've heard from my cousin that his former high school classmate's > uncle did a research on a large statistical sample of programmers and > found that emacs users' brains are about 12% smaller than vi users' :) > > Cheers, > Daniel > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > I'm afraid it's the other way around, really. You see, emacs contains 5 characters, thus requiring MORE brainpower to understand, where as vi is only 2 characters, requiring LESS brainpower. It's like that old joke. Why do blondes move to L.A? Because it's easy to spell. I guess what I'm saying is vi users are blondes. :) *crosses fingers and hopes he posted to the list this time* -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Wed Jun 17 01:45:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:45:23 +1200 Subject: walking a directory with very many files References: Message-ID: In message , Jean-Paul Calderone wrote: > The problem is that POSIX specifies the fields with types like off_t and > ino_t. Since ctypes doesn't know anything about these types, application > code has to specify their size and other attributes. As these vary from > platform to platform, you can't get it correct without asking a real C > compiler. Just to add to the complications, on 32-bit platforms, off_t can be either 64 bits or 32 bits, depending on whether a C program is compiled with -D_FILE_OFFSET_BITS=64 or not. This causes all kinds of aliasing of POSIX routines to the appropriate variants of the underlying libc routine names. With ctypes, you have to directly access the underlying routine names, unless you implement some kind of equivalent aliasing scheme on top. From mr.william.clifford at gmail.com Wed Jun 17 01:46:14 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Tue, 16 Jun 2009 22:46:14 -0700 (PDT) Subject: Exotic Logics Message-ID: I was staring at a logic table the other day, and I asked myself, "what if one wanted to play with exotic logics; how might one do it?" I did some searching but not being too sure of what to look for and carried away with my own enthusiasm for the idea, I didn't find much. What I've come up with is, no doubt, inefficient, naive, poor python style, and probably wrong in fundamental ways too subtle for me, but here it is: import itertools import operator class Logic(): """class of generic logic operators""" @staticmethod def lsd(rdx, n): """yield up base rdx digits of n in least significant order""" while n > 0: q, r = divmod(n, rdx) n = q yield r @staticmethod def rdxn(rdx, seq): """reduce a sequence of numbers by powers of rdx""" return reduce(operator.add, map(operator.mul, seq, (pow(rdx, i) for i in range(len(seq))))) @staticmethod def pute(rdx, opr, arg): """a logical primitive which returns 0 or 1.""" if arg < 0: return 0 o = tuple(lsd(rdx, opr)) try: return o[arg] except IndexError: return 0 @staticmethod def make_puter(rdx, opr): """return a function based on pute.""" o = tuple(Logic.lsd(rdx, opr)) def puter(arg): if arg < 0: return 0 try: return o[arg] except IndexError: return 0 return puter @staticmethod def make_inputs(rdx, *args): """yield a stripe of rdxn digits from args.""" largs = [Logic.lsd(rdx, a) for a in args] for i in itertools.izip_longest(*largs, fillvalue=0): yield Logic.rdxn(rdx, i) @staticmethod def compute(rdx, opr, *args): """return a number computed from opr of rdx.""" puter = Logic.make_puter(rdx, opr) inputs = Logic.make_inputs(rdx, *args) outputs = [puter(i) for i in inputs] return Logic.rdxn(rdx, outputs) @staticmethod def make_computer(rdx, opr): """return a computer of opr, rdx.""" def computer(*args): puter = Logic.make_puter(rdx, opr) inputs = Logic.make_inputs(rdx, *args) outputs = [puter(i) for i in inputs] return Logic.rdxn(rdx, outputs) return computer def __init__(self, rdx, opr): self._computer = Logic.make_computer(rdx, opr) def __call__(self, *args): return self._computer(*args) This seemed to be working for the limited tests I did on it, while I was doing them. The following checked out last time I tried: >>> and_ = Logic(2, 8) >>> or_ = Logic(2, 14) >>> xor = Logic(2, 6) I have no idea how to validate the results of the trinary and beyond logics. Thanks for reading and trying this out. Corrections? Criticism? Comments? -- William Clifford From ldo at geek-central.gen.new_zealand Wed Jun 17 01:49:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:49:59 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In message , Phil Runciman wrote: > FWIW I actually dislike this book! Why? From ldo at geek-central.gen.new_zealand Wed Jun 17 01:51:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:51:12 +1200 Subject: SIP v4.8.1 Released References: Message-ID: In message , Phil Thompson wrote: > SIP is a tool for generating Python modules that wrap C or C++ libraries. > It is similar to SWIG. It is used to generate PyQt and PyKDE. I find the name confusing. Every time I hear it I think "Session Initiation Protocol". OK, so I've been spending too much time with Asterisk. So sue me. :) From ldo at geek-central.gen.new_zealand Wed Jun 17 01:52:30 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:52:30 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In message , Steven D'Aprano wrote: > On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > >> In message , Piet van Oostrum wrote: >> >>> The exact time of the destruction of objects is an implementation >>> detail and should not be relied upon. >> >> That may be true in Java and other corporate-herd-oriented languages, >> but we know that dynamic languages like Perl and Python make heavy use >> of reference-counting wherever they can. If it's easy to satisfy >> yourself that the lifetime of an object will be delimited in this way, I >> don't see why you can't rely upon it. > > Reference counting is an implementation detail used by CPython but not > [implementations built on runtimes designed for corporate-herd-oriented > languages, like] IronPython or Jython. I rest my case. From ldo at geek-central.gen.new_zealand Wed Jun 17 01:53:33 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:53:33 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: In message <20090617091858.432f89ca at malediction>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >> > Not proud of this, but...: >> > >> > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >> > 174197 >> > >> > all .jpg files between 40 and 250KB with the path stored in a >> > database field... *sigh* >> >> Why not put the images themselves into database fields? >> >> > Oddly enough, I'm a relieved that others have had similar folder >> > sizes ... >> >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > > That way, you won't have to deal with many-files-in-path problem ... Why is that a problem? From http Wed Jun 17 02:04:11 2009 From: http (Paul Rubin) Date: 16 Jun 2009 23:04:11 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <7xd493v1k4.fsf@ruckus.brouhaha.com> Jaime Fernandez del Rio writes: > I am pretty sure that a continuous sequence of > curves that converges to a continuous curve, will do so uniformly. I think a typical example of a curve that's continuous but not uniformly continuous is f(t) = sin(1/t), defined when t > 0 It is continuous at every t>0 but wiggles violently as you get closer to t=0. You wouldn't be able to approximate it by sampling a finite number of points. A sequence like g_n(t) = sin((1+1/n)/ t) for n=1,2,... obviously converges to f, but not uniformly. On a closed interval, any continuous function is uniformly continuous. From http Wed Jun 17 02:13:41 2009 From: http (Paul Rubin) Date: 16 Jun 2009 23:13:41 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <7x7hzbv14a.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > > Reference counting is an implementation detail used by CPython but not > > [implementations built on runtimes designed for corporate-herd-oriented > > languages, like] IronPython or Jython. > > I rest my case. You're really being pretty ignorant. I don't know of any serious Lisp system that uses reference counting, both for performance reasons and to make sure cyclic structures are reclaimed properly. Lisp is certainly not a corporate herd language. Even CPython doesn't rely completely on reference counting (it has a fallback gc for cyclic garbage). Python introduced the "with" statement to get away from the kludgy CPython programmer practice of opening files and relying on the file being closed when the last reference went out of scope. From timr at probo.com Wed Jun 17 02:16:43 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:16:43 -0700 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: deostroll wrote: > >I want to be able to parse it into python objects. Any ideas? What did you not like about the very useful replies you have already received? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 02:16:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 06:16:54 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: On Wed, 17 Jun 2009 17:52:30 +1200, Lawrence D'Oliveiro wrote: > In message , > Steven D'Aprano wrote: > >> On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: >> >>> In message , Piet van Oostrum wrote: >>> >>>> The exact time of the destruction of objects is an implementation >>>> detail and should not be relied upon. >>> >>> That may be true in Java and other corporate-herd-oriented languages, >>> but we know that dynamic languages like Perl and Python make heavy use >>> of reference-counting wherever they can. If it's easy to satisfy >>> yourself that the lifetime of an object will be delimited in this way, >>> I don't see why you can't rely upon it. >> >> Reference counting is an implementation detail used by CPython but not >> [implementations built on runtimes designed for corporate-herd-oriented >> languages, like] IronPython or Jython. > > I rest my case. CLPython and Unladen Swallow do not use reference counting. I suppose you might successfully argue that Lisp is a corporate-herd-oriented language, and that Google (the company behind Unladen Swallow) is a corporate-herd. But PyPy doesn't use reference counting either. Perhaps you think that Python is a language designed for corporate-herds too? -- Steven From timr at probo.com Wed Jun 17 02:18:29 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:18:29 -0700 Subject: How to get the total size of a local hard disk? References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: willgun wrote: > >Unfortunately,I'm on win32. >Actually,I prefer a cross-platform method. Why do you need this? This kind of information is not very useful in a cross-platform application. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From deets at nospam.web.de Wed Jun 17 02:21:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Jun 2009 08:21:40 +0200 Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? In-Reply-To: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: <79rgbkF1rcncsU1@mid.uni-berlin.de> higer schrieb: > My Python version is 2.5.2; When I reading the bytecode of some pyc > file, I always found that there are many jump command from different > position,but to the same position. You can see this situation in > following code(this bytecode is just from one .pyc file and I don't > have its source .py file): > > ..... > 526 POP_TOP '' > 527 LOAD_FAST 'imeHandle' > 530 LOAD_ATTR 'isCnInput' > 533 CALL_FUNCTION_0 '' > 536 JUMP_IF_FALSE '574' > 539 POP_TOP '' > 540 LOAD_FAST 'GUIDefine' > 543 LOAD_ATTR 'CandidateIsOpen' > 546 JUMP_IF_TRUE '574' > 549 POP_TOP '' > 550 LOAD_FAST 'GUIDefine' > 553 LOAD_ATTR 'CompositionWndIsOpen' > 556 JUMP_IF_TRUE '574' > 559 POP_TOP '' > 560 LOAD_FAST 'isWanNengWB' > 563 JUMP_IF_FALSE '574' > 566 POP_TOP '' > 567 LOAD_FAST 'state' > 570 LOAD_CONST 1 > 573 BINARY_AND '' > 574_0 COME_FROM '' > 574_1 COME_FROM '' > 574_2 COME_FROM '' > 574_3 COME_FROM '' > ... > > From the above bytecode,we know that line 574 is the point that many > position jumps to.So,it just looks like the 'goto' function in C, but > we know that there is none such function in Python. > One 'JUMP**' command is companied with a 'COME_FROM' command,so more > than one 'COME_FROM' OPs are listed on line 574... > > But ,the question is, I have tried a lot of ways(e.g.for loop,while > loop and mixed) to re-present 'goto' style bytecodes like this, but > the result depressed me. > So,I think maybe it is just a compiler optimization in Python2.5? I'm > not sure,so I'm appreciated that if anyone can help me. Getting a depression because of a compiler is a bit strong... However, yes, bytecode is similar to assembler, and in that respect higher-level control-structures are created using (conditional) jumps. The same is true for other bytecode-languages, see here for the JVM: http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493 Diez From darwin at nowhere.com Wed Jun 17 02:23:53 2009 From: darwin at nowhere.com (Paul Hemans) Date: Wed, 17 Jun 2009 16:23:53 +1000 Subject: Managing a multiple threaded service Message-ID: Hi, New to Python .... I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site for data. I want to run the program as a windows service. My questions are: Should both of them run as threads and then just have an infinite loop with a sleep in the main thread in order to stop the main program from just terminating? Or should I choose one of the threads to run as the main program and spawn the other off? That was my original intention, but I am concerned that if I use SimpleHTTPRequestHandler in the main thread, will it block any attempt to terminate the service. Just looking for pointers to the best practice approach. This is where I am at: if __name__=="__main__": import SocketServer import threading import monitor ## Monitor changes on the server (separate thread) monitor = monitor.monitor(fnLog=self.logStatus) monitor.start() ## Service interface port = 8081 server=SocketServer.TCPServer(('',port),ScriptRequestHandler) server.serve_forever() ## To run the web server on a different thread... ## t = threading.Thread(target=server.serve_forever) ## t.setDaemon(True) # don't hang on exit ## t.start() server.socket.close() From timr at probo.com Wed Jun 17 02:24:20 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:24:20 -0700 Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: Tim Harig wrote: > >IronPython is not a GUI toolkit per se. It is a python implementation >build on top of .Net like Jython is built on top of Java. I therefore has >access to the MFCs which can be used to create native Windows GUIs. That's not correct. MFC is strictly a native C++ concept. IronPython, being a .NET language, has access to the .NET GUIs, which means either Windows Forms or the incredibly powerful Windows Presentation Framework. However, if I may be allowed to express an opinion, if you're going to play in that world, you are swimming upstream unless you write in C#. Otherwise, you end up spending most of your time translating C# concepts into Python. >This can also be done from Cpython using the pywin extensions. Here, you are correct. Pywin32 does include a Python implementation of MFC. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From martin.hellwig at dcuktec.org Wed Jun 17 02:29:07 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 07:29:07 +0100 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: edexter wrote: > On Jun 16, 12:27 pm, Stef Mientki wrote: >> hello, >> >> I am pleased to announce the first full alpha release of PyLab_Works, v0.3. >> >> PyLab_Works is a modular Visual Development Environment, based on >> data-flow programming technics. PyLab_Works is specially aimed at >> Education, Engineering and Science. The ideas behind PyLab_Works are, >> that the final user should not be burdened with programming details and >> domain details, whereas the domain expert should be able to implement >> the specific domain knowledge without being a full educated programmer. >> >> You can always find my notes on PyLab_Works on >> http://pic.flappie.nl >> Most of these pages are also collected in a single pdf document, which >> can be found here: >> http://pylab-works.googlecode.com/files/pw_manual.pdf >> >> The source code and a one-button-Windows-Installer can be found on >> codegoogle: >> http://code.google.com/p/pylab-works/ >> The files are rather large, because they contain some data samples. >> The Windows-Installer contains everything you need to get started with >> PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, >> Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, >> Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. >> Although the PyLab_Works programs are compiled with Py2Exe, all the >> source files are explicitly included. >> >> have fun, >> Stef Mientki > > program didn't start because .dll is missing (sorry I don't have the > name)... I don't know if that is just an issue with the installer > with vista or not (missing msv something 71. dll) You probably mean the microsoft visual C++ runtime (msvcr71.dll), windows vista has a brand new way (via manifest files) to make it more difficult to install compiled binaries. Search for 'Microsoft Visual C++ 2005 Redistributable Package' and install it. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From timr at probo.com Wed Jun 17 02:30:18 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:30:18 -0700 Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: higer wrote: > >My Python version is 2.5.2; When I reading the bytecode of some pyc >file, I always found that there are many jump command from different >position,but to the same position. You can see this situation in >following code(this bytecode is just from one .pyc file and I don't >have its source .py file): >... >From the above bytecode,we know that line 574 is the point that many >position jumps to.So,it just looks like the 'goto' function in C, but >we know that there is none such function in Python. >... >But ,the question is, I have tried a lot of ways(e.g.for loop,while >loop and mixed) to re-present 'goto' style bytecodes like this, but >the result depressed me. >So,I think maybe it is just a compiler optimization in Python2.5? I'm >not sure,so I'm appreciated that if anyone can help me. I can't figure out what you're asking here. Are you annoyed that the byte code contains GOTOs? This is a silly thing to worry about. The whole purpose of a compiler is to translate a program express in high-level constructs into a lower-level and more primitive format. The simplest form of an "if" statement or a "while" statement always includes unconditional branches. This exact same thing happens with every compiler. Assembly languages, for example, do not have "if/then/else" instructions, nor "while" instructions, nor "switch" instructions. If you write a C program with an "if" statement, the resulting assembly program will contain a "goto" (usually called "jump" or "branch"). Don't worry about it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Wed Jun 17 02:45:24 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 17 Jun 2009 16:45:24 +1000 Subject: Managing a multiple threaded service In-Reply-To: References: Message-ID: <4A389104.1030308@gmail.com> On 17/06/2009 4:23 PM, Paul Hemans wrote: > Hi, > New to Python .... > I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site > for data. I want to run the program as a windows service. > My questions are: > Should both of them run as threads and then just have an infinite loop with > a sleep in the main thread in order to stop the main program from just > terminating? No need for a loop - just have the main thread wait forever for the stop request. The main problem I forsee is asking the socketserver thread to terminate as it is likely to be inside 'accept' or some other blocking function. HTH, Mark From gabriel.rossetti at arimaz.com Wed Jun 17 03:15:04 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Wed, 17 Jun 2009 09:15:04 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> References: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> Message-ID: <4A3897F8.7070602@arimaz.com> John Machin wrote: > On Jun 17, 1:41 am, Gabriel Rossetti > wrote: > >> Hello everyone, >> >> I get an OperationalError with sqlite3 if I put the wrong column name, >> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it >> says : >> >> > [snip] > >> and to me it sounds more like a programming error than an operational >> error. >> > > How about showing us the code you used and the exact error message and > traceback? > > > Well, the code isn't really relevant to the problem, but here is is : import sqlite3 conn = sqlite3.connect("/tmp/test.db") conn.execute("SELECT name, value FROM local_param") for row in conn: print row And I get : Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: no such table: local_param Which I think should be a ProgrammingError If I fix the table name I but use a wrong column name I also get an OperationalError import sqlite3 conn = sqlite3.connect("/tmp/test.db") conn.execute("SELECT name, valueeeeeeee FROM local_parameters") for row in conn: print row Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: no such column: valueeeeeeee Which should also be a ProgrammingError as I see it and as my interpretation of the documention. Gabriel From wuerzner at gmail.com Wed Jun 17 03:30:22 2009 From: wuerzner at gmail.com (kmw) Date: Wed, 17 Jun 2009 00:30:22 -0700 (PDT) Subject: strange behavior with os.system References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: That's it. I am calling my own program and not coreutils' sort, what explains the unrequested output. Many thanks. Cheers, Kay On 16 Jun., 22:16, Piet van Oostrum wrote: > >>>>> kmw (k) wrote: > >k> Hi, > >k> I wanted to write a simple script (in 5 minutes or so) which replaces > >k> the option '+1' given to the command 'sort' by '-k 2' and than runs > >k> 'sort' with the modified argument list. After two hours I am giving up > >k> and ask you for help. This is what I tried (please excuse the verbose > >k> code, it is due to my various efforts to understand the error): > > [snip] > > >k> Please note the unrequested output of ''. The strange > >k> thing about this all is the fact that ?the whole thing works as > >k> expected when typed ?into the interpreter. I would be glad if anyone > >k> could help. > > MRAB has already given you some insight, I hope. > But are you aware that you are calling your own program again? > Or did you want to call the standard sort program? In that case you > shouldn't call ./sort as it is in argv[0], but just sort (assuming '.' > is not in your PATH) or the full path, like /usr/bin/sort. > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org From mail at microcorp.co.za Wed Jun 17 03:41:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 17 Jun 2009 09:41:18 +0200 Subject: Tool for browsing python code References: <4A3794A9.5080309@gmail.com><3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com><20090616163821.c3c9d48d.darcy@druid.net> Message-ID: <00d801c9ef21$daff6660$0d00a8c0@Hendrik> Horace Blegg wrote: >I've heard from my cousin that his former high school classmate's >uncle did a research on a large statistical sample of programmers and >found that emacs users' brains are about 12% smaller than vi users' :) >I'm afraid it's the other way around, really. You see, emacs contains 5 characters, thus requiring MORE >brainpower to understand, where as vi is only 2 characters, requiring LESS brainpower. It's like that old joke. >Why do blondes move to L.A? Because it's easy to spell. I guess what I'm saying is vi users are blondes. :) All this stuff is nonsense. It is a well known fact that the size of your brain is not governed by what editor you use, but by what you drink. The conjecture that some editors might drive you to drink is at the moment only a theory. I am not aware of any hard evidence that correlates hard tack drinking patterns with editor usage. So any research on brain size vs editor usage that does not also include drinking pattern data is essentially invalid. - Hendrik From davea at ieee.org Wed Jun 17 03:43:46 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Jun 2009 03:43:46 -0400 Subject: Newbie question about method options In-Reply-To: References: Message-ID: <4A389EB2.8040409@ieee.org> python-newbie113 wrote: > I am new to python and have a question about using methods. > > Here is the link i am looking at: > http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm > > If i use, create_arc(bbox, options) => id > what is id? and how do i find the parameter list representing options? > > Thanks for help in advance > > Andrew > > This is a tkinter question, not a python one, and it's really all about how the docs for tkinter are organized. I don't use tkinter, so I had to spelunk a little bit (try search). You're looking at a summary page. You want to see the details for a given one of those methods. Search for create_arc, and you'll find http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm as one of the links. The link "Back" will get you to: http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm which is the beginning of Chapter 14, "The Canvas Arc Item" As for 'id' I have no idea, but if you read further, you'll probably find out. The fact that all of these methods return one indicates it's some sort of object reference for those widgets. From mail at microcorp.co.za Wed Jun 17 04:01:24 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 17 Jun 2009 10:01:24 +0200 Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <00d901c9ef21$db289940$0d00a8c0@Hendrik> "Diez B. Roggisch" wrote: > Getting a depression because of a compiler is a bit strong... > > However, yes, bytecode is similar to assembler, and in that respect > higher-level control-structures are created using (conditional) jumps. > > The same is true for other bytecode-languages, see here for the JVM: > > http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493 This is right. It is my opinion that it is not possible to make a useful machine, virtual or real, which executes instructions sequentially, if the instruction set does not contain a conditional jump of some sort. I have tried doing it using conditional calls, and it fails on the equivalent of the first if ..., elif ... you try to write. - Hendrik From mk.fraggod at gmail.com Wed Jun 17 04:24:31 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 14:24:31 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: <20090617142431.2b25faf5@malediction> On Wed, 17 Jun 2009 17:53:33 +1200 Lawrence D'Oliveiro wrote: > > Why not use hex representation of md5/sha1-hashed id as a path, > > arranging them like /path/f/9/e/95ea4926a4 ? > > > > That way, you won't have to deal with many-files-in-path problem ... > > Why is that a problem? So you can os.listdir them? Don't ask me what for, however, since that's the original question. Also not every fs still in use handles this situation effectively, see my original post. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 04:28:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 08:28:20 GMT Subject: Exotic Logics References: Message-ID: On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > I was staring at a logic table the other day, and I asked myself, "what > if one wanted to play with exotic logics; how might one do it?" First question: what's an exotic logics? Do you mean things like three-value logic, fuzzy logic, probabilistic reasoning, etc? Or do you mean logical operators others than and, or, xor, nand, nor, etc? Or both? Something else? > I did > some searching but not being too sure of what to look for and carried > away with my own enthusiasm for the idea, I didn't find much. What I've > come up with is, no doubt, inefficient, naive, poor python style, and > probably wrong in fundamental ways too subtle for me, but here it is: > > import itertools > import operator > > class Logic(): > """class of generic logic operators""" [...] If (nearly) all your methods are static methods, chances are a class is the wrong solution. Why not just define the static methods as top-level functions? > This seemed to be working for the limited tests I did on it, while I was > doing them. The following checked out last time I tried: > >>>> and_ = Logic(2, 8) >>>> or_ = Logic(2, 14) >>>> xor = Logic(2, 6) > > I have no idea how to validate the results of the trinary and beyond > logics. The same way you would validate and_, or_ and xor: to validate something, you need to know what the correct answer is, then compare the answer you get with the answer you should get. For a binary operator and binary operands, you can exhaustively check every valid input: flag1 op flag2 there are four combinations of input flags: 0 op 0 0 op 1 1 op 0 1 op 1 For three-valued logic, there are 9 combinations. For four-valued, 16. So exhaustively testing all the possible inputs is quite simple. As far as getting the correct answers, you have to decide which three- valued logic(s) you want to use, then go look them up. Or just make them up yourself! E.g. given trinary flags 0, 1, 2, (say), you might want the operators to give the same results with 0, 1 as they would if you were applying it to binary flags 0, 1. E.g.: # binary operands 0 and 0 => 0 0 and 1 => 0 1 and 0 => 0 1 and 1 => 1 # trinary operands 0 and 0 => 0 0 and 1 => 0 0 and 2 => ? # probably 0 1 and 0 => 0 1 and 1 => 1 1 and 2 => ? # could be 0, or maybe 1 2 and 0 => ? # probably 0 2 and 1 => ? # 0 or 1 2 and 2 => ? # probably 2 Different choices lead to different versions of ternary logic. > Thanks for reading and trying this out. Corrections? Criticism? > Comments? You're implementation seems rather confusing. I think that's partly because you use lots of abbreviated jargon terms that mean little or nothing to me: rdx, opr (operator?), lsd, pute. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 04:44:19 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 08:44:19 GMT Subject: Exotic Logics References: Message-ID: On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > I was staring at a logic table the other day, and I asked myself, "what > if one wanted to play with exotic logics; how might one do it?" This might be useful for you, and if not useful, at least it might blow your mind like it did mine. (This is not original to me -- I didn't create it. However, I can't find the original source.) Imagine for a moment that there are no boolean values. There are no numbers. They were never invented. There are no classes. There are no objects. There are only functions. Could you define functions that act like boolean values? And could you define other functions to operate on them? def true(x, y): return x def false(x, y): return y def print_bool(b): print b("true", "false") print_bool(true) print_bool(false) def Not(b): def not_b(x, y): return b(y, x) return not_b print_bool(Not(true)) print_bool(Not(false)) print_bool(Not(Not(true))) def And(a, b): return a(b, a) def Or(a, b): return a(a, b) print_bool(And(true, true)) print_bool(And(true, false)) print_bool(Or(false, true)) print_bool(Or(false, false)) -- Steven From higerinbeijing at gmail.com Wed Jun 17 05:14:26 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 17 Jun 2009 02:14:26 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <64179b1f-6cec-4708-ae94-3ed5c5fb373e@g1g2000yqh.googlegroups.com> Hi,all: I'm sorry that I did not make my question clear. What I mean is that what the souce code would look like that will be compiled to such bytecodes. Regards, higer From command.bbs at alexbbs.twbbs.org Wed Jun 17 05:27:50 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 17 Jun 2009 09:27:50 GMT Subject: UDP queue size Message-ID: <4gRWbd$vn0@alexbbs.twbbs.org> I got a problem about UDP. How do I get the UDP buffer size? When the server had some delay in handling incoming UDP, it will lost some package. I wonder it's because the system buffer size, is there any ways to find the exactly size of the buffer? ex: client.py ---------------- import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in xrange(1000): s.sendto('xxx', ('192.168.1.135',10000)) server.py: in ip (192.168.1.135) ---------------- import socket import time s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(('',10000)) time.sleep(10) # here will only recv 255 package, others are lost... for i in xrange(1000): msg, addr = s.recvfrom(500) print i -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From wolfgang at rohdewald.de Wed Jun 17 05:40:31 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Jun 2009 11:40:31 +0200 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <200906171140.31320.wolfgang@rohdewald.de> On Wednesday 17 June 2009, Lie Ryan wrote: > Wolfgang Rohdewald wrote: > > On Wednesday, 17. June 2009, Steven D'Aprano wrote: > >> while text: > >> for c in text: > >> if c not in printable: return False > > > > that is one loop per character. > > unless printable is a set that would still execute the line "if c not in..." once for every single character, against just one regex call. With bigger block sizes, the advantage of regex should increase. > > wouldn't it be faster to apply a regex to text? > > something like > > > > while text: > > if re.search(r'\W',text): return False > > > > regex? Don't even start... Here comes a cProfile test. Note that the first variant of Steven would always have stopped after the first char. After fixing that making it look like variant 2 with block size=1, I now have 3 variants: Variant 1 Blocksize 1 Variant 2 Blocksize 65536 Variant 3 Regex on Blocksize 65536 testing for a file with 400k bytes shows regex as a clear winner. Doing the same for an 8k file: variant 2 takes 3ms, Regex takes 5ms. Variants 2 and 3 take about the same time for a file with 20k. python ascii.py | grep CPU 398202 function calls in 1.597 CPU seconds 13 function calls in 0.104 CPU seconds 1181 function calls in 0.012 CPU seconds import re import cProfile from string import printable def ascii_file1(name): with open(name, 'rb') as f: c = f.read(1) while c: if c not in printable: return False c = f.read(1) return True def ascii_file2(name): bs = 65536 with open(name, 'rb') as f: text = f.read(bs) while text: for c in text: if c not in printable: return False text = f.read(bs) return True def ascii_file3(name): bs = 65536 search = r'[^%s]' % re.escape(printable) reco = re.compile(search) with open(name, 'rb') as f: text = f.read(bs) while text: if reco.search(text): return False text = f.read(bs) return True def test(fun): if fun('/tmp/x'): print 'is ascii' else: print 'is not ascii' cProfile.run("test(ascii_file1)") cProfile.run("test(ascii_file2)") cProfile.run("test(ascii_file3)") -- Wolfgang From deets at nospam.web.de Wed Jun 17 05:59:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Jun 2009 11:59:15 +0200 Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> <64179b1f-6cec-4708-ae94-3ed5c5fb373e@g1g2000yqh.googlegroups.com> Message-ID: <79rst2F1pqvecU1@mid.uni-berlin.de> higer wrote: > Hi,all: > > I'm sorry that I did not make my question clear. What I mean is that > what the souce code would look like that will be compiled to such > bytecodes. >>> import dis >>> def foo(): ... for i in xrange(10): ... if i == 5: ... break ... if i == 4: ... continue ... i *= 100 ... >>> dis.disassemble(foo.func_code) 2 0 SETUP_LOOP 68 (to 71) 3 LOAD_GLOBAL 0 (xrange) 6 LOAD_CONST 1 (10) 9 CALL_FUNCTION 1 12 GET_ITER >> 13 FOR_ITER 54 (to 70) 16 STORE_FAST 0 (i) 3 19 LOAD_FAST 0 (i) 22 LOAD_CONST 2 (5) 25 COMPARE_OP 2 (==) 28 JUMP_IF_FALSE 5 (to 36) 31 POP_TOP 4 32 BREAK_LOOP 33 JUMP_FORWARD 1 (to 37) >> 36 POP_TOP 5 >> 37 LOAD_FAST 0 (i) 40 LOAD_CONST 3 (4) 43 COMPARE_OP 2 (==) 46 JUMP_IF_FALSE 7 (to 56) 49 POP_TOP 6 50 JUMP_ABSOLUTE 13 53 JUMP_FORWARD 1 (to 57) >> 56 POP_TOP 7 >> 57 LOAD_FAST 0 (i) 60 LOAD_CONST 4 (100) 63 INPLACE_MULTIPLY 64 STORE_FAST 0 (i) 67 JUMP_ABSOLUTE 13 >> 70 POP_BLOCK >> 71 LOAD_CONST 0 (None) 74 RETURN_VALUE >>> Pretty much everything with control-structures. Diez From sjmachin at lexicon.net Wed Jun 17 06:06:26 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Jun 2009 20:06:26 +1000 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <4A3897F8.7070602@arimaz.com> References: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> <4A3897F8.7070602@arimaz.com> Message-ID: <4A38C022.7090609@lexicon.net> On 17/06/2009 5:15 PM, Gabriel Rossetti wrote: > John Machin wrote: >> On Jun 17, 1:41 am, Gabriel Rossetti >> wrote: >> >>> Hello everyone, >>> >>> I get an OperationalError with sqlite3 if I put the wrong column name, >>> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it >>> says : >>> >>> >> [snip] >> >>> and to me it sounds more like a programming error than an operational >>> error. >>> >> >> How about showing us the code you used and the exact error message and >> traceback? >> >> >> > Well, the code isn't really relevant to the problem, but here is is : > > import sqlite3 > > conn = sqlite3.connect("/tmp/test.db") > conn.execute("SELECT name, value FROM local_param") > > for row in conn: > print row > > And I get : > > Traceback (most recent call last): > File "", line 1, in > sqlite3.OperationalError: no such table: local_param > > > Which I think should be a ProgrammingError > > If I fix the table name I but use a wrong column name I also get an > OperationalError OK OK alright already ... I agree with you ... report a bug. Cheers, John From paul.paj at gmail.com Wed Jun 17 06:09:34 2009 From: paul.paj at gmail.com (Paul Johnston) Date: Wed, 17 Jun 2009 03:09:34 -0700 (PDT) Subject: class or instance method Message-ID: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Hi, I would like to have a method that is both a classmethod and an instancemethod. So: class MyClass(object): @class_or_instance def myfunc(cls_or_self): pass The semantics I'd like are: When you call MyClass.myfunc, it gets passed a class When you call MyClass().myfunc, it gets passed an instance I'm sure I've seen some code to do this somewhere, but I can't find it now. Any help appreciated. Paul From pdpinheiro at gmail.com Wed Jun 17 06:18:27 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 03:18:27 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <4afb1842-e7e5-43f9-8320-ebf14b851d97@g19g2000yql.googlegroups.com> On Jun 17, 9:01?am, "Hendrik van Rooyen" wrote: > ?"Diez B. Roggisch" wrote: > > > Getting a depression because of a compiler is a bit strong... > > > However, yes, bytecode is similar to assembler, and in that respect > > higher-level control-structures are created using (conditional) jumps. > > > The same is true for other bytecode-languages, see here for the JVM: > > >http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.... > > This is right. > > It is my opinion that it is not possible to make a useful machine, > virtual or real, which executes instructions sequentially, if the > instruction set does not contain a conditional jump of some sort. > > I have tried doing it using conditional calls, and it fails on > the equivalent of the first if ..., elif ... ?you try to write. > > - Hendrik Not a matter of opinion. One of the requisite elements of a Turing Machine is conditional jumping. From 42flicks at gmail.com Wed Jun 17 06:22:08 2009 From: 42flicks at gmail.com (Mike) Date: Wed, 17 Jun 2009 22:22:08 +1200 Subject: GAEUnit testing Message-ID: <2b54d4370906170322h2e2aaa0ctea3701be8b5aa169@mail.gmail.com> Hello I'm using GAEUnit to develop an app for google appengine and am having a little trouble. I'm trying to make a test as follows: I have a file (say model.py) which contains Model.db model classes and some methods for accessing them. The methods are not part of the class. In my test I can call model.save_person(person) which will call Person(name=person) and Person.put(). I can confirm this is being saved to the db (app engine db stub) by logging the result of Person.all() under the call to put. What I want to do is create a method in model.py called get_people which will return Person.all(). If I do this the second test returns an empty result set. I think this is because the second test is not getting the same reference. In my set up I'd like to set up a Person with details such as address, phone, preferences and have each test get the data for this person and test the result of some transformations. I'd like to do this using the methods in my model.py class, and avoid importing the database to the test unit and using references to self. Am I approaching this correctly? How would I implement this? Thanks for any assistance, I'm new to python and especially unittesting. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Jun 17 06:39:47 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Jun 2009 12:39:47 +0200 Subject: class or instance method In-Reply-To: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Message-ID: <4a38c7e8$0$11904$426a74cc@news.free.fr> Paul Johnston a ?crit : > Hi, > > I would like to have a method that is both a classmethod and an > instancemethod. So: > > class MyClass(object): > @class_or_instance > def myfunc(cls_or_self): > pass > > The semantics I'd like are: > When you call MyClass.myfunc, it gets passed a class > When you call MyClass().myfunc, it gets passed an instance > > I'm sure I've seen some code to do this somewhere, but I can't find it > now. Any help appreciated. IIRC, there's something quite similar in formencode. From bruno.42.desthuilliers at websiteburo.invalid Wed Jun 17 06:47:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Jun 2009 12:47:24 +0200 Subject: Question about None In-Reply-To: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <4a38c9b1$0$11904$426a74cc@news.free.fr> John Yeung a ?crit : > On Jun 13, 2:29 am, Steven D'Aprano > wrote: >> Paul LaFollette wrote: >>> 3) (this is purely philosophical but I am curious) >>> Would it not be more intuitive if >>> isinstance(None, ) returned true? >> Good grief no!!! >> >> None is an object. It has a type, NoneType. It's *not* a >> string, or a float, or an int, or a list, so why would >> you want isinstance() to *lie* and say that it is? > > Because you might want None to behave as though it were nothing at > all. > > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. IOW, what's the OP is after is not the None type, but some yet unexisting "Anything" type !-) From ldo at geek-central.gen.new_zealand Wed Jun 17 07:04:37 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:04:37 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> Message-ID: In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 17:53:33 +1200 > Lawrence D'Oliveiro wrote: > >> > Why not use hex representation of md5/sha1-hashed id as a path, >> > arranging them like /path/f/9/e/95ea4926a4 ? >> > >> > That way, you won't have to deal with many-files-in-path problem ... >> >> Why is that a problem? > > So you can os.listdir them? Why should you have a problem os.listdir'ing lots of files? From ldo at geek-central.gen.new_zealand Wed Jun 17 07:07:15 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:07:15 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Lie Ryan wrote: > out.write ( > ''' > function JSString(Str) > { > var Result = '\"' > for (var i = 0; i < Str.length; ++i) > { > var ThisCh = Str.charAt(i) > if (ThisCh == '\\') > { > ThisCh = '\\\\' > } > else if (ThisCh == '\"') > { > ThisCh = '\\\"' > } > else if (ThisCh == '\t') > { > ThisCh = '\\t' > } > else if (ThisCh == '\n') > { > ThisCh = '\\n' > } /*if*/ > Result += ThisCh > } /*for*/ > return Result + '\"' > } /*JSString*/ > ''' > ) You haven't managed to get rid of the backslashes. > I might go even further: > > out.write ( > ''' > function JSString(Str) > { > const dq = '\"' > const slash = '\\' > > var Result = dq > for (var i = 0; i < Str.length; ++i) > { > var ThisCh = Str.charAt(i) > if (ThisCh == slash) > { > ThisCh = slash + slash > } > else if (ThisCh == dq) > { > ThisCh = slash + dq > } > else if (ThisCh == '\t') > { > ThisCh = slash + 't' > } > else if (ThisCh == '\n') > { > ThisCh = slash + 'n' > } /*if*/ > Result += ThisCh > } /*for*/ > return Result + dq > } /*JSString*/ > ''' > ) Now you've lost track of the original point of the discussion, which is about using alternate quotes to avoid backslashes. From ldo at geek-central.gen.new_zealand Wed Jun 17 07:29:48 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:29:48 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: In message <7x7hzbv14a.fsf at ruckus.brouhaha.com>, wrote: > Lawrence D'Oliveiro writes: > >> > Reference counting is an implementation detail used by CPython but not >> > [implementations built on runtimes designed for corporate-herd-oriented >> > languages, like] IronPython or Jython. >> >> I rest my case. > > You're really being pretty ignorant. I don't know of any serious Lisp > system that uses reference counting, both for performance reasons and > to make sure cyclic structures are reclaimed properly. Both of which, oddly enough, more modern dynamic languages like Python manage perfectly well. From zeal_goswami at yahoo.com Wed Jun 17 07:32:21 2009 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Wed, 17 Jun 2009 17:02:21 +0530 (IST) Subject: Regarding Python is scripting language or not Message-ID: <501798.29841.qm@web94916.mail.in2.yahoo.com> Hi, I have very basic question about Python that do we consider pyhton as script language. I searched in google but it becomes more confusion for me. After some analysis I came to know that Python support oops . Can anyone Guide me that Python is Oject oriented programming language or Script language Abhishek Goswami Chennai Phone No -0996227099 ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From charles at declareSub.com Wed Jun 17 07:37:32 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 07:37:32 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <7xd493v1k4.fsf@ruckus.brouhaha.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <4F141360-C2AF-4DC1-891D-6AB222960ABD@declareSub.com> On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: > Jaime Fernandez del Rio writes: >> I am pretty sure that a continuous sequence of >> curves that converges to a continuous curve, will do so uniformly. > > I think a typical example of a curve that's continuous but not > uniformly continuous is > > f(t) = sin(1/t), defined when t > 0 > > It is continuous at every t>0 but wiggles violently as you get closer > to t=0. You wouldn't be able to approximate it by sampling a finite > number of points. A sequence like > > g_n(t) = sin((1+1/n)/ t) for n=1,2,... > > obviously converges to f, but not uniformly. On a closed interval, > any continuous function is uniformly continuous. Isn't (-?, ?) closed? Charles Yeomans From charles at declareSub.com Wed Jun 17 07:49:52 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 07:49:52 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) In-Reply-To: <7x7hzbv14a.fsf@ruckus.brouhaha.com> References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 2009, at 2:13 AM, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> Reference counting is an implementation detail used by CPython but >>> not >>> [implementations built on runtimes designed for corporate-herd- >>> oriented >>> languages, like] IronPython or Jython. >> >> I rest my case. > > You're really being pretty ignorant. I don't know of any serious Lisp > system that uses reference counting, both for performance reasons and > to make sure cyclic structures are reclaimed properly. Lisp is > certainly not a corporate herd language. > > Even CPython doesn't rely completely on reference counting (it has a > fallback gc for cyclic garbage). Python introduced the "with" > statement to get away from the kludgy CPython programmer practice of > opening files and relying on the file being closed when the last > reference went out of scope. I'm curious as you why you consider this practice to be kludgy; my experience with RAII is pretty good. Charles Yeomans From dickinsm at gmail.com Wed Jun 17 07:52:29 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 04:52:29 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> On Jun 17, 7:04?am, Paul Rubin wrote: > I think a typical example of a curve that's continuous but not > uniformly continuous is > > ? ?f(t) = sin(1/t), defined when t > 0 > > It is continuous at every t>0 but wiggles violently as you get closer > to t=0. ?You wouldn't be able to approximate it by sampling a finite > number of points. ?A sequence like > > ? ?g_n(t) = sin((1+1/n)/ t) ? ?for n=1,2,... > > obviously converges to f, but not uniformly. ?On a closed interval, > any continuous function is uniformly continuous. Right, but pointwise convergence doesn't imply uniform convergence even with continuous functions on a closed bounded interval. For an example, take the sequence g_n (n >= 0), of continuous real-valued functions on [0, 1] defined by: g_n(t) = nt if 0 <= t <= 1/n else 1 Then for any 0 <= t <= 1, g_n(t) -> 0 as n -> infinity. But the convergence isn't uniform: max_t(g_n(t)-0) = 1 for all n. Maybe James is thinking of the standard theorem that says that if a sequence of continuous functions on an interval converges uniformly then its limit is continuous? Mark From dickinsm at gmail.com Wed Jun 17 07:56:20 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 04:56:20 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <6e1d0b33-254c-445d-96c3-5d5023c29fd5@k2g2000yql.googlegroups.com> On Jun 17, 12:52?pm, Mark Dickinson wrote: > g_n(t) = nt if 0 <= t <= 1/n else 1 Whoops. Wrong definition. That should be: g_n(t) = nt if 0 <= t <= 1/n else n(2/n-t) if 1/n <= t <= 2/n else 0 Then my claim that g_n(t) -> 0 for all t might actually make sense... From jeanmichel at sequans.com Wed Jun 17 08:13:15 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 14:13:15 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> Message-ID: <4A38DDDB.5070309@sequans.com> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >> What's np.arange? >> > > import numpy as np > > -- > Pierre "delroth" Bourdon > ?tudiant ? l'EPITA / Student at EPITA > Perfect example of why renaming namespaces should be done only when absolutely required, that is, almost never. Jean-Michel From contact at xavierho.com Wed Jun 17 08:24:16 2009 From: contact at xavierho.com (Xavier Ho) Date: Wed, 17 Jun 2009 22:24:16 +1000 Subject: class or instance method In-Reply-To: <4a38c7e8$0$11904$426a74cc@news.free.fr> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <4a38c7e8$0$11904$426a74cc@news.free.fr> Message-ID: <2d56febf0906170524l408dc07ev432b8d56db1c66c8@mail.gmail.com> I'm quite curious as to why you would like it, because: >>> MyClass (returns the MyClass class representation) >>> MyClass() (returns a instance of the MyClass class) So, are you just looking for a method that does exactly the above? Best regards, 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 Wed, Jun 17, 2009 at 8:39 PM, Bruno Desthuilliers wrote: > Paul Johnston a ?crit : > >> Hi, >> >> I would like to have a method that is both a classmethod and an >> instancemethod. So: >> >> class MyClass(object): >> @class_or_instance >> def myfunc(cls_or_self): >> pass >> >> The semantics I'd like are: >> When you call MyClass.myfunc, it gets passed a class >> When you call MyClass().myfunc, it gets passed an instance >> >> I'm sure I've seen some code to do this somewhere, but I can't find it >> now. Any help appreciated. >> > > IIRC, there's something quite similar in formencode. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jaime.frio at gmail.com Wed Jun 17 08:26:27 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Wed, 17 Jun 2009 14:26:27 +0200 Subject: Measuring Fractal Dimension ? In-Reply-To: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <97a8f1a70906170526m313948arcbe6ca22cbe601c8@mail.gmail.com> On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: > Maybe James is thinking of the standard theorem > that says that if a sequence of continuous functions > on an interval converges uniformly then its limit > is continuous? Jaime was simply plain wrong... The example that always comes to mind when figuring out uniform convergence (or lack of it), is the step function , i.e. f(x)= 0 if x in [0,1), x(x)=1 if x >= 1, being approximated by the sequence f_n(x) = x**n if x in [0,1), f_n(x) = 1 if x>=1, where uniform convergence is broken mostly due to the limiting function not being continuous. I simply was too quick with my extrapolations, and have realized I have a looooot of work to do for my "real and functional analysis" exam coming in three weeks... Jaime P.S. The snowflake curve, on the other hand, is uniformly continuous, right? -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From sjmachin at lexicon.net Wed Jun 17 08:29:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Jun 2009 05:29:19 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: On Jun 17, 1:40?pm, higer wrote: > My Python version is 2.5.2; When I reading the bytecode of some pyc > file, I always found that there are many jump command from different > position,but to the same position. You can see this situation in > following code(this bytecode is just from one .pyc file and I don't > have its source .py file): > Why don't you (a) read the answers you got on stackoverflow to the identical question (b) WRITE some code instead of inspecting the entrails of the code of others? From ml at well-adjusted.de Wed Jun 17 08:35:40 2009 From: ml at well-adjusted.de (Jochen Schulz) Date: Wed, 17 Jun 2009 14:35:40 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <20090617123540.GA19607@wasteland.homelinux.net> abhishek goswami: > > Can anyone Guide me that Python is Oject oriented programming language > or Script language In my opinion, Python is both. But an "objective" answer would require you to define what you means by these terms. If, by "object-oriented" you mean "everything has to be put into classes", then Python is not object-oriented. If, by "scripting language" you mean Python is an error-prone toy language, unsuitable for large, serious projects, then Python is not a scripting language either. J. -- My clothes aren't just fashion. They're a lifestyle. [Agree] [Disagree] -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From jeanmichel at sequans.com Wed Jun 17 08:38:55 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 14:38:55 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <4A38E3DF.2010408@sequans.com> abhishek goswami wrote: > Hi, > I have very basic question about Python that do we consider pyhton as > script language. > I searched in google but it becomes more confusion for me. After some > analysis I came to know that Python support oops . > > Can anyone Guide me that Python is Oject oriented programming language > or Script language > > Abhishek Goswami > Chennai > Phone No -0996227099 > > > ------------------------------------------------------------------------ > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > Depends on what you are calling a scripting language. Refering to wikipedia, "A *scripting language*, *script language* or *extension language* is a programming language that allows some control of a single or many software application(s) ." Python is definitely OOP oriented and I don't think it fits in the script definition above. Python is interpreted and platform independent, but you can still build standalone platform dependent binaries if required. Regarding your last question, I'm not sure scripting and OOP language are not compatible, I'm pretty sure you'll be able to find OOP scripting language. Jean-Michel From hniksic at xemacs.org Wed Jun 17 08:40:45 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 17 Jun 2009 14:40:45 +0200 Subject: class or instance method References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Message-ID: <87ljnr3ueq.fsf@busola.homelinux.net> Paul Johnston writes: > I would like to have a method that is both a classmethod and an > instancemethod. So: > > class MyClass(object): > @class_or_instance > def myfunc(cls_or_self): > pass > > The semantics I'd like are: > When you call MyClass.myfunc, it gets passed a class > When you call MyClass().myfunc, it gets passed an instance class class_or_instance(object): def __init__(self, fn): self.fn = fn def __get__(self, obj, cls): if obj is not None: return lambda *args, **kwds: self.fn(obj, *args, **kwds) else: return lambda *args, **kwds: self.fn(cls, *args, **kwds) >>> class MyClass(object): ... @class_or_instance ... def myfunc(cls_or_self): ... return cls_or_self ... >>> MyClass.myfunc() >>> MyClass().myfunc() <__main__.MyClass object at 0xb7a248cc> You might want to use functools.wrap to return named functions rather than unnamed lambdas, but you get the idea. From dickinsm at gmail.com Wed Jun 17 08:46:22 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 05:46:22 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> On Jun 17, 1:26?pm, Jaime Fernandez del Rio wrote: > On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: > > Maybe James is thinking of the standard theorem > > that says that if a sequence of continuous functions > > on an interval converges uniformly then its limit > > is continuous? s/James/Jaime. Apologies. > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? Yes, at least in the sense that it can be parametrized by a uniformly continuous function from [0, 1] to the Euclidean plane. I'm not sure that it makes a priori sense to describe the curve itself (thought of simply as a subset of the plane) as uniformly continuous. Mark From higerinbeijing at gmail.com Wed Jun 17 08:47:09 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 17 Jun 2009 05:47:09 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: <7734a932-31e9-4eb8-bc60-84a05f471e46@h18g2000yqj.googlegroups.com> On Jun 17, 8:29?pm, John Machin wrote: > On Jun 17, 1:40?pm, higer wrote: > > > My Python version is 2.5.2; When I reading the bytecode of some pyc > > file, I always found that there are many jump command from different > > position,but to the same position. You can see this situation in > > following code(this bytecode is just from one .pyc file and I don't > > have its source .py file): > > Why don't you (a) read the answers you got on stackoverflow to the > identical question (b) WRITE some code instead of inspecting the > entrails of the code of others? Thanks, I read the answer just now. And thank everbody for your suggestion! From Scott.Daniels at Acm.Org Wed Jun 17 09:05:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:05:12 -0700 Subject: walking a directory with very many files In-Reply-To: <20090617091858.432f89ca@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >>> Not proud of this, but...: >>> >>> [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >>> 174197 >>> >>> all .jpg files between 40 and 250KB with the path stored in a >>> database field... *sigh* >> Why not put the images themselves into database fields? >> >>> Oddly enough, I'm a relieved that others have had similar folder >>> sizes ... >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > ... > In fact, on modern filesystems it doesn't matter whether you accessing > /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea > with only hundred of them in each path. Probably better to use: /path/f9/e9/5ea4926a4 If you want to talk hundreds per layer. Branching 16 ways seems silly. --Scott David Daniels Scott.Daniels at Acm.Org From pdpinheiro at gmail.com Wed Jun 17 09:18:17 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 06:18:17 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> On Jun 17, 1:26?pm, Jaime Fernandez del Rio wrote: > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? The definition of uniform continuity is that, for any epsilon > 0, there is a delta > 0 such that, for any x and y, if x-y < delta, f(x)-f (y) < epsilon. Given that Koch's curve is shaped as recursion over the transformation from ___ to _/\_, it's immediately obvious that, for a delta of at most the length of ____, epsilon will be at most the height of /. It follows that, inversely, for any arbitrary epsilon, you find the smallest / that's still taller than epsilon, and delta is bound by the respective ____. (hooray for ascii demonstrations) Curiously enough, it's the recursive/self-similar nature of the Koch curve so easy to prove as uniformly continuous. From Scott.Daniels at Acm.Org Wed Jun 17 09:26:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:26:31 -0700 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> Message-ID: Jean-Michel Pichavant wrote: > On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >>> What's np.arange? >> >> import numpy as np > > Perfect example of why renaming namespaces should be done only when > absolutely required, that is, almost never. > > Jean-Michel Actually, "np." is quite commonly used in the numpy community, so it is a bit of a "term of art". Since you can often use several numpy elements in an expression, brevity is appreciated, and at least they've stopped assuming "from numpy import *" in their documents. Unfortunately, if you work in a numpy world long enough, you'll forget that not everyone uses numpy. --Scott David Daniels Scott.Daniels at Acm.Org From martin.hellwig at dcuktec.org Wed Jun 17 09:29:07 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 14:29:07 +0100 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: Jochen Schulz wrote: > abhishek goswami: >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language > > In my opinion, Python is both. But an "objective" answer would require > you to define what you means by these terms. > > If, by "object-oriented" you mean "everything has to be put into > classes", then Python is not object-oriented. If, by "scripting > language" you mean Python is an error-prone toy language, unsuitable for > large, serious projects, then Python is not a scripting language either. > > J. IMHO Python is an programming environment where you can chose the right approach for your particular problem. Because it seems to favour clarity over classification purity, it can not be so easily defined. This approach should be fine for everybody unless you are the type that insist on using one approach because in theory it should be suitable for everything. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From Scott.Daniels at Acm.Org Wed Jun 17 09:41:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:41:58 -0700 Subject: Newbie question about method options In-Reply-To: References: Message-ID: Dave Angel wrote: > python-newbie113 wrote: >> I am new to python and have a question about using methods. >> >> Here is the link i am looking at: >> http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm >> >> If i use, create_arc(bbox, options) => id >> what is id? and how do i find the parameter list representing options? > > Search for create_arc, and you'll find > http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm > as one of the links. The link "Back" will get you to: > http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm > > which is the beginning of Chapter 14, "The Canvas Arc Item" > > As for 'id' I have no idea, but if you read further, you'll probably > find out. The fact that all of these methods return one indicates it's > some sort of object reference for those widgets. Everything drawn on a canvas has an 'id' which just happens to be an integer (treat it as a magic cookie). You specify that id to the canvas to talk about that particular element, but you often group canvas elements together via "tags", and use the same canvas operations on a tag so that you can do your operation to everything with that tag. operations include such things as color manipulation, delete, clone, and move. --Scott David Daniels Scott.Daniels at Acm.Org From kshama.nagaraj at gmail.com Wed Jun 17 09:48:21 2009 From: kshama.nagaraj at gmail.com (kshama nagaraj) Date: Wed, 17 Jun 2009 15:48:21 +0200 Subject: os.read in non blocking mode of os.open : resource busy error Message-ID: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> Dear all, I am using os.open to open a tun/tap device and then read data from it. I also need to do some other tasks apart from reading from this device. So i wish to have the read non blocking. I am opening the device in non-block mode using os.O_NONBLOCK . But, if i do this, i get an error when i call the os.read a follows: File "./tunnel_more1.py", line 305, in main_loop payload = os.read(self.tun_fd,64) OSError: [Errno 11] Resource temporarily unavailable I am running my application with GNU Radio on Ubuntu. Can some one tell me, what is the error? What are the ways to use non blocking read? thanks all for your time and attention. -- Thanks & Regards Kshama -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jun 17 09:50:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:50:37 -0700 Subject: UDP queue size In-Reply-To: <4gRWbd$vn0@alexbbs.twbbs.org> References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: ???????? wrote: > I got a problem about UDP. > > How do I get the UDP buffer size? > > When the server had some delay in handling incoming UDP, it will lost > some package. I wonder it's because the system buffer size, is there any > ways to find the exactly size of the buffer? UDP is defined as "best effort then give up," so _everything_ that handles a UDP packet is allowed to drop it; that means switchers, routers, ..., anything along the path to the target application. So, you cannot expect to do any better than a conservative guess, perhaps augmented by dynamic scaling. --Scott David Daniels Scott.Daniels at Acm.Org From jure.erznoznik at gmail.com Wed Jun 17 10:00:02 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Wed, 17 Jun 2009 07:00:02 -0700 (PDT) Subject: Newbie queue question Message-ID: Hi, I'm pretty new to Python (2.6) and I've run into a problem I just can't seem to solve. I'm using dbfpy to access DBF tables as part of a little test project. I've programmed two separate functions, one that reads the DBF in main thread and the other which reads the DBF asynchronously in a separate thread. Here's the code: def demo_01(): '''DBF read speed only''' dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): rec = dbf1[i1] dbf1.close() def demo_03(): '''DBF read speed into a FIFO queue''' class mt(threading.Thread): q = Queue.Queue(64) def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) dbf1.close() del dbf1 self.q.join() t = mt() t.start() while t.isAlive(): try: rec = t.q.get(False, 0.2) t.q.task_done(); except: pass del t However I'm having serious issues with the second method. It seems that as soon as I start accessing the queue from both threads, the reading speed effectively halves. I have tried the following: 1. using deque instead of queue (same speed) 2. reading 10 records at a time and inserting them in a separate loop (hoped the congestion would help) 3. Increasing queue size to infinite and waiting 10 seconds in main thread before I started reading - this one yielded full reading speed, but the waiting took away all the threading benefits I'm sure I'm doing something very wrong here, I just can't figure out what. Can anyone help me with this? Thanks, Jure From Eric_Dexter at msn.com Wed Jun 17 10:12:14 2009 From: Eric_Dexter at msn.com (edexter) Date: Wed, 17 Jun 2009 07:12:14 -0700 (PDT) Subject: first full alpha release of PyLab_Works v0.3 References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: On Jun 17, 12:29?am, "Martin P. Hellwig" wrote: > edexter wrote: > > On Jun 16, 12:27 pm, Stef Mientki wrote: > >> hello, > > >> I am pleased to announce the first full alpha release of PyLab_Works, v0.3. > > >> PyLab_Works is a modular Visual Development Environment, based on > >> data-flow programming technics. PyLab_Works is specially aimed at > >> Education, Engineering and Science. The ideas behind PyLab_Works are, > >> that the final user should not be burdened with programming details and > >> domain details, whereas the domain expert should be able to implement > >> the specific ?domain knowledge without being a full educated programmer. > > >> You can always find my notes on PyLab_Works on > >> ? ?http://pic.flappie.nl > >> Most of these pages are also collected in a single pdf document, which > >> can be found here: > >> ?http://pylab-works.googlecode.com/files/pw_manual.pdf > > >> The source code and a one-button-Windows-Installer can be found on > >> codegoogle: > >> ?http://code.google.com/p/pylab-works/ > >> The files are rather large, because they contain some data samples. > >> The Windows-Installer contains everything you need to get started with > >> PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, ? > >> Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, > >> Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. > >> Although the PyLab_Works programs are compiled with Py2Exe, all the > >> source files are explicitly included. > > >> have fun, > >> Stef Mientki > > > program didn't start because .dll is missing (sorry I don't have the > > name)... ?I don't know if that is just an issue with the installer > > with vista or not (missing msv something 71. dll) > > You probably mean the microsoft visual C++ runtime (msvcr71.dll), > windows vista has a brand new way (via manifest files) to make it more > difficult to install compiled binaries. > > Search for 'Microsoft Visual C++ 2005 Redistributable Package' and > install it. > > -- > MPHhttp://blog.dcuktec.comm > 'If consumed, best digested with added seasoning to own preference.' it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 Redistributable Package did not help.. I had simular problems with alot of installers I had saved (from installing on xp) but when I grabbed newer installers they all worked, could be the manifast.... I was looking forward to trying it out.. From dickinsm at gmail.com Wed Jun 17 10:23:33 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 07:23:33 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> Message-ID: On Jun 17, 2:18?pm, pdpi wrote: > On Jun 17, 1:26?pm, Jaime Fernandez del Rio > wrote: > > > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? > > The definition of uniform continuity is that, for any epsilon > 0, > there is a delta > 0 such that, for any x and y, if x-y < delta, f(x)-f > (y) < epsilon. Given that Koch's curve is shaped as recursion over the > transformation from ___ to _/\_, it's immediately obvious that, for a > delta of at most the length of ____, epsilon will be at most the > height of /. It follows that, inversely, for any arbitrary epsilon, > you find the smallest / that's still taller than epsilon, and delta is > bound by the respective ____. (hooray for ascii demonstrations) I think I'm too stupid to follow this. It looks as though you're treating (a portion of?) the Koch curve as the graph of a function f from R -> R and claiming that f is uniformly continuous. But the Koch curve isn't such a graph (it fails the 'vertical line test', in the language of precalculus 101), so I'm confused. Here's an alternative proof: Let K_0, K_1, K_2, ... be the successive generations of the Koch curve, so that K_0 is the closed line segment from (0, 0) to (1, 0), K_1 looks like _/\_, etc. Parameterize each Kn by arc length, scaled so that the domain of the parametrization is always [0, 1] and oriented so that the parametrizing function fn has fn(0) = (0,0) and fn(1) = (1, 0). Let d = ||f1 - f0||, a positive real constant whose exact value I can't be bothered to calculate[*] (where ||f1 - f0|| means the maximum over all x in [0, 1] of the distance from f0(x) to f1(x)). Then from the self-similarity we get ||f2 - f1|| = d/3, ||f3 - f2|| = d/9, ||f4 - f3|| = d/27, etc. Hence, since sum_{i >= 0} d/(3^i) converges absolutely, the sequence f0, f1, f2, ... converges *uniformly* to a limiting function f : [0, 1] -> R^2 that parametrizes the Koch curve. And since a uniform limit of uniformly continuous function is uniformly continuous, it follows that f is uniformly continuous. Mark [*] I'm guessing 1/sqrt(12). From paul at boddie.org.uk Wed Jun 17 10:25:38 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Wed, 17 Jun 2009 07:25:38 -0700 (PDT) Subject: Tool for browsing python code References: Message-ID: <791f647b-4514-4273-a9c8-83e140b1040f@t21g2000yqi.googlegroups.com> On 16 Jun, 14:48, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time > trying to figure this out) > Anything like cscope with vim would be great. Are you limiting your inquiry to text editors or IDEs, or are Web- based solutions also interesting? Often, convenient browsing tools index the code and try and provide reasonable links from the place where a particular name or symbol may be used to the definition of that name or symbol elsewhere in a system. Initially, for a Web-based code browser, I looked at LXR [1], but it seemed that OpenGrok [2] was probably a better solution except for the fact that it uses the usual Java parallel universe of Web and application servers. Meanwhile, there are pages on the python.org Wiki about IDEs, editors and documentation tools, all of which might be relevant here: http://wiki.python.org/moin/DevelopmentTools Paul [1] http://lxr.linux.no/ [2] http://opensolaris.org/os/project/opengrok/ From kwmsmith at gmail.com Wed Jun 17 10:38:42 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 17 Jun 2009 09:38:42 -0500 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: On Tue, Jun 16, 2009 at 7:48 AM, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time trying > to figure this out) > Anything like cscope with vim would be great. Check out pycscope: http://pypi.python.org/pypi/pycscope/0.3 I use it myself, and it works fine. Better than ctags/etags for python. Kurt From http Wed Jun 17 10:46:12 2009 From: http (Paul Rubin) Date: 17 Jun 2009 07:46:12 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> Message-ID: <7xfxdyrk97.fsf@ruckus.brouhaha.com> Mark Dickinson writes: > It looks as though you're treating (a portion of?) the Koch curve as > the graph of a function f from R -> R and claiming that f is > uniformly continuous. But the Koch curve isn't such a graph (it > fails the 'vertical line test', I think you treat it as a function f: R -> R**2 with the usual distance metric on R**2. From descentspb at gmail.com Wed Jun 17 10:57:05 2009 From: descentspb at gmail.com (Igor Katson) Date: Wed, 17 Jun 2009 18:57:05 +0400 Subject: ANN: pyTenjin 0.8.0 - much faster template engine than Django In-Reply-To: References: Message-ID: <4A390441.3070905@gmail.com> kwatch wrote: > I have released pyTenjin 0.8.0 > Thanks for your project. I have used it a little, and there is a question to you. import tenjin from tenjin.helpers import * shared_cache = tenjin.GaeMemcacheCacheStorage() engine = tenjin.Engine(cache=shared_cache) 1. Why should I import tenjin.helpers if I don't use the helpers in my code? 2. Why does the code not work if I don't import the helpers? I think you should manage this issue inside the library. From castironpi at gmail.com Wed Jun 17 11:06:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 08:06:22 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Jun 16, 10:09?am, Mike Kazantsev wrote: > On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) > > Aaron Brady wrote: > > Making the charitable interpretation that this was the extent of c-l- > > py's support and enthusiasm for my idea, I will now go into mourning. > > Death occurred at oh-eight-hundred. ?Rest in peace, support & > > enthusiasm. > > I've read this thread from the beginning, being tempted to insert > remarks about shelve module or ORMs like SQLAlchemy, but that'd be > meaningless without the problem description, which I haven't seen > anywhere. Is it some trick idea like "let's walk on our heads"? More like bronze them, or hang them on a tackboard. You haven't convinced me that it's not a problem, or that it's an easy one. From castironpi at gmail.com Wed Jun 17 11:10:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 08:10:48 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <4a38c9b1$0$11904$426a74cc@news.free.fr> Message-ID: On Jun 17, 5:47?am, Bruno Desthuilliers wrote: > John Yeung a ?crit : > > But mathematically speaking, it's intuitive that "nothing" would match > > any type. > > IOW, what's the OP is after is not the None type, but some yet > unexisting "Anything" type !-) The behaviors of the 'anything' object are a subset of those of any other object. I don't believe that 'subset' is a proper characterization of the relationship between the methods of a subclass and the methods of its superclass. But 'superset' may be. Should 'object' inherit from None? From dickinsm at gmail.com Wed Jun 17 11:18:52 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 08:18:52 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 3:46?pm, Paul Rubin wrote: > Mark Dickinson writes: > > It looks as though you're treating (a portion of?) the Koch curve as > > the graph of a function f from R -> R and claiming that f is > > uniformly continuous. ?But the Koch curve isn't such a graph (it > > fails the 'vertical line test', > > I think you treat it as a function f: R -> R**2 with the usual > distance metric on R**2. Right. Or rather, you treat it as the image of such a function, if you're being careful to distinguish the curve (a subset of R^2) from its parametrization (a continuous function R -> R**2). It's the parametrization that's uniformly continuous, not the curve, and since any curve can be parametrized in many different ways any proof of uniform continuity should specify exactly which parametrization is in use. Mark From nick at craig-wood.com Wed Jun 17 11:29:31 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 17 Jun 2009 10:29:31 -0500 Subject: UDP queue size References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: ???M???v???@???? wrote: > I got a problem about UDP. > > How do I get the UDP buffer size? > > When the server had some delay in handling incoming UDP, it will lost > some package. I wonder it's because the system buffer size, is there any > ways to find the exactly size of the buffer? > > ex: > > client.py > import socket > > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > for i in xrange(1000): > s.sendto('xxx', ('192.168.1.135',10000)) > > > > server.py: in ip (192.168.1.135) > import socket > import time > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > s.bind(('',10000)) > time.sleep(10) > > # here will only recv 255 package, others are lost... > for i in xrange(1000): > msg, addr = s.recvfrom(500) > print i I think you want setsockopt... >>> import socket >>> import time >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.bind(('',10000)) >>> s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF) 112640 >>> s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1048576) >>> s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF) 262142 >>> I ran the above on linux and I expect the limit 262144 is settable in /proc/sys/net somewhere. No idea whether the above works on windows! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mk.fraggod at gmail.com Wed Jun 17 11:45:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 21:45:35 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> Message-ID: <20090617214535.108667ca@coercion> On Wed, 17 Jun 2009 23:04:37 +1200 Lawrence D'Oliveiro wrote: > In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 17:53:33 +1200 > > Lawrence D'Oliveiro wrote: > > > >> > Why not use hex representation of md5/sha1-hashed id as a path, > >> > arranging them like /path/f/9/e/95ea4926a4 ? > >> > > >> > That way, you won't have to deal with many-files-in-path problem ... > >> > >> Why is that a problem? > > > > So you can os.listdir them? > > Why should you have a problem os.listdir'ing lots of files? I shouldn't, and I don't ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From martin.hellwig at dcuktec.org Wed Jun 17 11:58:41 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 16:58:41 +0100 Subject: UDP queue size In-Reply-To: References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: Scott David Daniels wrote: > ???????? wrote: >> I got a problem about UDP. >> >> How do I get the UDP buffer size? >> >> When the server had some delay in handling incoming UDP, it will lost >> some package. I wonder it's because the system buffer size, is there any >> ways to find the exactly size of the buffer? > > UDP is defined as "best effort then give up," so _everything_ that > handles a UDP packet is allowed to drop it; that means switchers, > routers, ..., anything along the path to the target application. > So, you cannot expect to do any better than a conservative guess, > perhaps augmented by dynamic scaling. > > --Scott David Daniels > Scott.Daniels at Acm.Org I would like to add, that you are most likely to lose packages because they are to big, I can not remember for sure if UDP had a fixed limit above what the MTU does, but you might want to look at that direction too. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From pdpinheiro at gmail.com Wed Jun 17 11:58:48 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 08:58:48 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 4:18?pm, Mark Dickinson wrote: > On Jun 17, 3:46?pm, Paul Rubin wrote: > > > Mark Dickinson writes: > > > It looks as though you're treating (a portion of?) the Koch curve as > > > the graph of a function f from R -> R and claiming that f is > > > uniformly continuous. ?But the Koch curve isn't such a graph (it > > > fails the 'vertical line test', > > > I think you treat it as a function f: R -> R**2 with the usual > > distance metric on R**2. > > Right. ?Or rather, you treat it as the image of such a function, > if you're being careful to distinguish the curve (a subset > of R^2) from its parametrization (a continuous function > R -> R**2). ?It's the parametrization that's uniformly > continuous, not the curve, and since any curve can be > parametrized in many different ways any proof of uniform > continuity should specify exactly which parametrization is > in use. > > Mark I was being incredibly lazy and using loads of handwaving, seeing as I posted that (and this!) while procrastinating at work. an even lazier argument: given the _/\_ construct, you prove that its vertical growth is bound: the height of / is less than 1/3 (given a length of 1 for ___), so, even if you were to build _-_ with the middle segment at height = 1/3, the maximum vertical growth would be sum 1/3^n from 1 to infinity, so 0.5. Sideways growth has a similar upper bound. 0.5 < 1, so the chebyshev distance between any two points on the curve is <= 1. Ergo, for any x,y, f(x) is at most at chebyshev distance 1 of (y). Induce the argument for "smaller values of one". From icanbob at gmail.com Wed Jun 17 12:10:54 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 17 Jun 2009 09:10:54 -0700 (PDT) Subject: Executing a python script while it is running References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> Message-ID: On Jun 17, 1:42 am, Zach Hobesh wrote: > On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > > On Tue, Jun 16, 2009 at 6:21 PM, wrote: > >> Hey Dave, > > >> Thanks for the helpful responses. > > >>> Option 2 is what you get by default. Naturally it depends on what the > >>> application is using to launch the batch file, but the most common cases > >>> will launch a separate process. > > >> The app ended up delaying starting the second batch file until it finished > >> the first. I had the app trigger an infinite loop on completion, and sent > >> two files through at the same time. The second file finished seconds after > >> the first, but the batch file didn't trigger until I closed the first one. > > > Are you sure you aren't unknowingly having the app wait on the first > > batch file process until it terminates? How exactly are you launching > > the batch files? > > > Cheers, > > Chris > > -- > >http://blog.rebertia.com > > Hey Chris, > > I actually think that's what's happening, which is fine in my case > (for now anyway) as I just need them all to complete, we don't need > them running at the same time. I'm using a job management system, and > they have the option of triggering a command line after completing a > job. > > A better/safer solution might be spawning another job and re-inserting > to the jms queue. > > Thanks again, > > Zach You might want to take a look at the Python-SIMPL toolkit (http:// www.icanprogram.com/06py/main.html). SIMPL uses a Send/Receive/Reply interprocess messaging scheme which will naturally queue requests for you. Without too much effort you may be able to reorient your scheme to eliminate the batch file entirely. bob From brendandetracey at yahoo.com Wed Jun 17 12:15:17 2009 From: brendandetracey at yahoo.com (Brendan) Date: Wed, 17 Jun 2009 09:15:17 -0700 (PDT) Subject: exit() or sys.exit() Message-ID: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> What is the difference on exit() and sys.exit() when called in the main body of a script? From the command line they seem to have the same effect. Aside: Just used a python dictionary in which the keys were compiled regular expressions. Provided a very elegant solution. Have to love it. From python.list at tim.thechases.com Wed Jun 17 12:33:44 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 17 Jun 2009 11:33:44 -0500 Subject: exit() or sys.exit() In-Reply-To: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: <4A391AE8.8040605@tim.thechases.com> Brendan wrote: > What is the difference on exit() and sys.exit() when called in the > main body of a script? From the command line they seem to have the > same effect. In Python <=2.4 you had to use sys.exit() because __builtins__.exit() griped: tchase at asgix:~$ python2.4 Python 2.4.4 (#2, Apr 15 2008, 23:43:20) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> type(exit) >>> exit() Traceback (most recent call last): File "", line 1, in ? TypeError: 'str' object is not callable In 2.5, it's an instance of site.Quitter which is callable, allowing it to behave like sys.exit() (from my observations, __builtins__.exit() and sys.exit() behave the same). I tend to use sys.exit() because I've still got code running on machines mired at 2.4 -tkc From castironpi at gmail.com Wed Jun 17 12:34:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 09:34:47 -0700 (PDT) Subject: Executing a python script while it is running References: <4A381FBE.9040003@ieee.org> Message-ID: <16ed8850-33c9-4778-a263-15401d366f34@h28g2000yqd.googlegroups.com> On Jun 16, 3:48?pm, Zach Hobesh wrote: > > A lot more information would be useful. ?What version of Python, and what > > operating system environment? ?Exactly what would you like to happen when > > the batch file is invoked a second time? > > I'm running Python 2.6.2 on Windows. ?I'm passing filenames to the > batch files and I need all filenames to be processed. ?I can't have > any fails. ?I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > > > ?2) let them both run as separate processes > > This sounds like a good option, but I'm not totally sure on how to go > about this? > > > ?4) queue something to be processed when the first run finishes > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. This sort of falls under both categories, 2 & 4, and it will probably be judged 'poor practice' by history. We're all historians now, I guess. Windows has what's called a 'named mutex' for interprocess synchro'tion. Start your new process, acquire their shared mutex by name, and block on it. You will have one process for each file, but only one will run at once. You won't even need to build a shared library; 'ctypes' will suffice. From lie.1296 at gmail.com Wed Jun 17 12:37:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 16:37:04 GMT Subject: Exotic Logics In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > >> I was staring at a logic table the other day, and I asked myself, "what >> if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > your mind like it did mine. > > (This is not original to me -- I didn't create it. However, I can't find > the original source.) > > Imagine for a moment that there are no boolean values. > There are no numbers. They were never invented. > There are no classes. > There are no objects. > There are only functions. > > Could you define functions that act like boolean values? And could you > define other functions to operate on them? > > > def true(x, y): > return x > > def false(x, y): > return y > > def print_bool(b): > print b("true", "false") > String isn't considered object? Also, b/true()/false() is a function object, isn't it? Unless function is first-class, you can't pass them around like that, since you need a function pointer (a.k.a number); but if function is first-class then there it is an object. From castironpi at gmail.com Wed Jun 17 12:59:03 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 09:59:03 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> On Jun 17, 1:44?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > This might be useful for you, and if not useful, at least it might blow > your mind like it did mine. > > (This is not original to me -- I didn't create it. However, I can't find > the original source.) > > Imagine for a moment that there are no boolean values. > There are no numbers. ?They were never invented. > There are no classes. > There are no objects. > There are only functions. > > Could you define functions that act like boolean values? And could you > define other functions to operate on them? snip I think high and low /voltages/, though continuous and approximate, might satisfy this. There are no such things as electrons, only variations in density of the luminiferous ether. From rob.clewley at gmail.com Wed Jun 17 13:01:15 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Wed, 17 Jun 2009 13:01:15 -0400 Subject: ODE, GUI, plotter in Python In-Reply-To: <160620091700027246%shaibani@ymail.com> References: <160620091700027246%shaibani@ymail.com> Message-ID: There was just an announcement on this list and the scipy list for PyLab_Works, which sounds exactly like what you're looking for. I would not recommend starting over with a new simulator at this point. -Rob On Tue, Jun 16, 2009 at 12:00 PM, Ala wrote: > Hello everyone. > > I am starting on implementing a simulator using python, and since it's > the first time I code in python would appreciate a few pointers: > > The simulator will use a coupled ODE for the most part of the > simulation, I plan to use scipy. (Anything considered faster/better > than scipy for solving coupled ODEs? ) > > I plan for a GUI program with network graph plotting. I am leaning > towards using Qt for the GUI (internet forums seem to recommend it, > anyone got other preferences? ) > > Since the GUI application will contain few buttons and a plot, I am > planning to implement matplotlib into the GUI. But does anyone know if > matplotlib allows for interaction with the graph plot? (say for a > network simulation, allowing to right click on nodes and disable them > for instance, or alter some other properties of nodes and/or links > across them). > > I am just starting out, hence I'd rather get some advice and experiment > a bit for my self as I go along. > > Thank you. From castironpi at gmail.com Wed Jun 17 13:04:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:04:36 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <140d5517-f5a1-4027-9b52-c19964bdcf7e@i6g2000yqj.googlegroups.com> On Jun 17, 1:28?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > First question: what's an exotic logics? > > Do you mean things like three-value logic, fuzzy logic, probabilistic > reasoning, etc? You (OP) may be interested in the definitions of the fuzzy operators: and( x, y ) := min( x, y ) or( x, y ) := max( x, y ) not( x ) := 1 (one)- x nand( x, y ) := not( and( x, y ) ) = 1- min( x, y ) Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have: xor( x, y ) := min( max( x, y ), 1- min( x, y ) ) However, defining 'xor' as '( x and not y ) or ( y and not x )', we don't have: xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) ) Good question. From pdpinheiro at gmail.com Wed Jun 17 13:05:24 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 10:05:24 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> On Jun 17, 5:37?pm, Lie Ryan wrote: > Steven D'Aprano wrote: > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > >> I was staring at a logic table the other day, and I asked myself, "what > >> if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > > your mind like it did mine. > > > (This is not original to me -- I didn't create it. However, I can't find > > the original source.) > > > Imagine for a moment that there are no boolean values. > > There are no numbers. ?They were never invented. > > There are no classes. > > There are no objects. > > There are only functions. > > > Could you define functions that act like boolean values? And could you > > define other functions to operate on them? > > > def true(x, y): > > ? ? return x > > > def false(x, y): > > ? ? return y > > > def print_bool(b): > > ? ? print b("true", "false") > > String isn't considered object? > > Also, b/true()/false() is a function object, isn't it? Unless function > is first-class, you can't pass them around like that, since you need a > function pointer (a.k.a number); but if function is first-class then > there it is an object. What Steven was doing was implementing some of the more basic stuff from Lambda calculus in python. If you're implementing a different system in an existing language, you'll need to use _some_ facilities of the original language to interface with the outside world. Anyway, here's a sample interactive session I just tried: >>> def a(stuff): ... print stuff ... >>> def b(stuff): ... stuff("abc") ... >>> b(a) abc functions are first-class citizens in python. From brendandetracey at yahoo.com Wed Jun 17 13:06:20 2009 From: brendandetracey at yahoo.com (Brendan) Date: Wed, 17 Jun 2009 10:06:20 -0700 (PDT) Subject: exit() or sys.exit() References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: <005747ad-7f29-41b7-afed-3b592d7bc2b5@l12g2000yqo.googlegroups.com> On Jun 17, 1:33?pm, Tim Chase wrote: > Brendan wrote: > > What is the difference on exit() and sys.exit() when called in the > > main body of a script? From the command line they seem to have the > > same effect. > > In Python <=2.4 you had to use sys.exit() because > __builtins__.exit() griped: > > ? ?tchase at asgix:~$ python2.4 > ? ?Python 2.4.4 (#2, Apr 15 2008, 23:43:20) > ? ?[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 > Type "help", "copyright", "credits" or "license" for more > information. > ? ?>>> type(exit) > ? ? > ? ?>>> exit() > ? ?Traceback (most recent call last): > ? ? ?File "", line 1, in ? > ? ?TypeError: 'str' object is not callable > > In 2.5, it's an instance of site.Quitter which is callable, > allowing it to behave like sys.exit() ?(from my observations, > __builtins__.exit() and sys.exit() behave the same). > > I tend to use sys.exit() because I've still got code running on > machines mired at 2.4 > > -tkc Okay. Thanks. From castironpi at gmail.com Wed Jun 17 13:20:51 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:20:51 -0700 (PDT) Subject: Exotic Logics References: <140d5517-f5a1-4027-9b52-c19964bdcf7e@i6g2000yqj.googlegroups.com> Message-ID: On Jun 17, 10:04?am, Aaron Brady wrote: snip > You (OP) may be interested in the definitions of the fuzzy operators: > > and( x, y ) := min( x, y ) > or( x, y ) := max( x, y ) > not( x ) := 1 (one)- x > nand( x, y ) := not( and( x, y ) ) = 1- min( x, y ) > > Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have: > > xor( x, y ) := min( max( x, y ), 1- min( x, y ) ) > > However, defining 'xor' as '( x and not y ) or ( y and not x )', we > don't have: > > xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) ) Corollary: xor1( x, y ) === xor2( x, y ). Non-exhaustive demonstration, excerpt: >>> def xor1( x, y ): ... return min( max( x, y ), 1- min( x, y ) ) ... >>> def xor2( x, y ): ... return max( min( x, 1- y ), min( y, 1- x ) ) ... >>> for i in range( 0, 11, 2 ): ... for j in range( 0, 11, 2 ): ... print i, j, xor2( x, y )*10, ' ', ... print 0 0 0.0 0 2 2.0 0 4 4.0 0 6 6.0 0 8 8.0 2 0 2.0 2 2 2.0 2 4 4.0 2 6 6.0 2 8 8.0 4 0 4.0 4 2 4.0 4 4 4.0 4 6 6.0 4 8 6.0 6 0 6.0 6 2 6.0 6 4 6.0 6 6 4.0 6 8 4.0 8 0 8.0 8 2 8.0 8 4 6.0 8 6 4.0 8 8 2.0 10 0 10.0 10 2 8.0 10 4 6.0 10 6 4.0 10 8 2.0 They appear to be equal. I forgot to mention, fuzzy values take on values from the continuous open or closed range 0 to 1. From mensanator at aol.com Wed Jun 17 13:23:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 17 Jun 2009 10:23:59 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> Message-ID: <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> On Jun 17, 11:59?am, Aaron Brady wrote: > On Jun 17, 1:44?am, Steven D'Aprano > > > > wrote: > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > I was staring at a logic table the other day, and I asked myself, "what > > > if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > > your mind like it did mine. > > > (This is not original to me -- I didn't create it. However, I can't find > > the original source.) > > > Imagine for a moment that there are no boolean values. > > There are no numbers. ?They were never invented. > > There are no classes. > > There are no objects. > > There are only functions. > > > Could you define functions that act like boolean values? And could you > > define other functions to operate on them? > > snip > > I think high and low /voltages/, though continuous and approximate, > might satisfy this. > > There are no such things as electrons, I've got a Tesla coil if you'd like to meet some electrons personally. > only variations in density of > the luminiferous ether. From castironpi at gmail.com Wed Jun 17 13:30:39 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:30:39 -0700 (PDT) Subject: Exotic Logics References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: On Jun 17, 10:05?am, pdpi wrote: > On Jun 17, 5:37?pm, Lie Ryan wrote: > > > > > Steven D'Aprano wrote: > > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > >> I was staring at a logic table the other day, and I asked myself, "what > > >> if one wanted to play with exotic logics; how might one do it?" > > > > This might be useful for you, and if not useful, at least it might blow > > > your mind like it did mine. > > > > (This is not original to me -- I didn't create it. However, I can't find > > > the original source.) > > > > Imagine for a moment that there are no boolean values. > > > There are no numbers. ?They were never invented. > > > There are no classes. > > > There are no objects. > > > There are only functions. > > > > Could you define functions that act like boolean values? And could you > > > define other functions to operate on them? > > > > def true(x, y): > > > ? ? return x > > > > def false(x, y): > > > ? ? return y > > > > def print_bool(b): > > > ? ? print b("true", "false") > > > String isn't considered object? > > > Also, b/true()/false() is a function object, isn't it? Unless function > > is first-class, you can't pass them around like that, since you need a > > function pointer (a.k.a number); but if function is first-class then > > there it is an object. > > What Steven was doing was implementing some of the more basic stuff > from Lambda calculus in python. If you're implementing a different > system in an existing language, you'll need to use _some_ facilities > of the original language to interface with the outside world. Sir! Entropy levels are approaching dangerously low levels. We don't even have enough entropy to fi From castironpi at gmail.com Wed Jun 17 13:32:02 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:32:02 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> Message-ID: <1a554d09-a6c5-4cfa-99de-8252eb0a0195@r33g2000yqn.googlegroups.com> On Jun 17, 10:23?am, Mensanator wrote: > On Jun 17, 11:59?am, Aaron Brady wrote: > > > > > On Jun 17, 1:44?am, Steven D'Aprano > > > wrote: > > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > > I was staring at a logic table the other day, and I asked myself, "what > > > > if one wanted to play with exotic logics; how might one do it?" > > > > This might be useful for you, and if not useful, at least it might blow > > > your mind like it did mine. > > > > (This is not original to me -- I didn't create it. However, I can't find > > > the original source.) > > > > Imagine for a moment that there are no boolean values. > > > There are no numbers. ?They were never invented. > > > There are no classes. > > > There are no objects. > > > There are only functions. > > > > Could you define functions that act like boolean values? And could you > > > define other functions to operate on them? > > > snip > > > I think high and low /voltages/, though continuous and approximate, > > might satisfy this. > > > There are no such things as electrons, > > I've got a Tesla coil if you'd like to meet some electrons personally. The Wall Street Journal ran an article about Asian pleasure markets; they provide a-- quote-- "perfectly reasonable professional option". From castironpi at gmail.com Wed Jun 17 13:37:19 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:37:19 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> <1a554d09-a6c5-4cfa-99de-8252eb0a0195@r33g2000yqn.googlegroups.com> Message-ID: On Jun 17, 10:32?am, Aaron Brady wrote: > On Jun 17, 10:23?am, Mensanator wrote: snip > > > I think high and low /voltages/, though continuous and approximate, > > > might satisfy this. > > > > There are no such things as electrons, > > > I've got a Tesla coil if you'd like to meet some electrons personally. > > The Wall Street Journal ran an article about Asian pleasure markets; > they provide a-- quote-- "perfectly reasonable professional option". For shame, Lieutenant. Always cite your source. http://online.wsj.com/article/SB124416693109987685.html Last paragraph, second to last sentence. It was a book review of _The East, the West, and Sex_ by Richard Bernstein . From cameron.pulsford at gmail.com Wed Jun 17 13:41:07 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 13:41:07 -0400 Subject: Pythonic way to overwrite a file Message-ID: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Hey all, hopefully a simple question. I'm writing a simple python tool that opens a file, and does something like for line in file.readlines(): temp.write(line.doStuff()) However, I want to provide the option do this "in place", as in have the destination file be the same as the source file. Currently, I am writing to a temp file and then using "os.system('mv %s %s' % (dstfile, srcfile))" to copy the destination file onto the soruce file. This is extremely ugly though, and will only work on unix based systems (I'm guessing, unless windows has mv too). Is there a more pythonic way to do this? Ideally I'd like to change the file as I go through it and not deal with a second file at all. That wouldn't have any atomicity though... What would be the most pythonic+safest way to do this? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip.groeger at googlemail.com Wed Jun 17 13:58:14 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Wed, 17 Jun 2009 19:58:14 +0200 Subject: Create 3D Surface / Contour (with vpython?) Message-ID: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Hi! How can I create a 3D surface (or something like the picture on the FAQ page http://www.vpython.org/contents/FAQ.html ) with python [or vpython]. Didnt find anything in the Documentation under "graph" Basically like a contourf diagram in 3D ( http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think you know what I mean. Reason: I want to simulate waves in a square basin. Hope I dont need to use hundrets of little spheres (in case of vpython) for the surface ;) Thanks alot - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcharrow at csail.mit.edu Wed Jun 17 14:06:12 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Wed, 17 Jun 2009 14:06:12 -0400 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Message-ID: <4A393094.9090701@csail.mit.edu> Cameron Pulsford wrote: > Hey all, hopefully a simple question. > > I'm writing a simple python tool that opens a file, and does something like > > for line in file.readlines(): > temp.write(line.doStuff()) > > However, I want to provide the option do this "in place", as in have the > destination file be the same as the source file. > Is loading the whole file into memory an option? If so, this should work: filename = "spam.txt" lines = open(filename).readlines() # Read new = [somefunction(line) for line in lines] # Change open(filename, 'w').writelines(new) # Write If you want to stick with your original approach, but want it to work cross platform, then I think this is what you want: http://docs.python.org/library/shutil#shutil.move HTH, Ben From jeanmichel at sequans.com Wed Jun 17 14:09:04 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 20:09:04 +0200 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Message-ID: <4A393140.2060003@sequans.com> Cameron Pulsford wrote: > Hey all, hopefully a simple question. > > I'm writing a simple python tool that opens a file, and does something > like > > for line in file.readlines(): > temp.write(line.doStuff()) > > However, I want to provide the option do this "in place", as in have > the destination file be the same as the source file. Currently, I am > writing to a temp file and then using "os.system('mv %s %s' % > (dstfile, srcfile))" to copy the destination file onto the soruce > file. This is extremely ugly though, and will only work on unix based > systems (I'm guessing, unless windows has mv too). Is there a more > pythonic way to do this? Ideally I'd like to change the file as I go > through it and not deal with a second file at all. That wouldn't have > any atomicity though... What would be the most pythonic+safest way to > do this? > > Thanks in advance > Altering directly the file is dangerous, what if something goes wrong during the process ? Create a temp file and copying it if successful is your best bet. I guess using python modules like tempfile and shutil are a pythonic way to do it : import tempfile import shutil In [14]: tempfile.NamedTemporaryFile? Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, suffix='', prefix='tmp', dir=None) Docstring: Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to os.fdopen (default "w+b"). 'bufsize' -- the buffer size argument to os.fdopen (default -1). The file is created as mkstemp() would do it. Returns an object with a file-like interface; the name of the file is accessible as file.name. The file will be automatically deleted when it is closed. In [7]: shutil.copy? Definition: shutil.copy(src, dst) Docstring: Copy data and mode bits ("cp src dst"). The destination may be a directory. From cameron.pulsford at gmail.com Wed Jun 17 14:26:07 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 14:26:07 -0400 Subject: Pythonic way to overwrite a file In-Reply-To: <4A393140.2060003@sequans.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> Message-ID: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Essentially it just cleans up a source file of erroneous spaces and tabs and can also convert tabs to spaces so loading the whole file into memory is possibly an option. I am making this utility for personal use, and that would definitely be fine, but if it turned out well I'd open source it and then I wouldn't be so sure. This is only supposed to handle text files, so when would reading it all into memory become too much for most computers? I'm guessing there aren't many source files of too great a size. On Wed, Jun 17, 2009 at 2:09 PM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Cameron Pulsford wrote: > >> Hey all, hopefully a simple question. >> >> I'm writing a simple python tool that opens a file, and does something >> like >> >> for line in file.readlines(): >> temp.write(line.doStuff()) >> >> However, I want to provide the option do this "in place", as in have the >> destination file be the same as the source file. Currently, I am writing to >> a temp file and then using "os.system('mv %s %s' % (dstfile, srcfile))" to >> copy the destination file onto the soruce file. This is extremely ugly >> though, and will only work on unix based systems (I'm guessing, unless >> windows has mv too). Is there a more pythonic way to do this? Ideally I'd >> like to change the file as I go through it and not deal with a second file >> at all. That wouldn't have any atomicity though... What would be the most >> pythonic+safest way to do this? >> Thanks in advance >> >> > Altering directly the file is dangerous, what if something goes wrong > during the process ? > Create a temp file and copying it if successful is your best bet. > > I guess using python modules like tempfile and shutil are a pythonic way > to do it : > > import tempfile > import shutil > > In [14]: tempfile.NamedTemporaryFile? > Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, > suffix='', prefix='tmp', dir=None) > Docstring: > Create and return a temporary file. > Arguments: > 'prefix', 'suffix', 'dir' -- as for mkstemp. > 'mode' -- the mode argument to os.fdopen (default "w+b"). > 'bufsize' -- the buffer size argument to os.fdopen (default -1). > The file is created as mkstemp() would do it. > > Returns an object with a file-like interface; the name of the file > is accessible as file.name. The file will be automatically deleted > when it is closed. > > > In [7]: shutil.copy? > Definition: shutil.copy(src, dst) > Docstring: > Copy data and mode bits ("cp src dst"). > > The destination may be a directory. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcfletch at vrplumber.com Wed Jun 17 14:44:42 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Wed, 17 Jun 2009 14:44:42 -0400 Subject: Observer implementations In-Reply-To: References: Message-ID: <4A39399A.1030106@vrplumber.com> Tobias Weber wrote: > In article , > "Mike C. Fletcher" wrote: > > >> See PyDispatcher for code to do this. >> > > That was the original problem. Got it now: if used inside the class > definition dispatcher.connect will raise "cannot create weak reference > to 'classmethod' object". Outside (using Class.method) it works fine. > Ah, I think you've got a logic problem there. The classmethod during class creation has no reference to the class being created, so if you were to call *that* thing it would blow up: class x( object ): @classmethod def y( cls, text ): print text y( 'No you do not!' ) if you were to create a reference to *that* thing (the decorated un-bound class method) it would never have the binding for cls, so it wouldn't do anything. The correct way IMO to bind after-class-creation (e.g. by a class decorator or metaclass) where you reference a bound class method. If you *really* want to do it this way, you can do something like this: class x( object ): @classmethod def y( cls, value ): pass dispatcher.connect( lambda *args: x.y( *args ), signal='hello' ) but ick. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From ken at seehart.com Wed Jun 17 14:56:33 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 17 Jun 2009 11:56:33 -0700 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <4A393C61.3060504@seehart.com> abhishek goswami wrote: > Hi, > I have very basic question about Python that do we consider pyhton as > script language. > I searched in google but it becomes more confusion for me. After some > analysis I came to know that Python support oops . > > Can anyone Guide me that Python is Oject oriented programming language > or Script language > > Abhishek Goswami > Chennai > Phone No -0996227099 > ------------------------------------------------------------------------ > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > Both. Especially if you define the terms "object oriented" and "scripting" in terms of positive space (attributes that are present) instead of negative space (attributes that are not present). Python has all of the important features of OOP, but lacks some of the imposed constraints that some consider to be part of the definition of OOP (I personally do not consider the constraints to be central to a useful definition of OOP) Python has all of the important features that one would want in a scripting language (although it has a larger memory footprint than some scripting languages), but lacks many of limitations associated with "toy languages". Python is somewhat unique in it's ability to fill both of these areas so well without being unnatural. In my opinion, it is extremely useful to have one language that serves as both a highly scalable full-featured OOP language and as an extremely simple scripting language, because it allows one to build a large complex system within which one can easily do scripting tasks. Proof that python is a scripting language: print "Hello world" Proof that python is an OOP language benefiting from scripting capabilities: Django comes to mind. There are hundreds of others out there, but instead of listing them, I think I will get back to programming. Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jun 17 15:03:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Jun 2009 15:03:12 -0400 Subject: Regarding Python is scripting language or not In-Reply-To: <20090617123540.GA19607@wasteland.homelinux.net> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Jochen Schulz wrote: > abhishek goswami: >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language > > In my opinion, Python is both. But an "objective" answer would require > you to define what you means by these terms. > > If, by "object-oriented" you mean "everything has to be put into > classes", then Python is not object-oriented. That depends on what you mean by 'put into classes' (and 'everything'). If you mean 'be an instance of a class', which I think is the most natural reading, then Python *is* object-oriented and, if I understand what I have read correctly (so that ints are just (unboxed) ints and not members of an int class), Java *is not*! If you mean 'be an attribute of a class' (which to me is not 'in') or textually located within a class statement, then I doubt an language qualifies. It is impossible for every class statement to lie within a class statement and I wonder whether any language requires all classes to be attributes of some class (as opposed to subclasses or instances). However, if 'everything' means 'everything but classes', then, as I understand, Java and some others qualify. If fact, if one views modules as classes that cannot be instanced or as classes with one instance, themselves, then Python also qualifies. Python also qualifies if you mean 'be in some attribute of a class' and view modules as classes. *All* modules are values of sys.modules, including builtins, __main__, and sys itself. > If, by "scripting > language" you mean Python is an error-prone toy language, unsuitable for > large, serious projects, then Python is not a scripting language either. On the other hand, CPython is designed to be extended by and thereby script code written in C and C-wrapped Fortran. This is a big part of why it uses reference-counting for garbage collection. It also has functions for running other processes and interacting with other processes. Terry Jan Reedy From mr.william.clifford at gmail.com Wed Jun 17 15:05:00 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Wed, 17 Jun 2009 12:05:00 -0700 (PDT) Subject: Exotic Logics References: Message-ID: On Jun 17, 1:28?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > First question: what's an exotic logics? > > Do you mean things like three-value logic, fuzzy logic, probabilistic > reasoning, etc? > > Or do you mean logical operators others than and, or, xor, nand, nor, etc? > > Or both? Something else? The short answer is 'yes'. Obviously, I don't know much about this stuff. I was looking a table of different operators and their truth values and saw that these were just different ways of reading and comparing numbers. I wrote this code to explore this idea in a general sense and see where it leads and learn something about computers. > [...] > > If (nearly) all your methods are static methods, chances are a class is > the wrong solution. Why not just define the static methods as top-level > functions? That is exactly how they started. I wrapped them up in an class because I thought I might want to create a bunch of them for testing and experimentation. I'm curious to see how combinations of functions give the same (or different) results. I've read one can do all of the 16 binary operations with clever uses of NAND or NOR. [SNIP] > You're implementation seems rather confusing. I think that's partly > because you use lots of abbreviated jargon terms that mean little or > nothing to me: rdx, opr (operator?), lsd, pute. Sorry about the confusion. It's because I'm confused. I should check out a book on the subject. Thanks for your help. -- William Clifford From jholloway7 at gmail.com Wed Jun 17 15:08:08 2009 From: jholloway7 at gmail.com (Joe Holloway) Date: Wed, 17 Jun 2009 14:08:08 -0500 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906171057s2f183a06re7779afaf2f529a6@mail.gmail.com> References: <8fe048f70906171057s2f183a06re7779afaf2f529a6@mail.gmail.com> Message-ID: <8fe048f70906171208m7b652c5dj30011788fb025a2a@mail.gmail.com> Christian wrote: > > Joe Holloway schrieb: > > ImportError: Failed to import _strptime because the import lockis > > [sic] held by another thread. > > The error message is my fault. The cause of the mistake is obvious: No worries. The error message is clear even with the minor typo, I just wanted to recreate it here in case someone is searching for it down the road. > > Like I mentioned, it's only happened on a couple occasions because the > > right conditions have to be in place, but something doesn't seem right > > about it. ?I thought I'd ask on the mailing list before going so far > > as to open a ticket, but feel free to direct me there if that's the > > appropriate place for this. > > I have an idea what might happen in your application. Is an import > triggering the start of a thread? Not that I'm aware of. When the error is triggered, my module is simply calling into a library that's then calling into time.striptime(). The import that fails seems to be just a side effect of this. > You can get around the issue by decoupling imports from thread > startups. Your application should import all modules before it > starts its threaded components. To give you a better idea of the scenario, this is a Django web application deployed inside a WSGI container (mod_wsgi+Apache2). Ultimately, I'm not sure I have any control over when the imports occur since the WSGI container is what's managing the threads and my application is just being plugged into that container, if that makes sense. Consider that two URL handlers are likely be implemented in separate modules and hence both require a different set of imports. If both are served concurrently and one of them is making the first call to strptime while the other one has acquired the import lock, this can fail. Failing is obviously better than deadlocking, but it seems like pushing the workaround higher up in the call stack would cause some serious abstraction leaks. I don't fully understand what was causing the original deadlock, but my module should be able to call into time.strptime without incurring an ImportError or a deadlock under any circumstance? > For now you can decrease the severity of your issue by placing "import > _strptime" next to "import time" somewhere in your code. Once it a > module is loaded PyImport_ImportModuleNoBlock() will not fail to import > it a second time. Thanks for the workaround. I'm not all that concerned about the functional impact this has on my application since it has only happened a couple of times over the course of 6 weeks or so. My intent was more to make it visible in case there's a deeper design issue that can be addressed. Take care, Joe From vinay_sajip at yahoo.co.uk Wed Jun 17 15:15:34 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 17 Jun 2009 12:15:34 -0700 (PDT) Subject: A simpler logging configuration file format? References: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Message-ID: On Jun 5, 9:07?pm, geoff.ba... at gmail.com wrote: > Hi all, Some discussion about this has already taken place on the issue tracker: http://bugs.python.org/issue6136 and I thought I would summarise my comments there on this thread, for people who have no need to look at that issue. > At the moment, if I want to add a new logger "foo" writing to its own > file "foo" to my config file, I have to repeat the name 7(!) times, > editing 3 different sections in the process: Strictly speaking, you don't need to repeat the name "foo" 7 times. > 1) Add "foo" to [loggers] and [handlers]. (These seem completely > pointless and were apparently added in anticipation of new > functionality that never happened). You don't have to call the logger "foo" and the handler "foo". The names in the [loggers] and [handlers] section are just to allow the system to cross-refer different entities (loggers, handlers, formatters) declared in the config file. You could give the logger a name of "L1" and the handler a name of "H1", for example. > 2) Create the section > [logger_foo] > handler:foo > qualname:foo > level:INFO Here, if you named your logger L1, the section would be [logger_L1], not [logger_foo]. If you called your handler H1, then the handler line would be handlers=H1. The qualname is "foo" because you choose to log events to the logger named "foo". It could be more specific, e.g. "myapp.mymodule.myfunctionalarea". > 3) Create the section > [handler_foo] > class: FileHandler > args:("foo", "a") Here, if you named your handler H1, the section would be [handler_H1], not [handler_foo]. You've also called the log file "foo", which more conventionally you might name "foo.log". In your simple example where everything is named foo, and you've chosen to call cross-referencing handles within the file "foo", then naturally you repeat "foo" a lot of times. In an equivalent file [loggers] keys=root,L1 [handlers] keys=H1 [logger_L1] level=INFO handlers=H1 qualname=foo [handler_H1] class=FileHandler args=('foo.log', 'w') "foo" only occurs twice. > Wondering how it got like this, I found this blog from soon after it > was released in 2004: > > http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Pytho... > > Some of the verdicts are "full of dead chickens and error prone", > "horribly complicated" , "over-engineered". So along comes the > "basicConfig" method in 2005 which is supposed to address thes > concerns. But this can only be applied globally, not even to > individual loggers, so is only helpful for extremely basic usage > (everything to one target) as far as I can see. The config file is > still much as it was then. Some of this is just a consequence of using ConfigParser. The existing file format is not perfect or even complete (for example - no support for filters), and was proposed on python-dev for review before the logging package went into Python. The general consensus was that it was OK for basic use, and IIRC several people considered it as +0 or -0 because they envisaged doing their own thing (e.g. having the logging configuration as just part of an application's overall configuration). This is the reason configuration was put in a separate sub-module - if it's not needed, it needn't be loaded. AFAICT since basicConfig was introduced and later refined, there has not been much feedback about the configuration file format being a problem - and while that could be because no-one is using it, that's not borne out by the evidence. There have been numerous instances on c.l.py where questions have been raised about how to specify custom handlers in the configuration file, so at least some people are using it or have used it (the configuration functionality, I mean). > I'd really like to see the concept extended to encompass multiple > loggers and the config file. Allowing Logger.basicConfig should be > trivial. Writing a configuration format which took a section and > passed all the options in it to basicConfig would in my view lead to a > much friendlier syntax for normal usage. Well, basicConfig is for basic configuration of the logging package as a whole, not for configuring individual loggers or handlers. It's best not to conflate loggers and handlers - basicConfig might appear to do this because its arguments are partly specifying handler configuration and partly logger configuration. This is because it's the simplest case - one logger (the root logger) and one handler (according to the relevant arguments passed in). The handler-related arguments are used to create a default handler and/or formatter, the logging level is specified by the level argument, and it's applied to the root logger. It doesn't make sense to use the same approach if you are going to configure multiple loggers and handlers; if the existing format is not palatable, it's relatively easy to create your own format and write code to parse it and load it, and then call the programmatic API to configure logging appropriately. You mentioned on the bug tracker that you are coming from a background of using log4py - in which I believe loggers provide the functionality which is found in handlers in Python's logging. If you believe you have an idea for a much simpler configuration format (perhaps for simpler use cases, or perhaps for general use) I would encouraging writing an implementation and putting it up on PyPI so that people can play around with it and give feedback. ISTM that there is a general feeling that any sizeable new or changed functionality intended for the stdlib should be proven in the community through wide use before being seriously considered for inclusion. For example, I wrote a hierarchical configuration module, just one of several configuration-related modules on PyPI: http://pypi.python.org/pypi?%3Aaction=search&term=config&submit=search However, I am not proposing it for inclusion in the stdlib, as I don't believe it has had enough feedback yet from the community to be able to accurately gauge its quality or utility. From tjreedy at udel.edu Wed Jun 17 15:23:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Jun 2009 15:23:37 -0400 Subject: Exotic Logics In-Reply-To: References: Message-ID: William Clifford wrote: > same (or different) results. I've read one can do all of the 16 > binary > operations with clever uses of NAND or NOR. The book Laws of Form, by Spencer-Brown' is based on that observation, with nand/nor expanded to n-ary 'bag' functions (like sum() is). I recommend it, especially if you can find it in a library. tjr From lists at cheimes.de Wed Jun 17 15:25:08 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Jun 2009 21:25:08 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Terry Reedy wrote: > If you mean 'be an instance of a class', which I think is the most > natural reading, then Python *is* object-oriented and, if I understand > what I have read correctly (so that ints are just (unboxed) ints and not > members of an int class), Java *is not*! A friend of mine calls Java and C++ class centric programming languanges. ;) Christian From gokhansever at gmail.com Wed Jun 17 15:43:43 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 17 Jun 2009 14:43:43 -0500 Subject: Create 3D Surface / Contour (with vpython?) In-Reply-To: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> References: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Message-ID: <49d6b3500906171243g1a3df390pa4f95b7fad103efe@mail.gmail.com> On Wed, Jun 17, 2009 at 12:58 PM, Philip Gr?ger < philip.groeger at googlemail.com> wrote: > Hi! > How can I create a 3D surface (or something like the picture on the FAQ > page http://www.vpython.org/contents/FAQ.html ) with python [or vpython]. > Didnt find anything in the Documentation under "graph" > Basically like a contourf diagram in 3D ( > http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think > you know what I mean. > > Reason: I want to simulate waves in a square basin. Hope I dont need to use > hundrets of little spheres (in case of vpython) for the surface ;) > > Thanks alot > > - Philip > -- > http://mail.python.org/mailman/listinfo/python-list > > I suggest two alternatives, second one being the fancier: http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo.html http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#enthought.mayavi.mlab.surf -------------- next part -------------- An HTML attachment was scrubbed... URL: From Samnsparky at gmail.com Wed Jun 17 15:56:11 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 17 Jun 2009 12:56:11 -0700 (PDT) Subject: SHM and Touchpad Message-ID: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Hello! I am writing an application that requires access to the state of a synaptics touch pad on a laptop running Ubuntu Linux (for the number of fingers, pressure, x location, y location, etc). A different program using C++ accesses the information through SHM and I was hoping to do the same with Python. I looked in PyPi and I noticed that there was a module for SHM but I can not figure out where to download it from (http://pypi.python.org/pypi/shm). Does anyone have any suggestions? Thanks, Sam From jcd at sdf.lonestar.org Wed Jun 17 16:03:21 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 17 Jun 2009 16:03:21 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A38DDDB.5070309@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> Message-ID: <1245269001.27277.28.camel@aalcdl07> On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> What's np.arange? > >> > > > > import numpy as np > > > > -- > > Pierre "delroth" Bourdon > > ?tudiant ? l'EPITA / Student at EPITA > > > > Perfect example of why renaming namespaces should be done only when > absolutely required, that is, almost never. > > Jean-Michel I disagree. Renaming namespaces should always be done if it will help stop people from doing a 'from package import *'. However, example code should always include relevant imports. Cheers, Cliff From martin.hellwig at dcuktec.org Wed Jun 17 16:05:09 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 21:05:09 +0100 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: edexter wrote: > > it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 > Redistributable Package > did not help.. I had simular problems > with alot of installers I had saved (from installing on xp) but when > I grabbed newer installers > they all worked, could be the manifast.... I was looking forward to > trying it out.. > > Did you tried this one? http://www.microsoft.com/downloads/details.aspx?FamilyID=200b2fd9-ae1a-4a14-984d-389c36f85647&displaylang=en Found via: http://lmgtfy.com/?q=Microsoft+Visual+C%2B%2B+2005+SP1+Redistributable+Package+(x86)&l=1 -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From mani at tungle.com Wed Jun 17 16:05:48 2009 From: mani at tungle.com (Mani Ghasemlou) Date: Wed, 17 Jun 2009 16:05:48 -0400 Subject: logging.fileConfig limitations? Message-ID: Hi all, I have an application that writes out its logs in a subfolder of the user's local data directory. Let's say our user's name is "?????2". On my Windows XP machine, this logging path turns out to be: C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.log My application has a "bootstrap" kind of application that sets up the application's subfolder and writes out the log config file. Notice that the user's name contains non-ASCII characters. So, I encode the path in UTF8 format before writing the log config file. My resulting log config is (the last line is the most important): ----- BEGIN [formatters] keys: normal [handlers] keys: rotatingfile [loggers] keys: root [formatter_normal] format: %(asctime)s %(levelname)s %(module)s: %(message)s [logger_root] level: DEBUG handlers: rotatingfile [handler_rotatingfile] class: handlers.RotatingFileHandler formatter: normal args: ["C:/Documents and Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log", "a", 2*1024*1024, 5, None] ----- END Now it turns out that the logging module can't find "C:/Documents and Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log" specified in the "args" section, and rightfully so because this is an encoded string. *There does not seem to be a way for me to specify the encoding of the string so that the logging module resolves the proper unicode path.* This is my key problem! Is there some way to accomplish what I want? One interesting observation: I did some poking around in the logging module shipped with Python 2.5. I put in some code in the Python logging module to force UTF8 decoding of the "filename" argument, the result of which was interesting: it would end up logging in "C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.txt" (not MyApp.log !). I've done a little debugging and can't immediately figure out why this is happening. Any help would be greatly appreciated! Regards, Mani From philip at semanchuk.com Wed Jun 17 16:09:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Jun 2009 16:09:18 -0400 Subject: SHM and Touchpad In-Reply-To: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: On Jun 17, 2009, at 3:56 PM, Sparky wrote: > Hello! I am writing an application that requires access to the state > of a synaptics touch pad on a laptop running Ubuntu Linux (for the > number of fingers, pressure, x location, y location, etc). A different > program using C++ accesses the information through SHM and I was > hoping to do the same with Python. I looked in PyPi and I noticed that > there was a module for SHM but I can not figure out where to download > it from (http://pypi.python.org/pypi/shm). Does anyone have any > suggestions? Hi Sam, I'm not familiar with that shm, however there was (and still is) a old Python IPC module called shm. It uses Sys V semaphores, not POSIX semaphores like the shm in pypi. The old shm module has been replaced by two newer ones. For Sys V IPC: http://semanchuk.com/philip/sysv_ipc/ For POSIX IPC: http://semanchuk.com/philip/posix_ipc/ The old shm module is still around on semanchuk.com but I'm not updating it anymore (the author is AWOL and I'm just the maintainer) and I don't recommend using it. HTH Philip From Samnsparky at gmail.com Wed Jun 17 16:13:39 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 17 Jun 2009 13:13:39 -0700 (PDT) Subject: SHM and Touchpad References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: On Jun 17, 2:09?pm, Philip Semanchuk wrote: > On Jun 17, 2009, at 3:56 PM, Sparky wrote: > > > Hello! I am writing an application that requires access to the state > > of a synaptics touch pad on a laptop running Ubuntu Linux (for the > > number of fingers, pressure, x location, y location, etc). A different > > program using C++ accesses the information through SHM and I was > > hoping to do the same with Python. I looked in PyPi and I noticed that > > there was a module for SHM but I can not figure out where to download > > it from (http://pypi.python.org/pypi/shm). Does anyone have any > > suggestions? > > Hi Sam, > I'm not familiar with that shm, however there was (and still is) a old ? > Python IPC module called shm. It uses Sys V semaphores, not POSIX ? > semaphores like the shm in pypi. > > The old shm module has been replaced by two newer ones. For Sys V IPC:http://semanchuk.com/philip/sysv_ipc/ > > For POSIX IPC:http://semanchuk.com/philip/posix_ipc/ > > The old shm module is still around on semanchuk.com but I'm not ? > updating it anymore (the author is AWOL and I'm just the maintainer) ? > and I don't recommend using it. > > HTH > Philip Dear Philip, Thank you for your quick response, I will take a look at the link you provided. From manu3d at gmail.com Wed Jun 17 16:17:13 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 17 Jun 2009 13:17:13 -0700 (PDT) Subject: etree, lxml unexpected behaviour Message-ID: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> Hi everybody, I just tried the following: >>> import xml.etree.ElementTree as etree >>> e = etree.fromstring('') >>> e.getchildren()[0].attrib {'anAttr': '1', '{anotherNamespace}anotherAttr': '2'} Notice the lack of namespace before the attribute "anAttr". I find this unexpected because as you can see I did set the default namespace with xmlns="aNamespace" and the elements (rather than the attributes) are correctly associated with it, i.e.: >>> e Is there a way to change this behaviour so that attributes without namespace are correctly associated with the default namespace, just like the elements? lxml exhibit the exact same behaviour. Manu From lie.1296 at gmail.com Wed Jun 17 16:22:03 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 20:22:03 GMT Subject: SHM and Touchpad In-Reply-To: References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: Sparky wrote: > > Thank you for your quick response, I will take a look at the link you > provided. Depending on what you're trying to do, you may be able to use `synclient` with subprocess. From cameron.pulsford at gmail.com Wed Jun 17 16:35:58 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 16:35:58 -0400 Subject: Reading and setting file permissions programmatically Message-ID: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Sorry to flood the list but my google fu isn't up to par today I guess. Basically, is it possible to read the permissions on one file and then set the permissions of another file to the ones we just read? os.dup2 seemed like it would work but I might not be using it correctly. I know there is os.chmod, but I haven't found the equivalent to read permissions. Preferably this would work on unix and windows too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Wed Jun 17 16:36:31 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 20:36:31 GMT Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: Jean-Michel Pichavant wrote: > abhishek goswami wrote: >> Hi, >> I have very basic question about Python that do we consider pyhton as >> script language. >> I searched in google but it becomes more confusion for me. After some >> analysis I came to know that Python support oops . >> >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language >> >> Abhishek Goswami >> Chennai >> Phone No -0996227099 >> >> >> ------------------------------------------------------------------------ >> ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET >> > Depends on what you are calling a scripting language. > Refering to wikipedia, > "A *scripting language*, *script language* or *extension language* is a > programming language > that allows some control of a single or many software application(s) > ." > > Python is definitely OOP oriented and I don't think it fits in the > script definition above. Python is multiparadigm. It is a mix of OOP language and functional language. It does not force you to use certain paradigm and allows you to mix paradigms in a single piece of code. Python is a programming language when referring to the stand-alone virtual machine. Python is a scripting language when used inside OpenOffice.org or Inkscape or GIMP or Blender or other software that uses python as scripting language. You may also argue that python is a scripting language for the OS. IMHO, whether a language is scripting language or programming language is independent of the language (Python, Java, Basic, C, etc) nor the implementation (CPython, Sun's JVM, VB, GCC, etc) of the language, but instead tied to the usage of the language (Stand-alone Python vs. python on OpenOffice/Blender/GIMP/Inkscape, Standalone Java vs. browser-based Java, VB vs. VBA/VBScript, etc). > Python is interpreted and platform independent, but you can still build > standalone platform dependent binaries if required. > > Regarding your last question, I'm not sure scripting and OOP language > are not compatible, I'm pretty sure you'll be able to find OOP scripting > language. > > Jean-Michel From stefan_ml at behnel.de Wed Jun 17 16:58:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Jun 2009 22:58:06 +0200 Subject: etree, lxml unexpected behaviour In-Reply-To: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> References: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> Message-ID: <4a3958de$0$30230$9b4e6d93@newsspool1.arcor-online.net> Emanuele D'Arrigo wrote: > Hi everybody, I just tried the following: > >>>> import xml.etree.ElementTree as etree >>>> e = etree.fromstring('') >>>> e.getchildren()[0].attrib > {'anAttr': '1', '{anotherNamespace}anotherAttr': '2'} > > Notice the lack of namespace before the attribute "anAttr". I find > this unexpected because as you can see I did set the default namespace > with xmlns="aNamespace" and the elements (rather than the attributes) > are correctly associated with it, i.e.: > >>>> e > > > Is there a way to change this behaviour so that attributes without > namespace are correctly associated with the default namespace, just > like the elements? There isn't, because this is the correct behaviour according to the spec. http://www.w3.org/TR/REC-xml-names/#defaulting """ A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. """ Stefan From python at mrabarnett.plus.com Wed Jun 17 17:09:41 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Jun 2009 22:09:41 +0100 Subject: Reading and setting file permissions programmatically In-Reply-To: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> References: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Message-ID: <4A395B95.3070801@mrabarnett.plus.com> Cameron Pulsford wrote: > Sorry to flood the list but my google fu isn't up to par today I guess. > > Basically, is it possible to read the permissions on one file and then > set the permissions of another file to the ones we just read? os.dup2 > seemed like it would work but I might not be using it correctly. > > I know there is os.chmod, but I haven't found the equivalent to read > permissions. Preferably this would work on unix and windows too. > os.stat(path).st_mode From manu3d at gmail.com Wed Jun 17 17:15:52 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 17 Jun 2009 14:15:52 -0700 (PDT) Subject: etree, lxml unexpected behaviour References: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> <4a3958de$0$30230$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <3083d542-26ab-4b57-87b9-a848181e7bcc@w40g2000yqd.googlegroups.com> Thank you for the clarification Stefan, I understand. From philr at aspexconsulting.co.nz Wed Jun 17 17:18:04 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Thu, 18 Jun 2009 09:18:04 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: Because it reminds me of when things went badly wrong. IBM360, Von Neumann architecture, no hardware stacks ... IMHO Burroughs and ICL had better approaches to OS design back then but had less resources to develop their ideas. However, mainly this period marked a transition from the excitement and discovery phase of computing to commercial power plays and take-overs. The best ideas in a field tend to get lost in the melee of competition. Early computers were rooted in academia and there was a lot of cross fertilisation of ideas and approaches. IMHO commerce affected layers of the stack where it had no useful contribution to make. Vertical integration warred against sound architecture. The book has an important message and I recommend that people read it. The book is to me, and possibly only me, an icon representing when things went wrong. -----Original Message----- From: Lawrence D'Oliveiro [mailto:ldo at geek-central.gen.new_zealand] Sent: Wednesday, 17 June 2009 5:50 p.m. To: python-list at python.org Subject: RE: Good books in computer science? In message , Phil Runciman wrote: > FWIW I actually dislike this book! Why? From lie.1296 at gmail.com Wed Jun 17 17:21:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 21:21:27 GMT Subject: Exotic Logics In-Reply-To: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: pdpi wrote: > On Jun 17, 5:37 pm, Lie Ryan wrote: >> Steven D'Aprano wrote: >>> On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: >>>> I was staring at a logic table the other day, and I asked myself, "what >>>> if one wanted to play with exotic logics; how might one do it?" >>> This might be useful for you, and if not useful, at least it might blow >>> your mind like it did mine. >>> (This is not original to me -- I didn't create it. However, I can't find >>> the original source.) >>> Imagine for a moment that there are no boolean values. >>> There are no numbers. They were never invented. >>> There are no classes. >>> There are no objects. >>> There are only functions. >>> Could you define functions that act like boolean values? And could you >>> define other functions to operate on them? >>> def true(x, y): >>> return x >>> def false(x, y): >>> return y >>> def print_bool(b): >>> print b("true", "false") >> String isn't considered object? >> >> Also, b/true()/false() is a function object, isn't it? Unless function >> is first-class, you can't pass them around like that, since you need a >> function pointer (a.k.a number); but if function is first-class then >> there it is an object. > > What Steven was doing was implementing some of the more basic stuff > from Lambda calculus in python. If you're implementing a different > system in an existing language, you'll need to use _some_ facilities > of the original language to interface with the outside world. Anyway, > here's a sample interactive session I just tried: > >>>> def a(stuff): > .... print stuff > .... >>>> def b(stuff): > .... stuff("abc") > .... >>>> b(a) > abc > > functions are first-class citizens in python. I've just reread my sentence, and even I wouldn't have understood (or would misunderstood) what I was talking about if it was worded like that. What I meant was: if you can pass a function as an argument to another function, that means either: 1) you must use function pointer (numbers) or 2) function is a first-class object. Both violates the restriction (no number and no object respectively). Even after abandoning the semantics of functions in python, going to function as in purely mathematical sense, I still am not convinced (warning: I don't know lambda calculus, although I program in heavily functional style). PS: the string comment was meant to be a joke... From basti.wiesner at gmx.net Wed Jun 17 17:41:53 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Wed, 17 Jun 2009 23:41:53 +0200 Subject: exit() or sys.exit() References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: > What is the difference on exit() and sys.exit() when called in the > main body of a script? From the command line they seem to have the > same effect. As of Python 2.5 there is no difference, however documentation [1] says about exit() and quit(): > They are useful for the interactive interpreter shell and should not be > used in programs. [1] http://docs.python.org/library/constants.html#constants-added-by-the- site-module -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From alan.isaac at gmail.com Wed Jun 17 18:00:38 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 22:00:38 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> Message-ID: On 6/17/2009 4:03 PM J. Cliff Dyer apparently wrote: > example code > should always include relevant imports. Agreed. It was a cut and paste failure. Apologies. Alan Isaac From kyrie at uh.cu Wed Jun 17 18:03:08 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Wed, 17 Jun 2009 18:03:08 -0400 Subject: Exotic Logics In-Reply-To: References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: <1245276188.4a39681ca6b3b@mail.uh.cu> Quoting Lie Ryan : > pdpi wrote: > > On Jun 17, 5:37 pm, Lie Ryan wrote: > >> Steven D'Aprano wrote: > >>> On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > >>>> I was staring at a logic table the other day, and I asked myself, "what > >>>> if one wanted to play with exotic logics; how might one do it?" > >>> This might be useful for you, and if not useful, at least it might blow > >>> your mind like it did mine. > >>> (This is not original to me -- I didn't create it. However, I can't find > >>> the original source.) > >>> Imagine for a moment that there are no boolean values. > >>> There are no numbers. They were never invented. > >>> There are no classes. > >>> There are no objects. > >>> There are only functions. > >>> Could you define functions that act like boolean values? And could you > >>> define other functions to operate on them? > >>> [basic lambda calculus definitions] [...] > What I meant was: if you can pass a function as an argument to another > function, that means either: 1) you must use function pointer (numbers) > or 2) function is a first-class object. Both violates the restriction > (no number and no object respectively). > > Even after abandoning the semantics of functions in python, going to > function as in purely mathematical sense, I still am not convinced > (warning: I don't know lambda calculus, although I program in heavily > functional style). You are confusing semantics with implementation. At some point, of course one would need to use real object (at the lowest level, the computer I'm typing this in is a physical object). But the interesting part is that you can define the whole logic system using nothing but functions. You may need to implement it using objects, or maybe you could devise a machine that will behave like that using only sticks on the floor, but that doesn't matter. From the user's perspective, there would be only functions: no strings, no objects, no numbers. That reminds me of my last class (disclaimer: I teach discrete math). I told my students "well, let's assume that numbers exist", and I wasn't making fun of them... I found that topic easier to understand (computability, primitive recursion) if one ignores the numbers, even if one obviously has to write them somewhere at some point. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From alan.isaac at gmail.com Wed Jun 17 18:07:28 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 22:07:28 GMT Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: On 6/17/2009 8:38 AM Jean-Michel Pichavant apparently wrote: > I'm pretty sure you'll be able to find OOP scripting > language. fwiw, Alan Isaac From steven.samuel.cole at gmail.com Wed Jun 17 18:19:38 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Wed, 17 Jun 2009 15:19:38 -0700 (PDT) Subject: generator expression works in shell, NameError in script Message-ID: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Hello, I am trying to generate this list of tuples: [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] My code works fine in the Python shell: >>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>> title_choices [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] The same code run in a script fails with NameError: global name 'titles' is not defined Does anybody know why ? How can I fix the error ? Thank you very much :-) Steve From bearophileHUGS at lycos.com Wed Jun 17 18:22:41 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Wed, 17 Jun 2009 15:22:41 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <37cc0e5b-6ecd-42b9-8f81-74feb51240ec@j18g2000yql.googlegroups.com> Nathan Stoddard: > The best way to become a good programmer is to program. Write a lot of > code; work on some large projects. This will improve your skill more than > anything else. It's also important to learn new languages regularly. I > recommend to learn C, Python, and Lisp first. To become very good in a practical activity (like programming or writing stories or playing piano) you have to do many things for a lot of time. You have to practice it a lot, but that's not enough. You also must keep pushing forward the limit of your skills, doing things hard for you. Reading smart books and learning from the experts in the field is usually necessary. Quite often it's useful to read good books not much related with the activity you are doing too, because the human mind works better this way. Another thing you have to do is to keep your eyes open, for example to be able to understand when your learning is struck in some slow corner: now and then you will have to meta-learn, that is to change the way you learn and train yourself. This is a hard and often painful thing to do, but it's probably necessary if you want to become very good, because very often you learn in the wrong way, or in a not much efficient way. Howard Gardner too has written about such topic. Bye, bearophile From emile at fenx.com Wed Jun 17 18:27:32 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 15:27:32 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: On 6/17/2009 3:19 PM ssc said... > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > >>>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>>> title_choices > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined You get this because titles doesn't exist in the builtin, local or global namespaces. Post the code that fails. It's hard to debug working code. :) Emile > > Does anybody know why ? How can I fix the error ? > > Thank you very much :-) > > Steve From ldo at geek-central.gen.new_zealand Wed Jun 17 18:33:49 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 10:33:49 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 23:04:37 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >> >>> On Wed, 17 Jun 2009 17:53:33 +1200 >>> Lawrence D'Oliveiro wrote: >>> >>>>> Why not use hex representation of md5/sha1-hashed id as a path, >>>>> arranging them like /path/f/9/e/95ea4926a4 ? >>>>> >>>>> That way, you won't have to deal with many-files-in-path problem ... >>>> >>>> Why is that a problem? >>> >>> So you can os.listdir them? >> >> Why should you have a problem os.listdir'ing lots of files? > > I shouldn't, and I don't ;) Then why did you suggest that there was a problem being able to os.listdir them? From clp2 at rebertia.com Wed Jun 17 18:38:47 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Jun 2009 15:38:47 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> On Wed, Jun 17, 2009 at 3:19 PM, ssc wrote: > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > >>>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>>> title_choices > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined > > Does anybody know why ? How can I fix the error ? See what Emile said, but here's a nicer way to code it, IMHO: titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms'] title_choices = zip(range(len(titles)+1), ['']+titles) zip() to the rescue! Cheers, Chris -- http://blog.rebertia.com From tack at urandom.ca Wed Jun 17 18:41:44 2009 From: tack at urandom.ca (Jason Tackaberry) Date: Wed, 17 Jun 2009 18:41:44 -0400 Subject: generator expression works in shell, NameError in script In-Reply-To: <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> Message-ID: <1245278504.6577.120.camel@arrakis> On Wed, 2009-06-17 at 15:38 -0700, Chris Rebert wrote: > See what Emile said, but here's a nicer way to code it, IMHO: > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms'] > title_choices = zip(range(len(titles)+1), ['']+titles) > > zip() to the rescue! How about: enumerate([''] + titles) From emile at fenx.com Wed Jun 17 18:46:50 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 15:46:50 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <1245278504.6577.120.camel@arrakis> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <1245278504.6577.120.camel@arrakis> Message-ID: On 6/17/2009 3:41 PM Jason Tackaberry said... > How about: > > enumerate([''] + titles) > or perhaps, depending on usage... list(enumerate(titles)) Emile From joncle at googlemail.com Wed Jun 17 18:49:03 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 17 Jun 2009 15:49:03 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> On Jun 17, 11:19?pm, ssc wrote: > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > > >>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > >>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) > >>> title_choices > > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined > > Does anybody know why ? How can I fix the error ? > > Thank you very much :-) > > Steve Why are you doing this? I'm assuming a code to title look up is required (don't forget military, royal and honorable titles etc... :) ) Why not just: >>> titles = ['', 'Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>> lookup = dict(enumerate(titles)) >>> print lookup {0: '', 1: 'Dr', 2: 'Miss', 3: 'Mr', 4: 'Mrs', 5: 'Ms'} or if you don't want a dict, then just: >>> print list(enumerate(titles)) [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] From rhodri at wildebst.demon.co.uk Wed Jun 17 18:53:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Jun 2009 23:53:28 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Wed, 17 Jun 2009 16:06:22 +0100, Aaron Brady wrote: > On Jun 16, 10:09?am, Mike Kazantsev wrote: >> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) >> >> Aaron Brady wrote: >> > Making the charitable interpretation that this was the extent of c-l- >> > py's support and enthusiasm for my idea, I will now go into mourning. >> > Death occurred at oh-eight-hundred. ?Rest in peace, support & >> > enthusiasm. >> >> I've read this thread from the beginning, being tempted to insert >> remarks about shelve module or ORMs like SQLAlchemy, but that'd be >> meaningless without the problem description, which I haven't seen >> anywhere. Is it some trick idea like "let's walk on our heads"? > > More like bronze them, or hang them on a tackboard. You haven't > convinced me that it's not a problem, or that it's an easy one. Unfortunately it's up to you to demonstrate that it is a problem, whichever of the many possible 'it's you're talking about. So far, the question "Why would I want to use this? What's the use case?" has gone unanswered, and I'm sure I'm not the only baffled by it. -- Rhodri James *-* Wildebeest Herder to the Masses From tim.wintle at teamrubber.com Wed Jun 17 18:54:23 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 17 Jun 2009 23:54:23 +0100 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Message-ID: <1245279263.9195.27.camel@tim-laptop> On Wed, 2009-06-17 at 14:26 -0400, Cameron Pulsford wrote: > This is only supposed to handle text files, so when would reading it > all into memory become too much for most computers? I'm guessing there > aren't many source files of too great a size. I often use python with server log files - 1Tb of plain-text wouldn't seem too much to me, but it wouldn't fit into ram on many computers ;-) For source files I wouldn't think it would be a problem - but I agree with Jean-Michel, I can imagine running an app like yours over hundreds of source files at once. It wouldn't be nice if I decided to kill the program half way through and found it had died half way through processing a file and lost my code! Tim Wintle From steven.samuel.cole at gmail.com Wed Jun 17 18:54:28 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Wed, 17 Jun 2009 15:54:28 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> Message-ID: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Wow! Didn't expect that kind of instant support. Thank you very much, I'll give both zip and enumerate a try. The code I've shown is actually copied pretty straight from a Django form class, but I didn't want to mention that as not to dilute the conversation. Don't think it matters, anyway. This is the relevant excerpt: from django.forms import Form class SignupForm(Form): titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) Now that I look at it again, it seems odd to me to not have the code e.g. in __init__(...), but just 'class-global'. Still, that does not seem a reason for titles not to be not defined, as I do define it just in the line above. Does the generator expression have its own little namespace or so ? From rhodri at wildebst.demon.co.uk Wed Jun 17 18:58:25 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Jun 2009 23:58:25 +0100 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Message-ID: Top-posting, tsk, tsk. On Wed, 17 Jun 2009 19:26:07 +0100, Cameron Pulsford wrote: > Essentially it just cleans up a source file of erroneous spaces and tabs > and > can also convert tabs to spaces so loading the whole file into memory is > possibly an option. I am making this utility for personal use, and that > would definitely be fine, [snip] You won't say that the first time it screws up and destroys one of your files. Making in-place changes is something that should set big red lights flashing in software engineering terms. You don't want to get into the habit of doing that, especially for personal use. -- Rhodri James *-* Wildebeest Herder to the Masses From stef.mientki at gmail.com Wed Jun 17 18:59:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 18 Jun 2009 00:59:25 +0200 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: <4A39754D.5020604@gmail.com> >>> program didn't start because .dll is missing (sorry I don't have the >>> name)... I don't know if that is just an issue with the installer >>> with vista or not (missing msv something 71. dll) >>> >> You probably mean the microsoft visual C++ runtime (msvcr71.dll), >> windows vista has a brand new way (via manifest files) to make it more >> difficult to install compiled binaries. >> >> Search for 'Microsoft Visual C++ 2005 Redistributable Package' and >> install it. >> >> -- >> MPHhttp://blog.dcuktec.comm >> 'If consumed, best digested with added seasoning to own preference.' >> > > it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 > Redistributable Package > did not help.. I had simular problems > with alot of installers I had saved (from installing on xp) but when > I grabbed newer installers > they all worked, could be the manifast.... I was looking forward to > trying it out.. > > I rebuild the package with all windows system files included, suggested by Py2Exe, see the installation instructions: http://mientki.ruhosting.nl/data_www/pylab_works/pw_installation.html these system files will be unpacked in the root of the installation. I'm not familiar with Windows Vista, but this would be the trick in Windows XP. cheers, Stef From clp2 at rebertia.com Wed Jun 17 19:11:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Jun 2009 16:11:19 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> On Wed, Jun 17, 2009 at 3:54 PM, ssc wrote: > Wow! Didn't expect that kind of instant support. Thank you very much, > I'll give both zip and enumerate a try. > > The code I've shown is actually copied pretty straight from a Django > form class, but I didn't want to mention that as not to dilute the > conversation. Don't think it matters, anyway. This is the relevant > excerpt: > > from django.forms import Form > > class SignupForm(Form): > > ? ?titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > ? ?title_choices ? = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Now that I look at it again, it seems odd to me to not have the code > e.g. in __init__(...), but just 'class-global'. > Still, that does not seem a reason for titles not to be not defined, > as I do define it just in the line above. > > Does the generator expression have its own little namespace or so ? No, which leads to the common "WTF?" reaction upon seeing stuff like: >>> funcs = ((lambda: x) for x in range(7)) >>> list_of = list(funcs) >>> list_of[0]() 6 Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Wed Jun 17 19:13:03 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 16:13:03 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: On 6/17/2009 3:54 PM ssc said... > Wow! Didn't expect that kind of instant support. Thank you very much, > I'll give both zip and enumerate a try. > > The code I've shown is actually copied pretty straight from a Django > form class, but I didn't want to mention that as not to dilute the > conversation. Don't think it matters, anyway. This is the relevant > excerpt: > > from django.forms import Form > > class SignupForm(Form): > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Now that I look at it again, it seems odd to me to not have the code > e.g. in __init__(...), but just 'class-global'. And as class is an executable statement, I imagine titles exists in a namespace that hasn't yet been completely defined. > Still, that does not seem a reason for titles not to be not defined, > as I do define it just in the line above. Well, again, titles will exists in the SignupForm namespace once it exists, which it doesn't yet when you get to title_choices and want to access it. Define titles above the class and you should be OK. > > Does the generator expression have its own little namespace or so ? Sometimes -- in some python versions generator expressions leak... Emile From rhodri at wildebst.demon.co.uk Wed Jun 17 19:26:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 00:26:17 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro wrote: [snip example code] > You haven't managed to get rid of the backslashes. [snip other example code] > Now you've lost track of the original point of the discussion, which is > about using alternate quotes to avoid backslashes. Ah, selective amnesia, how useful you are. The original point of the discussion was in fact about using alternative quotes to avoid alternate backslashes (or at least excessive ones). The first example showed this nicely, actually, within the confines of a language which doesn't give you much more help. Yes, I know from past conversations that you have a superhuman ability to recognise the code in apparent line noise. That still doesn't make it legible to anyone else. -- Rhodri James *-* Wildebeest Herder to the Masses From steven.samuel.cole at gmail.com Wed Jun 17 19:38:39 2009 From: steven.samuel.cole at gmail.com (Steven Samuel Cole) Date: Thu, 18 Jun 2009 11:38:39 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> Message-ID: Both zip and enumerate do the trick. Thanks for the pointers, that's 2 more built-ins under my belt :-) Still don't really understand why my initial code didn't work, though... Thanks everyone! :-) From ethan at stoneleaf.us Wed Jun 17 19:56:03 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Jun 2009 16:56:03 -0700 Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: <4A398293.9080308@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > > >>On Wed, 17 Jun 2009 23:04:37 +1200 >>Lawrence D'Oliveiro wrote: >> >> >>>In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >>> >>> >>>>On Wed, 17 Jun 2009 17:53:33 +1200 >>>>Lawrence D'Oliveiro wrote: >>>> >>>> >>>>>>Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>arranging them like /path/f/9/e/95ea4926a4 ? >>>>>> >>>>>>That way, you won't have to deal with many-files-in-path problem ... >>>>> >>>>>Why is that a problem? >>>> >>>>So you can os.listdir them? >>> >>>Why should you have a problem os.listdir'ing lots of files? >> >>I shouldn't, and I don't ;) > > > Then why did you suggest that there was a problem being able to os.listdir > them? > He didn't, the OP did. From norseman at hughes.net Wed Jun 17 20:26:13 2009 From: norseman at hughes.net (norseman) Date: Wed, 17 Jun 2009 17:26:13 -0700 Subject: Create 3D Surface / Contour (with vpython?) In-Reply-To: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> References: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Message-ID: <4A3989A5.6040807@hughes.net> Philip Gr?ger wrote: > Hi! > How can I create a 3D surface (or something like the picture on the FAQ > page http://www.vpython.org/contents/FAQ.html ) with python [or > vpython]. Didnt find anything in the Documentation under "graph" > Basically like a contourf diagram in 3D > (http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I > think you know what I mean. > > Reason: I want to simulate waves in a square basin. Hope I dont need to > use hundrets of little spheres (in case of vpython) for the surface ;) > > Thanks alot > > - Philip > ========================= First of all, those are not quite contours, at least not as the mapping industry uses the term. They are function generated cross sections, perhaps rotated or translated, closely spaced, that have been rendered. Rendered makes them pictures (rasters) and as such the base values are no longer vectors. If you are looking to create pictures you need to plot the points in 3D space, rotate (in 3D space) to a viewpoint of choice and either render the points if they are close enough or create a series of triangular planes from the interior of the points. Do a Google on Triangulated Irregular Networks (TIN). Also try http://wikipedia.org/ The TIN was originally created to aid in computer generated surfaces for use in Aerial Mapping (Photogrammetry). The OG (original ground) could be generated and then the Engineer or Designer could use that to base his/her earth redistributions to a minimum in things like highways, subdivisions and such. Later when GIS came along it borrowed the equations and selected the raster format as it's base. Unfortunately rasters are equally spaced points of same size along the X or Y axis (can be same along both) thus forming a grid. TIN points are NOT on a grid. They occur where needed to dot outline the surface. Coupled with break lines (polylines, sometimes called line strings) to trace an edge (like edge of mountain road) the TIN can depict very accurately a surface. Mother Nature uses quite a number of math functions in just your front yard. The proper dotting of the area reduces the overall number of points required to 'shape' the surface. Contours, in mapping, are connected lines of equal elevation. Contours do not touch each other. Look up Topographic Maps, Lines of Equal Elevation, Contours, 2D representations of 3D objects, Photogrammetry, Land Surveying - subsection volumes. For a single function you can look at the choices you named. I think Rasterman has (had?) a good rendering program which could be used to render any formula output you may want to generate. Re-run your graphs with small increments and combine outputs and render. Should work. Waves are just cyclic output. (Crest and trough) Direction gets changed in small increments radiating out from point of creation and bounce (off wall) is part of path. Time determines total length. How complicated is that? The combined 360 degree outputs for a given time slice (time from creation) provides 'surface' at that point. Add 'vigor' factors to control frequency and strength (amplitude) of waves. I'm assuming you can do the math. That being the case, it should be a nice programming exercise. Good Luck; Steve From steve at nospam.au Wed Jun 17 20:36:01 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 10:36:01 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> >"Carl Banks" wrote in message >news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >On Jun 15, 7:56 pm, "steve" wrote: >> I was just looking at the python tutorial, and I noticed these lines: >> >> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >> >> "Windows makes a distinction between text and binary files; >> "the end-of-line characters in text files are automatically altered >> "slightly when data is read or written. >> >> I don't see any obvious way to at docs.python.org to get that corrected: >> Is >> there some standard procedure? > >What's wrong with it? > > >Carl Banks 1) Windows does not make a distinction between text and binary files. 2) end-of-line characters in text files are not automatically altered by Windows. (david) From steve at nospam.au Wed Jun 17 21:18:36 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 11:18:36 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: <4a3995ed$0$32369$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.16.04.29.14 at REMOVE.THIS.cybersource.com.au... > On Mon, 15 Jun 2009 20:58:47 -0700, Carl Banks wrote: > >> On Jun 15, 7:56 pm, "steve" wrote: >>> I was just looking at the python tutorial, and I noticed these lines: >>> >>> http://docs.python.org/tutorial/inputoutput.html#reading-and- > writing-... >>> >>> "Windows makes a distinction between text and binary files; "the >>> end-of-line characters in text files are automatically altered >>> "slightly when data is read or written. >>> >>> I don't see any obvious way to at docs.python.org to get that >>> corrected: Is there some standard procedure? >> >> What's wrong with it? > > Perhaps because it's unclear whether it is Windows, or Python, or both, > which is automatically altering the data. > > As for getting the docs changed, you can submit a bug request at the bug > tracker: > > http://bugs.python.org/ > > > > > -- > Steven Thanks, we've submitted a bug request, http://bugs.python.org/issue6301 Steve From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:34:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:34:25 GMT Subject: Exotic Logics References: Message-ID: On Wed, 17 Jun 2009 16:37:04 +0000, Lie Ryan wrote: >> Imagine for a moment that there are no boolean values. There are no >> numbers. They were never invented. There are no classes. >> There are no objects. >> There are only functions. >> >> Could you define functions that act like boolean values? And could you >> define other functions to operate on them? ... > String isn't considered object? Given that the strings only exist inside one function specifically for printing, I think we can ignore that. If you prefer, print_bool() could look at the function names, that would work just as well. One way or the other, we have to get human-readable names into the system *somehow*. > Also, b/true()/false() is a function object, isn't it? Unless function > is first-class, you can't pass them around like that, since you need a > function pointer (a.k.a number); but if function is first-class then > there it is an object. That's an implementation detail. So long as you can pass around functions, and return them, then it doesn't matter whether they are implemented as objects or not. -- Steven From robert.kern at gmail.com Wed Jun 17 21:37:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Jun 2009 20:37:52 -0500 Subject: python tutorial In-Reply-To: <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On 2009-06-17 19:36, steve wrote: >> "Carl Banks" wrote in message >> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >> On Jun 15, 7:56 pm, "steve" wrote: >>> I was just looking at the python tutorial, and I noticed these lines: >>> >>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>> >>> "Windows makes a distinction between text and binary files; >>> "the end-of-line characters in text files are automatically altered >>> "slightly when data is read or written. >>> >>> I don't see any obvious way to at docs.python.org to get that corrected: >>> Is >>> there some standard procedure? >> What's wrong with it? >> >> >> Carl Banks > > 1) Windows does not make a distinction between text and binary files. > > 2) end-of-line characters in text files are not automatically altered by > Windows. The Windows implementation of the C standard makes the distinction. E.g. using stdio to write out "foo\nbar\n" in a file opened in text mode will result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode will result in "foo\nbar\n" in memory. Reading such a file in binary mode will result in "foo\r\nbar\r\n". In your bug report, you point out several proprietary APIs that do not make such a distinction, but that does not remove the implementations of the standard APIs that do make such a distinction. http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx Perhaps it's a bit dodgy to blame "Windows" per se rather than its C runtime, but I think it's a reasonable statement on the whole. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:42:51 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:42:51 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: > 1) Windows does not make a distinction between text and binary files. Of course it does. Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> f = open("test", "wb") >>> f.write("abc\x1Adef") >>> f.close() >>> f = open("test", "r") # read as text >>> f.read() 'abc' >>> f.close() >>> f = open("test", "rb") # read as binary >>> f.read() 'abc\x1adef' >>> f.close() >>> -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:43:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:43:37 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> Even CPython doesn't rely completely on reference counting (it has a >> fallback gc for cyclic garbage). Python introduced the "with" >> statement to get away from the kludgy CPython programmer practice of >> opening files and relying on the file being closed when the last >> reference went out of scope. > > I'm curious as you why you consider this practice to be kludgy; my > experience with RAII is pretty good. Because it encourages harmful laziness. Laziness is only a virtue when it leads to good code for little effort, but in this case, it leads to non- portable code. Worse, if your data structures include cycles, it also leads to resource leaks. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:44:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:44:03 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 23:29:48 +1200, Lawrence D'Oliveiro wrote: > In message <7x7hzbv14a.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> > Reference counting is an implementation detail used by CPython but >>> > not [implementations built on runtimes designed for >>> > corporate-herd-oriented languages, like] IronPython or Jython. >>> >>> I rest my case. >> >> You're really being pretty ignorant. I don't know of any serious Lisp >> system that uses reference counting, both for performance reasons and >> to make sure cyclic structures are reclaimed properly. > > Both of which, oddly enough, more modern dynamic languages like Python > manage perfectly well. *Python* doesn't have a ref counter. That's an implementation detail of *CPython*. There is nothing in the specifications for the language Python which requires a ref counter. CPython's ref counter is incapable of dealing with cyclic structures, and so it has a second garbage collector specifically for that purpose. The only reason Python manages perfectly well is by NOT relying on a ref counter: some implementations don't have one at all, and the one which does, uses a second gc. Additionally, while I'm a fan of the simplicity of CPython's ref counter, one serious side effect of it is that it requires the GIL, which essentially means CPython is crippled on multi-core CPUs compared to non- ref counting implementations. -- Steven From mk.fraggod at gmail.com Wed Jun 17 22:14:23 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Thu, 18 Jun 2009 08:14:23 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: <20090618081423.2e0356b9@coercion> On Thu, 18 Jun 2009 10:33:49 +1200 Lawrence D'Oliveiro wrote: > In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 23:04:37 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > >> > >>> On Wed, 17 Jun 2009 17:53:33 +1200 > >>> Lawrence D'Oliveiro wrote: > >>> > >>>>> Why not use hex representation of md5/sha1-hashed id as a path, > >>>>> arranging them like /path/f/9/e/95ea4926a4 ? > >>>>> > >>>>> That way, you won't have to deal with many-files-in-path problem ... > >>>> > >>>> Why is that a problem? > >>> > >>> So you can os.listdir them? > >> > >> Why should you have a problem os.listdir'ing lots of files? > > > > I shouldn't, and I don't ;) > > Then why did you suggest that there was a problem being able to os.listdir > them? I didn't, OP did, and that's what the topic "walking directory with many files" is about. I wonder whether you're unable to read past the first line, trying to make some point or just some kind of alternatively-gifted (i.e. brain-handicapped) person to keep interpreting posts w/o context like that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jason.heeris at gmail.com Wed Jun 17 22:40:25 2009 From: jason.heeris at gmail.com (Jason) Date: Wed, 17 Jun 2009 19:40:25 -0700 (PDT) Subject: How can I enumerate (list) serial ports? Message-ID: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Hi, I'm developing an application to talk to a device over a serial port. I'm trying my hardest to keep it cross platform, so I was using pySerial for the serial communications. But I can't see a pythonic, cross-platform way to enumerate serial ports on a machine. Ideally I could show the user a list of "COM1","COM2", etc, or ttyS0, ttyS1, etc. At the moment I think they'll just have to type it into a box. Is there a known way to do this? Is there anyone who has a hack they're willing to share? Thanks, Jason From wistoch at gmail.com Wed Jun 17 22:45:36 2009 From: wistoch at gmail.com (Wei, James) Date: Wed, 17 Jun 2009 19:45:36 -0700 (PDT) Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux Message-ID: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> When I am editing python program with SPE, I found that SPE will freeze when it is doing auto-completion. The behavior is very strange that I can not edit the file again. If I switch to another file and then switch back, I can edit it again. So I switch to eclipse+pydev, but I found the same thing happen. So I think it is not the problem of SPE or eclipse or pydev. If I disable auto-completion function in SPE or Eclipse+PyDev, it will not freeze any longer. Anybody can give me some hints? I am using Ubuntu 8.10 and updated to latest. All packages is installed through package manager. From wistoch at gmail.com Wed Jun 17 22:47:37 2009 From: wistoch at gmail.com (Wei, James) Date: Wed, 17 Jun 2009 19:47:37 -0700 (PDT) Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> Message-ID: <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> On Jun 18, 10:45?am, "Wei, James" wrote: > When I am editing python program with SPE, I found that SPE will > freeze when it is doing auto-completion. The behavior is very strange > that I can not edit the file again. If I switch to another file and > then switch back, I can edit it again. > > So I switch to eclipse+pydev, but I found the same thing happen. So I > think it is not the problem of SPE or eclipse or pydev. > > If I disable auto-completion function in SPE or Eclipse+PyDev, it will > not freeze any longer. > > Anybody can give me some hints? > > I am using Ubuntu 8.10 and updated to latest. All packages is > installed through package manager. the only thing I googled related with it is http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html but I think they are different. From trinioler at gmail.com Wed Jun 17 22:57:12 2009 From: trinioler at gmail.com (Tyler Laing) Date: Wed, 17 Jun 2009 19:57:12 -0700 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> Message-ID: <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> Do you experience the same problem even on an empty program file or is it limited to just one file? -Tyler On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > On Jun 18, 10:45 am, "Wei, James" wrote: > > When I am editing python program with SPE, I found that SPE will > > freeze when it is doing auto-completion. The behavior is very strange > > that I can not edit the file again. If I switch to another file and > > then switch back, I can edit it again. > > > > So I switch to eclipse+pydev, but I found the same thing happen. So I > > think it is not the problem of SPE or eclipse or pydev. > > > > If I disable auto-completion function in SPE or Eclipse+PyDev, it will > > not freeze any longer. > > > > Anybody can give me some hints? > > > > I am using Ubuntu 8.10 and updated to latest. All packages is > > installed through package manager. > > the only thing I googled related with it is > > > http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html > > but I think they are different. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From charles at declareSub.com Wed Jun 17 22:58:27 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 22:58:27 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) In-Reply-To: References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: <596CA436-AF47-4164-AEBB-3B011B09C2E4@declareSub.com> On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: > On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: > >>> Even CPython doesn't rely completely on reference counting (it has a >>> fallback gc for cyclic garbage). Python introduced the "with" >>> statement to get away from the kludgy CPython programmer practice of >>> opening files and relying on the file being closed when the last >>> reference went out of scope. >> >> I'm curious as you why you consider this practice to be kludgy; my >> experience with RAII is pretty good. > > Because it encourages harmful laziness. Laziness is only a virtue > when it > leads to good code for little effort, but in this case, it leads to > non- > portable code. Worse, if your data structures include cycles, it also > leads to resource leaks. > Memory management may be an "implementation detail", but it is unfortunately one that illustrates the so-called law of leaky abstractions. So I think that one has to write code that follows the memory management scheme of whatever language one uses. For code written for CPython only, as mine is, RAII is an appropriate idiom and not kludgy at all. Under your assumptions, its use would be wrong, of course. Charles Yeomans From perfreem at gmail.com Wed Jun 17 23:28:43 2009 From: perfreem at gmail.com (per) Date: Wed, 17 Jun 2009 20:28:43 -0700 (PDT) Subject: fastest native python database? Message-ID: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> hi all, i'm looking for a native python package to run a very simple data base. i was originally using cpickle with dictionaries for my problem, but i was making dictionaries out of very large text files (around 1000MB in size) and pickling was simply too slow. i am not looking for fancy SQL operations, just very simple data base operations (doesn't have to be SQL style) and my preference is for a module that just needs python and doesn't require me to run a separate data base like Sybase or MySQL. does anyone have any recommendations? the only candidates i've seen are snaklesql and buzhug... any thoughts/benchmarks on these? any info on this would be greatly appreciated. thank you From wistoch at gmail.com Wed Jun 17 23:32:19 2009 From: wistoch at gmail.com (Wei, Xiaohai) Date: Thu, 18 Jun 2009 11:32:19 +0800 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> Message-ID: <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> yes, the same problem even on an empty program. every file has the same problem. for example, if I new a file and input the following: import os os. after I input '.', it will pop up the window, and i can select the function of os module or continue input. but after that, no action can be taken for this file unless I switch to other files and then switch back. On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing wrote: > Do you experience the same problem even on an empty program file or is it > limited to just one file? > > -Tyler > > On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > >> On Jun 18, 10:45 am, "Wei, James" wrote: >> > When I am editing python program with SPE, I found that SPE will >> > freeze when it is doing auto-completion. The behavior is very strange >> > that I can not edit the file again. If I switch to another file and >> > then switch back, I can edit it again. >> > >> > So I switch to eclipse+pydev, but I found the same thing happen. So I >> > think it is not the problem of SPE or eclipse or pydev. >> > >> > If I disable auto-completion function in SPE or Eclipse+PyDev, it will >> > not freeze any longer. >> > >> > Anybody can give me some hints? >> > >> > I am using Ubuntu 8.10 and updated to latest. All packages is >> > installed through package manager. >> >> the only thing I googled related with it is >> >> >> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >> >> but I think they are different. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Best wishes to you. Yours sincerely Xiaohai Wei wistoch at ustc.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Wed Jun 17 23:38:05 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 20:38:05 -0700 Subject: fastest native python database? In-Reply-To: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: On 6/17/2009 8:28 PM per said... > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. You might like gadfly... http://gadfly.sourceforge.net/gadfly.html Emile > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you From jussij at zeusedit.com Wed Jun 17 23:41:27 2009 From: jussij at zeusedit.com (JussiJ) Date: Wed, 17 Jun 2009 20:41:27 -0700 (PDT) Subject: What text editor is everyone using for Python References: <85hbz9f56i.fsf@agentultra.com> <35e44e77-fdd1-470a-b5ad-f5ffd187f1af@g22g2000pra.googlegroups.com> <9a346808-6e06-44de-b6b3-f3720286ff13@l12g2000yqo.googlegroups.com> <4a211274-f190-47e3-8166-5b3536d678e7@i28g2000prd.googlegroups.com> <802b4bfa-40b8-4459-b0c5-d5df5b61c181@n21g2000vba.googlegroups.com> Message-ID: On May 31, 12:42 am, edexter wrote: On the Windows platform the Zeus editor has Python language support: http://www.zeusedit.com > I will sometimes use word pad but i perfer syntax > highlighting.. The syntax highlighter is fully configurable. > I would be after is to be able to define my syntax file, the > ability to use code snippits, It has a code template feature. > the ability to add tools and compilers... and it also has these features. If also does Python code folding and is scriptable in Python. Jussi Jumppanen Author: Zeus for Windows From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 23:41:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 03:41:55 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 22:58:27 -0400, Charles Yeomans wrote: > On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: > >> On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> >>>> Even CPython doesn't rely completely on reference counting (it has a >>>> fallback gc for cyclic garbage). Python introduced the "with" >>>> statement to get away from the kludgy CPython programmer practice of >>>> opening files and relying on the file being closed when the last >>>> reference went out of scope. >>> >>> I'm curious as you why you consider this practice to be kludgy; my >>> experience with RAII is pretty good. >> >> Because it encourages harmful laziness. Laziness is only a virtue when >> it >> leads to good code for little effort, but in this case, it leads to >> non- >> portable code. Worse, if your data structures include cycles, it also >> leads to resource leaks. >> >> > > Memory management may be an "implementation detail", but it is > unfortunately one that illustrates the so-called law of leaky > abstractions. So I think that one has to write code that follows the > memory management scheme of whatever language one uses. For code > written for CPython only, as mine is, RAII is an appropriate idiom and > not kludgy at all. Under your assumptions, its use would be wrong, of > course. CPython isn't a language, it's an implementation. I'm unable to find anything in the Python Reference which explicitly states that files will be closed when garbage collected, except for one brief mention in tempfile.TemporaryFile: "Return a file-like object that can be used as a temporary storage area. The file is created using mkstemp(). It will be destroyed as soon as it is closed (including an implicit close when the object is garbage collected)." http://docs.python.org/library/tempfile.html In practical terms, it's reasonably safe to assume Python will close files when garbage collected (it would be crazy not to!) but that's not explicitly guaranteed anywhere I can see. In any case, there is no guarantee *when* files will be closed -- for long-lasting processes that open and close a lot of files, or for data structures with cycles, you might easily run out of file descriptors. The docs for file give two recipes for recommended ways of dealing with files: http://docs.python.org/library/stdtypes.html#file.close Both of them close the file, one explicitly, the other implicitly. In both cases, they promise to close the file as soon as you are done with it. Python the language does not. The tutorials explicitly recommends closing the file when you're done: "When you?re done with a file, call f.close() to close it and free up any system resources taken up by the open file." http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files In summary: relying on immediate closure of files is implementation specific behaviour. By all means do so, with your eyes open and with full understanding that you're relying on platform-specific behaviour with no guarantee of when, or even if, files will be closed. -- Steven From perfreem at gmail.com Wed Jun 17 23:47:57 2009 From: perfreem at gmail.com (per) Date: Wed, 17 Jun 2009 20:47:57 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <5a77a35e-7c7a-46a3-a1de-5ec5a6d4e6ca@t10g2000vbg.googlegroups.com> i would like to add to my previous post that if an option like SQLite with a python interface (pysqlite) would be orders of magnitude faster than naive python options, i'd prefer that. but if that's not the case, a pure python solution without dependencies on other things would be the best option. thanks for the suggestion, will look into gadfly in the meantime. On Jun 17, 11:38?pm, Emile van Sebille wrote: > On 6/17/2009 8:28 PM per said... > > > hi all, > > > i'm looking for a native python package to run a very simple data > > base. i was originally using cpickle with dictionaries for my problem, > > but i was making dictionaries out of very large text files (around > > 1000MB in size) and pickling was simply too slow. > > > i am not looking for fancy SQL operations, just very simple data base > > operations (doesn't have to be SQL style) and my preference is for a > > module that just needs python and doesn't require me to run a separate > > data base like Sybase or MySQL. > > You might like gadfly... > > http://gadfly.sourceforge.net/gadfly.html > > Emile > > > > > does anyone have any recommendations? the only candidates i've seen > > are snaklesql and buzhug... any thoughts/benchmarks on these? > > > any info on this would be greatly appreciated. thank you > > From jussij at zeusedit.com Wed Jun 17 23:52:36 2009 From: jussij at zeusedit.com (JussiJ) Date: Wed, 17 Jun 2009 20:52:36 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: <354ebc10-a3a1-49ef-bacb-9e1d69ed7ef6@y34g2000prb.googlegroups.com> On May 26, 3:35 am, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, The Zeus for Windows IDE is Python aware: http://www.zeusedit.com/python.html > and why. It does syntax highlighting, smart indenting, code folding etc etc You can write Zeus scripts in Python. Zeus also creates Python tag informatuion (via ctags.exe) and this information is used to populate the class/code browser. It is also possible to hook in the Python documentation so the help can be searched and accessed from within the editor: http://www.zeusedit.com/forum/viewtopic.php?t=8 Jussi Jumppanen Author: Zeus for Windows IDE NOTE: Zeus is shareware From mr.william.clifford at gmail.com Thu Jun 18 00:03:45 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Wed, 17 Jun 2009 21:03:45 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <3bf78076-688d-4ec8-9ea6-9fe070d94f4f@c20g2000prh.googlegroups.com> On Jun 17, 8:28?pm, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you I don't know how they stack up but what about: Python CDB http://pilcrow.madison.wi.us/#pycdb or Dee (for ideological reasons) http://www.quicksort.co.uk/ -- William Clifford From kushal.kumaran+python at gmail.com Thu Jun 18 00:19:49 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 18 Jun 2009 09:49:49 +0530 Subject: Reading and setting file permissions programmatically In-Reply-To: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> References: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Message-ID: <1e364c4e0906172119g4ebb3631tb02f335c18e3e19a@mail.gmail.com> On Thu, Jun 18, 2009 at 2:05 AM, Cameron Pulsford wrote: > Sorry to flood the list but my google fu isn't up to par today I guess. > Basically, is it possible to read the permissions on one file and then set > the permissions of another file to the ones we just read? os.dup2 seemed > like it would work but I might not be using it correctly. > I know there is os.chmod, but I haven't found the equivalent to read > permissions. Preferably this would work on unix and windows too. shutil.copymode -- kushal From afriere at yahoo.co.uk Thu Jun 18 01:17:04 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 22:17:04 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> On Jun 18, 5:03?am, Terry Reedy wrote: > That depends on what you mean by 'put into classes' (and 'everything'). > > If you mean 'be an instance of a class', which I think is the most > natural reading, then Python *is* object-oriented and, if I understand > what I have read correctly (so that ints are just (unboxed) ints and not > members of an int class), Java *is not*! +1 This needs to be said to those who imagine, because you have to code the class explicitly in Java whereas Python objects can be manipulated in ignorance of the idea of class, that Java is somehow OO in the way Python is not. OTOH the whole notion of defining OO by the use of classes automatically excludes from consideration prototype-based OO languages (eg. Self) which arguably offer a purer approach to OO than class centric languages. From delroth at gmail.com Thu Jun 18 01:41:13 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Thu, 18 Jun 2009 07:41:13 +0200 Subject: fastest native python database? In-Reply-To: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <1ba9eaed0906172241s2b22a191l1bfd9177d7f180d5@mail.gmail.com> On Thu, Jun 18, 2009 at 05:28, per wrote: > hi all, Hi, > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. If you just need something which does not depend on any external libraries (that's what I understand in "just needs python"), you should also consider sqlite3 as it is a built-in module in Python 2.5 and newer. You do not need modules like pysqlite to use it. -- Pierre "delroth" Bourdon ?tudiant ? l'EPITA / Student at EPITA From afriere at yahoo.co.uk Thu Jun 18 01:42:40 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 22:42:40 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: On Jun 15, 6:35?am, Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... (asun at lucrezia:~/pit/lsa/act:5)$ ls -1 | wc -l 142607 There, you've seen one with 142 thousand now! :P From steve at nospam.au Thu Jun 18 01:57:16 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 15:57:16 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Robert Kern" wrote in message news:mailman.1728.1245289092.8015.python-list at python.org... > On 2009-06-17 19:36, steve wrote: >>> "Carl Banks" wrote in message >>> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>> On Jun 15, 7:56 pm, "steve" wrote: >>>> I was just looking at the python tutorial, and I noticed these lines: >>>> >>>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>> >>>> "Windows makes a distinction between text and binary files; >>>> "the end-of-line characters in text files are automatically altered >>>> "slightly when data is read or written. >>>> >>>> I don't see any obvious way to at docs.python.org to get that >>>> corrected: >>>> Is >>>> there some standard procedure? >>> What's wrong with it? >>> >>> >>> Carl Banks >> >> 1) Windows does not make a distinction between text and binary files. >> >> 2) end-of-line characters in text files are not automatically altered by >> Windows. > > The Windows implementation of the C standard makes the distinction. E.g. > using stdio to write out "foo\nbar\n" in a file opened in text mode will > result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode > will result in "foo\nbar\n" in memory. Reading such a file in binary mode > will result in "foo\r\nbar\r\n". In your bug report, you point out several > proprietary APIs that do not make such a distinction, but that does not > remove the implementations of the standard APIs that do make such a > distinction. > > http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx > > Perhaps it's a bit dodgy to blame "Windows" per se rather than its C > runtime, but I think it's a reasonable statement on the whole. > > -- > 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 > Which is where I came in: I was looking for simple file IO in the tutorial. The tutorial tells me something false about Windows, rather than something true about Python. I'm looking at a statement that is clearly false (for anyone who knows anything about Windows file systems and Windows file io), which leaves the Python behaviour completely undefined (for anyone who knows nothing about Python). I understand that many of you don't really have any understanding of Windows, much less any background with Windows, and I'm here to help. That part was simple. The next part is where I can't help: What is the behaviour of Python? I'm sure you don't think that tutorial is only for readers who can guess that they have to extrapolate from the behaviour of the Visual C library in order to work out what Python does. Steve From steve at nospam.au Thu Jun 18 01:58:37 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 15:58:37 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... > On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: > >> 1) Windows does not make a distinction between text and binary files. > > Of course it does. > > > Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> f = open("test", "wb") >>>> f.write("abc\x1Adef") >>>> f.close() >>>> f = open("test", "r") # read as text >>>> f.read() > 'abc' >>>> f.close() >>>> f = open("test", "rb") # read as binary >>>> f.read() > 'abc\x1adef' >>>> f.close() >>>> > > > -- > Steven Ok, Python makes a distinction between text and binary files. Steve. From bob.martin at excite.com Thu Jun 18 02:07:26 2009 From: bob.martin at excite.com (Bob Martin) Date: Thu, 18 Jun 2009 06:07:26 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: in 117815 20090617 221804 Phil Runciman wrote: >Because it reminds me of when things went badly wrong. IBM360, Von Neumann = >architecture, no hardware stacks ... > >IMHO Burroughs and ICL had better approaches to OS design back then but had= >less resources to develop their ideas.=20 > >However, mainly this period marked a transition from the excitement and dis= >covery phase of computing to commercial power plays and take-overs. The bes= >t ideas in a field tend to get lost in the melee of competition. Early comp= >uters were rooted in academia and there was a lot of cross fertilisation of= >ideas and approaches. IMHO commerce affected layers of the stack where it = >had no useful contribution to make. Vertical integration warred against sou= >nd architecture. > >The book has an important message and I recommend that people read it. The = >book is to me, and possibly only me, an icon representing when things went = >wrong. Well, it's an opinion, but certainly not one I would agree with! AFAIAC the IBM 360 got everything right, which is why the instruction set is still going strong 45 years later (I've used it for every one of those 45 years). From mail at timgolden.me.uk Thu Jun 18 02:20:42 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Jun 2009 07:20:42 +0100 Subject: How can I enumerate (list) serial ports? In-Reply-To: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> References: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Message-ID: <4A39DCBA.3070303@timgolden.me.uk> Jason wrote: > Hi, > > I'm developing an application to talk to a device over a serial port. > I'm trying my hardest to keep it cross platform, so I was using > pySerial for the serial communications. But I can't see a pythonic, > cross-platform way to enumerate serial ports on a machine. As with many other such issues, instant cross-platformability is likely to be rare. I admin I haven't looked at pySerial but I imagine that, behind the scenes, it's doing some sort of conditional imports according to platform. I imagine you'd have to do something similar to get a list of port names. On Windows, WMI can give you what you want. Look at the Win32_SerialPort class. Hopefully, someone else can help for other platforms. TJG From afriere at yahoo.co.uk Thu Jun 18 02:21:06 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 23:21:06 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Jun 15, 1:00?am, rustom wrote: > > For every one Horowitz there are a thousand wannbes thumping on the > piano trying to become Horowitz. > The traction that practice gives is maximal only in the beginning. Funny but I was watching an interview/conversation between and older composer and a young up and coming WFCP (World Famous Concert Pianist) the other day. The composer had been teaching the pianist to understand the works he was playing ... anyway, the old guy remarked that when he was younger he wanted to be a WFCP too, but that he lacked a crucial ability that the young star had. What was it? "I lack the ability to make myself practise as well and for as long as you do." From gervich at sbcglobal.net Thu Jun 18 02:23:56 2009 From: gervich at sbcglobal.net (Jason Gervich) Date: Wed, 17 Jun 2009 23:23:56 -0700 Subject: IDLE comments Message-ID: <1245306236.3326.3.camel@jason-desktop> Why does IDLE use two hash marks for comments (##)? Most other editors (Geany, SPE) use a single hash mark (#) to designate comments. How does one change IDLE to use just a single (#) hash mark for comments? Thanks, Jason Gervich Santa Cruz, CA -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Thu Jun 18 02:44:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 23:44:36 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <687da532-5d62-47a3-a229-5ff4b66ca2bf@p4g2000vba.googlegroups.com> On Jun 17, 7:38?am, Jean-Michel Pichavant wrote: > abhishek goswami wrote: > > Hi, > > I have very basic question about Python that do we consider pyhton as > > script language. > > I searched in google but it becomes more confusion for me. After some > > analysis I came to know that Python support oops . > > > Can anyone Guide me that Python is Oject oriented programming language > > or Script language > > > Abhishek Goswami > > Chennai > > Phone No -0996227099 > > > ------------------------------------------------------------------------ > > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > > > > Depends on what you are calling a scripting language. > Refering to wikipedia, > "A *scripting language*, *script language* or *extension language* is a > programming language > that allows some control of a single or many software application(s) > ." > > Python is definitely OOP oriented and I don't think it fits in the > script definition above. > Python is interpreted and platform independent, but you can still build > standalone platform dependent binaries if required. > > Regarding your last question, I'm not sure scripting and OOP language > are not compatible, I'm pretty sure you'll be able to find OOP scripting > language. > > Jean-Michel I'm not the only one that thinks that Java is a joke, though I provoke flaming, and do not know it fluently. It's all big words and handcuffs. To quote my favorite t.v. show, 'You imply disparity where none exists.' You're trying to 'pigeon-hole', where the subjects are fairly complex, even though not ultimately continuous, but still not binary. You might as well be asking whether it's rainy or sunny out. Even day and night only account for 22-23 hours out of our day. Speaking of big words, programming languages vary in a number of dimensions. Regardless of what surface you use to divide the space, you'll have data points which aren't quite intuitively aligned with the rest of their category; not to shirk the burden of proof. The high complexity of Python blurs the partition. You might give it a center, and some membership density function that decreases with the distance from it, like the volume of a loudspeaker. I'm not sure whether you would define these from use data, or something more a priori. The former doesn't require as much contortion. Some have proposed the same tactic for culture division and nation borders, incidentally, as one 'compromization' tactic; that is, to 'fuzzily' classify regions, and languages likewise. It would make Python, say 10% appropriate for scripting, and 90% object-oriented, just as 10% of 'our' police comes from, and 10% of our taxes goes to Sweden. However, you've never heard of a 70% Catholic, and further, the logistics on that formulation don't align quite rightly: it would be more like, 'we' pay takes to Sweden at 10% of the tax rate at its capital and anywhere else that only Sweden influences. Some places of commerce even accept the kroner too. That still might not make you be 70% Catholic, but definitely ten people definitely definitely can. Come to think of it, the percentages don't have to add up to 1, it's more like Python is 50% appropriate for scripting, and object-oriented in the high nineties. I guess I was just trying to be politically correct, impartial, or otherwise unbiased, though consequently rigid in the meantime. Sadly so. Linguists define distinctions between natural languages by measure of mutual interpretability. The two most similar languages out there may be practically the same; the two most different may not have even any syntax in common; and the one most different from the one closest to it may well be Python. Fancy that! In this participant's humble opinion, no. There are better scripting languages out there. In his arrogant opinion, no. It 'sets the curve'. From citronelu at yahoo.com Thu Jun 18 02:54:07 2009 From: citronelu at yahoo.com (CiTro) Date: Wed, 17 Jun 2009 23:54:07 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix Message-ID: I'm looking for a way to convert a string to it's unicode "brother". This means: stringOne = "\u0026" stringTwo = u"\u0026" print unicode(stringOne) == stringTwo The result is false. What function should I use, to duplicate the effect of the "u" prefix ? From steven at REMOVE.THIS.cybersource.com.au Thu Jun 18 03:05:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 07:05:20 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote: > "Steven D'Aprano" wrote in > message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... >> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: >> >>> 1) Windows does not make a distinction between text and binary files. >> >> Of course it does. ... > Ok, Python makes a distinction between text and binary files. Microsoft have reported a bug where cmd.exe fails to recognise EOF in a text file: http://support.microsoft.com/kb/156258 The behaviour of reading past the \0x1A character is considered a bug, which says that cmd.exe at least (and by extension Windows apps in general) are expected to stop reading at \0x1A for text files. Technically, the Windows file systems record the length of text files and so an explicit EOF character is redundant, nevertheless, the behaviour of stopping the read at \0x1A is expected. Whether you want to claim it is "Windows" or "the Windows shell" or something else is a fine distinction that makes little difference in practice. Anyway, here's Raymond Chen of Microsoft explaining more: http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx -- Steven From __peter__ at web.de Thu Jun 18 03:08:33 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Jun 2009 09:08:33 +0200 Subject: String to unicode - duplicating by function the effect of u prefix References: Message-ID: CiTro wrote: > I'm looking for a way to convert a string to it's unicode "brother". > > This means: > > stringOne = "\u0026" > stringTwo = u"\u0026" > > print unicode(stringOne) == stringTwo > > The result is false. What function should I use, to duplicate the > effect of the "u" prefix ? "\u..." has a special meaning only in unicode, not string literals: >>> s = "\u0026" >>> len(s) 6 >>> s.decode("unicode-escape") u'&' >>> _ == u"\u0026" True Peter From quentel.pierre at wanadoo.fr Thu Jun 18 03:09:41 2009 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Thu, 18 Jun 2009 00:09:41 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> On 18 juin, 05:28, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you Hi, buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : from buzhug import Base db = Base('foo').create(('name',str),('age',int)) db.insert('john',33) # simple queries print db(name='john') # complex queries print [ rec.name for rec in db if age > 30 ] # update rec.update(age=34) I made a few speed comparisons with Gadfly, KirbyBase (another pure- Python DB, not maintained anymore) and SQLite. You can find the results on the buzhug home page : http://buzhug.sourceforge.net The conclusion is that buzhug is much faster than the other pure- Python db engines, and (only) 3 times slower than SQLite - Pierre From citronelu at yahoo.com Thu Jun 18 03:23:31 2009 From: citronelu at yahoo.com (CiTro) Date: Thu, 18 Jun 2009 00:23:31 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix References: Message-ID: <060b9f4a-8ca5-4459-b302-66311f5c39e1@u10g2000vbd.googlegroups.com> Thank you, Peter. That solved my problem. From ldo at geek-central.gen.new_zealand Thu Jun 18 03:29:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 19:29:53 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro > wrote: > > [snip example code] > >> You haven't managed to get rid of the backslashes. > > [snip other example code] > >> Now you've lost track of the original point of the discussion, which is >> about using alternate quotes to avoid backslashes. > > Ah, selective amnesia, how useful you are. The original point of the > discussion was in fact about using alternative quotes to avoid alternate > backslashes (or at least excessive ones). No mention of avoiding "alternate backslashes (or at least excessive ones)". Here's what I said, in message : > In message , Rhodri > James wrote: > >> On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro >> wrote: >> >>> In message , Rhodri >>> James wrote: >>> >>>> 2. That output string has severe "leaning toothpick" syndrome. Python >>>> accepts both single and double quotes to help avoid creating something >>>> so unreadable: use them. >>> >>> Backslashes are more scalable. >> >> That doesn't excuse sprinkling several million backslashes through >> literal constants when there's a more readable alternative. > > Perl allows just about any printable character as a quote. I tried > alternative quotes for many years, and decided making that choice was a > waste of brain cells. > > So no, using alternative quotes does not make things more readable. Now compare that with Lie Ryan's examples which, instead of using backslashes, instead used alternative quotes plus backslashes in one example, and in the other example, alternative quotes, alternatives to literal quotes, and backslashes. As opposed to my original routine, which managed three levels of quoting using just backslashes. Do you begin to understand what I mean by "scalable"? From ldo at geek-central.gen.new_zealand Thu Jun 18 03:34:47 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 19:34:47 +1200 Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: In message <07ac7d7a-48e1-45e5-a21c- f2c259c7528a at j12g2000vbl.googlegroups.com>, per wrote: > i'm looking for a native python package to run a very simple data > base. Use Python mapping objects. Most real-world databases will fit in memory anyway. From arnodel at googlemail.com Thu Jun 18 03:39:40 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Jun 2009 08:39:40 +0100 Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Christian Heimes writes: > Terry Reedy wrote: >> If you mean 'be an instance of a class', which I think is the most >> natural reading, then Python *is* object-oriented and, if I understand >> what I have read correctly (so that ints are just (unboxed) ints and not >> members of an int class), Java *is not*! > > A friend of mine calls Java and C++ class centric programming languanges. ;) It's unfair on C++ given that one can write perfectly good C++ programs without classes, just as in Python. -- Arnaud From phostu at gmail.com Thu Jun 18 03:49:17 2009 From: phostu at gmail.com (Vincent) Date: Thu, 18 Jun 2009 00:49:17 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix References: <060b9f4a-8ca5-4459-b302-66311f5c39e1@u10g2000vbd.googlegroups.com> Message-ID: <8d2464e6-5059-43db-af0b-c72c6819b89c@p21g2000prn.googlegroups.com> On Jun 18, 3:23?pm, CiTro wrote: > Thank you, Peter. That solved my problem. the another way is, codecs.raw_unicode_escape_decode(stringOne) == stringTwo From steve at nospam.au Thu Jun 18 04:06:38 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 18:06:38 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au><4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.18.07.05.20 at REMOVE.THIS.cybersource.com.au... > On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote: > >> "Steven D'Aprano" wrote in >> message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... >>> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: >>> >>>> 1) Windows does not make a distinction between text and binary files. >>> >>> Of course it does. > ... >> Ok, Python makes a distinction between text and binary files. > > Microsoft have reported a bug where cmd.exe fails to recognise EOF in a > text file: > > http://support.microsoft.com/kb/156258 > > The behaviour of reading past the \0x1A character is considered a bug, > which says that cmd.exe at least (and by extension Windows apps in > general) are expected to stop reading at \0x1A for text files. > > > Technically, the Windows file systems record the length of text files and > so an explicit EOF character is redundant, nevertheless, the behaviour of > stopping the read at \0x1A is expected. Whether you want to claim it is > "Windows" or "the Windows shell" or something else is a fine distinction > that makes little difference in practice. > > Anyway, here's Raymond Chen of Microsoft explaining more: > > http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx > > > > -- > Steven If you're pleased to be learning something about Windows, then I'm pleased for you. The reason that I didn't give a full discussion about the history of DOS and Microsoft C was that I didn't think it was relevant to a Python newsgroup. My Bad. I didn't think anyone would care about the behaviour of copy vs xcopy in DOS 6-. I'd like to see the Tutorial corrected so that it gives some useful information about the behaviour of Python. As part of that, I'd like to see it corrected so that it doesn't include patently false information, but only because the patently false information about Windows obscures the message about Python. Believe me, I really don't care what myths you believe about Windows, or why you believe them. I've got a full and interesting life of my own. I'm only interested in getting the Python tutorial corrected so that it gives some sensible information to someone who hasn't already had the advantage of learning what the popular myths represent to the Python community. So far I've been pointed to a discussion of C, a discussion of DOS, and a discussion of Windows NT 4. Great. Glad to see that you know how to use the Internet. I'll give you that if you already have a meaning to assign to those meaningless words, you know more Python than I do. And I'll give you that if you already have a meaning to assign to those meaningless words, you know more Visual C than I do. Is that all there is? You're going to leave the tutorial because you can mount an obscure justification and it makes sense to someone who already knows what it means? Tell me it isn't so :~( From jason.heeris at gmail.com Thu Jun 18 04:10:29 2009 From: jason.heeris at gmail.com (Jason) Date: Thu, 18 Jun 2009 01:10:29 -0700 (PDT) Subject: How can I enumerate (list) serial ports? References: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Message-ID: <9a91f171-e223-44a1-8b26-f09650a4e823@g15g2000pra.googlegroups.com> On Jun 18, 2:20?pm, Tim Golden wrote: > but I imagine that, behind the scenes, it's doing some sort > of conditional imports according to platform. I have, and yes indeed it does. > I imagine you'd > have to do something similar to get a list of port names. That's what I thought, although I might just defer to the user knowing what to type in (since they would have to identify the port allocated to the device in the first place). > On Windows, WMI can give you what you want. Look at the > Win32_SerialPort class. Hopefully, someone else can help > for other platforms. Thanks for this pointer :) Cheers, Jason From ben+python at benfinney.id.au Thu Jun 18 04:55:04 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Jun 2009 18:55:04 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <87r5xh2a6v.fsf@benfinney.id.au> "steve" writes: > So far I've been pointed to a discussion of C, a discussion of DOS, > and a discussion of Windows NT 4. Great. Glad to see that you know how > to use the Internet. Says the person who doesn't want to attach an identity to his messages. (Yes, that's ad hominem if used to dismiss your argument; but it's *you* that is raising ?know how to use the internet?, so at that point you become fair game, IMO.) > Is that all there is? You're going to leave the tutorial because you > can mount an obscure justification and it makes sense to someone who > already knows what it means? Tell me it isn't so :~( Who is ?you?? Someone who knows how to use the internet surely can tell that comp.lang.python isn't the place to come expecting *changes* in the Python tutorial. You started out asking how to *interpret* it, which is fine for this forum; but discussing it here isn't going to lead automatically to any *midification* to a document developed within the core of Python. -- \ ?Whatever you do will be insignificant, but it is very | `\ important that you do it.? ?Mahatma Gandhi | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Jun 18 05:09:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Jun 2009 11:09:38 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> Message-ID: <4a3a0442$0$9848$426a74cc@news.free.fr> Asun Friere a ?crit : (snip) > OTOH the whole notion of defining OO by the use of classes > automatically excludes from consideration prototype-based OO languages > (eg. Self) which arguably offer a purer approach to OO than class > centric languages. FWIW, there's no notion of "class" in the minimal (and only commonly agreed AFAIK) definitions of OO: 1/ an object id defined by an id, a state and a behaviour 2/ objects communicate by sending messages to each others From conra2004 at yahoo.com Thu Jun 18 05:24:39 2009 From: conra2004 at yahoo.com (yadin) Date: Thu, 18 Jun 2009 02:24:39 -0700 (PDT) Subject: please help...writing set to a file Message-ID: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Good day every one! I got this python program that returns me a set like this.. Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] I was reading this from a file?. How can I transform this to something that looks like this Column1 Column 2 100 A 200 B 300 C 400 D E F G And then write this to a file??? thank you for taking your time!!! From pdpinheiro at gmail.com Thu Jun 18 05:28:55 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 18 Jun 2009 02:28:55 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> Message-ID: <9c21ab4a-21f8-45e6-a3cb-54559eb900f1@t10g2000vbg.googlegroups.com> On Jun 18, 8:09?am, Pierre Quentel wrote: > On 18 juin, 05:28, per wrote: > > > > > > > hi all, > > > i'm looking for a native python package to run a very simple data > > base. i was originally using cpickle with dictionaries for my problem, > > but i was making dictionaries out of very large text files (around > > 1000MB in size) and pickling was simply too slow. > > > i am not looking for fancy SQL operations, just very simple data base > > operations (doesn't have to be SQL style) and my preference is for a > > module that just needs python and doesn't require me to run a separate > > data base like Sybase or MySQL. > > > does anyone have any recommendations? the only candidates i've seen > > are snaklesql and buzhug... any thoughts/benchmarks on these? > > > any info on this would be greatly appreciated. thank you > > Hi, > > buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : > > from buzhug import Base > db = Base('foo').create(('name',str),('age',int)) > db.insert('john',33) > # simple queries > print db(name='john') > # complex queries > print [ rec.name for rec in db if age > 30 ] > # update > rec.update(age=34) > > I made a few speed comparisons with Gadfly, KirbyBase (another pure- > Python DB, not maintained anymore) and SQLite. You can find the > results on the buzhug home page :http://buzhug.sourceforge.net > > The conclusion is that buzhug is much faster than the other pure- > Python db engines, and (only) 3 times slower than SQLite > > - Pierre Which means that, at this point in time, since both gadfly and sqlite use approximately the same API, sqlite takes the lead as a core package (post-2.5 anyway) From benjamin.kaplan at case.edu Thu Jun 18 06:30:18 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Jun 2009 06:30:18 -0400 Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 18, 2009 at 5:24 AM, yadin wrote: > Good day every one! > > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? > thank you for taking your time!!! > I don't think you can. A set doesn't maintain order so you couldn't count on it being returned in a particular order. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From karthik301176 at gmail.com Thu Jun 18 06:30:35 2009 From: karthik301176 at gmail.com (Karthik) Date: Thu, 18 Jun 2009 03:30:35 -0700 (PDT) Subject: Packing a ctypes struct containing bitfields. Message-ID: Hello Everybody, I'm trying to create a packed structure in ctypes (with one 64-bit element that is bitfielded to 48 bits), unsuccessfully: =================================== from ctypes import * class foo (Structure): _pack_ = 1 _fields_ = [ ("bar", c_ulonglong, 48), ] print("sizeof(foo) = %d" % sizeof(foo)) =================================== I'm expecting that this should print 6 - however, on my box, it prints 8. The following piece of C code, when compiled and run, prints 6, which is correct. =================================== struct foo { unsigned long long bar: 48; }; printf("sizeof(foo) = %d", sizeof(foo)); =================================== So... what am I doing wrong? Thanks, Karthik. From davea at ieee.org Thu Jun 18 06:34:05 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Jun 2009 06:34:05 -0400 Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: <4A3A181D.6020608@ieee.org> yadin wrote: > Good day every one! > > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp =?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? > thank you for taking your time!!! > > > Since a set has no order, it cannot be done. There's no association between 100 and A that can be independently determined from just the set and the list. Just how was the original assignment worded, anyway? And what version of Python are you using for it? After you solve that problem (perhaps by returning a list in both cases), then the real question might be one of formatting. Since the columns in your example don't line up in any meaningful way, perhaps you just want to slap a few spaces before and between the elements. You'll need to do a strip() on the pp items, to get rid of the newline. Then something like: line = " " + ppitem.strip() + " " + otheritem Loop through the lists and send the lines to the file. Don't forget to close it at the end. From georges at racinet.fr Thu Jun 18 07:21:56 2009 From: georges at racinet.fr (Racinet Georges) Date: Thu, 18 Jun 2009 13:21:56 +0200 Subject: Default namespace and attributes with ElementTree 1.3 Message-ID: <9405D110-5080-4BDB-BA80-187472C6DEF4@racinet.fr> Hi there, I've got a problem with the way ElementTree 1.3a3-20070912 handles attributes with the default namespace feature (please feel free to redirect me if this isn't the proper place to discuss such matters). >>> from elementtree import ElementTree as ET >>> e = ET.fromstring('') >>> ET.tostring(e) '' Notice that the 'id' attribute does not belong to the "foo" namespace. If I got the XML 1.0 specification right, this is perfectly normal (Quoting http://www.w3.org/TR/REC-xml-names/#defaulting) : "Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. (...) The namespace name for an unprefixed attribute name always has no value." Now, trying to serialize this back with the default_namespace feature of ET 1.3, I get an error, as predicted by the online documentation >>> t = ET.ElementTree(e) >>> t.write(sys.stdout, default_namespace='foo') Traceback (...) ValueError: cannot use non-qualified names with default_namespace option Since this is a parse/serialize round-trip, I think that this behaviour isn't right, and that unprefixed attributes should go through. Actually, shouldn't attributes even be outside of the scope of the default namespace feature ? Is there hope for future improvements about this ? I saw some FIXME comment in the source. The svn head version (rev 528) seems to be identical in that respect, by the way. Removing in ElementTree.py the part where the ValueError is been raised seems to solve the issue at first sight : >>> t.write(sys.stdout, default_namespace='foo') but this lets also unprefixed elements go through, which is unwanted: >>> e = ET.fromstring('') >>> t = ET.ElementTree(e) >>> t.write(sys.stdout, default_namespace='foo') I wouldn't care in my application, whose output is xhtml, though. Regards, -- Georges Racinet, http://www.racinet.fr Zope/CPS/Plone expertise, assistance & development GPG: 0x4862FFF7 -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 489 bytes Desc: This is a digitally signed message part URL: From x.piter at gmail.com Thu Jun 18 07:24:42 2009 From: x.piter at gmail.com (Piter_) Date: Thu, 18 Jun 2009 14:24:42 +0300 Subject: pyserial question Message-ID: <6f4f96030906180424w367d4d11r2f1d37ec264a4bf@mail.gmail.com> Hi all. I try to control some equipment from python trough comport. I have not succeeded in pyserial. But if I use this terminal: http://hw-server.com/files/priloha/termv19b.zip http://hw-server.com/software/termv19b.html It works with following settings. Boud rate: 9600 Data bids: 8 Parity: none stop bids: 1 Handshaking: RST on TX I cant find out how to set "Handshaking RST on TX" in pyserial. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Thu Jun 18 07:29:31 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 18 Jun 2009 06:29:31 -0500 Subject: UDP queue size References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: Martin P. Hellwig wrote: > Scott David Daniels wrote: > > ???????? wrote: > >> I got a problem about UDP. > >> > >> How do I get the UDP buffer size? > >> > >> When the server had some delay in handling incoming UDP, it will lost > >> some package. I wonder it's because the system buffer size, is there any > >> ways to find the exactly size of the buffer? > > > > UDP is defined as "best effort then give up," so _everything_ that > > handles a UDP packet is allowed to drop it; that means switchers, > > routers, ..., anything along the path to the target application. > > So, you cannot expect to do any better than a conservative guess, > > perhaps augmented by dynamic scaling. > > I would like to add, that you are most likely to lose packages because > they are to big, I can not remember for sure if UDP had a fixed limit > above what the MTU does, but you might want to look at that > direction too. UDP messages can be up to 64k. However they will be fragmented to the MTU which is 1500 bytes for most ethernet traffic. The means that the chance of losing a bigger UDP message is much higher because you only need to lose one of the fragments to lose the message. Most people who use UDP try to keep the total message size below 1500 bytes (1480 data without the header IIRC) for that reason. wireshark/tcpdump will quickly show you whether you are fragmenting your UDP messages. Another thing to bear in mind with UDP is that you can easily exceed the packets / second that switches / routers can bear if you send lots of small messages. Switches / routers will start dumping packets if you do that since. Some switches just crash in my experience too ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From anthra.norell at bluewin.ch Thu Jun 18 07:39:28 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Thu, 18 Jun 2009 13:39:28 +0200 Subject: CAD file format specifications? In-Reply-To: <4A37D79D.4070604@hughes.net> References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> Message-ID: <4A3A2770.2030802@bluewin.ch> norseman wrote: > Anthra Norell wrote: >> Andres Acosta wrote: >>> HI there Anthara have you checked out www.Blender.org, It is open >>> source and accepts a lot of your formats. for import and export. >>> Anrdres >>> Anthra Norell wrote: >>>> Hi, >>>> Anyone working with CAD who knows about numeric data entry? I >>>> have 3d coordinates of a construction site on a slope (borders, >>>> setbacks and isometric elevation lines). Someone made me aware of >>>> Google's Sketch Up. It looks very attractive for the purpose of >>>> architectural planning, especially suited to create visual >>>> impressions. Doodling seems easy. But I have to start with modeling >>>> the terrain and the envelope and the only way to do that seems to >>>> be in one of several CAD file formats (skp, dwg, dxf, 3ds, ddf and >>>> dem). So I need to cast my numbers into one of these formats. Any >>>> suggestions? >>>> >>>> Thanks >>>> >>>> Frederic >>>> >>> >>> >> Andres, >> >> Thanks for the tip. I wasn't aware of Blender. The web page looks >> promising. I downloaded it and am going to have a look at it. >> >> Frederic >> > =================== > Frederic; > Could you be a little more specific about your data's current > format and the format that seems to best suit your needs? > > Tabular source data and dxf output files for use in CAD are quite > simple to write. But this assumes dxf suits your display program's > needs. > > I think, for display purposes, Microsoft Word still accepts dxf files. > I run unix mostly and I don't keep up with Window$. ;( > > > I suggest you Google for CAD (Computer Aided Drafting) programs. There > are free ones out there. Most will take the DXF format. If the > contours are pre-traced you can polyline them to make the contours > look correct. If the 3D points are X-section or random you will need a > contour generating program.... and so it goes. > > Let's start here - what is your area of expertise, how much math in > your background, why are you attempting this exercise? > > In order to communicate properly I need to know. I can tailor my > comments to suit. > > > > > > Steve Turner > Licensed Land Surveyor CA 5197 (inactive) > 1st order Photogrammetric Compiler (2D depctions from 3D photo sets) > in short Map Maker, Master Grade > norseman at hughes.net Steve, Thank you for your support. In a nutshell: I have a patch of constructible land and have the coordinates of its borders and a few other parameters. The patch is on a slope, so I had a surveyor do the isometric elevation lines. That's a lot more coordinates. The coordinates are plain text. Plain text is a breeze to convert into Python sequences. So I made a bitmap of the ground plan with the elevation lines as a template to play around doing architecture. A ground plan is 2d and as such is rather ill-suited to conceptualize the vertical dimension. Then someone made me aware of Google Sketch Up. It looks sort of like MS Paint in three dimensions: intuitive for doodling. Before I waste time doodling a flying or a subterranean house I want to make a three-dimensional template of the terrain and the constructible volume. The way to import numeric data, for what I see, is as one of the following CAD-file formats: skp, dwg, dxf, 3ds, ddf or dem. So I need to convert my coordinates into one of them, preferably the conversion-friendliest, but I don't have the specifications of any one. I had a look at Blender. It looks impressive too. It might be an alternative to Sketch Up. I'll worry about that later. My immediate need is a file conversion utility. A cursory inspection of Blender's menu tabs and the various help options didn't turn up a file-conversion utility. So, my question is: How do I convert a bunch of three-dimensional coordinates defining lines into a file format Sketch Up can read (skp, dwg, dxf, 3ds, ddf or dem)? Frederic From darcy at druid.net Thu Jun 18 08:06:28 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Jun 2009 08:06:28 -0400 Subject: python tutorial In-Reply-To: References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <20090618080628.2adb7662.darcy@druid.net> On 18 Jun 2009 07:05:20 GMT Steven D'Aprano wrote: > Technically, the Windows file systems record the length of text files and > so an explicit EOF character is redundant, nevertheless, the behaviour of > stopping the read at \0x1A is expected. Whether you want to claim it is I really loved CP/M in its day but isn't it time we let go? -- 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 piet at cs.uu.nl Thu Jun 18 08:08:23 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 14:08:23 +0200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: >>>>> Charles Yeomans (CY) wrote: >CY> Memory management may be an "implementation detail", but it is >CY> unfortunately one that illustrates the so-called law of leaky >CY> abstractions. So I think that one has to write code that follows the >CY> memory management scheme of whatever language one uses. For code written >CY> for CPython only, as mine is, RAII is an appropriate idiom and not kludgy >CY> at all. Under your assumptions, its use would be wrong, of course. I dare to say that, even in CPython it is doomed to disappear, but we don't know yet on what timescale. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From peter.bell at com.au Thu Jun 18 08:27:02 2009 From: peter.bell at com.au (Peter Bell) Date: Thu, 18 Jun 2009 22:27:02 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au><4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a3a329e$1_4@news.peopletelecom.com.au> > "Steven D'Aprano" writes >http://support.microsoft.com/kb/156258 That says that Windows NT 3.5 and NT 4 couldn't make a distinction between text and binary files. I don't think that advances your case. If they had changed the Windows behaviour, yes, but Windows 7 seems to be compatible with NT 3.5 rather than with DOS. Peter Bell. From grguthrie at gmail.com Thu Jun 18 08:38:15 2009 From: grguthrie at gmail.com (guthrie) Date: Thu, 18 Jun 2009 05:38:15 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> Message-ID: <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> On Jun 17, 6:38?pm, Steven Samuel Cole wrote: > Still don't really understand why my initial code didn't work, though... Your code certainly looks reasonable, and looks to me like it "should" work. The comment of partial namespace is interesting, but unconvincing (to me) - but I am not a Python expert! It would certainly seem that within that code block it is in the local namespace, not removed from that scope to be in another. Seems that it should either be a bug, or else is a design error in the language! Just as in the above noted "WTF" - non-intuitive language constructs that surprise users are poor design. From ml at well-adjusted.de Thu Jun 18 09:07:59 2009 From: ml at well-adjusted.de (Jochen Schulz) Date: Thu, 18 Jun 2009 15:07:59 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: <20090618130759.GC19607@wasteland.homelinux.net> Terry Reedy: > Jochen Schulz wrote: >> >> If, by "object-oriented" you mean "everything has to be put into >> classes", then Python is not object-oriented. > > That depends on what you mean by 'put into classes' (and 'everything'). :) What I meant was that in Python you can write code without defining your own classes at all. I had Java in mind where you cannot write a program without using the keyword 'class'. But I think we agree here. J. -- In idle moments I remember former lovers with sentimental tenderness. [Agree] [Disagree] -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From alan.isaac at gmail.com Thu Jun 18 09:22:56 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 18 Jun 2009 13:22:56 GMT Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: On 6/18/2009 5:24 AM yadin apparently wrote: > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? http://docs.python.org/library/functions.html#sorted http://docs.python.org/library/itertools.html#itertools.izip_longest http://docs.python.org/library/stdtypes.html#str.format http://docs.python.org/library/functions.html#open hth, Alan Isaac From rhodri at wildebst.demon.co.uk Thu Jun 18 09:28:32 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 14:28:32 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro wrote: > Now compare that with Lie Ryan's examples which, instead of using > backslashes, instead used alternative quotes plus backslashes in one > example, and in the other example, alternative quotes, alternatives to > literal quotes, and backslashes. As opposed to my original routine, which > managed three levels of quoting using just backslashes. Do you begin to > understand what I mean by "scalable"? I do, and I still disagree. More importantly, Lie Ryan's examples were much more readable, which is what I was complaining about. -- Rhodri James *-* Wildebeest Herder to the Masses From nick at craig-wood.com Thu Jun 18 09:29:32 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 18 Jun 2009 08:29:32 -0500 Subject: Packing a ctypes struct containing bitfields. References: Message-ID: Karthik wrote: > Hello Everybody, > > I'm trying to create a packed structure in ctypes (with one 64-bit > element that is bitfielded to 48 bits), > unsuccessfully: > > =================================== > from ctypes import * > > class foo (Structure): > _pack_ = 1 > _fields_ = [ > ("bar", c_ulonglong, 48), > ] > > print("sizeof(foo) = %d" % sizeof(foo)) > =================================== > I'm expecting that this should print 6 - however, on my box, it prints > 8. > > The following piece of C code, when compiled and run, prints 6, which > is correct. > =================================== > struct foo { > unsigned long long bar: 48; > }; > > printf("sizeof(foo) = %d", sizeof(foo)); > =================================== > > So... what am I doing wrong? I compiled and ran the above with gcc on my linux box - it prints 8 unless I add __attribute__((__packed__)) to the struct. I'm not sure that using bitfields like that is a portable at all between compilers let alone architectures. I'd probably do from ctypes import * class foo (Structure): _pack_ = 1 _fields_ = [ ("bar0", c_uint32), ("bar1", c_uint16), ] def set_bar(self, bar): self.bar0 = bar & 0xFFFFFFFF self.bar1 = (bar >> 32) & 0xFFFF def get_bar(self): return (self.bar1 << 32) + self.bar0 bar = property(get_bar, set_bar) print "sizeof(foo) = %d" % sizeof(foo) f = foo() print f.bar f.bar = 123456789012345 print f.bar Which prints sizeof(foo) = 6 0 123456789012345 -- Nick Craig-Wood -- http://www.craig-wood.com/nick From HeinTest at web.de Thu Jun 18 09:35:38 2009 From: HeinTest at web.de (=?windows-1252?Q?Hans_M=FCller?=) Date: Thu, 18 Jun 2009 15:35:38 +0200 Subject: Once again, comparison wxpython with PyQt Message-ID: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Here we have to select between wxPython and PyQt for a medium size project. In this project several hundred dialogs are to be created. This work will be done by a program generator which has to re-written. The question now is which framework should we use. As far as I could found is PyQt with the Qt Framework the superior choice. Most articles I found (not all) results to PyQt. But Qt is expensive ~ 3400? per Developer and OS. Since these articles are more or less old, it would be nice to hear your current opinions. Condensed, I found this pros / cons: Pros for Qt: - best framwork, well designed - nice GUI builders - faster execution Cons: - epensive Pros for wxPython: - cheap - big community Cons: - more layers on top of OS - more bugs (still valid ?) - slower Can someone tell me about his experiences with one or both frameworks ? Thanks a lot, Greetings Hans From no.email at please.post Thu Jun 18 09:36:34 2009 From: no.email at please.post (kj) Date: Thu, 18 Jun 2009 13:36:34 +0000 (UTC) Subject: command-line one-liners a la Perl? Message-ID: I'm a recovering Perl addict, and I'm jonesin' badly for command-line one-liners, like % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt How can I get my fix with Python? kynn From pruebauno at latinmail.com Thu Jun 18 09:56:00 2009 From: pruebauno at latinmail.com (nn) Date: Thu, 18 Jun 2009 06:56:00 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> Message-ID: <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> On Jun 18, 8:38?am, guthrie wrote: > On Jun 17, 6:38?pm, Steven Samuel Cole > wrote: > > > Still don't really understand why my initial code didn't work, though... > > Your code certainly looks reasonable, and looks to me like it "should" > work. The comment of partial namespace is interesting, but > unconvincing (to me) - but I am not a Python expert! It would > certainly seem that within that code block it is in the local > namespace, not removed from that scope to be in another. > > Seems that it should either be a bug, or else is a design error in the > language! > > Just as in the above noted "WTF" - non-intuitive language constructs > that surprise users are poor design. This is certainly an odd one. This code works fine under 2.6 but fails in Python 3.1. >>> class x: ... lst=[2] ... gen=[lst.index(e) for e in lst] ... Traceback (most recent call last): File "", line 1, in File "", line 3, in x File "", line 3, in NameError: global name 'lst' is not defined >>> From python at mrabarnett.plus.com Thu Jun 18 10:05:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Jun 2009 15:05:12 +0100 Subject: command-line one-liners a la Perl? In-Reply-To: References: Message-ID: <4A3A4998.1090007@mrabarnett.plus.com> kj wrote: > > > I'm a recovering Perl addict, and I'm jonesin' badly for command-line > one-liners, like > > % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt > > How can I get my fix with Python? > python -c "print 'Hello world!'" Although you need to remember that Python makes much more use of whitespace, which limits the usefulness of the command line. From x.piter at gmail.com Thu Jun 18 10:18:10 2009 From: x.piter at gmail.com (Piter_) Date: Thu, 18 Jun 2009 07:18:10 -0700 (PDT) Subject: pyserial. How to set Handshaking to "RST on TX". Message-ID: <80890a0d-5645-4f56-a373-1e80bae5dbde@q37g2000vbi.googlegroups.com> Hi all I try to drive some equipment trough serial port. So far I could do it with some windows com port terminal if handhaking set to "RTS on TX". http://hw-server.com/software/termv19b.html But I cant find out how to set it in pyserial. Thanks in advance for any hint. From unayok at gmail.com Thu Jun 18 10:32:28 2009 From: unayok at gmail.com (unayok) Date: Thu, 18 Jun 2009 07:32:28 -0700 (PDT) Subject: command-line one-liners a la Perl? References: Message-ID: <8e29f8d7-edd1-493a-aa9a-f15565bd9353@r13g2000vbr.googlegroups.com> On Jun 18, 9:36?am, kj wrote: > I'm a recovering Perl addict, and I'm jonesin' badly for command-line > one-liners, like > > ? % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt > > How can I get my fix with Python? > > kynn I'd encourage you to learn the ways of Python which ordinarily don't encourage cramming lots of code into a single line. However... if you are insistent on seeing how much rope Python can give you to hang yourself... ;) $ python -c 'print "\n".join( "\t".join( ( data[3], data[1] ) ) for data in ( lambda fn : ( line.strip().split("\t") for line in file( fn, "r" ) ) )( "in.txt" ) if data[2].lower().find( "frobozz" ) > -1 )' (untested) should do something similar to your perl statement (display the fourth and second fields from tab-delimited lines containing "frobozz" in any case-mixture in the third field for lines read from the "in.txt" file). Note that the frobozz search is not a regex search in this example. Requiring regex would make things more complicated. Probably could be cleaned up a bit. u. From castironpi at gmail.com Thu Jun 18 10:44:42 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 18 Jun 2009 07:44:42 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: On Jun 18, 6:07?am, Jochen Schulz wrote: > Terry Reedy: > > > Jochen Schulz wrote: > > >> If, by "object-oriented" you mean "everything has to be put into > >> classes", then Python is not object-oriented. > > > That depends on what you mean by 'put into classes' (and 'everything'). > > :) What I meant was that in Python you can write code without defining > your own classes at all. I had Java in mind where you cannot write a > program without using the keyword 'class'. But I think we agree here. Numbers have infinite precision. From deets at nospam.web.de Thu Jun 18 10:49:21 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 18 Jun 2009 16:49:21 +0200 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <79v28tF1srnv7U1@mid.uni-berlin.de> Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size > project. In this project several hundred dialogs are to be created. This > work will be done by a program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. No, it's not. It is LGPL by now. You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's about 500?. However, it is much less than Qt used to be. Diez From chris at simplistix.co.uk Thu Jun 18 10:55:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 15:55:51 +0100 Subject: Announcing www.python-excel.org Message-ID: <4A3A5577.2060704@simplistix.co.uk> Hi All, Google unfortunately has a knack of presenting prospective Python users who need to work with Excel files with information that is now really rather out of date. To try and help with this, I've setup a small website at: http://www.python-excel.org ...to try and list the latest recommended ways of working with Excel files in Python. If you work with excel files in Python, then please take a look and let me know what you think. cheers, Chris PS: If anyone reading this has a python-related blog, it might help Google if you could post a short entry about this new site. -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From piet at cs.uu.nl Thu Jun 18 11:02:27 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 17:02:27 +0200 Subject: Newbie queue question References: Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Hi, >JE> I'm pretty new to Python (2.6) and I've run into a problem I just >JE> can't seem to solve. >JE> I'm using dbfpy to access DBF tables as part of a little test project. >JE> I've programmed two separate functions, one that reads the DBF in main >JE> thread and the other which reads the DBF asynchronously in a separate >JE> thread. >JE> Here's the code: >JE> def demo_01(): >JE> '''DBF read speed only''' >JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) >JE> for i1 in xrange(len(dbf1)): >JE> rec = dbf1[i1] >JE> dbf1.close() >JE> def demo_03(): >JE> '''DBF read speed into a FIFO queue''' >JE> class mt(threading.Thread): >JE> q = Queue.Queue(64) >JE> def run(self): >JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) >JE> for i1 in xrange(len(dbf1)): >JE> self.q.put(dbf1[i1]) >JE> dbf1.close() >JE> del dbf1 >JE> self.q.join() >JE> t = mt() >JE> t.start() >JE> while t.isAlive(): >JE> try: >JE> rec = t.q.get(False, 0.2) >JE> t.q.task_done(); >JE> except: >JE> pass >JE> del t >JE> However I'm having serious issues with the second method. It seems >JE> that as soon as I start accessing the queue from both threads, the >JE> reading speed effectively halves. >JE> I have tried the following: >JE> 1. using deque instead of queue (same speed) >JE> 2. reading 10 records at a time and inserting them in a separate loop >JE> (hoped the congestion would help) >JE> 3. Increasing queue size to infinite and waiting 10 seconds in main >JE> thread before I started reading - this one yielded full reading speed, >JE> but the waiting took away all the threading benefits >JE> I'm sure I'm doing something very wrong here, I just can't figure out >JE> what. For a start the thread switching and the queue administration just take time, that you can avoid if you do everything sequentially. Threading can have an advantage if there is the possiblilty of overlap. But there is none in your example, so it's just overhead. If your processing would do something substantially and if the reading of the file would be I/O bound for example. You don't say how big the file is, and it also may be in your O.S. cache so then reading it would essentially be CPU bound. And then there is this code: while t.isAlive(): try: rec = t.q.get(False, 0.2) t.q.task_done(); except: pass t.q.get(False, 0.2) means do a non-blocking get, so that when there is nothing in the queue it returns immediately and then takes the exception path which also is substantial overhead. Whether this will happen or not depends on the timing which depends on the scheduling of the O.S. For example when the O.S. schedules the main task first it will be busy wait looping quite a lot before the first item arrives in the queue. If the file is small it will probably put then all the items in the queue and there will be no more busy wait looping. But busy wait looping just consumes CPU time. By the way, the second parameter (0.2) which is supposed to be the timeout period is just ignored if the first parameter is false. You might be better off giving True as the first parameter to get. I dislike any form of busy wait loop. It would be better to just use a normal get(), but that conflicts with your end detection. while t.isAlive() is not a particularly good way to detect that the processing is finished I think because of timing issues. After the last t.q.task_done() [which doesn't need a semicolon, by the way] it takes some time before the self.q.join() will be processed and the thread finishes. In the mean time while t.isAlive() is constantly being tested, also wasting CPU time. IMHO a better way is to put a sentinel object in the queue: def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) self.q.put(None) dbf1.close() del dbf1 self.q.join() while True: rec = t.q.get() t.q.task_done() if rec is None: break And then you probably can also get rid of the self.q.join() and t.q.task_done() -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From pdpinheiro at gmail.com Thu Jun 18 11:22:59 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 18 Jun 2009 08:22:59 -0700 (PDT) Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> Message-ID: <5995aa64-ca3c-4e82-a8ca-8138af59ac2e@e20g2000vbc.googlegroups.com> On Jun 18, 3:49?pm, "Diez B. Roggisch" wrote: > Hans M?ller wrote: > > Here we have to select between wxPython and PyQt for a medium size > > project. In this project several hundred dialogs are to be created. This > > work will be done by a program generator which has to re-written. > > > The question now is which framework should we use. > > As far as I could found is PyQt with the Qt Framework the superior choice. > > Most articles I found (not all) results to PyQt. > > But Qt is expensive ~ 3400? per Developer and OS. > > No, it's not. It is LGPL by now. > > You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's > about 500?. However, it is much less than Qt used to be. > > Diez Not quite. You only have to pay for the commercial license -- you can use PyQT as GPL as well. This may or may not be acceptable for Hans's purposes, but nowhere near "have to pay licensing". From newsgroup at silveraxe.de Thu Jun 18 11:31:04 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Thu, 18 Jun 2009 17:31:04 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <79v28tF1srnv7U1@mid.uni-berlin.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> Message-ID: <4a3a5dc2$0$32676$9b4e6d93@newsspool2.arcor-online.net> Diez B. Roggisch schrieb: >> Here we have to select between wxPython and PyQt for a medium size >> project. In this project several hundred dialogs are to be created. This >> work will be done by a program generator which has to re-written. >> >> The question now is which framework should we use. >> As far as I could found is PyQt with the Qt Framework the superior choice. >> Most articles I found (not all) results to PyQt. >> But Qt is expensive ~ 3400? per Developer and OS. > > No, it's not. It is LGPL by now. > > You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's > about 500?. However, it is much less than Qt used to be. You are pretty close, it's ?350.00 + 15% VAT (UK) See here: http://www.riverbankcomputing.co.uk/commercial/buy Best, Hilmar From chris at simplistix.co.uk Thu Jun 18 11:38:14 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 16:38:14 +0100 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 Message-ID: <4A3A5F66.2030701@simplistix.co.uk> Hi All, Too many people in the Python community *still* think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's EuroPython conference in Birmingham, UK on Monday, 29th June that will cover working with Excel files in Python using the pure-python libraries xlrd, xlwt and xlutils. I'll be looking to cover: - Reading Excel Files Including extracting all the data types, formatting and working with large files. - Writing Excel Files Including formatting, many of the useful frilly extras and writing large excel files. - Modifying and Filtering Excel Files A run through of taking existing Excel files and modifying them in various ways. - Workshop for your problems I'm hoping anyone who attends will get a lot out of this! If you're planning on attending and have a particular problem you'd like to work on in this part of the tutorial, please drop me an email and I'll try and make sure I come prepared! All you need for the tutorial is a working knowledge of Excel and Python, with a laptop as an added benefit, and to be at EuroPython this year: http://www.europython.eu/ I look forward to seeing you all there! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From james at agentultra.com Thu Jun 18 11:45:45 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 18 Jun 2009 11:45:45 -0400 Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <85iqita6l2.fsf@agentultra.com> per writes: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you berkeley db is pretty fast. locking and such nice features are included. the module you'd be looking at is bsddb i believe. From aahz at pythoncraft.com Thu Jun 18 12:09:24 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Jun 2009 09:09:24 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: In article , Steven D'Aprano wrote: > >Additionally, while I'm a fan of the simplicity of CPython's ref counter, >one serious side effect of it is that it requires the GIL, which >essentially means CPython is crippled on multi-core CPUs compared to non- >ref counting implementations. Your bare "crippled" is an unfair overstatement. What you meant to write was that computational multi-threaded applications that don't use NumPy are crippled. Otherwise you're simply spreading FUD. -- 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 vinay_sajip at yahoo.co.uk Thu Jun 18 12:15:12 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 18 Jun 2009 09:15:12 -0700 (PDT) Subject: logging.fileConfig limitations? References: Message-ID: <6478bb0e-69aa-490f-8d4b-109f1e09617d@r3g2000vbp.googlegroups.com> On Jun 17, 9:05?pm, Mani Ghasemlou wrote: > Hi all, > > C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.log > > Now it turns out that the logging module can't find "C:/Documents and > Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log" > specified in the "args" section, and rightfully so because this is an > encoded string. *There does not seem to be a way for me to specify the > encoding of the string so that the logging module resolves the proper > unicode path.* This is my key problem! > > Is there some way to accomplish what I want? > No need to poke about in the source. Here's my script: #-- log_ufn.py -- import logging.config logging.config.fileConfig("log_ufn.ini") logging.error("Holy Cow, Batman!") and here's my configuration file, adapted from yours: #-- log_ufn.ini -- [formatters] keys: normal [handlers] keys: rotatingfile [loggers] keys: root [formatter_normal] format: %(asctime)s %(levelname)s %(module)s: %(message)s [logger_root] level: DEBUG handlers: rotatingfile [handler_rotatingfile] class: handlers.RotatingFileHandler formatter: normal args: (u"C:/Temp/\u00DF\u00E9\u00E4\u00F6\u00DC2/MyApp.log", "a", 2*1024*1024, 5, None) Note that I specified a Unicode filename, with Unicode escapes for ?????2. After I run the script (using ActivePython 2.5.2.2), I get the following output: # -- Contents of C:\temp\?????2\MyApp.log -- 2009-06-18 17:07:30,493 ERROR log_ufn: Holy Cow, Batman! Which seems to be what one would expect. From ethan at stoneleaf.us Thu Jun 18 12:30:28 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Jun 2009 09:30:28 -0700 Subject: python tutorial In-Reply-To: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4A3A6BA4.1050909@stoneleaf.us> steve wrote: > "Robert Kern" wrote in message > news:mailman.1728.1245289092.8015.python-list at python.org... > >>On 2009-06-17 19:36, steve wrote: >> >>>>"Carl Banks" wrote in message >>>>news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>>>On Jun 15, 7:56 pm, "steve" wrote: >>>> >>>>>I was just looking at the python tutorial, and I noticed these lines: >>>>> >>>>>http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>>> >>>>>"Windows makes a distinction between text and binary files; >>>>>"the end-of-line characters in text files are automatically altered >>>>>"slightly when data is read or written. >>>>> >>>>>I don't see any obvious way to at docs.python.org to get that >>>>>corrected: >>>>>Is >>>>>there some standard procedure? >>>> >>>>What's wrong with it? >>>> >>>> >>>>Carl Banks >>> >>>1) Windows does not make a distinction between text and binary files. >>> >>>2) end-of-line characters in text files are not automatically altered by >>>Windows. >> >>The Windows implementation of the C standard makes the distinction. E.g. >>using stdio to write out "foo\nbar\n" in a file opened in text mode will >>result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode >>will result in "foo\nbar\n" in memory. Reading such a file in binary mode >>will result in "foo\r\nbar\r\n". In your bug report, you point out several >>proprietary APIs that do not make such a distinction, but that does not >>remove the implementations of the standard APIs that do make such a >>distinction. >> >> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >> >>Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >>runtime, but I think it's a reasonable statement on the whole. >> >>-- >>Robert Kern > > > > Which is where I came in: I was looking for simple file IO in the tutorial. > The tutorial tells me something false about Windows, rather than something > true about Python. > > I'm looking at a statement that is clearly false (for anyone who knows > anything about Windows file systems and Windows file io), which leaves the > Python behaviour completely undefined (for anyone who knows nothing about > Python). > > I understand that many of you don't really have any understanding of > Windows, much less any background with Windows, and I'm here to help. That > part was simple. I will freely admit to having no idea of just how many pythonastis have good Windows experience/background, but how about you give us the benefit of the doubt and tell us exactly which languages/routines you play with *in windows* that fail to make a distinction between text and binary? > The next part is where I can't help: What is the behaviour of Python? > > I'm sure you don't think that tutorial is only for readers who can guess > that they have to extrapolate from the behaviour of the Visual C library in > order to work out what Python does. > > > Steve From torriem at gmail.com Thu Jun 18 12:32:27 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 18 Jun 2009 10:32:27 -0600 Subject: Exotic Logics In-Reply-To: References: Message-ID: <4A3A6C1B.70208@gmail.com> William Clifford wrote: > I've read one can do all of the 16 binary operations with clever uses > of NAND or NOR. That is correct. In fact semiconductor logic is done using these two principle gates. See http://en.wikipedia.org/wiki/NAND_logic . Quite interesting really. From wells at submute.net Thu Jun 18 12:54:58 2009 From: wells at submute.net (Wells Oliver) Date: Thu, 18 Jun 2009 11:54:58 -0500 Subject: A question on scope... Message-ID: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> In writing out python classes, it seems the 'self' is optional, meaning that inside a class method, "self.foo = bar" has the same effect as "foo = bar". Is this right? If so, it seems a little odd- what's the rationale? Or am I mistaken? -- Wells Oliver wells at submute.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jun 18 13:05:53 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Jun 2009 18:05:53 +0100 Subject: A question on scope... In-Reply-To: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> Message-ID: <4A3A73F1.7090107@mrabarnett.plus.com> Wells Oliver wrote: > In writing out python classes, it seems the 'self' is optional, meaning > that inside a class method, "self.foo = bar" has the same effect as "foo > = bar". Is this right? If so, it seems a little odd- what's the rationale? > > Or am I mistaken? > Inside a function or method "foo = bar" would make "foo" local by default. In an instance method an attribute "foo" of the instance needs a reference to the instance itself, by convention "self", therefore "self.foo". In a class method a reference to the class itself is by convention "cls", therefore "cls.foo". From lie.1296 at gmail.com Thu Jun 18 13:54:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 17:54:17 GMT Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: Rhodri James wrote: > On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro > wrote: > >> Now compare that with Lie Ryan's examples which, instead of using >> backslashes, instead used alternative quotes plus backslashes in one >> example, and in the other example, alternative quotes, alternatives to >> literal quotes, and backslashes. As opposed to my original routine, which >> managed three levels of quoting using just backslashes. Do you begin to >> understand what I mean by "scalable"? > > I do, and I still disagree. More importantly, Lie Ryan's examples were > much more readable, which is what I was complaining about. I still remember when I started programming, I wrote in QBASIC without indentations. I honestly saw no reason to indent because I still can see the program flow as clearly as the bottom of a bucket of crystalline water. No decisions to be made, everything is consistently justified left. I still remember asking a friend, "Why is your code jagged like that?" and him looking at me a bit confused at the question. From kyosohma at gmail.com Thu Jun 18 14:00:25 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 18 Jun 2009 11:00:25 -0700 (PDT) Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: Message-ID: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> On Jun 18, 10:38?am, Chris Withers wrote: > Hi All, > > Too many people in the Python community *still* think the only way to > work with Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's EuroPython > conference in Birmingham, UK on Monday, 29th June that will cover > working with Excel files in Python using the pure-python libraries xlrd, > xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > ? ?Including extracting all the data types, formatting and working with > ? ?large files. > > - Writing Excel Files > > ? ?Including formatting, many of the useful frilly extras and writing > ? ?large excel files. > > - Modifying and Filtering Excel Files > > ? ?A run through of taking existing Excel files and modifying them in > ? ?various ways. > > - Workshop for your problems > > ? ?I'm hoping anyone who attends will get a lot out of this! If you're > ? ?planning on attending and have a particular problem you'd like to work > ? ?on in this part of the tutorial, please drop me an email and I'll try > ? ?and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at EuroPython this > year: > > http://www.europython.eu/ > > I look forward to seeing you all there! > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk As I recall, these utilities don't allow the programmer to access Excel's formulas. Is that still an issue? Mike From ullrich at math.okstate.edu Thu Jun 18 14:13:42 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:13:42 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. I won't ask where I can find this definition. That Koch thing is a closed curve in R^2. That means _by definition_ that it is a continuous function from [0,1] to R^2 (with the same value at the endpoints). And any continuous fu From ullrich at math.okstate.edu Thu Jun 18 14:14:20 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:14:20 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. From ullrich at math.okstate.edu Thu Jun 18 14:16:06 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:16:06 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <201l35pbl234ousllfthb5vsl1advoj9cv@4ax.com> On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. Sorry if I've already posted half of this - having troubles hitting the toushpad on this little machine by accident. The fractal in question is a curve in R^2. By definition that means it is a continuous function from [a,b] to R^2 (with the same value at the two endpoints). Hence it's uniformly continuous. From ullrich at math.okstate.edu Thu Jun 18 14:17:44 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:17:44 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <141l35pi79g53kfjji7t9ms8ooahqrmomv@4ax.com> On Wed, 17 Jun 2009 07:35:35 +0200, Jaime Fernandez del Rio wrote: >On Wed, Jun 17, 2009 at 4:50 AM, Lawrence >D'Oliveiro wrote: >> In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, ?wrote: >> >>> Lawrence D'Oliveiro writes: >>> >>>> I don't think any countable set, even a countably-infinite set, can have >>>> a fractal dimension. It's got to be uncountably infinite, and therefore >>>> uncomputable. >>> >>> I think the idea is you assume uniform continuity of the set (as >>> expressed by a parametrized curve). ?That should let you approximate >>> the fractal dimension. >> >> Fractals are, by definition, not uniform in that sense. > >I had my doubts on this statement being true, so I've gone to my copy >of Gerald Edgar's "Measure, Topology and Fractal Geometry" and >Proposition 2.4.10 on page 69 states: "The sequence (gk), in the >dragon construction of the Koch curve converges uniformly." And >uniform continuity is a very well defined concept, so there really >shouldn't be an interpretation issue here either. Would not stick my >head out for it, but I am pretty sure that a continuous sequence of >curves that converges to a continuous curve, will do so uniformly. Nope. Not that I see the relvance here - the g_k _do_ converge uniformly. >Jaime From ullrich at math.okstate.edu Thu Jun 18 14:19:23 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:19:23 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans wrote: > >On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: > >> Jaime Fernandez del Rio writes: >>> I am pretty sure that a continuous sequence of >>> curves that converges to a continuous curve, will do so uniformly. >> >> I think a typical example of a curve that's continuous but not >> uniformly continuous is >> >> f(t) = sin(1/t), defined when t > 0 >> >> It is continuous at every t>0 but wiggles violently as you get closer >> to t=0. You wouldn't be able to approximate it by sampling a finite >> number of points. A sequence like >> >> g_n(t) = sin((1+1/n)/ t) for n=1,2,... >> >> obviously converges to f, but not uniformly. On a closed interval, >> any continuous function is uniformly continuous. > >Isn't (-?, ?) closed? What is your version of the definition of "closed"? >Charles Yeomans From ullrich at math.okstate.edu Thu Jun 18 14:21:50 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:21:50 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> Message-ID: <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> On Wed, 17 Jun 2009 05:46:22 -0700 (PDT), Mark Dickinson wrote: >On Jun 17, 1:26?pm, Jaime Fernandez del Rio >wrote: >> On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: >> > Maybe James is thinking of the standard theorem >> > that says that if a sequence of continuous functions >> > on an interval converges uniformly then its limit >> > is continuous? > >s/James/Jaime. Apologies. > >> P.S. The snowflake curve, on the other hand, is uniformly continuous, right? > >Yes, at least in the sense that it can be parametrized >by a uniformly continuous function from [0, 1] to the >Euclidean plane. I'm not sure that it makes a priori >sense to describe the curve itself (thought of simply >as a subset of the plane) as uniformly continuous. As long as people are throwing around all this math stuff: Officially, by definition a curve _is_ a parametrization. Ie, a curve in the plane _is_ a continuous function from an interval to the plane, and a subset of the plane is not a curve. Officially, anyway. >Mark From ullrich at math.okstate.edu Thu Jun 18 14:26:56 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:26:56 -0500 Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson wrote: >On Jun 17, 3:46?pm, Paul Rubin wrote: >> Mark Dickinson writes: >> > It looks as though you're treating (a portion of?) the Koch curve as >> > the graph of a function f from R -> R and claiming that f is >> > uniformly continuous. ?But the Koch curve isn't such a graph (it >> > fails the 'vertical line test', >> >> I think you treat it as a function f: R -> R**2 with the usual >> distance metric on R**2. > >Right. Or rather, you treat it as the image of such a function, >if you're being careful to distinguish the curve (a subset >of R^2) from its parametrization (a continuous function >R -> R**2). It's the parametrization that's uniformly >continuous, not the curve, Again, it doesn't really matter, but since you use the phrase "if you're being careful": In fact what you say is exactly backwards - if you're being careful that subset of the plane is _not_ a curve (it's sometimes called the "trace" of the curve". >and since any curve can be >parametrized in many different ways any proof of uniform >continuity should specify exactly which parametrization is >in use. Any _closed_ curve must have [a,b] as its parameter interval, and hence is uniformly continuous since any continuous function on [a,b] is uniformly continuous. >Mark From charles at declareSub.com Thu Jun 18 14:32:13 2009 From: charles at declareSub.com (Charles Yeomans) Date: Thu, 18 Jun 2009 14:32:13 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <814BF6DE-E201-4FCB-ACC4-328AEC689180@declareSub.com> On Jun 18, 2009, at 2:19 PM, David C. Ullrich wrote: > On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans > wrote: > >> >> On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: >> >>> Jaime Fernandez del Rio writes: >>>> I am pretty sure that a continuous sequence of >>>> curves that converges to a continuous curve, will do so uniformly. >>> >>> I think a typical example of a curve that's continuous but not >>> uniformly continuous is >>> >>> f(t) = sin(1/t), defined when t > 0 >>> >>> It is continuous at every t>0 but wiggles violently as you get >>> closer >>> to t=0. You wouldn't be able to approximate it by sampling a finite >>> number of points. A sequence like >>> >>> g_n(t) = sin((1+1/n)/ t) for n=1,2,... >>> >>> obviously converges to f, but not uniformly. On a closed interval, >>> any continuous function is uniformly continuous. >> >> Isn't (-?, ?) closed? > > What is your version of the definition of "closed"? >> My version of a closed interval is one that contains its limit points. Charles Yeomans From lie.1296 at gmail.com Thu Jun 18 14:48:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 18:48:27 GMT Subject: walking a directory with very many files In-Reply-To: <20090617110705.7e7c423f@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> Message-ID: <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Mike Kazantsev wrote: > On Wed, 17 Jun 2009 03:42:02 GMT > Lie Ryan wrote: > >> Mike Kazantsev wrote: >>> In fact, on modern filesystems it doesn't matter whether you >>> accessing /path/f9e95ea4926a4 with million files in /path >>> or /path/f/9/e/95ea with only hundred of them in each path. Former >>> case (all-in-one-path) would even outperform the latter with ext3 >>> or reiserfs by a small margin. >>> Sadly, that's not the case with filesystems like FreeBSD ufs2 (at >>> least in sixth branch), so it's better to play safe and create >>> subdirs if the app might be run on different machines than keeping >>> everything in one path. >> It might not matter for the filesystem, but the file explorer (and ls) >> would still suffer. Subfolder structure would be much better, and much >> easier to navigate manually when you need to. > > It's an insane idea to navigate any structure with hash-based names > and hundreds of thousands files *manually*: "What do we have here? > Hashies?" ;) > Like... when you're trying to debug a code that generates an error with a specific file... Yeah, it might be possible to just mv the file from outside, but not being able to enter a directory just because you've got too many files in it is kind of silly. From robert.kern at gmail.com Thu Jun 18 14:55:07 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Jun 2009 13:55:07 -0500 Subject: python tutorial In-Reply-To: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On 2009-06-18 00:57, steve wrote: > "Robert Kern" wrote in message > news:mailman.1728.1245289092.8015.python-list at python.org... >> On 2009-06-17 19:36, steve wrote: >>>> "Carl Banks" wrote in message >>>> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>>> On Jun 15, 7:56 pm, "steve" wrote: >>>>> I was just looking at the python tutorial, and I noticed these lines: >>>>> >>>>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>>> >>>>> "Windows makes a distinction between text and binary files; >>>>> "the end-of-line characters in text files are automatically altered >>>>> "slightly when data is read or written. >>>>> >>>>> I don't see any obvious way to at docs.python.org to get that >>>>> corrected: >>>>> Is >>>>> there some standard procedure? >>>> What's wrong with it? >>>> >>>> >>>> Carl Banks >>> 1) Windows does not make a distinction between text and binary files. >>> >>> 2) end-of-line characters in text files are not automatically altered by >>> Windows. >> The Windows implementation of the C standard makes the distinction. E.g. >> using stdio to write out "foo\nbar\n" in a file opened in text mode will >> result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode >> will result in "foo\nbar\n" in memory. Reading such a file in binary mode >> will result in "foo\r\nbar\r\n". In your bug report, you point out several >> proprietary APIs that do not make such a distinction, but that does not >> remove the implementations of the standard APIs that do make such a >> distinction. >> >> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >> >> Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >> runtime, but I think it's a reasonable statement on the whole. >> >> -- >> 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 >> > > > Which is where I came in: I was looking for simple file IO in the tutorial. > The tutorial tells me something false about Windows, rather than something > true about Python. I don't think it's false. I think it's a fair statement given the Windows implementation of the C standard library. Such things are frequently considered to be part of the OS. This isn't just some random API; it's the implementation of the C standard. > I'm looking at a statement that is clearly false (for anyone who knows > anything about Windows file systems and Windows file io), which leaves the > Python behaviour completely undefined (for anyone who knows nothing about > Python). > > I understand that many of you don't really have any understanding of > Windows, much less any background with Windows, and I'm here to help. That > part was simple. > > The next part is where I can't help: What is the behaviour of Python? The full technical description is where it belongs, in the reference manual rather than a tutorial: http://docs.python.org/library/functions.html#open > I'm sure you don't think that tutorial is only for readers who can guess > that they have to extrapolate from the behaviour of the Visual C library in > order to work out what Python does. All a tutorial level documentation needs to know is what is described: when a file is opened in text mode, the actual bytes written to a file for a newline may be different depending on the platform. The reason that it does not explain the precise behavior on each and every platform is because it *is* undefined. Python 2.x does whatever the C standard library implementation for stdio does. It mentions Windows as a particularly common example of a difference between text mode and binary mode. -- 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 tamuzija at yahoo.es Thu Jun 18 14:57:46 2009 From: tamuzija at yahoo.es (Moni GV) Date: Thu, 18 Jun 2009 18:57:46 +0000 (GMT) Subject: ERROR: how to use a text file in a module? Message-ID: <645298.22108.qm@web24404.mail.ird.yahoo.com> Hi, Help with a "No such file ..." error. I have the next folder structure: ---Network contains: ??? --packets.py ??? --Temp contains: ?????? -test.py Well, within packets.py I do this: from Temp.test import * Within test.py I do this: f = open ("topo.txt", "r") The error is: No such file "topo.txt" However, when I execute test.py, without using neither packets.py nor the folder structure, there is no error, because topo.txt exists. I'm sure I'm doing something wrong with the "import" staff or "path" maybe, but have no idea...please help!!! Thanks in advance! ** M?nica Guerrero M.Sc. Student Rey Juan Carlos University Madrid -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Thu Jun 18 15:08:14 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 19:08:14 GMT Subject: python tutorial In-Reply-To: <87r5xh2a6v.fsf@benfinney.id.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <87r5xh2a6v.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > You started out asking how to *interpret* it, which is fine for this > forum; but discussing it here isn't going to lead automatically to any > *midification* to a document developed within the core of Python. > I definitely want to see how python doc be midified, last time I checked MIDI cannot play spoken words, don't know whether there is text-to-speech sound font though ;) From tjreedy at udel.edu Thu Jun 18 15:17:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 15:17:05 -0400 Subject: Regarding Python is scripting language or not In-Reply-To: <20090618130759.GC19607@wasteland.homelinux.net> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> <20090618130759.GC19607@wasteland.homelinux.net> Message-ID: Jochen Schulz wrote: > Terry Reedy: >> Jochen Schulz wrote: >>> If, by "object-oriented" you mean "everything has to be put into >>> classes", then Python is not object-oriented. >> That depends on what you mean by 'put into classes' (and 'everything'). > > :) What I meant was that in Python you can write code without defining > your own classes at all. I had Java in mind where you cannot write a > program without using the keyword 'class'. But I think we agree here. Yes, I amplified your basic point ;-) From vishal_shetye at persistent.co.in Thu Jun 18 15:27:09 2009 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Fri, 19 Jun 2009 00:57:09 +0530 Subject: Help: Group based synchronize decorator Message-ID: I want to synchronize calls using rw locks per 'group' and my implementation is similar to http://code.activestate.com/recipes/465057/ except that I have my own Lock implementation. All my synchronized functions take 'whatGroup' as param. My lock considers 'group' while deciding on granting locks through acquire. What I could come up with is: - decorator knows(assumes) first param to decorated functions is always 'whatGroup' - decorator passes this 'whatGroup' argument to my lock which is used in acquire logic. Is it ok to make such assumptions in decorator? Any suggestions/alternatives? thanks vishal DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. From piet at cs.uu.nl Thu Jun 18 15:43:24 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 21:43:24 +0200 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a3a329e$1_4@news.peopletelecom.com.au> Message-ID: >>>>> "Peter Bell" (PB) wrote: >>> "Steven D'Aprano" >PB> writes >>> http://support.microsoft.com/kb/156258 >PB> That says that Windows NT 3.5 and NT 4 couldn't make >PB> a distinction between text and binary files. I don't think >PB> that advances your case. And that was a bug apparently (euphemistically called a `problem'). >PB> If they had changed the Windows behaviour, yes, but >PB> Windows 7 seems to be compatible with NT 3.5 rather >PB> than with DOS. If that is true then they may still be `researching this problem'. :=( -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Thu Jun 18 15:50:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 15:50:47 -0400 Subject: python tutorial In-Reply-To: <4A3A6BA4.1050909@stoneleaf.us> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4A3A6BA4.1050909@stoneleaf.us> Message-ID: >>>> >>>> 1) Windows does not make a distinction between text and binary files. 'Windows', in its broad sense of Windoes system, includes the standards and protocols mandated by its maker, Microsoft Corporation, and implemented in its C compiler, which it uses to compile the software that other interact with. I am pretty sure that WixXP Notepad *still* requires \r\n in text files, even though Wordpad does not. Don't know about Haste (la Vista) and the upcoming Win7. It is a common metaphor in English to ascribe agency to products and blame them for the sins (or virtues) of their maker. 'Unix' and 'Linux' are also used in the double meaning of OS core and OS system that includes core, languages tools, and standard utilities. >>>> 2) end-of-line characters in text files are not automatically >>>> altered by >>>> Windows. >>> >>> The Windows implementation of the C standard makes the distinction. >>> E.g. using stdio to write out "foo\nbar\n" in a file opened in text >>> mode will result in "foo\r\nbar\r\n" in the file. Reading such a file >>> in text mode will result in "foo\nbar\n" in memory. Reading such a >>> file in binary mode will result in "foo\r\nbar\r\n". In your bug >>> report, you point out several proprietary APIs that do not make such >>> a distinction, but that does not remove the implementations of the >>> standard APIs that do make such a distinction. >>> >>> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >>> >>> Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >>> runtime, but I think it's a reasonable statement on the whole. I agree. There are much worse sins in the docs to be fixed. Hmmm. "Bill Gates, his successors, and minions, still require, after 28 years, that we jump through artificial hoops, confuse ourselves, and waste effort, by differentiating text and binary files and fiddling with line endings." More accurate, perhaps, but probably less wise than the current text. Terry Jan Reedy From basti.wiesner at gmx.net Thu Jun 18 16:02:35 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Thu, 18 Jun 2009 22:02:35 +0200 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> <5995aa64-ca3c-4e82-a8ca-8138af59ac2e@e20g2000vbc.googlegroups.com> Message-ID: > On Jun 18, 3:49 pm, "Diez B. Roggisch" wrote: >> Hans M?ller wrote: >> > Here we have to select between wxPython and PyQt for a medium size >> > project. In this project several hundred dialogs are to be created. >> > This work will be done by a program generator which has to re-written. >> >> > The question now is which framework should we use. >> > As far as I could found is PyQt with the Qt Framework the superior >> > choice. Most articles I found (not all) results to PyQt. >> > But Qt is expensive ~ 3400? per Developer and OS. >> >> No, it's not. It is LGPL by now. >> >> You will have to pay licensing for *PyQT*. I'm not sure, but I *think* >> it's about 500?. However, it is much less than Qt used to be. >> >> Diez > > Not quite. You only have to pay for the commercial license -- you can > use PyQT as GPL as well. FWIW, PyQt4 license conditions do not enforce GPL 2 for derived work, but also permit a bunch of other free software licenses (e.g. MIT/X11, BSD, Apache, etc.) -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From kyosohma at gmail.com Thu Jun 18 16:25:05 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 18 Jun 2009 13:25:05 -0700 (PDT) Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <68d794fc-b036-4e9c-984d-0b2739acb2ff@o30g2000vbc.googlegroups.com> On Jun 18, 8:35?am, Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size project. > In this project several hundred dialogs are to be created. This work will be done by a > program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. > Since these articles are more or less old, it would be nice to hear your current opinions. > > Condensed, I found this pros / cons: > > Pros for Qt: > ? ? ? ? - best framwork, well designed "Best" in who's opinion? > ? ? ? ? - nice GUI builders > ? ? ? ? - faster execution How was the execution speed measured? > Cons: > ? ? ? ? - epensive The others have answered this... > > Pros for wxPython: > ? ? ? ? - cheap > ? ? ? ? - big community > Cons: > ? ? ? ? - more layers on top of OS > ? ? ? ? - more bugs (still valid ?) > ? ? ? ? - slower > Again, how was the slowness measured? > Can someone tell me about his experiences with one or both frameworks ? > > Thanks a lot, > > Greetings > Hans I've been using wxPython for almost three years. I can attest to there being a good solid community behind wx that is very friendly. The wxPython framework is built on top of C++ wxWidgets code, but as far as I know, pyQT is built on top of the QT framework. So I'm not sure where this idea of "more layers" for wx comes from. I haven't messed with QT to know if it is faster or not. Hopefully someone else can weigh in on that. I also don't know which has more bugs. For what I've done though, I've never had a bug to deal with. I've created a fairly involved timesheet for my company that's a little unwieldy at the moment. I also have quite a few smaller applications in wxPython. I like it quite a bit. All the widgets I've ever needed are already implemented and when they aren't there, it always seems that one of the other developers releases one. I would recommend trying to create something small in each toolkit (like a minimal calculator) and see which one makes the most sense to you. Mike From hyugaricdeau at gmail.com Thu Jun 18 16:55:45 2009 From: hyugaricdeau at gmail.com (Hyuga) Date: Thu, 18 Jun 2009 13:55:45 -0700 (PDT) Subject: Perl's @foo[3,7,1,-1] ? References: <4A342136.5010909@sweetapp.com> <4A3424F5.7010901@mrabarnett.plus.com> Message-ID: <897e4f4c-9d44-41e2-add8-fc7105625d6d@f10g2000vbf.googlegroups.com> On Jun 13, 6:22?pm, Brian Quinlan wrote: > MRAB wrote: > > Brian Quinlan wrote: > >> kj wrote: > >>> In Nick Craig-Wood > >>> writes: > > >>>> However I can't think of the last time I wanted to do this - array > >>>> elements having individual purposes are usually a sign that you should > >>>> be using a different data structure. > > >>> In the case I was working with, was a stand-in for the value returned > >>> by some_match.groups(). ?The match comes from a standard regexp > >>> defined elsewhere and that captures more groups than I need. ?(This > >>> regexp is applied to every line of a log file.) > > >>> kj > > >> The common idiom for this sort of thing is: > > >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() > > > Alternatively: > > > ? ? val1, val2, val3 = some_match.group(4, 8, something) > > Actually, now that I think about it, naming the groups seems like it > would make this code a lot less brittle. I was about to suggest that too, but it sounds like the OP has little or no control, in this case, over the RE itself. Another thing I would suggest is using the (?:) syntax--it allows creating a syntactic group that isn't returned in the list of match groups. From arnodel at googlemail.com Thu Jun 18 16:56:57 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Jun 2009 21:56:57 +0100 Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: David C. Ullrich writes: > On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > wrote: > >>On Jun 17, 3:46?pm, Paul Rubin wrote: >>> Mark Dickinson writes: >>> > It looks as though you're treating (a portion of?) the Koch curve as >>> > the graph of a function f from R -> R and claiming that f is >>> > uniformly continuous. ?But the Koch curve isn't such a graph (it >>> > fails the 'vertical line test', >>> >>> I think you treat it as a function f: R -> R**2 with the usual >>> distance metric on R**2. >> >>Right. Or rather, you treat it as the image of such a function, >>if you're being careful to distinguish the curve (a subset >>of R^2) from its parametrization (a continuous function >>R -> R**2). It's the parametrization that's uniformly >>continuous, not the curve, > > Again, it doesn't really matter, but since you use the phrase > "if you're being careful": In fact what you say is exactly > backwards - if you're being careful that subset of the plane > is _not_ a curve (it's sometimes called the "trace" of the curve". I think it is quite common to refer to call 'curve' the image of its parametrization. Anyway there is a representation theorem somewhere that I believe says for subsets of R^2 something like: A subset of R^2 is the image of a continuous function [0,1] -> R^2 iff it is compact, connected and locally connected. (I might be a bit -or a lot- wrong here, I'm not a practising mathematician) Which means that there is no need to find a parametrization of a plane curve to know that it is a curve. To add to this, the usual definition of the Koch curve is not as a function [0,1] -> R^2, and I wonder how hard it is to find such a function for it. It doesn't seem that easy at all to me - but I've never looked into fractals. -- Arnaud From jure.erznoznik at gmail.com Thu Jun 18 17:25:26 2009 From: jure.erznoznik at gmail.com (=?ISO-8859-15?Q?Jure_Erzno=B8nik?=) Date: Thu, 18 Jun 2009 14:25:26 -0700 (PDT) Subject: Newbie queue question References: Message-ID: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Thanks for the suggestions. I've been looking at the source code of threading support objects and I saw that non-blocking requests in queues use events, while blocking requests just use InterlockedExchange. So plain old put/get is much faster and I've managed to confirm this today with further testing. Sorry about the semicolon, just can't seem to shake it with my pascal & C++ background :) Currently, I've managed to get the code to this stage: class mt(threading.Thread): q = Queue.Queue() def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) dbf1.close() del dbf1 self.q.put(None) t = mt() t.start() time.sleep(22) rec = 1 while rec <> None: rec = t.q.get() del t Note the time.sleep(22). It takes about 22 seconds to read the DBF with the 200K records (71MB). It's entirely in cache, yes. So, If I put this sleep in there, the whole procedure finishes in 22 seconds with 100% CPU (core) usage. Almost as fast as the single threaded procedure. There is very little overhead. When I remove the sleep, the procedure finishes in 30 seconds with ~80% CPU (core) usage. So the threading overhead only happens when I actually cause thread interaction. This never happened to me before. Usually (C, Pascal) there was some threading overhead, but I could always measure it in tenths of a percent. In this case it's 50% and I'm pretty sure InterlockedExchange is the fastest thing there can be. My example currently really is a dummy one. It doesn't do much, only the reading thread is implemented, but that will change with time. Reading the data source is one task, I will proceed with calculations and with a rendering engine, both of which will be pretty CPU intensive as well. I'd like to at least make the reading part behave like I want it to before I proceed. It's clear to me I don't understand Python's threading concepts yet. I'd still appreciate further advice on what to do to make this sample work with less overhead. From tjreedy at udel.edu Thu Jun 18 17:51:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 17:51:01 -0400 Subject: Generator functions subclass generator? Message-ID: An iterator class is a class with an __iter__ method that returns self and a __next__ method that on each call returns one not-yet-returned item of the actual or virtual collection it represents and raises StopIteration when there are no more items to return. 'Generator' (3.1 name) is one of several built-in iterator classes. A generator function is a function with keyword 'yield' in its body. Its presence results in four special behaviors. 1. When the generator function is called, it returns a generator instance inst instead of executing its body code. 2. When inst.__next__ is called, the body *is* executed. 3. When any yield is reached, an object is returned (yielded), but execution of the body code is only suspended, not terminated. 4. The next call resume execution at the point of suspension. I believe any non-recursive generator functions can be written as an actual iterator class, though perhaps with more difficulty. (I suspect the same is true of recursive generators but I have never tried one.) The greater ease of writing gfs is one reason we have them. I find the first two bits of magic easier with the following simile: a generator function is like a virtual subclass of generator. In other words, def gf(params): body acts somewhat like the following hypothetical code class gf(generator): # inherited __new__ method stores the args # __iter__ is also inherited def __next__(): params = # added body 'yield' in the body of __next__ would still have special effects 3 and 4. I am planning to use this in my book. Does anyone else, particularly Python beginners, find it helpful? Terry Jan Reedy From rhodri at wildebst.demon.co.uk Thu Jun 18 18:42:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 23:42:55 +0100 Subject: ERROR: how to use a text file in a module? In-Reply-To: <645298.22108.qm@web24404.mail.ird.yahoo.com> References: <645298.22108.qm@web24404.mail.ird.yahoo.com> Message-ID: On Thu, 18 Jun 2009 19:57:46 +0100, Moni GV wrote: > Help with a "No such file ..." error. I have the next folder structure: > ---Network contains: > ??? --packets.py > ??? --Temp contains: > ?????? -test.py > > Well, within packets.py I do this: > from Temp.test import * Wildcarded imports like this aren't often a good idea. It has nothing to do with your problem, I just thought I'd mention it. > Within test.py I do this: > f = open ("topo.txt", "r") > > The error is: > No such file "topo.txt" > > However, when I execute test.py, without using neither packets.py nor > the folder structure, there is no error, because topo.txt exists. Where does topo.txt exist? In the Temp directory? I'll take a wild stab in the dark, and suggest that the way you ran your program the first time (to get the error) was approximately like this (depending on your operating system): cd Network python packets.py Am I right? And for the second time (when it worked) was: cd Network/Temp python test.py roughly what you did? Assuming that I'm right, notice that you are in different directories each time. Python will look for a file called "topo.txt" in the *current* directory (i.e. where you "cd"ed to) each time, *not* in the same directory as test.py. (If you double-clicked on the files, I think that's equivalent to the situations I outlined above. I certainly wouldn't want to trust where the current directory was in that case!) To fix this, you either need to be consistent about how you run your program and change the filename appropriately (i.e. writing 'open("Temp/topo.txt", "r")' instead), or you need to fix where 'topo.txt' is supposed to be relative to your home directory or the filesystem root and change the filename to match it (as in 'open("/usr/local/lalala/topo.txt", "r")' or 'open("~/Network/Test/topo.txt", "r")', or the equivalent on Windows). -- Rhodri James *-* Wildebeest Herder to the Masses From chris at simplistix.co.uk Thu Jun 18 18:43:09 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 23:43:09 +0100 Subject: xlutils 1.3.2 released! Message-ID: <4A3AC2FD.9090102@simplistix.co.uk> Hi All, I'm pleased to announce a new release of xlutils. This is a small collection of utilities that make use of both xlrd and xlwt to process Microsoft Excel files. The list of utilities included in this release are: xlutils.copy Tools for copying xlrd.Book objects to xlwt.Workbook objects. xlutils.display Utility functions for displaying information about xlrd-related objects in a user-friendly and safe fashion. xlutils.filter A mini framework for splitting and filtering Excel files into new Excel files. xlutils.margins Tools for finding how much of an Excel file contains useful data. xlutils.save Tools for serializing xlrd.Book objects back to Excel files. xlutils.styles Tools for working with formatting information expressed in styles. A full list of changes since the last release can be found here: http://www.simplistix.co.uk/software/python/xlutils/changes To find out more, please read here: http://www.simplistix.co.uk/software/python/xlutils In case you're not aware, xlrd and xlwt are two excellent pure-python libraries for reading and writing Excel files. They run on any platform and, likely, any implementation of Python without the need for horrific things like binding to Excel via COM and so needing a Windows machine. If you use any of xlrd, xlwt or xlutils, the following google group will be of use: http://groups.google.com.au/group/python-excel Hope some of this is of interest, I'd love to hear from anyone who ends up using it! cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From aahz at pythoncraft.com Thu Jun 18 18:43:53 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Jun 2009 15:43:53 -0700 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: In article , D'Arcy J.M. Cain wrote: > >I really loved CP/M in its day but isn't it time we let go? +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From chris at simplistix.co.uk Thu Jun 18 18:51:43 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 23:51:43 +0100 Subject: TestFixtures 1.6.0 released! Message-ID: <4A3AC4FF.5060200@simplistix.co.uk> Hi All, I'm pleased to announce the first advertised release of TestFixtures. This is a collection of helpers and mock objects that are useful when writing unit tests or doc tests. The modules currently included are: *Comparison* This class lets you instantiate placeholders that can be used to compared expected results with actual results where objects in the actual results do not support useful comparison. The comparision can be based just on the type of the object or on a partial set of the object's attributes, both of which are particularly handy when comparing sequences returned from tested code. *compare* A replacement for assertEquals and the failUnless(x() is True) pattern. Gives more useful differences when the arguments aren't the same, particularly for sequences and long strings. *diff* This function will compare two strings and give a unified diff of their comparison. Handy as a third parameter to unittest.TestCase.assertEquals. *generator* This function will return a generator that yields the arguments it was called with when the generator is iterated over. *LogCapture* This helper allows you to capture log messages for specified loggers in doctests. *log_capture* This decorator allows you to capture log messages for specified loggers for the duration of unittest methods. *replace* This decorator enables you to replace objects such as classes and functions for the duration of a unittest method. The replacements are removed regardless of what happens during the test. *Replacer* This helper enables you to replace objects such as classes and functions from within doctests and then restore the originals once testing is completed. *should_raise* This is a better version of assertRaises that lets you check the exception raised is not only of the correct type but also has the correct parameters. *TempDirectory* This helper will create a temporary directory for you using mkdtemp and provides a handy class method for cleaning all of these up. *tempdir* This decorator will create a temporary directory for the duration of the unit test and clear it up no matter the outcome of the test. *test_date* This is a handy class factory that returns datetime.date replacements that have a today method that gives repeatable, specifiable, testable dates. *test_datetime* This is a handy class factory that returns datetime.datetime replacements that have a now method that gives repeatable, specifiable, testable datetimes. *test_time* This is a handy replacement for time.time that gives repeatable, specifiable, testable times. *wrap* This is a generic decorator for wrapping method and function calls with a try-finally and having code executed before the try and as part of the finally. To find out more, please read here: http://pypi.python.org/pypi/testfixtures cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From scott.pigman at gmail.com Thu Jun 18 19:19:27 2009 From: scott.pigman at gmail.com (Scott) Date: Thu, 18 Jun 2009 16:19:27 -0700 (PDT) Subject: Allocating memory to pass back via ctypes callback function Message-ID: Hi, I'm using python ctypes to interact with the C API of a commercial-off- the-shelf application. I need to implement callback functions which will be called by the application. The callbacks take as a parameter a char** parameter for which the callback function will allocate memory and set the value of the underlying char*. The hitch is that I need to allocate the memory with the vendor's own memory allocation function because the caller will free the memory with the corresponding vendor free function. The problem is that I can't quite work out how to set the address of the incoming POINTER(c_char_p) parameter to the location provided by the memory allocation function. def my_callback(pointer_c_char_p): py_string = get_string_to_pass_back() address = VENDOR_malloc( len(py_string)*sizeof(c_char) ) # ???? how to set pointer_c_char_p.contents to memory location address? # ???? would this be the correct next thing to do? pointer_c_char_p.contents = c_char_p(py_string) # ???? return 0 Thanks, Scott From notontheweb at noisp.com Thu Jun 18 19:39:59 2009 From: notontheweb at noisp.com (Jive Dadson) Date: Thu, 18 Jun 2009 16:39:59 -0700 Subject: AT&T Usenet Netnews Service Shutting Down In-Reply-To: <1245249220_11395@newsgroups.bellsouth.net> References: <1245249220_11395@newsgroups.bellsouth.net> Message-ID: newsmaster at bellsouth.net wrote: > Please note that on or around July 15, 2009, AT&T will no longer be > offering access to the Usenet Netnews service. If you wish to continue > reading Usenet newsgroups, access is available through third-party vendors. > > http://support.att.net/usenet > > > Distribution: AT&T SouthEast Newsgroups Servers Ah ha. I think I may have figured out how to work around it. I need to use my EasyNews server to post the message, (with "SSL"), rather than the ATT server. I think. Maybe. Does anyone know if it's possible to have Thunderbird use different outgoing servers for different accounts? I know this is not a Python question. Please forgive me. The main reason I'm sending these messages is just to see if they go through. From dickinsm at gmail.com Thu Jun 18 20:01:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 18 Jun 2009 17:01:12 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 18, 7:26?pm, David C. Ullrich wrote: > On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > >Right. ?Or rather, you treat it as the image of such a function, > >if you're being careful to distinguish the curve (a subset > >of R^2) from its parametrization (a continuous function > >R -> R**2). ?It's the parametrization that's uniformly > >continuous, not the curve, > > Again, it doesn't really matter, but since you use the phrase > "if you're being careful": In fact what you say is exactly > backwards - if you're being careful that subset of the plane > is _not_ a curve (it's sometimes called the "trace" of the curve". Darn. So I've been getting it wrong all this time. Oh well, at least I'm not alone: "De?nition 1. A simple closed curve J, also called a Jordan curve, is the image of a continuous one-to-one function from R/Z to R2. [...]" - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. "We say that Gamma is a curve if it is the image in the plane or in space of an interval [a, b] of real numbers of a continuous function gamma." - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). Perhaps your definition of curve isn't as universal or 'official' as you seem to think it is? Mark From davea at ieee.org Thu Jun 18 20:11:33 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Jun 2009 20:11:33 -0400 Subject: Exotic Logics In-Reply-To: <4A3A6C1B.70208@gmail.com> References: <4A3A6C1B.70208@gmail.com> Message-ID: <4A3AD7B5.6010202@ieee.org> Michael Torrie wrote: > William Clifford wrote: > >> I've read one can do all of the 16 binary operations with clever uses >> of NAND or NOR. >> > > That is correct. In fact semiconductor logic is done using these two > principle gates. See http://en.wikipedia.org/wiki/NAND_logic . Quite > interesting really. > > Not "is done" but "could be" done. As your reference correctly points out, "However, contrary to popular belief, modern integrated circuits are not constructed exclusively from a single type of gate" From usenet at janc.invalid Thu Jun 18 20:11:55 2009 From: usenet at janc.invalid (JanC) Date: Fri, 19 Jun 2009 00:11:55 +0000 (UTC) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: Hendrik van Rooyen wrote: > It is my opinion that it is not possible to make a useful machine, > virtual or real, which executes instructions sequentially, if the > instruction set does not contain a conditional jump of some sort. > > I have tried doing it using conditional calls, and it fails on > the equivalent of the first if ..., elif ... you try to write. I'm 99.99% sure you can implement that by using a decision subroutine that returns subroutine pointers (and maybe parameter pointers), but it certainly won't be efficient on current CPU designs... -- JanC From pavlovevidence at gmail.com Thu Jun 18 20:26:43 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 18 Jun 2009 17:26:43 -0700 (PDT) Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <37219ea2-b5ce-4e43-9f0a-0e1c1b7fe1d6@t11g2000vbc.googlegroups.com> On Jun 17, 5:36?pm, "steve" wrote: > >"Carl Banks" wrote in message > >news:2f6271b1-5ffa-4cec-81f8->>0276ad647__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__ at p5g2000pre.googlegroups.com... > >On Jun 15, 7:56 pm, "steve" wrote: > >> I was just looking at the python tutorial, and I noticed these lines: > > >>http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > >> "Windows makes a distinction between text and binary files; > >> "the end-of-line characters in text files are automatically altered > >> "slightly when data is read or written. > > >> I don't see any obvious way to at docs.python.org to get that corrected: > >> Is > >> there some standard procedure? > > >What's wrong with it? > > >Carl Banks > > 1) Windows does not make a distinction between text and binary files. > > 2) end-of-line characters in text files are not automatically altered by > Windows. I agree with Robert Kern, it isn't necessary to distinguish between Windows OS and a particular Windows runtime library for the purposes of a tutorial. Carl Banks From http Thu Jun 18 20:40:55 2009 From: http (Paul Rubin) Date: 18 Jun 2009 17:40:55 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <7xmy85ys14.fsf@ruckus.brouhaha.com> David C. Ullrich writes: > >> obviously converges to f, but not uniformly. On a closed interval, > >> any continuous function is uniformly continuous. > > > >Isn't (-?, ?) closed? > > What is your version of the definition of "closed"? I think the whole line is closed, but I hadn't realized anyone considered the whole line to be an "interval". Apparently they do. So that the proper statement specifies compactness (= closed and bounded) rather than just "closed". From matt at tplus1.com Thu Jun 18 20:56:18 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 00:56:18 GMT Subject: Is this pylint error message valid or silly? Message-ID: Here's the code that I'm feeding to pylint: $ cat f.py from datetime import datetime def f(c="today"): if c == "today": c = datetime.today() return c.date() And here's what pylint says: $ pylint -e f.py No config file found, using default configuration ************* Module f E: 10:f: Instance of 'str' has no 'date' member (but some types could not be inferred) Is this a valid error message? Is the code above bad? If so, what is the right way? I changed from using a string as the default to None, and then pylint didn't mind: $ cat f.py from datetime import datetime def f(c=None): if c is None: c = datetime.today() return c.date() $ pylint -e f.py No config file found, using default configuration I don't see any difference between using a string vs None. Both are immutable. I find the string much more informative, since I can write out what I want. Looking for comments. Matt From karthik301176 at gmail.com Thu Jun 18 21:06:25 2009 From: karthik301176 at gmail.com (Karthik) Date: Thu, 18 Jun 2009 18:06:25 -0700 (PDT) Subject: Packing a ctypes struct containing bitfields. References: Message-ID: On Jun 18, 6:29?pm, Nick Craig-Wood wrote: > Karthik wrote: > > ?Hello Everybody, > > > ?I'm trying to create a packed structure in ctypes (with one 64-bit > > ?element that is bitfielded to 48 bits), > > ?unsuccessfully: > > > =================================== > > ?from ctypes import * > > > ?class foo (Structure): > > ? ? ?_pack_ = 1 > > ? ? ?_fields_ = [ > > ? ? ? ? ?("bar", ? ?c_ulonglong, 48), > > ? ? ?] > > > ?print("sizeof(foo) = %d" % sizeof(foo)) > > =================================== > > ?I'm expecting that this should print 6 - however, on my box, it prints > > ?8. > > > ?The following piece of C code, when compiled and run, prints 6, which > > ?is correct. > > =================================== > > ?struct foo { > > ? ? ?unsigned long long bar: 48; > > ?}; > > > ?printf("sizeof(foo) = %d", sizeof(foo)); > > =================================== > > > ?So... what am I doing wrong? > > I compiled and ran the above with gcc on my linux box - it prints 8 > unless I add __attribute__((__packed__)) to the struct. > > I'm not sure that using bitfields like that is a portable at all > between compilers let alone architectures. > > I'd probably do > > from ctypes import * > > class foo (Structure): > ? ? _pack_ = 1 > ? ? _fields_ = [ > ? ? ? ? ("bar0", ? ?c_uint32), > ? ? ? ? ("bar1", ? ?c_uint16), > ? ? ] > ? ? def set_bar(self, bar): > ? ? ? ? self.bar0 = bar & 0xFFFFFFFF > ? ? ? ? self.bar1 = (bar >> 32) & 0xFFFF > ? ? def get_bar(self): > ? ? ? ? return (self.bar1 << 32) + self.bar0 > ? ? bar = property(get_bar, set_bar) > > print "sizeof(foo) = %d" % sizeof(foo) > f = foo() > print f.bar > f.bar = 123456789012345 > print f.bar > > Which prints > > sizeof(foo) = 6 > 0 > 123456789012345 > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Oops, sorry about the missing __attribute__((packed)) - that was an error of omission. Thank you, Nick :) I'm looking at some C code that's using bitfields in structs, and I'm writing python code that "imports" these structs and messes around with them - unfortunately, I'm not at liberty to change the C code to not use bitfields. Your solution works fine, so that's what I'm going to use. Thanks, Karthik. From fabiofz at gmail.com Thu Jun 18 21:32:55 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 18 Jun 2009 22:32:55 -0300 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> Message-ID: > yes, the same problem even on an empty program. every file has the same > problem. > > for example, if I new a file and input the following: > import os > os. > after I input '.', it will pop up the window, and i can select the function > of os module or continue input. but after that, no action can be taken for > this file unless I switch to other files and then switch back. If it's in pydev, there's probably some problem in your interpreter configuration (when you do os. it'll spawn a shell to gather the completions -- but that should be pretty quick unless you have some firewall that's preventing the communication or the spawn didn't go well -- check your error log to see if you have any errors... In linux I've seen some problems when connecting to 127.0.0.1 while having ipv6 enabled or in a network card misconfiguration that could cause problems too). Cheers, Fabio > > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing wrote: >> >> Do you experience the same problem even on an empty program file or is it >> limited to just one file? >> >> -Tyler >> >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: >>> >>> On Jun 18, 10:45?am, "Wei, James" wrote: >>> > When I am editing python program with SPE, I found that SPE will >>> > freeze when it is doing auto-completion. The behavior is very strange >>> > that I can not edit the file again. If I switch to another file and >>> > then switch back, I can edit it again. >>> > >>> > So I switch to eclipse+pydev, but I found the same thing happen. So I >>> > think it is not the problem of SPE or eclipse or pydev. >>> > >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it will >>> > not freeze any longer. >>> > >>> > Anybody can give me some hints? >>> > >>> > I am using Ubuntu 8.10 and updated to latest. All packages is >>> > installed through package manager. >>> >>> the only thing I googled related with it is >>> >>> >>> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >>> >>> but I think they are different. >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > -- > Best wishes to you. > > Yours sincerely > > Xiaohai Wei > wistoch at ustc.edu > > -- > http://mail.python.org/mailman/listinfo/python-list > > From sjmachin at lexicon.net Thu Jun 18 22:08:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Jun 2009 02:08:57 +0000 (UTC) Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: Mike Driscoll gmail.com> writes: > On Jun 18, 10:38?am, Chris Withers wrote: > > working with Excel files in Python using the pure-python libraries xlrd, > > xlwt and xlutils. > As I recall, these utilities don't allow the programmer to access > Excel's formulas. Is that still an issue? xlwt supports creating XLS files with a large chunk of the Excel formula functionality. Support in xlrd for decompiling formulas exists only in a crude form sufficient to support debugging of xlwt formula enhancements. Whether this is an issue or not and for whom is difficult to detect -- certainly there have been no demands for refund of purchase price :-). Some recent enhancements have been initiated as patches supplied by programmers personally. Patches (preferably pre-discussed) are welcome, as would be any advice on how to get the big end of town to send patent lawyers[1], gun coders and money. [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ From notontheweb at noisp.com Thu Jun 18 22:23:52 2009 From: notontheweb at noisp.com (Jive Dadson) Date: Thu, 18 Jun 2009 19:23:52 -0700 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <_EC_l.156072$fo6.2168@en-nntp-09.dc1.easynews.com> Qt has far better documentation, and it has Qt Designer. The documentation is a big deal. I wrote a little project in wxPython, and I spent 90% of my time just trying to find the names of member functions and then to figure out what they do. Why not use Qt C++? I like Python a lot. Heck, I even embedded it in a robot controller that might have wrangled some of the wafers that went into your computer chips. But I think I would go with C++ for a medium size GUI project. Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size project. > In this project several hundred dialogs are to be created. This work > will be done by a > program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. > Since these articles are more or less old, it would be nice to hear your > current opinions. > > Condensed, I found this pros / cons: > > Pros for Qt: > - best framwork, well designed > - nice GUI builders > - faster execution > Cons: > - epensive > > Pros for wxPython: > - cheap > - big community > Cons: > - more layers on top of OS > - more bugs (still valid ?) > - slower > > > > > Can someone tell me about his experiences with one or both frameworks ? > > Thanks a lot, > > Greetings > Hans From ethan at stoneleaf.us Thu Jun 18 22:37:36 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Jun 2009 19:37:36 -0700 Subject: fastest native python database? In-Reply-To: <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> Message-ID: <4A3AF9F0.7000009@stoneleaf.us> Pierre Quentel wrote: > On 18 juin, 05:28, per wrote: > >>hi all, >> >>i'm looking for a native python package to run a very simple data >>base. i was originally using cpickle with dictionaries for my problem, >>but i was making dictionaries out of very large text files (around >>1000MB in size) and pickling was simply too slow. > > buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : > > from buzhug import Base > db = Base('foo').create(('name',str),('age',int)) > db.insert('john',33) > # simple queries > print db(name='john') > # complex queries > print [ rec.name for rec in db if age > 30 ] > # update > rec.update(age=34) > > I made a few speed comparisons with Gadfly, KirbyBase (another pure- > Python DB, not maintained anymore) and SQLite. You can find the > results on the buzhug home page : http://buzhug.sourceforge.net > > The conclusion is that buzhug is much faster than the other pure- > Python db engines, and (only) 3 times slower than SQLite > > - Pierre Howdy, Pierre! I have also written a pure Python implementation of a database, one that uses dBase III or VFP 6 .dbf files. Any chance you could throw it into the mix to see how quickly (or slowly!) it runs? The code to run the same steps are (after an import dbf): #insert test table = dbf.Table('/tmp/tmptable', 'a N(6.0), b N(6.0), c C(100)') # if recs is list of tuples for rec in recs: table.append(rec) # elif recs is list of lists #for a, b, c in recs: # current = table.append() # current.a = a # current.b = b # current.c = c #select1 test for i in range(100): nb = len(table) if nb: avg = sum([r.b for r in table])/nb #select2 test for num_string in num_strings: recs = table.find({'c':'%s'%num_string}, contained=True) nb = len(recs) if nb: avg = sum([r.b for r in recs])/nb #delete1 test for rec in table: if 'fifty' in rec.c: rec.delete_record() # to purge the records would then require a table.pack() #delete2 test for rec in table: if 10 < rec.a < 20000: rec.delete_record() # again, permanent deletion requires a table.pack() #update1 test table.order('a') for i in range(100): # update description says 1000, update code is 100 records = table.query(python='10*%d <= a < 10*%d' %(10*i,10*(i+1))) for rec in records: rec.b *= 2 #update2 test records = table.query(python="0 <= a < 1000") for rec in records: rec.c = new_c[rec.a] Thanks, I hope! :) ~Ethan~ http://groups.google.com/group/python-dbase -------------- next part -------------- A non-text attachment was scrubbed... Name: python-dbf.zip Type: application/x-zip-compressed Size: 23032 bytes Desc: not available URL: From trinioler at gmail.com Thu Jun 18 22:40:22 2009 From: trinioler at gmail.com (Tyler Laing) Date: Thu, 18 Jun 2009 19:40:22 -0700 Subject: Calling subprocess with arguments Message-ID: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> I've been trying any variation I can think of to do this properly, but here's my problem: I want to execute this command string: vlc -I rc This allows vlc to be controlled via a remote interface instead of the normal gui interface. Now, say, I try this from subprocess: >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) But I don't get the remote interface. I get the normal gui interface. So how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', 'rc'] with executable set to 'vlc'. I've had shell=True, I've had shell=False. I've tried all these combinations. What am I doing wrong? -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From rylesny at gmail.com Thu Jun 18 23:02:43 2009 From: rylesny at gmail.com (ryles) Date: Thu, 18 Jun 2009 20:02:43 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <400a9a27-89df-4caa-826c-fb23e2b68435@f16g2000vbf.googlegroups.com> > Does the generator expression have its own little namespace or so ? Yes, generators create a new scope: http://docs.python.org/reference/expressions.html#grammar-token-generator_expression From rylesny at gmail.com Thu Jun 18 23:09:25 2009 From: rylesny at gmail.com (ryles) Date: Thu, 18 Jun 2009 20:09:25 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: On Jun 18, 9:56?am, nn wrote: > On Jun 18, 8:38?am, guthrie wrote: > > > > > On Jun 17, 6:38?pm, Steven Samuel Cole > > wrote: > > > > Still don't really understand why my initial code didn't work, though... > > > Your code certainly looks reasonable, and looks to me like it "should" > > work. The comment of partial namespace is interesting, but > > unconvincing (to me) - but I am not a Python expert! It would > > certainly seem that within that code block it is in the local > > namespace, not removed from that scope to be in another. > > > Seems that it should either be a bug, or else is a design error in the > > language! > > > Just as in the above noted "WTF" - non-intuitive language constructs > > that surprise users are poor design. > > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > > >>> class x: > > ... ? ? lst=[2] > ... ? ? gen=[lst.index(e) for e in lst] > ... > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 3, in x > ? File "", line 3, in > NameError: global name 'lst' is not defined > > > > I believe it works in 2.x because unlike generator expressions, list comprehensions do not create a new scope. However, in 3.0 list comprehensions are actually treated as list(). http://docs.python.org/reference/expressions.html http://www.python.org/dev/peps/pep-0289 From philip at semanchuk.com Thu Jun 18 23:19:09 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Jun 2009 23:19:09 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught Message-ID: Hi all, I need help understanding how Python deals with Ctrl-C. A user has reported a bug in my posix_ipc module. When a Python app is waiting to acquire an IPC semaphore and the user hits Ctrl-C, my code should return a custom error indicating that the semaphore wait was interrupted by a signal. However, the caller never sees the error I set. Instead they get a KeyboardInterrupt that refuses to be caught by try/except. Here's a sample program that demonstrates the problem when run from the command line: # ----------------------------------- import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) try: sem.acquire() # User hits Ctrl + C while this is waiting except: print "********* I caught it!" sem.close() sem.unlink() # ----------------------------------- I expected that code to raise a posix_ipc.Error with the text, "The wait was interrupted by a signal" which would then be trapped by the except statement which would print the "I caught it!" message. Instead a KeyboardInterrupt error is propagated up to the interpreter and the process is killed as if the try/except wasn't there at all. I have verified that the C function sem_wait() returns -1 (failure), that errno is set to EINTR and that my detects that properly. So far, so good. PyErr_Occurred() returns NULL at that point. So my code calls PyErr_SetString() to set a custom error for the caller and returns NULL. It's apparently at some point after that that the KeyboardInterrupt error is being set. If I substitute my sysv_ipc module for posix_ipc (very similar to posix_ipc but uses Sys V semaphores instead of POSIX), I get the same behavior. I see this w/Python 2.5 under OS X and also w/Python 2.5 under Ubuntu 8.0.4. If anyone wants to look at my C code, the relevant case statement is on line 555 of posix_ipc_module.c. http://semanchuk.com/philip/posix_ipc/ http://semanchuk.com/philip/sysv_ipc/ Any suggestions would be appreciated. Thanks Philip From wistoch at gmail.com Thu Jun 18 23:22:36 2009 From: wistoch at gmail.com (Wei, Xiaohai) Date: Fri, 19 Jun 2009 11:22:36 +0800 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> Message-ID: <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> Thanks for your reply. where is the error log? I can not find it at /var/log I have a virtual network card to bridge kvm virtual machine. will it cause problem? as you said configuration of interpretor, how should I configure the interpretor? Thanks James On Fri, Jun 19, 2009 at 9:32 AM, Fabio Zadrozny wrote: > > yes, the same problem even on an empty program. every file has the same > > problem. > > > > for example, if I new a file and input the following: > > import os > > os. > > after I input '.', it will pop up the window, and i can select the > function > > of os module or continue input. but after that, no action can be taken > for > > this file unless I switch to other files and then switch back. > > If it's in pydev, there's probably some problem in your interpreter > configuration (when you do os. it'll spawn a shell to gather the > completions -- but that should be pretty quick unless you have some > firewall that's preventing the communication or the spawn didn't go > well -- check your error log to see if you have any errors... In linux > I've seen some problems when connecting to 127.0.0.1 while having ipv6 > enabled or in a network card misconfiguration that could cause > problems too). > > Cheers, > > Fabio > > > > > > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing > wrote: > >> > >> Do you experience the same problem even on an empty program file or is > it > >> limited to just one file? > >> > >> -Tyler > >> > >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > >>> > >>> On Jun 18, 10:45 am, "Wei, James" wrote: > >>> > When I am editing python program with SPE, I found that SPE will > >>> > freeze when it is doing auto-completion. The behavior is very strange > >>> > that I can not edit the file again. If I switch to another file and > >>> > then switch back, I can edit it again. > >>> > > >>> > So I switch to eclipse+pydev, but I found the same thing happen. So I > >>> > think it is not the problem of SPE or eclipse or pydev. > >>> > > >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it > will > >>> > not freeze any longer. > >>> > > >>> > Anybody can give me some hints? > >>> > > >>> > I am using Ubuntu 8.10 and updated to latest. All packages is > >>> > installed through package manager. > >>> > >>> the only thing I googled related with it is > >>> > >>> > >>> > http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html > >>> > >>> but I think they are different. > >>> > >>> -- > >>> http://mail.python.org/mailman/listinfo/python-list > >> > >> > >> > >> -- > >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > > > > > -- > > Best wishes to you. > > > > Yours sincerely > > > > Xiaohai Wei > > wistoch at ustc.edu > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- Best wishes to you. Yours sincerely Xiaohai Wei wistoch at ustc.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Fri Jun 19 00:20:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 19 Jun 2009 16:20:55 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <7a0hv6F1sm9rbU1@mid.individual.net> ssc wrote: > class SignupForm(Form): > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Does the generator expression have its own little namespace or so ? Yes. The generator expression is a function, with its own local namespace. Since the class scope is not visible from inside functions declared within it, the behaviour you're seeing results. -- Greg From greg at cosc.canterbury.ac.nz Fri Jun 19 00:28:10 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 19 Jun 2009 16:28:10 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: <7a0icpF1smf41U1@mid.individual.net> nn wrote: > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > >>>>class x: > > ... lst=[2] > ... gen=[lst.index(e) for e in lst] In 3.x it was decided that the loop variables in a list comprehension should be local, and not leak into the surrounding scope. This was implemented by making the list comprehension into a nested function. Unfortunately this leads to the same unintuitive behaviour as a genexp when used in a class scope. -- Greg From ben+python at benfinney.id.au Fri Jun 19 00:33:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Jun 2009 14:33:25 +1000 Subject: Is this pylint error message valid or silly? References: Message-ID: <87eitg267e.fsf@benfinney.id.au> Matthew Wilson writes: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): > > if c == "today": > c = datetime.today() > > return c.date() > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration > ************* Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types could > not be inferred) > > Is this a valid error message? Yes. Mentally run through your code and ask ?what happens if the condition for the ?if? statement is false?? > Is the code above bad? If so, what is the right way? Yes, it's bad: * The function name ?f? is completely unhelpful. Consider a reader of the function who has no access to the inside of your head: Your function should be named, preferably, as a verb phrase, to say what the function *does* when it is called. * The parameter name ?c? is completely undescriptive. Again, consider a reader ignorant of your thinking: You should name parameters so they help the reader know what the parameter is supposed to be and how it will be interpreted. * You're re-binding the parameter name ?c? to something different within the function: it starts out bound to the input string, but by the time the function ends you're expecting it to be bound to a datetime object. Instead, you should be binding a *different* name to the datetime object you create inside the function, and using that for the return statement. -- \ ?Read not to contradict and confute, nor to believe and take | `\ for granted ? but to weigh and consider.? ?Francis Bacon | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Fri Jun 19 01:51:52 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:51:52 +1200 Subject: Packing a ctypes struct containing bitfields. References: Message-ID: In message , Karthik wrote: > from ctypes import * Don't do that. From ldo at geek-central.gen.new_zealand Fri Jun 19 01:53:40 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:53:40 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> Message-ID: In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: > On Thu, 18 Jun 2009 10:33:49 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: >> >>> On Wed, 17 Jun 2009 23:04:37 +1200 >>> Lawrence D'Oliveiro wrote: >>> >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev >>>> wrote: >>>> >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 >>>>> Lawrence D'Oliveiro wrote: >>>>> >>>>>>> Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>> arranging them like /path/f/9/e/95ea4926a4 ? >>>>>>> >>>>>>> That way, you won't have to deal with many-files-in-path problem >>>>>>> ... >>>>>> >>>>>> Why is that a problem? >>>>> >>>>> So you can os.listdir them? >>>> >>>> Why should you have a problem os.listdir'ing lots of files? >>> >>> I shouldn't, and I don't ;) >> >> Then why did you suggest that there was a problem being able to >> os.listdir them? > > I didn't, OP did ... Then why did you reply to my question "Why is that a problem?" with "So that you can os.listdir them?", if you didn't think there was a problem (see above)? From ldo at geek-central.gen.new_zealand Fri Jun 19 01:54:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:54:31 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: In message , Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: >> >> >>>On Wed, 17 Jun 2009 23:04:37 +1200 >>>Lawrence D'Oliveiro wrote: >>> >>> >>>>In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >>>> >>>> >>>>>On Wed, 17 Jun 2009 17:53:33 +1200 >>>>>Lawrence D'Oliveiro wrote: >>>>> >>>>> >>>>>>>Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>>arranging them like /path/f/9/e/95ea4926a4 ? >>>>>>> >>>>>>>That way, you won't have to deal with many-files-in-path problem ... >>>>>> >>>>>>Why is that a problem? >>>>> >>>>>So you can os.listdir them? >>>> >>>>Why should you have a problem os.listdir'ing lots of files? >>> >>>I shouldn't, and I don't ;) >> >> Then why did you suggest that there was a problem being able to >> os.listdir them? > > He didn't ... He replied to my question "Why is that a problem?" with "So you can os.listdir them?". Why reply with an explanation of why it's a problem if you don't think it's a problem? From ldo at geek-central.gen.new_zealand Fri Jun 19 01:55:18 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:55:18 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan wrote: > Yeah, it might be possible to just mv the file from outside, but not > being able to enter a directory just because you've got too many files > in it is kind of silly. Sounds like a problem with your file/directory-manipulation tools. From rajat.dudeja at aeroflex.com Fri Jun 19 02:42:16 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Fri, 19 Jun 2009 02:42:16 -0400 Subject: How to check if file is open on Windows XP? Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> Hi, I'm looking for a fascility that can check if the file is open on Windows XP and if the file is open (say a notepad file is open), I want to close that file (i.e the notepad application) I found that there are no such methods available in OS modules. Is using Win32 API is the only solution? Pleae suggest. Thanks, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jun 19 02:46:14 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 02:46:14 -0400 Subject: AT&T Usenet Netnews Service Shutting Down In-Reply-To: References: <1245249220_11395@newsgroups.bellsouth.net> Message-ID: Jive Dadson wrote: > newsmaster at bellsouth.net wrote: >> Please note that on or around July 15, 2009, AT&T will no longer be >> offering access to the Usenet Netnews service. If you wish to continue >> reading Usenet newsgroups, access is available through third-party >> vendors. news.gmane.org (free) mirrors python-list as gmane.comp.python.general I prefer it to c.l.p because python-list filters out most spam. > Ah ha. I think I may have figured out how to work around it. I need to > use my EasyNews server to post the message, (with "SSL"), rather than > the ATT server. I think. Maybe. Does anyone know if it's possible to > have Thunderbird use different outgoing servers for different accounts? Tbird recommends not doing so (no idea why), so it *must* be possible ;-). Looks pretty simple. From tjreedy at udel.edu Fri Jun 19 02:55:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 02:55:52 -0400 Subject: Is this pylint error message valid or silly? In-Reply-To: References: Message-ID: Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): pylint infers that you intend users to pass a string. Human would guess the same at this point. > if c == "today": > c = datetime.today() Now I guess that you actually intend c to be passed as a datetime object. You only used the string as a type annotation, not as a real default value. Something like 'record_date = None' is better. > return c.date() and here you ask for the input's date, which strings do not have. > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration > ************* Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types could > not be inferred) > > Is this a valid error message? Is the code above bad? If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > > $ cat f.py > from datetime import datetime > > def f(c=None): > > if c is None: > c = datetime.today() > > return c.date() > > $ pylint -e f.py > No config file found, using default configuration > > I don't see any difference between using a string vs None. Both are > immutable. I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt From mail at anjanesh.net Fri Jun 19 03:22:16 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 19 Jun 2009 12:52:16 +0530 Subject: Integer Division Message-ID: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> >>> a = 1 >>> b = 25 >>> a / b 0 >>> float(a) / b 0.040000000000000001 >>> >>> from __future__ import division >>> a = 1 >>> b = 25 >>> a / b 0.040000000000000001 >>> In what simple way can I get just 0.04 ? -- Anjanesh Lekshmnarayanan From clp2 at rebertia.com Fri Jun 19 03:27:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 00:27:00 -0700 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: <50697b2c0906190027p5eea1343r5d9619948514b3fd@mail.gmail.com> On Fri, Jun 19, 2009 at 12:22 AM, Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 >>>> > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 >>>> > > In what simple way can I get just 0.04 ? Note that what you are shown is the repr() of the float rather than the str() of the float. The repr() value is what the number truly is in binary, but str() applies more sensible rounding. Example (remember that print() does an implicit str()): >>> from __future__ import division >>> print(1/25) 0.04 >>> repr(1/25) 0.040000000000000001 >>> Alternatively, you can use the decimal arithmetic library: >>> from decimal import Decimal >>> Decimal(1)/Decimal(25) Decimal('0.04') >>> Cheers, Chris -- http://blog.rebertia.com From jure.erznoznik at gmail.com Fri Jun 19 03:29:11 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 00:29:11 -0700 (PDT) Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Message-ID: I've done some further testing on the subject: I also added some calculations in the main loop to see what effect they would have on speed. Of course, I also added the same calculations to the single threaded functions. They were simple summary functions, like average, sum, etc. Almost no interaction with the buffers was added, just retrieval of a single field's value. Single threaded, the calculations added another 4.3 seconds to the processing time (~18%) MultiThreaded, they added 1.8 seconds. CPU usage remained below 100% of one core at all times. Made me check the process affinity. I know the main thread uses way less CPU than DBF reading thread (4 secs vs 22 secs). So I think adding these calculations should have but a minimal impact on threaded execution time. Instead, the execution time increases!!! I'm beginning to think that Python's memory management / functions introduce quite a significant overhead for threading. I think I'll just write this program in one of the compilers today to verify just how stupid I've become. From mk.fraggod at gmail.com Fri Jun 19 03:40:15 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 13:40:15 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> Message-ID: <20090619134015.349ba199@malediction> On Fri, 19 Jun 2009 17:53:40 +1200 Lawrence D'Oliveiro wrote: > In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: > > > On Thu, 18 Jun 2009 10:33:49 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev > >> wrote: > >> > >>> On Wed, 17 Jun 2009 23:04:37 +1200 > >>> Lawrence D'Oliveiro wrote: > >>> > >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev > >>>> wrote: > >>>> > >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 > >>>>> Lawrence D'Oliveiro wrote: > >>>>> > >>>>>>> Why not use hex representation of md5/sha1-hashed id as a > >>>>>>> path, arranging them like /path/f/9/e/95ea4926a4 ? > >>>>>>> > >>>>>>> That way, you won't have to deal with many-files-in-path > >>>>>>> problem ... > >>>>>> > >>>>>> Why is that a problem? > >>>>> > >>>>> So you can os.listdir them? > >>>> > >>>> Why should you have a problem os.listdir'ing lots of files? > >>> > >>> I shouldn't, and I don't ;) > >> > >> Then why did you suggest that there was a problem being able to > >> os.listdir them? > > > > I didn't, OP did ... > > Then why did you reply to my question "Why is that a problem?" with > "So that you can os.listdir them?", if you didn't think there was a > problem (see above)? Why do you think that if I didn't suggest there is a problem, I think there is no problem? I do think there might be such a problem and even I may have to face it someday. So, out of sheer curiosity how more rediculous this topic can be I'll try to rephrase and extend what I wrote in the first place: Why would you want to listdir them? I can imagine at least one simple scenario: you had some nasty crash and you want to check that every file has corresponding, valid db record. What's the problem with listdir if there's 10^x of them? Well, imagine that db record also holds file modification time (say, the files are some kind of cache), so not only you need to compare listdir results with db, but also do os.stat on every file and some filesystems will do it very slowly with so many of them in one place. Now, I think I made this point in the first answer, no? Of course you can make it more rediculous by your I-can-talk-away-any-problem-I-can't-see-or-solve approach by asking "why would you want to use such filesystems?", "why do you have to use FreeBSD?", "why do you have to work for such employer?", "why do you have to eat?" etc, but you know, sometimes it's easier and better for the project/work just to solve it, than talk everyone else away from it just because you don't like otherwise acceptable solution. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From chris at simplistix.co.uk Fri Jun 19 03:56:02 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 08:56:02 +0100 Subject: MailingLogger 3.3.0 Released! Message-ID: <4A3B4492.9030003@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with an X-Mailer header for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested In addition, extra support is provided for configuring the handlers when using ZConfig, Zope 2 or Zope 3. The latest releases of ZConfig, in particular, provide a great way to configure the python logging framework without having to resort to the appalling .ini-based configuration stuff: >>> from ZConfig import configureLoggers >>> configureLoggers(''' ... ... level INFO ... ... PATH STDOUT ... format %(levelname)s %(name)s %(message)s ... ... ... ''') This release of MailingLogger adds the ability to use %(levelname)s in subject-line formatting for SummarisingLoggers to include the highest level logged. For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From dickinsm at gmail.com Fri Jun 19 04:12:26 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 01:12:26 -0700 (PDT) Subject: Integer Division References: Message-ID: On Jun 19, 8:22?am, Anjanesh Lekshminarayanan wrote: > >>> a = 1 > >>> b = 25 > >>> a / b > 0 > >>> float(a) / b > > 0.040000000000000001 Python typically stores floats in binary, not decimal. The value 0.04 isn't exactly representable in binary, so the division float(1)/25 can't produce 0.04: what you get instead is a very good approximation to 0.04. That's why you're seeing what you're seeing above. Note that 0.0400...001 is *also* just an approximation to the actual value stored, but it's a better approximation than 0.04. The exact value stored is (probably, assuming your machine is typical): 0.040000000000000000832667268468867405317723751068115234375 or, if you prefer, it's: 5764607523034235/144115188075855872 > In what simple way can I get just 0.04 ? The answer to that depends on what you want and why you want it. Do you want a string or a number? And if you want a number, does it have to be *exactly* 0.04, or can your application cope with a tiny error? If you're trying to get a string and just want things to look nice, use str() instead of repr(), or display the value using print. If you want more control over the number of digits displayed, use Python's string formatting: e.g., in Python 2.6: >>> format(0.04, '.3f') # format with 3 places after the point '0.040' See the following for more information on format: http://docs.python.org/library/string.html#formatstrings If you're after the number and you *really* need to be able to manipulate the *exact* value 0.04 in Python (e.g., because you're doing financial work), you're probably better off using the Decimal module: http://docs.python.org/library/decimal.html See also: http://docs.python.org/tutorial/floatingpoint.html Mark From martin.schoon at gmail.com Fri Jun 19 04:16:39 2009 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Fri, 19 Jun 2009 10:16:39 +0200 Subject: Slow wxPyhon on Vista? Message-ID: <87y6ro3afs.fsf@crunchbang.Belkin> Hello there, this might be my first post here and it is slightly off topic since it is not about something I am developing. At work use a nifty little program called Task Coach. It helps me keep track of what I spend time on. Here is my problem. When I use it on a Vista box its user interface is very, very slow when it comes to some but not all operations. On any other Windows version it reacts instantaneously. I have not tried Task Coach on Linux or Solaris (yet). Is this how wxPython or Python works on Vista in general or is this the result of some local oddity on my employer's Vista configuration? TIA, /Martin From jure.erznoznik at gmail.com Fri Jun 19 04:27:48 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 01:27:48 -0700 (PDT) Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Message-ID: <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Digging further, I found this: http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html Looking up on this info, I found this: http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock If this is correct, no amount of threading would ever help in Python since only one core / CPU could *by design* ever be utilized. Except for the code that accesses *no* functions / memory at all. This does seem to be a bit harsh though. I'm now writing a simple test program to verify this. Multiple data- independed threads just so I can see if more than one core can at all be utilized. :( From usernet at ilthio.net Fri Jun 19 04:35:18 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Jun 2009 08:35:18 GMT Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: On 2009-06-19, =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > If this is correct, no amount of threading would ever help in Python > since only one core / CPU could *by design* ever be utilized. Except > for the code that accesses *no* functions / memory at all. Don't multithread...multiprocess. By running multiple python instances, the operating system handles the processor scheduling for each so that you can use all available CPUs/cores. It also tends to make debugging easier. It does create more overhead -- significantly more on some OSs. From lepto.python at gmail.com Fri Jun 19 04:42:06 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 19 Jun 2009 16:42:06 +0800 Subject: lib to do advanced geometry calculation? Message-ID: <6a4f17690906190142q518d2291k20df19f624b738fd@mail.gmail.com> My problem is some complex, because some condition is not supplied as a given value please have a look at http://www.lusiya.com/bbs/attachment/thumb/Mon_0906/80_3201_d2fa7bd75d28675.jpg because I have to do futher calculation based on previous steps as http://www.lusiya.com/bbs/attachment/thumb/Mon_0906/80_3201_d342e52235049e0.jpgshows, I want to get a precise value if possible, that is to say, (sqrt(2), 0), but not (1.414.0) [description] (clear condition) A=point(0,1) B=point(1,1) C=point(0,0) D=point(1,0) AC=segment(A, C) BD=segment(B, D) CD=segment(C, D) AB=segment(A, B) I=midpoint(B, D) (vague condition) E=pointOn(AC) F=pointOn(BD) EF=segment(E, F) G=mirror(A, EF) G=pointOn(CD) H=mirror(I, EF) H=pointOn(AB) (solve) E F [/description] Above is the description of my question, but I also hope I can write a problem like that to solve it. The only lib I know is sympy, but it seems that I must write different and long code accroding to different problem So is there any advanced (and lazy of cause) lib to handle my question? thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From heintest at web.de Fri Jun 19 04:42:33 2009 From: heintest at web.de (=?windows-1252?Q?Hans_M=FCller?=) Date: Fri, 19 Jun 2009 10:42:33 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Thanks for all your informative replies. If I understand you right, for a commercial, closed source program I only need a commercial PyQt license for ~ 500? ? As far as I know I also need a Qt Licenses which is ~3500? per OS. What is right ? Thanks a lot, Hans From piet at cs.uu.nl Fri Jun 19 04:53:27 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 10:53:27 +0200 Subject: Help: Group based synchronize decorator References: Message-ID: >>>>> Vishal Shetye (VS) wrote: >VS> I want to synchronize calls using rw locks per 'group' and my implementation is similar to >VS> http://code.activestate.com/recipes/465057/ >VS> except that I have my own Lock implementation. >VS> All my synchronized functions take 'whatGroup' as param. My lock considers 'group' while deciding on granting locks through acquire. >VS> What I could come up with is: >VS> - decorator knows(assumes) first param to decorated functions is always 'whatGroup' >VS> - decorator passes this 'whatGroup' argument to my lock which is used in acquire logic. >VS> Is it ok to make such assumptions in decorator? As long as you make sure that all decorated functions indeed adhere to that assumption there is nothing wrong with it. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From newsgroup at silveraxe.de Fri Jun 19 04:58:46 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Fri, 19 Jun 2009 10:58:46 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4a3b5347$0$30232$9b4e6d93@newsspool1.arcor-online.net> Hans M?ller schrieb: > Thanks for all your informative replies. > > If I understand you right, for a commercial, closed source program I > only need a commercial PyQt license for ~ 500? ? > > As far as I know I also need a Qt Licenses which is ~3500? per OS. > > What is right ? Qt is under the LGPL license to you can use it for free in your commercial program. Best, Hilmar From jeremy+complangpython at jeremysanders.net Fri Jun 19 05:00:16 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Fri, 19 Jun 2009 10:00:16 +0100 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Hans M?ller wrote: > Thanks for all your informative replies. > > If I understand you right, for a commercial, closed source program I > only need a commercial PyQt license for ~ 500? ? Why not ask the guys at riverbankcomputing? http://www.riverbankcomputing.co.uk/commercial/pyqt This page http://www.riverbankcomputing.co.uk/software/pyqt/license Says "The commercial version of PyQt can be used with both the commercial and LGPL versions of Qt." > As far as I know I also need a Qt Licenses which is ~3500? per OS. Not true, now Qt is licensed under the LGPL. You have to abide by the LGPL, however, which means that the user has to be able to relink a modified form of the library, Qt, with your application should they wish. You should check whether the LGPL is appropriate for the way you want to ship your program. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ From piet at cs.uu.nl Fri Jun 19 05:14:28 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 11:14:28 +0200 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: >>>>> John Machin (JM) wrote: >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ Apart from these patents probably being silly, why don't they just write the code in Python? :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From chris at simplistix.co.uk Fri Jun 19 05:21:11 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 10:21:11 +0100 Subject: ErrorHandler 1.0.0 Released! Message-ID: <4A3B5887.6000509@simplistix.co.uk> I'm pleased to finally get around to announcing the release of ErrorHandler. This is a handler for the python standard logging framework that can be used to tell whether messages have been logged at or above a certain level. This can be useful when wanting to ensure that no errors have been logged before committing data back to a database. Here's an example: First, you set up the error handler: >>> from logging import getLogger >>> from errorhandler import ErrorHandler >>> logger = getLogger() >>> e = ErrorHandler() The handler started off being un-fired: >>> e.fired False Then you do whatever else you need to do, which may involve logging: >>> logger.info('some information') >>> e.fired False However, if any logging occurs at an error level or above: >>> logger.error('an error') Then the error handler becomes fired: >>> e.fired True You use this as a condition to only do certain actions when no errors have been logged: >>> if e.fired: ... print "Not updating files as errors have occurred" Not updating files as errors have occurred If your code does work in batches, you may wish to reset the error handler at the start of each batch: >>> e.reset() >>> e.fired False For more information, please see: http://www.simplistix.co.uk/software/python/errorhandler or http://pypi.python.org/pypi/errorhandler cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Fri Jun 19 05:22:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 10:22:51 +0100 Subject: Excel Formulae in Python ;-) In-Reply-To: References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: <4A3B58EB.6070306@simplistix.co.uk> Piet van Oostrum wrote: >>>>>> John Machin (JM) wrote: > >> JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ > > Apart from these patents probably being silly, why don't they just write > the code in Python? :=) Would be cool, but there are things like Resolver One (http://www.resolversystems.com/product/) and DiscoveryScript (http://www.xefion.com/en/discoveryscript.html) ...that help. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From pod at internode.on.net Fri Jun 19 05:35:10 2009 From: pod at internode.on.net (PoD) Date: 19 Jun 2009 09:35:10 GMT Subject: CAD file format specifications? References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> Message-ID: <024b4dd3$0$20662$c3e8da3@news.astraweb.com> On Thu, 18 Jun 2009 13:39:28 +0200, Anthra Norell wrote: > I had a look at Blender. It looks impressive too. It might be an > alternative to Sketch Up. I'll worry about that later. My immediate need > is a file conversion utility. A cursory inspection of Blender's menu > tabs and the various help options didn't turn up a file-conversion > utility. So, my question is: How do I convert a bunch of > three-dimensional coordinates defining lines into a file format Sketch > Up can read (skp, dwg, dxf, 3ds, ddf or dem)? > > Frederic If you look in the File/Import menu in Blender, you will see all the file types which it can load. The importing is done with python scripts, so if you are going to write a converter you might just as well write an import script for Blender. The raw import script shows how simple it can be. From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 05:43:54 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 11:43:54 +0200 Subject: A question on scope... In-Reply-To: References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> Message-ID: <4a3b5dc3$0$2985$426a74cc@news.free.fr> MRAB a ?crit : > Wells Oliver wrote: NB : answering the OP (original post didn't show up on c.l.py ???) >> In writing out python classes, it seems the 'self' is optional, You mean, inside a method ? >> meaning that inside a class method, In Python, a "class method" is a method that operates on the class object itself instead of operating on an instance of the class. >> "self.foo = bar" has the same >> effect as "foo = bar". Is this right? It's obviously false, cf MRAB's answer. From jure.erznoznik at gmail.com Fri Jun 19 05:52:55 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 02:52:55 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? Message-ID: See here for introduction: http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 Digging through my problem, I discovered Python isn't exactly thread safe and to solve the issue, there's this Global Interpreter Lock (GIL) in place. Effectively, this causes the interpreter to utilize one core when threading is not used and .95 of a core when threading is utilized. Is there any work in progess on core Python modules that will permanently resolve this issue? Is there any other way to work around the issue aside from forking new processes or using something else? From gh at ghaering.de Fri Jun 19 06:20:16 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 19 Jun 2009 12:20:16 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <4A37BD14.5010807@arimaz.com> References: <4A37BD14.5010807@arimaz.com> Message-ID: Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > > " OperationalError > Exception raised for errors that are related to the > database's operation and not necessarily under the control > of the programmer, e.g. an unexpected disconnect occurs, > the data source name is not found, a transaction could not > be processed, a memory allocation error occurred during > processing, etc. It must be a subclass of DatabaseError. > ProgrammingError > Exception raised for programming errors, e.g. table not > found or already exists, syntax error in the SQL > statement, wrong number of parameters specified, etc. It > must be a subclass of DatabaseError. > " > > and to me it sounds more like a programming error than an operational > error. I agree. But I can't help you there. See _pysqlite_seterror() at http://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c What I do is map SQLite error codes to DB-API exceptions. And SQLite reports your error as generic SQLITE_ERROR, which is mapped to OperationalError. -- Gerhard From albert at spenarnc.xs4all.nl Fri Jun 19 06:49:00 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 19 Jun 2009 10:49:00 GMT Subject: preferring [] or () in list of error codes? References: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: In article , > > >But practicality beats purity -- there are many scenarios where we make >compromises in our meaning in order to get correct, efficient code. E.g. >we use floats, despite them being a poor substitute for the abstract Real >numbers we mean. > >In addition, using a tuple or a list in this context: > > if e.message.code in (25401,25402,25408): > >is so idiomatic, that using a set in it's place would be distracting. >Rather that efficiently communicating the programmer's intention, it >would raise in my mind the question "that's strange, why are they using a >set there instead of a tuple?". As a newby I'm really expecting a set here. The only reason my mind goes in the direction of 3 items is that it makes no sense in combination with ``in''. That makes this idiom one that should be killed. " point1 = (0,1,0) point2 = (1,0,0) point3 = (0,0,1) for i in (point1,point2, point3): .... " ??? I don't think so. At least I would do " for i in [point1,point2,point3]: statements " But I greatly prefer a set " for i in {point1,point2,point3}: statements " Because a set is unorderded, this would convey to the the compiler that it may evaluate the three statements concurrently. For a list I expect the guarantee that the statements are evaluated in order. For a tuple I don't know what to expect. That alone is sufficient reason not to use it here. [Yes I know { } doesn't denote a set. I tried it. I don't know how to denote a set ... ] >-- >Steven 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 scott.pigman at gmail.com Fri Jun 19 07:14:19 2009 From: scott.pigman at gmail.com (Scott) Date: Fri, 19 Jun 2009 04:14:19 -0700 (PDT) Subject: Allocating memory to pass back via ctypes callback function References: Message-ID: <0b8e092f-2353-4a6b-8ff0-62e1e7b4d427@r3g2000vbp.googlegroups.com> I think I found the answer to my own question. Can anyone spot any issues with the following solution? The application I'm writing will be hitting these callbacks pretty heavily so I'm nervous about mucking up the memory management and creating one of those bugs that passes undetected through testing but nails you in production. def my_callback(p_cstring): answer = 'foobar' address = VENDOR_malloc(len(answer)+1) cstring = c_char_p.from_address( address ) cstring.value = answer p_cstring.contents = cstring return From david.lyon at preisshare.net Fri Jun 19 07:16:33 2009 From: david.lyon at preisshare.net (David Lyon) Date: Fri, 19 Jun 2009 07:16:33 -0400 Subject: Slow wxPyhon on =?UTF-8?Q?Vista=3F?= In-Reply-To: <87y6ro3afs.fsf@crunchbang.Belkin> References: <87y6ro3afs.fsf@crunchbang.Belkin> Message-ID: <5bc3ad79f831b20568c6893831335c2a@preisshare.net> On Fri, 19 Jun 2009 10:16:39 +0200, martin.schoon at gmail.com (Martin Sch??n) wrote: > Here is my problem. When I use it on a Vista box its > user interface is very, very slow when it comes to > some but not all operations. On any other Windows > version it reacts instantaneously. I have not tried > Task Coach on Linux or Solaris (yet). > > Is this how wxPython or Python works on Vista in > general or is this the result of some local oddity on my > employer's Vista configuration? I have encountered the same thing on XP in one instance on a development box. For some reason, wxpython just grinds to a halt. I couldn't solve it and reimaged the O/S... that fixed it... David From piet at cs.uu.nl Fri Jun 19 07:23:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:23:16 +0200 Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Digging further, I found this: >JE> http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html >JE> Looking up on this info, I found this: >JE> http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock >JE> If this is correct, no amount of threading would ever help in Python >JE> since only one core / CPU could *by design* ever be utilized. Except >JE> for the code that accesses *no* functions / memory at all. It is not the design of the Python language, but of the Python implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:29:21 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:29:21 +0200 Subject: Integer Division References: Message-ID: >>>>> Anjanesh Lekshminarayanan (AL) escribi?: >>>>> a = 1 >>>>> b = 25 >>>>> a / b >AL> 0 >>>>> float(a) / b >AL> 0.040000000000000001 >>>>> >>>>> from __future__ import division >>>>> a = 1 >>>>> b = 25 >>>>> a / b >AL> 0.040000000000000001 >>>>> >AL> In what simple way can I get just 0.04 ? In addition to the answers others have given: >>> 0.04 0.040000000000000001 >>> IIRC, Python 3.1 will give 0.04. But this doesn't mean the answer will be mathematically equal to 0.04, just that it tries to make it less painful. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:32:10 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:32:10 +0200 Subject: Excel Formulae in Python ;-) References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: >>>>> Chris Withers (CW) wrote: >CW> Piet van Oostrum wrote: >>>>>>>> John Machin (JM) wrote: >>> >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ >>> >>> Apart from these patents probably being silly, why don't they just write >>> the code in Python? :=) >CW> Would be cool, but there are things like >CW> Resolver One (http://www.resolversystems.com/product/) >CW> and >CW> DiscoveryScript (http://www.xefion.com/en/discoveryscript.html) >CW> ...that help. Actually, I meant writing the patent application in Python :=) instead of this pseudo-exact legalese with goto instructions for the control flow. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:39:20 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:39:20 +0200 Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Digging further, I found this: >JE> http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html >JE> Looking up on this info, I found this: >JE> http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock >JE> If this is correct, no amount of threading would ever help in Python >JE> since only one core / CPU could *by design* ever be utilized. Except >JE> for the code that accesses *no* functions / memory at all. It is not the design of the Python language, but of the *CPython* implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From davea at ieee.org Fri Jun 19 08:06:51 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 08:06:51 -0400 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: <4A3B7F5B.1030302@ieee.org> Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b >>>> > 0 > >>>> float(a) / b >>>> > 0.040000000000000001 > > > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b >>>> > 0.040000000000000001 > > > In what simple way can I get just 0.04 ? > > Your subject line says "Integer Division" but you're dealing with floats. IEEE standard float cannot exactly represent 0.04 In fact, no binary floating point value of finite precision can get that exact value. So if you really want 0.04, you need to use the decimal package. It's the only way you'll be sure of exactly representing any decimal fraction you need. Let's call val = float(1)/25 If you're using future division (or Python 3.x), 1/25 will be exactly the same as val. In either case, the division cannot come out exactly, since there is no such exact float. On the other hand, some *string* representation of val may not come out "exact." Technically, to represent val in decimal digits may take up to 59 or so characters. But the two standard conversions from float to string ( float.__str__ and float.__val__ ) do a little rounding themselves. So you can try them, and see that one of them "works." (print calls the __str__ method, while the interpreter uses __repr__) The problem with this is that what "works" for one such val might fail for the next. And these __str__ and __val__ have been implemented multiple times, so testing on one Python version will not assure consistency on the next. The issue is that you're counting on two approximations canceling each other out. That'll work in some circumstances, but knowing what they are isn't reasonable. So what do people do? Simplest is to use a decimal package. I tried back in the early 80's to convince the IEEE committee to include decimal float in the standard, but was rejected. I had implemented (microcoded) arithmetic and transcendentals on a machine which offered only decimal floating point; no binary floating point. Next choice? Stick to integers, or implied fractions. For example, if dealing with dollars and cents, always calculate and store the value in pennies, and only insert the decimal when displaying. Finally, it's not hard (if you know something about the numbers) to get a "pretty" display version for yourself, rounding it as you're converting to string. Note that this affects other aspects of your program, such as comparisons between two floats. If you sum up 100 copies of .01, will you get exactly 1.0 ? I don't know, but in many cases, clearly not. This is not a new problem. I read about it in McCracken's Fortran book in 1967, where he said to use something on the order of: if abs(a-b) < .0000000001 ... when comparing reals. From ben+python at benfinney.id.au Fri Jun 19 08:13:36 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Jun 2009 22:13:36 +1000 Subject: preferring [] or () in list of error codes? References: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <87ab441kwf.fsf@benfinney.id.au> Albert van der Horst writes: > But I greatly prefer a set > > " > for i in {point1,point2,point3}: > statements > " Agreed, for the reasons you cite. I think this idiom can be expected to become more common and hopefully displace using a tuple literal or list literal, as the set literal syntax becomes more reliably available on arbitrary installed Python versions. > [Yes I know { } doesn't denote a set. I tried it. I don't know how to > denote a set ... ] Try it in Python 3 and be prepared to be pleased . -- \ ?Too many Indians spoil the golden egg.? ?Sir Joh | `\ Bjelke-Petersen | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 08:45:43 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 14:45:43 +0200 Subject: generator expression works in shell, NameError in script In-Reply-To: References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <4a3b8860$0$19616$426a74cc@news.free.fr> Emile van Sebille a ?crit : > On 6/17/2009 3:54 PM ssc said... >> Wow! Didn't expect that kind of instant support. Thank you very much, >> I'll give both zip and enumerate a try. >> >> The code I've shown is actually copied pretty straight from a Django >> form class, but I didn't want to mention that as not to dilute the >> conversation. Don't think it matters, anyway. This is the relevant >> excerpt: >> >> from django.forms import Form >> >> class SignupForm(Form): >> >> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in >> titles) >> >> Now that I look at it again, it seems odd to me to not have the code >> e.g. in __init__(...), but just 'class-global'. > > And as class is an executable statement, I imagine titles exists in a > namespace that hasn't yet been completely defined. >> Still, that does not seem a reason for titles not to be not defined, >> as I do define it just in the line above. > > Well, again, titles will exists in the SignupForm namespace once it > exists, which it doesn't yet when you get to title_choices and want to > access it. The namespace itself is as defined at any point of the class statement's body as the local namespace of a function at any given point of the function's body. Else decorators (or their alternate pre '@' syntactic-sugar version) wouldn't work. FWIW, the following code works JustFine(tm): bruno at bruno:~$ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list(enumerate(bar)) as well as this one: >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = [(bar.index(t)+1, t) for t in bar] and this one: >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list((b, b) for b in bar) but it indeed looks like using bar.index *in a generator expression* fails (at least in 2.5.2) : >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list((bar.index(b), b) for b in bar) ... Traceback (most recent call last): File "", line 1, in File "", line 3, in Foo File "", line 3, in NameError: global name 'bar' is not defined Looks like a bug to me :-/ From martin.hellwig at dcuktec.org Fri Jun 19 09:04:12 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 19 Jun 2009 14:04:12 +0100 Subject: Decorator question (how to test if decorated function is in a class) Message-ID: Hi all, I have been trying out to wrap my mind around the advantages of decorators and thought I found a use in one of my experiments. (see code after my sig). Although it works, I think it should be able to do it better. My particular problem is that I want to remove an argument (say always the first one) when the decorated function is called. However if the function is defined in a class the first argument is self and thus the second argument should be removed. Since I like to have a more general DRY approach I want to test if the decorated function is defined in a class or not thus knowing that the first argument is self and must be preserved. I tried different approaches but all didn't work and looked very unpythonic (looking at the attributes, descriptors namespaces, id() of the function, the first argument and the decorator itself). So is there a way to find out if the first argument is 'self' without making a false positive if the first argument is a class instance passed to a function? -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' code: class Decorator(object): "When used as Decorator(argument) returns a decorator" def __init__(self, key): self.key = key def __call__(self, function): "Return a decorator" def decorator(*arg_tuple, **arg_dict): "The decorator test if the arguments contain a valid key" if arg_tuple[0] == self.key: # This means it is a simple function, so check and strip it arg_list = arg_tuple[1::] return(function(*arg_list, **arg_dict)) elif arg_tuple[1] == self.key: # This means it is a class method, check it, # strip (but retain self) arg_list = arg_tuple arg_list = arg_list[0:1] + arg_list[2::] return(function(*arg_list, **arg_dict)) else: # The key was invalid return('invalid') return(decorator) class Test(object): @Decorator('key') def test(self, data): return(data) @Decorator('key') def function_2(self, data): return(data) @Decorator('key') def function_3(self, data): return(data) @Decorator('key') def test_f(data): return(data) # Test starts here test_c = Test() print(test_c.test('key', 'data')) print(test_f('key', 'data')) print(test_c.test('invalid', 'data')) print(test_f('invalid', 'data')) From dickinsm at gmail.com Fri Jun 19 09:08:18 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 06:08:18 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <4a3b8860$0$19616$426a74cc@news.free.fr> Message-ID: <2c34275d-f112-44ed-b99e-201c1ee3a823@v4g2000vba.googlegroups.com> On Jun 19, 1:45?pm, Bruno Desthuilliers wrote: > [...] > but it indeed looks like using bar.index *in a generator expression* > fails (at least in 2.5.2) : > > ? >>> class Foo(object): > ... ? ? bar = ['a', 'b', 'c'] > ... ? ? baaz = list((bar.index(b), b) for b in bar) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 3, in Foo > ? ?File "", line 3, in > NameError: global name 'bar' is not defined > > Looks like a bug to me :-/ I think it's working as intended: name resolution for nested scopes skips intermediate class scopes. The 'Discussion' section of PEP 227 (Statically Nested Scopes) is illuminating; here's a snippet: """Names in class scope are not accessible. Names are resolved in the innermost enclosing function scope. If a class definition occurs in a chain of nested scopes, the resolution process skips class definitions. This rule prevents odd interactions between class attributes and local variable access.""" Mark From castironpi at gmail.com Fri Jun 19 09:24:34 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 06:24:34 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Jun 17, 3:53?pm, "Rhodri James" wrote: > On Wed, 17 Jun 2009 16:06:22 +0100, Aaron Brady ? > wrote: > > > > > On Jun 16, 10:09?am, Mike Kazantsev wrote: > >> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) > > >> Aaron Brady wrote: > >> > Making the charitable interpretation that this was the extent of c-l- > >> > py's support and enthusiasm for my idea, I will now go into mourning. > >> > Death occurred at oh-eight-hundred. ?Rest in peace, support & > >> > enthusiasm. > > >> I've read this thread from the beginning, being tempted to insert > >> remarks about shelve module or ORMs like SQLAlchemy, but that'd be > >> meaningless without the problem description, which I haven't seen > >> anywhere. Is it some trick idea like "let's walk on our heads"? > > > More like bronze them, or hang them on a tackboard. ?You haven't > > convinced me that it's not a problem, or that it's an easy one. > > Unfortunately it's up to you to demonstrate that it is a problem, > whichever of the many possible 'it's you're talking about. ?So far, > the question "Why would I want to use this? ?What's the use case?" > has gone unanswered, and I'm sure I'm not the only baffled by it. I can demonstrate it's a problem; many things are. The subject line says it all. SQL will persist (and share for IPC, after a fashion) sets of statically typed tuples. But we have need for sets of dynamically typed tuples, in volatile storage at the very least, or no one would like Python. Whether we have need for them in persistent storage remains to be seen. POSH Python Object SHaring has been at least one student's graduate thesis. It couldn't hurt to pursue it if one has time, as with many things. It's pretty likely my estimates of end user usefulness of 'KeepDB', say, derive sturdily and steadily from our estimated popularity of Python. So much for my motives, though not for my opportunities. My implementation has followed two separate paths: one using SQL for a back-end host; the other using hand-coded bytes on disk, complete with large file support using views, and on-disk (or in-buffer) memory management, which incidentally I spoke up about about a year ago. It was the topic of an honors lecture in the Data Structures course in my undergrad. For the record, I still can't beat a log-N balanced tree for finding free nodes, but I am operating on the assumption that the smallest sufficient region is the best to return from 'alloc'. You are not being any help, Rhodri, in your question. Its chief virtue is fidelity of programming, that is, what you write is most true to what you mean. If you have an object on disk, and want the third element of its 'coords' list attribute, it's a waste to do anything other than find its disk address, then the disk address of its 'coords' attribute, then the disk address of the third element of that, such as say, loading or worse, processing, the entire structure; even if, and in light of parallel considerations about economic market transparency and efficiency, that is to say, economy, maybe / especially/ if, you are having a lowly machine make do. You don't want to open every box in your basement to find your tennis racket; you want to open one box, find the racket in the index, then open all and only the boxes that 'nestedly' contain the racket. (Yes, that's / all/ and /only/, or 'if and only if'-- not to be confused with 'one and only'.) It's more economic. From matt at tplus1.com Fri Jun 19 09:36:01 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 13:36:01 GMT Subject: Is this pylint error message valid or silly? References: Message-ID: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> On Fri 19 Jun 2009 02:55:52 AM EDT, Terry Reedy wrote: >> if c == "today": >> c = datetime.today() > > Now I guess that you actually intend c to be passed as a datetime > object. You only used the string as a type annotation, not as a real > default value. Something like 'record_date = None' is better. Thanks for the feedback. I think I should have used a more obvious string in my original example and a more descriptive parameter name. So, pretend that instead of c="today" I wrote record_date="defaults to today's date". I know my way is unorthodox, but I think it is a little bit more obvious to the reader than record_date=None The None is a signal to use a default value, but that is only apparent after reading the code. Thanks again for the comments. Matt From trinioler at gmail.com Fri Jun 19 09:47:38 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 06:47:38 -0700 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3618a6e10906190647h4726fc7tc919d00e2910fbc7@mail.gmail.com> This is a very long-running issue, that has been discussed many times. Here are the two sides to keeping the gil or removing it: Remove the GIL: - True multi-threaded programming - Scalable performance across a multi-core machine - Unfortunately, this causes a slow-down in single core/thread performance - Most of the slow down comes from Python's Reference counting, as every function is supposed to increase and decrease the references... which leads to a lot of synchronization and checking of locks. - It makes the core interpreter much more complex Keeping the GIL: - Processes should be used instead of threads. Look at Erlang, THE model of concurrency. It uses a process model for concurrency and message passing, rather than threads. This means you avoid deadlocks, livelocks, race conditions(not entirely, but they are reduced) - C extensions can still gain really impressive multi-threaded performance. My C extension, a wrapper around ffmpeg, releases the GIL for 90% or so of its processing time, so all other threads are still extremely responsive. - It allows python to stay simple, understandable, and offer good performance, if you know how to use it properly. Basically the two sides are that you it ends up slowing things down, it makes the interpreter more complex vs you should use processes instead, and be smart about how you use the GIL. -Tyler On Fri, Jun 19, 2009 at 2:52 AM, Jure Erzno?nik wrote: > See here for introduction: > > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcharrow at csail.mit.edu Fri Jun 19 09:53:08 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Fri, 19 Jun 2009 09:53:08 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4A3B9844.2030201@csail.mit.edu> Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? There is a group of people working on an alternative implementation to Python that, among other things, will not have a GIL: http://code.google.com/p/unladen-swallow/ There was even a successful attempt to remove the GIL from CPython, but it caused single threaded python code to be much slower. See more here: http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock Cheers, Ben From rhodri at wildebst.demon.co.uk Fri Jun 19 09:53:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Jun 2009 14:53:57 +0100 Subject: Is this pylint error message valid or silly? In-Reply-To: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> References: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> Message-ID: On Fri, 19 Jun 2009 14:36:01 +0100, Matthew Wilson wrote: > On Fri 19 Jun 2009 02:55:52 AM EDT, Terry Reedy wrote: >>> if c == "today": >>> c = datetime.today() >> >> Now I guess that you actually intend c to be passed as a datetime >> object. You only used the string as a type annotation, not as a real >> default value. Something like 'record_date = None' is better. > > Thanks for the feedback. I think I should have used a more obvious > string in my original example and a more descriptive parameter name. > > So, pretend that instead of > > c="today" > > I wrote > > record_date="defaults to today's date". > > I know my way is unorthodox, but I think it is a little bit more obvious > to the reader than > > record_date=None > > The None is a signal to use a default value, but that is only apparent > after reading the code. It's a very common idiom, however, and in addition record_data is None is a cheap test, while record_data == "defaults to today's date" is an expensive test as well as easy to mistype. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Fri Jun 19 10:00:52 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Jun 2009 15:00:52 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Fri, 19 Jun 2009 14:24:34 +0100, Aaron Brady wrote: > You are not being any help, Rhodri, in your question. To you, perhaps not. To me, it has at least had the effect of making what you're trying to do (write a pythonic object database) clearer. -- Rhodri James *-* Wildebeest Herder to the Masses From martin.vonloewis at hpi.uni-potsdam.de Fri Jun 19 10:16:18 2009 From: martin.vonloewis at hpi.uni-potsdam.de (Martin von Loewis) Date: Fri, 19 Jun 2009 16:16:18 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4A3B9DB2.4070909@hpi.uni-potsdam.de> > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. > Is there any other way to work around the issue aside from forking new > processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin From martin.vonloewis at hpi.uni-potsdam.de Fri Jun 19 10:16:31 2009 From: martin.vonloewis at hpi.uni-potsdam.de (Martin von Loewis) Date: Fri, 19 Jun 2009 16:16:31 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. > Is there any other way to work around the issue aside from forking new > processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin From mblume at socha.net Fri Jun 19 10:38:42 2009 From: mblume at socha.net (mblume) Date: 19 Jun 2009 14:38:42 GMT Subject: Is this pylint error message valid or silly? References: Message-ID: <4a3ba2f2$0$9117$5402220f@news.sunrise.ch> Am Fri, 19 Jun 2009 00:56:18 +0000 schrieb Matthew Wilson: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): > > if c == "today": > c = datetime.today() > > return c.date() > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration ************* > Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types > could not be inferred) > > Is this a valid error message? Is the code above bad? If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > > $ cat f.py > from datetime import datetime > > def f(c=None): > > if c is None: > c = datetime.today() > > return c.date() > > $ pylint -e f.py > No config file found, using default configuration > > I don't see any difference between using a string vs None. Both are > immutable. I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt Think of what happens if somebody calls some_result = f("yesterday") HTH Martin From Olivier.Darge at gmail.com Fri Jun 19 10:40:05 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 07:40:05 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <7a0e7314-e07f-4e1f-b9c6-6f9c336818be@g20g2000vba.googlegroups.com> On 19 juin, 11:52, Jure Erzno?nik wrote: > See here for introduction:http://groups.google.si/group/comp.lang.python/browse_thread/thread/3... > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? hi, please read this carefully, there is a solution for Python on multi-core : multiprocessing api. Really nice. Keep real threads for common tasks like network stuff for example. I recently complained too :-) Olivier From thomas.robitaille at gmail.com Fri Jun 19 10:40:11 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Fri, 19 Jun 2009 07:40:11 -0700 (PDT) Subject: multiprocessing and process run time Message-ID: <24112854.post@talk.nabble.com> Hi, I'm making use of the multiprocessing module, and I was wondering if there is an easy way to find out how long a given process has been running for. For example, if I do import multiprocessing as mp import time def time_waster(): time.sleep(1000) p = mp.Process(target=time_waster) p.start() Is there a way that I can then find how long p has been running for? I figured I can use p.pid to get the PID of the process, but I'm not sure where to go from there. Is there an easy way to do this? Thanks, Thomas -- View this message in context: http://www.nabble.com/multiprocessing-and-process-run-time-tp24112854p24112854.html Sent from the Python - python-list mailing list archive at Nabble.com. From invalid at invalid Fri Jun 19 10:41:53 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 09:41:53 -0500 Subject: pyserial question References: <6f4f96030906180424w367d4d11r2f1d37ec264a4bf@mail.gmail.com> Message-ID: On 2009-06-19, Dennis Lee Bieber wrote: > On Thu, 18 Jun 2009 14:24:42 +0300, Piter_ declaimed >> I cant find out how to set "Handshaking RST on TX" in pyserial. > > Never encountered "RST" mode... "RTS" mode is common. > >>From the source -- a port can be initialized with: [nothing relevent] > If RTS/CTS is not doing what you need... You may have to go > very low-level -- programmatically setting and clearing the > control lines. [...] That's not what wants. He wants RTS to be automatically asserted while data is being transmitted, and de-asserted while data is being received. That feature is called "RTS toggle" in MS-Window-speak. The rest of us usually call it half-duplex RTS control or auto-line-direction or something like that. Trying to do it manually from user-space is generally futile. If you're very lucky, you'll be able to get it to work some of the time on some platforms. [ example of manually setting/clearing RTS] > Again, both of those clips are readily viewable by just > looking at the .py files in the serial package. AFAIK, pyserial doesn't support RTS toggle -- it's a feature not supportted my some platforms and/or serial drivers. However, it is supported by the standard Win32 drivers, so you can enable it by setting the appropriate values in the DCB passed SetCommState(). I'm not a windows guy, so you're going to have to go search the Win32 API docs for details. You might be able to use pyserial to open the port, then get the file handle to do whatever low-level configuration tweaks you want, and then use pyserial to read/write data. NB: RTS toggle in Windows drivers isn't generally very reliable, since it's implemented in software by polling the UART status register. Not all UARTS set the tx shift register empty bit at the correct point in time. -- Grant Edwards grante Yow! Like I always say at -- nothing can beat visi.com the BRATWURST here in DUSSELDORF!! From invalid at invalid Fri Jun 19 10:44:17 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 09:44:17 -0500 Subject: Integer Division References: Message-ID: On 2009-06-19, Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 >>>> > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 >>>> > > In what simple way can I get just 0.04 ? You can't. There _is_no_ 0.04 when using binary IEEE floating point (which is what's used for floats on any computer you're likely to run across). You could use some other data type (rationals, BCD floats, etc.). -- Grant Edwards grante Yow! Hello. I know at the divorce rate among visi.com unmarried Catholic Alaskan females!! From aahz at pythoncraft.com Fri Jun 19 10:45:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 07:45:13 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: In article , Aaron Brady wrote: > >You are not being any help, Rhodri, in your question. Maybe not, but honestly, you're getting pretty close to going back in my killfile. Although you're no longer trolling this group, I find your writing difficult to read at best; answering questions from people like Rhodri is about your only chance to reach people like me. Even without the killfile, I'm skipping about 60-80% of your posts. It's a free Usenet, of course, so you're under no obligation to pay any attention to me, but I think you ought to consider the merits of changing your opinion of Rhodri's questions. Side note: the rhetorical trick of inserting a person's name in a statement is often intended and received as a mildly patronizing insult. It's not at all clear to me whether that was your intent; if not, you might want to change your writing style a bit. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jjkk73 at gmail.com Fri Jun 19 10:46:46 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 19 Jun 2009 15:46:46 +0100 Subject: Retrieving column values by column name with MySQLdb Message-ID: Hi, Is there a way of retrieving the value of columns in the rows returned by fetchall, by column name instead of index on the row? Code Snippet: query="select * from employees" db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) cursor = db.cursor () cursor.execute (query) rows = cursor.fetchall () for row in rows: print row[0] Instead of specifying the index of the row to retrieve the first column (row[0]), I'd like to retrieve the value of the first column by column name. Something like row.get('employee_id') Is something of the sort possible with Mysqdb? Thanks very much. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mk.fraggod at gmail.com Fri Jun 19 10:52:01 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 20:52:01 +0600 Subject: multiprocessing and process run time References: <24112854.post@talk.nabble.com> Message-ID: <20090619205201.51171713@coercion> On Fri, 19 Jun 2009 07:40:11 -0700 (PDT) Thomas Robitaille wrote: > I'm making use of the multiprocessing module, and I was wondering if there > is an easy way to find out how long a given process has been running for. > For example, if I do > > import multiprocessing as mp > import time > > def time_waster(): > time.sleep(1000) > > p = mp.Process(target=time_waster) > > p.start() > > Is there a way that I can then find how long p has been running for? I > figured I can use p.pid to get the PID of the process, but I'm not sure > where to go from there. Is there an easy way to do this? If you use unix-like platform (e.g. linux) you can just use 'ps -e -o pid,start_time | grep '. I'd used procpy to do ps-like stuff in python since it's a wrapper around the same procps library, prehaps it can get the same results as well, w/o having to invoke shell commands: http://code.google.com/p/procpy/ -- Mike Kazantsev // fraggod.net From trinioler at gmail.com Fri Jun 19 10:55:19 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 07:55:19 -0700 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> Message-ID: <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> So no one has an answer for why passing flags and the values the flags need through subprocess does not work? I would like an answer. I've examined all the examples I could find online, which were all toy examples, and not helpful to my problem. On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: > I've been trying any variation I can think of to do this properly, but > here's my problem: > > I want to execute this command string: vlc -I rc > > This allows vlc to be controlled via a remote interface instead of the > normal gui interface. > > Now, say, I try this from subprocess: > > >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, > stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > But I don't get the remote interface. I get the normal gui interface. So > how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', > 'rc'] with executable set to 'vlc'. I've had shell=True, I've had > shell=False. I've tried all these combinations. > > What am I doing wrong? > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Fri Jun 19 10:56:04 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 07:56:04 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Jun 19, 7:45?am, a... at pythoncraft.com (Aahz) wrote: > In article , > Aaron Brady ? wrote: > > > > >You are not being any help, Rhodri, in your question. ? > > Maybe not, but honestly, you're getting pretty close to going back in my > killfile. ?Although you're no longer trolling this group, I find your > writing difficult to read at best; answering questions from people like > Rhodri is about your only chance to reach people like me. ?Even without > the killfile, I'm skipping about 60-80% of your posts. ?It's a free > Usenet, of course, so you're under no obligation to pay any attention to > me, but I think you ought to consider the merits of changing your > opinion of Rhodri's questions. > > Side note: the rhetorical trick of inserting a person's name in a > statement is often intended and received as a mildly patronizing insult. > It's not at all clear to me whether that was your intent; if not, you > might want to change your writing style a bit. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha > Side note: the rhetorical trick of inserting a person's name in a This is a welcome digression for me. I wasn't sure that my idea was being taken seriously. On a temperature scale from freezing to boiling, I took Rhodri's message to be somewhere in the single digits-- quite chilly. Maybe if it hadn't made me feel so defensive, I could've just said so. But, judging from his reply, he got the message. > I find your > writing difficult to read at best; ... > I'm skipping about 60-80% of your posts. My loss. From javier.collado at gmail.com Fri Jun 19 11:05:24 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 19 Jun 2009 17:05:24 +0200 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: Hello, The problem might be that, aside from creating the Popen object, to get the command run you need to call 'communicate' (other options, not used with the Popen object directly, are 'call' or 'waitpid' as explained in the documentation). Did you do that? Best regards, Javier 2009/6/19 Tyler Laing : > So no one has an answer for why passing flags and the values the flags need > through subprocess does not work? I would like an answer. I've examined all > the examples I could find online, which were all toy examples, and not > helpful to my problem. > > On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: >> >> I've been trying any variation I can think of to do this properly, but >> here's my problem: >> >> I want to execute this command string: vlc -I rc >> >> This allows vlc to be controlled via? a remote interface instead of the >> normal gui interface. >> >> Now, say, I try this from subprocess: >> >> >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, >> >>> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >> But I don't get the remote interface. I get the normal gui interface. So >> how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', >> 'rc'] with executable set to 'vlc'. I've had shell=True, I've had >> shell=False. I've tried all these combinations. >> >> What am I doing wrong? >> >> -- >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > > -- > http://mail.python.org/mailman/listinfo/python-list > > From fabiofz at gmail.com Fri Jun 19 11:05:34 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 19 Jun 2009 12:05:34 -0300 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> Message-ID: On Fri, Jun 19, 2009 at 12:22 AM, Wei, Xiaohai wrote: > Thanks for your reply. > > where is the error log? I can not find it at /var/log Take a look at http://pydev.sourceforge.net/faq.html#how_do_i_report_a_bug (it gives the details on how to find the needed info). > I have a virtual network card to bridge kvm virtual machine. will it cause > problem? Not sure... What I know is that pydev creates a shell and connects to it through 127.0.0.1, so, if that fails, that could be a problem. > as you said configuration of interpretor, how should I configure the > interpretor? Please follow the getting started tutorial for that: http://fabioz.com/pydev/manual_101_root.html Cheers, Fabio > > Thanks > > James > > On Fri, Jun 19, 2009 at 9:32 AM, Fabio Zadrozny wrote: >> >> > yes, the same problem even on an empty program. every file has the same >> > problem. >> > >> > for example, if I new a file and input the following: >> > import os >> > os. >> > after I input '.', it will pop up the window, and i can select the >> > function >> > of os module or continue input. but after that, no action can be taken >> > for >> > this file unless I switch to other files and then switch back. >> >> If it's in pydev, there's probably some problem in your interpreter >> configuration (when you do os. it'll spawn a shell to gather the >> completions -- but that should be pretty quick unless you have some >> firewall that's preventing the communication or the spawn didn't go >> well -- check your error log to see if you have any errors... In linux >> I've seen some problems when connecting to 127.0.0.1 while having ipv6 >> enabled or in a network card misconfiguration that could cause >> problems too). >> >> Cheers, >> >> Fabio >> >> >> > >> > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing >> > wrote: >> >> >> >> Do you experience the same problem even on an empty program file or is >> >> it >> >> limited to just one file? >> >> >> >> -Tyler >> >> >> >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: >> >>> >> >>> On Jun 18, 10:45?am, "Wei, James" wrote: >> >>> > When I am editing python program with SPE, I found that SPE will >> >>> > freeze when it is doing auto-completion. The behavior is very >> >>> > strange >> >>> > that I can not edit the file again. If I switch to another file and >> >>> > then switch back, I can edit it again. >> >>> > >> >>> > So I switch to eclipse+pydev, but I found the same thing happen. So >> >>> > I >> >>> > think it is not the problem of SPE or eclipse or pydev. >> >>> > >> >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it >> >>> > will >> >>> > not freeze any longer. >> >>> > >> >>> > Anybody can give me some hints? >> >>> > >> >>> > I am using Ubuntu 8.10 and updated to latest. All packages is >> >>> > installed through package manager. >> >>> >> >>> the only thing I googled related with it is >> >>> >> >>> >> >>> >> >>> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >> >>> >> >>> but I think they are different. >> >>> >> >>> -- >> >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> >> >> >> -- >> >> Visit my blog at http://oddco.ca/zeroth/zblog >> > >> > >> > >> > -- >> > Best wishes to you. >> > >> > Yours sincerely >> > >> > Xiaohai Wei >> > wistoch at ustc.edu >> > >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> > > > > > -- > Best wishes to you. > > Yours sincerely > > Xiaohai Wei > wistoch at ustc.edu > From mk.fraggod at gmail.com Fri Jun 19 11:07:11 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:07:11 +0600 Subject: Retrieving column values by column name with MySQLdb References: Message-ID: <20090619210711.6a88ce7a@coercion> On Fri, 19 Jun 2009 15:46:46 +0100 jorma kala wrote: > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? Try this: db = MySQLdb.Connection(host=host,user=user,passwd=passwd,db=database) db.query(query) result = db.store_result() data = result.fetch_row(maxrows=0, how=1) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From trinioler at gmail.com Fri Jun 19 11:07:29 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 08:07:29 -0700 Subject: Calling subprocess with arguments In-Reply-To: References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> I can't use communicate, as it waits for the child process to terminate. Basically it blocks. I'm trying to have dynamic communication between the python program, and vlc. On Fri, Jun 19, 2009 at 8:05 AM, Charles Yeomans wrote: > > On Jun 19, 2009, at 10:55 AM, Tyler Laing wrote: > > So no one has an answer for why passing flags and the values the flags need > through subprocess does not work? I would like an answer. I've examined all > the examples I could find online, which were all toy examples, and not > helpful to my problem. > > On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: > >> I've been trying any variation I can think of to do this properly, but >> here's my problem: >> >> I want to execute this command string: vlc -I rc >> >> This allows vlc to be controlled via a remote interface instead of the >> normal gui interface. >> >> Now, say, I try this from subprocess: >> >> >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, >> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >> But I don't get the remote interface. I get the normal gui interface. So >> how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', >> 'rc'] with executable set to 'vlc'. I've had shell=True, I've had >> shell=False. I've tried all these combinations. >> >> What am I doing wrong? >> > > You might try > > p = subprocess.Popen('vlc -I rc test.avi', ... > > Charles Yeomans > > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From mk.fraggod at gmail.com Fri Jun 19 11:13:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:13:55 +0600 Subject: Calling subprocess with arguments References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: <20090619211355.4491c5e8@coercion> On Fri, 19 Jun 2009 07:55:19 -0700 Tyler Laing wrote: > I want to execute this command string: vlc -I rc > > This allows vlc to be controlled via a remote interface instead of the > normal gui interface. > > Now, say, I try this from subprocess: > > >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, > stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > But I don't get the remote interface. I get the normal gui interface. So > how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', > 'rc'] with executable set to 'vlc'. I've had shell=True, I've had > shell=False. I've tried all these combinations. > > What am I doing wrong? Write a simple script: #!/usr/bin/env python import sys open('/tmp/argv', 'w').write(repr(sys.argv)) And replace 'vlc' with a path to this script, then invoke it from a shell, compare the results. If it gets the right stuff, try the same with os.environ (prehaps vlc keeps socket location there, just like ssh/gpg-agents?). -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From mk.fraggod at gmail.com Fri Jun 19 11:21:42 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:21:42 +0600 Subject: Calling subprocess with arguments References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> Message-ID: <20090619212142.0cfd88db@coercion> On Fri, 19 Jun 2009 08:07:29 -0700 Tyler Laing wrote: > I can't use communicate, as it waits for the child process to terminate. > Basically it blocks. I'm trying to have dynamic communication between the > python program, and vlc. Unfortunately, subprocess module doesn't allow it out-of-the-box, but you can use fnctl calls to perform non-blocking reads/writes on it's pipes, like this: flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) After that, you can grab all the available data from the pipe at any given time w/o blocking. Try this recipe: http://code.activestate.com/recipes/576759/ -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From ethan at stoneleaf.us Fri Jun 19 11:24:05 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 19 Jun 2009 08:24:05 -0700 Subject: fastest native python database? In-Reply-To: <4A3AF9F0.7000009@stoneleaf.us> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> <4A3AF9F0.7000009@stoneleaf.us> Message-ID: <4A3BAD95.1020805@stoneleaf.us> Ethan Furman wrote: > This body part will be downloaded on demand. > Not sure what happened there... here's the text... Howdy, Pierre! I have also written a pure Python implementation of a database, one that uses dBase III or VFP 6 .dbf files. Any chance you could throw it into the mix to see how quickly (or slowly!) it runs? The code to run the same steps are (after an import dbf): #insert test table = dbf.Table('/tmp/tmptable', 'a N(6.0), b N(6.0), c C(100)') # if recs is list of tuples for rec in recs: table.append(rec) # elif recs is list of lists #for a, b, c in recs: # current = table.append() # current.a = a # current.b = b # current.c = c #select1 test for i in range(100): nb = len(table) if nb: avg = sum([record.b for record in table])/nb #select2 test for num_string in num_strings: records = table.find({'c':'%s'%num_string}, contained=True) nb = len(records) if nb: avg = sum([record.b for record in records])/nb #delete1 test for record in table: if 'fifty' in record.c: record.delete_record() # to purge the records would then require a table.pack() #delete2 test for rec in table: if 10 < rec.a < 20000: rec.delete_record() # again, permanent deletion requires a table.pack() #update1 test table.order('a') for i in range(100): # update description says 1000, update code is 100 records = table.query(python='10*%d <= a < 10*%d' %(10*i,10*(i+1))) for rec in records: rec.b *= 2 #update2 test records = table.query(python="0 <= a < 1000") for rec in records: rec.c = new_c[rec.a] Thanks, I hope! :) ~Ethan~ http://groups.google.com/group/python-dbase From Olivier.Darge at gmail.com Fri Jun 19 11:24:39 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 08:24:39 -0700 (PDT) Subject: multiprocessing and process run time References: Message-ID: On 19 juin, 16:40, Thomas Robitaille wrote: > Hi, > > I'm making use of the multiprocessing module, and I was wondering if there > is an easy way to find out how long a given process has been running for. > For example, if I do > > import multiprocessing as mp > import time > > def time_waster(): > ? ? time.sleep(1000) > > p = mp.Process(target=time_waster) > > p.start() > > Is there a way that I can then find how long p has been running for? I > figured I can use p.pid to get the PID of the process, but I'm not sure > where to go from there. Is there an easy way to do this? Something like : import multiprocessing as mp import time q_out = mp.Queue() def time_waster(qo): time.sleep(5) qo.put('stopped at ' + time.ctime(time.time())) def main(): p = mp.Process(target=time_waster, args=(q_out,)) print "start at: " + time.ctime(time.time()) p.start() p.join() print q_out.get() if __name__ == "__main__": main() The Queue (the one from multiprocessing ! don't mix with the Queue module) is used as a safe exchange object between the parent and all the child. Olivier From kushal.kumaran+python at gmail.com Fri Jun 19 11:25:51 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 19 Jun 2009 20:55:51 +0530 Subject: Retrieving column values by column name with MySQLdb In-Reply-To: References: Message-ID: <1e364c4e0906190825xf3e711ficca5efd715b7d789@mail.gmail.com> On Fri, Jun 19, 2009 at 8:16 PM, jorma kala wrote: > Hi, > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? > Code Snippet: > > ???? query="select * from employees" > ???? db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) > ???? cursor = db.cursor () > ???? cursor.execute (query) > ???? rows = cursor.fetchall () > > ??????for row in rows: > ?????????????? print row[0] > > > Instead of specifying the index of the row to retrieve the first column > (row[0]), I'd like to retrieve the value of the first column by column name. > Something like row.get('employee_id') > Is something of the sort possible with Mysqdb? > Thanks very much. > Use a DictCursor: import MySQLdb.cursors . . . cursor = db.cursor (MySQLdb.cursors.DictCursor) cursor.execute (query) rows = cursor.fetchall () for row in rows: print row['employee_id'] -- kushal From trinioler at gmail.com Fri Jun 19 11:28:17 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 08:28:17 -0700 Subject: Calling subprocess with arguments In-Reply-To: <20090619212142.0cfd88db@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> Message-ID: <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> Thanks mike, the idea that maybe some of the info isn't being passed is certainly interesting. Here's the output of os.environ and sys.argv: tyler at Surak:~$ cat environ {'XAUTHORITY': '/home/tyler/.Xauthority', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'ORBIT_SOCKETDIR': '/tmp/orbit-tyler', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'tyler', 'USER': 'tyler', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games', 'HOME': '/home/tyler', 'WINDOWPATH': '7', 'SSH_AGENT_PID': '3235', 'LANG': 'en_CA.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': 'c40b96e13a53e01daf91b3c24a37cc3f-1245418411.623618-1455422513', 'SESSION_MANAGER': 'local/Surak:/tmp/.ICE-unix/3078', 'SHLVL': '1', 'DISPLAY': ':0.0', 'WINDOWID': '62914615', 'COLUMNS': '80', 'GPG_AGENT_INFO': '/tmp/seahorse-WkObD8/S.gpg-agent:3260:1', 'USERNAME': 'tyler', 'GDM_XSERVER_LOCATION': 'local', 'GTK_RC_FILES': '/etc/gtk/gtkrc:/home/tyler/.gtkrc-1.2-gnome2', 'LINES': '24', 'SSH_AUTH_SOCK': '/tmp/keyring-glzV2L/socket.ssh', 'DESKTOP_SESSION': 'default', 'GDMSESSION': 'default', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-HXzG5Pt75p,guid=9fc00f8a914d6f800340ca634a3b93ac', '_': '/usr/bin/python', 'GTK_MODULES': 'canberra-gtk-module', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-glzV2L/socket', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GNOME_KEYRING_PID': '3065', '__GL_YIELD': 'NOTHING', 'GDM_LANG': 'en_CA.UTF-8', 'HISTCONTROL': 'ignoreboth', 'XDG_DATA_DIRS': '/usr/local/share/:/usr/share/:/usr/share/gdm/', 'PWD': '/home/tyler', 'COLORTERM': 'gnome-terminal', 'FROM_WRAPPER': 'yes', 'LS_COLORS': 'no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'} tyler at Surak:~$ cat argv ['./testsub.py', '-I', 'rc'] On Fri, Jun 19, 2009 at 8:21 AM, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 08:07:29 -0700 > Tyler Laing wrote: > > > I can't use communicate, as it waits for the child process to terminate. > > Basically it blocks. I'm trying to have dynamic communication between the > > python program, and vlc. > > Unfortunately, subprocess module doesn't allow it out-of-the-box, but > you can use fnctl calls to perform non-blocking reads/writes on it's > pipes, like this: > > flags = fcntl.fcntl(fd, fcntl.F_GETFL) > fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) > > After that, you can grab all the available data from the pipe at any > given time w/o blocking. > > Try this recipe: > > http://code.activestate.com/recipes/576759/ > > -- > Mike Kazantsev // fraggod.net > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jun 19 11:30:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Jun 2009 08:30:31 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: <4A37BD14.5010807@arimaz.com> Message-ID: On Jun 19, 8:20?pm, Gerhard H?ring wrote: > Gabriel Rossetti wrote: > > Hello everyone, > > > I get an OperationalError with sqlite3 if I put the wrong column name, > > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > > says : > > > " ? ? ? ?OperationalError > > ? ? ? ? ? ? ? ? ? ?Exception raised for errors that are related to the > > ? ? ? ? ? ?database's operation and not necessarily under the control > > ? ? ? ? ? ?of the programmer, e.g. an unexpected disconnect occurs, > > ? ? ? ? ? ?the data source name is not found, a transaction could not > > ? ? ? ? ? ?be processed, a memory allocation error occurred during > > ? ? ? ? ? ?processing, etc. ?It must be a subclass of DatabaseError. > > ? ? ? ? ? ? ? ? ?ProgrammingError > > ? ? ? ? ? ? ? ? ? ?Exception raised for programming errors, e.g. table not > > ? ? ? ? ? ?found or already exists, syntax error in the SQL > > ? ? ? ? ? ?statement, wrong number of parameters specified, etc. ?It > > ? ? ? ? ? ?must be a subclass of DatabaseError. > > " > > > and to me it sounds more like a programming error than an operational > > error. > > I agree. But I can't help you there. > > See _pysqlite_seterror() athttp://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c > > What I do is map SQLite error codes to DB-API exceptions. And SQLite > reports your error as generic SQLITE_ERROR, which is mapped to > OperationalError. Hi Gerhard, In http://www.sqlite.org/c3ref/prepare.html it says """When an error occurs, sqlite3_step() will return one of the detailed error codes or extended error codes. The legacy behavior was that sqlite3_step() would only return a generic SQLITE_ERROR result code and you would have to make a second call to sqlite3_reset() in order to find the underlying cause of the problem. With the "v2" prepare interfaces, the underlying reason for the error is returned immediately.""" Are you using sqlite3_prepare() or sqlite3_prepare_v2()? sqlite3_errcode() or sqlite3_extended_errcode()? Cheers, John From python.list at tim.thechases.com Fri Jun 19 11:32:32 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 19 Jun 2009 10:32:32 -0500 Subject: Retrieving column values by column name with MySQLdb In-Reply-To: References: Message-ID: <4A3BAF90.7020909@tim.thechases.com> jorma kala wrote: > Hi, > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? > Code Snippet: > > query="select * from employees" > db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) > cursor = db.cursor () > cursor.execute (query) > rows = cursor.fetchall () > > for row in rows: > print row[0] > > > Instead of specifying the index of the row to retrieve the first column > (row[0]), I'd like to retrieve the value of the first column by column name. > Something like row.get('employee_id') > Is something of the sort possible with Mysqdb? Mike gave you a good answer, though I think it's MySQL specific. For a more generic solution: cursor.execute(query) name_to_index = dict( (d[0], i) for i, d in enumerate(cursor.description) ) rows = cursor.fetchall() for row in rows: print row[name_to_index['employee_id']] Or in case you have lots of column-names, a simple lambda can ease the typing required: for row in rows: item = lambda col_name: row[name_to_index[col_name]] print item('employee_id') The built-in sqlite3 module also has a way to tell results to come back as a dict[1] Note in each case the column-name indexing is case-sensitive. Hope this helps, -tim [1] http://docs.python.org/library/sqlite3.html#sqlite3.Connection.row_factory From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 11:38:46 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 17:38:46 +0200 Subject: Decorator question (how to test if decorated function is in a class) In-Reply-To: References: Message-ID: <4a3bb0ee$0$3613$426a74cc@news.free.fr> Martin P. Hellwig a ?crit : > Hi all, > > I have been trying out to wrap my mind around the advantages of > decorators and thought I found a use in one of my experiments. (see code > after my sig). > > Although it works, I think it should be able to do it better. > My particular problem is that I want to remove an argument (say always > the first one) when the decorated function is called. > > However if the function is defined in a class the first argument is self > and thus the second argument should be removed. You'll have the same problem with a function defined outside a class then "attached" to the class, ie: def func(...): pass class Foo(object): pass Foo.meth = func > Since I like to have a more general DRY approach I want to test if the > decorated function is defined in a class or not thus knowing that the > first argument is self and must be preserved. Short answer: this makes no sense. > I tried different approaches but all didn't work and looked very > unpythonic (looking at the attributes, descriptors namespaces, id() of > the function, the first argument and the decorator itself). > > So is there a way to find out if the first argument is 'self' without > making a false positive if the first argument is a class instance passed > to a function? The solution to your problem is elsewhere... Read the doc about the descriptor protocol, and how it's implemented by the function type to "turn" functions into methods when they are looked up as attribute of a class... From mk.fraggod at gmail.com Fri Jun 19 11:47:52 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:47:52 +0600 Subject: Retrieving column values by column name with MySQLdb References: <4A3BAF90.7020909@tim.thechases.com> Message-ID: <20090619214752.2e84e737@coercion> On Fri, 19 Jun 2009 10:32:32 -0500 Tim Chase wrote: > Mike gave you a good answer, though I think it's MySQL specific. I don't have to deal with MySQL frequently but I've remembered that I used got the fields out somehow, and now, looking at the code, I wonder myself, why "how" is 1 and wtf is this "how", anyway!? ;) I can't seem to find any mention of such methods in documentation and even python source, guess they are implemented directly in underlying C lib. Hope I learned to abstract from such syntax since then, I sure do... -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From stefan_ml at behnel.de Fri Jun 19 11:54:32 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Jun 2009 17:54:32 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. You might want to read about "The Problem with Threads": http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf and then decide to switch to an appropriate concurrency model for your use case. Stefan From tjreedy at udel.edu Fri Jun 19 11:58:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 11:58:15 -0400 Subject: Is this pylint error message valid or silly? In-Reply-To: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> References: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> Message-ID: Matthew Wilson wrote: > Thanks for the feedback. I think I should have used a more obvious > string in my original example and a more descriptive parameter name. > > So, pretend that instead of > > c="today" > > I wrote > > record_date="defaults to today's date". > > I know my way is unorthodox, Which is fine. Just do not by surprised when a fake default fakes out pylint, which by its nature, must embody the orthodoxy of its author ;-) To win general acceptance, that in turn must match the orthodoxy of the general audience. but I think it is a little bit more obvious > to the reader than > > record_date=None > > The None is a signal to use a default value, but that is only apparent > after reading the code. > > Thanks again for the comments. > > Matt From mk.fraggod at gmail.com Fri Jun 19 12:00:28 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:00:28 +0600 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> Message-ID: <20090619220028.201b1484@coercion> On Fri, 19 Jun 2009 08:28:17 -0700 Tyler Laing wrote: > Thanks mike, the idea that maybe some of the info isn't being passed is > certainly interesting. > > Here's the output of os.environ and sys.argv: > ... I'm afraid these doesn't make much sense without the output from the second results, from py itself. My suggestion was just to compare them - pop the py shell, eval the outputs into two sets, do the diff and you'll see it at once. If there's an empty set then I guess it's pretty safe to assume that python creates subprocess in the same way the shell does. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From tjreedy at udel.edu Fri Jun 19 12:01:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 12:01:52 -0400 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 > > In what simple way can I get just 0.04 ? Short answer: use 3.1: >>> 1//25 0 >>> 1/25 0.04 ;-) But you should really try to understand the answers others gave. tjr From mk.fraggod at gmail.com Fri Jun 19 12:09:20 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:09:20 +0600 Subject: Calling subprocess with arguments In-Reply-To: <20090619220028.201b1484@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> Message-ID: <20090619220920.3aa68630@coercion> On Fri, 19 Jun 2009 22:00:28 +0600 Mike Kazantsev wrote: > On Fri, 19 Jun 2009 08:28:17 -0700 > Tyler Laing wrote: > > > Thanks mike, the idea that maybe some of the info isn't being passed is > > certainly interesting. > > > > Here's the output of os.environ and sys.argv: > > > ... > > I'm afraid these doesn't make much sense without the output from the > second results, from py itself. My suggestion was just to compare them > - pop the py shell, eval the outputs into two sets, do the diff and > you'll see it at once. > If there's an empty set then I guess it's pretty safe to assume that > python creates subprocess in the same way the shell does. Just thought of one more really simple thing I've missed: vlc might expect it's remote to work with tty, so when py shoves it a pipe instead, it automatically switches to non-interactive mode. You can remedy that a bit by superclassing subprocess.Popen, replacing pipes with pty, but they are quite hard to work with, prehaps pexpect module would be of some use there: http://pypi.python.org/pypi/pexpect/ -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From tjreedy at udel.edu Fri Jun 19 12:15:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 12:15:02 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. Python does not have (or not have) GIL. It is an implementation issue. CPython uses it, to good effect. > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? Use one of the other implementations. Jython, IronPython, Pypy, ??? From wells at submute.net Fri Jun 19 12:16:38 2009 From: wells at submute.net (Wells Oliver) Date: Fri, 19 Jun 2009 11:16:38 -0500 Subject: n00b confusion re: local variable referenced before assignment error Message-ID: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Writing a class which essentially spiders a site and saves the files locally. On a URLError exception, it sleeps for a second and tries again (on 404 it just moves on). The relevant bit of code, including the offending method: class Handler(threading.Thread): def __init__(self, url): threading.Thread.__init__(self) self.url = url def save(self, uri, location): try: handler = urllib2.urlopen(uri) except urllib2.HTTPError, e: if e.code == 404: return else: print "retrying %s (HTTPError)" % uri time.sleep(1) self.save(uri, location) except urllib2.URLError, e: print "retrying %s" % uri time.sleep(1) self.save(uri, location) if not os.path.exists(os.path.dirname(location)): os.makedirs(os.path.dirname(location)) file = open(location, "w") file.write(handler.read()) file.close() ... But what I am seeing is that after a retry (on catching a URLError exception), I see bunches of "UnboundLocalError: local variable 'handler' referenced before assignment" errors on line 38, which is the "file.write(handler.read())" line.. What gives? -- Wells Oliver wells at submute.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From garrickp at gmail.com Fri Jun 19 12:30:09 2009 From: garrickp at gmail.com (Falcolas) Date: Fri, 19 Jun 2009 09:30:09 -0700 (PDT) Subject: n00b confusion re: local variable referenced before assignment error References: Message-ID: <3d6cac13-48c9-4592-86c3-c4019386e460@j12g2000vbl.googlegroups.com> On Jun 19, 10:16?am, Wells Oliver wrote: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again (on > 404 it just moves on). The relevant bit of code, including the offending > method: > > [snip] > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? 'Handler' is only assigned in the try statement, so if you error into your exception clause, nothing will have been bound to the name 'handler', causing the exception you're seeing. From trinioler at gmail.com Fri Jun 19 12:30:48 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 09:30:48 -0700 Subject: Calling subprocess with arguments In-Reply-To: <20090619220920.3aa68630@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> <20090619220920.3aa68630@coercion> Message-ID: <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> Sorry, XD. I'll ask the VLC people if they happen to know why VLC won't open up the remote interface. -Tyler On Fri, Jun 19, 2009 at 9:09 AM, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 22:00:28 +0600 > Mike Kazantsev wrote: > > > On Fri, 19 Jun 2009 08:28:17 -0700 > > Tyler Laing wrote: > > > > > Thanks mike, the idea that maybe some of the info isn't being passed is > > > certainly interesting. > > > > > > Here's the output of os.environ and sys.argv: > > > > > ... > > > > I'm afraid these doesn't make much sense without the output from the > > second results, from py itself. My suggestion was just to compare them > > - pop the py shell, eval the outputs into two sets, do the diff and > > you'll see it at once. > > If there's an empty set then I guess it's pretty safe to assume that > > python creates subprocess in the same way the shell does. > > Just thought of one more really simple thing I've missed: vlc might > expect it's remote to work with tty, so when py shoves it a pipe > instead, it automatically switches to non-interactive mode. > > You can remedy that a bit by superclassing subprocess.Popen, replacing > pipes with pty, but they are quite hard to work with, prehaps pexpect > module would be of some use there: > > http://pypi.python.org/pypi/pexpect/ > > -- > Mike Kazantsev // fraggod.net > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Jun 19 12:30:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 19 Jun 2009 18:30:48 +0200 Subject: n00b confusion re: local variable referenced before assignment error In-Reply-To: References: Message-ID: <7a1spoF1t7fovU1@mid.uni-berlin.de> Wells Oliver schrieb: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again > (on 404 it just moves on). The relevant bit of code, including the > offending method: > > class Handler(threading.Thread): > def __init__(self, url): > threading.Thread.__init__(self) > self.url = url > > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > > ... > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable > 'handler' referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. Your code defines the name handler only if the urllib2.urlopen is successful. But you try later to access it uncoditionally, and of course that fails. You need to put the file-stuff after the urlopen, inside the try-except. Also note that python has no tail-recursion-optimization, so your method will recurse and at some point exhaust the stack if there are many errors. You should consider writing it rather as while-loop, with breaking out of it when the page could be fetched. Diez From mk.fraggod at gmail.com Fri Jun 19 12:36:38 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:36:38 +0600 Subject: n00b confusion re: local variable referenced before assignment error References: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Message-ID: <20090619223638.331fea20@coercion> On Fri, 19 Jun 2009 11:16:38 -0500 Wells Oliver wrote: > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? Why not? Try fails, except calls retry and after the retry code execution continues to the undefined "handler", since the try has failed here. You might want to insert return or avoid (possibly endless) recursion altogether - just wrap it into while loop with some counter (aka max_tries). Also, you can get rid of code duplication by catching some basic urllib2 exception, then checking if it's urllib2.HTTPError and it's code is 404, retrying ("continue" for the loop case) otherwise. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From trinioler at gmail.com Fri Jun 19 12:37:50 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 09:37:50 -0700 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> <20090619220920.3aa68630@coercion> <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> Message-ID: <3618a6e10906190937wb89ed9es93f0cad4ab1d9a3d@mail.gmail.com> It appears to be an issue specifically with VLC, not subprocess. Thank you guys. The remote interface works through sockets, which is perfectly fine... if I create a local socket, I can have it connect to the socket with command line arguments. On Fri, Jun 19, 2009 at 9:30 AM, Tyler Laing wrote: > Sorry, XD. I'll ask the VLC people if they happen to know why VLC won't > open up the remote interface. > > -Tyler > > On Fri, Jun 19, 2009 at 9:09 AM, Mike Kazantsev wrote: > >> On Fri, 19 Jun 2009 22:00:28 +0600 >> Mike Kazantsev wrote: >> >> > On Fri, 19 Jun 2009 08:28:17 -0700 >> > Tyler Laing wrote: >> > >> > > Thanks mike, the idea that maybe some of the info isn't being passed >> is >> > > certainly interesting. >> > > >> > > Here's the output of os.environ and sys.argv: >> > > >> > ... >> > >> > I'm afraid these doesn't make much sense without the output from the >> > second results, from py itself. My suggestion was just to compare them >> > - pop the py shell, eval the outputs into two sets, do the diff and >> > you'll see it at once. >> > If there's an empty set then I guess it's pretty safe to assume that >> > python creates subprocess in the same way the shell does. >> >> Just thought of one more really simple thing I've missed: vlc might >> expect it's remote to work with tty, so when py shoves it a pipe >> instead, it automatically switches to non-interactive mode. >> >> You can remedy that a bit by superclassing subprocess.Popen, replacing >> pipes with pty, but they are quite hard to work with, prehaps pexpect >> module would be of some use there: >> >> http://pypi.python.org/pypi/pexpect/ >> >> -- >> Mike Kazantsev // fraggod.net >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From Olivier.Darge at gmail.com Fri Jun 19 12:50:43 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 09:50:43 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 16:16, Martin von Loewis If you know that your (C) code is thread safe on its own, you can > release the GIL around long-running algorithms, thus using as many > CPUs as you have available, in a single process. what do you mean ? Cpython can't benefit from multi-core without multiple processes. Olivier From trinioler at gmail.com Fri Jun 19 13:05:10 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 10:05:10 -0700 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3618a6e10906191005i580eec03sd7be3a7a1ab6ba96@mail.gmail.com> CPython itself can't... but the c extension can. Mine did. On Fri, Jun 19, 2009 at 9:50 AM, OdarR wrote: > On 19 juin, 16:16, Martin von Loewis > If you know that your (C) code is thread safe on its own, you can > > release the GIL around long-running algorithms, thus using as many > > CPUs as you have available, in a single process. > > what do you mean ? > > Cpython can't benefit from multi-core without multiple processes. > > Olivier > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Fri Jun 19 13:13:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 19 Jun 2009 12:13:12 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <19003.50984.827956.602333@montanaro.dyndns.org> >> If you know that your (C) code is thread safe on its own, you can >> release the GIL around long-running algorithms, thus using as many >> CPUs as you have available, in a single process. Olivier> what do you mean ? Olivier> Cpython can't benefit from multi-core without multiple Olivier> processes. It can, precisely as Martin indicated. Only one thread at a time can hold the GIL. That doesn't mean that multiple threads can't execute. Suppose you have two threads, one of which winds up executing some bit of C code which doesn't mess with the Python run-time at all (say, a matrix multiply). Before launching into the matrix multiply, the extension module releases the GIL then performs the multiply. With the GIL released another thread can acquire it. Once the multiply finishes the first thread needs to reacquire the GIL before executing any calls into the Python runtime or returning. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From Olivier.Darge at gmail.com Fri Jun 19 14:08:31 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 11:08:31 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 19:13, s... at pobox.com wrote: > ? ? Olivier> what do you mean ? > > ? ? Olivier> Cpython can't benefit from multi-core without multiple > ? ? Olivier> processes. > > It can, precisely as Martin indicated. ?Only one thread at a time can hold > the GIL. ?That doesn't mean that multiple threads can't execute. ?Suppose I don't say multiple threads can't execute....(?). I say that with the Python library, I don't see (yet) benefit with multiple threads *on* multiple CPU/core. Ever seen this recent video/presentation ? : http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf > you have two threads, one of which winds up executing some bit of C code > which doesn't mess with the Python run-time at all (say, a matrix multiply). I don't know how to do that with common Python operations... Only one thread will be really running at a time in memory (meanwhile other thread are waiting). Are you refering to a specialized code ? > Before launching into the matrix multiply, the extension module releases the > GIL then performs the multiply. ?With the GIL released another thread can > acquire it. ?Once the multiply finishes the first thread needs to reacquire > the GIL before executing any calls into the Python runtime or returning. I don't see such improvement in the Python library, or maybe you can indicate us some meaningfull example...? I currently only use CPython, with PIL, Reportlab...etc. I don't see improvement on a Core2duo CPU and Python. How to proceed (following what you wrote) ? A contrario, I saw *real* improvement on parallel computing with the Py 2.6 multiprocessing module. Olivier From amita.ekbote at gmail.com Fri Jun 19 14:17:24 2009 From: amita.ekbote at gmail.com (Amita Ekbote) Date: Fri, 19 Jun 2009 13:17:24 -0500 Subject: Convert hash to struct Message-ID: Hello, I am retrieving values from a database in the form of a dictionary so I can access the values as d['column'] and I was wondering if there is a way to convert the hash to a struct like format so i can just say d.column. Makes it easier to read and understand. Thanks Amita -- Amita Ekbote From lie.1296 at gmail.com Fri Jun 19 14:42:49 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 18:42:49 GMT Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: Lawrence D'Oliveiro wrote: > In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan > wrote: > >> Yeah, it might be possible to just mv the file from outside, but not >> being able to enter a directory just because you've got too many files >> in it is kind of silly. > > Sounds like a problem with your file/directory-manipulation tools. > try an `ls` on a folder with 10000+ files. See how long is needed to print all the files. Ok, now pipe ls to less, take three days to browse through all the filenames to locate the file you want to see. The file manipulation tool may not have problems with it; it's the user that would have a hard time sorting through the huge amount of files. Even with glob and grep, some types of queries are just too difficult or is plain silly to write a full fledged one-time use program just to locate a few files. From ullrich at math.okstate.edu Fri Jun 19 14:43:11 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Fri, 19 Jun 2009 13:43:11 -0500 Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: Evidently my posts are appearing, since I see replies. I guess the question of why I don't see the posts themselves \is ot here... On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson wrote: >On Jun 18, 7:26?pm, David C. Ullrich wrote: >> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >> >Right. ?Or rather, you treat it as the image of such a function, >> >if you're being careful to distinguish the curve (a subset >> >of R^2) from its parametrization (a continuous function >> >R -> R**2). ?It's the parametrization that's uniformly >> >continuous, not the curve, >> >> Again, it doesn't really matter, but since you use the phrase >> "if you're being careful": In fact what you say is exactly >> backwards - if you're being careful that subset of the plane >> is _not_ a curve (it's sometimes called the "trace" of the curve". > >Darn. So I've been getting it wrong all this time. Oh well, >at least I'm not alone: > >"De?nition 1. A simple closed curve J, also called a >Jordan curve, is the image of a continuous one-to-one >function from R/Z to R2. [...]" > >- Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. > >"We say that Gamma is a curve if it is the image in >the plane or in space of an interval [a, b] of real >numbers of a continuous function gamma." > >- Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). > >Perhaps your definition of curve isn't as universal or >'official' as you seem to think it is? Perhaps not. I'm very surprised to see those definitions; I've been a mathematician for 25 years and I've never seen a curve defined a subset of the plane. Hmm. You left out a bit in the first definition you cite: "A simple closed curve J, also called a Jordan curve, is the image of a continuous one-to-one function from R/Z to R2. We assume that each curve comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z the time parameter. By abuse of notation, we write J(t) in R2 instead of phi_j (t), using the same notation for the function phi_J and its image J." Close to sounding like he can't decide whether J is a set or a function... Then later in the same paper "Definition 2. A polygon is a Jordan curve that is a subset of a finite union of lines. A polygonal path is a continuous function P : [0, 1] ->? R2 that is a subset of a finite union of lines. It is a polygonal arc, if it is 1 . 1." By that definition a polygonal path is not a curve. Worse: A polygonal path is a function from [0,1] to R^2 _that is a subset of a finite union of lines_. There's no such thing - the _image_ of such a function can be a subset of a finite union of lines. Not that it matters, but his defintion of "polygonal path" is, _if_ we're being very careful, self-contradictory. So I don't think we can count that paper as a suitable reference for what the _standard_ definitions are; the standard definitions are not self-contradictory this way. Then the second definition you cite: Amazon says the prerequisites are two years of calculus. The stanard meaning of log is log base e, even though it means log base 10 in calculus. >Mark From darcy at druid.net Fri Jun 19 14:49:09 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Jun 2009 14:49:09 -0400 Subject: Convert hash to struct In-Reply-To: References: Message-ID: <20090619144909.94a9a127.darcy@druid.net> On Fri, 19 Jun 2009 13:17:24 -0500 Amita Ekbote wrote: > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. Are there enough clues here? class MyDict(dict): def __getattribute__(self, name): return dict.__getattribute__(self, name) def __getattr__(self, name): return self.get(name, 42) x = MyDict({'a': 1, 'b': 2, 'values': 3}) print x.a print x.z print x.values Big question - what should the last line display? If you expect "3" and not "" then you need to reconsider the above implementation. Thinking about the question may change your opinion about this being a good idea after all. -- 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 lie.1296 at gmail.com Fri Jun 19 14:52:34 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 18:52:34 GMT Subject: Convert hash to struct In-Reply-To: References: Message-ID: Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > You may be able to update the class' dict: >>> class MyDB(object): ... def __init__(self, di): ... self.__dict__.update(di) ... >>> di = {'a':10, 'b': 20} >>> d = MyDB(di) >>> d <__main__.MyDB object at 0x7f756b0d0b90> >>> d.a 10 >>> d.b 20 but this might be a security risk, if you cannot trust the database or its content. It is much preferrable to use something like: >>> class MyDB(object): ... def __init__(self, di): ... self.a = di['a'] ... self.b = di['b'] since you now have full control of what collumns can go in and whatnot. From me at gustavonarea.net Fri Jun 19 15:02:44 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Fri, 19 Jun 2009 12:02:44 -0700 (PDT) Subject: Rich comparison methods don't work in sets? Message-ID: Hello, everyone. I've noticed that if I have a class with so-called "rich comparison" methods (__eq__, __ne__, etc.), when its instances are included in a set, set.__contains__/__eq__ won't call the .__eq__ method of the elements and thus the code below: """ obj1 = RichComparisonClass() obj2 = RichComparisonClass() set1 = set([obj1]) set2 = set([obj2]) if obj1 == obj2: print "Objects 1 and 2 are equivalent" else: print "Objects 1 and 2 aren't equivalent" if set1 == set2: print "Sets 1 and 2 are equivalent" else: print "Sets 1 and 2 aren't equivalent" """ Would output: """ Objects 1 and 2 are equivalent Sets 1 and 2 aren't equivalent """ instead of: """ Objects 1 and 2 are equivalent Sets 1 and 2 are equivalent """ How can I work around this? The only solution that comes to my mind is to write a function like this: """ def same_sets(set1, set2): if len(set1) != len(set2): return False for element1 in set1: found = False for element2 in set2: if element1 == element2: found = True break; if not found: return False return True """ But I see it pretty ugly; also I'd also have to roll out my own "contains" (e.g., `element in set`) function. I expect and hope there's a pythonic way to do this. Does it exist? Thanks in advance! From lists at cheimes.de Fri Jun 19 15:05:51 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 19 Jun 2009 21:05:51 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: OdarR wrote: > I don't see such improvement in the Python library, or maybe you can > indicate us some meaningfull example...? > > I currently only use CPython, with PIL, Reportlab...etc. > I don't see improvement on a Core2duo CPU and Python. How to proceed > (following what you wrote) ? I've seen a single Python process using the full capacity of up to 8 CPUs. The application is making heavy use of lxml for large XSL transformations, a database adapter and my own image processing library based upon FreeImage. Of course both lxml and my library are written with the GIL in mind. They release the GIL around every call to C libraries that don't touch Python objects. PIL releases the lock around ops as well (although it took me a while to figure it out because PIL uses its own API instead of the standard macros). reportlab has some optional C libraries that increase the speed, too. Are you using them? By the way threads are evil (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and not *the* answer to concurrency. Christian From pavlovevidence at gmail.com Fri Jun 19 15:08:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Jun 2009 12:08:55 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <6f90a341-c1a5-4fa7-9642-e48b3bf4f604@j12g2000vbl.googlegroups.com> On Jun 19, 6:53?am, Ben Charrow wrote: > Jure Erzno?nik wrote: > > See here for introduction: > >http://groups.google.si/group/comp.lang.python/browse_thread/thread/3... > > > Digging through my problem, I discovered Python isn't exactly thread > > safe and to solve the issue, there's this Global Interpreter Lock > > (GIL) in place. > > Effectively, this causes the interpreter to utilize one core when > > threading is not used and .95 of a core when threading is utilized. > > > Is there any work in progess on core Python modules that will > > permanently resolve this issue? > > Is there any other way to work around the issue aside from forking new > > processes or using something else? > > There is a group of people working on an alternative implementation to Python > that, among other things, will not have a GIL:http://code.google.com/p/unladen-swallow/ That's not a foregone conclusion. Well it's not a foregone conclusion that unladen-swallow will succeed at all, but even if it does they only say they intend to remove the GIL, not that they necessarily will. The GIL actually "solves" two problems: the overhead of synchronizing reference counts, and the difficulty of writing threaded extensions. The unladen-swallow team only address the first problem in their plans. So, even if they do remove the GIL, I doubt GvR will allow it to be merged back into CPython unless makes extensions are just as easy to write. That is something I have serious doubts they can pull off. Which means a GIL-less unladen-swallow is likely to end being another fork like IronPython and Jython. Those projects already have no GIL. Carl Banks From charles at declareSub.com Fri Jun 19 15:13:08 2009 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 19 Jun 2009 15:13:08 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: > Evidently my posts are appearing, since I see replies. > I guess the question of why I don't see the posts themselves > \is ot here... > > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson > wrote: > >> On Jun 18, 7:26 pm, David C. Ullrich >> wrote: >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >>>> Right. Or rather, you treat it as the image of such a function, >>>> if you're being careful to distinguish the curve (a subset >>>> of R^2) from its parametrization (a continuous function >>>> R -> R**2). It's the parametrization that's uniformly >>>> continuous, not the curve, >>> >>> Again, it doesn't really matter, but since you use the phrase >>> "if you're being careful": In fact what you say is exactly >>> backwards - if you're being careful that subset of the plane >>> is _not_ a curve (it's sometimes called the "trace" of the curve". >> >> Darn. So I've been getting it wrong all this time. Oh well, >> at least I'm not alone: >> >> "De?nition 1. A simple closed curve J, also called a >> Jordan curve, is the image of a continuous one-to-one >> function from R/Z to R2. [...]" >> >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. >> >> "We say that Gamma is a curve if it is the image in >> the plane or in space of an interval [a, b] of real >> numbers of a continuous function gamma." >> >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). >> >> Perhaps your definition of curve isn't as universal or >> 'official' as you seem to think it is? > > Perhaps not. I'm very surprised to see those definitions; I've > been a mathematician for 25 years and I've never seen a > curve defined a subset of the plane. I have. > > > Hmm. You left out a bit in the first definition you cite: > > "A simple closed curve J, also called a Jordan curve, is the image > of a continuous one-to-one function from R/Z to R2. We assume that > each curve > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z > the time > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j > (t), using the > same notation for the function phi_J and its image J." > > > Close to sounding like he can't decide whether J is a set or a > function... On the contrary, I find this definition to be written with some care. > Then later in the same paper > > "Definition 2. A polygon is a Jordan curve that is a subset of a > finite union of > lines. A polygonal path is a continuous function P : [0, 1] ->? R2 > that is a subset of > a finite union of lines. It is a polygonal arc, if it is 1 . 1." > These are a bit too casual for me as well... > > By that definition a polygonal path is not a curve. > > Worse: A polygonal path is a function from [0,1] to R^2 > _that is a subset of a finite union of lines_. There's no > such thing - the _image_ of such a function can be a > subset of a finite union of lines. > > Not that it matters, but his defintion of "polygonal path" > is, _if_ we're being very careful, self-contradictory. > So I don't think we can count that paper as a suitable > reference for what the _standard_ definitions are; > the standard definitions are not self-contradictory this way. Charles Yeomans From quarl at 8166.clguba.z.quarl.org Fri Jun 19 15:21:53 2009 From: quarl at 8166.clguba.z.quarl.org (Karl Chen) Date: Fri, 19 Jun 2009 15:21:53 -0400 Subject: timeit and __future__ Message-ID: I wanted to time something that uses with_statement, in python2.5. Importing __future__ in the statement or the setup doesn't work since it's not the beginning of the code being compiled. Other than using a separate module, I could only come up with this: timeit.template = 'from __future__ import with_statement\n' + timeit.template timeit should directly support importing __future__ stuff... From matt at tplus1.com Fri Jun 19 15:26:03 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 19:26:03 GMT Subject: Rich comparison methods don't work in sets? References: Message-ID: On Fri 19 Jun 2009 03:02:44 PM EDT, Gustavo Narea wrote: > Hello, everyone. > > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() > obj2 = RichComparisonClass() What does >>> obj1 is obj2 return? I don't know anything about set internals. Matt From sakradevanamindra at gmail.com Fri Jun 19 15:26:36 2009 From: sakradevanamindra at gmail.com (Leo Brugud) Date: Fri, 19 Jun 2009 12:26:36 -0700 (PDT) Subject: dynamically associate radio buttons with droplists Message-ID: Hi Folks, Not being very familiar with python, nor with cgi/http, I intend to have 3 of buttons in a webpage, each of them is associate with a file (so I have 3 files, too) What I would like to have is, when users choose a button, the droplist update automatically to load the contents of the associated file. Can someone educate me the approach of this? Thanks From davea at ieee.org Fri Jun 19 15:34:23 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 15:34:23 -0400 Subject: n00b confusion re: local variable referenced before assignment error In-Reply-To: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> References: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Message-ID: <4A3BE83F.8070004@ieee.org> Wells Oliver wrote: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again (on > 404 it just moves on). The relevant bit of code, including the offending > method: > > class Handler(threading.Thread): > def __init__(self, url): > threading.Thread.__init__(self) > self.url = url > > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > > ... > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? > > Your save() method is recursive in the case of that error, which is a poor excuse for what should have been a loop. You should have some retry depth check, just in case you get hundreds of such errors on the same site. But ignoring that issue, the specific symptom is caused when returning from the recursive call. You still fall through to the end of your outer method call, and try to write stuff from that handler (also wiping out the file "location" in the process). Without a handler, that causes an exception. So you should follow those calls to self.save() with return's. Much better would be to write a loop in the first place, and break out of the loop when you succeed. Then the flow is much easier to follow, and you can easily avoid the risk of looping forever, nor of running out of stack space. Something like (untested): def save(self, uri, location): for tries in xrange(10): #try up to 10 times try: handler = urllib2.urlopen(uri) except urllib2.HTTPError, e: if e.code == 404: break else: print "retrying %s (HTTPError)" % uri time.sleep(1) continue except urllib2.URLError, e: print "retrying %s" % uri time.sleep(1) continue if not os.path.exists(os.path.dirname(location)): os.makedirs(os.path.dirname(location)) file = open(location, "w") file.write(handler.read()) file.close() break Other refinements are possible, of course. For example, if you have any cleanup code at the end you may need an additional flag variable to tell whether you've succeeded or not. From __peter__ at web.de Fri Jun 19 15:37:17 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Jun 2009 21:37:17 +0200 Subject: Rich comparison methods don't work in sets? References: Message-ID: Gustavo Narea wrote: > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() How is RichComparisonClass implemented? Did you provide a __hash__() method such that obj1 == obj2 implies hash(obj1) == hash(obj2)? This is necessary for instances of the class to work properly with sets and dicts. Peter From pruebauno at latinmail.com Fri Jun 19 15:38:42 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:38:42 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt >>> def midnight_next_day(initial_time=None): if initial_time == "use today's date": initial_time = datetime.now() return initial_time.date() + timedelta(days=1) >>> midnight_next_day() Traceback (most recent call last): File "", line 1, in midnight_next_day() File "", line 6, in midnight_next_day return initial_time.date() + timedelta(days=1) AttributeError: 'NoneType' object has no attribute 'date' >>> From dickinsm at gmail.com Fri Jun 19 15:40:36 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 12:40:36 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> On Jun 19, 7:43?pm, David C. Ullrich wrote: > Evidently my posts are appearing, since I see replies. > I guess the question of why I don't see the posts themselves > \is ot here... Judging by this thread, I'm not sure that much is off-topic here. :-) > Perhaps not. I'm very surprised to see those definitions; I've > been a mathematician for 25 years and I've never seen a > curve defined a subset of the plane. That in turn surprises me. I've taught multivariable calculus courses from at least three different texts in three different US universities, and as far as I recall a 'curve' was always thought of as a subset of R^2 or R^3 in those courses (though not always with explicit definitions, since that would be too much to hope for with that sort of text). Here's Stewart's 'Calculus', p658: "Examples 2 and 3 show that different sets of parametric equations can represent the same curve. Thus we distinguish between a *curve*, which is a set of points, and a *parametric curve*, in which the points are traced in a particular way." Again as far as I remember, the rest of the language in those courses (e.g., 'level curve', 'curve as the intersection of two surfaces') involves thinking of curves as subsets of R^2 or R^3. Certainly I'll agree that it's then necessary to parameterize the curve before being able to do anything useful with it. [Standard question when teaching multivariable calculus: "Okay, so we've got a curve. What's the first thing we do with it?" Answer, shouted out from all the (awake) students: "PARAMETERIZE IT!" (And then calculate its length/integrate the given vector field along it/etc.) Those were the days...] A Google Books search even turned up some complex analysis texts where the word 'curve' is used to mean a subset of the plane; check out the book by Ian Stewart and David Orme Tall, 'Complex Analysis: a Hitchhiker's Guide to the Plane': they distinguish 'curves' (subset of the complex plane) from 'paths' (functions from a closed bounded interval to the complex plane). > "Definition 2. A polygon is a Jordan curve that is a subset of a > finite union of > lines. A polygonal path is a continuous function P : [0, 1] ->? R2 > that is a subset of > a finite union of lines. It is a polygonal arc, if it is 1 . 1." > > By that definition a polygonal path is not a curve. Right. I'm much more willing to accept 'path' as standard terminology for a function [a, b] -> (insert_favourite_space_here). > Not that it matters, but his defintion of "polygonal path" > is, _if_ we're being very careful, self-contradictory. Agreed. Surprising, coming from Hales; he must surely rank amongst the more careful mathematicians out there. > So I don't think we can count that paper as a suitable > reference for what the _standard_ definitions are; > the standard definitions are not self-contradictory this way. I just don't believe there's any such thing as 'the standard definition' of a curve. I'm happy to believe that in complex analysis and differential geometry it's common to define a curve to be a function. But in general I'd suggest that it's one of those terms that largely depends on context, and should be defined clearly when it's not totally obvious from the context which definition is intended. For example, for me, more often than not, a curve is a 1-dimensional scheme over a field k (usually *not* algebraically closed), that's at least some of {geometrically reduced, geometrically irreducible, proper, smooth}. That's a far cry either from a subset of an affine space or from a parametrization by an interval. > Then the second definition you cite: Amazon says the > prerequisites are two years of calculus. The stanard > meaning of log is log base e, even though means > log base 10 in calculus. Sorry, I've lost context for this comment. Why are logs relevant? (I'm very well aware of the debates over the meaning of log, having frequently had to help students 'unlearn' their "log=log10" mindset when starting a first post-calculus course). Mark From pruebauno at latinmail.com Fri Jun 19 15:41:18 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:41:18 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt >>> def midnight_next_day(initial_time="use today's date"): if initial_time == "use today's date": initial_time = datetime.now() return initial_time.date() + timedelta(days=1) >>> midnight_next_day() Traceback (most recent call last): File "", line 1, in midnight_next_day() File "", line 6, in midnight_next_day return initial_time.date() + timedelta(days=1) AttributeError: 'str' object has no attribute 'date' From pavlovevidence at gmail.com Fri Jun 19 15:41:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Jun 2009 12:41:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> On Jun 19, 11:08?am, OdarR wrote: > On 19 juin, 19:13, s... at pobox.com wrote: > > > ? ? Olivier> what do you mean ? > > > ? ? Olivier> Cpython can't benefit from multi-core without multiple > > ? ? Olivier> processes. > > > It can, precisely as Martin indicated. ?Only one thread at a time can hold > > the GIL. ?That doesn't mean that multiple threads can't execute. ?Suppose > > I don't say multiple threads can't execute....(?). > I say that with the Python library, I don't see (yet) benefit with > multiple threads *on* multiple CPU/core. He's saying that if your code involves extensions written in C that release the GIL, the C thread can run on a different core than the Python-thread at the same time. The GIL is only required for Python code, and C code that uses the Python API. C code that spends a big hunk of time not using any Python API (like, as Skip pointed out, a matrix multiply) can release the GIL and the thread can run on a different core at the same time. I always found to be a *terribly* weak rationalization. The fact is, few Python developers can take much advantage of this. (Note: I'm not talking about releasing the GIL for I/O operations, it's not the same thing. I'm talking about the ability to run computations on multiple cores at the same time, not to block in 50 threads at the same time. Multiple cores aren't going to help that much in the latter case.) I wish Pythonistas would be more willing to acknowledge the (few) drawbacks of the language (or implementation, in this case) instead of all this rationalization. It's like people here in Los Angeles who complain about overcast days. What, 330 days of sunshine not enough? Jesus. I wish people would just say, "This is a limitation of CPython. There are reasons why it's there, and it helps some people, but unfortunately it has drawbacks for others", instead of the typical "all u hav 2 do is rite it in C LOL". Carl Banks From clp2 at rebertia.com Fri Jun 19 15:42:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 12:42:49 -0700 Subject: Rich comparison methods don't work in sets? In-Reply-To: References: Message-ID: <50697b2c0906191242t1b92a7b6ne349ae34b29c57b1@mail.gmail.com> On Fri, Jun 19, 2009 at 12:02 PM, Gustavo Narea wrote: > Hello, everyone. > > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() > obj2 = RichComparisonClass() > > set1 = set([obj1]) > set2 = set([obj2]) > > if obj1 == obj2: > ? ?print "Objects 1 and 2 are equivalent" > else: > ? ?print "Objects 1 and 2 aren't equivalent" > > if set1 == set2: > ? ?print "Sets 1 and 2 are equivalent" > else: > ? ?print "Sets 1 and 2 aren't equivalent" > """ > > Would output: > """ > Objects 1 and 2 are equivalent > Sets 1 and 2 aren't equivalent > """ > > instead of: > """ > Objects 1 and 2 are equivalent > Sets 1 and 2 are equivalent > """ > > How can I work around this? The only solution that comes to my mind is Note that sets are dict-based and thus use hash tables internally. Thus, you must implement a sensible __hash__ method. The default __hash__ provided by class `object` uses the object ID for the hash. Since id(x) == id(y) iff x is y, and hash(x) != hash(y) implies x != y, If you don't implement __hash__, object's implementation causes every distinct object of your type to be considered unequal a priori, so it doesn't bother to check any further by calling the comparison methods. Cheers, Chris -- http://blog.rebertia.com From castironpi at gmail.com Fri Jun 19 15:50:53 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 12:50:53 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: On Jun 17, 8:28?pm, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you I have one or two. If the objects you're pickling are all dictionaries, you could store file names in a master 'shelve' object, and nested data in the corresponding files. Otherwise, it may be pretty cheap to write the operations by hand using ctypes if you only need a few, though that can get precarious quickly. Just like life, huh? Lastly, the 'sqlite3' module's bark is worse than its byte. From pruebauno at latinmail.com Fri Jun 19 15:52:37 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:52:37 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: <440006b0-1fcd-41a6-920c-d0167a2e54ac@n4g2000vba.googlegroups.com> On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt This is a limitation of static type checking and Pylint is a (limited) static type checker for Python. A language with static type checking would not have even allowed you to compile this. A static type checkers sees this: def midnight_next_day(initial_time [string or in python whatever gets passed(T)]): if initial_time [string (or T)]== [(some constant) string]: initial_time [datetime] = datetime.now() {implied else: initial_time [string or (T)] } return initial_time[could be either datetime or string (oops string does not have date()) pylint doesn?t check for T].date() + timedelta(days=1) or this: def midnight_next_day(initial_time [None object or (T)]): if initial_time [None object or (T)]== [None object]: initial_time [type datetime] = datetime.now() {implied else: initial_time [T] } return initial_time[datetime (pylint doesn?t check for T)].date() + timedelta(days=1) From jeremiah.jester at panasonic.aero Fri Jun 19 15:55:43 2009 From: jeremiah.jester at panasonic.aero (Jeremiah Jester) Date: Fri, 19 Jun 2009 12:55:43 -0700 Subject: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009 In-Reply-To: <4A3A5F66.2030701@simplistix.co.uk> References: <4A3A5F66.2030701@simplistix.co.uk> Message-ID: <1245441343.32055.2.camel@jesterj-laptop> Chris, Do you have any online tutorial for this topic? Thanks, JJ On Thu, 2009-06-18 at 08:38 -0700, Chris Withers wrote: > Hi All, > > Too many people in the Python community *still* think the only way to > work with Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's > EuroPython > conference in Birmingham, UK on Monday, 29th June that will cover > working with Excel files in Python using the pure-python libraries > xlrd, > xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > Including extracting all the data types, formatting and working > with > large files. > > - Writing Excel Files > > Including formatting, many of the useful frilly extras and writing > large excel files. > > - Modifying and Filtering Excel Files > > A run through of taking existing Excel files and modifying them in > various ways. > > - Workshop for your problems > > I'm hoping anyone who attends will get a lot out of this! If you're > planning on attending and have a particular problem you'd like to > work > on in this part of the tutorial, please drop me an email and I'll > try > and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at EuroPython > this > year: > > http://www.europython.eu/ > > I look forward to seeing you all there! > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > - http://www.simplistix.co.uk > > > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations.html > > > Disclaimer: The information contained in this transmission, including any attachments, may contain confidential information of Panasonic Avionics Corporation. This transmission is intended only for the use of the addressee(s) listed above. Unauthorized review, dissemination or other use of the information contained in this transmission is strictly prohibited. If you have received this transmission in error or have reason to believe you are not authorized to receive it, please notify the sender by return email and promptly delete the transmission. From anthra.norell at bluewin.ch Fri Jun 19 16:00:45 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 19 Jun 2009 22:00:45 +0200 Subject: CAD file format specifications? In-Reply-To: References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> <4A3A2770.2030802@bluewin.ch> Message-ID: <4A3BEE6D.4070702@bluewin.ch> Dennis Lee Bieber wrote: > On Thu, 18 Jun 2009 13:39:28 +0200, Anthra Norell > declaimed the following in > gmane.comp.python.general: > > > >> utility. So, my question is: How do I convert a bunch of >> three-dimensional coordinates defining lines into a file format Sketch >> Up can read (skp, dwg, dxf, 3ds, ddf or dem)? >> >> > Most CAD type data files are highly structured -- and the formats > may be under company control... > > http://en.wikipedia.org/wiki/USGS_DEM > http://rockyweb.cr.usgs.gov/nmpstds/acrodocs/dem/2DEM0198.PDF > > http://www.martinreddy.net/gfx/3d/3DS.spec > Dennis, norseman, Thanks for your suggestions. First thing I'm trying to write a DXF converter using norseman's excellent documentation. It seems I only need a simple subset of the DXF format (Entities). When I'm done I shall take a close look at the links above. So, thanks again. Frederic From piet at cs.uu.nl Fri Jun 19 16:03:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 22:03:16 +0200 Subject: multiprocessing and process run time References: Message-ID: >>>>> Thomas Robitaille (TR) wrote: >TR> Hi, >TR> I'm making use of the multiprocessing module, and I was wondering if there >TR> is an easy way to find out how long a given process has been running for. >TR> For example, if I do >TR> import multiprocessing as mp >TR> import time >TR> def time_waster(): >TR> time.sleep(1000) >TR> p = mp.Process(target=time_waster) >TR> p.start() >TR> Is there a way that I can then find how long p has been running for? I >TR> figured I can use p.pid to get the PID of the process, but I'm not sure >TR> where to go from there. Is there an easy way to do this? You could look at the psutil module: http://code.google.com/p/psutil/ -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From mitko at qlogic.com Fri Jun 19 16:18:58 2009 From: mitko at qlogic.com (Mitko Haralanov) Date: Fri, 19 Jun 2009 13:18:58 -0700 Subject: Checking for binary data in a string Message-ID: <20090619131858.1b4ade03@hematite.mv.qlogic.com> I have a question about finding out whether a string contains binary data? In my application, I am reading from a file which could contain binary data. After I have read the data, I transfer it using xmlrpclib. However, xmlrpclib has trouble unpacking XML which contains binary data and my application throws an exception. The solution to this problem is to use base64 encoding of the data but I don't know how to check whether the encoding will be needed? If I read in a string containing some binary data from the file, the type of that string is which is not different from any other string, so I can't use that as a check. The only other check that I can think of is to check every character in the read-in string against string.printable but that will take a long time. Can anyone suggest a better way to handle the check? Thank you in advance. -- Mitko Haralanov From lie.1296 at gmail.com Fri Jun 19 16:55:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 20:55:08 GMT Subject: Convert hash to struct In-Reply-To: References: Message-ID: Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > I just remembered something... If you used python > 2.6, you may also look at namedtuple From castironpi at gmail.com Fri Jun 19 17:00:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 14:00:49 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: Message-ID: <81d1e7ba-9718-4b67-becb-753ee3f99725@e20g2000vbc.googlegroups.com> On Jun 19, 12:42?pm, Chris Rebert wrote: > On Fri, Jun 19, 2009 at 12:02 PM, Gustavo Narea wrote: > > Hello, everyone. > > > I've noticed that if I have a class with so-called "rich comparison" > > methods > > (__eq__, __ne__, etc.), when its instances are included in a set, > > set.__contains__/__eq__ won't call the .__eq__ method of the elements > > and thus > > the code below: snip > > """ > > obj1 = RichComparisonClass() > > obj2 = RichComparisonClass() > > > set1 = set([obj1]) > > set2 = set([obj2]) > > > if obj1 == obj2: > > ? ?print "Objects 1 and 2 are equivalent" > > else: > > ? ?print "Objects 1 and 2 aren't equivalent" > > > if set1 == set2: > > ? ?print "Sets 1 and 2 are equivalent" > > else: > > ? ?print "Sets 1 and 2 aren't equivalent" > > """ > > > Would output: > > """ > > Objects 1 and 2 are equivalent > > Sets 1 and 2 aren't equivalent > > """ > > > instead of: > > """ > > Objects 1 and 2 are equivalent > > Sets 1 and 2 are equivalent > > """ > > > How can I work around this? The only solution that comes to my mind is > > Note that sets are dict-based and thus use hash tables internally. > Thus, you must implement a sensible __hash__ method. > The default __hash__ provided by class `object` uses the object ID for the hash. > > Since id(x) == id(y) ?iff ?x is y, and > hash(x) != hash(y) implies x != y, > If you don't implement __hash__, object's implementation causes every > distinct object of your type to be considered unequal a priori, so it > doesn't bother to check any further by calling the comparison methods. > > Cheers, > Chris > --http://blog.rebertia.com You're using sets for uniqueness and faster lookups than a list or other collection. Uniqueness is determined by hash key first, then by identity (due to an idiosyncrasy of 'RichCompareBool'), then by rich equality. If you want to compare to every element, you can't use sets, because they take short-cuts by omitting many of the comparisons. From amita.ekbote at gmail.com Fri Jun 19 17:03:58 2009 From: amita.ekbote at gmail.com (Amita Ekbote) Date: Fri, 19 Jun 2009 16:03:58 -0500 Subject: Convert hash to struct In-Reply-To: References: Message-ID: I wanted to make a more generic way of doing this so that even if the columns are modified or new ones are added it should be simple. Anyway I will reconsider this sort of am implementation. Just out of curiosity is there any other way of achieving this? Thanks Amita On Fri, Jun 19, 2009 at 1:52 PM, Lie Ryan wrote: > Amita Ekbote wrote: >> Hello, >> >> I am retrieving values from a database in the form of a dictionary so >> I can access the values as d['column'] and I was wondering if there is >> a way to convert the hash to a struct like format so i can just say >> d.column. Makes it easier to read and understand. >> >> Thanks >> Amita >> > > You may be able to update the class' dict: > >>>> class MyDB(object): > ... def __init__(self, di): > ... self.__dict__.update(di) > ... >>>> di = {'a':10, 'b': 20} >>>> d = MyDB(di) >>>> d > <__main__.MyDB object at 0x7f756b0d0b90> >>>> d.a > 10 >>>> d.b > 20 > > but this might be a security risk, if you cannot trust the database or > its content. > > It is much preferrable to use something like: > >>>> class MyDB(object): > ... def __init__(self, di): > ... self.a = di['a'] > ... self.b = di['b'] > > > since you now have full control of what collumns can go in and whatnot. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amita Ekbote From invalid at invalid Fri Jun 19 17:12:10 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 16:12:10 -0500 Subject: Checking for binary data in a string References: Message-ID: On 2009-06-19, Mitko Haralanov wrote: > I have a question about finding out whether a string contains > binary data? All strings contain binary data. Unless you've invented ternary logic and built a computer with it. ;) > If I read in a string containing some binary data from the file, the > type of that string is which is not different from any > other string, so I can't use that as a check. Correct. > The only other check that I can think of is to check every > character in the read-in string against string.printable but > that will take a long time. There's no such thing as a free lunch. If you want to know if some condition is true for every octet in a string, then you have to check whether it's true for every character in the string -- until you find it to be false. IOW, you can stop when you find the first non-printable octect. -- Grant Edwards grante Yow! Eisenhower!! Your at mimeograph machine upsets visi.com my stomach!! From jure.erznoznik at gmail.com Fri Jun 19 17:13:50 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 14:13:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Thanks guys, for all the replies. They were some very interesting reading / watching. Seems to me, the Unladen-Swallow might in time produce code which will have this problem lessened a bit. Their roadmap suggests at least modifying the GIL principles if not fully removing it. On top of this, they seem to have a pretty aggressive schedule with good results expected by Q3 this year. I'm hoping that their patches will be accepted to cPython codebase in a timely manner. I definitely liket the speed improvements they showed for Q1 modifications. Though those improvements don't help my case yet... The presentation from mr. Beasley was hilarious :D I find it curious to learn that just simple replacement from events to actual mutexes already lessens the problem a lot. This should already be implemented in the cPython codebase IMHO. As for multiprocessing alternatives, I'll have to look into them. I haven't yet done multiprocessing code and don't really know what will happen when I try. I believe that threads would be much more appropriate for my project, but it's definitely worth a shot. Since my project is supposed to be cross platform, I'm not really looking forward to learning cross platform for C++. All my C++ experience is DOS + Windows derivatives till now :( From davea at ieee.org Fri Jun 19 17:35:16 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 17:35:16 -0400 Subject: Checking for binary data in a string In-Reply-To: <20090619131858.1b4ade03@hematite.mv.qlogic.com> References: <20090619131858.1b4ade03@hematite.mv.qlogic.com> Message-ID: <4A3C0494.7090902@ieee.org> Mitko Haralanov wrote: > I have a question about finding out whether a string contains binary > data? > > In my application, I am reading from a file which could contain > binary data. After I have read the data, I transfer it using xmlrpclib. > > However, xmlrpclib has trouble unpacking XML which contains binary data > and my application throws an exception. The solution to this problem is > to use base64 encoding of the data but I don't know how to check > whether the encoding will be needed? > > If I read in a string containing some binary data from the file, the > type of that string is which is not different from any > other string, so I can't use that as a check. > > The only other check that I can think of is to check every character in > the read-in string against string.printable but that will take a long > time. > > Can anyone suggest a better way to handle the check? Thank you in > advance. > > All the data is binary. But perhaps you mean ASCII (7 bits), or you mean between 20-7f. or something. The way I'd tackle it is to build a translation table for your definition of "binary." Then simply do something like: if data != data.translate(table): ..... Convert to bin64 or whatever... The translation table would be defined such that table[ch] == ch for all ch that are "nonbinary" and table[ch] != ch for all ch that are "binary." And naturally you only build the table once, and reuse it on each buffer. This should be quicker than any for loop you could write, though there may be other builltin functions that are even quicker. It's a start, though. Note that you will probably also be escaping the xml special characters, such as &, <, and >. So you might get clever about letting a single translate pass tell you whether the data can be stored unmodified, then do a second translate to decide which way to modify it. Whether this is worthwhile depends in part on how often the buffer fits into which category. From Olivier.Darge at gmail.com Fri Jun 19 17:45:02 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 14:45:02 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 21:05, Christian Heimes wrote: > I've seen a single Python process using the full capacity of up to 8 > CPUs. The application is making heavy use of lxml for large XSL > transformations, a database adapter and my own image processing library > based upon FreeImage. interesting... > Of course both lxml and my library are written with the GIL in mind. > They release the GIL around every call to C libraries that don't touch > Python objects. PIL releases the lock around ops as well (although it > took me a while to figure it out because PIL uses its own API instead of > the standard macros). reportlab has some optional C libraries that > increase the speed, too. Are you using them? I don't. Or maybe I did, but I have no clue what to test. Do you have a real example, some code snippet to can prove/show activity on multiple core ? I accept your explanation, but I also like experiencing :) > By the way threads are evil > (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and > not *the* answer to concurrency. I don't see threads as evil from my little experience on the subject, but we need them. I'm reading what's happening in the java world too, it can be interesting. Olivier From jure.erznoznik at gmail.com Fri Jun 19 17:49:27 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 14:49:27 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Message-ID: Sorry, just a few more thoughts: Does anybody know why GIL can't be made more atomic? I mean, use different locks for different parts of code? This way there would be way less blocking and the plugin interface could remain the same (the interpreter would know what lock it used for the plugin, so the actual function for releasing / reacquiring the lock could remain the same) On second thought, forget this. This is probably exactly the cause of free-threading reduced performance. Fine-graining the locks increased the lock count and their implementation is rather slow per se. Strange that *nix variants don't have InterlockedExchange, probably because they aren't x86 specific. I find it strange that other architectures wouldn't have these instructions though... Also, an OS should still be able to support such a function even if underlying architecture doesn't have it. After all, a kernel knows what it's currently running and they are typically not preempted themselves. Also, a beside question: why does python so like to use events instead of "true" synchronization objects? Almost every library I looked at used that. IMHO that's quite irrational. Using objects that are intended for something else for the job while there are plenty of "true" options supported in every OS out there. Still, the free-threading mod could still work just fine if there was just one more global variable added: current python thread count. A simple check for value greater than 1 would trigger the synchronization code, while having just one thread would introduce no locking at all. Still, I didn't like the performance figures of the mod (0.6 execution speed, pretty bad core / processor scaling) I don't know why it's so hard to do simple locking just for writes to globals. I used to do it massively and it always worked almost with no penalty at all. It's true that those were all Windows programs, using critical sections. From Olivier.Darge at gmail.com Fri Jun 19 17:51:04 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 14:51:04 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: On 19 juin, 21:41, Carl Banks wrote: > He's saying that if your code involves extensions written in C that > release the GIL, the C thread can run on a different core than the > Python-thread at the same time. ?The GIL is only required for Python > code, and C code that uses the Python API. ?C code that spends a big > hunk of time not using any Python API (like, as Skip pointed out, a > matrix multiply) can release the GIL and the thread can run on a > different core at the same time. I understand the idea, even if I don't see any examples in the standard library. any examples ? > (Note: I'm not talking about releasing the GIL for I/O operations, > it's not the same thing. ?I'm talking about the ability to run > computations on multiple cores at the same time, not to block in 50 > threads at the same time. ?Multiple cores aren't going to help that > much in the latter case.) yes, I also speak about hard computation that could benefit with multiple cores. > I wish Pythonistas would be more willing to acknowledge the (few) > drawbacks of the language (or implementation, in this case) instead of > all this rationalization. ?It's like people here in Los Angeles who > complain about overcast days. ?What, 330 days of sunshine not enough? > Jesus. ?I wish people would just say, "This is a limitation of > CPython. ?There are reasons why it's there, and it helps some people, > but unfortunately it has drawbacks for others", instead of the typical > "all u hav 2 do is rite it in C LOL". "LOL" I would like to say such thing about my weather...I live in Europe in a rainy country. Olivier From davea at ieee.org Fri Jun 19 17:52:11 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 17:52:11 -0400 Subject: Convert hash to struct In-Reply-To: References: Message-ID: <4A3C088B.4030101@ieee.org> Amita Ekbote wrote: > I wanted to make a more generic way of doing this so that even if the > columns are modified or new ones are added it should be simple. Anyway > I will reconsider this sort of am implementation. Just out of > curiosity is there any other way of achieving this? > > Thanks > Amita > > On Fri, Jun 19, 2009 at 1:52 PM, Lie Ryan wrote: > >> Amita Ekbote wrote: >> >>> Hello, >>> >>> I am retrieving values from a database in the form of a dictionary so >>> I can access the values as d['column'] and I was wondering if there is >>> a way to convert the hash to a struct like format so i can just say >>> d.column. Makes it easier to read and understand. >>> >>> Thanks >>> Amita >>> >>> >> You may be able to update the class' dict: >> >> >>>>> class MyDB(object): >>>>> >> ... def __init__(self, di): >> ... self.__dict__.update(di) >> ... >> >>>>> di = {'a':10, 'b': 20} >>>>> d = MyDB(di) >>>>> d >>>>> >> <__main__.MyDB object at 0x7f756b0d0b90> >> >>>>> d.a >>>>> >> 10 >> >>>>> d.b >>>>> >> 20 >> >> but this might be a security risk, if you cannot trust the database or >> its content. >> >> It is much preferrable to use something like: >> >> >>>>> class MyDB(object): >>>>> >> ... def __init__(self, di): >> ... self.a = di['a'] >> ... self.b = di['b'] >> >> >> since you now have full control of what collumns can go in and whatnot. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> You really shouldn't top-post here; it makes the sequence of message and response very hard to follow. Put your comments at the end, unless it's a simple "thanks for the response" one-liner. Someone else pointed out that you can derive from dict, and showed you why that can be dangerous if one of the attributes you're trying to use happens to be already a method in the list class. But you could write a class that *contains* a dict, and gives you access to it by attribute. Look at this for starters: class undict(object): def __init__(self): self.data = {"key1":44, "key2":90} def __getattr__(self, name): try: return self.data[name] except KeyError: raise AttributeError(name) From jasondrew72 at gmail.com Fri Jun 19 17:58:27 2009 From: jasondrew72 at gmail.com (Jason) Date: Fri, 19 Jun 2009 14:58:27 -0700 (PDT) Subject: Convert hash to struct References: Message-ID: Here's my general-purpose solution for doing this: class Dict2Class(object): """ Update like a dictionary, but expose the keys as class properties. Sweet! You can instantiate and update this practically any way you choose, and the values are available as class properties. >>> c = Dict2Class((('fred', 11), ('joe', 88)), bob=9) >>> c.bob 9 >>> c.joe 88 >>> c = Dict2Class({'bob': 88, 'fred': 9}) >>> c.fred 9 >>> c = Dict2Class() >>> c.bob = 88 >>> c.bob 88 This subclasses plain old object. It could also subclass dict to provide even more functionality, but at the risk of naming collisions between the dict methods and property names. """ def __init__(self, *e, **f): self.__dict__ = dict(*e, **f) def update(self, *e, **f): self.__dict__.update(*e, **f) # Looks a little complex, but it rocks. On Jun 19, 2:17?pm, Amita Ekbote wrote: > ?Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > > -- > Amita Ekbote From jnoller at gmail.com Fri Jun 19 17:59:26 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 19 Jun 2009 17:59:26 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4222a8490906191459x1eaf912bt18b7db5e9f8dd5ea@mail.gmail.com> On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: > On 19 juin, 16:16, Martin von Loewis > If you know that your (C) code is thread safe on its own, you can >> release the GIL around long-running algorithms, thus using as many >> CPUs as you have available, in a single process. > > what do you mean ? > > Cpython can't benefit from multi-core without multiple processes. > > Olivier Sorry, you're incorrect. I/O Bound threads do in fact, take advantage of multiple cores. From wayne.dads.bell at gmail.com Fri Jun 19 17:59:33 2009 From: wayne.dads.bell at gmail.com (dads) Date: Fri, 19 Jun 2009 14:59:33 -0700 (PDT) Subject: File Syncing Message-ID: I've created a small application that when you click one of the buttons it randomly picks a paragraphs from a list that it generates from a text file and then copies them to the clipboard. It also has make new/edit/delete/print/ etc functionality. It's for work so I get some brownie points and every know and then I could work on it and learn python while getting paid (heaven) instead of my normal customer service job (mind I've done 95% of it at home). I've been allowed to install it on one of the blade servers so one of the team can use if they connect to that server. Great stuff. When we normally connect through one of the thin clients we connect randomly to one of three blade servers. I've just thought that when I add the app to the other servers they will be completely separate. So if the the paragraphs which are stored in text files are amended/ deleted/created will only happen on one server and not them all. I've a couple of questions: What would happen if more than one person used my application at the same time? I haven't added any I/O exception code so I think that would be an issue but would python crash? (it's only got simple functions and controls in it, no threading or process code or anything like that, i'd post it but it's 2500lines long) What would I have to learn to be able to sync the text files on each server? python network programming? Or something else? Sorry for my naivety =p From jure.erznoznik at gmail.com Fri Jun 19 18:06:07 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 15:06:07 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 19, 11:45?pm, OdarR wrote: > On 19 juin, 21:05, Christian Heimes wrote: > > > I've seen a single Python process using the full capacity of up to 8 > > CPUs. The application is making heavy use of lxml for large XSL > > transformations, a database adapter and my own image processing library > > based upon FreeImage. > > interesting... > > > Of course both lxml and my library are written with the GIL in mind. > > They release the GIL around every call to C libraries that don't touch > > Python objects. PIL releases the lock around ops as well (although it > > took me a while to figure it out because PIL uses its own API instead of > > the standard macros). reportlab has some optional C libraries that > > increase the speed, too. Are you using them? > > I don't. Or maybe I did, but I have no clue what to test. > Do you have a real example, some code snippet to can prove/show > activity on multiple core ? > I accept your explanation, but I also like experiencing :) > > > By the way threads are evil > > (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and > > not *the* answer to concurrency. > > I don't see threads as evil from my little experience on the subject, > but we need them. > I'm reading what's happening in the java world too, it can be > interesting. > > Olivier Olivier, What Christian is saying is that you can write a C/C++ Python plugin, release the GIL inside it and then process stuff in threads inside the plugin. All this is possible if the progammer doesn't use any Python objects and it's fairly easy to write such a plugin. Any counting example will do just fine. The problem with this solution is that you have to write the code in C which quite defeats the purpose of using an interpreter in the first place... Of course, no pure python code will currently utilize multiple cores (because of GIL). I do aggree though that threading is important. Regardless of any studies showing that threads suck, they are here and they offer relatively simple concurrency. IMHO they should never have been crippled like this. Even though GIL solves access violations, it's not the right approach. It simply kills all threading benefits except for the situation where you work with multiple I/O blocking threads. That's just about the only situation where this problem is not apparent. We're way past single processor single core computers now. An important product like Python should support these architectures properly even if only 1% of applications written in it use threading. But as Guido himself said; I should not complain but instead try to contribute to solution. That's the hard part, especially since there's lots of code that actually need the locking. From jure.erznoznik at gmail.com Fri Jun 19 18:10:17 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 15:10:17 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 19, 11:59?pm, Jesse Noller wrote: > On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: > > On 19 juin, 16:16, Martin von Loewis >> If you know that your (C) code is thread safe on its own, you can > >> release the GIL around long-running algorithms, thus using as many > >> CPUs as you have available, in a single process. > > > what do you mean ? > > > Cpython can't benefit from multi-core without multiple processes. > > > Olivier > > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. Incorrect. They take advantage of OS threading support where another thread can run while one is blocked for I/O. That is not equal to running on multiple cores (though it actually does do that, just that cores are all not well utilized - sum(x) < 100% of one core). You wil get better performance running on single core because of the way GIL is implemented in all cases. From paul at boddie.org.uk Fri Jun 19 18:18:06 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 19 Jun 2009 15:18:06 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: On 19 Jun, 21:41, Carl Banks wrote: > > (Note: I'm not talking about releasing the GIL for I/O operations, > it's not the same thing. ?I'm talking about the ability to run > computations on multiple cores at the same time, not to block in 50 > threads at the same time. ?Multiple cores aren't going to help that > much in the latter case.) There seems to be a mixing together of these two things when people talk about "concurrency". Indeed, on the concurrency-sig mailing list [1] there's already been discussion about whether a particular example [2] is really a good showcase of concurrency. According to Wikipedia, concurrency is about "computations [...] executing simultaneously" [3], not about whether one can handle hundreds of communications channels sequentially, although this topic is obviously relevant when dealing with communications between processing contexts. I agree with the over-rationalisation assessment: it's not convenient (let alone an advantage) for people to have to switch to C so that they can release the GIL, nor is it any comfort that CPython's limitations are "acceptable" for the socket multiplexing server style of solution when that isn't the kind of solution being developed. However, there are some reasonable tools out there (and viable alternative implementations), and I'm optimistic that the situation will only improve. Paul [1] http://mail.python.org/mailman/listinfo/concurrency-sig [2] http://wiki.python.org/moin/Concurrency/99Bottles [3] http://en.wikipedia.org/wiki/Concurrency_(computer_science) From lie.1296 at gmail.com Fri Jun 19 18:31:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 22:31:08 GMT Subject: Checking for binary data in a string In-Reply-To: References: Message-ID: Grant Edwards wrote: > On 2009-06-19, Mitko Haralanov wrote: > >> I have a question about finding out whether a string contains >> binary data? > > All strings contain binary data. Not quite, (python 2.x's) strings are binary data. It just happens that it behaves like text when you appropriately encode/decode it. In python 3.x, the default string have evolved to unicode string, which is a true text and the old string which contains arbitrary binary data evolved into bytestring. From jnoller at gmail.com Fri Jun 19 18:43:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 19 Jun 2009 18:43:39 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4222a8490906191543o74049391p7f86449f3d0b2319@mail.gmail.com> On Fri, Jun 19, 2009 at 6:10 PM, Jure Erzno?nik wrote: > On Jun 19, 11:59?pm, Jesse Noller wrote: >> On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: >> > On 19 juin, 16:16, Martin von Loewis > >> If you know that your (C) code is thread safe on its own, you can >> >> release the GIL around long-running algorithms, thus using as many >> >> CPUs as you have available, in a single process. >> >> > what do you mean ? >> >> > Cpython can't benefit from multi-core without multiple processes. >> >> > Olivier >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > > Incorrect. They take advantage of OS threading support where another > thread can run while one is blocked for I/O. > That is not equal to running on multiple cores (though it actually > does do that, just that cores are all not well utilized - sum(x) < > 100% of one core). > You wil get better performance running on single core because of the > way GIL is implemented in all cases. No. That's simply incorrect. I (and others) have seen significant increases in threaded, I/O bound code using multiple cores. It's not perfect, but it is faster. From gh at ghaering.de Fri Jun 19 19:09:24 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 20 Jun 2009 01:09:24 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: References: <4A37BD14.5010807@arimaz.com> Message-ID: John Machin wrote: > Hi Gerhard, > [...] > In http://www.sqlite.org/c3ref/prepare.html it says """When an error > occurs, sqlite3_step() will return one of the detailed error codes or > extended error codes. The legacy behavior was that sqlite3_step() > would only return a generic SQLITE_ERROR result code and you would > have to make a second call to sqlite3_reset() in order to find the > underlying cause of the problem. With the "v2" prepare interfaces, the > underlying reason for the error is returned immediately.""" > > Are you using sqlite3_prepare() or sqlite3_prepare_v2()? > sqlite3_errcode() or sqlite3_extended_errcode()? Because of compatibility with older SQLite versions, I'm using the old API only. I'll change this one day and then I'll be able to throw a lot of compatibility code out of the window, too. But I certainly won't go #ifdef hell and implement both. -- Gerhard From arlie.c at gmail.com Fri Jun 19 19:16:05 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 16:16:05 -0700 (PDT) Subject: Play MP3s from Windows Message-ID: Hi, Newbie here. I copied and pasted the code below. But when I ran it I got this error: D:\>python mp3.py Duree du fichier : 298919 millisecondes Traceback (most recent call last): File "mp3.py", line 37, in time.sleep(int(buf)/1000) ValueError: invalid literal for int() with base 10: '' The code: # -*- coding: utf-8 -*- import time from ctypes import windll, c_buffer class mci: def __init__(self): self.w32mci = windll.winmm.mciSendStringA self.w32mcierror = windll.winmm.mciGetErrorStringA def send(self,commande): buffer = c_buffer(255) errorcode = self.w32mci(str(commande),buffer,254,0) if errorcode: return errorcode, self.get_error(errorcode) else: return errorcode,buffer.value def get_error(self,error): error = int(error) buffer = c_buffer(255) self.w32mcierror(error,buffer,254) return buffer.value def directsend(self, txt): (err,buf)=self.send(txt) if err != 0: print'Erreur',str(err),'sur',txt,':',buf return (err,buf) mci=mci() mci.directsend('open "d:\\Linger.mp3" alias toto') mci.directsend('set toto time format milliseconds') err,buf=mci.directsend('status toto length ') print 'Duree du fichier : ',buf,' millisecondes' err,buf=mci.directsend('play toto from 0 to '+str(buf)) time.sleep(int(buf)/1000) mci.directsend('close toto') #@-salutations #-- #Michel Claveau Please help. I'm in the middle of a project and I wanted to use this. From arlie.c at gmail.com Fri Jun 19 19:20:09 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 16:20:09 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: On Jun 20, 7:16?am, Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : ?298919 ?millisecondes > Traceback (most recent call last): > ? File "mp3.py", line 37, in > ? ? time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' > > The code: > > # -*- coding: utf-8 -*- > > import time > from ctypes import windll, c_buffer > > class mci: > ? ? def __init__(self): > ? ? ? ? self.w32mci = windll.winmm.mciSendStringA > ? ? ? ? self.w32mcierror = windll.winmm.mciGetErrorStringA > > ? ? def send(self,commande): > ? ? ? ? buffer = c_buffer(255) > ? ? ? ? errorcode = self.w32mci(str(commande),buffer,254,0) > ? ? ? ? if errorcode: > ? ? ? ? ? ? return errorcode, self.get_error(errorcode) > ? ? ? ? else: > ? ? ? ? ? ? return errorcode,buffer.value > > ? ? def get_error(self,error): > ? ? ? ? error = int(error) > ? ? ? ? buffer = c_buffer(255) > ? ? ? ? self.w32mcierror(error,buffer,254) > ? ? ? ? return buffer.value > > ? ? def directsend(self, txt): > ? ? ? ? (err,buf)=self.send(txt) > ? ? ? ? if err != 0: > ? ? ? ? ? ? print'Erreur',str(err),'sur',txt,':',buf > ? ? ? ? return (err,buf) > > mci=mci() > mci.directsend('open "d:\\Linger.mp3" alias toto') > mci.directsend('set toto time format milliseconds') > err,buf=mci.directsend('status toto length ') > print 'Duree du fichier : ',buf,' millisecondes' > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > time.sleep(int(buf)/1000) > mci.directsend('close toto') > > #@-salutations > #-- > #Michel Claveau > > Please help. I'm in the middle of a project and I wanted to use this. By the way I using Python 2.6.2. From usernet at ilthio.net Fri Jun 19 19:27:10 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Jun 2009 23:27:10 GMT Subject: Play MP3s from Windows References: Message-ID: On 2009-06-19, Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : 298919 millisecondes > Traceback (most recent call last): > File "mp3.py", line 37, in > time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' Did you mean time.sleep(int(buf/1000)) which will guarantee that the value sent to sleep is an integer rather then a float if buf is not evenly divisible by 1000 (even after it has been rounded to an integer)? From aahz at pythoncraft.com Fri Jun 19 19:31:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:31:59 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > >I do aggree though that threading is important. Regardless of any >studies showing that threads suck, they are here and they offer >relatively simple concurrency. IMHO they should never have been >crippled like this. Even though GIL solves access violations, it's not >the right approach. It simply kills all threading benefits except for >the situation where you work with multiple I/O blocking threads. >That's just about the only situation where this problem is not >apparent. NumPy? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Fri Jun 19 19:35:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:35:18 -0700 Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: In article <157e0345-74e0-4144-a2e6-2b4cc854ce37 at z7g2000vbh.googlegroups.com>, Carl Banks wrote: > >I wish Pythonistas would be more willing to acknowledge the (few) >drawbacks of the language (or implementation, in this case) instead of >all this rationalization. Please provide more evidence that Pythonistas are unwilling to acknowledge the drawbacks of the GIL. I think you're just spreading FUD. The problem is that discussions about the GIL almost invariably include false statements about the GIL, and I'm certainly not going to hamper my writing to always include the caveats about GIL drawbacks while correcting the wrong information. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Fri Jun 19 19:36:32 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:36:32 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: >On Jun 19, 11:59=A0pm, Jesse Noller wrote: >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > >Incorrect. They take advantage of OS threading support where another >thread can run while one is blocked for I/O. That is not equal to >running on multiple cores (though it actually does do that, just that >cores are all not well utilized - sum(x) < 100% of one core). You wil >get better performance running on single core because of the way GIL is >implemented in all cases. You should put up or shut up -- I've certainly seen multi-core speedup with threaded software, so show us your benchmarks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From lists at cheimes.de Fri Jun 19 19:42:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 20 Jun 2009 01:42:20 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: OdarR schrieb: > On 19 juin, 21:41, Carl Banks wrote: >> He's saying that if your code involves extensions written in C that >> release the GIL, the C thread can run on a different core than the >> Python-thread at the same time. The GIL is only required for Python >> code, and C code that uses the Python API. C code that spends a big >> hunk of time not using any Python API (like, as Skip pointed out, a >> matrix multiply) can release the GIL and the thread can run on a >> different core at the same time. > > I understand the idea, even if I don't see any examples in the > standard library. > any examples ? http://svn.python.org/view/python/trunk/Modules/posixmodule.c?revision=72882&view=markup Search for Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS > yes, I also speak about hard computation that could benefit with > multiple cores. Hard computations gain more speed from carefully crafted C or Fortran code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or parallelized algorithms. If you start sharing values between multiple cores you have a serious problem. Oh, and use NumPy for the job ;) >> I wish people would just say, "This is a limitation of >> CPython. There are reasons why it's there, and it helps some people, >> but unfortunately it has drawbacks for others", instead of the typical >> "all u hav 2 do is rite it in C LOL". > > "LOL" > I would like to say such thing about my weather...I live in Europe in > a rainy country. It *is* a well known limitation of Python. All the nice 'n shiny syntax and features are coming with a cost. Python is a powerful language and good tool for lots of stuff. But Python is and will never become the ?bertool that solves every problem perfectly. At some point you need a different tool to get the raw power of your machine. C (and perhaps Fortran) are the weapons of choice for number crunching. Christian From rridge at csclub.uwaterloo.ca Fri Jun 19 19:46:31 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Fri, 19 Jun 2009 19:46:31 -0400 Subject: Status of Python threading support (GIL removal)? References: Message-ID: Jesse Noller wrote: > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. wrote: >Incorrect. They take advantage of OS threading support where another >thread can run while one is blocked for I/O. That is not equal to >running on multiple cores (though it actually does do that, just that >cores are all not well utilized - sum(x) < 100% of one core). You wil >get better performance running on single core because of the way GIL is >implemented in all cases. Aahz wrote: >You should put up or shut up -- I've certainly seen multi-core speedup >with threaded software, so show us your benchmarks! By definition an I/O bound thread isn't CPU bound so won't benefit from improved CPU resources. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From jure.erznoznik at gmail.com Fri Jun 19 19:49:39 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 16:49:39 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 20, 1:36?am, a... at pythoncraft.com (Aahz) wrote: > > You should put up or shut up -- I've certainly seen multi-core speedup > with threaded software, so show us your benchmarks! > -- Sorry, no intent to offend anyone here. Flame wars are not my thing. I have shown my benchmarks. See first post and click on the link. That's the reason I started this discussion. All I'm saying is that you can get threading benefit, but only if the threading in question is implemented in C plugin. I have yet to see pure Python code which does take advantage of multiple cores. From what I read about GIL, this is simply impossible by design. But I'm not disputing the fact that cPython as a whole can take advantage of multiple cores. There certainly are built-in objects that work as they should. From lists at cheimes.de Fri Jun 19 19:52:50 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 20 Jun 2009 01:52:50 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: Aahz wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854ce37 at z7g2000vbh.googlegroups.com>, > Carl Banks wrote: >> I wish Pythonistas would be more willing to acknowledge the (few) >> drawbacks of the language (or implementation, in this case) instead of >> all this rationalization. > > Please provide more evidence that Pythonistas are unwilling to > acknowledge the drawbacks of the GIL. I think you're just spreading FUD. > The problem is that discussions about the GIL almost invariably include > false statements about the GIL, and I'm certainly not going to hamper my > writing to always include the caveats about GIL drawbacks while > correcting the wrong information. Aahz, my magic pixie dust bag is empty. Do you have some spare dust to remove the cursed GIL all alone? :p Christian From emile at fenx.com Fri Jun 19 19:56:57 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 19 Jun 2009 16:56:57 -0700 Subject: Checking for binary data in a string In-Reply-To: <20090619131858.1b4ade03@hematite.mv.qlogic.com> References: <20090619131858.1b4ade03@hematite.mv.qlogic.com> Message-ID: On 6/19/2009 1:18 PM Mitko Haralanov said... > I have a question about finding out whether a string contains binary > data? > The only other check that I can think of is to check every character in > the read-in string against string.printable but that will take a long > time. Well, probably not really. Consider that CPU speeds dramatically outperform network transport speeds such that by the time your local performance becomes an issue, you've got a _huge_ xmlrpc argument to pass over the wire... Emile From lie.1296 at gmail.com Fri Jun 19 20:07:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Jun 2009 00:07:27 GMT Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3LV_l.19708$y61.13502@news-server.bigpond.net.au> Jure Erzno?nik wrote: > On Jun 20, 1:36 am, a... at pythoncraft.com (Aahz) wrote: >> You should put up or shut up -- I've certainly seen multi-core speedup >> with threaded software, so show us your benchmarks! >> -- > > Sorry, no intent to offend anyone here. Flame wars are not my thing. > > I have shown my benchmarks. See first post and click on the link. > That's the reason I started this discussion. > > All I'm saying is that you can get threading benefit, but only if the > threading in question is implemented in C plugin. > I have yet to see pure Python code which does take advantage of > multiple cores. From what I read about GIL, this is simply impossible > by design. > > But I'm not disputing the fact that cPython as a whole can take > advantage of multiple cores. There certainly are built-in objects that > work as they should. I never used threading together with I/O intensively before, but I heard that I/O operations releases the GIL, and such they're similar to GIL-releasing C extensions which makes it possible to benefit from multicore in I/O bound pure python code. Perhaps we should have more built-in/stdlib operations that can release GIL safely to release GIL by default? And perhaps some builtin/stdlib should receive an optional argument that instruct them to release GIL and by passing this argument, you're making a contract that you wouldn't do certain things that would disturb the builtin/stdlib's operations; the specifics of what operations are prohibited would be noted on their docs. From usernet at ilthio.net Fri Jun 19 20:07:41 2009 From: usernet at ilthio.net (Tim Harig) Date: Sat, 20 Jun 2009 00:07:41 GMT Subject: Play MP3s from Windows References: Message-ID: On 2009-06-19, Arlie wrote: > print 'Duree du fichier : ',buf,' millisecondes' You can obviously make sure that 'buf' can be accessed as a string. > time.sleep(int(buf)/1000) The error seems to be having issues converting buf to an int. Could you possibly convert it to a string before converting it to an int? time.sleep(int(str(buf))/1000) From python at mrabarnett.plus.com Fri Jun 19 20:48:25 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 01:48:25 +0100 Subject: Play MP3s from Windows In-Reply-To: References: Message-ID: <4A3C31D9.8070100@mrabarnett.plus.com> Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : 298919 millisecondes > Traceback (most recent call last): > File "mp3.py", line 37, in > time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' > > The code: > > # -*- coding: utf-8 -*- > > import time > from ctypes import windll, c_buffer > > class mci: > def __init__(self): > self.w32mci = windll.winmm.mciSendStringA > self.w32mcierror = windll.winmm.mciGetErrorStringA > > def send(self,commande): > buffer = c_buffer(255) > errorcode = self.w32mci(str(commande),buffer,254,0) > if errorcode: > return errorcode, self.get_error(errorcode) > else: > return errorcode,buffer.value > > def get_error(self,error): > error = int(error) > buffer = c_buffer(255) > self.w32mcierror(error,buffer,254) > return buffer.value > > def directsend(self, txt): > (err,buf)=self.send(txt) > if err != 0: > print'Erreur',str(err),'sur',txt,':',buf > return (err,buf) > > mci=mci() > mci.directsend('open "d:\\Linger.mp3" alias toto') > mci.directsend('set toto time format milliseconds') > err,buf=mci.directsend('status toto length ') > print 'Duree du fichier : ',buf,' millisecondes' From the output it's clear that 'buf' contains '298919'. > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > time.sleep(int(buf)/1000) From the output it's clear that 'buf' contains ''. Are you expecting it to contain the length, like it did for the previous call? Perhaps you should just use the length returned by the previous call. > mci.directsend('close toto') > From manidevarajan at gmail.com Fri Jun 19 20:52:05 2009 From: manidevarajan at gmail.com (Terminator) Date: Fri, 19 Jun 2009 17:52:05 -0700 (PDT) Subject: What is the best method to match a pattern in set of lines Message-ID: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Hello, My requierment is to get the "Stick Tag" value from the below o/p and based on tag take different actions. What is the best way to implement it. I am new to Python, so appreciate any input. Command o/p: =================================================================== File: Packet.tcl Status: Needs Merge Working revision: 1.2.98 Result of merge Repository revision: 1.2.99 /auto/quality/CVS/tools/ext/ Packet.tcl,v Sticky Tag: rel-ip-branch (branch: 1.584.2) Sticky Date: (none) Sticky Options: (none) Requirement: If "Sticky Tag" is rel-ip-brach do A else "Sticky Tag" is rel-ipv6-branch do B Thanks in advance. From arlie.c at gmail.com Fri Jun 19 20:57:01 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 17:57:01 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: <1030835b-efca-4219-85e1-0afd31fbba13@x31g2000prc.googlegroups.com> On Jun 20, 8:07?am, Tim Harig wrote: > On 2009-06-19, Arlie wrote: > > > print 'Duree du fichier : ',buf,' millisecondes' > > You can obviously make sure that 'buf' can be accessed as a string. > > > time.sleep(int(buf)/1000) > > The error seems to be having issues converting buf to an int. ?Could you > possibly convert it to a string before converting it to an int? > > time.sleep(int(str(buf))/1000) I'm still getting same error. So I just did this: ... mci=mci() mci.directsend('open "d:\\Linger.mp3" alias toto') mci.directsend('set toto time format milliseconds') err,buf=mci.directsend('status toto length ') print 'Duree du fichier : ',buf,' millisecondes' soundlength = int(buf) / 1000 err,buf=mci.directsend('play toto from 0 to '+str(buf)) #time.sleep(int(buf)/1000) time.sleep(soundlength) mci.directsend('close toto') From arlie.c at gmail.com Fri Jun 19 21:05:03 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 18:05:03 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: On Jun 20, 8:48?am, MRAB wrote: > Arlie wrote: > > Hi, > > > Newbie here. I copied and pasted the code below. But when I ran it I > > got this error: > > > D:\>python mp3.py > > Duree du fichier : ?298919 ?millisecondes > > Traceback (most recent call last): > > ? File "mp3.py", line 37, in > > ? ? time.sleep(int(buf)/1000) > > ValueError: invalid literal for int() with base 10: '' > > > The code: > > > # -*- coding: utf-8 -*- > > > import time > > from ctypes import windll, c_buffer > > > class mci: > > ? ? def __init__(self): > > ? ? ? ? self.w32mci = windll.winmm.mciSendStringA > > ? ? ? ? self.w32mcierror = windll.winmm.mciGetErrorStringA > > > ? ? def send(self,commande): > > ? ? ? ? buffer = c_buffer(255) > > ? ? ? ? errorcode = self.w32mci(str(commande),buffer,254,0) > > ? ? ? ? if errorcode: > > ? ? ? ? ? ? return errorcode, self.get_error(errorcode) > > ? ? ? ? else: > > ? ? ? ? ? ? return errorcode,buffer.value > > > ? ? def get_error(self,error): > > ? ? ? ? error = int(error) > > ? ? ? ? buffer = c_buffer(255) > > ? ? ? ? self.w32mcierror(error,buffer,254) > > ? ? ? ? return buffer.value > > > ? ? def directsend(self, txt): > > ? ? ? ? (err,buf)=self.send(txt) > > ? ? ? ? if err != 0: > > ? ? ? ? ? ? print'Erreur',str(err),'sur',txt,':',buf > > ? ? ? ? return (err,buf) > > > mci=mci() > > mci.directsend('open "d:\\Linger.mp3" alias toto') > > mci.directsend('set toto time format milliseconds') > > err,buf=mci.directsend('status toto length ') > > print 'Duree du fichier : ',buf,' millisecondes' > > ?From the output it's clear that 'buf' contains '298919'. > > > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > > time.sleep(int(buf)/1000) > > ?From the output it's clear that 'buf' contains ''. Are you expecting it > to contain the length, like it did for the previous call? Perhaps you > should just use the length returned by the previous call. I actually did that and it's working fine now. Thanks. > > > mci.directsend('close toto') > > I just got the program from the web. I have never program in python but I'm taking the risk of replacing an existing perl program for a more readable code. As of now everything seems like a haze to me. I have read python tutorial just yesterday. I'm due to deliver this project in 36 hours or less. This is suppose to download mp3 file to client then connect to mysql get the person info and play appropriate mp3 for that person calling his full name. From gagsl-py2 at yahoo.com.ar Fri Jun 19 22:16:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Jun 2009 23:16:20 -0300 Subject: Blogger Widget web app References: <7b3f931c-7750-440d-8f91-315c4c04dc72@d2g2000pra.googlegroups.com> Message-ID: En Thu, 11 Jun 2009 16:44:03 -0300, steven.oldner escribi?: > Please give me directions on where to start researching for answers. > I probably can do the javascript, but I don't know where to start on > the Python. > > 1. Wife has a blogger blog and wants a widget to embed in the posts. > 2. Widget will have a form that readers can enter their name and url. > 3. Widget also lists in numeric order the name and url of all the > readers who signed up in that post. > 4. Son has an old PC he turned into a server, and installed Windows > IIS on it. I'd look in the Python Package Index http://pypi.python.org/ for existing solutions. -- Gabriel Genellina From exarkun at divmod.com Fri Jun 19 22:42:57 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 19 Jun 2009 22:42:57 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <3LV_l.19708$y61.13502@news-server.bigpond.net.au> Message-ID: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> On Sat, 20 Jun 2009 00:07:27 GMT, Lie Ryan wrote: > [snip] > >Perhaps we should have more built-in/stdlib operations that can release >GIL safely to release GIL by default? And perhaps some builtin/stdlib >should receive an optional argument that instruct them to release GIL >and by passing this argument, you're making a contract that you wouldn't >do certain things that would disturb the builtin/stdlib's operations; >the specifics of what operations are prohibited would be noted on their >docs. There would be a lot less useless discussion if people would do a minimal amount of checking to see if the ideas they're suggesting are at all feasible. Why don't you take a look at the CPython source and see if this is actually possible? If you're not comfortable diving into a C program, then maybe you could try to become so first, or refrain from making suggestions that rely on technical details you know nothing about? Jean-Paul From gagsl-py2 at yahoo.com.ar Fri Jun 19 23:15:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 00:15:55 -0300 Subject: Error in reg dll References: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Message-ID: En Tue, 16 Jun 2009 02:09:57 -0300, Girish escribi?: > I am not able to register DLL generated from py2exe > When I try to register the dll using the commant: regsve32 dspace.dll, > I am getting error saying :"DLLRegisterServer in dspace.dll failed. > Return code was: 0xc0000005" I don't think the problem is in your setup.py, but on Dspace.py or any module it uses. 0xc0000005 is an Access Violation - an attempt to read/write memory at an illegal address. Try removing pieces from Dspace.py until you find the culprit. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Jun 19 23:50:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 00:50:14 -0300 Subject: Getting a processes' name? References: <4CD74416FB9F204EA1258409610E5626AD127A@svits27.main.ad.rit.edu> Message-ID: En Tue, 16 Jun 2009 11:42:08 -0300, Daniel Merboth (RIT Student) escribi?: > My college uses a program called AccessGrid for video conferencing, and > it runs through pythonw.exe. It comes with a python script to kill all > processes and exit the program. The problem is, the script kills > everything related to pythonw.exe, including my open scripts. I'm > looking for a way to get the name of the window or the processname, or > something, to differentiate between the running versions of pythonw.exe. The lazy answer is to make a copy of pythonw.exe under another name, and use that to launch the other scripts... Another way would be to use ExeMaker [1] so the process name is not pythonw.exe but another one. http://effbot.org/zone/exemaker.htm -- Gabriel Genellina From clp2 at rebertia.com Fri Jun 19 23:51:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 20:51:39 -0700 Subject: IDLE comments In-Reply-To: <1245306236.3326.3.camel@jason-desktop> References: <1245306236.3326.3.camel@jason-desktop> Message-ID: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: > Why does IDLE use two hash marks for comments (##)? Most other editors > (Geany, SPE) use a single hash mark (#) to designate comments. I would guess to distinguish its (usually block) comments from manually-added (usually explanatory) comments, but this is just conjecture. > How does one change IDLE to use just a single (#) hash mark for comments? Edit its source code? The GUI doesn't appear to expose any option for it. Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Fri Jun 19 23:58:56 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 20 Jun 2009 15:58:56 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: <7a351vF1tjnsaU1@mid.individual.net> ryles wrote: > However, in 3.0 list > comprehensions are actually treated as list(). That's not quite true -- it would be rather inefficient if it was. The code generated for the LC is much the same as it was in 2.x. But the whole LC is put into a nested function so that the loop variables are local to it. -- Greg From greg at cosc.canterbury.ac.nz Sat Jun 20 00:09:08 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 20 Jun 2009 16:09:08 +1200 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: Message-ID: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Philip Semanchuk wrote: > try: > sem.acquire() # User hits Ctrl + C while this is waiting > except: > print "********* I caught it!" > Instead a KeyboardInterrupt error is propagated up to the interpreter > and the process is killed as if the try/except wasn't there at all. Not sure exactly what's happening, but I think I can guess. Python installs a signal handler for Ctrl-C that sets a flag in the interpreter. Every so many bytecodes executed, the flag is checked and KeyboardInterrupt raised if it's set. So there can be a short delay between the Ctrl-C signal being received and KeyboardInterrupt being raised, and it seems that this delay results in it happening after the try-except has exited. You could try using signal.signal() to install a handler for Ctrl-C that does nothing in a section around the sem.acquire call(). That should prevent the KeyboardInterrupt flag from being set, but the signal will still be occurring at the Unix level, so the system call will get interrupted. -- Greg From aahz at pythoncraft.com Sat Jun 20 00:17:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 21:17:50 -0700 Subject: Is this pylint error message valid or silly? References: <87eitg267e.fsf@benfinney.id.au> Message-ID: In article <87eitg267e.fsf at benfinney.id.au>, Ben Finney wrote: >Matthew Wilson writes: >> >> from datetime import datetime >> def f(c="today"): >> if c == "today": >> c = datetime.today() >> return c.date() > >* You're re-binding the parameter name ???c??? to something different within > the function: it starts out bound to the input string, but by the time > the function ends you're expecting it to be bound to a datetime > object. Instead, you should be binding a *different* name to the > datetime object you create inside the function, and using that for the > return statement. Actually, I disagree that this is necessarily bad, although it's often a yellow flag. The context in which it is possibly appropriate is when you want your function to handle multiple types for one parameter and you always cast the data to one single type. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sat Jun 20 00:27:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 21:27:51 -0700 Subject: Missing c.l.py posts (was Re: A question on scope...) References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> Message-ID: In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > >NB : answering the OP (original post didn't show up on c.l.py ???) Correct. There's a problem with the mail->news gateway, I think that MIME messages are failing. I "fixed" the problem for c.l.py.announce by making the list reject non-ASCII messages, but I don't think that's an option for python-list. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From vincent at vincentdavis.net Sat Jun 20 01:20:22 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Jun 2009 23:20:22 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) Message-ID: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> I currently have something like this. class applicant(): def __int__(self, x, y): self.randomnum = normalvariate(x, y) then other stuff x, y are only used to calculate self.randomnum and this seems to work. But I want self.randomnum to be 0 <= randomnum <= 100. The only way I can thing of to do this is is with a while statement and that seems more complicated than necessary. I would really like to keep it on one line. How would I do that? Thanks Vincent Davis From gervich at sbcglobal.net Sat Jun 20 02:55:04 2009 From: gervich at sbcglobal.net (Jason Gervich) Date: Fri, 19 Jun 2009 23:55:04 -0700 Subject: IDLE comments In-Reply-To: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> References: <1245306236.3326.3.camel@jason-desktop> <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> Message-ID: <1245480904.3326.21.camel@jason-desktop> Thanks, Chris. The best (and only) explanation I've heard so far. AS for as editing the source code, that's beyond my gnubyness. I thought there might be an easily accessible configuration file, but for the time I'll use it as is. I do wonder why in all these forum discussions about which Python editor to use, IDLE is seldom mentioned. Perhaps the Curse of the Gnuby lies upon it! Thanks for the quick response. Jason Gervich Santa Cruz, CA On Fri, 2009-06-19 at 20:51 -0700, Chris Rebert wrote: > On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: > > Why does IDLE use two hash marks for comments (##)? Most other editors > > (Geany, SPE) use a single hash mark (#) to designate comments. > > I would guess to distinguish its (usually block) comments from > manually-added (usually explanatory) comments, but this is just > conjecture. > > > How does one change IDLE to use just a single (#) hash mark for comments? > > Edit its source code? The GUI doesn't appear to expose any option for it. > > Cheers, > Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_re at fastmail.us Sat Jun 20 03:38:14 2009 From: john_re at fastmail.us (john_re) Date: Sat, 20 Jun 2009 00:38:14 -0700 Subject: Join Python Global Meeting Sunday June 21 using VOIP - BerkeleyTIP Message-ID: <1245483494.28252.1321307207@webmail.messagingengine.com> Join the friendly Python Global [& ALL FREE SW HW & CULTURE] community Meeting: this Sunday, June 21, using VOIP, 10A - 6P Pacific USA time [GMT - 8? 7? hours] = 1P - 9P Eastern USA = 6P - 2A??? GMT - Daylight savings correction? +7 hours? at the BerkeleyTIP Global Free SW HW & Culture meeting http://sites.google.com/site/berkeleytip/ CONNECT VIA VOIP (& IRC): Join IRC channel #berkeleytip on freenode.net, & we'll help get you connected on VOIP. Have a VOIP headset. http://sites.google.com/site/berkeleytip/remote-attendance LOCAL MEETING NEW LOCATION: Free speech cafe closed Sundays in summer. Watch the BTIP local list for final in person UCB meeting location details: http://groups.google.com/group/BerkTIP GENERIC HOURLY SCHEDULE, & MARK YOUR CALENDAR - NEXT 3 MEETINGS: Sun June 21, Sat July 4, Sun July 19 http://sites.google.com/site/berkeleytip/schedule Join the mailing list, introduce yourself, tell us what projects you are interested in, invite others to join your project: BTIP-Global http://groups.google.com/group/BerkTIPGlobal ===== HOT TOPICs: Oracle owns OpenOffice & MySQL - What help is needed? KDE 4 aps need work - especially Calendar?! Open Hardware - Robotics? POLL: ** How about 2x per month Weekday Evening BTIP-Global Meetings? ** 1) The Wednesday & Thursday _after_ the BTIP weekend meetings? 2) The Monday & Tuesday _before_ the BTIP weekend meetings? 3) Other? Your suggestions? - Join the mailing list & send in your opinions/thoughts/suggestions. GROUP PROJECT - Asterisk VOIP conference server: We've now got our own Asterisk VOIP conference server. [Thanks, Windsor & Jack! :) ] Help: - get a user channel members status page working - get SIP & Skype ability? http://sites.google.com/site/berkeleytip/remote-attendance YOUR PROJECT - LET US KNOW, GET SOME VOLUNTEER HELP: http://groups.google.com/group/BerkTIPGlobal VIDEOS - OPPORTUNITY - FINDER VOLUNTEER NEEDED No videos this month, cause David & I are too busy. Do you want to find some for us all to watch? Check out this link, email the list & let us know you'd like to volunteer. :) http://sites.google.com/site/berkeleytip/talk-videos See the mailing lists for the latest info/changes: http://sites.google.com/site/berkeleytip/mailing-lists JOIN THE ANNOUNCEMENT LIST - 1 or 2 announcements per month: http://groups.google.com/group/BerkTIPAnc FOR FORWARDING: You are invited to forward this message to anywhere appropriate. From piet at cs.uu.nl Sat Jun 20 04:19:28 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:19:28 +0200 Subject: KeyboardInterrupt eats my error and then won't be caught References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: >>>>> greg (g) wrote: >g> Philip Semanchuk wrote: >>> try: >>> sem.acquire() # User hits Ctrl + C while this is waiting >>> except: >>> print "********* I caught it!" >>> Instead a KeyboardInterrupt error is propagated up to the interpreter >>> and the process is killed as if the try/except wasn't there at all. >g> Not sure exactly what's happening, but I think I can guess. >g> Python installs a signal handler for Ctrl-C that sets a >g> flag in the interpreter. Every so many bytecodes executed, >g> the flag is checked and KeyboardInterrupt raised if it's >g> set. >g> So there can be a short delay between the Ctrl-C signal >g> being received and KeyboardInterrupt being raised, and it >g> seems that this delay results in it happening after the >g> try-except has exited. I think you are approaching the cause of the problem. Your answer triggered the following thought in my head: There are actually two exceptions occurring: One is the Ctrl-C, which as you correctly say, will probably delayed until there is a `check' in the interpreter (see also David Beazley's wonderful presentation on the GIL). The other one is the exception that is generated in the IPC code by returning a NULL. This one should caught by the except clause. As the call to sem.acquire releases and reacquires the GIL, I think signal processing will be done immediately. This causes the KeyboardInterrupt exception to occur immediately i.e. to interrupt the handling of the other exception. >g> You could try using signal.signal() to install a handler >g> for Ctrl-C that does nothing in a section around the >g> sem.acquire call(). That should prevent the KeyboardInterrupt >g> flag from being set, but the signal will still be occurring >g> at the Unix level, so the system call will get interrupted. Your suggestion seems to work: import posix_ipc import signal sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) signal.signal(signal.SIGINT, lambda sig, frame: None) status = [] try: status.append("Trying") sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except: status.append("I caught it!") print status sem.close() sem.unlink() prints: ['Trying', 'I caught it!'] I also tried some other variants, catching the KeyboardInterrupt at various places: This one prints: ['Trying', 'Keyboard Interrupt'] This suggests to me that the first exception handling is aborted by the Ctrl-C handling. import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) status = [] try: try: status.append("Trying") sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except: status.append("I caught it!") except KeyboardInterrupt: status.append("Keyboard Interrupt") print status sem.close() sem.unlink() And this one prints: ['Trying', 'I caught it!'] import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) status = [] try: status.append("Trying") try: sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except KeyboardInterrupt: status.append("Interrupt") except: status.append("I caught it!") print status sem.close() sem.unlink() I was actually a bit surprised that the addition of the try/except KeyboardInterrupt helps solve the problem but that apparently the exception handler is not executed. Folding the two try's into one with two except clauses will not help as there are indeed two exceptions to be handled. I also added traceback printout in the outer exception handler and it points to the sem.acquire line. My conclusion is that if there are two exceptions at the same time, the inner exception handler is interrupted by the other exception even before the except clause can be entered. And only the outer one is really executed. This explains the behaviour that the OP described. I think you can only have two exceptions at the same time if at least one of them is a signal. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Sat Jun 20 04:34:58 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:34:58 +0200 Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Sorry, just a few more thoughts: >JE> Does anybody know why GIL can't be made more atomic? I mean, use >JE> different locks for different parts of code? >JE> This way there would be way less blocking and the plugin interface >JE> could remain the same (the interpreter would know what lock it used >JE> for the plugin, so the actual function for releasing / reacquiring the >JE> lock could remain the same) >JE> On second thought, forget this. This is probably exactly the cause of >JE> free-threading reduced performance. Fine-graining the locks increased >JE> the lock count and their implementation is rather slow per se. The major obstacles are the refcounts. It would mean that each refcounted object would need a separate lock including constants like 0, 1, True, None. You would have much more locking and unlocking then with the GIL. So to get rid of it first the refcounting has to go. But that is not sufficient. When the GIL will be removed I suspect that many concurrent programs will start to fail subtly because they make assumptions about the atomicity of the operations. In CPython each bytecode is atomic, but when there is no GIL this is no longer true. Java has defined this quite rigorously in its memory model (although there first memory model had subtle bugs): Read and write operations on 32-bit quantities are atomic, others not. This means that on a 64-bit system, where pointers are 64-bit even assignments on variables of object types are not atomic and have to be protected with synchronized. (My info is a few years old, so in the meantime it may have changed.) In a GIL-less python the same would be true. Of course the hardware that your program is running on could have atomic read/writes on 64-bit quantities but if you rely upon that your program may no longer be portable. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From mail at timgolden.me.uk Sat Jun 20 04:39:10 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 20 Jun 2009 09:39:10 +0100 Subject: How to check if file is open on Windows XP? In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> Message-ID: <4A3CA02E.7080209@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I'm looking for a fascility that can check if the file is open on Windows XP > and if the file is open (say a notepad file is open), I want to close that file > (i.e the notepad application) In short, this is far trickier than you might imagine. It's come up a number of times on the Python / Python-win32 lists. A recent thread is here: http://mail.python.org/pipermail/python-list/2009-May/713077.html But if you simply Google for things like: site:mail.python.org sysinternals handle You'll get a bunch of hits asking / answering the same thing. TJG From piet at cs.uu.nl Sat Jun 20 04:45:08 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:45:08 +0200 Subject: Status of Python threading support (GIL removal)? References: Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> I have shown my benchmarks. See first post and click on the link. >JE> That's the reason I started this discussion. >JE> All I'm saying is that you can get threading benefit, but only if the >JE> threading in question is implemented in C plugin. >JE> I have yet to see pure Python code which does take advantage of >JE> multiple cores. From what I read about GIL, this is simply impossible >JE> by design. In fact, at least theoretically, your original application could benefit from multiple cores. Take this scenario: You have one thread that reads from a file. On each read the GIL is released until the read has completed. In the meantime the other thread could do some CPU-intensive work. Now if the read comes entirely from the O.S. cache it is also CPU-bound. So there a second core comes in handy. Now usually these reads will not consume so much CPU so it will probably be hardly noticeable. But if you would have some kind of CPU-intensive User-space File System, for example with compression and/or encryption and the data is in memory you might notice it. In this example all your application code is written in Python. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Sat Jun 20 04:49:00 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:49:00 +0200 Subject: Status of Python threading support (GIL removal)? References: Message-ID: >>>>> Ross Ridge (RR) wrote: >RR> By definition an I/O bound thread isn't CPU bound so won't benefit from >RR> improved CPU resources. But doing I/O is not the same as being I/O bound. And Python allows multithreading when a thread does I/O even if that thread is not I/O bound but CPU bound. See my other posting for an example. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From ldo at geek-central.gen.new_zealand Sat Jun 20 04:51:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 20:51:07 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> <20090619134015.349ba199@malediction> Message-ID: In message <20090619134015.349ba199 at malediction>, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 17:53:40 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: >> >> > On Thu, 18 Jun 2009 10:33:49 +1200 >> > Lawrence D'Oliveiro wrote: >> > >> >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev >> >> wrote: >> >> >> >>> On Wed, 17 Jun 2009 23:04:37 +1200 >> >>> Lawrence D'Oliveiro wrote: >> >>> >> >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev >> >>>> wrote: >> >>>> >> >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 >> >>>>> Lawrence D'Oliveiro wrote: >> >>>>> >> >>>>>>> Why not use hex representation of md5/sha1-hashed id as a >> >>>>>>> path, arranging them like /path/f/9/e/95ea4926a4 ? >> >>>>>>> >> >>>>>>> That way, you won't have to deal with many-files-in-path >> >>>>>>> problem ... >> >>>>>> >> >>>>>> Why is that a problem? >> >>>>> >> >>>>> So you can os.listdir them? >> >>>> >> >>>> Why should you have a problem os.listdir'ing lots of files? >> >>> >> >>> I shouldn't, and I don't ;) >> >> >> >> Then why did you suggest that there was a problem being able to >> >> os.listdir them? >> > >> > I didn't, OP did ... >> >> Then why did you reply to my question "Why is that a problem?" with >> "So that you can os.listdir them?", if you didn't think there was a >> problem (see above)? > > Why do you think that if I didn't suggest there is a problem, I think > there is no problem? It wasn't that you didn't suggest there was a problem, but that you suggested a "solution" as though there was a problem. > Why would you want to listdir them? It's a common need, to find out what's in a directory. > I can imagine at least one simple scenario: you had some nasty crash > and you want to check that every file has corresponding, valid db > record. But why would that be relevant to this case? From ldo at geek-central.gen.new_zealand Sat Jun 20 04:54:03 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 20:54:03 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: In message , Lie Ryan wrote: > Lawrence D'Oliveiro wrote: > >> In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan >> wrote: >> >>> Yeah, it might be possible to just mv the file from outside, but not >>> being able to enter a directory just because you've got too many files >>> in it is kind of silly. >> >> Sounds like a problem with your file/directory-manipulation tools. > > try an `ls` on a folder with 10000+ files. > > See how long is needed to print all the files. As I've mentioned elsewhere, I had scripts routinely dealing with directories containing around 400,000 files. > Ok, now pipe ls to less, take three days to browse through all the > filenames to locate the file you want to see. Sounds like you're approaching the issue with a GUI-centric mentality, which is completely hopeless at dealing with this sort of situation. From pavlovevidence at gmail.com Sat Jun 20 05:02:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 02:02:34 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> On Jun 19, 4:42?pm, Christian Heimes wrote: > OdarR schrieb: > > > On 19 juin, 21:41, Carl Banks wrote: > >> He's saying that if your code involves extensions written in C that > >> release the GIL, the C thread can run on a different core than the > >> Python-thread at the same time. ?The GIL is only required for Python > >> code, and C code that uses the Python API. ?C code that spends a big > >> hunk of time not using any Python API (like, as Skip pointed out, a > >> matrix multiply) can release the GIL and the thread can run on a > >> different core at the same time. > > > I understand the idea, even if I don't see any examples in the > > standard library. > > any examples ? > > http://svn.python.org/view/python/trunk/Modules/posixmodule.c?revisio... > > Search for Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS > > > yes, I also speak about hard computation that could benefit with > > multiple cores. > > Hard computations gain more speed from carefully crafted C or Fortran > code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or > parallelized algorithms. If you start sharing values between multiple > cores you have a serious problem. > > Oh, and use NumPy for the job ;) > > >> I wish people would just say, "This is a limitation of > >> CPython. ?There are reasons why it's there, and it helps some people, > >> but unfortunately it has drawbacks for others", instead of the typical > >> "all u hav 2 do is rite it in C LOL". > > > "LOL" > > I would like to say such thing about my weather...I live in Europe in > > a rainy country. > > It *is* a well known limitation of Python. All the nice 'n shiny syntax > and features are coming with a cost. Python is a powerful language and > good tool for lots of stuff. But Python is and will never become the > ?bertool that solves every problem perfectly. At some point you need a > different tool to get the raw power of your machine. C (and perhaps > Fortran) are the weapons of choice for number crunching. This is the narrowminded attitude that irritates me. Here's the thing: not everyone complaining about the GIL is trying to get the "raw power of their machines." They just want to take advantage of multiple cores so that their Python program runs faster. It would be rude and presumptuous to tell such a person, "Well, GIL isn't that big of a deal because if you want speed you can always rewrite it in C to take advantage of multiple cores". Carl Banks From pavlovevidence at gmail.com Sat Jun 20 05:16:17 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 02:16:17 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <14f2ed75-20cd-4850-bc2e-6ea17a21ba51@r31g2000prh.googlegroups.com> On Jun 19, 4:35?pm, a... at pythoncraft.com (Aahz) wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854c... at z7g2000vbh.googlegroups.com>, > Carl Banks ? wrote: > >I wish Pythonistas would be more willing to acknowledge the (few) > >drawbacks of the language (or implementation, in this case) instead of > >all this rationalization. ? > > Please provide more evidence that Pythonistas are unwilling to > acknowledge the drawbacks of the GIL. I will not, since I was not making an assertion, but an observation that some Pythonistas ignore (and even outright dismiss) claims that Python has a drawback by countering with a suggestion that they should be doing it some other, often more obtuse, way anyway--and expressing a wish that I could observe this less often. Carl Banks From kay at fiber-space.de Sat Jun 20 05:36:22 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 20 Jun 2009 02:36:22 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Message-ID: > You might want to read about "The Problem with Threads": > > http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf > > and then decide to switch to an appropriate concurrency model for your use > case. and to a programming language that supports it. From contact at xavierho.com Sat Jun 20 05:37:20 2009 From: contact at xavierho.com (Xavier Ho) Date: Sat, 20 Jun 2009 19:37:20 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> While there are a lot of valid ways to do it, anything you do will change the outcome of the probability anyway. I'm assuming you are just looking to clamp the values. Try this: http://codepad.org/NzlmSMN9 (it runs the code, too) ========================================== # Clamp a normal distribution outcome import random class applicant(): def __init__(self, x, y): self.randomnum = clamp(random.normalvariate(x, y), 0, 100) def clamp(input, min=0, max=100): """Clamps the input between min and max. if input < min, returns min min < input < max, returns input input > max, returns max Default: min = 0, max = 100.""" if input < min: return min elif input > max: return max else: return input if __name__ == "__main__": for num in range(10): print applicant(random.randint(0,100), random.randint(0,100)).randomnum ====================================================== Or you could just use randint() if you only wanted a linear distribution. PS: Thanks, btw, new to python myself also, and looking into this was cool. :] Best regards, 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 Sat, Jun 20, 2009 at 3:20 PM, Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. I would really like to keep it > on one line. How would I do that? > > Thanks > Vincent Davis > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sat Jun 20 05:38:00 2009 From: http (Paul Rubin) Date: 20 Jun 2009 02:38:00 -0700 Subject: Question about None References: Message-ID: <7xzlc3gs93.fsf@ruckus.brouhaha.com> Paul LaFollette writes: > So, what I would like is some sort of object that is a "kind of" > everything but contains nothing, a unique minimal element of the > partial ordering imposed on the set of classes by the inheritance > heierarchy. Whilst I am not naive mathematically, I am relatively > naive in the area of language design. In my naivete, it seemed to me > that None could have been designed to be such a thing. Apparently > that is incorrect. I don't remember if I linked to this article: http://en.wikibooks.org/wiki/Haskell/Denotational_semantics You might like it. If you want to learn some contemporary programming language theory at a mathematical level, start with Harper's "Practical Foundations for Programming Languages": http://www.cs.cmu.edu/~rwh/plbook/book.pdf From ldo at geek-central.gen.new_zealand Sat Jun 20 06:21:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 22:21:12 +1200 Subject: File Syncing References: Message-ID: In message , dads wrote: > What would I have to learn to be able to sync the text files on each > server? How big is the text file? If it's small, why not have your script read it directly from a master server every time it runs, instead of having a local copy. From Olivier.Darge at gmail.com Sat Jun 20 06:24:37 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 20 Jun 2009 03:24:37 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <9ec761b0-3782-4153-a0d8-9b5f4fb171fd@t11g2000vbc.googlegroups.com> On 20 juin, 11:02, Carl Banks wrote: > Here's the thing: not everyone complaining about the GIL is trying to > get the "raw power of their machines." ?They just want to take > advantage of multiple cores so that their Python program runs > faster. > > It would be rude and presumptuous to tell such a person, "Well, GIL > isn't that big of a deal because if you want speed you can always > rewrite it in C to take advantage of multiple cores". merci Carl, you expressed what I would like to tell. Olivier From sumerc at gmail.com Sat Jun 20 06:58:02 2009 From: sumerc at gmail.com (k3xji) Date: Sat, 20 Jun 2009 03:58:02 -0700 (PDT) Subject: YASS (Yet Another Success Story) Message-ID: <534f19f6-181c-42ee-803c-9bd867b6d053@n4g2000vba.googlegroups.com> Hi all, Started a project year ago with hard goals in mind : Developing a game server which can handle thousands of clients simultaneously.System must be stable, scalable, efficient, and if the client need to migrate the server to another OS, this will be a matter of time, if possible without changing any code. Also, the system should be controlled via database operations, meaning some specific DB changes should be determined by the system on-the-fly and necassary processing should be done at runtime(Client timeout values, adding new game lobbies..etc..) And all of this should be a one-man project dues to the fact that the project is a volunteer work, thus is separate from our ordinary jobs, there is no budget:). This was 8 months ago, and I still remember we are talking with my colleguae to decide which programming language is better for our requirements. We wrote the tradeoffs of different languages on board and compare our objectives against them by giving numbers. I remember, the last three standing programming languages are: C++, Java, and Python. We decided that code maintability and stability is cheaper than native code efficiency and also easy porting is important. C++ is only successfull on efficiency but maintaining the code, even if we use 3rd party libraries is a nightmare, especially in a massive multithreaded project like a game server. Also, we decided a game server's bottleneck is on network I/O other than the actual processing which means there should be not so much performance degradation between C++ and an interpreted language. So the final is between Java and Python. I know Java has been adding very good optimizations for interpreter efficiency over the years(JIT compiling..etc.) And I remember somewhere reading that Java is 10 times faster than Python. But Python, on the other hand is a perfect language and very simple which means the project may be completed sooner and efficiency again will be not a so much problem as the bottleneck should be on network I/O if the server is coded correctly. Although we have made this decision, we still had some doubts but we move on with Python. I don't know Python at the time and only coded few simple projects with it. I started with reading python socket/threading tutorials, then I downloaded and read actual Python code to get deeper and deeper. This was 10 months ago. Now we have been able to implement the game server with Python using MySQL as a backend DB and currently 5000 players (increasing) are playing multiplayer games with it with a system load of 0.4-0.8(see Unix getloadavg output) on a 1.8 Ghz Dual Xeon processor. Let me give some benchmarks, please note that one thing I learn through this journey is that testing/benchmarking a server software is really difficult and maybe in some conditions impossible thing to do correctly as inactive client connections may cause indeterministic behavior and also WAN latencies are very different than LAN latencies..etc. Anyway, we had to do a benchmark before going with this server on live. We installed a UnrealIRCd server which is also using select() as an I/O paradigm just as we are and supporting many of the features we have. This server is a IRC server written in C and being written since nearly 10 years. We connect thousands of clients and do simple messaging between them. I don't have an official test/benchmark result or a nice graph for this, however the system running UnrealIRCD is locked up when processing 4 Mb/sec of data, where our 6 month old Python server is locking up the system resources after 3.5 Mb/sec. We have done other tests including stressing server accept(), adding inactive connections but I am really not %100 confident about the test environments and do not want to give you false impression. But we decided that this 0.5 Mb factor is still not enough for us and we move on to inspect what is really causing the bottlenecks and how to optimize them. Here, to be honest, I cannot see very uch help from Python. Profiling/Optimization is the only place I am upset with Python. Here is the requirements for the profiler: I want to be able to enable/disable profiler tool on the fly without requiring any kind of restart and the profiler should be multithreaded (thus thread-safe). I decided that cProfiler and other profiler tools are in need of some updates to fulfill my req?rements, which makes me write my own profiler. It took me 3 days to come up with a profiler that satisfies my requirements, this profiler will profile only my code, meaning the server code to avoid performance degradation and timings will need not be nested-aware and timing precision is not very important (other than secs). I have implemented the profiler with the help of decorators and started profiling my code on-live. Here comes the another part of Python that is some kind of shady: optimization. After profiling the code, it turns out most of the time is spent on the following: 1) Selecting/Deselecting interest sets for select() 2) Unnecessary function calls. (for integrating some OOP concepts, I think we have overlooked the performance factor and there really are some functions which can be inlined but declared as a function) 3) Redundant try-except's in all over place(Again our fault to make the system stable, we have put some debug purposed-assert like try- excepts in the main server flow.) After, looking on these subjects for 2 weeks, we came up with solutions for all of them, and we see that it is working approximately 5 times faster. This test is done in live, we run two server processes which are all running on a predefined CPU(means CPU affinity of the process is set before hand to avoid mis-interpreting system diagnose tools like top(1)). When same client number is connected to both servers, the second one is giving 5 times better values in top and ps tools. Also, the processing time (meaning the server loop except the select() call) is also 10 times faster than before. Just one note about optimizing Python code: do not optimize Python code based on your assumptions, just go and test if it really runs faster. I don't want to go to details of this hint, but believe me making Python code optimized may be very very tricky. It is then I decided to write up here this as a success story, as I am very newcomer to Python but come up with a nearly commercial product in a very short period of time and I don't think this is about my personal characteristics and intelligence or so:), as I am old enough to know/meet that there are much much more brilliant people than I am and they also have similar experiences with Python. So, one last note: every software project goes same tasks as above often much much more officially and carefully, I would suggest managers to see that just do not listen to the ordinary brain-washes. Python is a great choice for easy developing, easy debugging, easy maintaining and most importantly very very time-friendly. Of course there will be tasks .n which Python is suitable, but hey, if it Python is in the list, take it seriously. Thanks, Special thanks to people in this group who had answered my silly Python questions along the way. S?mer Cip From Yell123 at aol.com Sat Jun 20 07:12:48 2009 From: Yell123 at aol.com (Yell123 at aol.com) Date: Sat, 20 Jun 2009 07:12:48 EDT Subject: Python in Nashville Message-ID: I maintain a math hobby - magic square web page _http://www.knechtmagicsquare.paulscomputing.com/_ (http://www.knechtmagicsquare.paulscomputing.com/) A very bright fellow in England sent me a algorithm written in python to solve a problem I was working on. I can't seem to get it to work ... syntax problems.... The segment below gives the explanation and the code: If you are interested in the problem this solves ... see section 1 on my website "Topographical Model For the Magic Square" Sorry about the delay in replying; I've been having email problems.] > I read a article by your wife on magic squares. I have been fooling > around with magic square models. I read your bio and see you did some work > with random walk stuff. I have been wanting a algorithm ... ( perhaps a > Greedy algorithm) that would calculate the amount of retained water for any > order of magic square. ( see topographical model setion I on web link > below) Hm, interesting problem. Let's see. (Please forgive me if some or all of what I'm about to say is totally familiar and/or obvious to you.) If I've understood you right, your problem is as follows. Call the number written in each cell its "height". Define the "water height" of a cell to be the smallest N such that there's a path from that cell to the outside of the square using only cells of height <= N. So, when you pour an infinite amount of water over the square and let it settle, each cell ends up with water up to its water height, if that's bigger than its height. Then the "capacity" of the square is the sum of (water height - height) over cells for which that's positive, and you want to calculate the capacity of a given square. So, the following seems like a pretty good algorithm. It's a bit like Dijkstra's shortest-path algorithm. It needs a data structure called a "priority queue", which means a container that stores objects along with numbers called their "priorities", and has efficient ways of doing (1) add an object to the queue and (2) pull out the object with highest priority. We'll keep track of an upper bound on the water height for each cell, and use the queue to store cells for which we might be able to reduce the upper bound. No, actually we'll use it to store cells that might enable us to reduce their neighbours' upper bounds. 1. For each cell, set bound(cell) = n^2. (This is a very boring upper bound on the water height of the cell.) 2. For each cell on the edge of the square: 2a. Set bound(cell) = height(cell). 2b. Put that cell into the queue with priority -bound(cell). (So lower cells have higher priority. Actually, many priority queue implementations already use the "smaller number = higher priority" convention.) 3. While the queue isn't empty: 3a. Pull out the highest-priority cell from the queue. 3b. For each neighbour of that cell: 3b1. Let b = max(bound(cell),height(neighbour)). 3b2. If if bound(neighbour) > b: 3b2a. Set bound(neighbour) = b. 3b2b. Add the neighbour to the queue with priority -b. When this is finished, for every cell bound(cell) should equal (not just be an upper bound for) the cell's water height, because: 1. bound(cell) is always an upper bound on the cell's water height, because the only way it gets decreased is when we find that the cell has a neighbour whose water height is known to be <= its new value. (So there's a path from the cell to the edge, using nothing higher than that value, beginning with that neighbour.) 2. For cells along the edge, bound(cell) equals the cell's water height, because for these cells height = water height, and right at the start we set bound = height. 3. Suppose that when the algorithm finishes bound(cell) is actually bigger than cell's water height w. Then there is a path from the cell to the edge using nothing of height > w. Follow that path until you find a cell for which bound <= w. (There must always be one, since bound = height for edge cells and the last cell on our path is an edge cell and has height <= w.) Then we've found two adjacent cells of height <= w, one of which has bound <= w and one of which as bound > w. But at some point the former must have been put into the queue with bound <= w; when it came out, its neighbour would have been examined and had its bound decreased to <= w. Contradiction. >From 1 and 3, we find that at the end of the algorithm the bounds equal the water heights. Now we can just sum max(bound-height,0) over all cells, and get the total capacity of the square. Here's some Python code that does it (rather inefficiently): def process(square): n = len(square) # square is a list of lists bounds = [n*[n*n] for i in range(n)] queue = [] # lousy implementation, just for algorithm testing # head of queue is last element # big numbers for high priority for i in range(n-1): bounds[i][0] = square[i][0] queue.append((-bounds[i][0],i,0)) bounds[n-1][i] = square[n-1][i] queue.append((-bounds[n-1][i],n-1,i)) bounds[i+1][n-1] = square[i+1][n-1] queue.append((-bounds[i+1][n-1],i+1,n-1)) bounds[0][i+1] = square[0][i+1] queue.append((-bounds[0][i+1],0,i+1)) while queue: queue.sort() (b,i,j) = queue.pop() for (di,dj) in [(-1,0),(1,0),(0,-1),(0,1)]: u=i+di; v=j+dj if 0<=u0: s += delta return s Testing on one of your examples: >>> capacity([[6,26,49,34,35,13,12],[5,48,1,28,30,36,27], [47,2,19,20,21,29,37],[46,17,10,25,7,32,38],[45,24,22,3,33,9,39], [11,44,31,23,8,40,18],[15,14,43,42,41,16,4]]) 320 (Your page says 321, but I think 320 is correct. The sum of the heights in the submerged region is 394, not 393.) How efficient is this? Well, it's not quite obvious to me that a cell can't be put into the queue more than once, but I think that should be rare. So let's suppose that typically each cell goes in once. The queue should never be bigger than the number of cells aside from complications that arise when a cell is inserted more than once; it certainly shouldn't be bigger than, say, 4 times the number of cells. And each priority queue operation should take no worse than some modest multiple of log(queue_size) basic operations. So the total time to process the whole square shouldn't be worse than some small multiple of n^2 log n. That seems like about the best you could reasonably expect. (I have another approach in mind that might reduce that to n^2 f(n) where f grows even more slowly when n is very large, but at the cost of greater complexity when n is not very large. I bet you'll only be doing this for n not very large.) Note: the idiotic "sort the list every time" priority queue implementation in the Python code above is emphatically *not* suitable for production use. Find a proper priority queue implementation in your language of choice. -- g If some one could help me get this working ... I would be grateful. I have loaded Python Ver 2.6 ... but when I paste this code in it keeps giving me errors. Thanks Craig Knecht **************A Good Credit Score is 700 or Above. See yours in just 2 easy steps! (http://pr.atwola.com/promoclk/100126575x1222585064x1201462784/aol?redir=http://www.freecreditreport.com/pm/default.aspx?sc=668072&hmpgID=62&bcd= JunestepsfooterNO62) -------------- next part -------------- An HTML attachment was scrubbed... URL: From piet at cs.uu.nl Sat Jun 20 07:41:36 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 13:41:36 +0200 Subject: KeyboardInterrupt eats my error and then won't be caught References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: After my previous experiment I was curious how this works with input(). I replaced the sem.acquire() with raw_input() and ran the same tests. Now the inner exception is really taken so it works like the OP expected. The exception, however is KeyboardInterrupt, not the special exception from the IPC module. So I looked in the source code how they did it: The code is in Parser/myreadline.c. This code for input in function calls PyErr_CheckSignals() and PyOS_InterruptOccurred() for a proper handling of the interrupt. So it seems the OP should do something similar. Onl;y to deliver the custom error you will have to do some other stuff. I don't know what but maybe calling PyErr_SetString is sufficient as it might overwrite the KeyboardInterrupt stuff. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From castironpi at gmail.com Sat Jun 20 07:41:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 20 Jun 2009 04:41:46 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: <01a81c22-6da3-4bb9-a359-8ff6fc1270c3@l34g2000vbi.googlegroups.com> On Jun 19, 7:00?am, "Rhodri James" wrote: > On Fri, 19 Jun 2009 14:24:34 +0100, Aaron Brady ? > wrote: > > > You are not being any help, Rhodri, in your question. > > To you, perhaps not. ?To me, it has at least had the effect of making > what you're trying to do (write a pythonic object database) clearer. I stand corrected. Some help you were. I have nothing further to say about it. From python at mrabarnett.plus.com Sat Jun 20 08:34:00 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 13:34:00 +0100 Subject: IDLE comments In-Reply-To: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> References: <1245306236.3326.3.camel@jason-desktop> <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> Message-ID: <4A3CD738.8030807@mrabarnett.plus.com> Chris Rebert wrote: > On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: >> Why does IDLE use two hash marks for comments (##)? Most other editors >> (Geany, SPE) use a single hash mark (#) to designate comments. > > I would guess to distinguish its (usually block) comments from > manually-added (usually explanatory) comments, but this is just > conjecture. > The menu has the entries "Comment Out Region" and "Uncomment Region" so that you can disable lines of code by turning them into comments and then uncomment them again. By using "##" it can distinguish between comments that it has created from those that you might have added later, which start with one "#". >> How does one change IDLE to use just a single (#) hash mark for comments? > > Edit its source code? The GUI doesn't appear to expose any option for it. > From vincent at vincentdavis.net Sat Jun 20 08:54:23 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 06:54:23 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> Message-ID: <77e831100906200554h6068ac6k1b7ad97cc3e560dd@mail.gmail.com> > # Clamp a normal distribution outcome > > import random > > class applicant(): > ??? def __init__(self, x, y): > ??????? self.randomnum = clamp(random.normalvariate(x, y), 0, 100) > > def clamp(input, min=0, max=100): > ??? """Clamps the input between min and max. > > ??? if? input < min, returns min > ??????? min < input < max, returns input > ??????? input > max, returns max > > ??? Default: min = 0, max = 100.""" > ??? if input < min: > ??????? return min > ??? elif input > max: > ??????? return max > ??? else: > ??????? return input > > if __name__ == "__main__": > ??? for num in range(10): > ??????? print applicant(random.randint(0,100), > random.randint(0,100)).randomnum Why not have the def clamp inside the class? I would prefer to keep everything I need for the class together. I am new to classes but I have to say things like if __name__ == "__main__": have no intuitive meaning to me. It is true I don't know what __name__ and __main__ do and I can look it up but I don't even have a guess based on the names and usage. I am Now not sure if that is what I want or If I want to redraw from the distribution. I am wanting to simulate test scores. My option see to be to draw from a normal (I don't want linear) distribution and scale it to 0-100 or clamp it as you (Xavier) suggested or draw from the distribution again (this is what I was thinking) I think this is still what I want but I should look up the implications of each. The problem I have with the clamp is that the tails in the sample could be large. Thanks Vincent From contact at xavierho.com Sat Jun 20 09:01:58 2009 From: contact at xavierho.com (Xavier Ho) Date: Sat, 20 Jun 2009 23:01:58 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <2d56febf0906200600y36dd20d8ica7d08bfc5391e60@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <77e831100906200554h6068ac6k1b7ad97cc3e560dd@mail.gmail.com> <2d56febf0906200600y36dd20d8ica7d08bfc5391e60@mail.gmail.com> Message-ID: <2d56febf0906200601i634f1f49g6253db8eb91f0176@mail.gmail.com> (sorry Vincent, I sent it to you but not the mailing list.) Good luck, here are my answers: Why not have clamp in the class? Because Clamp itself is a reusable function. I was rather surprised it's not in the standard math module. if __name__ == "__main__" is only meaningful when the .py file itself is run as the main file (like typing in python name.py that has this code in the console). Otherwise if this file was imported and run in any other python run-time, including the standard console, the "__main__" part won't execute at all. The only purpose of that was to print out 10 random samples. If you're not sure if this is what you want, then um.. not much I can do there. What is this class originally for? If you feel the clamp is too huge, well, I'm always interested in improvements/alternatives! Best regards, 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 Sat, Jun 20, 2009 at 10:54 PM, Vincent Davis wrote: > > # Clamp a normal distribution outcome > > > > import random > > > > class applicant(): > > def __init__(self, x, y): > > self.randomnum = clamp(random.normalvariate(x, y), 0, 100) > > > > def clamp(input, min=0, max=100): > > """Clamps the input between min and max. > > > > if input < min, returns min > > min < input < max, returns input > > input > max, returns max > > > > Default: min = 0, max = 100.""" > > if input < min: > > return min > > elif input > max: > > return max > > else: > > return input > > > > if __name__ == "__main__": > > for num in range(10): > > print applicant(random.randint(0,100), > > random.randint(0,100)).randomnum > > Why not have the def clamp inside the class? I would prefer to keep > everything I need for the class together. > I am new to classes but I have to say things like if __name__ == > "__main__": have no intuitive meaning to me. It is true I don't know > what __name__ and __main__ do and I can look it up but I don't even > have a guess based on the names and usage. > > I am Now not sure if that is what I want or If I want to redraw from > the distribution. I am wanting to simulate test scores. My option see > to be to draw from a normal (I don't want linear) distribution and > scale it to 0-100 or clamp it as you (Xavier) suggested or draw from > the distribution again (this is what I was thinking) I think this is > still what I want but I should look up the implications of each. The > problem I have with the clamp is that the tails in the sample could be > large. > > Thanks > Vincent > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Jun 20 09:12:18 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 14:12:18 +0100 Subject: Python in Nashville In-Reply-To: References: Message-ID: <4A3CE032.6030701@mrabarnett.plus.com> Yell123 at aol.com wrote: > > I maintain a math hobby - magic square web page > > http://www.knechtmagicsquare.paulscomputing.com/ > > > A very bright fellow in England sent me a algorithm written in python to > solve a problem I was working on. I can't seem to get it to work ... > syntax problems.... > > [snip] > > *If some one could help me get this working ... I would be grateful.* > > ** > > *I have loaded Python Ver 2.6 ... but when I paste this code in it keeps > giving me errors.* > Are you trying to paste it in IDLE's interactive prompt? That can be difficult! :-) If I paste it all at once I get a syntax error, but if I paste one function at a time then it's OK. From skip at pobox.com Sat Jun 20 09:36:52 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 20 Jun 2009 08:36:52 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <19004.58868.719487.153677@montanaro.dyndns.org> Carl> Here's the thing: not everyone complaining about the GIL is trying Carl> to get the "raw power of their machines." They just want to take Carl> advantage of multiple cores so that their Python program runs Carl> faster. If their code is CPU-bound it's likely that rewriting critical parts in C or using packages like numpy would improve there performance with or without multi-threading. For people who aren't used to C there are tools like Pyrex and Cython which provide a middle road. Skip From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 09:39:51 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 20 Jun 2009 23:39:51 +1000 Subject: timeit and __future__ References: Message-ID: <0058c162$0$9746$c3e8da3@news.astraweb.com> Karl Chen wrote: > > I wanted to time something that uses with_statement, in python2.5. > Importing __future__ in the statement or the setup doesn't work > since it's not the beginning of the code being compiled. Other > than using a separate module, I could only come up with this: > > timeit.template = 'from __future__ import with_statement\n' + > timeit.template > > timeit should directly support importing __future__ stuff... Yes, it probably should. Please make a bug report/feature request at the Python bug tracker. If you have a patch, that would be even better. http://bugs.python.org/ -- Steven From davea at ieee.org Sat Jun 20 09:57:53 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 09:57:53 -0400 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <4A3CEAE1.4030509@ieee.org> Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. I would really like to keep it > on one line. How would I do that? > > Thanks > Vincent Davis > > There are at least two interpretations to your requirement, both of which change the distribution. So you have to specify what the real distribution is that you want. 1) clamp - see Xavier's response. This will give you more values at exactly 100 and/or exactly 0 than normalvariate would specify, 2) discard - this will throw away any values outside the range, and try again. And in this case, a loop is essential, plus some mechanism to handle the case where the loop would never terminate. For example, suppose x is 10000. From lucafbb at gmail.com Sat Jun 20 10:17:01 2009 From: lucafbb at gmail.com (Luca) Date: Sat, 20 Jun 2009 16:17:01 +0200 Subject: raw_input with a pre-compiled data Message-ID: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. -- -- luca From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:26:20 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:26:20 +1000 Subject: Convert hash to struct References: Message-ID: <0058cc47$0$9712$c3e8da3@news.astraweb.com> Jason wrote: > Here's my general-purpose solution for doing this: > > class Dict2Class(object): > """ > Update like a dictionary, but expose the keys as class properties. I'm afraid that's wrong. It's wrong twice: * Properties are computed attributes. These are not, they are regular attributes. * Class attributes are shared between all instances. These are not, so they are instance attributes (or just regular "attributes" without qualification), not class attributes. > def __init__(self, *e, **f): > self.__dict__ = dict(*e, **f) You're updating the instance __dict__, not the class __dict__. Hence they are instance attributes. This is the correct thing to do, but if you wanted to share keys and values between all instances, you would use class attributes: def __init__(self, *e, **f): self.__class__.__dict__ = dict(*e, **f) As far as properties, in this case there's no sensible reason for making them properties. (Properties have their uses, but this isn't one of them.) However, since I'm not sensible *grin*, here's a quick-and-dirty version that works, for some definition of "works": class Dict2PropertyClass(object): # Like Dict2Class except using properties. def __init__(self, *e, **f): for key, value in dict(*e, **f).items(): private = '_' + key setattr(self, private, value) getter = lambda self, private=private: getattr(self, private) setter = ( lambda self, value, private=private: setattr(self, private, value) ) setattr(self.__class__, key, property(getter, setter) ) Getting update() working with this version is left as an exercise for the masochistic *wink* -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:35:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:35:19 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) References: Message-ID: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. Then it isn't a normal variate. > The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. Why? It's a perfectly simple procedure: def __int__(self, x, y): x = -1 while not 0 <= x <= 100: x = normalvariate(x, y) # do other stuff That is the correct way to truncate a normal distribution. Alternatively, truncate values past the end-points, but this will distort the random distribution significantly: x = max(0, min(100, normalvariate(x, y))) You probably don't want that, as it will cause far more 0 and 100 values than you would otherwise expect. > I would really like to keep it > on one line. How would I do that? Why? Is the enter key on your keyboard broken? -- Steven From grante at visi.com Sat Jun 20 10:44:38 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 20 Jun 2009 09:44:38 -0500 Subject: Checking for binary data in a string References: Message-ID: On 2009-06-19, Lie Ryan wrote: > Grant Edwards wrote: >> On 2009-06-19, Mitko Haralanov wrote: >> >>> I have a question about finding out whether a string contains >>> binary data? >> >> All strings contain binary data. > > Not quite, (python 2.x's) strings are binary data. > > It just happens that it behaves like text when you appropriately > encode/decode it. > > In python 3.x, the default string have evolved to unicode > string, which is a true text and the old string which contains > arbitrary binary data evolved into bytestring. You've got a computer that stores unicode strings as something other than binary data? ;) -- Grant From contact at xavierho.com Sat Jun 20 10:49:55 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 21 Jun 2009 00:49:55 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> References: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> Message-ID: <2d56febf0906200749l49208681q1875a1feee0f10c4@mail.gmail.com> > > def __int__(self, x, y): > x = -1 > while not 0 <= x <= 100: > x = normalvariate(x, y) > # do other stuff > > That is the correct way to truncate a normal distribution. > > Thanks for the response. But why would you set the mean to -1 to begin? > > x = max(0, min(100, normalvariate(x, y))) > > That is an awesome way of shorthanding clamp. Best regards, 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 steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:54:22 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:54:22 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> Message-ID: <0058d2da$0$9759$c3e8da3@news.astraweb.com> Vincent Davis wrote: >> # Clamp a normal distribution outcome I don't know who you are quoting -- you should give attribution to them. >> def clamp(input, min=0, max=100): ... >> if input < min: >> return min >> elif input > max: >> return max >> else: >> return input An easier way to do this: return min(100, max(0, input)) but again, I stress that this will strongly distort the random distribution. It's probably not what you want. > Why not have the def clamp inside the class? Why bother? > I would prefer to keep > everything I need for the class together. But you don't. You have the random.normalvariate in a completely different module. I'm sure you have other operations like +, - etc as built-in functions. Not everything is inside the class. > I am new to classes but I have to say things like if __name__ == > "__main__": have no intuitive meaning to me. It is true I don't know > what __name__ and __main__ do and I can look it up but I don't even > have a guess based on the names and usage. When you import a module with the line: import mymodule Python automatically creates a variable mymodule.__name__ and sets it to the string "__mymodule__". When you run a module as a script, by calling it from the shell, using (for example): $ python mymodule.py Python automatically creates the variable mymodule.__name__ as before, but this time sets its value to the string "__main__". So the construction: if __name__ == "__main__": do_stuff_here() is a way to include code that will only be executed when running the module as a script, not when it is imported as a module. > I am Now not sure if that is what I want or If I want to redraw from > the distribution. I am wanting to simulate test scores. My option see > to be to draw from a normal (I don't want linear) distribution and > scale it to 0-100 or clamp it as you (Xavier) suggested or draw from > the distribution again (this is what I was thinking) I think this is > still what I want but I should look up the implications of each. The > problem I have with the clamp is that the tails in the sample could be > large. Strictly speaking, you want a different distribution, not normal. Possibly the F-distribution? Anyway, whatever it is, unless you need very accurate results, a truncated normal distribution shouldn't be *too* far off: close enough for government work. Clamping will not be very good: it will result in an excess of 0 and 100 scores. Imagine a graph that looks vaguely like this: 000: ********** 010: * 020: ** 030: **** 040: ******* 050: ********* 060: ********** 070: ******** 080: ***** 090: ** 100: ************* That's what you'll get by clamping (possibly exaggerated for effect). Truncating with a while loop will result in something closer to this: 000: * 010: * 020: ** 030: **** 040: ******* 050: ********* 060: ********** 070: ******** 080: ***** 090: ** 100: * which is far less distorted. -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:56:47 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:56:47 +1000 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: <0058d36a$0$9759$c3e8da3@news.astraweb.com> Lawrence D'Oliveiro wrote: >> Ok, now pipe ls to less, take three days to browse through all the >> filenames to locate the file you want to see. > > Sounds like you're approaching the issue with a GUI-centric mentality, > which is completely hopeless at dealing with this sort of situation. Piping the output of ls to less is a GUI-centric mentality? -- Steven From stefan_ml at behnel.de Sat Jun 20 11:28:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Jun 2009 17:28:23 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Kay Schluehr wrote: >> You might want to read about "The Problem with Threads": >> >> http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf >> >> and then decide to switch to an appropriate concurrency model for your use >> case. > > and to a programming language that supports it. Maybe, yes. But many different concurrency models are supported by a larger number of programming languages in one way or another, so the choice of an appropriate library is often sufficient - and usually a lot easier than using the 'most appropriate' programming language. Matter of available skills, mostly. There's usually a lot less code to be written that deals with concurrency than code that implements what the person paying you makes money with, so learning a new library may be worth it, while learning a new language may not. Stefan From lorenzo.digregorio at gmail.com Sat Jun 20 11:40:57 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sat, 20 Jun 2009 08:40:57 -0700 (PDT) Subject: Inheritance and forward references (prototypes) Message-ID: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --------------------------------------- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here I would have a prototype of class A which is the same as class BaseA class B(object): def __init__(self): self.obj = A() return if __name__ == "__main__": # class A(BaseA): # Uncomment this for using BaseA objects # pass class A(DebugA): # Uncomment this for using DebugA objects pass --------------------------------------- I can figure out some ways to fix this but none seems satisfying. Either they are too specific or too cumbersome. A runtime redefinition of class A does not seem to work either. What would be the most "pythonesque" solution other than sorting out the class order? Best Regards, Lorenzo From me at gustavonarea.net Sat Jun 20 11:50:41 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Sat, 20 Jun 2009 08:50:41 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: Message-ID: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Hello again, everybody. Thank you very much for your responses. You guessed right, I didn't use the __hash__ method (and I forgot to mention that, sorry). And unfortunately, I think I can't make them hashable, because the objects are compared based on their attributes, which are in turn other kind of objects compared based on other attributes. All these class instances are compared with __eq__/__ne__ and they wrap relatively complex data which would be hard to attempt to represent them unambiguously using a 32-bit integer. That's why I'm afraid I cannot use hashables. I guess I'll have to use something like the function of my first post. :( Thanks, - Gustavo. From wayne.dads.bell at gmail.com Sat Jun 20 11:58:16 2009 From: wayne.dads.bell at gmail.com (dads) Date: Sat, 20 Jun 2009 08:58:16 -0700 (PDT) Subject: File Syncing References: Message-ID: On Jun 20, 11:21?am, Lawrence D'Oliveiro wrote: > In message > b0d7-586b1b332... at t10g2000vbg.googlegroups.com>, dads wrote: > > What would I have to learn to be able to sync the text files on each > > server? > > How big is the text file? If it's small, why not have your script read it > directly from a master server every time it runs, instead of having a local > copy. Yeah the text files will never get bigger than a 100k. I don't think they have a master server but i'll check. Thanks From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 12:13:04 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 02:13:04 +1000 Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <024cfc8b$0$25987$c3e8da3@news.astraweb.com> Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. There is no need for hash to represent the data unambiguously. >>> hash(-1) -2 >>> hash(-2) -2 >>> hash(2.0**32 - 1) -2 >>> hash(1) 1 >>> hash(2.0**64 - 1) 1 >>> hash(2.0**64 + 1) 1 >>> hash(2) 2 >>> hash(1+2**32) 2 >>> hash(1+2**64) 2 >>> hash(1+2**128) 2 >>> hash(2.0) 2 The rule is, if x and y are equal, then hash(x) should equal hash(y). This does NOT imply that if hash(x) == hash(y), then x must equal y, nor is there any requirement for every unique piece of data to have a unique hash. -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 12:21:18 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 02:21:18 +1000 Subject: Inheritance and forward references (prototypes) References: Message-ID: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: You don't actually explain what is the problem. Fortunately, I'm good at guessing, and I think I can guess what your problem is (see below): > --------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > # here I would have a prototype of class A which is the same as class > BaseA > > class B(object): > def __init__(self): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > --------------------------------------- Class A only gets defined if you run the module as a script. What you need is to unconditionally define class A, outside of the if __name__ block: class A(BaseA): pass # A.__base__ = DebugA ## Uncomment this line for debugging. -- Steven From python at mrabarnett.plus.com Sat Jun 20 12:27:45 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 17:27:45 +0100 Subject: Rich comparison methods don't work in sets? In-Reply-To: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <4A3D0E01.60907@mrabarnett.plus.com> Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. > > I guess I'll have to use something like the function of my first > post. :( > A hash doesn't have to be unambiguous. It's just a way to reduce the number of equality checks that have to be made. Could you create a hash from a tuple of attributes? If all else fails you could define a hash function that returns a constant. You would, however, lose the speed advantage that a hash gives in narrowing down the possible matches. From gagsl-py2 at yahoo.com.ar Sat Jun 20 12:28:28 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 13:28:28 -0300 Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: En Sat, 20 Jun 2009 12:50:41 -0300, Gustavo Narea escribi?: > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. Combine the hash values of whatever objects are involved in __eq__ but make sure they cannot change (in that case the hash value would be invalid). No need for hash to be unambiguous - objects that compare equal must have the same hash value, but objects with the same hash value may be different. -- Gabriel Genellina From clp2 at rebertia.com Sat Jun 20 12:38:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Jun 2009 09:38:57 -0700 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: > Hi all. > > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working path. What does "pre-compile" mean in this context? It's not clear at all, so I can't even understand your question. Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Sat Jun 20 12:42:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 13:42:37 -0300 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: En Sat, 20 Jun 2009 11:17:01 -0300, Luca escribi?: > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working > path. What do you mean "pre-compile the raw_input input line"? Maybe you're looking for this: import os defpath = os.getcwd() path = raw_input("Enter path [%s]: " % defpath) if not path: path = defpath print "Using path=%s" % path -- Gabriel Genellina From vincent at vincentdavis.net Sat Jun 20 13:48:21 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 11:48:21 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> Message-ID: <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Quoting Steven, >Truncating with a while loop will result in something closer to this: > 000: * > 010: * > 020: ** > 030: **** > 040: ******* > 050: ********* > 060: ********** > 070: ******** > 080: ***** > 090: ** > 100: * > > which is far less distorted." That is why I was thinking of a while loop. > Strictly speaking, you want a different distribution, not normal. Possibly > the F-distribution?" Why do you suggest a F dist, I have to admit I am not really sure how "most" test score are distributed. I was thinking it would be a truncated skewed normal. i.e. scores range from 0-100, mean is 80. For my I realize this is venturing more into statistics. Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Jun 20 13:52:55 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 03:52:55 +1000 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> References: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> Message-ID: <4A3D21F7.9010608@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Paul Calderone wrote: > On Sat, 20 Jun 2009 00:07:27 GMT, Lie Ryan wrote: >> [snip] >> >> Perhaps we should have more built-in/stdlib operations that can release >> GIL safely to release GIL by default? And perhaps some builtin/stdlib >> should receive an optional argument that instruct them to release GIL >> and by passing this argument, you're making a contract that you wouldn't >> do certain things that would disturb the builtin/stdlib's operations; >> the specifics of what operations are prohibited would be noted on their >> docs. > > There would be a lot less useless discussion if people would do a minimal > amount of checking to see if the ideas they're suggesting are at all > feasible. > > Why don't you take a look at the CPython source and see if this is actually > possible? If you're not comfortable diving into a C program, then maybe > you > could try to become so first, or refrain from making suggestions that rely > on technical details you know nothing about? > > Jean-Paul There are 4 types of people's attitude towards discussion on GIL: Two useless ones: 1. seasoned developers who have run out of ideas and moved to other more important issues, leaving GIL problems to be solved by the future generation; 2. newbies who spurts out random ideas, often half-baked, impossible, unfeasible, or just plain stupid; and two helpful ones: 3. people who are too tired discussing GIL and just shut their mouth up; 4. people who preached resistance against GIL is futile and converted people of type 2 into type 3. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko9IfcACgkQqC3FTmXeMUa11wCdFMmvLM6Y3fx8DPcty27XhuVS eJkAnAup/G/cQkDML0k49a+SlM1ymvCS =1cRN -----END PGP SIGNATURE----- From davea at ieee.org Sat Jun 20 14:43:32 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 14:43:32 -0400 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: Message-ID: <4A3D2DD4.1010406@ieee.org> Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: > > --------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > # here I would have a prototype of class A which is the same as class > BaseA > > class B(object): > def __init__(self): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > --------------------------------------- > > I can figure out some ways to fix this but none seems satisfying. > Either they are too specific or too cumbersome. > A runtime redefinition of class A does not seem to work either. > What would be the most "pythonesque" solution other than sorting out > the class order? > > Best Regards, > Lorenzo > > You haven't shown us any problem. class B works fine with a forward reference to A. Now if you were trying to subclass A before defining it, that'd be a problem. Or if you were trying to make an instance of B before defining A. Better put some code together with enough meat to actually show a symptom. And tell us what sys.version says. I'm testing with 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running on Win XP. From davea at ieee.org Sat Jun 20 15:01:34 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 15:01:34 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: <4A3D320E.1080303@ieee.org> Luca wrote: > Hi all. > > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working path. > > You'll have to define several terms for us: 1) "pre-compile" - Are you coding in Python, or in C, or some other compiled language? Microsoft C has (had?) something called pre-compiled headers, but they never worked very well, so I kept them disabled. 2) "the choice" - what choice would that be? 3) "this" - what's this? 4) "current working path" - what does this mean? Do you perhaps mean "current directory" aka "current working directory" ? Or do you mean the path to the __main__ file? The only thing I can understand clearly is "read data from user command line". You get that from sys.argv usually, or you can parse it with optparse. Or if you need the line unmodified, AND if you're on Windows, you can use the win32 module to call something like GetCommandLine(). I'd have to check that last one, though. From davea at ieee.org Sat Jun 20 15:27:50 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 15:27:50 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: <699f51260906201216r30cd5986xa816e7dbf7224630@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <4A3D320E.1080303@ieee.org> <699f51260906201216r30cd5986xa816e7dbf7224630@mail.gmail.com> Message-ID: <4A3D3836.2070401@ieee.org> patx wrote: > Could you use if elif statements? Don't understand what you mean really? > > On Sat, Jun 20, 2009 at 3:01 PM, Dave Angel wrote: > > >> Luca wrote: >> >> >>> Hi all. >>> >>> I need to use a function like the raw_input to read data from user >>> command line, but I really like to pre-compile the choice and I'm not >>> able to do this. There is some other function/module I can use? >>> I wanna to pre-compile the raw_input input line with the current working >>> path. >>> >>> >>> >>> >> You'll have to define several terms for us: >> >> 1) "pre-compile" - Are you coding in Python, or in C, or some other >> compiled language? Microsoft C has (had?) something called pre-compiled >> headers, but they never worked very well, so I kept them disabled. >> 2) "the choice" - what choice would that be? >> 3) "this" - what's this? >> 4) "current working path" - what does this mean? Do you perhaps mean >> "current directory" aka "current working directory" ? Or do you mean the >> path to the __main__ file? >> >> The only thing I can understand clearly is "read data from user command >> line". You get that from sys.argv usually, or you can parse it with >> optparse. Or if you need the line unmodified, AND if you're on Windows, you >> can use the win32 module to call something like GetCommandLine(). I'd have >> to check that last one, though. >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> This was sent off-list. And it was top-posted, so I'll have to copy his two questions here... > Could you use if elif statements? Yes. Whenever they're needed. But I don't see the relevance to this thread. > Don't understand what you mean really? This "question" doesn't parse. From lie.1296 at gmail.com Sat Jun 20 15:58:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Jun 2009 19:58:59 GMT Subject: What is the best method to match a pattern in set of lines In-Reply-To: References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Message-ID: <7cb%l.19863$y61.15772@news-server.bigpond.net.au> Dennis Lee Bieber wrote: > On Fri, 19 Jun 2009 17:52:05 -0700 (PDT), Terminator > declaimed the following in > gmane.comp.python.general: > >> Hello, >> My requierment is to get the "Stick Tag" value from the below o/p and >> based on tag take different actions. What is the best way to implement >> it. I am new to Python, so appreciate any input. >> >> Command o/p: >> =================================================================== >> File: Packet.tcl Status: Needs Merge >> >> Working revision: 1.2.98 Result of merge >> Repository revision: 1.2.99 /auto/quality/CVS/tools/ext/ >> Packet.tcl,v >> Sticky Tag: rel-ip-branch (branch: 1.584.2) >> Sticky Date: (none) >> Sticky Options: (none) >> >> Requirement: >> If "Sticky Tag" is rel-ip-brach >> do A >> else "Sticky Tag" is rel-ipv6-branch >> do B >> >> Thanks in advance. > > Sounds like homework -- but rather advanced if the homework is to > extract/parse stuff from a CVS repository... > > > Step one: find the line with "Sticky Tag:" > I presume you can code an I/O loop reading lines from a file... in > that case, look at: > if "Sticky Tag:" in line: > > Step two: once the line is found; extract the word after the field > identifier... > > Step three: > if word == "rel-ip-branch": # I'm presuming brach is typo Regular expression? From piet at cs.uu.nl Sat Jun 20 16:16:21 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 22:16:21 +0200 Subject: Inheritance and forward references (prototypes) References: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Message-ID: >>>>> Steven D'Aprano (SD) wrote: >SD> Lorenzo Di Gregorio wrote: >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >SD> You don't actually explain what is the problem. Fortunately, I'm good at >SD> guessing, and I think I can guess what your problem is (see below): >>> --------------------------------------- >>> class BaseA(object): >>> def __init__(self): >>> return >>> >>> class DebugA(BaseA): >>> def __init__(self): >>> return >>> >>> # here I would have a prototype of class A which is the same as class >>> BaseA >>> >>> class B(object): >>> def __init__(self): >>> self.obj = A() >>> return >>> >>> if __name__ == "__main__": >>> # class A(BaseA): # Uncomment this for using BaseA objects >>> # pass >>> class A(DebugA): # Uncomment this for using DebugA objects >>> pass >>> --------------------------------------- >SD> Class A only gets defined if you run the module as a script. What you need >SD> is to unconditionally define class A, outside of the if __name__ block: >SD> class A(BaseA): >SD> pass >SD> # A.__base__ = DebugA ## Uncomment this line for debugging. >>>A.__base__ = DebugA TypeError: readonly attribute Make that: A.__bases__ = DebugA, >SD> -- >SD> Steven -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From lorenzo.digregorio at gmail.com Sat Jun 20 16:26:56 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sat, 20 Jun 2009 13:26:56 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: Message-ID: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> On Jun 20, 8:43?pm, Dave Angel wrote: > Lorenzo Di Gregorio wrote: > > Hi, > > > I'm wondering what would be the preferred way to solve the following > > forward reference problem: > > > --------------------------------------- > > class BaseA(object): > > ? ? def __init__(self): > > ? ? ? ? return > > > class DebugA(BaseA): > > ? ? def __init__(self): > > ? ? ? ? return > > > # here I would have a prototype of class A which is the same as class > > BaseA > > > class B(object): > > ? ? def __init__(self): > > ? ? ? ? self.obj = A() > > ? ? ? ? return > > > if __name__ == "__main__": > > # ? ?class A(BaseA): # Uncomment this for using BaseA objects > > # ? ? ? pass > > ? ? class A(DebugA): # Uncomment this for using DebugA objects > > ? ? ? ? pass > > --------------------------------------- > > > I can figure out some ways to fix this but none seems satisfying. > > Either they are too specific or too cumbersome. > > A runtime redefinition of class A does not seem to work either. > > What would be the most "pythonesque" solution other than sorting out > > the class order? > > > Best Regards, > > Lorenzo > > You haven't shown us any problem. ?class B works fine with a forward > reference to A. ?Now if you were trying to subclass A before defining > it, that'd be a problem. ?Or if you were trying to make an instance of B > before defining A. > > Better put some code together with enough meat to actually show a > symptom. ?And tell us what sys.version says. ?I'm testing with ? 2.6.2 > (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > on Win XP.- Hide quoted text - > > - Show quoted text - Thank you for your help: I'm working on a rather large source, but I think I have isolated the problem now. This listing generates an error: ----------------------------------------------- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return class B(object): def __init__(self,test=A()): self.obj = A() return if __name__ == "__main__": # class A(BaseA): # Uncomment this for using BaseA objects # pass class A(DebugA): # Uncomment this for using DebugA objects pass ----------------------------------------------- The error happens because Python apparently evaluates the named arguments before running the script. I think I have read something about this some (long) time ago but I can't find it anymore. Suggestions? BTW, my Python version is 2.6.1 (with latest PyDev). Thx! Lorenzo From philip at semanchuk.com Sat Jun 20 16:30:58 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 20 Jun 2009 16:30:58 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: <4D686E7E-0128-416F-AEDC-E39E8B4DAD0C@semanchuk.com> On Jun 20, 2009, at 7:41 AM, Piet van Oostrum wrote: > After my previous experiment I was curious how this works with > input(). I replaced the sem.acquire() with raw_input() and ran the > same > tests. Now the inner exception is really taken so it works like the OP > expected. The exception, however is KeyboardInterrupt, not the special > exception from the IPC module. > > So I looked in the source code how they did it: > The code is in Parser/myreadline.c. > > This code for input in function calls PyErr_CheckSignals() and > PyOS_InterruptOccurred() for a proper handling of the interrupt. So it > seems the OP should do something similar. Onl;y to deliver the custom > error you will have to do some other stuff. I don't know what but > maybe > calling PyErr_SetString is sufficient as it might overwrite the > KeyboardInterrupt stuff. Thank you Greg and especially Piet for going to the trouble of installing posix_ipc and experimenting with it. Piet, your research into raw_input() gave me a solution. In my C code, I added a call to PyErr_CheckSignals() as the first line inside the "case EINTR". Apparently calling PyErr_CheckSignals() sets the Python error indicator -- PyErr_Occurred() returns true and the error is PyExc_KeyboardInterrupt. I'm able to clear that error and return my own. Prior to adding the call to PyErr_CheckSignals(), PyErr_Occurred() returned false, so my code had no error to clear. Best of all, PyErr_CheckSignals() doesn't interfere with a Python- level signal handler if one is set. This worked under OS X and Linux. I'll have to think some more about exactly how I want my module to report the Ctrl-C, but at least now I have the tools to control the situation. Thanks again for your invaluable assistance. If I'm ever in NL or NZ I'll buy you a beer. =) Cheers Philip From bearophileHUGS at lycos.com Sat Jun 20 16:47:24 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 20 Jun 2009 13:47:24 -0700 (PDT) Subject: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Message-ID: <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> This is a small OT post, sorry. Dennis Lee Bieber, may I ask why most or all your posts are set to "No- Archive"? > HTTP://www.bestiaria.com/ I think there are other furries beside you around here. Bye, bearophile From robert.kern at gmail.com Sat Jun 20 16:54:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 20 Jun 2009 15:54:14 -0500 Subject: Rich comparison methods don't work in sets? In-Reply-To: <4A3D0E01.60907@mrabarnett.plus.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> <4A3D0E01.60907@mrabarnett.plus.com> Message-ID: On 2009-06-20 11:27, MRAB wrote: > Gustavo Narea wrote: >> Hello again, everybody. >> >> Thank you very much for your responses. You guessed right, I didn't >> use the __hash__ method (and I forgot to mention that, sorry). >> >> And unfortunately, I think I can't make them hashable, because the >> objects are compared based on their attributes, which are in turn >> other kind of objects compared based on other attributes. All these >> class instances are compared with __eq__/__ne__ and they wrap >> relatively complex data which would be hard to attempt to represent >> them unambiguously using a 32-bit integer. That's why I'm afraid I >> cannot use hashables. >> >> I guess I'll have to use something like the function of my first >> post. :( >> > A hash doesn't have to be unambiguous. It's just a way to reduce the > number of equality checks that have to be made. > > Could you create a hash from a tuple of attributes? A typical way to implement this is to make a method that returns a tuple of attributes to use in both the __eq__ and __hash__ methods. class Foo(object): def key(self): return (self.x, self.y, self.bar) def __eq__(self, other): return self.key() == other.key() def __ne__(self, other): return not (self == other) def __hash__(self): return hash(self.key()) As long as those attributes are also hashable, this usually works well. -- 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-url at phaseit.net Sat Jun 20 17:41:07 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Sat, 20 Jun 2009 21:41:07 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 20) Message-ID: QOTW: "... open recursion with abstraction is supported in OOP but it requires elaborate and rather tedious boilerplate in FP ..." - Martin Odersky http://www.nabble.com/Re%3A--scala--usefulness-of-OOP-p23273389.html How to write a method that may act both as an instance method and as a class method: http://groups.google.com/group/comp.lang.python/browse_thread/thread/41e3606af55598e8/ How to check the Python version? http://groups.google.com/group/comp.lang.python/browse_thread/thread/105dd4686e7985e1/ Exceptions alter the normal lifetime of some objects: http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f9056711e3e313c Are exit() and sys.exit() the same thing? http://groups.google.com/group/comp.lang.python/browse_thread/thread/72b318b07030a048/ "Exotic" logics http://groups.google.com/group/comp.lang.python/browse_thread/thread/75d688efdac05526/ A compilation of good books in Computer Science/Software Engineering: http://groups.google.com/group/comp.lang.python/browse_thread/thread/952facdd398772/ itertools.intersect is missing? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4772d9ff82a90a6c/ From Perl to Python: Lexical (private) scope: http://groups.google.com/group/comp.lang.python/browse_thread/thread/2b2536c28cd32888/ Multiple sequence subscripts: http://groups.google.com/group/comp.lang.python/browse_thread/thread/61c1d89d988a2cac/ None, vacuous truth, denotational semantics, and other philosophical aspects of emptyness: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c5397f9b6726b7a/ Walking a directory containing many many files: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ff3905b80de43588/ How to get the total size of a local hard disk in a cross-platform way :) http://groups.google.com/group/comp.lang.python/msg/c6c09fa6b3b62f84 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From castironpi at gmail.com Sat Jun 20 18:39:00 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 20 Jun 2009 15:39:00 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: On Jun 20, 9:27?am, MRAB wrote: > Gustavo Narea wrote: > > Hello again, everybody. > > > Thank you very much for your responses. You guessed right, I didn't > > use the __hash__ method (and I forgot to mention that, sorry). > > > And unfortunately, I think I can't make them hashable, because the > > objects are compared based on their attributes, which are in turn > > other kind of objects compared based on other attributes. All these > > class instances are compared with __eq__/__ne__ and they wrap > > relatively complex data which would be hard to attempt to represent > > them unambiguously using a 32-bit integer. That's why I'm afraid I > > cannot use hashables. > > > I guess I'll have to use something like the function of my first > > post. :( > > A hash doesn't have to be unambiguous. It's just a way to reduce the > number of equality checks that have to be made. > > Could you create a hash from a tuple of attributes? > > If all else fails you could define a hash function that returns a > constant. Ooo sneaky. +1 fancy. > You would, however, lose the speed advantage that a hash > gives in narrowing down the possible matches. Are there /any/ immutable members of the objects? From contact at xavierho.com Sat Jun 20 19:05:47 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 21 Jun 2009 09:05:47 +1000 Subject: Inheritance and forward references (prototypes) In-Reply-To: <2d56febf0906201604i582153a9yf822686f2103602f@mail.gmail.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <2d56febf0906201604i582153a9yf822686f2103602f@mail.gmail.com> Message-ID: <2d56febf0906201605j5d6706b9w230d3c2aebf068ea@mail.gmail.com> Arg, forgot to post to the mailing list again. -_- On a smaller issue, don't you need to do: class DebugA(BaseA): def __init__(self): BaseA.__init__(self) return As in, explicitly call the __init__ function when you initalise DebugA, since DebugA extends BaseA? I'm just getting this "necessary" step because my books say so. If anyone has a good explanation, please do tell. Best regards, 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 Sun, Jun 21, 2009 at 6:26 AM, Lorenzo Di Gregorio < lorenzo.digregorio at gmail.com> wrote: > On Jun 20, 8:43 pm, Dave Angel wrote: > > Lorenzo Di Gregorio wrote: > > > Hi, > > > > > I'm wondering what would be the preferred way to solve the following > > > forward reference problem: > > > > > --------------------------------------- > > > class BaseA(object): > > > def __init__(self): > > > return > > > > > class DebugA(BaseA): > > > def __init__(self): > > > return > > > > > # here I would have a prototype of class A which is the same as class > > > BaseA > > > > > class B(object): > > > def __init__(self): > > > self.obj = A() > > > return > > > > > if __name__ == "__main__": > > > # class A(BaseA): # Uncomment this for using BaseA objects > > > # pass > > > class A(DebugA): # Uncomment this for using DebugA objects > > > pass > > > --------------------------------------- > > > > > I can figure out some ways to fix this but none seems satisfying. > > > Either they are too specific or too cumbersome. > > > A runtime redefinition of class A does not seem to work either. > > > What would be the most "pythonesque" solution other than sorting out > > > the class order? > > > > > Best Regards, > > > Lorenzo > > > > You haven't shown us any problem. class B works fine with a forward > > reference to A. Now if you were trying to subclass A before defining > > it, that'd be a problem. Or if you were trying to make an instance of B > > before defining A. > > > > Better put some code together with enough meat to actually show a > > symptom. And tell us what sys.version says. I'm testing with 2.6.2 > > (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > > on Win XP.- Hide quoted text - > > > > - Show quoted text - > > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. > > Suggestions? > > BTW, my Python version is 2.6.1 (with latest PyDev). > > Thx! > Lorenzo > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Sat Jun 20 19:18:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 21 Jun 2009 00:18:31 +0100 Subject: Inheritance and forward references (prototypes) In-Reply-To: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: On Sat, 20 Jun 2009 21:26:56 +0100, Lorenzo Di Gregorio wrote: > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. I could have sworn this was in the FAQ, but apparently not. You're right, Python evaluates the default arguments when it executes the `def` instruction. (Yes, `def` is an executable instruction. It's got to create the function/method object after all!) The usual fix is not to make the default an instance of A (which will have all sorts of other side effects as well, since the same instance of A will be shared by all the Bs that don't supply a `test` parameter), but to use `None` as a marker. class B(object): def __init__(self, test=None): if test is None: test = A() self.obj = A() and so on. -- Rhodri James *-* Wildebeest Herder to the Masses From tjreedy at udel.edu Sat Jun 20 19:22:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Jun 2009 19:22:59 -0400 Subject: Rich comparison methods don't work in sets? In-Reply-To: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. If the result of 'o1 == o2' changes over time, then the objects are not very suitable as set members. > I guess I'll have to use something like the function of my first > post. :( > > Thanks, > > - Gustavo. From robert.kern at gmail.com Sat Jun 20 19:32:50 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 20 Jun 2009 18:32:50 -0500 Subject: Rich comparison methods don't work in sets? In-Reply-To: References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: On 2009-06-20 18:22, Terry Reedy wrote: > Gustavo Narea wrote: >> Hello again, everybody. >> >> Thank you very much for your responses. You guessed right, I didn't >> use the __hash__ method (and I forgot to mention that, sorry). >> >> And unfortunately, I think I can't make them hashable, because the >> objects are compared based on their attributes, which are in turn >> other kind of objects compared based on other attributes. All these >> class instances are compared with __eq__/__ne__ and they wrap >> relatively complex data which would be hard to attempt to represent >> them unambiguously using a 32-bit integer. That's why I'm afraid I >> cannot use hashables. > > If the result of 'o1 == o2' changes over time, then the objects are not > very suitable as set members. Sometimes, I think it would be nice if sets and the other containers could be modified to accept a user-supplied hash and comparison functions on construction. A key function like list.sort() would probably also work. Even when you have objects that aren't hashable in general, there are many times when you know you will not be modifying them in a given context. Being able to do set operations on them in that context would be really useful. -- 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 charles at declareSub.com Sat Jun 20 19:36:01 2009 From: charles at declareSub.com (Charles Yeomans) Date: Sat, 20 Jun 2009 19:36:01 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> Message-ID: On Jun 18, 2009, at 2:21 PM, David C. Ullrich wrote: > On Wed, 17 Jun 2009 05:46:22 -0700 (PDT), Mark Dickinson > wrote: > >> On Jun 17, 1:26 pm, Jaime Fernandez del Rio >> wrote: >>> On Wed, Jun 17, 2009 at 1:52 PM, Mark >>> Dickinson wrote: >>>> Maybe James is thinking of the standard theorem >>>> that says that if a sequence of continuous functions >>>> on an interval converges uniformly then its limit >>>> is continuous? >> >> s/James/Jaime. Apologies. >> >>> P.S. The snowflake curve, on the other hand, is uniformly >>> continuous, right? >> >> Yes, at least in the sense that it can be parametrized >> by a uniformly continuous function from [0, 1] to the >> Euclidean plane. I'm not sure that it makes a priori >> sense to describe the curve itself (thought of simply >> as a subset of the plane) as uniformly continuous. > > As long as people are throwing around all this math stuff: > Officially, by definition a curve _is_ a parametrization. > Ie, a curve in the plane _is_ a continuous function from > an interval to the plane, and a subset of the plane is > not a curve. > > Officially, anyway. This simply isn't true. Charles Yeomans From rhodri at wildebst.demon.co.uk Sat Jun 20 19:36:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 21 Jun 2009 00:36:33 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Fri, 19 Jun 2009 15:56:04 +0100, Aaron Brady wrote: > This is a welcome digression for me. I wasn't sure that my idea was > being taken seriously. On a temperature scale from freezing to > boiling, I took Rhodri's message to be somewhere in the single > digits-- quite chilly. Correctly, though apparently for the wrong reason. I know get what you're trying to do, despite you consistently refusing to present a use case. > Maybe if it hadn't made me feel so defensive, > I could've just said so. But, judging from his reply, he got the > message. I'm wondering whether you did, though. Aahz's later point that you need to work on your presentation skills is not something you should dismiss out of hand as you appear to. Your original post read very much like "here's some code, please tell me I'm brilliant and should carry on." Whether or not you are brilliant, that doesn't go down well. When you're trying to generate interest in something, actively generating disinterest like that isn't going to help. -- Rhodri James *-* Wildebeest Herder to the Masses From pavlovevidence at gmail.com Sat Jun 20 19:42:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 16:42:51 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> On Jun 20, 6:36?am, s... at pobox.com wrote: > ? ? Carl> Here's the thing: not everyone complaining about the GIL is trying > ? ? Carl> to get the "raw power of their machines." ?They just want to take > ? ? Carl> advantage of multiple cores so that their Python program runs > ? ? Carl> faster. > > If their code is CPU-bound it's likely that rewriting critical parts in C or > using packages like numpy would improve there performance with or without > multi-threading. ?For people who aren't used to C there are tools like Pyrex > and Cython which provide a middle road. Once again you miss the point. I'm sure you think you're trying to be helpful, but you're coming off as really presumptuous with this casual dismissal of their concerns. There are many, many valid reasons why people don't want to stray from Pure Python. Converting to C, Fortran, Pyrex, etc. has a significant cost (in both implementation and maintenance): much more than the cost of parallelizing pure Python code. I guess what really bothers me about this is how easily people throw out "shut up and use C" for some things, especially things that quite reasonably appear to be a silly limitation. Maybe you don't intend to sound like you're saying "shut up and use C", but to me, that's how you come off. If you're going to advise someone to use C, at least try to show some understanding for their concerns--it would go a long way. Carl Banks From davea at ieee.org Sat Jun 20 19:54:46 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 19:54:46 -0400 Subject: Inheritance and forward references (prototypes) In-Reply-To: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <4A3D76C6.4030400@ieee.org> Lorenzo Di Gregorio wrote: > On Jun 20, 8:43 pm, Dave Angel wrote: > >> Lorenzo Di Gregorio wrote: >> >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >>> >>> --------------------------------------- >>> class BaseA(object): >>> def __init__(self): >>> return >>> >>> class DebugA(BaseA): >>> def __init__(self): >>> return >>> >>> # here I would have a prototype of class A which is the same as class >>> BaseA >>> >>> class B(object): >>> def __init__(self): >>> self.obj =() >>> return >>> >>> if __name__ ="__main__": >>> # class A(BaseA): # Uncomment this for using BaseA objects >>> # pass >>> class A(DebugA): # Uncomment this for using DebugA objects >>> pass >>> --------------------------------------- >>> >>> I can figure out some ways to fix this but none seems satisfying. >>> Either they are too specific or too cumbersome. >>> A runtime redefinition of class A does not seem to work either. >>> What would be the most "pythonesque" solution other than sorting out >>> the class order? >>> >>> Best Regards, >>> Lorenzo >>> >> You haven't shown us any problem. class B works fine with a forward >> reference to A. Now if you were trying to subclass A before defining >> it, that'd be a problem. Or if you were trying to make an instance of B >> before defining A. >> >> Better put some code together with enough meat to actually show a >> symptom. And tell us what sys.version says. I'm testing with 2.6.2 >> (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running >> on Win XP.- Hide quoted text - >> >> - Show quoted text - >> > > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj =() > return > > if __name__ ="__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. > > Suggestions? > > BTW, my Python version is 2.6.1 (with latest PyDev). > > Thx! > Lorenzo > > This error is caused because a default argument uses class A. Default arguments of class methods are evaluated during the definition of the class, and not later when the class is instantiated. Thus the problem. To work around that specific problem, you may want to use the following: class B(object): def __init__(self,test=None): if test==None: test = A() self.obj =() return This is actually different than what you had, since what you had would have used the same A() object for all instances of B that didn't supply their own test() parameter. Maybe that's what you wanted, and maybe not, but default arguments set to mutable values are frequently a bug. But I'm wondering if you're just looking for problems. Why not put the commented switch early in the file, and test for it wherever you need to use it? import x, y, z _debug = False #_debug = True then as soon as BaseA and DebugA are defined, do the following: if _debug: class A(DebugA): pass else: class A(BaseA) pass From martin.hellwig at dcuktec.org Sat Jun 20 20:02:48 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 21 Jun 2009 01:02:48 +0100 Subject: Decorator question (how to test if decorated function is in a class) In-Reply-To: <4a3bb0ee$0$3613$426a74cc@news.free.fr> References: <4a3bb0ee$0$3613$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Short answer: this makes no sense. Absolutely right, took me a while to figure that out though :-) Lesson learned (again): If it really seems impossible to do something in Python, it is likely the proposed solution is flawed. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From xahlee at gmail.com Sat Jun 20 20:26:13 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 20 Jun 2009 17:26:13 -0700 (PDT) Subject: a evaluation of Google-code-prettify Message-ID: For those of you interested in the Google tech of syntax coloring source code in html on the fly using javascript, i've spent few hours for a evaluation. See: ? Google-code-prettify Examples http://xahlee.org/js/google-code-prettify/index.html Xah ? http://xahlee.org/ ? From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 21:09:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 11:09:19 +1000 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> Message-ID: <024d7a38$0$20654$c3e8da3@news.astraweb.com> Dennis Lee Bieber wrote: > On Sat, 20 Jun 2009 13:47:24 -0700 (PDT), Bearophile > declaimed the following in > gmane.comp.python.general: > >> This is a small OT post, sorry. >> >> Dennis Lee Bieber, may I ask why most or all your posts are set to "No- >> Archive"? >> > Taking into account some corrections from the last time I had to > explain... > > I'm from the days when the majority of NNTP servers were configured > to expire posts after some number of days (Netcom used to expire binary > groups after 24 hours! and most others were something like 14 days). > > Then came the precursor to GoogleGroups -- DejaNews -- threatening > to archive posts through eternity. This resulted in a fair amount of > protesting by some, and the creation of the x-no-archive header > convention (Agent even has configuration options such that, if one were > to not normally use x-no-archive such that one's own posts could be > archived, one could still honor it in replies to posts that did contain > it -- so those replies with quoted contents would also not be archived). > > It was at that time that I added the x-no-archive header to my posts > from Agent; as, while not as vocal as others, did object to DejaNews > plans. But your replies often contain useful information. It's a shame that they disappear from record, making them invisible for anyone searching the archives. A good rule of thumb when judging behaviour is to ask, "What if everyone did this?". If everyone set x-no-archive, then discussions on Usenet would be ephemeral, we couldn't point people to past discussions for information, and we would lose a lot of useful information. (Also a lot of garbage.) I can't tell you how often I find useful information in the archives of comp.lang.python thanks to those who archive the gname news-to-email gateway, and Google groups. If everyone did what you use, the entire community, including myself, would be far worse off. As far as I'm concerned, setting x-no-archive is harmful, anti-social behaviour on a technical newsgroup like this. You (almost) might as well just email the poster you're replying to directly. -- Steven From jure.erznoznik at gmail.com Sat Jun 20 21:23:50 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sat, 20 Jun 2009 18:23:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Look, guys, here's the thing: In the company I work at we decided to rewrite our MRP system in Python. I was one of the main proponents of it since it's nicely cross platform and allows for quite rapid application development. The language and it's built in functions are simply great. The opposition was quite strong, especially since the owner cheered for it - .net. So, recently I started writing a part of this new system in Python. A report generator to be exact. Let's not go into existing offerings, they are insufficient for our needs. First I started on a few tests. I wanted to know how the reporting engine will behave if I do this or that. One of the first tests was, naturally, threading. The reporting engine itself will have separate, semi-independent parts that can be threaded well, so I wanted to test that. The rest you know if you read the two threads I started on this group. Now, the core of the new application is designed so that it can be clustered so it's no problem if we just start multiple instances on one server, say one for each available core. The other day, a coworker of mine said something like: what?!? you've been using Python for two days "already" and you already say it's got a major fault? I kinda aggreed with him, especially since this particular coworker programmed strictly in Python for the last 6 months (and I haven't due to other current affairs). There was no way my puny testing could reveal such a major drawback. As it turns out, I was right. I have programmed enough threading to have tried enough variations which all reveal the GIL. Which I later confirmed through searching on the web. My purpose with developing the reporting engine in Python was twofold: learn Python as I go and create a native solution which will work out- of-the-box for all systems we decide to support. Making the thing open source while I'm at it was a side-bonus. However: Since the testing revealed this, shall we say "problem", I am tempted to just use plain old C++ again. Furthermore, I was also not quite content with the speed of arithmetic processing of the python engine. I created some simple aggregating objects that only performed two additions per pass. Calling them 200K times took 4 seconds. This is another reason why I'm beginning to think C++ might be a better alternative. I must admit, had the GIL issue not popped up, I'd just take the threading benefits and forget about it. But both things together, I'm thinking I need to rethink my strategy again. I may at some point decide that learning cross platform programming is worth a shot and just write a Python plugin for the code I write. The final effect will be pretty much the same, only faster. Perhaps I will even manage to get close to Crystal Reports speed, though I highly doubt that. But in the end, my Python skill will suffer. I still have an entire application (production support) to develop in it. Thanks for all the information and please don't flame each other. I already get the picture that GIL is a hot subject. From jure.erznoznik at gmail.com Sat Jun 20 21:27:16 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sat, 20 Jun 2009 18:27:16 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: Add: Carl, Olivier & co. - You guys know exactly what I wanted. Others: Going back to C++ isn't what I had in mind when I started initial testing for my project. From grant_ito at shaw.ca Sat Jun 20 21:37:27 2009 From: grant_ito at shaw.ca (Grant Ito) Date: Sat, 20 Jun 2009 18:37:27 -0700 Subject: Developing GUI applications Message-ID: Hi everyone. I'm looking to find out what people are using for an open source wysiwyg GUI developer. I'm running both Linux and Windows but prefer to do my development in Linux. I've got the most experience with Tkinter but am willing to look at wxPython and Tix as well. Thus far I've looked into PAGE and SpecTcl. The version of PAGE I've downloaded doesn't quite look like the online manual so I'm wondering about that. SpecTcl seems cool but I can't locate SpecPython by either Erik Brunel or Richard Colley, and the SpecTix page is down as well, as is the GUIBuilder page. All the sites I've looked at seem to date back to somewhere between 2002 and 2006. Any help would be much appreciated. ~Grant. From greg at cosc.canterbury.ac.nz Sat Jun 20 22:21:23 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 21 Jun 2009 14:21:23 +1200 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: <7a5jn2F1u1773U1@mid.individual.net> Philip Semanchuk wrote: > Best of all, PyErr_CheckSignals() doesn't interfere with a Python- level > signal handler if one is set. Ah, I hadn't realised that you were doing this in C code, and I was trying to think of a Python-level solution. For C code, the solution you give sounds like a good one. My only misgiving is that the user might expect to get a KeyboardInterrupt in response to Ctrl-C, so it might be better to just let it propagate instead of turning it into a different exception. -- Greg From vincent at vincentdavis.net Sat Jun 20 22:42:18 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 20:42:18 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <77e831100906201942y7cb312ccxb87a823f0eb52b54@mail.gmail.com> Quoting Dennis Lee Bieber limitedNormal ( 75, 20 ) computed statistics: mu = 75.5121294828 sigma = 8.16374859991 Note how computing the input sigma such that 3*sigma does not exceed boundaries results in a narrow bell curve (hmm, and for this set, no one scored 95-100) retryNormal ( 75, 20 ) computed statistics: mu = 73.283826412 sigma = 16.9151951316 The retry model produces a skew, but perhaps somewhat unnatural; a real skew should still have relatively few entries in the 95-100 bin, whereas this is still rather symmetrical about the mean. Compare the 45, 65, and 80 bins between these two, those show most of the retried values that otherwise clipped to 100 below. clippedNormal ( 75, 20 ) computed statistics: mu = 75.3240108464 sigma = 18.1008966385 Note the unnatural peak of grades in the 95-100 range resulting from clipping out of range values into the range. * See, the full results below* Wow thanks for this Dennis, I am actually trying to simulate the scores on the step 1 medical boards exam. The actual distribution is not readily available. I like your limitedNormal approach. I think this is the way for me to go. I can come up with some reasonable mean and sd numbers from actual results then I this approach seems the best to simulate those results. I should actualy know more about this as I do a lot of stats but mostly regressions. I need to look up ome more about the F dist, but I think your limited approuch is the way to go. Trying to combine learning python and simulating the medical residency application process has been interesting. Here is a graph of past test results, I relize they are not on a 0 - 100 score but they is easy to address [image: step1_score_distribution_custom.GIF] Thanks Vincent Davis 720-301-3003 On Sat, Jun 20, 2009 at 7:43 PM, Dennis Lee Bieber wrote: > > I must be bored today... > > Expanded variation: > > -=-=-=-=-=- > """ > Random Scores > """ > > import random > import numpy > > def limitedNormal(mu, sigma=None): > """ > returns a random score from a normal (bell) distribution in > which > the mean, mu, is supplied by the caller, and in which the > standard deviation, sigma, is computed such that 3-sigma does > not drop below 0 [for mu < 50] or rise above 100 [for mu > 50] > sigma is shown as a parameter but is not used -- it permits > using the same arguments for all three *Normal() methods > """ > if mu < 50.0: > sigma = mu / 3.0 > else: > sigma = (100.0 - mu) / 3.0 > return random.normalvariate(mu, sigma) > > def clippedNormal(mu, sigma): > """ > returns a random score from a normal distribution in which > the mean, mu, and standard deviation, sigma, are supplied > by the caller. > the result is clipped to the range 0..100 > """ > return max(0.0, > min(100.0, > random.normalvariate(mu, sigma))) > > def retryNormal(mu, sigma): > """ > returns a random score from a normal distribution in which > the mean, mu, and the standard deviation, sigma, are supplied > by the caller. > if the result falls outside the range 0..100 a new score > is generated. > extremely large sigma, or mu close to the range end points > will cause slowness, as many results are thrown out and retried > """ > score = -1 > while not (0.0 <= score <= 100.0): > score = random.normalvariate(mu, sigma) > return score > > > def clippedGamma(mu, B): > """ > returns a random score from a gamma distribution in which the > "shape", a, is computed as the mean, mu, as from a normal > distribution divided by the B, "rate". Both mu and B are > supplied by the caller. > as the gamma distribution has a long tail to the right, for mu > > 50 > the result is computed as 100 - gamma(100-mu) to reflect the > desired skewness > results are clipped to the boundaries 0..100 as there is no easy > way to compute B to limit results, as is done for sigma in > limitedNormal() > NOTE: while the mean of the results will approach mu, the peak > of > the curve will be to the right (for mu>50) or left (for mu<50) > relative to a normal curve > """ > if mu < 50.0: > return max(0.0, > min(100.0, > random.gammavariate(mu / B, B))) > else: > return 100.0 - max(0.0, > min(100.0, > random.gammavariate((100.0 - mu) / B, > B))) > > def retryGamma(mu, B): > """ > returns a random score from a gamma distribution in which the > "shape", a, is computed as the mean, mu, as from a normal > distribution divided by the B, "rate". Both mu and B are > supplied by the caller. > as the gamma distribution has a long tail to the right, for mu > > 50 > the result is computed as 100 - gamma(100-mu) to reflect the > desired skewness > results outside the boundaries 0..100 will be retried > NOTE: while the mean of the results will approach mu, the peak > of > the curve will be to the right (for mu>50) or left (for mu<50) > relative to a normal curve > """ > score = -1 > while not (0.0 <= score <= 100.0): > if mu < 50.0: > score = random.gammavariate(mu / B, B) > else: > score = 100.0 - random.gammavariate((100.0 - mu) / B, > B) > return score > > if __name__ == "__main__": > tries = [ ("limitedNormal", limitedNormal, (75, 20)), > ("retryNormal", retryNormal, (75, 20)), > ("clippedNormal", clippedNormal, (75, 20)), > ("clippedGamma", clippedGamma, (75, 10)), > ("retryGamma", retryGamma, (75, 10)) ] > > state = random.getstate() > > for (name, func, args) in tries: > random.setstate(state) #reset random number generator so > #each run has the same sequence > scores = [func(*args) for i in range(100)] > scores.sort() #so listing is easier to scan visually > mu = numpy.mean(scores) > sigma = numpy.std(scores) > print "\n\n%s ( %s, %s )" % tuple([name] + list(args)) > print "\tcomputed statistics: mu = %s\tsigma = %s" % (mu, sigma) > (histv, histb) = numpy.histogram(scores, > bins=20, > range=(0.0, 100.0)) > print "\t\thistogram" > for i, v in enumerate(histv): > print "%4d\t%s" % (histb[i+1], "*" * v) > print "" > ## print "\t\tsorted scores" > ## print scores > print "" > > -=-=-=-=-=-=-=- > > limitedNormal ( 75, 20 ) > computed statistics: mu = 75.5121294828 sigma = 8.16374859991 > histogram > 5 > 10 > 15 > 20 > 25 > 30 > 35 > 40 > 45 > 50 > 55 * > 60 *** > 65 ****** > 70 ***************** > 75 ******************* > 80 ************************ > 85 ***************** > 90 ********** > 95 *** > 100 > > > Note how computing the input sigma such that 3*sigma does not exceed > boundaries results in a narrow bell curve (hmm, and for this set, no one > scored 95-100) > > > > > retryNormal ( 75, 20 ) > computed statistics: mu = 73.283826412 sigma = 16.9151951316 > histogram > 5 > 10 > 15 > 20 > 25 > 30 * > 35 * > 40 ** > 45 **** > 50 ** > 55 **** > 60 ****** > 65 ********** > 70 ********* > 75 ********* > 80 ************* > 85 ************* > 90 ******** > 95 ********* > 100 ********* > > The retry model produces a skew, but perhaps somewhat unnatural; a > real skew should still have relatively few entries in the 95-100 bin, > whereas this is still rather symmetrical about the mean. Compare the > 45, 65, and 80 bins between these two, those show most of the retried > values that otherwise clipped to 100 below. > > > clippedNormal ( 75, 20 ) > computed statistics: mu = 75.3240108464 sigma = 18.1008966385 > histogram > 5 > 10 > 15 > 20 > 25 > 30 * > 35 * > 40 ** > 45 *** > 50 ** > 55 **** > 60 ****** > 65 ********** > 70 ********* > 75 ******** > 80 ********* > 85 ************ > 90 ******** > 95 ******* > 100 ****************** > > Note the unnatural peak of grades in the 95-100 range resulting from > clipping out of range values into the range. > > > clippedGamma ( 75, 20 ) > computed statistics: mu = 75.2343345947 sigma = 21.1537553145 > histogram > 5 * > 10 > 15 > 20 > 25 * > 30 * > 35 *** > 40 * > 45 ***** > 50 **** > 55 ** > 60 ** > 65 ******** > 70 ***** > 75 ******* > 80 ********* > 85 ****** > 90 *********** > 95 ****************** > 100 **************** > > One entry was clipped to 0.0 as it doesn't show up below > > > > retryGamma ( 75, 20 ) > computed statistics: mu = 75.7551006676 sigma = 19.8990180392 > histogram > 5 > 10 > 15 > 20 > 25 * > 30 * > 35 *** > 40 * > 45 ***** > 50 **** > 55 *** > 60 ** > 65 ******** > 70 ***** > 75 ******* > 80 ********* > 85 ****** > 90 *********** > 95 ****************** > 100 **************** > > > > > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfraed at ix.netcom.com wulfraed at bestiaria.com > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: web-asst at bestiaria.com) > HTTP://www.bestiaria.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Sat Jun 20 23:18:53 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 20 Jun 2009 22:18:53 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <19005.42653.594623.203120@montanaro.dyndns.org> Carl> I'm sure you think you're trying to be helpful, but you're coming Carl> off as really presumptuous with this casual dismissal of their Carl> concerns. My apologies, but in most cases there is more than one way to skin a cat. Trust me, if removing the global interpreter lock was easy, or probably even it was simply hard, it almost certainly would have been done by now. Continuing to harp on this particular aspect of the CPython implementation doesn't help. Carl> I guess what really bothers me about this is how easily people Carl> throw out "shut up and use C" for some things, especially things Carl> that quite reasonably appear to be a silly limitation. You completely misunderstand I think. People don't throw out "shut up and use C" out of ignorance. In fact, I don't believe I've ever read a response which took that tone. The practical matter is that there has so far been no acceptable patch to CPython which gets rid of the global interpreter lock. Extremely smart people have tried. More than once. If Guido knew then (20 years ago) what he knows now: * that the chip manufacturers would have run out of clock speed improvements for a few years and resorted to multi-core CPUs as a way to make their computers "faster" * that garbage collection algorithms would have improved as much as they have in the past twenty years I suspect he might well have considered garbage collection instead of reference counting as a way to reclaim unreferenced memory and we might have a GIL-less CPython implementation today. Carl> Maybe you don't intend to sound like you're saying "shut up and Carl> use C", but to me, that's how you come off. If you're going to Carl> advise someone to use C, at least try to show some understanding Carl> for their concerns--it would go a long way. Then you haven't been listening. This topic comes up over and over and over again. It's a well-known limitation of the implementation. Poking people in the eye with it over and over doesn't help. The reasons for the limitation are explained every time the topic is raised. In the absence of a GIL-less CPython interpreter you are simply going to have to look elsewhere for performance improvements I'm afraid. Yes, I'll drag out the same old saws: * code hot spots in C or C++ * use tools like Pyrex, Cython, Psyco or Shed Skin * for array procesing, use numpy, preferably on top of a recent enough version of Atlas which does transparent multi-threading under the covers * use multiple processes * rewrite your code to use more efficient algorithms I don't write those out of ignorance for your plight. It's just that if you want a faster Python program today you're going to have to look elsewhere for your speedups. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From kay at fiber-space.de Sun Jun 21 00:22:18 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 20 Jun 2009 21:22:18 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On 20 Jun., 17:28, Stefan Behnel wrote: > Kay Schluehr wrote: > >> You might want to read about "The Problem with Threads": > > >>http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf > > >> and then decide to switch to an appropriate concurrency model for your use > >> case. > > > and to a programming language that supports it. > > Maybe, yes. But many different concurrency models are supported by a larger > number of programming languages in one way or another, so the choice of an > appropriate library is often sufficient - and usually a lot easier than > using the 'most appropriate' programming language. Matter of available > skills, mostly. There's usually a lot less code to be written that deals > with concurrency than code that implements what the person paying you makes > money with, so learning a new library may be worth it, while learning a new > language may not. > > Stefan This implies that people stay defensive concerning concurrency ( like me right now ) and do not embrace it like e.g. Erlang does. Sometimes there is a radical change in the way we design applications and a language is the appropriate medium to express it succinctly. Concurrency is one example, writing GUIs and event driven programs in a declarative style ( Flex, WPF, JavaFX ) is another one. In particular the latter group shows that new skills are adopted rather quickly. I don't see that a concurrency oriented language has really peaked though yet. From pavlovevidence at gmail.com Sun Jun 21 00:38:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 21:38:16 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <062b4b9d-f27b-48ec-b760-057a9c818716@d2g2000pra.googlegroups.com> On Jun 20, 8:18?pm, s... at pobox.com wrote: > ? ? Carl> Maybe you don't intend to sound like you're saying "shut up and > ? ? Carl> use C", but to me, that's how you come off. ?If you're going to > ? ? Carl> advise someone to use C, at least try to show some understanding > ? ? Carl> for their concerns--it would go a long way. > > Then you haven't been listening. ?This topic comes up over and over and over > again. ?It's a well-known limitation of the implementation. ?Poking people > in the eye with it over and over doesn't help. ?The reasons for the > limitation are explained every time the topic is raised. ?In the absence of > a GIL-less CPython interpreter you are simply going to have to look > elsewhere for performance improvements I'm afraid. ?Yes, I'll drag out the > same old saws: > > ? ? * code hot spots in C or C++ > > ? ? * use tools like Pyrex, Cython, Psyco or Shed Skin > > ? ? * for array procesing, use numpy, preferably on top of a recent enough > ? ? ? version of Atlas which does transparent multi-threading under the > ? ? ? covers > > ? ? * use multiple processes > > ? ? * rewrite your code to use more efficient algorithms > > I don't write those out of ignorance for your plight. ?It's just that if you > want a faster Python program today you're going to have to look elsewhere > for your speedups. Just for the record, I am not taking issue with the advice itself (except that you forgot "use Jython/IronPython which have no GIL"). I'm not even saying that Python was wrong for having the GIL. All I'm saying is that [this is not aimed specifically at you] this advice can be delivered with more respect for the complainer's problem, and less fanboy-like knee-jerk defensiveness of Python. Carl Banks From clp2 at rebertia.com Sun Jun 21 01:09:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Jun 2009 22:09:23 -0700 Subject: Developing GUI applications In-Reply-To: References: Message-ID: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> On Sat, Jun 20, 2009 at 6:37 PM, Grant Ito wrote: > Hi everyone. > > I'm looking to find out what people are using for an open source wysiwyg GUI > developer. I'm running both Linux and Windows but prefer to do my > development in Linux. I've got the most experience with Tkinter but am > willing to look at wxPython and Tix as well. GTK: Glade - http://glade.gnome.org/ WxPython: Boa Constructor - http://boa-constructor.sourceforge.net/ Cheers, Chris -- http://blog.rebertia.com From paddy3118 at googlemail.com Sun Jun 21 01:32:05 2009 From: paddy3118 at googlemail.com (Paddy) Date: Sat, 20 Jun 2009 22:32:05 -0700 (PDT) Subject: Rosetta Code: request for help Message-ID: Hi, If you like programming problems and reading about/creating solutions to tasks in many languages not just Python, then take a look at Rosetta Code: http://www.rosettacode.org . If you 'lurk' for a while and read the submissions of others to get a feal for the site, then their is a list of tasks that still have no Python solution posted here: http://www.rosettacode.org/wiki/Tasks_not_implemented_in_Python that you might help out with. Some problems might need the use of specific but well known libraries such as PIL for the graphics, or specific knowledge. Others might be straight forward; or could do with an example translated to Python 3.x if it would change a lot from 2.x etc. Please take a look, I know I know I enjoy being involved. - Paddy. From jpablo.romero at gmail.com Sun Jun 21 01:33:22 2009 From: jpablo.romero at gmail.com (=?ISO-8859-1?Q?Juan_Pablo_Romero_M=E9ndez?=) Date: Sun, 21 Jun 2009 00:33:22 -0500 Subject: Developing GUI applications In-Reply-To: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> References: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> Message-ID: PyQt: http://www.riverbankcomputing.co.uk/software/pyqt/intro All the benefits of Qt: multiplataform, excellent documentation, great API, visual widget designer, etc, etc. For the coding itself, I use netbeans + python plugin. Regards, Juan Pablo 2009/6/21 Chris Rebert : > On Sat, Jun 20, 2009 at 6:37 PM, Grant Ito wrote: >> Hi everyone. >> >> I'm looking to find out what people are using for an open source wysiwyg GUI >> developer. I'm running both Linux and Windows but prefer to do my >> development in Linux. I've got the most experience with Tkinter but am >> willing to look at wxPython and Tix as well. > > GTK: Glade - http://glade.gnome.org/ > WxPython: Boa Constructor - http://boa-constructor.sourceforge.net/ > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > From billy.chasen at gmail.com Sun Jun 21 02:32:04 2009 From: billy.chasen at gmail.com (billy) Date: Sat, 20 Jun 2009 23:32:04 -0700 (PDT) Subject: Python class gotcha with scope? Message-ID: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> I don't quite understand why this happens. Why doesn't b have its own version of r? If r was just an int instead of a dict, then it would. >>> class foo: ... r = {} ... def setn(self, n): ... self.r["f"] = n ... >>> a = foo() >>> a.setn(4) >>> >>> b = foo() >>> b.r {'f': 4} thanks, billy From phostu at gmail.com Sun Jun 21 02:38:28 2009 From: phostu at gmail.com (Vincent) Date: Sat, 20 Jun 2009 23:38:28 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: <79d578a6-3cce-40e3-950e-ece3a452ce7d@c18g2000prh.googlegroups.com> On Jun 21, 2:32?pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ... ? ? r = {} > ... ? ? def setn(self, n): > ... ? ? ? ? ? ? self.r["f"] = n > ...>>> a = foo() > >>> a.setn(4) > > >>> b = foo() > >>> b.r > > {'f': 4} > > thanks, > > billy class Foo: def __init__(self): self.r = {} def setn(self,n): self.r['f'] = n a = Foo() a.setn(3) a.r {'f': 3} b = Foo() b.r {} From phostu at gmail.com Sun Jun 21 02:40:04 2009 From: phostu at gmail.com (Vincent) Date: Sat, 20 Jun 2009 23:40:04 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> <79d578a6-3cce-40e3-950e-ece3a452ce7d@c18g2000prh.googlegroups.com> Message-ID: <0ea4eceb-9291-49ee-8896-d13c88f6cd93@k17g2000prn.googlegroups.com> On Jun 21, 2:38?pm, Vincent wrote: > On Jun 21, 2:32?pm, billy wrote: > > > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ... ? ? r = {} > > ... ? ? def setn(self, n): > > ... ? ? ? ? ? ? self.r["f"] = n > > ...>>> a = foo() > > >>> a.setn(4) > > > >>> b = foo() > > >>> b.r > > > {'f': 4} > > > thanks, > > > billy > > class Foo: > ? ? def __init__(self): > ? ? ? ? self.r = {} > ? ? def setn(self,n): > ? ? ? ? self.r['f'] = n > > a = Foo() > a.setn(3) > a.r > {'f': 3} > b = Foo() > b.r > {} you defined r as class-level variable. and i defined r as instance-level variable. From pavlovevidence at gmail.com Sun Jun 21 02:41:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 23:41:03 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: On Jun 20, 11:32?pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ... ? ? r = {} > ... ? ? def setn(self, n): > ... ? ? ? ? ? ? self.r["f"] = n > ...>>> a = foo() > >>> a.setn(4) > > >>> b = foo() > >>> b.r > > {'f': 4} r is a class attribute, that is, it is attacted to the class itself. Look at what happens when you enter foo.r at the interactive prompt: >>> foo.r {'f': 4} You want an instance attribute, a value attached to the instance of the class. You create those in the __init__ method: class foo: def __init__(self): self.r = {} def setn(self,n): self.r["n"] = n Carl Banks From billy.chasen at gmail.com Sun Jun 21 02:53:05 2009 From: billy.chasen at gmail.com (billy) Date: Sat, 20 Jun 2009 23:53:05 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: great, thanks for the quick responses :) On Jun 21, 2:41?am, Carl Banks wrote: > On Jun 20, 11:32?pm, billy wrote: > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ... ? ? r = {} > > ... ? ? def setn(self, n): > > ... ? ? ? ? ? ? self.r["f"] = n > > ...>>> a = foo() > > >>> a.setn(4) > > > >>> b = foo() > > >>> b.r > > > {'f': 4} > > r is a class attribute, that is, it is attacted to the class itself. > Look at what happens when you enter foo.r at the interactive prompt: > > >>> foo.r > > {'f': 4} > > You want an instance attribute, a value attached to the instance of > the class. ?You create those in the __init__ method: > > class foo: > ? ? def __init__(self): > ? ? ? ? self.r = {} > ? ? def setn(self,n): > ? ? ? ? self.r["n"] = n > > Carl Banks From Olivier.Darge at gmail.com Sun Jun 21 03:32:31 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sun, 21 Jun 2009 00:32:31 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: <08830f2a-efd9-4e19-bf7b-e46c7e92a0ef@j20g2000vbp.googlegroups.com> On 21 juin, 03:27, Jure Erzno?nik wrote: > Add: > Carl, Olivier & co. - You guys know exactly what I wanted. > Others: Going back to C++ isn't what I had in mind when I started > initial testing for my project. Do you think multiprocessing can help you seriously ? Can you benefit from multiple cpu ? did you try to enhance your code with numpy ? Olivier (installed a backported multiprocessing on his 2.5.1 Python, but need installation of Xcode first) From p.elagin at gmail.com Sun Jun 21 03:43:22 2009 From: p.elagin at gmail.com (=?KOI8-R?B?/sXbydLTy8nKIOvP1A==?=) Date: Sun, 21 Jun 2009 00:43:22 -0700 (PDT) Subject: Newbie queue question References: Message-ID: <344816e6-2cbf-45d5-bea4-9cb90b18a1c0@o14g2000vbo.googlegroups.com> 1. say me dbf files count? 2. why dbf ? From jure.erznoznik at gmail.com Sun Jun 21 04:20:03 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sun, 21 Jun 2009 01:20:03 -0700 (PDT) Subject: Newbie queue question References: <344816e6-2cbf-45d5-bea4-9cb90b18a1c0@o14g2000vbo.googlegroups.com> Message-ID: <012d8040-b72b-48d1-84cf-471b82ff94d9@x6g2000vbg.googlegroups.com> On Jun 21, 9:43?am, ????????? ??? wrote: > 1. say me dbf files count? > 2. why dbf ? It was just a test. It was the most compatible format I could get between Python and the business application I work with without using SQL servers and such. Otherwise it's of no consequence. The final application will have a separate input engine that will support multiple databases as input. Jure From jure.erznoznik at gmail.com Sun Jun 21 04:39:38 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sun, 21 Jun 2009 01:39:38 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> <08830f2a-efd9-4e19-bf7b-e46c7e92a0ef@j20g2000vbp.googlegroups.com> Message-ID: On Jun 21, 9:32?am, OdarR wrote: > > Do you think multiprocessing can help you seriously ? > Can you benefit from multiple cpu ? > > did you try to enhance your code with numpy ? > > Olivier > (installed a backported multiprocessing on his 2.5.1 Python, but need > installation of Xcode first) Multithreading / multiprocessing can help me with my problem. As you know, database reading is typically I/O bound so it helps to put it in a separate thread. I might not even notice the GIL if I used SQL access in the first place. As it is, DBFPY is pretty CPU intensive since it's a pure Python DBF implementation. To continue: the second major stage (summary calculations) is completely CPU bound. Using numpy might or might not help with it. Those are simple calculations, mostly additions. I try not to put the entire database in arrays to save memory and so I mostly just add counters where I can. Soe functions simply require arrays, but they are more rare, so I guess I'm safe with that. You wouldn't believe how complex some reports can be. Threading + memory saving is a must and even so, I'll probably have to implement some sort of serialization later on, so that the stuff can run on more memory constrained devices. The third major stage, rendering engine, is again mostly CPU bound, but at the same time it's I/O bound as well when outputting the result. All three major parts are more or less independent from each other and can run simultaneously, just with a bit of a delay. I can perform calculations while waiting for the next record and I can also start rendering immediately after I have all the data for the first group available. I may use multiprocessing, but I believe it introduces more communication overhead than threads and am so reluctant to go there. Threads were perfect, other stuff wasn't. To make things worse, no particular extension / fork / branch helps me here. So if I wanted to just do the stuff in Python, I'd have to move to Jthon or IronPython and hope cPython eventually improves in this area. I do actually need cPython since the other two aren't supported on all platforms my company intends to support. The main issue I currently have with GIL is that execution time is worse when I use threading. Had it been the same, I wouldn't worry too much about it. Waiting for a permenent solution would be much easier then... From lucafbb at gmail.com Sun Jun 21 05:28:19 2009 From: lucafbb at gmail.com (Luca) Date: Sun, 21 Jun 2009 11:28:19 +0200 Subject: raw_input with a pre-compiled data In-Reply-To: <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <27308d500906210228t2b62ab6dyb6b12e821dd7cad5@mail.gmail.com> On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: > On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >> Hi all. >> >> I need to use a function like the raw_input to read data from user >> command line, but I really like to pre-compile the choice and I'm not >> able to do this. There is some other function/module I can use? >> I wanna to pre-compile the raw_input input line with the current working path. > > What does "pre-compile" mean in this context? It's not clear at all, > so I can't even understand your question. I'm really sorry to all that replied... In fact I literally traduced a concept from italian and the term precompiled was not so clear... What I mean is this: I wanna that raw_input (or other modules) ask to the user the data, but some data inserted is already present, to the user can cancel it with the BACKSPACE key. Examples below (the "_" is the initial cursor position). >>> raw_input("Insert the directory to work: ") Insert the directory to work: _ What I need is: >>> XXX_raw_input("Insert the directory to work: ", default="/home/john/") Insert the directory to work: /home/john_ In the second example a user can cancel the text "/home/john". I hope this time is more clear, sorry again. -- -- luca From mail at microcorp.co.za Sun Jun 21 05:38:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 21 Jun 2009 11:38:18 +0200 Subject: Developing GUI applications References: Message-ID: <007a01c9f254$026c5ac0$0d00a8c0@Hendrik> "Grant Ito" wrote: > Hi everyone. > > I'm looking to find out what people are using for an open source wysiwyg GUI > developer. I'm running both Linux and Windows but prefer to do my > development in Linux. I've got the most experience with Tkinter but am > willing to look at wxPython and Tix as well. > > Thus far I've looked into PAGE and SpecTcl. The version of PAGE I've > downloaded doesn't quite look like the online manual so I'm wondering about > that. SpecTcl seems cool but I can't locate SpecPython by either Erik Brunel > or Richard Colley, and the SpecTix page is down as well, as is the > GUIBuilder page. > > All the sites I've looked at seem to date back to somewhere between 2002 and > 2006. Any help would be much appreciated. Have a long, hard look at Boa Constructor. It is a RAD based on wx. It actually works as advertised. - Hendrik From kushal.kumaran+python at gmail.com Sun Jun 21 05:47:45 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sun, 21 Jun 2009 15:17:45 +0530 Subject: os.read in non blocking mode of os.open : resource busy error In-Reply-To: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> References: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> Message-ID: <1e364c4e0906210247r6dbcfbe6kdb963ff86ebd3c5a@mail.gmail.com> On Wed, Jun 17, 2009 at 7:18 PM, kshama nagaraj wrote: > Dear all, > > I am using os.open to open a tun/tap device and then read data from it. > I also need to do some other tasks apart from reading from this device. So i > wish to have the read non blocking. > I am opening the device in non-block mode using os.O_NONBLOCK . > But, if i do this, i get an error when i call the os.read a follows: > > ?File "./tunnel_more1.py", line 305, in main_loop > ??? payload = os.read(self.tun_fd,64) > OSError: [Errno 11] Resource temporarily unavailable > >From the glibc documentation of read: `EAGAIN' Normally, when no input is immediately available, `read' waits for some input. But if the `O_NONBLOCK' flag is set for the file (*note File Status Flags::), `read' returns immediately without reading any data, and reports this error. And from ipython: In [1]: import errno In [2]: print errno.EAGAIN 11 That's your error 11. > I am running my application with GNU Radio on Ubuntu. > > Can some one tell me, what is the error? What are the ways to use non > blocking read? > > thanks all for your time and attention. > > From mail at microcorp.co.za Sun Jun 21 05:47:49 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 21 Jun 2009 11:47:49 +0200 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net><4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <009601c9f255$5708b460$0d00a8c0@Hendrik> "Kay Schluehr" wrote: > This implies that people stay defensive concerning concurrency ( like > me right now ) and do not embrace it like e.g. Erlang does. Sometimes > there is a radical change in the way we design applications and a > language is the appropriate medium to express it succinctly. > Concurrency is one example, writing GUIs and event driven programs in > a declarative style ( Flex, WPF, JavaFX ) is another one. In > particular the latter group shows that new skills are adopted rather > quickly. > > I don't see that a concurrency oriented language has really peaked > though yet. I think that this is because (like your link has shown) the problem is really not trivial, and also because the model that can bring sanity to the party (independent threads/processes that communicate with queued messages) is seen as inefficient at small scale. - Hendrik From rklein at tpg.com.au Sun Jun 21 05:57:33 2009 From: rklein at tpg.com.au (rkl) Date: Sun, 21 Jun 2009 02:57:33 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> On Jun 15, 2:35?am, tom wrote: > i can traverse adirectoryusing os.listdir() or os.walk(). but if adirectoryhas a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > adirectoryas a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. I might be a little late with my comment here. David Beazley in his PyCon'2008 presentation "Generator Tricks For Systems Programmers" had this very elegant example of handling an unlimited numbers of files: import os, fnmatch def gen_find(filepat,top): """gen_find(filepat,top) - find matching files in directory tree, start searching from top expects: a file pattern as string, and a directory path as string yields: a sequence of filenames (including paths) """ for path, dirlist, filelist in os.walk(top): for name in fnmatch.filter(filelist,filepat): yield os.path.join(path,name) for file in gen_find('*.py', '/'): print file From mail at timgolden.me.uk Sun Jun 21 06:06:23 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 21 Jun 2009 11:06:23 +0100 Subject: waling a directory with very many files In-Reply-To: <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> Message-ID: <4A3E061F.50108@timgolden.me.uk> rkl wrote: > I might be a little late with my comment here. > > David Beazley in his PyCon'2008 presentation "Generator Tricks > For Systems Programmers" had this very elegant example of handling an > unlimited numbers of files: David Beazley's generator stuff is definitely worth recommending on. I think the issue here is that: anything which ultimately uses os.listdir (and os.walk does) is bound by the fact that it will create a long list of every file before handing it back. Certainly there are techniques (someone posted a ctypes wrapper for opendir; I recommended FindFirst/NextFile on Windows) which could be applied, but those are all outside the stdlib. TJG From __peter__ at web.de Sun Jun 21 06:51:20 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Jun 2009 12:51:20 +0200 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: Luca wrote: > On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: >> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >>> Hi all. >>> >>> I need to use a function like the raw_input to read data from user >>> command line, but I really like to pre-compile the choice and I'm not >>> able to do this. There is some other function/module I can use? >>> I wanna to pre-compile the raw_input input line with the current working >>> path. >> >> What does "pre-compile" mean in this context? It's not clear at all, >> so I can't even understand your question. > > I'm really sorry to all that replied... In fact I literally traduced a With "traduced" you stumbled upon another false friend ;) http://it.wikipedia.org/wiki/Falso_amico > concept from italian and the term precompiled was not so clear... > > What I mean is this: I wanna that raw_input (or other modules) ask to > the user the data, but some data inserted is already present, to the > user can cancel it with the BACKSPACE key. > > Examples below (the "_" is the initial cursor position). > > >>> raw_input("Insert the directory to work: ") > Insert the directory to work: _ > > What I need is: > >>> XXX_raw_input("Insert the directory to work: ", > >>> default="/home/john/") > Insert the directory to work: /home/john_ > > In the second example a user can cancel the text "/home/john". > > I hope this time is more clear, sorry again. import readline def input_default(prompt, default): def startup_hook(): readline.insert_text(default) readline.set_startup_hook(startup_hook) try: return raw_input(prompt) finally: readline.set_startup_hook(None) print input_default("directory? ", default="/home/john") The cmd module may also be worth having a look. Peter From stefan_ml at behnel.de Sun Jun 21 06:55:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 21 Jun 2009 12:55:00 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <4a3e1184$0$31878$9b4e6d93@newsspool3.arcor-online.net> Christian Heimes wrote: > Hard computations gain more speed from carefully crafted C or Fortran > code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or > parallelized algorithms. If you start sharing values between multiple > cores you have a serious problem. > > Oh, and use NumPy for the job ;) [...] > It *is* a well known limitation of Python. All the nice 'n shiny syntax > and features are coming with a cost. Python is a powerful language and > good tool for lots of stuff. But Python is and will never become the > ?bertool that solves every problem perfectly. At some point you need a > different tool to get the raw power of your machine. C (and perhaps > Fortran) are the weapons of choice for number crunching. Well, and there's always Cython to the rescue when you need it. Stefan From stefan_ml at behnel.de Sun Jun 21 07:20:11 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 21 Jun 2009 13:20:11 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4a3e176c$0$31861$9b4e6d93@newsspool3.arcor-online.net> Jure Erzno?nik wrote: > On Jun 20, 1:36 am, a... at pythoncraft.com (Aahz) wrote: >> You should put up or shut up -- I've certainly seen multi-core speedup >> with threaded software, so show us your benchmarks! >> -- > > Sorry, no intent to offend anyone here. Flame wars are not my thing. > > I have shown my benchmarks. See first post and click on the link. > That's the reason I started this discussion. > > All I'm saying is that you can get threading benefit, but only if the > threading in question is implemented in C plugin. > I have yet to see pure Python code which does take advantage of > multiple cores. From what I read about GIL, this is simply impossible > by design. Well, CPython is written in C. So running Python code in CPython will necessarily run C code (whatever "plugin" means in your post above). If that C code frees the GIL or not depends on the parts of CPython or external packages that you use. And there are many parts that free the GIL and will thus benefit (sometimes heavily) from threading and multiple-cores, and there are also many parts that do not free the GIL and will therefore not (or likely not) benefit from multiple-cores. Claiming that "pure Python code does not free the GIL" in the context of CPython when you define "pure Python code" as code that does not depend on C code is plain flawed. Stefan From jeremy+complangpython at jeremysanders.net Sun Jun 21 07:48:19 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Sun, 21 Jun 2009 12:48:19 +0100 Subject: Status of Python threading support (GIL removal)? References: Message-ID: Jesse Noller wrote: > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. I don't know whether anyone else brought this up, but it looks like Python has problems with even this form of threading http://www.dabeaz.com/python/GIL.pdf It's certainly a very interesting read if you're interested in this subject. -- Jeremy Sanders http://www.jeremysanders.net/ From luislupeXXX at gmailXXX.com Sun Jun 21 07:51:16 2009 From: luislupeXXX at gmailXXX.com (Luis P. Mendes) Date: 21 Jun 2009 11:51:16 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) Message-ID: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> Hi, I have a program that uses a lot of resources: memory and cpu but it never returned this error before with other loads: """ MemoryError c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the error above Aborted """ The last time I checked physical RAM while the script was running, it was used in about 75% and there is no reason (based in other runs of the program) for it to surpass 80% (maximum). $ python -V Python 2.5.2 Pyscopg2 is version 2.0.8 I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ 1.66GHz and 3GB of RAM I could not find this error. What does this mean? Is this a bug of Python? of Psycopg2? Luis From lorenzo.digregorio at gmail.com Sun Jun 21 07:55:45 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sun, 21 Jun 2009 04:55:45 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> On 21 Jun., 01:54, Dave Angel wrote: > LorenzoDiGregoriowrote: > > On Jun 20, 8:43 pm, Dave Angel wrote: > > >>LorenzoDiGregoriowrote: > > >>> Hi, > > >>> I'm wondering what would be the preferred way to solve the following > >>> forward reference problem: > > >>> --------------------------------------- > >>> class BaseA(object): > >>> ? ? def __init__(self): > >>> ? ? ? ? return > > >>> class DebugA(BaseA): > >>> ? ? def __init__(self): > >>> ? ? ? ? return > > >>> # here I would have a prototype of class A which is the same as class > >>> BaseA > > >>> class B(object): > >>> ? ? def __init__(self): > >>> ? ? ? ? self.obj =() > >>> ? ? ? ? return > > >>> if __name__ ="__main__": > >>> # ? ?class A(BaseA): # Uncomment this for using BaseA objects > >>> # ? ? ? pass > >>> ? ? class A(DebugA): # Uncomment this for using DebugA objects > >>> ? ? ? ? pass > >>> --------------------------------------- > > >>> I can figure out some ways to fix this but none seems satisfying. > >>> Either they are too specific or too cumbersome. > >>> A runtime redefinition of class A does not seem to work either. > >>> What would be the most "pythonesque" solution other than sorting out > >>> the class order? > > >>> Best Regards, > >>>Lorenzo > > >> You haven't shown us any problem. ?class B works fine with a forward > >> reference to A. ?Now if you were trying to subclass A before defining > >> it, that'd be a problem. ?Or if you were trying to make an instance of B > >> before defining A. > > >> Better put some code together with enough meat to actually show a > >> symptom. ?And tell us what sys.version says. ?I'm testing with ? 2.6.2 > >> (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > >> on Win XP.- Hide quoted text - > > >> - Show quoted text - > > > Thank you for your help: I'm working on a rather large source, but I > > think I have isolated the problem now. > > This listing generates an error: > > > ----------------------------------------------- > > class BaseA(object): > > ? ? def __init__(self): > > ? ? ? ? return > > > class DebugA(BaseA): > > ? ? def __init__(self): > > ? ? ? ? return > > > class B(object): > > ? ? def __init__(self,test=A()): > > ? ? ? ? self.obj =() > > ? ? ? ? return > > > if __name__ ="__main__": > > # ? ?class A(BaseA): # Uncomment this for using BaseA objects > > # ? ? ? ?pass > > ? ? ?class A(DebugA): # Uncomment this for using DebugA objects > > ? ? ? ? ?pass > > ----------------------------------------------- > > > The error happens because Python apparently evaluates the named > > arguments before running the script. > > I think I have read something about this some (long) time ago but I > > can't find it anymore. > > > Suggestions? > > > BTW, my Python version is 2.6.1 (with latest PyDev). > > > Thx! > >Lorenzo > > This error is caused because a default argument uses class A. ?Default > arguments of class methods are evaluated during the definition of the > class, and not later when the class is instantiated. ?Thus the problem. > > To work around that specific problem, you may want to use the following: > > class B(object): > ? ? def __init__(self,test=None): > ? ? ? ? if test==None: > ? ? ? ? ? ? test = A() > ? ? ? ? self.obj =() > ? ? ? ? return > > This is actually different than what you had, since what you had would > have used the same A() object for all instances of B that didn't supply > their own test() parameter. ?Maybe that's what you wanted, and maybe > not, but default arguments set to mutable values are frequently a bug. > > But I'm wondering if you're just looking for problems. ?Why not put the > commented switch early in the file, and test for it wherever you need to > use it? > > import ?x, y, z > _debug = False > #_debug = True > > then as soon as ?BaseA and DebugA are defined, do the following: > > if _debug: > ? ? class A(DebugA): > ? ? ? ? pass > else: > ? ? class A(BaseA) > ? ? ? ? pass- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - I had also thought of using "None" (or whatever else) as a marker but I was curious to find out whether there are better ways to supply an object with standard values as a default argument. In this sense, I was looking for problems ;-) Of course the observation that "def" is an instruction and no declaration changes the situation: I would not have a new object being constructed for every instantiation with no optional argument, because __init__ gets executed on the instantiation but test=A() gets executed on reading 'def'. At this point I think there is no other way than using a marker as suggested above multiple times, if I want to supply a new object with default values for non-passed arguments. Anybody with a better idea? From piet at cs.uu.nl Sun Jun 21 08:25:13 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 21 Jun 2009 14:25:13 +0200 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: I notice that I see several postings on news:comp.lang.python that are replies to other postings that I don't see. Examples are the postings by Dennis Lee Bieber that I am replying to (but I break the thread on purpose). For example the posting with Message-ID: references: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c at mail.gmail.com> which is not present on my news server. I have been wondering why these disappear, and I noticed the following in the Dennis Lee Bieber posting: On Sat, 20 Jun 2009 11:48:21 -0600, Vincent Davis declaimed the following in gmane.comp.python.general: So apparently some of these come through gmane.comp.python.general. So my question is: would this be the cause of these disappearing postings? Are postings on gmane.comp.python.general not relayed to comp.lang.python? Are they relayed to the python mailing list? I find it quite disturbing that sometimes only half of a discussion is visible. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From me at gustavonarea.net Sun Jun 21 08:27:32 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Sun, 21 Jun 2009 05:27:32 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <73497769-1271-401b-9ee2-5e9e7ebb6274@g20g2000vba.googlegroups.com> Hi, everyone. OK, I got it now! The value of the hash is not decisive, as __eq__ will still be called when the hashes match. It's like a filter, for performance reasons. It's really nice, I just tried it and it worked. Thank you very, very much!! Cheers, - Gustavo. From lie.1296 at gmail.com Sun Jun 21 09:04:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:04:59 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) In-Reply-To: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> Message-ID: <%dq%l.20091$y61.11699@news-server.bigpond.net.au> Luis P. Mendes wrote: > Hi, > > I have a program that uses a lot of resources: memory and cpu but it > never returned this error before with other loads: > > """ > MemoryError > c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the > error above > Aborted > """ > The last time I checked physical RAM while the script was running, it was > used in about 75% and there is no reason (based in other runs of the > program) for it to surpass 80% (maximum). > > $ python -V > Python 2.5.2 > > Pyscopg2 is version 2.0.8 > > I use Linux, Kernel 2.6.24.5-smp #2 SMP > with a Core2 CPU T5500 @ 1.66GHz and 3GB of RAM > > I could not find this error. What does this mean? > > Is this a bug of Python? of Psycopg2? > > Luis Have you tried running without psyco? Psyco increases memory usage quite significantly. If it runs well without psyco, you can try looking at your code and selectively psyco parts that need the speed boost the most. From lie.1296 at gmail.com Sun Jun 21 09:13:09 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:13:09 GMT Subject: Inheritance and forward references (prototypes) In-Reply-To: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: Lorenzo Di Gregorio wrote: > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observation that "def" is an instruction and no > declaration changes the situation: I would not have a new object being > constructed for every instantiation with no optional argument, because > __init__ gets executed on the instantiation but test=A() gets executed > on reading 'def'. > > At this point I think there is no other way than using a marker as > suggested above multiple times, if I want to supply a new object with > default values for non-passed arguments. Using None as default for mutable default argument is the common idiom for the problem you're having. From luislupeXXX at gmailXXX.com Sun Jun 21 09:23:43 2009 From: luislupeXXX at gmailXXX.com (Luis P. Mendes) Date: 21 Jun 2009 13:23:43 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> <%dq%l.20091$y61.11699@news-server.bigpond.net.au> Message-ID: <4a3e345e$0$90270$14726298@news.sunsite.dk> Sun, 21 Jun 2009 13:04:59 +0000, Lie Ryan escreveu: > Luis P. Mendes wrote: >> Hi, >> >> I have a program that uses a lot of resources: memory and cpu but it >> never returned this error before with other loads: >> >> """ >> MemoryError >> c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the >> error above >> Aborted >> """ >> The last time I checked physical RAM while the script was running, it >> was used in about 75% and there is no reason (based in other runs of >> the program) for it to surpass 80% (maximum). >> >> $ python -V >> Python 2.5.2 >> >> Pyscopg2 is version 2.0.8 >> >> I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ >> 1.66GHz and 3GB of RAM >> >> I could not find this error. What does this mean? >> >> Is this a bug of Python? of Psycopg2? >> >> Luis > > Have you tried running without psyco? Psyco increases memory usage quite > significantly. > > If it runs well without psyco, you can try looking at your code and > selectively psyco parts that need the speed boost the most. I really need Psyco (use version 1.6 - forgot to mention earlier) to speed up the code. The part that consumes more memory is the one that needs Psyco the most. Luis From paul.paj at gmail.com Sun Jun 21 09:31:58 2009 From: paul.paj at gmail.com (Paul Johnston) Date: Sun, 21 Jun 2009 06:31:58 -0700 (PDT) Subject: class or instance method References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> Message-ID: <76a06a1d-3536-4bf1-ad39-cbb1c1d71ea5@a5g2000pre.googlegroups.com> Hi, > class class_or_instance(object): > ? ? def __init__(self, fn): ... This works a treat, thank-you. Paul From lie.1296 at gmail.com Sun Jun 21 09:50:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:50:08 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) In-Reply-To: <4a3e345e$0$90270$14726298@news.sunsite.dk> References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> <%dq%l.20091$y61.11699@news-server.bigpond.net.au> <4a3e345e$0$90270$14726298@news.sunsite.dk> Message-ID: Luis P. Mendes wrote: > Sun, 21 Jun 2009 13:04:59 +0000, Lie Ryan escreveu: >> Have you tried running without psyco? Psyco increases memory usage quite >> significantly. >> >> If it runs well without psyco, you can try looking at your code and >> selectively psyco parts that need the speed boost the most. > > I really need Psyco (use version 1.6 - forgot to mention earlier) to > speed up the code. > The part that consumes more memory is the one that needs Psyco the most. Yeah, but try running without psyco first and see if the problem is really caused by psyco. If it still produces an error, then we can rule out psyco as the root cause of the problem. Selective psyco-ing can reduce the amount of memory psyco uses and may just be slightly slower than full boosting (and sometimes it may actually become faster in memory constrained situation as less swapping is needed). From deets at nospam.web.de Sun Jun 21 10:15:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 16:15:54 +0200 Subject: question about c++ and python In-Reply-To: References: Message-ID: <7a6tkqF1teatrU2@mid.uni-berlin.de> Issa Kamar schrieb: > Dear Sirs; > > I'm a PhD student,i have a question i wish if you can help me really.I'm working in Linux ubuntu 8.10,i have a c++ file which i need to connect this file to a python file and run it,i wish really if u can send me the method that can help me to do this and really I'm very thankful. If you send me money, I will send you the code. Otherwise, I suggest you start googling a bit and find out how to map C++-classes to Python. There is an abundance of information on that topic out there. Popular options include SWIG, Boost::Python and SIP, the latter I can only recommend from personal experience. Diez From issa.kamar at aul.edu.lb Sun Jun 21 10:17:11 2009 From: issa.kamar at aul.edu.lb (Issa Kamar) Date: Sun, 21 Jun 2009 16:17:11 +0200 Subject: question about c++ and python Message-ID: <9F3CEFC83E7BF24993F24EC234527543168B13CC4A@srv100002.aul.local> Dear Sirs; I'm a PhD student,i have a question i wish if you can help me really.I'm working in Linux ubuntu 8.10,i have a c++ file which i need to connect this file to a python file and run it,i wish really if u can send me the method that can help me to do this and really I'm very thankful. best regards From philip at semanchuk.com Sun Jun 21 10:49:42 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Jun 2009 10:49:42 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: <7a5jn2F1u1773U1@mid.individual.net> References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> <7a5jn2F1u1773U1@mid.individual.net> Message-ID: <756639A4-CE03-4E84-8EBE-BF3D9B88F375@semanchuk.com> On Jun 20, 2009, at 10:21 PM, greg wrote: > Philip Semanchuk wrote: > >> Best of all, PyErr_CheckSignals() doesn't interfere with a Python- >> level signal handler if one is set. > > Ah, I hadn't realised that you were doing this in C > code, and I was trying to think of a Python-level > solution. > > For C code, the solution you give sounds like a > good one. > > My only misgiving is that the user might expect to > get a KeyboardInterrupt in response to Ctrl-C, so > it might be better to just let it propagate instead > of turning it into a different exception. I completely agree. The simple solution (for me) is to handle all return codes of EINTR the same way which is to raise posix_ipc.Error with the message "The wait was interrupted by a signal". But that loses information. KeyboardInterrupt is very specific while posix_ipc.Error is generic and even parsing the message doesn't tell much more. When my C code sees EINTR, I will probably raise KeyboardError when I see that and add a specific posix_ipc.SignalError to raise in other EINTR circumstances. Thanks, Philip From vincent at vincentdavis.net Sun Jun 21 11:34:23 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 21 Jun 2009 09:34:23 -0600 Subject: python needs a tutorial for install and setup on a Mac Message-ID: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> I am running python on a mac and when I was getting going it was difficult to setup information. Specifically how modify bash_profile, how pythonpath works and how to set it up. how to switch between python versions. How/where to install modules if you have multiple installed versions. I am thinking about this from perspective of a new pythoner (is there a word for a person who programs in python). I think many new pythoners may be like me and don't mess with the underling UNIX on a mac. My question/suggestion is that there be a nice tutorial for this. I am wiling to contribute much but I am still somewhat new to python and may need help with some details. Also where should this be posted, how do I post it. Do other think there is a need? Any willing to help? But of course I may have missed a great tutorial out there if so I think It needs to be easier to findor I need to learn how to look. Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Jun 21 11:54:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 17:54:47 +0200 Subject: docs error for PyBuffer_FillInfo? Message-ID: <7a73e8F1totcrU1@mid.uni-berlin.de> I'm trying to wrap a C++-lib with SIP & need to return a buffer-object from one method. I'm on python2.6 (OS X, but that doesn't matter I guess), and http://docs.python.org/c-api/buffer.html#Py_buffer gives a signature like this: int PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len, int readonly, int infoflags)? However, the abstract.h of the Python-installation has this: PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, Py_ssize_t len, int readonly, int flags); And obviously enough, compiling my wrapper fails because there is an argument missing. So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - all I've got is a void* and a total size of the buffer. Diez From aahz at pythoncraft.com Sun Jun 21 11:57:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 08:57:13 -0700 Subject: Status of Python threading support (GIL removal)? References: <627e1793-aeeb-43ec-9e09 <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: In article <90303b55-8686-4d56-b89c-01e31d0a6080 at l8g2000vbp.googlegroups.com>, =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > >So, recently I started writing a part of this new system in Python. A >report generator to be exact. Let's not go into existing offerings, >they are insufficient for our needs. > >First I started on a few tests. I wanted to know how the reporting >engine will behave if I do this or that. One of the first tests was, >naturally, threading. The reporting engine itself will have separate, >semi-independent parts that can be threaded well, so I wanted to test >that. This is not something that I would expect Python threads to provide a performance boost for. I would expect that if it were a GUI app, it would improve responsiveness, properly designed. If performance were a goal, I would start by profiling it under a single-threaded design and see where the hotspots were, then either choose one of several options for improving performance or go multi-process. Note that I'm generally one of the Python thread boosters (unlike some people who claim that Python threads are worthless), but I also never claim that Python threads are good for CPU-intensive operations (which report generation is), *except* for making GUI applications more responsive. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sun Jun 21 11:59:37 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 08:59:37 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , Jeremy Sanders wrote: >Jesse Noller wrote: >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > >I don't know whether anyone else brought this up, but it looks >like Python has problems with even this form of threading > >http://www.dabeaz.com/python/GIL.pdf Most of us have already seen this. It's a good point, but IME writing multi-threaded apps for multi-core machines, I think one should be careful to avoid reading too much into it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From gruszczy at gmail.com Sun Jun 21 12:00:31 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 21 Jun 2009 18:00:31 +0200 Subject: urllib2 urlopen takes too much time Message-ID: <1be78d220906210900n66b606ffy496a6030d488fd5d@mail.gmail.com> I have encountered a performance problem using suds, which was traced down to _socket.recv. I am calling some web services and each of them uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, while the rest of the call is finished in milliseconds. Because of this, my web app works really slow, especially when it must do many ws calls. I could of course decrease the number of calls and do a lot of caching (which would be quite perilous and I wouldn't like to delve into this), but it seems as treating symptoms, rather than the illness itself. The machine I am connecting to through ws is in the same building, the connection should be really fast and mostly it is - except for using suds. Is it possible, that I could done something wrong and it hangs on this socket for too long? Have anyone encountered similar problems? Oh, and we did some profiling using also other tool written in C#, that also uses those web services and it worked much faster, so it doesn't seem to be connection problem. -- Filip Gruszczy?ski From grguthrie at gmail.com Sun Jun 21 12:00:52 2009 From: grguthrie at gmail.com (guthrie) Date: Sun, 21 Jun 2009 09:00:52 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> <7a0icpF1smf41U1@mid.individual.net> Message-ID: <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> On Jun 18, 11:28?pm, greg wrote: > nn wrote: > > This is certainly an odd one. This code works fine under 2.6 but fails > > in Python 3.1. > > >>>>class x: > > > ... ? ? lst=[2] > > ... ? ? gen=[lst.index(e) for e in lst] > > In 3.x it was decided that the loop variables in a list > comprehension should be local, and not leak into the > surrounding scope. This was implemented by making the > list comprehension into a nested function. > > Unfortunately this leads to the same unintuitive > behaviour as a genexp when used in a class scope. > -- I don't get this - the only local loop variable is "e", not lst. And lst is used twice in the generator expression, which is being complained about? It would generally be the case that a nested function would have access to its enclosing scope. In any case, even if/when the current behavior is explained or rationalized, it certainly appears un-intuitive, and that is another level of "error"! :-) From a.harrowell at gmail.com Sun Jun 21 12:01:53 2009 From: a.harrowell at gmail.com (TYR) Date: Sun, 21 Jun 2009 09:01:53 -0700 (PDT) Subject: urllib2 content-type headers Message-ID: I have a little application that wants to send data to a Google API. This API requires an HTTP header to be set as follows: Authorization: GoogleLogin auth=[value of auth token goes here] Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect this is due to an unfeature of urllib2. Notably, although you can use urllib2.Request's add_header method to append a header, the documentation (http://docs.python.org/library/urllib2.html) says that: remember that a few standard headers (Content-Length, Content-Type and Host) are added when the Request is passed to urlopen() (or OpenerDirector.open()). And: Note that there cannot be more than one header with the same name, and later calls will overwrite previous calls in case the key collides. To put it another way, you cannot rely on Content-Type being correct because whatever you set it to explicitly, urllib2 will silently change it to something else which may be wrong, and there is no way to stop it. What happened to "explicit is better than implicit"? From lists at cheimes.de Sun Jun 21 13:03:36 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Jun 2009 19:03:36 +0200 Subject: docs error for PyBuffer_FillInfo? In-Reply-To: <7a73e8F1totcrU1@mid.uni-berlin.de> References: <7a73e8F1totcrU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > > And obviously enough, compiling my wrapper fails because there is an > argument missing. > > So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - > all I've got is a void* and a total size of the buffer. The second argument points to the (optional) object for that you are creating the view. The code in Object/stringobject.c is a good example: static int string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags) { return PyBuffer_FillInfo(view, (PyObject*)self, (void *)self->ob_sval, Py_SIZE(self), 1, flags); } Christian From philip at semanchuk.com Sun Jun 21 13:08:46 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Jun 2009 13:08:46 -0400 Subject: urllib2 content-type headers In-Reply-To: References: Message-ID: <6CD5BD99-24AB-4CE8-B952-72D56D27BD16@semanchuk.com> On Jun 21, 2009, at 12:01 PM, TYR wrote: > I have a little application that wants to send data to a Google API. > This API requires an HTTP header to be set as follows: > > Authorization: GoogleLogin auth=[value of auth token goes here] > > Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect > this is due to an unfeature of urllib2. Notably, although you can use > urllib2.Request's add_header method to append a header, the > documentation (http://docs.python.org/library/urllib2.html) says that: > > remember that a few standard headers (Content-Length, Content-Type and > Host) are added when the Request is passed to urlopen() (or > OpenerDirector.open()). > > And: > > Note that there cannot be more than one header with the same name, and > later calls will overwrite previous calls in case the key collides. > > To put it another way, you cannot rely on Content-Type being correct > because whatever you set it to explicitly, urllib2 will silently > change it to something else which may be wrong, and there is no way to > stop it. What happened to "explicit is better than implicit"? Hi TYR, I'm confused, are you having a problem with the Content-Type or Authorization headers? Some suggestions -- - Try sending the request to a server you control so you can see what it is actually receiving. Maybe urllib2 isn't overwriting your header at all, but you're sending (e.g.) a misconfigured auth token. - Use a protocol sniffer like Wireshark to see what's going out over the wire - Urrlib2 automates some things for you (like building headers), but as with all automated magic sometimes it's not what you want. The httplib module offers finer control over HTTP conversations. You might want to use httplib to debug this problem even if you find you don't need it in your final solution. good luck Philip From walton.nathaniel at gmail.com Sun Jun 21 13:12:03 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 10:12:03 -0700 (PDT) Subject: os.system vs subprocess Message-ID: I get different behavior with os.system and subprocess (no surprise there I guess), but I was hoping for some clarification, namely why. If I type this directly into the command window: java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > mapoutput.txt mapoutput.txt stores the output: Command line mode: input file=censettings.xml 1358 files will be created in C:\Documents and Settings\Nate\Desktop \freqanalysis\tilefiles\CENSUS1-tiles 1358 tiles created out of 1358 in 16 seconds If I execute said command with subprocess, the output is not written to mapoutput.txt - the output just appears in the command window. If I execute said command with os.system, the output is written to mapoutput.txt like I expected. In reality all I want to do is access the first two lines of the above output before the process finishes, something which I haven't been able to manage with subprocess so far. I saw that somehow I might be able to use os.read(), but this is my first attempt at working with pipes/processes, so I'm a little overwhelmed. Thanks! From http Sun Jun 21 13:12:40 2009 From: http (Paul Rubin) Date: 21 Jun 2009 10:12:40 -0700 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <7x7hz5jyt3.fsf@ruckus.brouhaha.com> "Hendrik van Rooyen" writes: > I think that this is because (like your link has shown) the problem > is really not trivial, and also because the model that can bring > sanity to the party (independent threads/processes that communicate > with queued messages) is seen as inefficient at small scale. That style works pretty well in Python and other languages. The main gripe about it for Python is the subject of this thread, i.e. the GIL. From clp2 at rebertia.com Sun Jun 21 14:12:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Jun 2009 11:12:29 -0700 Subject: os.system vs subprocess In-Reply-To: References: Message-ID: <50697b2c0906211112m731ca0ddk1849e4f27cfbe53c@mail.gmail.com> On Sun, Jun 21, 2009 at 10:12 AM, Nate wrote: > I get different behavior with os.system and subprocess (no surprise > there I guess), but I was hoping for some clarification, namely why. > > If I type this directly into the command window: > > java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > > mapoutput.txt > > mapoutput.txt stores the output: > Command line mode: input file=censettings.xml > 1358 files will be created in C:\Documents and Settings\Nate\Desktop > \freqanalysis\tilefiles\CENSUS1-tiles > 1358 tiles created out of 1358 in 16 seconds > > If I execute said command with subprocess, the output is not written > to mapoutput.txt - the output just appears in the command window. Show us the subprocess version of you code. People tend to not get the parameters quite right if they're not familiar with the library. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Sun Jun 21 14:22:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Jun 2009 11:22:39 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <50697b2c0906211122x412bbb2ahb0cb27f67b4d8b66@mail.gmail.com> On Sun, Jun 21, 2009 at 5:25 AM, Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. Examples are the postings by > Dennis Lee Bieber that I am replying to (but I As addressed in an earlier thread, Mr. Bieber chooses to set a Usenet header (X-Noarchive) in his postings that suppresses their permanent archiving (and often the archiving of replies to his posts). I would direct you to the thread, but it looks like it wasn't archived. :P Cheers, Chris -- http://blog.rebertia.com From davea at dejaviewphoto.com Sun Jun 21 14:53:28 2009 From: davea at dejaviewphoto.com (Dave Angel) Date: Sun, 21 Jun 2009 14:53:28 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <4A3E81A8.3050301@dejaviewphoto.com> Peter Otten wrote: > Luca wrote: > > >> On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: >> >>> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >>> >>>> Hi all. >>>> >>>> I need to use a function like the raw_input to read data from user >>>> command line, but I really like to pre-compile the choice and I'm not >>>> able to do this. There is some other function/module I can use? >>>> I wanna to pre-compile the raw_input input line with the current working >>>> path. >>>> >>> What does "pre-compile" mean in this context? It's not clear at all, >>> so I can't even understand your question. >>> >> I'm really sorry to all that replied... In fact I literally traduced a >> > > With "traduced" you stumbled upon another false friend ;) > > http://it.wikipedia.org/wiki/Falso_amico > > >> concept from italian and the term precompiled was not so clear... >> >> What I mean is this: I wanna that raw_input (or other modules) ask to >> the user the data, but some data inserted is already present, to the >> user can cancel it with the BACKSPACE key. >> >> Examples below (the "_" is the initial cursor position). >> >> >>> raw_input("Insert the directory to work: ") >> Insert the directory to work: _ >> >> What I need is: >> >>> XXX_raw_input("Insert the directory to work: ", >> >>> default="/home/john/") >> Insert the directory to work: /home/john_ >> >> In the second example a user can cancel the text "/home/john". >> >> I hope this time is more clear, sorry again. >> > > > import readline > > def input_default(prompt, default): > def startup_hook(): > readline.insert_text(default) > readline.set_startup_hook(startup_hook) > try: > return raw_input(prompt) > finally: > readline.set_startup_hook(None) > > print input_default("directory? ", default="/home/john") > > The cmd module may also be worth having a look. > > Peter > > > The readline module is specific to Unix implementations. I don't know what OS the OP was using. From piet at cs.uu.nl Sun Jun 21 15:03:54 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 21 Jun 2009 21:03:54 +0200 Subject: Meta question: disappearing posts References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: >>>>> Chris Rebert (CR) wrote: >CR> On Sun, Jun 21, 2009 at 5:25 AM, Piet van Oostrum wrote: >>> I notice that I see several postings on news:comp.lang.python that are >>> replies to other postings that I don't see. Examples are the postings by >>> Dennis Lee Bieber that I am replying to (but I >CR> As addressed in an earlier thread, Mr. Bieber chooses to set a Usenet >CR> header (X-Noarchive) in his postings that suppresses their permanent >CR> archiving (and often the archiving of replies to his posts). >CR> I would direct you to the thread, but it looks like it wasn't archived. :P Actually, I do see Mr. Bieber's posts, but not the ones he replies to. And I am not talking about the archives but about the regular NNTP server, although the retention period somewhere along the path could be so low that posts disappear before they reach us. Anyway, as I saw gmane mentioned in the replies I wondered if that would have something to do with the problem. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From walton.nathaniel at gmail.com Sun Jun 21 15:12:07 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 12:12:07 -0700 (PDT) Subject: os.system vs subprocess References: Message-ID: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> On Jun 21, 2:12?pm, Chris Rebert wrote: > On Sun, Jun 21, 2009 at 10:12 AM, Nate wrote: > > I get different behavior with os.system and subprocess (no surprise > > there I guess), but I was hoping for some clarification, namely why. > > > If I type this directly into the command window: > > > java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > > > mapoutput.txt > > > mapoutput.txt stores the output: > > Command line mode: input file=censettings.xml > > 1358 files will be created in C:\Documents and Settings\Nate\Desktop > > \freqanalysis\tilefiles\CENSUS1-tiles > > 1358 tiles created out of 1358 in 16 seconds > > > If I execute said command with subprocess, the output is not written > > to mapoutput.txt - the output just appears in the command window. > > Show us the subprocess version of you code. People tend to not get the > parameters quite right if they're not familiar with the library. > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Here it is: gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) From milesck at umich.edu Sun Jun 21 15:20:38 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 15:20:38 -0400 Subject: urllib2 content-type headers In-Reply-To: References: Message-ID: On Jun 21, 2009, at 12:01 PM, TYR wrote: > Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect > this is due to an unfeature of urllib2. Notably, although you can use > urllib2.Request's add_header method to append a header, the > documentation (http://docs.python.org/library/urllib2.html) says that: > > remember that a few standard headers (Content-Length, Content-Type and > Host) are added when the Request is passed to urlopen() (or > OpenerDirector.open()). > > And: > > Note that there cannot be more than one header with the same name, and > later calls will overwrite previous calls in case the key collides. > > To put it another way, you cannot rely on Content-Type being correct > because whatever you set it to explicitly, urllib2 will silently > change it to something else which may be wrong, and there is no way to > stop it. What happened to "explicit is better than implicit"? Those headers are added (by AbstractHTTPHandler.do_request_) only if they are missing. -Miles From milesck at umich.edu Sun Jun 21 15:47:32 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 15:47:32 -0400 Subject: generator expression works in shell, NameError in script In-Reply-To: <4a3b8860$0$19616$426a74cc@news.free.fr> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <4a3b8860$0$19616$426a74cc@news.free.fr> Message-ID: <62C32142-89B7-4181-A515-2C7F3B37E344@umich.edu> On Jun 19, 2009, at 8:45 AM, Bruno Desthuilliers wrote: > >>> class Foo(object): > ... bar = ['a', 'b', 'c'] > ... baaz = list((b, b) for b in bar) > > but it indeed looks like using bar.index *in a generator expression* > fails (at least in 2.5.2) : > > >>> class Foo(object): > ... bar = ['a', 'b', 'c'] > ... baaz = list((bar.index(b), b) for b in bar) > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in Foo > File "", line 3, in > NameError: global name 'bar' is not defined The reason that the first one works but the second fails is clearer if you translate each generator expression to the approximately equivalent generator function: class Foo(object): bar = ['a', 'b', 'c'] def _gen(_0): for b in _0: yield (b, b) baaz = list(_gen(iter(bar)) # PEP 227: "the name bindings that occur in the class block # are not visible to enclosed functions" class Foo(object): bar = ['a', 'b', 'c'] def _gen(_0): for b in _0: yield (bar.index(b), b) baaz = list(_gen(iter(bar)) -Miles From lists at cheimes.de Sun Jun 21 15:49:35 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Jun 2009 21:49:35 +0200 Subject: os.system vs subprocess In-Reply-To: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: Nate wrote: > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) Try this: gmapcreator = subprocess.Popen( ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar", "-dfile=censettings.xml"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = gmapcreator.communicate("stdin input") The subprocess doesn't use the shell so you have to apply the command as a list of strings. Do you really need stdin, stdout and stderr as pipes? If you aren't carefully with the API your program can block. Christian From paul.hermeneutic at gmail.com Sun Jun 21 15:57:34 2009 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 21 Jun 2009 14:57:34 -0500 Subject: Can I replace this for loop with a join? In-Reply-To: <74h2hnF135f35U1@mid.individual.net> References: <74h2hnF135f35U1@mid.individual.net> Message-ID: <1245614253.3797.1.camel@linux-3eb6.site> On Mon, 2009-04-13 at 17:03 +0200, WP wrote: > Hello, I have dictionary {1:"astring", 2:"anotherstring", etc} > > I now want to print: > "Press 1 for astring" > "Press 2 for anotherstring" etc > > I could do it like this: > dict = {1:'astring', 2:'anotherstring'} > for key in dict.keys(): > print 'Press %i for %s' % (key, dict[key]) > > Press 1 for astring > Press 2 for anotherstring > > but can I use a join instead? > > Thanks for any replies! > > - WP In addition to the comments already made, this code will be quite broken if there is ever a need to localize your package in another language. From deets at nospam.web.de Sun Jun 21 16:08:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 22:08:50 +0200 Subject: docs error for PyBuffer_FillInfo? In-Reply-To: References: <7a73e8F1totcrU1@mid.uni-berlin.de> Message-ID: <7a7ib8F1sd7uqU1@mid.uni-berlin.de> Christian Heimes schrieb: > Diez B. Roggisch wrote: >> And obviously enough, compiling my wrapper fails because there is an >> argument missing. >> >> So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - >> all I've got is a void* and a total size of the buffer. > > The second argument points to the (optional) object for that you are > creating the view. The code in Object/stringobject.c is a good example: > > static int > string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags) > { > return PyBuffer_FillInfo(view, (PyObject*)self, > (void *)self->ob_sval, Py_SIZE(self), > 1, flags); > } But doesn't this mean the docs are faulty? Shall I report a bug? And I have to say that the docs are anything but clear to me. As I said, I've got a method void *lock(readonly=True) as part of a C++-library. So, all I've got is a void-pointer and a length (through another method). But I'm unsure about how to allocate the view - just with malloc? What about reference-counting, do I have to increment it? A self-contained example in the docs would be great. Any pointers? Thanks, Diez From tjreedy at udel.edu Sun Jun 21 16:16:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Jun 2009 16:16:10 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. Examples are the postings by > Dennis Lee Bieber that I am replying to (but I > break the thread on purpose). For example the posting with Message-ID: > references: > <77e831100906192220y5536d9d2oe5ca2dcc59084c0c at mail.gmail.com> which is > not present on my news server. I have been wondering why these > disappear, and I noticed the following in the Dennis Lee Bieber posting: > On Sat, 20 Jun 2009 11:48:21 -0600, Vincent Davis > declaimed the following in > gmane.comp.python.general: > > So apparently some of these come through gmane.comp.python.general. I am posting and reading thru gmane and generally see no problem. Sometimes I do see replies before the posting being replied. Sometimes certain posts get 'echoed' about week after the original posting date. If a reply gets echoed, but not the original, and one missed both originally, that can look weird. tjr > > So my question is: would this be the cause of these disappearing > postings? Are postings on gmane.comp.python.general not relayed to > comp.lang.python? Are they relayed to the python mailing list? I find it > quite disturbing that sometimes only half of a discussion is visible. From paul.hermeneutic at gmail.com Sun Jun 21 16:28:27 2009 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 21 Jun 2009 15:28:27 -0500 Subject: GNUstep and Python Message-ID: <1245616107.3797.3.camel@linux-3eb6.site> Has anyone used GNUstep? In addition to Objective-C, there are Java and Ruby bindings. Has anyone created a Python binding to GNUstep? From philr at aspexconsulting.co.nz Sun Jun 21 16:40:08 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Mon, 22 Jun 2009 08:40:08 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: ->From: Bob Martin [mailto:bob.martin at excite.com] -.Sent: Thursday, 18 June 2009 6:07 p.m. -Subject: Re: RE: Good books in computer science? -in 117815 20090617 221804 Phil Runciman wrote: ->Because it reminds me of when things went badly wrong. IBM360, Von Neumann = ->architecture, no hardware stacks ... -> ->IMHO Burroughs and ICL had better approaches to OS design back then but had= ->less resources to develop their ideas.=20 -> ->However, mainly this period marked a transition from the excitement and dis= ->covery phase of computing to commercial power plays and take-overs. The bes= ->t ideas in a field tend to get lost in the melee of competition. Early comp= ->uters were rooted in academia and there was a lot of cross fertilisation of= ->ideas and approaches. IMHO commerce affected layers of the stack where it = ->had no useful contribution to make. Vertical integration warred against sou= ->nd architecture. -> ->The book has an important message and I recommend that people read it. The = ->book is to me, and possibly only me, an icon representing when things went = ->wrong. -Well, it's an opinion, but certainly not one I would agree with! -AFAIAC the IBM 360 got everything right, which is why the instruction set is still -going strong 45 years later (I've used it for every one of those 45 years). Yes, I was afraid someone would use that sort of argument. Sadly, having the best instruction set does not lead to commercial success. If it did then Interdata would still be with us. They used IBM360 instructions. How many instruction sets have you used? I have used at least 9.(I nearly missed the DG Nova). KDF9 had the best set for general computing that I had the privilege of using but that is not to say it was the best. The Burroughs B series or PDP11 may have been better... and doubtless there are many more candidates. What I can say is that for scientific/engineering calculations the RPN of KDF9 was Great because assembler was no harder than using algol60 for the calculations part of the problems I worked on. Oh yes, I even used assembler on the IBM360 series. It was a 360/50. The experience Did impact on the force of my observations! FWIW I learned it using the training material For the ICL System 4 which was superior to IBM's. The ICL System 4 was not a success... despite its instruction set. ;-) -AFAIAC the IBM 360 got everything right How many known bugs did the OS end up with? I know it hit 50,000+ and counting. LOL Suffice to say we are on a journey and Python is part of the scenery. Phil From Scott.Daniels at Acm.Org Sun Jun 21 16:51:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 21 Jun 2009 13:51:58 -0700 Subject: Inheritance and forward references (prototypes) In-Reply-To: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: Lorenzo Di Gregorio wrote: > On 21 Jun., 01:54, Dave Angel wrote: >> ... >> class B(object): >> def __init__(self,test=None): >> if test==None: >> test = A() >> self.obj =() >> return > ... > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observation that "def" is an instruction and no > declaration changes the situation: I would not have a new object being > constructed for every instantiation with no optional argument, because > __init__ gets executed on the instantiation but test=A() gets executed > on reading 'def'.... If what you are worrying about is having a single default object, you could do something like this: class B(object): _default = None def __init__(self, test=None): if test is None: test = self._default if test is None: B._default = test = A() ... --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Sun Jun 21 16:59:32 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 22:59:32 +0200 Subject: GNUstep and Python In-Reply-To: <1245616107.3797.3.camel@linux-3eb6.site> References: <1245616107.3797.3.camel@linux-3eb6.site> Message-ID: <7a7l9kF1tv7viU1@mid.uni-berlin.de> Paul Watson schrieb: > Has anyone used GNUstep? > > In addition to Objective-C, there are Java and Ruby bindings. > > Has anyone created a Python binding to GNUstep? There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. Diez From Scott.Daniels at Acm.Org Sun Jun 21 17:23:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 21 Jun 2009 14:23:41 -0700 Subject: class or instance method In-Reply-To: <87ljnr3ueq.fsf@busola.homelinux.net> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> Message-ID: <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> Hrvoje Niksic wrote: > ... > class class_or_instance(object): > def __init__(self, fn): > self.fn = fn > def __get__(self, obj, cls): > if obj is not None: > return lambda *args, **kwds: self.fn(obj, *args, **kwds) > else: > return lambda *args, **kwds: self.fn(cls, *args, **kwds) > ... Just to polish a bit: import functools class ClassOrInstance(object): def __init__(self, fn): self._function = fn self._wrapper = functools.wraps(fn) def __get__(self, obj, cls): return self._wrapper(functools.partial(self._function, cls if obj is None else obj)) --Scott David Daniels Scott.Daniels at Acm.Org From milesck at umich.edu Sun Jun 21 17:56:01 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 17:56:01 -0400 Subject: class or instance method In-Reply-To: <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> Message-ID: <50CD264B-A191-4F3D-9FAF-712656D2798E@umich.edu> On Jun 21, 2009, at 5:23 PM, Scott David Daniels wrote: > Hrvoje Niksic wrote: >> ... >> class class_or_instance(object): >> def __init__(self, fn): >> self.fn = fn >> def __get__(self, obj, cls): >> if obj is not None: >> return lambda *args, **kwds: self.fn(obj, *args, **kwds) >> else: >> return lambda *args, **kwds: self.fn(cls, *args, **kwds) >> ... > > Just to polish a bit: > > import functools > > class ClassOrInstance(object): > def __init__(self, fn): > self._function = fn > self._wrapper = functools.wraps(fn) > > def __get__(self, obj, cls): > return self._wrapper(functools.partial(self._function, > cls if obj is None else obj)) from types import MethodType class ClassOrInstance(object): def __init__(self, func): self._func = func def __get__(self, obj, cls): return MethodType(self._func, cls if obj is None else obj, cls) -Miles From ben+python at benfinney.id.au Sun Jun 21 18:09:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Jun 2009 08:09:45 +1000 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> <1245614253.3797.1.camel@linux-3eb6.site> Message-ID: <87skhtxmqe.fsf@benfinney.id.au> Paul Watson writes: > On Mon, 2009-04-13 at 17:03 +0200, WP wrote: > > dict = {1:'astring', 2:'anotherstring'} > > for key in dict.keys(): > > print 'Press %i for %s' % (key, dict[key]) > > In addition to the comments already made, this code will be quite > broken if there is ever a need to localize your package in another > language. How is this code especially broken? AFAICT, it merely needs the strings marked for translation, which is the best i18n situation any regular program can hope for anyway. -- \ ?Crime is contagious? if the government becomes a lawbreaker, | `\ it breeds contempt for the law.? ?Justice Louis Brandeis | _o__) | Ben Finney From walton.nathaniel at gmail.com Sun Jun 21 18:42:51 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 15:42:51 -0700 (PDT) Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: On Jun 21, 3:49?pm, Christian Heimes wrote: > Nate wrote: > > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > Try this: > > gmapcreator = subprocess.Popen( > ? ? ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar", > ? ? "-dfile=censettings.xml"], stdin=subprocess.PIPE, > ? ? stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > out, err = gmapcreator.communicate("stdin input") > > The subprocess doesn't use the shell so you have to apply the command as > a list of strings. > > Do you really need stdin, stdout and stderr as pipes? If you aren't > carefully with the API your program can block. > > Christian Christian, Thanks for your response. Related to this talk about shells, maybe you could point me towards a resource where I could read about how windows commands are processed w/w/o shells? I guess I assumed all subprocess commands were intepreted by the same thing, cmd.exe., or perhaps the shell. I guess this also ties in with me wondering what the whole subprocess Popen instantiation encompassed (the __init__ of the subprocess.Popen class?). I don't think I need stdin, stdout, stderr as pipes, I just was faced with several options for how to capture these things and I chose subprocess.PIPE. I could also os.pipe my own pipes, or create a file descriptor in one of a couple of ways, right? I'm just unclear on which method is preferable for me. All I want to do is pull the first 2 lines from the output before gmapcreator.jar finishes. The first 2 lines of output are always the same except a few numbers. From steve at REMOVETHIS.cybersource.com.au Sun Jun 21 19:24:28 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 22 Jun 2009 09:24:28 +1000 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <024eb31e$0$23675$c3e8da3@news.astraweb.com> Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. I see the same problem. I suspect it's because of over-vigorous spam filtering from Usenet providers. Some even block everything from anyone using Google Groups. It's quite frustrating, to have perfectly valid Python-related posts go missing while dozens of posts offering to sell well-known brands of shoes and watches are delivered. -- Steven From lists at cheimes.de Sun Jun 21 19:40:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 22 Jun 2009 01:40:58 +0200 Subject: os.system vs subprocess In-Reply-To: References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: Nate wrote: > Thanks for your response. Related to this talk about shells, maybe you > could point me towards a resource where I could read about how windows > commands are processed w/w/o shells? I guess I assumed all subprocess > commands were intepreted by the same thing, cmd.exe., or perhaps the > shell. The subprocess module never uses the shell unless you tell it so. On Unix the modules uses fork() the exec*() familiy to create a new process. On Windows it's the CreateProcess() api. If you want to read about the Windows stuff then have fun at http://msdn.microsoft.com/ ;) > I guess this also ties in with me wondering what the whole subprocess > Popen instantiation encompassed (the __init__ of the subprocess.Popen > class?). It does *a lot* of stuff. The subprocess module tries very hard to create an easy to use interface that abstracts all OS specific traps very well. Most of the subprocess module is written in Python but that doesn't mean it's easy to understand. Have fun again! > I don't think I need stdin, stdout, stderr as pipes, I just was faced > with several options for how to capture these things and I chose > subprocess.PIPE. I could also os.pipe my own pipes, or create a file > descriptor in one of a couple of ways, right? I'm just unclear on > which method is preferable for me. All I want to do is pull the first > 2 lines from the output before gmapcreator.jar finishes. The first 2 > lines of output are always the same except a few numbers. os.pipe() are suffering from the same issue as subprocess.PIPE. In fact the PIPE constant tells subprocess to use OS specific pipes. If you don't read from all pipes simultaneously one pipe may get filled up to its buffer limit and both programs block. As long as you use just one PIPE or the communicate() method then nothing can get wrong. Christian From aahz at pythoncraft.com Sun Jun 21 19:43:49 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 16:43:49 -0700 Subject: dynamically associate radio buttons with droplists References: Message-ID: In article , Leo Brugud wrote: > >Not being very familiar with python, nor with cgi/http, I intend to >have 3 of buttons in a webpage, each of them is associate with a file >(so I have 3 files, too) > >What I would like to have is, when users choose a button, the droplist >update automatically to load the contents of the associated file. > >Can someone educate me the approach of this? Are you trying to do this without requiring the user to click the submit button? If yes, you need to learn JavaScript (although I think there are web frameworks that will auto-generate the JavaScript, you need to know JavaScript in order to do debugging). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From greg at cosc.canterbury.ac.nz Sun Jun 21 20:44:47 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 22 Jun 2009 12:44:47 +1200 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> <50697b2c0906211122x412bbb2ahb0cb27f67b4d8b66@mail.gmail.com> Message-ID: <7a82dsF1tthgsU1@mid.individual.net> Dennis Lee Bieber wrote: > unless one is reading from a server > that interprets X-no-archive to mean "delete before reading". Can't be too careful with security. Destroy it, memorize it and then read it! -- Greg From arlie.c at gmail.com Sun Jun 21 20:48:29 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 17:48:29 -0700 (PDT) Subject: pyinstaller Message-ID: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Newbie here using Python 2.6.2 on MS WinXP Pro SP3. I'm trying create an frozen exec and was able to generate and exe file. python D:\pyinstaller-1.3\Makespec.py -F myprog.py python D:\pyinstaller-1.3\Build.py myprog.spec --paths=D: \pyinstaller-1.3;D:\PROJECTS\pyproject but when I ran "myprog.exe" i get this: Traceback (most recent call last): File "", line 2, in File "D:\pyinstaller-1.3\iu.py", line 312, in importHook mod = _self_doimport(nm, ctx, fqname) File "D:\pyinstaller-1.3\iu.py", line 398, in doimport exec co in mod.__dict__ File "D:\PROJECTS\python.paging.system.client \buildpaging_system_client\out1.p yz/MySQLdb", line 19, in File "D:\pyinstaller-1.3\iu.py", line 312, in importHook mod = _self_doimport(nm, ctx, fqname) File "D:\pyinstaller-1.3\iu.py", line 382, in doimport mod = director.getmod(nm) File "D:\pyinstaller-1.3\iu.py", line 215, in getmod mod = owner.getmod(nm) File "D:\pyinstaller-1.3\iu.py", line 77, in getmod mod = imp.load_module(nm, fp, attempt, (ext, mode, typ)) ImportError: _mysql: init failed ~~~ I have to source files namely: myprog.py mp3.py This is the content of spec file: a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'myprog.py'], pathex=['D:\\PROJECTS\\pyproject']) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, a.binaries, name='myprog.exe', debug=False, strip=False, upx=False, console=True ) Please help. From arlie.c at gmail.com Sun Jun 21 20:59:10 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 17:59:10 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: Renamed the project directory. from ... File "D:\PROJECTS\python.paging.system.client \buildpaging_system_client\out1.p ... to ... File "D:\PROJECTS\pyproject \buildpyproject\out1.p ... From arlie.c at gmail.com Sun Jun 21 21:07:47 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 18:07:47 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: <065679db-ade1-44f0-8c85-9d5efa806568@p6g2000pre.googlegroups.com> Imported files in myprog.py: import MySQLdb import os # works on Windows or Linux, also Vista import os.path import time import mp3 ~~~~~~~ Content of mp3.py: # -*- coding: utf-8 -*- #Michel Claveau import time from ctypes import windll, c_buffer class mci: def __init__(self): self.w32mci = windll.winmm.mciSendStringA self.w32mcierror = windll.winmm.mciGetErrorStringA def send(self,commande): buffer = c_buffer(255) errorcode = self.w32mci(str(commande),buffer,254,0) if errorcode: return errorcode, self.get_error(errorcode) else: return errorcode,buffer.value def get_error(self,error): error = int(error) buffer = c_buffer(255) self.w32mcierror(error,buffer,254) return buffer.value def directsend(self, txt): (err,buf)=self.send(txt) if err != 0: print'Error',str(err),'sur',txt,':',buf return (err,buf) ################################################################### def play(mp3file): xmci=mci() xmci.directsend('open "' + mp3file + '" alias toto') xmci.directsend('set toto time format milliseconds') err,buf=xmci.directsend('status toto length ') #print 'Duree du fichier : ',buf,' millisecondes' soundlength = int(buf) / 1000 err,buf=xmci.directsend('play toto from 0 to '+str(buf)) #time.sleep(int(buf)/1000) time.sleep(soundlength + 1) xmci.directsend('close toto') From greg at cosc.canterbury.ac.nz Sun Jun 21 21:08:41 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 22 Jun 2009 13:08:41 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> <7a0icpF1smf41U1@mid.individual.net> <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> Message-ID: <7a83qpF1u3ivuU1@mid.individual.net> guthrie wrote: > -- I don't get this - the only local loop variable is "e", not lst. Yes, but the whole list comprehension gets put into a nested function, including the part that evaluates lst. (It's not strictly *necessary* to do that, but that's the way it happens to be implemented at the moment.) > It would generally be the case that a nested function would have > access to its enclosing scope. Usually, but class namespaces are a special case -- they're not considered to be enclosing scopes, even though textually they're written that way. > it certainly appears un-intuitive It is, but it's hard to see what could be done to improve the situation without introducing worse problems. -- Greg From arlie.c at gmail.com Sun Jun 21 21:16:24 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 18:16:24 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> <065679db-ade1-44f0-8c85-9d5efa806568@p6g2000pre.googlegroups.com> Message-ID: <759f6b39-e42f-46a1-80b4-32e953a4753a@x29g2000prf.googlegroups.com> Content of warnmyprog.txt: W: no module named posix (conditional import by os) W: no module named optik.__all__ (top-level import by optparse) W: no module named readline (delayed, conditional import by cmd) W: no module named readline (delayed import by pdb) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named ctypes.windll (top-level import by mp3) W: no module named ctypes.c_buffer (top-level import by mp3) W: no module named posix (delayed, conditional import by iu) W: no module named fcntl (conditional import by subprocess) W: no module named org (top-level import by copy) W: no module named _emx_link (conditional import by os) W: no module named optik.__version__ (top-level import by optparse) W: no module named fcntl (top-level import by tempfile) W: __all__ is built strangely at line 0 - collections (C:\Python26\lib \collections.pyc) W: delayed exec statement detected at line 0 - collections (C: \Python26\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed __import__ hack detected at line 0 - encodings (C: \Python26\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - optparse (D: \pyinstaller-1.3\optparse.pyc) W: delayed __import__ hack detected at line 0 - ctypes (C: \Python26\lib\ctypes\__init__.pyc) W: delayed __import__ hack detected at line 0 - ctypes (C: \Python26\lib\ctypes\__init__.pyc) W: __all__ is built strangely at line 0 - dis (C:\Python26\lib \dis.pyc) W: delayed eval hack detected at line 0 - os (C:\Python26\lib\os.pyc) W: __all__ is built strangely at line 0 - __future__ (C:\Python26\lib \__future__.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\lib\unittest.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\lib\unittest.pyc) W: __all__ is built strangely at line 0 - tokenize (C:\Python26\lib \tokenize.pyc) W: delayed exec statement detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed __import__ hack detected at line 0 - pickle (C: \Python26\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (C: \Python26\lib\pickle.pyc) W: delayed conditional exec statement detected at line 0 - iu (D: \pyinstaller-1.3\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (D: \pyinstaller-1.3\iu.pyc) W: delayed eval hack detected at line 0 - gettext (C:\Python26\lib \gettext.pyc) W: delayed __import__ hack detected at line 0 - optik.option_parser (D:\pyinstaller-1.3\optik\option_parser.pyc) W: delayed conditional eval hack detected at line 0 - warnings (C: \Python26\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (C:\Python26\lib\warnings.pyc) W: __all__ is built strangely at line 0 - optik (D: \pyinstaller-1.3\optik\__init__.pyc) W: delayed exec statement detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C: \Python26\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C: \Python26\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) From ldo at geek-central.gen.new_zealand Sun Jun 21 21:50:10 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 13:50:10 +1200 Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > The subprocess doesn't use the shell ... It can if you tell it to. From ldo at geek-central.gen.new_zealand Sun Jun 21 21:52:55 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 13:52:55 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: In message , Phil Runciman wrote: > What I can say is that for scientific/engineering calculations the RPN of > KDF9 was Great because assembler was no harder than using algol60 for the > calculations part of the problems I worked on. Unfortunately, we had to learn the hard way that machine instruction sets must be designed for efficiency of execution, not ease of use by humans. Stack-based architectures, for all their charm, cannot match register-based ones in this regard. From aahz at pythoncraft.com Sun Jun 21 23:28:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 20:28:40 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: In article , Piet van Oostrum wrote: > >I notice that I see several postings on news:comp.lang.python that are >replies to other postings that I don't see. As stated previously, my suspicion is that at least some is caused by a problem with MIME messages and the mail->news gateway on python.org. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From timr at probo.com Sun Jun 21 23:50:14 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Jun 2009 20:50:14 -0700 Subject: File Syncing References: Message-ID: <5rvt35donevj7k3e3rf6bg7d51e676uujo@4ax.com> dads wrote: >On Jun 20, 11:21?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message > >> b0d7-586b1b332... at t10g2000vbg.googlegroups.com>, dads wrote: >> > What would I have to learn to be able to sync the text files on each >> > server? >> >> How big is the text file? If it's small, why not have your script read it >> directly from a master server every time it runs, instead of having a local >> copy. > >Yeah the text files will never get bigger than a 100k. I don't think >they have a master server but i'll check. Thanks He's suggesting that you just PICK one and make that the master server. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bcharrow at csail.mit.edu Mon Jun 22 00:14:50 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Mon, 22 Jun 2009 00:14:50 -0400 Subject: Idioms and Anti-Idioms Question Message-ID: <4A3F053A.10208@csail.mit.edu> I have a question about the "Using Backslash to Continue Statements" in the howto "Idioms and Anti-Idioms in Python" (http://docs.python.org/howto/doanddont.html#using-backslash-to-continue-statements) It says: "...if the code was: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) then it would just be subtly wrong." What is subtly wrong about this piece of code? I can't see any bugs and can't think of subtle gotchas (e.g. the '\' is removed or the lines become separated, because in both cases an IndentationError would be raised). Cheers, Ben From cjns1989 at gmail.com Mon Jun 22 01:30:20 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Mon, 22 Jun 2009 01:30:20 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <20090622053020.GA2769@turki.gavron.org> On Sun, Jun 14, 2009 at 06:42:50PM EDT, Lawrence D'Oliveiro wrote: > In message , Chris > Jones wrote: > > Vivaldi vs. Mozart > > > > And the latter especially had definitely mastered his editor. Just > > think of the sheer volume of the coding he managed during his short > > life. > > > > Not many bugs either? > > I thought Vivaldi did more. The style of music was such that they > could virtually sketch it out in shorthand, and leave it to the > copyists to expand to proper notation for the musicians to play. I > imagine that it was also the job of copyists to fix the typos. 100 years before Frederick W. Taylor was born..? Vivaldi ran a school for musically-minded young women, I heard, so his alumni may have pitched in. Mozart on the other hand, pretty much must have spent his days coding. It has been estimated that the fastest copyist would need years to manually reproduce the sum total of his manuscripts. Mind you, that's only stuff I read years ago, and even though I looked around a bit, I have no evidence to corroborate. > In other words, high productivity was a direct consequence of adoption > of a cookie-cutter style. It looks like we pretty much agree. You make it sound like it was Vivaldi who invented Pacbase. :-) Maybe I'm nitpicking, but the one thing I don't understand is how you practice programming. The term makes obvious sense when you're talking about your golf swing, acquiring competitive driving skills, playing tetris.. But programming..?? CJ From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 01:51:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jun 2009 05:51:11 GMT Subject: Idioms and Anti-Idioms Question References: Message-ID: On Mon, 22 Jun 2009 00:14:50 -0400, Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in > the howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to- continue-statements) > > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > + calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? I can't see any bugs and > can't think of subtle gotchas (e.g. the '\' is removed or the lines > become separated, because in both cases an IndentationError would be > raised). As examples go, it's pretty lousy because you can't just copy and paste it into an interpreter session and see for yourself. However, with some helper objects: def forbulate(*args): return [1] def calculate_number(*args): return 2 class K: pass foo = K() foo.bar = lambda: {'first': [1, 2, 3]} baz = K() baz.quux = lambda *args: [3]*10 value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) I can run the example. I confirm that it works without a space after the line continuation character. Using Python 2.5, if I put a space after the backslash I get SyntaxError: unexpected character after line continuation character followed by IndentationError: unexpected indent So I don't understand the claim that the code is "subtly wrong" either. It looks to me like it's obviously wrong. -- Steven From lie.1296 at gmail.com Mon Jun 22 01:54:47 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 05:54:47 GMT Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in > the howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to-continue-statements) > > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > + calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? I can't see any bugs and > can't think of subtle gotchas (e.g. the '\' is removed or the lines > become separated, because in both cases an IndentationError would be > raised). The preferred style is to put the binary operators before the line-break (i.e. the line break is after the operators): value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ calculate_number(10, 20)*forbulate(500, 360) and even more preferrable is NOT to use explicit line break at all; relying on implicit breaking with parentheses since then you won't need to worry about empty lines: value = (foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + calculate_number(10, 20)*forbulate(500, 360) ) although, in a formula that is so complex, the most preferable way is to separate them so they won't need to take more than a single line: a = foo.bar()['first'][0] b = baz.quux(1, 2)[5:9] c = calculate_number(10, 20) d = forbulate(500, 360) value = a*b + c*d of course, a, b, c, d should be substituted with a more helpful names. The following is an extract from PEP 8: """ The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is *after* the operator, not before it. """ From vishal_shetye at persistent.co.in Mon Jun 22 02:27:35 2009 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Mon, 22 Jun 2009 11:57:35 +0530 Subject: Help: Group based synchronize decorator In-Reply-To: References: Message-ID: Thanks. - vishal > -----Original Message----- > Sent: Friday, June 19, 2009 3:15 PM > To: python-list at python.org > Subject: Python-list Digest, Vol 69, Issue 214 > > Message: 6 > Date: Fri, 19 Jun 2009 10:53:27 +0200 > From: Piet van Oostrum > To: python-list at python.org > Subject: Re: Help: Group based synchronize decorator > Message-ID: > Content-Type: text/plain; charset=us-ascii > > >>>>> Vishal Shetye (VS) wrote: > > >VS> I want to synchronize calls using rw locks per 'group' and my > implementation is similar to > >VS> http://code.activestate.com/recipes/465057/ > >VS> except that I have my own Lock implementation. > > >VS> All my synchronized functions take 'whatGroup' as param. My lock > considers 'group' while deciding on granting locks through acquire. > > >VS> What I could come up with is: > >VS> - decorator knows(assumes) first param to decorated functions is > always 'whatGroup' > >VS> - decorator passes this 'whatGroup' argument to my lock which is used > in acquire logic. > > >VS> Is it ok to make such assumptions in decorator? > > As long as you make sure that all decorated functions indeed adhere to > that assumption there is nothing wrong with it. > -- > Piet van Oostrum > URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] > Private email: piet at vanoostrum.org DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. From bob.martin at excite.com Mon Jun 22 02:36:02 2009 From: bob.martin at excite.com (Bob Martin) Date: Mon, 22 Jun 2009 06:36:02 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: in 118305 20090621 214008 Phil Runciman wrote: >How many instruction sets have you used? I have used at least 9. IBM 1401 IBM 1410 IBM 7090/7094 IBM 1620 IBM 360 IBM System/7 IBM 1130 IBM 1800 IBM Series/1 Intel 8080 etc Motorola 6800 etc Texas 9900 (my second favourite) plus a bunch of IBM microprocessor cards (eg Woodstock). From artem.bz at gmail.com Mon Jun 22 02:59:41 2009 From: artem.bz at gmail.com (=?KOI8-R?B?4dLUxc0g7snLz8zBxdfJ3g==?=) Date: Sun, 21 Jun 2009 23:59:41 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP References: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Message-ID: <4ebdb4bb-2c5b-4f91-ab2d-13e552a0b180@k20g2000vbp.googlegroups.com> Hello! Project: http://unpyc.googlecode.com/svn/trunk/ For resolve problem You must: 1. modify file setup.py replace ext_modules = [Extension('unpyc/marshal_20', ['unpyc/'], define_macros=[]), Extension('unpyc/marshal_21', ['unpyc/marshal_21.c'], define_macros=[]), Extension('unpyc/marshal_22', ['unpyc/marshal_22.c'], define_macros=[]), Extension('unpyc/marshal_23', ['unpyc/marshal_23.c'], define_macros=[]), Extension('unpyc/marshal_24', ['unpyc/marshal_24.c'], define_macros=[]), Extension('unpyc/marshal_25', ['unpyc/marshal_25.c'], define_macros=[]), Extension('unpyc/marshal_26', ['unpyc/marshal_26.c'], define_macros=[]), ] on ext_modules = [Extension('marshal_20', ['marshal_20.c'], define_macros=[]), Extension('marshal_21', ['marshal_21.c'], define_macros=[]), Extension('marshal_22', ['marshal_22.c'], define_macros=[]), Extension('marshal_23', ['marshal_23.c'], define_macros=[]), Extension('marshal_24', ['marshal_24.c'], define_macros=[]), Extension('marshal_25', ['marshal_25.c'], define_macros=[]), Extension('marshal_26', ['marshal_26.c'], define_macros=[]), ] 2. ?opy files marshal_20.c marshal_21.c marshal_22.c marshal_23.c marshal_24.c marshal_25.c marshal_26.c from "unpyc" directory to "..\unpyc" near "setup.py" file. 3. Run python.exe setup.py install From eckhardt at satorlaser.com Mon Jun 22 03:07:03 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 22 Jun 2009 09:07:03 +0200 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> <1245614253.3797.1.camel@linux-3eb6.site> <87skhtxmqe.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Paul Watson writes: >> On Mon, 2009-04-13 at 17:03 +0200, WP wrote: >> > dict = {1:'astring', 2:'anotherstring'} >> > for key in dict.keys(): >> > print 'Press %i for %s' % (key, dict[key]) >> >> In addition to the comments already made, this code will be quite >> broken if there is ever a need to localize your package in another >> language. > > How is this code especially broken? AFAICT, it merely needs the strings > marked for translation, which is the best i18n situation any regular > program can hope for anyway. > The problem is that some language might require you to write "For X press Y", which is impossible to achieve here. I think percent-formatting supports using keys, like "Press %{key} for %{action}" % {'key': key, 'action':dict[key]} However, I would also like to hear what Paul really meant and also the alternatives he proposes. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From http Mon Jun 22 03:26:51 2009 From: http (Paul Rubin) Date: 22 Jun 2009 00:26:51 -0700 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> Message-ID: <7xbpog3f0k.fsf@ruckus.brouhaha.com> WP writes: > I could do it like this: > dict = {1:'astring', 2:'anotherstring'} > for key in dict.keys(): > print 'Press %i for %s' % (key, dict[key]) > Press 1 for astring > Press 2 for anotherstring Note that dict.keys() will return the keys in random order. > but can I use a join instead? print '\n'.join('Press %s for %s' for (k,v) in sorted(dict.iteritems())) (untested) should print them in order. Yes it is ok to use %s to format integers. Note: normally you should not call your dictionary 'dict', since 'dict' is a built-in value and overriding it could confuse people and/or code. From lucaberto at libero.it Mon Jun 22 03:29:06 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 00:29:06 -0700 (PDT) Subject: ctypes list library Message-ID: There is a command for ctypes that help me to know the entry points inside a library. Thanks Luca From sunruijia at gmail.com Mon Jun 22 03:33:11 2009 From: sunruijia at gmail.com (=?GB2312?B?wu2yu82jzOO1xNbt?=) Date: Mon, 22 Jun 2009 00:33:11 -0700 (PDT) Subject: error when use libgmail with proxy Message-ID: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Hi all, Does anybody use libgmail with proxy? I met error here. Below is code snip: libgmail.PROXY_URL = G_PROXY # the proxy url self.ga = libgmail.GmailAccount(account,pwd) self.ga.login() Error information: ga.login () File "C:\Python25\Lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage (req) File "C:\Python25\Lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open (req) File "build\bdist.win32\egg\mechanize\_opener.py", line 191, in open File "C:\Python25\lib\urllib2.py", line 399, in _open '_open', req) File "C:\Python25\lib\urllib2.py", line 360, in _call_chain result = func (*args) File "build\bdist.win32\egg\mechanize\_http.py", line 751, in https_open AttributeError: 'int' object has no attribute 'find_key_cert' Is it possible the issue of mechanize? From mail at timgolden.me.uk Mon Jun 22 03:57:40 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Jun 2009 08:57:40 +0100 Subject: os.system vs subprocess In-Reply-To: References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: <4A3F3974.70704@timgolden.me.uk> Nate wrote: > Thanks for your response. Related to this talk about shells, maybe you > could point me towards a resource where I could read about how windows > commands are processed w/w/o shells? I guess I assumed all subprocess > commands were intepreted by the same thing, cmd.exe., or perhaps the > shell. Just a comment here: on Windows, you almost *never* need to specify shell=True. Certainly, far less than most people seem to think you need to. The only things which certainly need shell to be set True are those which don't really exist as programs in their own right: dir, copy etc. You don't need to set it for batch files (altho' this does seem to vary slightly between versions) and you certainly don't need to set it for console programs in general, such as Python. import subprocess subprocess.call (["dir"], shell=False) subprocess.call (["dir"], shell=True) with open ("test.bat", "w") as f: f.write ("echo hello") subprocess.call (["test.bat"], shell=False) subprocess.call (["python", "-c", "import sys; print sys.executable"], shell=False) This all works as expected using Python 2.6.1 on WinXP SP3 TJG From ldo at geek-central.gen.new_zealand Mon Jun 22 04:01:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 20:01:07 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Lie Ryan wrote: > The preferred style is to put the binary operators before the line-break > ... Not by me. I prefer using a two-dimensional layout to make the expression structure more obvious: value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) In this case it's not necessary, but if the factors were really long, this could become value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) From mail at microcorp.co.za Mon Jun 22 04:03:13 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 22 Jun 2009 10:03:13 +0200 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net><4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> <7x7hz5jyt3.fsf@ruckus.brouhaha.com> Message-ID: <002d01c9f30f$e4b07b80$0d00a8c0@Hendrik> "Paul Rubin" wrote: > "Hendrik van Rooyen" writes: > > I think that this is because (like your link has shown) the problem > > is really not trivial, and also because the model that can bring > > sanity to the party (independent threads/processes that communicate > > with queued messages) is seen as inefficient at small scale. > > That style works pretty well in Python and other languages. The main > gripe about it for Python is the subject of this thread, i.e. the GIL. I have found that if you accept it, and sprinkle a few judicious time.sleep(short_time)'s around, things work well. Sort of choosing yourself when the thread gives up its turn. - Hendrik From lucafbb at gmail.com Mon Jun 22 04:19:48 2009 From: lucafbb at gmail.com (Luca) Date: Mon, 22 Jun 2009 10:19:48 +0200 Subject: raw_input with a pre-compiled data In-Reply-To: References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: > With "traduced" you stumbled upon another false friend ;) > > http://it.wikipedia.org/wiki/Falso_amico D'oh!!! x-) > import readline > > def input_default(prompt, default): > ? ?def startup_hook(): > ? ? ? ?readline.insert_text(default) > ? ?readline.set_startup_hook(startup_hook) > ? ?try: > ? ? ? ?return raw_input(prompt) > ? ?finally: > ? ? ? ?readline.set_startup_hook(None) > > print input_default("directory? ", default="/home/john") > Thanks! It works! This is working on Linux and MacOS too. > The readline module is specific to Unix implementations. > I don't know what OS the OP was using. Any one knows is this working also on Windows? I've no Win system right no to test this... -- -- luca From clp2 at rebertia.com Mon Jun 22 04:36:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 01:36:05 -0700 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> Message-ID: <50697b2c0906220136h3a3b8e32l4c2a8624c0b0f806@mail.gmail.com> On Mon, Jun 22, 2009 at 1:19 AM, Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: >> With "traduced" you stumbled upon another false friend ;) >> >> http://it.wikipedia.org/wiki/Falso_amico > > D'oh!!! ? x-) > >> import readline >> >> def input_default(prompt, default): >> ? ?def startup_hook(): >> ? ? ? ?readline.insert_text(default) >> ? ?readline.set_startup_hook(startup_hook) >> ? ?try: >> ? ? ? ?return raw_input(prompt) >> ? ?finally: >> ? ? ? ?readline.set_startup_hook(None) >> >> print input_default("directory? ", default="/home/john") >> > > Thanks! It works! This is working on Linux and MacOS too. > >> The readline module is specific to Unix implementations. >> I don't know what OS the OP was using. > > Any one knows is this working also on Windows? I've no Win system > right no to test this... No, it won't. "specific to Unix" == Unix-only Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Mon Jun 22 04:49:18 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 10:49:18 +0200 Subject: ctypes list library In-Reply-To: References: Message-ID: <7a8usgF1mj0ccU1@mid.uni-berlin.de> luca72 schrieb: > There is a command for ctypes that help me to know the entry points > inside a library. dir() on a loaded library? But it won't do you any good, without having the header-file you can't possibly know what the functions take for parameters. Diez From __peter__ at web.de Mon Jun 22 04:52:12 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Jun 2009 10:52:12 +0200 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: >> import readline > Any one knows is this working also on Windows? I've no Win system > right no to test this... I do not have Windows available, either, but you might try http://ipython.scipy.org/moin/PyReadline/Intro Peter From lucaberto at libero.it Mon Jun 22 04:56:52 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 01:56:52 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> Thanks for your reply. I have another question i can load a list of library? Thanks Luca From deets at nospam.web.de Mon Jun 22 05:04:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 11:04:00 +0200 Subject: ctypes list library In-Reply-To: <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> Message-ID: <7a8vo1F1sas0bU1@mid.uni-berlin.de> luca72 schrieb: > Thanks for your reply. > I have another question i can load a list of library? Yes. Diez From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:13:42 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:13:42 +0200 Subject: Missing c.l.py posts (was Re: A question on scope...) In-Reply-To: References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> Message-ID: <4a3f4b46$0$11882$426a74cc@news.free.fr> Aahz a ?crit : > In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, > Bruno Desthuilliers wrote: >> NB : answering the OP (original post didn't show up on c.l.py ???) > > Correct. There's a problem with the mail->news gateway, I think that > MIME messages are failing. I "fixed" the problem for c.l.py.announce by > making the list reject non-ASCII messages, but I don't think that's an > option for python-list. Hu, I see. FWIW, it's not the first time I observe this (posts not showing up, only answers...), but at least I now know why. Well, I guess it might be possible to have the gateway "extract" the text part from MIME messages, but I'm not sure I'd volunteer to work on this... Just out of curiousity, where can I find more infos on this gateway ? From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:21:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:21:23 +0200 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Message-ID: <4a3f4d13$0$11882$426a74cc@news.free.fr> Piet van Oostrum a ?crit : >>>>>> Steven D'Aprano (SD) wrote: (snip) >> SD> # A.__base__ = DebugA ## Uncomment this line for debugging. > >>>> A.__base__ = DebugA > TypeError: readonly attribute > > Make that: A.__bases__ = DebugA, or even better (readability-wise): A.__bases__ = (DebugA,) Just the same thing, but at least you wont neither miss the ',' no wonder wether it's a typo or the author really wanted a tuple. From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:28:01 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:28:01 +0200 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <4a3f4ea1$0$9730$426a74cc@news.free.fr> Dave Angel a ?crit : (snip > Default > arguments of class methods are evaluated during the definition of the > class Default arguments of functions are eval'd during the execution of the def statement. The fact that you use a def statement within a class statement's body is totally orthogonal - a def statement produces a function object, period. It's only when resolved as a class attribute that a function "becomes" a method object (thanks to the descriptor protocol). From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: ctypes list library References: Message-ID: luca72 wrote: > There is a command for ctypes that help me to know the entry points > inside a library. I don't know.. However nm on the library works quite well on the command line $ nm --defined-only -D /usr/lib/libdl.so 00000000 A GLIBC_2.0 00000000 A GLIBC_2.1 00000000 A GLIBC_2.3.3 00000000 A GLIBC_2.3.4 00000000 A GLIBC_PRIVATE 0000304c B _dlfcn_hook 000013b0 T dladdr 00001400 T dladdr1 00000ca0 T dlclose 00001170 T dlerror 00001490 T dlinfo 00001760 T dlmopen 00000ae0 T dlopen 000018d0 T dlopen 00000cf0 T dlsym 00000dd0 W dlvsym nm from the mingw distribution works on Windows too IIRC. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: Allocating memory to pass back via ctypes callback function References: <0b8e092f-2353-4a6b-8ff0-62e1e7b4d427@r3g2000vbp.googlegroups.com> Message-ID: Scott wrote: > I think I found the answer to my own question. Can anyone spot any > issues with the following solution? The application I'm writing will > be hitting these callbacks pretty heavily so I'm nervous about mucking > up the memory management and creating one of those bugs that passes > undetected through testing but nails you in production. > > def my_callback(p_cstring): > answer = 'foobar' > > address = VENDOR_malloc(len(answer)+1) > > cstring = c_char_p.from_address( address ) I think this allocates the pointer (the c_char_p) in the malloced block, not the actual data... > cstring.value = answer And this overwrites the pointer > p_cstring.contents = cstring > return If you try this, it gives all sorts of rubbish data / segfaults memmove(address, address+1, 1) Here is how I'd do it from ctypes import * from ctypes.util import find_library c_lib = CDLL(find_library("c")) malloc = c_lib.malloc malloc.argtypes = [c_long] malloc.restype = c_void_p answer = 'foobar\0' address = malloc(len(answer)) print address cstring = c_char_p() print addressof(cstring) cstring.value = address memmove(address, answer, len(answer)) print cstring.value memmove(address, address+1, 1) print cstring.value Which prints 159611736 3084544552 foobar ooobar -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: Convert hash to struct References: Message-ID: D'Arcy J.M. Cain wrote: > On Fri, 19 Jun 2009 13:17:24 -0500 > Amita Ekbote wrote: > > I am retrieving values from a database in the form of a dictionary so > > I can access the values as d['column'] and I was wondering if there is > > a way to convert the hash to a struct like format so i can just say > > d.column. Makes it easier to read and understand. > > Are there enough clues here? > > class MyDict(dict): > def __getattribute__(self, name): > return dict.__getattribute__(self, name) > > def __getattr__(self, name): > return self.get(name, 42) > > x = MyDict({'a': 1, 'b': 2, 'values': 3}) That is my preferred solution - subclass dict rather than make a new type... I use this a lot for returning results from databases. Here is a more fleshed out version. Changing KeyError to AttributeError is necessary if you want the object to pickle. class MyDict(dict): """ A dictionary with attribute access also. If a builtin dictionary method collides with a member of the dictionary, the member function will win. """ def __getattr__(self, name): try: return super(db_dict, self).__getitem__(name) except KeyError: raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name)) def __setattr__(self, name, value): return super(db_dict, self).__setitem__(name, value) def __delattr__(self, name): try: return super(db_dict, self).__delitem__(name) except KeyError: raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name)) def copy(self): return MyDict(self) > print x.a > print x.z > print x.values > > Big question - what should the last line display? If you expect "3" > and not "" then > you need to reconsider the above implementation. Thinking about the > question may change your opinion about this being a good idea after > all. Indeed! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From csali at tiscali.it Mon Jun 22 05:53:18 2009 From: csali at tiscali.it (Carlo Salinari) Date: Mon, 22 Jun 2009 11:53:18 +0200 Subject: ctypes list library In-Reply-To: <7a8usgF1mj0ccU1@mid.uni-berlin.de> References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <4A3F548E.3010808@tiscali.it> Diez B. Roggisch wrote: > luca72 schrieb: >> There is a command for ctypes that help me to know the entry points >> inside a library. > > dir() on a loaded library? > > But it won't do you any good, without having the header-file you can't > possibly know what the functions take for parameters. I was trying this right now, but I can't even get the exported function names: >>> from ctypes import * >>> l = cdll.msvcrt >>> type(l) >>> dir(l) ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_func_flags_', '_func_restype_', '_handle', '_name'] shouldn't the C functions names be there? From deets at nospam.web.de Mon Jun 22 05:59:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 11:59:09 +0200 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <7a92ocF1uhgjcU1@mid.uni-berlin.de> Carlo Salinari wrote: > Diez B. Roggisch wrote: >> luca72 schrieb: >>> There is a command for ctypes that help me to know the entry points >>> inside a library. >> >> dir() on a loaded library? >> >> But it won't do you any good, without having the header-file you can't >> possibly know what the functions take for parameters. > > I was trying this right now, but I can't even get the exported function > names: To be honest, I wasn't 100% sure about this. That was the reason for the "?", but I admit that I should have phrased it more explicitly. But again, it is pretty useless anyway. Diez From jonas.esp at googlemail.com Mon Jun 22 06:06:53 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 22 Jun 2009 03:06:53 -0700 (PDT) Subject: Check module without import it Message-ID: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> Is there any way to check that it's installed a module without import it directly? I'm using the nex code but it's possible that it not been necessary to import a module ----------------- try: import module except ImportError: pass else: print 'make anything' ----------------- From phostu at gmail.com Mon Jun 22 06:22:32 2009 From: phostu at gmail.com (Vincent) Date: Mon, 22 Jun 2009 03:22:32 -0700 (PDT) Subject: error when use libgmail with proxy References: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Message-ID: <61667eb5-4b7f-40ba-ad1a-f096e0544fc2@v35g2000pro.googlegroups.com> On Jun 22, 3:33 pm, ?????? wrote: > Hi all, > Does anybody use libgmail with proxy? I met error here. > > Below is code snip: > > libgmail.PROXY_URL = G_PROXY # the proxy url > self.ga = libgmail.GmailAccount(account,pwd) > self.ga.login() > > Error information: > ga.login > () > File "C:\Python25\Lib\site-packages\libgmail.py", line 305, in > login > pageData = self._retrievePage > (req) > File "C:\Python25\Lib\site-packages\libgmail.py", line 348, in > _retrievePage > resp = self.opener.open > (req) > File "build\bdist.win32\egg\mechanize\_opener.py", line 191, in > open > File "C:\Python25\lib\urllib2.py", line 399, in > _open > '_open', > req) > File "C:\Python25\lib\urllib2.py", line 360, in > _call_chain > result = func > (*args) > File "build\bdist.win32\egg\mechanize\_http.py", line 751, in > https_open > AttributeError: 'int' object has no attribute > 'find_key_cert' > > Is it possible the issue of mechanize? I do not know why you need proxy. i have used gdata do the same work like you. then i descript it in my blog: vincent-w.blogspot.com From eglyph at gmail.com Mon Jun 22 06:43:46 2009 From: eglyph at gmail.com (eGlyph) Date: Mon, 22 Jun 2009 03:43:46 -0700 (PDT) Subject: error when use libgmail with proxy References: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Message-ID: <6c61f034-c1dc-4341-ae7e-79a7fd80e989@r3g2000vbp.googlegroups.com> On 22 ???, 10:33, ?????? wrote: > Hi all, > Does anybody use libgmail with proxy? I met error here. I wouldn't recommend to use this module at all. It was writtent at the time when no IMAP was available at Google. Now there are POP and IMAP, so it's better to use them. From kushal.kumaran+python at gmail.com Mon Jun 22 06:44:16 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 22 Jun 2009 16:14:16 +0530 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: > I am running python on a mac and when I was getting going it was difficult > to setup information. Specifically how modify bash_profile, how pythonpath > works and how to set it up. how to switch between python versions. How/where > to install modules if you have multiple installed versions. I am thinking > about this from perspective? of a new pythoner (is there a word for a person > who programs in python). I think many new pythoners may be like me and don't > mess with the underling UNIX on a mac. > My question/suggestion is that there be a nice tutorial for this. I am > wiling to contribute much but I am still somewhat new to python and may need > help with some details. Also where should this be posted, how do I post it. > Do other think there is a need? Any willing to help? > But of course I may have missed a great tutorial out there if so I think It > needs to be easier to findor I need to learn how to look. > Have you seen the page at http://www.python.org/download/mac/ and the pages linked from it? -- kushal From wbsoft at xs4all.nl Mon Jun 22 06:57:35 2009 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Mon, 22 Jun 2009 12:57:35 +0200 Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: <200906221257.35618.wbsoft@xs4all.nl> Op maandag 22 juni 2009, schreef Lawrence D'Oliveiro: > value = \ > ( > foo.bar()['first'][0] * baz.quux(1, 2)[5:9] > + > calculate_number(10, 20) * forbulate(500, 360) > ) I' prefer: value = (foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360)) w best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From Olivier.Darge at gmail.com Mon Jun 22 07:22:15 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 22 Jun 2009 04:22:15 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: On 22 juin, 12:44, Kushal Kumaran wrote: > On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: > > I am running python on a mac and when I was getting going it was difficult > > to setup information. Specifically how modify bash_profile, how pythonpath > > works and how to set it up. how to switch between python versions. How/where > > to install modules if you have multiple installed versions. I am thinking > > about this from perspective? of a new pythoner (is there a word for a person > > who programs in python). I think many new pythoners may be like me and don't > > mess with the underling UNIX on a mac. > > My question/suggestion is that there be a nice tutorial for this. I am > > wiling to contribute much but I am still somewhat new to python and may need > > help with some details. Also where should this be posted, how do I post it. > > Do other think there is a need? Any willing to help? > > But of course I may have missed a great tutorial out there if so I think It > > needs to be easier to findor I need to learn how to look. > > Have you seen the page athttp://www.python.org/download/mac/and the > pages linked from it? do you think a pythonista can go further than the given example ? " >>> 2 + 2 4 " ;-) Olivier From Olivier.Darge at gmail.com Mon Jun 22 07:30:35 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 22 Jun 2009 04:30:35 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <63c6a696-540c-4eee-903a-d22bfb7a216a@l34g2000vbi.googlegroups.com> On 22 juin, 12:44, Kushal Kumaran > Have you seen the page athttp://www.python.org/download/mac/and the > pages linked from it? > As a (usefull) add-on : iPython (a must), I found this page a good help : http://www.brianberliner.com/2008/04/ipython-on-mac-os-x-105-leopard/ Olivier From lorenzo.digregorio at gmail.com Mon Jun 22 07:33:43 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Mon, 22 Jun 2009 04:33:43 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: <8bcd8622-d2a1-4ab1-9270-1334d0ac48a9@n21g2000vba.googlegroups.com> On 21 Jun., 22:51, Scott David Daniels wrote: > LorenzoDiGregoriowrote: > > On 21 Jun., 01:54, Dave Angel wrote: > >> ... > >> class B(object): > >> ? ? def __init__(self,test=None): > >> ? ? ? ? if test==None: > >> ? ? ? ? ? ? test = A() > >> ? ? ? ? self.obj =() > >> ? ? ? ? return > > ... > > I had also thought of using "None" (or whatever else) as a marker but > > I was curious to find out whether there are better ways to supply an > > object with standard values as a default argument. > > In this sense, I was looking for problems ;-) > > > Of course the observation that "def" is an instruction and no > > declaration changes the situation: I would not have a new object being > > constructed for every instantiation with no optional argument, because > > __init__ gets executed on the instantiation but test=A() gets executed > > on reading 'def'.... > > If what you are worrying about is having a single default object, you > could do something like this: > > ? ? ?class B(object): > ? ? ? ? ?_default = None > > ? ? ? ? ?def __init__(self, test=None): > ? ? ? ? ? ? ?if test is None: > ? ? ? ? ? ? ? ? ?test = self._default > ? ? ? ? ? ? ? ? ?if test is None: > ? ? ? ? ? ? ? ? ? ? ?B._default = test = A() > ? ? ? ? ? ? ?... > > --Scott David Daniels > Scott.Dani... at Acm.Org- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - Well, I could also declare (ups, define ;-)) __init__(self,**kwargs) and within the __init__, if kwargs['test'] exists, do test = kwargs ['test'], if it does not exist, do test = A(). The point is that it would have been cleaner to place it straight in the __init__, but due to the semantic of 'def' this does not seem possible. From ldo at geek-central.gen.new_zealand Mon Jun 22 08:03:36 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 00:03:36 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Wilbert Berendsen wrote: > I' prefer: > > value = (foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + > calculate_number(10, 20) * forbulate(500, 360)) I prefer using a two-dimensional layout to make the expression structure more obvious: value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) In this case it's not necessary, but if the factors were really long, this could become value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) From lucaberto at libero.it Mon Jun 22 08:19:43 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 05:19:43 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> Message-ID: Can you tell me how load a list of library Thanks From aberry at aol.in Mon Jun 22 08:20:02 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 05:20:02 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <24146279.post@talk.nabble.com> Switching between python version Lets assume you have python 2.4.x and now you installed 2.5.x.By default python path will point to 2.4.x. To switch to python 2.5.x, use following commands... cd /usr/bin sudo rm pythonw sudo ln -s "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" pythonw sudo rm python sudo ln -s pythonw python2.5 sudo ln -s python2.5 python this worked for me... do let me know if any1 has other way of doing... Rgds, aberry Vincent Davis wrote: > > I am running python on a mac and when I was getting going it was difficult > to setup information. Specifically how modify bash_profile, how pythonpath > works and how to set it up. how to switch between python versions. > How/where > to install modules if you have multiple installed versions. I am thinking > about this from perspective of a new pythoner (is there a word for a > person > who programs in python). I think many new pythoners may be like me and > don't > mess with the underling UNIX on a mac. > My question/suggestion is that there be a nice tutorial for this. I am > wiling to contribute much but I am still somewhat new to python and may > need > help with some details. Also where should this be posted, how do I post > it. > Do other think there is a need? Any willing to help? > But of course I may have missed a great tutorial out there if so I think > It > needs to be easier to findor I need to learn how to look. > > Thanks > Vincent > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146279.html Sent from the Python - python-list mailing list archive at Nabble.com. From deets at nospam.web.de Mon Jun 22 08:29:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 14:29:58 +0200 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> Message-ID: <7a9bj5F1uhor1U1@mid.uni-berlin.de> luca72 wrote: > Can you tell me how load a list of library from ctypes.util import find_library from ctypes import CDLL for name in list_of_libraries: lib = CDLL(find_library(name)) Do you actually read the documentation of ctypes? Or python, for that matter? Diez From deets at nospam.web.de Mon Jun 22 08:31:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 14:31:17 +0200 Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <7a9blkF1uhor1U2@mid.uni-berlin.de> aberry wrote: > > Switching between python version > Lets assume you have python 2.4.x and now you installed 2.5.x.By default > python path will point to 2.4.x. To switch to python 2.5.x, use following > commands... > > cd /usr/bin > sudo rm pythonw > sudo ln -s "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" > pythonw > sudo rm python > sudo ln -s pythonw python2.5 > sudo ln -s python2.5 python > > this worked for me... do let me know if any1 has other way of doing... Bad idea. It might break tools that need the /usr/bin/python to be the system's python. a simple export PATH=/Library/.../bin:$PATH inside .bashrc should be all you need. Diez From tkpmep at hotmail.com Mon Jun 22 08:42:40 2009 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Mon, 22 Jun 2009 05:42:40 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> I think a setup guide for the Mac would prove very useful. Earlier this year, I tried installing Python 2.6 on my iMac, and ran into all sorts of problems, largely as a result of the fact that I knew very little about Unix. I finally downloaded and installed the Enthought Python distribution for the Mac and it worked like a charm. From pdpinheiro at gmail.com Mon Jun 22 08:46:55 2009 From: pdpinheiro at gmail.com (pdpi) Date: Mon, 22 Jun 2009 05:46:55 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> On Jun 19, 8:13?pm, Charles Yeomans wrote: > On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: > > > > > > > Evidently my posts are appearing, since I see replies. > > I guess the question of why I don't see the posts themselves > > \is ot here... > > > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson > > wrote: > > >> On Jun 18, 7:26 pm, David C. Ullrich ? > >> wrote: > >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > >>>> Right. ?Or rather, you treat it as the image of such a function, > >>>> if you're being careful to distinguish the curve (a subset > >>>> of R^2) from its parametrization (a continuous function > >>>> R -> R**2). ?It's the parametrization that's uniformly > >>>> continuous, not the curve, > > >>> Again, it doesn't really matter, but since you use the phrase > >>> "if you're being careful": In fact what you say is exactly > >>> backwards - if you're being careful that subset of the plane > >>> is _not_ a curve (it's sometimes called the "trace" of the curve". > > >> Darn. ?So I've been getting it wrong all this time. ?Oh well, > >> at least I'm not alone: > > >> "De?nition 1. A simple closed curve J, also called a > >> Jordan curve, is the image of a continuous one-to-one > >> function from R/Z to R2. [...]" > > >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. > > >> "We say that Gamma is a curve if it is the image in > >> the plane or in space of an interval [a, b] of real > >> numbers of a continuous function gamma." > > >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). > > >> Perhaps your definition of curve isn't as universal or > >> 'official' as you seem to think it is? > > > Perhaps not. I'm very surprised to see those definitions; I've > > been a mathematician for 25 years and I've never seen a > > curve defined a subset of the plane. > > I have. > > > > > > > > > Hmm. You left out a bit in the first definition you cite: > > > "A simple closed curve J, also called a Jordan curve, is the image > > of a continuous one-to-one function from R/Z to R2. We assume that > > each curve > > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z > > the time > > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j > > (t), using the > > same notation for the function phi_J and its image J." > > > Close to sounding like he can't decide whether J is a set or a > > function... > > On the contrary, I find this definition to be written with some care. I find the usage of image slightly ambiguous (as it suggests the image set defines the curve), but that's my only qualm with it as well. Thinking pragmatically, you can't have non-simple curves unless you use multisets, and you also completely lose the notion of curve orientation and even continuity without making it a poset. At this point in time, parsimony says that you want to ditch your multiposet thingie (and God knows what else you want to tack in there to preserve other interesting curve properties) and really just want to define the curve as a freaking function and be done with it. From steve.ferg.bitbucket at gmail.com Mon Jun 22 08:50:34 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 22 Jun 2009 05:50:34 -0700 (PDT) Subject: easiest way to check python version? References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: Here is what I use in easygui:
#--------------------------------------------------
# check python version and take appropriate action
#--------------------------------------------------
"""
>From the python documentation:

sys.hexversion contains the version number encoded as a single
integer. This is
guaranteed to increase with each version, including proper support for
non-
production releases. For example, to test that the Python interpreter
is at
least version 1.5.2, use:

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
"""
if sys.hexversion >= 0x020600F0: runningPython26 = True
else: runningPython26 = False

if sys.hexversion >= 0x030000F0: runningPython3 = True
else: runningPython3 = False

if runningPython3:
    from tkinter import *
    import tkinter.filedialog as tk_FileDialog
    from io import StringIO
else:
    from Tkinter import *
    import tkFileDialog as tk_FileDialog
    from StringIO import StringIO

-- Steve Ferg From aberry at aol.in Mon Jun 22 08:56:12 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 05:56:12 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <7a9blkF1uhor1U2@mid.uni-berlin.de> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> Message-ID: <24146713.post@talk.nabble.com> thanks for suggestion... what should I put in 'bashrc ' so that I can switch between different version. as python command will always point to one Python framework (lets either 2.4.x or 2.5.x). regards, aberry Diez B. Roggisch-2 wrote: > > aberry wrote: > >> >> Switching between python version >> Lets assume you have python 2.4.x and now you installed 2.5.x.By default >> python path will point to 2.4.x. To switch to python 2.5.x, use following >> commands... >> >> cd /usr/bin >> sudo rm pythonw >> sudo ln -s >> "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" >> pythonw >> sudo rm python >> sudo ln -s pythonw python2.5 >> sudo ln -s python2.5 python >> >> this worked for me... do let me know if any1 has other way of doing... > > Bad idea. It might break tools that need the /usr/bin/python to be the > system's python. > > a simple > > export PATH=/Library/.../bin:$PATH > > inside .bashrc should be all you need. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146713.html Sent from the Python - python-list mailing list archive at Nabble.com. From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 08:56:24 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 14:56:24 +0200 Subject: Graphical library - charts Message-ID: Hello, I have thousends of files with logs from monitoring system. Each file has some important data (numbers). I'd like to create charts using those numbers. Could you please suggest library which will allow creating such charts ? The preferred chart is line chart. Besides is there any library which allow me to zoom in/out of such chart ? Sometimes I need to create chart using long-term data (a few months) but then observe a minutes - it would be good to not create another short-term chart but just zoom-in. Those files are on one unix server and the charts will be displayed on another unix server so the X-Window protocol is going to be used. Any suggestions ? Best regards przemol From jeanmichel at sequans.com Mon Jun 22 08:57:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 14:57:37 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1245269001.27277.28.camel@aalcdl07> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> Message-ID: <4A3F7FC1.1000200@sequans.com> J. Cliff Dyer wrote: > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >> >>>> What's np.arange? >>>> >>>> >>> import numpy as np >>> >>> -- >>> Pierre "delroth" Bourdon >>> ?tudiant ? l'EPITA / Student at EPITA >>> >>> >> Perfect example of why renaming namespaces should be done only when >> absolutely required, that is, almost never. >> >> Jean-Michel >> > > I disagree. Renaming namespaces should always be done if it will help > stop people from doing a 'from package import *'. However, example code > should always include relevant imports. > > Cheers, > Cliff > > > The import * should not used if possible, I totally agree on that point, but there's no need to rename namespaces for that. br Jean-Michel From aberry at aol.in Mon Jun 22 09:00:07 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 06:00:07 -0700 (PDT) Subject: UnicodeDecodeError: problem when path contain folder start with character 'u Message-ID: <24146775.post@talk.nabble.com> I am facing an error on Unicode decoding of path if it contain a folder/file name starting with character 'u' . Here is what I did in IDLE 1. >>> fp = "C:\\ab\\anil" 2. >>> unicode(fp, "unicode_escape") 3. u'C:\x07b\x07nil' 4. >>> fp = "C:\\ab\\unil" 5. >>> unicode(fp, "unicode_escape") 6. 7. Traceback (most recent call last): 8. File "", line 1, in 9. unicode(fp, "unicode_escape") 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 5-9: end of string in escape sequence 11. >>> Not sure whether I am doing something wrong or this is as designed behavior . any help appreciated Rgds, aberry -- View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24146775.html Sent from the Python - python-list mailing list archive at Nabble.com. From bluefisher80 at gmail.com Mon Jun 22 09:17:20 2009 From: bluefisher80 at gmail.com (Jim Qiu) Date: Mon, 22 Jun 2009 21:17:20 +0800 Subject: How to output a complex List object to a file. Message-ID: Hi all, I have a object list list this: from bots.botsconfig import * from D96Arecords import recorddefs from edifactsyntax3 import syntax structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] I need to output this "structure" object into a file, how to do that ? Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Mon Jun 22 09:17:43 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jun 2009 06:17:43 -0700 Subject: Missing c.l.py posts (was Re: A question on scope...) References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> <4a3f4b46$0$11882$426a74cc@news.free.fr> Message-ID: In article <4a3f4b46$0$11882$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Aahz a ?crit : >> In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> >>> NB : answering the OP (original post didn't show up on c.l.py ???) >> >> Correct. There's a problem with the mail->news gateway, I think that >> MIME messages are failing. I "fixed" the problem for c.l.py.announce by >> making the list reject non-ASCII messages, but I don't think that's an >> option for python-list. > >Hu, I see. FWIW, it's not the first time I observe this (posts not >showing up, only answers...), but at least I now know why. Well, I guess >it might be possible to have the gateway "extract" the text part from >MIME messages, but I'm not sure I'd volunteer to work on this... Just >out of curiousity, where can I find more infos on this gateway ? It's part of Mailman, so that's where you should start. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From davea at ieee.org Mon Jun 22 09:17:47 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 09:17:47 -0400 Subject: ctypes list library In-Reply-To: References: Message-ID: <4A3F847B.4060608@ieee.org> Nick Craig-Wood wrote: > luca72 wrote: > >> There is a command for ctypes that help me to know the entry points >> inside a library. >> > > I don't know.. > > However nm on the library works quite well on the command line > > $ nm --defined-only -D /usr/lib/libdl.so > 00000000 A GLIBC_2.0 > 00000000 A GLIBC_2.1 > 00000000 A GLIBC_2.3.3 > 00000000 A GLIBC_2.3.4 > 00000000 A GLIBC_PRIVATE > 0000304c B _dlfcn_hook > 000013b0 T dladdr > 00001400 T dladdr1 > 00000ca0 T dlclose > 00001170 T dlerror > 00001490 T dlinfo > 00001760 T dlmopen > 00000ae0 T dlopen > 000018d0 T dlopen > 00000cf0 T dlsym > 00000dd0 W dlvsym > > nm from the mingw distribution works on Windows too IIRC. > > For Windows, you can use the Microsoft tool DUMPBIN to display entry points (and other stuff) for a DLL. Notice that a DLL may have almost any extension, including EXE, SYS, DRV, ... From bjourne at gmail.com Mon Jun 22 09:20:26 2009 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 22 Jun 2009 15:20:26 +0200 Subject: Graphical library - charts In-Reply-To: References: Message-ID: <740c3aec0906220620p4e43a326g5893bb15cbc43042@mail.gmail.com> 2009/6/22 : > Hello, > > I have thousends of files with logs from monitoring system. Each file > has some important data (numbers). I'd like to create charts using those > numbers. Could you please suggest library which will allow creating > such charts ? The preferred chart is line chart. > > Besides is there any library which allow me to zoom in/out of such chart ? > Sometimes I need to create chart using long-term data (a few months) but > then observe a minutes - it would be good to not create another short-term > chart but just zoom-in. > > Those files are on one unix server and the charts will be displayed on > another unix server so the X-Window protocol is going to be used. Try Google Charts. It is quite excellent for easily creating simple charts. There is also Gnuplot which is more advanced and complicated. Both tools have python bindings. -- mvh Bj?rn From philip at semanchuk.com Mon Jun 22 09:23:04 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 22 Jun 2009 09:23:04 -0400 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <6172D09B-ABB4-4E89-8F4D-619F05531F9A@semanchuk.com> On Jun 22, 2009, at 9:17 AM, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, ...snip... > > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? Have you looked at the pickle module? From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 09:27:03 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 15:27:03 +0200 Subject: Graphical library - charts References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart >> ? Sometimes I need to create chart using long-term data (a few months) >> but then observe a minutes - it would be good to not create another >> short-term chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. Which option is better: pygooglechart http://pygooglechart.slowchop.com/ google-chartwrapper http://code.google.com/p/google-chartwrapper/ Regards Przemek From steve.ferg.bitbucket at gmail.com Mon Jun 22 09:29:56 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 22 Jun 2009 06:29:56 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: If you are looking for *classics*, then you can't beat Michael Jackson's "Principles of Program Design" and "System Development". They are pre-ObjectOriented, but if you really want to understand what application programming is all about, this is where you should start. I also recommend Eric S. Roberts "Thinking Recursively". I don't know if it can be considered a classic, but a good programmer needs to be able to understand and do recursion, and I found this book a very readable introduction. It may also help if you bring a tighter focus to your search. The domain of programming can be divided up into large subdomains, each with its own specialized types of problems, techniques and classics. Here are some subdomains that I can think of off the top of my head: system programming -- dealing with interacting with the computer at the bits and bytes level scientific programming -- dealing with algorithms business programming -- dealing with data structures and the events that change them embedded & real-time programming -- dealing with controlling machines ... and there are probably others, such as writing compilers/ interpreters, and robotics programming. From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 09:35:14 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 15:35:14 +0200 Subject: Graphical library - charts References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart >> ? Sometimes I need to create chart using long-term data (a few months) >> but then observe a minutes - it would be good to not create another >> short-term chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. By the way: do I need any access to internet while using this library ? Regards przemol From rridge at csclub.uwaterloo.ca Mon Jun 22 09:36:52 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Mon, 22 Jun 2009 09:36:52 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: Piet van Oostrum wrote: >I notice that I see several postings on news:comp.lang.python that are >replies to other postings that I don't see. Aahz wrote: >As stated previously, my suspicion is that at least some is caused by a >problem with MIME messages and the mail->news gateway on python.org. I'm not sure what MIME would have to do with it, but Piet van Oostrum's problem is almost certainly as result of the python.org mail to news gateway mangling the References header. The missing postings he's looking for don't actually exist. Just go up the thread one more posting and you'll find the message that was being replied to. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From deets at nospam.web.de Mon Jun 22 09:36:56 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 15:36:56 +0200 Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> Message-ID: <7a9fgnF1uclajU1@mid.uni-berlin.de> aberry wrote: > > thanks for suggestion... > what should I put in 'bashrc ' so that I can switch between different > version. > as python command will always point to one Python framework (lets either > 2.4.x or 2.5.x). if you want to switch, put in there three different lines, and comment that in that you need. Or write short bash-functions that replace the path. Not scripts!! They won't work. But I think if you want to switch, you are better off using fully qualified names, such as python2.5 and link these to your desired versions. Or start using virtualenvs for everything (as I do), and don't bother as you simply activate the one you want before using python. Diez From philip at semanchuk.com Mon Jun 22 09:59:02 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 22 Jun 2009 09:59:02 -0400 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <24146713.post@talk.nabble.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> <24146713.post@talk.nabble.com> Message-ID: On Jun 22, 2009, at 8:56 AM, aberry wrote: > > thanks for suggestion... > what should I put in 'bashrc ' so that I can switch between different > version. > as python command will always point to one Python framework (lets > either > 2.4.x or 2.5.x). Something like this would work: alias py25='/Library/Frameworks/Python.framework/Versions/2.5/bin/ pythonw' > Diez B. Roggisch-2 wrote: >> >> aberry wrote: >> >>> >>> Switching between python version >>> Lets assume you have python 2.4.x and now you installed 2.5.x.By >>> default >>> python path will point to 2.4.x. To switch to python 2.5.x, use >>> following >>> commands... >>> >>> cd /usr/bin >>> sudo rm pythonw >>> sudo ln -s >>> "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" >>> pythonw >>> sudo rm python >>> sudo ln -s pythonw python2.5 >>> sudo ln -s python2.5 python >>> >>> this worked for me... do let me know if any1 has other way of >>> doing... >> >> Bad idea. It might break tools that need the /usr/bin/python to be >> the >> system's python. >> >> a simple >> >> export PATH=/Library/.../bin:$PATH >> >> inside .bashrc should be all you need. >> >> Diez >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -- > View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146713.html > Sent from the Python - python-list mailing list archive at Nabble.com. > > -- > http://mail.python.org/mailman/listinfo/python-list From jcd at sdf.lonestar.org Mon Jun 22 10:12:08 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 10:12:08 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3F7FC1.1000200@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> Message-ID: <1245679928.22057.24.camel@aalcdl07> On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > J. Cliff Dyer wrote: > > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > > > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> > >>>> What's np.arange? > >>>> > >>>> > >>> import numpy as np > >>> > >>> -- > >>> Pierre "delroth" Bourdon > >>> ?tudiant ? l'EPITA / Student at EPITA > >>> > >>> > >> Perfect example of why renaming namespaces should be done only when > >> absolutely required, that is, almost never. > >> > >> Jean-Michel > >> > > > > I disagree. Renaming namespaces should always be done if it will help > > stop people from doing a 'from package import *'. However, example code > > should always include relevant imports. > > > > Cheers, > > Cliff > > > > > > > The import * should not used if possible, I totally agree on that point, > but there's no need to rename namespaces for that. > > br > > Jean-Michel > Technically, no. But we're dealing with people, who are notoriously *un*technical in their behavior. A person is much more likely to develop bad habits if the alternative means more work for them. The reason people do `from foo import *` is that they don't want to type more than they have to. If they can write a one or two letter namespace, they're likely to be happy with that trade-off. If the alternative is to write out long module names every time you use a variable, they'll tend to develop bad habits. To paraphrase Peter Maurin, coding guidelines should have the aim of helping to "bring about a world in which it is easy to be good." I don't really see much problem with renaming namespaces: For people reading the code, everything is explicit, as you can just look at the top of the module to find out what module a namespace variable represent; the local namespace doesn't get polluted with God knows what from God knows where; and code remains succinct. I've found in my own code that using, for example, the name `sqlalchemy` in my code means that I have to go through painful contortions to get your code down to the PEP-8 recommended 80 characters per line. The resulting mess of multi-line statements is significantly less readable than the same code using the abbreviation `sa`. Do you have an argument for avoiding renaming namespaces? So far the only example you provided is a code fragment that doesn't run. I don't disagree with you on that example; referring to numpy as np without telling anyone what np refers to is a bad idea, but no functioning piece of code could reasonably do that. Cheers, Cliff From jcd at sdf.lonestar.org Mon Jun 22 10:17:19 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 10:17:19 -0400 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <1245680239.22057.25.camel@aalcdl07> Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, > {ID:'NAD',MIN:1,MAX:5,LEVEL:[ > {ID:'CTA',MIN:0,MAX:5,LEVEL:[ > {ID:'COM',MIN:0,MAX:5}, > ]}, > ]}, > {ID:'RFF',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'CUX',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ > {ID:'PIA',MIN:0,MAX:5}, > {ID:'IMD',MIN:0,MAX:5}, > {ID:'RFF',MIN:0,MAX:5}, > {ID:'ALI',MIN:0,MAX:5}, > {ID:'MOA',MIN:0,MAX:5}, > {ID:'PRI',MIN:0,MAX:5}, > {ID:'QTY',MIN:0,MAX:999,LEVEL:[ > {ID:'NAD',MIN:0,MAX:1}, > ]}, > ]}, > ]}, > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? > > Jim > From charles at declareSub.com Mon Jun 22 10:31:26 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 22 Jun 2009 10:31:26 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: On Jun 22, 2009, at 8:46 AM, pdpi wrote: > On Jun 19, 8:13 pm, Charles Yeomans wrote: >> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >> >> >> >> >> >> >>> Hmm. You left out a bit in the first definition you cite: >> >>> "A simple closed curve J, also called a Jordan curve, is the image >>> of a continuous one-to-one function from R/Z to R2. We assume that >>> each curve >>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>> R/Z >>> the time >>> parameter. By abuse of notation, we write J(t) in R2 instead of >>> phi_j >>> (t), using the >>> same notation for the function phi_J and its image J." >> >>> Close to sounding like he can't decide whether J is a set or a >>> function... >> >> On the contrary, I find this definition to be written with some care. > > I find the usage of image slightly ambiguous (as it suggests the image > set defines the curve), but that's my only qualm with it as well. > > Thinking pragmatically, you can't have non-simple curves unless you > use multisets, and you also completely lose the notion of curve > orientation and even continuity without making it a poset. At this > point in time, parsimony says that you want to ditch your multiposet > thingie (and God knows what else you want to tack in there to preserve > other interesting curve properties) and really just want to define the > curve as a freaking function and be done with it. > -- But certainly the image set does define the curve, if you want to view it that way -- all parameterizations of a curve should satisfy the same equation f(x, y) = 0. Charles Yeomans From vlastimil.brom at gmail.com Mon Jun 22 10:41:10 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 22 Jun 2009 16:41:10 +0200 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u In-Reply-To: <24146775.post@talk.nabble.com> References: <24146775.post@talk.nabble.com> Message-ID: <9fdb569a0906220741w5a43a574nef3e47f5dc07e996@mail.gmail.com> 2009/6/22 aberry : > > I am facing an error on Unicode decoding of path if it contain a folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" > 2. >>> unicode(fp, "unicode_escape") > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" > 5. >>> unicode(fp, "unicode_escape") > 6. > 7. Traceback (most recent call last): > 8. ? File "", line 1, in > 9. ? ? unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position > 5-9: end of string in escape sequence > 11. >>> > > Not sure whether I am doing something wrong or this is as designed behavior > . > any help appreciated > > Rgds, > aberry > > > -- > View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24146775.html > Sent from the Python - python-list mailing list archive at Nabble.com. > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, It seems, that using unicode_escape codec is not appropriate here, are you sure, you are dealing with unicode encoded strings? The examples seem like usual strings with backslashes escaped. If these should be paths, you probably can use them directly without conversion (the "bel" hex 0x07 character is maybe not expected here, is it?) vbr From thudfoo at opensuse.us Mon Jun 22 11:05:26 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 22 Jun 2009 08:05:26 -0700 Subject: Check module without import it In-Reply-To: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> References: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> Message-ID: <3d881a310906220805o2ff91ba4hf989d34747c2d8b7@mail.gmail.com> On Mon, Jun 22, 2009 at 3:06 AM, Kless wrote: > Is there any way to check that it's installed a module without import > it directly? > > I'm using the nex code but it's possible that it not been necessary to > import a module > > ----------------- > try: > ? import module > except ImportError: > ? pass > else: > ? print 'make anything' > ----------------- Have a look at find_module in the imp module of the standard library. From vincent at vincentdavis.net Mon Jun 22 11:19:42 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 22 Jun 2009 09:19:42 -0600 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> Message-ID: <77e831100906220819t25c93219k5f564bf01ba888dc@mail.gmail.com> tkpmep at hotmail.com wrote: > I think a setup guide for the Mac would prove very useful. Earlier > this year, I tried installing Python 2.6 on my iMac, and ran into all > sorts of problems, largely as a result of the fact that I knew very > little about Unix. I finally downloaded and installed the Enthought > Python distribution for the Mac and it worked like a charm. > Exactly why I think this is needed. I did the same thing, installed Enthought. Then I wanted to use 2.6 and now 3.0.1 . I have all versions installed. They work and I know how to switch between but not so sure what s going on when I things a package. I should not require lots of googling for the answers. The mailing lists are great and everyone is helpful but do you really want to answer the same questions again and agian. Kushal Kumaran "Have you seen the page at http://www.python.org/download/mac/ and the pages linked from it? Yes I have as I am sure tkpmep at hotmail.com and did not find it usefull, or I should say only a little. So I still have no answer, There seems to be a need but, no one has said "post it hear" or volunteered to help. Am I going about this wrong? Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jun 22 11:34:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 11:34:15 -0400 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> Message-ID: Kushal Kumaran wrote: > On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: >> I am running python on a mac and when I was getting going it was difficult >> to setup information. Specifically how modify bash_profile, how pythonpath >> works and how to set it up. how to switch between python versions. How/where >> to install modules if you have multiple installed versions. I am thinking >> about this from perspective of a new pythoner (is there a word for a person >> who programs in python). I think many new pythoners may be like me and don't >> mess with the underling UNIX on a mac. >> My question/suggestion is that there be a nice tutorial for this. I am >> wiling to contribute much but I am still somewhat new to python and may need >> help with some details. Also where should this be posted, how do I post it. >> Do other think there is a need? Any willing to help? >> But of course I may have missed a great tutorial out there if so I think It >> needs to be easier to findor I need to learn how to look. The Python doc set includes Using Python. Chapter 4 is ... on a Macintosh. If you think that is inadequate, start a new issue on the tracker (after searching for existing Mac doc issues). Python is a volunteer enterprise, and Python-Mac is a relatively small subset of volunteers, so feel free to help. > Have you seen the page at http://www.python.org/download/mac/ and the > pages linked from it? It is possible that the chapter should include material from or link to material in other pages. tjr From tjreedy at udel.edu Mon Jun 22 11:45:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 11:45:21 -0400 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u In-Reply-To: <24146775.post@talk.nabble.com> References: <24146775.post@talk.nabble.com> Message-ID: aberry wrote: > I am facing an error on Unicode decoding of path if it contain a folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" The results in two single \s in the string. Use / for paths, even on Windows, and you will have less trouble. > 2. >>> unicode(fp, "unicode_escape") why? Not for interacting with file system. It tries to interpret \s. Not what you want. > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" This has \u followed by three chars. \u followed by FOUR chars is a unicode escape for ONE unicode char. > 5. >>> unicode(fp, "unicode_escape") This tries to interpret \uxxxx as 1 char, but it only fines \uxxx and the string ends. > 6. > 7. Traceback (most recent call last): > 8. File "", line 1, in > 9. unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position > 5-9: end of string in escape sequence Read the doc for string literals and unicode function. From piet at cs.uu.nl Mon Jun 22 11:54:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 22 Jun 2009 17:54:16 +0200 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u References: Message-ID: >>>>> aberry (a) a ?crit: >a> I am facing an error on Unicode decoding of path if it contain a folder/file >a> name starting with character 'u' . >a> Here is what I did in IDLE >a> 1. >>> fp = "C:\\ab\\anil" >a> 2. >>> unicode(fp, "unicode_escape") >a> 3. u'C:\x07b\x07nil' >a> 4. >>> fp = "C:\\ab\\unil" >a> 5. >>> unicode(fp, "unicode_escape") >a> 6. >a> 7. Traceback (most recent call last): >a> 8. File "", line 1, in >a> 9. unicode(fp, "unicode_escape") >a> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position >a> 5-9: end of string in escape sequence >a> 11. >>> >a> Not sure whether I am doing something wrong or this is as designed behavior >a> . >a> any help appreciated Calling unicode(fp, "unicode_escape") with these filenames is nonsense. unicode_escape is for transforming a string like \u20ac to a ?-sign or vice versa: >>> fp="\\u20ac" >>> print unicode(fp,"unicode_escape") ? So what are you trying to achieve? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Mon Jun 22 12:02:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 12:02:06 -0400 Subject: Graphical library - charts In-Reply-To: References: Message-ID: przemolicc at poczta.fm-n-o-s-p-a-m wrote: >> Try Google Charts. It is quite excellent for easily creating simple >> charts. There is also Gnuplot which is more advanced and complicated. >> Both tools have python bindings. > > By the way: do I need any access to internet while using this library ? http://code.google.com/apis/chart/basics.html GoogleCharts are generated by Google in response to a url call to Google. They are intended for embedding in a web page with the url being part of an image element. While interesting for that, they may not be what you want for your app The largest size is well less than full screen. From jeanmichel at sequans.com Mon Jun 22 12:14:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 18:14:14 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1245679928.22057.24.camel@aalcdl07> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4A3FADD6.3010608@sequans.com> J. Cliff Dyer wrote: > On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > >> J. Cliff Dyer wrote: >> >>> On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: >>> >>> >>>> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >>>> >>>> >>>>>> What's np.arange? >>>>>> >>>>>> >>>>>> >>>>> import numpy as np >>>>> >>>>> -- >>>>> Pierre "delroth" Bourdon >>>>> ?tudiant ? l'EPITA / Student at EPITA >>>>> >>>>> >>>>> >>>> Perfect example of why renaming namespaces should be done only when >>>> absolutely required, that is, almost never. >>>> >>>> Jean-Michel >>>> >>>> >>> I disagree. Renaming namespaces should always be done if it will help >>> stop people from doing a 'from package import *'. However, example code >>> should always include relevant imports. >>> >>> Cheers, >>> Cliff >>> >>> >>> >>> >> The import * should not used if possible, I totally agree on that point, >> but there's no need to rename namespaces for that. >> >> br >> >> Jean-Michel >> >> > > Technically, no. But we're dealing with people, who are notoriously > *un*technical in their behavior. A person is much more likely to > develop bad habits if the alternative means more work for them. The > reason people do `from foo import *` is that they don't want to type > more than they have to. If they can write a one or two letter > namespace, they're likely to be happy with that trade-off. If the > alternative is to write out long module names every time you use a > variable, they'll tend to develop bad habits. To paraphrase Peter > Maurin, coding guidelines should have the aim of helping to "bring about > a world in which it is easy to be good." > > I don't really see much problem with renaming namespaces: For people > reading the code, everything is explicit, as you can just look at the > top of the module to find out what module a namespace variable > represent; the local namespace doesn't get polluted with God knows what > from God knows where; and code remains succinct. > > I've found in my own code that using, for example, the name `sqlalchemy` > in my code means that I have to go through painful contortions to get > your code down to the PEP-8 recommended 80 characters per line. The > resulting mess of multi-line statements is significantly less readable > than the same code using the abbreviation `sa`. > > Do you have an argument for avoiding renaming namespaces? So far the > only example you provided is a code fragment that doesn't run. I don't > disagree with you on that example; referring to numpy as np without > telling anyone what np refers to is a bad idea, but no functioning piece > of code could reasonably do that. > > Cheers, > Cliff > > Maybe I've been a little bit too dictatorial when I was saying that renaming namespaces should be avoided. Sure your way of doing make sense. In fact they're 2 main purposes of having strong coding rules: 1/ ease the coder's life 2/ ease the reader's life The perfect rule satisfies both of them, but when I have to choose, I prefer number 2. Renaming packages, especially those who are world wide used, may confuse the reader and force him to browse into more code. From the OP example, I was just pointing the fact that **he alone** gains 3 characters when **all** the readers need to ask what means "np". Renaming namespaces with a well chosen name (meaningful) is harmless. br Jean-Michel From edreamleo at charter.net Mon Jun 22 12:23:03 2009 From: edreamleo at charter.net (Edward K Ream) Date: Mon, 22 Jun 2009 11:23:03 -0500 Subject: ANN: Leo 4.6 beta 2 released Message-ID: Leo 4.6 b2 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.6: -------------------------- - Cached external files *greatly* reduces the time to load .leo files. - Leo now features a modern Qt interface by default. Leo's legacy Tk interface can also be used. - New --config, --file and --gui command-line options. - Leo tests syntax of .py files when saving them. - Leo can now open any kind of file into @edit nodes. - @auto-rst nodes support "round-tripping" of reStructuredText files. - Properties of commanders, positions and nodes simplify programming. - Improved Leo's unit testing framework. - Leo now requires Python 2.4 or later. - Dozens of small improvements and bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html -------------------------------------------------------------------- Edward K. Ream email: edreamleo at yahoo.com Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From tanner989 at hotmail.com Mon Jun 22 12:37:20 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Mon, 22 Jun 2009 11:37:20 -0500 Subject: Help Message-ID: Hi i was wondering how i should go about this problem: ok so i am writing a program for my school's football team and to keep the stats for each player there is a notebook with 3 tabs that has a txtctrl and a + and - button. i need to find a way to when you click the + or - button it updates that stat for that individual player. _________________________________________________________________ Hotmail? has ever-growing storage! Don?t worry about storage limits. http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From zelegolas at gmail.com Mon Jun 22 12:58:19 2009 From: zelegolas at gmail.com (zelegolas) Date: Mon, 22 Jun 2009 09:58:19 -0700 (PDT) Subject: wikipedia with python Message-ID: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Let me know if it's the right place to ask. I'm looking for wiki writen with python where I can import all wikipedia site. If you have any links please let me know. Thanks From psimon at sonic.net Mon Jun 22 13:01:35 2009 From: psimon at sonic.net (Paul Simon) Date: Mon, 22 Jun 2009 10:01:35 -0700 Subject: Graphical library - charts References: Message-ID: <4a3fb8f7$0$95510$742ec2ed@news.sonic.net> I suggest you look at matplotlib. It's a bit of a learning curve but will do whatever you need. I have a similar requirement and found that gnuplot did not work for me. The plots are impressive. Paul Simon wrote in message news:h1nv4q$5k2$1 at news.dialog.net.pl... > Hello, > > I have thousends of files with logs from monitoring system. Each file > has some important data (numbers). I'd like to create charts using those > numbers. Could you please suggest library which will allow creating > such charts ? The preferred chart is line chart. > > Besides is there any library which allow me to zoom in/out of such chart ? > Sometimes I need to create chart using long-term data (a few months) but > then observe a minutes - it would be good to not create another short-term > chart but just zoom-in. > > Those files are on one unix server and the charts will be displayed on > another unix server so the X-Window protocol is going to be used. > > Any suggestions ? > > Best regards > przemol > From martin at marcher.name Mon Jun 22 13:16:08 2009 From: martin at marcher.name (Martin) Date: Mon, 22 Jun 2009 19:16:08 +0200 Subject: wikipedia with python In-Reply-To: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: <5fa6c12e0906221016x146a44ccr66528c73667caac9@mail.gmail.com> Does this help: http://www.mediawiki.org/wiki/MoinMoin On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: > Let me know if it's the right place to ask. > > I'm looking for wiki writen with python where I can import all > wikipedia site. > If you have any links please let me know. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From lie.1296 at gmail.com Mon Jun 22 13:18:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 17:18:24 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: Jean-Michel Pichavant wrote: > Maybe I've been a little bit too dictatorial when I was saying that > renaming namespaces should be avoided. > Sure your way of doing make sense. In fact they're 2 main purposes of > having strong coding rules: > 1/ ease the coder's life > 2/ ease the reader's life > > The perfect rule satisfies both of them, but when I have to choose, I > prefer number 2. Renaming packages, especially those who are world wide > used, may confuse the reader and force him to browse into more code. > > From the OP example, I was just pointing the fact that **he alone** > gains 3 characters when **all** the readers need to ask what means "np". > Renaming namespaces with a well chosen name (meaningful) is harmless. As long as you keep all import statements at the head of the file, there is no readability problems with renaming namespace. Glance at the header file, see: import numpy as np and it's not hard to mentally switch np as numpy... well, as long as your header doesn't look like this: import numpy as np import itertools as it import Tkinter as Tk from time import time as t From andreengels at gmail.com Mon Jun 22 13:23:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 22 Jun 2009 19:23:59 +0200 Subject: wikipedia with python In-Reply-To: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: > Let me know if it's the right place to ask. > > I'm looking for wiki writen with python where I can import all > wikipedia site. > If you have any links please let me know. I don't think that's possible. If you wnat to import Wikipedia in a wiki, it will probably have to be MediaWiki - and that's written in PHP. What do you want to use the material for? -- Andr? Engels, andreengels at gmail.com From lie.1296 at gmail.com Mon Jun 22 13:36:07 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 17:36:07 GMT Subject: Graphical library - charts In-Reply-To: References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart ? >> Sometimes I need to create chart using long-term data (a few months) but >> then observe a minutes - it would be good to not create another short-term >> chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. > I've used Quickplot (http://quickplot.sourceforge.net/) for similar purpose. It's not the most elegant solution since the chart viewer is external, not embedded to your program, but it works, zooming and all. You simply need to create a program that convert the log file into list of points and pipe it to quickplot or save it into a file and point quickplot to it (look at the command line options). The chart navigation is a bit unusual, but is efficient to work with once you get used to it. From ullrich at math.okstate.edu Mon Jun 22 14:11:02 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:11:02 -0500 Subject: Measuring Fractal Dimension ? References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: <59iv35d8rat0rvm45d3u14trhen69efrfe@4ax.com> On Mon, 22 Jun 2009 05:46:55 -0700 (PDT), pdpi wrote: >On Jun 19, 8:13?pm, Charles Yeomans wrote: >> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >> >> >> >> >> >> > Evidently my posts are appearing, since I see replies. >> > I guess the question of why I don't see the posts themselves >> > \is ot here... >> >> > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson >> > wrote: >> >> >> On Jun 18, 7:26 pm, David C. Ullrich ? >> >> wrote: >> >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >> >>>> Right. ?Or rather, you treat it as the image of such a function, >> >>>> if you're being careful to distinguish the curve (a subset >> >>>> of R^2) from its parametrization (a continuous function >> >>>> R -> R**2). ?It's the parametrization that's uniformly >> >>>> continuous, not the curve, >> >> >>> Again, it doesn't really matter, but since you use the phrase >> >>> "if you're being careful": In fact what you say is exactly >> >>> backwards - if you're being careful that subset of the plane >> >>> is _not_ a curve (it's sometimes called the "trace" of the curve". >> >> >> Darn. ?So I've been getting it wrong all this time. ?Oh well, >> >> at least I'm not alone: >> >> >> "De?nition 1. A simple closed curve J, also called a >> >> Jordan curve, is the image of a continuous one-to-one >> >> function from R/Z to R2. [...]" >> >> >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. >> >> >> "We say that Gamma is a curve if it is the image in >> >> the plane or in space of an interval [a, b] of real >> >> numbers of a continuous function gamma." >> >> >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). >> >> >> Perhaps your definition of curve isn't as universal or >> >> 'official' as you seem to think it is? >> >> > Perhaps not. I'm very surprised to see those definitions; I've >> > been a mathematician for 25 years and I've never seen a >> > curve defined a subset of the plane. >> >> I have. >> >> >> >> >> >> >> >> > Hmm. You left out a bit in the first definition you cite: >> >> > "A simple closed curve J, also called a Jordan curve, is the image >> > of a continuous one-to-one function from R/Z to R2. We assume that >> > each curve >> > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z >> > the time >> > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j >> > (t), using the >> > same notation for the function phi_J and its image J." >> >> > Close to sounding like he can't decide whether J is a set or a >> > function... >> >> On the contrary, I find this definition to be written with some care. > >I find the usage of image slightly ambiguous (as it suggests the image >set defines the curve), but that's my only qualm with it as well. > >Thinking pragmatically, you can't have non-simple curves unless you >use multisets, and you also completely lose the notion of curve >orientation and even continuity without making it a poset. At this >point in time, parsimony says that you want to ditch your multiposet >thingie (and God knows what else you want to tack in there to preserve >other interesting curve properties) and really just want to define the >curve as a freaking function and be done with it. Precisely. From ullrich at math.okstate.edu Mon Jun 22 14:16:56 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:16:56 -0500 Subject: Measuring Fractal Dimension ? References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: On Mon, 22 Jun 2009 10:31:26 -0400, Charles Yeomans wrote: > >On Jun 22, 2009, at 8:46 AM, pdpi wrote: > >> On Jun 19, 8:13 pm, Charles Yeomans wrote: >>> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >>> >>> >>> >>> >>> >>> >>>> Hmm. You left out a bit in the first definition you cite: >>> >>>> "A simple closed curve J, also called a Jordan curve, is the image >>>> of a continuous one-to-one function from R/Z to R2. We assume that >>>> each curve >>>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>>> R/Z >>>> the time >>>> parameter. By abuse of notation, we write J(t) in R2 instead of >>>> phi_j >>>> (t), using the >>>> same notation for the function phi_J and its image J." >>> >>>> Close to sounding like he can't decide whether J is a set or a >>>> function... >>> >>> On the contrary, I find this definition to be written with some care. >> >> I find the usage of image slightly ambiguous (as it suggests the image >> set defines the curve), but that's my only qualm with it as well. >> >> Thinking pragmatically, you can't have non-simple curves unless you >> use multisets, and you also completely lose the notion of curve >> orientation and even continuity without making it a poset. At this >> point in time, parsimony says that you want to ditch your multiposet >> thingie (and God knows what else you want to tack in there to preserve >> other interesting curve properties) and really just want to define the >> curve as a freaking function and be done with it. >> -- > > >But certainly the image set does define the curve, if you want to view >it that way -- all parameterizations of a curve should satisfy the >same equation f(x, y) = 0. This sounds like you didn't read his post, or totally missed the point. Say S is the set of (x,y) in the plane such that x^2 + y^2 = 1. What's the "index", or "winding number", of that curve about the origin? (Hint: The curve c defined by c(t) = (cos(t), sin(t)) for 0 <= t <= 2pi has index 1 about the origin. The curve d(t) = (cos(-t), sin(-t)) (0 <= t <= 2pi) has index -1. The curve (cos(2t), sin(2t)) (same t) has index 2.) >Charles Yeomans From zelegolas at gmail.com Mon Jun 22 14:24:20 2009 From: zelegolas at gmail.com (ZeLegolas) Date: Mon, 22 Jun 2009 14:24:20 -0400 Subject: wikipedia with python In-Reply-To: <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels wrote: > On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >> Let me know if it's the right place to ask. >> >> I'm looking for wiki writen with python where I can import all >> wikipedia site. >> If you have any links please let me know. > > I don't think that's possible. If you wnat to import Wikipedia in a > wiki, it will probably have to be MediaWiki - and that's written in > PHP. > > What do you want to use the material for? Well sorry I was not clear. I have a wiki running with mediawiki and I want to import in a wiki written with python. From jeanmichel at sequans.com Mon Jun 22 14:31:13 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 20:31:13 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4A3FCDF1.4020203@sequans.com> Lie Ryan wrote: > Jean-Michel Pichavant wrote: > > > > >> Maybe I've been a little bit too dictatorial when I was saying that >> renaming namespaces should be avoided. >> Sure your way of doing make sense. In fact they're 2 main purposes of >> having strong coding rules: >> 1/ ease the coder's life >> 2/ ease the reader's life >> >> The perfect rule satisfies both of them, but when I have to choose, I >> prefer number 2. Renaming packages, especially those who are world wide >> used, may confuse the reader and force him to browse into more code. >> >> From the OP example, I was just pointing the fact that **he alone** >> gains 3 characters when **all** the readers need to ask what means "np". >> Renaming namespaces with a well chosen name (meaningful) is harmless. >> > > As long as you keep all import statements at the head of the file, there > is no readability problems with renaming namespace. > > Glance at the header file, see: > import numpy as np > > and it's not hard to mentally switch np as numpy... > > well, as long as your header doesn't look like this: > import numpy as np > import itertools as it > import Tkinter as Tk > from time import time as t > yep, your example is good, no namespace renaming ... :o) I would gladly accept the following renaming: import theMostEfficientPythonPackageInTheWorld as meppw Hopefully, package names are often usable as provided. Moreover, writing numpy instead of np is not harder for the coder than switching mentally from np to numpy for the reader. It's just about who you want to make the life easier, the coder or the reader ? br Jean-Michel From ullrich at math.okstate.edu Mon Jun 22 14:43:19 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:43:19 -0500 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> Message-ID: <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> On Fri, 19 Jun 2009 12:40:36 -0700 (PDT), Mark Dickinson wrote: >On Jun 19, 7:43?pm, David C. Ullrich wrote: >> Evidently my posts are appearing, since I see replies. >> I guess the question of why I don't see the posts themselves >> \is ot here... > >Judging by this thread, I'm not sure that much is off-topic >here. :-) > >> Perhaps not. I'm very surprised to see those definitions; I've >> been a mathematician for 25 years and I've never seen a >> curve defined a subset of the plane. > >That in turn surprises me. I've taught multivariable >calculus courses from at least three different texts >in three different US universities, and as far as I >recall a 'curve' was always thought of as a subset of >R^2 or R^3 in those courses (though not always with >explicit definitions, since that would be too much >to hope for with that sort of text). Here's Stewart's >'Calculus', p658: > >"Examples 2 and 3 show that different sets of parametric >equations can represent the same curve. Thus we >distinguish between a *curve*, which is a set of points, >and a *parametric curve*, in which the points are >traced in a particular way." > >Again as far as I remember, the rest of the language >in those courses (e.g., 'level curve', 'curve as the >intersection of two surfaces') involves thinking >of curves as subsets of R^2 or R^3. Certainly >I'll agree that it's then necessary to parameterize >the curve before being able to do anything useful >with it. > >[Standard question when teaching multivariable >calculus: "Okay, so we've got a curve. What's >the first thing we do with it?" Answer, shouted >out from all the (awake) students: "PARAMETERIZE IT!" >(And then calculate its length/integrate the >given vector field along it/etc.) >Those were the days...] Surely you don't say a curve is a subset of the plane and also talk about the integrals of verctor fields over _curves_? This is getting close to the point someone else made, before I had a chance to: We need a parametriztion of that subset of the plane before we can do most interesting things with it. The parametrization determines the set, but the set does not determine the parametrization (not even "up to" some sort of isomorphism; the set does not determine multiplicity, orientation, etc.) So if the definition of "curve" is not as I claim then in some sense it _should_ be. Hales defines a curve to be a set C and then says he assumes that there is a parametrization phi_C. Does he ever talk about things like the orientation of a curve a about a point? Seems likely. If so then his use of the word "curve" is simply not consistent with his definition. >A Google Books search even turned up some complex >analysis texts where the word 'curve' is used to >mean a subset of the plane; check out >the book by Ian Stewart and David Orme Tall, >'Complex Analysis: a Hitchhiker's Guide to the >Plane': they distinguish 'curves' (subset of the >complex plane) from 'paths' (functions from a >closed bounded interval to the complex plane). Hmm. I of all people am in no position to judge a book on complex analysis by the silliness if its title... >> "Definition 2. A polygon is a Jordan curve that is a subset of a >> finite union of >> lines. A polygonal path is a continuous function P : [0, 1] ->? R2 >> that is a subset of >> a finite union of lines. It is a polygonal arc, if it is 1 . 1." >> >> By that definition a polygonal path is not a curve. > >Right. I'm much more willing to accept 'path' as standard >terminology for a function [a, b] -> (insert_favourite_space_here). > >> Not that it matters, but his defintion of "polygonal path" >> is, _if_ we're being very careful, self-contradictory. > >Agreed. Surprising, coming from Hales; he must surely rank >amongst the more careful mathematicians out there. > >> So I don't think we can count that paper as a suitable >> reference for what the _standard_ definitions are; >> the standard definitions are not self-contradictory this way. > >I just don't believe there's any such thing as >'the standard definition' of a curve. I'm happy >to believe that in complex analysis and differential >geometry it's common to define a curve to be a >function. But in general I'd suggest that it's one >of those terms that largely depends on context, and >should be defined clearly when it's not totally >obvious from the context which definition is >intended. For example, for me, more often than not, >a curve is a 1-dimensional scheme over a field k >(usually *not* algebraically closed), that's at >least some of {geometrically reduced, geometrically >irreducible, proper, smooth}. That's a far cry either >from a subset of an affine space or from a >parametrization by an interval. Ok. >> Then the second definition you cite: Amazon says the >> prerequisites are two years of calculus. The stanard >> meaning of log is log base e, even though means >> log base 10 in calculus. > >Sorry, I've lost context for this comment. Why >are logs relevant? (I'm very well aware of the >debates over the meaning of log, having frequently >had to help students 'unlearn' their "log=log10" >mindset when starting a first post-calculus course). The point is that a calculus class is not mathematics. In my universe the standard definition of "log" is different froim what log means in a calculus class, and my point was that a definition of "curve" in a book that specifies it's supposed to be accessible to calculus students doesn't seem to me like much evidence regarding the standard definition in mathematics. >Mark From cgoldberg at gmail.com Mon Jun 22 14:50:19 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Mon, 22 Jun 2009 11:50:19 -0700 (PDT) Subject: Graphical library - charts References: <4a3fb8f7$0$95510$742ec2ed@news.sonic.net> Message-ID: <90cbb6a6-e814-478e-b1e2-c1252b8bfbe7@r3g2000vbp.googlegroups.com> > I suggest you look at matplotlib. +1 Another vote Matplotlib. It has impressive graphing/plotting capabilities and is used as a Python module/library. Description from site: "matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala matlab or mathematica), web application servers, and six graphical user interface toolkits." http://matplotlib.sourceforge.net/ -Corey Goldberg From chris at simplistix.co.uk Mon Jun 22 14:55:12 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 22 Jun 2009 19:55:12 +0100 Subject: Help In-Reply-To: References: Message-ID: <4A3FD390.3060409@simplistix.co.uk> tanner barnes wrote: > Hi i was wondering how i should go about this problem: ok so i am > writing a program for my school's football team and to keep the stats > for each player there is a notebook with 3 tabs that has a txtctrl and a > + and - button. i need to find a way to when you click the + or - button > it updates that stat for that individual player. We are not mind readers ;-) What version of Python are you using? What GUI framework are you using? Is there anywhere we can see your existing code? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From andreengels at gmail.com Mon Jun 22 15:01:16 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 22 Jun 2009 21:01:16 +0200 Subject: wikipedia with python In-Reply-To: <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> Message-ID: <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> On Mon, Jun 22, 2009 at 8:24 PM, ZeLegolas wrote: > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. I don't think it will work, but you could try using the Special:Export page. -- Andr? Engels, andreengels at gmail.com From zelegolas at gmail.com Mon Jun 22 15:07:47 2009 From: zelegolas at gmail.com (ZeLegolas) Date: Mon, 22 Jun 2009 15:07:47 -0400 Subject: wikipedia with python In-Reply-To: <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> Message-ID: On Mon, 22 Jun 2009 21:01:16 +0200, Andre Engels wrote: > On Mon, Jun 22, 2009 at 8:24 PM, ZeLegolas wrote: > >> Well sorry I was not clear. I have a wiki running with mediawiki and I >> want >> to import in a wiki written with python. > > I don't think it will work, but you could try using the Special:Export > page. Thanks I will try. :) I don't choose the wiki base on python yet. Do you know one similar to mediawiki or what is the best wiki that you know? From robert.kern at gmail.com Mon Jun 22 15:11:49 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 22 Jun 2009 14:11:49 -0500 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3FCDF1.4020203@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> <4A3FCDF1.4020203@sequans.com> Message-ID: On 2009-06-22 13:31, Jean-Michel Pichavant wrote: > Moreover, writing numpy instead of np is not harder for the coder than > switching mentally from np to numpy for the reader. It's just about who > you want to make the life easier, the coder or the reader ? It depends on the audience. For those familiar with numpy and the np convention, it's easier to read code that uses np because there are many lines with several numpy functions called in each. -- 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 greyna at socal.rr.com Mon Jun 22 15:13:10 2009 From: greyna at socal.rr.com (Greg Reyna) Date: Mon, 22 Jun 2009 12:13:10 -0700 Subject: Procedures Message-ID: Learning Python (on a Mac), with the massive help of Mark Lutz's excellent book, "Learning Python". What I want to do is this: I've got a Class Object that begins with a def. It's designed to be fed a string that looks like this: "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," I'm parsing the string by finding the commas, and pulling out the data between them. No problem so far (I think...) The trouble is, there is a place where code is repeated: 1. Resetting the start & end position and finding the next comma in the string. In my previous experience (with a non-OOP language), I could create a 'procedure', which was a separate function. With a call like: var=CallProcedure(arg1,arg2) the flow control would go to the procedure, run, then Return back to the main function. In Python, when I create a second def in the same file as the first it receives a "undefined" error. I can't figure out how to deal with this. How do I set it up to have my function #1 call my function #2, and return? The only programming experience I've had where I pretty much knew what I was doing was with ARexx on the Amiga, a language much like Python without the OOP part. ARexx had a single-step debugger as part of the language installation. I've always depended on a debugger to help me understand what I'm doing (eg Script Debugger for Apple Script--not that I understand Apple Script) Python's debug system is largely confusing to me, but of course I'll keep at it. I would love to see a step-by-step debugging tutorial designed for someone like me who usually wants to single-step through an entire script. Thanks for any help, Greg Reyna From Scott.Daniels at Acm.Org Mon Jun 22 15:14:10 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Jun 2009 12:14:10 -0700 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> Chris Jones wrote: > .... Maybe I'm nitpicking, but the one thing I don't understand is how you > practice programming. > > The term makes obvious sense when you're talking about your golf swing, > acquiring competitive driving skills, playing tetris.. > > But programming..?? It is practice in the same way as learning to write well requires practice. Writing good code is a writing skill, as well as a precision of thought exercise. The basics of Computer Science are well-covered in TAOCP Volumes 1-5 (not all yet available in stores :-). You _must know data structures and fundamental algorithms, but after that what you write is a way of expressing clearly what you learn in a field. The field may be as narrow as "the field of Ink-Jet Printer automated testing for models XXX through XYZ of manufacturer Z," but in some sense the programs should clearly expr4ess that knowledge. If you read books on learning to write clearly, even if they are oriented to (non-fiction) writing in English, none of them advocate intensive study of a theory with little practice. You can follow the advice in those books (with a "loose" interpretation of the instructions) and improve your code. What the best teach you is be succinct, clear, unambiguous, and try new things regularly. It is only this variation that can help you get better. Read what others write about how to write code, but remember you will have your own style. Take what others write about how to code as a cook does a recipe: you should be understand what is being attempted, try it the authors way to see what new might surprise you, and carry away only what you find you can incorporate into your own process. How we pull stuff from our brains is as varied as the brains themselves. We bring a host of experiences to our writing, and we should similarly bring that to the programs we write. --Scott David Daniels Scott.Daniels at Acm.Org From dickinsm at gmail.com Mon Jun 22 15:38:51 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 22 Jun 2009 12:38:51 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 22, 7:43?pm, David C. Ullrich wrote: > Surely you don't say a curve is a subset of the plane and > also talk about the integrals of verctor fields over _curves_? > [snip rest of long response that needs a decent reply, but > possibly not here... ] I wonder whether we can find a better place to have this discussion; I think there are still plenty of interesting things to say, but I fear we're rather abusing the hospitality of comp.lang.python at the moment. I'd suggest moving it to sci.math, except that I've seen the noise/signal ratio over there... Mark From saurabh at saurabh.org Mon Jun 22 15:40:03 2009 From: saurabh at saurabh.org (saurabh) Date: 22 Jun 2009 19:40:03 GMT Subject: Open source python projects Message-ID: <4a3fde13$0$48239$14726298@news.sunsite.dk> Hi There, I am an experienced C programmer and recently dived into python, I have developed an instant love for it. I have been doing some routine scripting for day to day admin tasks,also have done some Tkinter and socket programming using python. I am looking for some open source python project preferably in one of the above areas (not strictly, am open to others too) to contribute. Please give me any pointers to some python project which needs a contributor. Thanks Saurabh From Scott.Daniels at Acm.Org Mon Jun 22 16:02:45 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Jun 2009 13:02:45 -0700 Subject: fastest native python database? In-Reply-To: References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > ... Use Python mapping objects. > Most real-world databases will fit in memory anyway. Interesting theory. Certainly true for some definitions of "most" and "real-world" (and "databases" for that matter). --Scott David Daniels Scott.Daniels at Acm.Org From jcd at sdf.lonestar.org Mon Jun 22 16:03:31 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 16:03:31 -0400 Subject: Procedures In-Reply-To: References: Message-ID: <1245701011.2066.20.camel@aalcdl07> On Mon, 2009-06-22 at 12:13 -0700, Greg Reyna wrote: > Learning Python (on a Mac), with the massive help of Mark Lutz's > excellent book, "Learning Python". > > What I want to do is this: > I've got a Class Object that begins with a def. It's designed to be > fed a string that looks like this: > > "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > > I'm parsing the string by finding the commas, and pulling out the > data between them. > No problem so far (I think...) The trouble is, there is a place > where code is repeated: > > 1. Resetting the start & end position and finding the next comma in the string. > Have you looked at the split() method on string objects. It works kind of like this: >>> s = "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," >>> s.split(",") ['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl 4', ' 2+4', ''] >>> elements = s.split(",") >>> elements ['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl 4', ' 2+4', ''] >>> elements[2] ' 3+8' > In my previous experience (with a non-OOP language), I could create a > 'procedure', which was a separate function. With a call like: > var=CallProcedure(arg1,arg2) the flow control would go to the > procedure, run, then Return back to the main function. > Python doesn't have procedures quite like this. It has functions (the things starting with "def"), which generally speaking take arguments and return values. For the most part, you do not want your functions to operate on variables that aren't either defined in the function or passed in as arguments. That leads to difficult-to-debug code. > In Python, when I create a second def in the same file as the first > it receives a "undefined" error. I can't figure out how to deal with > this. How do I set it up to have my function #1 call my function #2, > and return? Your problem description is confusing. First of all, no class starts with 'def'. They all start with 'class'. Perhaps you are talking about a module (a python file)? Also, telling us that you get an undefined error is not particularly helpful. Every Exception that python raises is accompanied by an extensive stack trace which will help you (or us) debug the problem. If you don't show us this information, we can't tell you what's going wrong. It will tell you (in ways that are crystal clear once you have a bit of practice reading them) exactly what went wrong. Can you show your code, as well as the complete error message you are receiving? My suggestions here, are essentially a paraphrasing of Eric Raymond's essay, "How to Ask Smart Questions." It is freely available on the web, and easily found via google. I recommend reading that, in order to get the most mileage out this news group. Cheers, Cliff From coldtortuga at gmail.com Mon Jun 22 16:08:16 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Mon, 22 Jun 2009 13:08:16 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 11, 6:23?pm, Mensanator wrote: > Removing the duplicates could be a big problem. It is fairly easy to ignore duplicates in a sorted list:
from itertools import groupby
def unique(ordered):
    """Yield the unique elements from a sorted iterable.
    """
    for key,_ in groupby(ordered):
        yield key
Combining this with some ideas of others, we have a simple, complete solution:
def intersect(*ascendingSeqs):
    """Yield the intersection of zero or more ascending iterables.
    """
    N=len(ascendingSeqs)
    if N==0:
        return

    unq = [unique(s) for s in ascendingSeqs]
    val = [u.next() for u in unq]
    while True:
        for i in range(N):
            while val[i-1] > val[i]:
                val[i] = unq[i].next()
        if val[0]==val[-1]:
            yield val[0]
            val[-1] = unq[-1].next()
This works with empty arg-lists; combinations of empty, infinite and finite iterators; iterators with duplicate elements; etc. The only requirement is that all iterators are sorted ascending. -- FC From gnewsg at gmail.com Mon Jun 22 16:49:17 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 22 Jun 2009 13:49:17 -0700 (PDT) Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: On 22 Giu, 21:40, saurabh wrote: > Hi There, > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. > > Please give me any pointers to some python project which needs a > contributor. > > Thanks > Saurabh If you have experience in C system programming then you could help us with psutil: http://code.google.com/p/psutil You might want to take a look at our Milestone wiki which lists some features we would like to implement: http://code.google.com/p/psutil/wiki/Milestones The platforms we aim to support are: Linux, OS X, Windows and FreeBSD. If you're interested feel free to contact me at [g.rodola -AT- gmail - DOT- com] or use the psutil mailing list: http://groups.google.com/group/psutil --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From philr at aspexconsulting.co.nz Mon Jun 22 16:53:20 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 23 Jun 2009 08:53:20 +1200 Subject: Good books in computer science? In-Reply-To: <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> Message-ID: A big yes to Scott's remarks. The first law of programming is: "Write as you would be written unto". Apologies to Kingsley. Phil -----Original Message----- From: Scott David Daniels [mailto:Scott.Daniels at Acm.Org] Sent: Tuesday, 23 June 2009 7:14 a.m. To: python-list at python.org Subject: Re: Good books in computer science? Chris Jones wrote: > .... Maybe I'm nitpicking, but the one thing I don't understand is how you > practice programming. > > The term makes obvious sense when you're talking about your golf swing, > acquiring competitive driving skills, playing tetris.. > > But programming..?? It is practice in the same way as learning to write well requires practice. Writing good code is a writing skill, as well as a precision of thought exercise. The basics of Computer Science are well-covered in TAOCP Volumes 1-5 (not all yet available in stores :-). You _must know data structures and fundamental algorithms, but after that what you write is a way of expressing clearly what you learn in a field. The field may be as narrow as "the field of Ink-Jet Printer automated testing for models XXX through XYZ of manufacturer Z," but in some sense the programs should clearly expr4ess that knowledge. If you read books on learning to write clearly, even if they are oriented to (non-fiction) writing in English, none of them advocate intensive study of a theory with little practice. You can follow the advice in those books (with a "loose" interpretation of the instructions) and improve your code. What the best teach you is be succinct, clear, unambiguous, and try new things regularly. It is only this variation that can help you get better. Read what others write about how to write code, but remember you will have your own style. Take what others write about how to code as a cook does a recipe: you should be understand what is being attempted, try it the authors way to see what new might surprise you, and carry away only what you find you can incorporate into your own process. How we pull stuff from our brains is as varied as the brains themselves. We bring a host of experiences to our writing, and we should similarly bring that to the programs we write. --Scott David Daniels Scott.Daniels at Acm.Org From charles at declareSub.com Mon Jun 22 17:03:14 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 22 Jun 2009 17:03:14 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: <2060624A-FC8E-4709-81E3-A1B6D346434D@declareSub.com> On Jun 22, 2009, at 2:16 PM, David C. Ullrich wrote: > On Mon, 22 Jun 2009 10:31:26 -0400, Charles Yeomans > wrote: > >> >> On Jun 22, 2009, at 8:46 AM, pdpi wrote: >> >>> On Jun 19, 8:13 pm, Charles Yeomans wrote: >>>> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >>>> >>>> >>>> >>>> >>>> >>>> >>>>> Hmm. You left out a bit in the first definition you cite: >>>> >>>>> "A simple closed curve J, also called a Jordan curve, is the image >>>>> of a continuous one-to-one function from R/Z to R2. We assume that >>>>> each curve >>>>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>>>> R/Z >>>>> the time >>>>> parameter. By abuse of notation, we write J(t) in R2 instead of >>>>> phi_j >>>>> (t), using the >>>>> same notation for the function phi_J and its image J." >>>> >>>>> Close to sounding like he can't decide whether J is a set or a >>>>> function... >>>> >>>> On the contrary, I find this definition to be written with some >>>> care. >>> >>> I find the usage of image slightly ambiguous (as it suggests the >>> image >>> set defines the curve), but that's my only qualm with it as well. >>> >>> Thinking pragmatically, you can't have non-simple curves unless you >>> use multisets, and you also completely lose the notion of curve >>> orientation and even continuity without making it a poset. At this >>> point in time, parsimony says that you want to ditch your multiposet >>> thingie (and God knows what else you want to tack in there to >>> preserve >>> other interesting curve properties) and really just want to define >>> the >>> curve as a freaking function and be done with it. >>> -- >> >> >> But certainly the image set does define the curve, if you want to >> view >> it that way -- all parameterizations of a curve should satisfy the >> same equation f(x, y) = 0. > > This sounds like you didn't read his post, or totally missed the > point. > > Say S is the set of (x,y) in the plane such that x^2 + y^2 = 1. > What's the "index", or "winding number", of that curve about the > origin? > > (Hint: The curve c defined by c(t) = (cos(t), sin(t)) for > 0 <= t <= 2pi has index 1 about the origin. The curve > d(t) = (cos(-t), sin(-t)) (0 <= t <= 2pi) has index -1. > The curve (cos(2t), sin(2t)) (same t) has index 2.) That is to say, the "winding number" is a property of both the curve and a parameterization of it. Or, in other words, the winding number is a property of a function from S1 to C. Charles Yeomans From garabik-news-2005-05 at kassiopeia.juls.savba.sk Mon Jun 22 17:11:26 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Mon, 22 Jun 2009 21:11:26 +0000 (UTC) Subject: wikipedia with python References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: Andre Engels wrote: > On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >> Let me know if it's the right place to ask. >> >> I'm looking for wiki writen with python where I can import all >> wikipedia site. >> If you have any links please let me know. > > I don't think that's possible. If you wnat to import Wikipedia in a > wiki, it will probably have to be MediaWiki - and that's written in > PHP. > MoinMoin has a MediaWiki format parser (or two). Not 100% compatible, but good enough for some purposes. Templates will be a problem, though. -- ----------------------------------------------------------- | 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 cmpython at gmail.com Mon Jun 22 18:25:06 2009 From: cmpython at gmail.com (CM) Date: Mon, 22 Jun 2009 15:25:06 -0700 (PDT) Subject: launch a .py file from a batch file Message-ID: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> I'd like to launch a number of programs, one of which is a Python GUI app, from a batch file launcher. I'd like to click the .bat file and have it open all the stuff and then not show the "DOS" console. I can launch an Excel and Word file fine using, e.g.: Start "" "path/mydocument.doc" But if I try that with a Python file, like: Start "" "path/myPythonApp.py" It does nothing. The others open fine and no Python app. However, if I do this instead (where path = full pathname to Python file), cd path myPythonApp.py it will launch the Python app fine, but it will show the "DOS" console. How can I get it to launch a .py file and yet not show the console? Thanks, Che From 1x7y2z9 at gmail.com Mon Jun 22 18:35:28 2009 From: 1x7y2z9 at gmail.com (1x7y2z9) Date: Mon, 22 Jun 2009 15:35:28 -0700 (PDT) Subject: re.NONE Message-ID: I am currently using python v2.5.2. Not sure if this is defined in a later version, but it would be nice to define re.NONE = 0 in the re module. This would be useful in cases such as: flags = re.DOTALL if dotall else re.NONE Also useful for "building up" flags by ORing with other flags. Thanks. From clp2 at rebertia.com Mon Jun 22 18:51:13 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 15:51:13 -0700 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <50697b2c0906221551y637aee15g7ae563360c9ce18@mail.gmail.com> On Mon, Jun 22, 2009 at 6:17 AM, Jim Qiu wrote: > Hi all, > > I have a object list list this: > I need to output this "structure" object into a file, how to do that ? Links for the modules mentioned: http://docs.python.org/library/pickle.html http://docs.python.org/library/json.html Cheers, Chris -- http://blog.rebertia.com From peter at www.pjb.com.au Mon Jun 22 18:52:29 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 22 Jun 2009 22:52:29 GMT Subject: Idioms and Anti-Idioms Question References: Message-ID: On 2009-06-22, Lie Ryan wrote: > Ben Charrow wrote: >> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ >> + calculate_number(10, 20)*forbulate(500, 360) >> What is subtly wrong about this piece of code? I can't see any bugs and >> can't think of subtle gotchas (e.g. the '\' is removed or the lines >> become separated, because in both cases an IndentationError would be >> raised). > > The preferred style is to put the binary operators before the line-break > (i.e. the line break is after the operators): > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ > calculate_number(10, 20)*forbulate(500, 360) > ... > The following is an extract from PEP 8: > The preferred way of wrapping long lines is by using Python's > implied line continuation inside parentheses, brackets and braces. > If necessary, you can add an extra pair of parentheses around an > expression, but sometimes using a backslash looks better. Make sure to > indent the continued line appropriately. The preferred place to break > around a binary operator is *after* the operator, not before it. Damian Conway, in Perl Best Practices, puts forward a clear argument for breaking *before* the operator: Using an expression at the end of a statement gets too long, it's common practice to break that expression after an operator and then continue the expression on the following line ... The rationale is that the operator that remains at the end of the line acts like a continutation marker, indicating that the expression continues on the following line. Using the operator as a continutation marker seems like an excellent idea, but there's a serious problem with it: people rarely look at the right edge of code. Most of the semantic hints in a program - such as keywords - appear on the left side of that code. More importantly, the structural cues for understanding code - for example, indenting, - are predominantly on the left as well ... This means that indenting the continued lines of the expression actually gives a false impression of the underlying structure, a misperception that the eye must travel all the way to the right margin to correct. which seems to me well-argued. I wonder on what grounds PEP8 says "The preferred place to break around a binary operator is *after* the operator" ? Perhaps it's just the "continutation marker" rationale? Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From skip at pobox.com Mon Jun 22 19:09:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 22 Jun 2009 18:09:06 -0500 Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: <19008.3858.487195.120433@montanaro.dyndns.org> Saurabh> I am looking for some open source python project preferably in Saurabh> one of the above areas (not strictly, am open to others too) to Saurabh> contribute. If you have some Windows programming experience the SpamBayes project (http://www.spambayes.org/) could use some assistance. We have been held up because our existing Windows experts have been too busy to contribute much for a couple years. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From python at bdurham.com Mon Jun 22 19:18:38 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 22 Jun 2009 19:18:38 -0400 Subject: Open source python projects In-Reply-To: <19008.3858.487195.120433@montanaro.dyndns.org> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> <19008.3858.487195.120433@montanaro.dyndns.org> Message-ID: <1245712718.25211.1321657737@webmail.messagingengine.com> Saurabh, 1. The Dabo crew is doing some exciting thing. Might be worth checking out. http://dabodev.com 2. The Py2exe project is also looking for help (and some C experience would be beneficial to this project). http://py2exe.org 3. There's a bunch of encryption code floating around in native Python that would benefit from being recoded as native C modules. Welcome! Malcolm From davea at ieee.org Mon Jun 22 19:22:51 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 19:22:51 -0400 Subject: Procedures In-Reply-To: References: Message-ID: <4A40124B.70400@ieee.org> Greg Reyna wrote: >
Learning > Python (on a Mac), with the massive help of Mark Lutz's excellent > book, "Learning Python". > > What I want to do is this: > I've got a Class Object that begins with a def. It's designed to be > fed a string that looks like this: > > "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > > I'm parsing the string by finding the commas, and pulling out the data > between them. > No problem so far (I think...) The trouble is, there is a place where > code is repeated: > > 1. Resetting the start & end position and finding the next comma in > the string. > > In my previous experience (with a non-OOP language), I could create a > 'procedure', which was a separate function. With a call like: > var=CallProcedure(arg1,arg2) the flow control would go to the > procedure, run, then Return back to the main function. > > In Python, when I create a second def in the same file as the first it > receives a "undefined" error. I can't figure out how to deal with > this. How do I set it up to have my function #1 call my function #2, > and return? > > The only programming experience I've had where I pretty much knew what > I was doing was with ARexx on the Amiga, a language much like Python > without the OOP part. ARexx had a single-step debugger as part of the > language installation. I've always depended on a debugger to help me > understand what I'm doing (eg Script Debugger for Apple Script--not > that I understand Apple Script) Python's debug system is largely > confusing to me, but of course I'll keep at it. I would love to see a > step-by-step debugging tutorial designed for someone like me who > usually wants to single-step through an entire script. > > Thanks for any help, > Greg Reyna > > You should post an example. Otherwise we can just make wild guesses. So for a wild guess, perhaps your question is how an instance method calls another instance method. But to put it briefly, a def inside a class definition does not create a name at global scope, but instead defines a method of that class. Normally, you have to use an object of that class as a prefix to call such a function (with the exception of __init__() for one example). class A(object): def func1(self, parm1, parm2): do some work self.func2(arg1) do some more work def func2(self, parm1): do some common work q = A() q.func1("data1", "data2") Here we use q.func1() to call the func1 method on the q instance of the class. We could also call q.func2() similarly. But I think you may have been asking about func1 calling func2. Notice the use of self.func2(). Self refers to the object of the method we're already in. From noname at nowhere.com Mon Jun 22 19:29:24 2009 From: noname at nowhere.com (Pegasus) Date: Tue, 23 Jun 2009 01:29:24 +0200 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: <4a40141d$0$47541$4fafbaef@reader1.news.tin.it> ndPython for Nanodesktop http://www.psp-ita.com/forum/viewtopic.php?t=28323 It shall be the most advanced, professional, reliable Python interpreter for Playstation Portable but there is actually a lack of performance and we are working to identify the origin of the problem. We need help. From noname at nowhere.com Mon Jun 22 19:32:54 2009 From: noname at nowhere.com (Pegasus) Date: Tue, 23 Jun 2009 01:32:54 +0200 Subject: Performance problem in ndPython 2.5.2. Why ? Message-ID: <4a4014d5$0$47539$4fafbaef@reader1.news.tin.it> Hi, I'm working on a version of Stackless Python (2.5.2) for Nanodesktop PSP. The interpreter works, but it is slow. So, I want to ask this: is there any option/#define that I can pass to pyconfig.h that makes faster the interpreter ? Which are the #define that affect the performance of Stackless Python ? Perhaps there is some library that I must include in the interpreter to obtain a boost of performance ? From milesck at umich.edu Mon Jun 22 19:34:40 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Mon, 22 Jun 2009 19:34:40 -0400 Subject: Idioms and Anti-Idioms Question In-Reply-To: <4A3F053A.10208@csail.mit.edu> References: <4A3F053A.10208@csail.mit.edu> Message-ID: On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote: > What is subtly wrong about this piece of code? I can't see any bugs > and can't think of subtle gotchas (e.g. the '\' is removed or the > lines become separated, because in both cases an IndentationError > would be raised). Perhaps, along with one of those gotchas, a mix of tabs and spaces are used such that the second line only _appears_ to have a different level of indentation? ;) -Miles From alan.isaac at gmail.com Mon Jun 22 19:35:20 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 22 Jun 2009 23:35:20 GMT Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: On 6/22/2009 3:40 PM saurabh apparently wrote: > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. A one off project ... If you can help figure out how to produce a Windows installer of SimpleParse for Python 2.6 and post your experience here, I believe quite a few projects would profit, not to mention the SimpleParse users themselves. Cheers, Alan Isaac From python at mrabarnett.plus.com Mon Jun 22 19:43:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2009 00:43:06 +0100 Subject: re.NONE In-Reply-To: References: Message-ID: <4A40170A.9030101@mrabarnett.plus.com> 1x7y2z9 wrote: > I am currently using python v2.5.2. > > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. This would be useful in cases > such as: > flags = re.DOTALL if dotall else re.NONE > > Also useful for "building up" flags by ORing with other flags. > > Thanks. Just use 0. If you want it added then try requesting it at: http://bugs.python.org/ although it might be best to first gauge how much support you have for the suggestion. From contact at xavierho.com Mon Jun 22 19:47:49 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 23 Jun 2009 09:47:49 +1000 Subject: re.NONE In-Reply-To: <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> Message-ID: <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> (arg, MRAB, sorry, wrong address!) Defining None to 0 is a bad idea. You'll have trouble debugging later on. 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, Jun 23, 2009 at 9:43 AM, MRAB wrote: > 1x7y2z9 wrote: > >> I am currently using python v2.5.2. >> >> Not sure if this is defined in a later version, but it would be nice >> to define re.NONE = 0 in the re module. This would be useful in cases >> such as: >> flags = re.DOTALL if dotall else re.NONE >> >> Also useful for "building up" flags by ORing with other flags. >> >> Thanks. >> > > Just use 0. > > If you want it added then try requesting it at: > > http://bugs.python.org/ > > although it might be best to first gauge how much support you have for > the suggestion. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Jun 22 19:55:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 23 Jun 2009 00:55:28 +0100 Subject: re.NONE In-Reply-To: <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> Message-ID: Re-ordered to eliminate the top-posting. On Tue, 23 Jun 2009 00:47:49 +0100, Xavier Ho wrote: > On Tue, Jun 23, 2009 at 9:43 AM, MRAB wrote: > >> 1x7y2z9 wrote: >> >>> I am currently using python v2.5.2. >>> >>> Not sure if this is defined in a later version, but it would be nice >>> to define re.NONE = 0 in the re module. This would be useful in cases >>> such as: >>> flags = re.DOTALL if dotall else re.NONE >>> >>> Also useful for "building up" flags by ORing with other flags. >>> >>> Thanks. >>> >> >> Just use 0. >> >> If you want it added then try requesting it at: >> >> http://bugs.python.org/ >> >> although it might be best to first gauge how much support you have for >> the suggestion. >> > (arg, MRAB, sorry, wrong address!) > > Defining None to 0 is a bad idea. You'll have trouble debugging later on. They aren't talking about None, they're talking about a hypothetical re.NONE to use as a flag to re.match() and the like. There's no issue with defining that to be 0, since it is the correct value! -- Rhodri James *-* Wildebeest Herder to the Masses From contact at xavierho.com Mon Jun 22 20:01:30 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 23 Jun 2009 10:01:30 +1000 Subject: re.NONE In-Reply-To: <2d56febf0906221700p7f8936d7u3c273534b0352772@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> <2d56febf0906221700p7f8936d7u3c273534b0352772@mail.gmail.com> Message-ID: <2d56febf0906221701g77d9d8dbh3d110131d13b1888@mail.gmail.com> Rhodri wrote: They aren't talking about None, they're talking about a hypothetical re.NONE to use as a flag to re.match() and the like. There's no issue with defining that to be 0, since it is the correct value! Ah, I see. That makes more sense. Thanks. :] (... I fail at sending to mailing list for some reason. What happend to the reply-to request? =/) 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 davea at ieee.org Mon Jun 22 20:04:39 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 20:04:39 -0400 Subject: launch a .py file from a batch file In-Reply-To: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> Message-ID: <4A401C17.4050903@ieee.org> CM wrote: > I'd like to launch a number of programs, one of which is a Python GUI > app, from a batch file launcher. I'd like to click the .bat file and > have it open all the stuff and then not show the "DOS" console. > > I can launch an Excel and Word file fine using, e.g.: > Start "" "path/mydocument.doc" > > But if I try that with a Python file, like: > Start "" "path/myPythonApp.py" > > It does nothing. The others open fine and no Python app. > > However, if I do this instead (where path = full pathname to Python > file), > cd path > myPythonApp.py > > it will launch the Python app fine, but it will show the "DOS" > console. > > How can I get it to launch a .py file and yet not show the console? > > Thanks, > Che > > Assuming you're running on Windows XP, try the following line in your batch file: @start path\MyPythonApp.pyw That's of course after you rename your script to a pyw extension. That's associated with pythonw, which doesn't need a command window. Your batch file itself will still display a cmd window while it's running, but it'll finish quickly. This is the same as when using one to start a spreadsheet or whatever. If you cannot change the extension to the correct pyw extension, then try specifying the interpreter explicitly in the start line: @start c:\python26\pythonw.exe path\MyPythonApp.py You may need quotes in either of these cases, if you managed to include spaces in your pathnames. From ldo at geek-central.gen.new_zealand Mon Jun 22 20:56:11 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 12:56:11 +1200 Subject: re.NONE References: Message-ID: In message , 1x7y2z9 wrote: > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. Do so: re.NONE = 0 Problem solved. From bluefisher80 at gmail.com Mon Jun 22 21:38:51 2009 From: bluefisher80 at gmail.com (=?utf-8?B?Ymx1ZWZpc2hlcjgw?=) Date: Tue, 23 Jun 2009 09:38:51 +0800 Subject: =?utf-8?B?UmU6IFJlOiBIb3cgdG8gb3V0cHV0IGEgY29tcGxleCBMaXN0IG9iamVjdCB0byBhIGZpbGUu?= References: , <50697b2c0906221551y637aee15g7ae563360c9ce18@mail.gmail.com> Message-ID: <200906230938498438339@gmail.com> Let me get my question more clear, I want like the "structure" object printed into another python source file, which i will use in other program. The pickled format or even JSONed format does not fullfil my requirement, does it? Do i make it clear, I still need your guides. Jim Detail step: # #this object is constructed in A.py structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] ## #Then I need some code to output the exactly same structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] # Into second file B.py B.py will be a file of another application. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluefisher80 at gmail.com Mon Jun 22 21:51:54 2009 From: bluefisher80 at gmail.com (bluefisher80) Date: Tue, 23 Jun 2009 09:51:54 +0800 Subject: How to output a complex List object to a file. References: , <1245680239.22057.25.camel@aalcdl07> Message-ID: <200906230951525317160@gmail.com> Actually I think i am just looking for print >> myFile.py, myListObj 2009-06-23 bluefisher80 ???? J. Cliff Dyer ????? 2009-06-22 22:17:12 ???? Jim Qiu ??? python-list ??? Re: How to output a complex List object to a file. Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, > {ID:'NAD',MIN:1,MAX:5,LEVEL:[ > {ID:'CTA',MIN:0,MAX:5,LEVEL:[ > {ID:'COM',MIN:0,MAX:5}, > ]}, > ]}, > {ID:'RFF',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'CUX',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ > {ID:'PIA',MIN:0,MAX:5}, > {ID:'IMD',MIN:0,MAX:5}, > {ID:'RFF',MIN:0,MAX:5}, > {ID:'ALI',MIN:0,MAX:5}, > {ID:'MOA',MIN:0,MAX:5}, > {ID:'PRI',MIN:0,MAX:5}, > {ID:'QTY',MIN:0,MAX:999,LEVEL:[ > {ID:'NAD',MIN:0,MAX:1}, > ]}, > ]}, > ]}, > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? > > Jim > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jun 22 21:55:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 18:55:41 -0700 Subject: How to output a complex List object to a file. In-Reply-To: <200906230951525317160@gmail.com> References: <1245680239.22057.25.camel@aalcdl07> <200906230951525317160@gmail.com> Message-ID: <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> 2009/6/22 bluefisher80 : > > Actually I think i am just looking for > > print >> myFile.py, myListObj Well, that syntax is deprecated. And you'd have to create the actual file object. And put it in a variable. So it's more like: f = file("myFile.py", "w") f.write(str(myListObj)) f.close() However, the fact that you want to do this suggests a code smell. Why do you need to do this in the first place? Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Mon Jun 22 22:11:49 2009 From: cmpython at gmail.com (C M) Date: Mon, 22 Jun 2009 22:11:49 -0400 Subject: launch a .py file from a batch file In-Reply-To: <4A401C17.4050903@ieee.org> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: On Mon, Jun 22, 2009 at 8:04 PM, Dave Angel wrote: > CM wrote: > >> I'd like to launch a number of programs, one of which is a Python GUI >> app, from a batch file launcher. I'd like to click the .bat file and >> have it open all the stuff and then not show the "DOS" console. >> >> I can launch an Excel and Word file fine using, e.g.: >> Start "" "path/mydocument.doc" >> >> But if I try that with a Python file, like: >> Start "" "path/myPythonApp.py" >> >> It does nothing. The others open fine and no Python app. >> >> However, if I do this instead (where path = full pathname to Python >> file), >> cd path >> myPythonApp.py >> >> it will launch the Python app fine, but it will show the "DOS" >> console. >> >> How can I get it to launch a .py file and yet not show the console? >> >> Thanks, >> Che >> >> >> > Assuming you're running on Windows XP, try the following line in your batch > file: > @start path\MyPythonApp.pyw > > That's of course after you rename your script to a pyw extension. That's > associated with pythonw, which doesn't need a command window. > Well, I renamed my script to have a .pyw extension, and then ran the line above. Without quotes, it doesn't find it (because I have spaces in the path). With quotes it just opens a console and does nothing (does not launch the app). Any ideas? Thanks. Che > > Your batch file itself will still display a cmd window while it's running, > but it'll finish quickly. This is the same as when using one to start a > spreadsheet or whatever. > > If you cannot change the extension to the correct pyw extension, then try > specifying the interpreter explicitly in the start line: > > @start c:\python26\pythonw.exe path\MyPythonApp.py > > You may need quotes in either of these cases, if you managed to include > spaces in your pathnames. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluefisher80 at gmail.com Mon Jun 22 22:31:45 2009 From: bluefisher80 at gmail.com (=?utf-8?B?Ymx1ZWZpc2hlcjgw?=) Date: Tue, 23 Jun 2009 10:31:45 +0800 Subject: =?utf-8?B?UmU6IFJlOiBSZTogSG93IHRvIG91dHB1dCBhIGNvbXBsZXggTGlzdCBvYmplY3QgdG8gYSBmaWxlLg==?= References: , <1245680239.22057.25.camel@aalcdl07>, <200906230951525317160@gmail.com>, <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> Message-ID: <200906231031415155616@gmail.com> Hi Thanks for you tip, I am generating some code for another python application, so is there a better way for code generating? Actually i just need to generate some list objects to define EDI syntax using python. 2009-06-23 bluefisher80 ???? Chris Rebert ????? 2009-06-23 09:55:41 ???? bluefisher80 ??? J. Cliff Dyer; python-list ??? Re: Re: How to output a complex List object to a file. 2009/6/22 bluefisher80 : > > Actually I think i am just looking for > > print >> myFile.py, myListObj Well, that syntax is deprecated. And you'd have to create the actual file object. And put it in a variable. So it's more like: f = file("myFile.py", "w") f.write(str(myListObj)) f.close() However, the fact that you want to do this suggests a code smell. Why do you need to do this in the first place? Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From Andras.Pikler at students.olin.edu Mon Jun 22 22:49:48 2009 From: Andras.Pikler at students.olin.edu (Andras Pikler) Date: Mon, 22 Jun 2009 22:49:48 -0400 Subject: Converting Python code to C/C++ Message-ID: Hi! Short: I need to turn a Python program that I (mostly) wrote into C code, and I am at a loss. Long: I'm doing research/programming for a professor, and we are working with MIDI files (a type of simple music file). The research deals with generating variations from a musical melody; currently, my Python code uses a Python midi package I found online to read the notes in question from a midi file, about 350 lines of my own code to generate a variation based on these notes and the professor's algorithms, and finally the package again to write the new melody to another midi file. Now, my professor would like to have this exact code in C/C++, as she believes C is more compatible with MATLAB, and wants the code to be available in multiple languages in case a programmer works for her in the future who knows C but not Python. While I know a tiny bit of C (emphasis on the tiny), I would much prefer if there were some sort of automatic compiler I could use to turn my Python code into C than taking a week or two or three to learn the minimum I need about C, find a way to access MIDI files in it, and rewrite all of my code. After some googling, I found and tried Shedskin, but it doesn't work, as the Python midi package I'm using uses modules which Shedskin does not support. Otherwise, I haven't found much. Is there anything out there to help me do this? If not, from anyone who has experience in this regard, how daunting should I expect this to be? Any help is appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 22:52:59 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Jun 2009 02:52:59 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > In my universe the standard definition of "log" is different froim what > log means in a calculus class Now I'm curious what the difference is. -- Steven From jfabiani at yolo.com Mon Jun 22 22:56:54 2009 From: jfabiani at yolo.com (John Fabiani) Date: Mon, 22 Jun 2009 19:56:54 -0700 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> <19008.3858.487195.120433@montanaro.dyndns.org> Message-ID: python at bdurham.com wrote: > Saurabh, > > 1. The Dabo crew is doing some exciting thing. Might be worth checking > out. > http://dabodev.com yes Dabo is doing a lot these days. Using wxPython for the GUI, a fast interface for data supporting SQLite, MySQL,Postgres, Firebird, MsSQL and Now a web like program that supports the code from Dabo projects over the web. The report writer has had many improvements recently. People from everywhere are joining in - very cool. From magawake at gmail.com Mon Jun 22 23:17:22 2009 From: magawake at gmail.com (Mag Gam) Date: Mon, 22 Jun 2009 23:17:22 -0400 Subject: Reading a large csv file Message-ID: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Hello All, I have a very large csv file 14G and I am planning to move all of my data to hdf5. I am using h5py to load the data. The biggest problem I am having is, I am putting the entire file into memory and then creating a dataset from it. This is very inefficient and it takes over 4 hours to create the hdf5 file. The csv file has various types: int4, int4, str, str, str, str, str I was wondering if anyone knows of any techniques to load this file faster? TIA From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 23:42:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Jun 2009 03:42:29 GMT Subject: Reading a large csv file References: Message-ID: On Mon, 22 Jun 2009 23:17:22 -0400, Mag Gam wrote: > Hello All, > > I have a very large csv file 14G and I am planning to move all of my > data to hdf5. [...] > I was wondering if anyone knows of any techniques to load this file > faster? Faster than what? What are you using to load the file? -- Steven From clp2 at rebertia.com Tue Jun 23 00:17:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 21:17:37 -0700 Subject: How to output a complex List object to a file. In-Reply-To: <200906231031415155616@gmail.com> References: <1245680239.22057.25.camel@aalcdl07> <200906230951525317160@gmail.com> <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> <200906231031415155616@gmail.com> Message-ID: <50697b2c0906222117u1cc4ab31g42c17f629f6840ee@mail.gmail.com> On Mon, Jun 22, 2009 at 7:31 PM, bluefisher80 wrote: > Hi > > Thanks for you tip, > > I am generating some code for another python?application, > > so is there a better way for code generating? Actually i just need to > generate some list objects to define EDI syntax using python. Well, I would say avoid having to generate code in the first place, but if it's unavoidable, then that's essentially how you'd do it. Cheers, Chris -- http://blog.rebertia.com From metolone+gmane at gmail.com Tue Jun 23 00:21:24 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 22 Jun 2009 21:21:24 -0700 Subject: UnicodeDecodeError: problem when path contain folder start withcharacter 'u References: <24146775.post@talk.nabble.com> Message-ID: "aberry" wrote in message news:24146775.post at talk.nabble.com... > > I am facing an error on Unicode decoding of path if it contain a > folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" > 2. >>> unicode(fp, "unicode_escape") > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" > 5. >>> unicode(fp, "unicode_escape") > 6. > 7. Traceback (most recent call last): > 8. File "", line 1, in > 9. unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in > position > 5-9: end of string in escape sequence > 11. >>> > > Not sure whether I am doing something wrong or this is as designed > behavior > . > any help appreciated What is your intent? Below gives a unicode strings with backslashes. No need for unicode_escape here. >>> fp = "C:\\ab\\unil" >>> fp 'C:\\ab\\unil' >>> print fp C:\ab\unil >>> unicode(fp) u'C:\\ab\\unil' >>> print unicode(fp) C:\ab\unil >>> u'C:\\ab\\unil' u'C:\\ab\\unil' >>> print u'C:\\ab\\unil' C:\ab\unil From tkjthingone at gmail.com Tue Jun 23 00:28:05 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Mon, 22 Jun 2009 21:28:05 -0700 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: Do you even HAVE 14 gigs of memory? I can imagine that if the OS needs to start writing to the page file, things are going to slow down. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at al.com.au Tue Jun 23 01:16:41 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 23 Jun 2009 15:16:41 +1000 Subject: square box graph (?) API in python Message-ID: <4A406539.1060904@al.com.au> Hi, I'm trying to graph something that looks like the bottom half of this http://windirstat.info/images/windirstat.jpg I was wondering if there is any API in python or wxPython specifically to do this? I know it is possible to do calculation manually and use floatcanvas or something similar but I was wondering if something like this has already been done. Cheers Astan From astan.chee at al.com.au Tue Jun 23 01:19:12 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 23 Jun 2009 15:19:12 +1000 Subject: square box graph (?) API in python In-Reply-To: <4A406539.1060904@al.com.au> References: <4A406539.1060904@al.com.au> Message-ID: <4A4065D0.2040406@al.com.au> Hi, I'm trying to graph something that looks like the bottom half of this http://windirstat.info/images/windirstat.jpg I was wondering if there is any API in python or wxPython specifically to do this? I know it is possible to do calculation manually and use floatcanvas or something similar but I was wondering if something like this has already been done. Cheers Astan From magawake at gmail.com Tue Jun 23 01:27:03 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 23 Jun 2009 01:27:03 -0400 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Yes, the system has 64Gig of physical memory. What I meant was, is it possible to load to a hdf5 dataformat (basically NumPy array) without reading the entire file at first? I would like to splay to disk beforehand so it would be a bit faster instead of having 2 copies in memory. On Tue, Jun 23, 2009 at 12:28 AM, Horace Blegg wrote: > Do you even HAVE 14 gigs of memory? I can imagine that if the OS needs to > start writing to the page file, things are going to slow down. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From __peter__ at web.de Tue Jun 23 02:47:43 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Jun 2009 08:47:43 +0200 Subject: Reading a large csv file References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: Mag Gam wrote: > Yes, the system has 64Gig of physical memory. > > > What I meant was, is it possible to load to a hdf5 dataformat > (basically NumPy array) without reading the entire file at first? I > would like to splay to disk beforehand so it would be a bit faster > instead of having 2 copies in memory. It is certainly possible to read a csv file one line at a time. What exactly are you doing to convert it into hdf5? Showing some of your code might help. Peter From tjreedy at udel.edu Tue Jun 23 03:09:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Jun 2009 03:09:58 -0400 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Message-ID: Mag Gam wrote: > Yes, the system has 64Gig of physical memory. drool ;-). > What I meant was, is it possible to load to a hdf5 dataformat > (basically NumPy array) without reading the entire file at first? I > would like to splay to disk beforehand so it would be a bit faster > instead of having 2 copies in memory. If you can write hdf5 a line at a time, you should be able to something like for line in cvs: process line write hdf5 line this assumes 1-1 lines. From dickinsm at gmail.com Tue Jun 23 03:19:50 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 23 Jun 2009 00:19:50 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 23, 3:52?am, Steven D'Aprano wrote: > On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > > In my universe the standard definition of "log" is different froim what > > log means in a calculus class > > Now I'm curious what the difference is. It's just the usual argument about whether 'log' means log base 10 or log base e (natural log). At least in the US, most[*] calculus texts (and also most calculators), for reasons best known to themselves, use 'ln' to mean natural log and 'log' to mean log base 10. But most mathematicians use 'log' to mean natural log: pick up a random pure mathematics research paper that has the word 'log' in it, and unless it's otherwise qualified, it's safe to assume that it means log base e. (Except in the context of algorithmic complexity, where it might well mean log base 2 instead...) Python also suffers a bit from this confusion: the Decimal class defines methods 'ln' and 'log10', while the math module and cmath modules define 'log' and 'log10'. (But the Decimal module has other problems, like claiming that 0**0 is undefined while infinity**0 is 1.) [*] A notable exception is Michael Spivak's 'Calculus', which also happens to be the book I learnt calculus from many years ago. Mark From eric.brunel at nospam-pragmadev.com Tue Jun 23 03:50:07 2009 From: eric.brunel at nospam-pragmadev.com (Eric Brunel) Date: 23 Jun 2009 07:50:07 GMT Subject: GNUstep and Python References: <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <7a7l9kF1tv7viU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Paul Watson schrieb: >> Has anyone used GNUstep? >> >> In addition to Objective-C, there are Java and Ruby bindings. >> >> Has anyone created a Python binding to GNUstep? > > There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. Apparently, it's not: There was some compatibility in earlier versions, but it's been officially removed in version 2.0. See http://pyobjc.sourceforge.net/NEWS-2.0.html : "GNUstep support has been removed because this has never worked properly, nobody seems interested in fixing that and the internal APIs of PyObjC have changed greatly." I'd love to see that happen, but GNUStep seems to be disappearing little by little. Too bad... From michael at stroeder.com Tue Jun 23 04:59:55 2009 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Tue, 23 Jun 2009 10:59:55 +0200 Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: saurabh wrote: > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. > > Please give me any pointers to some python project which needs a > contributor. I'm sure there are many projects which could need a helping hand. But instead of pointing you to a specific project I'd rather recommend that you contribute to projects you're using for your own daily work. Why? Because you simply know what's really needed if you deploy a software yourself. Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com From p.f.moore at gmail.com Tue Jun 23 05:30:25 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 23 Jun 2009 10:30:25 +0100 Subject: launch a .py file from a batch file In-Reply-To: References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> 2009/6/23 C M : >> Assuming you're running on Windows XP, try the following line in your >> batch file: >> @start path\MyPythonApp.pyw >> >> That's of course after you rename your script to a pyw extension. ?That's >> associated with pythonw, which doesn't need a command window. > > Well, I renamed my script to have a .pyw extension, and then ran the line > above.? Without quotes, it doesn't find it (because I have spaces in the > path). > With quotes it just opens a console and does nothing (does not launch the > app). > > Any ideas? Use @start "" "path\MyPythonApp.pyw" The first item in quotes is the window title. If you only include the path (in quotes) it's taken as a title, which is why you need the second set of quotes. Paul. From girish.cfc at gmail.com Tue Jun 23 06:45:59 2009 From: girish.cfc at gmail.com (Girish) Date: Tue, 23 Jun 2009 03:45:59 -0700 (PDT) Subject: Error in reg dll References: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Message-ID: <3b719cd0-5487-4711-b3ee-a148900f2683@d25g2000prn.googlegroups.com> Hi, somehow I fixed the issue related to error code 0xc0000005. Now I am getting a different error code while registering DLL.. it says: "DllRegisrerServer in Dspacvce.dll Failed. Reyurn Code was: 0x80040201" On Jun 20, 8:15?am, "Gabriel Genellina" wrote: > En Tue, 16 Jun 2009 02:09:57 -0300,Girish escribi?: > > > I am not able to registerDLLgenerated from py2exe > > When I try to register thedllusing the commant: regsve32 dspace.dll, > > I am getting error saying :"DLLRegisterServer in dspace.dllfailed. > > Return code was: 0xc0000005" > > I don't think the problem is in your setup.py, but on Dspace.py or any ? > module it uses. 0xc0000005 is an Access Violation - an attempt to ? > read/write memory at an illegal address. > Try removing pieces from Dspace.py until you find the culprit. > > -- > Gabriel Genellina From bieffe62 at gmail.com Tue Jun 23 06:59:32 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 03:59:32 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? Message-ID: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Hi all, is there any site that reports the current porting (to Python 3.x) status of the main non-standard extension modules (such as pygtk, pywin32, wxpython, ...) ? I think such information would be very useful for people - like me - which are tryiing to decide how/when/if to port existing scripts/ applications to the new python, or also which python to use to start a new program. I searched and googled for this information but without finding anything. It looks to me that also the single extension module sites are quite shy at announcing plans for the porting (I understand that in part this is for the "is ready when is ready" philosophy of many non-large open software projects). Ciao ----- FB From ldo at geek-central.gen.new_zealand Tue Jun 23 07:16:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 23:16:42 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Peter Billam wrote: > Damian Conway, in Perl Best Practices, puts forward a clear argument > for breaking *before* the operator: Except in JavaScript, where you have no choice. From aberry at aol.in Tue Jun 23 07:32:08 2009 From: aberry at aol.in (aberry) Date: Tue, 23 Jun 2009 04:32:08 -0700 (PDT) Subject: UnicodeDecodeError: problem when path contain folder start withcharacter 'u In-Reply-To: References: <24146775.post@talk.nabble.com> Message-ID: <24164207.post@talk.nabble.com> thanks all for help... actually this was in old code having 'unicode_escape' . i hope it was there to handle path which may contain localized chars... but removing unicode_escape' it worked fine... :) rgds, aberry Mark Tolonen-3 wrote: > > > "aberry" wrote in message > news:24146775.post at talk.nabble.com... >> >> I am facing an error on Unicode decoding of path if it contain a >> folder/file >> name starting with character 'u' . >> >> Here is what I did in IDLE >> 1. >>> fp = "C:\\ab\\anil" >> 2. >>> unicode(fp, "unicode_escape") >> 3. u'C:\x07b\x07nil' >> 4. >>> fp = "C:\\ab\\unil" >> 5. >>> unicode(fp, "unicode_escape") >> 6. >> 7. Traceback (most recent call last): >> 8. File "", line 1, in >> 9. unicode(fp, "unicode_escape") >> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in >> position >> 5-9: end of string in escape sequence >> 11. >>> >> >> Not sure whether I am doing something wrong or this is as designed >> behavior >> . >> any help appreciated > > What is your intent? Below gives a unicode strings with backslashes. No > need for unicode_escape here. > >>>> fp = "C:\\ab\\unil" >>>> fp > 'C:\\ab\\unil' >>>> print fp > C:\ab\unil >>>> unicode(fp) > u'C:\\ab\\unil' >>>> print unicode(fp) > C:\ab\unil >>>> u'C:\\ab\\unil' > u'C:\\ab\\unil' >>>> print u'C:\\ab\\unil' > C:\ab\unil > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24164207.html Sent from the Python - python-list mailing list archive at Nabble.com. From stephane at harobed.org Tue Jun 23 07:47:42 2009 From: stephane at harobed.org (Klein =?iso-8859-1?q?St=E9phane?=) Date: Tue, 23 Jun 2009 11:47:42 +0000 (UTC) Subject: I look for private Python Index server on my local network... What do you use ? Message-ID: Hi, I wonder what Python Index server (like as pypi.python.org) do you use in your corporation for handle your private python eggs ? I found three solutions : * http://pypi.python.org/pypi/basketweaver/0.1.2-r6 * http://pypi.python.org/pypi/pypi/2005-08-01 * http://pypi.python.org/pypi/EggBasket/0.6.1b Do you know another software ? What do you use ? Thanks for your help, Stephane From jakecjacobson at gmail.com Tue Jun 23 09:17:41 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Tue, 23 Jun 2009 06:17:41 -0700 (PDT) Subject: Authenticating to web service using https and client certificate Message-ID: <8ba5a3e5-a77f-43c5-ae9e-8e8c043bf804@n21g2000vba.googlegroups.com> Hi, I need to post some XML files to a web client that requires a client certificate to authenticate. I have some code that works on posting a multipart form over http but I need to modify it to pass the proper certificate and post the XML file. Is there any example code that will point me in the correct direction? Thanks for your help. From davea at ieee.org Tue Jun 23 09:21:01 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 23 Jun 2009 09:21:01 -0400 Subject: launch a .py file from a batch file In-Reply-To: <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> Message-ID: <4A40D6BD.1070002@ieee.org> Paul Moore wrote: > 2009/6/23 C M : > >>> Assuming you're running on Windows XP, try the following line in your >>> batch file: >>> @start path\MyPythonApp.pyw >>> >>> That's of course after you rename your script to a pyw extension. That's >>> associated with pythonw, which doesn't need a command window. >>> >> Well, I renamed my script to have a .pyw extension, and then ran the line >> above. Without quotes, it doesn't find it (because I have spaces in the >> path). >> With quotes it just opens a console and does nothing (does not launch the >> app). >> >> Any ideas? >> > > Use > > @start "" "path\MyPythonApp.pyw" > > The first item in quotes is the window title. If you only include the > path (in quotes) it's taken as a title, which is why you need the > second set of quotes. > > Paul. > > CM - Paul is right. If you have to use quotes, then you also need the extra argument to hold the "title" for the command window that won't be created. Stupid syntax on "Start.exe". I seldom hit that because I try not to put anything in a directory with spaces in it, like "Program Files" or "Documents and Settings" I have uncovered dozens of bugs in other people's programs over the years that were triggered by spaces in the pathname. It's not so bad now, but still can bite you. From rolf.wester at ilt.fraunhofer.de Tue Jun 23 09:51:48 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Tue, 23 Jun 2009 15:51:48 +0200 Subject: C-extension 2 times slower than exe Message-ID: <4a40ddee$1@news.fhg.de> Hi, I have a C++ program that I would like to steer using Python. I made the wrapper using swig and linked the code (without the main function) into a shared object. My Python script loads the extension and calls a function of the C-extension, the rest runs entirely within the C-extension. For comparison I compiled the code including the main function with the same compilation options and linked all into an exe. The main function of the exe calls the same function as my Python script does. Surprisingly the code in the Python C-extension runs twice as long as the same code in the exe. Does anyone know what could be the reason for this behaviour? Thank you in advance Rolf From philip at semanchuk.com Tue Jun 23 10:06:53 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 10:06:53 -0400 Subject: C-extension 2 times slower than exe In-Reply-To: <4a40ddee$1@news.fhg.de> References: <4a40ddee$1@news.fhg.de> Message-ID: On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > Hi, > > I have a C++ program that I would like to steer using Python. I made > the > wrapper using swig and linked the code (without the main function) > into > a shared object. My Python script loads the extension and calls a > function of the C-extension, the rest runs entirely within the > C-extension. For comparison I compiled the code including the main > function with the same compilation options and linked all into an exe. > The main function of the exe calls the same function as my Python > script > does. Surprisingly the code in the Python C-extension runs twice as > long > as the same code in the exe. Does anyone know what could be the reason > for this behaviour? If the runtime of the C/C++ code is short, the time spent initializing the Python interpreter might have a big impact on the runtime of the Python version. From rolf.wester at ilt.fraunhofer.de Tue Jun 23 10:20:44 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Tue, 23 Jun 2009 16:20:44 +0200 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> Message-ID: <4a40e4b6$1@news.fhg.de> Philip Semanchuk wrote: > > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > >> Hi, >> >> I have a C++ program that I would like to steer using Python. I made the >> wrapper using swig and linked the code (without the main function) into >> a shared object. My Python script loads the extension and calls a >> function of the C-extension, the rest runs entirely within the >> C-extension. For comparison I compiled the code including the main >> function with the same compilation options and linked all into an exe. >> The main function of the exe calls the same function as my Python script >> does. Surprisingly the code in the Python C-extension runs twice as long >> as the same code in the exe. Does anyone know what could be the reason >> for this behaviour? > > If the runtime of the C/C++ code is short, the time spent initializing > the Python interpreter might have a big impact on the runtime of the > Python version. > > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use the time command to measure the time consumed but I also measure the time within the C-code using clock() and get similar result. So the Python startup time is not the reason for the runtime difference I found. Thank you anyway. Rolf From metolone+gmane at gmail.com Tue Jun 23 10:27:41 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 23 Jun 2009 07:27:41 -0700 Subject: UnicodeDecodeError: problem when path contain folder startwithcharacter 'u References: <24146775.post@talk.nabble.com> <24164207.post@talk.nabble.com> Message-ID: "aberry" wrote in message news:24164207.post at talk.nabble.com... > Mark Tolonen-3 wrote: >> "aberry" wrote in message >> news:24146775.post at talk.nabble.com... >>> >>> I am facing an error on Unicode decoding of path if it contain a >>> folder/file >>> name starting with character 'u' . >>> >>> Here is what I did in IDLE >>> 1. >>> fp = "C:\\ab\\anil" >>> 2. >>> unicode(fp, "unicode_escape") >>> 3. u'C:\x07b\x07nil' >>> 4. >>> fp = "C:\\ab\\unil" >>> 5. >>> unicode(fp, "unicode_escape") >>> 6. >>> 7. Traceback (most recent call last): >>> 8. File "", line 1, in >>> 9. unicode(fp, "unicode_escape") >>> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in >>> position >>> 5-9: end of string in escape sequence >>> 11. >>> >>> >>> Not sure whether I am doing something wrong or this is as designed >>> behavior >>> . >>> any help appreciated >> >> What is your intent? Below gives a unicode strings with backslashes. No >> need for unicode_escape here. >> >>>>> fp = "C:\\ab\\unil" >>>>> fp >> 'C:\\ab\\unil' >>>>> print fp >> C:\ab\unil >>>>> unicode(fp) >> u'C:\\ab\\unil' >>>>> print unicode(fp) >> C:\ab\unil >>>>> u'C:\\ab\\unil' >> u'C:\\ab\\unil' >>>>> print u'C:\\ab\\unil' >> C:\ab\unil > > thanks all for help... > actually this was in old code having 'unicode_escape' . > i hope it was there to handle path which may contain localized chars... > > but removing unicode_escape' it worked fine... :) If that was the case, then here's a few other options: >>> print 'c:\\\\abc\\\\unil\\xe4'.decode('unicode_escape') c:\abc\unil? >>> print r'c:\\abc\\unil\xe4'.decode('unicode_escape') c:\abc\unil? >>> print u'c:\\abc\u005cunil\u00e4' c:\abc\unil? >>> print ur'c:\abc\u005cunil\u00e4' c:\abc\unil? You can also use forward slashes as another poster mentioned. If you want to display the filenames with the backslashes, os.path.normpath can be used: >>> print os.path.normpath('c:/abc/unil\u00e4'.decode('unicode_escape')) c:\abc\unil? Note you only have to jump through these hoops to generate hard-coded filenames with special characters. If they are already on disk, just read them in with something like os.listdir(u'.'), which generates a list of unicode filenames. -Mark From mwilson at the-wire.com Tue Jun 23 10:29:21 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 23 Jun 2009 10:29:21 -0400 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Lawrence D'Oliveiro wrote: > >>> Ok, now pipe ls to less, take three days to browse through all the >>> filenames to locate the file you want to see. >> >> Sounds like you're approaching the issue with a GUI-centric mentality, >> which is completely hopeless at dealing with this sort of situation. > > Piping the output of ls to less is a GUI-centric mentality? Yeah. The "dump it on the user" idea, or more politely "can't decide anything until the user has seen everything" is evident in the most "characteristic" GUIs. Mel. From jeff at jmcneil.net Tue Jun 23 10:35:18 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 23 Jun 2009 07:35:18 -0700 (PDT) Subject: I look for private Python Index server on my local network... What do you use ? References: Message-ID: On Jun 23, 7:47?am, Klein St?phane wrote: > Hi, > > I wonder what Python Index server (like as pypi.python.org) do you use in > your corporation for handle your private python eggs ? > > I found three solutions : > > *http://pypi.python.org/pypi/basketweaver/0.1.2-r6 > *http://pypi.python.org/pypi/pypi/2005-08-01 > *http://pypi.python.org/pypi/EggBasket/0.6.1b > > Do you know another software ? What do you use ? > > Thanks for your help, > Stephane I've always just created a directory structure laid out by egg name and enabled directory indexing. I've never really had a need for anything more complex and this has always worked well for me. For example: [root at buildslave01 eggs]# pwd /var/www/html/eggs [root at buildslave01 eggs]# [root at buildslave01 eggs]# ls Beaker hostapi.logmgmt Paste SQLAlchemy zope.component [root at buildslave01 eggs]# [root at buildslave01 eggs]# ls Beaker/ Beaker-1.1.2-py2.4.egg Beaker-1.2.1-py2.4.egg [root at buildslave01 eggs]# On this particular system, buildbot drops successfully built eggs into the correct location automatically for testing purposes. HTH, Jeff From cameron.pulsford at gmail.com Tue Jun 23 10:45:33 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Tue, 23 Jun 2009 10:45:33 -0400 Subject: Help with dictionaries and multidimensial lists Message-ID: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Hey all, I have a dictionary that looks like this (small example version) {(1, 2): 0} named a so I can do a[1,2] which returns 0. What I also have is a list of coordinates into a 2 dimensional array that might look like this b = [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Tue Jun 23 10:47:54 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 07:47:54 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: <0f4625ea-5100-4772-8bbc-c28ef9f67565@k8g2000yqn.googlegroups.com> On 23 Giu, 12:59, Francesco Bochicchio wrote: > Hi all, > > is there any site that reports the current porting (to Python 3.x) > status of the main non-standard extension modules (such as pygtk, > pywin32, wxpython, ...) ? > I think such information would be very useful for people - like me - > which are tryiing to decide how/when/if to port existing scripts/ > applications to the new python, or also ?which python to use to start > a new program. > > I searched and googled for this information ?but without finding > anything. It looks to me that also the single extension module sites > are quite shy at announcing plans for the porting (I understand that > in part this is for the "is ready when is ready" philosophy of many > non-large open software projects). > > Ciao > ----- > FB Well, I kept searching and found this at least : http://www.daniweb.com/forums/thread165340.html It lists Qt , BeautfulSoup (with problems) and pywin32 (which I use a lot :-) Another (less famous) module that I use, ply, also supports python3.x Maybe in the near future I can start porting some of my scripts ... Still believe that a central point to keep track of most of extension porting effort would be very useful ... Ciao ---- FB From deets at nospam.web.de Tue Jun 23 10:54:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Jun 2009 16:54:28 +0200 Subject: [Mac] file copy References: Message-ID: <7ac8e0F1tludjU1@mid.uni-berlin.de> Tobias Weber wrote: > Hi, > which is the best way to copy files on OS X? I want to preserve resource > forks and extended attributes. Are these still relevant on OSX? I've always only copied files directly, and never had any troubles. Diez From jcd at sdf.lonestar.org Tue Jun 23 10:59:50 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 23 Jun 2009 10:59:50 -0400 Subject: Procedures In-Reply-To: References: <1245701011.2066.20.camel@aalcdl07> Message-ID: <1245769190.5086.28.camel@aalcdl07> Please keep the discussion on-list. (Reply-all, rather than just replying to me.) On Mon, 2009-06-22 at 15:36 -0700, Greg Reyna wrote: > It's not the error that concerned me. The fact that there is an > error of this type makes clear that there's something wrong with the > way the scripts are structured. I was trying to communicate that I > recognized this fact. Clearly, I was not successful. Thought I'd > try to save bandwidth, too. > ... > I had tried running this previously with only one Class header: > "LineReader", the others were just defs. I changed the short defs > into sub-classes out of desperation, since I don't understand why the > main script is not recognizing functions that are in the same file. > > First is the shell input/output, then "ParseWork.py", the entire text > file that contains the scripts. > > Thanks for your interest, Cliff, > Greg > --- > >>> import ParseWork > >>> avar = ParseWork.LineReader() > >>> xstring = 'scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4,' > >>> avar.parseLine(xstring) > Traceback (most recent call last): > File "", line 1, in > File "ParseWork.py", line 13, in parseLine > xreturn = advanceSearch(xstring) #shorten the part of string to > be searched > NameError: global name 'advanceSearch' is not defined > >>> > --- > class LineReader: > def parseLine(self, xstring): > global sc_info,scnum,pnlnum,prev_pos,cur_pos > sc_info = { 'sc':{0:0}} #dict to store scene num; pnl num(s), ftge > prev_pos = 0 > cur_pos = xstring.find(',') #defaults to length of string > while xstring.find(',',(prev_pos+1)) != -1: > temp = xstring[prev_pos:cur_pos] #pull out the part btwn commas > section = temp.strip() > if section[0:1] == 's': > scnum = int(section[5:]) #get the number(s) off the > end of scene block > sc_info['sc',scnum] = scnum #store scnum-which is > both key and value > xreturn = advanceSearch(xstring) #shorten the part > of string to be searched > continue > if section[0:1] == 'p': > pnlnum = int(section[3:]) > sc_info['sc',scnum,pnlnum] = pnlnum #store pnlnum & > temp value for pnlnum > xreturn = advanceSearch(xstring) #the return value > is to move flow back here > continue > if section[0:1] != 's' or 'p': > xnum = section[0:] #section must contain the footage > if section.find('+'): #the + exists > ftge = parseFtge(section) > sc_info['sc',scnum,pnlnum] = ftge #store ftge in pnlnum > xreturn = advanceSearch(xstring) > continue > else: > ftge = (section/16.0) #section is frames-convert > to decimal > sc_info['sc',scnum,pnlnum] = ftge #store ftge in pnlnum > xreturn = advanceSearch(xstring) > continue > else: > print sc_info > > class ContRead(LineReader): > def advanceSearch(xstring): > prev_pos = (cur_pos +1) > cur_pos = xstring.find(',',prev_pos) #find the next comma > return > > class Footage(LineReader): > def parseFtge(section): > xplus = section.find('+') #find position of '+' > xfeet = int(section[0:xplus]) > xframes = int(section[(xplus + 1):-1]) > xframes_d = (xframes/16.0) > return (xfeet + xframes_d) > > >From what I can see you have no need for classes in your code. This is probably what is causing you trouble at the moment, so I would say just remove them. def parse_line(line): """splits a line on commas""" return line.split(',') def parse_footer(line): """Strips off leading four characters (maybe 'Ftr:'), and then parses the rest as above""" return parse_line([4:]) That should solve your problem. Below I illustrate some of how classes work, in case you are dead set on using them. Learning Python should address all of this as well. I haven't read it, so I can't be more specific. To call a method from another method within a class, you need to prefix it with self. That looks like this: class Spam(object): ## {1} def parse_line(self, line): ## {2} return line.split(',') def parse_footer(self, line): return self.parse_line(line[4:]) ## {3} # {1} always subclass 'object' to use newstyle classes # {2} Note that method declarations have an extra first argument, # usually called "self", which refers to your instance of the class. # {3} "self" finds parse_line within the current class # or superclasses of the current class. Note that self has # moved from inside the parentheses to before the method name. To call a method from another class you need to instantiate that class first. class Spam(object): def parse_line(self, line): return line.split(',') class Eggs(object): def parse_footer(self, line): parser = Spam() parser.parse_line(line[4:]) ## {4} # {4} The Spam instance "parser" is fed to the method "parse_line" as # its first argument (as "self"). If a class subclasses another class (by, e.g., replacing 'object' with 'Spam' in the class declaration of 'Eggs'), then methods in Eggs can reference methods in Spam using 'self'. class Spam(object): def parse_line(self, line): return line.split(',') class Eggs(Spam): ## {5} def parse_footer(self, line): return self.parse_line(line[4:]) ## {6} # {5} Now Eggs is a subclass of Spam # {6} "self" looks for a method called parse_line in Eggs, and # when it fails to find it, looks in Eggs' superclass, Spam # and finds it there. Hope that helps Cheers, Cliff > >On Mon, 2009-06-22 at 12:13 -0700, Greg Reyna wrote: > >> Learning Python (on a Mac), with the massive help of Mark Lutz's > >> excellent book, "Learning Python". > >> > >> What I want to do is this: > >> I've got a Class Object that begins with a def. It's designed to be > >> fed a string that looks like this: > >> > >> "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > >> > >> I'm parsing the string by finding the commas, and pulling out the > >> data between them. > >> No problem so far (I think...) The trouble is, there is a place > >> where code is repeated: > >> > >> 1. Resetting the start & end position and finding the next comma > >>in the string. > > > > > > >Have you looked at the split() method on string objects. It works kind > >of like this: > > > >>>> s = "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > >>>> s.split(",") > >['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl > >4', ' 2+4', ''] > >>>> elements = s.split(",") > >>>> elements > >['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl > >4', ' 2+4', ''] > >>>> elements[2] > >' 3+8' > > > > > > > >> In my previous experience (with a non-OOP language), I could create a > >> 'procedure', which was a separate function. With a call like: > >> var=CallProcedure(arg1,arg2) the flow control would go to the > >> procedure, run, then Return back to the main function. > >> > > > >Python doesn't have procedures quite like this. It has functions (the > >things starting with "def"), which generally speaking take arguments and > >return values. For the most part, you do not want your functions to > >operate on variables that aren't either defined in the function or > >passed in as arguments. That leads to difficult-to-debug code. > > > > > >> In Python, when I create a second def in the same file as the first > >> it receives a "undefined" error. I can't figure out how to deal with > >> this. How do I set it up to have my function #1 call my function #2, > >> and return? > > > >Your problem description is confusing. First of all, no class starts > >with 'def'. They all start with 'class'. Perhaps you are talking about > >a module (a python file)? > > > >Also, telling us that you get an undefined error is not particularly > >helpful. Every Exception that python raises is accompanied by an > >extensive stack trace which will help you (or us) debug the problem. If > >you don't show us this information, we can't tell you what's going > >wrong. It will tell you (in ways that are crystal clear once you have a > >bit of practice reading them) exactly what went wrong. > > > >Can you show your code, as well as the complete error message you are > >receiving? > > > >My suggestions here, are essentially a paraphrasing of Eric Raymond's > >essay, "How to Ask Smart Questions." It is freely available on the web, > >and easily found via google. I recommend reading that, in order to get > >the most mileage out this news group. > > > >Cheers, > >Cliff > From jeff at jmcneil.net Tue Jun 23 11:12:15 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 23 Jun 2009 08:12:15 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: <8b675cdf-026e-4e70-b6b0-d466411eaa2d@l5g2000vbp.googlegroups.com> On Jun 23, 6:59?am, Francesco Bochicchio wrote: > Hi all, > > is there any site that reports the current porting (to Python 3.x) > status of the main non-standard extension modules (such as pygtk, > pywin32, wxpython, ...) ? > I think such information would be very useful for people - like me - > which are tryiing to decide how/when/if to port existing scripts/ > applications to the new python, or also ?which python to use to start > a new program. > > I searched and googled for this information ?but without finding > anything. It looks to me that also the single extension module sites > are quite shy at announcing plans for the porting (I understand that > in part this is for the "is ready when is ready" philosophy of many > non-large open software projects). > > Ciao > ----- > FB You can pull a list of what works with 3.0 via PyPi, there's a link which points you to http://pypi.python.org/pypi?:action=browse&c=533&show=all. If the package isn't listed on PyPi, I believe you'll have to check out the vendor/distribution site. I posted something like this on my blog a few months back. Finding what's available isn't too terribly difficult. I thought it would be nice to have a port status page that lets the community know where certain package stand so volunteers can step in and help. I guess it would be rather difficult to keep such a page updated, though. From philip at semanchuk.com Tue Jun 23 11:13:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 11:13:38 -0400 Subject: [Mac] file copy In-Reply-To: <7ac8e0F1tludjU1@mid.uni-berlin.de> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <31BEEB5D-11A4-469C-A340-6A21E8A0D9CB@semanchuk.com> On Jun 23, 2009, at 10:54 AM, Diez B. Roggisch wrote: > Tobias Weber wrote: > >> Hi, >> which is the best way to copy files on OS X? I want to preserve >> resource >> forks and extended attributes. > > Are these still relevant on OSX? I've always only copied files > directly, and > never had any troubles. I think resource forks are now stored as extended attributes, and Apple's version of cp is aware of extended attributes. Try this -- create a text file via terminal using `touch foo.txt`. In Finder, click "get info" on the file and change it to open with anything other than TextEdit (e.g. Firefox). Now go back to terminal and look at the file. It's still zero bytes long, but try the command `xattr foo.txt` -- $ xattr foo.txt com.apple.FinderInfo com.apple.ResourceFork Also -- $ cp foo.txt bar.txt $ xattr bar.txt com.apple.FinderInfo com.apple.ResourceFork xattr -h gives options for this command. To the OP -- I remember reading somewhere that xattr is written in Python. You might find it useful or even be able to import it directly. HTH Philip From sn at sncs.se Tue Jun 23 11:20:39 2009 From: sn at sncs.se (Sverker Nilsson) Date: Tue, 23 Jun 2009 08:20:39 -0700 (PDT) Subject: Guppy-PE/Heapy 0.1.9 released Message-ID: I am happy to announce Guppy-PE 0.1.9 Guppy-PE is a library and programming environment for Python, currently providing in particular the Heapy subsystem, which supports object and heap memory sizing, profiling and debugging. It also includes a prototypical specification language, the Guppy Specification Language (GSL), which can be used to formally specify aspects of Python programs and generate tests and documentation from a common source. The main news in this release: o A patch by Chad Austin to compile with Visual Studio 2003 and Python 2.5 C compilers. I think this may fix similar problems with other Microsoft compilers. o Interactive help system, providing a .doc attribute that can be used to get info on available attributes in text form and also by invoking a browser. o New documentation file, heapy_tutorial.html. It contains for now an example of how to get started and use the interactive help. o Bug fix wrt pop for mutable bitset. (Not used in heapy, only in sets/test.py) o guppy.hpy().test() now includes the set-specific tests. o Remote monitor does not longer require readline library being installed. License: MIT Guppy-PE 0.1.9 is available in source tarball format on the Python Package Index (a.k.a. Cheeseshop): http://pypi.python.org/pypi/guppy/0.1.9 The project homepage is on Sourceforge: http://guppy-pe.sourceforge.net Enjoy, Sverker Nilsson Expertise in Linux, embedded systems, image processing, C, Python... http://sncs.se From gagsl-py2 at yahoo.com.ar Tue Jun 23 11:24:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Jun 2009 12:24:03 -0300 Subject: Idioms and Anti-Idioms Question References: <4A3F053A.10208@csail.mit.edu> Message-ID: En Mon, 22 Jun 2009 20:34:40 -0300, Miles Kaufmann escribi?: > On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote: > >> What is subtly wrong about this piece of code? I can't see any bugs >> and can't think of subtle gotchas (e.g. the '\' is removed or the lines >> become separated, because in both cases an IndentationError would be >> raised). > > Perhaps, along with one of those gotchas, a mix of tabs and spaces are > used such that the second line only _appears_ to have a different level > of indentation? ;) Neither. As back in time as I can go (Python 1.5), having any character after the backslash has always been a syntax error no matter what. Only the error message has changed: C:\TEMP>python15 syntaxerror.py File "syntaxerror.py", line 18 value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ ^ SyntaxError: invalid token So the "it might be subtly wrong" argument is strongly wrong. -- Gabriel Genellina From jaime.frio at gmail.com Tue Jun 23 11:29:39 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Tue, 23 Jun 2009 17:29:39 +0200 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Message-ID: <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> On Tue, Jun 23, 2009 at 4:45 PM, Cameron Pulsford wrote: > Hey all, I have a dictionary that looks like this (small example version) > {(1, 2): 0} named a > > so I can do a[1,2] which returns 0. What I also have is a list of > coordinates into a 2 dimensional array that might look like this b = > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? a[tuple(b[0])] should do it... Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From pavlovevidence at gmail.com Tue Jun 23 11:32:43 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 23 Jun 2009 08:32:43 -0700 (PDT) Subject: Idioms and Anti-Idioms Question References: Message-ID: <43e3d938-bfc0-43f1-924f-29c00ea1ab6d@g19g2000yql.googlegroups.com> On Jun 21, 9:14?pm, Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in the > howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to-contin...) > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > ? ? ? ? ?+ calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? ?I can't see any bugs and can't > think of subtle gotchas (e.g. the '\' is removed or the lines become separated, > because in both cases an IndentationError would be raised). Perhaps it was originally was like this: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) Carl Banks From cameron.pulsford at gmail.com Tue Jun 23 11:35:16 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Tue, 23 Jun 2009 11:35:16 -0400 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> Message-ID: <5700df6b0906230835r78c18b2csb630b7f134dac391@mail.gmail.com> Thanks! On Tue, Jun 23, 2009 at 11:29 AM, Jaime Fernandez del Rio < jaime.frio at gmail.com> wrote: > On Tue, Jun 23, 2009 at 4:45 PM, Cameron > Pulsford wrote: > > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > > > > so I can do a[1,2] which returns 0. What I also have is a list of > > coordinates into a 2 dimensional array that might look like this b = > > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? > > a[tuple(b[0])] should do it... > > Jaime > > -- > (\__/) > ( O.o) > ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus > planes de dominaci?n mundial. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwmsmith at gmail.com Tue Jun 23 11:49:53 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Tue, 23 Jun 2009 10:49:53 -0500 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: On Mon, Jun 22, 2009 at 9:49 PM, Andras Pikler wrote: > Hi! > > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > and I am at a loss. > > > > Long: I?m doing research/programming for a professor, and we are working > with MIDI files (a type of simple music file). The research deals with > generating variations from a musical melody; currently, my Python code uses > a Python midi package I found online to read the notes in question from a > midi file, about 350 lines of my own code to generate a variation based on > these notes and the professor?s algorithms, and finally the package again to > write the new melody to another midi file. > > > > Now, my professor would like to have this exact code in C/C++, as she > believes C is more compatible with MATLAB, and wants the code to be > available in multiple languages in case a programmer works for her in the > future who knows C but not Python. While I know a tiny bit of C (emphasis on > the tiny), I would much prefer if there were some sort of automatic compiler > I could use to turn my Python code into C than taking a week or two or three > to learn the minimum I need about C, find a way to access MIDI files in it, > and rewrite all of my code. > > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > Python midi package I?m using uses modules which Shedskin does not support. > Otherwise, I haven?t found much. Is there anything out there to help me do > this? If not, from anyone who has experience in this regard, how daunting > should I expect this to be? Taking on C from a cold start and being able to handle the ins and outs of interfacing with Python isn't something that's feasible in 'two or three weeks'. Here are a couple of options -- take 'em or leave 'em: 1) Put the code in Cython: http://www.cython.org/ (full disclosure: I'm doing a GSoC project with Cython). It will convert pretty much any python code into C code (even closures are supported in the most recent version, I think), and the C code can then be compiled into an extension module. The only problem with the above is the C code isn't, at first blush, easy to read. Nor is it supposed to be changed by the user. So that leads us to option... 2) Write the core functionality in C yourself, and then wrap those C functions in Cython. You'll want to take a look at the documentation: http://docs.cython.org/ and, more specifically on wrapping C code: http://docs.cython.org/docs/external_C_code.html I don't think you'll be able to avoid learning C, though. Kurt From jcd at sdf.lonestar.org Tue Jun 23 11:50:06 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 23 Jun 2009 11:50:06 -0400 Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: <1245772206.8812.1.camel@aalcdl07> On Mon, 2009-06-22 at 22:52 +0000, Peter Billam wrote: > I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > > -- > Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html If the lines got separated, a leading + could disappear into its line without any errors showing up. A trailing + would raise a syntax error. >>> spam = 6 >>> spam + File "", line 1 spam + ^ SyntaxError: invalid syntax >>> + spam 6 >>> From tanner989 at hotmail.com Tue Jun 23 12:19:06 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Tue, 23 Jun 2009 11:19:06 -0500 Subject: help! Message-ID: Python Version: 2.6 GUI toolkit: WxPython Ok so i am writing a program for my school's football team. In one part there is a notebook with 4 tabs for that stats. In each tab there are 4 txtctrl's with a + and - for each. The problem im having is that i need when you click the + or - button that it updates that stat for the player. _________________________________________________________________ Microsoft brings you a new way to search the web. Try Bing? now http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try_bing_1x1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Tue Jun 23 12:20:38 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 09:20:38 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> <8b675cdf-026e-4e70-b6b0-d466411eaa2d@l5g2000vbp.googlegroups.com> Message-ID: <40a2c409-256a-46c9-9769-1a3c0b4d4590@g1g2000yqh.googlegroups.com> On 23 Giu, 17:12, Jeff McNeil wrote: > On Jun 23, 6:59?am, Francesco Bochicchio wrote: > > > > > > > Hi all, > > > is there any site that reports the current porting (to Python 3.x) > > status of the main non-standard extension modules (such as pygtk, > > pywin32, wxpython, ...) ? > > You can pull a list of what works with 3.0 via PyPi, there's a link > which points you tohttp://pypi.python.org/pypi?:action=browse&c=533&show=all. > If the package isn't listed on PyPi, I believe you'll have to check > out the vendor/distribution site. > > I posted something like this on my blog a few months back. ?Finding > what's available isn't too terribly difficult. I thought it would be > nice to have a port status page that lets the community know where > certain package stand so volunteers can step in and help. I guess it > would be rather difficult to keep such a page updated, though > > - Mostra testo citato - Thanks. I thought of pypy, and even tried to search for Python 3 using its search button, but somehow missed the handy "python 3" link on the sidebar :-0 I agree that keeping a complete list would be very difficult, although useful ... Ciao ---- FB From philip at semanchuk.com Tue Jun 23 12:35:31 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 12:35:31 -0400 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: On Jun 23, 2009, at 12:20 PM, Tobias Weber wrote: > In article , > Philip Semanchuk wrote: > >> I think resource forks are now stored as extended attributes, and > > No I'll take your word for it because I was just guessing, but then why do the xattrs in the example I gave show a resource fork? > >> Apple's version of cp is aware of extended attributes. > > Yes, but the manual doesn't say to what extent, nor anything about > ACLs Your original question didn't say anything about ACLs either. >> To the OP -- I remember reading somewhere that xattr is written in >> Python. You might find it useful or even be able to import it >> directly. > > It uses a C extension, but I could import it if I wanted to re-invent > the wheel ;) Isn't importing a module that's already written the exact opposite of re-inventing the wheel? From aahz at pythoncraft.com Tue Jun 23 12:51:03 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 09:51:03 -0700 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: In article <024d7a38$0$20654$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >Dennis Lee Bieber wrote: >> On Sat, 20 Jun 2009 13:47:24 -0700 (PDT), Bearophile >> declaimed the following in >> gmane.comp.python.general: >>> >>> Dennis Lee Bieber, may I ask why most or all your posts are set to "No- >>> Archive"? >> >> I'm from the days when the majority of NNTP servers were configured >> to expire posts after some number of days (Netcom used to expire binary >> groups after 24 hours! and most others were something like 14 days). >> >> Then came the precursor to GoogleGroups -- DejaNews -- threatening >> to archive posts through eternity. This resulted in a fair amount of >> protesting by some, and the creation of the x-no-archive header >> convention (Agent even has configuration options such that, if one were >> to not normally use x-no-archive such that one's own posts could be >> archived, one could still honor it in replies to posts that did contain >> it -- so those replies with quoted contents would also not be archived). >> >> It was at that time that I added the x-no-archive header to my posts >> from Agent; as, while not as vocal as others, did object to DejaNews >> plans. > >But your replies often contain useful information. It's a shame that they >disappear from record, making them invisible for anyone searching the >archives. > >A good rule of thumb when judging behaviour is to ask, "What if everyone did >this?". If everyone set x-no-archive, then discussions on Usenet would be >ephemeral, we couldn't point people to past discussions for information, >and we would lose a lot of useful information. (Also a lot of garbage.) I >can't tell you how often I find useful information in the archives of >comp.lang.python thanks to those who archive the gname news-to-email >gateway, and Google groups. If everyone did what you use, the entire >community, including myself, would be far worse off. > >As far as I'm concerned, setting x-no-archive is harmful, anti-social >behaviour on a technical newsgroup like this. You (almost) might as well >just email the poster you're replying to directly. Your response to Dennis seems at least a little over-the-top. So far as I'm concerned, anyone who joined Usenet after DejaNews is a latecomer; trying to change the cultural beliefs of those who were here first is asserting your superiority. I happen to disagree with people who post with X-no-archive, but I think it's certainly their right. Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, and it all worked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 12:53:14 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 09:53:14 -0700 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: In article <4a3fde13$0$48239$14726298 at news.sunsite.dk>, saurabh wrote: > >I am an experienced C programmer and recently dived into python, >I have developed an instant love for it. >I have been doing some routine scripting for day to day admin tasks,also >have done some Tkinter and socket programming using python. > >I am looking for some open source python project preferably in one of >the above areas (not strictly, am open to others too) to contribute. http://wiki.python.org/moin/VolunteerOpportunities -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From anishaapte at gmail.com Tue Jun 23 12:54:02 2009 From: anishaapte at gmail.com (jythonuser) Date: Tue, 23 Jun 2009 09:54:02 -0700 (PDT) Subject: Dynamic method invocation Message-ID: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> Hi I am new to jythong and was wondering if/how I can do the following - a) register a java object with a given name with jython interpreter using set method b) call methods on the java object - but the methods may not exist on the object, so I would like to call from jython a generic method that I have defined on the object as opposed to using java reflection. Thus the java class is more like a proxy for invocation. As an example, I register an instance of java class Bar with name foo. I want to be able to call from jython - foo.method1 (args) I don't want to define all the methods that I can call from jython on class foo but have a generic method that the above jython code will invoke. I want to use a model where the methods that can be called on foo are discovered dynamically once they are invoked on java class. Clearly Java won't let me do this during method invocation so I am wondering if I can register some sort of proxy object with jython that will let me then delegate right call down to the java object. Thanks a bunch From python at mrabarnett.plus.com Tue Jun 23 13:08:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2009 18:08:57 +0100 Subject: reply to OT diversion In-Reply-To: References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: <4A410C29.8050305@mrabarnett.plus.com> Aahz wrote: [snip] > Your response to Dennis seems at least a little over-the-top. So far as > I'm concerned, anyone who joined Usenet after DejaNews is a latecomer; > trying to change the cultural beliefs of those who were here first is > asserting your superiority. I happen to disagree with people who post > with X-no-archive, but I think it's certainly their right. > > Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, > and it all worked. Difficult to prove, though, because the evidence no longer exists! :-) From lie.1296 at gmail.com Tue Jun 23 13:49:07 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 17:49:07 GMT Subject: Measuring Fractal Dimension ? In-Reply-To: References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: Mark Dickinson wrote: > On Jun 23, 3:52 am, Steven D'Aprano > wrote: >> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: >>> In my universe the standard definition of "log" is different froim what >>> log means in a calculus class >> Now I'm curious what the difference is. > > It's just the usual argument about whether 'log' means > log base 10 or log base e (natural log). At least in the > US, most[*] calculus texts (and also most calculators), > for reasons best known to themselves, use 'ln' to mean > natural log and 'log' to mean log base 10. But most > mathematicians use 'log' to mean natural log: pick up a > random pure mathematics research paper that has the word > 'log' in it, and unless it's otherwise qualified, it's > safe to assume that it means log base e. (Except in the > context of algorithmic complexity, where it might well > mean log base 2 instead...) I usually use log without explicit base only when the base isn't relevant in the context (i.e. when whatever sane base you put in it wouldn't really affect the operations). In algorithmic complexity, a logarithm's base doesn't affect the growth shape and, like constant multiplier, is considered irrelevant to the complexity. > Python also suffers a bit from this confusion: the > Decimal class defines methods 'ln' and 'log10', while > the math module and cmath modules define 'log' and > 'log10'. In fact, in the Decimal class there is no log to an arbitrary base. > (But the Decimal module has other problems, > like claiming that 0**0 is undefined while > infinity**0 is 1.) Well, in math inf**0 is undefined. Since python is programming language, and in language standards it is well accepted that undefined behavior means implementations can do anything they like including returning 0, 1, 42, or even spitting errors, that doesn't make python non-conforming implementation. A more serious argument: in IEEE 745 float, inf**0 is 1. Mathematic operation in python is mostly a wrapper for the underlying C library's sense of math. > [*] A notable exception is Michael Spivak's 'Calculus', which also > happens to be the book I learnt calculus from many years ago. From python at bdurham.com Tue Jun 23 14:05:34 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Jun 2009 14:05:34 -0400 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: <1245780334.11467.1321801415@webmail.messagingengine.com> Mag, If your source data is clean, it may also be faster for you to parse your input files directly vs. use the CSV module which may(?) add some overhead. Check out the struct module and/or use the split() method of strings. We do a lot of ETL processing with flat files and on a slow single core processing workstation, we can typically process 2 Gb of data in ~5 minutes. I would think a worst case processing time would be less than an hour for 14 Gb of data. Malcolm From lie.1296 at gmail.com Tue Jun 23 14:07:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 18:07:04 GMT Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: Peter Billam wrote: > On 2009-06-22, Lie Ryan wrote: >> Ben Charrow wrote: >>> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ >>> + calculate_number(10, 20)*forbulate(500, 360) >>> What is subtly wrong about this piece of code? I can't see any bugs and >>> can't think of subtle gotchas (e.g. the '\' is removed or the lines >>> become separated, because in both cases an IndentationError would be >>> raised). >> The preferred style is to put the binary operators before the line-break >> (i.e. the line break is after the operators): >> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ >> calculate_number(10, 20)*forbulate(500, 360) >> ... >> The following is an extract from PEP 8: >> The preferred way of wrapping long lines is by using Python's >> implied line continuation inside parentheses, brackets and braces. >> If necessary, you can add an extra pair of parentheses around an >> expression, but sometimes using a backslash looks better. Make sure to >> indent the continued line appropriately. The preferred place to break >> around a binary operator is *after* the operator, not before it. > > Damian Conway, in Perl Best Practices, puts forward a clear argument > for breaking *before* the operator: > Using an expression at the end of a statement gets too long, > it's common practice to break that expression after an operator > and then continue the expression on the following line ... > The rationale is that the operator that remains at the end > of the line acts like a continutation marker, indicating that > the expression continues on the following line. > Using the operator as a continutation marker seems like > an excellent idea, but there's a serious problem with it: > people rarely look at the right edge of code. > Most of the semantic hints in a program - such as keywords - > appear on the left side of that code. More importantly, the > structural cues for understanding code - for example, indenting, - > are predominantly on the left as well ... This means that indenting > the continued lines of the expression actually gives a false > impression of the underlying structure, a misperception that > the eye must travel all the way to the right margin to correct. > > which seems to me well-argued. I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > When you're *scanning* the code, breaking the line before the operator might be better since you can easily see that that a line is a continuation from the previous line. However, when it comes to *reading* the code, it's easy to miss that the code continues to the next line, especially when you rely on parentheses' implicit line continuation and don't use an explicit line-continuation character (i.e. \). So... IMHO when it comes to break before or after the operator, it depends on whether you rely on parentheses or explicit line continuation. If you use implicit continuation with parentheses, it's better to break after operators; else if you use explicit continuation with \, it's better to break before operators. Since python prefers using parentheses' implicit line cont., it follows that breaking after operator is the natural choice. From lie.1296 at gmail.com Tue Jun 23 14:13:20 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 18:13:20 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4X80m.250$ze1.226@news-server.bigpond.net.au> Jean-Michel Pichavant wrote: > Lie Ryan wrote: >> Jean-Michel Pichavant wrote: >> >> >> >> >>> Maybe I've been a little bit too dictatorial when I was saying that >>> renaming namespaces should be avoided. >>> Sure your way of doing make sense. In fact they're 2 main purposes of >>> having strong coding rules: >>> 1/ ease the coder's life >>> 2/ ease the reader's life >>> >>> The perfect rule satisfies both of them, but when I have to choose, I >>> prefer number 2. Renaming packages, especially those who are world wide >>> used, may confuse the reader and force him to browse into more code. >>> >>> From the OP example, I was just pointing the fact that **he alone** >>> gains 3 characters when **all** the readers need to ask what means "np". >>> Renaming namespaces with a well chosen name (meaningful) is harmless. >>> >> >> As long as you keep all import statements at the head of the file, there >> is no readability problems with renaming namespace. >> >> Glance at the header file, see: >> import numpy as np >> >> and it's not hard to mentally switch np as numpy... >> >> well, as long as your header doesn't look like this: >> import numpy as np >> import itertools as it >> import Tkinter as Tk >> from time import time as t >> > > yep, your example is good, no namespace renaming ... :o) > I would gladly accept the following renaming: > import theMostEfficientPythonPackageInTheWorld as meppw > Hopefully, package names are often usable as provided. > > Moreover, writing numpy instead of np is not harder for the coder than > switching mentally from np to numpy for the reader. It's just about who > you want to make the life easier, the coder or the reader ? My point was, use namespace renaming whenever that improves readability; however like all tools, don't overuse it Another usecase might be when you have two similarly named package which might bring confusion on which is which if left as is. From cmpython at gmail.com Tue Jun 23 14:14:08 2009 From: cmpython at gmail.com (Che M) Date: Tue, 23 Jun 2009 11:14:08 -0700 (PDT) Subject: launch a .py file from a batch file References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> On Jun 23, 5:30?am, Paul Moore wrote: > 2009/6/23 C M : > > >> Assuming you're running on Windows XP, try the following line in your > >> batch file: > >> @start path\MyPythonApp.pyw > > >> That's of course after you rename your script to a pyw extension. ?That's > >> associated with pythonw, which doesn't need a command window. > > > Well, I renamed my script to have a .pyw extension, and then ran the line > > above.? Without quotes, it doesn't find it (because I have spaces in the > > path). > > With quotes it just opens a console and does nothing (does not launch the > > app). > > > Any ideas? > > Use > > @start "" "path\MyPythonApp.pyw" > > The first item in quotes is the window title. If you only include the > path (in quotes) it's taken as a title, which is why you need the > second set of quotes. > > Paul. Unfortunately, when I try that it says "Windows cannot find [that file]", etc. And yet I am copying the filename right from the file manager and it IS there. What's also odd is that if I open the file using cd and then just putting the filename on the next line, that file (which I gave a .pyw extension) doesn't open, but a file that has a .py extension does. Any ideas? Thanks. Che From torriem at gmail.com Tue Jun 23 14:28:51 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 12:28:51 -0600 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <4A411EE3.4090101@gmail.com> Tobias Weber wrote: >> Apple's version of cp is aware of extended attributes. > > Yes, but the manual doesn't say to what extent, nor anything about ACLs mv, cp, etc (but not rsync) are completely aware of resource forks from Tiger on. This is well documented and known on the Mac forums. So shutils should work just fine for copying, moving, etc. From torriem at gmail.com Tue Jun 23 14:30:42 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 12:30:42 -0600 Subject: C-extension 2 times slower than exe In-Reply-To: <4a40e4b6$1@news.fhg.de> References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: <4A411F52.3080109@gmail.com> Rolf Wester wrote: > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use > the time command to measure the time consumed but I also measure the > time within the C-code using clock() and get similar result. So the > Python startup time is not the reason for the runtime difference I > found. Thank you anyway. Without a profiler it's hard to say where the time is being consumed. You might want to use ctypes and open your c++ code as a DLL without the python extension wrapper. From tjreedy at udel.edu Tue Jun 23 14:37:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Jun 2009 14:37:59 -0400 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Message-ID: Cameron Pulsford wrote: > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > > so I can do a[1,2] which returns 0. What I also have is a list of > coordinates into a 2 dimensional array that might look like this b = > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? Unless you are mutating your coordinate pairs in place, which you very seldom would *have to* do, I would make them tuples. b = [ (1,2), (3,5), ...] This would even save a bit of memory. I prefer this to converting list pairs to tuple pairs on access. tjr From malaclypse2 at gmail.com Tue Jun 23 14:45:21 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Jun 2009 14:45:21 -0400 Subject: [Mac] file copy In-Reply-To: <4A411EE3.4090101@gmail.com> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> <4A411EE3.4090101@gmail.com> Message-ID: <16651e80906231145r23a45dc1n5841e6d0b7747128@mail.gmail.com> On Tue, Jun 23, 2009 at 2:28 PM, Michael Torrie wrote: > mv, cp, etc (but not rsync) are completely aware of resource forks from > Tiger on. ?This is well documented and known on the Mac forums. > > So shutils should work just fine for copying, moving, etc. I don't think that's true. The shutil docs (http://docs.python.org/library/shutil.html) has a big red box at the top that says: """ Warning Even the higher-level file copying functions (copy(), copy2()) can?t copy all file metadata. On POSIX platforms, this means that file owner and group are lost as well as ACLs. On Mac OS, the resource fork and other metadata are not used. This means that resources will be lost and file type and creator codes will not be correct. On Windows, file owners, ACLs and alternate data streams are not copied. """ If I understand the OP's question from the first email in this thread, that should pretty strongly warn you that shutil.copy2 is not going to do what you want. Not being a mac user myself, I don't know what the right way to accomplish what you want is, though. -- Jerry From deets at nospam.web.de Tue Jun 23 15:51:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Jun 2009 21:51:53 +0200 Subject: Dynamic method invocation In-Reply-To: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> Message-ID: <7acq2qF1u879sU1@mid.uni-berlin.de> jythonuser schrieb: > Hi > I am new to jythong and was wondering if/how I can do the following - > > a) register a java object with a given name with jython interpreter > using set method > b) call methods on the java object - but the methods may not exist on > the object, so I would like to call from jython a generic method that > I have defined on the object as opposed to using java reflection. > Thus the java class is more like a proxy for invocation. > > As an example, I register an instance of java class Bar with name > foo. I want to be able to call from jython - > foo.method1 (args) > I don't want to define all the methods that I can call from jython on > class foo but have a generic method that the above jython code will > invoke. I want to use a model where the methods that can be called on > foo are discovered dynamically once they are invoked on java class. > Clearly Java won't let me do this during method invocation so I am > wondering if I can register some sort of proxy object with jython that > will let me then delegate right call down to the java object. It's very unclear to me what you want, but to me, it looks as if you have some misconceptions about jython. There is no "registration" of java-objects. If you have a java-object, you can assign it to a name, and simply invoke any method on it (internally, that will mean using reflection, but that's below the covers for you) foo = SomeJavaClass() foo.some_method() As long as some_method is defined on SomeJavaClass, this will work. And there is also no type-information needed, so this will work in Jython, but not in java: ---- java ---- class A { public void foo() {}; } class B { // NOT A SUBCLASS OF A!! public void foo() {}; } ---- jython ---- if some_condition: bar = A() else: bar = B() bar.foo() Regarding the "generic method thing", I guess this will work: foo = SomeJavaObject() m = getattr(foo, "method_name_that_might_not_be_defined", None) if m: m(argument) Diez From milesck at umich.edu Tue Jun 23 16:42:48 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 23 Jun 2009 16:42:48 -0400 Subject: [Mac] file copy In-Reply-To: References: Message-ID: <7CBEBC9B-0DC2-417B-8003-F6D6B7EC998D@umich.edu> On Jun 23, 2009, at 9:52 AM, Tobias Weber wrote: > Hi, > which is the best way to copy files on OS X? I want to preserve > resource > forks and extended attributes. > > ... > > bin/cp -p This. cp -p, mv, rsync -E, tar, and other utilities will use the copyfile(3) API to preserve extended attributes, resource forks, and ACLs. cp -Rp should be just as safe as a Finder copy--moreso if you run it as root--with the exception of preserving creation dates. Or if you're worried about hard links, check out ditto(1). You presumably already know this, but avoid shutil at all costs. BackupBouncer (http://www.n8gray.org/code/backup-bouncer/) makes testing what gets preserved by various methods of copying quick and easy. The results for a Finder copy: Verifying: basic-permissions ... FAIL (Critical) Verifying: timestamps ... ok (Critical) Verifying: symlinks ... ok (Critical) Verifying: symlink-ownership ... FAIL Verifying: hardlinks ... FAIL (Important) Verifying: resource-forks ... Sub-test: on files ... ok (Critical) Sub-test: on hardlinked files ... FAIL (Important) Verifying: finder-flags ... ok (Critical) Verifying: finder-locks ... ok Verifying: creation-date ... ok Verifying: bsd-flags ... ok Verifying: extended-attrs ... Sub-test: on files ... ok (Important) Sub-test: on directories ... ok (Important) Sub-test: on symlinks ... ok Verifying: access-control-lists ... Sub-test: on files ... ok (Important) Sub-test: on dirs ... ok (Important) Verifying: fifo ... FAIL Verifying: devices ... FAIL Verifying: combo-tests ... Sub-test: xattrs + rsrc forks ... ok Sub-test: lots of metadata ... FAIL sudo cp -Rp: Verifying: basic-permissions ... ok (Critical) Verifying: timestamps ... ok (Critical) Verifying: symlinks ... ok (Critical) Verifying: symlink-ownership ... ok Verifying: hardlinks ... FAIL (Important) Verifying: resource-forks ... Sub-test: on files ... ok (Critical) Sub-test: on hardlinked files ... FAIL (Important) Verifying: finder-flags ... ok (Critical) Verifying: finder-locks ... ok Verifying: creation-date ... FAIL Verifying: bsd-flags ... ok Verifying: extended-attrs ... Sub-test: on files ... ok (Important) Sub-test: on directories ... ok (Important) Sub-test: on symlinks ... ok Verifying: access-control-lists ... Sub-test: on files ... ok (Important) Sub-test: on dirs ... ok (Important) Verifying: fifo ... ok Verifying: devices ... ok Verifying: combo-tests ... Sub-test: xattrs + rsrc forks ... ok Sub-test: lots of metadata ... ok -Miles From benjamin.kaplan at case.edu Tue Jun 23 17:07:22 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 23 Jun 2009 17:07:22 -0400 Subject: help! In-Reply-To: References: Message-ID: On Tue, Jun 23, 2009 at 12:19 PM, tanner barnes wrote: > Python Version: 2.6 > GUI toolkit: WxPython > > Ok so i am writing a program for my school's football team. In one part > there is a notebook with 4 tabs for that stats. In each > tab there are 4 txtctrl's with a + and - for each. The problem im having is > that i need when you click the + or - button that it updates that stat for > the player. > And what would you like us to tell you? Without specific details, the only advice I can give is to bind an event to the plus and minus buttons that updates the data. Or do you not know how to do that? What do you mean by update? Update the text in the GUI, save to a text file, or commit to a database? Please be as specific as possible. > ________________________________ > Microsoft brings you a new way to search the web. Try Bing? now > -- > http://mail.python.org/mailman/listinfo/python-list > > From egrefen at gmail.com Tue Jun 23 17:29:31 2009 From: egrefen at gmail.com (Edward Grefenstette) Date: Tue, 23 Jun 2009 14:29:31 -0700 (PDT) Subject: Trouble with running java using Popen Message-ID: I have a java prog I need to run at some point during the execution of a python module. The path to the folder containing the all the relevant java stuff (which runs fine from the command line) is stored in pkgpath. The relevant code is this: >>> os.chdir(pkgpath) >>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>> SemVectPackage.wait() Here indexpath is the path to a particular index file (usually indexpath = "./indexfolder/fileindex"), so that effectively Popen should be running the equivalent of the shell command: - java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex - which, again, runs fine in the terminal. However running the program returns the following error (echoed from shell, doesn't interrupt prog): - Exception in thread "main" java.lang.NoClassDefFoundError: SemanticVectorsEvaluator - I have no idea why this isn't working. Anyone have any suggestions as to how I might troubleshoot this? Best, Edward From 1x7y2z9 at gmail.com Tue Jun 23 17:32:27 2009 From: 1x7y2z9 at gmail.com (1x7y2z9) Date: Tue, 23 Jun 2009 14:32:27 -0700 (PDT) Subject: re.NONE References: Message-ID: <6778a308-609c-4218-ab32-e56cb97a1af1@y28g2000prd.googlegroups.com> On Jun 22, 5:56?pm, Lawrence D'Oliveiro wrote: > In message > c77d-4a47-8cb4-7dd916d69... at s1g2000prd.googlegroups.com>, 1x7y2z9 wrote: > > Not sure if this is defined in a later version, but it would be nice > > to define re.NONE = 0 in the re module. > > Do so: > > ? ? re.NONE = 0 > > Problem solved. It would be nice to have such a constant defined in the re module (make it standard). From davea at ieee.org Tue Jun 23 17:52:34 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 23 Jun 2009 17:52:34 -0400 Subject: launch a .py file from a batch file In-Reply-To: <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> Message-ID: <4A414EA2.30004@ieee.org> Che M wrote: > On Jun 23, 5:30 am, Paul Moore wrote: > >> 2009/6/23 C M : >> >> >>>> Assuming you're running on Windows XP, try the following line in your >>>> batch file: >>>> @start path\MyPythonApp.pyw >>>> >>>> That's of course after you rename your script to a pyw extension. That's >>>> associated with pythonw, which doesn't need a command window. >>>> >>> Well, I renamed my script to have a .pyw extension, and then ran the line >>> above. Without quotes, it doesn't find it (because I have spaces in the >>> path). >>> With quotes it just opens a console and does nothing (does not launch the >>> app). >>> >>> Any ideas? >>> >> Use >> >> @start "" "path\MyPythonApp.pyw" >> >> The first item in quotes is the window title. If you only include the >> path (in quotes) it's taken as a title, which is why you need the >> second set of quotes. >> >> Paul. >> > > Unfortunately, when I try that it says "Windows cannot find [that > file]", etc. > And yet I am copying the filename right from the file manager and it > IS > there. > > What's also odd is that if I open the file using cd and then just > putting > the filename on the next line, that file (which I gave a .pyw > extension) > doesn't open, but a file that has a .py extension does. > > Any ideas? > Thanks. > Che > > > If you run the xx.pyw file interactively, does it work? If not, perhaps the pyw file association is broken. It, along with the py association, should have been set up by the Python install. You can check it (and fix it) with assoc and ftype. Here's what mine look like: M:\>assoc .pyw .pyw=Python.NoConFile M:\>ftype Python.NoConFile Python.NoConFile="C:\ProgFiles\Python26\pythonw.exe" "%1" %* Or, as I said in an earlier message, you could explicitly specify the interpreter to be run on the start line. Something like: @start "notitle" "c:\ProgFiles\Python26\pythonw.exe" "path\script.pyw" From norseman at hughes.net Tue Jun 23 18:11:17 2009 From: norseman at hughes.net (norseman) Date: Tue, 23 Jun 2009 15:11:17 -0700 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <4A415305.6020105@hughes.net> Edward Grefenstette wrote: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? > > Best, > Edward ================= First glance shows you using ./ in code and ../in terminal. Might check that first. Second glance shows you using Popen vs popen (OK) but is that the correct stdout? It is the CHILD's stdout that is being requested here. (Probably what you had in mind, but ... is it?) Third item - running from the terminal usually loads the terminal environment. Running under program control may NOT load the environment. This is a particular problem in Window$. Is the difference going to effect your efforts? As for Java specific problems (if any) I don't know. Another might. Steve From clp2 at rebertia.com Tue Jun 23 18:13:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Jun 2009 15:13:14 -0700 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <50697b2c0906231513l48cc067fg5e85bc104fa104de@mail.gmail.com> On Tue, Jun 23, 2009 at 2:29 PM, Edward Grefenstette wrote: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? Have you tried?: arglist = ["java", "-Xmx1024m", "SemanticVectorsEvaluator", "." + indexpath] SemVectPackage = Popen(arglist, stdout=PIPE) SemVectPackage.wait() Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 23 18:29:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 00:29:17 +0200 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <7ad39tF1uued4U1@mid.uni-berlin.de> Edward Grefenstette schrieb: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? I'd say you got an CLASSPATH-issue here. You can add that explicitly via env as argument to Popen, or pass it via commandline-args. Diez From v.richomme at gmail.com Tue Jun 23 18:59:23 2009 From: v.richomme at gmail.com (smartmobili) Date: Tue, 23 Jun 2009 15:59:23 -0700 (PDT) Subject: Python 3.0.1 and mingw Message-ID: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> I wanted to know if you have some patch to compile python 3.x on mingw platform because I found some but doesn't work very well : make gcc -o python.exe \ Modules/python.o \ libpython3.0.a -lm Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Fatal Python error: Py_Initialize: can't initialize sys standard streams ImportError: No module named encodings.utf_8 I have some questions about posixmodule.c, config.c and makesetup, I can see in posixmodule that you define a INITFUNC like this : #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined (__BORLANDC__)) && !defined(__QNX__) #define INITFUNC PyInit_nt #define MODNAME "nt" #elif defined(PYOS_OS2) #define INITFUNC PyInit_os2 #define MODNAME "os2" #else #define INITFUNC PyInit_posix #define MODNAME "posix" #endif So first I tried to add || defined(____MINGW32____) to declare a PyInit_nt but after config.c was still using PyInit_posix. How does makesetup choose to include one function or another ? So finally python is using PyInit_posix... and after any idea why I got the compilation error ? From buzzard at urubu.freeserve.co.uk Tue Jun 23 19:55:14 2009 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Wed, 24 Jun 2009 00:55:14 +0100 Subject: IDLE / Python 2.5 under Jaunty Message-ID: A little off-topic perhaps, but I can't think of anywhere more likely to contain people with answers. I've just upgraded to Jaunty Jackalope where Python 2.6 is the default Python version. I'm still developing under 2.5, but IDLE now refuses to respond to left click events (for code editing, menus etc. respond as expected). If I right click, then left click I can move the cursor, but that's not ideal. I've tried SPE which is great, but I can't find a way of configuring the Python version, so I'm stuck with a 2.6 shell. I've had limited success with Boa Constructor (which defaulted to Python 2.6 and wxPython 2.6). By renaming a symlink (/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode.pth) I managed to get the wx version for Python 2.5 to default to 2.8.9.1. I've pointed Boa at 2.5 using the interpreter chooser, but the Boa frame designer still appears to expect wxPython 2.6 (it finds "errors" in my code and refuses to fire up). So, has anybody else had the left click issue with IDLE (and solved it)? Does anyone know how I can configure Boa to use wxPython 2.8.9.1? Does anyone know if it's possible to configure the Python version under SPE? Cheers. Duncan From pavlovevidence at gmail.com Tue Jun 23 19:57:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 23 Jun 2009 16:57:20 -0700 (PDT) Subject: C-extension 2 times slower than exe References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: On Jun 23, 7:20?am, Rolf Wester wrote: > Philip Semanchuk wrote: > > > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > > >> Hi, > > >> I have a C++ program that I would like to steer using Python. I made the > >> wrapper using swig and linked the code (without the main function) into > >> a shared object. My Python script loads the extension and calls a > >> function of the C-extension, the rest runs entirely within the > >> C-extension. For comparison I compiled the code including the main > >> function with the same compilation options and linked all into an exe. > >> The main function of the exe calls the same function as my Python script > >> does. Surprisingly the code in the Python C-extension runs twice as long > >> as the same code in the exe. Does anyone know what could be the reason > >> for this behaviour? > > > If the runtime of the C/C++ code is short, the time spent initializing > > the Python interpreter might have a big impact on the runtime of the > > Python version. > > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use > the time command to measure the time consumed but I also measure the > time within the C-code using clock() and get similar result. So the > Python startup time is not the reason for the runtime difference I > found. Thank you anyway. We can't really help you much unless you give us more details about what you did (how did you built it, how did you time it, and how are you calling the C extension from Python). All we can do is throw out possible ideas, and I will toss out a few, but if that's not it you'll have to post details. Are you building the extension with the same optimization flags as the compiler? Are you calling the C code repeatedly from inside a Python loop? From rcdailey at gmail.com Tue Jun 23 19:57:36 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Tue, 23 Jun 2009 16:57:36 -0700 (PDT) Subject: Forwarding keyword arguments Message-ID: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Suppose I have 2 functions like so: def Function2( **extra ): # do stuff def Function1( **extra ): Function2( extra ) As you can see, I would like to forward the additional keyword arguments in variable 'extra' to Function2 from Function1. How can I do this? I'm using Python 3.0.1 From david.lyon at preisshare.net Tue Jun 23 20:09:25 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 23 Jun 2009 20:09:25 -0400 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: <56c405e7af4de7e14ae05ebd9e5f4a4b@preisshare.net> On Wed, 24 Jun 2009 00:55:14 +0100, duncan smith wrote: > Does anyone know how I can configure Boa to use wxPython 2.8.9.1? Does > anyone know if it's possible to configure the Python version under SPE? It definitely is possible. In fact you need to use wxpython 2.8 with Boa. I had a similar problem under some ubuntu version. You can install 2.6 and 2.8 wxpython. But from memory there is a wxversion ubuntu package also. I had to do some "force"ing as there seemed to be circular dependencies. In the end I got it to work just fine... David From apt.shansen at gmail.com Tue Jun 23 20:25:47 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 23 Jun 2009 17:25:47 -0700 Subject: Forwarding keyword arguments In-Reply-To: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <7a9c25c20906231725s2e987849pc1928500f28e6ae5@mail.gmail.com> > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 def Function1(**extra): Function2(**extra) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jun 23 20:34:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Jun 2009 21:34:23 -0300 Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey escribi?: > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 Function2(**extra) See http://docs.python.org/3.0/reference/expressions.html#calls -- Gabriel Genellina From rcdailey at gmail.com Tue Jun 23 20:45:00 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Tue, 23 Jun 2009 17:45:00 -0700 (PDT) Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <46c60603-f026-4061-a616-b12adfca7d3d@w40g2000yqd.googlegroups.com> On Jun 23, 7:34?pm, "Gabriel Genellina" wrote: > En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey ? > escribi?: > > > Suppose I have 2 functions like so: > > > def Function2( **extra ): > > ? ?# do stuff > > > def Function1( **extra ): > > ? ?Function2( extra ) > > > As you can see, I would like to forward the additional keyword > > arguments in variable 'extra' to Function2 from Function1. How can I > > do this? I'm using Python 3.0.1 > > Function2(**extra) > Seehttp://docs.python.org/3.0/reference/expressions.html#calls > > -- > Gabriel Genellina Thanks for the answer. I did look through the docs but I missed it I guess. From ben+python at benfinney.id.au Tue Jun 23 20:57:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Jun 2009 10:57:18 +1000 Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <87zlbywis1.fsf@benfinney.id.au> Robert Dailey writes: > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) (Style note: The Python style guide, PEP 8, would have the above code written as:: def function2(**extra): # do stuff def function1(**extra): function2(extra) See for a sensible style guide for Python code.) > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 The syntax for ?collect remaining positional arguments into a sequence? in a function definition versus ?unpack the values from this sequence into positional arguments? in a function call are intentionally similar:: def bar(spam, eggs, beans): pass def foo(*args): bar(*args) Likewise for the syntax for ?collect remaining keyword arguments into a mapping? in a function definition versus ?unpack the items from this mapping into keyword arguments? in a function call:: def function2(spam, eggs, beans): pass def function1(**kwargs): function2(**kwargs) For more detail, see the language reference section explaining calls . -- \ ?A society that will trade a little liberty for a little order | `\ will lose both, and deserve neither.? ?Thomas Jefferson, in a | _o__) letter to Madison | Ben Finney From torriem at gmail.com Tue Jun 23 21:24:16 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 19:24:16 -0600 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <4A418040.1070503@gmail.com> Tobias Weber wrote: > Why "so"? shutil does not use bin/cp! That's good to know. I had always thought that that was what shutils did, but you're right; it does not. That said, since cp indeed *can* copy resource forks on Tiger and up, you could use subprocess to call it. Just as an aside, your response to a couple of the suggestions in this thread has been a bit brusque, even given the normal limits of e-mail communications. While it's true that nothing so far has been quite what you wanted, I'm sure that everyone has certainly tried to help you find a solution by throwing out different ideas! It is also true that for many people resources forks are not at all necessary, which is probably why someone mentioned that before, perhaps hoping to save you work. Anyways, I certainly hope you do get something working. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 23 22:20:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Jun 2009 02:20:11 GMT Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: > Steven D'Aprano wrote: > >> Lawrence D'Oliveiro wrote: >> >>>> Ok, now pipe ls to less, take three days to browse through all the >>>> filenames to locate the file you want to see. >>> >>> Sounds like you're approaching the issue with a GUI-centric mentality, >>> which is completely hopeless at dealing with this sort of situation. >> >> Piping the output of ls to less is a GUI-centric mentality? > > Yeah. The "dump it on the user" idea, or more politely "can't decide > anything until the user has seen everything" is evident in the most > "characteristic" GUIs. Perhaps you're using different GUIs to me. In my experience, most GUIs tend to *hide* data from the user rather than give them everything under the sun. The classic example is Windows, which hides certain files in the GUI file manager even if you tell it to show all files. -- Steven From egrefen at gmail.com Tue Jun 23 22:54:10 2009 From: egrefen at gmail.com (Edward Grefenstette) Date: Tue, 23 Jun 2009 19:54:10 -0700 (PDT) Subject: Trouble with running java using Popen References: <7ad39tF1uued4U1@mid.uni-berlin.de> Message-ID: Bingo. I was running the python script in GNU script, and it wasn't loading my bash config file properly. Have fixed it by altering .screenrc and now the code runs fine. Would have never guessed to look if you hadn't mentioned it, cheers! Best, Ed On Jun 23, 11:29?pm, "Diez B. Roggisch" wrote: > Edward Grefenstette schrieb: > > > > > I have a java prog I need to run at some point during the execution of > > a python module. > > > The path to the folder containing the all the relevant java stuff > > (which runs fine from the command line) is stored in pkgpath. The > > relevant code is this: > > >>>> os.chdir(pkgpath) > >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath > >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) > >>>> SemVectPackage.wait() > > > Here indexpath is the path to a particular index file (usually > > indexpath = "./indexfolder/fileindex"), so that effectively Popen > > should be running the equivalent of the shell command: > > - > > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > > - > > which, again, runs fine in the terminal. > > > However running the program returns the following error (echoed from > > shell, doesn't interrupt prog): > > - > > Exception in thread "main" java.lang.NoClassDefFoundError: > > SemanticVectorsEvaluator > > - > > > I have no idea why this isn't working. Anyone have any suggestions as > > to how I might troubleshoot this? > > I'd say you got an CLASSPATH-issue here. You can add that explicitly via > env as argument to Popen, or pass it via commandline-args. > > Diez From aahz at pythoncraft.com Tue Jun 23 23:02:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:02:11 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: In article , Mark Dickinson wrote: >On Jun 22, 7:43=A0pm, David C. Ullrich wrote: >> >> Surely you don't say a curve is a subset of the plane and >> also talk about the integrals of verctor fields over _curves_? >> [snip rest of long response that needs a decent reply, but >> possibly not here... ] > >I wonder whether we can find a better place to have this discussion; I >think there are still plenty of interesting things to say, but I fear >we're rather abusing the hospitality of comp.lang.python at the moment. As long as it's confined to this thread, I certainly have no objection; right now, this thread is occupying only a small fractin of c.l.py bandwidth. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From kay at fiber-space.de Tue Jun 23 23:06:16 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Tue, 23 Jun 2009 20:06:16 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: On 24 Jun., 00:59, smartmobili wrote: > I wanted to know if you have some patch to compile python 3.x on mingw > platform because I found some > but doesn't work very well : > > make > > gcc -o python.exe \ > Modules/python.o \ > libpython3.0.a -lm > Could not find platform independent libraries > Could not find platform dependent libraries > Consider setting $PYTHONHOME to [:] > Fatal Python error: Py_Initialize: can't initialize sys standard > streams > ImportError: No module named encodings.utf_8 > > I have some questions about posixmodule.c, config.c and makesetup, > I can see in posixmodule that you define a INITFUNC like this : > > #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined > (__BORLANDC__)) && > !defined(__QNX__) > #define INITFUNC PyInit_nt > #define MODNAME "nt" > > #elif defined(PYOS_OS2) > #define INITFUNC PyInit_os2 > #define MODNAME "os2" > > #else > #define INITFUNC PyInit_posix > #define MODNAME "posix" > #endif > > So first I tried to add || defined(____MINGW32____) to declare a > PyInit_nt > but after config.c > was still using PyInit_posix. How does makesetup choose to include one > function or another ? > So finally python is using PyInit_posix... > > and after any idea why I got the compilation error ? Why on earth do you want to compile Python 3.0.1? From aahz at pythoncraft.com Tue Jun 23 23:08:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:08:18 -0700 Subject: Beauty and Fitness References: <7a73lrF1totcrU2@mid.uni-berlin.de> Message-ID: In article <7a73lrF1totcrU2 at mid.uni-berlin.de>, Diez B. Roggisch wrote: > >My god, these days they allow just anybody to spam, even f***tards that >are to stupid to include the actual URL of the spam they want to divulge. Thank you for reposting the spam in its entirety, with special thanks for munging your address so I can't even chide you privately. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 23:09:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:09:30 -0700 Subject: urllib2 urlopen takes too much time References: Message-ID: In article , =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= wrote: > >I have encountered a performance problem using suds, which was traced >down to _socket.recv. I am calling some web services and each of them >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, >while the rest of the call is finished in milliseconds. What happens if you use urlopen() by itself? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 23:13:37 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:13:37 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: In article , Ross Ridge wrote: >Aahz wrote: >>Piet van Oostrum wrote: >>> >>>>I notice that I see several postings on news:comp.lang.python that are >>>replies to other postings that I don't see. >> >>As stated previously, my suspicion is that at least some is caused by a >>problem with MIME messages and the mail->news gateway on python.org. > >I'm not sure what MIME would have to do with it, but Piet van Oostrum's >problem is almost certainly as result of the python.org mail to news >gateway mangling the References header. The missing postings he's looking >for don't actually exist. Just go up the thread one more posting and >you'll find the message that was being replied to. While that's also a bug in Mailman (I have a long-standing to-do item to fix that), there are also plenty of posts that simply aren't showing up in c.l.py. As I said, I'm pretty sure (based on what was happening with c.l.py.announce) that it's some kind of weird problem with the mail->news gateway with MIME posts. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From lie.1296 at gmail.com Tue Jun 23 23:30:54 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 03:30:54 GMT Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: duncan smith wrote: > I've just upgraded to Jaunty Jackalope where Python 2.6 is the default > Python version. I'm still developing under 2.5, but IDLE now refuses to > respond to left click events (for code editing, menus etc. respond as > expected). If I right click, then left click I can move the cursor, but > that's not ideal. For the meantime, you should search/file a bug report on Launchpad (Ubuntu's bugtracker) on: https://launchpad.net/ubuntu/ if you haven't already done so. I just tried idle 2.6 (python 2.6, Tk 8.4) on Gentoo, and left-clicking seems to run fine (although I'm a bit unclear on what kinds of left-clicking IDLE refuses to respond to). On the reports to Launchpad, don't forget to include the versions of python, idle, and Tk as reported on Help > About. From steven.samuel.cole at gmail.com Wed Jun 24 00:48:18 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Tue, 23 Jun 2009 21:48:18 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> Message-ID: <13e776b0-6ca8-479e-ba82-eb5b7eb8f445@a5g2000pre.googlegroups.com> On Jun 18, 10:49?am, Jon Clements wrote: > Why are you doing this? I'm assuming a code to title look up is > required (don't forget military, royal and honorable titles > etc... :) ) I'm in New Zealand. Hardly any need for military titles, rarely any for royal and damn sure none for honorable :-D (scnr) From gdamjan at gmail.com Wed Jun 24 01:02:33 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 24 Jun 2009 07:02:33 +0200 Subject: Best way to enumerate classes in a module Message-ID: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> I need to programmaticaly enumerate all the classes in a given module. Currently I'm using dir(module) but the Notice on the documentation page [1] says "dir() is supplied primarily as a convenience for use at an interactive prompt" so that kind of scares me. Is there a better approach? If there is, how do I get all the classes of the current module? [1] http://docs.python.org/library/functions.html#dir -- ?????? ( http://softver.org.mk/damjan/ ) Q: What's tiny and yellow and very, very, dangerous? A: A canary with the super-user password. From ldo at geek-central.gen.new_zealand Wed Jun 24 01:08:57 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Jun 2009 17:08:57 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: In message , Steven D'Aprano wrote: > On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: > >> Steven D'Aprano wrote: >> >>> Lawrence D'Oliveiro wrote: >>> >>>>> Ok, now pipe ls to less, take three days to browse through all the >>>>> filenames to locate the file you want to see. >>>> >>>> Sounds like you're approaching the issue with a GUI-centric mentality, >>>> which is completely hopeless at dealing with this sort of situation. >>> >>> Piping the output of ls to less is a GUI-centric mentality? >> >> Yeah. The "dump it on the user" idea, or more politely "can't decide >> anything until the user has seen everything" is evident in the most >> "characteristic" GUIs. > > Perhaps you're using different GUIs to me. In my experience, most GUIs > tend to *hide* data from the user rather than give them everything under > the sun. Which is getting a bit away from what we're discussing here, but certainly it is characteristic of GUIs to show you all 400,000 files in a directory, or at least try to do so, and either hang for half an hour or run out of memory and crash, rather than give you some intelligent way of prefiltering the file display up front. From chris at simplistix.co.uk Wed Jun 24 02:30:56 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 07:30:56 +0100 Subject: I look for private Python Index server on my local network... What do you use ? In-Reply-To: References: Message-ID: <4A41C820.9030303@simplistix.co.uk> Klein St?phane wrote: > I wonder what Python Index server (like as pypi.python.org) do you use in > your corporation for handle your private python eggs ? > > I found three solutions : > > * http://pypi.python.org/pypi/basketweaver/0.1.2-r6 > * http://pypi.python.org/pypi/pypi/2005-08-01 > * http://pypi.python.org/pypi/EggBasket/0.6.1b > > Do you know another software ? http://pypi.python.org/pypi/haufe.eggserver/0.2.5 > What do you use ? I actually just store the private eggs directly in a subversion repository and that the url of the folder the eggs live in to find-links. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Wed Jun 24 02:37:23 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 07:37:23 +0100 Subject: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009 In-Reply-To: <1245441343.32055.2.camel@jesterj-laptop> References: <4A3A5F66.2030701@simplistix.co.uk> <1245441343.32055.2.camel@jesterj-laptop> Message-ID: <4A41C9A3.5050602@simplistix.co.uk> Jeremiah Jester wrote: > Chris, > Do you have any online tutorial for this topic? I'm afraid not currently... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Wed Jun 24 02:37:54 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 08:37:54 +0200 Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. > > Is there a better approach? > > If there is, how do I get all the classes of the current module? inspect.getmembers(module, inspect.isclass), but this uses dir() internally. You may have to remove imported classes: >>> def getclasses(module): ... def accept(obj): ... return inspect.isclass(obj) and module.__name__ == obj.__module__ ... return [class_ for name, class_ in inspect.getmembers(module, accept)] ... >>> getclasses(inspect) [, , ...] Peter From chris at simplistix.co.uk Wed Jun 24 03:13:01 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 08:13:01 +0100 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Message-ID: <4A41D1FD.7080004@simplistix.co.uk> Terry Reedy wrote: > Mag Gam wrote: >> Yes, the system has 64Gig of physical memory. > > drool ;-). Well, except that, dependent on what OS he's using, the size of one process may well still be limited to 2GB... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From Tim.Couper at standardbank.com Wed Jun 24 03:15:06 2009 From: Tim.Couper at standardbank.com (Couper, Tim T) Date: Wed, 24 Jun 2009 08:15:06 +0100 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Your prof. may find this thread of interest http://mail.python.org/pipermail/python-list/2000-June/039779.html My experience is that developers who know C and C++ can be productive in less than 1 week in python, and find it liberating, and educational, to do so. And at the same time they will have added a second language to their toolbox. As Kurt points out, learning C/C++ takes considerably longer (weeks/months to attain a level of competence). Python is now used in a number of universities as the language in which to teach comp sci undergraduate courses (I know of Leeds, & MIT), biomathematics, and my daughter just finished her PhD in speech and language processing at Edinburgh .. using python and Matplotlib .. as the extensive C/C++ libraries in that infomatics world are wrapped in python - and the MSc Comp Sci course has replaced Java as the language for teaching with Python. Dr Tim Couper -----Original Message----- From: python-list-bounces+tim.couper=standardbank.com at python.org [mailto:python-list-bounces+tim.couper=standardbank.com at python.org] On Behalf Of Kurt Smith Sent: 23 June 2009 16:50 Cc: python-list at python.org Subject: Re: Converting Python code to C/C++ On Mon, Jun 22, 2009 at 9:49 PM, Andras Pikler wrote: > Hi! > > > > Short: I need to turn a Python program that I (mostly) wrote into C > code, and I am at a loss. > > > > Long: I'm doing research/programming for a professor, and we are > working with MIDI files (a type of simple music file). The research > deals with generating variations from a musical melody; currently, my > Python code uses a Python midi package I found online to read the > notes in question from a midi file, about 350 lines of my own code to > generate a variation based on these notes and the professor's > algorithms, and finally the package again to write the new melody to another midi file. > > > > Now, my professor would like to have this exact code in C/C++, as she > believes C is more compatible with MATLAB, and wants the code to be > available in multiple languages in case a programmer works for her in > the future who knows C but not Python. While I know a tiny bit of C > (emphasis on the tiny), I would much prefer if there were some sort of > automatic compiler I could use to turn my Python code into C than > taking a week or two or three to learn the minimum I need about C, > find a way to access MIDI files in it, and rewrite all of my code. > > > > After some googling, I found and tried Shedskin, but it doesn't work, > as the Python midi package I'm using uses modules which Shedskin does not support. > Otherwise, I haven't found much. Is there anything out there to help > me do this? If not, from anyone who has experience in this regard, how > daunting should I expect this to be? Taking on C from a cold start and being able to handle the ins and outs of interfacing with Python isn't something that's feasible in 'two or three weeks'. Here are a couple of options -- take 'em or leave 'em: 1) Put the code in Cython: http://www.cython.org/ (full disclosure: I'm doing a GSoC project with Cython). It will convert pretty much any python code into C code (even closures are supported in the most recent version, I think), and the C code can then be compiled into an extension module. The only problem with the above is the C code isn't, at first blush, easy to read. Nor is it supposed to be changed by the user. So that leads us to option... 2) Write the core functionality in C yourself, and then wrap those C functions in Cython. You'll want to take a look at the documentation: http://docs.cython.org/ and, more specifically on wrapping C code: http://docs.cython.org/docs/external_C_code.html I don't think you'll be able to avoid learning C, though. Kurt -- http://mail.python.org/mailman/listinfo/python-list ***************************************************************************** This communication is sent by the Standard Bank Plc or one of its affiliates The registered details of Standard Bank Plc are: Registered in England No. 2130447, Registered Office 25 Dowgate Hill London EC4R 2SB Authorised and Regulated by the Financial Services Authority. More information on Standard Bank is available at www.standardbank.com Everything in this email and any attachments relating to the official business of Standard Bank Group Limited and any or all subsidiaries, the Company, is proprietary to the Company. It is confidential, legally privileged and protected by relevant laws. The Company does not own and endorse any other content. Views and opinions are those of the sender unless clearly stated as being that of the Company. The person or persons addressed in this email are the sole authorised recipient. Please notify the sender immediately if it has unintentionally, or inadvertently reached you and do not read, disclose or use the content in any way and delete this e-mail from your system. The Company cannot ensure that the integrity of this email has beenmaintained nor that it is free of errors, virus, interception or interference. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. ***************************************************************************** From usernet at ilthio.net Wed Jun 24 03:17:33 2009 From: usernet at ilthio.net (Tim Harig) Date: Wed, 24 Jun 2009 07:17:33 GMT Subject: wikipedia with python References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: On 2009-06-22, ZeLegolas wrote: > On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels > wrote: >> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >>> I'm looking for wiki writen with python where I can import all >>> wikipedia site. >> PHP. >> What do you want to use the material for? > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. To clarify, check one: [ ] A. You already have mediawiki wiki running on a web server; but, you would prefer to have your wiki power by Python. [ ] B. You already have mediawiki running on a web server and you have another wiki powered by Python; and, you would like to take the information from the python powered wiki and copy it to the mediawiki. [ ] C. You already have mediawiki running on a web server and you would also like to use the functionality of a wiki which is written in Python. Somehow, you would like to somehow access some of the Python's functionality and use it from inside of mediawiki. Perhaps making them work side by side. [ ] D. You already have mediawiki running on a webserver; but, you would like to get data from another mediawiki server that you don't have direct database access to; so, you would like to write a script in Python to scrape the data off of the other mediawiki's website. [ ] E. You already have a wiki running in python on a webserver and you would like to import data from another wiki that is powered by mediawiki. You might or might not have direct access to the database used by the wikimedia server. You would like a Python script to convert/scrap the data. [ ] F. Other From sjmachin at lexicon.net Wed Jun 24 03:18:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 00:18:47 -0700 (PDT) Subject: re.NONE References: Message-ID: <40123fe2-e0a8-4f24-95f2-225171f08fd0@o21g2000prn.googlegroups.com> On Jun 23, 8:35?am, 1x7y2z9 <1x7y... at gmail.com> wrote: > I am currently using python v2.5.2. > > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. ?This would be useful in cases > such as: > flags = re.DOTALL if dotall else re.NONE > > Also useful for "building up" flags by ORing with other flags. -1 0 is even more useful. YAGNI. BTW everybody try typing NONE a few times fast ... if your fingers don't fight your brain and produce None anyway, you haven't been using Python long enough :-) From lie.1296 at gmail.com Wed Jun 24 03:30:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 07:30:24 GMT Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Steven > D'Aprano wrote: > >> On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: >> >>> Steven D'Aprano wrote: >>> >>>> Lawrence D'Oliveiro wrote: >>>> >>>>>> Ok, now pipe ls to less, take three days to browse through all the >>>>>> filenames to locate the file you want to see. >>>>> Sounds like you're approaching the issue with a GUI-centric mentality, >>>>> which is completely hopeless at dealing with this sort of situation. >>>> Piping the output of ls to less is a GUI-centric mentality? >>> Yeah. The "dump it on the user" idea, or more politely "can't decide >>> anything until the user has seen everything" is evident in the most >>> "characteristic" GUIs. >> Perhaps you're using different GUIs to me. In my experience, most GUIs >> tend to *hide* data from the user rather than give them everything under >> the sun. > > Which is getting a bit away from what we're discussing here, but certainly > it is characteristic of GUIs to show you all 400,000 files in a directory, > or at least try to do so, and either hang for half an hour or run out of > memory and crash, rather than give you some intelligent way of prefiltering > the file display up front. In many debugging cases, you don't even know what to filter, which is what I was referring to when I said "Even with glob and grep ..." For example, when the problem mysteriously disappears when the file is isolated From andreengels at gmail.com Wed Jun 24 03:34:25 2009 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Jun 2009 09:34:25 +0200 Subject: wikipedia with python In-Reply-To: References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: <6faf39c90906240034w4694b166ud006a02d53ed9722@mail.gmail.com> On Wed, Jun 24, 2009 at 9:17 AM, Tim Harig wrote: > [ ] D. You already have mediawiki running on a webserver; but, you would > ? ? ? ?like to get data from another mediawiki server that you don't have > ? ? ? ?direct database access to; so, you would like to write a script in > ? ? ? ?Python to scrape the data off of the other mediawiki's website. In case D (and more general, to anyone who wants to do something to a Mediawiki wiki using Python), you can use the Python Wikipediabot Framework, http://pywikipediabot.sourceforge.net/ -- Andr? Engels, andreengels at gmail.com From lie.1296 at gmail.com Wed Jun 24 03:38:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 07:38:17 GMT Subject: wikipedia with python In-Reply-To: References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: ZeLegolas wrote: > On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels > wrote: >> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >>> Let me know if it's the right place to ask. >>> >>> I'm looking for wiki writen with python where I can import all >>> wikipedia site. >>> If you have any links please let me know. >> I don't think that's possible. If you wnat to import Wikipedia in a >> wiki, it will probably have to be MediaWiki - and that's written in >> PHP. >> >> What do you want to use the material for? > > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. > Is there anything insufficient in mediawiki, that you think could be satisfied with a python-based wiki? MediaWiki is one of the best wiki software around, so any features not found in MediaWiki or its plugins isn't likely to be available in another wiki (unless "written in a language I know" is considered a feature). From lele at metapensiero.it Wed Jun 24 03:41:05 2009 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 24 Jun 2009 09:41:05 +0200 Subject: GNUstep and Python References: <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <7a7l9kF1tv7viU1@mid.uni-berlin.de> Message-ID: <87iqimaxke.fsf@nautilus.homeip.net> Eric Brunel writes: > Diez B. Roggisch wrote: >> Paul Watson schrieb: >> There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. > > Apparently, it's not: There was some compatibility in earlier versions, but > it's been officially removed in version 2.0. See > http://pyobjc.sourceforge.net/NEWS-2.0.html : > "GNUstep support has been removed because this has never worked properly, > nobody seems interested in fixing that and the internal APIs of PyObjC have > changed greatly." It's been a lot of time ago, but that is wrong: when I initially implemented PyObjC I put a lot of effort in understanding the differences between the NeXT and the GNU ObjC runtimes, and PyObjC used to work ok on both, with a slight bias toward the GNU runtime (having the source at hands helps, as you know :-) Version 2.0 brought major changes to the internals, mainly to support the new MacOS frameworks, with tools to automatically create the needed glue interfaces between the two worlds. Too bad I wasn't involved/motivated enough to keep the GNU runtime support up-to-date, and it was finally declared obsolete and removed. Just a few cents of clarity, ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at nautilus.homeip.net | -- Fortunato Depero, 1929. From sjmachin at lexicon.net Wed Jun 24 03:48:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 00:48:41 -0700 (PDT) Subject: re.NONE References: <40123fe2-e0a8-4f24-95f2-225171f08fd0@o21g2000prn.googlegroups.com> Message-ID: <31f9e5bd-ee8f-471f-809c-18af74726833@v23g2000pro.googlegroups.com> On Jun 24, 5:18?pm, John Machin wrote: > On Jun 23, 8:35?am, 1x7y2z9 <1x7y... at gmail.com> wrote: > > > I am currently using python v2.5.2. > > > Not sure if this is defined in a later version, but it would be nice > > to define re.NONE = 0 in the re module. ?This would be useful in cases > > such as: > > flags = re.DOTALL if dotall else re.NONE > > > Also useful for "building up" flags by ORing with other flags. > > -1 > > 0 is even more useful. YAGNI. > > BTW everybody try typing NONE a few times fast ... if your fingers > don't fight your brain and produce None anyway, you haven't been using > Python long enough :-) Oh and I forgot to mention that if this proposal goes ahead it will need a one-letter version -- perhaps re.Z -- and maybe even a PEP. It could end up rivalling the legendary IEFBR14 in the ratio-of-overhead- to-functionality stakes. From pavlovevidence at gmail.com Wed Jun 24 03:49:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 00:49:34 -0700 (PDT) Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: On Jun 23, 10:02?pm, ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] ?says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. > > Is there a better approach? > > If there is, how do I get all the classes of the current module? You can use module.__dict__.values() (or .itervalues()) to retrieve the contents of the module (and of course .keys() if you want names). If you want to check the same module that the code appears in, use globals() instead of module.__dict__. Something makes me think that module.__dict__ was only added to Python fairly recently, but I'm not sure. A word of warning (although I would guess you are already aware of these issues, but for other readers): this method can't tell the difference between a class defined in the module and a class imported into it. Finally, despite the warning, I think you are ok to use dir() for that purpose. It's not likely to change. Carl Banks From mail at microcorp.co.za Wed Jun 24 04:08:36 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 24 Jun 2009 10:08:36 +0200 Subject: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <008301c9f4a3$2fcd4c80$0d00a8c0@Hendrik> "Aahz" wrote: > While that's also a bug in Mailman (I have a long-standing to-do item to > fix that), there are also plenty of posts that simply aren't showing up > in c.l.py. As I said, I'm pretty sure (based on what was happening with > c.l.py.announce) that it's some kind of weird problem with the mail->news > gateway with MIME posts. I have lately had some posts returned with a "seems to be forged" message. Two reasons for that: - first is if I use the smtp server from our local telco - saix - then there is no apparent relationship between where the message comes from and where it comes from, if you follow my Irish... - Second is if the same telco assigns me an IP that has been put on a list of bad boy IPs. So it is kind of pot luck if you see this message or not. - Hendrik From pdpinheiro at gmail.com Wed Jun 24 05:12:05 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 02:12:05 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> On Jun 23, 6:49?pm, Lie Ryan wrote: > Mark Dickinson wrote: > > On Jun 23, 3:52 am, Steven D'Aprano > > wrote: > >> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > >>> In my universe the standard definition of "log" is different froim what > >>> log means in a calculus class > >> Now I'm curious what the difference is. > > > It's just the usual argument about whether 'log' means > > log base 10 or log base e (natural log). ?At least in the > > US, most[*] calculus texts (and also most calculators), > > for reasons best known to themselves, use 'ln' to mean > > natural log and 'log' to mean log base 10. ?But most > > mathematicians use 'log' to mean natural log: ?pick up a > > random pure mathematics research paper that has the word > > 'log' in it, and unless it's otherwise qualified, it's > > safe to assume that it means log base e. ?(Except in the > > context of algorithmic complexity, where it might well > > mean log base 2 instead...) > > I usually use log without explicit base only when the base isn't > relevant in the context (i.e. when whatever sane base you put in it > wouldn't really affect the operations). In algorithmic complexity, a > logarithm's base doesn't affect the growth shape and, like constant > multiplier, is considered irrelevant to the complexity. > > > Python also suffers a bit from this confusion: ?the > > Decimal class defines methods 'ln' and 'log10', while > > the math module and cmath modules define 'log' and > > 'log10'. ? > > In fact, in the Decimal class there is no log to an arbitrary base. > > > (But the Decimal module has other problems, > > like claiming that 0**0 is undefined while > > infinity**0 is 1.) > > Well, in math inf**0 is undefined. Since python is programming language, > and in language standards it is well accepted that undefined behavior > means implementations can do anything they like including returning 0, > 1, 42, or even spitting errors, that doesn't make python non-conforming > implementation. > > A more serious argument: in IEEE 745 float, inf**0 is 1. Mathematic > operation in python is mostly a wrapper for the underlying C library's > sense of math. > > > > > [*] A notable exception is Michael Spivak's 'Calculus', which also > > happens to be the book I learnt calculus from many years ago. Well, AFAIK Python defines CPython as the standard. So whatever CPython does is the defined behaviour. Regarding inf ** 0, why does IEEE745 define it as 1, when there is a perfectly fine NaN value? From shelika.void at gmail.com Wed Jun 24 05:39:32 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 02:39:32 -0700 (PDT) Subject: Dictionary self lookup Message-ID: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Hi all. Assuming that python dictionaries already provide a bit of "shoot yourself in the foot", I think what I have in mind would not be so bad. What do you think of dictionaries having a self lookup in their declaration? Be able to do this: a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax instead of: a = { "foo" : "foo1" } a["bar"] = a["foo"] Maybe I'm murdering python syntax/philosophy right here so let me know if that's the case. I was thinking this could probably be done in python abstract tree but as I never looked into it I may be wrong. I'm willing to make the effort, provided I get some directions and that this idea is worth it. Any feedback is welcome. Cheers, Norberto From NoEmail at NoDomain.com Wed Jun 24 05:42:59 2009 From: NoEmail at NoDomain.com (saurabh) Date: Wed, 24 Jun 2009 14:42:59 +0500 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: Thanks a lot everyone for your prompt replies. I am really glad to see so many options for me. I am sure joining any of the above projects will enrich my understanding of python and programming.I will just have to find out , to which project I will be most useful.I will definitely join one of them. -Saurabh From v.richomme at gmail.com Wed Jun 24 05:55:47 2009 From: v.richomme at gmail.com (smartmobili) Date: Wed, 24 Jun 2009 02:55:47 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: <82ca7daf-b6e9-4601-87db-a1b94c8eb7c2@f10g2000vbf.googlegroups.com> On 24 juin, 05:06, Kay Schluehr wrote: > On 24 Jun., 00:59, smartmobili wrote: > > > > > > > > > I wanted to know if you have some patch to compile python 3.x on mingw > > platform because I found some > > but doesn't work very well : > > > ? ? make > > > gcc ? -o python.exe \ > > Modules/python.o \ > > libpython3.0.a ? ?-lm > > Could not find platform independent libraries > > Could not find platform dependent libraries > > Consider setting $PYTHONHOME to [:] > > Fatal Python error: Py_Initialize: can't initialize sys standard > > streams > > ImportError: No module named encodings.utf_8 > > > I have some questions about posixmodule.c, config.c and makesetup, > > I can see in posixmodule that you define a INITFUNC like this : > > > #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined > > (__BORLANDC__)) && > > !defined(__QNX__) > > #define INITFUNC PyInit_nt > > #define MODNAME "nt" > > > #elif defined(PYOS_OS2) > > #define INITFUNC PyInit_os2 > > #define MODNAME "os2" > > > #else > > #define INITFUNC PyInit_posix > > #define MODNAME "posix" > > #endif > > > So first I tried to add || defined(____MINGW32____) to declare a > > PyInit_nt > > but after config.c > > was still using PyInit_posix. How does makesetup choose to include one > > function or another ? > > So finally python is using PyInit_posix... > > > and after any idea why I got the compilation error ? > > Why on earth do you want to compile Python 3.0.1? Because I need python to be able to compile other libraries on mingw (subcersion, ....). From deets at nospam.web.de Wed Jun 24 05:59:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 11:59:13 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <7aebgaF1up16pU1@mid.uni-berlin.de> Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. What kind of foot-shooting do you have in mind? > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. Obviously the proposed syntax can't work, as at the time of the dictionary construction the name the dict is bound to is either not known, or even bound to *another* dict. Additionally, the code would be by no means more efficient than the above "long" version, as whatever notation you chose, it won't help to deal with the fact that the dict-object itself, and also a potentially reference key, aren't already available. So behind the curtain, the exact same logic would apply, with all runtime-costs. Which leaves us with the question: why the heck do you want this? Diez From clp2 at rebertia.com Wed Jun 24 06:05:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 03:05:40 -0700 Subject: Dictionary self lookup In-Reply-To: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <50697b2c0906240305h6ce621c1k677202e94d3c2664@mail.gmail.com> On Wed, Jun 24, 2009 at 2:39 AM, Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. The idea sounds quite confusing and seems unnecessary. Specifically, your proposal appears to contravene the following points of the holy Zen of Python: - Explicit is better than implicit. - Readability counts. - Special cases aren't special enough to break the rules. - In the face of ambiguity, refuse the temptation to guess. - If the implementation is hard to explain, it's a bad idea. Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Wed Jun 24 06:06:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 12:06:37 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <7aebu7F1uahjuU1@mid.uni-berlin.de> Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. I doubt this will ever be accepted, but out of curiosity: *why* do you want this? And if you are willing to put some constraints on you keys, it would be easy enough to do this: def wicked_dict(**kwargs): mappings = [(name, source) for name, source in kwargs.iteritems() if name.startswith("_") res = dict((key, value) for key, value in kwarges.iteritems() if not name.startswith("_")) for name, source in mappings: res[name] = res[source] return res Diez From shelika.void at gmail.com Wed Jun 24 06:21:48 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 03:21:48 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> Message-ID: <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: > Norberto Lopes wrote: > > Hi all. > > Assuming that python dictionaries already provide a bit of "shoot > > yourself in the foot", I think what I have in mind would not be so > > bad. > > What kind of foot-shooting do you have in mind? > a = { "foo" : { "bar" : "moo" }} a["bar"] = a["foo"] print a {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} a["foo"]["bar"] = a["foo"] print a {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} (I know it's not a C shoot in the foot or something but still...) > > > > > > > > What do you think of dictionaries having a self lookup in their > > declaration? > > > Be able to do this: > > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > > instead of: > > > a = { "foo" : "foo1" } > > a["bar"] = a["foo"] > > > Maybe I'm murdering python syntax/philosophy right here so let me know > > if that's the case. > > I was thinking this could probably be done in python abstract tree but > > as I never looked into it I may be wrong. I'm willing to make the > > effort, provided I get some directions and that this idea is worth it. > > > Any feedback is welcome. > > Obviously the proposed syntax can't work, as at the time of the dictionary > construction the name the dict is bound to is either not known With just more thatn syntactic sugar this could be done >, or even bound to *another* dict. > doh! Didn't thought about that one. Nice catch. > Additionally, the code would be by no means more efficient than the > above "long" version, as whatever notation you chose, it won't help to deal > with the fact that the dict-object itself, and also a potentially reference > key, aren't already available. > > So behind the curtain, the exact same logic would apply, with all > runtime-costs. > > Which leaves us with the question: why the heck do you want this? > Syntactic sugar basically. I'm not ranting about performance, just easier write up. config = {"home" : "/home/test", "user1": config["home"] + "/user1", "user2" : config["home"] + "/user2", "python-dev" : config["user1"] + "/Projects/py-dev" } config = {"home" : "/home/test"} config["user1"] = config["home"] + "/user1" config["user2"] = config["home"] + "/user2" config["python-dev"] = config["user1"] + "/py-dev" Now, if you change config["home"] you'd have to redo all of the other entries. With the first one (assuming pointers to the entries) everything would get updated. Although python does not handles dict keys/values this way. Now that I think of this there would be a lot more than just syntactic sugar for this. (ignore the path concatenation without os.path) From shelika.void at gmail.com Wed Jun 24 06:22:48 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 03:22:48 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <2256855f-9e11-4650-83b6-04dc60934869@n21g2000vba.googlegroups.com> On Jun 24, 12:05?pm, Chris Rebert wrote: > On Wed, Jun 24, 2009 at 2:39 AM, Norberto Lopes wrote: > > Hi all. > > Assuming that python dictionaries already provide a bit of "shoot > > yourself in the foot", I think what I have in mind would not be so > > bad. > > > What do you think of dictionaries having a self lookup in their > > declaration? > > > Be able to do this: > > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > > instead of: > > > a = { "foo" : "foo1" } > > a["bar"] = a["foo"] > > > Maybe I'm murdering python syntax/philosophy right here so let me know > > if that's the case. > > The idea sounds quite confusing and seems unnecessary. > > Specifically, your proposal appears to contravene the following points > of the holy Zen of Python: > > - Explicit is better than implicit. > - Readability counts. > - Special cases aren't special enough to break the rules. > - In the face of ambiguity, refuse the temptation to guess. > - If the implementation is hard to explain, it's a bad idea. > > Cheers, > Chris > --http://blog.rebertia.com Ok, no arguments against this one :( /agree From mail131 at gmail.com Wed Jun 24 06:23:30 2009 From: mail131 at gmail.com (Przemyslaw Bak) Date: Wed, 24 Jun 2009 03:23:30 -0700 (PDT) Subject: fileinput.input, readlines and ... Message-ID: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Hello, I many files with log data. The structure of the file is quite inconvenience and similar to the following example: Data1 ValueA Data2 ValueB Data3 ValueC ... To get the values I need to find Data* and then get to the next line. I tried to use fileinput.input : ... for line in fileinput.input(filename): if line.find("Data2") >= 0: (now what ?) So I can find the requested line (Data2) but how to get value from the next line ? Is the fileinput.input the most convenient for this type of task ? Maybe readline or readlines would be better ? What can you recommend ? Regards From nospam at invalid.invalid Wed Jun 24 06:34:24 2009 From: nospam at invalid.invalid (robert) Date: Wed, 24 Jun 2009 12:34:24 +0200 Subject: Windows: open() -> "[Errno 38] Filename too long" Message-ID: When doing open/os.stat/...(dirpath+filename) and total path > 250 chars then OSError: "[Errno 38] Filename too long" is there a way to access the file without changing to that directory (its in a thread and a fast iteration of many file too) ? From mail at timgolden.me.uk Wed Jun 24 06:43:34 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Jun 2009 11:43:34 +0100 Subject: Windows: open() -> "[Errno 38] Filename too long" In-Reply-To: References: Message-ID: <4A420356.2060701@timgolden.me.uk> robert wrote: > When doing open/os.stat/...(dirpath+filename) > and total path > 250 chars then > > OSError: "[Errno 38] Filename too long" > > is there a way to access the file without changing to that directory > (its in a thread and a fast iteration of many file too) ? Change filename r"c:\temp\long.txt" to ur"\\?\c:\temp\long.txt" TJG From dickinsm at gmail.com Wed Jun 24 07:02:33 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 24 Jun 2009 04:02:33 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> Message-ID: <298b6e65-9caf-4c5d-bb3b-b0627054fc28@j19g2000vbp.googlegroups.com> On Jun 24, 10:12?am, pdpi wrote: > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > perfectly fine NaN value? Have a look at: http://www.eecs.berkeley.edu/~wkahan/ieee754status/ieee754.ps (see particularly page 9). Mark From deets at nospam.web.de Wed Jun 24 07:21:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 13:21:30 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> Message-ID: <7aegajF1uqhasU1@mid.uni-berlin.de> Norberto Lopes wrote: > On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: >> Norberto Lopes wrote: >> > Hi all. >> > Assuming that python dictionaries already provide a bit of "shoot >> > yourself in the foot", I think what I have in mind would not be so >> > bad. >> >> What kind of foot-shooting do you have in mind? >> > > a = { "foo" : { "bar" : "moo" }} > a["bar"] = a["foo"] > print a > {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} > a["foo"]["bar"] = a["foo"] > print a > {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} > > (I know it's not a C shoot in the foot or something but still...) And something working alike for lists and objects. Cyclic references are a fact of (programming)-life unless you go fully functional - and then you'd certainly miss it sometimes.. > config = {"home" : "/home/test"} > config["user1"] = config["home"] + "/user1" > config["user2"] = config["home"] + "/user2" > config["python-dev"] = config["user1"] + "/py-dev" > > > Now, if you change config["home"] you'd have to redo all of the other > entries. With the first one (assuming pointers to the entries) > everything would get updated. Although python does not handles dict > keys/values this way. Now that I think of this there would be a lot > more than just syntactic sugar for this. Things that are re-done usually are useful being put into a function. Then redoing becomes easier :) Diez From shelika.void at gmail.com Wed Jun 24 07:21:35 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 04:21:35 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: On Jun 24, 1:21?pm, "Diez B. Roggisch" wrote: > Norberto Lopes wrote: > > On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: > >> Norberto Lopes wrote: > >> > Hi all. > >> > Assuming that python dictionaries already provide a bit of "shoot > >> > yourself in the foot", I think what I have in mind would not be so > >> > bad. > > >> What kind of foot-shooting do you have in mind? > > > a = { "foo" : { "bar" : "moo" }} > > a["bar"] = a["foo"] > > print a > > {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} > > a["foo"]["bar"] = a["foo"] > > print a > > {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} > > > (I know it's not a C shoot in the foot or something but still...) > > And something working alike for lists and objects. Cyclic references are a > fact of (programming)-life unless you go fully functional - and then you'd > certainly miss it sometimes.. > Yes. (and sometimes you miss functional :D) > > config = {"home" : "/home/test"} > > config["user1"] = config["home"] + "/user1" > > config["user2"] = config["home"] + "/user2" > > config["python-dev"] = config["user1"] + "/py-dev" > > > Now, if you change config["home"] you'd have to redo all of the other > > entries. With the first one (assuming pointers to the entries) > > everything would get updated. Although python does not handles dict > > keys/values this way. Now that I think of this there would be a lot > > more than just syntactic sugar for this. > > Things that are re-done usually are useful being put into a function. Then > redoing becomes easier :) > > Diez True. In any case, reading from your pov, it seems that the solution would cause more problems than solving one. Thanks for the feedback though. Much appreciated :) From __peter__ at web.de Wed Jun 24 07:32:32 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 13:32:32 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Przemyslaw Bak wrote: > Hello, > > I many files with log data. The structure of the file is quite > inconvenience and similar to the following example: > Data1 > ValueA > Data2 > ValueB > Data3 > ValueC > ... > To get the values I need to find Data* and then get to the next line. > I tried to use fileinput.input : > ... > for line in fileinput.input(filename): > if line.find("Data2") >= 0: > (now what ?) > > So I can find the requested line (Data2) but how to get value from the > next line ? lines = fileinput.input(filename) for line in lines: if "Data2" in line: print line.strip(), "-->", next(lines).strip() > Is the fileinput.input the most convenient for this type of task ? > Maybe > readline or readlines would be better ? > What can you recommend ? If you need more than a few name value pairs it pays to put the data in a dictionary first: # assuming that values always consist of a single line with open(filename) as instream: lines = (line.strip() for line in lines) lookup = dict(zip(lines, lines)) print lookup["Data2"] print lookup["Data3"] Peter From magawake at gmail.com Wed Jun 24 07:38:11 2009 From: magawake at gmail.com (Mag Gam) Date: Wed, 24 Jun 2009 04:38:11 -0700 Subject: Reading a large csv file In-Reply-To: <4A41D1FD.7080004@simplistix.co.uk> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> Sorry for the delayed response. I was trying to figure this problem out. The OS is Linux, BTW Here is some code I have: import numpy as np from numpy import * import gzip import h5py import re import sys, string, time, getopt import os src=sys.argv[1] fs = gzip.open(src) x=src.split("/") filename=x[len(x)-1] #Get YYYY/MM/DD format YYYY=(filename.rsplit(".",2)[0])[0:4] MM=(filename.rsplit(".",2)[0])[4:6] DD=(filename.rsplit(".",2)[0])[6:8] f=h5py.File('/tmp/test_foo/FE.hdf5','w') grp="/"+YYYY try: f.create_group(grp) except ValueError: print "Year group already exists" grp=grp+"/"+MM try: f.create_group(grp) except ValueError: print "Month group already exists" grp=grp+"/"+DD try: group=f.create_group(grp) except ValueError: print "Day group already exists" str_type=h5py.new_vlen(str) mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', 'f4', 'f4')} print "Filename is: ",src fs = gzip.open(src) dset = f.create_dataset ('Foo',data=arr,compression='gzip') s=0 #Takes the longest here for y in fs: continue a=y.split(',') s=s+1 dset.resize(s,axis=0) fs.close() f.close() This works but just takes a VERY long time. Any way to optimize this? TIA On Wed, Jun 24, 2009 at 12:13 AM, Chris Withers wrote: > Terry Reedy wrote: >> >> Mag Gam wrote: >>> >>> Yes, the system has 64Gig of physical memory. >> >> drool ;-). > > Well, except that, dependent on what OS he's using, the size of one process > may well still be limited to 2GB... > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > ? ? ? ? ? - http://www.simplistix.co.uk > -- > http://mail.python.org/mailman/listinfo/python-list > From luke.leighton at googlemail.com Wed Jun 24 07:55:07 2009 From: luke.leighton at googlemail.com (lkcl) Date: Wed, 24 Jun 2009 04:55:07 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: <1f3c975f-9910-4139-8a45-589673ea920a@s6g2000vbp.googlegroups.com> On Jun 23, 10:59 pm, smartmobili wrote: > I wanted to know if you have some patch to compile python 3.x on mingw > platform because I found some > but doesn't work very well : you should compile a 2.N version. despite efforts and proof that the efforts passed all but about 8-12 regression tests, the python development core team deemed the 2.5 and the 2.7 mingw port efforts to be a waste of time. if you or anyone else disagrees with this, please do say so, on the python-dev mailing list and also in the bugtracker. at least one person has already done so: http://bugs.python.org/issue4954#msg85994 http://bugs.python.org/issue5046 states that i am not allowed to post "work in progress", despite it being significantly complete, and despite it being worthwhile to have added in as-is into the standard python repository. http://bugs.python.org/issue4954 is where a python2.5 mingw native _and_ cross-compile was successfully built. http://bugs.python.org/issue3871 is where roumen continues to provide the benefits of the continuous work that he is doing. when i last checked, he wasn't able to do native mingw32 builds but only cross- compiles, but that may have changed. the most significant difference between 4954 and 3871 at the time when my efforts were terminated due to python developer hostility is that i spent considerable time reducing the size of configure. firing up a new /bin/sh under MSYS, native, takes 0.7 seconds (and < 0.01 on a gnu/linux box). firing up a new /bin/sh under MSYS, running under Wine, took _well_ over two seconds. consequently, running an "unmodified" version of configure would take well over half an hour. by cutting most of configure out and going with a pre-prepared Config.h i was able to reduce that time down to (only) about 10 minutes. which is just about tolerable. like all free software projects, there is considerable additional work to be done: everything is "work in progress", but thanks to the python developers applying one standard to themselves on what constitutes "work in progress" and another for contributors, you will not get the benefit of my input and expertise until you (python users) can get the python developers to treat my efforts to help users with a little more respect. l. From dickinsm at gmail.com Wed Jun 24 08:32:13 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 24 Jun 2009 05:32:13 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> Message-ID: <9db988bc-2bc1-4505-95c9-76be34555372@z26g2000vbl.googlegroups.com> On Jun 24, 10:12?am, pdpi wrote: > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > perfectly fine NaN value? Other links: the IEEE 754 revision working group mailing list archives are public; there was extensive discussion about special values of pow and similar functions. Here's a relevant Google search: http://www.google.com/search?q=site:grouper.ieee.org++pow+annex+D The C99 rationale document has some explanations for the choices for special values in Annex F. Look at pages 179--182 in: http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf Note that the original IEEE 754-1985 didn't give specifications for pow and other transcendental functions; so a complete specification for pow appeared in the C99 standard before it appeared in the current IEEE standard, IEEE 754-2008. Thus C99 Annex F probably had at least some small influence on the choices made for IEEE 754-2008 (and in turn, IEEE 754-1985 heavily influenced C99 Annex F). My own take on all this, briefly: - floating-point numbers are not real numbers, so mathematics can only take you so far in deciding what the 'right' values are for special cases; pragmatics has to play a role too. - there's general consensus in the numerical and mathematical community that it's useful to define pow(0.0, 0.0) to be 1. - once you've decided to define pow(0.0, 0.0) to be 1.0, it's easy to justify taking pow(inf, 0.0) to be 1.0: the same limiting arguments can be used as justification; or one can use reflection formulae like pow(1/x, y) = 1/pow(x, y), or... - one piece of general philosophy used for C99 and IEEE 754 seems to have been that NaN results should be avoided when it's possible to give a meaningful non-nan value instead. - part of the reason that pow is particularly controversial is that it's really trying to be two different functions at once: it's trying to be both a generalization of the `analytic' power function x**y = exp(y*log(x)), for real y and positive real x, and in this context one can make a good argument that 0**0 should be undefined; but at the same time it's also used in contexts where y is naturally thought of as an integer; and in the latter context bad things happen if you don't define pow(0, 0) to be 1. I really should get back to work now. Mark From stephane at openerp.com Wed Jun 24 09:06:51 2009 From: stephane at openerp.com (Stephane Wirtel) Date: Wed, 24 Jun 2009 15:06:51 +0200 Subject: Decode a barcode ? Message-ID: <4A4224EB.1070309@openerp.com> Hi all, I would like to know if there is a way to decode a barcode with a library ? Thank you so much, Stephane -- Stephane Wirtel - "As OpenERP is OpenSource, please feel free to contribute." Developper - Technical Lecturer OpenERP OpenERP - Tiny SPRL Chaussee de Namur, 40 B-1367 Gerompont Tel: +32.81.81.37.00 Web: http://www.tiny.be Web: http://www.openerp.com Planet: http://www.openerp.com/planet/ Blog: http://stephane-wirtel-at-tiny.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: stephane.vcf Type: text/x-vcard Size: 443 bytes Desc: not available URL: From sakradevanamindra at gmail.com Wed Jun 24 09:09:37 2009 From: sakradevanamindra at gmail.com (Shoryuken) Date: Wed, 24 Jun 2009 06:09:37 -0700 (PDT) Subject: dynamically associate radio buttons with droplists References: Message-ID: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> On Jun 21, 8:43?pm, a... at pythoncraft.com (Aahz) wrote: > In article ,LeoBrugud? wrote: > > > > >Not being very familiar with python, nor with cgi/http, ?I intend to > >have 3 of buttons in a webpage, each of them is associate with a file > >(so I have 3 files, too) > > >What I would like to have is, when users choose a button, the droplist > >update automatically to load the contents of the associated file. > > >Can someone educate me the approach of this? > > Are you trying to do this without requiring the user to click the submit > button? ?If yes, you need to learn JavaScript (although I think there are > web frameworks that will auto-generate the JavaScript, you need to know > JavaScript in order to do debugging). > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha Thanks, and yes I want to do it without the submit button So python alone cannot do this? From chris at simplistix.co.uk Wed Jun 24 09:18:09 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 14:18:09 +0100 Subject: Decode a barcode ? In-Reply-To: <4A4224EB.1070309@openerp.com> References: <4A4224EB.1070309@openerp.com> Message-ID: <4A422791.3010501@simplistix.co.uk> Stephane Wirtel wrote: > I would like to know if there is a way to decode a barcode with a library ? What do you mean by decode? Do you mean starting with a .gif or something containing a barcode? Most barcode readers just act as keyboards, so you don't often need to do this ;-) If you mean something else, please elaborate! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From noname at nowhere.com Wed Jun 24 09:22:06 2009 From: noname at nowhere.com (Pegasus) Date: Wed, 24 Jun 2009 15:22:06 +0200 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS Message-ID: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> I need help with an implementation of your interpreter under PSPE/PSP. I need to know something about the C functions that are recalled by the interpreter when it executes a .pyc file. Our version of ndPython is very slow in execution respect to Carlos's StackLess Python (another product for PSP). We believe that the trouble is in a routine of our Nanodesktop libc that can be a bottleneck. But we don't know which can be the interested routine (string ? memory allocation ?) Please, help us. The product is complete, but we cannot release cause this problem. Thank you in advance. Filippo Battaglia From marco.bizzarri at gmail.com Wed Jun 24 09:23:04 2009 From: marco.bizzarri at gmail.com (Marco Bizzarri) Date: Wed, 24 Jun 2009 15:23:04 +0200 Subject: Decode a barcode ? In-Reply-To: <4A4224EB.1070309@openerp.com> References: <4A4224EB.1070309@openerp.com> Message-ID: <3f0d61c40906240623n22f44ea5xd1bb1061bfc1f46d@mail.gmail.com> If you're looking for a library in python to find barcodes inside an image, and then decoding it, I'm afraid you're out of luck; as far as I can tell, there is no such a library available. In case you're looking for the theory on how to do that, I think this group is not the best suited to post such a question :) (( Despite the fact that many people could know the answer )) regards Marco On Wed, Jun 24, 2009 at 3:06 PM, Stephane Wirtel wrote: > Hi all, > > I would like to know if there is a way to decode a barcode with a library ? > > Thank you so much, > > Stephane > -- > Stephane Wirtel - "As OpenERP is OpenSource, please feel free to > contribute." > Developper - Technical Lecturer OpenERP > OpenERP - Tiny SPRL > Chaussee de Namur, 40 > B-1367 Gerompont > Tel: +32.81.81.37.00 > Web: http://www.tiny.be > Web: http://www.openerp.com > Planet: http://www.openerp.com/planet/ > Blog: http://stephane-wirtel-at-tiny.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Jun 24 09:33:48 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 24 Jun 2009 09:33:48 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: Ross Ridge wrote: >I'm not sure what MIME would have to do with it, but Piet van Oostrum's >problem is almost certainly as result of the python.org mail to news >gateway mangling the References header. The missing postings he's looking >for don't actually exist. Just go up the thread one more posting and >you'll find the message that was being replied to. In article , Aahz wrote: >While that's also a bug in Mailman (I have a long-standing to-do item to >fix that), there are also plenty of posts that simply aren't showing up >in c.l.py. Well, the message IDs that Piet van Oostrum gave are symptomatic of the References header bug and and just like he described, my newsreader also shows Dennis Lee Bieber always replying to posts that don't exist. Other messages might be getting eaten by the gateway, but the missing posts that Piet is complaining about almost certainly never existed. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From motoom at xs4all.nl Wed Jun 24 09:35:15 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 24 Jun 2009 15:35:15 +0200 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: <4A422B93.2090305@xs4all.nl> Duncan Smith wrote: > IDLE now refuses to > respond to left click events (for code editing, menus etc. respond as > expected). If I right click, then left click I can move the cursor, but > that's not ideal. > > So, has anybody else had the left click issue with IDLE (and solved it)? Irritating problem, isn't it? I experience the same on FreeBSD with Tk8.5. I had to downgrade to Tk8.4, which has ugly fonts. See http://bugs.python.org/issue2995 "Moving the mouse over the text widget changes the cursor to the I-beam as expected, but click on text doesn't position the beam at the mouse position. It is also impossible to select text with the mouse. Selecting text with shift-arrow keys works, however." It's closed because it doesn't seem related to Python. 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 mail at microcorp.co.za Wed Jun 24 09:58:03 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 24 Jun 2009 15:58:03 +0200 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <007b01c9f4d4$287b8ec0$0d00a8c0@Hendrik> "Steven D'Aprano" wrote: >On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > >> In my universe the standard definition of "log" is different froim what >> log means in a calculus class > >Now I'm curious what the difference is. > Maybe he is a lumberjack, and quite all right... - Hendrik From rolf.wester at ilt.fraunhofer.de Wed Jun 24 10:10:35 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Wed, 24 Jun 2009 16:10:35 +0200 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: <4a4233d0$1@news.fhg.de> Hello, thank you all very much for your replies. I tried to simplify things and make the two versions as comparable as possible. I put the C++ part of the program into a shared object libff.so. For the exe the main function is linked against this shared object. For the python stuff I made an interface consiting of only one function call_solver with the same code that has the main function used for the exe. Then I created a wrapper for this interface using swig and linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code just imports _ff and calls call_solver wich creates an object of the class Solver and calls its member solve (the main function of the exe does the same). I included some code for timing into the C++-code. #include //beginning of solve clock_t t0 = clock(); ... clock_t t1 = clock(); //end of solve cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The sources are compiled using the flags -fPIC -O3. Timing: 1) time python ff.py time used = 3.74 real 0m3.234s user 0m3.712s sys 0m0.192s 2) time ff time used = 2.19 real 0m3.170s user 0m2.088s sys 0m0.168s I tried some other optimizations: -O0: 1) time used = 21.91 real 0m21.568s user 0m22.001s sys 0m0.160s 2) time used = 20.87 real 0m22.206s user 0m20.989s sys 0m0.148s -O1 1) time used = 4.04 real 0m3.660s user 0m4.000s sys 0m0.160s 2) time used = 2.72 real 0m3.454s user 0m2.648s sys 0m0.164s It seems that there is an overhead of about 2 secs within the C++-code. I'm going to try this out with a problem that takes much more time than the present one. Regards Rolf Carl Banks wrote: > On Jun 23, 7:20 am, Rolf Wester wrote: >> Philip Semanchuk wrote: >> >>> On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: >>>> Hi, >>>> I have a C++ program that I would like to steer using Python. I made the >>>> wrapper using swig and linked the code (without the main function) into >>>> a shared object. My Python script loads the extension and calls a >>>> function of the C-extension, the rest runs entirely within the >>>> C-extension. For comparison I compiled the code including the main >>>> function with the same compilation options and linked all into an exe. >>>> The main function of the exe calls the same function as my Python script >>>> does. Surprisingly the code in the Python C-extension runs twice as long >>>> as the same code in the exe. Does anyone know what could be the reason >>>> for this behaviour? >>> If the runtime of the C/C++ code is short, the time spent initializing >>> the Python interpreter might have a big impact on the runtime of the >>> Python version. >> The runtime is about 2.5 sec and 5.0 sec respectively. I not only use >> the time command to measure the time consumed but I also measure the >> time within the C-code using clock() and get similar result. So the >> Python startup time is not the reason for the runtime difference I >> found. Thank you anyway. > > We can't really help you much unless you give us more details about > what you did (how did you built it, how did you time it, and how are > you calling the C extension from Python). All we can do is throw out > possible ideas, and I will toss out a few, but if that's not it you'll > have to post details. > > Are you building the extension with the same optimization flags as the > compiler? > > Are you calling the C code repeatedly from inside a Python loop? > From invalid at invalid Wed Jun 24 10:10:43 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 24 Jun 2009 09:10:43 -0500 Subject: Converting Python code to C/C++ References: Message-ID: On 2009-06-24, Couper, Tim T wrote: > Your prof. may find this thread of interest > > http://mail.python.org/pipermail/python-list/2000-June/039779.html > > My experience is that developers who know C and C++ can be productive in > less than 1 week in python, and find it liberating, and educational, to > do so. And at the same time they will have added a second language to > their toolbox. As Kurt points out, learning C/C++ takes considerably > longer (weeks/months to attain a level of competence). I agree. Your professor is deluded and knows nothing about software development [not that either is particularly unusual in an academic setting]. Converting a Python program to C or C++ is a complete waste of time (both now _and_ later) unless there are severe, insurmountable performance problems with the Python version. Python is a far, far better language for both real-world production application development and for algorithm R&D. With Python, you spend your time working on algorithms and solving real-world problems. In C or C++, you spend your time fighting with the bugs in your code that are preventing the program from running. An algorithm that takes a few hours to implement and test in Python will take weeks in C or C++. That said, you'll be niether the first nor last person to be forced by a professor or manager to waste weeks or months of time doing something that's obviously stupid and futile from a technical point of view. -- Grant Edwards grante Yow! What's the MATTER at Sid? ... Is your BEVERAGE visi.com unsatisfactory? From donnyf at gmail.com Wed Jun 24 10:23:35 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 07:23:35 -0700 (PDT) Subject: Reading then sending new parts of a log file Message-ID: Hey guys. I'm trying to work up a little program that will send any new lines written to a file (log file from my home automation software) to me via instant message. I've gotten the instant message sending part figured out using xmpppy. I've done a few things with Python in the past but I am in no means more than a beginner/hacker. Can someone tell me what commands/ modules/etc exist for monitoring and parsing a file for new information that I can then send to my IM sending function? I am not asking for anyone to write the code but merely a push in the right direction. Thanks! From pdpinheiro at gmail.com Wed Jun 24 10:35:17 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 07:35:17 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 24, 2:58?pm, "Hendrik van Rooyen" wrote: > "Steven D'Aprano" wrote: > >On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > > >> In my universe the standard definition of "log" is different froim what > >> log means in a calculus class > > >Now I'm curious what the difference is. > > Maybe he is a lumberjack, and quite all right... > > - Hendrik Or perhaps he works in a sewage facility. But yeah, Log2 and LogE are the only two bases that make "natural" sense except in specialized contexts. Base 10 (and, therefore, Log10) is an artifact of having that 10 fingers (in fact, whatever base you use, you always refer to it as base 10). From aahz at pythoncraft.com Wed Jun 24 10:37:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 07:37:23 -0700 Subject: dynamically associate radio buttons with droplists References: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> Message-ID: In article <16b382ee-a3ae-46ee-88fd-d87fc40d208d at g20g2000vba.googlegroups.com>, Shoryuken wrote: >On Jun 21, 8:43=A0pm, a... at pythoncraft.com (Aahz) wrote: >> In article .com>,LeoBrugud=A0 wrote: >>> >>>Not being very familiar with python, nor with cgi/http, =A0I intend to >>>have 3 of buttons in a webpage, each of them is associate with a file >>>(so I have 3 files, too) >>> >>>What I would like to have is, when users choose a button, the droplist >>>update automatically to load the contents of the associated file. >> >> Are you trying to do this without requiring the user to click the submit >> button? =A0If yes, you need to learn JavaScript (although I think there a= >re >> web frameworks that will auto-generate the JavaScript, you need to know >> JavaScript in order to do debugging). > >Thanks, and yes I want to do it without the submit button > >So python alone cannot do this? Correct; you need to have code run in the browser, and few browsers support Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From gagsl-py2 at yahoo.com.ar Wed Jun 24 10:48:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Jun 2009 11:48:50 -0300 Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> <1f3c975f-9910-4139-8a45-589673ea920a@s6g2000vbp.googlegroups.com> Message-ID: En Wed, 24 Jun 2009 08:55:07 -0300, lkcl escribi?: > On Jun 23, 10:59 pm, smartmobili wrote: >> I wanted to know if you have some patch to compile python 3.x on mingw >> platform because I found some >> but doesn't work very well : > > you should compile a 2.N version. > [...] > http://bugs.python.org/issue5046 states that i am not allowed to > post "work in progress", despite it being significantly complete, and > despite it being worthwhile to have added in as-is into the standard > python repository. What you've been told is not to use the Python bug tracker as a blog. You could write about your progresses in *another* place, and maybe from time to time post a link here so interested people is aware of it. > by cutting most of configure out and going with a pre-prepared > Config.h i was able to reduce that time down to (only) about 10 > minutes. That's fine, the "official" Windows build uses a hand written config.h too. > like all free software projects, there is considerable additional > work to be done: everything is "work in progress", but thanks to the > python developers applying one standard to themselves on what > constitutes "work in progress" and another for contributors, you will > not get the benefit of my input and expertise until you (python users) > can get the python developers to treat my efforts to help users with a > little more respect. If you expect your work to be taken seriously, work seriously. Randomly changing code until some symptom disappears isn't a very good practice, I'd say. Try to polish the patches a little until you are happy with them, and only then submit them. -- Gabriel Genellina From grenander at gmail.com Wed Jun 24 10:57:23 2009 From: grenander at gmail.com (Art) Date: Wed, 24 Jun 2009 07:57:23 -0700 (PDT) Subject: isinstance(obj, type(obj)) == True? Message-ID: I have the following problem: ipdb> p type(self) ipdb> isinstance(self, component.BiasComponent) False I thought that isinstance(obj, type(obj)) == True. The specific problem is when I try to call the super of a class and it only occurs after 'reload'ing the file in the interpreter. What am I messing up by reloading? It doesn't occur if I using for the first time in a fresh interpreter session. ---> 32 class BiasComponent(ModelComponent): 33 def __init__(self, g, model): 34 super(BiasComponent, self).__init__(g, model) TypeError: super(type, obj): obj must be an instance or subtype of type Seems like the self passed to __init__ is messed up in some way. Thanks! From philip.groeger at googlemail.com Wed Jun 24 10:59:09 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Wed, 24 Jun 2009 16:59:09 +0200 Subject: Animate Surface / Clear Scene (vpython) Message-ID: <386f361c0906240759i653539f7pc0408e239d147ae4@mail.gmail.com> Hi there! I just found a nice vpython example program on how to create surfaces (its one of the standard examples if you download vpython ... called "faces_heightfield" - just search for that). Is there a way to animate this surface? All my attempts resulted in creating just another surface without deleting the old one. Or is there a "clear scene from all objects" command? If animating such a surface in vpython is too complicated / slow / etc ... I have to try mayavi. But I already know vpython ;) thanks alot -Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From schwehr at gmail.com Wed Jun 24 11:22:19 2009 From: schwehr at gmail.com (Kurt Schwehr) Date: Wed, 24 Jun 2009 08:22:19 -0700 (PDT) Subject: A superclass using a child classes' methods Message-ID: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> I'm trying to build an OO system for encoding and decoding datapackets. I'd like the parent class to have an encode function that uses each of the child classes' packing methods. It appears that this works for attributes of children accessed by the parent, but not for methods. Is that right? For attributes I found this example, where the alphabet attribute is set in the child, but used in the parent. http://www.pasteur.fr/formation/infobio/python/ch19s04.html Should I just set an attribute in the child class and then call the super's functionality making is pull the data from the attribute? Thanks, -kurt From torriem at gmail.com Wed Jun 24 11:49:07 2009 From: torriem at gmail.com (Michael Torrie) Date: Wed, 24 Jun 2009 09:49:07 -0600 Subject: A superclass using a child classes' methods In-Reply-To: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <4A424AF3.5020103@gmail.com> Kurt Schwehr wrote: > I'm trying to build an OO system for encoding and decoding > datapackets. I'd like the parent class to have an encode function > that uses each of the child classes' packing methods. It appears that > this works for attributes of children accessed by the parent, but not > for methods. Is that right? For attributes I found this example, > where the alphabet attribute is set in the child, but used in the > parent. There is no difference between an attribute and a method. They are both attributes. One happens to be callable and is a method call. I just tried it and it seemed to work fine. In my old C++ days, I believe you would call this scenario virtual classes. In python, since everything is dynamic and computed at runtime, I think you can just refer to any attribute in the instance and as long as someone down the road provides it, it would work. For example: class parent(object): def test(self): print self.child_attribute self.child_method() class child(parent): def __init__(self): self.child_attribute = 'child' def child_method(self): print 'child method is called' c=child() c.test() This should display "child" and "child method is called" From buzzard at urubu.freeserve.co.uk Wed Jun 24 11:54:26 2009 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Wed, 24 Jun 2009 16:54:26 +0100 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: Michiel Overtoom wrote: > > Duncan Smith wrote: > >> IDLE now refuses to >> respond to left click events (for code editing, menus etc. respond as >> expected). If I right click, then left click I can move the cursor, but >> that's not ideal. >> >> So, has anybody else had the left click issue with IDLE (and solved it)? > > Irritating problem, isn't it? I experience the same on FreeBSD with Tk8.5. > I had to downgrade to Tk8.4, which has ugly fonts. > > See http://bugs.python.org/issue2995 > > "Moving the mouse over the text widget changes the cursor to the I-beam > as expected, but click on text doesn't position the beam at the mouse > position. It is also impossible to select text with the mouse. > Selecting text with shift-arrow keys works, however." > > It's closed because it doesn't seem related to Python. > > Greetings, > Thanks for the responses. I searched far and wide, and couldn't find anyone else having the same problem. I have Tk 8.4.19-2 and 8.5.6-3 on this machine. I remember changing the font a while back (before upgrading to Jaunty) because it was barely readable. I guess the issue is with Tk 8.5.6-3. Just found I can move the cursor (by left clicking) if I hold the control key down. Shift arrow keys works for selection. Still not so good. Cheers. Duncan From brian at sweetapp.com Wed Jun 24 11:56:42 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 24 Jun 2009 16:56:42 +0100 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <4A424CBA.9040103@sweetapp.com> You could start by reading this: http://catb.org/~esr/faqs/smart-questions.html Cheers, Brian Pegasus wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. > > I need to know something about the C > functions that are recalled by the interpreter > when it executes a .pyc file. > > Our version of ndPython is very slow in > execution respect to Carlos's StackLess > Python (another product for PSP). > > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) > > > Please, help us. The product is complete, > but we cannot release cause this problem. > > Thank you in advance. > Filippo Battaglia > > From icanbob at gmail.com Wed Jun 24 12:01:13 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 24 Jun 2009 09:01:13 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: On Jun 23, 11:49 am, Kurt Smith wrote: > On Mon, Jun 22, 2009 at 9:49 PM, Andras > > > > Pikler wrote: > > Hi! > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > > and I am at a loss. > > > Long: I?m doing research/programming for a professor, and we are working > > with MIDI files (a type of simple music file). The research deals with > > generating variations from a musical melody; currently, my Python code uses > > a Python midi package I found online to read the notes in question from a > > midi file, about 350 lines of my own code to generate a variation based on > > these notes and the professor?s algorithms, and finally the package again to > > write the new melody to another midi file. > > > Now, my professor would like to have this exact code in C/C++, as she > > believes C is more compatible with MATLAB, and wants the code to be > > available in multiple languages in case a programmer works for her in the > > future who knows C but not Python. While I know a tiny bit of C (emphasis on > > the tiny), I would much prefer if there were some sort of automatic compiler > > I could use to turn my Python code into C than taking a week or two or three > > to learn the minimum I need about C, find a way to access MIDI files in it, > > and rewrite all of my code. > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > > Python midi package I?m using uses modules which Shedskin does not support. > > Otherwise, I haven?t found much. Is there anything out there to help me do > > this? If not, from anyone who has experience in this regard, how daunting > > should I expect this to be? > > Taking on C from a cold start and being able to handle the ins and > outs of interfacing with Python isn't something that's feasible in > 'two or three weeks'. Here are a couple of options -- take 'em or > leave 'em: > > 1) Put the code in Cython:http://www.cython.org/ (full disclosure: > I'm doing a GSoC project with Cython). It will convert pretty much > any python code into C code (even closures are supported in the most > recent version, I think), and the C code can then be compiled into an > extension module. > > The only problem with the above is the C code isn't, at first blush, > easy to read. Nor is it supposed to be changed by the user. So that > leads us to option... > > 2) Write the core functionality in C yourself, and then wrap those C > functions in Cython. You'll want to take a look at the documentation: > > http://docs.cython.org/ > > and, more specifically on wrapping C code: > > http://docs.cython.org/docs/external_C_code.html > > I don't think you'll be able to avoid learning C, though. > > Kurt 3) use Python-SIMPL to connect your C module to your Python module using a 5 function API without any need for wrappers. ie. have your cake and eat it too http://www.icanprogram.com/06py/main.html bob From Scott.Daniels at Acm.Org Wed Jun 24 12:10:50 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:10:50 -0700 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: Couper, Tim T wrote: > ... My experience is that developers who know C and C++ can be productive > in less than 1 week in python, and find it liberating, and educational, to > do so. And at the same time they will have added a second language to > their toolbox. As Kurt points out, learning C/C++ takes considerably > longer (weeks/months to attain a level of competence). Yup. Remember that "be productive" is not quite the same as "master." The nice thing is that the mastery comes on a gentle slope, adding to your productivity without requiring drastic rethinking of all you understood (as is done to physics students, for example). > Python is now used in a number of universities as the language in which > to teach comp sci undergraduate courses (I know of Leeds, & MIT), > biomathematics, and my daughter just finished her PhD in speech and > language processing at Edinburgh .. using python and Matplotlib .. as > the extensive C/C++ libraries in that infomatics world are wrapped in > python - and the MSc Comp Sci course has replaced Java as the language > for teaching with Python. As a data point, Georgia Tech (I believe) had a two-semester Computer Science intro course in C++. In introducing a Python intro course, they provided for a few years both the Python and the C++ first semester, and kept the C++ second semester. They found no measurable difference in the performance on the second course (still in C++) even though the Python course people had to learn a new language in addition to learning the rest of the coursework. The first course is now in Python, since at the end of the two-semester sequence they know two languages and apparently suffer no compensating loss. --Scott David Daniels Scott.Daniels at Acm.Org From xelothath13 at gmail.com Wed Jun 24 12:11:22 2009 From: xelothath13 at gmail.com (humn) Date: Wed, 24 Jun 2009 09:11:22 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? Message-ID: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> I'm writing a script to convert Latex commands to bbcode by using the str.replace function and I'm confused as to why this works: if '\chapter' in line: line = line.replace('\chapter{', '[b][u]') line = line.replace('}', '[/b][/u]') but this doesn't: if '\title' in line: line = line.replace('\title{', '[size=150][b]') line = line.replace('}', '[/b][/size]') Here is the short version of the script: infile = open('test.tex') outfilename = infile.name.partition('.')[0] + '.bbcode' outfile = open(outfilename, 'w') for line in infile: if '\title' in line: line = line.replace('\title{', '[size=150][b]') line = line.replace('}', '[/b][/size]\n') if '\chapter' in line: line = line.replace('\chapter{', '[b][u]') line = line.replace('}', '[/u][/b]') outfile.write(line) infile.close() outfile.close() From bryanvick at gmail.com Wed Jun 24 12:17:31 2009 From: bryanvick at gmail.com (Bryan) Date: Wed, 24 Jun 2009 09:17:31 -0700 (PDT) Subject: Get name of class without instance Message-ID: Given a class: class Foo(object): pass How can I get the name "Foo" without having an instance of the class? str(Foo) gives me more than just the name Foo. "__main__.Account" Foo.__class__.__name__ gives me "type" I don't want to do: Foo().__class__.__name__ if possible. I would rather avoid the constructor. I just want to get a string "Foo" From skip at pobox.com Wed Jun 24 12:21:57 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 24 Jun 2009 11:21:57 -0500 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> Message-ID: <19010.21157.212566.880066@montanaro.dyndns.org> Mag> s=0 Mag> #Takes the longest here Mag> for y in fs: Mag> continue Mag> a=y.split(',') Mag> s=s+1 Mag> dset.resize(s,axis=0) Mag> fs.close() Mag> f.close() Mag> This works but just takes a VERY long time. Mag> Any way to optimize this? I sort of suspect you're missing something there. Is there nothing between the for loop and the overly indented continue statement? At any rate, try using the csv module to read in your records: import csv reader = csv.reader(fs) ... for s, row in enumerate(reader): dset.resize(s, axis=0) -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From elwinter at verizon.net Wed Jun 24 12:22:10 2009 From: elwinter at verizon.net (Eric Winter) Date: Wed, 24 Jun 2009 09:22:10 -0700 (PDT) Subject: Unable to get Tkinter menubar to appear under OS X Message-ID: <3737fd18-4973-4cc3-914d-fbdefdbbb8a7@t10g2000vbg.googlegroups.com> Hi all. I've googled this issue several times and come up dry. Here's the situation: I have a X-windows build of Tkinter for Python built on an OS X machine (10.4 or 10.5, same issue). This is not the Aqua version of Tk, but Tk built from source using X-Window support. I also use a from- source build of Python, not the system Python. I don't like this arrangement, but project requirements (allegedly) dictate this approach. When I run any application using that copy of Tkinter and that copy of Python, everything seems to work fine except menus - the code which creates the menus runs, but no menus appear, either in the window or at the top of the screen. Am I required to use the Aqua version of Tk on OS X? If not, do I need to do something special on OS X when I built Tk and/or Python? Any hints here would be greatly appreciated. Thanks, Eric Winter Fermi Science Support Center NASA Goddard Space Flight Center From jeanmichel at sequans.com Wed Jun 24 12:23:28 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Jun 2009 18:23:28 +0200 Subject: A superclass using a child classes' methods In-Reply-To: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <4A425300.4060508@sequans.com> Kurt Schwehr wrote: > I'm trying to build an OO system for encoding and decoding > datapackets. I'd like the parent class to have an encode function > that uses each of the child classes' packing methods. It appears that > this works for attributes of children accessed by the parent, but not > for methods. hell no, this works for methods as well. > Is that right? For attributes I found this example, > where the alphabet attribute is set in the child, but used in the > parent. > > http://www.pasteur.fr/formation/infobio/python/ch19s04.html > > Should I just set an attribute in the child class and then call the > super's functionality making is pull the data from the attribute? > > Thanks, > -kurt > class Parent: def foo(self): raise NotImplementedError() # virtual method, it has to be overriden by childs def bar(self): self.foo() class Son(Parent): def foo(self): print "I'm your son" class Daughter(Parent): def foo(self): print "I'm your daughter" Son().bar() "I'm your son" Declaring the foo method at the Parent level is not required. But it's a good practice: explicit > implicit and it helps to write proper documentation. Jean-Michel From jeanmichel at sequans.com Wed Jun 24 12:24:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Jun 2009 18:24:37 +0200 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <4A425345.4070703@sequans.com> Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > > >>> Foo.__name__ 'Foo' 8-) JM From mail at timgolden.me.uk Wed Jun 24 12:25:21 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Jun 2009 17:25:21 +0100 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <4A425371.3050903@timgolden.me.uk> Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > You are going to kick yourself: class Foo (object): pass print Foo.__name__ TJG From Scott.Daniels at Acm.Org Wed Jun 24 12:26:30 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:26:30 -0700 Subject: Dictionary self lookup In-Reply-To: References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: Norberto Lopes wrote: > On Jun 24, 1:21 pm, "Diez B. Roggisch" wrote: >> Norberto Lopes wrote: ... >>> config = {"home" : "/home/test"} >>> config["user1"] = config["home"] + "/user1" >>> config["user2"] = config["home"] + "/user2" >>> config["python-dev"] = config["user1"] + "/py-dev" I'd write this as: home = "/home/test" config = {"home" : home, "user1" : home + "/user1", "user2" : home + "/user2", "python-dev" : home + "/py-dev"} or even (if the list gets much longer): home = "/home/test" config = {"home" : "", "user1" : "/user1", "user2" : "/user2", "python-dev" : "/py-dev"} for key, entry in config.iteritems(): config[key] = home + entry --Scott David Daniels Scott.Daniels at Acm.Org From unayok at gmail.com Wed Jun 24 12:28:34 2009 From: unayok at gmail.com (unayok) Date: Wed, 24 Jun 2009 09:28:34 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: On Jun 24, 12:11?pm, humn wrote: > but this doesn't: > > if '\title' in line: > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > ? ? ? ? line = line.replace('}', '[/b][/size]') \t is an escaped character. so, '\title' will look for 'itle' Two ways to fix this: 1. use r'\title' 2. use '\\title' \c does not represent a known escape sequence so it remains two characters. From bryanvick at gmail.com Wed Jun 24 12:28:56 2009 From: bryanvick at gmail.com (Bryan) Date: Wed, 24 Jun 2009 09:28:56 -0700 (PDT) Subject: Get name of class without instance References: Message-ID: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> On Jun 24, 9:25?am, Tim Golden wrote: > Bryan wrote: > > Given a class: > > > class Foo(object): > > ? ? pass > > > How can I get the name "Foo" without having an instance of the class? > > > str(Foo) gives me more than just the name Foo. ? "__main__.Account" > > Foo.__class__.__name__ gives me "type" > > > I don't want to do: > > Foo().__class__.__name__ if possible. ?I would rather avoid the > > constructor. ?I just want to get a string "Foo" > > You are going to kick yourself: > > class Foo (object): pass > > print Foo.__name__ > > TJG Whoops. How come dir(Foo) does not show __name__? That is how I was investigating the possibilities. From jcd at sdf.lonestar.org Wed Jun 24 12:36:19 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 24 Jun 2009 12:36:19 -0400 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <1245861379.13858.0.camel@aalcdl07> On Wed, 2009-06-24 at 09:17 -0700, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > I'll give you a hint: >>> Foo().__class__ is Foo True From schwehr at gmail.com Wed Jun 24 12:37:11 2009 From: schwehr at gmail.com (Kurt Schwehr) Date: Wed, 24 Jun 2009 09:37:11 -0700 (PDT) Subject: A superclass using a child classes' methods References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <87ccaa96-6462-45d3-8108-f09a94ae6797@l28g2000vba.googlegroups.com> Jean-Michel, Thanks for the excellent response setting me straight. Now to figure out what dumb thing I did to make my code not work... -kurt On Jun 24, 12:23?pm, Jean-Michel Pichavant wrote: > Kurt Schwehr wrote: > > I'm trying to build an OO system for encoding and decoding > > datapackets. ?I'd like the parent class to have an encode function > > that uses each of the child classes' packing methods. ?It appears that > > this works for attributes of children accessed by the parent, but not > > for methods. > [clear example of it working] > > Declaring the foo method at the Parent level is not required. But it's a > good practice: explicit > implicit and it helps to write proper > documentation. > > Jean-Michel From Scott.Daniels at Acm.Org Wed Jun 24 12:37:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:37:57 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Peter Otten wrote: > ... > If you need more than a few name value pairs it pays to put the data in a > dictionary first: > > # assuming that values always consist of a single line > with open(filename) as instream: > lines = (line.strip() for line in lines) > lookup = dict(zip(lines, lines)) > print lookup["Data2"] > print lookup["Data3"] Little bit of a fluff-up here. Perhaps something like: with open(filename) as instream: lines = (line.strip() for line in instream) lookup = dict(zip(lines[::2], lines[1::2])) The other way to do it is: lookup = {} with open(filename) as instream: gen = (line.strip() for line in instream) for key in gen: lookup[key] = next(gen) --Scott David Daniels Scott.Daniels at Acm.Org From kd at kendyck.com Wed Jun 24 12:38:20 2009 From: kd at kendyck.com (Ken Dyck) Date: Wed, 24 Jun 2009 09:38:20 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: On Jun 24, 12:11?pm, humn wrote: > I'm confused as to why this works: > > if '\chapter' in line: > ? ? ? ? line = line.replace('\chapter{', '[b][u]') > ? ? ? ? line = line.replace('}', '[/b][/u]') > > but this doesn't: > > if '\title' in line: > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > ? ? ? ? line = line.replace('}', '[/b][/size]') In string literals---whether they use single or double quotes--- backslashes are used as escape characters to denote special characters. The '\t' in '\title' is interpreted as the tab character so the string that your code is trying to find and replace is actually 'itle'. There isn't any special meaning for '\c', so python interprets that to mean a backslash followed by the character 'c', which is why the first case works. There are two ways to solve the problem: 1. Prefix the string literal with an 'r', indicating that backslashes should not be treated as escape characters (eg. r'\title'), or 2. Use a double backslash in the string literal to indicate that you mean a literal backslash, not an escape character (eg. '\\title') The official documentation, including a list of the special escape sequences, is here: http://docs.python.org/reference/lexical_analysis.html#string-literals -Ken From xelothath13 at gmail.com Wed Jun 24 12:39:05 2009 From: xelothath13 at gmail.com (humn) Date: Wed, 24 Jun 2009 09:39:05 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> On Jun 24, 12:28?pm, unayok wrote: > On Jun 24, 12:11?pm, humn wrote: > > > but this doesn't: > > > if '\title' in line: > > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > > ? ? ? ? line = line.replace('}', '[/b][/size]') > > \t is an escaped character. so, '\title' will look for > 'itle' > > Two ways to fix this: > > 1. use r'\title' > > 2. use '\\title' > > \c does not represent a known escape sequence so it remains two > characters. Thank you! Didn't know that it would escape characters with single quotes. I thought it only did that with double quotes. From dstanek at dstanek.com Wed Jun 24 12:47:59 2009 From: dstanek at dstanek.com (David Stanek) Date: Wed, 24 Jun 2009 12:47:59 -0400 Subject: Get name of class without instance In-Reply-To: References: Message-ID: Try Foo.__name__ if Foo is a class object. On 6/24/09, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from my mobile device David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From Scott.Daniels at Acm.Org Wed Jun 24 12:57:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:57:31 -0700 Subject: Reading then sending new parts of a log file In-Reply-To: References: Message-ID: Chuck Connors wrote: > Hey guys. I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? I am not > asking for anyone to write the code but merely a push in the right > direction. > > Thanks! What OS and version, what Python and version. --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Wed Jun 24 12:58:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 17:58:48 +0100 Subject: Why is it that str.replace doesn't work sometimes? In-Reply-To: <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: <4A425B48.4020509@mrabarnett.plus.com> humn wrote: > On Jun 24, 12:28 pm, unayok wrote: >> On Jun 24, 12:11 pm, humn wrote: >> >>> but this doesn't: >>> if '\title' in line: >>> line = line.replace('\title{', '[size=150][b]') >>> line = line.replace('}', '[/b][/size]') >> \t is an escaped character. so, '\title' will look for >> 'itle' >> >> Two ways to fix this: >> >> 1. use r'\title' >> >> 2. use '\\title' >> >> \c does not represent a known escape sequence so it remains two >> characters. > > Thank you! Didn't know that it would escape characters with single > quotes. I thought it only did that with double quotes. There's no difference between the two types of quote character. Python itself prefers to show ' when printing, unless " would be clearer: >>> # The empty string. >>> '' '' >>> "" '' >>> # Quoting the other type. >>> '"' '"' >>> "'" "'" >>> # Quoting the same type. >>> '\'' "'" >>> "\"" '"' From pdpinheiro at gmail.com Wed Jun 24 13:06:05 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 10:06:05 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: 9db988bc-2bc1-4505-95c9-76be34555372@z26g2000vbl.googlegroups.com Message-ID: <3a1eff07-8f85-4f85-bff8-58d70c3eaf6c@p23g2000vbl.googlegroups.com> On Jun 24, 1:32?pm, Mark Dickinson wrote: > On Jun 24, 10:12?am, pdpi wrote: > > > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > > perfectly fine NaN value? > > Other links: ?the IEEE 754 revision working group mailing list > archives are public; ?there was extensive discussion about > special values of pow and similar functions. ?Here's a relevant > Google search: > > http://www.google.com/search?q=site:grouper.ieee.org++pow+annex+D > > The C99 rationale document has some explanations for the > choices for special values in Annex F. ?Look at pages 179--182 > in: > > http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf > > Note that the original IEEE 754-1985 didn't give specifications > for pow and other transcendental functions; ?so a complete > specification for pow appeared in the C99 standard before it > appeared in the current IEEE standard, IEEE 754-2008. ?Thus > C99 Annex F probably had at least some small influence on the > choices made for IEEE 754-2008 (and in turn, IEEE 754-1985 > heavily influenced C99 Annex F). > > My own take on all this, briefly: > > ?- floating-point numbers are not real numbers, so mathematics > ? ?can only take you so far in deciding what the 'right' values > ? ?are for special cases; ?pragmatics has to play a role too. > > ?- there's general consensus in the numerical and mathematical > ? ?community that it's useful to define pow(0.0, 0.0) to be 1. > > ?- once you've decided to define pow(0.0, 0.0) to be 1.0, it's > ? ?easy to justify taking pow(inf, 0.0) to be 1.0: ?the same > ? ?limiting arguments can be used as justification; ?or one can > ? ?use reflection formulae like pow(1/x, y) = 1/pow(x, y), or... > > ?- one piece of general philosophy used for C99 and IEEE 754 > ? ?seems to have been that NaN results should be avoided > ? ?when it's possible to give a meaningful non-nan value instead. > > ?- part of the reason that pow is particularly controversial > ? ?is that it's really trying to be two different functions > ? ?at once: ?it's trying to be both a generalization of the > ? ?`analytic' power function x**y = exp(y*log(x)), for > ? ?real y and positive real x, and in this context one can > ? ?make a good argument that 0**0 should be undefined; but > ? ?at the same time it's also used in contexts where y is > ? ?naturally thought of as an integer; and in the latter > ? ?context bad things happen if you don't define pow(0, 0) > ? ?to be 1. > > I really should get back to work now. > > Mark Thanks for the engrossing read (and damn you for making me waste valuable work hours). After perusing both C99 and the previous presentation on IEEE754, I find myself unconvinced regarding the special cases. It just stinks of bug-proneness, and I fail to see how assuming common values for exceptional cases relieves you from testing for those special cases and getting them behaving right (in an application-specific way) just the same. From tjreedy at udel.edu Wed Jun 24 13:07:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 13:07:36 -0400 Subject: Best way to enumerate classes in a module In-Reply-To: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. That notice primarily refers to the fact that the special names (of __xxx__ form) returned are implementation and version dependent, and may not be complete in the sense that dir(ob) may not return __xyz__ even though ob.__xyz__ exists and can be retrieved. If you are only interested in regular-name attribute of ob, let your fear fly away. From rridge at csclub.uwaterloo.ca Wed Jun 24 13:17:53 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 24 Jun 2009 13:17:53 -0400 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, > and it all worked. Not really, Usenet was archived before DejaNews arrived on the scene. I can find plenty of my posts from before then. Regardless, Usenet works better now that searchable archives are available on the WWW. Dennis Lee Bieber wrote: > If there were an "X-no-google" option I'd switch... I have no real >concerns about archives /accessed via NNTP through some paid-traceable >account/... But look at how much effort Google has to go through in the >attempt of obliterating email addresses in the attempt at minimizing >collection of such by spammers... Uh... this makes no sense. X-No-Archive does nothing to prevent spammers from harvesting your e-mail address. Your current posts are available to spammers for free on NNTP and WWW servers all over the 'net with or without the header. At least Google does try to hide your e-mail address, other WWW sites don't bother: http://www.rhinocerus.net/forum/lang-python/571842-re-pyserial-question.html You'd be more protected from spammers with an X-Google-Only option. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From clp2 at rebertia.com Wed Jun 24 13:22:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 10:22:39 -0700 Subject: isinstance(obj, type(obj)) == True? In-Reply-To: References: Message-ID: <50697b2c0906241022v1b290e34m75d5f58ab173b140@mail.gmail.com> On Wed, Jun 24, 2009 at 7:57 AM, Art wrote: > I have the following problem: > > ipdb> p type(self) > > > ipdb> isinstance(self, component.BiasComponent) > False > > I thought that isinstance(obj, type(obj)) == True. > > The specific problem is when I try to call the super of a class and it > only occurs after 'reload'ing the file in the interpreter. What am I > messing up by reloading? It doesn't occur if I using for the first > time in a fresh interpreter session. > > ---> 32 class BiasComponent(ModelComponent): > ? ? ?33 ? ? def __init__(self, g, model): > ? ? ?34 ? ? ? ? super(BiasComponent, self).__init__(g, model) > > TypeError: super(type, obj): obj must be an instance or subtype of > type > > Seems like the self passed to __init__ is messed up in some way. I would guess you're running into one of the caveats of using reload(); see http://docs.python.org/library/functions.html#reload Printing out id(BiasComponent) and id(type(obj)) both before and after the reload() call should be instructive. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Jun 24 13:25:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 13:25:12 -0400 Subject: Converting Python code to C/C++ In-Reply-To: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> References: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Message-ID: >> Short: I need to turn a Python program that I (mostly) wrote into C >> code, and I am at a loss. >> >> Now, my professor would like to have this exact code in C/C++, as she >> believes C is more compatible with MATLAB, and wants the code to be >> available in multiple languages in case a programmer works for her in >> the future who knows C but not Python. While I know a tiny bit of C >> (emphasis on the tiny), Your professor should wait until your Python version is complete and in final form and until a C version is needed. Then hire someone competent in both languages to do the translation. From __peter__ at web.de Wed Jun 24 13:29:19 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 19:29:19 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Scott David Daniels wrote: > Peter Otten wrote: >> with open(filename) as instream: >> lines = (line.strip() for line in lines) >> lookup = dict(zip(lines, lines)) > Little bit of a fluff-up here. Sorry, it should have been with open(filename) as instream: lines = (line.strip() for line in instream) lookup = dict(zip(lines, lines)) > Perhaps something like: > > with open(filename) as instream: > lines = (line.strip() for line in instream) > lookup = dict(zip(lines[::2], lines[1::2])) Tu quoque ;) Peter From clp2 at rebertia.com Wed Jun 24 13:31:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 10:31:02 -0700 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <50697b2c0906241031i4178b67bx1045d0cf684a15b0@mail.gmail.com> On Wed, Jun 24, 2009 at 6:22 AM, Pegasus wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. > > I need to know something about the C > functions that are recalled by the interpreter > when it executes a .pyc file. > > Our version of ndPython is very slow in > execution respect to Carlos's StackLess > Python (another product for PSP). > > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) > > > Please, help us. The product is complete, > but we cannot release cause this problem. > > Thank you in advance. > Filippo Battaglia In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. Cheers, Chris -- http://blog.rebertia.com From Wwy58 at yahoo.com Wed Jun 24 13:50:50 2009 From: Wwy58 at yahoo.com (David) Date: Wed, 24 Jun 2009 10:50:50 -0700 (PDT) Subject: urllib2.urlopen issue Message-ID: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> hello, I have a url that is "http://query.directrdr.com/ptrack? pid=225&v_url=http:// www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". If I open it on a browser, I can get its contents without any problem. However, if I use following code, import urllib2 url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' xml = urllib2.urlopen(url).read() then I get an exception of File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open raise URLError(err) urllib2.URLError: I think this is caused by the embedded "v_url=..." in the url. Anybody knows how to fix this? By the way, this code works well if I change the value of url to something like "www.yahoo.com" or "www.google.com". Thanks so much. From shelika.void at gmail.com Wed Jun 24 14:07:00 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 11:07:00 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: <2f093ae3-4393-4b36-a6fe-037b6acf4a5e@s6g2000vbp.googlegroups.com> On Jun 24, 6:26?pm, Scott David Daniels wrote: > Norberto Lopes wrote: > > On Jun 24, 1:21 pm, "Diez B. Roggisch" wrote: > >> Norberto Lopes wrote: ... > >>> config = {"home" : "/home/test"} > >>> config["user1"] = config["home"] + "/user1" > >>> config["user2"] = config["home"] + "/user2" > >>> config["python-dev"] = config["user1"] + "/py-dev" > > I'd write this as: > ? ? home = "/home/test" > ? ? config = {"home" : home, "user1" : home + "/user1", > ? ? ? ? ? ? ? "user2" : home + "/user2", "python-dev" : home + "/py-dev"} > > or even (if the list gets much longer): > > ? ? home = "/home/test" > ? ? config = {"home" : "", "user1" : "/user1", "user2" : "/user2", > ? ? ? ? ? ? ? "python-dev" : "/py-dev"} > ? ? for key, entry in config.iteritems(): > ? ? ? ? config[key] = home + entry > > --Scott David Daniels > Scott.Dani... at Acm.Org Yeah, there are a lot of options. That was just an example. Btw, I had "python-dev" depending on "user1" and "user1" depending on "home" precisely so that the way you suggested would get complicated. Yours examples fail in the python-dev key-value. You'd need an "extra" step ;) From xahlee at gmail.com Wed Jun 24 14:09:40 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 24 Jun 2009 11:09:40 -0700 (PDT) Subject: talk of concurrency by Anders Hejlsberg and Guy Steele Message-ID: <5846735f-74aa-4c6a-933a-83ded986390c@u9g2000prd.googlegroups.com> of recent talks about concurrency, this video interview would be of interest: http://channel9.msdn.com/posts/Charles/Anders-Hejlsberg-and-Guy-Steele-Concurrency-and-Language-Design/ Anders Hejlsberg and Guy Steele: Concurrency and Language Design Posted By: Charles | Oct 6th, 2008 @ 6:27 AM | 75,079 Views | 19 Comments Xah ? http://xahlee.org/ ? From aahz at pythoncraft.com Wed Jun 24 14:11:27 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 11:11:27 -0700 Subject: urllib2.urlopen issue References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: In article <854313cf-6323-4ca9-b883-65ca8f414d96 at v23g2000pro.googlegroups.com>, David wrote: > >import urllib2 >url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' >xml = urllib2.urlopen(url).read() > >then I get an exception of > > File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > raise URLError(err) >urllib2.URLError: > >I think this is caused by the embedded "v_url=..." in the url. urllib.quote_plus() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From clp2 at rebertia.com Wed Jun 24 14:27:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 11:27:12 -0700 Subject: urllib2.urlopen issue In-Reply-To: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: <50697b2c0906241127h26562e9fsac42ecc1f32f13da@mail.gmail.com> On Wed, Jun 24, 2009 at 10:50 AM, David wrote: > hello, > > I have a url that is "http://query.directrdr.com/ptrack? > pid=225&v_url=http:// > www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". > If I open it on a browser, I can get its contents without any > problem. > However, if I use following code, > > > import urllib2 > > > url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// > www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' > > > xml = urllib2.urlopen(url).read() > > > then I get an exception of > > > ?File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > ? ?raise URLError(err) > urllib2.URLError: Unable to reproduce with either urllib or urllib2's urlopen(). I get some XML back without error both ways. Using Python 2.6.2 on Mac OS X. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Jun 24 14:31:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 14:31:44 -0400 Subject: isinstance(obj, type(obj)) == True? In-Reply-To: References: Message-ID: Art wrote: > I have the following problem: > > ipdb> p type(self) > > > ipdb> isinstance(self, component.BiasComponent) > False > > I thought that isinstance(obj, type(obj)) == True. Yes, but that is not what you entered ;-). The name 'component.BiasComponent' is not bound to type(self), but to another object, probably with the same .__name__ attribute. > The specific problem is when I try to call the super of a class and it > only occurs after 'reload'ing the file in the interpreter. What am I > messing up by reloading? The relationship between namespace names and definition names. My guess is that you have two class objects with the same definition name. This happens when you reload the code for a class and have instances that keep the original class object alive. This sort of problem is why reload was *removed* from Py3. It did not work the way people wanted it to and expected it to. I recommend not to use it. > It doesn't occur if I using for the first > time in a fresh interpreter session. Starting fresh is the right thing to do. IDLE has a 'Restart Shell' command for this reason. It automatically restarts when you run a file. You have already wasted more time with reload than most people would ever save in a lifetime of using reload, even if it worked as expected. Terry Jan Reedy From invalid at invalid Wed Jun 24 14:35:34 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 24 Jun 2009 13:35:34 -0500 Subject: Converting Python code to C/C++ References: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Message-ID: On 2009-06-24, Terry Reedy wrote: > Your professor should wait until your Python version is complete and in > final form and until a C version is needed. Then hire someone competent > in both languages to do the translation. Professor... hire... Good one! :) -- Grant Edwards grante Yow! BARRY ... That was at the most HEART-WARMING visi.com rendition of "I DID IT MY WAY" I've ever heard!! From koranthala at gmail.com Wed Jun 24 14:38:02 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 24 Jun 2009 11:38:02 -0700 (PDT) Subject: Matplotlib - an odd problem Message-ID: <2717e804-3ec0-4bbc-b850-17dbefa5d45b@g15g2000pra.googlegroups.com> Hi, I am using Matplotlib with Django to display charts on the web page. I am facing an odd problem in that, everytime I do a refresh on the web page, the image darkens - and the text becomes little unreadable. 5/6 refreshes later, the text becomes completely unreadable. Since I am using Django test server, the same process is being used. i.e. every refresh does not create a new process. When I tried killing the process, the image again cleared. So I think it is sort of memory leak or a saved value which is messing up something. But I cannot seem to find the issue at all. The code is as follows - import pylab from cStringIO import StringIO def print_pie_chart(request): labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' data = [15,30,45, 10] pylab.figure(1, figsize=(2,2)) ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', shadow=True) out = StringIO() pylab.savefig(out, format="PNG") out.seek(0) response = HttpResponse() response['Content-Type'] = 'image/png' response.write(out.read()) return response Can anyone help me out here? From tjreedy at udel.edu Wed Jun 24 14:40:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 14:40:36 -0400 Subject: Get name of class without instance In-Reply-To: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> References: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> Message-ID: Bryan wrote: > How come dir(Foo) does not show __name__? That is how I was > investigating the possibilities. Interesting question. Seems like an oversight. dir(some_module) and dir(some_function) include '__name__'. I suggest you search the tracker for existing issues on this subject and add a feature request if there is none. From donnyf at gmail.com Wed Jun 24 14:42:56 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 11:42:56 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 11:57?am, Scott David Daniels wrote: > What OS and version, what Python and version. Win XP, Python 2.6.2 From saurabh.gupta.7 at gmail.com Wed Jun 24 14:46:55 2009 From: saurabh.gupta.7 at gmail.com (Saurabh) Date: Wed, 24 Jun 2009 11:46:55 -0700 (PDT) Subject: Tutorials on Jinja Message-ID: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Hi All, I am trying to move my application on a MVC architecture and plan to use Jinja for the same. Can anyone provide me with few quick links that might help me to get started with Jinja? Thanks, Saby From Wwy58 at yahoo.com Wed Jun 24 14:59:29 2009 From: Wwy58 at yahoo.com (David) Date: Wed, 24 Jun 2009 11:59:29 -0700 (PDT) Subject: urllib2.urlopen issue References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> On Jun 24, 11:27?am, Chris Rebert wrote: > On Wed, Jun 24, 2009 at 10:50 AM, David wrote: > > hello, > > > I have a url that is "http://query.directrdr.com/ptrack? > > pid=225&v_url=http:// > >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". > > If I open it on a browser, I can get its contents without any > > problem. > > However, if I use following code, > > > import urllib2 > > > url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// > >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' > > > xml = urllib2.urlopen(url).read() > > > then I get an exception of > > > ?File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > > ? ?raise URLError(err) > > urllib2.URLError: > > Unable to reproduce with either urllib or urllib2's urlopen(). I get > some XML back without error both ways. Using Python 2.6.2 on Mac OS X. > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Thanks Aahz. And thanks Chris. The XML content is what I am looking for. I use Python 2.5. Maybe I should update to 2.6.2? Python version problem? From unayok at gmail.com Wed Jun 24 15:48:44 2009 From: unayok at gmail.com (unayok) Date: Wed, 24 Jun 2009 12:48:44 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 10:23?am, Chuck Connors wrote: > Hey guys. ?I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. ?I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. ?Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? ?I am not > asking for anyone to write the code but merely a push in the right > direction. Here's a little nudge: http://code.activestate.com/recipes/157035/ In place of its "print" line, you'd make your call into your existing code to send the message. Some of the comments offer some improvements on it (always read the comments on the recipes), but this is likely the direction you will want to head. From twirlip at bigfoot.com Wed Jun 24 15:53:49 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 20:53:49 +0100 Subject: It's ... Message-ID: ... my first Python program! So please be gentle (no fifty ton weights on the head!), but tell me if it's properly "Pythonic", or if it's a dead parrot (and if the latter, how to revive it). I'm working from Beazley's /Python: Essential Reference/ (2nd ed. 2001), so my first newbie question is how best to find out what's changed from version 2.1 to version 2.5. (I've recently installed 2.5.4 on my creaky old Win98SE system.) I expect to be buying the 4th edition when it comes out, which will be soon, but before then, is there a quick online way to find this out? Having only got up to page 84 - where we can actually start to read stuff from the hard disk - I'm emboldened to try to learn to do something useful, such as removing all those annoying hard tab characters from my many old text files (before I cottoned on to using soft tabs in my text editor). This sort of thing seems to work, in the interpreter (for an ASCII text file, named 'h071.txt', in the current directory): stop = 3 # Tab stops every 3 characters from types import StringType # Is this awkwardness necessary? detab = lambda s : StringType.expandtabs(s, stop) # Or use def f = open('h071.txt') # Do some stuff to f, perhaps, and then: f.seek(0) print ''.join(map(detab, f.xreadlines())) f.close() Obviously, to turn this into a generally useful program, I need to learn to write to a new file, and how to parcel up the Python code, and write a script to apply the "detab" function to all the files found by searching a Windows directory, and replace the old files with the new ones; but, for the guts of the program, is this a reasonable way to write the code to strip tabs from a text file? For writing the output file, this seems to work in the interpreter: g = open('temp.txt', 'w') g.writelines(map(detab, f.xreadlines())) g.close() In practice, does this avoid creating the whole string in memory at one time, as is done by using ''.join()? (I'll have to read up on "opaque sequence objects", which have only been mentioned once or twice in passing - another instance perhaps being an xrange()?) Not that that matters much in practice (in this simple case), but it seems elegant to avoid creating the whole output file at once. OK, I'm just getting my feet wet, and I'll try not to ask too many silly questions! First impressions are: (1) Python seems both elegant and practical; and (2) Beazley seems a pleasantly unfussy introduction for someone with at least a little programming experience in other languages. -- Angus Rodgers From lie.1296 at gmail.com Wed Jun 24 15:57:09 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 19:57:09 GMT Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: Mag Gam wrote: > Sorry for the delayed response. I was trying to figure this problem > out. The OS is Linux, BTW Maybe I'm just being pedantic, but saying your OS is Linux means little as there are hundreds of variants (distros) of Linux. (Not to mention that Linux is a kernel, not a full blown OS, and people in GNU will insist to call Linux-based OS GNU/Linux) > Here is some code I have: > import numpy as np > from numpy import * Why are you importing numpy twice as np and as *? > import gzip > import h5py > import re > import sys, string, time, getopt > import os > > src=sys.argv[1] > fs = gzip.open(src) > x=src.split("/") > filename=x[len(x)-1] > > #Get YYYY/MM/DD format > YYYY=(filename.rsplit(".",2)[0])[0:4] > MM=(filename.rsplit(".",2)[0])[4:6] > DD=(filename.rsplit(".",2)[0])[6:8] > > f=h5py.File('/tmp/test_foo/FE.hdf5','w') this particular line would make it impossible to have more than one instance of the program open. May not be your concern... > > grp="/"+YYYY > try: > f.create_group(grp) > except ValueError: > print "Year group already exists" > > grp=grp+"/"+MM > try: > f.create_group(grp) > except ValueError: > print "Month group already exists" > > grp=grp+"/"+DD > try: > group=f.create_group(grp) > except ValueError: > print "Day group already exists" > > str_type=h5py.new_vlen(str) > mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', > 'f4', 'f4')} > print "Filename is: ",src > fs = gzip.open(src) > dset = f.create_dataset ('Foo',data=arr,compression='gzip') What is `arr`? > s=0 > > #Takes the longest here > for y in fs: > continue > a=y.split(',') > s=s+1 > dset.resize(s,axis=0) You increment s by 1 for each iteration, would this copy the dataset? (I never worked with h5py, so I don't know how it works) From mail131 at gmail.com Wed Jun 24 16:17:35 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 13:17:35 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: On Jun 24, 1:32?pm, Peter Otten <__pete... at web.de> wrote: > Przemyslaw Bak wrote: > > Hello, > > > I many files with log data. The structure of the file is quite > > inconvenience and similar to the following example: > > Data1 > > ? ValueA > > Data2 > > ? ValueB > > Data3 > > ? ValueC > > ... > > To get the values I need to find Data* and then get to the next line. > > I tried to use fileinput.input : > > ... > > for line in fileinput.input(filename): > > ? ? if line.find("Data2") >= 0: > > ? ? ? ? (now what ?) > > > So I can find the requested line (Data2) but how to get value from the > > next line ? > > lines = fileinput.input(filename) > for line in lines: > ? ? if "Data2" in line: > ? ? ? ? print line.strip(), "-->", next(lines).strip() I get an error: ... print line.strip(), "-->", next(lines).strip() NameError: global name 'next' is not defined From Scott.Daniels at Acm.Org Wed Jun 24 16:34:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 13:34:33 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <08qdneYKoJrfEd_XnZ2dnUVZ_q-dnZ2d@pdx.net> Peter Otten wrote: > Scott David Daniels wrote: >> Peter Otten wrote: >>> with open(filename) as instream: >>> lines = (line.strip() for line in lines) >>> lookup = dict(zip(lines, lines)) > >> Little bit of a fluff-up here. > > Sorry, it should have been > > with open(filename) as instream: > lines = (line.strip() for line in instream) > lookup = dict(zip(lines, lines)) > >> Perhaps something like: >> >> with open(filename) as instream: >> lines = (line.strip() for line in instream) >> lookup = dict(zip(lines[::2], lines[1::2])) > > Tu quoque ;) You are exactly right (and my vocabulary expands a bit); I must go wipe the egg off of my face now. I still am thinking lists even though I am writing generators. I should have written: with open(filename) as instream: lines = [line.strip() for line in instream] lookup = dict(zip(lines[::2], lines[1::2])) But, your example does in fact work as written. --Scott David Daniels Scott.Daniels at Acm.Org From twirlip at bigfoot.com Wed Jun 24 16:34:59 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 21:34:59 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 20:53:49 +0100, I wrote: >[...] my first newbie question is how best to find out >what's changed from version 2.1 to version 2.5. >[...] is there a quick online way to find this out? One way seems to be: ... although there doesn't seem to be any ... ah! ... "What's New in Python 2.2" -- Angus Rodgers From aahz at pythoncraft.com Wed Jun 24 16:38:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 13:38:52 -0700 Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: In article <2838671f-d582-4af1-b850-ccc18ff9dd76 at a36g2000yqc.googlegroups.com>, Francesco Bochicchio wrote: > >is there any site that reports the current porting (to Python 3.x) >status of the main non-standard extension modules (such as pygtk, >pywin32, wxpython, ...) ? Feel free to create a wiki page on python.org... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jcd at sdf.lonestar.org Wed Jun 24 16:40:29 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 24 Jun 2009 16:40:29 -0400 Subject: It's ... In-Reply-To: References: Message-ID: <1245876029.20649.21.camel@aalcdl07> On Wed, 2009-06-24 at 20:53 +0100, Angus Rodgers wrote: > ... my first Python program! So please be gentle (no fifty ton > weights on the head!), but tell me if it's properly "Pythonic", > or if it's a dead parrot (and if the latter, how to revive it). > Yay. Welcome to Python. > I'm working from Beazley's /Python: Essential Reference/ (2nd > ed. 2001), so my first newbie question is how best to find out > what's changed from version 2.1 to version 2.5. (I've recently > installed 2.5.4 on my creaky old Win98SE system.) I expect to > be buying the 4th edition when it comes out, which will be soon, > but before then, is there a quick online way to find this out? > Check here: http://docs.python.org/whatsnew/index.html It's not designed to be newbie friendly, but it's in there. > Having only got up to page 84 - where we can actually start to > read stuff from the hard disk - I'm emboldened to try to learn > to do something useful, such as removing all those annoying hard > tab characters from my many old text files (before I cottoned on > to using soft tabs in my text editor). > > This sort of thing seems to work, in the interpreter (for an > ASCII text file, named 'h071.txt', in the current directory): > > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? Not anymore. You can just use str for this. > detab = lambda s : StringType.expandtabs(s, stop) # Or use def First, use def. lambda is a rarity for use when you'd rather not assign your function to a variable. Second, expandtabs is a method on string objects. s is a string object, so you can just use s.expandtabs(stop) Third, I'd recommend passing your tabstops into detab with a default argument, rather than defining it irrevocably in a global variable (which is brittle and ugly) def detab(s, stop=3): #do stuff Then you can do three_space_version = detab(s) eight_space_version = detab(s, 8) > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) f is not opened for writing, so if you do stuff to the contents of f, you'll have to put the new version in a different variable, so f.seek(0) doesn't help. If you don't do stuff to it, then you're at the beginning of the file anyway, so either way, you shouldn't need to f.seek(0). > print ''.join(map(detab, f.xreadlines())) Sometime in the history of python, files became iterable, which means you can do the following: for line in f: print detab(line) Much prettier than running through join/map shenanigans. This is also the place to modify the output before passing it to detab: for line in f: # do stuff to line print detab(line) Also note that you can iterate over a file several times: f = open('foo.txt') for line in f: print line[0] # prints the first character of every line for line in f: print line[1] #prints the second character of every line > f.close() > > Obviously, to turn this into a generally useful program, I need > to learn to write to a new file, and how to parcel up the Python > code, and write a script to apply the "detab" function to all the > files found by searching a Windows directory, and replace the old > files with the new ones; but, for the guts of the program, is this > a reasonable way to write the code to strip tabs from a text file? > > For writing the output file, this seems to work in the interpreter: > > g = open('temp.txt', 'w') > g.writelines(map(detab, f.xreadlines())) > g.close() > Doesn't help, as map returns a list. You can use itertools.imap, or you can use a for loop, as above. > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? (I'll have to read up > on "opaque sequence objects", which have only been mentioned once > or twice in passing - another instance perhaps being an xrange()?) > Not that that matters much in practice (in this simple case), but > it seems elegant to avoid creating the whole output file at once. The terms to look for, rather than opaque sequence objects are "iterators" and "generators". > > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. > Glad you're enjoying Beazley. I would look for something more up-to-date. Python's come a long way since 2.1. I'd hate for you to miss out on all the iterators, booleans, codecs, subprocess, yield, unified int/longs, decorators, decimals, sets, context managers and new-style classes that have come since then. > -- > Angus Rodgers Cheers, Cliff From python at mrabarnett.plus.com Wed Jun 24 16:44:27 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 21:44:27 +0100 Subject: [SPAM] It's ... In-Reply-To: References: Message-ID: <4A42902B.6060701@mrabarnett.plus.com> Angus Rodgers wrote: [snip] > This sort of thing seems to work, in the interpreter (for an > ASCII text file, named 'h071.txt', in the current directory): > > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? > detab = lambda s : StringType.expandtabs(s, stop) # Or use def > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) > f.close() > stop = 3 # Tab stops every 3 characters detab = lambda s: s.expandtabs(stop) f = open('h071.txt') # Do some stuff to f, perhaps, and then: # f.seek(0) # Not necessary print ''.join(map(detab, f.xreadlines())) f.close() > Obviously, to turn this into a generally useful program, I need > to learn to write to a new file, and how to parcel up the Python > code, and write a script to apply the "detab" function to all the > files found by searching a Windows directory, and replace the old > files with the new ones; but, for the guts of the program, is this > a reasonable way to write the code to strip tabs from a text file? > > For writing the output file, this seems to work in the interpreter: > > g = open('temp.txt', 'w') > g.writelines(map(detab, f.xreadlines())) > g.close() > > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? (I'll have to read up > on "opaque sequence objects", which have only been mentioned once > or twice in passing - another instance perhaps being an xrange()?) > Not that that matters much in practice (in this simple case), but > it seems elegant to avoid creating the whole output file at once. > > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. > STOP = 3 # Tab stops every 3 characters in_file = open('h071.txt') out_file = open('temp.txt', 'w') for line in in_file: # Iterates one line at a time out_file.write(line.expandtabs(STOP)) in_file.close() out_file.close() From janssonks at gmail.com Wed Jun 24 16:48:15 2009 From: janssonks at gmail.com (Karl Jansson) Date: Wed, 24 Jun 2009 15:48:15 -0500 Subject: installation in mac os x In-Reply-To: <79c05cF1q46qkU1@mid.uni-berlin.de> References: <79c05cF1q46qkU1@mid.uni-berlin.de> Message-ID: <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> > > What happens if you work on the commandline (Terminal)? > > Python2.6 should be available from (out of my head) > > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > If that's working, it is successfully installed. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list If I work on the commandline, I have version 2.3, which works. But some of the commands in the tutorial don't work with that version, so I had to upgrade in order to do the tutorial. But I still can't do it, obviously. Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Jun 24 17:00:27 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 23:00:27 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Private Private wrote: > > lines = fileinput.input(filename) > > for line in lines: > > if "Data2" in line: > > print line.strip(), "-->", next(lines).strip() > > I get an error: > > ... > print line.strip(), "-->", next(lines).strip() > NameError: global name 'next' is not defined In Python versions prior to 2.6 instead of next(lines) you can use lines.next() Peter From frank.ruiz at gmail.com Wed Jun 24 17:01:02 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 14:01:02 -0700 Subject: Paramiko Help Message-ID: Apologies.. Python newb here.. switching from perl to python.. so please forgive if this is a dumb question. I am using the paramiko module and have some global variables defined. i.e. hostname = ' 10.10.10.10' sshport = '22' I am then trying to pass this variable into the client connect method - client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, root) I also have public key setup between source and destination host, so not sure if this will work, but trying to jump one hurtle at at time. So it seems like the values past to the connect method are taken at face value based on the error message I am seeing: TypeError: an integer is required Any help is much appreciated. Thanks! From joncle at googlemail.com Wed Jun 24 17:04:51 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Jun 2009 14:04:51 -0700 (PDT) Subject: Paramiko Help References: Message-ID: <99d20f8c-8106-4c70-8e60-8a8f2ebeb736@o36g2000vbi.googlegroups.com> On Jun 24, 10:01?pm, Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' > > I am then trying to pass this variable into the client connect method - > > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, root) > > I also have public key setup between source and destination host, so > not sure if this will work, but trying to jump one hurtle at at time. > > So it seems like the values past to the connect method are taken at > face value based on the error message I am seeing: > > TypeError: an integer is required > > Any help is much appreciated. > > Thanks! wild guess: should sshport = 22 (instead of '22') From clp2 at rebertia.com Wed Jun 24 17:05:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 14:05:37 -0700 Subject: Paramiko Help In-Reply-To: References: Message-ID: <50697b2c0906241405y62cf236al5a138a2813968bb@mail.gmail.com> On Wed, Jun 24, 2009 at 2:01 PM, Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' I'm haven't used Paramiko, but I would guess that this should instead be: sshport = 22 Note that Python does not autoconvert between strings and numbers like Perl does. Also, in the future, please give the full error traceback, not just the final error message, as it's much harder to debug code without it. Cheers, Chris -- http://blog.rebertia.com From jeff_barish at earthlink.net Wed Jun 24 17:06:27 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Wed, 24 Jun 2009 15:06:27 -0600 Subject: Problem with multithreading Message-ID: I have a program that uses multithreading to monitor two loops. When something happens in loop1, it sends a message to loop2 to have it execute a command. loop2 might have to return a result. If it does, it puts the result in a queue. loop1, meanwhile, would have blocked waiting for something to appear in the queue. The program works for a while, but eventually freezes. I know that freezing is a sign of deadlock. However, I put in print statements to localize the problem and discovered something weird. The freeze always occurs at a point in the code with the following statements: print "about to try" try: print "in try" I get "about to try", but not "in try". Is this observation consistent with the deadlock theory? If not, what could be making the program freeze at the try statement? I wrote a test program using the same techniques to illustrate the problem, but the test program works perfectly. I could post it, though, if it would help to understand what I am doing -- and what might be wrong in the real program. -- Jeffrey Barish From Scott.Daniels at Acm.Org Wed Jun 24 17:10:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 14:10:54 -0700 Subject: It's ... In-Reply-To: References: Message-ID: Angus Rodgers wrote: > ... my first ... question is how best to find out what's changed from version 2.1 > to version 2.5. (I've recently installed 2.5.4) Consecutively read: http://docs.python.org/whatsnew/2.2.html http://docs.python.org/whatsnew/2.3.html http://docs.python.org/whatsnew/2.4.html http://docs.python.org/whatsnew/2.5.html > stop = 3 # Tab stops every 3 characters Typically program constants should be full caps. See PEP 8 > from types import StringType # Is this awkwardness necessary? Nope > detab = lambda s : StringType.expandtabs(s, stop) # Or use def Really use def unless you have a solid reason not to. At the moment, I'd suggest you simply presume you have no such reason. Also, expandtabs is an instance method, so the roundabout is not needed. def detab(s): return s.expandtabs(stop) > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) Too much, even though that is how you thought the problem out. First, text files are now iterable (producing a line at a time much like xreadlines). Second the map above creates a list of all detabbed lines, then (while that list still exists), it also creates a string constant which is the "new" contents of the file. I'd simply use: for line in f: print detab(line.rstrip()) or even: for line in f: print line.rstrip().expandtabs(stop) > ... > g.writelines(map(detab, f.xreadlines())) > > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? Nope. But you could use a generator expression if you wanted: g.writelines(detab(line) for line in f) > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. Both 1 and 2 are true in spades. --Scott David Daniels Scott.Daniels at Acm.Org From donnyf at gmail.com Wed Jun 24 17:12:22 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 14:12:22 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 2:48?pm, unayok wrote: > Here's a little nudge:http://code.activestate.com/recipes/157035/ > > In place of its "print" line, you'd make your call into your existing > code to send the message. Wow! Thanks for the _shove_ in the right direction. Looks perfect. From twirlip at bigfoot.com Wed Jun 24 17:12:33 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:12:33 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 16:40:29 -0400, "J. Cliff Dyer" wrote: >On Wed, 2009-06-24 at 20:53 +0100, Angus Rodgers wrote: >> [...] >> from types import StringType # Is this awkwardness necessary? > >Not anymore. You can just use str for this. > >> detab = lambda s : StringType.expandtabs(s, stop) # Or use def > >First, use def. lambda is a rarity for use when you'd rather not assign >your function to a variable. > >Second, expandtabs is a method on string objects. s is a string object, >so you can just use s.expandtabs(stop) How exactly do I get detab, as a function from strings to strings (for a fixed tab size)? (This is aside from the point, which you make below, that the whole map/join idea is a bit of a no-no - in some other context, I might want to isolate a method like this.) >Third, I'd recommend passing your tabstops into detab with a default >argument, rather than defining it irrevocably in a global variable >(which is brittle and ugly) No argument there - I was just messing about in the interpreter, to see if the main idea worked. >> f = open('h071.txt') # Do some stuff to f, perhaps, and then: >> f.seek(0) > >f is not opened for writing, so if you do stuff to the contents of f, >you'll have to put the new version in a different variable, so f.seek(0) >doesn't help. If you don't do stuff to it, then you're at the beginning >of the file anyway, so either way, you shouldn't need to f.seek(0). I seemed to find that if I executed f.xreadlines() or f.readlines() once, I was somehow positioned at the end of the file or something, and had to do the f.seek(0) - but maybe I did something else silly. >> print ''.join(map(detab, f.xreadlines())) > >Sometime in the history of python, files became iterable, which means >you can do the following: > >for line in f: > print detab(line) > >Much prettier than running through join/map shenanigans. This is also >the place to modify the output before passing it to detab: > >for line in f: > # do stuff to line > print detab(line) > >Also note that you can iterate over a file several times: > >f = open('foo.txt') >for line in f: > print line[0] # prints the first character of every line >for line in f: > print line[1] #prints the second character of every line >> f.close() This all looks very nice. >> For writing the output file, this seems to work in the interpreter: >> >> g = open('temp.txt', 'w') >> g.writelines(map(detab, f.xreadlines())) >> g.close() >> > >Doesn't help, as map returns a list. Pity. Oh, well. >You can use itertools.imap, or you >can use a for loop, as above. This is whetting my appetite! >The terms to look for, rather than opaque sequence objects are >"iterators" and "generators". OK, will do. >Glad you're enjoying Beazley. I would look for something more >up-to-date. Python's come a long way since 2.1. I'd hate for you to >miss out on all the iterators, booleans, codecs, subprocess, yield, >unified int/longs, decorators, decimals, sets, context managers and >new-style classes that have come since then. I'll get either Beazley's 4th ed. (due next month, IIRC), or Chun, /Core Python Programming/ (2nd ed.), or both, unless someone has a better suggestion. (Eventually I'll migrate from Windows 98SE(!), and will need info on Python later than 2.5, but that's all I need for now.) -- Angus Rodgers From philip at semanchuk.com Wed Jun 24 17:13:10 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 24 Jun 2009 17:13:10 -0400 Subject: installation in mac os x In-Reply-To: <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> References: <79c05cF1q46qkU1@mid.uni-berlin.de> <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> Message-ID: <95F13F9F-7E39-4376-8530-09EE1D358D67@semanchuk.com> On Jun 24, 2009, at 4:48 PM, Karl Jansson wrote: >> >> What happens if you work on the commandline (Terminal)? >> >> Python2.6 should be available from (out of my head) >> >> /Library/Frameworks/Python.framework/Versions/2.6/bin/python >> >> If that's working, it is successfully installed. >> >> Diez >> -- http://mail.python.org/mailman/listinfo/python-list > > If I work on the commandline, I have version 2.3, which works. But > some of the commands in the tutorial don't work with that version, > so I had to upgrade in order to do the tutorial. But I still can't > do it, obviously. The system Python (2.3) is in /usr/bin and that's probably first in your path, so when you simply type 'python' it finds /usr/bin/python. Python 2.6 might have installed itself in /usr/local/bin. Try invoking /usr/local/bin/python and see which one you get (if that works at all). If that's Python 2.6, then move /usr/local/bin ahead of usr/bin in your path and then you'll invoke Python 2.6 by just typing 'python' at the command line. If that doesn't work, hunt around in /Library/Frameworks as Diez suggested. Until we figure out whether or not you actually have 2.6 installed, it is difficult to suggest how to invoke it. Let us know what you find. bye Philip From Scott.Daniels at Acm.Org Wed Jun 24 17:13:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 14:13:13 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Private Private wrote: > On Jun 24, 1:32 pm, Peter Otten <__pete... at web.de> wrote: ... >> lines = fileinput.input(filename) >> for line in lines: >> if "Data2" in line: >> print line.strip(), "-->", next(lines).strip() > > I get an error: > > ... > print line.strip(), "-->", next(lines).strip() > NameError: global name 'next' is not defined > Sorry, I am running 2.6 Try: print line.strip(), "-->", lines.next().strip() --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Wed Jun 24 17:13:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 22:13:58 +0100 Subject: Paramiko Help In-Reply-To: References: Message-ID: <4A429716.3070102@mrabarnett.plus.com> Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' > > I am then trying to pass this variable into the client connect method - > > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, root) > > I also have public key setup between source and destination host, so > not sure if this will work, but trying to jump one hurtle at at time. > > So it seems like the values past to the connect method are taken at > face value based on the error message I am seeing: > > TypeError: an integer is required > > Any help is much appreciated. > It looks like sshport needs to be an integer, not a string. Unlike Perl, Python won't magically convert the string to an integer. From twirlip at bigfoot.com Wed Jun 24 17:15:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:15:43 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 22:12:33 +0100, I wrote: >How exactly do I get detab, as a function from strings to strings >(for a fixed tab size)? (It's OK - this has been explained in another reply. I'm still a little hazy about what exactly objects are in Python, but the haze will soon clear, I'm sure, especially after I have written more than one one-line program!) -- Angus Rodgers From lie.1296 at gmail.com Wed Jun 24 17:17:18 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 21:17:18 GMT Subject: Why is it that str.replace doesn't work sometimes? In-Reply-To: References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: MRAB wrote: > There's no difference between the two types of quote character. a small exception is single-quote can contain double quote but cannot contain unescaped single quote while double-quote can contain single quote but cannot contain unescaped double quote. From lie.1296 at gmail.com Wed Jun 24 17:31:32 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 21:31:32 GMT Subject: Problem with multithreading In-Reply-To: References: Message-ID: Jeffrey Barish wrote: > I have a program that uses multithreading to monitor two loops. When > something happens in loop1, it sends a message to loop2 to have it execute > a command. loop2 might have to return a result. If it does, it puts the > result in a queue. loop1, meanwhile, would have blocked waiting for > something to appear in the queue. The program works for a while, but > eventually freezes. I know that freezing is a sign of deadlock. However, > I put in print statements to localize the problem and discovered something > weird. The freeze always occurs at a point in the code with the following > statements: > > print "about to try" > try: > print "in try" > > > I get "about to try", but not "in try". Is this observation consistent with > the deadlock theory? If not, what could be making the program freeze at > the try statement? I wrote a test program using the same techniques to > illustrate the problem, but the test program works perfectly. I could post > it, though, if it would help to understand what I am doing -- and what > might be wrong in the real program. The key in writing a test code is to reduce the buggy code until you can't reduce anymore without losing the bug. It is sometimes difficult to write a buggy test code... try writing the test code again with that technique, and post it From twirlip at bigfoot.com Wed Jun 24 17:43:01 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:43:01 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 14:10:54 -0700, Scott David Daniels wrote: >Angus Rodgers wrote: > >> from types import StringType # Is this awkwardness necessary? >Nope I'm starting to see some of the mental haze that was confusing me. >Also, expandtabs is an instance method, so the roundabout is not needed. > > def detab(s): > return s.expandtabs(stop) I'd forgotten where Beazley had explained that "methods such as ... s.expandtabs() always return a new string as opposed to mod- ifying the string s." I must have been hazily thinking of it as somehow modifying s, even though my awkward code itself depended on a vague understanding that it didn't. No point in nailing this polly to the perch any more! >I'd simply use: > for line in f: > print detab(line.rstrip()) >or even: > for line in f: > print line.rstrip().expandtabs(stop) I'll read up on iterating through files, somewhere online for the moment, and then get a more up-to-date textbook. And I'll try not too ask too many silly questions like this, but I wanted to make sure I wasn't getting into any bad programming habits right at the start - and it's a good thing I did, because I was! >Nope. But you could use a generator expression if you wanted: > g.writelines(detab(line) for line in f) Ah, so that actually does what I was fondly hoping my code would do. Thanks! I must learn about these "generator" thingies. -- Angus Rodgers From davea at ieee.org Wed Jun 24 17:43:20 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Jun 2009 17:43:20 -0400 Subject: Reading then sending new parts of a log file In-Reply-To: References: Message-ID: <4A429DF8.2000204@ieee.org> Chuck Connors wrote: > Hey guys. I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? I am not > asking for anyone to write the code but merely a push in the right > direction. > > Thanks! > > I assume you have a reason not to put the logic into the program that's creating the log file. Tell us the Python version, and OS it's running on. So your problem is to monitor a text file, and detect whenever it grows, taking the new parts and incrementally doing something with them. Here's a fragment from my tail program: def getRest(options, filename, oldstat, stat, callback): more = stat.st_size - oldstat.st_size #Note: this could be negative, if the file shrank while we were waiting if more > 0: infile = open(filename, "rb") infile.seek(oldstat.st_size) buf = infile.read(more) #BUGBUG perhaps should break this into multiple reads, if over 8k callback(buf) #process the new text def follow(options, filename, oldstat, callback): while True: stat = os.stat(filename) if stat.st_mtime > oldstat.st_mtime or stat.st_size != oldstat.st_size: getRest(options, filename, oldstat, stat, callback) oldstat = stat else: time.sleep(options.sec_to_wait) The concept here is that we only do real work when the stat() of a file has changed. Then, if the size is larger than last time, we process the new text. options is an object with various optional attributes. In this case, I think the only one used was sec_to_wait, which is how long we should delay before re-checking the stat. If it's too small, you waste CPU time. Your callback will have to deal with breaking things into messages, probably at convenient line-breaks. And of course the whole thing might want to be turned inside out, and coded as a generator. But it's a starting point, as you asked. From aahz at pythoncraft.com Wed Jun 24 17:54:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 14:54:34 -0700 Subject: It's ... References: Message-ID: In article , J. Cliff Dyer wrote: > >Glad you're enjoying Beazley. I would look for something more >up-to-date. Python's come a long way since 2.1. I'd hate for you to >miss out on all the iterators, booleans, codecs, subprocess, yield, >unified int/longs, decorators, decimals, sets, context managers and >new-style classes that have come since then. While those are all nice, they certainly aren't essential to learning Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From exarkun at divmod.com Wed Jun 24 17:55:12 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 24 Jun 2009 17:55:12 -0400 Subject: Matplotlib - an odd problem In-Reply-To: <2717e804-3ec0-4bbc-b850-17dbefa5d45b@g15g2000pra.googlegroups.com> Message-ID: <20090624215513.22176.1757453334.divmod.quotient.9186@henry.divmod.com> On Wed, 24 Jun 2009 11:38:02 -0700 (PDT), koranthala wrote: >Hi, >I am using Matplotlib with Django to display charts on the web page. >I am facing an odd problem in that, everytime I do a refresh on the >web page, the image darkens - and the text becomes little unreadable. >5/6 refreshes later, the text becomes completely unreadable. >Since I am using Django test server, the same process is being used. >i.e. every refresh does not create a new process. When I tried killing >the process, the image again cleared. >So I think it is sort of memory leak or a saved value which is messing >up something. >But I cannot seem to find the issue at all. > >The code is as follows - > >import pylab >from cStringIO import StringIO > >def print_pie_chart(request): > labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > data = [15,30,45, 10] > pylab.figure(1, figsize=(2,2)) > ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) > pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', >shadow=True) > out = StringIO() > pylab.savefig(out, format="PNG") > out.seek(0) > response = HttpResponse() > response['Content-Type'] = 'image/png' > response.write(out.read()) > return response > >Can anyone help me out here? Your code redraws over the same graph over and over again. You need to create a new graph each time you want to draw something new. It took me ages (and help) to figure out how the non-global APIs in matplotlib. Here's an example: from matplotlib.figure import Figure from matplotlib.axes import Axes from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas fig = Figure(figsize=(9, 9), dpi=100) axe = Axes(fig, (0, 0, 1.0, 1.0)) axe.pie(range(5)) fig.add_axes(axe) canvas = FigureCanvas(fig) canvas.set_size_request(640, 480) fig.savefig("foo.png") Hope this helps, Jean-Paul From lists at cheimes.de Wed Jun 24 17:59:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 24 Jun 2009 23:59:52 +0200 Subject: Get name of class without instance In-Reply-To: References: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> Message-ID: Terry Reedy wrote: > Bryan wrote: > >> How come dir(Foo) does not show __name__? That is how I was >> investigating the possibilities. > > Interesting question. Seems like an oversight. dir(some_module) and > dir(some_function) include '__name__'. I suggest you search the tracker > for existing issues on this subject and add a feature request if there > is none. The __name__ attribute of types and classes is actually a descriptor of the metaclass. It doesn't show up just like __bases__ and a few others. However for modules __name__ is just an ordinary attribute that gets set by the module class. Christian From milesck at umich.edu Wed Jun 24 18:04:38 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Wed, 24 Jun 2009 18:04:38 -0400 Subject: urllib2.urlopen issue In-Reply-To: <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> Message-ID: <43B36CC2-259C-404D-8E28-36455C08C92B@umich.edu> On Jun 24, 2009, at 2:59 PM, David wrote: > On Jun 24, 11:27 am, Chris Rebert wrote: >> On Wed, Jun 24, 2009 at 10:50 AM, David wrote: >>> hello, >>> >>> I have a url that is "http://query.directrdr.com/ptrack? >>> pid=225&v_url=http:// >>> www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". >>> If I open it on a browser, I can get its contents without any >>> problem. >>> However, if I use following code, >>> >>> import urllib2 >>> >>> url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// >>> www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' >>> >>> xml = urllib2.urlopen(url).read() >>> >>> then I get an exception of >>> >>> File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open >>> raise URLError(err) >>> urllib2.URLError: >> >> Unable to reproduce with either urllib or urllib2's urlopen(). I get >> some XML back without error both ways. Using Python 2.6.2 on Mac OS >> X. >> > > Thanks Aahz. And thanks Chris. The XML content is what I am looking > for. I use Python 2.5. Maybe I should update to 2.6.2? Python version > problem? No, it also works for me on Python 2.5.1. A wild guess: does this code work? import socket socket.gethostbyname(socket.gethostname()) If it throws a similar exception (Name or service not known), the root problem may be a misconfiguration in your /etc/hosts or /etc/ resolv.conf files. -Miles From frank.ruiz at gmail.com Wed Jun 24 18:22:02 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 15:22:02 -0700 Subject: Paramiko help - processing multiple commands Message-ID: Greetings, I am trying to process multiple commands using paramiko. I have searched other threads, and I think my use case is a little different. I am trying to login to a storage node that has a special shell, and as such I cant execute a script on the storage node side. I am also trying to avoid using pexpect because I hate making system calls.. hence my leaning towards paramiko. Was hoping someone could help me identify a way to process multiple commands using paramiko. I have two commands listed below, however only one is getting processed. Any help is much appreciated. Thanks! Here is my script: #!/usr/bin/env python #-Modules--------------------------------------------------------------------- import optparse import sys import paramiko #-Variables------------------------------------------------------------------- plog = 'storagessh.log' suser = 'root' #-Config---------------------------------------------------------------------- #-Subs-Defined---------------------------------------------------------------- def options(): global hostname global goldenimage global lunclone global sshport usage = "usage: %prog [options] -n -g -l " parser = optparse.OptionParser(usage) parser.add_option("-n", "--node", dest="hostname", help="Name of storage node you are connecting to.") parser.add_option("-g", "--gold", dest="goldenimage", help="Name of goldenimage to clone.") parser.add_option("-l", "--lun", dest="lunclone", help="Name of lun to create.") parser.add_option("-p", "--port", dest="sshport", default=22, help="SSH port number.") options, args = parser.parse_args() if not options.hostname: parser.error("Missing hostname argument.") exit elif not options.goldenimage: parser.error("Missing goldenimage argument.") exit elif not options.lunclone: parser.error("Missing lun argument.") exit hostname = options.hostname goldenimage = options.goldenimage lunclone = options.lunclone sshport = options.sshport def storagessh(): paramiko.util.log_to_file(plog) client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, suser) stdin, stdout, stderr = client.exec_command('show') stdin, stdout, stderr = client.exec_command('help') print stdout.read() client.close() #--Initialization------------------------------------------------------------- if __name__ == "__main__": options() storagessh() From cmpython at gmail.com Wed Jun 24 19:03:00 2009 From: cmpython at gmail.com (Che M) Date: Wed, 24 Jun 2009 16:03:00 -0700 (PDT) Subject: dynamically associate radio buttons with droplists References: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> Message-ID: <207e83b0-812b-4c24-9fda-99d599354d52@f30g2000vbf.googlegroups.com> On Jun 24, 10:37?am, a... at pythoncraft.com (Aahz) wrote: > In article <16b382ee-a3ae-46ee-88fd-d87fc40d2... at g20g2000vba.googlegroups.com>, > > > > Shoryuken ? wrote: > >On Jun 21, 8:43=A0pm, a... at pythoncraft.com (Aahz) wrote: > >> In article >.com>,LeoBrugud=A0 wrote: > > >>>Not being very familiar with python, nor with cgi/http, =A0I intend to > >>>have 3 of buttons in a webpage, each of them is associate with a file > >>>(so I have 3 files, too) > > >>>What I would like to have is, when users choose a button, the droplist > >>>update automatically to load the contents of the associated file. > > >> Are you trying to do this without requiring the user to click the submit > >> button? =A0If yes, you need to learn JavaScript (although I think there a= > >re > >> web frameworks that will auto-generate the JavaScript, you need to know > >> JavaScript in order to do debugging). > > >Thanks, and yes I want to do it without the submit button > > >So python alone cannot do this? > > Correct; you need to have code run in the browser, and few browsers > support Python. Might want to consider Pyjamas, the python-to-javascript Compiler and a Web Widget set: http://code.google.com/p/pyjamas/ From twirlip at bigfoot.com Wed Jun 24 19:03:55 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 00:03:55 +0100 Subject: It's ... References: Message-ID: <15b545hkm0vr3h77b8qjgrn7dq08a4c7lu@4ax.com> On Wed, 24 Jun 2009 22:43:01 +0100, I wrote: >No point in nailing this polly to the perch any more! Indeed not, so please skip what follows (I've surely been enough of an annoying newbie, already!), but I've just remembered why I wrote my program in such an awkward way. I wanted to be able to import the type name t (StringType in this case) so that I could simply use t.m() as the name of one of its methods [if "method" is the correct term]; but in this case, where m is expandtabs(), an additional parameter (the tab size) is needed; so, I used the lambda expression to get around this, entirely failing to realise that (as was clearly shown in the replies I got), if I was going to use "lambda" at all (not recommended!), then it would be a lot simpler to write the function as lambda s : s.m(), with or without any additional parameters needed. (It didn't really have anything to do with a separate confusion as to what exactly "objects" are.) >I wanted to make sure I wasn't getting into any bad programming >habits right at the start I'm just trying to make sure I really understand how I screwed up. (In future, I'll try to work through a textbook with exercises. But I thought I'd better try to get some quick feedback at the start, because I knew that I was fumbling around, and that it was unlikely to be necessary to use such circumlocutions.) -- Angus Rodgers From joncle at googlemail.com Wed Jun 24 19:34:41 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Jun 2009 16:34:41 -0700 (PDT) Subject: Paramiko help - processing multiple commands References: Message-ID: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> On Jun 24, 11:22?pm, Frank Ruiz wrote: > Greetings, > > I am trying to process multiple commands using paramiko. I have > searched other threads, and I think my use case is a little different. > I am trying to login to a storage node that has a special shell, and > as such I cant execute a script on the storage node side. > > I am also trying to avoid using pexpect because I hate making system > calls.. hence my leaning towards paramiko. > > Was hoping someone could help me identify a way to process multiple > commands using paramiko. > > I have two commands listed below, however only one is getting processed. > > Any help is much appreciated. > > Thanks! > > Here is my script: > > #!/usr/bin/env python > > #-Modules--------------------------------------------------------------------- > import optparse > import sys > import paramiko > > #-Variables------------------------------------------------------------------- > plog = 'storagessh.log' > suser = 'root' > > #-Config---------------------------------------------------------------------- > > #-Subs-Defined---------------------------------------------------------------- > def options(): > ? ? global hostname > ? ? global goldenimage > ? ? global lunclone > ? ? global sshport > > ? ? usage = "usage: %prog [options] -n -g -l " > > ? ? parser = optparse.OptionParser(usage) > > ? ? parser.add_option("-n", "--node", > ? ? ? ? ? ? ? ? ? ? ? dest="hostname", > ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") > ? ? parser.add_option("-g", "--gold", > ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", > ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") > ? ? parser.add_option("-l", "--lun", > ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", > ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") > ? ? parser.add_option("-p", "--port", > ? ? ? ? ? ? ? ? ? ? ? dest="sshport", > ? ? ? ? ? ? ? ? ? ? ? default=22, > ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") > ? ? options, args = parser.parse_args() > > ? ? if not options.hostname: > ? ? ? ? parser.error("Missing hostname argument.") > ? ? ? ? exit > ? ? elif not options.goldenimage: > ? ? ? ? parser.error("Missing goldenimage argument.") > ? ? ? ? exit > ? ? elif not options.lunclone: > ? ? ? ? parser.error("Missing lun argument.") > ? ? ? ? exit > > ? ? hostname = options.hostname > ? ? goldenimage = options.goldenimage > ? ? lunclone = options.lunclone > ? ? sshport = options.sshport > > def storagessh(): > ? ? paramiko.util.log_to_file(plog) > ? ? client = paramiko.SSHClient() > ? ? client.load_system_host_keys() > ? ? client.connect(hostname, sshport, suser) > ? ? stdin, stdout, stderr = client.exec_command('show') > ? ? stdin, stdout, stderr = client.exec_command('help') > ? ? print stdout.read() > ? ? client.close() > > #--Initialization------------------------------------------------------------- > if __name__ == "__main__": > ? ? options() > ? ? storagessh() Again, as you were asked on the original post -- full tracebacks and explain "what is not working". The use of global variables scares me -- why are those needed? From jcd at sdf.lonestar.org Wed Jun 24 19:41:44 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Wed, 24 Jun 2009 19:41:44 -0400 Subject: It's ... In-Reply-To: References: Message-ID: <1245886904.29331.5.camel@mctell> On Wed, 2009-06-24 at 14:54 -0700, Aahz wrote: > In article , > J. Cliff Dyer wrote: > > > >Glad you're enjoying Beazley. I would look for something more > >up-to-date. Python's come a long way since 2.1. I'd hate for you to > >miss out on all the iterators, booleans, codecs, subprocess, yield, > >unified int/longs, decorators, decimals, sets, context managers and > >new-style classes that have come since then. > > While those are all nice, they certainly aren't essential to learning > Python. Mostly, no, you are correct. With some exceptions: 1) You have to know iterators at a basic level (not enough to understand how the iterator protocol works, but enough to know what 'for line in f:' does. 2) Sets are as essential as any other data structure. If you are learning both lists and tuples, you should be learning sets as well. 3) If you're learning object-oriented programmin, new-style classes should be the only classes you use. 4) You should know how a decorator works, in case you run across one in the wild. 5) Booleans are a basic type. You should know them. Codecs, the subprocess module, yield, decimals and context managers can certainly come later. (All this of course, is assuming the Python 2.x world, which I think is still the right way to learn, for now) Cheers, Cliff > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha From luismgz at gmail.com Wed Jun 24 19:44:48 2009 From: luismgz at gmail.com (Neuruss) Date: Wed, 24 Jun 2009 16:44:48 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: On 23 jun, 12:49, Kurt Smith wrote: > On Mon, Jun 22, 2009 at 9:49 PM, Andras > > > > > > Pikler wrote: > > Hi! > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > > and I am at a loss. > > > Long: I?m doing research/programming for a professor, and we are working > > with MIDI files (a type of simple music file). The research deals with > > generating variations from a musical melody; currently, my Python code uses > > a Python midi package I found online to read the notes in question from a > > midi file, about 350 lines of my own code to generate a variation based on > > these notes and the professor?s algorithms, and finally the package again to > > write the new melody to another midi file. > > > Now, my professor would like to have this exact code in C/C++, as she > > believes C is more compatible with MATLAB, and wants the code to be > > available in multiple languages in case a programmer works for her in the > > future who knows C but not Python. While I know a tiny bit of C (emphasis on > > the tiny), I would much prefer if there were some sort of automatic compiler > > I could use to turn my Python code into C than taking a week or two or three > > to learn the minimum I need about C, find a way to access MIDI files in it, > > and rewrite all of my code. > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > > Python midi package I?m using uses modules which Shedskin does not support. > > Otherwise, I haven?t found much. Is there anything out there to help me do > > this? If not, from anyone who has experience in this regard, how daunting > > should I expect this to be? > > Taking on C from a cold start and being able to handle the ins and > outs of interfacing with Python isn't something that's feasible in > 'two or three weeks'. ?Here are a couple of options -- take 'em or > leave 'em: > > 1) Put the code in Cython:http://www.cython.org/?(full disclosure: > I'm doing a GSoC project with Cython). ?It will convert pretty much > any python code into C code (even closures are supported in the most > recent version, I think), and the C code can then be compiled into an > extension module. > > The only problem with the above is the C code isn't, at first blush, > easy to read. ?Nor is it supposed to be changed by the user. ?So that > leads us to option... > > 2) Write the core functionality in C yourself, and then wrap those C > functions in Cython. ?You'll want to take a look at the documentation: > > http://docs.cython.org/ > > and, more specifically on wrapping C code: > > http://docs.cython.org/docs/external_C_code.html > > I don't think you'll be able to avoid learning C, though. > > Kurt There's another (very good) option: Try shedskin http://code.google.com/p/shedskin/ . Shedskin can compile a whole program or part of it as an extension module. It translates python code to c++ and compiles it. The good thing is that you don't have to know anything about c or c++. You simply have to restrict your coding style a little bit to make it explicitly static. For example: if you declare a = 5, that means that "a" is an integer, so you cannot then change it to a string (a = "hello", won't work). Luis From tommy.nordgren at comhem.se Wed Jun 24 20:20:38 2009 From: tommy.nordgren at comhem.se (Tommy Nordgren) Date: Thu, 25 Jun 2009 02:20:38 +0200 Subject: [Mac] file copy In-Reply-To: <7ac8e0F1tludjU1@mid.uni-berlin.de> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: On Jun 23, 2009, at 4:54 PM, Diez B. Roggisch wrote: > Tobias Weber wrote: > >> Hi, >> which is the best way to copy files on OS X? I want to preserve >> resource >> forks and extended attributes. > > Are these still relevant on OSX? I've always only copied files > directly, and > never had any troubles. > > Diez > -- the cp command copies INCLUDING resource forks, since tiger. ------------------------------------------------------ "Home is not where you are born, but where your heart finds peace" - Tommy Nordgren, "The dying old crone" tommy.nordgren at comhem.se From frank.ruiz at gmail.com Wed Jun 24 20:35:18 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 17:35:18 -0700 Subject: Paramiko help - processing multiple commands In-Reply-To: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> References: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> Message-ID: Hi Jon, Thanks for the reply. So there are no errors. Essentially everything runs as planned. Sorry for being ignorant, but I am not sure if there is another way for providing trace data. I will look into what other debugging I can provide. Essentially what happens is that only the second command gets processed and the first is ignored. As far as the global variables are concerned, I am not too sure what the best way is to allow my variables to be seen by another sub. In the script I am using optparse, however in order for the variables to make any sense to my storagessh sub, I have to declare them as global, since all the variables within my options sub have a local scope. I am not too sure of a better way to do this. I don't like it much either. Hopefully you can help me shed some light on this in terms of best practice. Normally I declare variable scope outside of my subroutines where required. However since variable scope is local within a subroutine, seems like I have to declare them global in order for the other subs to see it. Anyhow.. your feedback has been much appreciated.. The script is still a work in progress, so I plan to do so more cosmetic enhancements once I review it a few more times. Thanks! On Wed, Jun 24, 2009 at 4:34 PM, Jon Clements wrote: > On Jun 24, 11:22?pm, Frank Ruiz wrote: >> Greetings, >> >> I am trying to process multiple commands using paramiko. I have >> searched other threads, and I think my use case is a little different. >> I am trying to login to a storage node that has a special shell, and >> as such I cant execute a script on the storage node side. >> >> I am also trying to avoid using pexpect because I hate making system >> calls.. hence my leaning towards paramiko. >> >> Was hoping someone could help me identify a way to process multiple >> commands using paramiko. >> >> I have two commands listed below, however only one is getting processed. >> >> Any help is much appreciated. >> >> Thanks! >> >> Here is my script: >> >> #!/usr/bin/env python >> >> #-Modules--------------------------------------------------------------------- >> import optparse >> import sys >> import paramiko >> >> #-Variables------------------------------------------------------------------- >> plog = 'storagessh.log' >> suser = 'root' >> >> #-Config---------------------------------------------------------------------- >> >> #-Subs-Defined---------------------------------------------------------------- >> def options(): >> ? ? global hostname >> ? ? global goldenimage >> ? ? global lunclone >> ? ? global sshport >> >> ? ? usage = "usage: %prog [options] -n -g -l " >> >> ? ? parser = optparse.OptionParser(usage) >> >> ? ? parser.add_option("-n", "--node", >> ? ? ? ? ? ? ? ? ? ? ? dest="hostname", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") >> ? ? parser.add_option("-g", "--gold", >> ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") >> ? ? parser.add_option("-l", "--lun", >> ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") >> ? ? parser.add_option("-p", "--port", >> ? ? ? ? ? ? ? ? ? ? ? dest="sshport", >> ? ? ? ? ? ? ? ? ? ? ? default=22, >> ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") >> ? ? options, args = parser.parse_args() >> >> ? ? if not options.hostname: >> ? ? ? ? parser.error("Missing hostname argument.") >> ? ? ? ? exit >> ? ? elif not options.goldenimage: >> ? ? ? ? parser.error("Missing goldenimage argument.") >> ? ? ? ? exit >> ? ? elif not options.lunclone: >> ? ? ? ? parser.error("Missing lun argument.") >> ? ? ? ? exit >> >> ? ? hostname = options.hostname >> ? ? goldenimage = options.goldenimage >> ? ? lunclone = options.lunclone >> ? ? sshport = options.sshport >> >> def storagessh(): >> ? ? paramiko.util.log_to_file(plog) >> ? ? client = paramiko.SSHClient() >> ? ? client.load_system_host_keys() >> ? ? client.connect(hostname, sshport, suser) >> ? ? stdin, stdout, stderr = client.exec_command('show') >> ? ? stdin, stdout, stderr = client.exec_command('help') >> ? ? print stdout.read() >> ? ? client.close() >> >> #--Initialization------------------------------------------------------------- >> if __name__ == "__main__": >> ? ? options() >> ? ? storagessh() > > Again, as you were asked on the original post -- full tracebacks and > explain "what is not working". > > The use of global variables scares me -- why are those needed? > -- > http://mail.python.org/mailman/listinfo/python-list > From sjmachin at lexicon.net Wed Jun 24 20:56:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 17:56:24 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: On Jun 25, 7:17?am, Lie Ryan wrote: > MRAB wrote: > > There's no difference between the two types of quote character. > > a small exception is single-quote can contain double quote but cannot > contain unescaped single quote while double-quote can contain single > quote but cannot contain unescaped double quote. Refinement 1: S can contain D but cannot contain unescaped S D can contain S but cannot contain unescaped D Refinement 2: for Q in list_of_defined_quote_characters: Q can contain non-Q but cannot contain unescaped Q I'd call that orthogonal and a similarity not a small exception to "no difference" :-) From pavlovevidence at gmail.com Wed Jun 24 21:42:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 18:42:25 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: <5fcd261e-eb99-41a3-9814-b7829653f7f0@g23g2000vbr.googlegroups.com> On Jun 24, 7:10?am, Grant Edwards wrote: > On 2009-06-24, Couper, Tim T wrote: > > > Your prof. may find this thread of interest > > >http://mail.python.org/pipermail/python-list/2000-June/039779.html > > > My experience is that developers who know C and C++ can be productive in > > less than 1 week in python, and find it liberating, and educational, to > > do so. And at the same time they will have added a second language to > > their toolbox. As Kurt points out, learning C/C++ takes considerably > > longer (weeks/months to attain a level of competence). > > I agree. ?Your professor is deluded and knows nothing about > software development [not that either is particularly unusual > in an academic setting]. ?Converting a Python program to C or > C++ is a complete waste of time (both now _and_ later) unless > there are severe, insurmountable performance problems with the > Python version. What if the point of asking a student to convert Python to C is to teach them this: > Python is a far, far better language for both real-world > production application development and for algorithm R&D. ?With > Python, you spend your time working on algorithms and solving > real-world problems. ?In C or C++, you spend your time fighting > with the bugs in your code that are preventing the program from > running. ?An algorithm that takes a few hours to implement and > test in Python will take weeks in C or C++. If that [teaching them this] is the case, it might be best use of time they will ever have. Carl Banks From rompubil at gmail.com Wed Jun 24 21:51:56 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 18:51:56 -0700 (PDT) Subject: tkinter: get filename of askopenfilename Message-ID: Hi there, I am writing an interface with Tkinter. My minimal program looks like this: ############# import Tkinter import tkFileDialog root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): filename = tkFileDialog.askopenfilename(filetypes=[("all files","*")]) # print filename root.mainloop() ############# I would like to recover the filename variable outside the "open_file_dialog" function. For instance, to be able to print the selected file name (uncomment "# print filename" line). Is there a way to do that? Thanks in advance. R From pavlovevidence at gmail.com Wed Jun 24 22:42:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 19:42:03 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: On Jun 24, 2:39?am, Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. If you don't mind abusing Python syntax, you can do it using something like this: def DictMaker(name,bases,dct): dct.pop('__metaclass__',None) return dct class a: __metaclass__ = DictMaker home = "/home/test" user1 = home + "/user1" user2 = home + "/user2" python_dev = user1 + "/py-dev" print a Carl Banks From amosanderson at gmail.com Wed Jun 24 23:07:14 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Wed, 24 Jun 2009 22:07:14 -0500 Subject: os.walk and os.listdir problems python 3.0+ Message-ID: I've run into a bit of an issue iterating through files in python 3.0 and 3.1rc2. When it comes to a files with '\u200b' in the file name it gives the error... Traceback (most recent call last): File "ListFiles.py", line 19, in f.write("file:{0}\n".format(i)) File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 30: character maps to Code is as follows... import os f = open("dirlist.txt", 'w') for root, dirs, files in os.walk("C:\\Users\\Filter\\"): f.write("root:{0}\n".format(root)) f.write("dirs:\n") for i in dirs: f.write("dir:{0}\n".format(i)) f.write("files:\n") for i in files: f.write("file:{0}\n".format(i)) f.close() input("done") The file it's choking on happens to be a link that internet explorer created. There are two files that appear in explorer to have the same name but one actually has a zero width space ('\u200b') just before the .url extension. In playing around with this I've found several files with the same character throughout my file system. OS: Vista SP2, Language: US English. Am I doing something wrong or did I find a bug? It's worth noting that Python 2.6 just displays this character as a ? just as it appears if you type dir at the windows command prompt. -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Wed Jun 24 23:25:26 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 24 Jun 2009 20:25:26 -0700 (PDT) Subject: Matplotlib - an odd problem References: Message-ID: <52edee85-f229-448a-ad0d-319f748cfbe6@y28g2000prd.googlegroups.com> On Jun 25, 2:55?am, Jean-Paul Calderone wrote: > On Wed, 24 Jun 2009 11:38:02 -0700 (PDT), koranthala wrote: > >Hi, > >I am using Matplotlib with Django to display charts on the web page. > >I am facing an odd problem in that, everytime I do a refresh on the > >web page, the image darkens - and the text becomes little unreadable. > >5/6 refreshes later, the text becomes completely unreadable. > >Since I am using Django test server, the same process is being used. > >i.e. every refresh does not create a new process. When I tried killing > >the process, the image again cleared. > >So I think it is sort of memory leak or a saved value which is messing > >up something. > >But I cannot seem to find the issue at all. > > >The code is as follows - > > >import pylab > >from cStringIO import StringIO > > >def print_pie_chart(request): > > ? ?labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > > ? ?data = [15,30,45, 10] > > ? ?pylab.figure(1, figsize=(2,2)) > > ? ?ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) > > ? ?pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', > >shadow=True) > > ? ?out = StringIO() > > ? ?pylab.savefig(out, format="PNG") > > ? ?out.seek(0) > > ? ?response = HttpResponse() > > ? ?response['Content-Type'] = 'image/png' > > ? ?response.write(out.read()) > > ? ?return response > > >Can anyone help me out here? > > Your code redraws over the same graph over and over again. ?You need to > create a new graph each time you want to draw something new. ?It took me > ages (and help) to figure out how the non-global APIs in matplotlib. > > Here's an example: > > ? from matplotlib.figure import Figure > ? from matplotlib.axes import Axes > ? from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas > > ? fig = Figure(figsize=(9, 9), dpi=100) > ? axe = Axes(fig, (0, 0, 1.0, 1.0)) > ? axe.pie(range(5)) > ? fig.add_axes(axe) > > ? canvas = FigureCanvas(fig) > ? canvas.set_size_request(640, 480) > > ? fig.savefig("foo.png") > > Hope this helps, > Jean-Paul Thank you Jean-Paul From jeff_barish at earthlink.net Thu Jun 25 00:09:44 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Wed, 24 Jun 2009 22:09:44 -0600 Subject: Problem with multithreading References: Message-ID: Jeffrey Barish wrote: > I have a program that uses multithreading to monitor two loops. When > something happens in loop1, it sends a message to loop2 to have it execute > a command. loop2 might have to return a result. If it does, it puts the > result in a queue. loop1, meanwhile, would have blocked waiting for > something to appear in the queue. The program works for a while, but > eventually freezes. I know that freezing is a sign of deadlock. However, > I put in print statements to localize the problem and discovered something > weird. The freeze always occurs at a point in the code with the following > statements: > > print "about to try" > try: > print "in try" > > > I get "about to try", but not "in try". Is this observation consistent > with > the deadlock theory? If not, what could be making the program freeze at > the try statement? I wrote a test program using the same techniques to > illustrate the problem, but the test program works perfectly. I could > post it, though, if it would help to understand what I am doing -- and > what might be wrong in the real program. As I ponder this problem, I am beginning to believe that the problem is not related to multithreading. If the problem were due to a collision between the two threads then timing would matter, yet I find that the program always freezes at exactly the same statement (which executes perfectly hundreds of times before the freeze). Moreover, the test program that I wrote to test the multithreading implementation works perfectly. And finally, there is nothing going on related to multithreading at this point in the code. Why else might the program freeze at a try statement? -- Jeffrey Barish From norseman at hughes.net Thu Jun 25 00:15:19 2009 From: norseman at hughes.net (norseman) Date: Wed, 24 Jun 2009 21:15:19 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A42F9D7.4080002@hughes.net> rom wrote: > Hi there, > > I am writing an interface with Tkinter. My minimal program looks like > this: > ############# > import Tkinter > import tkFileDialog > # define globals here filename= '' # will take care of the problem > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > filename = tkFileDialog.askopenfilename(filetypes=[("all > files","*")]) > > # print filename > > root.mainloop() > ############# > > I would like to recover the filename variable outside the > "open_file_dialog" function. For instance, to be able to print the > selected file name (uncomment "# print filename" line). > > Is there a way to do that? > > Thanks in advance. > > R From noahdain at gmail.com Thu Jun 25 00:16:13 2009 From: noahdain at gmail.com (Noah Dain) Date: Thu, 25 Jun 2009 00:16:13 -0400 Subject: Paramiko help - processing multiple commands In-Reply-To: References: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> Message-ID: On Wed, Jun 24, 2009 at 8:35 PM, Frank Ruiz wrote: > Hi Jon, > > Thanks for the reply. So there are no errors. Essentially everything > runs as planned. Sorry for being ignorant, but I am not sure if there > is another way for providing trace data. I will look into what other > debugging I can provide. > > Essentially what happens is that only the second command gets > processed and the first is ignored. > > As far as the global variables are concerned, I am not too sure what > the best way is to allow my variables to be seen by another sub. In > the script I am using optparse, however in order for the variables to > make any sense to my storagessh sub, I have to declare them as global, > since all the variables within my options sub have a local scope. > > I am not too sure of a better way to do this. I don't like it much > either. Hopefully you can help me shed some light on this in terms of > best practice. > > Normally I declare variable scope outside of my subroutines where required. > > However since variable scope is local within a subroutine, seems like > I have to declare them global in order for the other subs to see it. > > Anyhow.. your feedback has been much appreciated.. The script is still > a work in progress, so I plan to do so more cosmetic enhancements once > I review it a few more times. > > Thanks! > > On Wed, Jun 24, 2009 at 4:34 PM, Jon Clements wrote: >> On Jun 24, 11:22?pm, Frank Ruiz wrote: >>> Greetings, >>> >>> I am trying to process multiple commands using paramiko. I have >>> searched other threads, and I think my use case is a little different. >>> I am trying to login to a storage node that has a special shell, and >>> as such I cant execute a script on the storage node side. >>> >>> I am also trying to avoid using pexpect because I hate making system >>> calls.. hence my leaning towards paramiko. >>> >>> Was hoping someone could help me identify a way to process multiple >>> commands using paramiko. >>> >>> I have two commands listed below, however only one is getting processed. >>> >>> Any help is much appreciated. >>> >>> Thanks! >>> >>> Here is my script: >>> >>> #!/usr/bin/env python >>> >>> #-Modules--------------------------------------------------------------------- >>> import optparse >>> import sys >>> import paramiko >>> >>> #-Variables------------------------------------------------------------------- >>> plog = 'storagessh.log' >>> suser = 'root' >>> >>> #-Config---------------------------------------------------------------------- >>> >>> #-Subs-Defined---------------------------------------------------------------- >>> def options(): >>> ? ? global hostname >>> ? ? global goldenimage >>> ? ? global lunclone >>> ? ? global sshport >>> >>> ? ? usage = "usage: %prog [options] -n -g -l " >>> >>> ? ? parser = optparse.OptionParser(usage) >>> >>> ? ? parser.add_option("-n", "--node", >>> ? ? ? ? ? ? ? ? ? ? ? dest="hostname", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") >>> ? ? parser.add_option("-g", "--gold", >>> ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") >>> ? ? parser.add_option("-l", "--lun", >>> ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") >>> ? ? parser.add_option("-p", "--port", >>> ? ? ? ? ? ? ? ? ? ? ? dest="sshport", >>> ? ? ? ? ? ? ? ? ? ? ? default=22, >>> ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") >>> ? ? options, args = parser.parse_args() >>> >>> ? ? if not options.hostname: >>> ? ? ? ? parser.error("Missing hostname argument.") >>> ? ? ? ? exit >>> ? ? elif not options.goldenimage: >>> ? ? ? ? parser.error("Missing goldenimage argument.") >>> ? ? ? ? exit >>> ? ? elif not options.lunclone: >>> ? ? ? ? parser.error("Missing lun argument.") >>> ? ? ? ? exit >>> >>> ? ? hostname = options.hostname >>> ? ? goldenimage = options.goldenimage >>> ? ? lunclone = options.lunclone >>> ? ? sshport = options.sshport >>> >>> def storagessh(): >>> ? ? paramiko.util.log_to_file(plog) >>> ? ? client = paramiko.SSHClient() >>> ? ? client.load_system_host_keys() >>> ? ? client.connect(hostname, sshport, suser) >>> ? ? stdin, stdout, stderr = client.exec_command('show') >>> ? ? stdin, stdout, stderr = client.exec_command('help') >>> ? ? print stdout.read() >>> ? ? client.close() >>> >>> #--Initialization------------------------------------------------------------- >>> if __name__ == "__main__": >>> ? ? options() >>> ? ? storagessh() >> >> Again, as you were asked on the original post -- full tracebacks and >> explain "what is not working". >> >> The use of global variables scares me -- why are those needed? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > this works for me: def storagessh(): paramiko.util.log_to_file(plog) client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, suser) stdin, stdout, stderr = client.exec_command('ps') print stdout.read() stdin, stdout, stderr = client.exec_command('help') print stdout.read() client.close() 1) you reassign stdin, stdout, stderr so with your code you will never see the stdout of the first command ('show') 2) the 'show' command did not exist on my system, so no output. I substituted 'ps' and added the print statement also, using user 'root' for dev code is a Bad Thing. -- Noah Dain From norseman at hughes.net Thu Jun 25 00:28:59 2009 From: norseman at hughes.net (norseman) Date: Wed, 24 Jun 2009 21:28:59 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A42FD0B.7090205@hughes.net> OOPS - I left out the global statement rom wrote: > Hi there, > > I am writing an interface with Tkinter. My minimal program looks like > this: > ############# > import Tkinter > import tkFileDialog > # define globals here filename= '' # will take care of the problem > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): global filename # need this to assign to it > filename = tkFileDialog.askopenfilename(filetypes=[("all > files","*")]) > > # print filename > > root.mainloop() > ############# > > I would like to recover the filename variable outside the > "open_file_dialog" function. For instance, to be able to print the > selected file name (uncomment "# print filename" line). > > Is there a way to do that? > > Thanks in advance. > > R From Scott.Daniels at Acm.Org Thu Jun 25 00:29:55 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 21:29:55 -0700 Subject: It's ... In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Angus Rodgers wrote: >> ... my first ... question is how best to find out what's changed from >> version 2.1 > > to version 2.5. (I've recently installed 2.5.4) > Consecutively read: > http://docs.python.org/whatsnew/2.2.html As someone else pointed out: http://www.python.org/doc/2.2.3/whatsnew/whatsnew22.html > http://docs.python.org/whatsnew/2.3.html > http://docs.python.org/whatsnew/2.4.html > http://docs.python.org/whatsnew/2.5.html I forgot to add Richard Gruet's excellent resources, homed here: http://rgruet.free.fr/ You want to check out PQR 2.5 or 2.6 reference; he encodes when (what version) a feature came into the language. SO it is a great overview to read through as you try to take yourself from 2.1 to 2.5. I'd go for the "modern" style unless the colors annoy you. --Scott David Daniels Scott.Daniels at Acm.Org From rompubil at gmail.com Thu Jun 25 00:46:31 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 21:46:31 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: Thanks for your response. I have modified this minimal program as you suggested but still is not able to print the filename: ###################### import Tkinter import tkFileDialog global filename filename='' root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print filename root.mainloop() ###################### Is this what you mean? On Jun 25, 1:28?pm, norseman wrote: > OOPS - I left out the global statement > > rom wrote: > > Hi there, > > > I am writing an interface with Tkinter. My minimal program looks like > > this: > > ############# > > import Tkinter > > import tkFileDialog > > # define globals here > filename= '' ? ? # will take care of the problem > > > root = Tkinter.Tk() > > > Tkinter.Button(root, text='Notch genes...', command=lambda: > > open_file_dialog()).pack() > > > def open_file_dialog(): > > ? ? ? ?global filename ? # need this to assign to it > > > ? ? filename = tkFileDialog.askopenfilename(filetypes=[("all > > files","*")]) > > > # print filename > > > root.mainloop() > > ############# > > > I would like to recover the filename variable outside the > > "open_file_dialog" function. For instance, to be able to print the > > selected file name (uncomment "# print filename" line). > > > Is there a way to do that? > > > Thanks in advance. > > > R > > From mail131 at gmail.com Thu Jun 25 00:57:36 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 21:57:36 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <08d4e77c-eb46-41ea-a970-c20b947a442a@g20g2000vba.googlegroups.com> On Jun 24, 11:00?pm, Peter Otten <__pete... at web.de> wrote: > Private Private wrote: > > > lines = fileinput.input(filename) > > > for line in lines: > > > ? ? if "Data2" in line: > > > ? ? ? ? print line.strip(), "-->", next(lines).strip() > > > I get an error: > > > ... > > ? ? print line.strip(), "-->", next(lines).strip() > > NameError: global name 'next' is not defined > > In Python versions prior to 2.6 instead of > > next(lines) > > you can use > > lines.next() > > Peter That works perfectly. Thank you :-) From mail131 at gmail.com Thu Jun 25 01:02:27 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 22:02:27 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: On Jun 24, 12:23?pm, Przemyslaw Bak wrote: > Hello, > > I many files with log data. The structure of the file is quite Each requested value is in separated file. While traversing using os.path.walk I have noticed that I get files unsorted. Is it possible to get them sorted ? przemol From Scott.Daniels at Acm.Org Thu Jun 25 01:12:25 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 22:12:25 -0700 Subject: Problem with multithreading In-Reply-To: References: Message-ID: <4umdnc6YSuk8mN7XnZ2dnUVZ_vidnZ2d@pdx.net> Jeffrey Barish wrote: > Jeffrey Barish wrote: >> >> print "about to try" >> try: >> print "in try" >> .... > > As I ponder this problem, I am beginning to believe that the problem is not > related to multithreading. If the problem were due to a collision between > the two threads then timing would matter, yet I find that the program > always freezes at exactly the same statement (which executes perfectly > hundreds of times before the freeze). Moreover, the test program that I > wrote to test the multithreading implementation works perfectly. And > finally, there is nothing going on related to multithreading at this point > in the code. Why else might the program freeze at a try statement? Or a print statement or ... We need more clues than three lines of source. --Scott David Daniels Scott.Daniels at Acm.Org From rompubil at gmail.com Thu Jun 25 01:44:25 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 22:44:25 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> Ok. I think I got it. I have to do it in this way: ########################### import Tkinter import tkFileDialog filename='' root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print_filename() def print_filename(): print filename root.mainloop() ########################### Thanks again On Jun 25, 1:46?pm, rom wrote: > Thanks for your response. I have modified this minimal program as you > suggested but still is not able to print the filename: > > ###################### > import Tkinter > import tkFileDialog > > global filename > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > print filename > > root.mainloop() > ###################### > > Is this what you mean? > > On Jun 25, 1:28?pm, norseman wrote: > > > OOPS - I left out the global statement > > > rom wrote: > > > Hi there, > > > > I am writing an interface with Tkinter. My minimal program looks like > > > this: > > > ############# > > > import Tkinter > > > import tkFileDialog > > > # define globals here > > filename= '' ? ? # will take care of the problem > > > > root = Tkinter.Tk() > > > > Tkinter.Button(root, text='Notch genes...', command=lambda: > > > open_file_dialog()).pack() > > > > def open_file_dialog(): > > > ? ? ? ?global filename ? # need this to assign to it > > > > ? ? filename = tkFileDialog.askopenfilename(filetypes=[("all > > > files","*")]) > > > > # print filename > > > > root.mainloop() > > > ############# > > > > I would like to recover the filename variable outside the > > > "open_file_dialog" function. For instance, to be able to print the > > > selected file name (uncomment "# print filename" line). > > > > Is there a way to do that? > > > > Thanks in advance. > > > > R > > From metolone+gmane at gmail.com Thu Jun 25 01:57:02 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 24 Jun 2009 22:57:02 -0700 Subject: os.walk and os.listdir problems python 3.0+ References: Message-ID: "Amos Anderson" wrote in message news:a073a9cf0906242007k5067314dn8e9d7b1c6da6286a at mail.gmail.com... > I've run into a bit of an issue iterating through files in python 3.0 and > 3.1rc2. When it comes to a files with '\u200b' in the file name it gives > the > error... > > Traceback (most recent call last): > File "ListFiles.py", line 19, in > f.write("file:{0}\n".format(i)) > File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_table)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in > position > 30: character maps to > > Code is as follows... > import os > f = open("dirlist.txt", 'w') > > for root, dirs, files in os.walk("C:\\Users\\Filter\\"): > f.write("root:{0}\n".format(root)) > f.write("dirs:\n") > for i in dirs: > f.write("dir:{0}\n".format(i)) > f.write("files:\n") > for i in files: > f.write("file:{0}\n".format(i)) > f.close() > input("done") > > The file it's choking on happens to be a link that internet explorer > created. There are two files that appear in explorer to have the same name > but one actually has a zero width space ('\u200b') just before the .url > extension. In playing around with this I've found several files with the > same character throughout my file system. OS: Vista SP2, Language: US > English. > > Am I doing something wrong or did I find a bug? It's worth noting that > Python 2.6 just displays this character as a ? just as it appears if you > type dir at the windows command prompt. In Python 3.x strings default to Unicode. Unless you choose an encoding, Python will use the default system encoding to encode the Unicode strings into a file. On Windows, the filesystem uses Unicode and supports the full character set, but cp1252 (on your system) is the default text file encoding, which doesn't support zero-width space. Specify an encoding for the output file such as UTF-8: >>> f=open('blah.txt','w',encoding='utf8') >>> f.write('\u200b') 1 >>> f.close() -Mark From wbrehaut at mcsnet.ca Thu Jun 25 02:04:12 2009 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Thu, 25 Jun 2009 00:04:12 -0600 Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh wrote: >Hi All, > >I am trying to move my application on a MVC architecture and plan to >use Jinja for the same. Can anyone provide me with few quick links >that might help me to get started with Jinja? Perhaps the most useful link is: http://www.google.com/ from which you can easily find many more with a very basic search, including: http://jinja.pocoo.org/ Hope that helps? wwwayne > >Thanks, >Saby From twirlip at bigfoot.com Thu Jun 25 03:05:58 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 08:05:58 +0100 Subject: [SPAM] It's ... References: Message-ID: Someone has gently directed me to the Tutor mailing list: which I hadn't known about. I've joined, and will try to confine my initial blundering experiments to there. Sorry about the spam spam spam spam, lovely spam, wonderful spam! -- Angus Rodgers From sean_mcilroy at yahoo.com Thu Jun 25 03:12:22 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Thu, 25 Jun 2009 00:12:22 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> i think what he means is to put the global declaration inside the function that assigns to filename: def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) as it was, the function was creating a new variable called filename and assigning to THAT (and then doing absolutely nothing with it). with the above modification, the function understands that filename refers to the global variable of that name, and that variable's value does indeed get printed, but since the print statement comes before root.mainloop() -- hence before the button gets pressed -- filename gets printed before the function has assigned to it. this fact becomes apparent if you initialize the variable with filename='blank' (for example). putting the print statement after root.mainloop() doesn't work either, since root.mainloop() keeps control from getting to the print statement. the effect i think you want can be gotten from putting the print statement into the function as well, so what you end up with is this: import Tkinter import tkFileDialog filename = 'uninitialized' def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print filename root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=open_file_dialog).pack() root.mainloop() From mail at microcorp.co.za Thu Jun 25 03:18:32 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 25 Jun 2009 09:18:32 +0200 Subject: Fw: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) Message-ID: <00eb01c9f565$25bfd240$0d00a8c0@Hendrik> Below is one that just disappeared, without any feedback: (unless I just missed it) - Hendrik ----- Original Message ----- From: "Hendrik van Rooyen" To: "Aahz" ; Sent: Wednesday, June 24, 2009 10:08 AM Subject: Re: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) > "Aahz" wrote: > > > While that's also a bug in Mailman (I have a long-standing to-do item to > > fix that), there are also plenty of posts that simply aren't showing up > > in c.l.py. As I said, I'm pretty sure (based on what was happening with > > c.l.py.announce) that it's some kind of weird problem with the mail->news > > gateway with MIME posts. > > I have lately had some posts returned with a "seems to be forged" message. > Two reasons for that: > - first is if I use the smtp server from our local telco - saix - then there is > no apparent relationship between where the message comes from and > where it comes from, if you follow my Irish... > - Second is if the same telco assigns me an IP that has been put on a list > of bad boy IPs. > > So it is kind of pot luck if you see this message or not. > > - Hendrik > From mail131 at gmail.com Thu Jun 25 03:29:28 2009 From: mail131 at gmail.com (Private Private) Date: Thu, 25 Jun 2009 00:29:28 -0700 (PDT) Subject: Python simple web development Message-ID: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Hi, I am looking for a python library which will allow me to do a simple web development. I need to use some forms (but nice looking :-) ), creating images based on input from those forms, etc. I have read a bit about Django and TurboGears but I am afraid that this is too big for my requirements (am I wrong ?). Can you suggest anything ? From steven at REMOVE.THIS.cybersource.com.au Thu Jun 25 03:34:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Jun 2009 07:34:24 GMT Subject: Barbara Liskov wins Turing Award Message-ID: I haven't seen any links to this here: Barbara Liskov has won the Turing Award: http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? [quote] Institute Professor Barbara Liskov has won the Association for Computing Machinery's A.M. Turing Award, one of the highest honors in science and engineering, for her pioneering work in the design of computer programming languages. Liskov's achievements underpin virtually every modern computing-related convenience in people's daily lives. [end quote] Liskov is well known for the "Liskov substitution principle". She also created the language CLU, one of the most important inspirations to Python, and coined the term "pass by object" (also known as "pass by object reference") to describe CLU's then novel argument passing behaviour. Such behaviour has since become a virtual standard for OO languages such as Python and Java. -- Steven From clp2 at rebertia.com Thu Jun 25 03:43:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Jun 2009 00:43:43 -0700 Subject: Barbara Liskov wins Turing Award In-Reply-To: References: Message-ID: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> On Thu, Jun 25, 2009 at 12:34 AM, Steven D'Aprano wrote: > I haven't seen any links to this here: Barbara Liskov has won the Turing > Award: > > http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? > > > [quote] > Institute Professor Barbara Liskov has won the Association for Computing > Machinery's A.M. Turing Award, one of the highest honors in science and > engineering, for her pioneering work in the design of computer > programming languages. Liskov's achievements underpin virtually every > modern computing-related convenience in people's daily lives. > [end quote] > > Liskov is well known for the "Liskov substitution principle". She also > created the language CLU, one of the most important inspirations to > Python Erm, Wikipedia (which is generally excellent on programming topics) seems to disagree with you. http://en.wikipedia.org/wiki/Python_(programming_language) "Influenced by ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java" Unless you mean it influenced Python indirectly by way of the aforelisted languages... Cheers, Chris -- http://blog.rebertia.com From rompubil at gmail.com Thu Jun 25 04:02:08 2009 From: rompubil at gmail.com (rom) Date: Thu, 25 Jun 2009 01:02:08 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> Message-ID: <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> Thanks again. After your replies, I have understood how to do what I wanted. What I wanted to do is to get a value after clicking a button and use it in another part of the program. As you said, after getting the value, I have to store it in a global variable. However, the program does not do anything with it until I trigger another event, e.g. by clicking on another button. Therefore, I have added another button to my program: ##################### import Tkinter import tkFileDialog filename = 'uninitialized' def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) def print_variable(variable): print variable root = Tkinter.Tk() Tkinter.Button(root, text='Select file...', command=open_file_dialog).pack() Tkinter.Button(root, text='Print file', command=lambda: print_variable (filename)).pack() root.mainloop() ##################### On Jun 25, 4:12?pm, Sean McIlroy wrote: > i think what he means is to put the global declaration inside the > function that assigns to filename: > > def open_file_dialog(): > ? ? global filename > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > as it was, the function was creating a new variable called filename > and assigning to THAT (and then doing absolutely nothing with it). > with the above modification, the function understands that filename > refers to the global variable of that name, and that variable's value > does indeed get printed, but since the print statement comes before > root.mainloop() -- hence before the button gets pressed -- filename > gets printed before the function has assigned to it. this fact becomes > apparent if you initialize the variable with filename='blank' (for > example). putting the print statement after root.mainloop() doesn't > work either, since root.mainloop() keeps control from getting to the > print statement. the effect i think you want can be gotten from > putting the print statement into the function as well, so what you end > up with is this: > > import Tkinter > import tkFileDialog > > filename = 'uninitialized' > > def open_file_dialog(): > ? ? global filename > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > ? ? print filename > > root = Tkinter.Tk() > Tkinter.Button(root, text='Notch genes...', > command=open_file_dialog).pack() > root.mainloop() From bieffe62 at gmail.com Thu Jun 25 04:33:08 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 01:33:08 -0700 (PDT) Subject: Recipes for trace statements inside python programs? Message-ID: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Hi all, as many - I think - python programmers, I find muself debugging my scripts by placing print statements in strategic places rather than using the python debugger, and commenting/uncommenting them according to myy deugging needs. After a time, these prints staements start to evolving in some ad-hoc half-baked framework ... so I wonder if there is somewhere there is a full-baked trace statement support framework which I can use. I'm aware of the logging module, but for me it its more geared toward application logging rather than toward trace for debugging purpose. Having googlet and found nothing (or too much but nothing relef?vant), I'm now asking The List. Here is what I have in mind: Each module, function, class and method should have an attribute, say trace_flag, which can be set to true or false value. there should be a function TRACE which does something like this: if __debug__ : def TRACE(*args): if trace_enabled(): print "TRACE(%s) : %s " % ( context(), " ".join( str(x) for x in args ) ) where trace_enabled() should return the value of the innermost trace_flag (checking current function/method then current class (if any) then current module) and context() shoud return a string like "module.function" or "module.class.method" ). At this point I could in my test code enable the trace in the function/class that gives me trouble and disable it after I fixed it, without having to touch the actual code under test. I guess it should not be too hard do using python introspection modules, but of couse I first would like to know if something like this already exists. I'm aware that this imposes a performance penalty, but my scripts are not operformance-critical. And if I put an if __debug__ switch From bieffe62 at gmail.com Thu Jun 25 04:40:01 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 01:40:01 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: Sorry, hit the send button by mistake ... The definition of the trace function should be like: if __debug__ : def TRACE(*args): if trace_enabled(): print "TRACE(%s) : %s " % ( context(), " ".join( str(x) for x in args ) ) else : # optimazed code, only a function call performance penalty def TRACE(*args): pass If I don't find anything suitable, maybe I will bake my own again, this time aiming to something that I can reuse ... Ciao and thanks for any tip/suggestion ------ FB From tjreedy at udel.edu Thu Jun 25 04:49:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 04:49:19 -0400 Subject: Barbara Liskov wins Turing Award In-Reply-To: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> References: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jun 25, 2009 at 12:34 AM, Steven > D'Aprano wrote: >> I haven't seen any links to this here: Barbara Liskov has won the Turing >> Award: It was posted about the time of the announcement, but is worth the reminded. >> http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? >> >> >> [quote] >> Institute Professor Barbara Liskov has won the Association for Computing >> Machinery's A.M. Turing Award, one of the highest honors in science and >> engineering, for her pioneering work in the design of computer >> programming languages. Liskov's achievements underpin virtually every >> modern computing-related convenience in people's daily lives. >> [end quote] >> >> Liskov is well known for the "Liskov substitution principle". She also >> created the language CLU, one of the most important inspirations to >> Python This inspired me to to spend a couple of hours finding and reading a CLU manual. > Erm, Wikipedia (which is generally excellent on programming topics) > seems to disagree with you. > > http://en.wikipedia.org/wiki/Python_(programming_language) > "Influenced by ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java" > > Unless you mean it influenced Python indirectly by way of the > aforelisted languages... Python's object model, assignment semantics, and call-by-object mechanism, and that name, come from CLU. Whether Guido knew of it directly or not, I do not know. To the extent that the above is part of the heart of Python, I think Steven's statement stands pretty well. From chris at simplistix.co.uk Thu Jun 25 04:59:06 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 25 Jun 2009 09:59:06 +0100 Subject: Python simple web development In-Reply-To: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <4A433C5A.5010101@simplistix.co.uk> Private Private wrote: > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). You are wrong :-) > Can you suggest anything ? http://www.djangoproject.com/ http://bfg.repoze.org/ http://pylonshq.com/ Drink whichever koolaid you like the taste of :-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From robin at reportlab.com Thu Jun 25 05:01:53 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 25 Jun 2009 10:01:53 +0100 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <4A433D01.3060506@chamonix.reportlab.co.uk> pdpi wrote: ....... > > But yeah, Log2 and LogE are the only two bases that make "natural" > sense except in specialized contexts. Base 10 (and, therefore, Log10) > is an artifact of having that 10 fingers (in fact, whatever base you > use, you always refer to it as base 10). someone once explained to me that the set of systems that are continuous in the calculus sense was of measure zero in the set of all systems I think it was a fairly formal discussion, but my understanding was of the hand waving sort. If true that makes calculus (and hence all of our understanding of such "natural" concepts) pretty small and perhaps non-applicable. On the other hand R Kalman (of Bucy and Kalman filter fame) likened study of continuous linear dynamical systems to "a man searching for a lost ring under the only light in a dark street" ie we search where we can see. Because such systems are tractable doesn't make them natural or essential or applicable in a generic sense. -- Robin Becker From martin.hellwig at dcuktec.org Thu Jun 25 05:10:50 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Jun 2009 10:10:50 +0100 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: Chris Rebert wrote: > > In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. > > Cheers, > Chris Let me demonstrate: Chris, I have no sympathy for you :-) -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From lucaberto at libero.it Thu Jun 25 05:15:57 2009 From: lucaberto at libero.it (luca72) Date: Thu, 25 Jun 2009 02:15:57 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> <7a9bj5F1uhor1U1@mid.uni-berlin.de> Message-ID: <186cfa90-c309-4266-aae0-a89f9e49ef95@v4g2000vba.googlegroups.com> Hello but find_library find only the lib. but if i need to load from a list of lib how i have to do. My proble is that i have 5 lib (a,b,c,d,e), if i load the a i get lib b not found, if for first i load the b and than the a i get the same error how i have to proceed. Thanks Luca From http Thu Jun 25 05:38:44 2009 From: http (Paul Rubin) Date: 25 Jun 2009 02:38:44 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <7x63eky7ob.fsf@ruckus.brouhaha.com> Robin Becker writes: > someone once explained to me that the set of systems that are > continuous in the calculus sense was of measure zero in the set of all > systems I think it was a fairly formal discussion, but my > understanding was of the hand waving sort. That is very straightforward if you don't mind a handwave. Let S be some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 otherwise (this is a discontinuous function if S is nonempty). How many different such f's can there be? Obviously one for every possible subset of the reals. The cardinality of such f's is the power set of the reals, i.e. much larger than the set of reals. On the other hand, let g be some arbitrary continuous function on the reals. Let H be the image of Q (the set of rationals) under g. That is, H = {g(x) such that x is rational}. Since g is continuous, it is completely determined by H, which is a countable set. So the cardinality is RxN which is the same as the cardinality of R. > If true that makes calculus (and hence all of our understanding of > such "natural" concepts) pretty small and perhaps non-applicable. No really, it is just set theory, which is a pretty bogus subject in some sense. There aren't many discontinuous functions in nature. There is a philosophy of mathematics (intuitionism) that says classical set theory is wrong and in fact there are NO discontinuous functions. They have their own mathematical axioms which allow developing calculus in a way that all functions are continuous. > On the other hand R Kalman (of Bucy and Kalman filter fame) likened > study of continuous linear dynamical systems to "a man searching for > a lost ring under the only light in a dark street" ie we search > where we can see. Because such systems are tractable doesn't make > them natural or essential or applicable in a generic sense. Really, I think the alternative he was thinking of may have been something like nonlinear PDE's, a horribly messy subject from a practical point of view, but still basically free of set-theoretic monstrosities. The Banach-Tarski paradox has nothing to do with nature. From nospam at invalid.invalid Thu Jun 25 06:05:58 2009 From: nospam at invalid.invalid (robert) Date: Thu, 25 Jun 2009 12:05:58 +0200 Subject: print u'\u2013' error on console/terminal Message-ID: >>> sys.stdout.encoding 'cp850' >>> print u'\u2013' Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position 0: character maps to >>> sys.stdout.encoding='xy' Traceback (most recent call last): File "", line 1, in TypeError: readonly attribute is there a switch to suppress those encoding errors for standard print's on the console - e.g. for getting automatic behavior like 'replace' : >>> print u'a \2013 b'.encode('cp850','replace') a ?3 b >>> or a new filter file class necessary? From koranthala at gmail.com Thu Jun 25 07:15:23 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 25 Jun 2009 04:15:23 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <00402361-e5f7-4583-975b-fa9a72048098@y6g2000prf.googlegroups.com> On Jun 25, 1:40?pm, Francesco Bochicchio wrote: > Sorry, hit the send button by mistake ... > The definition of the trace function should be like: > > if __debug__ : > ? ?def TRACE(*args): > ? ? ?if ?trace_enabled(): print "TRACE(%s) : %s " % ( context(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " ".join( str(x) for x in args ) ) > else : # optimazed code, only a function call performance penalty > ? ?def TRACE(*args): pass > > If I don't find anything suitable, maybe I will bake my own again, > this > time aiming to something that I can reuse ... > > Ciao and thanks for any tip/suggestion > ------ > FB Is assert what you are looking for? From samwyse at gmail.com Thu Jun 25 07:22:39 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 04:22:39 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <9ce574ea-2638-4f85-a61b-b594bb592e7f@r36g2000vbn.googlegroups.com> I use an @trace decorator. This (http://wordaligned.org/articles/ echo) will get you started but there are lots of others available. My personal preference is a decorator that catches, displays and re- raises exceptions as well as displaying both calling parameters and returned values. btw, here's a cool Python3K (or 2.6 if you turn on print functions) trick that's sort-of on topic since it relates to log files and such: import functools, sys warn = functools.partial(print, file=sys.stderr) logfile = open(...) log = functools.partial(print, file=logfile) # etc. On Jun 25, 3:33?am, Francesco Bochicchio wrote: > Hi all, > > as many - I think - python programmers, I find muself debugging my > scripts by placing print statements in strategic places rather than > using the python debugger, and commenting/uncommenting them according > to myy deugging needs. ?After a time, these prints staements start to > evolving in some ad-hoc half-baked framework ... so I wonder if there > is somewhere there is a full-baked trace statement support framework > which I can use. I'm aware of the logging module, but for me it its > more geared toward ?application logging rather than toward trace for > debugging purpose. From rajat.dudeja at aeroflex.com Thu Jun 25 07:22:54 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Thu, 25 Jun 2009 07:22:54 -0400 Subject: How to get filename from a pid? Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> Hi, I've a PID of a process (the process is a notepad application), I want to know which file is opened by this process. regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Thu Jun 25 07:23:07 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 25 Jun 2009 12:23:07 +0100 Subject: Measuring Fractal Dimension ? In-Reply-To: <7x63eky7ob.fsf@ruckus.brouhaha.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <4A435E1B.3040701@chamonix.reportlab.co.uk> Paul Rubin wrote: ......... > That is very straightforward if you don't mind a handwave. Let S be > some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 > otherwise (this is a discontinuous function if S is nonempty). How > many different such f's can there be? Obviously one for every > possible subset of the reals. The cardinality of such f's is the > power set of the reals, i.e. much larger than the set of reals. > > On the other hand, let g be some arbitrary continuous function on the > reals. Let H be the image of Q (the set of rationals) under g. That > is, H = {g(x) such that x is rational}. Since g is continuous, it is > completely determined by H, which is a countable set. So the > cardinality is RxN which is the same as the cardinality of R. > ok so probably true then > >> If true that makes calculus (and hence all of our understanding of >> such "natural" concepts) pretty small and perhaps non-applicable. > > No really, it is just set theory, which is a pretty bogus subject in > some sense. There aren't many discontinuous functions in nature. > There is a philosophy of mathematics (intuitionism) that says > classical set theory is wrong and in fact there are NO discontinuous > functions. They have their own mathematical axioms which allow > developing calculus in a way that all functions are continuous. > so does this render all the discreteness implied by quantum theory unreliable? or is it that we just cannot see(measure) the continuity that really happens? Certainly there are people like Wolfram who seem to think we're in some kind of giant calculating engine where state transitions are discontinuous. >> On the other hand R Kalman (of Bucy and Kalman filter fame) likened >> study of continuous linear dynamical systems to "a man searching for >> a lost ring under the only light in a dark street" ie we search >> where we can see. Because such systems are tractable doesn't make >> them natural or essential or applicable in a generic sense. > > Really, I think the alternative he was thinking of may have been > something like nonlinear PDE's, a horribly messy subject from a > practical point of view, but still basically free of set-theoretic > monstrosities. The Banach-Tarski paradox has nothing to do with nature. My memory of his seminar was that he was concerned about our failure to model even the simplest of systems with non-linearity and/or discreteness. I seem to recall that was about the time that chaotic behaviours were starting to appear in the control literature and they certainly depend on non-linearity. -- Robin Becker From samwyse at gmail.com Thu Jun 25 07:27:57 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 04:27:57 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <876f577b-733f-4714-b520-0d087fd38ffc@q37g2000vbi.googlegroups.com> I just started with web2py (http://www.web2py.com/) for an internal- use-only app that doesn't need to be very pretty. Been using it for about a week and after re-watching the tutorial, I've decided that I'm making things way too complicated. So today I'm going to replace a lot of my code with some built-ins. On Jun 25, 2:29?am, Private Private wrote: > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? From bieffe62 at gmail.com Thu Jun 25 08:06:31 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 05:06:31 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> <00402361-e5f7-4583-975b-fa9a72048098@y6g2000prf.googlegroups.com> Message-ID: On 25 Giu, 13:15, koranthala wrote: > On Jun 25, 1:40?pm, Francesco Bochicchio wrote: > > > Is assert what you are looking for? > No. Assert raises exception if some condition is met. I just want to be able to enable/disable the printout of intermediate data, on a per function/method/class/module basis, without altering the execution flow. Ciao --- FB From gnperumal at gmail.com Thu Jun 25 08:06:55 2009 From: gnperumal at gmail.com (krishna) Date: Thu, 25 Jun 2009 05:06:55 -0700 (PDT) Subject: How to convert he boolean values into integers Message-ID: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Hi Guys, I need to convert 1010100110 boolean value to some think like 2345, if its possible then post me your comment on this Advanced thanks for all Narayana perumal.G From dusan.smitran at gmail.com Thu Jun 25 08:14:48 2009 From: dusan.smitran at gmail.com (dusans) Date: Thu, 25 Jun 2009 05:14:48 -0700 (PDT) Subject: scipy stats binom_test Message-ID: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> Amm i using the function wrong or ...? cuz in R i get the right value >>> binom_test(3, 5, p=0.8) 0.262 > dbinom(3, 5, 0.8) [1] 0.205 From eckhardt at satorlaser.com Thu Jun 25 08:20:41 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 25 Jun 2009 14:20:41 +0200 Subject: How to convert he boolean values into integers References: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Message-ID: krishna wrote: > I need to convert 1010100110 boolean value to some think like 2345, if > its possible then post me your comment on this Yes, sure. You can simply sum up the digit values and then format them as decimal number. You can also just look up the number: def decode_binary(input): for i in range(2**len(input)): if bin(i)==input: return str(i) I Hope I was able to help you with your homework! ;^) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From samwyse at gmail.com Thu Jun 25 08:31:04 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 05:31:04 -0700 (PDT) Subject: I need a dict that inherits its mappings Message-ID: I need a dict-like object that, if it doesn't contain a key, will return the value from a "parent" object. Is there an easy way to do this so I don't have to define __getitem__ and __contains__ and others that I haven't even thought of yet? Here's a use case, if you're confused: en_GB=mydict() en_US=mydict(en_GB) en_GB['bonnet']='part of your car' print en_US['bonnet'] # prints 'part of your car' en_US['bonnet']='a type of hat' print en_US['bonnet'] # prints 'a type of hat' print en_GB['bonnet'] # prints 'part of your car' From samwyse at gmail.com Thu Jun 25 08:33:02 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 05:33:02 -0700 (PDT) Subject: How to convert he boolean values into integers References: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Message-ID: >>> int('1010100110', 2) 678 On Jun 25, 7:06?am, krishna wrote: > Hi Guys, > > I need to convert 1010100110 boolean value to some think like 2345, if > its possible then post me your comment on this > > Advanced thanks for all > > Narayana perumal.G From mail at timgolden.me.uk Thu Jun 25 08:52:55 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Jun 2009 13:52:55 +0100 Subject: How to get filename from a pid? In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> Message-ID: <4A437327.2020204@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I've a PID of a process (the process is a notepad application), > I want to know which file is opened by this process. Is there anything wrong with this answer which I gave you last week? (Note: there might be, but the fact that you seem to have ignored it makes me wonder...) http://groups.google.com/group/comp.lang.python/msg/6a44e15473b08de0?hl=en TJG From horos11 at gmail.com Thu Jun 25 08:56:45 2009 From: horos11 at gmail.com (Edward Peschko) Date: Thu, 25 Jun 2009 05:56:45 -0700 Subject: trace options Message-ID: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> All, I've been looking at the trace module, and although it looks useful, I'm surprised that there aren't a couple of features that I would have thought would be fairly basic. So, does trace support (for the --trace option): - indentation tracking stacklevel (where each function is prefixed by tabs equal to the number of stacklevels deep in the program) - output to something other than sys.stdout (eg. output to a file specified either by environmental variable or by parameter). - mult-threaded programs going to multiple output handles, especially in light of the above - fully qualified python modules in path: (eg: /path/to/module/my_module.py(1): print "HERE" instead of my_module.py(1): print "HERE". Ultimately, I'd like to be able to look at two runs of a program and be able to pinpoint the very first difference between thembased on the output of their trace runs. As it stands, I really can't do this. Of course I could implement the above, but I was hoping to avoid duplicated effort if someone has already implemented options like this..I posted the above to the python-dev list, they suggested I take it here, so any help would be appreciated. Ed From jcd at sdf.lonestar.org Thu Jun 25 09:37:58 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Thu, 25 Jun 2009 09:37:58 -0400 Subject: Paramiko help - processing multiple commands In-Reply-To: References: Message-ID: <1245937078.28168.9.camel@mctell> On Wed, 2009-06-24 at 15:22 -0700, Frank Ruiz wrote: > Greetings, > > I am trying to process multiple commands using paramiko. I have > searched other threads, and I think my use case is a little different. > I am trying to login to a storage node that has a special shell, and > as such I cant execute a script on the storage node side. > > I am also trying to avoid using pexpect because I hate making system > calls.. hence my leaning towards paramiko. > > Was hoping someone could help me identify a way to process multiple > commands using paramiko. > > I have two commands listed below, however only one is getting processed. > > Any help is much appreciated. > > Thanks! > > Here is my script: > > #!/usr/bin/env python > > > #-Modules--------------------------------------------------------------------- > import optparse > import sys > import paramiko > > > #-Variables------------------------------------------------------------------- > plog = 'storagessh.log' > suser = 'root' > > > #-Config---------------------------------------------------------------------- > > #-Subs-Defined---------------------------------------------------------------- > def options(): > global hostname > global goldenimage > global lunclone > global sshport > > usage = "usage: %prog [options] -n -g -l " > > parser = optparse.OptionParser(usage) > > parser.add_option("-n", "--node", > dest="hostname", > help="Name of storage node you are connecting to.") > parser.add_option("-g", "--gold", > dest="goldenimage", > help="Name of goldenimage to clone.") > parser.add_option("-l", "--lun", > dest="lunclone", > help="Name of lun to create.") > parser.add_option("-p", "--port", > dest="sshport", > default=22, > help="SSH port number.") > options, args = parser.parse_args() > > if not options.hostname: > parser.error("Missing hostname argument.") > exit > elif not options.goldenimage: > parser.error("Missing goldenimage argument.") > exit > elif not options.lunclone: > parser.error("Missing lun argument.") > exit > > hostname = options.hostname > goldenimage = options.goldenimage > lunclone = options.lunclone > sshport = options.sshport > It looks like you are trying to create a configuration class, but going through extra gyrations to use global variables instead. Perl's class system is rather convoluted, but it is straightforward in python, and will make your code easier to maintain. I recommend you take a look at the section on classes in the python tutorial, and play around with it. Not everything needs to be a class in python, but in certain cases (and this is one of them) it will make things much cleaner. > def storagessh(): > paramiko.util.log_to_file(plog) > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, suser) > stdin, stdout, stderr = client.exec_command('show') > stdin, stdout, stderr = client.exec_command('help') > print stdout.read() > client.close() > You just did it. You processed two commands. The only problem is that you wrote values to stdin, stdout, and stderr with the show command, and then immediately overwrote them with the help command. Use different variable names for each command (like stdout_show and stdout_help), and you should be fine. > > > > #--Initialization------------------------------------------------------------- > if __name__ == "__main__": > options() > storagessh() From gagsl-py2 at yahoo.com.ar Thu Jun 25 09:59:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Jun 2009 10:59:40 -0300 Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: En Sun, 21 Jun 2009 21:48:29 -0300, Arlie escribi?: > Newbie here using Python 2.6.2 on MS WinXP Pro SP3. I'm trying create > an frozen exec and was able to generate and exe file. Have you tried py2exe? > Imported files in myprog.py: > import MySQLdb Probably using MySQLdb requires some extra work... Try a more specific forum, http://www.pyinstaller.org/ menctions a mailing list. -- Gabriel Genellina From amosanderson at gmail.com Thu Jun 25 10:15:15 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Thu, 25 Jun 2009 09:15:15 -0500 Subject: os.walk and os.listdir problems python 3.0+ In-Reply-To: References: Message-ID: Thank you. That works very well when writing to a text file but what is the equivalent when writing the information to stdout using print? Sorry when I originally replied I sent it directly and it didn't go to the list. On Thu, Jun 25, 2009 at 12:57 AM, Mark Tolonen > wrote: > > "Amos Anderson" wrote in message > news:a073a9cf0906242007k5067314dn8e9d7b1c6da6286a at mail.gmail.com... > > I've run into a bit of an issue iterating through files in python 3.0 and >> 3.1rc2. When it comes to a files with '\u200b' in the file name it gives >> the >> error... >> >> Traceback (most recent call last): >> File "ListFiles.py", line 19, in >> f.write("file:{0}\n".format(i)) >> File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode >> return codecs.charmap_encode(input,self.errors,encoding_table)[0] >> UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in >> position >> 30: character maps to >> >> Code is as follows... >> import os >> f = open("dirlist.txt", 'w') >> >> for root, dirs, files in os.walk("C:\\Users\\Filter\\"): >> f.write("root:{0}\n".format(root)) >> f.write("dirs:\n") >> for i in dirs: >> f.write("dir:{0}\n".format(i)) >> f.write("files:\n") >> for i in files: >> f.write("file:{0}\n".format(i)) >> f.close() >> input("done") >> >> The file it's choking on happens to be a link that internet explorer >> created. There are two files that appear in explorer to have the same name >> but one actually has a zero width space ('\u200b') just before the .url >> extension. In playing around with this I've found several files with the >> same character throughout my file system. OS: Vista SP2, Language: US >> English. >> >> Am I doing something wrong or did I find a bug? It's worth noting that >> Python 2.6 just displays this character as a ? just as it appears if you >> type dir at the windows command prompt. >> > > In Python 3.x strings default to Unicode. Unless you choose an encoding, > Python will use the default system encoding to encode the Unicode strings > into a file. On Windows, the filesystem uses Unicode and supports the full > character set, but cp1252 (on your system) is the default text file > encoding, which doesn't support zero-width space. Specify an encoding for > the output file such as UTF-8: > > f=open('blah.txt','w',encoding='utf8') >>>> f.write('\u200b') >>>> >>> 1 > >> f.close() >>>> >>> > -Mark > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saurabh.gupta.7 at gmail.com Thu Jun 25 10:17:42 2009 From: saurabh.gupta.7 at gmail.com (Saurabh) Date: Thu, 25 Jun 2009 07:17:42 -0700 (PDT) Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: On Jun 25, 2:04?am, Wayne Brehaut wrote: > On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh > > wrote: > >Hi All, > > >I am trying to move my application on a MVC architecture and plan to > >use Jinja for the same. Can anyone provide me with few quick links > >that might help me to get started with Jinja? > > Perhaps the most useful link is: > > http://www.google.com/ > > from which you can easily find many more with a very basic search, > including: > > http://jinja.pocoo.org/ > > Hope that helps? > wwwayne > > > > >Thanks, > >Saby > > Thanks (Sir!). I was hoping to get some good tutorial on implementation (which I wasn't able to find with a basic search - http://dev.pocoo.org/projects/lodgeit/ is what I was referring to earlier) as this is my first assignment on any template engine (never used Cheetah, MakO, Tempita). I would appreciate people responding with something helpful. If you find a question pretty naive, kindly ignore the question rather than passing comments on it. Doesn't helps anyone's time. Thanks again From invalid at invalid Thu Jun 25 10:45:08 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 25 Jun 2009 09:45:08 -0500 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: On 2009-06-24, Chris Rebert wrote: > In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. And to insure that a post is ignored, make sure the subject contains no meaningful question, only a plea for help: http://catb.org/~esr/faqs/smart-questions.html#bespecificurget Also be sure to use "urgent", "important" or "high priority" in the subject: http://catb.org/~esr/faqs/smart-questions.html#urgent However, he did forget to use multiple exclamation points -- "the nails in the coffin of a Usenet post". -- Grant Edwards grante Yow! Kids, don't gross me at off ... "Adventures with visi.com MENTAL HYGIENE" can be carried too FAR! From jeseems at gmail.com Thu Jun 25 10:49:16 2009 From: jeseems at gmail.com (Jeseem S) Date: Thu, 25 Jun 2009 07:49:16 -0700 (PDT) Subject: compiling python 2.6.2 on uclibc Message-ID: hi, am looking for patched to compile python 2.6.2 on uclibc. any help is greatly appreciated thanks jeseem From msliczniak at gmail.com Thu Jun 25 11:10:12 2009 From: msliczniak at gmail.com (Michael Sliczniak) Date: Thu, 25 Jun 2009 08:10:12 -0700 (PDT) Subject: extending method descriptors Message-ID: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Suppose I have this: Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A(object): ... __slots__ = ('x', 'y') ... >>> a = A() >>> b = A() So I am using descriptors (and I want to). I also would like to have methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was to extend member_descriptor, but it seems that I cannot: >>> type(A.x) >>> class my_descriptor(type(A.x)): ... def foo(): ... return 1 ... Traceback (most recent call last): File "", line 1, in TypeError: Error when calling the metaclass bases type 'member_descriptor' is not an acceptable base type Is there some way, outside of using C, to be able to do what I want. Yes I want a.x and b.x to be different, but type(a).x.foo(), type (b).x.foo(), and A.x.foo() should all be the same. I have tried other approaches and get exceptions of one flavor or another with everything I have tried. Thanks, mzs From aahz at pythoncraft.com Thu Jun 25 11:26:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 08:26:59 -0700 Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> <13e776b0-6ca8-479e-ba82-eb5b7eb8f445@a5g2000pre.googlegroups.com> Message-ID: In article <13e776b0-6ca8-479e-ba82-eb5b7eb8f445 at a5g2000pre.googlegroups.com>, ssc wrote: >On Jun 18, 10:49=A0am, Jon Clements wrote: >> >> Why are you doing this? I'm assuming a code to title look up is >> required (don't forget military, royal and honorable titles >> etc... :) ) > >I'm in New Zealand. Hardly any need for military titles, rarely any >for royal and damn sure none for honorable :-D (scnr) +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From kirk at daycos.com Thu Jun 25 11:31:47 2009 From: kirk at daycos.com (Kirk Strauser) Date: Thu, 25 Jun 2009 10:31:47 -0500 Subject: It's ... References: Message-ID: <87ab3w72jg.fsf@daycos.com> At 2009-06-24T19:53:49Z, Angus Rodgers writes: > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? > detab = lambda s : StringType.expandtabs(s, stop) # Or use def > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) > f.close() An equivalent in modern Pythons: >>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) In short: expandtabs is a method on strings, there's no need to seek to the beginning, and files are closed when they are garbage collected (although I can't make myself not close output files after years of doing so), and map() is largely deprecated in favor of list comprehensions and generator functions. -- Kirk Strauser The Day Companies From pdpinheiro at gmail.com Thu Jun 25 11:36:50 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 25 Jun 2009 08:36:50 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <4d764b41-a9aa-477f-9b8e-9a96f718d3bd@f16g2000vbf.googlegroups.com> On Jun 25, 12:23?pm, Robin Becker wrote: > Paul Rubin wrote: > > so does this render all the discreteness implied by quantum theory unreliable? > or is it that we just cannot see(measure) the continuity that really happens? > Certainly there are people like Wolfram who seem to think we're in some kind of > giant calculating engine where state transitions are discontinuous. More like that axiomatic system doesn't accurately map to reality as we currently understand it. Your posts made me think that I wasn't clear in saying e and 2 are the only "natural" bases for logs. The log function, as the inverse of the exponential, is a pretty fundamental function. The base e exponential has a load of very natural properties, f'(x) = f (x) being an example. As the smallest admissible integer base, log 2 is also a pretty natural notion, especially in computer science, or in general all that follow from binary true/false systems. From paul at boddie.org.uk Thu Jun 25 12:06:43 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 25 Jun 2009 09:06:43 -0700 (PDT) Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <2508eb2a-d641-4efe-b9f0-09e1873112ad@k26g2000vbp.googlegroups.com> On 24 Jun, 15:22, "Pegasus" wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. There doesn't seem to be much of an intersection between the PSP and "mainstream" Python communities, so some more context may have been desirable here. [...] > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) It sounds like a job for a profiler. Maybe KCachegrind [1] along with some other tools might be of assistance. Paul [1] http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindWhat From pdpinheiro at gmail.com Thu Jun 25 12:22:03 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 25 Jun 2009 09:22:03 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <80fc1882-eb07-4c10-9361-1fc151c6e2fb@r25g2000vbn.googlegroups.com> On Jun 25, 10:38?am, Paul Rubin wrote: > Robin Becker writes: > > someone once explained to me that the set of systems that are > > continuous in the calculus sense was of measure zero in the set of all > > systems I think it was a fairly formal discussion, but my > > understanding was of the hand waving sort. > > That is very straightforward if you don't mind a handwave. ?Let S be > some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 > otherwise (this is a discontinuous function if S is nonempty). ?How > many different such f's can there be? ?Obviously one for every > possible subset of the reals. ?The cardinality of such f's is the > power set of the reals, i.e. much larger than the set of reals. > > On the other hand, let g be some arbitrary continuous function on the > reals. ?Let H be the image of Q (the set of rationals) under g. ?That > is, H = {g(x) such that x is rational}. ?Since g is continuous, it is > completely determined by H, which is a countable set. ?So the > cardinality is RxN which is the same as the cardinality of R. ? > > > If true that makes calculus (and hence all of our understanding of > > such "natural" concepts) pretty small and perhaps non-applicable. > > No really, it is just set theory, which is a pretty bogus subject in > some sense. ?There aren't many discontinuous functions in nature. > There is a philosophy of mathematics (intuitionism) that says > classical set theory is wrong and in fact there are NO discontinuous > functions. ?They have their own mathematical axioms which allow > developing calculus in a way that all functions are continuous. > > > On the other hand R Kalman (of Bucy and Kalman filter fame) likened > > study of continuous linear dynamical systems to "a man searching for > > a lost ring under the only light in a dark street" ie we search > > where we can see. Because such systems are tractable doesn't make > > them natural or essential or applicable in a generic sense. > > Really, I think the alternative he was thinking of may have been > something like nonlinear PDE's, a horribly messy subject from a > practical point of view, but still basically free of set-theoretic > monstrosities. ?The Banach-Tarski paradox has nothing to do with nature. I'll take the Banach-Tarski construct (it's not a paradox, damn it!) over non-linear PDEs any day of the week, thankyouverymuch. :) From nick at craig-wood.com Thu Jun 25 12:30:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 11:30:03 -0500 Subject: A superclass using a child classes' methods References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> <87ccaa96-6462-45d3-8108-f09a94ae6797@l28g2000vba.googlegroups.com> Message-ID: Kurt Schwehr wrote: > Thanks for the excellent response setting me straight. Now to figure > out what dumb thing I did to make my code not work... If you have trouble then post the code (or a cut down version demonstrating the code) - it always helps to have real code with real error messages when tracking down problems. A lot of people (like me) will enjoy the puzzle of looking through your code and finding out where it went wrong. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Thu Jun 25 12:30:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 11:30:03 -0500 Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: Carl Banks wrote: > On Jun 23, 10:02?pm, ?????? ??????????? wrote: > > I need to programmaticaly enumerate all the classes in a given module. > > Currently I'm using dir(module) but the Notice on the documentation page > > [1] ?says "dir() is supplied primarily as a convenience for use at an > > interactive prompt" so that kind of scares me. > > > > Is there a better approach? > > > > If there is, how do I get all the classes of the current module? > > You can use module.__dict__.values() (or .itervalues()) to retrieve > the contents of the module (and of course .keys() if you want names). > If you want to check the same module that the code appears in, use > globals() instead of module.__dict__. > > Something makes me think that module.__dict__ was only added to Python > fairly recently, but I'm not sure. It exists in python2.1 - I don't have an older python to check at the moment. > A word of warning (although I would guess you are already aware of > these issues, but for other readers): this method can't tell the > difference between a class defined in the module and a class imported > into it. > > Finally, despite the warning, I think you are ok to use dir() for that > purpose. It's not likely to change. Good advice... And as a double check >>> import sys >>> set(sys.__dict__.keys()) == set(dir(sys)) True >>> import os >>> set(os.__dict__.keys()) == set(dir(os)) True -- Nick Craig-Wood -- http://www.craig-wood.com/nick From __peter__ at web.de Thu Jun 25 12:53:12 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Jun 2009 18:53:12 +0200 Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Message-ID: Michael Sliczniak wrote: > Suppose I have this: > > Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> class A(object): > ... __slots__ = ('x', 'y') > ... >>>> a = A() >>>> b = A() > > So I am using descriptors (and I want to). I also would like to have > methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was > to extend member_descriptor, but it seems that I cannot: > >>>> type(A.x) > >>>> class my_descriptor(type(A.x)): > ... def foo(): > ... return 1 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: Error when calling the metaclass bases > type 'member_descriptor' is not an acceptable base type > > Is there some way, outside of using C, to be able to do what I want. > Yes I want a.x and b.x to be different, but type(a).x.foo(), type > (b).x.foo(), and A.x.foo() should all be the same. I have tried other > approaches and get exceptions of one flavor or another with everything > I have tried. If you define an attribute with the same name in both the class and its instances the instance attribute just hides the class attribute: >>> class X(object): ... def foo(self): return "yadda" ... >>> class A(object): ... def __init__(self, x): ... self.x = x ... x = X() ... >>> a = A("foo") >>> b = A("bar") >>> a.x, b.x, type(a).x.foo(), type(b).x.foo() ('foo', 'bar', 'yadda', 'yadda') This is probably not what you expected. So what are you really trying to achieve? Peter From twirlip at bigfoot.com Thu Jun 25 12:53:51 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:53:51 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser wrote: >At 2009-06-24T19:53:49Z, Angus Rodgers writes: > >> print ''.join(map(detab, f.xreadlines())) > >An equivalent in modern Pythons: > >>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) I guess the code below would also have worked in 2.1? (It does in 2.5.4.) print ''.join(line.expandtabs(3) for line in \ file('h071.txt').xreadlines()) -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 12:56:47 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:56:47 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:53:51 +0100, I wrote: >On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser > wrote: > >>At 2009-06-24T19:53:49Z, Angus Rodgers writes: >> >>> print ''.join(map(detab, f.xreadlines())) >> >>An equivalent in modern Pythons: >> >>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) > >I guess the code below would also have worked in 2.1? >(It does in 2.5.4.) > > print ''.join(line.expandtabs(3) for line in \ > file('h071.txt').xreadlines()) Possibly silly question (in for a penny ...): does the new feature, by which a file becomes iterable, operate by some kind of coercion of a file object to a list object, via something like x.readlines()? -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 12:58:35 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:58:35 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:56:47 +0100, I found a new way to disgrace myself, thus: >[...] something like x.readlines()? ^ I don't know how that full stop got in there. Please ignore it! -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 13:07:19 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 18:07:19 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently: >[...] does the new feature, >by which a file becomes iterable, operate by some kind of coercion >of a file object to a list object, via something like x.readlines()? Sorry to follow up my own post yet again (amongst my weapons is a fanatical attention to detail when it's too late!), but I had better rephrase that question: Scratch "list object", and replace it with something like: "some kind of iterator object, that is at least already implicit in 2.1 (although the term 'iterator' isn't mentioned in the index to the 2nd edition of Beazley's book)". Something like that! 8-P -- Angus Rodgers From python at mrabarnett.plus.com Thu Jun 25 13:22:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 18:22:48 +0100 Subject: It's ... In-Reply-To: References: <87ab3w72jg.fsf@daycos.com> Message-ID: <4A43B268.1040202@mrabarnett.plus.com> Angus Rodgers wrote: > On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser > wrote: > >> At 2009-06-24T19:53:49Z, Angus Rodgers writes: >> >>> print ''.join(map(detab, f.xreadlines())) >> An equivalent in modern Pythons: >> >>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) > > I guess the code below would also have worked in 2.1? > (It does in 2.5.4.) > > print ''.join(line.expandtabs(3) for line in \ > file('h071.txt').xreadlines()) > That uses a generator expression, which was introduced in 2.4. From norseman at hughes.net Thu Jun 25 13:24:00 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:24:00 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A43B2B0.1050006@hughes.net> rom wrote: > Thanks for your response. I have modified this minimal program as you > suggested but still is not able to print the filename: > > ###################### > import Tkinter > import tkFileDialog > > global filename # NO NO NO! No global line here > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): # global var goes here, inside the def so the var filename is not local # just like I show below. > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > > print filename > > root.mainloop() > ###################### > > Is this what you mean? > > > On Jun 25, 1:28 pm, norseman wrote: >> OOPS - I left out the global statement >> >> rom wrote: >>> Hi there, >>> I am writing an interface with Tkinter. My minimal program looks like >>> this: >>> ############# >>> import Tkinter >>> import tkFileDialog >> # define globals here >> filename= '' # will take care of the problem >> >>> root = Tkinter.Tk() >>> Tkinter.Button(root, text='Notch genes...', command=lambda: >>> open_file_dialog()).pack() >>> def open_file_dialog(): >> global filename # need this to assign to it >> >>> filename = tkFileDialog.askopenfilename(filetypes=[("all >>> files","*")]) >>> # print filename >>> root.mainloop() >>> ############# >>> I would like to recover the filename variable outside the >>> "open_file_dialog" function. For instance, to be able to print the >>> selected file name (uncomment "# print filename" line). >>> Is there a way to do that? >>> Thanks in advance. >>> R >> > From norseman at hughes.net Thu Jun 25 13:33:54 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:33:54 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> References: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> Message-ID: <4A43B502.8000400@hughes.net> rom wrote: > Ok. I think I got it. I have to do it in this way: > ########################### > import Tkinter > import tkFileDialog > > > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > global filename > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > print_filename() > > def print_filename(): > print filename > > root.mainloop() > ########################### > Thanks again > > On Jun 25, 1:46 pm, rom wrote: >> Thanks for your response. I have modified this minimal program as you >> suggested but still is not able to print the filename: >> >> ###################### >> import Tkinter >> import tkFileDialog >> >> global filename >> filename='' >> >> root = Tkinter.Tk() >> >> Tkinter.Button(root, text='Notch genes...', command=lambda: >> open_file_dialog()).pack() >> >> def open_file_dialog(): >> filename = tkFileDialog.askopenfilename(filetypes= >> [("allfiles","*")]) >> >> print filename >> >> root.mainloop() >> ###################### >> >> Is this what you mean? >> >> On Jun 25, 1:28 pm, norseman wrote: >> >>> OOPS - I left out the global statement >>> rom wrote: >>>> Hi there, >>>> I am writing an interface with Tkinter. My minimal program looks like >>>> this: >>>> ############# >>>> import Tkinter >>>> import tkFileDialog >>> # define globals here >>> filename= '' # will take care of the problem >>>> root = Tkinter.Tk() >>>> Tkinter.Button(root, text='Notch genes...', command=lambda: >>>> open_file_dialog()).pack() >>>> def open_file_dialog(): >>> global filename # need this to assign to it >>>> filename = tkFileDialog.askopenfilename(filetypes=[("all >>>> files","*")]) >>>> # print filename >>>> root.mainloop() >>>> ############# >>>> I would like to recover the filename variable outside the >>>> "open_file_dialog" function. For instance, to be able to print the >>>> selected file name (uncomment "# print filename" line). >>>> Is there a way to do that? >>>> Thanks in advance. >>>> R >> =========== Now you got it!! So ignore my just previous response. :) The global statement inside the def keeps the specified variable from being local by default. If the global statement is "higher up the food chain" then it will cause Python to look back for a definition from that point. There may not be one or it might be other than expected. Python works backward (or up) from global statement through the defs and modules enclosing it. Uses first found. A small suggestion, filename is a word usually used commonly. fname would be a better substitute. Or fn or ifil, ofil (in/out files) and so forth. Of course it is perfectly OK for question and answer time. version: Python OS : All or Not relevant date : June 25, 2009 Steve From larudwer at freenet.de Thu Jun 25 13:51:10 2009 From: larudwer at freenet.de (larudwer) Date: Thu, 25 Jun 2009 19:51:10 +0200 Subject: Problem with multithreading References: Message-ID: "Jeffrey Barish" schrieb im Newsbeitrag news:mailman.2091.1245902997.8015.python-list at python.org... > Jeffrey Barish wrote: > >> I have a program that uses multithreading to monitor two loops. When >> something happens in loop1, it sends a message to loop2 to have it >> execute >> a command. loop2 might have to return a result. If it does, it puts the >> result in a queue. loop1, meanwhile, would have blocked waiting for >> something to appear in the queue. The program works for a while, but >> eventually freezes. I know that freezing is a sign of deadlock. >> However, >> I put in print statements to localize the problem and discovered >> something >> weird. The freeze always occurs at a point in the code with the >> following >> statements: >> >> print "about to try" >> try: >> print "in try" >> >> >> I get "about to try", but not "in try". Is this observation consistent >> with >> the deadlock theory? If not, what could be making the program freeze at >> the try statement? I wrote a test program using the same techniques to >> illustrate the problem, but the test program works perfectly. I could >> post it, though, if it would help to understand what I am doing -- and >> what might be wrong in the real program. > > As I ponder this problem, I am beginning to believe that the problem is > not > related to multithreading. If the problem were due to a collision between > the two threads then timing would matter, yet I find that the program > always freezes at exactly the same statement (which executes perfectly > hundreds of times before the freeze). Moreover, the test program that I > wrote to test the multithreading implementation works perfectly. And > finally, there is nothing going on related to multithreading at this point > in the code. Why else might the program freeze at a try statement? > -- > Jeffrey Barish > If you have one thread sleeping you need another running thread to waken up the sleeping thread. If the running thread terminates unexpectedly the other thread will sleep forever. Though. Since there is a try statement in your example code and the failure always happens there, there might be the chance that some unexpected exception was thrown and cought somewhere else in your program. If the Program is terminated, the last print might also have gone lost in some I/O buffer. There is no guarantee that the print statement really wasn't executed. Think about things like exception Queue.Empty Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty. exception Queue.Full Exception raised when non-blocking put() (or put_nowait()) is called on a Queue object which is full. From mail131 at gmail.com Thu Jun 25 13:57:10 2009 From: mail131 at gmail.com (Private Private) Date: Thu, 25 Jun 2009 10:57:10 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> On Jun 25, 10:59?am, Chris Withers wrote: > Private Private wrote: > > from those forms, etc. I have read a bit about Django and TurboGears > > but I am afraid that this is too big for my requirements (am I > > wrong ?). > > You are wrong :-) Why ? What I've read about Django, Turbogears is that they are powerful enough to create big web-based portals, applications, etc. I need just simple forms without any sophisticated functionality. So again: why I am wrong ? przemol From norseman at hughes.net Thu Jun 25 13:58:05 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:58:05 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> References: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> Message-ID: <4A43BAAD.8040108@hughes.net> rom wrote: > Thanks again. After your replies, I have understood how to do what I > wanted. What I wanted to do is to get a value after clicking a button > and use it in another part of the program. As you said, after getting > the value, I have to store it in a global variable. However, the > program does not do anything with it until I trigger another event, > e.g. by clicking on another button. Therefore, I have added another > button to my program: > ##################### > import Tkinter > import tkFileDialog > > filename = 'uninitialized' > > def open_file_dialog(): > global filename > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > def print_variable(variable): > print variable > > root = Tkinter.Tk() > Tkinter.Button(root, text='Select file...', > command=open_file_dialog).pack() > > Tkinter.Button(root, text='Print file', command=lambda: print_variable > (filename)).pack() > > root.mainloop() > ##################### Your original, as written, would open and print immediately. But it could be a problem as (or if) more code is added in that area. This current code allows the user to open, perhaps view via other code and print only if wanted. Either is OK, having both is OK, making it do what Rom wants is best. :) If open/print was wanted, put the print statement in the open file button group right after the open file statement. Anyone reading the code will immediately understand that is the intent. At least for that button. Also it would be best to put the def statements before the button statements. Actually it is best to put all defs BEFORE the GUI (frame, buttons, etc...) statements when using Tkinter. The print filename statement being placed as in the original request may attempt to print filename after other code above it is run. Since Tkinter is not a 'closed' package, that is, it's statements can be interspersed with program code, it is thus best to make sure what will and will not be triggered by other actions. I've beat my head on that a few times. :) Steve ...(snip) From bojan at sudarevic.com Thu Jun 25 14:04:57 2009 From: bojan at sudarevic.com (Bojan Sudarevic) Date: Thu, 25 Jun 2009 20:04:57 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? Message-ID: Hi, I'm PHP developer and entirely new to Python. I installed it (version 2.5.2, from Debian repos) today on the persuasion of a friend, who is a Python addict. The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, I don*t know, I just did). And the answer wasn't 9.6. Here it is: >>> 3.2*3 9.6000000000000014 So I became curious... >>> 3.21*3 9.629999999999999 >>> (3.2*3)*2 19.200000000000003 ... and so on ... After that I tried Windows version (3.1rc2), and... >>> 3.2*3 9.600000000000001 I wasn't particularly good in math in school and university, but I'm pretty sure that 3.2*3 is 9.6. Cheers, Bojan From amosanderson at gmail.com Thu Jun 25 14:18:08 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Thu, 25 Jun 2009 13:18:08 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: I think what your experiencing is addressed on this page... http://docs.python.org/tutorial/floatingpoint.html ... it has to do with the binary representation of the numbers. On Thu, Jun 25, 2009 at 1:04 PM, Bojan Sudarevic wrote: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > > >>> 3.2*3 > 9.6000000000000014 > > So I became curious... > > >>> 3.21*3 > 9.629999999999999 > >>> (3.2*3)*2 > 19.200000000000003 > ... and so on ... > > After that I tried Windows version (3.1rc2), and... > > >>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. > > Cheers, > Bojan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Thu Jun 25 14:19:22 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 11:19:22 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <26be756e-5a0a-40cd-b9a2-133ce14ac7d7@n30g2000vba.googlegroups.com> On Jun 25, 7:04?pm, Bojan Sudarevic wrote: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > [examples snipped] Hi Bojan, This is a FAQ. Take a look at: http://docs.python.org/tutorial/floatingpoint.html and let us know whether that explains things to your satisfaction. Mark From tomasz.zielinski at pyconsultant.eu Thu Jun 25 14:20:13 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Thu, 25 Jun 2009 11:20:13 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <71fb8dc4-42ec-46e6-9ec9-ce066f14f706@l32g2000vba.googlegroups.com> On 25 Cze, 20:04, Bojan Sudarevic wrote: > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. > It's not math, it's floating point representation of numbers - and its limited accuracy. Type 9.6 and you'll get 9.5999999999999996 -- Tomasz Zielinski http://pyconsultant.eu From pecora at anvil.nrl.navy.mil Thu Jun 25 14:20:33 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 25 Jun 2009 14:20:33 -0400 Subject: Problem with multithreading References: Message-ID: In article , "larudwer" wrote: > "Jeffrey Barish" schrieb im Newsbeitrag > news:mailman.2091.1245902997.8015.python-list at python.org... > > Jeffrey Barish wrote: > > > >> I have a program that uses multithreading to monitor two loops. When > >> something happens in loop1, it sends a message to loop2 to have it > >> execute > >> a command. loop2 might have to return a result. If it does, it puts the > >> result in a queue. loop1, meanwhile, would have blocked waiting for > >> something to appear in the queue. The program works for a while, but > >> eventually freezes. I know that freezing is a sign of deadlock. > >> However, > >> I put in print statements to localize the problem and discovered > >> something > >> weird. The freeze always occurs at a point in the code with the > >> following > >> statements: > >> > >> print "about to try" > >> try: > >> print "in try" > >> > >> > >> I get "about to try", but not "in try". Is this observation consistent Try putting a flush in after the 2nd print statement in case the output is left in some I/O buffer when the thing terminates. e.g. import sys .... try: print 'in try" sys.stdout.flush() -- -- Lou Pecora From tjreedy at udel.edu Thu Jun 25 14:21:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 14:21:18 -0400 Subject: I need a dict that inherits its mappings In-Reply-To: References: Message-ID: samwyse wrote: > I need a dict-like object that, if it doesn't contain a key, will > return the value from a "parent" object. Is there an easy way to do > this so I don't have to define __getitem__ and __contains__ and others > that I haven't even thought of yet? Here's a use case, if you're > confused: > > en_GB=mydict() > en_US=mydict(en_GB) > > en_GB['bonnet']='part of your car' > print en_US['bonnet'] # prints 'part of your car' > > en_US['bonnet']='a type of hat' > print en_US['bonnet'] # prints 'a type of hat' > print en_GB['bonnet'] # prints 'part of your car' For that specific case: def lookup(key): try: return en_US[key] except KeyError: return en_GB[key] More generally, def make_lookup_with_backup(d1, d2): def _l(key): try: return d1[key] except KeyError: return d2[key] return _ Terry Jan Reedy From emile at fenx.com Thu Jun 25 14:29:32 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 25 Jun 2009 11:29:32 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: On 6/25/2009 11:04 AM Bojan Sudarevic said... >>>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. Yes -- in this world. But in the inner workings of computers, 3.2 isn't accurately representable in binary. This is a faq. ActivePython 2.6.2.2 (ActiveState Software Inc.) based on Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 3.2 3.2000000000000002 >>> Emile From paul.nospam at rudin.co.uk Thu Jun 25 14:32:12 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 25 Jun 2009 19:32:12 +0100 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <87ljngmafn.fsf@rudin.co.uk> Bojan Sudarevic writes: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > >>>> 3.2*3 > 9.6000000000000014 > > So I became curious... > >>>> 3.21*3 > 9.629999999999999 >>>> (3.2*3)*2 > 19.200000000000003 > ... and so on ... > > After that I tried Windows version (3.1rc2), and... > >>>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. This is almost certainly nothing to do with python per se, but the floating point implementation of your hardware. Floating point arithmetic on computers is not accurate to arbitrary precision. If you want such precision use a library that supports it or make you own translations to and from appropriate integer sums (but it's going to be slower). From dickinsm at gmail.com Thu Jun 25 14:35:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 11:35:12 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <11bda8df-45ce-4356-aafe-5e80b037105c@n21g2000vba.googlegroups.com> On Jun 25, 7:04?pm, Bojan Sudarevic wrote: > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. It looks like it's false in PHP too, by the way (not that I know any PHP, so I could well be missing something...) bernoulli:py3k dickinsm$ php -a Interactive mode enabled References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> Message-ID: <4A43C3DB.7080504@simplistix.co.uk> Private Private wrote: > What I've read about Django, Turbogears is that they are powerful > enough to create big web-based portals, applications, etc. > I need just simple forms without any sophisticated functionality. > So again: why I am wrong ? Just because something is powerful doesn't mean you can't do simple things with it. Have a read of the first few chapters of the Django book... http://www.djangobook.com/ Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From bojan at sudarevic.com Thu Jun 25 14:37:59 2009 From: bojan at sudarevic.com (Bojan Sudarevic) Date: Thu, 25 Jun 2009 20:37:59 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <26be756e-5a0a-40cd-b9a2-133ce14ac7d7@n30g2000vba.googlegroups.com> Message-ID: In article <26be756e-5a0a-40cd-b9a2-133ce14ac7d7 @n30g2000vba.googlegroups.com>, dickinsm at gmail.com says... > This is a FAQ. Take a look at: > > http://docs.python.org/tutorial/floatingpoint.html > > and let us know whether that explains things to your > satisfaction. > Hi Mark, Yes, that explains things to my satisfation. Now I'm embarrassed that I didn't know that before. Thanks, Bojan From torriem at gmail.com Thu Jun 25 14:41:13 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 25 Jun 2009 12:41:13 -0600 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: <4A43C4C9.1020601@gmail.com> Bojan Sudarevic wrote: > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > >>>> 3.2*3 > 9.6000000000000014 I'm surprised how often people encounter this and wonder about it. As I began programming back in the day using C, this is just something I grew up with (grudging acceptance). I guess PHP artificially rounds the results or something to make it seem like it's doing accurate calculations, which is a bit surprising to me. We all know that IEEE floating point is a horribly inaccurate representation, but I guess I'd rather have my language not hide that fact from me. Maybe PHP is using BCD or something under the hood (slow but accurate). If you want accurate math, check out other types like what is in the decimal module: >>> import decimal >>> a=decimal.Decimal('3.2') >>> print a * 3 9.6 From robert.kern at gmail.com Thu Jun 25 14:44:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 13:44:47 -0500 Subject: scipy stats binom_test In-Reply-To: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> References: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> Message-ID: On 2009-06-25 07:14, dusans wrote: > Amm i using the function wrong or ...? cuz in R i get the right value > >>>> binom_test(3, 5, p=0.8) > 0.262 > >> dbinom(3, 5, 0.8) > [1] 0.205 The R equivalent of scipy.stats.binom_test() is binom.test(), not dbinom(). If you want the equivalent of dbinom(), use scipy.stats.binom.pmf(3,5,0.8). If you have more scipy questions, you should ask them on the scipy 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 robert.kern at gmail.com Thu Jun 25 14:56:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 13:56:37 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: <4A43C4C9.1020601@gmail.com> References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 13:41, Michael Torrie wrote: > If you want accurate math, check out other types like what is in the > decimal module: > >>>> import decimal >>>> a=decimal.Decimal('3.2') >>>> print a * 3 > 9.6 I wish people would stop representing decimal floating point arithmetic as "more accurate" than binary floating point arithmetic. It isn't. Decimal floating point arithmetic does have an extremely useful niche: where the inputs have finite decimal representations and either the only operations are addition, subtraction and multiplication (e.g. many accounting problems) OR there are conventional rounding modes to follow (e.g. most of the other accounting problems). In the former case, you can claim that decimal floating point is more accurate *for those problems*. But as soon as you have a division operation, decimal floating point has the same accuracy problems as binary floating point. -- 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 spconv+m at gmail.com Thu Jun 25 15:02:48 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Thu, 25 Jun 2009 21:02:48 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem Message-ID: <111013c20906251202q5846efebw60ef54439ecefb6f@mail.gmail.com> Hello I'm writing an application in Python 2.5.4 under Windows (xp sp3 en). I use Tkinter as the main GUI toolkit. The app is intended to be portable (not fully but win & mac os x is a must). It works as it should on my system, but when I've sent the program to my friend who has a mac computer, he told me accented characters are turned into weird symbols. It is another must, the GUI consists of widgets with polish characters. I always use UTF-8 encoding in Python and I save my scripts in Notepad++ as UTF-8 without BOM. I've never experienced similar problems under Windows with Tkinter before I've created a simple test script: CODE_START >> # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() Label(root, text='?????????').pack() Button(root, text='?????????').pack() Entry(root).pack() root.mainloop() CODE_END >> No problem on Windows, but on mac Button widget has correct text. Label and Entry has garbage instead of accented characters. (Mac OS X 10.5.6 and 10.4.11 both armed with Python 2.5.4) I've tried various UTF file encoding (also with BOM mark), use of u"text" or unicode() function - non of this worked. Googling shows not much: reload(sys) sys.setdefaultencoding("utf-8") or: root = Tk() root.tk.call('encoding', 'system', 'utf-8') After applying this, the effect remains the same - one big garbage. I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both support UTF-8, Python also supports it - so where is the problem? How can I show mac-users polish signs? Please Help! From martin at v.loewis.de Thu Jun 25 15:25:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 25 Jun 2009 21:25:07 +0200 Subject: Barbara Liskov wins Turing Award In-Reply-To: References: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> Message-ID: <4a43cf13$0$5131$9b622d9e@news.freenet.de> > Python's object model, assignment semantics, and call-by-object > mechanism, and that name, come from CLU. Whether Guido knew of it > directly or not, I do not know. To the extent that the above is part of > the heart of Python, I think Steven's statement stands pretty well. Why do you say that? ISTM that Python is much closer to Smalltalk than to CLU in its object model. CLU is statically typed (and it is important to its notion of program correctness that it is statically typed); Smalltalk and Python aren't. In addition, Smalltalk and Python have inheritance; CLU (deliberately) doesn't. Liskov reported that she didn't know about Smalltalk until 1976. I believe that Python's, CLU's, and Smalltalk's assignment semantics actually all come from Simula. I would claim the same for the call-by-object mechanism - except that this is probably best described as coming from LISP (in the sense of caller and callee sharing references). FWIW, Simula has also inheritance, but that specific notion of inheritance did not transfer to any other language, except for Beta. Regards, Martin From pavlovevidence at gmail.com Thu Jun 25 15:30:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 12:30:30 -0700 (PDT) Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Message-ID: <4dbdd92b-2f7d-45a4-933e-ed15e65f854c@s16g2000vbp.googlegroups.com> On Jun 25, 8:10?am, Michael Sliczniak wrote: > Suppose I have this: > > Python 2.5.1 (r251:54863, Feb ?6 2009, 19:02:12) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information.>>> class A(object): > > ... ? ? __slots__ = ('x', 'y') > ... > > >>> a = A() > >>> b = A() > > So I am using descriptors (and I want to). I also would like to have > methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was > to extend member_descriptor, but it seems that I cannot: > > >>> type(A.x) > > >>> class my_descriptor(type(A.x)): > > ... ? ? def foo(): > ... ? ? ? ? ? ? return 1 > ... > Traceback (most recent call last): > ? File "", line 1, in > TypeError: Error when calling the metaclass bases > ? ? type 'member_descriptor' is not an acceptable base type The question isn't too clear, but I can explain this error message. A Python type defined in C must have Py_TP_BASETYPE set in its tp_flags field, otherwise subclassing it isn't happening. If you want such functionality, I believe it would be easiest have to implement a MemberDescriptorWrapper class in Python that delegates to the actual member_descriptor. You would use it something like this: class A(object): __slots__ = ['_x_internal','_y_internal'] x = MemberDescriptorWrapper('_x_internal') y = MemberDescriptorWrapper('_y_internal') MemberDescriptorWrapper class would have to implement __get__, __set__, and __del__ methods and have them call the corresponding methods on the slot; details are left as an exercise. Carl Banks From dickinsm at gmail.com Thu Jun 25 15:31:05 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 12:31:05 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: On Jun 25, 7:41?pm, Michael Torrie wrote: > I guess PHP artificially rounds the results or something to make it seem > like it's doing accurate calculations, which is a bit surprising to me. After a bit of experimentation on my machine, it *looks* as though PHP is using the usual hardware floats internally (no big surprise there), but implicit conversions to string use 14 significant digits. If Python's repr used '%.14g' internally instead of '%.17g' then we'd see pretty much the same thing in Python. > We all know that IEEE floating point is a horribly inaccurate > representation [...] That's a bit extreme! Care to elaborate? , but I guess I'd rather have my language not hide that > fact from me. ?Maybe PHP is using BCD or something under the hood (slow > but accurate). > > If you want accurate math, check out other types like what is in the > decimal module: As Robert Kern already said, there really isn't any sense in which decimal floating-point is any more accurate than binary floating-point, except that---somewhat tautologically---it's better at representing decimal values exactly. The converse isn't true, though, from a numerical perspective: there are some interesting examples of bad things that can happen with decimal floating-point but not with binary. For example, given any two Python floats a and b, and assuming IEEE 754 arithmetic with default rounding, it's always true that a <= (a+b)/2 <= b, provided that a+b doesn't overflow. Not so for decimal floating-point: >>> import decimal >>> decimal.getcontext().prec = 6 # set working precision to 6 sig figs >>> (decimal.Decimal('7.12346') + decimal.Decimal('7.12348'))/2 Decimal('7.12345') Similarly, sqrt(x*x) == x is always true for a positive IEEE 754 double x (again assuming the default roundTiesToEven rounding mode, and assuming that x*x neither overflows nor underflows). But this property fails for IEEE 754-compliant decimal floating-point. Mark From martin.schoon at gmail.com Thu Jun 25 15:36:53 2009 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Thu, 25 Jun 2009 21:36:53 +0200 Subject: Slow wxPyhon on Vista? References: <87y6ro3afs.fsf@crunchbang.Belkin> Message-ID: <87vdmkhzqi.fsf@crunchbang.Belkin> David Lyon writes: > On Fri, 19 Jun 2009 10:16:39 +0200, martin.schoon at gmail.com (Martin > Sch??n) wrote: >> Here is my problem. When I use it on a Vista box its >> user interface is very, very slow when it comes to >> some but not all operations. On any other Windows >> version it reacts instantaneously. I have not tried >> Task Coach on Linux or Solaris (yet). >> >> Is this how wxPython or Python works on Vista in >> general or is this the result of some local oddity on my >> employer's Vista configuration? > > I have encountered the same thing on XP in one instance > on a development box. For some reason, wxpython just > grinds to a halt. > > I couldn't solve it and reimaged the O/S... that > fixed it... Reimaged? Since my first post on this I have installed the very latest version of Task Coach and Vista has been through an SP1 install. The GUI speed issue remains despite this. /Martin From ---***gilucasa***--- at email.it Thu Jun 25 15:37:53 2009 From: ---***gilucasa***--- at email.it (gianbrix) Date: Thu, 25 Jun 2009 19:37:53 GMT Subject: py2exe: some problems Message-ID: Hi, I am trying to get an exe file using py2exe with one my application. If I let all in the same main folder it works fine. If I set zipfile="bin\\myapp.zip" I get some errors like this: "unable to load dlls:" relating to win32gui or win32print etc. What is wrong? There is a way to have zipfile set to None and move the pyds and dlls in the bin folder? Regards Gianluca From jeff_barish at earthlink.net Thu Jun 25 15:47:30 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Thu, 25 Jun 2009 13:47:30 -0600 Subject: Problem with multithreading References: Message-ID: Lou Pecora wrote: > In article , > "larudwer" wrote: > >> "Jeffrey Barish" schrieb im Newsbeitrag >> news:mailman.2091.1245902997.8015.python-list at python.org... >> > Jeffrey Barish wrote: >> > >> >> I have a program that uses multithreading to monitor two loops. When >> >> something happens in loop1, it sends a message to loop2 to have it >> >> execute >> >> a command. loop2 might have to return a result. If it does, it puts >> >> the >> >> result in a queue. loop1, meanwhile, would have blocked waiting for >> >> something to appear in the queue. The program works for a while, but >> >> eventually freezes. I know that freezing is a sign of deadlock. >> >> However, >> >> I put in print statements to localize the problem and discovered >> >> something >> >> weird. The freeze always occurs at a point in the code with the >> >> following >> >> statements: >> >> >> >> print "about to try" >> >> try: >> >> print "in try" >> >> >> >> >> >> I get "about to try", but not "in try". Is this observation >> >> consistent > > Try putting a flush in after the 2nd print statement in case the output > is left in some I/O buffer when the thing terminates. e.g. > > import sys > > .... > > try: > print 'in try" > sys.stdout.flush() > > I was hoping for some suggestions of things to think about, so thanks especially to those who had such suggestions. Believe it or not (and I'm having trouble believing it myself), I didn't think to use flush. When I did, I found that, indeed, the program did progress past the try statement. It made it to a call to GStreamer (playbin2), which has been proving itself intractable in my experience. Note that my test program (which works) excised GStreamer. The next step will be to try again to compile the latest version of PyGST as the version in Ubuntu 9.04 is one generation old. The last time I tried, the compile failed. This is the first time in days that I have had any hope. -- Jeffrey Barish From tjreedy at udel.edu Thu Jun 25 16:08:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 16:08:24 -0400 Subject: trace options In-Reply-To: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> References: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> Message-ID: Edward Peschko wrote: > All, > > I've been looking at the trace module, and although it looks useful, I'm > surprised that there aren't a couple of features that I would have thought > would be fairly basic. So, does trace support (for the --trace option): I have never used the trace module but decided to try it out, following the simple example in the docs with a simple function. It seems a bit underdocumented, so I presume help with that would be welcome. I also found deficiencies in the operation, though different from you. > - indentation tracking stacklevel (where each function is prefixed > by tabs equal to the number of stacklevels deep in the program) Trace already does one space indents for modules after the first --- modulename: threading, funcname: settrace --- modulename: compare, funcname: lt_iw and lines after the first compare.py(47): while m != 0 and n != 0: compare.py(48): m, n = m-1, n-1 That would have to be eliminated, at least when stack indents were on. Tabs are nasty when interpreted as 8 chars. If added, the user should specify the indent: indent = ' ', for instance, for 2 space indents. > - output to something other than sys.stdout (eg. output to a file > specified either by environmental variable or by parameter). That seems reasonable. It also seems reasonable that I be able to write counts *to* stdout (the screen) when running interactive. But when I changed r.write_results(show_missing=True, coverdir="/tmp") in the doc example to just r.write_results() I got nothing, rather than the line-by-line count I expected. A bug? On the other hand, r.write_results(summary=True) did give output - the coverage for the module, which was not helpful. This was so with both run('func(args)') and runfunc(func, args) Coverage should be by function, I think, especially with runfunc. > - mult-threaded programs going to multiple output handles, > especially in light of the above > > - fully qualified python modules in path: (eg: > > /path/to/module/my_module.py(1): print "HERE" > > instead of > > my_module.py(1): print "HERE". I think a full name in the modulename line would be good, but full names in the trace lines would be awful. In fact, I would prefer no name, and, especially when using runfunc, line numbers relative to the function rather than the module. Also remove the silly indent. So I would like --- modulename: compare, funcname: lt_iw compare.py(47): while m != 0 and n != 0: compare.py(48): m, n = m-1, n-1 changed to Modulename: path/compare, funcname: lt_iw 1: while m != 0 and n != 0: 2: m, n = m-1, n-1 > Ultimately, I'd like to be able to look at two runs of a program > and be able to pinpoint the very first difference > between thembased on the output of their trace runs. As it > stands, I really can't do this. When I trace a function mentally, to write or debug, I keep track of the values of the local names. Perhaps trace was not meant for this. However, if I were modifying trace, the first thing I would add would be the ability to print variable values with each line executed. > Of course I could implement the above, but I was > hoping to avoid duplicated effort if someone has > already implemented options like this..I posted the above to > the python-dev list, they suggested I take it here, so any help > would be appreciated. I searched http://pypi.python.org/pypi for 'trace' and did not see anything obvious. If you do modify trace and your changes are not immediately accepted, you could list your version on PyPI. In fact, that might be the best way to get them in. Of course, one problem you can see from the above is that different people will have different ideas on what constitutes 'better' ;-). Terry Jan Reedy From martin at v.loewis.de Thu Jun 25 16:12:46 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 25 Jun 2009 22:12:46 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: Message-ID: <4a43da3e$0$14855$9b622d9e@news.freenet.de> > I've tried various UTF file encoding (also with BOM mark), use of > u"text" Always use u"text". This should work. Everything else might not work. > After applying this, the effect remains the same - one big garbage. Can you please be more specific? What is "one big garbage"? > I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both > support UTF-8, Python also supports it - so where is the problem? Most likely, Tk does not work correctly on your system. See whether you can get correct results with wish. Regards, Martin From martin at v.loewis.de Thu Jun 25 16:16:11 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 25 Jun 2009 22:16:11 +0200 Subject: print u'\u2013' error on console/terminal In-Reply-To: References: Message-ID: <4a43db0b$0$14855$9b622d9e@news.freenet.de> > is there a switch to suppress those encoding errors for standard print's > on the console No, there is no such switch. > or a new filter file class necessary? You can wrap sys.stdout with a codecs.StreamWriter, passing "replace" as the error handler. Regards, Martin From spconv+m at gmail.com Thu Jun 25 16:52:57 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Thu, 25 Jun 2009 22:52:57 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4a43da3e$0$14855$9b622d9e@news.freenet.de> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> Message-ID: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> 2009/6/25 "Martin v. L?wis" : >> I've tried various UTF file encoding (also with BOM mark), use of >> u"text" > > Always use u"text". This should work. Everything else might not work. But I tried this here without success >> After applying this, the effect remains the same - one big garbage. > > Can you please be more specific? What is "one big garbage"? > There is a square (or some other weird sign) in place where polish accented character should be (like "?????" etc) This problem is only on mac os x and it doesn't apply to button widget (where characters are correct) >> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >> support UTF-8, Python also supports it - so where is the problem? > > Most likely, Tk does not work correctly on your system. See whether > you can get correct results with wish. > There is no wish. I'm talking about build-in Tkinter (isn't Tk build-in Python?). btw. I'm workin on Windows, my friend on Mac - he points me the problem he has with my script. He is not a computer geek nor a programmer - he even doesn't know what wish/Tk or Python is Does different endianness can have something to do here? From norseman at hughes.net Thu Jun 25 17:23:04 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 14:23:04 -0700 Subject: [Gimp-user] Color change a whole range based on a break point Message-ID: <4A43EAB8.6080402@hughes.net> I know I'm not the only one that does archival scanning and georefferencing of old maps. What follows is the combined conversations between myself (norseman at hughes.net and saulgoode at flashingtwelve.brickfilms.com) that lead to getting what is needed for the above process when working with sources that are copies made with the "Sepia" process of old (before Xerox copiers). Namely; a clean raster. For non-sepia source I use GIMP->Colors->Levels and get excellent results with minor effort. 1) original request and reply > > Wanted: > > In Gimp, to add (SUM) the RGB values for a pixel and then > > change all pixels who's RGB SUM is greater than a user stated value > > to WHITE. > > Second side of that is to change all RGB SUMs less than value given to Black. BUT not doing both at same time, thus allowing user to "step" > > in and see what got lost. * Duplicate the layer. * Desaturate the duplicate using the "Average" method. * Add layermask to the duplicate using the "Initialize to: Grayscale Copy of Layer" option. * Bucket fill the duplicate layer with white. * Run "Colors->Threshold" on the layermask, setting the value appropriately. * Bucket fill your original layer with black. 2) starting round 2 Quoting norseman : > I understand the idea. I am not getting any usable results. > > If I cut out a small piece of a project raster and send it to you > would you have the time to try your idea(s) on it? That would be fine. Perhaps I misinterpreted what you are trying to accomplish. 3) closing results As often happens, just as one is ready to quit, the unexpected happens. I went back to your idea of Desaturate and Threshold and tried them without doing the layer/fill parts. (keep original, save as newname the modified) Success! What I have is 45 year old sepias of USGS 7.5 minute Topo Quads with inked lines drawn on the sepia. They have 'faded' and the surface has corroded and some has rubbed off onto the inked lines originally drawn on them. Thus the black lines are tainted with color. The rest of the sepia is like any other old sepia. It is trying to become all one color - very dark sepia. :) What I did was try your idea of Desaturate (I settled on the Lightness setting) and then used Threshold (left or 'black' side set to 50 +/- and right or white side set to 200 to 220) and BINGO! -- I get what I want! The sepia (very nearly 100%) turns white and the inked lines are dark enough for further processing. Final manual touch-up prior to vectorizing will be very minor. Manually doing the major cleanup is less than 60 seconds per sheet. Majority of sheets take less than 30 seconds. Anticipate individual settings and times to vary with source conditions. :) Final product is to be inked lines converted to georefferenced vectors. side note: the 'small sample' I had clipped out was small compared to the original sheet but it was still 25 megabytes AFTER LZW compression! The original sheets are 200 megabytes each in uncompressed RGB Tiff. A totally manual cleanup of originals is definitely an unwanted task. GIMP: 2.6.6 OS : Window$ XP PRO As of writing, I have not tested on Linux but I do expect same results. Sincerely - I do appreciate your help. Steve From nick at craig-wood.com Thu Jun 25 17:30:02 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 16:30:02 -0500 Subject: C-extension 2 times slower than exe References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> <4a4233d0$1@news.fhg.de> Message-ID: Rolf Wester wrote: > Hello, > > thank you all very much for your replies. > > I tried to simplify things and make the two versions as comparable as > possible. I put the C++ part of the program into a shared object > libff.so. For the exe the main function is linked against this shared > object. For the python stuff I made an interface consiting of only one > function call_solver with the same code that has the main function used > for the exe. Then I created a wrapper for this interface using swig and > linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code > just imports _ff and calls call_solver wich creates an object of the > class Solver and calls its member solve (the main function of the exe > does the same). > > I included some code for timing into the C++-code. > > #include > > //beginning of solve > clock_t t0 = clock(); > ... > clock_t t1 = clock(); > //end of solve > cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; > > I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The > sources are compiled using the flags -fPIC -O3. > > Timing: > > 1) time python ff.py > time used = 3.74 > real 0m3.234s > user 0m3.712s > sys 0m0.192s Those times look odd because the user time is > than the real time. User time is number of CPU seconds used. Real time is wallclock time. That must mean a) your program is threading b) there is something up with timing on your computer Looks odd but exactly what it means I don't know! > 2) time ff > time used = 2.19 > real 0m3.170s > user 0m2.088s > sys 0m0.168s -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gagsl-py2 at yahoo.com.ar Thu Jun 25 17:32:49 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Jun 2009 18:32:49 -0300 Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: En Thu, 25 Jun 2009 04:29:28 -0300, Private Private escribi?: > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > Can you suggest anything ? You may try pesto: http://pesto.redgecko.org/ pesto is a very small framework (45k to download!), WSGI compliant, includes session management, mapping URL->function, caching, templates (optional, whichever you like). Minimalist but flexible. Anyway, learning to use Django isn't a bad idea. -- Gabriel Genellina From python at mrabarnett.plus.com Thu Jun 25 17:50:31 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 22:50:31 +0100 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> Message-ID: <4A43F127.5060807@mrabarnett.plus.com> Sebastian Paj?k wrote: > 2009/6/25 "Martin v. L?wis" : >>> I've tried various UTF file encoding (also with BOM mark), use of >>> u"text" >> Always use u"text". This should work. Everything else might not work. > > But I tried this here without success > >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) > >>> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >>> support UTF-8, Python also supports it - so where is the problem? >> Most likely, Tk does not work correctly on your system. See whether >> you can get correct results with wish. >> > > There is no wish. I'm talking about build-in Tkinter (isn't Tk > build-in Python?). > > btw. I'm workin on Windows, my friend on Mac - he points me the > problem he has with my script. He is not a computer geek nor a > programmer - he even doesn't know what wish/Tk or Python is > > > Does different endianness can have something to do here? In summary: You're providing the same text for a Button and a Label. On Mac OSX the Button shows the text correctly, but the Label doesn't. Is this correct? From norseman at hughes.net Thu Jun 25 17:57:08 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 14:57:08 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> Message-ID: <4A43F2B4.30604@hughes.net> Sebastian Paj?k wrote: > 2009/6/25 "Martin v. L?wis" : >>> I've tried various UTF file encoding (also with BOM mark), use of >>> u"text" >> Always use u"text". This should work. Everything else might not work. > > But I tried this here without success > >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) > >>> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >>> support UTF-8, Python also supports it - so where is the problem? >> Most likely, Tk does not work correctly on your system. See whether >> you can get correct results with wish. >> > > There is no wish. I'm talking about build-in Tkinter (isn't Tk > build-in Python?). > > btw. I'm workin on Windows, my friend on Mac - he points me the > problem he has with my script. He is not a computer geek nor a > programmer - he even doesn't know what wish/Tk or Python is > > > Does different endianness can have something to do here? ================ Can, but should not. I read that the problem is when using the Polish language only. Otherwise things work normally. Is that correct? If so then byte swap may be a problem. Using the u'string' should solve that. I am assuming you have the Polish alphabet working correctly on your machine. I think I read that was so in an earlier posting. Are there any problems with his alphabet scrambling on your machine? If so that needs investigating. Here I assume you are reading Polish from him on your machine and not a network translator version. No - Tkinter is not built in. tkinter is a module shipped with Python for people to use. (Tk interface) use: import tkinter From Google: Tkinter Life Preserver Tkinter is a Python interface to the Tk GUI toolkit. This document is not designed to be an exhaustive tutorial on either Tk or Tkinter. ...www.python.org/doc/life-preserver/ more properly Tcl/Tk see also www.tcl.tk Steve From python at mrabarnett.plus.com Thu Jun 25 17:57:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 22:57:20 +0100 Subject: Problem with multithreading In-Reply-To: References: Message-ID: <4A43F2C0.3020205@mrabarnett.plus.com> Jeffrey Barish wrote: [snip] > Lou Pecora wrote: > >> Try putting a flush in after the 2nd print statement in case the output >> is left in some I/O buffer when the thing terminates. e.g. >> >> import sys >> >> .... >> >> try: >> print 'in try" >> sys.stdout.flush() >> >> > > I was hoping for some suggestions of things to think about, so thanks > especially to those who had such suggestions. Believe it or not (and I'm > having trouble believing it myself), I didn't think to use flush. When I > did, I found that, indeed, the program did progress past the try statement. > It made it to a call to GStreamer (playbin2), which has been proving itself > intractable in my experience. Note that my test program (which works) > excised GStreamer. The next step will be to try again to compile the > latest version of PyGST as the version in Ubuntu 9.04 is one generation > old. The last time I tried, the compile failed. This is the first time in > days that I have had any hope. On occasion I've needed to debug a program that's crashing, and I've found it best to open the log file unbuffered, otherwise I lose the final log messages. It saves me from having to flush each message explicitly. From spconv+m at gmail.com Thu Jun 25 18:47:54 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 00:47:54 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4A43F2B4.30604@hughes.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> Message-ID: <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> > Can, but should not. > I read that the problem is when using the Polish language only. Otherwise > things work normally. Is that correct? Yes, correct > If so then byte swap may be a problem. ?Using the u'string' should solve > that. I am assuming you have the Polish alphabet working correctly on your > machine. I think I read that was so in an earlier posting. > > Are there any problems with his alphabet scrambling on your machine? > If so that needs investigating. ?Here I assume you are reading Polish from > him on your machine and not a network translator version. > The original thread is here: http://mail.python.org/pipermail/python-list/2009-June/717666.html I've explained the problem there From python at mrabarnett.plus.com Thu Jun 25 18:49:37 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 23:49:37 +0100 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> <4a4233d0$1@news.fhg.de> Message-ID: <4A43FF01.5030406@mrabarnett.plus.com> Nick Craig-Wood wrote: > Rolf Wester wrote: >> Hello, >> >> thank you all very much for your replies. >> >> I tried to simplify things and make the two versions as comparable as >> possible. I put the C++ part of the program into a shared object >> libff.so. For the exe the main function is linked against this shared >> object. For the python stuff I made an interface consiting of only one >> function call_solver with the same code that has the main function used >> for the exe. Then I created a wrapper for this interface using swig and >> linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code >> just imports _ff and calls call_solver wich creates an object of the >> class Solver and calls its member solve (the main function of the exe >> does the same). >> >> I included some code for timing into the C++-code. >> >> #include >> >> //beginning of solve >> clock_t t0 = clock(); >> ... >> clock_t t1 = clock(); >> //end of solve >> cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; >> >> I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The >> sources are compiled using the flags -fPIC -O3. >> >> Timing: >> >> 1) time python ff.py >> time used = 3.74 >> real 0m3.234s >> user 0m3.712s >> sys 0m0.192s > > Those times look odd because the user time is > than the real time. > > User time is number of CPU seconds used. Real time is wallclock time. > > That must mean > a) your program is threading > b) there is something up with timing on your computer > > Looks odd but exactly what it means I don't know! > >> 2) time ff >> time used = 2.19 >> real 0m3.170s >> user 0m2.088s >> sys 0m0.168s > Perhaps multithreading on dual cores? From Scott.Daniels at Acm.Org Thu Jun 25 19:43:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 25 Jun 2009 16:43:33 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: Robert Kern wrote: > ... I wish people would stop representing decimal floating point arithmetic > as "more accurate" than binary floating point arithmetic. It isn't. > Decimal floating point arithmetic does have an extremely useful niche: > ... Well, we don't actually have an arbitrary-precision, huge exponent version of binary floating point. In that sense the Decimal floating point beats it. Not that it would be too hard to have such a floating point in Python (long for mantissa, int for exponent, ...), but we don't in fact have such a module in place. --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Thu Jun 25 19:50:21 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 18:50:21 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 18:43, Scott David Daniels wrote: > Robert Kern wrote: >> ... I wish people would stop representing decimal floating point >> arithmetic as "more accurate" than binary floating point arithmetic. >> It isn't. Decimal floating point arithmetic does have an extremely >> useful niche: ... > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. You may not. I do. http://code.google.com/p/mpmath/ -- 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 Thu Jun 25 19:53:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 16:53:04 -0700 Subject: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: In article , Hendrik van Rooyen wrote: > >I have lately had some posts returned with a "seems to be forged" message. >Two reasons for that: >- first is if I use the smtp server from our local telco - saix - then there is > no apparent relationship between where the message comes from and > where it comes from, if you follow my Irish... >- Second is if the same telco assigns me an IP that has been put on a list > of bad boy IPs. > >So it is kind of pot luck if you see this message or not. Sorry, didn't see it. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From mensanator at aol.com Thu Jun 25 19:53:39 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Jun 2009 16:53:39 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: <4f0bb9cf-f2ca-4b1d-a803-0d77661a9899@p23g2000vbl.googlegroups.com> On Jun 25, 6:43?pm, Scott David Daniels wrote: > Robert Kern wrote: > > ... I wish people would stop representing decimal floating point arithmetic > > as "more accurate" than binary floating point arithmetic. It isn't. > > Decimal floating point arithmetic does have an extremely useful niche: > > ... > > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. ?In that sense the Decimal floating > point beats it. ?Not that it would be too hard to have such a floating > point in Python (long for mantissa, int for exponent, ...), but we don't > in fact have such a module in place. We have the gmpy module which can do arbitray precision floats. >>> gmpy.pi(600) mpf ('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446e0', 600) > > --Scott David Daniels > Scott.Dani... at Acm.Org From aahz at pythoncraft.com Thu Jun 25 19:55:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 16:55:40 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: In article , Scott David Daniels wrote: > >Well, we don't actually have an arbitrary-precision, huge exponent >version of binary floating point. gmpy? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From robert.kern at gmail.com Thu Jun 25 20:07:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 19:07:37 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 18:43, Scott David Daniels wrote: > Robert Kern wrote: >> ... I wish people would stop representing decimal floating point >> arithmetic as "more accurate" than binary floating point arithmetic. >> It isn't. Decimal floating point arithmetic does have an extremely >> useful niche: ... > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. In that sense the Decimal floating > point beats it. And while that's true, to a point, that isn't what Michael or the many others are referring to when they claim that decimal is more accurate (without any qualifiers). They are misunderstanding the causes and limitations of the example "3.2 * 3 == 9.6". You can see a great example of this in the comparison between new Cobra language and Python: http://cobra-language.com/docs/python/ In that case, they have a fixed-precision decimal float from the underlying .NET runtime but still making the claim that it is more accurate arithmetic. While you may make (completely correct) claims that decimal.Decimal can be more accurate because of its arbitrary precision capabilities, this is not the claim others are making or the one I am arguing against. -- 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 norseman at hughes.net Thu Jun 25 20:09:15 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 17:09:15 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> Message-ID: <4A4411AB.1090302@hughes.net> Sebastian Paj?k wrote: >> Can, but should not. >> I read that the problem is when using the Polish language only. Otherwise >> things work normally. Is that correct? > > Yes, correct > >> If so then byte swap may be a problem. Using the u'string' should solve >> that. I am assuming you have the Polish alphabet working correctly on your >> machine. I think I read that was so in an earlier posting. >> >> Are there any problems with his alphabet scrambling on your machine? >> If so that needs investigating. Here I assume you are reading Polish from >> him on your machine and not a network translator version. >> > > The original thread is here: > http://mail.python.org/pipermail/python-list/2009-June/717666.html > I've explained the problem there ================ I re-read the posting. (Thanks for the link) You do not mention if he has sent you any Polish words and if they appear OK on your machine. A note here: In reading the original posting I get symbols that are not familiar to me as alphabet. From the line in your original: Label(root, text='?????????').pack() I see text=' then an e with a goatee a capitol O with an accent symbol on top (') an a with a tail on the right a s with an accent on top an I do no not know what - maybe some sort of l with a slash through the middle a couple of z with accents on top a capitol C with an accent on top a n with a short bar on top I put the code into python and took a look. I get: cat xx # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() Button(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() Entry(root).pack() root.mainloop() Then: python xx File "xx", line 10 SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details So I did. It notes Window$ puts things into those lines. Namely: "To aid with platforms such as Windows, which add Unicode BOM marks to the beginning of Unicode files, the UTF-8 signature '\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well (even if no magic encoding comment is given). " Then I took out the o with the accent and re-ran the file. Everything works except the text is exactly as shown above. That is: \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 (shows twice as directed, one for label, one for button, no apostrophes) OK - now I take a look at what in actually in the file. in MC on Linux Slackware 10.2 I read, in the mail folder, 0119 capitol A with a tilde on top. HEX readings beginning at the 0119\... 30 31 31 39 C3 B3 5C but in the python file xx, I read: 30 31 31 39 5C 0119\... I would have to say the mail system is screwing you up. Might try zipping the file and sending it that way and see if problem changes. Steve From martin at v.loewis.de Thu Jun 25 21:01:35 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Fri, 26 Jun 2009 03:01:35 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> Message-ID: <4a441def$0$12249$9b622d9e@news.freenet.de> >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) ***PLEASE*** be specific. A square box is something *completely* different than any other weird sign. It is impossible to understand the problem if you don't know *exactly* what happens. in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) I see. So it is a font problem: if the square box is displayed, it means that the font just doesn't have a glyph for the character you want to display. Try using a different font in the label widget. > There is no wish. I'm talking about build-in Tkinter So try installing Tk separately. > (isn't Tk build-in Python?). Depends on where exactly you got your Python from, and what exactly is your OSX version. Recent releases of OSX include a copy of Tcl/Tk, and some sets of Python binaries link against the Apple Tk. Regards, Martin From kee at kagi.com Thu Jun 25 21:02:25 2009 From: kee at kagi.com (Kee Nethery) Date: Thu, 25 Jun 2009 18:02:25 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working Message-ID: <87338909-96C7-489A-9B85-CB6F7FE8DA18@kagi.com> Summary: I have XML as string and I want to pull it into ElementTree so that I can play with it but it is not working for me. XML and fromstring when used with a string do not do the same thing as parse does with a file. How do I get this to work? Details: I have a CGI that receives XML via an HTTP POST as a POST variable named 'theXml'. The POST data is a string that the CGI receives, it is not a file on a hard disk. The POSTed string looks like this when viewed in pretty format: Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts jumbo at shrimp.edu The pseudocode in Python 2.6.2 looks like: import xml.etree.ElementTree as et formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et.XML(theXmlData) and when this runs, theXmlDataTree is set to: theXmlDataTree instance attrib dict {} tag str xml tail NoneType None text NoneType None I get the same result with fromstring: formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et.fromstring(theXmlData) I can put the xml in a file and reference the file by it's URL and use: et.parse(urllib.urlopen(theUrl)) and that will set theXmlDataTree to: theXmlDataTree instance This result I can play with. It contains all the XML. et.parse seems to pull in the entire XML document and give me something to play with whereas et.XML and et.fromstring do not. Questions: How do I get this to work? Where in the docs did it give me an example of how to make this work (what did I miss from reading the docs)? ... and for bonus points ... Why isn't et.parse the only way to do this? Why have XML or fromstring at all? Why not enhance parse and deprecate XML and fromstring with something like: formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et .parse (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) Thanks in advance, Kee Nethery From python at mrabarnett.plus.com Thu Jun 25 22:08:27 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Jun 2009 03:08:27 +0100 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251539vac5c017l613603a5fbc0bb36@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F127.5060807@mrabarnett.plus.com> <111013c20906251539vac5c017l613603a5fbc0bb36@mail.gmail.com> Message-ID: <4A442D9B.9090009@mrabarnett.plus.com> Sebastian Paj?k wrote: >> You're providing the same text for a Button and a Label. On Mac OSX the >> Button shows the text correctly, but the Label doesn't. >> >> Is this correct? > > Yes this is correct. My first mail is here: > http://mail.python.org/pipermail/python-list/2009-June/717666.html > My only other thought is that the widgets might be using different fonts, although in your example you're not specifying the fonts, so I assume they'll default to the same one. You could try specifying their fonts explicitly, just in case, although I'm expecting that it won't make a difference... From nobody at nowhere.com Thu Jun 25 22:38:14 2009 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Jun 2009 03:38:14 +0100 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: On Thu, 25 Jun 2009 18:02:25 -0700, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree > so that I can play with it but it is not working for me. XML and > fromstring when used with a string do not do the same thing as parse > does with a file. How do I get this to work? Why do you need an ElementTree rather than an Element? XML(string) returns the root element, as if you had used et.parse(f).getroot(). You can turn this into an ElementTree with e.g. et.ElementTree(XML(string)). > Why isn't et.parse the only way to do this? Why have XML or fromstring > at all? Why not enhance parse and deprecate XML and fromstring with > something like: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = > et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) If you want to treat a string as a file, use StringIO. From unayok at gmail.com Thu Jun 25 22:47:36 2009 From: unayok at gmail.com (unayok) Date: Thu, 25 Jun 2009 19:47:36 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: <0eab2287-62b0-42e4-a864-e2316b82dee8@f30g2000vbf.googlegroups.com> On Jun 25, 9:02 pm, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree > so that I can play with it but it is not working for me. XML and > fromstring when used with a string do not do the same thing as parse > does with a file. How do I get this to work? > > Details: > I have a CGI that receives XML via an HTTP POST as a POST variable > named 'theXml'. The POST data is a string that the CGI receives, it is > not a file on a hard disk. > > The POSTed string looks like this when viewed in pretty format: [...] > et.parse seems to pull in the entire XML document and give me > something to play with whereas et.XML and et.fromstring do not. > > Questions: > How do I get this to work? > Where in the docs did it give me an example of how to make this work > (what did I miss from reading the docs)? > [skipping bonus points question] I'm not sure what you're expecting. It looks to me like things are working okay: My test script: import xml.etree.ElementTree as ET data=""" Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts ju... at shrimp.edu """ xml = ET.fromstring( data ) print xml print "attrib ", xml.attrib print "tag ", xml.tag print "text ", xml.text print "contents " for element in xml : print element print "tostring" print ET.tostring( xml ) when run, produces: attrib {} tag xml text contents tostring Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts ju... at shrimp.edu Which seems to me quite useful (i.e. it has the full XML available). Maybe you can explain how you were trying to "play with" the results of fromstring() that you can't do from parse(). The documentation for elementtree indicates: > The ElementTree wrapper type adds code to load XML files as trees > of Element objects, and save them back again. and > The Element type can be used to represent XML files in memory. > The ElementTree wrapper class is used to read and write XML files. In the above case, you should find that the getroot() of your loaded ElementTree instance ( parse().getroot() ) to be the same as the Element generated by fromstring(). From pavlovevidence at gmail.com Thu Jun 25 23:04:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 20:04:08 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> On Jun 25, 6:02?pm, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree ? > so that I can play with it but it is not working for me. XML and ? > fromstring when used with a string do not do the same thing as parse ? > does with a file. How do I get this to work? > > Details: > I have a CGI that receives XML via an HTTP POST as a POST variable ? > named 'theXml'. The POST data is a string that the CGI receives, it is ? > not a file on a hard disk. > > The POSTed string looks like this when viewed in pretty format: > > > ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? Autumn > ? ? ? ? ? ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ? ? ? ? ? ? 8.46 > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? YES > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? 19 Any Street > ? ? ? ? ? ? ? ? ? ? ? ? Berkeley > ? ? ? ? ? ? ? ? ? ? ? ? California > ? ? ? ? ? ? ? ? ? ? ? ? 12345 > ? ? ? ? ? ? ? ? ? ? ? ? People's Republic of Berkeley > ? ? ? ? ? ? ? ? ? ? ? ? Jon Roberts > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ju... at shrimp.edu > ? ? ? ? > > > The pseudocode in Python 2.6.2 looks like: > > import xml.etree.ElementTree as et > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.XML(theXmlData) > > and when this runs, theXmlDataTree is set to: > > theXmlDataTree ?instance ? ? ? ? > ? ? ? ? attrib ?dict ? ?{} > ? ? ? ? tag ? ? str ? ? xml > ? ? ? ? tail ? ?NoneType ? ? ? ?None > ? ? ? ? text ? ?NoneType ? ? ? ?None > > I get the same result with fromstring: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.fromstring(theXmlData) > > I can put the xml in a file and reference the file by it's URL and use: > > et.parse(urllib.urlopen(theUrl)) > > and that will set theXmlDataTree to: > > theXmlDataTree ?instance ? ? ? ? 0x67cb48> > > This result I can play with. It contains all the XML. I believe you are misunderstanding something. et.XML and et.fromstring return Elements, whereas et.parse returns an ElementTree. These are two different things; however, both of them "contain all the XML". In fact, an ElementTree (which is returned by et.parse) is just a container for the root Element (returned by et.fromstring)--and it adds no important functionality to the root Element as far as I can tell. Given an Element (as returned by et.XML or et.fromstring) you can pass it to the ElementTree constructor to get an ElementTree instance. The following line should give you something you can "play with": theXmlDataTree = et.ElementTree(et.fromstring(theXmlData)) Conversely, given an ElementTree (as returned bu et.parse) you can call the getroot method to obtain the root Element, like so: theXmlRootElement = et.parse(xmlfile).getroot() I have no use for ElementTree instances so I always call getroot right away and only store the root element. You may prefer to work with ElementTrees rather than with Elements directly, and that's perfectly fine; just use the technique above to wrap up the root Element if you use et.fromstring. [snip] > Why isn't et.parse the only way to do this? Why have XML or fromstring ? > at all? Because Fredrick Lundh wanted it that way. Unlike most Python libraries ElementTree is under the control of one person, which means it was not designed or vetted by the community, which means it would tend to have some interface quirks. You shouldn't complain: the library is superb compared to XML solutions like DOM. A few minor things should be no big deal. Carl Banks From kee at kagi.com Thu Jun 25 23:53:57 2009 From: kee at kagi.com (Kee Nethery) Date: Thu, 25 Jun 2009 20:53:57 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <839382F7-B326-45F2-B2C3-506B14FFE0B0@kagi.com> thank you to everyone, I'll play with these suggestions tomorrow at work and report back. On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > Because Fredrick Lundh wanted it that way. Unlike most Python > libraries ElementTree is under the control of one person, which means > it was not designed or vetted by the community, which means it would > tend to have some interface quirks. Yep > You shouldn't complain: the > library is superb compared to XML solutions like DOM. Which is why I want to use it. > A few minor > things should be no big deal. True and I will eventually get past the minor quirks. As a newbie, figured I'd point out the difficult portions, things that conceptually are confusing. I know that after lots of use I'm not going to notice that it is strange that I have to stand on my head and touch my nose 3 times to open the fridge door. The contortions will seem normal. Results tomorrow, thanks everyone for the assistance. Kee Nethery From timr at probo.com Fri Jun 26 00:31:42 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Jun 2009 21:31:42 -0700 Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: humn wrote: > >Thank you! Didn't know that it would escape characters with single >quotes. I thought it only did that with double quotes. That's only true in Perl and PHP, but not in Python or C. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Scott.Daniels at Acm.Org Fri Jun 26 00:32:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 25 Jun 2009 21:32:28 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> Message-ID: <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> norseman wrote: > ... A note here: In reading the original posting I get symbols that are not > familiar to me as alphabet. > From the line in your original: > Label(root, text='?????????').pack() > I see text=' > then an e with a goatee > a capitol O with an accent symbol on top (') > an a with a tail on the right > a s with an accent on top > an I do no not know what - maybe some sort of l with a > slash through the middle > a couple of z with accents on top > a capitol C with an accent on top > a n with a short bar on top Here's something to try in any future circumstances: Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import unicodedata as ud >>> for ch in '?????????': print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch))) 281 119 ? LATIN SMALL LETTER E WITH OGONEK 243 f3 ? LATIN SMALL LETTER O WITH ACUTE 261 105 ? LATIN SMALL LETTER A WITH OGONEK 347 15b ? LATIN SMALL LETTER S WITH ACUTE 322 142 ? LATIN SMALL LETTER L WITH STROKE 380 17c ? LATIN SMALL LETTER Z WITH DOT ABOVE 378 17a ? LATIN SMALL LETTER Z WITH ACUTE 263 107 ? LATIN SMALL LETTER C WITH ACUTE 324 144 ? LATIN SMALL LETTER N WITH ACUTE --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Fri Jun 26 00:38:39 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 21:38:39 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <19c53184-96d2-4ae8-aa2d-41ec9a71a218@e20g2000vbc.googlegroups.com> On Jun 25, 8:53?pm, Kee Nethery wrote: > On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > > A few minor > > things should be no big deal. > > True and I will eventually get past the minor quirks. As a newbie, ? > figured I'd point out the difficult portions, things that conceptually ? > are confusing. I know that after lots of use I'm not going to notice ? > that it is strange that I have to stand on my head and touch my nose 3 ? > times to open the fridge door. The contortions will seem normal. Well it's not *that* bad. (That would be PIL. :) Carl Banks From msrachel.e at gmail.com Fri Jun 26 00:47:51 2009 From: msrachel.e at gmail.com (Rachel P) Date: Thu, 25 Jun 2009 21:47:51 -0700 (PDT) Subject: I need a dict that inherits its mappings References: Message-ID: <8298a601-185b-4e50-b1c6-dea47ae51732@a5g2000pre.googlegroups.com> On Jun 25, 5:31?am, samwyse wrote: > I need a dict-like object that, if it doesn't contain a key, will > return the value from a "parent" object. ? See: http://code.activestate.com/recipes/305268/ Also try subclassing dict and implementing a __missing__() method. Raymond From stefan_ml at behnel.de Fri Jun 26 01:11:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 07:11:33 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> Carl Banks wrote: >> Why isn't et.parse the only way to do this? Why have XML or fromstring >> at all? > > Because Fredrick Lundh wanted it that way. Unlike most Python > libraries ElementTree is under the control of one person, which means > it was not designed or vetted by the community, which means it would > tend to have some interface quirks. Just for the record: Fredrik doesn't actually consider it a design "quirk". He argues that it's designed for different use cases. While parse() parses a file, which normally contains a complete document (represented in ET as an ElementTree object), fromstring() and especially the 'literal wrapper' XML() are made for parsing strings, which (most?) often only contain XML fragments. With a fragment, you normally want to continue doing things like inserting it into another tree, so you need the top-level element in almost all cases. Stefan From tomreed05 at gmail.com Fri Jun 26 01:29:30 2009 From: tomreed05 at gmail.com (Tom Reed) Date: Fri, 26 Jun 2009 06:29:30 +0100 Subject: No trees in the stdlib? Message-ID: <4A445CBA.9080602@gmail.com> Why no trees in the standard library, if not as a built in? I searched the archive but couldn't find a relevant discussion. Seems like a glaring omission considering the batteries included philosophy, particularly balanced binary search trees. No interest, no good implementations, something other reason? Seems like a good fit for the collections module. Can anyone shed some light? Thanks. -- Tom From aahz at pythoncraft.com Fri Jun 26 01:32:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 22:32:13 -0700 Subject: No trees in the stdlib? References: Message-ID: In article , Tom Reed wrote: > >Why no trees in the standard library, if not as a built in? I searched >the archive but couldn't find a relevant discussion. Seems like a >glaring omission considering the batteries included philosophy, >particularly balanced binary search trees. No interest, no good >implementations, something other reason? Seems like a good fit for the >collections module. Can anyone shed some light? What do you want such a tree for? Why are dicts and the bisect module inadequate? Note that there are plenty of different tree implementations available from either PyPI or the Cookbook. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From pavlovevidence at gmail.com Fri Jun 26 01:46:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 22:46:33 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> On Jun 25, 10:11?pm, Stefan Behnel wrote: > Carl Banks wrote: > >> Why isn't et.parse the only way to do this? Why have XML or fromstring ? > >> at all? > > > Because Fredrick Lundh wanted it that way. ?Unlike most Python > > libraries ElementTree is under the control of one person, which means > > it was not designed or vetted by the community, which means it would > > tend to have some interface quirks. > > Just for the record: Fredrik doesn't actually consider it a design "quirk". Well of course he wouldn't--it's his library. > He argues that it's designed for different use cases. While parse() parses > a file, which normally contains a complete document (represented in ET as > an ElementTree object), fromstring() and especially the 'literal wrapper' > XML() are made for parsing strings, which (most?) often only contain XML > fragments. With a fragment, you normally want to continue doing things like > inserting it into another tree, so you need the top-level element in almost > all cases. Whatever, like I said I am not going to nit-pick over small things, when all the big things are done right. Carl Banks From backup95 at netcabo.pt Fri Jun 26 01:55:50 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 06:55:50 +0100 Subject: No trees in the stdlib? In-Reply-To: References: Message-ID: <4A4462E6.7080700@netcabo.pt> Aahz wrote: > In article , > Tom Reed wrote: > >> Why no trees in the standard library, if not as a built in? I searched >> the archive but couldn't find a relevant discussion. Seems like a >> glaring omission considering the batteries included philosophy, >> particularly balanced binary search trees. No interest, no good >> implementations, something other reason? Seems like a good fit for the >> collections module. Can anyone shed some light? >> > > What do you want such a tree for? Why are dicts and the bisect module > inadequate? Note that there are plenty of different tree implementations > available from either PyPI or the Cookbook. > A hash table is very different to a BST. They are both useful. The bisect module I'm not familiar with, I'll have to look into that, thanks. I have found pyavl on the web, it does the job ok, but there no implementations for python3 that I know of. Simple example usage case: Insert string into data structure in sorted order if it doesn't exist, else retrieve it. From backup95 at netcabo.pt Fri Jun 26 02:05:18 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 07:05:18 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A44651E.40306@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > > Simple example usage case: Insert string into data structure in sorted > order if it doesn't exist, else retrieve it. > Crap, sorry about the mixed identities, I'm not using my own machine. The original post is mine also. From stefan_ml at behnel.de Fri Jun 26 02:20:15 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:20:15 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> Message-ID: <4a4468a0$0$32680$9b4e6d93@newsspool2.arcor-online.net> Carl Banks wrote: > On Jun 25, 10:11 pm, Stefan Behnel wrote: >> Carl Banks wrote: >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring >>>> at all? >>> Because Fredrick Lundh wanted it that way. Unlike most Python >>> libraries ElementTree is under the control of one person, which means >>> it was not designed or vetted by the community, which means it would >>> tend to have some interface quirks. >> Just for the record: Fredrik doesn't actually consider it a design "quirk". > > Well of course he wouldn't--it's his library. That's not an argument at all. Fredrik put out a alpha of ET 1.3 (long ago, actually), which is (or was?) meant as a clean-up release for a number of real quirks in the library (lxml also fixes most of them since 2.0). The above definitely hasn't changed, simply because it's not considered 'wrong' by the author(s). Stefan From backup95 at netcabo.pt Fri Jun 26 02:21:05 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 07:21:05 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A4468D1.700@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. The main problem with pyavl by the way is that it doesn't seem to be subclassable (?). Besides some interface glitches, like returning None on delete if I recall correctly. There's also rbtree, which I didn't try. And I think that's it. On the whole not a lot of choice and not as practical for such a common data structure. From clp2 at rebertia.com Fri Jun 26 02:23:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Jun 2009 23:23:41 -0700 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> On Thu, Jun 25, 2009 at 10:55 PM, Jo?o Valverde wrote: > Aahz wrote: >> >> In article , >> Tom Reed ? wrote: >> >>> >>> Why no trees in the standard library, if not as a built in? I searched >>> the archive but couldn't find a relevant discussion. Seems like a glaring >>> omission considering the batteries included philosophy, particularly >>> balanced binary search trees. No interest, no good implementations, >>> something other reason? Seems like a good fit for the collections module. >>> Can anyone shed some light? >>> >> >> What do you want such a tree for? ?Why are dicts and the bisect module >> inadequate? ?Note that there are plenty of different tree implementations >> available from either PyPI or the Cookbook. >> > > A hash table is very different to a BST. ?They are both useful. The bisect > module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > Simple example usage case: Insert string into data structure in sorted order > if it doesn't exist, else retrieve it. That's pretty much the bisect module in a nutshell. It manipulates a sorted list using binary search. Cheers, Chris -- http://blog.rebertia.com From stefan_ml at behnel.de Fri Jun 26 02:39:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:39:33 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: <4a446d25$0$32682$9b4e6d93@newsspool2.arcor-online.net> Hi, Kee Nethery wrote: > Why isn't et.parse the only way to do this? Why have XML or fromstring > at all? Well, use cases. XML() is an alias for fromstring(), because it's convenient (and well readable) to write section = XML('
A to Z
') section.append(paragraphs) for XML literals in source code. fromstring() is there because when you want to parse a fragment from a string that you got from whatever source, it's easy to express that with exactly that function, as in el = fromstring(some_string) If you want to parse a document from a file or file-like object, use parse(). Three use cases, three functions. The fourth use case of parsing a document from a string does not have its own function, because it is trivial to write tree = parse(BytesIO(some_byte_string)) I do not argue that fromstring() should necessarily return an Element, as parsing fragments is more likely for literals than for strings that come from somewhere else. However, given that the use case of parsing a document from a string is so easily handled with parse(), I find it ok to give the second use case its own function, simply because tree = fromstring(some_string) fragment_top_element = tree.getroot() absolutely does not catch it. > Why not enhance parse and deprecate XML and fromstring with > something like: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) This will not work because ET cannot parse from unicode strings (unless they only contain plain ASCII characters and you happen to be using Python 2.x). lxml can parse from unicode strings, but it requires that the XML must not have an encoding declaration (which would render it non well-formed). This is convenient for parsing HTML, it's less convenient for XML usually. If what you meant is actually parsing from a byte string, this is easily done using BytesIO(), or StringIO() in Py2.x (x<6). Stefan From stefan_ml at behnel.de Fri Jun 26 02:48:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:48:52 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Jo?o Valverde wrote: > Besides some interface glitches, like returning None > on delete if I recall correctly. That's actually not /that/ uncommon. Operations that change an object are not (side-effect free) functions, so it's just purity if they do not have a return value. Although practicality beats purity, sometimes... ;) Stefan From milesck at umich.edu Fri Jun 26 02:54:45 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Fri, 26 Jun 2009 02:54:45 -0400 Subject: No trees in the stdlib? In-Reply-To: <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> References: <4A4462E6.7080700@netcabo.pt> <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> Message-ID: On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote: > On Thu, Jun 25, 2009 at 10:55 PM, Jo?o Valverde > wrote: >> Aahz wrote: >>> >>> In article , >>> Tom Reed wrote: >>> >>>> >>>> Why no trees in the standard library, if not as a built in? I >>>> searched >>>> the archive but couldn't find a relevant discussion. Seems like a >>>> glaring >>>> omission considering the batteries included philosophy, >>>> particularly >>>> balanced binary search trees. No interest, no good implementations, >>>> something other reason? Seems like a good fit for the collections >>>> module. >>>> Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? Why are dicts and the bisect >>> module >>> inadequate? Note that there are plenty of different tree >>> implementations >>> available from either PyPI or the Cookbook. >>> >> >> Simple example usage case: Insert string into data structure in >> sorted order >> if it doesn't exist, else retrieve it. > > That's pretty much the bisect module in a nutshell. It manipulates a > sorted list using binary search. With O(n) insertions and removals, though. A decent self-balancing binary tree will generally do those in O(log n). -Miles From jason.scheirer at gmail.com Fri Jun 26 03:09:06 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 26 Jun 2009 00:09:06 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> On Jun 25, 10:32?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Tom Reed ? wrote: > > > > >Why no trees in the standard library, if not as a built in? I searched > >the archive but couldn't find a relevant discussion. Seems like a > >glaring omission considering the batteries included philosophy, > >particularly balanced binary search trees. No interest, no good > >implementations, something other reason? Seems like a good fit for the > >collections module. Can anyone shed some light? > > What do you want such a tree for? ?Why are dicts and the bisect module > inadequate? ?Note that there are plenty of different tree implementations > available from either PyPI or the Cookbook. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha ...And heapq is more-or-less an emulation of a tree structure in its underlying model. I once wrote a binary sorted tree data structure for Python in C. It performed anywhere from 15-40% worse than dicts. I think with optimization it will only perform 10% worse than dicts at best. Oh hey maybe that is why trees aren't an emphasized part of the standard. They are going to be much slower than the ultra-optimized dicts already in the standard lib. From backup95 at netcabo.pt Fri Jun 26 03:09:36 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:09:36 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A447430.1060201@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > > Simple example usage case: Insert string into data structure in sorted > order if it doesn't exist, else retrieve it. > After browsing the bisect module I don't think it is the complete answer. Please correct me if I'm mistaken but... Ignoring for a moment that subjectively I feel this is not very pythonic for my use case, if I get back the insertion position, doesn't that mean I have to go over on average N/2 items on a linked list to insert the item in position? Maybe less for sophisticated implementations but still O(n)? That doesn't compare favorably to the cost of (possibly) having to rebalance a tree on insertion. From eckhardt at satorlaser.com Fri Jun 26 03:17:02 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 26 Jun 2009 09:17:02 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: Robert Kern wrote: > I wish people would stop representing decimal floating point arithmetic as > "more accurate" than binary floating point arithmetic. Those that failed, learned. You only see those that haven't learnt yet. Dialog between two teachers: T1: Oh those pupils, I told them hundred times! when will they learn? T2: They did, but there's always new pupils. TGIF Uli (wave and smile) -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From kushal.kumaran+python at gmail.com Fri Jun 26 03:47:37 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Jun 2009 13:17:37 +0530 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <1e364c4e0906260047s1a65763cqaf561646f05f5596@mail.gmail.com> On Thu, Jun 25, 2009 at 10:32 AM, Private Private wrote: > On Jun 24, 12:23?pm, Przemyslaw Bak wrote: >> Hello, >> >> I many files with log data. The structure of the file is quite > > Each requested value is in separated file. > While traversing using os.path.walk I have noticed that I get files > unsorted. > Is it possible to get them sorted ? > You can use the os.walk generator and sort the filenames in the returned tuple. -- regards, kushal From backup95 at netcabo.pt Fri Jun 26 03:48:49 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:48:49 +0100 Subject: No trees in the stdlib? In-Reply-To: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> Message-ID: <4A447D61.2090904@netcabo.pt> Jason Scheirer wrote: > On Jun 25, 10:32 pm, a... at pythoncraft.com (Aahz) wrote: > >> In article , >> Tom Reed wrote: >> >> >> >> >>> Why no trees in the standard library, if not as a built in? I searched >>> the archive but couldn't find a relevant discussion. Seems like a >>> glaring omission considering the batteries included philosophy, >>> particularly balanced binary search trees. No interest, no good >>> implementations, something other reason? Seems like a good fit for the >>> collections module. Can anyone shed some light? >>> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree implementations >> available from either PyPI or the Cookbook. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> "as long as we like the same operating system, things are cool." --piranha >> > > ...And heapq is more-or-less an emulation of a tree structure in its > underlying model. I once wrote a binary sorted tree data structure for > Python in C. It performed anywhere from 15-40% worse than dicts. I > think with optimization it will only perform 10% worse than dicts at > best. > > Oh hey maybe that is why trees aren't an emphasized part of the > standard. They are going to be much slower than the ultra-optimized > dicts already in the standard lib. > But a dict can't be used to implement a (sorted) table ADT. From backup95 at netcabo.pt Fri Jun 26 03:49:45 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:49:45 +0100 Subject: No trees in the stdlib? In-Reply-To: <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4A447D99.70809@netcabo.pt> Stefan Behnel wrote: > Jo?o Valverde wrote: > >> Besides some interface glitches, like returning None >> on delete if I recall correctly. >> > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. > > Although practicality beats purity, sometimes... ;) > > Stefan > I didn't know that. But in this case I think purity gets pummeled every time :) It's still not making sense to force a lookup to fetch something before deleting (another lookup operation). If that were imposed by python's internal machinery I'd suggest fixing that instead. From aljosa.mohorovic at gmail.com Fri Jun 26 03:54:31 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 26 Jun 2009 00:54:31 -0700 (PDT) Subject: naming packages for pypi Message-ID: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> is it possible to have 2 packages with same name registered at pypi? are packages unique per name or also per category or something else? if package is unique per name how do you name you packages? do you name them something like -myapp, -myapp, -myapp, ... if this is current situation is this something that you learned to live with and there are no indications that this will eventually change? Aljosa Mohorovic From backup95 at netcabo.pt Fri Jun 26 03:58:29 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:58:29 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A447D99.70809@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <4A447D99.70809@netcabo.pt> Message-ID: <4A447FA5.4050602@netcabo.pt> Jo?o Valverde wrote: > Stefan Behnel wrote: >> Jo?o Valverde wrote: >> >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >>> >> >> That's actually not /that/ uncommon. Operations that change an object >> are >> not (side-effect free) functions, so it's just purity if they do not >> have a >> return value. >> >> Although practicality beats purity, sometimes... ;) >> >> Stefan >> > I didn't know that. But in this case I think purity gets pummeled > every time :) It's still not making sense to force a lookup to fetch > something before deleting (another lookup operation). If that were > imposed by python's internal machinery I'd suggest fixing that instead. > To be clear what I mean by that is that it's just reference passing so it can't generate programmatic errors. From clp2 at rebertia.com Fri Jun 26 04:00:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 01:00:40 -0700 Subject: No trees in the stdlib? In-Reply-To: <4A447430.1060201@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4A447430.1060201@netcabo.pt> Message-ID: <50697b2c0906260100h2fbb1ff3hc7035d72f236318f@mail.gmail.com> On Fri, Jun 26, 2009 at 12:09 AM, Jo?o Valverde wrote: > Jo?o Valverde wrote: >> >> Aahz wrote: >>> >>> In article , >>> Tom Reed ? wrote: >>> >>>> >>>> Why no trees in the standard library, if not as a built in? I searched >>>> the archive but couldn't find a relevant discussion. Seems like a glaring >>>> omission considering the batteries included philosophy, particularly >>>> balanced binary search trees. No interest, no good implementations, >>>> something other reason? Seems like a good fit for the collections module. >>>> Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? ?Why are dicts and the bisect module >>> inadequate? ?Note that there are plenty of different tree implementations >>> available from either PyPI or the Cookbook. >>> >> >> A hash table is very different to a BST. ?They are both useful. The bisect >> module I'm not familiar with, I'll have to look into that, thanks. >> >> I have found pyavl on the web, it does the job ok, but there no >> implementations for python3 that I know of. >> >> Simple example usage case: Insert string into data structure in sorted >> order if it doesn't exist, else retrieve it. >> > After browsing the bisect module I don't think it is the complete answer. > Please correct me if I'm mistaken but... > > Ignoring for a moment that subjectively I feel this is not very pythonic for > my use case, if I get back the insertion position, doesn't that mean I have > to go over on average N/2 items on a linked list to insert the item in Linked list?! Python lists are *array-based*. <"You must be new here" joke redacted> Cheers, Chris -- http://blog.rebertia.com From Andras.Horvath at cern.ch Fri Jun 26 04:04:21 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Fri, 26 Jun 2009 10:04:21 +0200 Subject: validating HTTPS certificates? Message-ID: <20090626080421.GI6455@cern.ch> Hi, (disclaimer: this might be a FAQ entry somewhere but I honestly did use Google) I'm in the process of picking a language for a client application that accesses a HTTPS (actually SOAP) server. This would be easy enough in Python, but I came across a strange fact: neither httplib nor urllib offer the possibility to actually verify the server's certificate. After some digging I've found that from 2.6 onward, the ssl module offers such functionality but it's not trivial, at least for me, to glue that to the HTTP protocol modules (and then those to the SOAP module). Did I miss something? If not, is this feature foreseen, e.g. the trivial build-up of a HTTPS connection while verifying the certificate chain? thanks, Andras From clp2 at rebertia.com Fri Jun 26 04:19:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 01:19:38 -0700 Subject: naming packages for pypi In-Reply-To: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: <50697b2c0906260119m27ee5ed3l61f3c5773712a8de@mail.gmail.com> On Fri, Jun 26, 2009 at 12:54 AM, Aljosa Mohorovic wrote: > is it possible to have 2 packages with same name registered at pypi? > are packages unique per name or also per category or something else? > > if package is unique per name how do you name you packages? > do you name them something like -myapp, -myapp, > -myapp, ... > > if this is current situation is this something that you learned to > live with and there are no indications that this will eventually > change? IIRC, packages support nesting, so just do that instead. Simply put project1..projectN into a "myapp" package and put "myapp" on PyPI. Cheers, Chris -- http://blog.rebertia.com From backup95 at netcabo.pt Fri Jun 26 04:28:56 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 09:28:56 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A447430.1060201@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4A447430.1060201@netcabo.pt> Message-ID: <4A4486C8.9060400@netcabo.pt> Jo?o Valverde wrote: > Jo?o Valverde wrote: >> Aahz wrote: >>> In article , >>> Tom Reed wrote: >>> >>>> Why no trees in the standard library, if not as a built in? I >>>> searched the archive but couldn't find a relevant discussion. Seems >>>> like a glaring omission considering the batteries included >>>> philosophy, particularly balanced binary search trees. No interest, >>>> no good implementations, something other reason? Seems like a good >>>> fit for the collections module. Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? Why are dicts and the bisect module >>> inadequate? Note that there are plenty of different tree >>> implementations >>> available from either PyPI or the Cookbook. >>> >> A hash table is very different to a BST. They are both useful. The >> bisect module I'm not familiar with, I'll have to look into that, >> thanks. >> >> I have found pyavl on the web, it does the job ok, but there no >> implementations for python3 that I know of. >> >> Simple example usage case: Insert string into data structure in >> sorted order if it doesn't exist, else retrieve it. >> > After browsing the bisect module I don't think it is the complete > answer. Please correct me if I'm mistaken but... > > Ignoring for a moment that subjectively I feel this is not very > pythonic for my use case, if I get back the insertion position, > doesn't that mean I have to go over on average N/2 items on a linked > list to insert the item in position? Maybe less for sophisticated > implementations but still O(n)? That doesn't compare favorably to the > cost of (possibly) having to rebalance a tree on insertion. I was indeed corrected on this shameful blunder, but in my defense array based lists are implementation dependent and the case for trees can be made on deletion. From pavlovevidence at gmail.com Fri Jun 26 04:53:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 01:53:33 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> <4a4468a0$0$32680$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <53ca7cd6-7bff-478b-a9c7-89c707f580d9@a5g2000pre.googlegroups.com> On Jun 25, 11:20?pm, Stefan Behnel wrote: > Carl Banks wrote: > > On Jun 25, 10:11 pm, Stefan Behnel wrote: > >> Carl Banks wrote: > >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring ? > >>>> at all? > >>> Because Fredrick Lundh wanted it that way. ?Unlike most Python > >>> libraries ElementTree is under the control of one person, which means > >>> it was not designed or vetted by the community, which means it would > >>> tend to have some interface quirks. > >> Just for the record: Fredrik doesn't actually consider it a design "quirk". > > > Well of course he wouldn't--it's his library. > > That's not an argument at all. I can't even imagine what you think I was arguing when I wrote this, or what issue you could have with this statement. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 05:10:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 09:10:15 GMT Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: <00606b41$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 11:30:03 -0500, Nick Craig-Wood wrote: >> Something makes me think that module.__dict__ was only added to Python >> fairly recently, but I'm not sure. > > It exists in python2.1 - I don't have an older python to check at the > moment. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import math >>> len(math.__dict__) 27 -- Steven From pavlovevidence at gmail.com Fri Jun 26 05:15:24 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 02:15:24 -0700 (PDT) Subject: naming packages for pypi References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: On Jun 26, 12:54?am, Aljosa Mohorovic wrote: > is it possible to have 2 packages with same name registered at pypi? > are packages unique per name or also per category or something else? > > if package is unique per name how do you name you packages? > do you name them something like -myapp, -myapp, > -myapp, ... > > if this is current situation is this something that you learned to > live with and there are no indications that this will eventually > change? First off, we need to distinguish between software package (a bunch of software and other data distributed together) and Python package (a hierarchical collection of python modules). Furthermore some Python packages are top-level packages, others are subpackages. Your post seems to suggest some conflating of these concepts so you need to make it clear what you really mean. Usually one PyPI entry corresponds to one software package which contains one unique top level package (which can in turn contain many subpackages), but that's not always the case. The main restriction is that a given top-level package may not appear in more than one PyPI entry. Top-level package names are unique. (That is, unless workarounds, such as customizing the installation, are employed.) Carl Banks From michele.simionato at gmail.com Fri Jun 26 05:56:15 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Jun 2009 02:56:15 -0700 (PDT) Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: <964863ac-bb22-4137-91fe-0c9a448819a9@f16g2000vbf.googlegroups.com> On Jun 24, 7:07?pm, Terry Reedy wrote: > ?????? ??????????? wrote: > > I need to programmaticaly enumerate all the classes in a given module. > > Currently I'm using dir(module) but the Notice on the documentation page > > [1] ?says "dir() is supplied primarily as a convenience for use at an > > interactive prompt" so that kind of scares me. > > That notice primarily refers to the fact that the special names (of > __xxx__ form) returned are implementation and version dependent, and may > not be complete in the sense that dir(ob) may not return __xyz__ even > though ob.__xyz__ exists and can be retrieved. > > If you are only interested in regular-name attribute of ob, let your > fear fly away. There are rather special cases (not your case) where dir does not retrieve all the names to which an object can respond. In particular this happens for class objects: In [1]: class C(object): pass ...: In [2]: dir(C) Out[2]: ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] Notice the absense of the special names __name__, __mro__, __subclasses__ and also mro, which is not special. All these names are defined on the metaclass type and C responds to them, but they are not retrieved by dir. From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:01:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:01:52 GMT Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <0060775a$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote: > If you want accurate math, check out other types like what is in the > decimal module: > >>>> import decimal >>>> a=decimal.Decimal('3.2') >>>> print a * 3 > 9.6 Not so. Decimal suffers from the exact same problem, just with different numbers: >>> import decimal >>> x = decimal.Decimal('1')/decimal.Decimal('3') >>> 3*x == 1 False Some numbers can't be represented exactly in base 2, and some numbers can't be represented exactly in base 10. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:04:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:04:04 GMT Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <006077de$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:31:05 -0700, Mark Dickinson wrote: >> We all know that IEEE floating point is a horribly inaccurate >> representation [...] > > That's a bit extreme! Care to elaborate? Well, 0.1 requires an infinite number of binary places, and IEEE floats only have a maximum of 53 or so, so that implies that floats are infinitely inaccurate... *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:08:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:08:38 GMT Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> Message-ID: <006078f0$0$9721$c3e8da3@news.astraweb.com> On Fri, 26 Jun 2009 00:09:06 -0700, Jason Scheirer wrote: > I once wrote a binary sorted tree data structure for Python in C. It > performed anywhere from 15-40% worse than dicts. I think with > optimization it will only perform 10% worse than dicts at best. > > Oh hey maybe that is why trees aren't an emphasized part of the > standard. They are going to be much slower than the ultra-optimized > dicts already in the standard lib. But dicts require hashable keys, and are in arbitrary order. You can't (for example) traverse a dict in post-order. Hash tables (dicts) are useful for many of the same things that trees are useful for, but they are different data structures with different strengths and weaknesses, and different uses. To argue that we don't need trees because we have dicts makes as much sense as arguing that we don't need dicts because we have lists. -- Steven From magawake at gmail.com Fri Jun 26 06:47:18 2009 From: magawake at gmail.com (Mag Gam) Date: Fri, 26 Jun 2009 06:47:18 -0400 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: <1cbd6f830906260347g7c709213ucde150f28e18a8d8@mail.gmail.com> Thankyou everyone for the responses! I took some of your suggestions and my loading sped up by 25% On Wed, Jun 24, 2009 at 3:57 PM, Lie Ryan wrote: > Mag Gam wrote: >> Sorry for the delayed response. I was trying to figure this problem >> out. The OS is Linux, BTW > > Maybe I'm just being pedantic, but saying your OS is Linux means little > as there are hundreds of variants (distros) of Linux. (Not to mention > that Linux is a kernel, not a full blown OS, and people in GNU will > insist to call Linux-based OS GNU/Linux) > >> Here is some code I have: >> import numpy as np >> from numpy import * > > Why are you importing numpy twice as np and as *? > >> import gzip >> import h5py >> import re >> import sys, string, time, getopt >> import os >> >> src=sys.argv[1] >> fs = gzip.open(src) >> x=src.split("/") >> filename=x[len(x)-1] >> >> #Get YYYY/MM/DD format >> YYYY=(filename.rsplit(".",2)[0])[0:4] >> MM=(filename.rsplit(".",2)[0])[4:6] >> DD=(filename.rsplit(".",2)[0])[6:8] > >> >> f=h5py.File('/tmp/test_foo/FE.hdf5','w') > > this particular line would make it impossible to have more than one > instance of the program open. May not be your concern... > >> >> grp="/"+YYYY >> try: >> ? f.create_group(grp) >> except ValueError: >> ? print "Year group already exists" >> >> grp=grp+"/"+MM >> try: >> ? f.create_group(grp) >> except ValueError: >> ? print "Month group already exists" >> >> grp=grp+"/"+DD >> try: >> ? group=f.create_group(grp) >> except ValueError: >> ? print "Day group already exists" >> > >> str_type=h5py.new_vlen(str) > >> mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', >> 'f4', 'f4')} >> print "Filename is: ",src >> fs = gzip.open(src) > >> dset = f.create_dataset ('Foo',data=arr,compression='gzip') > > What is `arr`? > >> s=0 >> >> #Takes the longest here >> for y in fs: >> ? ? ?continue >> ? a=y.split(',') > >> ? s=s+1 >> ? dset.resize(s,axis=0) > > You increment s by 1 for each iteration, would this copy the dataset? (I > never worked with h5py, so I don't know how it works) > -- > http://mail.python.org/mailman/listinfo/python-list > From magawake at gmail.com Fri Jun 26 06:49:38 2009 From: magawake at gmail.com (Mag Gam) Date: Fri, 26 Jun 2009 06:49:38 -0400 Subject: seeking thru a file Message-ID: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> I have a compressed CSV gziped file. I was wondering if it is possible to seek thru a file For example: I want to load the first 100 lines into an array. Process the data Seek from 101 line to 200 lines. Process the data (remove lines 0 - 100) from memory Seek 201 to 300 line. Process the data (remove 200-300)) from memory etc..etc.. From msliczniak at gmail.com Fri Jun 26 07:09:32 2009 From: msliczniak at gmail.com (Michael Sliczniak) Date: Fri, 26 Jun 2009 04:09:32 -0700 (PDT) Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> <4dbdd92b-2f7d-45a4-933e-ed15e65f854c@s16g2000vbp.googlegroups.com> Message-ID: <5ab86546-8d46-4313-a09d-82dc905f4e7b@j12g2000vbl.googlegroups.com> On Jun 25, 2:30?pm, Carl Banks wrote: Thank you for the very good reply. In fact delegating is the approach that works. The main thing to notice is that for an uninstantiated class the first arg to __get__ is None: class desc(object): __slots__ = ('x') def __init__(self, desc): self.x = desc def __get__(self, a, b): #print 'desc get', `self`, `a`, `b` if a == None: return self return self.x.__get__(a) def __set__(self, a, b): #print 'desc set', `self`, `a`, `b` self.x.__set__(a, b) def foo(self): return 'foo' def bar(self): return 'bar' class A(object): __slots__ = ('x', 'y') def __init__(self, *args): for i in xrange(len(args)): setattr(self, A.__slots__[i], args[i]) a = A(0, 1) b = A(2, 3) print a.x, a.y, b.x, b.y x = A.x dx = desc(x) A.x = dx y = A.y dy = desc(y) A.y = dy print type(a).x.foo() print type(a).x.bar() print type(a).y.foo() print type(a).y.bar() print type(b).x.foo() print type(b).x.bar() print type(b).y.foo() print type(b).y.bar() print a.x, a.y, b.x, b.y a.x = -1 a.y = -2 b.x = -3 b.y = -4 print a.x, a.y, b.x, b.y A.x = x print a.x, a.y, b.x, b.y This produces this output: 0 1 2 3 foo bar foo bar foo bar foo bar 0 1 2 3 -1 -2 -3 -4 -1 -2 -3 -4 The manner in which __get__ has to delegate is not pleasant compared to if you could simply derive a new class from method_descriptor with the foo and bar methods though, oh well. From http Fri Jun 26 07:14:18 2009 From: http (Paul Rubin) Date: 26 Jun 2009 04:14:18 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <7xy6rfjlh1.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > > Besides some interface glitches, like returning None > > on delete if I recall correctly. > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. But deletes in an AVL tree should not cause mutation. They should just allocate a new root and path up to where the deleted node was. That allows having references to the old and new versions of the tree, etc. From http Fri Jun 26 07:15:48 2009 From: http (Paul Rubin) Date: 26 Jun 2009 04:15:48 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> Message-ID: <7xtz23jlej.fsf@ruckus.brouhaha.com> Chris Rebert writes: > > Simple example usage case: Insert string into data structure in > > sorted order if it doesn't exist, else retrieve it. > > That's pretty much the bisect module in a nutshell. It manipulates a > sorted list using binary search. That lets you find an existing entry in log(n) time, but inserting or deleting an entry still takes linear time. Also, you don't get a persistent structure in the sense of functional programming. From stefan_ml at behnel.de Fri Jun 26 07:37:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 13:37:25 +0200 Subject: No trees in the stdlib? In-Reply-To: <7xy6rfjlh1.fsf@ruckus.brouhaha.com> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <7xy6rfjlh1.fsf@ruckus.brouhaha.com> Message-ID: <4a44b2f5$0$31340$9b4e6d93@newsspool4.arcor-online.net> Paul Rubin wrote: > Stefan Behnel writes: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> not (side-effect free) functions, so it's just purity if they do not have a >> return value. > > But deletes in an AVL tree should not cause mutation. They should > just allocate a new root and path up to where the deleted node was. > That allows having references to the old and new versions of the tree, > etc. I doubt that there are many AVL implementations that do that. Plus, if deletion doesn't delete, I'd happily consider that a bug. Stefan From bhardwajjayesh at gmail.com Fri Jun 26 07:38:33 2009 From: bhardwajjayesh at gmail.com (jayesh bhardwaj) Date: Fri, 26 Jun 2009 04:38:33 -0700 (PDT) Subject: file transfer in python Message-ID: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> i am trying to find something useful in python to transfer html files from one terminal to other. Can this be done with some module or shall i start coding my own module using low level socket interface. If u know about some books on this topic or any online help then plz help. From twirlip at bigfoot.com Fri Jun 26 07:52:55 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Fri, 26 Jun 2009 12:52:55 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: <50d94559b1ki83o0k23g0sb5i9ps6mc25o@4ax.com> On Thu, 25 Jun 2009 18:22:48 +0100, MRAB wrote: >Angus Rodgers wrote: >> On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser >> wrote: >> >>> At 2009-06-24T19:53:49Z, Angus Rodgers writes: >>> >>>> print ''.join(map(detab, f.xreadlines())) >>> An equivalent in modern Pythons: >>> >>>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) >> >> I guess the code below would also have worked in 2.1? >> (It does in 2.5.4.) >> >> print ''.join(line.expandtabs(3) for line in \ >> file('h071.txt').xreadlines()) >> >That uses a generator expression, which was introduced in 2.4. Sorry, I forgot that list comprehensions need square brackets. The following code works in 2.1 (I installed version 2.1.3, on a different machine, to check!): f = open('h071.txt') # Can't use file('h071.txt') in 2.1 print ''.join([line.expandtabs(3) for line in f.xreadlines()]) (Of course, in practice I'll stick to doing it the more sensible way that's already been explained to me. I'm ordering a copy of Wesley Chun, /Core Python Programming/ (2nd ed., 2006), to learn about version 2.5.) -- Angus Rodgers From nils at ccsg.de Fri Jun 26 08:00:58 2009 From: nils at ccsg.de (=?ISO-8859-1?Q?Nils_R=FCttershoff?=) Date: Fri, 26 Jun 2009 14:00:58 +0200 Subject: seeking thru a file In-Reply-To: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> References: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> Message-ID: <4A44B87A.80509@ccsg.de> Hi Mag, Mag Gam wrote: > I have a compressed CSV gziped file. I was wondering if it is possible > to seek thru a file > > For example: > > I want to load the first 100 lines into an array. Process the data > > Seek from 101 line to 200 lines. Process the data (remove lines 0 - > 100) from memory > > Seek 201 to 300 line. Process the data (remove 200-300)) from memory > > etc..etc.. > This would be very easy. Here is one way you could do it: (I didn't test the code; I've just write it down, assuming you use python 2.6, cause you didn't mentioned which version you are using...) import gzip step = 100 data_present = True with gzip.open(foo.csv.gzip) as my_file: counter = 0 my_buffer = [] while data_present: while counter <= step: line = my_file.readline() if line: my_buffer.append(my_file.readline()) counter += 1 else: data_present = False break if len(my_buffer) > 0: do_something(my_buffer) counter = 0 my_buffer = [] Kind Regards, Nils From doron.tal.list at gmail.com Fri Jun 26 08:07:45 2009 From: doron.tal.list at gmail.com (Doron Tal) Date: Fri, 26 Jun 2009 15:07:45 +0300 Subject: file transfer in python In-Reply-To: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: <2a8674c60906260507h164c5a99gd26ada06a9ec8b6d@mail.gmail.com> On Fri, Jun 26, 2009 at 2:38 PM, jayesh bhardwaj wrote: > i am trying to find something useful in python to transfer html files > from one terminal to other. Can this be done with some module or shall > i start coding my own module using low level socket interface. If u > know about some books on this topic or any online help then plz help. > -- > http://mail.python.org/mailman/listinfo/python-list > You can try the xmlrpclib: http://docs.python.org/library/xmlrpclib.html#binary-objects --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Fri Jun 26 08:07:54 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Fri, 26 Jun 2009 05:07:54 -0700 (PDT) Subject: file transfer in python References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: On 26 Giu, 13:38, jayesh bhardwaj wrote: > i am trying to find something useful in python to transfer html files > from one terminal to other. Can this be done with some module or shall > i start coding my own module using low level socket interface. If u > know about some books on this topic or any online help then plz help. In the standard library there is ftplib, which allows your program to act as a FTP client. Of course the receiver end should have an FTP server installing and running. I don't tink it can handle SFTP protocol, so if you are concerned with security you should opt for someting else, or protect your connection somehow (e.g. SSH tunneling). Or, if you have ssh (client and server) installed, you could simply spawn a subprocess ( see the subprocess module for that ) which execute one or more 'scp' commands. Ciao ---- FB From bijoy.franco at gmail.com Fri Jun 26 08:23:17 2009 From: bijoy.franco at gmail.com (bijoy franco) Date: Fri, 26 Jun 2009 17:53:17 +0530 Subject: Python simple web development In-Reply-To: References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> Hi, I am learning pylons..It seems to be very simple and flexible.. Just give a try if it seems interesting for you Thanks Bijoy On Fri, Jun 26, 2009 at 3:02 AM, Gabriel Genellina wrote: > En Thu, 25 Jun 2009 04:29:28 -0300, Private Private > escribi?: > > I am looking for a python library which will allow me to do a simple >> web development. I need to use >> some forms (but nice looking :-) ), creating images based on input >> from those forms, etc. I have read a bit about Django and TurboGears >> but I am afraid that this is too big for my requirements (am I >> wrong ?). >> Can you suggest anything ? >> > > You may try pesto: http://pesto.redgecko.org/ > > pesto is a very small framework (45k to download!), WSGI compliant, > includes session management, mapping URL->function, caching, templates > (optional, whichever you like). Minimalist but flexible. > > Anyway, learning to use Django isn't a bad idea. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From spconv+m at gmail.com Fri Jun 26 08:28:42 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 14:28:42 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4A4411AB.1090302@hughes.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> Message-ID: <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> 2009/6/26 norseman : > Sebastian Paj?k wrote: >>> >>> Can, but should not. >>> I read that the problem is when using the Polish language only. Otherwise >>> things work normally. Is that correct? >> >> Yes, correct >> >>> If so then byte swap may be a problem. ?Using the u'string' should solve >>> that. I am assuming you have the Polish alphabet working correctly on >>> your >>> machine. I think I read that was so in an earlier posting. >>> >>> Are there any problems with his alphabet scrambling on your machine? >>> If so that needs investigating. ?Here I assume you are reading Polish >>> from >>> him on your machine and not a network translator version. >>> >> >> The original thread is here: >> http://mail.python.org/pipermail/python-list/2009-June/717666.html >> I've explained the problem there > > ================ > I re-read the posting. (Thanks for the link) > > You do not mention if he has sent you any Polish words and if they > appear OK on your machine. > He has sent my a polish words, they appear correct. We both have the english version of systems (they are both set to polish locale (time, dates, keyboard etc.)) > A note here: ?In reading the original posting I get symbols that are not > familiar to me as alphabet. > From the line in your original: > ? ? Label(root, text='?????????').pack() > I see text=' > ? ? ? ? ? then an e with a goatee > ? ? ? ? ? ? ? ?a ?capitol O with an accent symbol on top (') > ? ? ? ? ? ? ? ?an a with a tail on the right > ? ? ? ? ? ? ? ?a ?s with an accent on top > ? ? ? ? ? ? ? ?an I do no not know what - maybe some sort of l with a > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? slash through the middle > ? ? ? ? ? ? ? ?a ?couple of z with accents on top > ? ? ? ? ? ? ? ?a ?capitol C with an accent on top > ? ? ? ? ? ? ? ?a ?n with a short bar on top > > I put the code into python and took a look. > > > > I get: > cat xx > > # -*- coding: utf-8 -*- > > import sys > from Tkinter import * > > root = Tk() > > Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() > Button(root, > text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() > Entry(root).pack() > > root.mainloop() > > Then: > python xx > ?File "xx", line 10 > SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no > encoding declared; see http://www.python.org/peps/pep-0263.html for details > > So I did. > It notes Window$ puts things into those lines. Namely: > "To aid with platforms such as Windows, which add Unicode BOM marks > ? ?to the beginning of Unicode files, the UTF-8 signature > ? ?'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well > ? ?(even if no magic encoding comment is given). > " > > Then I took out the o with the accent and re-ran the file. > > Everything works except the text is exactly as shown above. That is: > \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 > (shows twice as directed, one for label, one for button, no apostrophes) > > OK - now I take a look at what in actually in the file. > in MC on Linux Slackware 10.2 I read, in the mail folder, > 0119 capitol A with a tilde on top. > HEX readings beginning at the 0119\... > 30 31 31 39 C3 B3 5C > > but in the python file xx, I read: > 30 31 31 39 5C > 0119\... > > I would have to say the mail system is screwing you up. ?Might try zipping > the file and sending it that way and see if problem changes. > I've tried zipping It looks like you you didn't save the script in UTF-8. Try to run the original script file from attachment (UTF-8 without BOM). ps. Do you have mac os x? It would be better if someone with mac tested it # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() root.tk.call('encoding', 'system', 'utf-8') Label(root, text=u'?????????').pack() Button(root, text=u'?????????').pack() root.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: test1.py Type: application/octet-stream Size: 242 bytes Desc: not available URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 26 08:34:52 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 26 Jun 2009 14:34:52 +0200 Subject: seeking thru a file In-Reply-To: References: Message-ID: <4a44c06b$0$403$426a74cc@news.free.fr> Mag Gam a ?crit : > I have a compressed CSV gziped file. Then gunzip it first... > I was wondering if it is possible > to seek thru a file > > For example: > > I want to load the first 100 lines into an array. Process the data > > Seek from 101 line to 200 lines. Process the data (remove lines 0 - > 100) from memory > > Seek 201 to 300 line. Process the data (remove 200-300)) from memory > > etc..etc.. Yes, you can... Now is there any reason you want to micro-manage stuff already managed by Python and the file system ?-) To iterate on a text file's lines, just open the file - the file object is it's own iterator, and will (with help from the filesystem AFAIK) properly handle cache, buffers and whatnot. The canonical code snippet is: # iterating over a file line by line without # loading the while file in memory f = open("/path/to/some/file.txt") for line in f: do_something_with(line) f.close() Unless you have a good reason (micro-managing IO buffers not being one) to want to work by 100-lines batch, then this should be just enough. Now note that Python also have a csv module in the standard lib, which will probably (except perhaps in a very few corner cases) be more robust and efficient that whatever you'd write. HTH From spconv+m at gmail.com Fri Jun 26 08:37:41 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 14:37:41 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4a441def$0$12249$9b622d9e@news.freenet.de> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <4a441def$0$12249$9b622d9e@news.freenet.de> Message-ID: <111013c20906260537w893c0a2j75479e5d44f43209@mail.gmail.com> > ?in place where polish >> accented character should be (like "?????" etc) >> This problem is only on mac os x and it doesn't apply to button widget >> (where characters are correct) > > I see. So it is a font problem: if the square box is displayed, it means > that the font just doesn't have a glyph for the character you want to > display. Try using a different font in the label widget. I've tried many fonts, the effect is always the same. Standard fonts like Arial, Tahoma, Vedana all have Polish glyphs. The problem is that Tkinter selects wrong glyphs for non-ASCII chars. It's not the font issue as text on Button widget appears correctly >> There is no wish. I'm talking about build-in Tkinter > > So try installing Tk separately. > >> (isn't Tk build-in Python?). > > Depends on where exactly you got your Python from, and what exactly > is your OSX version. Recent releases of OSX include a copy of Tcl/Tk, > and some sets of Python binaries link against the Apple Tk. > As I said I don't have mac osx. I just expect my Python script to be portable and behave the same on both Windows and OSX, but It isn't. From udyantw at gmail.com Fri Jun 26 10:07:51 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 07:07:51 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation Message-ID: I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in both flavors of Python: 2.6.2 and 3.0.1 (CPython) The code: #!/usr/bin/env python def remaining_peg (peg1, peg2): return (6 - peg1 - peg2) def hanoi (num_discs, start, end): if (1 == num_discs): print "Top of peg {0} to peg {1}".format(start,end) # used print() for Py 3.0.1 else: hanoi ((num_discs - 1), start, (remaining_peg (start, end))) hanoi (1, start, end) hanoi ((num_discs - 1), (remaining_peg (start, end)), end) hanoi(20,2,3) The times: real usr sys Python 2.6.2 7.994s 3.336s 3.296s Python 3.0.1 55.302s 38.024s 5.876s What happened to Python? From pdpinheiro at gmail.com Fri Jun 26 10:09:25 2009 From: pdpinheiro at gmail.com (pdpi) Date: Fri, 26 Jun 2009 07:09:25 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <0060775a$0$9721$c3e8da3@news.astraweb.com> Message-ID: <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> On Jun 26, 11:01?am, Steven D'Aprano wrote: > On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote: > > If you want accurate math, check out other types like what is in the > > decimal module: > > >>>> import decimal > >>>> a=decimal.Decimal('3.2') > >>>> print a * 3 > > 9.6 > > Not so. Decimal suffers from the exact same problem, just with different > numbers: > > >>> import decimal > >>> x = decimal.Decimal('1')/decimal.Decimal('3') > >>> 3*x == 1 > > False > > Some numbers can't be represented exactly in base 2, and some numbers > can't be represented exactly in base 10. > > -- > Steven But since 10 = 2 * 5, all numbers that can be finitely represented in binary can be represented finitely in decimal as well, with the exact same number of places for the fractional part (and no more digits than the binary representation in the integer part) From stefan_ml at behnel.de Fri Jun 26 10:14:50 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 16:14:50 +0200 Subject: Py 3 slower than Py 2. Towers of Hanoi implementation In-Reply-To: References: Message-ID: <4a44d7d9$0$32673$9b4e6d93@newsspool2.arcor-online.net> Udyant Wig wrote: > I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > The code: > #!/usr/bin/env python > def remaining_peg (peg1, peg2): > return (6 - peg1 - peg2) > > def hanoi (num_discs, start, end): > if (1 == num_discs): > print "Top of peg {0} to peg {1}".format(start,end) # used print() > for Py 3.0.1 > > else: > hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > hanoi (1, start, end) > hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > The times: real usr sys > Python 2.6.2 7.994s 3.336s 3.296s > Python 3.0.1 55.302s 38.024s 5.876s > > What happened to Python? Have you tried Python 3.1? Have you made sure that both Python interpreters were build with the same compiler arguments and that none of them is a debug build? Stefan From h.b.furuseth at usit.uio.no Fri Jun 26 10:35:59 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Fri, 26 Jun 2009 16:35:59 +0200 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel writes: >Jo?o Valverde wrote: >> Besides some interface glitches, like returning None >> on delete if I recall correctly. > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. It's purity that they don't return the modified tree/dict/whatever. They can still return the deleted element and remain pure. -- Hallvard From udyantw at gmail.com Fri Jun 26 10:37:09 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 07:37:09 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation References: <4a44d7d9$0$32673$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <5cc9327a-eedc-49ce-b817-35dad9616405@w31g2000prd.googlegroups.com> On Jun 26, 7:14?pm, Stefan Behnel wrote: > Udyant Wig wrote: > > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin > > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > > The code: > > #!/usr/bin/env python > > def remaining_peg (peg1, peg2): > > ? ?return (6 - peg1 - peg2) > > > def hanoi (num_discs, start, end): > > ? ?if (1 == num_discs): > > ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > > for Py 3.0.1 > > > ? ?else: > > ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > > ? ? ? ? ? ?hanoi (1, start, end) > > ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > > What happened to Python? > > Have you tried Python 3.1? Have you made sure that both Python interpreters > were build with the same compiler arguments and that none of them is a > debug build? > > Stefan Yes. Both were built with the same compiler parameters. No. None of them is a debug build. I'm currently getting Python 3.1 From stefan_ml at behnel.de Fri Jun 26 10:42:42 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 16:42:42 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4a44de62$0$32677$9b4e6d93@newsspool2.arcor-online.net> Hallvard B Furuseth wrote: > Stefan Behnel writes: >> Jo?o Valverde wrote: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> not (side-effect free) functions, so it's just purity if they do not have a >> return value. > > It's purity that they don't return the modified tree/dict/whatever. > They can still return the deleted element and remain pure. Fair enough. Stefan From Slattery_T at bls.gov Fri Jun 26 10:57:35 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 10:57:35 -0400 Subject: "The system cannot execute the specified program." Message-ID: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Our office has a copy of Python 3.0 installed on a network share device. When I try to run it I get this message: "The system cannot execute the specified program." When I googled that message, the links that came up had to do with missing DLLs. So I fired up Dependency Walker and found out that there were indeed DLLs that it needed that the OS couldn't find. So I supplied those DLLs. And it still gives the same message, even though Dependency Walker is now happy. Does anybody have a clue what might cause this amazingly uninformative message? On a related note: there's a *.chm file on the same share, that's a PYthon user's guide. When I start that, I get a window with the full table of contents and index on the left side. But on the right side where the contents should be ... "Navigation to the web page was canceled". WTF??? -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From p.f.moore at gmail.com Fri Jun 26 11:01:24 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 26 Jun 2009 16:01:24 +0100 Subject: Py 3 slower than Py 2. Towers of Hanoi implementation In-Reply-To: References: Message-ID: <79990c6b0906260801r6efc7560ud2c465cd68704d72@mail.gmail.com> 2009/6/26 Udyant Wig : > I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > The code: > #!/usr/bin/env python > def remaining_peg (peg1, peg2): > ? ? ? ?return (6 - peg1 - peg2) > > def hanoi (num_discs, start, end): > ? ? ? ?if (1 == num_discs): > ? ? ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > for Py 3.0.1 > > ? ? ? ?else: > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > ? ? ? ? ? ? ? ?hanoi (1, start, end) > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > What happened to Python? I/O in Python 3.0 is known to be slow, because the bulk of the implementation is in Python (rather than C). Python 3.1 addresses this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the print commented out, the second are with the print, redirected to the null device. The tests are on a pretty slow Windows XP SP2 laptop. >timer & \Apps\Python26\python.exe hanoi.py & timer Timer 1 on: 15:54:53 Timer 1 off: 15:54:57 Elapsed: 0:00:03.88 >timer & \Apps\Python31\python.exe hanoi.py & timer Timer 1 on: 15:57:05 Timer 1 off: 15:57:09 Elapsed: 0:00:03.67 >timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer Timer 1 on: 15:57:44 Timer 1 off: 15:58:14 Elapsed: 0:00:29.91 >timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer Timer 1 on: 15:58:38 Timer 1 off: 15:59:09 Elapsed: 0:00:30.63 Nothing much in it. Paul. From aljosa.mohorovic at gmail.com Fri Jun 26 11:05:01 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 26 Jun 2009 08:05:01 -0700 (PDT) Subject: naming packages for pypi References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: <96438f05-b536-4a79-8ba2-d19bdbd1eb8e@j20g2000vbp.googlegroups.com> On Jun 26, 11:15 am, Carl Banks wrote: > Your post seems to suggest some conflating of these concepts so you > need to make it clear what you really mean. my example: when creating website example.com (django project) it contains multiple django apps which i package separately. most of websites have news, about, contact so i would create 3 packages news, about and contact and add them to pypi.example.com (private pypi for my company). same thing happens for site example2.com, example3.com so finally i have something like: example.com-news # news package for project/site example.com example2.com-news # news package for project/site example2.com example3.com-news # news package for project/site example3.com i'm trying to find a better way, currently it looks to me like packaging system is missing namespaces/categories or something similar but i'm guessing it's only that i don't know how to do it properly. that's why i'm asking so please suggest a proper way for me to do it. Aljosa Mohorovic From Scott.Daniels at Acm.Org Fri Jun 26 11:07:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 08:07:24 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> References: <0060775a$0$9721$c3e8da3@news.astraweb.com> <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> Message-ID: pdpi wrote: > ... But since 10 = 2 * 5, all numbers that can be finitely represented in > binary can be represented finitely in decimal as well, with the exact > same number of places for the fractional part (and no more digits > than the binary representation in the integer part) OK, so base 30 is the obvious choice, digits and letters, and 1/N works for n in range(1, 7) + range(8, 11). G?del numbers, anyone? :-) --Scott David Daniels Scott.Daniels at Acm.Org From andreengels at gmail.com Fri Jun 26 11:17:03 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 26 Jun 2009 17:17:03 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <0060775a$0$9721$c3e8da3@news.astraweb.com> <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> Message-ID: <6faf39c90906260817wbba0391x44d49b9cb6c7a521@mail.gmail.com> On Fri, Jun 26, 2009 at 5:07 PM, Scott David Daniels wrote: > pdpi wrote: >> >> ... But since 10 = 2 * 5, all numbers that can be finitely represented in >> binary can be represented finitely in decimal as well, with the exact >> same number of ?places for the fractional part (and no more digits >> than the binary representation in the integer part) > > OK, so base 30 is the obvious choice, digits and letters, and 1/N works > for n in range(1, 7) + range(8, 11). ?G?del numbers, anyone? :-) To get even more working, use real rational numbers: p/q represented by the pair of numbers (p,q) with p,q natural numbers. Then 1/N works for every N, and upto any desired precision. -- Andr? Engels, andreengels at gmail.com From fpm at u.washington.edu Fri Jun 26 11:18:29 2009 From: fpm at u.washington.edu (cassiope) Date: Fri, 26 Jun 2009 08:18:29 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <67a85e72-9171-4e54-8562-a30e0002191d@x1g2000prh.googlegroups.com> On Jun 25, 1:33?am, Francesco Bochicchio wrote: > Hi all, > > as many - I think - python programmers, I find muself debugging my > scripts by placing print statements in strategic places rather than > using the python debugger, and commenting/uncommenting them according > to myy deugging needs. ?After a time, these prints staements start to > evolving in some ad-hoc half-baked framework ... so I wonder if there > is somewhere there is a full-baked trace statement support framework > which I can use. I'm aware of the logging module, but for me it its > more geared toward ?application logging rather than toward trace for > debugging purpose. > > Having googlet and found nothing (or too much but nothing relef?vant), > I'm now asking The List. > > Here is what I have in mind: > > Each module, function, class and method should have an attribute, say > trace_flag, which can be set to true or false value. > > there should be a function TRACE which does something like this: > > if __debug__ : > def TRACE(*args): > ? ? ?if ?trace_enabled(): print "TRACE(%s) : %s " % ( context(), " > ".join( str(x) for x in args ) ) > > where trace_enabled() should return the value of the innermost > trace_flag (checking current function/method then current class (if > any) then current module) and context() shoud return a string like > "module.function" or "module.class.method" ). > > At this point I could in my test code enable ?the trace in the > function/class that gives me trouble and disable it after I fixed it, > without having to touch the actual code under test. > > I guess it should not be too hard do using python introspection > modules, but of couse I first would like to know if something like > this already exists. > > I'm ?aware that this imposes a performance penalty, but my scripts are > not operformance-critical. And if I put an if __debug__ switch What are you trying to achieve that could not be accomplished with the logging module? http://docs.python.org/library/logging.html#module-logging -f From mail at timgolden.me.uk Fri Jun 26 11:21:19 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 26 Jun 2009 16:21:19 +0100 Subject: "The system cannot execute the specified program." In-Reply-To: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <4A44E76F.6040305@timgolden.me.uk> Tim Slattery wrote: > Our office has a copy of Python 3.0 installed on a network share > device. When I try to run it I get this message: "The system cannot > execute the specified program." To be honest, I'd look at one of the Portable Python installations, specifically designed to be run off a stick or a network share. http://www.portablepython.com/ http://www.voidspace.org.uk/python/movpy/ TJG From spconv+m at gmail.com Fri Jun 26 11:27:26 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 17:27:26 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: <111013c20906260827r62a06679lf3455f18ed34ff38@mail.gmail.com> Maybe this picture will tell you more: http://files.getdropbox.com/u/1211593/tkinter.png The original script: http://files.getdropbox.com/u/1211593/test1.py May someone can confirm this osx behaviour? 2009/6/26 Sebastian Paj?k : > 2009/6/26 norseman : >> Sebastian Paj?k wrote: >>>> >>>> Can, but should not. >>>> I read that the problem is when using the Polish language only. Otherwise >>>> things work normally. Is that correct? >>> >>> Yes, correct >>> >>>> If so then byte swap may be a problem. ?Using the u'string' should solve >>>> that. I am assuming you have the Polish alphabet working correctly on >>>> your >>>> machine. I think I read that was so in an earlier posting. >>>> >>>> Are there any problems with his alphabet scrambling on your machine? >>>> If so that needs investigating. ?Here I assume you are reading Polish >>>> from >>>> him on your machine and not a network translator version. >>>> >>> >>> The original thread is here: >>> http://mail.python.org/pipermail/python-list/2009-June/717666.html >>> I've explained the problem there >> >> ================ >> I re-read the posting. (Thanks for the link) >> >> You do not mention if he has sent you any Polish words and if they >> appear OK on your machine. >> > > He has sent my a polish words, they appear correct. We both have the > english version of systems (they are both set to polish locale (time, > dates, keyboard etc.)) > >> A note here: ?In reading the original posting I get symbols that are not >> familiar to me as alphabet. >> From the line in your original: >> ? ? Label(root, text='?????????').pack() >> I see text=' >> ? ? ? ? ? then an e with a goatee >> ? ? ? ? ? ? ? ?a ?capitol O with an accent symbol on top (') >> ? ? ? ? ? ? ? ?an a with a tail on the right >> ? ? ? ? ? ? ? ?a ?s with an accent on top >> ? ? ? ? ? ? ? ?an I do no not know what - maybe some sort of l with a >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? slash through the middle >> ? ? ? ? ? ? ? ?a ?couple of z with accents on top >> ? ? ? ? ? ? ? ?a ?capitol C with an accent on top >> ? ? ? ? ? ? ? ?a ?n with a short bar on top >> >> I put the code into python and took a look. >> >> >> >> I get: >> cat xx >> >> # -*- coding: utf-8 -*- >> >> import sys >> from Tkinter import * >> >> root = Tk() >> >> Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() >> Button(root, >> text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() >> Entry(root).pack() >> >> root.mainloop() >> >> Then: >> python xx >> ?File "xx", line 10 >> SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no >> encoding declared; see http://www.python.org/peps/pep-0263.html for details >> >> So I did. >> It notes Window$ puts things into those lines. Namely: >> "To aid with platforms such as Windows, which add Unicode BOM marks >> ? ?to the beginning of Unicode files, the UTF-8 signature >> ? ?'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well >> ? ?(even if no magic encoding comment is given). >> " >> >> Then I took out the o with the accent and re-ran the file. >> >> Everything works except the text is exactly as shown above. That is: >> \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 >> (shows twice as directed, one for label, one for button, no apostrophes) >> >> OK - now I take a look at what in actually in the file. >> in MC on Linux Slackware 10.2 I read, in the mail folder, >> 0119 capitol A with a tilde on top. >> HEX readings beginning at the 0119\... >> 30 31 31 39 C3 B3 5C >> >> but in the python file xx, I read: >> 30 31 31 39 5C >> 0119\... >> >> I would have to say the mail system is screwing you up. ?Might try zipping >> the file and sending it that way and see if problem changes. >> > > I've tried zipping > It looks like you you didn't save the script in UTF-8. Try to run the > original script file from attachment (UTF-8 without BOM). > ps. Do you have mac os x? It would be better if someone with mac tested it > > > # -*- coding: utf-8 -*- > > import sys > > from Tkinter import * > > root = Tk() > root.tk.call('encoding', 'system', 'utf-8') > > Label(root, text=u'?????????').pack() > Button(root, text=u'?????????').pack() > > root.mainloop() > From news123 at free.fr Fri Jun 26 11:29:11 2009 From: news123 at free.fr (News123) Date: Fri, 26 Jun 2009 17:29:11 +0200 Subject: R-tree implemetation in python without external C_libraries Message-ID: <4a44e947$0$420$426a74cc@news.free.fr> Hi, I'd like to have a small rtree library for a small python project. ( good data structure for 2D searches ) For this mini - project I'd prefer, to have no C-library dependencies Does anyone have a small implementation which I'm allowed to use and modify, which does not use an external C-library? What I'm mostly interested in is the R-Tree creation. Thanks in advance for any pointers. If you don't know a pure python implementation, then I'd be also interested in implemetations in other languages. I could then use these implementations and recode them to python. The alternative languages could be perl java java-script C C++ thanks in advance for any pointers bye N From aadarshjajodia at gmail.com Fri Jun 26 11:58:45 2009 From: aadarshjajodia at gmail.com (Addy) Date: Fri, 26 Jun 2009 08:58:45 -0700 (PDT) Subject: opening a https web page Message-ID: <5e3e86e5-d908-4eff-8ea2-aff508eeae69@s38g2000prg.googlegroups.com> Dear sir, i am not being able to open "https://" web pages using urllib2 or urllib. I am being able to open "http" pages though. i am connecting the internet through a proxy server. I am being able to open "https://" pages if i am using an ineternet connection that does not connect through a proxy server.Please Help. Looking forward to your reply. Aadarsh Jajodia From niloyroy47 at gmail.com Fri Jun 26 12:08:40 2009 From: niloyroy47 at gmail.com (padfoot) Date: Fri, 26 Jun 2009 09:08:40 -0700 (PDT) Subject: handling https sites Message-ID: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Sir, Is there any module in python to open https sites through a proxy.I am connectyed to the net via a proxy server and i am unable to crawl https sites. From barakatx2 at gmail.com Fri Jun 26 12:09:41 2009 From: barakatx2 at gmail.com (BarakatX2) Date: Fri, 26 Jun 2009 09:09:41 -0700 (PDT) Subject: MultiValueDict? Message-ID: <4d67805e-2eed-4745-9e02-85797330013b@l5g2000vbp.googlegroups.com> , , ]}> for f in files['rqFiles']: print f.name This gives me an "'str' object has no attribute 'name'" error. I don't know if there is a special way to access MultiValueDicts values, but I assumed each key has a list that is accessed just like any other list. Any help is appreciated. From shawn.milo at gmail.com Fri Jun 26 12:28:20 2009 From: shawn.milo at gmail.com (Shawn Milochik) Date: Fri, 26 Jun 2009 12:28:20 -0400 Subject: handling https sites In-Reply-To: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> References: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Message-ID: <696448CE-B9E6-4412-9C98-E543218317E5@gmail.com> On Jun 26, 2009, at 12:08 PM, padfoot wrote: > Sir, > Is there any module in python to open https sites through a > proxy.I am connectyed to the net via a proxy server and i am unable to > crawl https sites. > -- > http://mail.python.org/mailman/listinfo/python-list Check out the "Scrape the Web" series from the 2009 PyCon: http://advocacy.python.org/podcasts/ From Slattery_T at bls.gov Fri Jun 26 12:29:39 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 12:29:39 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Tim Slattery wrote: >Our office has a copy of Python 3.0 installed on a network share >device. When I try to run it I get this message: "The system cannot >execute the specified program." I should add that before I knew about our shared installation, I downloaded the AS distribution of Python 2.6 from ActiveState. Their install procedure is a *.bat file that calls Python to put everything in the right place. When the bat file tries to invoke Python, I get the same message. -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From cgoldberg at gmail.com Fri Jun 26 12:34:02 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Fri, 26 Jun 2009 09:34:02 -0700 (PDT) Subject: handling https sites References: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Message-ID: > Is there any module in python to open https > sites through a proxy. yes, you can use "urllib2". from the urllib2 docs: "The default is to read the list of proxies from the environment variables" So if you have a proxy setup, it should detect it from your environment vars. If you want to specify something different, you want to build an opener with a ProxyHandler: http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler -Corey From duncan.booth at invalid.invalid Fri Jun 26 12:51:00 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Jun 2009 16:51:00 GMT Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: Tim Slattery wrote: > Our office has a copy of Python 3.0 installed on a network share > device. When I try to run it I get this message: "The system cannot > execute the specified program." > > When I googled that message, the links that came up had to do with > missing DLLs. So I fired up Dependency Walker and found out that there > were indeed DLLs that it needed that the OS couldn't find. So I > supplied those DLLs. And it still gives the same message, even though > Dependency Walker is now happy. > > Does anybody have a clue what might cause this amazingly uninformative > message? Are you using Vista? There seem to be some strange security settings for network shares in Vista. I had a file shared from an XP system which my Vista system could not access even though other machines could access it. Eventually I had to copy the file from the XP machine onto the Vista machine and it was happy to access it once it was on the local system. Alternatively for a non-Vista wild guess, could it be that Python 3.0 is loading some libraries that use .Net and is therefore triggering the 'code access security' which prevents the running of .Net applications from a network share? From nobody at nowhere.com Fri Jun 26 13:01:24 2009 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Jun 2009 18:01:24 +0100 Subject: validating HTTPS certificates? References: Message-ID: On Fri, 26 Jun 2009 10:04:21 +0200, Andras.Horvath wrote: > (disclaimer: this might be a FAQ entry somewhere but I honestly did use > Google) > > I'm in the process of picking a language for a client application that > accesses a HTTPS (actually SOAP) server. This would be easy enough in > Python, but I came across a strange fact: neither httplib nor urllib > offer the possibility to actually verify the server's certificate. > > After some digging I've found that from 2.6 onward, the ssl module > offers such functionality but it's not trivial, at least for me, to glue > that to the HTTP protocol modules (and then those to the SOAP module). > > Did I miss something? If not, is this feature foreseen, e.g. the trivial > build-up of a HTTPS connection while verifying the certificate chain? For a urllib-style interface, there's not much point in performing verification after the fact. Either the library performs verification or it doesn't. If it doesn't, you've just sent the (potentially confidential) request to an unknown server; discovering this after the fact doesn't really help. From http Fri Jun 26 13:13:25 2009 From: http (Paul Rubin) Date: 26 Jun 2009 10:13:25 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <7xy6rfjlh1.fsf@ruckus.brouhaha.com> <4a44b2f5$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <7x1vp67way.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > > But deletes in an AVL tree should not cause mutation. They should > > just allocate a new root and path up to where the deleted node was. > I doubt that there are many AVL implementations that do that. Plus, if > deletion doesn't delete, I'd happily consider that a bug. I've never seen one that DIDN'T do that, but maybe it's just the crowd I hang out with. See "Purely Functional Data Structures" by Chris Okasaki for more detailed descriptions of such methods. From aahz at pythoncraft.com Fri Jun 26 13:15:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 10:15:58 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: In article <006078f0$0$9721$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >Hash tables (dicts) are useful for many of the same things that trees are >useful for, but they are different data structures with different >strengths and weaknesses, and different uses. To argue that we don't need >trees because we have dicts makes as much sense as arguing that we don't >need dicts because we have lists. The problem is that trees are like standards: there are so many to choose from. Each has its own tradeoffs, and because Python dicts and lists can substitute for many of the traditionals uses of trees, the tradeoffs are less clear. I think nobody would object to adding trees to the standard library, but it will certainly require a clear PEP, preferably with a pointer to an existing PyPI library that has acquired real-world use. (In particular, WRT the bisect module, although insertion and deletion are O(N), the constant factor for doing a simple memory move at C speed swamps bytecode until N gets very large -- and we already have collections.deque() for some other common use cases.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From udyantw at gmail.com Fri Jun 26 13:16:40 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 10:16:40 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation References: Message-ID: <3ecf9ea5-b7e4-4a2d-ad97-8e1faec2ace6@v23g2000pro.googlegroups.com> On Jun 26, 8:01?pm, Paul Moore wrote: > 2009/6/26 Udyant Wig : > > > > > > > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin > > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > > The code: > > #!/usr/bin/env python > > def remaining_peg (peg1, peg2): > > ? ? ? ?return (6 - peg1 - peg2) > > > def hanoi (num_discs, start, end): > > ? ? ? ?if (1 == num_discs): > > ? ? ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > > for Py 3.0.1 > > > ? ? ? ?else: > > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > > ? ? ? ? ? ? ? ?hanoi (1, start, end) > > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > > What happened to Python? > > I/O in Python 3.0 is known to be slow, because the bulk of the > implementation is in Python (rather than C). Python 3.1 addresses > this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the > print commented out, the second are with the print, redirected to the > null device. The tests are on a pretty slow Windows XP SP2 laptop. > > >timer & \Apps\Python26\python.exe hanoi.py & timer > > Timer 1 on: 15:54:53 > Timer 1 off: 15:54:57 ?Elapsed: 0:00:03.88 > > >timer & \Apps\Python31\python.exe hanoi.py & timer > > Timer 1 on: 15:57:05 > Timer 1 off: 15:57:09 ?Elapsed: 0:00:03.67 > > >timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer > > Timer 1 on: 15:57:44 > Timer 1 off: 15:58:14 ?Elapsed: 0:00:29.91 > > >timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer > > Timer 1 on: 15:58:38 > Timer 1 off: 15:59:09 ?Elapsed: 0:00:30.63 > > Nothing much in it. > > Paul. Thank you for clearing that up. From http Fri Jun 26 13:25:17 2009 From: http (Paul Rubin) Date: 26 Jun 2009 10:25:17 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <7x3a9mkiv6.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > (In particular, WRT the bisect module, although insertion and deletion > are O(N), the constant factor for doing a simple memory move at C speed > swamps bytecode until N gets very large -- and we already have > collections.deque() for some other common use cases.) Again, at least in my case, I'd hope for an immutable structure. Also, "N very large" is likely to mean no more than a few thousand, which is small by today's standards. And the C speed difference goes away completely if the tree implementation is also in C. Hedgehog Lisp has a good functional AVL tree implementation written in C, that I might try to wrap with the Python C API sometime. I think it is LGPL licensed though, not so good for the Python stdlib. From daniel at stutzbachenterprises.com Fri Jun 26 13:33:31 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 26 Jun 2009 12:33:31 -0500 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> Message-ID: On Fri, Jun 26, 2009 at 1:54 AM, Miles Kaufmann wrote: > On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote: > >> That's pretty much the bisect module in a nutshell. It manipulates a >> sorted list using binary search. >> > > With O(n) insertions and removals, though. A decent self-balancing binary > tree will generally do those in O(log n). FWIW, you can get O(log**2 n) inserts and deletes by using the bisect module on my blist extension type (http://pypi.python.org/pypi/blist/). It's a drop-in replacement for list(), with different asymptotic performance characteristics. Copying a blist is O(1), so the functional-programming types can wrap it in non-mutating semantics if they so choose. ;) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From trentm at activestate.com Fri Jun 26 13:40:12 2009 From: trentm at activestate.com (Trent Mick) Date: Fri, 26 Jun 2009 10:40:12 -0700 Subject: "The system cannot execute the specified program." In-Reply-To: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: <4A4507FC.9040105@activestate.com> Tim Slattery wrote: > Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." > > I should add that before I knew about our shared installation, I > downloaded the AS distribution of Python 2.6 from ActiveState. Their > install procedure is a *.bat file that calls Python to put everything > in the right place. When the bat file tries to invoke Python, I get > the same message. > I'm jumping in mid-thread here, so apologies if I've missed something. Just want to clarify something: the main AS distribution of Python (ActivePython) for Windows is an MSI. There is sometimes a .zip file with an install.bat -- but that isn't really intended for wide use. Is that what you are referring to here? Cheers, Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From backup95 at netcabo.pt Fri Jun 26 14:57:42 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 19:57:42 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A451A26.402@netcabo.pt> Aahz wrote: > In article <006078f0$0$9721$c3e8da3 at news.astraweb.com>, > Steven D'Aprano wrote: > >> Hash tables (dicts) are useful for many of the same things that trees are >> useful for, but they are different data structures with different >> strengths and weaknesses, and different uses. To argue that we don't need >> trees because we have dicts makes as much sense as arguing that we don't >> need dicts because we have lists. >> > > The problem is that trees are like standards: there are so many to choose > from. Each has its own tradeoffs, and because Python dicts and lists can > substitute for many of the traditionals uses of trees, the tradeoffs are > less clear. I think nobody would object to adding trees to the standard > library, but it will certainly require a clear PEP, preferably with a > pointer to an existing PyPI library that has acquired real-world use. > > > Wish I had asked this before this year's GSoC started. What's lacking is an associative array that preserves ordering, doesn't require a hash function and has fast insertions and deletions in O(log(n)). The particular algorithm to achieve this is a secondary issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault for having opened the topic with simply "trees" instead, it would have avoided this vagueness problem, but I'm genuinely surprised to know there are no data structures that efficiently support such a common need in Python. And I really enjoy the using this language. From ffernand.list at gmail.com Fri Jun 26 15:09:35 2009 From: ffernand.list at gmail.com (Filipe Fernandes) Date: Fri, 26 Jun 2009 15:09:35 -0400 Subject: alternative to JoinableQueue's please Message-ID: I'm currently using the multiprocessing package and I'm hugely impressed at its simplicity (thanks very much Jesse Noller). Although, it seems that there's a bug in JoinableQueue's which renders using it pointless over a regular Queue as per Issue 4660 http://bugs.python.org/issue4660 To re-iterate... task_done() which is to be called for each get() throws the exception: ValueError: task_done() called too many times every once in a while. The reasons for this are outlined by Brian in the issue above, but no confirmation has been provided. The reasons for using JoinableQueue I think are obvious. I want to block the main processing using queue.join() until the tasks that have been placed on the queue have been finished by the worker processes. I can't be the only one experiencing this (besides Brian)... are there others who ran into this? Are there work arounds (besides a home-brewed one) ? filipe From norseman at hughes.net Fri Jun 26 15:10:02 2009 From: norseman at hughes.net (norseman) Date: Fri, 26 Jun 2009 12:10:02 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: <4A451D0A.4030607@hughes.net> Scott David Daniels wrote: > norseman wrote: >> ... A note here: In reading the original posting I get symbols that >> are not >> familiar to me as alphabet. >> From the line in your original: >> Label(root, text='?????????').pack() >> I see text=' >> then an e with a goatee >> a capitol O with an accent symbol on top (') >> an a with a tail on the right >> a s with an accent on top >> an I do no not know what - maybe some sort of l with a >> slash through the middle >> a couple of z with accents on top >> a capitol C with an accent on top >> a n with a short bar on top > > Here's something to try in any future circumstances: > > Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > >>> import unicodedata as ud > >>> for ch in '?????????': > print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch))) > > > 281 119 ? LATIN SMALL LETTER E WITH OGONEK > 243 f3 ? LATIN SMALL LETTER O WITH ACUTE > 261 105 ? LATIN SMALL LETTER A WITH OGONEK > 347 15b ? LATIN SMALL LETTER S WITH ACUTE > 322 142 ? LATIN SMALL LETTER L WITH STROKE > 380 17c ? LATIN SMALL LETTER Z WITH DOT ABOVE > 378 17a ? LATIN SMALL LETTER Z WITH ACUTE > 263 107 ? LATIN SMALL LETTER C WITH ACUTE > 324 144 ? LATIN SMALL LETTER N WITH ACUTE > > --Scott David Daniels > Scott.Daniels at Acm.Org ============== Good thought, good idea, useful tool. BUT - compare your output to what I *see*. And I do not see any f3 anywhere except in the doc ref I copy/duped and in this file. I suspect the mail handlers all have some differences. I also suspect Window$ is still cooking it's outputs. It has a long history of saying one thing and doing another. I used to program exclusively in assembly. I know for a fact Window$ can and does lie. Little ones, not often, but like your f3. I don't have one. Not from the copy/paste of the original posting, not anywhere I have looked in reviewing possible cause/effect of the problem posted. I do have a C3 B3 byte pair after the 30 31 31 39 (0119) and before the 5C (\) that follows the 0119. MC shows it as a CAP-A with a tilde on top of it. Firefox shows it as a CAP-O with an accent on top. (Kids today call the Accent a single quote.) I do not know what Window$ program to guide you to for proper hex listings. I'm not even sure an accurate one exists. (No doubt someone will now list a few thousand of them. :) Maybe zipping and transferring the .zip will help - maybe not. I would like to know the results. Steve From walton.nathaniel at gmail.com Fri Jun 26 15:11:19 2009 From: walton.nathaniel at gmail.com (Nate) Date: Fri, 26 Jun 2009 12:11:19 -0700 (PDT) Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: <197ef967-cec7-4d5e-8dda-5ebb087b6d88@y6g2000prf.googlegroups.com> I ended up going with this: http://code.activestate.com/recipes/440554/ seems to feed me new lines of output atleast before the subprocess finishes, with some adjustment of the time delays. I'll guess I'll just be packing winpy into the installer. Or something. From stefan_ml at behnel.de Fri Jun 26 15:14:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 21:14:25 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4a451e11$0$30225$9b4e6d93@newsspool1.arcor-online.net> Jo?o Valverde wrote: > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). > [...] > I'm genuinely surprised to know > there are no data structures that efficiently support such a common need > in Python. That's because it's simply not that a common need (in the sense that there isn't a suitable alternative). I know that Trees have their use cases where they really shine, but in surprisingly many cases a dict, a set, a list or a combination of them will do just fine. And if you find a case where those just don't fit, you may need a database anyway. Stefan From aahz at pythoncraft.com Fri Jun 26 15:14:42 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 12:14:42 -0700 Subject: No trees in the stdlib? References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: In article , =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: > >What's lacking is an associative array that preserves ordering, doesn't >require a hash function and has fast insertions and deletions in >O(log(n)). The particular algorithm to achieve this is a secondary >issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault >for having opened the topic with simply "trees" instead, it would have >avoided this vagueness problem, but I'm genuinely surprised to know >there are no data structures that efficiently support such a common need >in Python. And I really enjoy the using this language. Why AVL/RBT instead of B*? It's not that simple.... Another problem is that unless the tree is coded in C, the constant factors are going to swamp algorithmic complexity for many use cases -- that in turn makes it more difficult to deploy a PyPI library for real-world testing. Anyway, I'm *not* trying to discourage you, just explain some of the roadblocks to acceptance that likely are why it hasn't already happened. If you're serious about pushing this through, you have two options: * Write the code and corresponding PEP yourself (which leads to the second option, anyway) * Lobby on the python-ideas mailing list -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From pavlovevidence at gmail.com Fri Jun 26 15:32:59 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 12:32:59 -0700 (PDT) Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Jun 26, 7:35?am, Hallvard B Furuseth wrote: > Stefan Behnel writes: > >Jo?o Valverde wrote: > >> Besides some interface glitches, like returning None > >> on delete if I recall correctly. > > > That's actually not /that/ uncommon. Operations that change an object are > > not (side-effect free) functions, so it's just purity if they do not have a > > return value. > > It's purity that they don't return the modified tree/dict/whatever. > They can still return the deleted element and remain pure. Correct, dict.pop does exactly this. Carl Banks From wong_powah at yahoo.ca Fri Jun 26 15:43:05 2009 From: wong_powah at yahoo.ca (powah) Date: Fri, 26 Jun 2009 12:43:05 -0700 (PDT) Subject: change the first character of the line to uppercase in a text file Message-ID: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> How to change the first character of the line to uppercase in a text file? e.g. input is: abc xyz Bd ef gH ij output should be: Abc xyz Bd ef GH ij From robert.kern at gmail.com Fri Jun 26 15:44:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Jun 2009 14:44:29 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-26 02:17, Ulrich Eckhardt wrote: > Robert Kern wrote: >> I wish people would stop representing decimal floating point arithmetic as >> "more accurate" than binary floating point arithmetic. > > Those that failed, learned. You only see those that haven't learnt yet. > > Dialog between two teachers: > T1: Oh those pupils, I told them hundred times! when will they learn? > T2: They did, but there's always new pupils. Unfortunately, I keep seeing people who claim to be old hands at floating point making these unlearned remarks. I have no issue with neophytes like the OP expecting different results and asking questions. It is those who answer them with an air of authority that need to take a greater responsibility for knowing what they are talking about. I lament the teachers, not the pupils. -- 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 kee at kagi.com Fri Jun 26 15:56:24 2009 From: kee at kagi.com (Kee Nethery) Date: Fri, 26 Jun 2009 12:56:24 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: First, thanks to everyone who responded. Figured I'd test all the suggestions and provide a response to the list. Here goes ... On Jun 25, 2009, at 7:38 PM, Nobody wrote: > Why do you need an ElementTree rather than an Element? XML(string) > returns > the root element, as if you had used et.parse(f).getroot(). You can > turn > this into an ElementTree with e.g. et.ElementTree(XML(string)). I tried this: et.ElementTree(XML(theXmlData)) and it did not work. I had to modify it to this to get it to work: et.ElementTree(et.XML(theXmlData)) >> formPostData = cgi.FieldStorage() >> theXmlData = formPostData['theXml'].value >> theXmlDataTree = >> et >> .parse >> (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) > > If you want to treat a string as a file, use StringIO. I tried this: import StringIO theXmlDataTree = et.parse(StringIO.StringIO(theXmlData)) orderXml = theXmlDataTree.findall('purchase') and it did work. StringIO converts the string into what looks like a file so parse can process it as a file. Cool. On Jun 25, 2009, at 7:47 PM, unayok wrote: > I'm not sure what you're expecting. It looks to me like things are > working okay: > > My test script: > > [snip] I agree your code works. When I tried: theXmlDataTree = et.fromstring(theXmlData) orderXml = theXmlDataTree.findall('purchase') When I modified mine to programmatically look inside using the "for element in theXmlDataTree" I was able to see the contents. The debugger I am using does not offer me a window into the ElementTree data and that was part of the problem. So yes, et.fromstring is working correctly. It helps to have someone show me the missing step needed to confirm the code works and the IDE does not. On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > I believe you are misunderstanding something. et.XML and > et.fromstring return Elements, whereas et.parse returns an > ElementTree. These are two different things; however, both of them > "contain all the XML". In fact, an ElementTree (which is returned by > et.parse) is just a container for the root Element (returned by > et.fromstring)--and it adds no important functionality to the root > Element as far as I can tell. Thank you for explaining the difference. I absolutely was misunderstanding this. > Given an Element (as returned by et.XML or et.fromstring) you can pass > it to the ElementTree constructor to get an ElementTree instance. The > following line should give you something you can "play with": > > theXmlDataTree = et.ElementTree(et.fromstring(theXmlData)) Yes this works. On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote: > If you want to parse a document from a file or file-like object, use > parse(). Three use cases, three functions. The fourth use case of > parsing a > document from a string does not have its own function, because it is > trivial to write > > tree = parse(BytesIO(some_byte_string)) :-) Trivial for someone familiar with the language. For a newbie like me, that step was non-obvious. > If what you meant is actually parsing from a byte string, this is > easily > done using BytesIO(), or StringIO() in Py2.x (x<6). Yes, thanks! Looks like BytesIO is a v.3.x enhancement. Looks like the StringIO does what I need since all I'm doing is pulling the unicode string into et.parse. Am guessing that either would work equally well. >> theXmlDataTree = > et > .parse > (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) > > This will not work because ET cannot parse from unicode strings > (unless > they only contain plain ASCII characters and you happen to be using > Python > 2.x). lxml can parse from unicode strings, but it requires that the > XML > must not have an encoding declaration (which would render it non > well-formed). This is convenient for parsing HTML, it's less > convenient for > XML usually. Right for my example, if the data is coming in as UTF-8 I believe I can do: theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding ='utf-8') Again, as a newbie, thanks to everyone who took the time to respond. Very helpful. Kee From Slattery_T at bls.gov Fri Jun 26 16:12:45 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 16:12:45 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: Trent Mick wrote: >Tim Slattery wrote: >> Tim Slattery wrote: >> >>> Our office has a copy of Python 3.0 installed on a network share >>> device. When I try to run it I get this message: "The system cannot >>> execute the specified program." >> >> I should add that before I knew about our shared installation, I >> downloaded the AS distribution of Python 2.6 from ActiveState. Their >> install procedure is a *.bat file that calls Python to put everything >> in the right place. When the bat file tries to invoke Python, I get >> the same message. >> > >I'm jumping in mid-thread here, so apologies if I've missed something. >Just want to clarify something: the main AS distribution of Python >(ActivePython) for Windows is an MSI. Given the way my machine here is locked down, I'm pretty sure I couldn't run the *.msi file. >There is sometimes a .zip file with an install.bat -- but that isn't >really intended for wide use. Is that what you are referring to here? That's what it is. They give you a choice of MSI or AS. The AS choice is a zip file that you unzip, then run the bat file on the top level. There's no indication that it's "not intended for wide use". -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From Slattery_T at bls.gov Fri Jun 26 16:14:25 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 16:14:25 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <2uaa45l8vefaac4evsji8nqifbm3bgleru@4ax.com> Duncan Booth wrote: >Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." >> >> When I googled that message, the links that came up had to do with >> missing DLLs. So I fired up Dependency Walker and found out that there >> were indeed DLLs that it needed that the OS couldn't find. So I >> supplied those DLLs. And it still gives the same message, even though >> Dependency Walker is now happy. >> >> Does anybody have a clue what might cause this amazingly uninformative >> message? > >Are you using Vista? No Vista involved. My machine is XP Pro. The server is some MS server OS, I'm not sure which one. >Alternatively for a non-Vista wild guess, could it be that Python 3.0 is >loading some libraries that use .Net and is therefore triggering the 'code >access security' which prevents the running of .Net applications from a >network share? I saw nothing that remotely resembled that message. -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From trentm at activestate.com Fri Jun 26 16:40:08 2009 From: trentm at activestate.com (Trent Mick) Date: Fri, 26 Jun 2009 13:40:08 -0700 Subject: "The system cannot execute the specified program." In-Reply-To: References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: <4A453228.1010705@activestate.com> Tim Slattery wrote: > That's what it is. They give you a choice of MSI or AS. The AS choice > is a zip file that you unzip, then run the bat file on the top level. > There's no indication that it's "not intended for wide use". Granted not much, other than it isn't listed in the main download tables: http://www.activestate.com/activepython/downloads/ and not discussed in the install notes: http://docs.activestate.com/activepython/2.6/installnotes.html Cheers, Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From emile at fenx.com Fri Jun 26 16:46:43 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Jun 2009 13:46:43 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On 6/26/2009 12:43 PM powah said... > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij How far have you gotten? Emile From tjreedy at udel.edu Fri Jun 26 16:47:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Jun 2009 16:47:05 -0400 Subject: "The system cannot execute the specified program." In-Reply-To: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: Tim Slattery wrote: > Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." Slightly OT, but do try to replace that with 3.1 as soon as you can. Significant improvements in certain areas. From clp2 at rebertia.com Fri Jun 26 16:51:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 13:51:36 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <50697b2c0906261351l182bf503kf308141a28739d25@mail.gmail.com> On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij We're not in the business of doing homework. Some hints though: `s.upper()` converts the string in variable `s` to all upper case (e.g. "aBcD".upper() --> "ABCD") `for line in afile:` iterates over each line in a file object. `afile` is the file object and `line` gets assigned each line in turn. `s[x]` gets you the (x+1)-th character in the string `s` (e.g. "abcd"[2] --> "c") And here are the docs on working with files: http://docs.python.org/library/functions.html#open http://docs.python.org/library/stdtypes.html#file-objects That should be enough to get you started. Cheers, Chris -- http://blog.rebertia.com From python.list at tim.thechases.com Fri Jun 26 16:59:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 26 Jun 2009 15:59:35 -0500 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <4A4536B7.6060407@tim.thechases.com> powah wrote: > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij While you're asking the Python list, I'd just use GNU sed: sed -i 's/./\U&/' myfile.txt I don't know if the "\U"=="make the replacement uppercase" is a GNU-sed specific thing, but it works here on my Debian box's version 4.1.5 when I tested it. -tkc From Scott.Daniels at Acm.Org Fri Jun 26 17:30:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 14:30:14 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: powah wrote: > How to change the first character of the line to uppercase in a text > file? Here is an English hint on the above: The "How ... file" above is a noun phrase, and is not a sentence, never mind a question. Putting a question mark after the noun phrase does not make that phrase a question. "Would someone explain to me how ...file?" would be a question albeit inappropriate here, since you showed no work. By the way, that strange sentence structure usually clues me in that it is you again, apparently someone who does homework by posting to the list before attempting to work it out alone. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Fri Jun 26 17:37:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 14:37:37 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: norseman wrote: > Scott David Daniels wrote: >> norseman wrote: >>> ... A note here: In reading the original posting I get ... >>> then an e with a goatee >> >> Here's something to try in any future circumstances: >> > Good thought, good idea, useful tool. > > BUT - compare your output to what I *see*. Have you considered font issues when printing? The best encoding will not show anything reasonable when printed with a font without the characters in question. I'm not saying I know its wrong, only that there is another issue to check. you might both swap outputs from the over-explict printing I used above. --Scott David Daniels Scott.Daniels at Acm.Org From python at rcn.com Fri Jun 26 17:44:16 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 14:44:16 -0700 (PDT) Subject: alternative to JoinableQueue's please References: Message-ID: [Filipe Fernandes] > The reasons for using JoinableQueue I think are obvious. ?I want to > block the main processing using queue.join() until the tasks that have > been placed on the queue have been finished by the worker processes. > > I can't be the only one experiencing this (besides Brian)... are there > others who ran into this? ?Are there work arounds (besides a > home-brewed one) ? Before Queue.task_done() and Queue.task_join() were added, other idioms were used. One technique is to use a second queue to track incomplete tasks. # adding work unfinished_tasks.put(None) q.put(task) # doing work t = q.get() f(t) unfinished_tasks.get() # waiting for unfinished tasks to complete while unfinished_tasks.qsize(): sleep(0.1) Raymond From charles at declareSub.com Fri Jun 26 17:46:51 2009 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 26 Jun 2009 17:46:51 -0400 Subject: Python simple web development In-Reply-To: <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> Message-ID: <43A85C9B-C1D8-44C5-9744-37488EA0CD3D@declareSub.com> Or you could try my approach and write your own web app. Charles Yeomans From fetchinson at googlemail.com Fri Jun 26 17:56:01 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 26 Jun 2009 14:56:01 -0700 Subject: Python simple web development In-Reply-To: <4A43C3DB.7080504@simplistix.co.uk> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> <4A43C3DB.7080504@simplistix.co.uk> Message-ID: >> What I've read about Django, Turbogears is that they are powerful >> enough to create big web-based portals, applications, etc. >> I need just simple forms without any sophisticated functionality. >> So again: why I am wrong ? > > Just because something is powerful doesn't mean you can't do simple > things with it. But complexity typically brings in an extra overhead that the OP might not need. I'm using turbogears for a project but for other simple things I don't, because the all the super powerful infrastructure of turbogears is just not necessary and slows things down without a reason. So I would recommend the OP against using either django or turbogears if the project is really small and will stay small in the future. This last point is hard to guess in advance though :) Cheers, Daniel > Have a read of the first few chapters of the Django book... > > http://www.djangobook.com/ -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From thomasmallen at gmail.com Fri Jun 26 18:08:03 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Fri, 26 Jun 2009 15:08:03 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: On Jun 25, 3:29?am, Private Private wrote: > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? I don't think anything's lighter than web.py. http://webpy.org/ Thomas From anishaapte at gmail.com Fri Jun 26 18:11:12 2009 From: anishaapte at gmail.com (jythonuser) Date: Fri, 26 Jun 2009 15:11:12 -0700 (PDT) Subject: Dynamic method invocation References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> <7acq2qF1u879sU1@mid.uni-berlin.de> Message-ID: <06cb50d2-57fb-4583-86b5-bb5704c5ab13@p23g2000vbl.googlegroups.com> Sorry for being a little vague. The last part of your response seems like what I would need. So here are more details on what I am trying to do. I have an extensible command shell in java where commmand providers plug in to supply new commands. I have a java class called MyShell which has execCommand method on it. Thus MyShell class does not have a concrete method on it for each command that it supports (e.g. grep, ls, cat etc) but a generic execCommand method that takes the name of the command and command params as arguments. clas MyShell () { Object execCommand (cmdName, params) { Object o = // find command object from command name return o.invoke (cmdName, params); } | Now I want to use this in jython. So I could do something like shell = MyShell() shell.exec ("grep", grep_args) What I would like to do is - shell.grep (grep_args) That way my users don't have to use some gorpy exec/invoke syntax for each command but think that shell has all the commands defined on it. So based on your example I am hoping that I can use getattr on "some" object that returns me "some" method that I can call. Does this make sense and is there a way to do this in jython? From anishaapte at gmail.com Fri Jun 26 18:16:01 2009 From: anishaapte at gmail.com (jythonuser) Date: Fri, 26 Jun 2009 15:16:01 -0700 (PDT) Subject: Dynamic method invocation References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> <7acq2qF1u879sU1@mid.uni-berlin.de> <06cb50d2-57fb-4583-86b5-bb5704c5ab13@p23g2000vbl.googlegroups.com> Message-ID: <68e7fe05-a44b-452e-be67-795c499577f5@n19g2000vba.googlegroups.com> Actually let me add that in jython I don't need to always use MyShell. It may be ok to wrapper it with some Jython class which then delegates to MyShell. So something like shell = MyJythonShell() shell.grep (grep_args) So MyJythonShell is defined in Jython which calls MyShell. Am wondering how to go about all this. From torriem at gmail.com Fri Jun 26 18:27:18 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 26 Jun 2009 16:27:18 -0600 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: <4A454B46.9030801@gmail.com> Robert Kern wrote: > In the former case, you can claim that decimal floating point is more accurate > *for those problems*. But as soon as you have a division operation, decimal > floating point has the same accuracy problems as binary floating point. True. Poor choice of words on my part. No matter what representation one chooses for numbers, we can remember that digits != precision. That's why significant digits were drilled into our heads in physics! That's the reason IEEE actually works out for most things that we need floating point for. From petr.messner at gmail.com Fri Jun 26 18:35:45 2009 From: petr.messner at gmail.com (Petr Messner) Date: Sat, 27 Jun 2009 00:35:45 +0200 Subject: Python simple web development In-Reply-To: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <67c97cd90906261535m6031ca4q943fca58a4518773@mail.gmail.com> What about Werkzeug? I like its simplicity (well, basically everything I need are WSGI request/response objects :) + some templating library). Petr 2009/6/25 Private Private : > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? From martin at v.loewis.de Fri Jun 26 18:40:18 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 27 Jun 2009 00:40:18 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: <4a454e52$0$5115$9b622d9e@news.freenet.de> > And I do not see any f3 anywhere except in the doc ref I copy/duped and > in this file. That surely is a bug in your email program - get a better one. Take a look at http://mail.python.org/pipermail/python-list/2009-June/717666.html which displays correctly - maybe you can find a web browser that works. Regards, Martin From python at rcn.com Fri Jun 26 19:14:14 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 16:14:14 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: <01c79050-7be5-4f9c-bfcd-5e5b0d63f16e@s1g2000prd.googlegroups.com> [Tom Reed] > Why no trees in the standard library, if not as a built in? The sqlite3 module is built on a binary-tree structure. It can be used with persistent data or kept in-memory. The gdbm module has similar flexibility (see the F mode). FWIW, there are some ASPN implementing various types of trees (red-black, pairing heaps, etc). Raymond From python at rcn.com Fri Jun 26 19:22:18 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 16:22:18 -0700 (PDT) Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: [Jo?o Valverde] > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). FWIW, Py3.1 has an OrderedDict() that preserves insertion order. It has O(1) lookup, deletion, insertion, and popping; and O(n) iteration. The ASPN Cookbook has equivalent code that runs on earlier versions of Python. > in Python. And I really enjoy the using this language. Am glad you like it. Raymond From piet at cs.uu.nl Fri Jun 26 19:28:35 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 01:28:35 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: >>>>> Sebastian Paj?k (SP) wrote: >SP> Maybe this picture will tell you more: >SP> http://files.getdropbox.com/u/1211593/tkinter.png >SP> The original script: >SP> http://files.getdropbox.com/u/1211593/test1.py >SP> May someone can confirm this osx behaviour? Yes, I get the same. But it is a problem of the underlying Tk implementation. I get the same strange behaviour in wish. Text widgets seem to have the same problem and it has to do with the use of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but this seems to cause other problems. See: http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862062 http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862807 -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From sjmachin at lexicon.net Fri Jun 26 19:52:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 26 Jun 2009 16:52:21 -0700 (PDT) Subject: MultiValueDict? References: <4d67805e-2eed-4745-9e02-85797330013b@l5g2000vbp.googlegroups.com> Message-ID: On Jun 27, 2:09?am, BarakatX2 wrote: > png)>, , > ]}> There is nothing in this schema to suggest that any object has a .name attribute . > > ? ? for f in files['rqFiles']: > ? ? ? ? print f.name > > This gives me an "'str' object has no attribute 'name'" error. I don't > know if there is a special way to access MultiValueDicts values, but I > assumed each key has a list that is accessed just like any other list. You might start by telling us what a MultiValueDict is -- it's not from the standard Python distribution AFAICT. Consider asking the source of MultiValueDicts. Consider reading any docs for the module or package that defines MultiValueDicts. Consider inspecting some of the objects: print files['rqFiles'] # given your error message, probably get sth like ['foo.png', 'bar.png', ...] print files From spconv+m at gmail.com Fri Jun 26 19:55:22 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Sat, 27 Jun 2009 01:55:22 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: <111013c20906261655o78611affxc68fd720e99e980a@mail.gmail.com> 2009/6/27 Piet van Oostrum : >>>>>> Sebastian Paj?k (SP) wrote: > >>SP> Maybe this picture will tell you more: >>SP> http://files.getdropbox.com/u/1211593/tkinter.png > >>SP> The original script: >>SP> http://files.getdropbox.com/u/1211593/test1.py > >>SP> May someone can confirm this osx behaviour? > > Yes, I get the same. But it is a problem of the underlying Tk > implementation. I get the same strange behaviour in wish. > > Text widgets seem to have the same problem and it has to do with the use > of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but > this seems to cause other problems. > Uhhh. good to know It should be written somewhere with BIG letters so people like me whouldn't be confused... Thanks Sebastian From davidh at ilm.com Fri Jun 26 20:09:53 2009 From: davidh at ilm.com (David Hirschfield) Date: Fri, 26 Jun 2009 17:09:53 -0700 Subject: Replacing a built-in method of a module object instance Message-ID: <4A456351.5050902@ilm.com> I have a need to replace one of the built-in methods of an arbitrary instance of a module in some python code I'm writing. Specifically, I want to replace the __getattribute__() method of the module I'm handed with my own __getattribute__() method which will do some special work on the attribute before letting the normal attribute lookup continue. I'm not sure how this would be done. I've looked at all the documentation on customizing classes and creating instance methods...but I think I'm missing something about how built-in methods are defined for built-in types, and where I'd have to replace it. I tried this naive approach, which doesn't work: m = def __getattribute__(self, attr): print "modified getattribute:",attr return object.__getattribute__(self, attr) import types m.__getattribute__ = types.MethodType(__getattribute__,m) It seems to create an appropriately named method on the module instance, but that method isn't called when doing any attribute lookups, so something's not right. Any ideas? Is this even possible? Thanks in advance! -David -- Presenting: mediocre nebula. From abuse at 127.0.0.1 Fri Jun 26 20:48:50 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 00:48:50 GMT Subject: looking for a book on python Message-ID: Hello and thank you for taking your time to read this. I was interested in learning about python. In the long ago past I did learn some programing but I have not used any of it for years. I do remember some basics however so the book does not have to be for a total beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) I have been using Linux for a while and overall still don't know much about it but I can find my way. I have my system dual boot with windows vista. I do realize that everyone is different but I would like to see some suggestions and maybe reasons why you think it is good. I have looked for/searched and found a few different books but as my means are a bit limited right now I don't really want to buy several just one or maybe two books. Oh and if someone knows a place to find some used books of this sort that would be great (ebay I guess :) Thanks for your thoughts Randy theslayers9 gmail From ffernand.list at gmail.com Fri Jun 26 21:19:58 2009 From: ffernand.list at gmail.com (Filipe Fernandes) Date: Fri, 26 Jun 2009 21:19:58 -0400 Subject: alternative to JoinableQueue's please In-Reply-To: References: Message-ID: <4A4573BE.9030704@gmail.com> Raymond Hettinger wrote: > [Filipe Fernandes] >> The reasons for using JoinableQueue I think are obvious. I want to >> block the main processing using queue.join() until the tasks that have >> been placed on the queue have been finished by the worker processes. >> >> I can't be the only one experiencing this (besides Brian)... are there >> others who ran into this? Are there work arounds (besides a >> home-brewed one) ? > > Before Queue.task_done() and Queue.task_join() were added, other > idioms were used. > > One technique is to use a second queue to track incomplete tasks. > > # adding work > unfinished_tasks.put(None) > q.put(task) > > > # doing work > t = q.get() > f(t) > unfinished_tasks.get() > > > # waiting for unfinished tasks to complete > while unfinished_tasks.qsize(): > sleep(0.1) Thanks Raymond... yours is by far is the simplest and should have been an obvious solution. I didn't want to stray too far from what I had and this fits the bill. In case others are curious... I had looked at using the example in http://docs.python.org/library/multiprocessing.html#using-a-remote-manager to use the traditional Queue from module Queue which includes the join and task_done method calls. But creating a server process/thread just for that is rather over-kill. I also looked at using process pools asynchronously and waiting for the iterators to come back to determine if jobs were completed. But your solution is the simplest to implement. And easy enough to create a composite class containing the two queues to simulate the real one (although I have not tried the following, I'm not in the office right now). class JoinableQueue(object): def __init__(*args, **kwargs): self.__tasks = Queue() self.__queue = Queue(*args, **kwargs) def put(self, *args, **kwargs): self.__tasks.put(None) self.__queue.put(*args, **kwargs) def get(self, *args, **kwargs): return self.__queue.get(*args, **kwargs) def task_done(): try: self.__tasks.get(False) except Queue.Empty: raise ValueError('task_done called too many times') def join(): while not self.__tasks.empty(): sleep(0.1) [Add methods to simulate as required....] filipe ps: Thanks Raymond for the quick reply... and I feel rather apologetic for having bothered the list with this :S From tkjthingone at gmail.com Fri Jun 26 21:22:09 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 26 Jun 2009 18:22:09 -0700 Subject: looking for a book on python In-Reply-To: References: Message-ID: Hello, http://diveintopython.org/ - might be a good place to start. There are also a bunch of free programming books (some related to python, some not) to be found here: http://www.e-booksdirectory.com/programming.php#python - How good these books may or may not be is up to you to find out. Also, some uni's/collegs have taken to posting videos of classes online, that you can watch for free. An example would be: http://webcast.berkeley.edu/ - Go to courses, and then 'select semester' (upper right) and start looking through. Some years have more programming classes than others. Not explicitly python, but programming is programming is programming or something like that. Should be enough to get you started :) On Fri, Jun 26, 2009 at 5:48 PM, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > I was interested in learning about python. In the long ago past I > did learn some programing but I have not used any of it for years. I do > remember some basics however so the book does not have to be for a total > beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) > I have been using Linux for a while and overall still don't know > much about it but I can find my way. I have my system dual boot with > windows vista. > I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe two > books. > Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 gmail > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Fri Jun 26 21:43:40 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 27 Jun 2009 13:43:40 +1200 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <7albocF1vlgm3U1@mid.individual.net> Jo?o Valverde wrote: > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). Careful here -- you can't get away from the need for hashability just by using a tree. Even if you don't need to actually hash the values, it's still important that the criterion for ordering between objects doesn't change while they're in the tree, otherwise they'll be in the wrong place and won't be found by subsequent lookups. > I'm genuinely surprised to know > there are no data structures that efficiently support such a common need > in Python. Is it really all that common? If it truly were common, there probably *would* be something for it in the stdlib by now. What sort of things are you doing that you want such a structure for? Maybe we can suggest a way of using the existing data structures to achieve the same goal. -- Greg From wong_powah at yahoo.ca Fri Jun 26 21:58:27 2009 From: wong_powah at yahoo.ca (powah) Date: Fri, 26 Jun 2009 18:58:27 -0700 (PDT) Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Jun 26, 4:51?pm, Chris Rebert wrote: > On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: > > How to change the first character of the line to uppercase in a text > > file? > > e.g. > > input is: > > abc xyz > > Bd ef > > gH ij > > > output should be: > > Abc xyz > > Bd ef > > GH ij > > We're not in the business of doing homework. Some hints though: > > `s.upper()` converts the string in variable `s` to all upper case > (e.g. "aBcD".upper() --> "ABCD") > `for line in afile:` iterates over each line in a file object. `afile` > is the file object and `line` gets assigned each line in turn. > `s[x]` gets you the (x+1)-th character in the string `s` (e.g. > "abcd"[2] --> "c") > > And here are the docs on working with files:http://docs.python.org/library/functions.html#openhttp://docs.python.org/library/stdtypes.html#file-objects > > That should be enough to get you started. > > Cheers, > Chris > --http://blog.rebertia.com Thank you for your hint. This is my solution: f = open('test', 'r') for line in f: print line[0].upper()+line[1:], From aahz at pythoncraft.com Fri Jun 26 22:02:29 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 19:02:29 -0700 Subject: looking for a book on python References: Message-ID: In article , Randy Foiles wrote: > > I do realize that everyone is different but I would like to see some >suggestions and maybe reasons why you think it is good. I have looked >for/searched and found a few different books but as my means are a bit >limited right now I don't really want to buy several just one or maybe >two books. You could get the book I co-wrote (Python for Dummies), but honestly, I think you should try using some of the online tutorials first. The standard Python tutorial is aimed at people with some programing experience: http://docs.python.org/tutorial/index.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From sato.photo at gmail.com Fri Jun 26 22:22:27 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Fri, 26 Jun 2009 19:22:27 -0700 (PDT) Subject: Beginning with Python; the right choice? Message-ID: Hi, As you can imagine, I am new, both to this group and to Python. I have read various posts on the best book to buy or online tutorial to read and have started to go through them. I was wondering, as someone with virtually no programming experience (I am a photographer by trade), is Python the right language for me to try and learn? I do vaguely remember learning what I think was BASIC on some old Apple's back in elementary school (circa 1992). Would something like that (the name at least makes it SOUND easier) be more feasible? If I do choose to learn Python, are there any tutorials for the absolute beginner. I do not mean beginner to Python, but rather, beginner to programming. Someone who hasn't a clue what object oriented whatcha-ma-whoozit means. I ask again because I understand that content is always evolving and there might be new tutorials out there. Thanks! -Daniel Sato From amosanderson at gmail.com Fri Jun 26 22:50:22 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Fri, 26 Jun 2009 21:50:22 -0500 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: In learning most programming languages, in my experience anyway, it's easy to get overwhelmed and want to give up. Python is easy enough that you should be able to pick it to a point that it will be useful to you while still learning the more advanced features. Python generally teaches good programming practices and I can see easily moving from Python to a more advanced language. BASIC is so far removed from modern languages that, IMO, it would make it difficult to transition to a modern language like C, C++ or Java. Python.org has a tutorial that should get you going. It seems to assume some programming knowledge but I think it's clear enough that even an absolute beginner could learn from it. http://docs.python.org/tutorial/index.html I learned C++ coming from Applesoft BASIC and Tandy Coco3 BASIC. I got a Sam's Teach Yourself book to do it. I really don't recommend that approach to anybody. It was very hard for me to understand the concepts necessary to make good use of C++. If I had only known about Python. On Fri, Jun 26, 2009 at 9:22 PM, sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Sat Jun 27 00:09:04 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Jun 2009 21:09:04 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On Jun 26, 9:22?pm, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? Yes, absolutely. > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? No, go with Python. You can still get BASIC today, but it is usually far different from what you saw on early Apples. If you have Excel, try doing some macro programming to get a feel for what BASIC is like. Excel's macro language is actually Visual Basic for Applications. I use it extensively, not because it's a wonderful language, but because I have things that need getting done in Excel, such as looking at the contents of a cell and deciding which of the Inhalation vs. Ingestion TACO standard has been exceeded and performing formatting accordingly. Nice to have that kind of power on your spreadsheet when you need it. But away from Excel, I drop Visual Basic like a live grenade. I do math research as a hobby and Excel even with VBA can't hold a candle to what I can do in Python. > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ? I've been using Python for 10 years and have never once done any object-oriented programming, so don't be intimidated by the fact that Python has it. You don't HAVE to use it. Sure, it would nice to learn it, but it need not stand in your way. > I ask again because I understand > that content is always evolving and there might be new tutorials out > there. I'm not up on what's available, tutorial-wise, but I'm sure others will point you in a decent direction. > > Thanks! > > -Daniel Sato From tkjthingone at gmail.com Sat Jun 27 00:10:11 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 26 Jun 2009 21:10:11 -0700 Subject: postgreSQL python bindings - which one? Message-ID: Hi, I'm having a hard time deciding which set of PGSQL python bindings to go with. I don't know much about SQL to begin with, so the collage of packages of somewhat daunting. I'm starting a pet project in order to teach my self more, but I want to avoid getting off on the wrong foot and picking a package that is not going to be actively updated in the future. There seem to be several implementations * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. * http://www.pygresql.org/ - version 4.0 was released beginning of this year, update before that was sometime in 06 ( http://www.pygresql.org/changelog.html ) * http://python.projects.postgresql.org/ - first release was this month? The last one of those three looks to be the most promising, but I just can't tell for sure. Your input is appreciated :) Small side note: Why PGSQL? I have a pre-existing database with good documentation that I want to use as my playground. The pre-existing database is also related to the pet project (in that it has information that I will need to get at in order for the pet project to be of much use). Thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sat Jun 27 00:56:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 01:56:11 -0300 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> <7a9bj5F1uhor1U1@mid.uni-berlin.de> <186cfa90-c309-4266-aae0-a89f9e49ef95@v4g2000vba.googlegroups.com> Message-ID: En Thu, 25 Jun 2009 06:15:57 -0300, luca72 escribi?: > Hello but find_library find only the lib. but if i need to load from a > list of lib how i have to do. > My proble is that i have 5 lib (a,b,c,d,e), if i load the a i get lib > b not found, if for first i load the b and than the a i get the same > error how i have to proceed. Try adding the parameter mode=ctypes.RTLD_GLOBAL when loading the library. -- Gabriel Genellina From backup95 at netcabo.pt Sat Jun 27 01:03:11 2009 From: backup95 at netcabo.pt (=?UTF-8?B?Sm/Do28gVmFsdmVyZGU=?=) Date: Sat, 27 Jun 2009 06:03:11 +0100 Subject: No trees in the stdlib? In-Reply-To: <7albocF1vlgm3U1@mid.individual.net> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> Message-ID: <4A45A80F.4090600@netcabo.pt> greg wrote: > Jo?o Valverde wrote: > >> What's lacking is an associative array that preserves ordering, >> doesn't require a hash function and has fast insertions and deletions >> in O(log(n)). > > Careful here -- you can't get away from the need for > hashability just by using a tree. Even if you don't > need to actually hash the values, it's still important > that the criterion for ordering between objects doesn't > change while they're in the tree, otherwise they'll > be in the wrong place and won't be found by subsequent > lookups. I'm aware :) Technically it's necessary to define a total ordering on the set of keys. > > > I'm genuinely surprised to know >> there are no data structures that efficiently support such a common >> need in Python. > > Is it really all that common? If it truly were common, > there probably *would* be something for it in the > stdlib by now. Obviously my experience differs, but those were my expectations. > > What sort of things are you doing that you want such > a structure for? Maybe we can suggest a way of using > the existing data structures to achieve the same > goal. > To answer the question of what I need the BSTs for, without getting into too many boring details it is to merge and sort IP blocklists, that is, large datasets of ranges in the form of (IP address, IP address, string). Originally I was also serializing them in a binary format (but no more after a redesign). I kept the "merge and sort" part as a helper script, but that is considerably simpler to implement. Please note that I'm happy with my code, it works well. I intended to implement it in C all along, even before trying Python. The python code was a side thing for testing/curiosity/fun. It prompted my original question but that was really about Python and the standard library itself, and I don't wish to waste anyone's time. As an anecdotal data point (honestly not trying to raise the "Python is slow" strawman), I implemented the same algorithm in C and Python, using pyavl. Round numbers were 4 mins vs 4 seconds, against Python (plus pyavl). Even considering I'm a worse Python programmer than C programmer, it's a lot. I know many will probably think I tried to do "C in Python" but that's not the case, at least I don' t think so. Anyway like I said, not really relevant to this discussion. From debatem1 at gmail.com Sat Jun 27 01:05:56 2009 From: debatem1 at gmail.com (CTO) Date: Fri, 26 Jun 2009 22:05:56 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: On Jun 26, 1:29?am, Tom Reed wrote: > Whynotrees in the standard library, if not as a built in? I searched > the archive but couldn't find a relevant discussion. Seems like a > glaring omission considering the batteries included philosophy, > particularly balanced binary search trees.Nointerest,nogood > implementations, something other reason? Seems like a good fit for the > collections module. Can anyone shed some light? > > Thanks. > -- > Tom I've written a graph library (trees being rooted connected acyclic graphs) called Graphine that you could try. Obviously not a part of the standard library, but it (or networkx) will almost certainly do what you're looking for. You can find graphine at graphine.org, or networkx at networkx.lanl.gov. Geremy Condra From backup95 at netcabo.pt Sat Jun 27 01:06:53 2009 From: backup95 at netcabo.pt (=?UTF-8?B?Sm/Do28gVmFsdmVyZGU=?=) Date: Sat, 27 Jun 2009 06:06:53 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45A80F.4090600@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> Message-ID: <4A45A8ED.9090103@netcabo.pt> Jo?o Valverde wrote: > greg wrote: >> Jo?o Valverde wrote: >> >>> What's lacking is an associative array that preserves ordering, >>> doesn't require a hash function and has fast insertions and >>> deletions in O(log(n)). >> >> Careful here -- you can't get away from the need for >> hashability just by using a tree. Even if you don't >> need to actually hash the values, it's still important >> that the criterion for ordering between objects doesn't >> change while they're in the tree, otherwise they'll >> be in the wrong place and won't be found by subsequent >> lookups. > > I'm aware :) Technically it's necessary to define a total ordering on > the set of keys. >> >> > I'm genuinely surprised to know >>> there are no data structures that efficiently support such a common >>> need in Python. >> >> Is it really all that common? If it truly were common, >> there probably *would* be something for it in the >> stdlib by now. > Obviously my experience differs, but those were my expectations. >> >> What sort of things are you doing that you want such >> a structure for? Maybe we can suggest a way of using >> the existing data structures to achieve the same >> goal. >> > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). Originally I was also serializing them in a binary > format (but no more after a redesign). I kept the "merge and sort" > part as a helper script, but that is considerably simpler to implement. Crap, this sentence is totally confusing. I meant kept the merge code as a helper script and moved the rest to C, see next paragraph. > Please note that I'm happy with my code, it works well. I intended to > implement it in C all along (for a system daemon), even before trying > Python. The python code was a side thing for testing/curiosity/fun. It > prompted my original question but that was really about Python and the > standard library itself, and I don't wish to waste anyone's time. > > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and Python, > using pyavl. Round numbers were 4 mins vs 4 seconds, against Python > (plus pyavl). Even considering I'm a worse Python programmer than C > programmer, it's a lot. I know many will probably think I tried to do > "C in Python" but that's not the case, at least I don' t think so. > Anyway like I said, not really relevant to this discussion. > From gagsl-py2 at yahoo.com.ar Sat Jun 27 01:18:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 02:18:32 -0300 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: En Wed, 24 Jun 2009 23:42:03 -0300, Carl Banks escribi?: > On Jun 24, 2:39?am, Norberto Lopes wrote: >> What do you think of dictionaries having a self lookup in their >> declaration? >> >> Be able to do this: >> >> a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax >> >> instead of: >> >> a = { "foo" : "foo1" } >> a["bar"] = a["foo"] > > If you don't mind abusing Python syntax, you can do it using something > like this: > > > def DictMaker(name,bases,dct): > dct.pop('__metaclass__',None) > return dct > > > class a: > __metaclass__ = DictMaker > > home = "/home/test" > user1 = home + "/user1" > user2 = home + "/user2" > python_dev = user1 + "/py-dev" Certainly an abuse of syntax, but it's a nice trick! -- Gabriel Genellina From tjreedy at udel.edu Sat Jun 27 01:39:14 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 01:39:14 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? I consider Python the Basic of the 21st century. From cmpython at gmail.com Sat Jun 27 01:41:28 2009 From: cmpython at gmail.com (Che M) Date: Fri, 26 Jun 2009 22:41:28 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On Jun 26, 10:22?pm, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ?I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato I was in your exact position (well, I wasn't a photographer) less than three years ago, and I started Python from no programming knowledge other than, just as you said, BASIC from long, long ago. I picked it up enough to do what I want to do and have been quite happy with it. I learned (my small subset of) it here and there over a year or so I guess, just as I felt like it, as it was purely for hobby (and I still learn new stuff of course). If you are hellbent on learning it and have good instructional material, you could learn a lot in a good month, really. My best advice is to get a couple of ultra-basic short tutorials read/viewed, and then identify *what it is you want to use Python to do*. Any language can be used to essentially anything, and I feel it is better to learn *per task* than to try to simply learn the whole language. You will feel better having accomplished something in line with your goals. In terms of good tutorials for absolute beginners, here are two: Alan Gauld's Learning to Program http://www.freenetpages.co.uk/hp/alan.gauld/ ShowMeDo.com has lots of Python instructional videos, including this one for absolute beginners: http://showmedo.com/videotutorials/series?name=irgGc9ChS I also recommend the Python tutor list, which you can sign up for here: http://mail.python.org/mailman/listinfo/tutor So what is it that you want to use Python for? Che From clp2 at rebertia.com Sat Jun 27 01:41:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 22:41:35 -0700 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> On Fri, Jun 26, 2009 at 10:39 PM, Terry Reedy wrote: > sato.photo at gmail.com wrote: >> >> Hi, >> >> As you can imagine, I am new, both to this group and to Python. ?I >> have read various posts on the best book to buy or online tutorial to >> read and have started to go through them. ?I was wondering, as someone >> with virtually no programming experience (I am a photographer by >> trade), is Python the right language for me to try and learn? >> >> I do vaguely remember learning what I think was BASIC on some old >> Apple's back in elementary school (circa 1992). ?Would something like >> that (the name at least makes it SOUND easier) be more feasible? > > I consider Python the Basic of the 21st century. I don't know whether that's an insult or a compliment... :P Cheers, Chris -- http://blog.rebertia.com From backup95 at netcabo.pt Sat Jun 27 01:42:21 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sat, 27 Jun 2009 06:42:21 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A45B13D.3000805@netcabo.pt> Aahz wrote: > In article , > =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: > >> What's lacking is an associative array that preserves ordering, doesn't >> require a hash function and has fast insertions and deletions in >> O(log(n)). The particular algorithm to achieve this is a secondary >> issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault >> for having opened the topic with simply "trees" instead, it would have >> avoided this vagueness problem, but I'm genuinely surprised to know >> there are no data structures that efficiently support such a common need >> in Python. And I really enjoy the using this language. >> > > Why AVL/RBT instead of B*? It's not that simple.... Another problem is > that unless the tree is coded in C, the constant factors are going to > swamp algorithmic complexity for many use cases -- that in turn makes it > more difficult to deploy a PyPI library for real-world testing. > I wouldn't consider anything other than C for such a module on efficiency alone, unless it was a prototype of course. But I have little knowledge about the Python C API. About B* trees, again not an expert but I don't see how the added complexity brings any noticeable advantage to implement the associative array data structure I mentioned. Simple is better. > Anyway, I'm *not* trying to discourage you, just explain some of the > roadblocks to acceptance that likely are why it hasn't already happened. > > If you're serious about pushing this through, you have two options: > > * Write the code and corresponding PEP yourself (which leads to the > second option, anyway) > > * Lobby on the python-ideas mailing list > Currently I don't have a strong need for this. I just believe it would be a benefit to a language I like a lot. Lobbying isn't my thing. I'd rather write code, but neither am I the most qualified person for the job. It would certainly be interesting and fun and challenging in a good way and a great way to learn some new stuff. But I would definitely need mentoring or asking some silly questions on the mailing list. Maybe I'll seriously consider it some other time. From stefan_ml at behnel.de Sat Jun 27 01:52:26 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Jun 2009 07:52:26 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4a45b39a$0$30228$9b4e6d93@newsspool1.arcor-online.net> Jo?o Valverde wrote: > I wouldn't consider anything other than C for such a module on > efficiency alone, unless it was a prototype of course. But I have little > knowledge about the Python C API. Cython is your true friend, if only for rapid prototyping. http://cython.org/ Stefan From __peter__ at web.de Sat Jun 27 01:52:38 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 07:52:38 +0200 Subject: Replacing a built-in method of a module object instance References: Message-ID: David Hirschfield wrote: > I have a need to replace one of the built-in methods of an arbitrary > instance of a module in some python code I'm writing. > > Specifically, I want to replace the __getattribute__() method of the > module I'm handed with my own __getattribute__() method which will do > some special work on the attribute before letting the normal attribute > lookup continue. > > I'm not sure how this would be done. I've looked at all the > documentation on customizing classes and creating instance methods...but > I think I'm missing something about how built-in methods are defined for > built-in types, and where I'd have to replace it. I tried this naive > approach, which doesn't work: > > m = > > def __getattribute__(self, attr): > print "modified getattribute:",attr > return object.__getattribute__(self, attr) > > import types > m.__getattribute__ = types.MethodType(__getattribute__,m) > > It seems to create an appropriately named method on the module instance, > but that method isn't called when doing any attribute lookups, so > something's not right. > Any ideas? Is this even possible? Special methods are looked up in the type, not the instance, and you cannot set attributes of the module type. As a workaround you can write a wrapper class and put that into the sys.modules module cache: >>> class Module(object): ... def __init__(self, module): ... self.__module = module ... def __getattr__(self, name): ... try: ... return getattr(self.__module, name.lower()) ... except AttributeError: ... def dummy(*args): pass ... return dummy ... >>> import shutil >>> import sys >>> sys.modules["shutil"] = Module(shutil) >>> import shutil >>> shutil.MOVE >>> shutil.yadda Peter From stefan_ml at behnel.de Sat Jun 27 02:06:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Jun 2009 08:06:01 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: <4a45b6c9$0$30231$9b4e6d93@newsspool1.arcor-online.net> Kee Nethery wrote: > On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote: >> parsing a >> document from a string does not have its own function, because it is >> trivial to write >> >> tree = parse(BytesIO(some_byte_string)) > > :-) Trivial for someone familiar with the language. For a newbie like > me, that step was non-obvious. I actually meant the code complexity, not the fact that you need to know BytesIO to do the above. >> If what you meant is actually parsing from a byte string, this is easily >> done using BytesIO(), or StringIO() in Py2.x (x<6). > > Yes, thanks! Looks like BytesIO is a v.3.x enhancement. It should be available in 2.6 AFAIR, simply as an alias for StringIO. > Looks like the > StringIO does what I need since all I'm doing is pulling the unicode > string into et.parse. As I said, this won't work, unless you are either a) passing a unicode string with plain ASCII characters in Py2.x or b) confusing UTF-8 and Unicode >>> theXmlDataTree = >> et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) >> >> This will not work because ET cannot parse from unicode strings (unless >> they only contain plain ASCII characters and you happen to be using >> Python >> 2.x). lxml can parse from unicode strings, but it requires that the XML >> must not have an encoding declaration (which would render it non >> well-formed). This is convenient for parsing HTML, it's less >> convenient for XML usually. > > Right for my example, if the data is coming in as UTF-8 I believe I can do: > theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding > ='utf-8') Yes, although in this case you are not parsing a unicode string but a UTF-8 encoded byte string. Plus, passing 'UTF-8' as encoding to the parser is redundant, as it is the default for XML. Stefan From laplacian42 at gmail.com Sat Jun 27 02:25:55 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:25:55 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: On Jun 26, 6:08?pm, Thomas Allen wrote: > On Jun 25, 3:29?am, Private Private wrote: > > > > Can you suggest anything ? > > I don't think anything's lighter than web.py. > > http://webpy.org/ > My impression is that webpy is intended for experienced users who might otherwise just write all their own code, but who might as well use webpy instead because it's there. It's tutorial is very brief, and (if memory serves) webpy didn't even have any docs at all for a while. As Thomas suggests, maybe have a look at Werkzeug http://werkzeug.pocoo.org/ . They've got substantial docs (which look quite good) and even a nifty screencast. From gagsl-py2 at yahoo.com.ar Sat Jun 27 02:32:12 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 03:32:12 -0300 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: En Thu, 25 Jun 2009 14:07:19 -0300, Angus Rodgers escribi?: > On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently: > >> [...] does the new feature, >> by which a file becomes iterable, operate by some kind of coercion >> of a file object to a list object, via something like x.readlines()? > > Sorry to follow up my own post yet again (amongst my weapons is > a fanatical attention to detail when it's too late!), but I had > better rephrase that question: > > Scratch "list object", and replace it with something like: "some > kind of iterator object, that is at least already implicit in 2.1 > (although the term 'iterator' isn't mentioned in the index to the > 2nd edition of Beazley's book)". Something like that! 8-P Iterators were added in Python 2.2. An iterator is an object that can be iterated over; that is, an object for which "for item in some_iterator: ..." works. Files are their own iterators, yielding one line at a time. See PEP 234 http://www.python.org/dev/peps/pep-0234/ -- Gabriel Genellina From laplacian42 at gmail.com Sat Jun 27 02:38:23 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:38:23 -0700 (PDT) Subject: looking for a book on python References: Message-ID: On Jun 26, 8:48?pm, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > ? ? ? ? I was interested in learning about python. ?In the long ago past I did > learn some programing but I have not used any of it for years. ?I do > remember some basics however so the book does not have to be for a total > beginner. ?(C, C++, BASIC, Visual BASIC, Pascal and some ADA) > ? ? ? ? I have been using Linux for a while and overall still don't know much > about it but I can find my way. ?I have my system dual boot with windows > vista. > ? ? ? ? I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. ?I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe > two books. > ? ? ? ? Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 ? gmail The Oreilly "Python in a Nutshell" (2006, 2nd ed.) book is very good and will get you up to speed in short order. From backup95 at netcabo.pt Sat Jun 27 02:41:39 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sat, 27 Jun 2009 07:41:39 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45B13D.3000805@netcabo.pt> References: <006078f0$0$9721$c3e8da3@news.astraweb.com> <4A45B13D.3000805@netcabo.pt> Message-ID: <4A45BF23.9080609@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: >> Anyway, I'm *not* trying to discourage you, just explain some of the >> roadblocks to acceptance that likely are why it hasn't already happened. >> >> If you're serious about pushing this through, you have two options: >> >> * Write the code and corresponding PEP yourself (which leads to the >> second option, anyway) >> >> * Lobby on the python-ideas mailing list >> > > Currently I don't have a strong need for this. I just believe it would > be a benefit to a language I like a lot. Lobbying isn't my thing. I'd > rather write code, but neither am I the most qualified person for the > job. It would certainly be interesting and fun and challenging in a > good way and a great way to learn some new stuff. But I would > definitely need mentoring or asking some silly questions on the > mailing list. Maybe I'll seriously consider it some other time. There's also another issue raise by Paul Rubin I wasn't even aware of, that the LGPL is not suitable for the standard library. Having to write a complete BST implementation in C is a drag. There are already good C libraries available. From laplacian42 at gmail.com Sat Jun 27 02:47:05 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:47:05 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> On Jun 27, 2:25?am, "laplacia... at gmail.com" wrote: > > As Thomas suggests, maybe have a look at Werkzeug ... Typo: s/Thomas/Petr/ From gagsl-py2 at yahoo.com.ar Sat Jun 27 03:08:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 04:08:13 -0300 Subject: os.walk and os.listdir problems python 3.0+ References: Message-ID: En Thu, 25 Jun 2009 11:15:15 -0300, Amos Anderson escribi?: > Thank you. That works very well when writing to a text file but what is > the > equivalent when writing the information to stdout using print? See this recent post: http://comments.gmane.org/gmane.comp.python.general/627850 -- Gabriel Genellina From virtualbuddha at gmail.com Sat Jun 27 03:28:39 2009 From: virtualbuddha at gmail.com (Virtual Buddha) Date: Sat, 27 Jun 2009 00:28:39 -0700 (PDT) Subject: Regular Expression Non Capturing Grouping Does Not Work. Message-ID: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Hello all, I am having some difficulties with the non-capturing grouping in python regular expression module. Even the code from the online documentation (http://docs.python.org/ howto/regex.html#non-capturing-and-named-groups) does not seem to work. As per the docs given in the link above this should happen (text copied from the page): >>> m = re.match("([abc])+", "abc") >>> m.groups() ('c',) >>> m = re.match("(?:[abc])+", "abc") >>> m.groups() () BUT, this is what I get: >>> m = re.match("([abc])+", "abc") >>> m.group() 'abc' >>> m = re.match("(?:[abc])+", "abc") >>> m.group() 'abc' I am using python 2.6 on opensuse 11.1. Any one know what I might be doing wrong? Or is this a bug? Thank you VB From __peter__ at web.de Sat Jun 27 03:45:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 09:45:47 +0200 Subject: Regular Expression Non Capturing Grouping Does Not Work. References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: Virtual Buddha wrote: > Hello all, > > I am having some difficulties with the non-capturing grouping in > python regular expression module. > > Even the code from the online documentation (http://docs.python.org/ > howto/regex.html#non-capturing-and-named-groups) does not seem to > work. > > As per the docs given in the link above this should happen (text > copied from the page): > >>>> m = re.match("([abc])+", "abc") >>>> m.groups() > ('c',) >>>> m = re.match("(?:[abc])+", "abc") >>>> m.groups() > () > > BUT, this is what I get: > >>>> m = re.match("([abc])+", "abc") >>>> m.group() > 'abc' >>>> m = re.match("(?:[abc])+", "abc") >>>> m.group() > 'abc' > > I am using python 2.6 on opensuse 11.1. Any one know what I might be > doing wrong? Or is this a bug? group != groups match.group() or match.group(0) gives you a special group that comprises the whole match. Regular capturing groups start at index 1, and only those are returned by match.groups(): >> re.match("(?:[abc])+", "abc").group() # one group 'abc' >>> re.match("(?:[abc])+", "abc").groups() # all capturing groups () Peter From milesck at umich.edu Sat Jun 27 03:46:01 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 27 Jun 2009 03:46:01 -0400 Subject: Regular Expression Non Capturing Grouping Does Not Work. In-Reply-To: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: <7CFA84EB-FF01-4ABF-ABC7-77FA0677DFC1@umich.edu> On Jun 27, 2009, at 3:28 AM, Virtual Buddha wrote: > Hello all, > > I am having some difficulties with the non-capturing grouping in > python regular expression module. > > Even the code from the online documentation (http://docs.python.org/ > howto/regex.html#non-capturing-and-named-groups) does not seem to > work. > > ... Notice that you are calling .group() on the match object instead of .groups(). Without any arguments, .group() is equivalent to .group(0), which means "return the entire matching string." http://docs.python.org/library/re.html#re.MatchObject.group -Miles From tjreedy at udel.edu Sat Jun 27 03:57:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 03:57:30 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> References: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Jun 26, 2009 at 10:39 PM, Terry Reedy wrote: >> sato.photo at gmail.com wrote: >>> Hi, >>> >>> As you can imagine, I am new, both to this group and to Python. I >>> have read various posts on the best book to buy or online tutorial to >>> read and have started to go through them. I was wondering, as someone >>> with virtually no programming experience (I am a photographer by >>> trade), is Python the right language for me to try and learn? >>> >>> I do vaguely remember learning what I think was BASIC on some old >>> Apple's back in elementary school (circa 1992). Would something like >>> that (the name at least makes it SOUND easier) be more feasible? >> I consider Python the Basic of the 21st century. > > I don't know whether that's an insult or a compliment... :P At one time, Basic was the language that everyone learned, at least amateurs and beginners of the time. It was an important part of the microcomputer revolution. It made beginning programming available to anyone, in spite of its faults. From mail at microcorp.co.za Sat Jun 27 03:58:21 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 27 Jun 2009 09:58:21 +0200 Subject: Beginning with Python; the right choice? References: Message-ID: <00ac01c9f6fd$9f0da480$0d00a8c0@Hendrik> "Terry Reedy" wrote: > I consider Python the Basic of the 21st century. Oh Dear. Was it not Dijkstra who said that learning basic rotted your brain, or words more or less to that effect? And here I am, feeling rather dull lately... :-) To the OP: - Learning Python will get you going, and productive in the sense of actually making programmes that do simple stuff with files on disk, and so on, faster than anything else I know of. And the beauty of it is that no matter how far, and in which direction, you want to go, there is a pythonic way to do it. So none of your effort put in to learn some python thing is wasted - you can literally start small and build up at your own pace. And when you get stuck, you can come here or to the tutor list, and you will get friendly help. - Hendrik From Olivier.Darge at gmail.com Sat Jun 27 04:16:06 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 27 Jun 2009 01:16:06 -0700 (PDT) Subject: looking for a book on python References: Message-ID: On 27 juin, 02:48, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > ? ? ? ? I was interested in learning about python. ?In the long ago past I did > learn some programing but I have not used any of it for years. ?I do > remember some basics however so the book does not have to be for a total > beginner. ?(C, C++, BASIC, Visual BASIC, Pascal and some ADA) > ? ? ? ? I have been using Linux for a while and overall still don't know much > about it but I can find my way. ?I have my system dual boot with windows > vista. > ? ? ? ? I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. ?I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe > two books. > ? ? ? ? Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 ? gmail "Learning Python" http://oreilly.com/catalog/9780596513986/ new issue soon, covering 2.6 and 3 http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c the best book I read concerning Py understanding, well written. I would start with web content, then later would buy the fourth edition of "Learning Python". enjoy, Olivier From virtualbuddha at gmail.com Sat Jun 27 04:16:59 2009 From: virtualbuddha at gmail.com (Virtual Buddha) Date: Sat, 27 Jun 2009 01:16:59 -0700 (PDT) Subject: Regular Expression Non Capturing Grouping Does Not Work. References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: <63f2fd74-e7a1-401e-ac83-cff70192efdb@g23g2000vbr.googlegroups.com> > group != groups > > match.group() or match.group(0) gives you a special group that comprises the > whole match. Regular capturing groups start at index 1, and only those are > returned by match.groups(): > > >> re.match("(?:[abc])+", "abc").group() # one group > 'abc' > >>> re.match("(?:[abc])+", "abc").groups() # all capturing groups > > () > > Peter Aaargh! Should have caught that myself. Sorry for wasting all your time. Thank you Peter and Miles! (I am off to bed now. 4:10 am :) From gagsl-py2 at yahoo.com.ar Sat Jun 27 04:31:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 05:31:24 -0300 Subject: YASS (Yet Another Success Story) References: <534f19f6-181c-42ee-803c-9bd867b6d053@n4g2000vba.googlegroups.com> Message-ID: En Sat, 20 Jun 2009 07:58:02 -0300, k3xji escribi?: > Started a project year ago with hard goals in mind : Developing a game > server which can handle thousands of clients simultaneously. [...] > I don't know Python at the time and only coded few simple projects > with it. And you still could write the server - that's very good (and shows your own great skills and Python ease of use...) > After profiling the code, it turns out most of the time is spent on > the following: > [...] 3) Redundant try-except's in all over place(Again our fault to make > the system stable, we have put some debug purposed-assert like try- > excepts in the main server flow.) I don't think this should make a difference. Setting up a try/except block usually has a very small cost (if no exception is actually raised). Care to tell us more details? > Just one note > about optimizing Python code: do not optimize Python code based on > your assumptions, just go and test if it really runs faster. I don't > want to go to details of this hint, but believe me making Python code > optimized may be very very tricky. Yes, specially if you came from a statically typed language; what looks "innocent" may have a significant cost (e.g. resolving obj.name), and what looks complicated may be fairly fast (e.g. a list comprehension). > It is then I decided to write up here this as a success story, as I am > very newcomer to Python but come up with a nearly commercial product > in a very short period of time and I don't think this is about my > personal characteristics and intelligence or so:), as I am old enough > to know/meet that there are much much more brilliant people than I am > and they also have similar experiences with Python. Thanks for sharing your experience! > So, one last note: every software project goes same tasks as above > often much much more officially and carefully, I would suggest > managers to see that just do not listen to the ordinary brain-washes. > Python is a great choice for easy developing, easy debugging, easy > maintaining and most importantly very very time-friendly. Of course > there will be tasks .n which Python is suitable, but hey, if it Python > is in the list, take it seriously. Nice summary! -- Gabriel Genellina From Olivier.Darge at gmail.com Sat Jun 27 04:32:55 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 27 Jun 2009 01:32:55 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On 27 juin, 04:22, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ?I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato hi, what is for you the purpose of learning programming ? what do you want to do ? at first glance, I think Python is a good choice for you, for its clarity. Olivier From Joachim at Strombergson.com Sat Jun 27 04:54:41 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Sat, 27 Jun 2009 10:54:41 +0200 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <4A45DE51.7000907@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! Che M wrote: > In terms of good tutorials for absolute beginners, here are two: > > Alan Gauld's Learning to Program > http://www.freenetpages.co.uk/hp/alan.gauld/ ... Also, don't miss the great Dive into Python: http://diveintopython.org/ A well written, easy to understand and fun (yes) introduction to all fantastic things in Python. - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpF3lEACgkQZoPr8HT30QG+jQCgq5ZpTS8ErLA9/YKIPBdJSNGp F80AoKBZHSCDfzPawcECKsYiIKbmLA5G =ML8w -----END PGP SIGNATURE----- From twirlip at bigfoot.com Sat Jun 27 05:03:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 10:03:43 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Sat, 27 Jun 2009 03:32:12 -0300, "Gabriel Genellina" wrote: >Iterators were added in Python 2.2. Just my luck. :-) >See PEP 234 http://www.python.org/dev/peps/pep-0234/ You've got to love a language whose documentation contains sentences beginning like this: "Among its chief virtues are the following four -- no, five -- no, six -- points: [...]" -- Angus Rodgers From ldo at geek-central.gen.new_zealand Sat Jun 27 05:27:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Jun 2009 21:27:07 +1200 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: In message <1co94553odu2d0dfnn89fdkgbsvo5dv3br at 4ax.com>, Tim Slattery wrote: > When I googled that message, the links that came up had to do with > missing DLLs. Ironic, isn't it, that Microsoft designs these messages to be non-technical to avoid putting off ordinary users, and yet it just ends up blanding them to the point of unintelligibility, so that you need to resort to Google to figure out what they mean. From Iris-und-Thomas-Lehmann at T-Online.de Sat Jun 27 05:47:48 2009 From: Iris-und-Thomas-Lehmann at T-Online.de (Thomas Lehmann) Date: Sat, 27 Jun 2009 02:47:48 -0700 (PDT) Subject: Fast Dictionary Access Message-ID: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only. if data.has_key(key): value = data[key] But this does mean (does it?) that the dictionary is searched two times! If so, can somebody show me how to do this in one step? From peter.mosley at talk21.com Sat Jun 27 05:52:44 2009 From: peter.mosley at talk21.com (peter) Date: Sat, 27 Jun 2009 02:52:44 -0700 (PDT) Subject: Python Imaging Library download link broken? Message-ID: Just got a new computer and I'm trying to download my favourite applications. All's well until I get to PIL, and here pythonware and effbot both return a 502 Proxy error. Is this just a temporary glitch, or something more serious? And if it's the latter, is there any alternative source? Peter From clp2 at rebertia.com Sat Jun 27 05:53:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Jun 2009 02:53:40 -0700 Subject: Fast Dictionary Access In-Reply-To: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <50697b2c0906270253t6a5dd942l3343b92ba86ac138@mail.gmail.com> On Sat, Jun 27, 2009 at 2:47 AM, Thomas Lehmann wrote: > Hi! > > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if ?data.has_key(key): > ? value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? Use exception handling: try: value = data[key] except KeyError: print "No such key" else: print "The value for that key is", value Cheers, Chris -- http://blog.rebertia.com From sato.photo at gmail.com Sat Jun 27 05:57:56 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Sat, 27 Jun 2009 02:57:56 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: Thank you for all of the links and advice. What do I want to learn Python for? Again, pardon me for my lack of relevant information. I am also a journalist (an out of work one at the moment, like so many others) and I feel that learning python could be useful for computer assisted reporting, that is, utilizing databases, creating interactive maps and the like. http://chicago.everyblock.com/crime/ I also am fond of the Ellington Content Management System, made using django, which, if I am not mistaken, is related to Python...in...some...way..lol. I'll figure it out? Any additional advice now that you know what I want to learn and why would be greatly appreciated. Oh and, if you need a photographer, www.danielsato.com! thanks again! -daniel From http Sat Jun 27 05:58:21 2009 From: http (Paul Rubin) Date: 27 Jun 2009 02:58:21 -0700 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7x63eigfr6.fsf@ruckus.brouhaha.com> Thomas Lehmann writes: > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? value = data.get(key, None) sets value to None if the key is not in the dictionary. You can use some other sentinel if None might actually be a value in the dictionary. One way to get a unique sentinel is: sentinel = object() You can also use exception handling (this is quite efficient in Python) as Chris Rebert mentioned. From twirlip at bigfoot.com Sat Jun 27 06:21:32 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:21:32 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah wrote: >On Jun 26, 4:51?pm, Chris Rebert wrote: >> On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: >> > How to change the first character of the line to uppercase in a text >> > file? >> > [...] >> >> We're not in the business of doing homework. Some hints though: >> >> `s.upper()` converts the string in variable `s` to all upper case >> (e.g. "aBcD".upper() --> "ABCD") >> `for line in afile:` iterates over each line in a file object. >> [...] >> >> And here are the docs on working with files: >> http://docs.python.org/library/functions.html#open >> http://docs.python.org/library/stdtypes.html#file-objects >> >> That should be enough to get you started. > >Thank you for your hint. >This is my solution: >f = open('test', 'r') >for line in f: > print line[0].upper()+line[1:], I know this is homework, so I didn't want to say anything (especially as I'm a newcomer, also just starting to learn the language), but it seems OK to mention that if you hunt around some more in the standard library documentation, you'll find an even shorter way to write this. -- Angus Rodgers From twirlip at bigfoot.com Sat Jun 27 06:39:28 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:39:28 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah wrote: >Thank you for your hint. >This is my solution: >f = open('test', 'r') >for line in f: > print line[0].upper()+line[1:], Will your program handle empty lines of input correctly? -- Angus Rodgers From albert at spenarnc.xs4all.nl Sat Jun 27 06:48:03 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 10:48:03 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: In article <0244e76b$0$20638$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >Nathan Stoddard wrote: > >> The best way to become a good programmer is to program. Write a lot of >> code; work on some large projects. This will improve your skill more than >> anything else. > >I think there are about 100 million VB code-monkeys who prove that theory >wrong. > >Seriously, and without denigrating any specific language, you can program by >(almost) mindlessly following a fixed number of recipes and patterns. This >will get the job done, but it won't make you a good programmer. For programming practice I do the problems of http://projecteuler.net/ I'm on the Eulerians page (best performers on 25 last problems). There is not a single VB programmer in the top 100. (Lots of Python programmers, C-family, also Haskel, APL, LISP Algol, Forth, Perl and I repeat not a single VB programmer.) Currently the top place is a Python programmer. These programs may be very demanding, minutes on very fast systems. Bad algorithms take days, weeks or literally forever. Interestingly the factor 5 between Python and C is irrelevant compared to a good algorithm, apparently. >-- >Steven 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 twirlip at bigfoot.com Sat Jun 27 06:54:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:54:43 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah > wrote: > >>Thank you for your hint. >>This is my solution: >>f = open('test', 'r') >>for line in f: >> print line[0].upper()+line[1:], > >Will your program handle empty lines of input correctly? Strangely enough, it seems to do so, but why? -- Angus Rodgers From albert at spenarnc.xs4all.nl Sat Jun 27 06:58:13 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 10:58:13 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: In article <0050ecf7$0$9684$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: > >> I think I'm paraphrasing Richard Feynman here, but the >> only way to truly understand something is to do it. > >An amazingly inappropriate quote for a *theoretical* physicist to have said. The remark of Feynman goes to the heart of science and mathematics. (Try understanding some number theory or string theory by just reading about it.) > >Whether Feynman did or didn't say that, it's clearly untrue: many people do >without understanding. Many people can cook, some people are expert cooks, This is even a classical lack of logic skills. Feynman says a->b, and you attack b->a. >-- >Steven > 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 albert at spenarnc.xs4all.nl Sat Jun 27 07:02:09 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 11:02:09 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In article <7xocssvzrh.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >koranthala writes: >> Which are the classic books in computer science which one should >> peruse? >> I have (a) Code Complete (b) GOF (c) Art of programming. >> >> Art of programming was too tough for me - and I couldnt understand >> much. The other two were good books - I understood and implemented >> quite a bit from both. >> What are the other books which I should peruse? > >Code Complete and GOF are software engineering books but not really >CS books. TAOCP is a CS book but a bit old fashioned. Other classics: > >Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, >Ronald L. Rivest, and Clifford Stein. Thanks. I lost that title a while ago, must buy. Also "Numerical Recipe's in FORTRAN/Pascal/C" (Have they done Python yet?) > >Structure and Interpretation of Computer Programs by Harold Abelson >and Gerald Jay Sussman (online at mitpress.mit.edu/sicp) 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 __peter__ at web.de Sat Jun 27 07:02:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:02:47 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Angus Rodgers wrote: > On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: > >>On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >> wrote: >> >>>Thank you for your hint. >>>This is my solution: >>>f = open('test', 'r') >>>for line in f: >>> print line[0].upper()+line[1:], >> >>Will your program handle empty lines of input correctly? > > Strangely enough, it seems to do so, but why? Because there aren't any. When you read lines from a file there will always be at least the newline character. Otherwise it would indeed fail: >>> for line in "peter\npaul\n\nmary".splitlines(): ... print line[0].upper() + line[1:] ... Peter Paul Traceback (most recent call last): File "", line 2, in IndexError: string index out of range From twirlip at bigfoot.com Sat Jun 27 07:13:57 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:13:57 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten <__peter__ at web.de> wrote: >Angus Rodgers wrote: > >> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >> >>>Will your program handle empty lines of input correctly? >> >> Strangely enough, it seems to do so, but why? > >Because there aren't any. When you read lines from a file there will always >be at least the newline character. Otherwise it would indeed fail: > >>>> for line in "peter\npaul\n\nmary".splitlines(): >... print line[0].upper() + line[1:] >... >Peter >Paul >Traceback (most recent call last): > File "", line 2, in >IndexError: string index out of range Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be treated as a single character. -- Angus Rodgers From twirlip at bigfoot.com Sat Jun 27 07:16:34 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:16:34 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: <5qvb45l9nmhgtkij7j2p7lc2lcsjjf1hf2@4ax.com> On Sat, 27 Jun 2009 12:13:57 +0100, I wrote: >the \r\n sequence at the end of a Win/DOS file Of course, I meant the end of a line of text, not the end of the file. (I promise I'll try to learn to proofread my posts. This is getting embarrassing!) -- Angus Rodgers From sanal.vikram at gmail.com Sat Jun 27 07:18:58 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sat, 27 Jun 2009 04:18:58 -0700 (PDT) Subject: to use unicode strings only Message-ID: Hey gentlemen, I wanna make all the strings in my code unicode strings. How to do it without giving unicode switch 'u' before every string? From jure.erznoznik at gmail.com Sat Jun 27 07:33:25 2009 From: jure.erznoznik at gmail.com (=?UTF-8?Q?Jure_Erzno=C5=BEnik?=) Date: Sat, 27 Jun 2009 04:33:25 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: Norberto, While certainly useful, this kind of functionality contradicts the way today's "string" libraries work. What you are proposing isn't dict self referencing, but rather strings referencing other external data (in this case other strings from the same dict). When you write code like config = {"home" : "/home/test"} config["user1"] = config["home"] + "/user1" config["user1"] isn't stored in memory as config["home"] + "/user1", but as a concatenated string ("/home/test/user1"), composed of both those strings. The reference to original composing strings is lost at the moment the expression itself is evaluated to be inserted into the dict. There's no compiler / interpreter that would do this any other way. At least not that I know of. So best suggestion would be to simply do an object that would parse strings before returning them. In the string itself, you can have special blocks that tell your parser that they are references to other objects. You can take good old DOS syntax for that: "%variable%" or something more elaborate if "%" is used in your strings too much. Anyway, your code would then look like (one possible way): config = {"home" : "/home/test"} config["user1"] = "%config["home"]%" + "/user1" or config = {"home" : "/home/test", "user1" : "%config[\"home\"]%/user1"} The parser would then just match "%(something)%" and replace it with actual value found in referenced variable. Eval() can help you there. Maybe there's already something in Python's libraries that matches your need. But you sure better not expect this to be included in language syntax. It's a pretty special case. Jure From duncan.booth at invalid.invalid Sat Jun 27 07:40:53 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jun 2009 11:40:53 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: Thomas Lehmann wrote: > Hi! > > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? That code actually does 3 dictionary lookups and creates a temporary object: the first lookup is to find the 'has_key' method, then it has to bind the method to data which involves creating a 'built-in method' object and then it calls it. Only then do you get the two lookups you expected. Replacing your code with: if key in data: value = data[key] reduces the overhead to two dictionary lookups, no temporary objects or function calls. The suggested alternative: value = data.get(key, None) also has two dictionary lookups: one to find the 'get' method and one to find the key, but as in the first case it also has the overhead of binding the method and then calling it. In other words the get method is often the clearest (and therefore best) way to write the code, but if performance matters do a check using the 'in' operator (or if you know the key lookup will fail only very rarely consider using try..except). In all of the above I'm assuming the code is actually inside a function accessing local variables otherwise accessing variables might involve yet more dictionary lookups. From twirlip at bigfoot.com Sat Jun 27 07:49:39 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:49:39 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: <0h0c45dggsmas6kt5bv9tfvl2mmv3sgatf@4ax.com> On Sat, 27 Jun 2009 12:13:57 +0100, I wrote: >Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be >treated as a single character. For instance, if test001A.txt is this file: abc xyz Bd ef gH ij and test001E.py is this: f = open('test001A.txt', 'r') for line in f: print repr(line) then the output from "python test001E.py > temp.txt" is this: 'abc xyz\n' 'Bd ef\n' '\n' 'gH ij\n' and indeed the output from "print repr(f.read())" is this: 'abc xyz\nBd ef\n\ngH ij\n' How do you actually get to see the raw bytes of a file in Windows? OK, this seems to work: f = open('test001A.txt', 'rb') # Binary mode print repr(f.read()) Output: 'abc xyz\r\nBd ef\r\n\r\ngH ij\r\n' Indeed, when a Windows file is opened for reading in binary mode, the length of an "empty" line is returned as 2. This is starting to make some sense to me now. -- Angus Rodgers From __peter__ at web.de Sat Jun 27 07:49:57 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:49:57 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: Angus Rodgers wrote: > On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten > <__peter__ at web.de> wrote: > >>Angus Rodgers wrote: >> >>> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >>> >>>>Will your program handle empty lines of input correctly? >>> >>> Strangely enough, it seems to do so, but why? >> >>Because there aren't any. When you read lines from a file there will >>always be at least the newline character. Otherwise it would indeed fail: >> >>>>> for line in "peter\npaul\n\nmary".splitlines(): >>... print line[0].upper() + line[1:] >>... >>Peter >>Paul >>Traceback (most recent call last): >> File "", line 2, in >>IndexError: string index out of range > > Hmm ... the \r\n sequence at the end of a Win/DOS line > seems to be treated as a single character. Yes, but "\n"[1:] will return an empty string rather than fail. From python at mrabarnett.plus.com Sat Jun 27 07:50:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 12:50:26 +0100 Subject: to use unicode strings only In-Reply-To: References: Message-ID: <4A460782.7010905@mrabarnett.plus.com> Gaudha wrote: > Hey gentlemen, > > I wanna make all the strings in my code unicode strings. How to do it > without giving unicode switch 'u' before every string? Use Python 3.1 instead. From olivergeorge at gmail.com Sat Jun 27 07:53:55 2009 From: olivergeorge at gmail.com (olivergeorge) Date: Sat, 27 Jun 2009 04:53:55 -0700 (PDT) Subject: Python Imaging Library download link broken? References: Message-ID: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Ditto. Anyone know what's happening with pythonware? (and why PIL is such a pain to install for that matter.) From __peter__ at web.de Sat Jun 27 07:54:19 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:54:19 +0200 Subject: to use unicode strings only References: Message-ID: MRAB wrote: > Gaudha wrote: >> I wanna make all the strings in my code unicode strings. How to do it >> without giving unicode switch 'u' before every string? > > Use Python 3.1 instead. or use from __future__ import unicode_literals in Python 2.6. From Iris-und-Thomas-Lehmann at T-Online.de Sat Jun 27 07:56:56 2009 From: Iris-und-Thomas-Lehmann at T-Online.de (Thomas Lehmann) Date: Sat, 27 Jun 2009 04:56:56 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? Well, I'm a 100% C++ programmer but I like programming python for prototyping and tools. The answer on your question depends on your requirements. Some are saying that using Java and Swing are the best way to write applications. But nothing is for free except the most languages you can download and install. When you have no idea about software development you should have a look there first. Do you want some little scripting only to get some jobs easier done - well - you're right to use python. However - you should be aware of: When you have learned python a while and when you will be forced to programm C++, Java or C# you have to start again! Check your requirements... From twirlip at bigfoot.com Sat Jun 27 08:01:27 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 13:01:27 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: On Sat, 27 Jun 2009 13:49:57 +0200, Peter Otten <__peter__ at web.de> wrote: >Angus Rodgers wrote: > >> On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten >> <__peter__ at web.de> wrote: >> >>>Angus Rodgers wrote: >>> >>>> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >>>> >>>>>Will your program handle empty lines of input correctly? >>>> >>>> Strangely enough, it seems to do so, but why? >>> >>>Because there aren't any. When you read lines from a file there will >>>always be at least the newline character. Otherwise it would indeed fail: >>> >>>>>> for line in "peter\npaul\n\nmary".splitlines(): >>>... print line[0].upper() + line[1:] >>>... >>>Peter >>>Paul >>>Traceback (most recent call last): >>> File "", line 2, in >>>IndexError: string index out of range >> >> Hmm ... the \r\n sequence at the end of a Win/DOS > >line > >> seems to be treated as a single character. > >Yes, but "\n"[1:] will return an empty string rather than fail. Yes, I understood that, and it's logical, but what was worrying me was how to understand the cross-platform behaviour of Python with regard to the different representation of text files in Windows and Unix-like OSs. (I remember getting all in a tizzy about this the last time I tried to do any programming. That was in C++, about eight years ago. Since then, I've only written a couple of short BASIC programs for numerical analysis on a TI-84+ calculator, and I feel as if I don't understand ANYTHING any more, but I expect it'll come back to me. Sorry about my recent flurry of confused posts! If I have any silly questions of my own, I'll post then to the Tutor list, but in this instance, I imagined I knew what I was talking about, and didn't expect to get into difficulties ...) 8-P -- Angus Rodgers From philip.groeger at googlemail.com Sat Jun 27 08:12:20 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Sat, 27 Jun 2009 14:12:20 +0200 Subject: Animate 3D Surface Message-ID: <386f361c0906270512j3658727dvddf86cc92a6fd040@mail.gmail.com> Hi, is there a way to animate a 3D surface in python using matplotlib 0.98 / mayavi 3 (i have the python(xy) suite for windows) or vpython? In *vpython* I tried to adjust the included faces_heightfield.py demo. But didnt find a way to delete the old surface. I just add more... In *matplotlib* I heard that the 3d features are discontinued in 0.91 (or something like that) And in *mayavi* I played around with surf() but with the surf(fkt(z0,0)).mlab_source.set command the picture won't update + show (the demo file in the documentation didnt work as well). I know there are vpython and mayavi mailing lists, but I didn't get an answer from them. I just hope someone of you can give me some "construct" which will work. Maybe I am just using the wrong methods. thanks alot!! - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Jun 27 08:13:07 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 14:13:07 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: Angus Rodgers wrote: > Yes, I understood that, and it's logical, but what was worrying me > was how to understand the cross-platform behaviour of Python with > regard to the different representation of text files in Windows > and Unix-like OSs. (I remember getting all in a tizzy about this If you are concerned about line endings open the file in universal newline mode: f = open(filename, "rU") """ In addition to the standard fopen values mode may be 'U' or 'rU'. Python is usually built with universal newline support; supplying 'U' opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention '\n', the Macintosh convention '\r', or the Windows convention '\r\n'. All of these external representations are seen as '\n' by the Python program. If Python is built without universal newline support a mode with 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types seen. """ From marduk at letterboxes.org Sat Jun 27 08:27:36 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 27 Jun 2009 08:27:36 -0400 Subject: postgreSQL python bindings - which one? In-Reply-To: References: Message-ID: <1246105656.18806.2.camel@blackwidow.nbk> On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: > Hi, I'm having a hard time deciding which set of PGSQL python bindings > to go with. I don't know much about SQL to begin with, so the collage > of packages of somewhat daunting. I'm starting a pet project in order > to teach my self more, but I want to avoid getting off on the wrong > foot and picking a package that is not going to be actively updated in > the future. > > There seem to be several implementations > * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. > * http://www.pygresql.org/ - version 4.0 was released beginning of > this year, update before that was sometime in 06 > ( http://www.pygresql.org/changelog.html ) > * http://python.projects.postgresql.org/ - first release was this > month? > > The last one of those three looks to be the most promising, but I just > can't tell for sure. Your input is appreciated :) > psycopg2: http://initd.org/pub/software/psycopg/ Last release was in May. -a From magawake at gmail.com Sat Jun 27 08:44:12 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 08:44:12 -0400 Subject: csv blank fields Message-ID: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> I am using the csv package to parse a compressed .csv.gz file. So far its working perfectly fine but it fails when I have a missing value in on of the fields. For example, I have this Abc,def,,jkl Is it possible to fill the missing column with a null? I want, Abc,def,NULL,jkl TIA From http Sat Jun 27 08:58:35 2009 From: http (Paul Rubin) Date: 27 Jun 2009 05:58:35 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <7x1vp56dfo.fsf@ruckus.brouhaha.com> Albert van der Horst writes: > >Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, > >Ronald L. Rivest, and Clifford Stein. > > Thanks. I lost that title a while ago, must buy. Wait a few months, a third edition is in the works. > Also "Numerical Recipe's in FORTRAN/Pascal/C" > (Have they done Python yet?) They haven't done Python AFAIK. I liked the C version but the licensing of the software is pretty evil and so I'm a bit turned off to the series these days. I think the hardcore numerics crowd never liked the book anyway. From http Sat Jun 27 08:59:39 2009 From: http (Paul Rubin) Date: 27 Jun 2009 05:59:39 -0700 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7xws6x4ytg.fsf@ruckus.brouhaha.com> Duncan Booth writes: > The suggested alternative: > > value = data.get(key, None) > > also has two dictionary lookups:... dg = data.get ... (inside loop): value = dg(key,None) From python at mrabarnett.plus.com Sat Jun 27 09:04:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 14:04:38 +0100 Subject: csv blank fields In-Reply-To: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> Message-ID: <4A4618E6.7000102@mrabarnett.plus.com> Mag Gam wrote: > I am using the csv package to parse a compressed .csv.gz file. So far > its working perfectly fine but it fails when I have a missing value in > on of the fields. > > For example, I have this > > Abc,def,,jkl > > Is it possible to fill the missing column with a null? > > I want, > Abc,def,NULL,jkl > What do you mean by "fails"? I get an empty string, which is what I'd expect. From magawake at gmail.com Sat Jun 27 09:33:09 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 09:33:09 -0400 Subject: csv blank fields In-Reply-To: <4A4618E6.7000102@mrabarnett.plus.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> well, I am actually loading the row into a fixed width array reader=csv.reader(fs) for s,row in enumerate(reader): t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) d[s]=t If there is a missing field, I get a problem in one of my rows On Sat, Jun 27, 2009 at 9:04 AM, MRAB wrote: > Mag Gam wrote: >> >> I am using the csv package to parse a compressed .csv.gz file. So far >> its working perfectly fine but it fails when I have a missing value in >> on of the fields. >> >> For example, I have this >> >> Abc,def,,jkl >> >> Is it possible to fill the missing column with a null? >> >> I want, >> Abc,def,NULL,jkl >> > What do you mean by "fails"? I get an empty string, which is what I'd > expect. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin at python.org Sat Jun 27 09:43:17 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 13:43:17 +0000 (UTC) Subject: to use unicode strings only References: Message-ID: Gaudha gmail.com> writes: > > Hey gentlemen, > > I wanna make all the strings in my code unicode strings. How to do it > without giving unicode switch 'u' before every string? Or the -U flag, but that's probably a bad idea. From __peter__ at web.de Sat Jun 27 10:03:33 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 16:03:33 +0200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: Mag Gam wrote: > well, I am actually loading the row into a fixed width array > > reader=csv.reader(fs) > for s,row in enumerate(reader): > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > d[s]=t > > > If there is a missing field, I get a problem in one of my rows Please be specific. Describe what you want and what you get. If you give code make it self-contained so that others can run it without having to guess the values of the variables you introduce. If an exception occurs cut and paste the traceback into your post, too. Peter From darcy at druid.net Sat Jun 27 10:05:48 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 27 Jun 2009 10:05:48 -0400 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <20090627100548.4440dd45.darcy@druid.net> On Sat, 27 Jun 2009 11:54:43 +0100 Angus Rodgers wrote: > On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: > >>f = open('test', 'r') > >>for line in f: > >> print line[0].upper()+line[1:], > > > >Will your program handle empty lines of input correctly? > > Strangely enough, it seems to do so, but why? The clue is the comma at the end of the print statement. It is there because no lines are empty. They have at least a newline. -- 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 qq13234722 at gmail.com Sat Jun 27 10:12:22 2009 From: qq13234722 at gmail.com (=?GB2312?B?t+jNvMHp?=) Date: Sat, 27 Jun 2009 07:12:22 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: <96dd77f8-640f-4588-8c4a-008c5f28886c@n7g2000prc.googlegroups.com> On 6?27?, ??10?22?, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato Oh, i think python is the best programing language for you ! From vasudevram at gmail.com Sat Jun 27 10:58:07 2009 From: vasudevram at gmail.com (vasudevram) Date: Sat, 27 Jun 2009 07:58:07 -0700 (PDT) Subject: file transfer in python References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: On Jun 26, 5:07?pm, Francesco Bochicchio wrote: > On 26 Giu, 13:38, jayesh bhardwaj wrote: > > > i am trying to find something useful in python to transfer html files > > from one terminal to other. Can this be done with some module or shall > > i start coding my own module using low level socket interface. If u > > know about some books on this topic or any online help then plz help. > > In the standard library there is ftplib, which allows your program to > act as a FTP client. Of course > the receiver end should have an FTP server installing and running. I > don't tink it can handle SFTP protocol, so > if you are concerned with security you should opt for someting else, > or protect your connection somehow (e.g. SSH tunneling). > > Or, if you have ssh (client and server) installed, you could simply > spawn a subprocess ( see the subprocess module for that ) which > execute one or more 'scp' commands. > > Ciao > ---- > FB There are many ways to do it; each may have it's own pros and cons. The low level sockets approach is feasible, as you said, and not too difficult, either. Read from each file and write the data to a socket from one end; read the data from the other end, and write it to a file. For the FTP approach, as Francesco said, the Python standard library has ftplib, which can help you with the client side, i.e. the sending side. If you don't have an FTP server on the receiving side, you could try using pyftpdlib to implement your own FTP server in Python: http://code.google.com/p/pyftpdlib/ Quoting from that URL: " Python FTP server library provides a high-level portable interface to easily write asynchronous FTP servers with Python. pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. It is used in projects like Google Chromium and Bazaar and included in Linux Fedora and FreeBSD package repositories. " Of course all that could be too much overhead; also, you would need permission to install your FTP daemon program written using pyftpdlib, on the receiving computer. As Francesco said, you could use the subprocess module and spawn a process that runs instances of scp. Another fairly easy way could be to write an XML-RPC client and server. The client, on the sending side, can send the data of each file to the server via an XML-RPC method call (in chunks, if needed, if the file is large); the server, on the receiving side, can read that data, and write it to a file on the file system. The client could send the file name of each file first, via a separate method call, before the data of each file, so the server would know under what name to save the file on its file system. By using the Binary data type supported by XML-RPC, you could send any type of file, whether text or binary, and irrespective of the operating system of the sender or receiver, whether Windows or UNIX. I've done this in some code of mine, so I know it works. You might have to take care about newline conversions (LF to CR + LF or vice versa), though, if one side is UNIX and the other is Windows, and do that conversion only for files that are text files. (For binary files, you actually have to make sure that you DO NOT do that conversion, or you will corrupt the data.) And do a similar conversion if one side is Mac and the other is Windows or Linux. On Mac, line endings are marked with a CR. LF = Line Feed (ASCII 10) CR = Carriage Return (ASCII 13) The subprocess + scp method may be slower than the XML-RPC method, since it will have to spawn a new scp process for each file sent, unless you use wildcards and transfer all or many files in one call. One the other hand, the XML-RPC method may be slower, since it transfers the data over HTTP (which rides on TCP which rides on IP), whereas scp probably uses a lower level protocol such as TCP packets directly, or something similar to what FTP uses - those protocols may have less overhead per unit of data sent. Which approach is best depends on your needs, whether it is a one-off job, or whether you need to repeat the job regularly, etc., how much time you have to write the code, etc. HTH, Vasudev --- Vasudev Ram Biz: www.dancingbison.com xtopdf: fast and easy PDF creation from other file formats: www.dancingbison.com/products.html Blog (on software innovation): jugad2.blogspot.com From jkv at unixcluster.dk Sat Jun 27 11:00:46 2009 From: jkv at unixcluster.dk (jkv) Date: Sat, 27 Jun 2009 17:00:46 +0200 Subject: csv blank fields In-Reply-To: <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> Message-ID: <4A46341E.2010008@unixcluster.dk> Mag Gam wrote: > > well, I am actually loading the row into a fixed width array > > > > reader=csv.reader(fs) > > for s,row in enumerate(reader): > > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > > d[s]=t > > > > > > If there is a missing field, I get a problem in one of my rows > > > I had a similar problem, my problem was that in my source data (csv file) sometimes the last cell was left out, so i ended up doing a try to check if the row existed, if not i appended to the row. Something like: try: row[11] except IndexError: row.append("") If you want to insert a value into empty cells you can do something like this: if row[10] == '' row[10] = 'NULL' -- Regards, jkv http://unixcluster.dk/public.key From sanal.vikram at gmail.com Sat Jun 27 11:57:24 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sat, 27 Jun 2009 08:57:24 -0700 (PDT) Subject: to use unicode strings only References: Message-ID: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> On Jun 27, 4:54?pm, Peter Otten <__pete... at web.de> wrote: > MRAB wrote: > > Gaudha wrote: > >> I wanna make all the strings in my code unicode strings. How to do it > >> without giving unicode switch 'u' before every string? > > > Use Python 3.1 instead. > > or use > > from __future__ import unicode_literals > > in Python 2.6. I know about Python 3.1 have the capability. But, unfortunately the community for which I'm working do not prefer Python 3.*... And Peter, I tried importing the __future__ module. It's also not working... From twirlip at bigfoot.com Sat Jun 27 12:02:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 17:02:43 +0100 Subject: Buffer pair for lexical analysis of raw binary data Message-ID: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Partly as an educational exercise, and partly for its practical benefit, I'm trying to pick up a programming project from where I left off in 2001. It implemented in slightly generalised form the "buffer pair" scheme for lexical analysis described on pp. 88--92 of Aho et al., /Compilers: Principles, Techniques and Tools/ (1986). (I'm afraid I don't have a page reference for the 2007 second edition. Presumably it's also in Knuth somewhere.) Documentation for one of the C++ header files describes it thus (but I never quite got the hang of C++, so some of the language- specific details may be very poorly conceived): "An object incorporates a handle to a file, opened in read-only mode, and a buffer containing (by default) raw binary data from that file. The constructor also has an option to open a file in text mode. The buffer may, optionally, consist of several segments, linked to one another in cyclic sequence. The number of segments is a constant class member, nblocks (1 <= nblocks <= 32,767). A second constant class member, block (1 <= block <= 32,767) gives the size of each of the segments in bytes. The purpose of creating a buffer in cyclically linked segments is to allow reference to the history of reading the file, even though it is being read sequentially. The bare class does not do this itself, but is designed so that classes derived from it may incorporate one or more pointers to parts of the buffer that have already been read (assuming these parts have not yet been overwritten). If there were only one segment, the length of available history would periodically be reduced to zero, when the buffer is re- freshed. In general, the available history occupies at least a fraction (nblocks - 1)/nblocks of a full buffer." Aho et al. describe the scheme thus (p. 90): "Two pointers to the input buffer are maintained. The string of characters between the two pointers is the current lexeme. Initially, both pointers point to the first character of the next lexeme to be found. One, called the forward pointer, scans ahead until a match for a pattern is found. Once the next lexeme is determined, the forward pointer is set to the character at its right end. After the lexeme is processed, both pointers are set to the character immediately past the lexeme." [There follows a description of the use of "sentinels" to test efficiently for pointers moving past the end of input to date.] I seem to remember (but my memory is still very hazy) that there was some annoying difficulty in coding the raw binary input file reading operation in C++ in an implementation-independent way; and I'm reluctant to go back and perhaps get bogged down again in whatever way I got bogged down before; so I would prefer to use Python for the whole thing, if possible (either using some existing library, or else by recoding it all myself in Python). Does some Python library already provide some functionality like this? (It's enough to do it with nblocks = 2, as in Aho et al.) If not, is this a reasonable thing to try to program in Python? (At the same time as learning the language, and partly as a fairly demanding exercise intended to help me to learn it.) Or should I just get my hands dirty with some C++ compiler or other, and get my original code working on my present machine (possibly in ANSI C instead of C++), and call it from Python? -- Angus Rodgers From magawake at gmail.com Sat Jun 27 12:35:47 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 12:35:47 -0400 Subject: csv blank fields In-Reply-To: References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Peter: Sorry if I wasn't clear before. While reading my csv file, notice I am putting the content in an array. If lets say, row[5] has nothing in it, python gives an exception. Instead of the exception, I would like to assign 'NULL' to row[5]. Does that help? On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten<__peter__ at web.de> wrote: > Mag Gam wrote: > >> well, I am actually loading the row into a fixed width array >> >> reader=csv.reader(fs) >> for s,row in enumerate(reader): >> > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) >> d[s]=t >> >> >> If there is a missing field, I get a problem in one of my rows > > Please be specific. Describe what you want and what you get. > > If you give code make it self-contained so that others can run it without > having to guess the values of the variables you introduce. > > If an exception occurs cut and paste the traceback into your post, too. > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > From msrachel.e at gmail.com Sat Jun 27 12:41:13 2009 From: msrachel.e at gmail.com (Rachel P) Date: Sat, 27 Jun 2009 09:41:13 -0700 (PDT) Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: [Thomas Lehmann] > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if ?data.has_key(key): > ? ?value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? Several thoughts for you: * Python isn't C++ * Dict lookups in Python are ubiquitous * Trying to avoid them is often an exercise in futility * Because of cache effects, double lookups are *very* cheap * If this particular fragment is critical, consider using get(): data_get = data.get ... # inner-loop code value = data_get(key) # assigns None for missing values * Another alternative is a try-block: try: # setup is cheap value = data[key] except KeyError: # matching is expensive ... * Or you can use collections.defaultdict() or a dict subclass that defines __missing__(). * In general though, think of dicts as one of Python's most optimized structures, one that should be embraced rather than avoided. * Tim Peter's take on the subject from year's ago (paraphrased): "Anything written using Python dictionaries is a gazillion times faster than C". Raymond From benjamin at python.org Sat Jun 27 12:44:30 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 16:44:30 +0000 (UTC) Subject: to use unicode strings only References: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> Message-ID: Gaudha gmail.com> writes: > And Peter, I tried importing the __future__ module. It's also not > working... How so? From charles at declareSub.com Sat Jun 27 12:46:23 2009 From: charles at declareSub.com (Charles Yeomans) Date: Sat, 27 Jun 2009 12:46:23 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: On Jun 26, 2009, at 10:22 PM, sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > As an alternative to Python, I'd suggest REALbasic. Its main disadvantage is that it is not free. But you get a language, editor, and two application frameworks in one package. Charles Yeomans From laplacian42 at gmail.com Sat Jun 27 12:54:36 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Sat, 27 Jun 2009 09:54:36 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? Message-ID: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> I just read a blog post of Guido's http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html and notice that he doesn't comment on what he wants in a GUI toolkit for Python. I sorta' wish he'd just come out and say, "This is what I think would be suitable for a GUI toolkit for Python: ...". That way, someone could then just come along and implement it. (Or maybe he's said this and I missed it?) So, what *does* Guido want in a GUI toolkit for Python? From python at mrabarnett.plus.com Sat Jun 27 13:06:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 18:06:23 +0100 Subject: csv blank fields In-Reply-To: <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: <4A46518F.40708@mrabarnett.plus.com> Mag Gam wrote: > Peter: > > Sorry if I wasn't clear before. > > While reading my csv file, notice I am putting the content in an array. > > If lets say, row[5] has nothing in it, python gives an exception. > Instead of the exception, I would like to assign 'NULL' to row[5]. > > Does that help? > You still didn't say what the exception was! Anyway, if you expect 'row' to contain 11 items, then you could append the missing ones: for s, row in enumerate(reader): # Fill any empty slots with "NULL". row = [r or "NULL" for r in row] # Append missing (empty) slots on the end. row += ["NULL"] * (11 - len(row)) d[s] = np.array([tuple(row)], dtype=mtype) > > On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten<__peter__ at web.de> wrote: >> Mag Gam wrote: >> >>> well, I am actually loading the row into a fixed width array >>> >>> reader=csv.reader(fs) >>> for s,row in enumerate(reader): >>> >> t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) >>> d[s]=t >>> >>> >>> If there is a missing field, I get a problem in one of my rows >> Please be specific. Describe what you want and what you get. >> >> If you give code make it self-contained so that others can run it without >> having to guess the values of the variables you introduce. >> >> If an exception occurs cut and paste the traceback into your post, too. >> From todorovic.dejan at gmail.com Sat Jun 27 13:06:32 2009 From: todorovic.dejan at gmail.com (netpork) Date: Sat, 27 Jun 2009 10:06:32 -0700 (PDT) Subject: encoding problem Message-ID: Hello, I have ssl socket with server and client, on my development machine everything works pretty well. Database which I have to use is mssql on ms server 2003, so I decided to install the same python config there and run my python server script. Now here is the problem, server is returning strange characters although default encoding is the same on both development and server machines. Any hints? Thanks in advance. From caseyhHAMMER_TIME at istar.ca Sat Jun 27 13:07:32 2009 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Sat, 27 Jun 2009 10:07:32 -0700 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: >So, what *does* Guido want in a GUI toolkit for Python? I saw a talk by a school teacher on pyFLTK: GUI programming made easy. On another note: I#: Groovy makes it easy to tie into the Java Swing GUI, so if Python could do that, with the added complication being the user would need a JVM. -- Regards, Casey From __peter__ at web.de Sat Jun 27 13:12:44 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 19:12:44 +0200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: Mag Gam wrote: Please don't top-post. > Sorry if I wasn't clear before. > > While reading my csv file, notice I am putting the content in an array. That's already in the code you posted. What's missing is the value of "mtypes". I really meant it when I asked you to provide a self-contained example, i. e. one that I can run on my computer. > If lets say, row[5] has nothing in it No, it containes an empty string as MRAB already inferred. > , python gives an exception. What exception? What traceback? Please take the time to read http://catb.org/esr/faqs/smart-questions.html > Instead of the exception, I would like to assign 'NULL' to row[5]. The string "NULL"? That would be # untested for s, row in enumerate(reader): row = tuple(c if c else "NULL" for c in row) t = np.array([row], dtype=mtype) ... I'm not a numpy expert, but creating a lot of temporary arrays does look wasteful... > Does that help? Sorry, no. I (or someone else who doesn't bother to guess) could have come up with a better answer in a shorter time if you had actually answered my questions. Peter From danger at rulez.sk Sat Jun 27 13:16:45 2009 From: danger at rulez.sk (Daniel Gerzo) Date: Sat, 27 Jun 2009 19:16:45 +0200 Subject: Looking for developer to help me Message-ID: <4A4653FD.6040208@rulez.sk> Hello guys, I have started to work on a new python library (called PySubLib), which is intended to allow applications to work with subtitles (the most common formats) easily. As I am pretty new to Python programming, I would appreciate if somebody with some spare time and Python foo could help/mentor me with this effort. In case there's somebody with Python skills willing to guide me, please let me know. I have already written some code, and if you're interested you may find it at http://bitbucket.org/danger/pysublib/src/. Thanks, -- S pozdravom / Best regards Daniel Gerzo From philip at semanchuk.com Sat Jun 27 13:23:04 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Jun 2009 13:23:04 -0400 Subject: postgreSQL python bindings - which one? In-Reply-To: <1246105656.18806.2.camel@blackwidow.nbk> References: <1246105656.18806.2.camel@blackwidow.nbk> Message-ID: On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote: > On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: >> Hi, I'm having a hard time deciding which set of PGSQL python >> bindings >> to go with. I don't know much about SQL to begin with, so the collage >> of packages of somewhat daunting. I'm starting a pet project in order >> to teach my self more, but I want to avoid getting off on the wrong >> foot and picking a package that is not going to be actively updated >> in >> the future. >> >> There seem to be several implementations >> * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. >> * http://www.pygresql.org/ - version 4.0 was released beginning of >> this year, update before that was sometime in 06 >> ( http://www.pygresql.org/changelog.html ) >> * http://python.projects.postgresql.org/ - first release was this >> month? >> >> The last one of those three looks to be the most promising, but I >> just >> can't tell for sure. Your input is appreciated :) >> > > psycopg2: http://initd.org/pub/software/psycopg/ +1 Although I'm not using it anymore, I had good success with psycopg2 and strongly recommend it. From kee at kagi.com Sat Jun 27 13:35:03 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 10:35:03 -0700 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <5847CB44-D6E3-45C7-9765-BE66076832DB@kagi.com> I'll give you the same advice I used to give to people when they wanted to decide whether to get a Mac or a PC, go with what your local group of friends is using. In general, if you have a local friend who can come over weekly (or you can visit weekly) and have them help you with the stumbling blocks, that is way more important than whether one language is better than another. If there is someone at work who can stop by your desk on a daily basis, that is even better. All computer languages have a learning curve and a whole set of quirks that are things that "everyone knows" (-: unless you are new to the language). Eventually you will grok the language and know all the weird gotchas that make no sense to a new person and from that point forward the documentation will make sense and you'll be able to go very far without having to ask others for help. Until that time, something as simple as the use of a colon instead of a semi-colon can halt your project for weeks. Having someone who can look at your code and say "there's your problem ..." is way more important than the language itself. With all that background, here are my personal choices. I started a long time ago with FORTRAN, BASIC, assembly language for single chip micros, and ultimately Hypercard and AppleScript (on the Mac), and finally the language used by the Arduino micros. I've built a ton of code using Hypercard all the way from web server CGIs to standalone user applications, to unattended code that runs forever doing a task when needed. Hypercard is no longer a viable coding platform so I had to find alternatives. For GUI stuff on a Mac or PC, I use RunRev. For all the Hypercard stuff I've built in the past I migrated to Runtime Revolution (RunRev) which can be described as a multi-platform Hypercard on steroids. The workflow is similar to Cocoa on the Mac. You first create the user interface by dragging buttons and fields and controllers and such onto windows and then when you like the way the user interface works, you write code to have the various interface elements do what they are supposed to when a user interacts with them. For GUI type applications, things that run on a user's computer, sometimes referred to as a heavy client, I find Runtime Revolution to be extremely easy and I'm very productive in that environment. I have web CGIs built in RunRev and it works quite well but ... it is a single threaded system so a web site with tons simultaneous hits will have scaling up problems. That said, high traffic web sites do use RunRev but I wanted something that was not single threaded for web stuff. For web stuff I have used RunRev but am moving towards Python. I went with Python mostly because a friend of mine who knows me and who writes in many languages, thought it was the best fit for the way my mind works, and he volunteered to help me when I get stuck on stuff. He helped me find the Komodo IDE and got me set up to where I had a very simple hello world CGI that I could expand upon. Python has a proven ability to scale up and support more users than I will ever need to support. It is what Google and many others run on. The philosophy is for there to be only one way to perform a function. A competent Python programmer can follow the code written by another because there is only one dialect of Python (unlike Perl). These are things I like about Python. I'm using Python 2.6.2 with the Komodo IDE and I'm limiting myself to the packages that come with the standard install of Python. So I'm not using TurboGears or Django or WSGI or any of those, I just use cgi and urllib (and urllib2). Until I know enough to really understand what my code is doing, and more importantly what those packages are doing or not, I'm not going to use add-on packages. So far I have not needed them. All that said, right now I am extremely inefficient in Python as compared to RunRev. I can build a fairly complex CGI in RunRev in a day, with Python, it takes me a month. Much of that has to do with RunRev being a variation of Hypercard (both use a HyperTalk style language) and I'm way past the 10,000 hour usage level on the HyperTalk language. I'm barely at 100 hours with Python so right now everything is a struggle. But I like Python and plan to stick with it. Kee Nethery From tjreedy at udel.edu Sat Jun 27 13:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:35:16 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: A > Steven D'Aprano wrote: > >>> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >>> said: >>> I think I'm paraphrasing Richard Feynman here, but the >>> only way to truly understand something is to do it. >> An amazingly inappropriate quote for a *theoretical* physicist to have said. Who got his start *doing* calculations for the Manhattan (atomic bomb) project, and checking them against real results. Like it or not, they 'did' it is a big way. He got his Nobel Prize for finding out how to *do* calculations that matched quantum mechanics experiments. (or something like that). His early bobby was picking locks and cracking safes -- mostly as a way to understand them. It was not enough for him to just read about them. tjr From tjreedy at udel.edu Sat Jun 27 13:38:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:38:04 -0400 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Peter Otten wrote: >>> Will your program handle empty lines of input correctly? >> Strangely enough, it seems to do so, but why? > > Because there aren't any. When you read lines from a file there will always > be at least the newline character. Otherwise it would indeed fail: Except possibly for the last line. From kee at kagi.com Sat Jun 27 13:41:28 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 10:41:28 -0700 Subject: looking for a book on python In-Reply-To: References: Message-ID: <7D341BFE-01DB-4CFB-9969-6B90BA81D6E1@kagi.com> I'm a newbie and I need examples and I find that Python for Dummies is my best paper source for examples. Kee Nethery From piet at cs.uu.nl Sat Jun 27 13:44:42 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 19:44:42 +0200 Subject: encoding problem References: Message-ID: >>>>> netpork (n) wrote: >n> Hello, >n> I have ssl socket with server and client, on my development machine >n> everything works pretty well. >n> Database which I have to use is mssql on ms server 2003, so I decided >n> to install the same python config there and run my python server >n> script. >n> Now here is the problem, server is returning strange characters >n> although default encoding is the same on both development and server >n> machines. >n> Any hints? Yes, read http://catb.org/esr/faqs/smart-questions.html -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Sat Jun 27 13:47:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:47:42 -0400 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: laplacian42 at gmail.com wrote: > I just read a blog post of Guido's > http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html > and notice that he doesn't comment on what he wants in a GUI toolkit > for Python. > > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". That way, someone > could then just come along and implement it. (Or maybe he's said this > and I missed it?) > > So, what *does* Guido want in a GUI toolkit for Python? What he did say is "But it hasn't really gotten any less complex to create the simplest of simple UIs. And that's a shame. When is Microsoft going to learn the real lesson about simplicity of HTML?" From aahz at pythoncraft.com Sat Jun 27 13:53:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 27 Jun 2009 10:53:33 -0700 Subject: looking for a book on python References: Message-ID: In article , Kee Nethery wrote: > >I'm a newbie and I need examples and I find that Python for Dummies is >my best paper source for examples. Thank you! That's one thing we worked hard on. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From piet at cs.uu.nl Sat Jun 27 13:55:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 19:55:17 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: >>>>> Terry Reedy (TR) wrote: >TR> Peter Otten wrote: >>>>> Will your program handle empty lines of input correctly? >>>> Strangely enough, it seems to do so, but why? >>> >>> Because there aren't any. When you read lines from a file there will >>> always be at least the newline character. Otherwise it would indeed fail: >TR> Except possibly for the last line. But then that line wouldn't be empty either. If there is an empty line not terminated by a newline after the last newline, then that is called 'end-of-file' :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From __peter__ at web.de Sat Jun 27 13:56:46 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 19:56:46 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Terry Reedy wrote: > Peter Otten wrote: > >>>> Will your program handle empty lines of input correctly? >>> Strangely enough, it seems to do so, but why? >> >> Because there aren't any. When you read lines from a file there will >> always be at least the newline character. Otherwise it would indeed fail: > > Except possibly for the last line. It may not end with a newline, but it will still contain at least one character. From kee at kagi.com Sat Jun 27 14:35:53 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 11:35:53 -0700 Subject: Python simple web development In-Reply-To: <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> Message-ID: <5A63D179-3A31-4339-AE5D-A2A19D99D93E@kagi.com> Until I'm an experience Python coder, I'm sticking with built-in packages only. My simple CGI is: #!/usr/bin/env python # this simple CGI responds to a GET or a POST # send anything you want to this and it will parrot it back. # a line that starts with #2 is the old-style code you should use that works # with versions less than Python 2.6. I'm using 2.6.2 and am trying to use # code that works with Python 3.x and up. import cgi ## so that I can be a web server CGI import os ## only purpose is for getting the CGI client values like IP and URL def main(): # create the output variable and then add stuff to it that gets returned cgiResponseData = 'stuff from the client browser connection:\n' # so that there is something to return, go through the CGI client data #2 for cgiKey in os.environ.keys(): for cgiKey in list(os.environ.keys()): # for each client data value, add a line to the output cgiResponseData = cgiResponseData + \ str(cgiKey) + ' = ' + os.environ[cgiKey] + '\n' # this says give me a list of all the user inputs posted to the cgi formPostData = cgi.FieldStorage() cgiResponseData = cgiResponseData + '\n\nstuff from the URL POST or GET:\n' # cycle through those inputs and output them right back #2 for keyValue in formPostData: for keyValue in list(formPostData): cgiResponseData = cgiResponseData + \ str(keyValue) + ' = ' + formPostData[keyValue].value + '\n' #2 print 'Content-type: text/html' #2 print #2 print cgiResponseData print('Content-type: text/html') print('') print(cgiResponseData) main() From emile at fenx.com Sat Jun 27 15:54:33 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Jun 2009 12:54:33 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On 6/27/2009 3:39 AM Angus Rodgers said... > On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah > wrote: > >> Thank you for your hint. >> This is my solution: >> f = open('test', 'r') >> for line in f: >> print line[0].upper()+line[1:], > > Will your program handle empty lines of input correctly? It will when the final line is changed to: print line[:1].upper()+line[1:] Emile From Scott.Daniels at Acm.Org Sat Jun 27 16:01:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 27 Jun 2009 13:01:01 -0700 Subject: Fast Dictionary Access In-Reply-To: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7J6dnbkkVox95dvXnZ2dnUVZ_r2dnZ2d@pdx.net> Thomas Lehmann wrote: > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? To get almost the same result (assuming value is already loaded): value = data.get(key, value) Otherwise, as others have said: if key in data: value = data[key] The form: try: value = data[key] except KeyError: pass works, but is not terribly efficient unless failures are rare. And this is a micro-optimization, measure before changing your program structure away from the clearest code you can write. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jun 27 16:02:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 27 Jun 2009 13:02:22 -0700 Subject: Python Imaging Library download link broken? In-Reply-To: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: <7J6dnbgkVoys5NvXnZ2dnUVZ_r1i4p2d@pdx.net> olivergeorge wrote: > Ditto. Anyone know what's happening with pythonware? (and why PIL is > such a pain to install for that matter.) (1) It is usually there; be patient. (2) I suggest you demand a refund. --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Sat Jun 27 16:25:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 21:25:15 +0100 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <4A46802B.2070600@mrabarnett.plus.com> Emile van Sebille wrote: > On 6/27/2009 3:39 AM Angus Rodgers said... >> On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >> wrote: >> >>> Thank you for your hint. >>> This is my solution: >>> f = open('test', 'r') >>> for line in f: >>> print line[0].upper()+line[1:], >> >> Will your program handle empty lines of input correctly? > > > It will when the final line is changed to: > > print line[:1].upper()+line[1:] > 'line' will _never_ be ''. If a line ends with a newline then that will be preserved returned as part of the string. This applies to the 'file' methods 'readline', 'readlines', etc, and the iterator, which returns a line. 'readline' will return '' only when it has reached the end of the file. From no.email at please.post Sat Jun 27 16:31:29 2009 From: no.email at please.post (kj) Date: Sat, 27 Jun 2009 20:31:29 +0000 (UTC) Subject: The Python Way for module configuration? Message-ID: [PYTHON NOOB ALERT] I want to write a module that serves as a Python front-end to a database. This database can be either in the form of tab-delimited flat files, XML files, or a PostgreSQL server. The module is meant to hide these database implementation details from its users. But, minimally, the module needs to have some configuration details to know where to get the data. There are many ways to provide this configuration data to the module, but I would like to know what's considered "best practice" for this type of problem in the Python world. Ideally, I'm looking for a system that is unobtrusive under normal operations, but easy to override during testing and debugging. I would appreciate your comments and suggestions. TIA! kynn From laplacian42 at gmail.com Sat Jun 27 16:33:46 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Sat, 27 Jun 2009 13:33:46 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <4626ad33-1dd5-4885-a373-b9cae3ff954e@a7g2000yqk.googlegroups.com> On Jun 27, 1:47?pm, Terry Reedy wrote: > laplacia... at gmail.com wrote: > > > So, what *does* Guido want in a GUI toolkit for Python? > > What he did say is "But it hasn't really gotten any less complex to > create the simplest of simple UIs. And that's a shame. When is Microsoft > going to learn the real lesson about simplicity of HTML?" Long ago I did some Java programming and tried out Swing. I think the complaints about it are that it's a very large toolkit that requires a lot of inheritance to use. However, the underlying premise used by the layout managers seemed sound: 1. Choose a layout manager. 2. Put one or more containers in it. 3. Fill the containers with widgets (or other containers), letting them decide how to lay out the widgets. That aspect, I liked. Seems a lot like nested elements in an html page. Perhaps this was what Guido was alluding to? From python at mrabarnett.plus.com Sat Jun 27 16:38:39 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 21:38:39 +0100 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <4A46834F.7010205@mrabarnett.plus.com> kj wrote: > > > [PYTHON NOOB ALERT] > > I want to write a module that serves as a Python front-end to a > database. This database can be either in the form of tab-delimited > flat files, XML files, or a PostgreSQL server. The module is meant > to hide these database implementation details from its users. > > But, minimally, the module needs to have some configuration details > to know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. > > I would appreciate your comments and suggestions. > There are already modules which provide access to databases. From aaronjsherman at gmail.com Sat Jun 27 16:54:56 2009 From: aaronjsherman at gmail.com (Aaron Sherman) Date: Sat, 27 Jun 2009 13:54:56 -0700 (PDT) Subject: The Python Way for module configuration? References: Message-ID: On Jun 27, 4:38?pm, MRAB wrote: > > I would appreciate your comments and suggestions. > > There are already modules which provide access to databases. As you can see the "Python Way" is to be rude ;-) Anyway, your answer is that there are some abstraction layers called "ORMs". You can grab one of these and write a back end for it. However, you might first want to look at SQLLite and see if it already has what you want (e.g. a light-weight, zero-install database interface). From emile at fenx.com Sat Jun 27 17:01:40 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Jun 2009 14:01:40 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <4A46802B.2070600@mrabarnett.plus.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <4A46802B.2070600@mrabarnett.plus.com> Message-ID: On 6/27/2009 1:25 PM MRAB said... > Emile van Sebille wrote: >> On 6/27/2009 3:39 AM Angus Rodgers said... >>> On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >>> wrote: >>> >>>> Thank you for your hint. >>>> This is my solution: >>>> f = open('test', 'r') >>>> for line in f: >>>> print line[0].upper()+line[1:], >>> >>> Will your program handle empty lines of input correctly? >> >> >> It will when the final line is changed to: >> >> print line[:1].upper()+line[1:] >> > 'line' will _never_ be ''. If a line ends with a newline then that will > be preserved returned as part of the string. This applies to the 'file' > methods 'readline', 'readlines', etc, and the iterator, which returns a > line. 'readline' will return '' only when it has reached the end of the > file. > Sorry -- habit. I tend to use that technique to avoid IndexErrors as a matter of course. Emile From martin at v.loewis.de Sat Jun 27 17:06:06 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 27 Jun 2009 23:06:06 +0200 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <4a4689bf$0$14790$9b622d9e@news.freenet.de> > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". He is not in the business of designing GUI toolkits, but in the business of designing programming languages. So he abstains from specifying (or even recommending) a GUI library. What he makes clear is the point that Terry cites: no matter what the GUI toolkit is or what features it has - it should be simple to create GUIs, as simple as creating HTML. > So, what *does* Guido want in a GUI toolkit for Python? His concern really isn't what is in the toolkit, but what isn't. It must not require lots of lines of code to produce a simple GUI, it must not require specification of absolute coordinates, ... - you should be able to continue the list yourself. Regards, Martin From benjamin at python.org Sat Jun 27 17:12:10 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 16:12:10 -0500 Subject: [RELEASED] Python 3.1 final Message-ID: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> On behalf of the Python development team, I'm thrilled to announce the first production release of Python 3.1. Python 3.1 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 visit: http://www.python.org/download/releases/3.1/ 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's contributors) From tkjthingone at gmail.com Sat Jun 27 17:29:54 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Sat, 27 Jun 2009 14:29:54 -0700 Subject: postgreSQL python bindings - which one? In-Reply-To: References: <1246105656.18806.2.camel@blackwidow.nbk> Message-ID: On Sat, Jun 27, 2009 at 10:23 AM, Philip Semanchuk wrote: > > On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote: > > On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: >> >>> Hi, I'm having a hard time deciding which set of PGSQL python bindings >>> to go with. I don't know much about SQL to begin with, so the collage >>> of packages of somewhat daunting. I'm starting a pet project in order >>> to teach my self more, but I want to avoid getting off on the wrong >>> foot and picking a package that is not going to be actively updated in >>> the future. >>> >>> There seem to be several implementations >>> * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. >>> * http://www.pygresql.org/ - version 4.0 was released beginning of >>> this year, update before that was sometime in 06 >>> ( http://www.pygresql.org/changelog.html ) >>> * http://python.projects.postgresql.org/ - first release was this >>> month? >>> >>> The last one of those three looks to be the most promising, but I just >>> can't tell for sure. Your input is appreciated :) >>> >>> >> psycopg2: http://initd.org/pub/software/pPhilip Semanchuk >> sycopg/ >> > > > +1 > > Although I'm not using it anymore, I had good success with psycopg2 and > strongly recommend it. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Awesome, thank you very much for the link! -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sat Jun 27 17:41:36 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Jun 2009 16:41:36 -0500 Subject: Good books in computer science? In-Reply-To: <7x1vp56dfo.fsf@ruckus.brouhaha.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x1vp56dfo.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-27 07:58, Paul Rubin wrote: > Albert van der Horst writes: >>> Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, >>> Ronald L. Rivest, and Clifford Stein. >> Thanks. I lost that title a while ago, must buy. > > Wait a few months, a third edition is in the works. > >> Also "Numerical Recipe's in FORTRAN/Pascal/C" >> (Have they done Python yet?) > > They haven't done Python AFAIK. I liked the C version but the > licensing of the software is pretty evil and so I'm a bit turned off > to the series these days. I think the hardcore numerics crowd never > liked the book anyway. My opinion is that the text itself is a pretty good introduction to the workings of a broad variety of numerical algorithms. For any particular area, there are probably better books that go into more depth and are closer to the state of the art, but I don't think there are any books that cover the wide swath numerical algorithms that NR does. In that regard, I treat it like Wikipedia: a good place to start, not the best place to stop. I think the code succeeds reasonably well for teaching the algorithms, but I don't think they are well-engineered for production use. There are usually better libraries with better licenses. -- 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 cook_jim at yahoo.com Sat Jun 27 18:14:16 2009 From: cook_jim at yahoo.com (Jim) Date: Sat, 27 Jun 2009 15:14:16 -0700 (PDT) Subject: tokenize module Message-ID: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> I'm trying to understand the output of the tokenize.generate_tokens() generator. The token types returned seem to be more general than I'd expect. For example, when fed the following line of code: def func_a(): the (abbreviated) returned token tuples are as follows: (NAME, def, ..., def func_a():) (NAME , func_a, ..., def func_a():) (OP, (, ..., def func_a():) (OP, ), ..., def func_a():) (OP, :, ..., def func_a():) (NEWLINE, NEWLINE, ..., def func_a():) It seems to me that the token '(' should be identified as 'LPAR' and ')' as 'RPAR', as found in the dictionary token.tok_name. What am I missing here? From no.email at please.post Sat Jun 27 18:18:37 2009 From: no.email at please.post (kj) Date: Sat, 27 Jun 2009 22:18:37 +0000 (UTC) Subject: The Python Way for module configuration? References: Message-ID: In Aaron Sherman writes: >On Jun 27, 4:38=A0pm, MRAB wrote: >> > I would appreciate your comments and suggestions. >> >> There are already modules which provide access to databases. >As you can see the "Python Way" is to be rude ;-) >Anyway, your answer is that there are some abstraction layers called >"ORMs". You can grab one of these and write a back end for it. >However, you might first want to look at SQLLite and see if it already >has what you want (e.g. a light-weight, zero-install database >interface). Hi, thanks, but the database aspect of my question is tangential. What I'm interested in is the general problem of providing configuration parameters to a module. TIA! kynn From bearophileHUGS at lycos.com Sat Jun 27 18:40:59 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 27 Jun 2009 15:40:59 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: Albert van der Horst: > For programming practice I do the problems of > http://projecteuler.net/ Time ago I have solved some of them with Python, D and C (some of them are quite hard for me), I have tried to produce very fast code (like a D generator for prime numbers that's like 100 times faster of some 'fast' C# prime generators I've seen in that forum). But then I have stopped because to me they seem a waste of time, they look too much academic, they don't exercise the right muscles of the mind. They may be good if you want to become good in performing numerical number theory, and bad for everyone else. Seeing how many people like to do those Project Euler puzzles, I presume my ideas aren't shared by most people. I am now using some solutions of mine of those problems to spot "performance bugs" in a new D compiler (and even in ShedSkin), so they are somewhat useful again :-) Bye, bearophile From abuse at 127.0.0.1 Sat Jun 27 19:12:34 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:12:34 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: OdarR wrote: > On 27 juin, 02:48, Randy Foiles wrote: >> Hello and thank you for taking your time to read this. >> I was interested in learning about python. In the long ago past I did >> learn some programing but I have not used any of it for years. I do >> remember some basics however so the book does not have to be for a total >> beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) >> I have been using Linux for a while and overall still don't know much >> about it but I can find my way. I have my system dual boot with windows >> vista. >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. >> Oh and if someone knows a place to find some used books of this sort >> that would be great (ebay I guess :) >> Thanks for your thoughts >> Randy theslayers9 gmail > > "Learning Python" > http://oreilly.com/catalog/9780596513986/ > > new issue soon, covering 2.6 and 3 > http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c > > the best book I read concerning Py understanding, well written. > > I would start with web content, then later would buy the fourth > edition of "Learning Python". > > enjoy, > Olivier Thank you. I was thinking of that book and a few others. I am not sure at this point what the difference is in 2.6 and 3? Randy From abuse at 127.0.0.1 Sat Jun 27 19:13:22 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:13:22 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Randy Foiles wrote: >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. > > You could get the book I co-wrote (Python for Dummies), but honestly, I > think you should try using some of the online tutorials first. The > standard Python tutorial is aimed at people with some programing > experience: > > http://docs.python.org/tutorial/index.html I had not thought about the "dummies" books for this I will look and see if my local B&N has it. From abuse at 127.0.0.1 Sat Jun 27 19:16:17 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:16:17 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: <5Lx1m.1604$NF6.775@nwrddc02.gnilink.net> laplacian42 at gmail.com wrote: > On Jun 26, 8:48 pm, Randy Foiles wrote: >> Hello and thank you for taking your time to read this. >> I was interested in learning about python. In the long ago past I did >> learn some programing but I have not used any of it for years. I do >> remember some basics however so the book does not have to be for a total >> beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) >> I have been using Linux for a while and overall still don't know much >> about it but I can find my way. I have my system dual boot with windows >> vista. >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. >> Oh and if someone knows a place to find some used books of this sort >> that would be great (ebay I guess :) >> Thanks for your thoughts >> Randy theslayers9 gmail > > The Oreilly "Python in a Nutshell" (2006, 2nd ed.) book is very good > and will get you up to speed in short order. This is one of the books I see around and it does seem that O'Reilly is where most people go for them :) What is it that you like about this one? From todorovic.dejan at gmail.com Sat Jun 27 19:28:15 2009 From: todorovic.dejan at gmail.com (=?ISO-8859-2?Q?dejan_todorovi=E6?=) Date: Sat, 27 Jun 2009 16:28:15 -0700 (PDT) Subject: encoding problem References: Message-ID: <9a70fd24-9e40-4ea4-8ad7-1f952e9cd544@y9g2000yqg.googlegroups.com> It was problem with pymssql that not supports unicode, switched to pyodbc, everything is fine. Thanks for your swift reply. ;) On Jun 27, 7:44?pm, Piet van Oostrum wrote: > >>>>> netpork (n) wrote: > >n> Hello, > >n> I have ssl socket with server and client, on my development machine > >n> everything works pretty well. > >n> Database which I have to use is mssql on ms server 2003, so I decided > >n> to install the same python config there and run my python server > >n> script. > >n> Now here is the problem, server is returning strange characters > >n> although default encoding is the same on both development and server > >n> machines. > >n> Any hints? > > Yes, readhttp://catb.org/esr/faqs/smart-questions.html > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org From petr.messner at gmail.com Sat Jun 27 19:48:33 2009 From: petr.messner at gmail.com (Petr Messner) Date: Sun, 28 Jun 2009 01:48:33 +0200 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <67c97cd90906271648k7e74ac25qee1e5e6ae5608c55@mail.gmail.com> Hi, 2009/6/28 kj : ... > What I'm interested in is the general problem of providing > configuration parameters to a module. > Some database/ORM libraries are configured via simple strings in the form "dialect://user:password at host/dbname[?key=value..]", for example "mysql://me:topsecret at localhost/test?encoding=utf8". Is this what you want to know? Petr From davea at ieee.org Sat Jun 27 20:07:29 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Jun 2009 20:07:29 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <4A46B441.7020109@ieee.org> sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato > > I am also a photographer (portraits, weddings, parties, ...). But my previous career was computer software (9 patents). So I know a bit about both. I only learned Python in the past year, having used 35 languages professionally previously. And although Python wasn't the easiest to learn, it was in the top 3, and it has the best ratio of power to difficulty of learning. The real point is that unless you're trying to make a career in software, you're unlikely to need any of these "more powerful" languages. And you can probably write a useful utility in your first 24 hours with the language. Don't worry too much about "object oriented" at the start. And don't worry much about using "old tutorials." Until Python 3, the language has been quite stable for many years. So my advice would be to download Python 2.6 for your operating system, and start playing. Pick something simple for your first tasks, preferably something useful in your main career. For example, try writing a utility that examines a directory tree of image files, looking for some anomaly that you come up with. For example, I use Nikon cameras, so my raw files have a .NEF extension. I never delete the NEF file, but instead move it into a subdirectory "Culled." So I could write a script that searches all subdirectories of directory images/2009-05, looking for gaps in the filenames found. Or look for .psd files that don't have a corresponding .NEF file above them. Or check the .xmp files to make sure the business copyright is in all files. I don't know what operating system you're using, but it would be a big help if you're familiar with the use of the command prompt. From aahz at pythoncraft.com Sat Jun 27 20:09:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 27 Jun 2009 17:09:45 -0700 Subject: looking for a book on python References: Message-ID: In article , Randy Foiles wrote: >OdarR wrote: >> >> "Learning Python" >> http://oreilly.com/catalog/9780596513986/ >> >> new issue soon, covering 2.6 and 3 >> http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c > >I was thinking of that book and a few others. I am not sure at this >point what the difference is in 2.6 and 3? There are lots of differences between 2.6 and the just-released 3.1, but opinions are split about which is better for learning: some people say that you should learn 3.x first because it's the future of Python and it's simpler/cleaner; others (including me) say you should learn 2.x first because that's where the bulk of current code is and many 3rd-party libraries have not yet been ported to 3.x. In the end, it doesn't make a lot of difference, as long as you stick with only 2.x or 3.x during your initial learning: the core Python syntax changes very little between the 2.x and 3.x, and there are only two critical differences that will hit you up-front: * Python 2.x has ``print`` as a statement; 3.x has ``print()`` as a function * Python 2.x has 8-bit strings by default; 3.x uses Unicode and has no way to access 8-bit strings except as byte arrays You might want to bookmark this, though: http://docs.python.org/3.1/whatsnew/index.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From ChollaPete at gmail.com Sat Jun 27 20:32:20 2009 From: ChollaPete at gmail.com (ChollaPete) Date: Sat, 27 Jun 2009 17:32:20 -0700 (PDT) Subject: Clobbered 2.6 binary under Frameworks.python, reinstall fails Message-ID: <5a1fb8c8-2b23-4529-bd3e-9f6d10566cc2@y17g2000yqn.googlegroups.com> Mac OS X (Tiger 10.4), running Python 2.6 downloaded from python.org as a DMG installer. I clobbered the python binary in /Library/Frameworks/Python.frameworks/ Versions/Current/bin, so I tried to reinstall from the python.org 2.6.2 DMG installer. No joy. Install fails at the end with no helpful diagnostic message. So, I deleted everything in /Applications/Python2.6, in /Library/ Frameworks/Python.frameworks and /usr/local/bin. The install still fails. Any help would be appreciated. I realize that the upgraders often aren't intended to be used to repair an existing installation. My thinking now is that I may need to delete existing package receipts or plists, but this is just wild speculation. Thanks. Mark From ncoghlan at gmail.com Sat Jun 27 20:53:49 2009 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 28 Jun 2009 10:53:49 +1000 Subject: [Python-Dev] [RELEASED] Python 3.1 final In-Reply-To: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: <4A46BF1D.2090002@gmail.com> Benjamin Peterson wrote: > On behalf of the Python development team, I'm thrilled to announce the first > production release of Python 3.1. Excellent news! Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- From ChollaPete at gmail.com Sat Jun 27 20:54:23 2009 From: ChollaPete at gmail.com (ChollaPete) Date: Sat, 27 Jun 2009 17:54:23 -0700 (PDT) Subject: Clobbered 2.6 binary under Frameworks.python, reinstall fails References: <5a1fb8c8-2b23-4529-bd3e-9f6d10566cc2@y17g2000yqn.googlegroups.com> Message-ID: On Jun 27, 5:32?pm, ChollaPete wrote: > Mac OS ?X (Tiger 10.4), running Python 2.6 downloaded from python.org > as a DMG installer. > > I clobbered the python binary in /Library/Frameworks/Python.frameworks/ > Versions/Current/bin, so I tried to reinstall from the python.org > 2.6.2 DMG installer. ?No joy. ?Install fails at the end with no > helpful diagnostic message. > > So, I deleted everything in /Applications/Python2.6, in /Library/ > Frameworks/Python.frameworks and /usr/local/bin. ?The install still > fails. > > Any help would be appreciated. ?I realize that the upgraders often > aren't intended to be used to repair an existing installation. ?My > thinking now is that I may need to delete existing package receipts or > plists, but this is just wild speculation. > > Thanks. > > Mark Well, upon inspection of the various directories, everything seemed to be there, so I ran the interpreter and it seemed to work. Evaluated a simple expression at the >>> prompt, imported a module and ran its function. So, I don't know what part of the install failed. If anyone can tell me where to find the various scripts that the MPKG runs, that would help. Thanks, Mark From wuwei23 at gmail.com Sat Jun 27 21:03:23 2009 From: wuwei23 at gmail.com (alex23) Date: Sat, 27 Jun 2009 18:03:23 -0700 (PDT) Subject: No trees in the stdlib? References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: Jo?o Valverde wrote: > Currently I don't have a strong need for this. And clearly neither has anyone else, hence the absence from the stdlib. As others have pointed out, there are alternative approaches, and plenty of recipes on ActiveState, which seem to have scratched whatever itch there is for the data structure you're advocating. While Python's motto is "batteries included" I've always felt there was an implicit "but not the kitchen sink" following it. Just because something "could" be useful shouldn't be grounds for inclusion. That's what pypi & the recipes are for. Ideally, little should be created wholesale for the stdlib, what should be added are the existing 3rd party modules that have become so ubiquitous that their presence on any python platform is just expected. From backup95 at netcabo.pt Sat Jun 27 22:03:48 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sun, 28 Jun 2009 03:03:48 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A46CF84.2080005@netcabo.pt> alex23 wrote: > Jo?o Valverde wrote: > >> Currently I don't have a strong need for this. >> > > And clearly neither has anyone else, hence the absence from the > stdlib. As others have pointed out, there are alternative approaches, > and plenty of recipes on ActiveState, which seem to have scratched > whatever itch there is for the data structure you're advocating. > Propose such alternative then. There are none that offer the same performance. At best they're workarounds. I don't care about recipes. That's called research. If people don't find it to be useful, that's fine. Surprising, but fine. And I don't have a need because I'm not using Python for my project. If I wanted to I couldn't, without implementing myself or porting to Python 3 a basic computer science data structure. > While Python's motto is "batteries included" I've always felt there > was an implicit "but not the kitchen sink" following it. Just because > something "could" be useful shouldn't be grounds for inclusion. That's > what pypi & the recipes are for. Ideally, little should be created > wholesale for the stdlib, what should be added are the existing 3rd > party modules that have become so ubiquitous that their presence on > any python platform is just expected. > Agreed. From davea at ieee.org Sat Jun 27 22:52:47 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Jun 2009 22:52:47 -0400 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <4A46DAFF.2000709@ieee.org> kj wrote: > In Aaron Sherman writes: > > >> On Jun 27, 4:38=A0pm, MRAB wrote: >> > > >>>> I would appreciate your comments and suggestions. >>>> >>> There are already modules which provide access to databases. >>> > > >> As you can see the "Python Way" is to be rude ;-) >> > > >> Anyway, your answer is that there are some abstraction layers called >> "ORMs". You can grab one of these and write a back end for it. >> However, you might first want to look at SQLLite and see if it already >> has what you want (e.g. a light-weight, zero-install database >> interface). >> > > > Hi, thanks, but the database aspect of my question is tangential. > What I'm interested in is the general problem of providing > configuration parameters to a module. > > TIA! > > kynn > > > Check out the ConfigParser module, a standard module. In Python 3.0, it's renamed to configparser, but still part of the standard distribution. This module interprets a file that's in roughly the INI format. From milesck at umich.edu Sat Jun 27 22:56:32 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 27 Jun 2009 22:56:32 -0400 Subject: No trees in the stdlib? In-Reply-To: <4A45A8ED.9090103@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> <4A45A8ED.9090103@netcabo.pt> Message-ID: Jo?o Valverde wrote: > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). Originally I was also serializing them in a binary > format (but no more after a redesign). I kept the "merge and sort" > part as a helper script, but that is considerably simpler to > implement. > > ... > > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and > Python, using pyavl. Round numbers were 4 mins vs 4 seconds, against > Python (plus pyavl). Even considering I'm a worse Python programmer > than C programmer, it's a lot. I know many will probably think I > tried to do "C in Python" but that's not the case, at least I don' t > think so. Anyway like I said, not really relevant to this discussion. What format were you using to represent the IP addresses? (Is it a Python class?) And why wouldn't you use a network address/subnet mask pair to represent block ranges? (It seems like being able to represent ranges that don't fit into a subnet's 2^n block wouldn't be that common of an occurrence, and that it might be more useful to make those ranges easier to manipulate.) One of the major disadvantages of using a tree container is that usually multiple comparisons must be done for every tree operation. When that comparison involves a call into Python bytecode (for custom cmp/lt methods) the cost can be substantial. Compare that to Python's hash-based containers, which only need to call comparison methods in the event of hash collisions (and that's hash collisions, not hash table bucket collisions, since the containers cache each object's hash value). I would imagine that tree-based containers would only be worth using with objects with comparison methods implemented in C. Not that I'm trying to be an apologist, or reject your arguments; I can definitely see the use case for a well-implemented, fast tree- based container for Python. And so much the better if, when you need one, there was a clear consensus about what package to use (like PIL for image manipulation--it won't meet every need, and there are others out there, but it's usually the first recommended), rather than having to search out and evaluate a dozen different ones. -Miles From ben+python at benfinney.id.au Sat Jun 27 23:28:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 13:28:31 +1000 Subject: The Python Way for module configuration? References: Message-ID: <87fxdlujds.fsf@benfinney.id.au> (Even if you don't want to receive email, could you please give your actual name in the ?From? field instead of just initials? It makes conversation less confusing.) kj writes: > But, minimally, the module needs to have some configuration details to > know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. The standard library provides the ability to parse plain text configuration files and populate a collection of values for configuration. The module's name is changing to conform to the library standards; see . This way, you can customise the execution of your program by modifying configuration settings in a non-executable configuration file. It also allows a cascade of overrides, for e.g. user-specific configuration overrides or test-specific overrides, etc. -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From backup95 at netcabo.pt Sat Jun 27 23:44:02 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sun, 28 Jun 2009 04:44:02 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> <4A45A8ED.9090103@netcabo.pt> Message-ID: <4A46E702.40805@netcabo.pt> Miles Kaufmann wrote: > Jo?o Valverde wrote: >> To answer the question of what I need the BSTs for, without getting >> into too many boring details it is to merge and sort IP blocklists, >> that is, large datasets of ranges in the form of (IP address, IP >> address, string). Originally I was also serializing them in a binary >> format (but no more after a redesign). I kept the "merge and sort" >> part as a helper script, but that is considerably simpler to implement. >> >> ... >> >> As an anecdotal data point (honestly not trying to raise the "Python >> is slow" strawman), I implemented the same algorithm in C and Python, >> using pyavl. Round numbers were 4 mins vs 4 seconds, against Python >> (plus pyavl). Even considering I'm a worse Python programmer than C >> programmer, it's a lot. I know many will probably think I tried to do >> "C in Python" but that's not the case, at least I don' t think so. >> Anyway like I said, not really relevant to this discussion. > > What format were you using to represent the IP addresses? (Is it a > Python class?) And why wouldn't you use a network address/subnet mask > pair to represent block ranges? (It seems like being able to > represent ranges that don't fit into a subnet's 2^n block wouldn't be > that common of an occurrence, and that it might be more useful to make > those ranges easier to manipulate.) I was using a bytes subclass. I'm not free to choose CIDR notation, range boundaries must be arbitrary. > > One of the major disadvantages of using a tree container is that > usually multiple comparisons must be done for every tree operation. > When that comparison involves a call into Python bytecode (for custom > cmp/lt methods) the cost can be substantial. Compare that to Python's > hash-based containers, which only need to call comparison methods in > the event of hash collisions (and that's hash collisions, not hash > table bucket collisions, since the containers cache each object's hash > value). I would imagine that tree-based containers would only be > worth using with objects with comparison methods implemented in C. I would flip your statement and say one of the advantages of using trees is that they efficiently keep random input sorted. Obviously no algorithm can do that with single comparisons. And not requiring a hash function is a desirable quality for non-hashable objects. There's a world beyond dicts. :) I profiled the code and indeed the comparisons dominated the execution time. Trimming the comparison function to the bare minimum, a single python operation, almost doubled the program's speed. > > Not that I'm trying to be an apologist, or reject your arguments; I > can definitely see the use case for a well-implemented, fast > tree-based container for Python. And so much the better if, when you > need one, there was a clear consensus about what package to use (like > PIL for image manipulation--it won't meet every need, and there are > others out there, but it's usually the first recommended), rather than > having to search out and evaluate a dozen different ones. > Thanks, and I'm not trying to start a religion either. ;) From pavlovevidence at gmail.com Sun Jun 28 00:04:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 27 Jun 2009 21:04:51 -0700 (PDT) Subject: The Python Way for module configuration? References: Message-ID: <3583bbfc-4f89-4ee0-aa56-b934880a8523@t21g2000yqi.googlegroups.com> On Jun 27, 3:18?pm, kj wrote: > In Aaron Sherman writes: > > >On Jun 27, 4:38=A0pm, MRAB wrote: > >> > I would appreciate your comments and suggestions. > > >> There are already modules which provide access to databases. > >As you can see the "Python Way" is to be rude ;-) > >Anyway, your answer is that there are some abstraction layers called > >"ORMs". You can grab one of these and write a back end for it. > >However, you might first want to look at SQLLite and see if it already > >has what you want (e.g. a light-weight, zero-install database > >interface). > > Hi, thanks, but the database aspect of my question is tangential. > What I'm interested in is the general problem of providing > configuration parameters to a module. The best way to do this totally depends on how complex these parameters are. Are they simple one-to-one key-value pairs? Then the frontend should explose a dict interface. There are probably existing third-party libraries that expose dict-like interfaces to all of your imagined backends. Check pypi.python.org, and also Python cookbook. If the configuration is more complex, such as if it is hierarchical, if it includes many-to-many relationships, if it is graph-like, then a more sophisticated frontend will be needed. For these situations I second the recommendation to consider an ORM (such as SqlAlchemy). I am not aware of any ORMs that can use SQL, XML, and tab-delimited text all as backends, though. I am not a big database guy though. Also, I exhort to you consider whether you really need so many different backends for a configuration file. Might your time be better spent improving some other aspect of your application? Carl Banks From kay at fiber-space.de Sun Jun 28 00:44:44 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 27 Jun 2009 21:44:44 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <6c737d94-a5a6-42a8-a6dc-13b6936f8eb0@t13g2000yqt.googlegroups.com> On 27 Jun., 23:06, "Martin v. L?wis" wrote: > > I sorta' wish he'd just come out and say, "This is what I think would > > be suitable for a GUI toolkit for Python: ...". > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. ... which isn't all that different today. One might just take a look at JavaFX and how gracefully it handles declarative data flow a.k.a. data binding. The evolution of programming languages goes on, with or rather without Python. From http Sun Jun 28 01:31:22 2009 From: http (Paul Rubin) Date: 27 Jun 2009 22:31:22 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <7xws6w2ac5.fsf@ruckus.brouhaha.com> Robin Becker writes: > > There is a philosophy of mathematics (intuitionism) that says... > > there are NO discontinuous functions. > so does this render all the discreteness implied by quantum theory > unreliable? or is it that we just cannot see(measure) the continuity > that really happens? I think the latter. Quantum theory anyway describes continuous operators that have discrete eigenvalues, not the same thing as discontinuous functions. From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:31:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:31:37 GMT Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: <0062db08$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: > (Even if you don't want to receive email, could you please give your > actual name in the ?From? field instead of just initials? It makes > conversation less confusing.) Some people prefer to be known by their initials. Some people's legal names *are* initials. There's nothing confusing about addressing somebody by their initials. The only complication in this case is knowing the correct way to capitalise it -- should it be K.J. or Kj or something else? > kj writes: Apart from capitalisation, it works perfectly. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:36:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:36:06 GMT Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <0062dc15$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 19:55:17 +0200, Piet van Oostrum wrote: >>>>>> Terry Reedy (TR) wrote: > >>TR> Peter Otten wrote: >>>>>> Will your program handle empty lines of input correctly? >>>>> Strangely enough, it seems to do so, but why? >>>> >>>> Because there aren't any. When you read lines from a file there will >>>> always be at least the newline character. Otherwise it would indeed >>>> fail: > >>TR> Except possibly for the last line. > > But then that line wouldn't be empty either. > > If there is an empty line not terminated by a newline after the last > newline, then that is called 'end-of-file' :=) I try to always write file-handling files under the assumption that some day somebody (possibly me) will pass the function a file-like object, and therefore make the minimum number of assumptions about each line. For example, I wouldn't assume that lines can't be empty, or that they must end in a newline. The later is violated even by ordinary files, but the former could be violated by a file-like object which iterated over (say) ['first line', 'second line', '', 'the previous line was blank']. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:37:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:37:18 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <0062dc5c$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: [...] > Raymond Raymond, does Rachel know you're using her gmail account? *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 02:19:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 06:19:22 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <0062e638$0$9714$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:23:07 +0100, Robin Becker wrote: > Paul Rubin wrote: [...] >> No really, it is just set theory, which is a pretty bogus subject in >> some sense. There aren't many discontinuous functions in nature. Depends on how you define "discontinuous". Catastrophe theory is full of discontinuous changes in state. Animal (by which I include human) behaviour often displays discontinuous changes. So does chemistry: one minute the grenade is sitting there, stable as can be, the next it's an expanding cloud of gas and metal fragments. Then there's spontaneous symmetry breaking. At an atomic level, it's difficult to think of things which *aren't* discontinuous. And of course, if quantum mechanics is right, nature is *nothing but* discontinuous functions. >> There >> is a philosophy of mathematics (intuitionism) that says classical set >> theory is wrong and in fact there are NO discontinuous functions. They >> have their own mathematical axioms which allow developing calculus in a >> way that all functions are continuous. On the other hand, there's also discrete mathematics, including discrete versions of calculus. > so does this render all the discreteness implied by quantum theory > unreliable? or is it that we just cannot see(measure) the continuity > that really happens? That's a question for scientific investigation, not mathematics or philosophy. It may be that the universe is fundamentally discontinuous, and the continuous functions we see are only because of our insufficiently high resolution senses and instruments. Or it may be that the discontinuities we see are only because we're not capable of looking closely enough to see the smooth function passing between the two ends of the discontinuity. My money is on the universe being fundamentally discontinuous. We can explain the continuous behaviour of classical-scale phenomenon in terms of discontinuous quantum behaviour, but it doesn't seem possible to explain discontinuous quantum behaviour in terms of lower-level continuous behaviour. -- Steven From zaphod at beeblebrox.net Sun Jun 28 02:26:14 2009 From: zaphod at beeblebrox.net (Zaphod) Date: Sun, 28 Jun 2009 06:26:14 GMT Subject: Beginning with Python; the right choice? References: Message-ID: snip > In terms of good tutorials for absolute beginners, here are two: > > Alan Gauld's Learning to Program > http://www.freenetpages.co.uk/hp/alan.gauld/ > > ShowMeDo.com has lots of Python instructional videos, including this one > for absolute beginners: > http://showmedo.com/videotutorials/series?name=irgGc9ChS > > I also recommend the Python tutor list, which you can sign up for here: > http://mail.python.org/mailman/listinfo/tutor > > So what is it that you want to use Python for? > > Che Also have a look at http://openbookproject.net/thinkcs/python/english2e/ which is a bit less in depth but faster and also fun way to get started. I teach high school programming and although I do teach Visual Basic at the lower levels (grade 9/10) I use Python for my grade 11/12 students. It's an easy language to learn and has an incredible amount of functionality through importable libraries. From http Sun Jun 28 02:52:02 2009 From: http (Paul Rubin) Date: 27 Jun 2009 23:52:02 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7xocs83l65.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Depends on how you define "discontinuous". The mathematical way, of course. For any epsilon > 0, etc. > Catastrophe theory is full of discontinuous changes in state. Animal > (by which I include human) behaviour often displays discontinuous > changes. So does chemistry: one minute the grenade is sitting there, > stable as can be, the next it's an expanding cloud of gas and metal > fragments. If that transition from grenade to gas cloud takes a minute (or even a femtosecond), it's not a mathematical discontinuity. The other examples work out about the same way. From lie.1296 at gmail.com Sun Jun 28 03:25:36 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 28 Jun 2009 07:25:36 GMT Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: Jo?o Valverde wrote: > alex23 wrote: >> Jo?o Valverde wrote: >> >>> Currently I don't have a strong need for this. >>> >> >> And clearly neither has anyone else, hence the absence from the >> stdlib. As others have pointed out, there are alternative approaches, >> and plenty of recipes on ActiveState, which seem to have scratched >> whatever itch there is for the data structure you're advocating. >> > > Propose such alternative then. There are none that offer the same > performance. At best they're workarounds. > > I don't care about recipes. That's called research. > > If people don't find it to be useful, that's fine. Surprising, but fine. Python devs, based on my observation, tend to choose a data structure based on the interface and not its implementation. Binary Sorted Tree is an implementation, its interface can be a sorted dict (sorted key-value mapping) or a list (not the most natural interface for a tree). Basically, python already have all the common interfaces, i.e. list, set, and mapping/dict. Let's see it like this. In how many ways can a list be implemented? - Array (python's builtin list) - Linked List - Binary Tree - and the list goes on... All of them can expose their interface as list, but only array implementation is available as builtin. > And I don't have a need because I'm not using Python for my project. If > I wanted to I couldn't, without implementing myself or porting to Python > 3 a basic computer science data structure. > >> While Python's motto is "batteries included" I've always felt there >> was an implicit "but not the kitchen sink" following it. Just because >> something "could" be useful shouldn't be grounds for inclusion. That's >> what pypi & the recipes are for. Ideally, little should be created >> wholesale for the stdlib, what should be added are the existing 3rd >> party modules that have become so ubiquitous that their presence on >> any python platform is just expected. >> > > Agreed. From sajmikins at gmail.com Sun Jun 28 03:39:10 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 28 Jun 2009 00:39:10 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <64cb06c8-8463-4664-9375-5f72d49df1d2@c9g2000yqm.googlegroups.com> On Jun 27, 12:54?pm, "laplacia... at gmail.com" wrote: > I just read a blog post of Guido'shttp://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decl... > and notice that he doesn't comment on what he wants in a GUI toolkit > for Python. > > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". That way, someone > could then just come along and implement it. (Or maybe he's said this > and I missed it?) > > So, what *does* Guido want in a GUI toolkit for Python? FWIW, I created a simple GUI builder module I call pygoo that lets you create Tkinter GUIs from a simple text "specification". http://www.pygoo.com/ http://code.google.com/p/pygoo/ Warm regards, ~Simon From timr at probo.com Sun Jun 28 03:46:05 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Jun 2009 00:46:05 -0700 Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> Message-ID: <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> Jim wrote: >I'm trying to understand the output of the tokenize.generate_tokens() >generator. The token types returned seem to be more general than I'd >expect. For example, when fed the following line of code: > >def func_a(): >... >It seems to me that the token '(' should be identified as 'LPAR' and >')' as 'RPAR', as found in the dictionary token.tok_name. What am I >missing here? Did you read the module? Right at the top, it says: It is designed to match the working of the Python tokenizer exactly, except that it produces COMMENT tokens for comments and gives type OP for all operators -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nobody at nowhere.com Sun Jun 28 03:51:07 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 08:51:07 +0100 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: On Sat, 27 Jun 2009 17:17:22 -0700, Dennis Lee Bieber wrote: >> His concern really isn't what is in the toolkit, but what isn't. >> It must not require lots of lines of code to produce a simple >> GUI, it must not require specification of absolute coordinates, >> ... - you should be able to continue the list yourself. >> > > Sounds a bit like a return of DECWindows on Xt... Which had a > textual design language to define the widgets in use, names for > callbacks, etc. and only required the application to load the file and > map the callbacks to actual code... > > You could change the layout without touching the application code > (as long as you weren't adding new widgets) Xt itself provides some of that, the rest can be had through UIL (which is part of Motif). GTK+ can do much of this using Glade. The concept of separating code from data is sensible enough, and mirrors the concept of stylesheets in HTML. It shouldn't be necessary to specify size, position, labels, colours and the like via code. Code only needs to be able to get a handle on a specific widget so that it can read and write its state, dynamically register callbacks, etc. From stef.mientki at gmail.com Sun Jun 28 04:06:11 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 28 Jun 2009 10:06:11 +0200 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4a4689bf$0$14790$9b622d9e@news.freenet.de> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <4A472473.1030706@gmail.com> Martin v. L?wis wrote: >> I sorta' wish he'd just come out and say, "This is what I think would >> be suitable for a GUI toolkit for Python: ...". >> > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. > > What he makes clear is the point that Terry cites: no matter what the > GUI toolkit is or what features it has - it should be simple to create > GUIs, as simple as creating HTML. > > >> So, what *does* Guido want in a GUI toolkit for Python? >> > > His concern really isn't what is in the toolkit, but what isn't. > It must not require lots of lines of code to produce a simple > GUI, it must not require specification of absolute coordinates, > ... - you should be able to continue the list yourself. > > Gui_support obey the above 2 rules, so I guess, 'm on the right way with GUI_support http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html What are the other rules ? cheers, Stef > Regards, > Martin > From comet2005 at gmail.com Sun Jun 28 04:25:39 2009 From: comet2005 at gmail.com (iceangel89) Date: Sun, 28 Jun 2009 01:25:39 -0700 (PDT) Subject: Advantages of Python (for web/desktop apps)? Message-ID: <24239603.post@talk.nabble.com> i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python now (for desktop apps since its open source and just want to try what it offers, but will like to know what good it has for web development also) i wonder what do users of Python say? somethings i am curious abt (that came to my mind) now are: - performance - ide to use? - how do i design GUI for windows app? -- View this message in context: http://www.nabble.com/Advantages-of-Python-%28for-web-desktop-apps%29--tp24239603p24239603.html Sent from the Python - python-list mailing list archive at Nabble.com. From ben+python at benfinney.id.au Sun Jun 28 04:39:28 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 18:39:28 +1000 Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> Message-ID: <87bpo8vjjz.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: > > > (Even if you don't want to receive email, could you please give your > > actual name in the ?From? field instead of just initials? It makes > > conversation less confusing.) > > Some people prefer to be known by their initials. Some people prefer to spend their volunteer time conversing with people who don't just use initials or pseudonyms. > There's nothing confusing about addressing somebody by their initials. I find it much less confusing to converse with someone if I can keep straight who they are, and names work better than initials for that purpose. -- \ ?Whenever you read a good book, it's like the author is right | `\ there, in the room talking to you, which is why I don't like to | _o__) read good books.? ?Jack Handey | Ben Finney From ben+python at benfinney.id.au Sun Jun 28 04:40:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 18:40:20 +1000 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> <0062dc5c$0$9714$c3e8da3@news.astraweb.com> Message-ID: <877hywvjij.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: > [...] > > Raymond > > Raymond, does Rachel know you're using her gmail account? It's a good thing names are being used here, rather than just initials. -- \ ?No one ever went broke underestimating the taste of the | `\ American public.? ?Henry L. Mencken | _o__) | Ben Finney From nobody at nowhere.com Sun Jun 28 04:58:14 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 09:58:14 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: > Python 3.1 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. That's a significant improvement. It still decodes os.environ and sys.argv before you have a chance to call sys.setfilesystemencoding(), but it appears to be recoverable (with some effort; I can't find any way to re-do the encoding without manually replacing the surrogates). However, sys.std{in,out,err} are still created as text streams, and AFAICT there's nothing you can do about this from within your code. All in all, Python 3.x still has a long way to go before it will be suitable for real-world use. From mail at microcorp.co.za Sun Jun 28 04:59:07 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 28 Jun 2009 10:59:07 +0200 Subject: The Python Way for module configuration? References: Message-ID: <010601c9f7ce$be12da40$0d00a8c0@Hendrik> "kj" wrote: > I want to write a module that serves as a Python front-end to a > database. This database can be either in the form of tab-delimited > flat files, XML files, or a PostgreSQL server. The module is meant > to hide these database implementation details from its users. > > But, minimally, the module needs to have some configuration details > to know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. To pass in configuration to a module, you have basically two choices: - Use the command line and sys.argv - Put the stuff in a file of some sort. I would not recommend the first option, because it ultimately ends up as an abomination such as we can see with gcc, where it has spawned over elaborate systems of makefiles to tell it how to do something - so we are back at a file, in any event. So the questions become - how do you organise the file, and how do you get hold of the stuff in it. You have been pointed to configparser, and others. You can also do a simple thing, as a module gets executed upon import. If your parameters are simple, this may be the easiest way of doing it, namely to just write the bunch of them down, all in a configuration.py file, like this: P1 = 7 P2 = 42 alloweds = [john,mary,sally] Then where you want to use them, you do the following: import configuration as cf if cf.P1 > 3: do something if suspect in cf.alloweds: let user in else: print "Go away you fiend from the nether regions" sys.stdout.flush() sys.exit() if not cf.P2 == 42: print "The end of the universe has arrived - hide!" while True: pass Do not forget that you can put a dictionary there to handle more complex stuff. You can also get fancy and put whole classes of data into such a file. In what I do, I have never felt the need for that. You get the drift (I hope) - Hendrik From simon at brunningonline.net Sun Jun 28 05:04:25 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sun, 28 Jun 2009 10:04:25 +0100 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <8c7f10c60906280204o2c21df34r334129c69ce3299c@mail.gmail.com> 2009/6/27 sato.photo at gmail.com : > Thank you for all of the links and advice. > > What do I want to learn Python for? > > Again, pardon me for my lack of relevant information. ?I am also a > journalist (an out of work one at the moment, like so many others) and > I feel that learning python could be useful for computer assisted > reporting, that is, utilizing databases, creating interactive maps and > the like. > > http://chicago.everyblock.com/crime/ That's a Python site! As a journalist, you might also be interested in - The Guardian, a UK national newspaper, quickly wrote and deployed a Python application to allow their readers to cooperate in the massive manual task of analysing MPs' expenses receipts, looking for ill-doing. -- Cheers, Simon B. From pavlovevidence at gmail.com Sun Jun 28 05:39:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Jun 2009 02:39:47 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <14b07411-5cda-48d9-8848-eeed216f856e@e21g2000yqb.googlegroups.com> On Jun 27, 4:33?am, Jure Erzno?nik wrote: > When you write code like > config = {"home" : "/home/test"} > config["user1"] = config["home"] + "/user1" > > config["user1"] isn't stored in memory as config["home"] + "/user1", > but as a concatenated string ("/home/test/user1"), composed of both > those strings. The reference to original composing strings is lost at > the moment the expression itself is evaluated to be inserted into the > dict. > There's no compiler / interpreter that would do this any other way. At > least not that I know of. It's called Lazy Evaluation and there are a bunch of tools that do it implicitly and automatically. Off hand I can think of make and Mathematica. I know there are some functional programming languages that do it as well. Also there are languages like Lisp that have strong syntactic support for lazy evaluation although it's not done implicitly. Not Python, though. > So best suggestion would be to simply do an object that would parse > strings before returning them. In the string itself, you can have > special blocks that tell your parser that they are references to other > objects. [snip example] > But you sure better not expect this to be included in language syntax. > It's a pretty special case. That is a very good suggestion that might be a better solution to the OP's problem. You are right that is would require a bit of work. Python does have string interpolation methods that can do keyword-based substitution, but they don't work recursively, and it's not straightforward to get it to work recursively. Carl Banks From pavlovevidence at gmail.com Sun Jun 28 05:57:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Jun 2009 02:57:50 -0700 (PDT) Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: On Jun 27, 4:40?am, Duncan Booth wrote: > Thomas Lehmann wrote: > > Hi! > > > In C++, programming STL you will use the insert method which always > > provides a position and a flag which indicates whether the position > > results from a new insertion or an exisiting element. Idea is to have > > one search only. > > > > > if ?data.has_key(key): > > ? ?value = data[key] > > > > > But this does mean (does it?) that the dictionary is searched two > > times! If so, can somebody show me how to do this in one step? > > That code actually does 3 dictionary lookups and creates a temporary > object: the first lookup is to find the 'has_key' method, then it has to > bind the method to data which involves creating a 'built-in method' object > and then it calls it. Only then do you get the two lookups you expected. > > Replacing your code with: > > ? ?if key in data: value = data[key] > > reduces the overhead to two dictionary lookups, no temporary objects or > function calls. > > The suggested alternative: > > ? ?value = data.get(key, None) > > also has two dictionary lookups: one to find the 'get' method and one to > find the key, but as in the first case it also has the overhead of binding > the method and then calling it. > > In other words the get method is often the clearest (and therefore best) > way to write the code, but if performance matters do a check using the 'in' > operator (or if you know the key lookup will fail only very rarely consider > using try..except). It's not that simple. Attribute lookups are fast because the keys are interned strings. However, the key lookup in the data object might be an object where hash and compare operations are much slower. So it's not valid in general to equate the two lookups. Unless you know that your dict keys are going to be really fast like interned strings it makes sense to minimize dict lookups. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:07:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:07:38 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> Message-ID: <00631bb9$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 23:52:02 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Depends on how you define "discontinuous". > > The mathematical way, of course. For any epsilon > 0, etc. I thought we were talking about discontinuities in *nature*, not in mathematics. There's no "of course" about it. >> Catastrophe theory is full of discontinuous changes in state. Animal >> (by which I include human) behaviour often displays discontinuous >> changes. So does chemistry: one minute the grenade is sitting there, >> stable as can be, the next it's an expanding cloud of gas and metal >> fragments. > > If that transition from grenade to gas cloud takes a minute (or even a > femtosecond), it's not a mathematical discontinuity. In mathematics, you can cut up a pea and reassemble it into a solid sphere the size of the Earth. Try doing that with a real pea. Mathematics is an abstraction. It doesn't necessarily correspond to reality. Assuming that reality "really is" the mathematical abstraction underneath is just an assumption, and not one supported by any evidence. > The other examples work out about the same way. Quantum phenomenon are actual mathematical discontinuities, or at least they can be, e.g. electron levels in an atom. Even when they are continuous, they're continuous because they consist of an infinity of discontinuous levels infinitesimally far apart. -- Steven From sanal.vikram at gmail.com Sun Jun 28 06:09:20 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sun, 28 Jun 2009 03:09:20 -0700 (PDT) Subject: to use unicode strings only References: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> Message-ID: <75bb932d-38cc-40b5-9489-6f807715b405@e21g2000yqb.googlegroups.com> On Jun 27, 9:44?pm, Benjamin Peterson wrote: > Gaudha gmail.com> writes: > > > And Peter, I tried importing the __future__ module. It's also not > > working... > > How so? Sorry guys, __future__ module is working excellent :-). I had some bad coding somewhere else, just fixed it. Anyway, thank you for all... From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:17:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:17:52 GMT Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> <87bpo8vjjz.fsf@benfinney.id.au> Message-ID: <00631e1f$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 18:39:28 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: >> >> > (Even if you don't want to receive email, could you please give your >> > actual name in the ?From? field instead of just initials? It makes >> > conversation less confusing.) >> >> Some people prefer to be known by their initials. > > Some people prefer to spend their volunteer time conversing with people > who don't just use initials or pseudonyms. And some people refuse to use words with the letter "E" in them. Just out of curiosity, how are you supposed to recognise people who are using pseudonyms? For all we know, "Steven D'Aprano" might be a pseudonym -- you haven't seen my birth certificate. I noticed that you ignored my comment about people's whose legal names are initials. >> There's nothing confusing about addressing somebody by their initials. > > I find it much less confusing to converse with someone if I can keep > straight who they are, and names work better than initials for that > purpose. Really? Can you cope with two-letter names like Jo, Li, Ed, Cy, or even Wm (a variant of William), or are you about to start insisting that people choose three-letter names? If you can cope with Al, Di or Mo, then what's the difference between those names and two-letter initials? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:23:50 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:23:50 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <00631f86$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 02:57:50 -0700, Carl Banks wrote: > So it's not valid in general to equate the two lookups. Unless you know > that your dict keys are going to be really fast like interned strings it > makes sense to minimize dict lookups. Or to stop making assumptions about what's fast and what's not fast, and actually profile the code and see where the hold-ups are. "Dear Pythonistas, I have a program that runs for six hours performing some wickedly complicated calculations on data extracted from a dict. The dictionary lookups take five and a half seconds, how can I speed them up?" *wink* -- Steven From http Sun Jun 28 06:28:51 2009 From: http (Paul Rubin) Date: 28 Jun 2009 03:28:51 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7x3a9kfy8s.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I thought we were talking about discontinuities in *nature*, not in > mathematics. There's no "of course" about it. IIRC we were talking about fractals, which are a topic in mathematics. This led to some discussion of mathematical continuity, and the claim that mathematical discontinuity doesn't appear to occur in nature (and according to some, it shouldn't occur in mathematics either). > In mathematics, you can cut up a pea and reassemble it into a solid > sphere the size of the Earth. Try doing that with a real pea. That's another example of a mathematical phenomenon that doesn't occur in nature. What are you getting at? > Quantum phenomenon are actual mathematical discontinuities, or at > least they can be, e.g. electron levels in an atom. I'm sure you know more physics than I do, but I was always taught that observables (like electron levels) were eigenvalues of underlying continuous operators. That the eigenvalues are discrete just means some continuous function has multiple roots that are discrete. There is a theorem (I don't know the proof or even the precise statement) that if quantum mechanics has the slightest amount of linearity, then it's possible in principle to solve NP-hard problems in polynomial time with quantum computers. So I think it is treated as perfectly linear. From simone.perone at gmail.com Sun Jun 28 07:05:02 2009 From: simone.perone at gmail.com (sgperone) Date: Sun, 28 Jun 2009 04:05:02 -0700 (PDT) Subject: PyQT QWebView Local swf file not loading Message-ID: Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange behaviour: inside a widget i have this code: self.view = QWebView(self) self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True) that's i'm creating a QWebView instance with PluginsEnabled flag on. next lines are: Case 1 =================================================== f = QtCore.QUrl("http://www.example.com/myflashfile.swf") print f self.view.load(f) in this case f == True and the swf file is showing correctly inside the widget Case 2 =================================================== f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf") print f self.view.load(f) in this case f == False and no swf clip showed up. Really weird... if I use a local html file with code to embed the local swf file everything is working. So, it seems that: It is impossible to load a local swf file directly into QWebView without a "wrapper" html code. Anyone experienced the same issue ? Thanks From simone.perone at gmail.com Sun Jun 28 07:10:05 2009 From: simone.perone at gmail.com (sgperone) Date: Sun, 28 Jun 2009 04:10:05 -0700 (PDT) Subject: PyQT QWebView Local swf file not loading References: Message-ID: <332a45a5-cb9b-4a61-b975-9e04c8055196@z9g2000yqi.googlegroups.com> On 28 Giu, 13:05, sgperone wrote: > Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange > behaviour: > > inside a widget i have this code: > > self.view = QWebView(self) > self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True) > > that's i'm creating a QWebView instance with PluginsEnabled flag on. > > next lines are: > > Case 1 > =================================================== > f = QtCore.QUrl("http://www.example.com/myflashfile.swf") > print f > self.view.load(f) > > in this case f == True and the swf file is showing correctly inside > the widget > > Case 2 > =================================================== > f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf") > print f Correction: =================================================== it's not "f" that is True or False, but : inside code i have: self.connect(self.view,QtCore.SIGNAL("loadFinished (bool)"),self.loadFinished) and def loadFinished(self,bool): print bool > self.view.load(f) > > in this case f == False and no swf clip showed up. > > Really weird... if I use a local html file with code to embed the > local swf file everything is working. > > So, it seems that: > > It is impossible to load a local swf file directly into QWebView > without a "wrapper" html code. > > Anyone experienced the same issue ? > > Thanks From martin at v.loewis.de Sun Jun 28 08:36:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 28 Jun 2009 14:36:37 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <4a4763d5$0$307$9b622d9e@news.freenet.de> > That's a significant improvement. It still decodes os.environ and sys.argv > before you have a chance to call sys.setfilesystemencoding(), but it > appears to be recoverable (with some effort; I can't find any way to re-do > the encoding without manually replacing the surrogates). See PEP 383. > However, sys.std{in,out,err} are still created as text streams, and AFAICT > there's nothing you can do about this from within your code. That's intentional, and not going to change. You can access the underlying byte streams if you want to, as you could already in 3.0. Regards, Martin P.S. Please identify yourself on this newsgroup. From aahz at pythoncraft.com Sun Jun 28 08:38:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 05:38:34 -0700 Subject: Python and journalism (was Re: Beginning with Python; the right choice?) References: Message-ID: In article , sato.photo at gmail.com wrote: > >What do I want to learn Python for? > >Again, pardon me for my lack of relevant information. I am also a >journalist (an out of work one at the moment, like so many others) and >I feel that learning python could be useful for computer assisted >reporting, that is, utilizing databases, creating interactive maps and >the like. You're absolutely right! You're also not the first person to have that realization: http://www.time.com/time/business/article/0,8599,1902202,00.html http://www.ojr.org/ojr/stories/060605niles/ http://www.medill.northwestern.edu/admissions/page.aspx?id=58645 (Probably you already knew this, but I'm posting for other people.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From martin at v.loewis.de Sun Jun 28 08:41:04 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 28 Jun 2009 14:41:04 +0200 Subject: encoding problem In-Reply-To: <8522bfaf-7efc-4ebb-a63a-b5ecc73e236d@35g2000pry.googlegroups.com> References: <85e9957b-ed0a-4983-8427-46ab520c4a4a@s9g2000prm.googlegroups.com> <6r1m72Ffb5kpU3@mid.uni-berlin.de> <8522bfaf-7efc-4ebb-a63a-b5ecc73e236d@35g2000pry.googlegroups.com> Message-ID: <4a4764e0$0$307$9b622d9e@news.freenet.de> > That is the reason why we have to explicitly declare a encoding as > long as we have non-ASCII in source. True - but it doesn't have to be the "correct" encoding. If you declared your source as latin-1, the effect is the same on byte string literals, but not on Unicode literals. In that sense, the encoding declaration only "matters" for Unicode literals (of course, it also matters for source editors, and in a few other places). Regards, Martin From python.list at tim.thechases.com Sun Jun 28 09:45:08 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Jun 2009 08:45:08 -0500 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: <24239603.post@talk.nabble.com> References: <24239603.post@talk.nabble.com> Message-ID: <4A4773E4.3030800@tim.thechases.com> iceangel89 wrote: > i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used > .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python > now (for desktop apps since its open source and just want to try what it > offers, but will like to know what good it has for web development also) > > somethings i am curious abt (that came to my mind) now are: gvn ur pnchnt 4 illgble shrthnd, u mgt prefr perl ovr pythn. or prhps u wnt asmbly lang. XOR EAX, EAX; MOV [EAX], EAX > - performance More than sufficient for my needs (scripting, web apps, most GUI apps) -- you can always drop to optimized C/C++ functions/modules if needed or use custom modules like numpy/numeric/etc for processor-intense work. > - ide to use? http://lmgtfy.com/?q=python+ide I use vim. Others use emacs. Some use Eclipse. Some use WingIDE. Etc, etc, etc. Try 'em each and see what you like > - how do i design GUI for windows app? http://lmgtfy.com/?q=python+gui Lots of options -- choose the one you like. -tkc From nuffnough at gmail.com Sun Jun 28 09:45:49 2009 From: nuffnough at gmail.com (Nuff Nuff) Date: Sun, 28 Jun 2009 06:45:49 -0700 (PDT) Subject: Running a script from a windows right click menu..? Message-ID: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> I wrote a little script that affects a bunch of files in the folder that it is run in. Now what I want to do is to make it run from the right click menu but I don't know how. Would you give me an example script that will simply print the woriking directory, and show me how to add that to the right click menu in windows explorer? TIA Nuffi From esj at harvee.org Sun Jun 28 10:09:21 2009 From: esj at harvee.org (Eric S. Johansson) Date: Sun, 28 Jun 2009 10:09:21 -0400 Subject: pep 8 constants In-Reply-To: <49a50517$0$3567$426a74cc@news.free.fr> References: <49a50517$0$3567$426a74cc@news.free.fr> Message-ID: <4A477991.4050109@harvee.org> Bruno Desthuilliers wrote: > Brendan Miller a ?crit : >> PEP 8 doesn't mention anything about using all caps to indicate a >> constant. >> >> Is all caps meaning "don't reassign this var" a strong enough >> convention to not be considered violating good python style? I see a >> lot of people using it, but I also see a lot of people writing >> non-pythonic code... so I thought I'd see what the consensus is. > > Most - if not all - of the python code I've seen so far used this > convention, and I always used (and respected) it myself. I reject this convention because any form of caps significantly increases vocal load for disabled programmers using speech recognition through extra utterances, and degraded recognition. In my experience, language conventions like this come about because most geeks generally don't think about disabled programmers and the effect that language changes will have on them. I deal by trying to build my accessibility tools as best I can but handling stuff like pep 8 is hard because it requires a smart environment that know the meanings of every class, method. or variable so it can lead the grammar in the right direction. ThenWenUHve names like this. Cr** in a stick. you might as well take a gun to my wrists because that is how much pain I will be in typing them. again need *good* editor support for English to name translation. so I reject pep 8 because I have no voice safe alternative From aahz at pythoncraft.com Sun Jun 28 11:00:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:00:23 -0700 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: In article <0qec45lho8lkng4n20sb1ad4eguat675pb at 4ax.com>, Angus Rodgers wrote: > >Partly as an educational exercise, and partly for its practical >benefit, I'm trying to pick up a programming project from where >I left off in 2001. It implemented in slightly generalised form >the "buffer pair" scheme for lexical analysis described on pp. >88--92 of Aho et al., /Compilers: Principles, Techniques and >Tools/ (1986). (I'm afraid I don't have a page reference for the >2007 second edition. Presumably it's also in Knuth somewhere.) > > [...] > >Does some Python library already provide some functionality like >this? (It's enough to do it with nblocks = 2, as in Aho et al.) Not AFAIK, but there may well be something in the recipes or PyPI; have you tried searching them? >If not, is this a reasonable thing to try to program in Python? Definitely! It should be lots easier to program this with Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From news123 at free.fr Sun Jun 28 11:03:07 2009 From: news123 at free.fr (News123) Date: Sun, 28 Jun 2009 17:03:07 +0200 Subject: creating garbage collectable objects (caching objects) Message-ID: <4a47862b$0$31117$426a74cc@news.free.fr> Hi. I started playing with PIL. I'm performing operations on multiple images and would like compromise between speed and memory requirement. The fast approach would load all images upfront and create then multiple result files. The problem is, that I do not have enough memory to load all files. The slow approach is to load each potential source file only when it is needed and to release it immediately after (leaving it up to the gc to free memory when needed) The question, that I have is whether there is any way to tell python, that certain objects could be garbage collected if needed and ask python at a later time whether the object has been collected so far (image has to be reloaded) or not (image would not have to be reloaded) # Fastest approach: imgs = {} for fname in all_image_files: imgs[fname] = Image.open(fname) for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): img = do_somethingwith(img,imgs[img_file]) img.save() # Slowest approach: for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): src_img = Image.open(img_file) img = do_somethingwith(img,src_img) img.save() # What I'd like to do is something like: imgs = GarbageCollectable_dict() for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): if src_img in imgs: # if 'm lucke the object is still there src_img = imgs[img_file] else: src_img = Image.open(img_file) img = do_somethingwith(img,src_img) img.save() Is this possible? Thaks in advance for an answer or any other ideas of how I could do smart caching without hogging all the system's memory From aahz at pythoncraft.com Sun Jun 28 11:03:21 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:03:21 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: In article , Tim Chase wrote: > >> - how do i design GUI for windows app? > >http://lmgtfy.com/?q=python+gui This is the first time I've tried LMGTFY, and it seems to be a piece of trash that requires JavaScript. I suggest that lmgtfy.com not be considered a standard part of the Python community. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jfabiani at yolo.com Sun Jun 28 11:06:33 2009 From: jfabiani at yolo.com (John Fabiani) Date: Sun, 28 Jun 2009 08:06:33 -0700 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: Casey Hawthorne wrote: >>So, what *does* Guido want in a GUI toolkit for Python? > > I saw a talk by a school teacher on pyFLTK: GUI programming made easy. > > On another note: I#: Groovy makes it easy to tie into the Java Swing > GUI, so if Python could do that, with the added complication being the > user would need a JVM. > > -- > Regards, > Casey Dabo makes it transparent when it come to tying the data to the widget. Based on the wxPython. So it meets Guido's requirements. From benjamin at python.org Sun Jun 28 11:22:15 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 15:22:15 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > All in all, Python 3.x still has a long way to go before it will be > suitable for real-world use. Such as? From Scott.Daniels at Acm.Org Sun Jun 28 11:41:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 28 Jun 2009 08:41:47 -0700 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Nobody wrote: > On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: > > That's a significant improvement.... > All in all, Python 3.x still has a long way to go before it will be > suitable for real-world use. Fortunately, I have assiduously avoided the real word, and am happy to embrace the world from our 'bot overlords. Congratulations on another release from the hydra-like world of multi-head development. --Scott David Daniels Scott.Daniels at Acm.Org From p.f.moore at gmail.com Sun Jun 28 11:45:51 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 28 Jun 2009 16:45:51 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4a4763d5$0$307$9b622d9e@news.freenet.de> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> 2009/6/28 "Martin v. L?wis" : >> However, sys.std{in,out,err} are still created as text streams, and AFAICT >> there's nothing you can do about this from within your code. > > That's intentional, and not going to change. You can access the > underlying byte streams if you want to, as you could already in 3.0. I had a quick look at the documentation, and couldn't see how to do this. It's the first time I'd read the new IO module documentation, so I probably missed something obvious. Could you explain how I get the byte stream underlying sys.stdin? (That should give me enough to find what I was misunderstanding in the docs). Thanks, Paul. From aahz at pythoncraft.com Sun Jun 28 11:52:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:52:11 -0700 Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> <87bpo8vjjz.fsf@benfinney.id.au> Message-ID: In article <87bpo8vjjz.fsf at benfinney.id.au>, Ben Finney wrote: >Steven D'Aprano writes: >> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: >>> >>> (Even if you don't want to receive email, could you please give your >>> actual name in the ???From??? field instead of just initials? It makes >>> conversation less confusing.) >> >> Some people prefer to be known by their initials. > >Some people prefer to spend their volunteer time conversing with people >who don't just use initials or pseudonyms. Bully for you! Just don't bully people who don't follow your preferred naming system. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From twirlip at bigfoot.com Sun Jun 28 12:03:59 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sun, 28 Jun 2009 17:03:59 +0100 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: On 28 Jun 2009 08:00:23 -0700, aahz at pythoncraft.com (Aahz) wrote: >In article <0qec45lho8lkng4n20sb1ad4eguat675pb at 4ax.com>, >Angus Rodgers wrote: >> >>Partly as an educational exercise, and partly for its practical >>benefit, I'm trying to pick up a programming project from where >>I left off in 2001. It implemented in slightly generalised form >>the "buffer pair" scheme for lexical analysis described on pp. >>88--92 of Aho et al., /Compilers: Principles, Techniques and >>Tools/ (1986). (I'm afraid I don't have a page reference for the >>2007 second edition. Presumably it's also in Knuth somewhere.) >> >> [...] >> >>Does some Python library already provide some functionality like >>this? (It's enough to do it with nblocks = 2, as in Aho et al.) > >Not AFAIK, but there may well be something in the recipes or PyPI; have >you tried searching them? Searching for "buffer" at (which I didn't know about) gives quite a few hits (including reflex 0.1, "A lightweight regex-based lexical scanner library"). By "recipes", do you mean (also new to me)? There is certainly a lot of relevant code there (e.g. "Recipe 392150: Buffered Stream with Multiple Forward-Only Readers"), which I can try to learn from, even if I can't use it directly. Thanks! -- Angus Rodgers From piet at cs.uu.nl Sun Jun 28 12:09:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 28 Jun 2009 18:09:47 +0200 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: >>>>> Paul Moore (PM) wrote: >PM> 2009/6/28 "Martin v. L?wis" : >>>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>>> there's nothing you can do about this from within your code. >>> >>> That's intentional, and not going to change. You can access the >>> underlying byte streams if you want to, as you could already in 3.0. >PM> I had a quick look at the documentation, and couldn't see how to do >PM> this. It's the first time I'd read the new IO module documentation, so >PM> I probably missed something obvious. Could you explain how I get the >PM> byte stream underlying sys.stdin? (That should give me enough to find >PM> what I was misunderstanding in the docs). http://docs.python.org/3.1/library/sys.html#sys.stdin -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From lists at cheimes.de Sun Jun 28 12:09:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 28 Jun 2009 18:09:57 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> Message-ID: <4A4795D5.4070304@cheimes.de> Paul Moore schrieb: > 2009/6/28 "Martin v. L?wis" : >>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>> there's nothing you can do about this from within your code. >> That's intentional, and not going to change. You can access the >> underlying byte streams if you want to, as you could already in 3.0. > > I had a quick look at the documentation, and couldn't see how to do > this. It's the first time I'd read the new IO module documentation, so > I probably missed something obvious. Could you explain how I get the > byte stream underlying sys.stdin? (That should give me enough to find > what I was misunderstanding in the docs). You've missed the most obvious place to look for the feature -- the documentation of sys.stdin :) http://docs.python.org/3.0/library/sys.html#sys.stdin >>> import sys >>> sys.stdin >>> sys.stdin.buffer >>> sys.stdin.read(1) '\n' >>> sys.stdin.buffer.read(1) b'\n' Christian From lists at cheimes.de Sun Jun 28 12:09:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 28 Jun 2009 18:09:57 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> Message-ID: <4A4795D5.4070304@cheimes.de> Paul Moore schrieb: > 2009/6/28 "Martin v. L?wis" : >>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>> there's nothing you can do about this from within your code. >> That's intentional, and not going to change. You can access the >> underlying byte streams if you want to, as you could already in 3.0. > > I had a quick look at the documentation, and couldn't see how to do > this. It's the first time I'd read the new IO module documentation, so > I probably missed something obvious. Could you explain how I get the > byte stream underlying sys.stdin? (That should give me enough to find > what I was misunderstanding in the docs). You've missed the most obvious place to look for the feature -- the documentation of sys.stdin :) http://docs.python.org/3.0/library/sys.html#sys.stdin >>> import sys >>> sys.stdin >>> sys.stdin.buffer >>> sys.stdin.read(1) '\n' >>> sys.stdin.buffer.read(1) b'\n' Christian From p.f.moore at gmail.com Sun Jun 28 12:18:37 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 28 Jun 2009 17:18:37 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4A4795D5.4070304@cheimes.de> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> <4A4795D5.4070304@cheimes.de> Message-ID: <79990c6b0906280918r7a88480al5a1a795293a0cac9@mail.gmail.com> 2009/6/28 Christian Heimes : > Paul Moore schrieb: >> I had a quick look at the documentation, and couldn't see how to do >> this. It's the first time I'd read the new IO module documentation, so >> I probably missed something obvious. Could you explain how I get the >> byte stream underlying sys.stdin? (That should give me enough to find >> what I was misunderstanding in the docs). > > You've missed the most obvious place to look for the feature -- the > documentation of sys.stdin :) > > http://docs.python.org/3.0/library/sys.html#sys.stdin > >>>> import sys >>>> sys.stdin > >>>> sys.stdin.buffer > >>>> sys.stdin.read(1) > > '\n' >>>> sys.stdin.buffer.read(1) Thanks. Like you say, the obvious place I didn't think of... :-) (I'd have experimented, but this PC doesn't have Python 3 installed at the moment :-() The "buffer" attribute doesn't seem to be documented in the docs for the io module. I'm guessing that the TextIOBase class should have a note that you get at the buffer through the "buffer" attribute? Paul. From aahz at pythoncraft.com Sun Jun 28 12:26:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 09:26:23 -0700 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: In article , Angus Rodgers wrote: > >By "recipes", do you mean > (also new to me)? Yup! You may also want to pick up the edited recipes in the Python Cookbook. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From nobody at nowhere.com Sun Jun 28 12:27:52 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 17:27:52 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 15:22:15 +0000, Benjamin Peterson wrote: > Nobody nowhere.com> writes: >> All in all, Python 3.x still has a long way to go before it will be >> suitable for real-world use. > > Such as? Such as not trying to shoe-horn every byte string it encounters into Unicode. Some of them really are *just* byte strings. From no.email at please.post Sun Jun 28 13:22:29 2009 From: no.email at please.post (kj) Date: Sun, 28 Jun 2009 17:22:29 +0000 (UTC) Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: In <87fxdlujds.fsf at benfinney.id.au> Ben Finney writes: >(Even if you don't want to receive email, could you please give your >actual name in the ???From??? field instead of just initials? It makes >conversation less confusing.) I don't know why, but for as long as I can remember everyone calls me kj, even my mom. My name is Keaweikekahiali??iokamoku Jallalahwallalruwalpindi kj From benjamin at python.org Sun Jun 28 13:24:11 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 17:24:11 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > Such as not trying to shoe-horn every byte string it encounters into > Unicode. Some of them really are *just* byte strings. You're certainly allowed to convert them back to byte strings if you want. From tjreedy at udel.edu Sun Jun 28 13:31:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 13:31:50 -0400 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Nobody wrote: > On Sun, 28 Jun 2009 15:22:15 +0000, Benjamin Peterson wrote: > >> Nobody nowhere.com> writes: >>> All in all, Python 3.x still has a long way to go before it will be >>> suitable for real-world use. >> Such as? > > Such as not trying to shoe-horn every byte string it encounters into > Unicode. Some of them really are *just* byte strings. Let's ignore the disinformation. So false it is hardly worth refuting. From benjamin at python.org Sun Jun 28 13:34:34 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 17:34:34 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> <4A4795D5.4070304@cheimes.de> <79990c6b0906280918r7a88480al5a1a795293a0cac9@mail.gmail.com> Message-ID: Paul Moore gmail.com> writes: > The "buffer" attribute doesn't seem to be documented in the docs for > the io module. I'm guessing that the TextIOBase class should have a > note that you get at the buffer through the "buffer" attribute? Good point. I've now documented it, and the "raw" attribute of BufferedIOBase. From benjamin.kaplan at case.edu Sun Jun 28 13:51:08 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 28 Jun 2009 13:51:08 -0400 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: References: <24239603.post@talk.nabble.com> Message-ID: On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote: > In article , > Tim Chase ? wrote: >> >>> - how do i design GUI for windows app? >> >>http://lmgtfy.com/?q=python+gui > > This is the first time I've tried LMGTFY, and it seems to be a piece of > trash that requires JavaScript. ?I suggest that lmgtfy.com not be > considered a standard part of the Python community. It's not a standard part of the python community. It stands for "let me google that for you" and it's a slightly more polite way of saying STFW. It's just an animation of typing the search term in a Google-like search page and clicking the search button. Then it says "was that so hard" and redirects you to the Google search results for that term. > -- > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sun Jun 28 14:10:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 14:10:23 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a47862b$0$31117$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) See the weakref module. But note that in CPython, objects are collected as soon as there all no normal references, not when 'needed'. > > > # Fastest approach: > imgs = {} > for fname in all_image_files: > imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > img = do_somethingwith(img,imgs[img_file]) > img.save() > > > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > if src_img in imgs: # if 'm lucke the object is still there > src_img = imgs[img_file] > else: > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > Is this possible? From sajmikins at gmail.com Sun Jun 28 14:19:26 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 28 Jun 2009 11:19:26 -0700 (PDT) Subject: creating garbage collectable objects (caching objects) References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <1c0621d9-c38b-4117-8bf9-0b4b8bf0ba15@r10g2000yqa.googlegroups.com> On Jun 28, 11:03?am, News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) > > # Fastest approach: > imgs = {} > for fname in all_image_files: > ? ? imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? img = do_somethingwith(img,imgs[img_file]) > ? ? img.save() > > # Slowest approach: > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? src_img = Image.open(img_file) > ? ? ? ? img = do_somethingwith(img,src_img) > ? ? img.save() > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? if src_img in imgs: # if 'm lucke the object is still there > ? ? ? ? ? ? ? ? src_img = imgs[img_file] > ? ? ? ? else: > ? ? ? ? ? ? ? ? src_img = Image.open(img_file) > ? ? ? ? img = do_somethingwith(img,src_img) > ? ? img.save() > > Is this possible? > > Thaks in advance for an answer or any other ideas of > how I could do smart caching without hogging all the system's > memory Maybe I'm just being thick today, but why would the "slow" approach be slow? The same amount of I/O and processing would be done either way, no? Have you timed both methods? That said, take a look at the weakref module Terry Reedy already mentioned, and maybe the gc (garbage collector) module too (although that might just lead to wasting a lot of time fiddling with stuff that the gc is supposed to handle transparently for you in the first place.) From shr at basushr.net Sun Jun 28 14:31:00 2009 From: shr at basushr.net (Shrutarshi Basu) Date: Sun, 28 Jun 2009 14:31:00 -0400 Subject: Flexible warning system Message-ID: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> I'm writing a Python package where I have an underlying object model that is manipulated by a runtime control layer and clients that interface with this runtime. As I'm developing this i'm realizing that there are going to be a number of places where the runtime might affect the object model in ways that might not be immediately obvious to the user. I would like to have some sort of warning system where the runtime can raise a warning and then the clients can 'catch' those warnings and display them as they want to. Is there some sort of a system that will operates like that or will I have to roll my own? If I do need to roll my own, any ideas on how I should go about it? I know that there is a warning module, but it seems to that all outputs go to standard out which isn't what I want. Thanks, Basu Shrutarshi Basu Computer Science, Electrical and Computer Engineering, Lafayette College, The ByteBaker -- http://bytebaker.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sun Jun 28 14:35:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 28 Jun 2009 15:35:45 -0300 Subject: Running a script from a windows right click menu..? References: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> Message-ID: En Sun, 28 Jun 2009 10:45:49 -0300, Nuff Nuff escribi?: > I wrote a little script that affects a bunch of files in the folder > that it is run in. > > Now what I want to do is to make it run from the right click menu but > I don't know how. > > Would you give me an example script that will simply print the > woriking directory, and show me how to add that to the right click > menu in windows explorer? In the Windows registry, add a new key under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell Make its default value the item text you want in the context menu. Add a new key under it, "command", and make its default value the command line you want to execute. Will look like this: "path to python.exe" "path to your script.py" %1 %* See http://msdn.microsoft.com/en-us/library/dd807139(VS.85).aspx for more details -- Gabriel Genellina From aahz at pythoncraft.com Sun Jun 28 14:43:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 11:43:19 -0700 Subject: [RELEASED] Python 3.1 final References: Message-ID: In article , Benjamin Peterson wrote: >Nobody nowhere.com> writes: >> >> Such as not trying to shoe-horn every byte string it encounters into >> Unicode. Some of them really are *just* byte strings. > >You're certainly allowed to convert them back to byte strings if you want. Yes, but do you get back the original byte strings? Maybe I'm missing something, but my impression is that this is still an issue for the email module as well as command-line arguments and environment variables. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sun Jun 28 14:45:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 11:45:06 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: In article , Benjamin Kaplan wrote: >On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote: >> In article , >> Tim Chase =A0 wrote: >>> >>>> - how do i design GUI for windows app? >>> >>>http://lmgtfy.com/?q=3Dpython+gui >> >> This is the first time I've tried LMGTFY, and it seems to be a piece of >> trash that requires JavaScript. =A0I suggest that lmgtfy.com not be >> considered a standard part of the Python community. > >It's not a standard part of the python community. It stands for "let >me google that for you" and it's a slightly more polite way of saying >STFW. > >It's just an animation of typing the search term in a Google-like >search page and clicking the search button. Then it says "was that so >hard" and redirects you to the Google search results for that term. Perhaps I was unclear: I already knew what LMGTFY stands for, and I think that using a site that requires JavaScript is anti-social. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From enleverLesX_XXmcX at XmclavXeauX.com Sun Jun 28 14:50:03 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Sun, 28 Jun 2009 20:50:03 +0200 Subject: Running a script from a windows right click menu..? References: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> Message-ID: <4a47bb5d$0$17099$ba4acef3@news.orange.fr> Bonsoir ! Un exemple l?: http://www.mclaveau.com/grimoire/bleu.html#999 @-salutations -- MCI From davea at ieee.org Sun Jun 28 14:51:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 28 Jun 2009 14:51:31 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a47862b$0$31117$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <4A47BBB3.3050704@ieee.org> News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) > > > # Fastest approach: > imgs = {} > for fname in all_image_files: > imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > img = do_somethingwith(img,imgs[img_file]) > img.save() > > > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > if src_img in imgs: # if 'm lucke the object is still there > src_img = imgs[img_file] > else: > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > Is this possible? > > Thaks in advance for an answer or any other ideas of > how I could do smart caching without hogging all the system's > memory > > > You don't say what implementation of Python, nor on what OS platform. Yet you're asking how to influence that implementation. In CPython, version 2.6 (and probably most other versions, but somebody else would have to chime in) an object is freed as soon as its reference count goes to zero. So the garbage collector is only there to catch cycles, and it runs relatively infrequently. So, if you keep a reference to an object, it'll not be freed. Theoretically, you can use the weakref module to keep a reference without inhibiting the garbage collection, but I don't have any experience with the module. You could start by studying its documentation. But probably you want a weakref.WeakValueDictionary. Use that in your third approach to store the cache. If you're using Cython or Jython, or one of many other implementations, the rules will be different. The real key to efficiency is usually managing locality of reference. If a given image is going to be used for many output files, you might try to do all the work with it before going on to the next image. In that case, it might mean searching all_creation_rules for rules which reference the file you've currently loaded, measurement is key. From benjamin at python.org Sun Jun 28 15:21:49 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 19:21:49 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Aahz pythoncraft.com> writes: > Yes, but do you get back the original byte strings? Maybe I'm missing > something, but my impression is that this is still an issue for the email > module as well as command-line arguments and environment variables. The email module is, yes, broken. You can recover the bytestrings of command-line arguments and environment variables. From nobody at nowhere.com Sun Jun 28 16:54:34 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 21:54:34 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: >> Yes, but do you get back the original byte strings? Maybe I'm missing >> something, but my impression is that this is still an issue for the email >> module as well as command-line arguments and environment variables. > > The email module is, yes, broken. You can recover the bytestrings of > command-line arguments and environment variables. 1. Does Python offer any assistance in doing so, or do you have to manually convert the surrogates which are generated for unrecognised bytes? 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? Most of the issues can be worked around by calling sys.setfilesystemencoding('iso-8859-1') at the start of the program, but sys.argv and os.environ have already been converted by this point. From thomas.robitaille at gmail.com Sun Jun 28 17:00:46 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Sun, 28 Jun 2009 14:00:46 -0700 (PDT) Subject: Column types with DB API Message-ID: <24245424.post@talk.nabble.com> Hi, I'm trying to use DB API compliant database modules (psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to determine the type of each column in a table. The DB API defines cursor.description which contains information about the column names and types (once .execute() has been used to select part or all of the table), but the types are expressed as integers. I realize that these numbers can be checked against the type objects such as MySQLdb.NUMBER to determine whether a given column is a number, a date, text, etc. However, is there any way to determine what the sub-type of a column is, for example if a column is a NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or real number? Thanks in advance for any advice, Thomas -- View this message in context: http://www.nabble.com/Column-types-with-DB-API-tp24245424p24245424.html Sent from the Python - python-list mailing list archive at Nabble.com. From nobody at nowhere.com Sun Jun 28 17:01:34 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 22:01:34 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 13:31:50 -0400, Terry Reedy wrote: >>> Nobody nowhere.com> writes: >>>> All in all, Python 3.x still has a long way to go before it will be >>>> suitable for real-world use. >>> Such as? >> >> Such as not trying to shoe-horn every byte string it encounters into >> Unicode. Some of them really are *just* byte strings. > > Let's ignore the disinformation. Translation: let's ignore anything which falsifies the assumptions. > So false it is hardly worth refuting. Your copy of Trolling by Numbers must be getting pretty dog-eared by now. From benjamin at python.org Sun Jun 28 17:25:13 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 21:25:13 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: > > >> Yes, but do you get back the original byte strings? Maybe I'm missing > >> something, but my impression is that this is still an issue for the email > >> module as well as command-line arguments and environment variables. > > > > The email module is, yes, broken. You can recover the bytestrings of > > command-line arguments and environment variables. > > 1. Does Python offer any assistance in doing so, or do you have to > manually convert the surrogates which are generated for unrecognised bytes? fs_encoding = sys.getfilesystemencoding() bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] > > 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? What's a non-invertible encoding? I can't find a reference to the term. From nikon at puffy.pl Sun Jun 28 17:26:21 2009 From: nikon at puffy.pl (Tomasz Pajor) Date: Sun, 28 Jun 2009 23:26:21 +0200 Subject: fork, threads and proper closing Message-ID: <4A47DFFD.2030400@puffy.pl> Hello, Configuration is as follows. I have a starter process which creates 3 sub processes (forks) and each of this processes creates a number of threads. Threads in that processes have semaphore so on KeyboardInterrupt without sending a sigterm to the subprocess i'm not able to close threads. Is there any work around? Can I somehow run join for the thread on keyboard interrupt? -- Best regards Tomasz Pajor From h.b.furuseth at usit.uio.no Sun Jun 28 17:34:10 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Sun, 28 Jun 2009 23:34:10 +0200 Subject: [RELEASED] Python 3.1 final References: Message-ID: Benjamin Peterson writes: >Nobody nowhere.com> writes: >> On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: >> 1. Does Python offer any assistance in doing so, or do you have to >> manually convert the surrogates which are generated for unrecognised bytes? > > fs_encoding = sys.getfilesystemencoding() > bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] > >> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? > > What's a non-invertible encoding? I can't find a reference to the term. Different ISO-2022 strings can map to the same Unicode string. Thus you can convert back to _some_ ISO-2022 string, but it won't necessarily match the original. -- Hallvard From martin at v.loewis.de Sun Jun 28 17:50:44 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 28 Jun 2009 23:50:44 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <4a47e5b4$0$30303$9b622d9e@news.freenet.de> > 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? ISO-2022 cannot be used as a system encoding. Please do read the responses I write, and please do identify yourself. Regards, Martin From rhodri at wildebst.demon.co.uk Sun Jun 28 17:58:53 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 22:58:53 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: On Sat, 27 Jun 2009 22:12:10 +0100, Benjamin Peterson wrote: > On behalf of the Python development team, I'm thrilled to announce the > first production release of Python 3.1. Why is everyone always thrilled to announce things? Why is noone ever bored to announce? :-) So PEP 378 got in then? Bleh. It's still the wrong solution, and it still makes the right solution harder to do. -- Rhodri James *-* Wildebeest Herder to the Masses From martin at v.loewis.de Sun Jun 28 18:13:34 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 29 Jun 2009 00:13:34 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: <4a47eb0e$0$30901$9b622d9e@news.freenet.de> >> On behalf of the Python development team, I'm thrilled to announce the >> first production release of Python 3.1. > > Why is everyone always thrilled to announce things? I cannot talk about everyone, but in the specific case, I suppose Benjamin was thrilled because it was his first release of a large open source software package. Knowing that you have worked so long on a single project, to see the project then finally completed, is exciting - just try it out for yourself. Regards, Martin From rhodri at wildebst.demon.co.uk Sun Jun 28 18:16:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 23:16:39 +0100 Subject: pep 8 constants In-Reply-To: <4A477991.4050109@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: On Sun, 28 Jun 2009 15:09:21 +0100, Eric S. Johansson wrote: > Bruno Desthuilliers wrote: >> Brendan Miller a ?crit : >>> PEP 8 doesn't mention anything about using all caps to indicate a >>> constant. >>> >>> Is all caps meaning "don't reassign this var" a strong enough >>> convention to not be considered violating good python style? I see a >>> lot of people using it, but I also see a lot of people writing >>> non-pythonic code... so I thought I'd see what the consensus is. >> >> Most - if not all - of the python code I've seen so far used this >> convention, and I always used (and respected) it myself. > > I reject this convention because any form of caps significantly > increases vocal > load for disabled programmers using speech recognition through extra > utterances, > and degraded recognition. Reject away, but I'm afraid you've still got some work to do to convince me that PEP 8 is more work for an SR system than any other convention. If, on the other hand you're trying to convince me that *no* convention is preferable, I'm going to laugh hollowly. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Jun 28 18:17:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 23:17:37 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4a47eb0e$0$30901$9b622d9e@news.freenet.de> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> <4a47eb0e$0$30901$9b622d9e@news.freenet.de> Message-ID: On Sun, 28 Jun 2009 23:13:34 +0100, Martin v. L?wis wrote: >>> On behalf of the Python development team, I'm thrilled to announce the >>> first production release of Python 3.1. >> >> Why is everyone always thrilled to announce things? > > I cannot talk about everyone, but in the specific case, I suppose > Benjamin was thrilled because it was his first release of a large > open source software package. Knowing that you have worked so long > on a single project, to see the project then finally completed, > is exciting - just try it out for yourself. There was a smiley at the end of that paragraph, Martin! -- Rhodri James *-* Wildebeest Herder to the Masses From gh at ghaering.de Sun Jun 28 18:21:22 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 29 Jun 2009 00:21:22 +0200 Subject: Column types with DB API In-Reply-To: <24245424.post@talk.nabble.com> References: <24245424.post@talk.nabble.com> Message-ID: Thomas Robitaille wrote: > Hi, > > I'm trying to use DB API compliant database modules > (psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to > determine the type of each column in a table. The DB API defines > cursor.description which contains information about the column names and > types (once .execute() has been used to select part or all of the table), > but the types are expressed as integers. I realize that these numbers can be > checked against the type objects such as MySQLdb.NUMBER to determine whether > a given column is a number, a date, text, etc. However, is there any way to > determine what the sub-type of a column is, for example if a column is a > NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or > real number? Not with the DB-API. You'll have to implement all this for each database separately. For some databases (like SQLite) it's even impossible. I suggest you don't bother with cursor.description at all. Depending on it doesn't harmonize with the way Python is typically used: duck typing. -- Gerhard From gh at ghaering.de Sun Jun 28 18:23:04 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 29 Jun 2009 00:23:04 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Nobody wrote: >> On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: >> >> >> That's a significant improvement.... >> All in all, Python 3.x still has a long way to go before it will be >> suitable for real-world use. > > Fortunately, I have assiduously avoided the real word, and am happy to > embrace the world from our 'bot overlords. > > Congratulations on another release from the hydra-like world of > multi-head development. +1 QOTW -- Gerhard From hanooter at gmail.com Sun Jun 28 19:13:18 2009 From: hanooter at gmail.com (mclovin) Date: Sun, 28 Jun 2009 16:13:18 -0700 (PDT) Subject: handeling very large dictionaries Message-ID: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Hello all, I need to have a dictionary of about 8 gigs (well the data it is processing is around 4gb). so naturally i am running into memory errors. So i looked around and found bsddb which acts like a dictionary object only offloads the data from the RAM to the HDD, however that only supports strings. my dictionaries hold my own class objects Is there something like it that is more flexible? From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 19:23:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 23:23:02 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> Message-ID: <0063d626$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 03:28:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> I thought we were talking about discontinuities in *nature*, not in >> mathematics. There's no "of course" about it. > > IIRC we were talking about fractals, which are a topic in mathematics. > This led to some discussion of mathematical continuity, and the claim > that mathematical discontinuity doesn't appear to occur in nature (and > according to some, it shouldn't occur in mathematics either). I would argue that it's the other way around: mathematical *continuity* doesn't occur in nature. If things look continuous, it's only because we're not looking close enough. But that depends on what you call "things"... if electron shells are real (and they seem to be) and discontinuous, and the shells are predicted/ specified by eigenvalues of some continuous function, is the continuous function part of nature or just a theoretical abstraction? >> In mathematics, you can cut up a pea and reassemble it into a solid >> sphere the size of the Earth. Try doing that with a real pea. > > That's another example of a mathematical phenomenon that doesn't occur > in nature. What are you getting at? The point is that you can't safely draw conclusions about *nature* from *mathematics*. The existence or non-existence of discontinuities/ continuities in nature is an empirical question that can't be settled by any amount of armchair theorising, even very intelligent theorising, by theorists, philosophers or mathematicians. You have to go out and look. By the way, the reason you can't do to a pea in reality what you can do with a mathematical abstraction of a pea is because peas are made of discontinuous atoms. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 19:30:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 23:30:23 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> Message-ID: <0063d7e0$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 10:09:21 -0400, Eric S. Johansson wrote: > Bruno Desthuilliers wrote: >> Brendan Miller a ?crit : >>> PEP 8 doesn't mention anything about using all caps to indicate a >>> constant. >>> >>> Is all caps meaning "don't reassign this var" a strong enough >>> convention to not be considered violating good python style? I see a >>> lot of people using it, but I also see a lot of people writing >>> non-pythonic code... so I thought I'd see what the consensus is. >> >> Most - if not all - of the python code I've seen so far used this >> convention, and I always used (and respected) it myself. > > I reject this convention because any form of caps significantly > increases vocal load for disabled programmers using speech recognition > through extra utterances, and degraded recognition. [...] > so I reject pep 8 because I have no voice safe alternative And you are perfectly entitled to. That puts you at a disadvantage if you wish to submit code for the standard library, where PEP 8 compliance is required, but for your own code you are entitled to use whatever conventions you prefer. -- Steven From http Sun Jun 28 19:59:09 2009 From: http (Paul Rubin) Date: 28 Jun 2009 16:59:09 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7x4otzykoi.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > But that depends on what you call "things"... if electron shells are real > (and they seem to be) and discontinuous, and the shells are predicted/ > specified by eigenvalues of some continuous function, is the continuous > function part of nature or just a theoretical abstraction? Again, electron shells came up in the context of a question about quantum theory, which is a mathematical theory involving continuous operators. That theory appears to very accurately model and predict observable natural phenomena. Is the real physical mechanism underneath observable nature actually some kind of discrete "checkers game" to which quantum theory is merely a close approximation? Maybe, but there's not a predictive mathematical theory like that right now, and even if there was, we'd be back to the question of just how it is that the checkers get from one place to another. > By the way, the reason you can't do to a pea in reality what you can do > with a mathematical abstraction of a pea is because peas are made of > discontinuous atoms. Not so much discontinuity, as the physical unreality of non-measurable sets. From cook_jim at yahoo.com Sun Jun 28 21:40:55 2009 From: cook_jim at yahoo.com (bootkey) Date: Sun, 28 Jun 2009 18:40:55 -0700 (PDT) Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> Message-ID: <40e3eff9-9e5c-4979-91bd-c85988352e91@k15g2000yqc.googlegroups.com> On Jun 28, 1:46?am, Tim Roberts wrote: > Jim wrote: > >I'm trying to understand the output of the tokenize.generate_tokens() > >generator. ?The token types returned seem to be more general than I'd > >expect. ?For example, when fed the following line of code: > > >def func_a(): > >... > >It seems to me that the token '(' should be identified as 'LPAR' and > >')' as 'RPAR', as found in the dictionary token.tok_name. ?What am I > >missing here? > > Did you read the module? ?Right at the top, it says: > > > It is designed to match the working of the Python tokenizer exactly, except > that it produces COMMENT tokens for comments and gives type OP for all > operators > > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Thanks for the reply. I wonder why the tokenizer classifies all operators simply as OP, instead of the various operators listed in the tok_name dictionary. Jim Cook From greg at cosc.canterbury.ac.nz Sun Jun 28 21:51:12 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 29 Jun 2009 13:51:12 +1200 Subject: Measuring Fractal Dimension ? In-Reply-To: <0062e638$0$9714$c3e8da3@news.astraweb.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7aqkukF20j8k3U1@mid.individual.net> Steven D'Aprano wrote: > one > minute the grenade is sitting there, stable as can be, the next it's an > expanding cloud of gas and metal fragments. I'm not sure that counts as "discontinuous" in the mathematical sense. If you were to film the grenade exploding and play it back slowly enough, the process would actually look fairly smooth. Mathematically, it's possible for a system to exhibit chaotic behaviour (so that you can't tell exactly when the grenade is going to go off) even though all the equations describing its behaviour are smooth and continuous. > My money is on the universe being fundamentally discontinuous. That's quite likely true. Quantum mechanics doesn't actually predict discrete behaviour -- the mathematics deals with continuously-changing state functions. It's only the interpretation of those functions (as determining the probabilities of finding the system in one of a discrete set of states) that introduces discontinuities. So it seems quite plausible that the continuous functions are just approximations of some underlying discrete process. The trick will be figuring out how such a process can work without running afoul of the various theorems concerning the non-existince of hidden variable theories... -- Greg From greg at cosc.canterbury.ac.nz Sun Jun 28 22:17:18 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 29 Jun 2009 14:17:18 +1200 Subject: Measuring Fractal Dimension ? In-Reply-To: <7x4otzykoi.fsf@ruckus.brouhaha.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> <7x4otzykoi.fsf@ruckus.brouhaha.com> Message-ID: <7aqmfiF1vh4vfU1@mid.individual.net> Paul Rubin wrote: > Steven D'Aprano writes: > >>But that depends on what you call "things"... if electron shells are real >>(and they seem to be) and discontinuous, and the shells are predicted/ >>specified by eigenvalues of some continuous function, is the continuous >>function part of nature or just a theoretical abstraction? Another thing to think about: If you put the atom in a magnetic field, the energy levels of the electrons get shifted slightly. To the extent that you can vary the magnetic field continuously, you can continuously adjust the energy levels. This of course raises the question of whether it's really possible to continuously adjust a magnetic field. But it's at least possible to do so with much finer granularity than the differences between energy levels in an atom. So if there is a fundamentally discrete model underlying everything, it must be at a much finer granularity than anything we've so far observed, and the discrete things that we have observed probably aren't direct reflections of it. -- Greg From aahz at pythoncraft.com Sun Jun 28 22:39:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 19:39:00 -0700 Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: In article <9efff087-bd6e-49fb-ad30-a955a64b85f9 at j32g2000yqh.googlegroups.com>, mclovin wrote: > >I need to have a dictionary of about 8 gigs (well the data it is >processing is around 4gb). so naturally i am running into memory >errors. > >So i looked around and found bsddb which acts like a dictionary object >only offloads the data from the RAM to the HDD, however that only >supports strings. Look at the pickle module. Personally, I'd use SQLite instead of bsddb. You might also look into a full-blown ORM such as SQLAlchemy. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From tjreedy at udel.edu Sun Jun 28 23:01:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 23:01:02 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <7aqkukF20j8k3U1@mid.individual.net> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7aqkukF20j8k3U1@mid.individual.net> Message-ID: greg wrote: > Steven D'Aprano wrote: >> one minute the grenade is sitting there, stable as can be, the next >> it's an expanding cloud of gas and metal fragments. > > I'm not sure that counts as "discontinuous" in the mathematical > sense. If you were to film the grenade exploding and play it > back slowly enough, the process would actually look fairly > smooth. radioactive emission might be a better example then. I do not believe there is any acceleration like you see with grenade fragments. Certainly, none with em radiation. Nothing....emission at light speed. From wuwei23 at gmail.com Sun Jun 28 23:03:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 28 Jun 2009 20:03:21 -0700 (PDT) Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: On Jun 29, 9:13 am, mclovin wrote: > Is there something like it that is more flexible? Have you seen the stdlib module 'shelve'? http://docs.python.org/library/shelve.html It creates a persistent file-based dictionary, which can hold any type of object as long as it can be pickled. I really like the 3rd party module 'shove': http://pypi.python.org/pypi/shove It's similar to shelve but provides many more backend options, including dbs, svn and Amazon S3. Very handy. From backup95 at netcabo.pt Sun Jun 28 23:23:47 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 04:23:47 +0100 Subject: No trees in the stdlib? In-Reply-To: <7x3a9mkiv6.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> Message-ID: <4A4833C3.6090305@netcabo.pt> Paul Rubin wrote: > aahz at pythoncraft.com (Aahz) writes: > >> (In particular, WRT the bisect module, although insertion and deletion >> are O(N), the constant factor for doing a simple memory move at C speed >> swamps bytecode until N gets very large -- and we already have >> collections.deque() for some other common use cases.) >> > > Again, at least in my case, I'd hope for an immutable structure. > > Could you clarify what you mean by immutable? As in... not mutable? As in without supporting insertions and deletions? That's has the same performance as using binary search on a sorted list. What's the point of using a tree for that? From http Sun Jun 28 23:54:11 2009 From: http (Paul Rubin) Date: 28 Jun 2009 20:54:11 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> Message-ID: <7xeit3ae58.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Could you clarify what you mean by immutable? As in... not mutable? As > in without supporting insertions and deletions? Correct. > That's has the same performance as using binary search on a sorted > list. What's the point of using a tree for that? The idea is you can accomplish the equivalent of insertion or deletion by allocating a new root, along with the path down to the place you want to insert, i.e. O(log n) operations. So instead of mutating an existing tree, you create a new tree that shares most of its structure with the old tree, and switch over to using the new tree. This trivially lets you maintain snapshots of old versions of the tree, implement an "undo" operation, have a background thread do a complex operation on a snapshot while the foreground thread does any number of update-and-replace operations, etc. This is very standard stuff. See: http://en.wikipedia.org/wiki/Persistent_data_structure The wikipedia article on AVL trees makes it pretty obvious how an implementation would work. From esj at harvee.org Mon Jun 29 01:07:19 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 01:07:19 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A484C07.9050800@harvee.org> Rhodri James wrote: > Reject away, but I'm afraid you've still got some work to do to > convince me that PEP 8 is more work for an SR system than any other > convention. Name name higher than normal recognition error rate. can require multiple tries or hand correction MultiWordName mulitwordname very high error rate. many retries or hand hurting typing. multi_word_name multiwordname normal error rate (low), can need multiple tries or hand correction StdlYCps sierra tango delta lima yankee charley papa sierra *** very high error rate *** search and replace for all instances with a x_y_z form name is recommended If, on the other hand you're trying to convince me that > *no* convention is preferable, I'm going to laugh hollowly. no, I know the value if convention when editors can't tell you anything about the name in question. I would like to see more support for disabled programmers like myself and the thousands of programmers injured every year and forced to leave the field. seriously, there is no money in disability access especially for programmers. and forgive me if this comes off sounding like a jerk but if the collective you don't give a sh** about your fellow programmers, who will? should all disabled programmers be dumped on the shelf even their brains are still good and they have guts to try to work in a field that gave them a life rearranging injury? please help. the disability access you help build may save your own job someday. Or, what I need to edit code may make your world better as well. From Olivier.Darge at gmail.com Mon Jun 29 01:10:07 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sun, 28 Jun 2009 22:10:07 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: On 28 juin, 23:26, Tomasz Pajor wrote: > Hello, > > Configuration is as follows. > > I have a starter process which creates 3 sub processes (forks) and each > of this processes creates a number of threads. > Threads in that processes have semaphore so on KeyboardInterrupt without > sending a sigterm to the subprocess i'm not able to close threads. > Is there any work around? Can I somehow run join for the thread on > keyboard interrupt? When creating a thread you can add a Queue parameter to communicate with threads: http://docs.python.org/library/queue.html easy and reliable. give them a "poison pill" in the queue: a recognizable object placed on the queue that means "when you get this, stop." better to not rely on keyboard for thread stopping. Olivier From backup95 at netcabo.pt Mon Jun 29 01:17:01 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:17:01 +0100 Subject: No trees in the stdlib? In-Reply-To: <7xeit3ae58.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: <4A484E4D.2050702@netcabo.pt> Paul Rubin wrote: > Jo?o Valverde writes: > >> Could you clarify what you mean by immutable? As in... not mutable? As >> in without supporting insertions and deletions? >> > > Correct. > > >> That's has the same performance as using binary search on a sorted >> list. What's the point of using a tree for that? >> > > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. This > trivially lets you maintain snapshots of old versions of the tree, > implement an "undo" operation, have a background thread do a complex > operation on a snapshot while the foreground thread does any number of > update-and-replace operations, etc. > > > Interesting, thanks. The concept is not difficult to understand but I'm not sure it would be preferable. A copy operation should have the same cost as a "snapshot", undo is kind of redundant and multithreading... don't see a compelling use that would justify it. Also the interface is a mapping so it'd be rather nice to emulate dict's. Have you considered how the syntax would work in Python by the way? This: new_tree = old_tree.insert(object) Just looks wrong. The interface should support non functional idioms too. From backup95 at netcabo.pt Mon Jun 29 01:24:36 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:24:36 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A484E4D.2050702@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <4A484E4D.2050702@netcabo.pt> Message-ID: <4A485014.902@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Could you clarify what you mean by immutable? As in... not mutable? As >>> in without supporting insertions and deletions? >> >> Correct. >> >>> That's has the same performance as using binary search on a sorted >>> list. What's the point of using a tree for that? >>> >> >> The idea is you can accomplish the equivalent of insertion or deletion >> by allocating a new root, along with the path down to the place you >> want to insert, i.e. O(log n) operations. So instead of mutating an >> existing tree, you create a new tree that shares most of its structure >> with the old tree, and switch over to using the new tree. This >> trivially lets you maintain snapshots of old versions of the tree, >> implement an "undo" operation, have a background thread do a complex >> operation on a snapshot while the foreground thread does any number of >> update-and-replace operations, etc. >> >> >> > Interesting, thanks. The concept is not difficult to understand but > I'm not sure it would be preferable. A copy operation should have the > same cost as a "snapshot", undo is kind of redundant and > multithreading... don't see a compelling use that would justify it. > Also the interface is a mapping so it'd be rather nice to emulate dict's. > > Have you considered how the syntax would work in Python by the way? This: > > new_tree = old_tree.insert(object) > Heh, that's a poor example for a mapping. But: bst[key] = object is even dicier for immutable structures no? From http Mon Jun 29 01:41:46 2009 From: http (Paul Rubin) Date: 28 Jun 2009 22:41:46 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: <7xprcny4th.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Interesting, thanks. The concept is not difficult to understand but > I'm not sure it would be preferable. A copy operation should have the > same cost as a "snapshot", You mean a deep-copy? That is unnecessarily expensive; with a functional structure you can snapshot (or copy) by copying a single pointer. > undo is kind of redundant and multithreading... don't see a > compelling use that would justify it. Here is one: http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b > Have you considered how the syntax would work in Python by the way? This: > new_tree = old_tree.insert(object) > Just looks wrong. It looks fine to me. Obviously you could support a wrapper with a mutating slot that holds a pointer to the tree. From http Mon Jun 29 01:42:19 2009 From: http (Paul Rubin) Date: 28 Jun 2009 22:42:19 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <4A484E4D.2050702@netcabo.pt> Message-ID: <7xljnby4sk.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > bst[key] = object > is even dicier for immutable structures no? bst = bst.insert(key, object) From ldo at geek-central.gen.new_zealand Mon Jun 29 01:44:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 29 Jun 2009 17:44:17 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message <976cc575-80b9-406a- ae4d-03cb4d401dc4 at p36g2000prn.googlegroups.com>, olivergeorge wrote: > (and why PIL is such a pain to install for that matter.) "apt-get install python-imaging", anybody? From turian at gmail.com Mon Jun 29 01:52:43 2009 From: turian at gmail.com (Joseph Turian) Date: Sun, 28 Jun 2009 22:52:43 -0700 (PDT) Subject: Abort SimpleXMLRPCServer request prematurely? Message-ID: <4886c8dc-235d-4442-b2d6-bc08a023bbd1@h2g2000yqg.googlegroups.com> With SimpleXMLRPCServer, if the server is taking too long, how can I use the client to kill the request and have the server abort prematurely? Thanks, Joseph From wuwei23 at gmail.com Mon Jun 29 01:53:09 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 28 Jun 2009 22:53:09 -0700 (PDT) Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: "Eric S. Johansson" wrote: > no, I know the value if convention when editors can't tell you anything about > the name in question. ?I would like to see more support for disabled programmers > like myself and the thousands of programmers injured every year and forced to > leave the field. ?seriously, there is no money in disability access especially > for programmers. Well, if we can't use conventions like uppercasing, camelcasing and underscoring, what are you recommending we do instead? You seem to be asking us to change our behaviour to benefit only others, but without offering any guidance on to how that is possible. More importantly, shouldn't these modifications to common conventions be coming _from_ the community of disabled programmers? I have a hard time ensuring that I've gotten accurate requirements from co-workers with whom I can actually see and speak, trying to determine how I could write my code with accessibility in mind without any established means of gauging success just seems impossible. > and forgive me if this comes off sounding like a jerk but if > the collective you don't give a sh** about your fellow programmers, who will? This isn't intended to be callous, as I feel that the collective doesn't care as a whole about _any_ programmers, but isn't the answer the very same disabled programmers for whom accessibility is an issue? Programming tends to be needs driven (which, admittedly, can be simply "to pay the bills"), and those who have a need tend to be better at working out how to address it. One possibility may be to approach a group for whom accessibility is already a consideration, such as the Gnome Accessibility Project: http://live.gnome.org/GAP As they are already developing Python-based accessibility tools for Gnome - http://live.gnome.org/Accessibility/PythonPoweredAccessibility - it wouldn't be a big stretch to start addressing coding accessibility within that scope, either as part of the project or as an independent adjunct to it, especially if someone with domain knowledge volunteered ;) From turian at gmail.com Mon Jun 29 01:54:57 2009 From: turian at gmail.com (Joseph Turian) Date: Sun, 28 Jun 2009 22:54:57 -0700 (PDT) Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: You could also try using a key-value store. I am using pytc, a Python API for Tokyo Cabinet. It seems to figure out quite nicely when to go to disk, and when to use memory. But I have not done extensive tests. Here is some example code for using pytc: http://github.com/turian/pytc-example/tree/master Joseph On Jun 28, 7:13 pm, mclovin wrote: > Hello all, > > I need to have a dictionary of about 8 gigs (well the data it is > processing is around 4gb). so naturally i am running into memory > errors. > > So i looked around and found bsddb which acts like a dictionary object > only offloads the data from the RAM to the HDD, however that only > supports strings. > > my dictionaries hold my own class objects > > Is there something like it that is more flexible? From backup95 at netcabo.pt Mon Jun 29 01:56:07 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:56:07 +0100 Subject: No trees in the stdlib? In-Reply-To: <7xprcny4th.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> Message-ID: <4A485777.2000301@netcabo.pt> Paul Rubin wrote: > Jo?o Valverde writes: > >> Interesting, thanks. The concept is not difficult to understand but >> I'm not sure it would be preferable. A copy operation should have the >> same cost as a "snapshot", >> > > You mean a deep-copy? That is unnecessarily expensive; with a > functional structure you can snapshot (or copy) by copying a single > pointer. > > Shallow copy... >> undo is kind of redundant and multithreading... don't see a >> compelling use that would justify it. >> > > Here is one: > http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b > > I just skimmed that but if someone really needs multithreading for such intensive processing without wanting a database, fair enough I guess. >> Have you considered how the syntax would work in Python by the way? This: >> new_tree = old_tree.insert(object) >> Just looks wrong. >> > > It looks fine to me. Obviously you could support a wrapper with > a mutating slot that holds a pointer to the tree. > I didn't get the last part, sorry. But I think you'd have a lot of users annoyed that the interface is similar to a list yet their objects mysteriously disappear. To me, tree.insert() implies mutability but I defer that to others like yourself with more experience in Python than me. From __peter__ at web.de Mon Jun 29 02:14:03 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Jun 2009 08:14:03 +0200 Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: Eric S. Johansson wrote: > MultiWordName mulitwordname > very high error rate. many retries or hand hurting typing. Can you define macros in your speech recognition software? multiwordname might slightly lower the error rate. Peter From backup95 at netcabo.pt Mon Jun 29 02:16:21 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 07:16:21 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A485777.2000301@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <4A485C35.7090003@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Interesting, thanks. The concept is not difficult to understand but >>> I'm not sure it would be preferable. A copy operation should have the >>> same cost as a "snapshot", >> >> You mean a deep-copy? That is unnecessarily expensive; with a >> functional structure you can snapshot (or copy) by copying a single >> pointer. >> >> > > Shallow copy... > > Actually I meant whatever that snapshot operation is, minus the insertion, if that makes sense. From nikon at puffy.pl Mon Jun 29 02:22:06 2009 From: nikon at puffy.pl (Tomasz Pajor) Date: Mon, 29 Jun 2009 08:22:06 +0200 Subject: fork, threads and proper closing In-Reply-To: References: Message-ID: <4A485D8E.3000108@puffy.pl> > On 28 juin, 23:26, Tomasz Pajor wrote: > >> Hello, >> >> Configuration is as follows. >> >> I have a starter process which creates 3 sub processes (forks) and each >> of this processes creates a number of threads. >> Threads in that processes have semaphore so on KeyboardInterrupt without >> sending a sigterm to the subprocess i'm not able to close threads. >> Is there any work around? Can I somehow run join for the thread on >> keyboard interrupt? >> > > When creating a thread you can add a Queue parameter to communicate > with threads: > http://docs.python.org/library/queue.html > easy and reliable. > > give them a "poison pill" in the queue: a recognizable object placed > on the queue that means "when you get this, stop." > can You provide any working example? > better to not rely on keyboard for thread stopping. > i use keyboard interrupt only for debuging purposes > Olivier > From sjmachin at lexicon.net Mon Jun 29 02:28:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 28 Jun 2009 23:28:39 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> <7J6dnbgkVoys5NvXnZ2dnUVZ_r1i4p2d@pdx.net> Message-ID: On Jun 28, 6:02?am, Scott David Daniels wrote: > olivergeorge wrote: > > Ditto. ?Anyone know what's happening with pythonware? ?(and why PIL is > > such a pain to install for that matter.) > > (2) I suggest you demand a refund. ... and tell us what the response was :-) From usernet at ilthio.net Mon Jun 29 03:02:53 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 07:02:53 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-29, Lawrence D'Oliveiro wrote: > "apt-get install python-imaging", anybody? C:\>apt-get install python-imaging Bad command or file name Nope. 01:10,501$ apt-get install python-imaging bash: apt-get: command not found Not quite; but, it does give me an idea. Debian usually keeps the origional source packages in their package repositories: 02:09,502,(1)$ wget http://ftp.de.debian.org/debian/pool/main/p/python-imaging/python1.1.5.orig.tar.gz => `python-imaging_1.1.5.orig.tar.gz' Resolving ftp.de.debian.org... 141.76.2.4 Connecting to ftp.de.debian.org|141.76.2.4|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 429,570 (420K) [application/x-gzip] 100%[=========================================>] 429,570 246.97K/s 02:09:43 (246.26 KB/s) - `python-imaging_1.1.5.orig.tar.gz' saved [429570/429570] 01:10,503$ Now that's the ticket! From Andras.Horvath at cern.ch Mon Jun 29 03:18:20 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Mon, 29 Jun 2009 09:18:20 +0200 Subject: validating HTTPS certificates? In-Reply-To: References: Message-ID: <20090629071820.GM3186@cern.ch> On Fri, Jun 26, 2009 at 07:01:24PM +0200, Nobody wrote: > For a urllib-style interface, there's not much point in performing > verification after the fact. Either the library performs verification or > it doesn't. If it doesn't, you've just sent the (potentially confidential) > request to an unknown server; discovering this after the fact doesn't > really help. I was more thinking about supplying a/some CA certificate(s) and requiring that the site cert be valid (otherwise the connection should fail). This sounds very EAFP to me. Andras From sajmikins at gmail.com Mon Jun 29 03:21:16 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:21:16 -0400 Subject: Flexible warning system In-Reply-To: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> References: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> Message-ID: <50f98a4c0906290021m114bd8a5y6c91e1ebeceb3256@mail.gmail.com> On Sun, Jun 28, 2009 at 2:31 PM, Shrutarshi Basu wrote: > I'm writing a Python package where I have an underlying object model that is > manipulated by a runtime control layer and clients that interface with this > runtime. As I'm developing this i'm realizing that there are going to be a > number of places where the runtime might affect the object model in ways > that might not be immediately obvious to the user. I would like to have some > sort of warning system where the runtime can raise a warning and then the > clients can 'catch' those warnings and display them as they want to. Is > there some sort of a system that will operates like that or will I have to > roll my own? If I do need to roll my own, any ideas on how I should go about > it? I know that there is a warning module, but it seems to that all outputs > go to standard out which isn't what I want. > Thanks, > Basu > > Shrutarshi Basu > Computer Science, > Electrical and Computer Engineering, > Lafayette College, > The ByteBaker -- http://bytebaker.com > I just glanced at the docs for the warnings module and it seems like exactly what you're asking for, and you can change the default writing to stdout: "Warning messages are normally written to sys.stderr, but their disposition can be changed flexibly, from ignoring all warnings to turning them into exceptions. The disposition of warnings can vary based on the warning category (see below), the text of the warning message, and the source location where it is issued. Repetitions of a particular warning for the same source location are typically suppressed." - http://docs.python.org/library/warnings.html That said, why not just use exceptions? HTH, ~Simon From sajmikins at gmail.com Mon Jun 29 03:23:07 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:23:07 -0400 Subject: The Python Way for module configuration? In-Reply-To: References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: <50f98a4c0906290023w2cb7952bn867dc54e53933573@mail.gmail.com> On Sun, Jun 28, 2009 at 1:22 PM, kj wrote: > In <87fxdlujds.fsf at benfinney.id.au> Ben Finney writes: > >>(Even if you don't want to receive email, could you please give your >>actual name in the ?From? field instead of just initials? It makes >>conversation less confusing.) > > I don't know why, but for as long as I can remember everyone calls > me kj, even my mom. ?My name is Keaweikekahiali?iokamoku > Jallalahwallalruwalpindi > > kj > Now that's funny. +1 QotW ~SF From sajmikins at gmail.com Mon Jun 29 03:24:28 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:24:28 -0400 Subject: Good books in computer science? In-Reply-To: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <50f98a4c0906290024h304c52d1h64356a699accc1e9@mail.gmail.com> On Sat, Jun 13, 2009 at 11:49 AM, koranthala wrote: > Hi all, > ? ?I do understand that this is not a python question and I apologize > for that straight up. > ? ?But I am a full time follower of this group and I have seen very > very brilliant programmers and solutions. > ? ?I also want to be a good programmer - so this question. > > ? ?Which are the classic books in computer science which one should > peruse? > ? ?I have ?(a) Code Complete (b) GOF (c) Art of programming. > > ? ?Art of programming was too tough for me - and I couldnt understand > much. The other two were good books - I understood and implemented > quite a bit from both. > ? ?What are the other books which I should peruse? > > Regards > K Knuth. I.e. "The Art of Computer Programming" by Prof. Knuth Your library should have a copy (it's a multi-volume opus), if not consider donating yours after you read them. From casper.feldmann at googlemail.com Mon Jun 29 03:42:54 2009 From: casper.feldmann at googlemail.com (C. Feldmann) Date: Mon, 29 Jun 2009 00:42:54 -0700 (PDT) Subject: pythonware.com down? Message-ID: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Hi, I am trying to get a hold of PIL, but pythonware.com seems to be down. Are there mirrors out there? I get a 502 Error "Bad Gateway - The proxy server received an invalid response from an upstream server." Does anyone else get that error? Thanks Casper From news123 at free.fr Mon Jun 29 03:59:09 2009 From: news123 at free.fr (News123) Date: Mon, 29 Jun 2009 09:59:09 +0200 Subject: creating garbage collectable objects (caching objects) In-Reply-To: References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <4a48744d$0$414$426a74cc@news.free.fr> Dave Angel wrote: > News123 wrote: >> Hi. >> >> I started playing with PIL. >> >> I'm performing operations on multiple images and would like compromise >> between speed and memory requirement. >> . . . >> >> The question, that I have is whether there is any way to tell python, >> that certain objects could be garbage collected if needed and ask python >> at a later time whether the object has been collected so far (image has >> to be reloaded) or not (image would not have to be reloaded) >> >> >> > You don't say what implementation of Python, nor on what OS platform. > Yet you're asking how to influence that implementation. Sorry my fault. I'm using C-python under Windows and under Linux > > In CPython, version 2.6 (and probably most other versions, but somebody > else would have to chime in) an object is freed as soon as its reference > count goes to zero. So the garbage collector is only there to catch > cycles, and it runs relatively infrequently. If CYthon frees objects as early as possible (as soon as the refcount is 0), then weakref wil not really help me. In this case I'd have to elaborate into a cache like structure. > > So, if you keep a reference to an object, it'll not be freed. > Theoretically, you can use the weakref module to keep a reference > without inhibiting the garbage collection, but I don't have any > experience with the module. You could start by studying its > documentation. But probably you want a weakref.WeakValueDictionary. > Use that in your third approach to store the cache. > > If you're using Cython or Jython, or one of many other implementations, > the rules will be different. > > The real key to efficiency is usually managing locality of reference. > If a given image is going to be used for many output files, you might > try to do all the work with it before going on to the next image. In > that case, it might mean searching all_creation_rules for rules which > reference the file you've currently loaded, measurement is key. Changing the order of the images to be calculated is key and I'm working on that. For a first step I can reorder the image creation such, that all outpout images, that depend only on one input image will be calculated one after the other. so for this case I can transform: # Slowest approach: for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): src_img = Image.open(img_file) img = do_somethingwith(img,src_img) # wrong indentation in OP img.save() into src_img = Image.open(img_file) for creation_rule in all_creation_rules_with_on_src_img(): img = Image.new(...) img = do_somethingwith(img,src_img) img.save() What I was more concerned is a group of output images depending on TWO or more input images. Depending on the platform (and the images) I might not be able to preload all two (or more images) So, as CPython's garbage collection takes always place immediately, then I'd like to pursue something else. I can create a cache, which caches input files as long as python leaves at least n MB available for the rest of the system. For this I have to know how much RAM is still available on a system. I'll start looking into this. thanks again N From nurazije at gmail.com Mon Jun 29 04:24:36 2009 From: nurazije at gmail.com (NurAzije) Date: Mon, 29 Jun 2009 01:24:36 -0700 (PDT) Subject: whizBase vs. Python Message-ID: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Hi, I am working on a study and I need expert opinion, I did not work with Python before, can anyone help me with a comparison between WhizBase (www.whizbase.com) and Python please. Thank you in advance, Ashraf Gheith From clp2 at rebertia.com Mon Jun 29 04:54:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 01:54:12 -0700 Subject: whizBase vs. Python In-Reply-To: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: <50697b2c0906290154o273d50dcsb258091c41291373@mail.gmail.com> On Mon, Jun 29, 2009 at 1:24 AM, NurAzije wrote: > Hi, > I am working on a study and I need expert opinion, I did not work with > Python before, can anyone help me with a comparison between WhizBase > (www.whizbase.com) and Python please. Python is a popular, open-source, cross-platform, general-purpose programming language with a large standard library that is often used in web programming. Popular Python web frameworks include TurboGears and Django. WhizBase appears to be a proprietary, Windows-only, database-centric web macro language (or proper programming language perhaps, I didn't investigate deeply). Proprietary language = Vendor lock-in = Lose. Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Jun 29 04:58:42 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 29 Jun 2009 09:58:42 +0100 Subject: pep 8 constants In-Reply-To: <4A484C07.9050800@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: On Mon, 29 Jun 2009 06:07:19 +0100, Eric S. Johansson wrote: > Rhodri James wrote: > >> Reject away, but I'm afraid you've still got some work to do to >> convince me that PEP 8 is more work for an SR system than any other >> convention. > [snip sundry examples] Yes, yes, recognition systems need both training and a careful selection of words to recognise to be effective. This I learned twenty years ago: if "cap" has a high failure rate, use something else. As far as I can tell, the only thing that you are even vaguely suggesting for convention use is underscores_with_everything. As promised, I laugh hollowly. -- Rhodri James *-* Wildebeest Herder to the Masses From nobody at nowhere.com Mon Jun 29 04:59:54 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 09:59:54 +0100 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 28 Jun 2009 20:54:11 -0700, Paul Rubin wrote: > Jo?o Valverde writes: >> Could you clarify what you mean by immutable? As in... not mutable? As >> in without supporting insertions and deletions? > > Correct. > >> That's has the same performance as using binary search on a sorted >> list. What's the point of using a tree for that? > > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. The main issue here is that you need to be a bit smarter when it comes to "modifying" the tree. If you want to insert, delete or replace multiple elements, using repeated insert()s (etc) on the root is sub-optimal, as you will end up repeatedly duplicating the upper levels. Ideally you want to provide operations which will add/remove/replace multiple elements in a single traversal. From usernet at ilthio.net Mon Jun 29 05:04:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 09:04:44 GMT Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: On 2009-06-29, NurAzije wrote: > Hi, > I am working on a study and I need expert opinion, I did not work with > Python before, can anyone help me with a comparison between WhizBase > (www.whizbase.com) and Python please. Given posts like: http://groups.google.com/group/Server-side-programing/browse_thread/thread/16cfcf58bc943a0/15840d85eedd952e#15840d85eedd952e is this just thinly veiled spam? The domain and the posting IP address are both out of Sarajevo, Bosnia. Obviously you alreadly know your product is nothing but a database macro processor. Python is a dynamic programming language and therefore far more capable. Your product is proprietary with less capability while Python is free and powerful. From info at egenix.com Mon Jun 29 05:07:04 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 29 Jun 2009 11:07:04 +0200 Subject: ANN: eGenix mxODBC Connect 1.0.2 - Python Database Interface Message-ID: <4A488438.7070409@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python Database Interface Version 1.0.2 Our new client-server product for connecting Python applications to relational databases - from all major platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-1.0.2-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable and convenient way. Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect the ideal basis for writing cross-platform database programs and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. By removing the need to install and configure ODBC drivers on the client side, mxODBC Connect greatly simplifies setup and configuration of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS mxODBC Connect 1.0.2 is a patch-level release of our new mxODBC Connect product. * More Secure We have upgraded the server to our latest eGenix pyOpenSSL release 0.9.0-0.9.8k, which includes a number of important bug fixes to both pyOpenSSL and the used OpenSSL library. * More Robust Previous versions had a timeout issue that we have solved with this release. We have have also added a special case for shutting down the client with a broken server connection. In such cases, the client will no longer wait for a timeout and terminate much faster. * Ideal for Building Bridges mxODBC Connect Client now works on all major Python platforms. As a result, connecting from e.g. Linux or Mac OS X to an SQL Server database has never been easier. You can even keep the data sources you already have configured on your Windows machine and connect to them as if your application were running on the database server itself. ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 1.0 licenses can download and upgrade their existing installations without having to purchase new licenses or upgrades. The licenses will continue to work with version 1.0.2. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From usernet at ilthio.net Mon Jun 29 05:07:56 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 09:07:56 GMT Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: On 2009-06-29, C. Feldmann wrote: > I am trying to get a hold of PIL, but pythonware.com seems to be down. > Are there mirrors out there? > I get a 502 Error "Bad Gateway - The proxy server received an invalid > response from an upstream server." > Does anyone else get that error? Yes, more info below: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2dbba1a1bd6ebee6/1d832c468efc3828?tvc=1#1d832c468efc3828 From mfmdevine at gmail.com Mon Jun 29 05:20:39 2009 From: mfmdevine at gmail.com (amadain) Date: Mon, 29 Jun 2009 02:20:39 -0700 (PDT) Subject: urllib2.URLError: error using twill with python References: <023cef3d$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Jun 8, 12:58?pm, Steven D'Aprano wrote: > On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote: > > Hi > > I wonder if someone could point me in the right direction. I used the > > following code to access gmail but I got a > > ? ? ? ? ?urllib2.URLError: > > error when I ran it. I have included the Traceback > > > import twill, string, os > > b=twill.commands.get_browser() > > b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; > > rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() > > b.go('http://www.gmail.com') > > f=b.get_form("1") > > b.showforms() > > f['Email']= email > > f['Passwd'] =password > > b.clicked(f, f) > > b.submit() > > My bet is that the above is not the actual code you have run. I bet that > the offending line is actually something like the following: > > b.go("'http://www.gmail.com") > > Note that there is a single character difference. > > Consider the last two lines of the traceback: > > > ? ? raise URLError('unknown url type: %s' % type) > > urllib2.URLError: > > It seems to be saying that the url type is 'http -- note the leading > single quote. > > -- > Steven Actually that is the exact code run from a python shell. Try it yourself. I could not find anybody who successfully automated sending a gmail through python with twill so if you know how I would greatly appreciate any pointers. From gil.shinar at gmail.com Mon Jun 29 05:35:17 2009 From: gil.shinar at gmail.com (eranlevi) Date: Mon, 29 Jun 2009 02:35:17 -0700 (PDT) Subject: Timeout when connecting to sybase DBS Message-ID: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> Hi All, I'm using the Sybase module for connecting and using a sybase DBS. When I try to connect when the DBS is down, it take approximately 4 minutes for the function (conn.ct_connect) to return with an error. I have looked for a timeout parameter to limit the 4 minutes to something more reasonable but couldn't find one. Can anyone please help? BTW, I'm using Sybase.connect(, , , datetime='auto') Thanks Gil From nobody at nowhere.com Mon Jun 29 06:06:06 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 11:06:06 +0100 Subject: validating HTTPS certificates? References: Message-ID: On Mon, 29 Jun 2009 09:18:20 +0200, Andras.Horvath wrote: >> For a urllib-style interface, there's not much point in performing >> verification after the fact. Either the library performs verification or >> it doesn't. If it doesn't, you've just sent the (potentially confidential) >> request to an unknown server; discovering this after the fact doesn't >> really help. > > I was more thinking about supplying a/some CA certificate(s) and > requiring that the site cert be valid (otherwise the connection should > fail). This sounds very EAFP to me. This is easier to do with urllib2 than urllib. For urllib, you would need to either "fix" URLopener.open_https() or clone half of urllib (URLOpener and FancyURLOpener). For urllib2, you can use urllib2.install_opener() to replace the built-in HTTPSHandler with a subclass which performs validation. Validation should just be a matter of passing cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking that SSLSocket.getpeercert() returns a non-empty dictionary. Note: the above is purely theoretical, based upon the (2.6) documentation and source code. I suggest that you verify it by connecting to a site with a bogus (e.g. self-signed) certificate and checking that it fails. From lenglish5 at cox.net Mon Jun 29 06:18:28 2009 From: lenglish5 at cox.net (Lawson English) Date: Mon, 29 Jun 2009 03:18:28 -0700 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4a4689bf$0$14790$9b622d9e@news.freenet.de> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <4A4894F4.7040606@cox.net> Martin v. L?wis wrote: >> I sorta' wish he'd just come out and say, "This is what I think would >> be suitable for a GUI toolkit for Python: ...". >> > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. > > What he makes clear is the point that Terry cites: no matter what the > GUI toolkit is or what features it has - it should be simple to create > GUIs, as simple as creating HTML. > > Tim Berners-Lee would laugh to hear html described as "simple." He was very frustrated with how long it took anyone to create a graphical toolkit to create webpages. >> So, what *does* Guido want in a GUI toolkit for Python? >> > > His concern really isn't what is in the toolkit, but what isn't. > It must not require lots of lines of code to produce a simple > GUI, it must not require specification of absolute coordinates, > ... - you should be able to continue the list yourself. > > Regards, > Martin > From marek at xivilization.net Mon Jun 29 06:19:40 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 29 Jun 2009 12:19:40 +0200 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: <20090629121940.42b88764@halmanfloyd.lan.local> On 28 Jun 2009 11:45:06 -0700 aahz at pythoncraft.com (Aahz) wrote: > Perhaps I was unclear: I already knew what LMGTFY stands for, and I > think that using a site that requires JavaScript is anti-social. Maybe they could just redirect to Google if JS wasn't detected. regards, Marek From casper.feldmann at googlemail.com Mon Jun 29 06:31:08 2009 From: casper.feldmann at googlemail.com (C. Feldmann) Date: Mon, 29 Jun 2009 03:31:08 -0700 (PDT) Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: On 29 Jun., 11:07, Tim Harig wrote: > On 2009-06-29, C. Feldmann wrote: > > > I am trying to get a hold of PIL, but pythonware.com seems to be down. > > Are there mirrors out there? > > I get a 502 Error "Bad Gateway - The proxy server received an invalid > > response from an upstream server." > > Does anyone else get that error? > > Yes, more info below: > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... yeah. need the windows version. guess this is another reason to add to my "why I should buy a mac" list. :) From nobody at nowhere.com Mon Jun 29 06:33:55 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 11:33:55 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 21:25:13 +0000, Benjamin Peterson wrote: >> > The email module is, yes, broken. You can recover the bytestrings of >> > command-line arguments and environment variables. >> >> 1. Does Python offer any assistance in doing so, or do you have to >> manually convert the surrogates which are generated for unrecognised bytes? > > fs_encoding = sys.getfilesystemencoding() > bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] This results in an internal error: > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") Traceback (most recent call last): File "", line 1, in SystemError: Objects/bytesobject.c:3182: bad argument to internal function [FWIW, the error corresponds to _PyBytes_Resize, which has a cautionary comment almost as large as the code.] The documentation gives the impression that "surrogateescape" is only meaningful for decoding. >> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? > > What's a non-invertible encoding? I can't find a reference to the term. One where different inputs can produce the same output. From godson.g at gmail.com Mon Jun 29 06:50:32 2009 From: godson.g at gmail.com (Godson Gera) Date: Mon, 29 Jun 2009 16:20:32 +0530 Subject: pythonware.com down? In-Reply-To: References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: way back machine,comes to rescue. http://web.archive.org/web/20071011003451/www.pythonware.com/products/pil/index.htm On Mon, Jun 29, 2009 at 4:01 PM, C. Feldmann wrote: > On 29 Jun., 11:07, Tim Harig wrote: > > On 2009-06-29, C. Feldmann wrote: > > > > > I am trying to get a hold of PIL, but pythonware.com seems to be down. > > > Are there mirrors out there? > > > I get a 502 Error "Bad Gateway - The proxy server received an invalid > > > response from an upstream server." > > > Does anyone else get that error? > > > > Yes, more info below: > > > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... > > yeah. need the windows version. guess this is another reason to add to > my "why I should buy a mac" list. :) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera http://godson.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Mon Jun 29 07:01:20 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 29 Jun 2009 07:01:20 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a48744d$0$414$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> Message-ID: <4A489F00.1040003@ieee.org> News123 wrote: > Dave Angel wrote: > >> News123 wrote: >> >>> Hi. >>> >>> I started playing with PIL. >>> >>> I'm performing operations on multiple images and would like compromise >>> between speed and memory requirement. >>> . . . >>> >>> The question, that I have is whether there is any way to tell python, >>> that certain objects could be garbage collected if needed and ask python >>> at a later time whether the object has been collected so far (image has >>> to be reloaded) or not (image would not have to be reloaded) >>> >>> >>> > > >>> >>> >> You don't say what implementation of Python, nor on what OS platform. >> Yet you're asking how to influence that implementation. >> > > Sorry my fault. I'm using C-python under Windows and under Linux > >> In CPython, version 2.6 (and probably most other versions, but somebody >> else would have to chime in) an object is freed as soon as its reference >> count goes to zero. So the garbage collector is only there to catch >> cycles, and it runs relatively infrequently. >> > > If CYthon frees objects as early as possible (as soon as the refcount is > 0), then weakref wil not really help me. > In this case I'd have to elaborate into a cache like structure. > >> So, if you keep a reference to an object, it'll not be freed. >> Theoretically, you can use the weakref module to keep a reference >> without inhibiting the garbage collection, but I don't have any >> experience with the module. You could start by studying its >> documentation. But probably you want a weakref.WeakValueDictionary. >> Use that in your third approach to store the cache. >> >> If you're using Cython or Jython, or one of many other implementations, >> the rules will be different. >> >> The real key to efficiency is usually managing locality of reference. >> If a given image is going to be used for many output files, you might >> try to do all the work with it before going on to the next image. In >> that case, it might mean searching all_creation_rules for rules which >> reference the file you've currently loaded, measurement is key. >> > > Changing the order of the images to be calculated is key and I'm working > on that. > > For a first step I can reorder the image creation such, that all outpout > images, that depend only on one input image will be calculated one after > the other. > > so for this case I can transform: > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) # wrong indentation in OP > img.save() > > > into > src_img = Image.open(img_file) > for creation_rule in all_creation_rules_with_on_src_img(): > img = Image.new(...) > img = do_somethingwith(img,src_img) > img.save() > > > What I was more concerned is a group of output images depending on TWO > or more input images. > > Depending on the platform (and the images) I might not be able to > preload all two (or more images) > > So, as CPython's garbage collection takes always place immediately, > then I'd like to pursue something else. > I can create a cache, which caches input files as long as python leaves > at least n MB available for the rest of the system. > > For this I have to know how much RAM is still available on a system. > > I'll start looking into this. > > thanks again > > > > N > > > As I said earlier, I think weakref is probably what you need. A weakref is still a reference from the point of view of the ref-counting, but not from the point of view of the garbage collector. Have you read the help on weakref module? In particular, did you read Pep 0205? http://www.python.org/dev/peps/pep-0205/ Object cache is one of the two reasons for the weakref module. From nobody at nowhere.com Mon Jun 29 07:02:20 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 12:02:20 +0100 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. L?wis wrote: >> That's a significant improvement. It still decodes os.environ and sys.argv >> before you have a chance to call sys.setfilesystemencoding(), but it >> appears to be recoverable (with some effort; I can't find any way to re-do >> the encoding without manually replacing the surrogates). > > See PEP 383. Okay, that's useful, except that it may have some bugs: > r = "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") Traceback (most recent call last): File "", line 1, in SystemError: Objects/bytesobject.c:3182: bad argument to internal function Trying a few random test cases suggests that the ratio of valid to invalid bytes has an effect. Strings which consist mostly of invalid bytes trigger the error, those which are mostly valid don't. The error corresponds to _PyBytes_Resize(), which has the following words of caution in a preceding comment: /* The following function breaks the notion that strings are immutable: it changes the size of a string. We get away with this only if there is only one module referencing the object. You can also think of it as creating a new string object and destroying the old one, only more efficiently. In any case, don't use this if the string may already be known to some other part of the code... Note that if there's not enough memory to resize the string, the original string object at *pv is deallocated, *pv is set to NULL, an "out of memory" exception is set, and -1 is returned. Else (on success) 0 is returned, and the value in *pv may or may not be the same as on input. As always, an extra byte is allocated for a trailing \0 byte (newsize does *not* include that), and a trailing \0 byte is stored. */ Assuming that this gets fixed, it should make most of the problems with 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. sys.argv_bytes and os.environ_bytes. >> However, sys.std{in,out,err} are still created as text streams, and AFAICT >> there's nothing you can do about this from within your code. > > That's intentional, and not going to change. You can access the > underlying byte streams if you want to, as you could already in 3.0. Okay, I've since been pointed to the relevant information (I was looking under "File Objects"; I didn't think to look at "sys"). From command.bbs at alexbbs.twbbs.org Mon Jun 29 07:13:00 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 29 Jun 2009 11:13:00 GMT Subject: python extend c++ module Message-ID: <4gb5PD$wPA@alexbbs.twbbs.org> I have written a c++ extend module and I use distutils to build. setup.py ---------------- from distutils.core import setup, Extension setup(name="noddy", version="1.0", ext_modules=[ Extension("noddy3", ["noddy3.cpp", "a.cpp"]) ]) I found it's quite strange when compiling. I didn't use extern "C" at all , how can python get the right c++ funciton name without any compile error?? I found that it first use gcc to compile noddy3.cpp and then link by g++. Could anyone explain what it's all about? Thanks a lot!! here is the compiling message. --------------------------------------- running install running build running build_ext building 'noddy3' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp -o build/temp.linux-i686-2.6/noddy3.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so running install_lib copying build/lib.linux-i686-2.6/noddy3.so -> /usr/local/lib/python2.6/site-packages running install_egg_info Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From ldo at geek-central.gen.new_zealand Mon Jun 29 07:21:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 29 Jun 2009 23:21:12 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message , Tim Harig wrote: > On 2009-06-29, Lawrence D'Oliveiro > wrote: > >> "apt-get install python-imaging", anybody? > > C:\>apt-get install python-imaging > Bad command or file name Sounds more like broken OS with no integrated package management. From usernet at ilthio.net Mon Jun 29 07:23:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 11:23:44 GMT Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: <4v12m.1716$8r.173@nlpi064.nbdc.sbc.com> On 2009-06-29, C. Feldmann wrote: > On 29 Jun., 11:07, Tim Harig wrote: >> On 2009-06-29, C. Feldmann wrote: >> >> > I am trying to get a hold of PIL, but pythonware.com seems to be down. >> > Are there mirrors out there? >> > I get a 502 Error "Bad Gateway - The proxy server received an invalid >> > response from an upstream server." >> > Does anyone else get that error? >> >> Yes, more info below: >> >> http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... > > yeah. need the windows version. guess this is another reason to add to > my "why I should buy a mac" list. :) The source is operating system agnostic. From python.list at tim.thechases.com Mon Jun 29 07:25:09 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 29 Jun 2009 06:25:09 -0500 Subject: pep 8 constants In-Reply-To: <4A484C07.9050800@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: <4A48A495.7040504@tim.thechases.com> >> Reject away, but I'm afraid you've still got some work to do to >> convince me that PEP 8 is more work for an SR system than any other >> convention. > > Name name > higher than normal recognition error rate. can require multiple tries or hand > correction > > MultiWordName mulitwordname > very high error rate. many retries or hand hurting typing. > > multi_word_name multiwordname > normal error rate (low), can need multiple tries or hand correction It sounds like the issue should be one of making your screen-reader smarter, not dumbing down Python conventions. I don't know what SR you're using (Jaws? Window Eyes? yasr? screeder? speakup? VoiceOver?) but it sounds like at least for the above cases, along with the PEP-8 MULTI_WORD_NAME constant convention, a simple regexp+transformation should be able to reprocess the input into something easier to handle/hear/understand. I'm not sure any/all of the previously-listed screen-readers give such regexp transformation control, but I would expect that at least the OSS ones (yasr, screeder, & speakup) it would be possible to add the feature if it doesn't already exist. For these three, you might ping the blinux mailing list to see if anybody there knows how to implement such transforms. > StdlYCps sierra tango delta lima yankee charley papa sierra > > *** very high error rate *** search and replace for all instances with a x_y_z > form name is recommended As for StuDlyCaps, it's hard on the seeing too, so I advocate a firm smack on the back of the head for those that prefer this abomination. :-) -tkc From lfscripter at gmail.com Mon Jun 29 07:28:29 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Mon, 29 Jun 2009 12:28:29 +0100 Subject: Running Invisible console Application Message-ID: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Hi, i have a console application that i want to ran (invisible) as a daemon, how can i do that? Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Jun 29 07:30:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 13:30:52 +0200 Subject: python extend c++ module In-Reply-To: <4gb5PD$wPA@alexbbs.twbbs.org> References: <4gb5PD$wPA@alexbbs.twbbs.org> Message-ID: ???????? schrieb: > I found it's quite strange when compiling. I didn't use extern "C" at all > , how can python get the right c++ funciton name without any compile error?? > > I found that it first use gcc to compile noddy3.cpp and then link by g++. > > Could anyone explain what it's all about? The Python header files already contain the necessary extern "C" declarations. You can safely import the Python.h header file in a cpp file without an extern "C" block. Christian From solipsis at pitrou.net Mon Jun 29 07:41:11 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 29 Jun 2009 11:41:11 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > This results in an internal error: > > > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") > Traceback (most recent call last): > File "", line 1, in > SystemError: Objects/bytesobject.c:3182: bad argument to internal function Please report a bug on http://bugs.python.org As for a bytes version of sys.argv and os.environ, you're welcome to propose a patch (this would be a separate issue on the aforementioned issue tracker). Thanks Antoine. From h.b.furuseth at usit.uio.no Mon Jun 29 07:57:49 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Mon, 29 Jun 2009 13:57:49 +0200 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: Nobody writes: >On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. L?wis wrote: >> See PEP 383. > > Okay, that's useful, except that it may have some bugs: > (...) > Assuming that this gets fixed, it should make most of the problems with > 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. > sys.argv_bytes and os.environ_bytes. That's hopeless to keep track of across modules if something modifies sys.argv or os.environ. If the current scheme for recovering the original bytes proves insufficient, what could work is a string type which can have an attribute with the original bytes (if the source was bytes). And/or sys.argv and os.environ maintaining the correspondence when feasible. Anyway, I haven't looked at whether any of this is a problem, so don't mind me:-) As long as it's definitely possible to tell python once and for all not to apply locales and string conversions, instead of having to keep track of an ever-expanding list of variables to tame it's bytes->character conversions (as happened with Emacs). -- Hallvard From tim.wintle at teamrubber.com Mon Jun 29 08:01:19 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 29 Jun 2009 13:01:19 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45A80F.4090600@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> Message-ID: <1246276879.21161.25.camel@tim-laptop> On Sat, 2009-06-27 at 06:03 +0100, Jo?o Valverde wrote: > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and Python, > using pyavl. Round numbers were 4 mins vs 4 seconds, against Python > (plus pyavl). Out of interest, I recently wrote something similar that imported (a class of) snort rules for blacklisting ip traffic. I could only use the standard library. I ended up writing a simple tree using dict-like objects [1]. Afraid I haven't got a taught CS background to know the name of the structure. (note insertion wasn't the focus, and I didn't bother writing it to handle updates/merges - this is a quick script I run every now and then, so I'm sure it could be done better - I just liked having the standard dict interface for each node) I only had three levels of branching, using the first octet to branch at the root node, the second octet to branch as the second node, and the final two to branch at the third node's depth (since even then that's normally sparse relative to the first two nodes). It works well enough for me - I'm IO bound reading in ip addresses from logs to check against the blacklist, and there is a fair bit of other processing going on for each line. (Obviously I converted the ip addresses to integers before doing all this to avoid hashing strings etc) [1] (As rules could be for any subnet I overloaded some of the dict methods to check against rules on unusual subnets etc. before checking individual ips in the final part) > Even considering I'm a worse Python programmer than C > programmer, it's a lot. I know many will probably think I tried to do > "C in Python" but that's not the case, at least I don' t think so. > Anyway like I said, not really relevant to this discussion. > From p.f.moore at gmail.com Mon Jun 29 08:05:51 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 29 Jun 2009 13:05:51 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <79990c6b0906290505m601bc4d2hf95622b88d3cdb17@mail.gmail.com> 2009/6/29 Antoine Pitrou : > As for a bytes version of sys.argv and os.environ, you're welcome to propose a > patch (this would be a separate issue on the aforementioned issue tracker). But please be aware that such a proposal would have to consider: 1. That on Windows, the native form is the character version, and the bytes version would have to address all the same sorts of encoding issues that the OP is complaining about in the character versions. [1] 2. That the proposal address the question of how to write portable, robust, code (given that choosing argv vs argv_bytes based on sys.platform is unlikely to count as a good option...) 3. Why defining your own argv_bytes as argv_bytes = [a.encode("iso-8859-1", "surrogateescape") for a in sys.argv] is insufficient (excluding issues with bugs, which will be fixed regardless) for the occasional cases where it's needed. Before writing the proposal, the OP should probably review the extensive discussions which can be found in the python-dev archives. It would be wrong for people reading this thread to think that the implemented approach is in any sense a "quick fix" - it's certainly a compromise (and no-one likes all aspects of any compromise!) but it's one made after a lot of input from people with widely differing requirements. Paul. [1] And my understanding, from the PEP, is that even on POSIX, the argv and environ data is intended to be character data, even though the native C APIs expose a byte-oriented interface. So conceptually, character format is "correct" on POSIX as well... (But I don't write code for POSIX systems, so I'll leave it to the POSIX users to debate this point further). From rustompmody at gmail.com Mon Jun 29 08:08:45 2009 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Jun 2009 05:08:45 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: This thread has thrown up some interesting suggestions but they all seem to fall into one of two categories: - the high-ground: Dijkstra, Knuth etc - the low-ground: write (any-which-how) a lot of code And both these 'grounds' seem to cause more argument and less suggestions for good books. Let me therefore try to find a middle-ground and make a suggestion that I used to make to my students when I taught them programming: Read the Python Manual -- specifically the library. It contains a fairly good conspectus of modern day IT/CS. Some examples of what I mean: Want to study TDD? Read unittest and doctest and then go on to reading (and practising) Kent Beck etc Want to get into unix system programming? Nothing like playing around with os.path and stat before burining your hands with C. Networking protocols? smtplib, urllib, ftplib etc Low level networking? socket, select etc Algorithms? Good to get your feet on the ground with timeit From usernet at ilthio.net Mon Jun 29 08:13:13 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 12:13:13 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-29, Lawrence D'Oliveiro wrote: > Sounds more like broken OS with no integrated package management. Package managers with dependency tracking were all the rage when I first started using Linux. So I tried Red Hat and everything worked great until the depency database corrupted itself. Since then, I have learned to install using whatever package manager but to upgrade or install new packages from source. From lanuradha at gmail.com Mon Jun 29 08:15:19 2009 From: lanuradha at gmail.com (Anul) Date: Mon, 29 Jun 2009 05:15:19 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <8bff581e-3178-44c8-b778-d7c0795b43c2@f19g2000yqo.googlegroups.com> On Jun 29, 5:08?pm, rustom wrote: > > Want to study TDD? ?Read unittest and doctest and then go on to > reading (and practising) Kent Beck etc > Want to get into unix system programming? ?Nothing like playing around > with os.path and stat before burining your hands with C. > Networking protocols? smtplib, urllib, ftplib etc > Low level networking? socket, select etc > Algorithms? Good to get your feet on the ground with timeit Ive found twisted is a good excuse to study lot of CS arcana ranging from laziness of lambdas, event driven programming From python at mrabarnett.plus.com Mon Jun 29 08:18:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 13:18:50 +0100 Subject: Running Invisible console Application In-Reply-To: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> References: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Message-ID: <4A48B12A.3060808@mrabarnett.plus.com> Elf Scripter wrote: > Hi, i have a console application that i want to ran (invisible) as > a daemon, how can i do that? > Change the extension from ".py" to ".pyw". From bieffe62 at gmail.com Mon Jun 29 08:44:27 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Mon, 29 Jun 2009 05:44:27 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: On 29 Giu, 07:10, OdarR wrote: > On 28 juin, 23:26, Tomasz Pajor wrote: > > > Hello, > > > Configuration is as follows. > > > I have a starter process which creates 3 sub processes (forks) and each > > of this processes creates a number of threads. > > Threads in that processes have semaphore so on KeyboardInterrupt without > > sending a sigterm to the subprocess i'm not able to close threads. > > Is there any work around? Can I somehow run join for the thread on > > keyboard interrupt? > > When creating a thread you can add a Queue parameter to communicate > with threads:http://docs.python.org/library/queue.html > easy and reliable. > > give them a "poison pill" in the queue: a recognizable object placed > on the queue that means "when you get this, stop." > This is the way I usually go, but it has one important limitation: if the thread is waiting for a blocking I/O operation to complete, like reading from a socket with no data or waiting for a locked resource (i.e. semaphore) to be unlocked, it will not service the queue and will not read the 'quit command' (the poison pill), and therefore will not quit until the blocking I/O terminates (and it could be never). ASAIK, there is no way - in python - to solve this. > Olivier Ciao ---- FB From peter.mosley at talk21.com Mon Jun 29 08:54:19 2009 From: peter.mosley at talk21.com (peter) Date: Mon, 29 Jun 2009 05:54:19 -0700 (PDT) Subject: Python Imaging Library download link broken? References: Message-ID: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Whilst this is an interesting discussion about installers, I'm still trying to find a copy of PIL. Any ideas? From bhardwajjayesh7 at gmail.com Mon Jun 29 08:55:39 2009 From: bhardwajjayesh7 at gmail.com (golu) Date: Mon, 29 Jun 2009 05:55:39 -0700 (PDT) Subject: problems with mysql db Message-ID: here i have posted my code...plz tell why am i getting the error "int argument required" on the hash marked line(see below) although i am giving an int value #the code import os import string import MySQLdb import stopcheck conn = MySQLdb.connect(host='localhost',user='root',db='urdb') def file_extractor(dir_name): url_count = 0 for file in os.listdir(dir_name): if(file[-4:] == '.txt'): file_path = os.path.join(dir_name,file) curse = conn.cursor() url_count += 1 curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", (url_count,file_path)) #error word_extractor(url_count,file_path) def word_extractor(url_count,file): fhandle = open(file) line = fhandle.readline() k=stopcheck.checker() k.create() while line: words = line.split() cursor = conn.cursor() for word1 in words: if word1 not in string.punctuation: if (k.check(word1) is 0) and (word1[0:4] != 'http') : word_count+=1 try: cursor.execute("INSERT INTO word_table(id,word) VALUES(%d,%s)" , (word_count,word1)) cursor.execute("INSERT INTO wordmatch (word_id,url_id) values(%d,%d)",(word_count,url_count)) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) line=fhandle.readline() if __name__ == '__main__': #url_count=0 #word_count=0 dir = os.path.join('D://','acm') file_extractor(dir) From Andras.Horvath at cern.ch Mon Jun 29 09:08:50 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Mon, 29 Jun 2009 15:08:50 +0200 Subject: validating HTTPS certificates? In-Reply-To: References: Message-ID: <20090629130850.GB7799@cern.ch> > validation. Validation should just be a matter of passing > cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking > that SSLSocket.getpeercert() returns a non-empty dictionary. That'd be cool unless I can't use an already-open socket (by SSL, for verification) in any of the built-in HTTP engines, by the look of it. Andras From aahz at pythoncraft.com Mon Jun 29 09:12:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Jun 2009 06:12:47 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> <20090629121940.42b88764@halmanfloyd.lan.local> Message-ID: In article <20090629121940.42b88764 at halmanfloyd.lan.local>, Marek Kubica wrote: >On 28 Jun 2009 11:45:06 -0700 >aahz at pythoncraft.com (Aahz) wrote: >> >> Perhaps I was unclear: I already knew what LMGTFY stands for, and I >> think that using a site that requires JavaScript is anti-social. > >Maybe they could just redirect to Google if JS wasn't detected. Exactly. They have chosen to be anti-social; therefore, I think anyone using lmgtfy.com is also anti-social. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From usernet at ilthio.net Mon Jun 29 09:25:21 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 13:25:21 GMT Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: <5h32m.1938$Wj7.746@nlpi065.nbdc.sbc.com> On 2009-06-29, peter wrote: > Whilst this is an interesting discussion about installers, I'm still > trying to find a copy of PIL. Any ideas? I alluded to a source version below. It will compile on Windows as well as on *nix. Google finds what looks like older versions here: http://sping.sourceforge.net/PIL/ From petr.messner at gmail.com Mon Jun 29 09:32:40 2009 From: petr.messner at gmail.com (Petr Messner) Date: Mon, 29 Jun 2009 15:32:40 +0200 Subject: problems with mysql db In-Reply-To: References: Message-ID: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Hi, use %s instead of %d in SQL statements, because (AFAIK) conversions (including SQL escaping) from Python values to SQL values are done before the % operator is called - that value is not a number by that point. I hope you understood it, sorry for my English :-) You can also check MySQLdb module source, it's pretty clear. PM 2009/6/29 golu : > here i have posted my code...plz tell why am i getting the error "int > argument required" on the hash marked line(see below) although i am > giving an int value > #the code > import os > import string > import MySQLdb > import stopcheck > conn = MySQLdb.connect(host='localhost',user='root',db='urdb') > > def file_extractor(dir_name): > url_count = 0 > > for file in os.listdir(dir_name): > if(file[-4:] == '.txt'): > file_path = os.path.join(dir_name,file) > curse = conn.cursor() > url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > (url_count,file_path)) #error > word_extractor(url_count,file_path) > def word_extractor(url_count,file): > fhandle = open(file) > line = fhandle.readline() > k=stopcheck.checker() > k.create() > > while line: > words = line.split() > cursor = conn.cursor() > for word1 in words: > if word1 not in string.punctuation: > if (k.check(word1) is 0) and (word1[0:4] != 'http') : > word_count+=1 > try: > cursor.execute("INSERT INTO word_table(id,word) > VALUES(%d,%s)" , (word_count,word1)) > cursor.execute("INSERT INTO wordmatch > (word_id,url_id) values(%d,%d)",(word_count,url_count)) > except MySQLdb.Error, e: > print "Error %d: %s" % (e.args[0], e.args[1]) > line=fhandle.readline() > > if __name__ == '__main__': > #url_count=0 > #word_count=0 > > dir = os.path.join('D://','acm') > file_extractor(dir) > -- > http://mail.python.org/mailman/listinfo/python-list > From charles at declareSub.com Mon Jun 29 10:16:22 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 29 Jun 2009 10:16:22 -0400 Subject: Running Invisible console Application In-Reply-To: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> References: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Message-ID: On Jun 29, 2009, at 7:28 AM, Elf Scripter wrote: > Hi, i have a console application that i want to ran (invisible) as a > daemon, how can i do that? > Search the web for python + daemon. I found plenty of code, including mostly prewritten solutions, for my own work. Charles Yemans From python-url at phaseit.net Mon Jun 29 10:16:23 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Mon, 29 Jun 2009 14:16:23 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 29) Message-ID: QOTW: "Fortunately, I have assiduously avoided the real wor[l]d, and am happy to embrace the world from our 'bot overlords. Congratulations on another release from the hydra-like world of multi-head development." - Scott David Daniels, on release of 3.1 http://groups.google.com/group/comp.lang.python/msg/620d014fb549dbe6 A success story (involving a game server): http://groups.google.com/group/comp.lang.python/browse_thread/thread/11abba7af6e266b0/ Floats and Decimal objects demythified: http://groups.google.com/group/comp.lang.python/browse_thread/thread/77a9ecc671602e79/ Converting Python code to C/C++: how to do it, alternatives, and when it would be advisable: http://groups.google.com/group/comp.lang.python/browse_thread/thread/7152ab4f1c7dbced/ A generator expression declared at class scope: the namespace resolution rules aren't so intuitive: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e1ab6188673fc623/ A look at 2.1 sample code shows how much (or how little) the language evolved over time: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3e2139c2191bb191/ No "tree" data structure is available in the standard library - should one exist? http://groups.google.com/group/comp.lang.python/browse_thread/thread/c632217cfc7c7dcc/ Correctly implementing rich comparisons so 'set' membership works as expected: http://groups.google.com/group/comp.lang.python/browse_thread/thread/c0b1c58585c110eb/ Python threading and the GIL (again): http://groups.google.com/group/comp.lang.python/browse_thread/thread/9e22ab012388b538/ In ElementTree, XML() and fromstring() aren't the same thing: http://groups.google.com/group/comp.lang.python/browse_thread/thread/397f410b060afca2/ Open source Python projects that need help: http://groups.google.com/group/comp.lang.python/browse_thread/thread/667b9922a60ea836/ Meta issue: some posts appear to be missing, depending on where you read this (the mailing list, the newsgroup, the gmane gateway...) http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cc24ff07dfd3afd/e7ad466392094c8c?#e7ad466392094c8c http://groups.google.com/group/comp.lang.python/browse_thread/thread/f67e695fa6364ec9/9174d8c5b4f07f74?#9174d8c5b4f07f74 [OT] Measuring Fractal Dimension (mad mathematicians only): http://groups.google.com/group/comp.lang.python/browse_thread/thread/a258b6c9005146c5/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From marshalc at carleton.edu Mon Jun 29 10:28:07 2009 From: marshalc at carleton.edu (Chris Marshall) Date: Mon, 29 Jun 2009 09:28:07 -0500 (CDT) Subject: Configuring Python for Tcl/Tk in UNIX Message-ID: <542109298.163561246285687188.JavaMail.root@mail2.its.carleton.edu> My goal is to use Tkinter on a ScientificLinux machine for a GUI I wrote. I installed Python 2.6.2, then built Tcl and Tk 8.5.7 from source. The final step is to configure Python 2.6 to run Tk. When I use the "make" command in the Python 2.6.2 directory, all is well until it tries to built _tkinter.so. I get an error as follows: *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory. Failed to build the following modules: _tkinter I cannot use the default install location of /usr/bin, so I am trying to install into another directory. I line-by-line edited the setup.py file to point to the proper directory and I get the same error. Has anyone had a similar problem? Any advice is greatly appreciated. Thanks, Chris From gagsl-py2 at yahoo.com.ar Mon Jun 29 10:43:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 11:43:26 -0300 Subject: creating garbage collectable objects (caching objects) References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> <4A489F00.1040003@ieee.org> Message-ID: En Mon, 29 Jun 2009 08:01:20 -0300, Dave Angel escribi?: > News123 wrote: >> What I was more concerned is a group of output images depending on TWO >> or more input images. >> >> Depending on the platform (and the images) I might not be able to >> preload all two (or more images) >> >> So, as CPython's garbage collection takes always place immediately, >> then I'd like to pursue something else. >> I can create a cache, which caches input files as long as python leaves >> at least n MB available for the rest of the system. > As I said earlier, I think weakref is probably what you need. A weakref > is still a reference from the point of view of the ref-counting, but not > from the point of view of the garbage collector. Have you read the help > on weakref module? In particular, did you read Pep 0205? > http://www.python.org/dev/peps/pep-0205/ You've misunderstood something. A weakref is NOT "a reference from the point of view of the ref-counting", it adds zero to the reference count. When the last "real" reference to some object is lost, the object is destroyed, even if there exist weak references to it. That's the whole point of a weak reference. The garbage collector isn't directly related. py> from sys import getrefcount as rc py> class X(object): pass ... py> x=X() py> rc(x) 2 py> y=x py> rc(x) 3 py> import weakref py> r=weakref.ref(x) py> r py> rc(x) 3 py> del y py> rc(x) 2 py> del x py> r (remember that getrefcount -as any function- holds a temporary reference to its argument, so the number it returns is one more than the expected value) > Object cache is one of the two reasons for the weakref module. ...when you don't want the object to stay artificially alive just because it's referenced in the cache. But the OP wants a different behavior, it seems. A standard dictionary where images are removed when they're no more needed (or a memory restriction is fired). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jun 29 10:59:59 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 11:59:59 -0300 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: En Mon, 29 Jun 2009 10:32:40 -0300, Petr Messner escribi?: > use %s instead of %d in SQL statements, because (AFAIK) conversions > (including SQL escaping) from Python values to SQL values are done > before the % operator is called - that value is not a number by that > point. > > I hope you understood it, sorry for my English :-) You can also check > MySQLdb module source, it's pretty clear. It's best to think of %s as just a marker; other adapters use ? or :3 for the same purpose, and other styles exist too. The fact that it's the same character used for formatting strings with the % operator is an unfortunate coincidence (or a very bad choice, I don't know). -- Gabriel Genellina From esj at harvee.org Mon Jun 29 11:03:05 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:03:05 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A48D7A9.40905@harvee.org> Peter Otten wrote: > Eric S. Johansson wrote: > >> MultiWordName mulitwordname >> very high error rate. many retries or hand hurting typing. > > Can you define macros in your speech recognition software? > > multiwordname > > might slightly lower the error rate. > Yes it would. I think it would be possible to specify a better grammar however. In the context of speech engine, if you know how the word is going to be used, (i.e. it's a method, it's a class, etc.) you can automatically do the transformation as part of the editors function. You need to know where you are in the syntax tree and that gives you enough knowledge to do the name transformation. When you stop thinking of speech recognition interactions as discrete macros or magic tricks, you can do a lot to accelerate coding. Fruit equals pear tree sub branch plus 5 The translator should know that the name on the lval is a variable (type signature determined later) and is terminated by the word equals (or =). The system would then apply the appropriate the name transformation. Continue on, equals would be transformed =, pear tree would be considered a complete name and based on whether it is a class definition or instance, would be transformed as a single name. Sub means there's an index here and would put the appropriate brackets between the expression branch (symbol terminated by plus) and 5 (symbol terminated by the end of line, fruit = pear_tree[branch+5] The next challenge comes in editing. It's fairly simple I would like to say "edit line [1*]" and put that line in an isolated buffer where I can edit the English form using all of the Select-and-Say controls. That should close the cycle from creation through editing. a small port of the development cycle. fyiw, the symbol trandformation code exists and has existed for almost 10 years. we need smart editing environments to make use of it. From nobody at nowhere.com Mon Jun 29 11:16:32 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 16:16:32 +0100 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: On Mon, 29 Jun 2009 13:57:49 +0200, Hallvard B Furuseth wrote: >> Okay, that's useful, except that it may have some bugs: >> (...) >> Assuming that this gets fixed, it should make most of the problems with >> 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. >> sys.argv_bytes and os.environ_bytes. > > That's hopeless to keep track of across modules if something modifies > sys.argv or os.environ. Oh, I wasn't suggesting that they should be updated. Just that there should be some way to get at the original data. The mechanism used in 3.1 is sufficient. I'm mostly concerned that it's *possible* to recover the data; convenience is of secondary importance. Calling sys.setfilesystemencoding('iso-8859-1') right at the start of the code eliminates most of the issues. It's just the stuff which happens before the first line of code is executed (sys.argv, os.environ, sys.stdin etc) which was problematic. [BTW, it isn't just Python that has problems. The directory where I was performing tests happened to be an svn checkout. A subsequent "svn update" promptly crapped out because I'd left behind a file whose name wasn't valid ASCII.] From sk8in_zombi at yahoo.com.au Mon Jun 29 11:25:17 2009 From: sk8in_zombi at yahoo.com.au (Mr SZ) Date: Mon, 29 Jun 2009 08:25:17 -0700 (PDT) Subject: Find the name of a setup tools plugin when its class is known. Message-ID: <591684.58381.qm@web54504.mail.re2.yahoo.com> Hi, Using pkg_resources, I can iterate through the plugins in an entrypoint and note down the plugin classes and all using "pkg_resources.iter_entry_points(ENTRYPOINT)" Now, when the plugin is loaded, I want to know it's entrypoint name as I have to load a bunch of settings identified by the name string. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From nobody at nowhere.com Mon Jun 29 11:35:46 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 16:35:46 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Mon, 29 Jun 2009 11:41:11 +0000, Antoine Pitrou wrote: > Nobody nowhere.com> writes: >> >> This results in an internal error: >> >> > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") >> Traceback (most recent call last): >> File "", line 1, in >> SystemError: Objects/bytesobject.c:3182: bad argument to internal function > > Please report a bug on http://bugs.python.org Done. > As for a bytes version of sys.argv and os.environ, you're welcome to propose a > patch (this would be a separate issue on the aforementioned issue tracker). Assuming that the above bug gets fixed, it isn't really necessary. In particular, maintaining bytes/string versions in the presence of updates is likely to be more trouble than it's worth. From aaron.hildebrandt at gmail.com Mon Jun 29 11:47:34 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Mon, 29 Jun 2009 08:47:34 -0700 (PDT) Subject: Using Python for file packing Message-ID: I'm working on a Python application right now that uses a large number of audio assets. Instead of having a directory full of audio, I'd like to pack all the audio into a single file. Is there any easy way to do this in Python? My first instinct was to attempt to pickle all the audio data, but something tells me that that experiment would only end in tears. From esj at harvee.org Mon Jun 29 11:49:04 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:49:04 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A48E270.6000403@harvee.org> alex23 wrote: > "Eric S. Johansson" wrote: >> no, I know the value if convention when editors can't tell you anything about >> the name in question. I would like to see more support for disabled programmers >> like myself and the thousands of programmers injured every year and forced to >> leave the field. seriously, there is no money in disability access especially >> for programmers. > > Well, if we can't use conventions like uppercasing, camelcasing and > underscoring, what are you recommending we do instead? help build a smart editing environment please. > > You seem to be asking us to change our behaviour to benefit only > others, but without offering any guidance on to how that is possible. > More importantly, shouldn't these modifications to common conventions > be coming _from_ the community of disabled programmers? I have a hard > time ensuring that I've gotten accurate requirements from co-workers > with whom I can actually see and speak, trying to determine how I > could write my code with accessibility in mind without any established > means of gauging success just seems impossible. Extremely valid point. The behavior I'm asking you to change is to consider the impact choices you make have on people with disabilities. I can only advocate for disabled programmer since I am one. Have been so for over 15 years. Have tried to maintain my position as architectural expert only to receive from venture capitalists and the likes "what good are you, you can't know enough to design our systems because you can't code" (yes, real quote). This is not always the case but enough that it really hurts my economics as well as the economics of other disabled programmers. Back in early 2000, I ran a series of workshops on the very issue of programming by voice. Back then we recognized the necessity for very smart editing environments which can tell us enough about what each symbol means so that we can direct the appropriate transformations from a higher-level grammar. I've introduce concepts such as command disambiguation through reduction of scope. Other people have added very good ideas with regards to usability and user interfaces for speech driven environment. Unfortunately, they all are gluons to an editor and they don't really integrate well because the editor isn't smart enough. Heck, have you ever noticed how most Python smart editors can't even indent properly according to local contexts. Emacs is the only one and even that one sometimes fails I can give you guidance as to what needs to be done. Other people can give guidance but I'm shooting for what may seem unachievable. Work with me a while and I will guide you as to how it's achievable. Maybe not by you but by someone we can find. I have lived way too many years with circus tricks. I don't want to end my life realizing I wasted my time in IT and regretting that I didn't take up the offer by mass rehab to go in restaurant or hotel management. one thing you can do to get a feel for out life is to get a copy of Naturally Speaking standard (100$ staples) and remove/cover keyboard. write email etc at first (10h) then try to write pep8 code. note to anyone who tries this, I'll support you in getting DNS running and help figure out any problems. only cost is if I tell you to do something like get a new mic, *do it*. I've lived this works and probably have put more deep thought and 8kloc into it because I do not accept circures tricks as a way of life. I want it to work right and I know how to do it. I just don't have the hands and hte money to pay me to do it. > >> and forgive me if this comes off sounding like a jerk but if >> the collective you don't give a sh** about your fellow programmers, who will? > > This isn't intended to be callous, as I feel that the collective > doesn't care as a whole about _any_ programmers, but isn't the answer > the very same disabled programmers for whom accessibility is an issue? > Programming tends to be needs driven (which, admittedly, can be simply > "to pay the bills"), and those who have a need tend to be better at > working out how to address it. yup how long will i be before you become disablesd? maybe not as badly as I am but you should start feeling some hand problems in your later 40's to early 50's and it goes down hill from there. self preservation/interest comes to mind as a possible motive for action. I thought 15 years would be enough for somebody else to push the isssue but no. if it is going to be, it has to be me. > > One possibility may be to approach a group for whom accessibility is > already a consideration, such as the Gnome Accessibility Project: > http://live.gnome.org/GAP not right focus for this project. tis one needs **deep** python knowledge (gvr level) and embedding it into an editor. heck, maybe we need a python interpreter in the editor to resolve some of the symbol stuff if we can get useful data from incomplete code. and I'll leave you an editor feature that may be usefull for all symbol not defined: choose from list or create new. I'll explain later. thanks for you thoughtful reply. From esj at harvee.org Mon Jun 29 11:51:35 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:51:35 -0400 Subject: pep 8 constants In-Reply-To: <4A48A495.7040504@tim.thechases.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> Message-ID: <4A48E307.50804@harvee.org> Tim Chase wrote: It sounds like the issue should be one of making your screen-reader > smarter, not dumbing down Python conventions. I don't know what SR > you're using (Jaws? Window Eyes? yasr? screeder? speakup? Naturally speaking is speech recognition (speech in text out) it is not text to speech although it does have a pluging for that From Scott.Daniels at Acm.Org Mon Jun 29 11:52:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 08:52:48 -0700 Subject: problems with mysql db In-Reply-To: References: Message-ID: golu wrote: > here i have posted my code...plz tell why am i getting the error "int > argument required" on the hash marked line(see below) although i am > giving an int value > ... url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > (url_count,file_path)) #error > ... Try something more like: > ... url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > [(url_count,file_path)]) > ... From davea at ieee.org Mon Jun 29 12:12:38 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 29 Jun 2009 12:12:38 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> <4A489F00.1040003@ieee.org> Message-ID: <4A48E7F6.9020404@ieee.org> Gabriel Genellina wrote: >
En Mon, > 29 Jun 2009 08:01:20 -0300, Dave Angel escribi?: >> News123 wrote: > >>> What I was more concerned is a group of output images depending on TWO >>> or more input images. >>> >>> Depending on the platform (and the images) I might not be able to >>> preload all two (or more images) >>> >>> So, as CPython's garbage collection takes always place immediately, >>> then I'd like to pursue something else. >>> I can create a cache, which caches input files as long as python leaves >>> at least n MB available for the rest of the system. > >> As I said earlier, I think weakref is probably what you need. A >> weakref is still a reference from the point of view of the >> ref-counting, but not from the point of view of the garbage >> collector. Have you read the help on weakref module? In particular, >> did you read Pep 0205? http://www.python.org/dev/peps/pep-0205/ > > You've misunderstood something. A weakref is NOT "a reference from the > point of view of the ref-counting", it adds zero to the reference > count. When the last "real" reference to some object is lost, the > object is destroyed, even if there exist weak references to it. That's > the whole point of a weak reference. The garbage collector isn't > directly related. > > py> from sys import getrefcount as rc > py> class X(object): pass > ... > py> x=X() > py> rc(x) > 2 > py> y=x > py> rc(x) > 3 > py> import weakref > py> r=weakref.ref(x) > py> r > > py> rc(x) > 3 > py> del y > py> rc(x) > 2 > py> del x > py> r > > > (remember that getrefcount -as any function- holds a temporary > reference to its argument, so the number it returns is one more than > the expected value) > >> Object cache is one of the two reasons for the weakref module. > > ...when you don't want the object to stay artificially alive just > because it's referenced in the cache. But the OP wants a different > behavior, it seems. A standard dictionary where images are removed > when they're no more needed (or a memory restriction is fired). > Thanks for correcting me. As I said earlier, I have no experience with weakref. The help and the PEP did sound to me like it would work for his needs. So how about adding an attribute in the large object that refers to the object iself?. Then the ref count will never go to zero, but it can be freed by the gc. Also store the ref in a WeakValueDictionary, and you can find the object without blocking its gc. And no, I haven't tried it, and wouldn't unless a machine had nothing important running on it. Clearly, the gc might not be able to keep up with this kind of abuse. But if gc is triggered by any attempt to make too-large an object, it might work. DaveA From nobody at nowhere.com Mon Jun 29 12:17:17 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 17:17:17 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Mon, 29 Jun 2009 13:05:51 +0100, Paul Moore wrote: >> As for a bytes version of sys.argv and os.environ, you're welcome to >> propose a patch (this would be a separate issue on the aforementioned >> issue tracker). > > But please be aware that such a proposal would have to consider: > > 1. That on Windows, the native form is the character version, and the > bytes version would have to address all the same sorts of encoding > issues that the OP is complaining about in the character versions. [1] A bytes version doesn't make sense on Windows (at least, not on the NT-based versions, and the DOS-based branch isn't worth bothering about, IMHO). Also, Windows *needs* to deal with characters due to the fact that filenames, environment variables, etc are case-insensitive. > 2. That the proposal address the question of how to write portable, > robust, code (given that choosing argv vs argv_bytes based on > sys.platform is unlikely to count as a good option...) There is a tension here between robustness and portability. In my situation, robustness means getting the "unadulterated" data. I can always adulterate it myself if I need to. > 3. Why defining your own argv_bytes as argv_bytes = > [a.encode("iso-8859-1", "surrogateescape") for a in sys.argv] is > insufficient (excluding issues with bugs, which will be fixed > regardless) for the occasional cases where it's needed. Other than the bug, it appears to be sufficient. I don't need to support a locale where nl_langinfo(CODESET) is ISO-2022 (I *do* need to support lossless round-trip of ISO-2022 filenames, possibly stored in argv and maybe even in environ, but that's a different matter; the code only really needs to run with LANG=C). > [1] And my understanding, from the PEP, is that even on POSIX, the > argv and environ data is intended to be character data, even though > the native C APIs expose a byte-oriented interface. So conceptually, > character format is "correct" on POSIX as well... (But I don't write > code for POSIX systems, so I'll leave it to the POSIX users to debate > this point further). Even if it's "intended" to be character data, it isn't *required* to be. In particular, it's not required to be in the locale's encoding. A common example of what I need to handle is: find /www ... -print0 | xargs -0 myscript where the filenames can be in a wide variety of different encodings (sometimes even within a single directory). From lfscripter at gmail.com Mon Jun 29 12:18:20 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Mon, 29 Jun 2009 17:18:20 +0100 Subject: Creating an Instance Messenger type of application Message-ID: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> Hello,Has anyone created an Instance Messenger in Python before, i mean a simple or Complex GUI based instance messenger? I thought about something like, the client also act as server, has it`s own listening port, but how can i handle uer auth? and adding visual effects to it. Please i am not trying to design another Yahoo IM/Skype but just for learning and also want to create real live application using the socket module. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchimento at gmail.com Mon Jun 29 12:19:31 2009 From: dchimento at gmail.com (Doug) Date: Mon, 29 Jun 2009 09:19:31 -0700 (PDT) Subject: Ctypes, pthreads and pthread_mutex_t Message-ID: <3ab1306f-3f37-403f-9768-81b657c87409@j14g2000vbp.googlegroups.com> Has any converted the structure pthread_mutex_t to a ctypes structure class ? I looking at some C code that is using pthreads and need to translate pthreads_mutex_t structure into python (via ctypes) Thanks From javier.collado at gmail.com Mon Jun 29 12:20:41 2009 From: javier.collado at gmail.com (Javier Collado) Date: Mon, 29 Jun 2009 18:20:41 +0200 Subject: Making code run in both source tree and installation path Message-ID: Hello, I would like to be able to run the main script in a python project from both the source tree and the path in which it's installed on Ubuntu. The script, among other things, imports a package which in turns makes use of some data files that contains some metadata that is needed in xml format. The source tree has an structure such as this one: setup.py debian/ (packaging files) src/ (source code) src/lib (package files) src/data (data files) src/bin (main script) However, when the project is installed using setup.py install, the directory structure is approximately this way: /usr/local/bin (main script) /usr/local/share/ (data files) /usr/local/lib/python2.x/dist-packages/ (library files) And when installing the code through a package, the structure is the same one, but removing "local". Hence, the data files aren't always in the same relative directories depending on we're executing code from the source tree or from the installation. To make it possible to run the code from both places, I've seen different approaches: - distutils trick in setup.py to modify the installed script (i.e. changing a global variable value) so that it has a reference to the data files location. - Heuristic in the package code to detect when it's being executed from the source tree and when it has been the installed - Just using an environment variable that the user must set according to his needs I guess that there are other options, for example, maybe using buildout. What would you say it's the best/more elegant option to solve this problem? Best regards, Javier From kushal.kumaran+python at gmail.com Mon Jun 29 12:23:17 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 29 Jun 2009 21:53:17 +0530 Subject: Using Python for file packing In-Reply-To: References: Message-ID: <1e364c4e0906290923l2733e49es5ad85090c6a115ef@mail.gmail.com> On Mon, Jun 29, 2009 at 9:17 PM, Aaron Scott wrote: > I'm working on a Python application right now that uses a large number > of audio assets. Instead of having a directory full of audio, I'd like > to pack all the audio into a single file. Is there any easy way to do > this in Python? My first instinct was to attempt to pickle all the > audio data, but something tells me that that experiment would only end > in tears. Do you mean like a zip or tar file? http://docs.python.org/library/zipfile.html http://docs.python.org/library/tarfile.html -- kushal From aaron.hildebrandt at gmail.com Mon Jun 29 12:35:01 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Mon, 29 Jun 2009 09:35:01 -0700 (PDT) Subject: Using Python for file packing References: Message-ID: > Do you mean like a zip or tar file? > > http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html > I had no idea you could access a single file from a ZIP or TAR without explicitly extracting it somewhere. Thanks. From sajmikins at gmail.com Mon Jun 29 12:42:39 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 12:42:39 -0400 Subject: Creating an Instance Messenger type of application In-Reply-To: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> References: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> Message-ID: <50f98a4c0906290942s75b3bebl856ab7bc1688429e@mail.gmail.com> On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripter wrote: > Hello, > Has anyone created an Instance Messenger in Python before, i mean a simple > or Complex GUI based instance messenger? > I thought about something like, the client also act as server, has it`s own > listening port, but how can i handle uer auth? and adding visual effects to > it. > Please i am not trying to design another Yahoo IM/Skype but just for > learning and also want to create real live application using the socket > module. Instant, not Instance, Did you check google? From tomasz.dysinski at gmail.com Mon Jun 29 12:43:27 2009 From: tomasz.dysinski at gmail.com (bunnybones) Date: Mon, 29 Jun 2009 09:43:27 -0700 (PDT) Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> <4v12m.1716$8r.173@nlpi064.nbdc.sbc.com> Message-ID: <01fa223c-838d-446b-81c6-f7ed74da81e6@h2g2000yqg.googlegroups.com> I'm having the same problem accessing pythonware or effbot. I can't find any news about their server status. I can ping both addresses just fine. Does anyone know what is going on? Maybe the ghosts of celebrities recently passed are mucking with the tubes. RIP Billy Mays From sajmikins at gmail.com Mon Jun 29 12:58:00 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 12:58:00 -0400 Subject: Creating an Instance Messenger type of application In-Reply-To: <6be1e1a30906290944m332fa62as12c134f78d00c715@mail.gmail.com> References: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> <50f98a4c0906290942s75b3bebl856ab7bc1688429e@mail.gmail.com> <6be1e1a30906290944m332fa62as12c134f78d00c715@mail.gmail.com> Message-ID: <50f98a4c0906290958k4c646ac6pa5991994ae3f568d@mail.gmail.com> On Mon, Jun 29, 2009 at 12:44 PM, Elf Scripter wrote: > Thank you for correcting my mistake. > I checked google but nothing close. did you have any idea? > > On Mon, Jun 29, 2009 at 5:42 PM, Simon Forman wrote: >> >> On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripter >> wrote: >> > Hello, >> > Has anyone created an Instance Messenger in Python before, i mean a >> > simple >> > or Complex GUI based instance messenger? >> > I thought about something like, the client also act as server, has it`s >> > own >> > listening port, but how can i handle uer auth? and adding visual effects >> > to >> > it. >> > Please i am not trying to design another Yahoo IM/Skype but just for >> > learning and also want to create real live application using the socket >> > module. >> >> Instant, not Instance, ?Did you check google? > > I wouldn't try writing an IM or IRC client and/or server directly on the socket module, unless you really really wanted the learning experience. You might look at the "words" sub-project of the Twisted project [1] (although Twisted code has a significant learning curve itself, they do almost all of the network related heavy lifting for you.) There's also apparently a python binding to something called libpurple which seems to be a library used/provided by the "purple" multi-protocol IM/IRC client (used to be called GAIM). [2] HTH, ~Simon [1] http://twistedmatrix.com/trac/wiki/TwistedWords [2] http://briglia.net/wiki/tiki-index.php?page=Python-purple+Howto From Olivier.Darge at gmail.com Mon Jun 29 13:32:43 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 29 Jun 2009 10:32:43 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: <0b0454b8-aec1-40e4-b156-49030f80a46b@b9g2000yqm.googlegroups.com> On 29 juin, 14:44, Francesco Bochicchio wrote: > On 29 Giu, 07:10, OdarR wrote: > > > > > On 28 juin, 23:26, Tomasz Pajor wrote: > > > > Hello, > > > > Configuration is as follows. > > > > I have a starter process which creates 3 sub processes (forks) and each > > > of this processes creates a number of threads. > > > Threads in that processes have semaphore so on KeyboardInterrupt without > > > sending a sigterm to the subprocess i'm not able to close threads. > > > Is there any work around? Can I somehow run join for the thread on > > > keyboard interrupt? > > > When creating a thread you can add a Queue parameter to communicate > > with threads:http://docs.python.org/library/queue.html > > easy and reliable. > > > give them a "poison pill" in the queue: a recognizable object placed > > on the queue that means "when you get this, stop." > > This is the way I usually go, but it has one important limitation: if > the thread is waiting > for a blocking I/O operation to complete, like reading from a socket > with no data or waiting add a small wait (time.sleep()), and also, I/O function in Python can often releas the GIL... > for a locked resource (i.e. semaphore) to be unlocked, it will not > service the queue and will > not read the 'quit command' (the poison pill), and therefore will not > quit until the blocking > I/O terminates (and it could be never). > > ASAIK, there is no way - in python - to solve this. no easy way, yes... but I think I gave a good advice to our friend Tomasz :) Olivier From destroooooy at gmail.com Mon Jun 29 13:54:38 2009 From: destroooooy at gmail.com (destroooooy) Date: Mon, 29 Jun 2009 10:54:38 -0700 (PDT) Subject: python library call equivalent to `which' command Message-ID: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine the output from `which' itself, but I would like something more portable. I looked through the `os' and `os.path' modules but I didn't find anything. TIA Craig From hjtoi-better-remove-before-reply at comcast.net Mon Jun 29 14:22:37 2009 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Mon, 29 Jun 2009 11:22:37 -0700 Subject: validating HTTPS certificates? References: Message-ID: Andras.Horvath at cern.ch wrote: > I'm in the process of picking a language for a client application that > accesses a HTTPS (actually SOAP) server. This would be easy enough in > Python, but I came across a strange fact: neither httplib nor urllib > offer the possibility to actually verify the server's certificate. Right, stdlib does not do this for you automatically. You'd either need to write that code yourself, or use a third party library. I wrote a long post about this when 2.6 came out: http://www.heikkitoivonen.net/blog/2008/10/14/ssl-in-python-26/ -- Heikki Toivonen From ethan at stoneleaf.us Mon Jun 29 14:25:11 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Jun 2009 11:25:11 -0700 Subject: pep 8 constants In-Reply-To: <4A48E270.6000403@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> Message-ID: <4A490707.3040207@stoneleaf.us> Eric S. Johansson wrote: > > yup how long will i[t] be before you become disablesd? maybe not as badly as I am > but you should start feeling some hand problems in your later 40's to early 50's > and it goes down hill from there. self preservation/interest comes to mind as a > possible motive for action. I thought 15 years would be enough for somebody > else to push the isssue but no. if it is going to be, it has to be me. For anyone who is still able to use their hands for typing, especially if you're beginning to encounter the painful wrists, consider switching to a Dvorak layout. It was a system I was curious about even before I needed it, and when I did need it I was able to create the layout in assembler (now, of course, it's widely available as a standard keyboard layout). I started noticing the pain in my late twenties (aggravated, I'm sure, by arthritis), but with switching to Dvorak the pain left and has only very rarely been noticable again. It will mostly likely be a challenge to switch, but well worth it. http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard ~Ethan~ From georgedogaru at gmail.com Mon Jun 29 14:42:11 2009 From: georgedogaru at gmail.com (geo) Date: Mon, 29 Jun 2009 11:42:11 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: <26759d8f-be58-4c44-a524-015d64323dce@l31g2000yqb.googlegroups.com> On Jun 29, 2:54?pm, peter wrote: > Whilst this is an interesting discussion about installers, I'm still > trying to find a copy of PIL. ?Any ideas? Hello, I had the very same problem and found this: http://www.portablepython.com/ It contains PIL and some other cool stuff. Hope it helps. George From timpinkawa at gmail.com Mon Jun 29 14:53:30 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 13:53:30 -0500 Subject: python library call equivalent to `which' command In-Reply-To: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 12:54 PM, destroooooy wrote: > Hi, > I'm looking for a Python library function that provides the same > functionality as the `which' command--namely, search the $PATH > variable for a given string and see if it exists anywhere within. I > currently examine the output from `which' itself, but I would like > something more portable. I looked through the `os' and `os.path' > modules but I didn't find anything. This works on POSIX systems. Windows uses semicolons to separate paths rather than colons so that would need to be taken into account when running on Windows. This also doesn't recognize shell built-ins, only real binaries. import os def which(file): for path in os.environ["PATH"].split(":"): if file in os.listdir(path): print "%s/%s" % (path, file) >>> which("ls") /bin/ls From mail at timgolden.me.uk Mon Jun 29 14:58:00 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 29 Jun 2009 19:58:00 +0100 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A490EB8.3030101@timgolden.me.uk> Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 12:54 PM, destroooooy wrote: >> Hi, >> I'm looking for a Python library function that provides the same >> functionality as the `which' command--namely, search the $PATH >> variable for a given string and see if it exists anywhere within. I >> currently examine the output from `which' itself, but I would like >> something more portable. I looked through the `os' and `os.path' >> modules but I didn't find anything. > > This works on POSIX systems. Windows uses semicolons to separate paths > rather than colons so that would need to be taken into account when > running on Windows. This also doesn't recognize shell built-ins, only > real binaries. > > import os > > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) > >>>> which("ls") > /bin/ls There's a "which.py" in the tools directory included in the Python distribution. On windows, that's c:\python26\tools\scripts; don't know where to look on Linux. Don't know how good it is as I -- like many, I suspect -- wrote my own, which in my case is Windows-specific. TJG From mabdelkader at gmail.com Mon Jun 29 15:03:14 2009 From: mabdelkader at gmail.com (ma) Date: Mon, 29 Jun 2009 15:03:14 -0400 Subject: TWiki Python API Wrapper Message-ID: <148918f0906291203i222ca6i1eabc2e46656ba9e@mail.gmail.com> Has anyone come across a decent python API wrapper for TWiki? I'm trying to automate some reports and logs to automatically post, create topics, and re-arrange a few things on our TWiki, but my googleFu has failed me :( I did find an interesting module in Perl, http://cpanratings.perl.org/dist/WWW-Mechanize-TWiki . Looking at the TWiki documentations, I found a perl API reference: http://twiki.org/cgi-bin/view/TWiki/TWikiFuncDotPm . A proof of concept, using these two perl modules, was generated by a blog post here: http://roberthanson.blogspot.com/2006/01/copying-from-blogger-to-twiki-with.html Before I make my own pythonic port, using mechanize, and wrapping around the aforementioned TWiki api, I wanted to see if anyone had any other ideas, approaches, or modules to help expedite the task? Thanks! Mahmoud Abdelkader -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jun 29 15:06:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 15:06:52 -0400 Subject: No trees in the stdlib? In-Reply-To: <7xeit3ae58.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. Now I get what your have been talking about over several posts. Update and mutate are kind of synonymous in my mind, but the above explains how they can be different. This > trivially lets you maintain snapshots of old versions of the tree, > implement an "undo" operation, have a background thread do a complex > operation on a snapshot while the foreground thread does any number of > update-and-replace operations, etc. > > This is very standard stuff. Now for someone raised on arrays, iteration, and procedural programming ;-). > http://en.wikipedia.org/wiki/Persistent_data_structure Reading it now. > > The wikipedia article on AVL trees makes it pretty obvious how an > implementation would work. From gordon at panix.com Mon Jun 29 15:15:08 2009 From: gordon at panix.com (John Gordon) Date: Mon, 29 Jun 2009 19:15:08 +0000 (UTC) Subject: Q: finding distance between 2 time's References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: In <023130ef$0$19421$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: > > if time_difference < 3601: > That's a potential off-by-one error. [...] The right test is: > if time_difference <= 3600: Aren't those two comparisons the same? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From esj at harvee.org Mon Jun 29 15:15:32 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 15:15:32 -0400 Subject: pep 8 constants In-Reply-To: <4A490707.3040207@stoneleaf.us> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> <4A490707.3040207@stoneleaf.us> Message-ID: <4A4912D4.5070900@harvee.org> Ethan Furman wrote: > Eric S. Johansson wrote: >> >> yup how long will i[t] be before you become disablesd? maybe not as >> badly as I am >> but you should start feeling some hand problems in your later 40's to >> early 50's >> and it goes down hill from there. self preservation/interest comes to >> mind as a >> possible motive for action. I thought 15 years would be enough for >> somebody >> else to push the isssue but no. if it is going to be, it has to be me. > > For anyone who is still able to use their hands for typing, especially > if you're beginning to encounter the painful wrists, consider switching > to a Dvorak layout. It was a system I was curious about even before I > needed it, and when I did need it I was able to create the layout in > assembler (now, of course, it's widely available as a standard keyboard > layout). I started noticing the pain in my late twenties (aggravated, > I'm sure, by arthritis), but with switching to Dvorak the pain left and > has only very rarely been noticable again. It will mostly likely be a > challenge to switch, but well worth it. a good suggestion but not really addressing the point I'm trying to make of building a system that would help people more profoundly injured. for example, I've tried Dvorak and the act of typing was so painful that I couldn't learn it From chambon.pascal at gmail.com Mon Jun 29 15:15:52 2009 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Mon, 29 Jun 2009 21:15:52 +0200 Subject: Direct interaction with subprocess - the curse of blocking I/O Message-ID: <4A4912E8.7090506@gmail.com> Hello everyone I've had real issues with subprocesses recently : from a python script, on windows, I wanted to "give control" to a command line utility, i.e forward user in put to it and display its output on console. It seems simple, but I ran into walls : - subprocess.communicate() only deals with a forecast input, not step-by-step user interaction - pexpect module is unix-only, and for automation, not interactive input - when wanting to do all the job manually (transfering data between the standard streams of the python program and the binary subprocess, I met the issue : select() works only on windows, and python's I/O are blocking, so I can't just, for example, get data from the subprocess' stdout and expect the function to return if no input is present - the requesting thread might instead block forever. Browsing the web, I found some hints : - use the advanced win32 api to create non-blocking I/O : rather complicated, non portable and far from the python normal files - use threads that block on the different streams and eat/feed them without ever stopping : rather portable, but gives problems on shutdown (How to terminate these threads without danger ? On some OSes, a process never dies as long as any thread - even "daemonic" - lives, I've seen people complaining about it). So well, I'd like to know, do you people know any solution to this simple problem - making a user interact directly with a subprocess ? Or would this really require a library handling each case separately (win32 api, select().....) ? Thanks a lot for your interest and advice, regards, Pascal From lists at cheimes.de Mon Jun 29 15:17:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 21:17:20 +0200 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: Tim Pinkawa wrote: > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) "if file in os.list()" is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you have to verify that the file has the executable bit, too. Christian From esj at harvee.org Mon Jun 29 15:28:07 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 15:28:07 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: <4A4915C7.5050204@harvee.org> Rhodri James wrote: > On Mon, 29 Jun 2009 06:07:19 +0100, Eric S. Johansson > wrote: > >> Rhodri James wrote: >> >>> Reject away, but I'm afraid you've still got some work to do to >>> convince me that PEP 8 is more work for an SR system than any other >>> convention. >> > > [snip sundry examples] > > Yes, yes, recognition systems need both training and a careful selection > of words to recognise to be effective. This I learned twenty years ago: > if "cap" has a high failure rate, use something else. A more profitable way would be to build a framework doing the right job and not trying to make it happen by side effect and "speaking the keyboard". Speaking the keyboard is whenever you force someone to go through gyrations to adjust spacing, case or special single character assertions (i.e.;). > > As far as I can tell, the only thing that you are even vaguely suggesting > for convention use is underscores_with_everything. As promised, I laugh > hollowly. I'm sorry. It may have been too subtle. I'm suggesting a smart editor that can tell me anything about any name in the body of code I'm working or anything I've included. with that kind of tool, I can have a command grammar that is much friendlier to the voice and gets work done faster than typing.things such as: what is this name? it's a class. What are its methods? tree branch root root template plea se .root(howmany=1, branches=3, nodes={}) and the query can go from there. Using tools like these, one can keep pep-8 conventions and not create a discriminatory environment. From timpinkawa at gmail.com Mon Jun 29 15:31:25 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 14:31:25 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: > "if file in os.list()" is slow and not correct. You have to check if the > file is either a real file or a symlink to a file and not a directory or > special. Then you have to verify that the file has the executable bit, too. I realize four lines of Python does not replicate the functionality of which exactly. It was intended to give the original poster something to start with. I am curious about it being slow, though. Is there a faster way to get the contents of a directory than os.listdir() or is there a faster way to see if an element is in a list other than "x in y"? I believe 'which' will terminate once it finds any match, which mine does not, but that can be fixed by adding a break after the print. From nobody at nowhere.com Mon Jun 29 15:37:29 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 20:37:29 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 13:53:30 -0500, Tim Pinkawa wrote: >> I'm looking for a Python library function that provides the same >> functionality as the `which' command--namely, search the $PATH >> variable for a given string and see if it exists anywhere within. I >> currently examine the output from `which' itself, but I would like >> something more portable. I looked through the `os' and `os.path' >> modules but I didn't find anything. > > This works on POSIX systems. Windows uses semicolons to separate paths > rather than colons so that would need to be taken into account when > running on Windows. This also doesn't recognize shell built-ins, only > real binaries. FWIW, "which" doesn't recognise built-ins either; the "type" built-in does. > import os > > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) There are a couple of problems with this: 1. "which" only considers executable files, and the default behaviour is to only display the first matching file. Also, I'm assuming that the OP wants a function which returns the path rather than printing it. 2. os.listdir() requires read permission (enumerate permission) on each directory. The standard "which" utility stat()s each possible candidate, so it only requires execute permission (lookup permission) on the directories. A secondary issue is performance; enumerating a directory to check for a specific entry can be much slower than stat()ing the specific entry. IOW: def which(file): for path in os.environ["PATH"].split(os.pathsep): if os.access(os.path.join(path, file), os.X_OK): return "%s/%s" % (path, file) But for Windows, you also need to use PATHEXT, e.g.: for dir in os.environ["PATH"].split(os.pathsep): for ext in os.environ["PATHEXT"].split(os.pathsep): full = os.path.join(dir, "%s.%s" % (file, ext)) if os.access(full, os.X_OK): return full Disclaimer: I don't know how accurate os.access(..., os.X_OK) is on Windows; OTOH, it's probably as good as you'll get. From timpinkawa at gmail.com Mon Jun 29 15:38:54 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 14:38:54 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 2:31 PM, Tim Pinkawa wrote: > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. To answer my own question on this specific case, you could check with os.access which may be faster. I am still curious, Christian, if your issue with it being slow was that "os.listdir is slow" or "os.listdir is slow in this case". From robert.kern at gmail.com Mon Jun 29 15:43:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 29 Jun 2009 14:43:04 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On 2009-06-29 14:31, Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. Just check if os.path.exists(os.path.join(path, filename)). -- 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 a0046088 at airmail.net Mon Jun 29 15:51:24 2009 From: a0046088 at airmail.net (wwwayne) Date: Mon, 29 Jun 2009 13:51:24 -0600 Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: <156i45d84n4g0ajhjrk80obhmahp5o9ha3@4ax.com> On Thu, 25 Jun 2009 07:17:42 -0700 (PDT), Saurabh wrote: >On Jun 25, 2:04?am, Wayne Brehaut wrote: >> On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh >> >> wrote: >> >Hi All, >> >> >I am trying to move my application on a MVC architecture and plan to >> >use Jinja for the same. Can anyone provide me with few quick links >> >that might help me to get started with Jinja? >> >> Perhaps the most useful link is: >> >> http://www.google.com/ >> >> from which you can easily find many more with a very basic search, >> including: >> >> http://jinja.pocoo.org/ >> >> Hope that helps? >> wwwayne >> >> >> >> >Thanks, >> >Saby >> >> > >Thanks (Sir!). I was hoping to get some good tutorial on >implementation (which I wasn't able to find with a basic search - >http://dev.pocoo.org/projects/lodgeit/ is what I was referring to >earlier) as this is my first assignment on any template engine (never >used Cheetah, MakO, Tempita). >I would appreciate people responding with something helpful. If you >find a question pretty naive, kindly ignore the question rather than >passing comments on it. Doesn't helps anyone's time. Not phrasing questions in a helpful way initially also doesn't lead to good use of anyone's time, and I suggest another link: http://catb.org/esr/faqs/smart-questions.html Your original question asked for a "few quick links that might help me to get started with Jinja", which made it appear you didn't know where to start and hadn't yet done even a basic search yourself, so I thought I *was* being helpful. Now that you provide the information that would have helped others to respond more usefully previously, perhaps they will. w >Thanks again From lists at cheimes.de Mon Jun 29 15:53:42 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 21:53:42 +0200 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A491BC6.3080901@cheimes.de> Tim Pinkawa wrote: > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. Agreed! > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. You don't need to get the entire directory content to see if a file exists. The stat() syscall is much faster because it requires fewer disk reads. On modern file systems stat() is a O(1) operation while "file" in listdir() is a O(n) operation. By the way you need the result of os.stat anyway to see if the file has the executable bits set. Christian From cgoldberg at gmail.com Mon Jun 29 16:06:35 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Mon, 29 Jun 2009 13:06:35 -0700 (PDT) Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: <1ed266a1-fdb2-4887-bf7d-b1bae316988a@x3g2000yqa.googlegroups.com> > So well, I'd like to know, do you people know any solution to this > simple problem - making a user interact directly with a subprocess? you might want something like Expect. check out the pexpect module: http://pexpect.sourceforge.net/pexpect.html -Corey From ethan at stoneleaf.us Mon Jun 29 16:07:13 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Jun 2009 13:07:13 -0700 Subject: alternative to JoinableQueue's please In-Reply-To: <4A4573BE.9030704@gmail.com> References: <4A4573BE.9030704@gmail.com> Message-ID: <4A491EF1.9030609@stoneleaf.us> > ps: Thanks Raymond for the quick reply... and I feel rather apologetic > for having bothered the list with this :S > No need to feel that way -- many of us still learn from simple looking problems! :) ~Ethan~ From nobody at nowhere.com Mon Jun 29 16:17:39 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:17:39 +0100 Subject: Q: finding distance between 2 time's References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Jun 2009 19:15:08 +0000, John Gordon wrote: >> > if time_difference < 3601: > >> That's a potential off-by-one error. [...] The right test is: > >> if time_difference <= 3600: > > Aren't those two comparisons the same? Not if time_difference is a float. From nobody at nowhere.com Mon Jun 29 16:26:29 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:26:29 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 14:31:25 -0500, Tim Pinkawa wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() No. > or is there a faster way to see if an element is in a list other than > "x in y"? No. However, there is a faster (and more correct) way to test for file existence than enumerating the directory then checking whether the file is in the resulting list, namely to stat() the file. I.e. os.path.exists() or os.access(); the latter will allow you to check for execute permission at the same time. On some systems, the speed difference may be very significant. If readdir() is a system call, os.listdir() will make one system call (two context switches) per directory entry, while os.access() will make one system call in total. [Linux has the (non-standard) getdents() system call, which returns multiple directory entries per call. The readdir() library function uses getdents(), as it is much more efficient than using the readdir() system call.] From Scott.Daniels at Acm.Org Mon Jun 29 16:30:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 13:30:13 -0700 Subject: Q: finding distance between 2 time's In-Reply-To: References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: John Gordon wrote: > In <023130ef$0$19421$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >>> if time_difference < 3601: >> That's a potential off-by-one error. [...] The right test is: >> if time_difference <= 3600: > Aren't those two comparisons the same? Only if time_difference is an integer. --Scott David Daniels Scott.Daniels at Acm.Org From torriem at gmail.com Mon Jun 29 16:33:16 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 29 Jun 2009 14:33:16 -0600 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: <24239603.post@talk.nabble.com> References: <24239603.post@talk.nabble.com> Message-ID: <4A49250C.1090801@gmail.com> iceangel89 wrote: > i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used > .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python > now (for desktop apps since its open source and just want to try what it > offers, but will like to know what good it has for web development also) Give it a try. wxPython or PyQt is preferred for GUI development in general on win32. PyGTK also works on win32 but maybe isn't as nice-looking as the first two options (although the API is much more pythonic by some accounts). The Idle IDE may get you started. When you've profiled your program and found where the common cases are slow, then you can work on optimization substitution pure python routines with native ones written in C, C++, etc From nobody at nowhere.com Mon Jun 29 16:35:36 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:35:36 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 21:53:42 +0200, Christian Heimes wrote: >> I am curious about it being slow, though. Is there a faster way to get >> the contents of a directory than os.listdir() or is there a faster way >> to see if an element is in a list other than "x in y"? I believe >> 'which' will terminate once it finds any match, which mine does not, >> but that can be fixed by adding a break after the print. > > You don't need to get the entire directory content to see if a file > exists. The stat() syscall is much faster because it requires fewer disk > reads. On modern file systems stat() is a O(1) operation while "file" in > listdir() is a O(n) operation. Apart from performance, stat() is more correct. readdir() (and Linux' getdents()) requires read permission on the directory, while stat() (and open() etc) only requires execute permission. On shared web (etc) servers, it's not uncommon for system directories (e.g. /usr/bin) to be "drwxr-x--x", as normal users shouldn't need to enumerate these directories. From nobody at nowhere.com Mon Jun 29 16:45:06 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:45:06 +0100 Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: On Mon, 29 Jun 2009 21:15:52 +0200, Pascal Chambon wrote: > I've had real issues with subprocesses recently : from a python script, > on windows, I wanted to "give control" to a command line utility, i.e > forward user in put to it and display its output on console. Are you talking about a popen(..., 'w') situation? I.e. where Python feeds data to the child's stdin but the child's stdout doesn't go through Python? Or a slave process, where both stdin and stdout/stderr are piped to/from Python? The latter is inherently tricky (which is why C's popen() lets you connect to stdin or stdout but not both). You have to use either multiple threads, select/poll, or non-blocking I/O. If the child's output is to the console, it should presumably be the former, i.e. piping stdin but allowing the child to inherit stdout, in which case, where's the problem? Or are you piping its stdout via Python for the hell of it? From tjreedy at udel.edu Mon Jun 29 16:47:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 16:47:58 -0400 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4A4894F4.7040606@cox.net> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> <4A4894F4.7040606@cox.net> Message-ID: > Martin v. L?wis wrote: >>> I sorta' wish he'd just come out and say, "This is what I think would >>> be suitable for a GUI toolkit for Python: ...". >>> >> >> He is not in the business of designing GUI toolkits, but in the business >> of designing programming languages. So he abstains from specifying >> (or even recommending) a GUI library. >> >> What he makes clear is the point that Terry cites: no matter what the >> GUI toolkit is or what features it has - it should be simple to create >> GUIs, as simple as creating HTML. Having quoted Guido, I will note a few other things: Python already comes with a GUI toolkit, so the question is really "What would Guido want in a replacement for tk/tkinter?" Obviously, it should be even better that the current (and even, prospective) version of TK. 'Better' would need to be demonstrated. Part of that would be a PEP written by or supported by the person in charge of the replacement, with a detailed comparison and argument. Part of that would also be a re-writing of IDLE with the new GUI, with some visible advantage in the gui part of the code. I do not believe either has been done. The replacement should also have majority support. However, there are at least 3 or 4 contenders. My impression is that most of the supporters of each prefer (and rationally so) the status quo to having one of the other contenders being chosen, and thereby shutting out their favorite. The replacement would need to work with Py 3. TK does. I have not noticed that anything else does, though that should change eventually. (And I am sure someone will point of something I have not noticed.) Guido is properly somewhat conservative about 'spending' BDFL points. There is no need to decide anything at present. Terry Jan Reedy From peter.mosley at talk21.com Mon Jun 29 16:57:48 2009 From: peter.mosley at talk21.com (peter) Date: Mon, 29 Jun 2009 13:57:48 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> <26759d8f-be58-4c44-a524-015d64323dce@l31g2000yqb.googlegroups.com> Message-ID: <1e4066cd-cc8b-4124-85ba-a239b88c1c4a@a36g2000yqc.googlegroups.com> Thanks for this - looks promising. But I've just tried pythonware again and it's back up - so it was just a glitch after all. Peter From piet at cs.uu.nl Mon Jun 29 17:12:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 29 Jun 2009 23:12:09 +0200 Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: >>>>> peter (p) wrote: >p> Whilst this is an interesting discussion about installers, I'm still >p> trying to find a copy of PIL. Any ideas? Pythonware is up again: http://pythonware.com/products/pil/index.htm -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From Scott.Daniels at Acm.Org Mon Jun 29 17:16:34 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:16:34 -0700 Subject: Using Python for file packing In-Reply-To: References: Message-ID: Aaron Scott wrote: >> Do you mean like a zip or tar file? >> >> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >> > > I had no idea you could access a single file from a ZIP or TAR without > explicitly extracting it somewhere. Thanks. You will find the zip format works better if you are compressing. The zipfile compression is per file in the archive, rather than applied to the entire archive (as in tarfile). The results of the tar format decision is that extracting the last file in a .tgz (.tar.gz) or .tar.bz2 (sometimes called .tbz) requires the expansion of the entire archive, while extraction on a .zip is reposition, read, and possibly expand. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Mon Jun 29 17:26:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:26:09 -0700 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: Robert Kern wrote: > On 2009-06-29 14:31, Tim Pinkawa wrote: >> On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes >> wrote: >>> "if file in os.list()" is slow and not correct. You have to check if the >>> file is either a real file or a symlink to a file and not a directory or >>> special. Then you have to verify that the file has the executable >>> bit, too. >> >> I realize four lines of Python does not replicate the functionality of >> which exactly. It was intended to give the original poster something >> to start with. >> >> I am curious about it being slow, though. Is there a faster way to get >> the contents of a directory than os.listdir() or is there a faster way >> to see if an element is in a list other than "x in y"? I believe >> 'which' will terminate once it finds any match, which mine does not, >> but that can be fixed by adding a break after the print. > > Just check if os.path.exists(os.path.join(path, filename)). > But on windows, checking for a list of possible extensions, it may well be faster to operate on the listdir output. I made my which-equivalent function a generator, so I could choose to stop at the first entry or continue at the invoker's pleasure (good for both Trojan-discovery and "forgot to delete the .pyc" operations). --Scott David Daniels Scott.Daniels at Acm.Org From rhvonlehe at gmail.com Mon Jun 29 17:41:34 2009 From: rhvonlehe at gmail.com (rhvonlehe at gmail.com) Date: Mon, 29 Jun 2009 14:41:34 -0700 (PDT) Subject: using input(), raw_input() to allow user to run different functions Message-ID: Something's been giving me difficulty.. We have a USB-attached device that we frequently debug with simple python scripts. The model has always been that each script logs on to the device, does something, then logs off. As it turns out, we have mostly written scripts as unit tests for each API command. So, we'll call one script that will configure a process on the device, and a separate script that will retrieve the results of that process. The model is changing inside the device such that all settings will be lost when we log off. This means we'll have to merge a bunch of scripts in various ways. I thought it would be neat if I could have one master python script do the logon, then allow the user to input the name of a previously- written script he wanted to execute while logged on. Finally, when exiting the master script, the user would logout from the device. I'm trying to test this by using input() or raw_input() to get the function the user wants to execute. I'm not having much luck. Here's an example: Shell.py: #! /usr/bin/env python from CollectNDResults import * ... request = input('Script shell >>> ') print request exec (request) ## I realize the parentheses are not needed ... When I run Shell.py I get this: Script shell >>> CollectNDResults Traceback (most recent call last): File "./Shell.py", line 35, in ? Shell(sys.argv[1:]) File "./Shell.py", line 24, in Shell exec (request) TypeError: exec: arg 1 must be a string, file, or code object Is there a good reference for me to figure out how to turn my function name into the code object that I want to execute? Is there a better way to do what I'm trying to do? Thanks, Rich From Scott.Daniels at Acm.Org Mon Jun 29 17:43:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:43:31 -0700 Subject: Direct interaction with subprocess - the curse of blocking I/O In-Reply-To: References: Message-ID: Pascal Chambon wrote: > I've had real issues with subprocesses recently : from a python script, > on windows, I wanted to "give control" to a command line utility, i.e > forward user in put to it and display its output on console.... > Browsing the web, I found some hints : > - use the advanced win32 api to create non-blocking I/O : rather > complicated, non portable ... > > So well, I'd like to know, do you people know any solution to this > simple problem - making a user interact directly with a subprocess ? Or > would this really require a library handling each case separately (win32 > api, select().....) ? I would guess the architectural differences are so great that an attempt to "do something simple" is going to involve architecture-specific code. and I personally wouldn't have it any other way. Simulating a shell with hooks on its I/O should be so complicated that a "script kiddie" has trouble writing a Trojan. --Scott David Daniels Scott.Daniels at Acm.Org From trentm at activestate.com Mon Jun 29 17:45:44 2009 From: trentm at activestate.com (Trent Mick) Date: Mon, 29 Jun 2009 14:45:44 -0700 Subject: python library call equivalent to `which' command In-Reply-To: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A493608.2070907@activestate.com> destroooooy wrote: > Hi, > I'm looking for a Python library function that provides the same > functionality as the `which' command--namely, search the $PATH > variable for a given string and see if it exists anywhere within. I > currently examine the output from `which' itself, but I would like > something more portable. I looked through the `os' and `os.path' > modules but I didn't find anything. http://code.google.com/p/which/ Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From junhufr at gmail.com Mon Jun 29 17:51:50 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 14:51:50 -0700 (PDT) Subject: Drawing in PDF Message-ID: HEllo, I've a pdf file, and i want to draw some additional stuff on it, by example : some markup .... notation. Anyone has idea how to do that ? thank you in advance. From user at example.net Mon Jun 29 17:54:33 2009 From: user at example.net (superpollo) Date: Mon, 29 Jun 2009 23:54:33 +0200 Subject: timer Message-ID: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> hi folks. the follwing shoud print 'stuff' for 3 seconds and then stop. why it does not work? (prints stuff forever) 1 #!/usr/bin/python 2 3 import threading 4 import sys 5 6 t = threading.Timer(3.0, sys.exit) 7 t.start() 8 while True: 9 print "stuff ", bye From backup95 at netcabo.pt Mon Jun 29 17:54:38 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 22:54:38 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A485777.2000301@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <4A49381E.9060303@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Interesting, thanks. The concept is not difficult to understand but >>> I'm not sure it would be preferable. A copy operation should have the >>> same cost as a "snapshot", >> >> You mean a deep-copy? That is unnecessarily expensive; with a >> functional structure you can snapshot (or copy) by copying a single >> pointer. >> >> > > Shallow copy... > >>> undo is kind of redundant and multithreading... don't see a >>> compelling use that would justify it. >> >> Here is one: >> http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b >> >> > > I just skimmed that but if someone really needs multithreading for > such intensive processing without wanting a database, fair enough I > guess. > >>> Have you considered how the syntax would work in Python by the way? >>> This: >>> new_tree = old_tree.insert(object) >>> Just looks wrong. >> >> It looks fine to me. Obviously you could support a wrapper with >> a mutating slot that holds a pointer to the tree. >> > I didn't get the last part, sorry. But I think you'd have a lot of > users annoyed that the interface is similar to a list yet their > objects mysteriously disappear. To me, tree.insert() implies > mutability but I defer that to others like yourself with more > experience in Python than me. > Rereading this I got what you meant by "wrapper with mutating slot". But that is (like I think you implied) functionally equivalent to a mutating data structure, with worse performance because of additional memory allocation and such. Is it faster to rebalance the tree with a persistent data structure? From gagsl-py2 at yahoo.com.ar Mon Jun 29 17:58:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 18:58:45 -0300 Subject: Ctypes, pthreads and pthread_mutex_t References: <3ab1306f-3f37-403f-9768-81b657c87409@j14g2000vbp.googlegroups.com> Message-ID: En Mon, 29 Jun 2009 13:19:31 -0300, Doug escribi?: > Has any converted the structure pthread_mutex_t to > a ctypes structure class ? > I looking at some C code that is using pthreads and need to translate > pthreads_mutex_t structure into python (via ctypes) I think the pthread_mutex_t type is intended to be "opaque" to application code. You should not mess with its contents; the only thing one must know is its size (and only if one wants to allocate it from Python). For the most part, it's like a void* pointer. -- Gabriel Genellina From clp2 at rebertia.com Mon Jun 29 17:59:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 14:59:42 -0700 Subject: using input(), raw_input() to allow user to run different functions In-Reply-To: References: Message-ID: <50697b2c0906291459m483ee444ybd7142404992fe75@mail.gmail.com> On Mon, Jun 29, 2009 at 2:41 PM, rhvonlehe at gmail.com wrote: > Something's been giving me difficulty.. > > We have a USB-attached device that we frequently debug with simple > python scripts. ?The model has always been that each script logs on to > the device, does something, then logs off. ?As it turns out, we have > mostly written scripts as unit tests for each API command. ?So, we'll > call one script that will configure a process on the device, and a > separate script that will retrieve the results of that process. > > The model is changing inside the device such that all settings will be > lost when we log off. ?This means we'll have to merge a bunch of > scripts in various ways. > > I thought it would be neat if I could have one master python script do > the logon, then allow the user to input the name of a previously- > written script he wanted to execute while logged on. ?Finally, when > exiting the master script, the user would logout from the device. > > I'm trying to test this by using input() or raw_input() to get the > function the user wants to execute. ?I'm not having much luck. ?Here's > an example: > > > > Shell.py: > #! /usr/bin/env python > from CollectNDResults import * > ... > request = input('Script shell >>> ') > print request > exec (request) ? ## I realize the parentheses are not needed > ... > > > When I run Shell.py I get this: > > Script shell >>> CollectNDResults > > Traceback (most recent call last): > ?File "./Shell.py", line 35, in ? > ? ?Shell(sys.argv[1:]) > ?File "./Shell.py", line 24, in Shell > ? ?exec (request) > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > name into the code object that I want to execute? input() already does that. Note how you're getting back a *function object*. Just call the function (i.e. request() ). The exec statement takes a *string* of code to execute, not a function object, hence the error you're getting. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Mon Jun 29 18:08:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:08:15 +0100 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A493B4F.2070102@mrabarnett.plus.com> Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. Have a look at os.path.isfile(), os.path.isdir() and os.path.islink(). From clp2 at rebertia.com Mon Jun 29 18:08:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 15:08:35 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <50697b2c0906291508w36f25ed0t8a2a38e8d5c8d74@mail.gmail.com> On Mon, Jun 29, 2009 at 2:51 PM, Jun wrote: > HEllo, > > I've a pdf file, and i want to draw some additional stuff on it, by > example : some markup .... notation. Anyone has idea how to do that ? > thank you in advance. ReportLab (http://www.reportlab.org/) can do PDF generation, although it sounds like the for-pay, proprietary "PageCatcher" add-on library might be needed to read from existing PDFs. Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Mon Jun 29 18:09:23 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 29 Jun 2009 15:09:23 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: On 6/29/2009 2:51 PM Jun said... > HEllo, > > I've a pdf file, and i want to draw some additional stuff on it, by > example : some markup .... notation. Anyone has idea how to do that ? > thank you in advance. ISTM that reportlab's commercial offering does that. http://www.reportlab.com/sectors/developers/ Emile From junhufr at gmail.com Mon Jun 29 18:14:10 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 15:14:10 -0700 (PDT) Subject: Drawing in PDF References: Message-ID: On Jun 30, 12:09?am, Emile van Sebille wrote: > On 6/29/2009 2:51 PM Jun said... > > > HEllo, > > > I've a pdf file, and i want to draw some additional stuff on it, by > > example : some markup .... notation. Anyone has idea how to do that ? > > thank you in advance. > > ISTM that reportlab's commercial offering does that. > > http://www.reportlab.com/sectors/developers/ > > Emile Thanks a lot, is there open source solution ? From python at mrabarnett.plus.com Mon Jun 29 18:18:30 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:18:30 +0100 Subject: Using Python for file packing In-Reply-To: References: Message-ID: <4A493DB6.6050005@mrabarnett.plus.com> Scott David Daniels wrote: > Aaron Scott wrote: >>> Do you mean like a zip or tar file? >>> >>> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >>> >>> >> >> I had no idea you could access a single file from a ZIP or TAR without >> explicitly extracting it somewhere. Thanks. > You will find the zip format works better if you are compressing. The > zipfile compression is per file in the archive, rather than applied to > the entire archive (as in tarfile). The results of the tar format > decision is that extracting the last file in a .tgz (.tar.gz) or > .tar.bz2 (sometimes called .tbz) requires the expansion of the entire > archive, while extraction on a .zip is reposition, read, and possibly > expand. > If the audio is already compressed then a zipfile probably won't be able to compress it any more. From python at mrabarnett.plus.com Mon Jun 29 18:22:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:22:23 +0100 Subject: using input(), raw_input() to allow user to run different functions In-Reply-To: References: Message-ID: <4A493E9F.2080606@mrabarnett.plus.com> rhvonlehe at gmail.com wrote: > Something's been giving me difficulty.. > > We have a USB-attached device that we frequently debug with simple > python scripts. The model has always been that each script logs on to > the device, does something, then logs off. As it turns out, we have > mostly written scripts as unit tests for each API command. So, we'll > call one script that will configure a process on the device, and a > separate script that will retrieve the results of that process. > > The model is changing inside the device such that all settings will be > lost when we log off. This means we'll have to merge a bunch of > scripts in various ways. > > I thought it would be neat if I could have one master python script do > the logon, then allow the user to input the name of a previously- > written script he wanted to execute while logged on. Finally, when > exiting the master script, the user would logout from the device. > > I'm trying to test this by using input() or raw_input() to get the > function the user wants to execute. I'm not having much luck. Here's > an example: > > > > Shell.py: > #! /usr/bin/env python > from CollectNDResults import * > ... > request = input('Script shell >>> ') > print request > exec (request) ## I realize the parentheses are not needed > ... > > > When I run Shell.py I get this: > > Script shell >>> CollectNDResults > > Traceback (most recent call last): > File "./Shell.py", line 35, in ? > Shell(sys.argv[1:]) > File "./Shell.py", line 24, in Shell > exec (request) > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > name into the code object that I want to execute? Is there a better > way to do what I'm trying to do? > >>> def foo(): print "running foo" >>> import sys >>> func_name = "foo" >>> getattr(sys.modules[__name__], func_name)() running foo From emile at fenx.com Mon Jun 29 18:22:48 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 29 Jun 2009 15:22:48 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: On 6/29/2009 3:14 PM Jun said... > On Jun 30, 12:09 am, Emile van Sebille wrote: >> On 6/29/2009 2:51 PM Jun said... >> >>> HEllo, >>> I've a pdf file, and i want to draw some additional stuff on it, by >>> example : some markup .... notation. Anyone has idea how to do that ? >>> thank you in advance. >> ISTM that reportlab's commercial offering does that. >> >> http://www.reportlab.com/sectors/developers/ >> >> Emile > > Thanks a lot, is there open source solution ? Not that I'm aware of. If you have the appropriate source data you could create the complete document using the open source ReportLab. There are also tools available for combining PDFs. But if you want to insert into the middle of an existing PDF let us know if you find an open source answer. Emile From python at mrabarnett.plus.com Mon Jun 29 18:32:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:32:26 +0100 Subject: timer In-Reply-To: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> Message-ID: <4A4940FA.9010206@mrabarnett.plus.com> superpollo wrote: > hi folks. > > the follwing shoud print 'stuff' for 3 seconds and then stop. why it > does not work? (prints stuff forever) > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 import sys > 5 > 6 t = threading.Timer(3.0, sys.exit) > 7 t.start() > 8 while True: > 9 print "stuff ", > The Timer runs the function in another thread. Perhaps sys.exit is just exiting that thread and not the main thread. From p.f.moore at gmail.com Mon Jun 29 18:38:01 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 29 Jun 2009 23:38:01 +0100 Subject: timer In-Reply-To: <4A4940FA.9010206@mrabarnett.plus.com> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <79990c6b0906291538j56d417eaxcc62bcc504dd28f4@mail.gmail.com> 2009/6/29 MRAB : > superpollo wrote: >> >> hi folks. >> >> the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >> not work? (prints stuff forever) >> >> ? ? ?1 #!/usr/bin/python >> ? ? ?2 >> ? ? ?3 import threading >> ? ? ?4 import sys >> ? ? ?5 >> ? ? ?6 t = threading.Timer(3.0, sys.exit) >> ? ? ?7 t.start() >> ? ? ?8 while True: >> ? ? ?9 ? ? print "stuff ", >> > The Timer runs the function in another thread. Perhaps sys.exit is just > exiting that thread and not the main thread. sys.exit raises a SystemExit exception, which will get handled in the new thread (where it won't do anything). Conceded, this isn't particularly intuitive. For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. Paul. From junhufr at gmail.com Mon Jun 29 18:57:54 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 15:57:54 -0700 (PDT) Subject: Drawing in PDF References: Message-ID: <7b874bde-c7b6-4569-9646-a2dfe355e78f@b14g2000yqd.googlegroups.com> On Jun 30, 12:22?am, Emile van Sebille wrote: > On 6/29/2009 3:14 PM Jun said... > > > On Jun 30, 12:09 am, Emile van Sebille wrote: > >> On 6/29/2009 2:51 PM Jun said... > > >>> HEllo, > >>> I've a pdf file, and i want to draw some additional stuff on it, by > >>> example : some markup .... notation. Anyone has idea how to do that ? > >>> thank you in advance. > >> ISTM that reportlab's commercial offering does that. > > >>http://www.reportlab.com/sectors/developers/ > > >> Emile > > > Thanks a lot, is there open source solution ? > > Not that I'm aware of. ?If you have the appropriate source data you > could create the complete document using the open source ReportLab. > There are also tools available for combining PDFs. ?But if you want to > insert into the middle of an existing PDF let us know if you find an > open source answer. > > Emile I checked out whyteboard project (http://code.google.com/p/ whyteboard/) which intends to use cairo (Drawing) and Python Poppler (load PDF). From magicus23 at gmail.com Mon Jun 29 19:12:35 2009 From: magicus23 at gmail.com (magicus) Date: Mon, 29 Jun 2009 19:12:35 -0400 Subject: Python Imaging Library download link broken? In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On Mon Jun 29 2009 07:21:12 GMT-0400 (EDT) Lawrence D'Oliveiro typed: > In message , Tim Harig wrote: > >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >> >>> "apt-get install python-imaging", anybody? >> C:\>apt-get install python-imaging >> Bad command or file name > > Sounds more like broken OS with no integrated package management. > :-P It works here in the sense that it reports that there is nothing to do as it is already installed. ciao, f -- "Hell, if you understood everything I say, you'd be me." -- Miles Davis From rhodri at wildebst.demon.co.uk Mon Jun 29 19:18:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 00:18:17 +0100 Subject: pep 8 constants In-Reply-To: <4A4915C7.5050204@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> Message-ID: On Mon, 29 Jun 2009 20:28:07 +0100, Eric S. Johansson wrote: > Rhodri James wrote: >> As far as I can tell, the only thing that you are even vaguely >> suggesting >> for convention use is underscores_with_everything. As promised, I laugh >> hollowly. > > I'm sorry. It may have been too subtle. I'm suggesting a smart editor > that can > tell me anything about any name in the body of code I'm working or > anything I've > included. with that kind of tool, I can have a command grammar that is > much > friendlier to the voice and gets work done faster than typing.things > such as: > > what is this name? > it's a class. > What are its methods? > tree > branch > root > > root template plea > se > .root(howmany=1, branches=3, nodes={}) > > and the query can go from there. > > Using tools like these, one can keep pep-8 conventions and not create a > discriminatory environment. Could you elucidate a bit? I'm not seeing how you're intending to keep PEP-8 conventions in this, and I'm not entirely convinced that without them the smart editor approach doesn't in fact reduce your productivity. -- Rhodri James *-* Wildebeest Herder to the Masses From backup95 at netcabo.pt Mon Jun 29 19:27:33 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Tue, 30 Jun 2009 00:27:33 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A494DE5.9070805@netcabo.pt> alex23 wrote: > Jo?o Valverde wrote: > >> Currently I don't have a strong need for this. >> > > And clearly neither has anyone else, hence the absence from the > stdlib. As others have pointed out, there are alternative approaches, > and plenty of recipes on ActiveState, which seem to have scratched > whatever itch there is for the data structure you're advocating. > > I can't resist quoting Sedgewick here. Then I'll shut up about it. [quote=http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf] Abstract The red-black tree model for implementing balanced search trees, introduced by Guibas and Sedge- wick thirty years ago, is now found throughout our computational infrastructure. Red-black trees are described in standard textbooks and are the underlying data structure for symbol-table imple- mentations within C++, Java, Python, BSD Unix, and many other modern systems. [/quote] You'd think so, but no. You should correct him that in Python a balanced search tree is the useless cross between a dict and a database. From superprad at gmail.com Mon Jun 29 19:47:27 2009 From: superprad at gmail.com (PK) Date: Mon, 29 Jun 2009 19:47:27 -0400 Subject: identify checksum type? Message-ID: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Given a checksum value, whats the best way to find out what type it is? meaning. I can use hashlib module and compute a md5 or sha1 for a given data etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats the best way for me to identify if its a sha1 or md5 or anyother sum type for that matter? is there a nice way to do this in python? ~ PK -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Jun 29 19:54:16 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 30 Jun 2009 01:54:16 +0200 Subject: identify checksum type? In-Reply-To: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Message-ID: PK schrieb: > Given a checksum value, whats the best way to find out what type it is? > > meaning. I can use hashlib module and compute a md5 or sha1 for a given data > etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats > the best way for me to identify if its a sha1 or md5 or anyother sum type > for that matter? > > is there a nice way to do this in python? As far as I know there is no way to identify a checksum by its value. A checksum is just a number. You can try an educated guess based on the length of the checksum. Or you can try all hash algorithms until you get a hit but that may lead to security issues. Some applications prefix the hash value with an identifier like "{MD5}" or "{SHA1}". Christian From steve at REMOVE-THIS-cybersource.com.au Mon Jun 29 20:11:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 00:11:02 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <025949cb$0$20671$c3e8da3@news.astraweb.com> On Mon, 29 Jun 2009 11:49:04 -0400, Eric S. Johansson wrote: > alex23 wrote: >> "Eric S. Johansson" wrote: >>> no, I know the value if convention when editors can't tell you >>> anything about the name in question. I would like to see more support >>> for disabled programmers like myself and the thousands of programmers >>> injured every year and forced to leave the field. seriously, there is >>> no money in disability access especially for programmers. >> >> Well, if we can't use conventions like uppercasing, camelcasing and >> underscoring, what are you recommending we do instead? > > help build a smart editing environment please. Why do you think a smart editing environment is in opposition to coding conventions? Surely an editor smart enough to know a variable name spoken as "pear tree" is an instance and therefore spelled as pear_tree (to use your own example) would be smart enough to know a variable name spoken as "red" is a constant and therefore spelled "RED"? Sounds to me that your speech environment needs a command to turn capslock on and off, and your problem with PEP 8 is solved: x equals caps on red caps off plus three > Heck, have you ever noticed how most Python smart editors can't even > indent properly according to local contexts. Emacs is the only one and > even that one sometimes fails I use kwrite for editing, and I can't say I've ever noticed a failure. > I've lived this works and probably have put more deep thought and 8kloc > into it because I do not accept circures tricks as a way of life. I > want it to work right and I know how to do it. I just don't have the > hands and hte money to pay me to do it. You're using a speech interface, right? You've written about "putting a gun to your wrists", said you can't follow PEP 8 because it's not voice safe, and generally given the impression that you can't use a keyboard. So... just how do you get "hte" from saying "the"? If you are using a keyboard to type this post, then surely it's not such a huge imposition to type a couple of words in all caps here and there while you speak the rest of the code? x equals R E D plus three I know that doesn't resolve the issue for those people who truly can't use a keyboard at all, even for a single character, but it's unfair to insist that the only permitted coding conventions are the ones suitable for the tiny minority who, frankly, are going to have problems no matter what coding conventions we have. Especially when these coding conventions are entirely optional. -- Steven From davidh at ilm.com Mon Jun 29 21:01:29 2009 From: davidh at ilm.com (David Hirschfield) Date: Mon, 29 Jun 2009 18:01:29 -0700 Subject: Determining if a function is a method of a class within a decorator Message-ID: <4A4963E9.30202@ilm.com> I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able to do some things a little differently depending on whether I'm swapping two functions, or two methods of a class. Trouble is, it appears that when the decorator is called the function is not yet bound to an instance, so no matter whether it's a method or function, it looks the same to the decorator. This simple example illustrates the problem: import inspect class swapWith(object): def __init__(self, replacement): self.replacement = replacement def __call__(self, thingToReplace): def _replacer(*args, **kws): import inspect print "replacing:",self.replacement,inspect.ismethod(self.replacement) return self.replacement(*args, **kws) return _replacer class MyClass(object): def swapIn(self): print "this method will be swapped in" @swapWith(swapIn) def swapOut(self): print "this method will be swapped out" c = MyClass() c.swapOut() def swapInFn(): print "this function will be swapped in" @swapWith(swapInFn) def swapOutFn(): print "this function will be swapped out" swapOutFn() Both MyClass.swapIn and swapInFn look like the same thing to the decorator, and MyClass.swapOut and swapOutFn look the same. So is there a pattern I can follow that will allow me to determine whether the objects I'm given are plain functions or belong to a class? Thanks in advance, -David -- Presenting: mediocre nebula. From tjreedy at udel.edu Mon Jun 29 21:31:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 21:31:45 -0400 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: <4A4963E9.30202@ilm.com> References: <4A4963E9.30202@ilm.com> Message-ID: David Hirschfield wrote: > I'm having a little problem with some python metaprogramming. I want to > have a decorator which I can use either with functions or methods of > classes, which will allow me to swap one function or method for another. > It works as I want it to, except that I want to be able to do some > things a little differently depending on whether I'm swapping two > functions, or two methods of a class. Unbounds methods are simply functions which have become attributes of a class. Especially in Py3, there is *no* difference. Bound methods are a special type of partial function. In Python, both are something else, though still callables. Conceptually, a partial function *is* a function, just with fewer parameters. > Trouble is, it appears that when the decorator is called the function is > not yet bound to an instance, so no matter whether it's a method or > function, it looks the same to the decorator. Right. Whether it is an A or an A, it looks like an A. Worse: when the decorator is called, there is no class for there to be instances of. > > This simple example illustrates the problem: Add a second parameter to tell the decorator which variant of behavior you want. Or write two variations of the decorator and use the one you want. tjr From esj at harvee.org Mon Jun 29 21:52:37 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 21:52:37 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> Message-ID: <4A496FE5.9060005@harvee.org> Rhodri James wrote: > > Could you elucidate a bit? I'm not seeing how you're intending to keep > PEP-8 conventions in this, and I'm not entirely convinced that without > them the smart editor approach doesn't in fact reduce your productivity. > thank you for asking for an elaboration. Programming by voice has one goal. enable a disabled person such as myself to create code by voice with a minimum of vocal or hand damage. let's use an example. Admittedly, this is a very simple example but hopefully it illustrates my point What I dictate is: from pots is class telephone What should generate is: class Telephone (pots): as you can see, taken from the simplistic expression, we generate the right pep-8 convention. (I think). This is not the only grammar one can use but, it's one that comes to mind that doesn't have a lot of dead ends. So if I was dictating code, it would look something like: >From pots is new class telephone new constructor first argument last mile = between quotes copper Second argument fiber delivery date = between quotes when hell freezes over" jump to body first argument to self second argument to self new method construction crew . . . Telephone fieldwork = telephone second argument fiber delivery date = between quotes hell froze over recycled coffee = telephone fieldwork construction crew ----------------- This is the rough example of what I think should be spoken and what can be translated to code. What isn't shown is disambiguation techniques. For example, when a name is said, if it is not unique to the context, then a small pop-up shows the ambiguities and lets the user choose. Yes your focus shifts rapidly but you're in the groove of writing code and it's just making your choices explicit. For example, if telephone wasn't unique because we had telephone pole and telephone truck as classes elsewhere in the namespace, you would see a pop-up with each name with a number next to it. You could either click on the item or say a digit to reinforce the choice. If the class had more methods, when I say "telephone fieldwork" that gets translated into knowledge of what class it's an instance of and all the choices are displayed but at the same time, the natural language form are shoved into the grammar so you can continue speaking. If you speak quickly enough, you will see no choice but the grammar will still be loaded up so that you will get the right thing. at each stage of the way, names get transformed into the pep-8 form without me having to say anything special. The environment knows what form it wants and does the transformation automatically. I'm surprised people aren't doing this already for their handcrafted code. It's one less bit of detail you need to pay attention to. From davidh at ilm.com Mon Jun 29 22:01:01 2009 From: davidh at ilm.com (David Hirschfield) Date: Mon, 29 Jun 2009 19:01:01 -0700 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: References: <4A4963E9.30202@ilm.com> Message-ID: <4A4971DD.9080707@ilm.com> Yeah, it definitely seems like having two separate decorators is the solution. But the strange thing is that I found this snippet after some deep googling, that seems to do something *like* what I want, though I don't understand the descriptor stuff nearly well enough to get what's happening: http://stackoverflow.com/questions/306130/python-decorator-makes-function-forget-that-it-belongs-to-a-class answer number 3, by ianb. It seems to indicate there's a way to introspect and determine the class that the function is going to be bound to...but I don't get it, and I'm not sure it's applicable to my case. I'd love an explanation of what is going on in that setup, and if it isn't usable for my situation, why not? Thanks again, -David Terry Reedy wrote: > David Hirschfield wrote: >> I'm having a little problem with some python metaprogramming. I want >> to have a decorator which I can use either with functions or methods >> of classes, which will allow me to swap one function or method for >> another. It works as I want it to, except that I want to be able to >> do some things a little differently depending on whether I'm swapping >> two functions, or two methods of a class. > > Unbounds methods are simply functions which have become attributes of > a class. Especially in Py3, there is *no* difference. > > Bound methods are a special type of partial function. In Python, both > are something else, though still callables. Conceptually, a partial > function *is* a function, just with fewer parameters. > >> Trouble is, it appears that when the decorator is called the function >> is not yet bound to an instance, so no matter whether it's a method >> or function, it looks the same to the decorator. > > Right. Whether it is an A or an A, it looks like an A. > > Worse: when the decorator is called, there is no class for there to be > instances of. >> >> This simple example illustrates the problem: > > Add a second parameter to tell the decorator which variant of behavior > you want. Or write two variations of the decorator and use the one you > want. > > tjr > -- Presenting: mediocre nebula. From ldo at geek-central.gen.new_zealand Mon Jun 29 22:05:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 14:05:26 +1200 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: In message , Gabriel Genellina wrote: > The fact that it's the same character used for formatting strings with the > % operator is an unfortunate coincidence (or a very bad choice, I don't > know). That's not the problem. The problem is that MySQLdb IS indeed using Python format substitution to do its argument substitution. Python expects the value for "%d" to be an integer. But MySQLdb has already converted all the argument values to strings. Hence the error. If MySQLdb were doing its own parsing of the format string, it could produce a more meaningful error message when it sees "%d" (e.g. "only %s substitutions allowed"). From alitosis at gmail.com Mon Jun 29 22:12:12 2009 From: alitosis at gmail.com (alito) Date: Mon, 29 Jun 2009 19:12:12 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: On Jun 18, 11:56?pm, nn wrote: > On Jun 18, 8:38?am, guthrie wrote: > > > > > On Jun 17, 6:38?pm, Steven Samuel Cole > > wrote: > > > > Still don't really understand why my initial code didn't work, though... > > > Your code certainly looks reasonable, and looks to me like it "should" > > work. The comment of partial namespace is interesting, but > > unconvincing (to me) - but I am not a Python expert! It would > > certainly seem that within that code block it is in the local > > namespace, not removed from that scope to be in another. > > > Seems that it should either be a bug, or else is a design error in the > > language! > > > Just as in the above noted "WTF" - non-intuitive language constructs > > that surprise users are poor design. > > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > > >>> class x: > > ... ? ? lst=[2] > ... ? ? gen=[lst.index(e) for e in lst] > ... > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 3, in x > ? File "", line 3, in > NameError: global name 'lst' is not defined > Arghh. I see thousands of future wtf!? posts to c.l.p. triggered by this new feature. Might as well save some time and add it to the FAQ already. From lehchao at gmail.com Mon Jun 29 22:13:06 2009 From: lehchao at gmail.com (kio) Date: Mon, 29 Jun 2009 19:13:06 -0700 (PDT) Subject: why PyObject_VAR_HEAD? Message-ID: Hi, I'm studying the CPython source code. I don?t quite understand why they?re using PyObject_VAR_HEAD to define struct like PyListObject. To define such kind of struct, could I use _PyObject_HEAD_EXTRA as a header and add "items" pointer and "allocated" count explicity? Is there any difference? Thanks. Eric From bob at vitamindinc.com Mon Jun 29 22:21:07 2009 From: bob at vitamindinc.com (Bob Petersen) Date: Mon, 29 Jun 2009 19:21:07 -0700 Subject: Creating multiprocessing processes without forking on MacOSX? Message-ID: <9d4bd1f40906291921k57d11164t7bb1045080b86678@mail.gmail.com> All, I am using the multiprocessing backport with Python 2.5.4 on a cross-platform Mac/Windows app. Things were going swimmingly until I tried to load a library on the Mac that calls CoreFoundation system calls. I discovered that certain (many?) OSX system calls fail when called from a forked process. See http://developer.apple.com/technotes/tn2005/tn2083.html#SECDAEMONVSFRAMEWORKSand http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html(search for "fork"). Unfortunately, we are already using multprocessing (and its Queues and Pipes) and have a lot of time invested in it. The three options I see are (1) replace multiprocessing with subrocess calls, (2) wrap the library that makes the MacOSX calls in a separate "server" process, or (3) modify the multiprocessing module to, on the Mac, be able to create "non-forked" processes (using subprocess, or fork() then exec*(), or similar). My question is, how realistic is #3? On the Windows side multiprocessing is not using fork(), so it seems like the library may already support this. If this is not completely crazy, I'd be interested in suggestions on what would have to change. I'm happy to provide a patch if it is useful to others. Thanks, Bob Petersen -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Jun 29 22:25:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 02:25:24 GMT Subject: Determining if a function is a method of a class within a decorator References: Message-ID: On Mon, 29 Jun 2009 18:01:29 -0700, David Hirschfield wrote: > I'm having a little problem with some python metaprogramming. I want to > have a decorator which I can use either with functions or methods of > classes, which will allow me to swap one function or method for another. > It works as I want it to, except that I want to be able to do some > things a little differently depending on whether I'm swapping two > functions, or two methods of a class. > > Trouble is, it appears that when the decorator is called the function is > not yet bound to an instance, so no matter whether it's a method or > function, it looks the same to the decorator. Then: * use a naming convention to recognise methods (e.g. check if the first argument is called "self" by looking at function.func_code.co_varnames); * use two different decorators, or a decorator that takes an extra "method or function argument"; * play around with the class metaclass and see if you can do something special (and probably fragile); * do the replacements after the class is created without decorator syntax, e.g.: Class.method1 = swapWith(Class.method2)(Class.method1) > This simple example illustrates the problem: [snip] No it doesn't. It appears to work perfectly, from what I can guess you're trying to accomplish. Have you considered a possibly simpler way of swapping methods/functions? >>> def parrot(): ... print "It's pining for the fjords." ... >>> def cheeseshop(): ... print "We don't stock Cheddar." ... >>> parrot, cheeseshop = cheeseshop, parrot >>> >>> parrot() We don't stock Cheddar. >>> cheeseshop() It's pining for the fjords. Admittedly, this doesn't let you do extra processing before calling the swapped functions, but perhaps it will do for what you need. -- Steven From benjamin at python.org Mon Jun 29 22:30:18 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 30 Jun 2009 02:30:18 +0000 (UTC) Subject: why =?utf-8?b?UHlPYmplY3RfVkFSX0hFQUQ/?= References: Message-ID: kio gmail.com> writes: > > Hi, > > I'm studying the CPython source code. I don?t quite understand why > they?re using PyObject_VAR_HEAD to define struct like PyListObject. To > define such kind of struct, could I use _PyObject_HEAD_EXTRA as a > header and add "items" pointer and "allocated" count explicity? Is > there any difference? No, PyObject_VAR_HEAD adds a ob_size field, which is used to indicate the size of the list. PyList uses this just as a convenience; it does not actually use varsize mallocing. You could use PyObject_HEAD if you added an additional size field. From esj at harvee.org Mon Jun 29 22:37:15 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 22:37:15 -0400 Subject: pep 8 constants In-Reply-To: <025949cb$0$20671$c3e8da3@news.astraweb.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> Message-ID: <4A497A5B.4040503@harvee.org> Steven D'Aprano wrote: > Why do you think a smart editing environment is in opposition to coding > conventions? Surely an editor smart enough to know a variable name spoken > as "pear tree" is an instance and therefore spelled as pear_tree (to use > your own example) would be smart enough to know a variable name spoken as > "red" is a constant and therefore spelled "RED"? no. I think a smart editing environment should support a coding convention. If an editor is smart enough to track type and instance information, yes. It should be able to generate the right strings for symbols. The question is, how do we get such a smart editor. as far as I know, none exist and the smart ones so far seem to be oriented towards hand use and are almost inaccessible to speech. > > Sounds to me that your speech environment needs a command to turn > capslock on and off, and your problem with PEP 8 is solved: you haven't used recognition, have you? > > x equals caps on red caps off plus three it also means "red" is a single utterance. "RED" is three utterances. You've just tripled vocal load for single word which means vat you just cut my ability to work by two thirds. My voice is not as robust as my hands used to be. It's a coarse tools not designed for engraving fine detail but instead painting broadbrush strokes. for more you expect a person to say, the less time they can spend on work effort. This is why I'm advocating a very smart at her with very high level grammar structure using visual disambiguation techniques. >> Heck, have you ever noticed how most Python smart editors can't even >> indent properly according to local contexts. Emacs is the only one and >> even that one sometimes fails > > I use kwrite for editing, and I can't say I've ever noticed a failure. okay, it fails from a speech recognition user perspective. Put the cursor on the line and hit the tab key. Insert spaces/tabs in the line of text. Not good for speech recognition. If mess of indentation and hit the tab key, it doesn't automatically indent to the right location. I'll be damned if I'm in the sit there speaking "tabkeytabkeytabkeytabkeytabkey" because the error should take care of it for me and save my voice. Like I said, Emacs does it correctly and nobody else does as far as I can tell. >> I've lived this works and probably have put more deep thought and 8kloc >> into it because I do not accept circures tricks as a way of life. I >> want it to work right and I know how to do it. I just don't have the >> hands and hte money to pay me to do it. > > You're using a speech interface, right? You've written about "putting a > gun to your wrists", said you can't follow PEP 8 because it's not voice > safe, and generally given the impression that you can't use a keyboard. > > So... just how do you get "hte" from saying "the"? joys of speech recognition. it was probably either due to a persistent misrecognition that didn't have the right word and the correction dialog or, I found the speech recognition error and could not corrected by voice. and note, there are two errors above that lie would have had to correct by hand. > If you are using a keyboard to type this post, then surely it's not such > a huge imposition to type a couple of words in all caps here and there > while you speak the rest of the code? if I had typed this post, there would be two orders of magnitude more errors because of intentional tremors and reduction of targeting accuracy. to give you Monday an example. Sometimes my hands shake so badly, I cannot eat soup or even Chile. I'm unable to use an iPhone except with a great deal of effort. am the iPhone with a user with tremors, you activate more than one key about a third of the time. > x equals R E D plus > three I only have about 1000 keystrokes equivalents today in my hands. Where am I going to use them? Try adding (driving), preparing food, personal hygiene, or typing PEP-8 compliant code? What I usually do is I do something like constant_read = RED at the beginning of my code and well I think you know I'm getting at. I generate something only I can read which does nobody any good. > I know that doesn't resolve the issue for those people who truly can't > use a keyboard at all, even for a single character, but it's unfair to > insist that the only permitted coding conventions are the ones suitable > for the tiny minority who, frankly, are going to have problems no matter > what coding conventions we have. You're looking at it from the classical anti-accommodation perspective. Don't change the convention, give us the tools so we can comply with what the rest of you do. It's like instead of putting a cut out every street corner, every powered scooter/wheelchair comes with a antigravity boost that will lift them over the curbstone. Accessibility belongs with the individual through tools that take the standard and change it to their needs. While we don't have anti-gravitational devices, we can make smart matters and that would solve a lot more problems than just the simple compliance with PEP-8 > > Especially when these coding conventions are entirely optional. these conventions are religion for some special if you want to contribute code. But look at the bigger issue. If your brother, or best friend was disabled and couldn't make a living programming anymore, which you or which are not feel enough compassion/responsibility to try and help them get back on their feet? Assuming your answer was a compassionate one, try and extend that out word to tens of thousands of developers losing their livelihood every year. Do you feel enough compassion and can you get together enough people feel similar levels of compassion to try and build a smart editing environment (all dicksizing about gui kits aside) and make it possible for these people to continue in their desired profession? I know I hit on this point a lot but not are you helping your peers, some people you may even know but you are saving yourself from being forced away from programming at some point in the future whether it be from RSI, arthritis, broken wrist, drop the fee or whatever. As we age, we all lose ability. I wish I had known enough about the future to try and secure a future for myself but I didn't. And so now I play an absolute pain in the ass on the net trying to get people to think about themselves and their fellow programmers. I know I'm obnoxious, I'm sorry but I want something to work for more than just me. I want something that can be reproduce by individuals, rehabilitation facilities, handicap advocacy groups. I don't want anyone to go through what I did trying to rebuild my worklife. It was hell and if I can save somebody from it by being an advocate, I'm going to keep doing it So yeah, it would be swell to have a smart editor. I do believe that with the right groundwork, a smart editor could not only serve the needs of people with speech recognition but also present enough information so that text-to-speech users can hear what they're working with. He may not be able to imagine this but, you don't want to read the display, you want to read the meta-information behind the symbols on the display and that's what a blind programmer would need to hear in order to understand the code. Or at least that's what a few have told me. From http Mon Jun 29 22:40:56 2009 From: http (Paul Rubin) Date: 29 Jun 2009 19:40:56 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <7xhbxy8mvb.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Rereading this I got what you meant by "wrapper with mutating slot". > But that is (like I think you implied) functionally equivalent to a > mutating data structure, with worse performance because of additional > memory allocation and such. Is it faster to rebalance the tree with a > persistent data structure? If you're going to use a self-balancing tree you will have to do some tree rotations even if the tree is mutable. My guess is that it's still O(log n) updates, but with a smaller proportionality constant. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:39:22 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:39:22 +1200 Subject: Drawing in PDF References: Message-ID: In message , Jun wrote: > ... is there open source solution ? Poppler? From ldo at geek-central.gen.new_zealand Mon Jun 29 23:41:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:41:42 +1200 Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: In message , Pascal Chambon wrote: > I met the issue : select() works only on windows ... No it doesn't. It works only on sockets on Windows, on Unix/Linux it works with all file descriptors . From timr at probo.com Mon Jun 29 23:42:22 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 29 Jun 2009 20:42:22 -0700 Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> <40e3eff9-9e5c-4979-91bd-c85988352e91@k15g2000yqc.googlegroups.com> Message-ID: bootkey wrote: > >Thanks for the reply. I wonder why the tokenizer classifies all >operators simply as OP, instead of the various operators listed in the >tok_name dictionary. I imagine it's just an exercise left to the reader. It's not that hard of an extension. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:47:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:47:26 +1200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: In message , MRAB wrote: > row = [r or "NULL" for r in row] I know that, in this particular case, all the elements of row are strings, and the only string that is equivalent to False is the empty string, but still row = [[r, "NULL"][r == ""] for r in row] From ldo at geek-central.gen.new_zealand Mon Jun 29 23:48:52 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:48:52 +1200 Subject: Looking for developer to help me References: Message-ID: In message , Daniel Gerzo wrote: > http://bitbucket.org/danger/pysublib/src/ Can't seem to get through to your site. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:55:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:55:01 +1200 Subject: Making code run in both source tree and installation path References: Message-ID: In message , Javier Collado wrote: > - distutils trick in setup.py to modify the installed script (i.e. > changing a global variable value) so that it has a reference to the > data files location. This seems to me to be the cleanest solution, at least as a default. > - Heuristic in the package code to detect when it's being executed > from the source tree and when it has been the installed By definition, a "heuristic" can never be fully reliable. > - Just using an environment variable that the user must set according > to his needs This can be useful as a way to override default settings. But requiring it means extra trouble for the user. For configurable settings, best to observe a hierarchy like the following (from highest to lowest priority): * command-line options * environment-variable settings * user prefs in ~/.whatever * system configs in /etc * common data in /usr/share * hard-coded From ldo at geek-central.gen.new_zealand Mon Jun 29 23:58:22 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:58:22 +1200 Subject: fork, threads and proper closing References: Message-ID: In message , Francesco Bochicchio wrote: > ... if the thread is waiting for a blocking I/O operation to complete, > like reading from a socket with no data or waiting for a locked resource > (i.e. semaphore) to be unlocked, it will not service the queue and will > not read the 'quit command' (the poison pill), and therefore will not > quit until the blocking I/O terminates (and it could be never). Under Linux systems, threads are little different from processes. In particular, sending a thread/process a signal will cause any blocking I/O operation in progress to abort, either with only some bytes read/written, or if nothing was read/written, with an EINTR error. From clp2 at rebertia.com Tue Jun 30 00:17:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 21:17:17 -0700 Subject: csv blank fields In-Reply-To: References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> On Mon, Jun 29, 2009 at 8:47 PM, Lawrence D'Oliveiro wrote: > In message , MRAB > wrote: > >> ? ? ?row = [r or "NULL" for r in row] > > I know that, in this particular case, all the elements of row are strings, > and the only string that is equivalent to False is the empty string, but > still > > ? ?row = [[r, "NULL"][r == ""] for r in row] While I do find the use of booleans as integers interesting, I think the ternary operator would be clearer: row = [("NULL" if r == "" else r) for r in row] Cheers, Chris -- http://blog.rebertia.com From timr at probo.com Tue Jun 30 00:23:57 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 29 Jun 2009 21:23:57 -0700 Subject: Python Imaging Library download link broken? References: Message-ID: peter wrote: > >Just got a new computer and I'm trying to download my favourite >applications. All's well until I get to PIL, and here pythonware and >effbot both return a 502 Proxy error. > >Is this just a temporary glitch, or something more serious? And if >it's the latter, is there any alternative source? Surprisingly, this appears to have been caused by the death of Michael Jackson. The burden of people sending messages, downloading videos, buying albums, etc., has crippled the Internet worldwide. AT&T reported at its peak that there were more than 60,000 text messages PER SECOND being sent regarding Jackson. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From magawake at gmail.com Tue Jun 30 00:47:21 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 30 Jun 2009 00:47:21 -0400 Subject: csv blank fields In-Reply-To: <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> Message-ID: <1cbd6f830906292147x6e18b240q9a972e51dd7c6e4d@mail.gmail.com> Thankyou! On Tue, Jun 30, 2009 at 12:17 AM, Chris Rebert wrote: > On Mon, Jun 29, 2009 at 8:47 PM, Lawrence > D'Oliveiro wrote: >> In message , MRAB >> wrote: >> >>> ? ? ?row = [r or "NULL" for r in row] >> >> I know that, in this particular case, all the elements of row are strings, >> and the only string that is equivalent to False is the empty string, but >> still >> >> ? ?row = [[r, "NULL"][r == ""] for r in row] > > While I do find the use of booleans as integers interesting, I think > the ternary operator would be clearer: > > row = [("NULL" if r == "" else r) for r in row] > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > From steven at REMOVE.THIS.cybersource.com.au Tue Jun 30 01:45:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 05:45:17 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Jun 2009 22:37:15 -0400, Eric S. Johansson wrote: > Steven D'Aprano wrote: ... >> Sounds to me that your speech environment needs a command to turn >> capslock on and off, and your problem with PEP 8 is solved: > > you haven't used recognition, have you? No. >> x equals caps on red caps off plus three > > it also means "red" is a single utterance. "RED" is three utterances. > You've just tripled vocal load for single word which means vat you just > cut my ability to work by two thirds. That assumes that every word is all caps. In practice, for real-life Python code, I've tripled the vocal load of perhaps one percent of your utterances, which cuts your productivity by 2%. If you have 10000 words in you per day, and one percent get wrapped with a leading and trailing "capslock", you have: 9900 regular words plus 100 constants versus 9700 regular words plus 100 constants plus 200 by capslock. Your productivity goes down by 200 words out of 10,000, or two percent. >>> Heck, have you ever noticed how most Python smart editors can't even >>> indent properly according to local contexts. Emacs is the only one and >>> even that one sometimes fails >> >> I use kwrite for editing, and I can't say I've ever noticed a failure. > > okay, it fails from a speech recognition user perspective. Put the > cursor on the line and hit the tab key. Insert spaces/tabs in the line > of text. Not good for speech recognition. If mess of indentation and > hit the tab key, it doesn't automatically indent to the right location. > I'll be damned if I'm in the sit there speaking > "tabkeytabkeytabkeytabkeytabkey" because the error should take care of > it for me and save my voice. Like I said, Emacs does it correctly and > nobody else does as far as I can tell. I don't understand what you're describing. If you set kwrite to use "Python style" indent mode, then starting a new line will automatically indent to either the current indent level, or one extra indent level if the line ends with a colon. You shouldn't need to indent forward more than one level at a time when writing Python code, although you will need to dedent multiple levels on occasion. > I only have about 1000 keystrokes equivalents today in my hands. Where > am I going to use them? Try adding (driving), preparing food, personal > hygiene, or typing PEP-8 compliant code? Your choice naturally. > You're looking at it from the classical anti-accommodation perspective. > Don't change the convention, give us the tools so we can comply with > what the rest of you do. Just a minute. You're the one who started this discussion rejecting the convention. Your first post started off: "I reject this convention..." and then finished with "so I reject pep 8 because I have no voice safe alternative" Do you blame us for reading this as a protest against uppercase identifiers? Now you're saying you're happy for us to keep the all-uppercase convention and just want better tools. Okay, you want better tools. Great. If you're attempting to raise the profile of disabled programmers, you've done so, but what exactly are you expecting? I've already said it's your right to reject the convention for your own code. Go right ahead. This is only a problem if you're editing other people's code which is using uppercase constants. You've rejected capslock red capslock because it takes three utterances, but said you use constant_red instead. That's two utterances, saving you only one. If you actually have to say the underscore, your convention takes six syllables versus five for my idea. >> Especially when these coding conventions are entirely optional. > > these conventions are religion for some special if you want to > contribute code. Does your editor have search and replace? Before you contribute code, do a global replacement of constant_red for RED. > But look at the bigger issue. Yes, we get it. It sucks to have a physical disability. The universe isn't arranged to make it easy for those who do, and even systems built by people are only indifferently suitable. So, let's get down to practical matters: Do you wish to register a protest against all-caps constants in PEP 8? Do you wish to ask the Python Dev team to rethink their decision? Do you wish to raise the profile of disabled programmers? Do you wish to start a project developing a better, smarter editor, and are looking for volunteers? -- Steven From http Tue Jun 30 02:54:01 2009 From: http (Paul Rubin) Date: 29 Jun 2009 23:54:01 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> Message-ID: <7xk52u2ovq.fsf@ruckus.brouhaha.com> I just came across this, a rather advanced algorithms book but my favorite kind: the text (in draft form, anyway) is free online. http://www.cs.princeton.edu/theory/complexity/ From saxi at nm.ru Tue Jun 30 02:54:33 2009 From: saxi at nm.ru (saxi) Date: Mon, 29 Jun 2009 23:54:33 -0700 (PDT) Subject: Error in Pango while using cairo/librsvg References: <4a363441$0$30238$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7d765488-3330-4a9d-904f-67f29dde59dd@h2g2000yqg.googlegroups.com> I use pyWxSVG to convert a svg file to a png image. pyWxSVG is svg canvas for wxPython. View and print svg file or svg content, convert svg to raster graphics. Open svg, svgz file as wx.Image, use wx.BITMAP_TYPE_SVG, wx.BITMAP_TYPE_SVGZ type. Partial support svg format. Tested with Python 2.5 and wxPython 2.8.9.2. Path parser and elliptical arc approximation from Enable. From phil at riverbankcomputing.com Tue Jun 30 03:00:43 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 30 Jun 2009 08:00:43 +0100 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> <4A4894F4.7040606@cox.net> Message-ID: <6b03a4a46a2b070694248e216750c6d4@localhost> On Mon, 29 Jun 2009 16:47:58 -0400, Terry Reedy wrote: > The replacement would need to work with Py 3. TK does. I have not > noticed that anything else does, though that should change eventually. > (And I am sure someone will point of something I have not noticed.) PyQt does. Phil From nurazije at gmail.com Tue Jun 30 03:19:26 2009 From: nurazije at gmail.com (NurAzije) Date: Tue, 30 Jun 2009 00:19:26 -0700 (PDT) Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: <0bc58d9a-37cf-4e09-a28f-5edb0489ea30@h8g2000yqm.googlegroups.com> On Jun 29, 11:04?am, Tim Harig wrote: > On 2009-06-29, NurAzije wrote: > > > Hi, > > I am working on a study and I need expert opinion, I did not work with > > Python before, can anyone help me with a comparison betweenWhizBase > > (www.whizbase.com) and Python please. > > Given posts like:http://groups.google.com/group/Server-side-programing/browse_thread/t... > is this just thinly veiled spam? ?The domain and the posting IP address are > both out of Sarajevo, Bosnia. > > Obviously you alreadly know your product is nothing but a database > macro processor. ?Python is a dynamic programming language and therefore > far more capable. > > Your product is proprietary with less capability while Python is free and > powerful. Hi Tim, I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, for that it is interesting for me. regards, Ashraf Gheith From danger at rulez.sk Tue Jun 30 04:10:03 2009 From: danger at rulez.sk (Daniel Gerzo) Date: Tue, 30 Jun 2009 10:10:03 +0200 Subject: Looking for developer to help me In-Reply-To: References: Message-ID: <518b3e7bb9a4c28ae524f572d163df62@services.rulez.sk> Dear Lawrence, On Tue, 30 Jun 2009 15:48:52 +1200, Lawrence D'Oliveiro wrote: > In message , Daniel > Gerzo wrote: > >> http://bitbucket.org/danger/pysublib/src/ > > Can't seem to get through to your site. BitBucket isn't actually my site, it's a Mercurial hosting provider. I wonder why it doesn't work for you...maybe some routing problem, I advice you to try a bit later. -- S pozdravom / Best regards Daniel From gagsl-py2 at yahoo.com.ar Tue Jun 30 04:11:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 05:11:41 -0300 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: En Tue, 30 Jun 2009 03:33:52 -0300, Dennis Lee Bieber escribi?: > On Mon, 29 Jun 2009 11:59:59 -0300, "Gabriel Genellina" > declaimed the following in > gmane.comp.python.general: > >> The fact that it's the same character used for formatting strings with >> the >> % operator is an unfortunate coincidence (or a very bad choice, I don't >> know). >> > At the core -- if one looks at the Python source of the module and > takes into account that, prior to MySQL 5.x, MySQL did not support > "prepared statements", everything being sent as a full string query -- > MySQLdb actually uses string interpolation to fill in the fields... > AFTER, of course, passing all the arguments through a function that > "safes" them (escaping sensitive characters, converting numerics to > string equivalent, etc., wrapping quotes about them). Thanks for the historical reference. Even then, the code *could* have used other markers, like ?, doing the appropiate substitutions before the final string interpolation... (but critisizing the original design after many years isn't fair!) -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Tue Jun 30 04:16:02 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 20:16:02 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message , Tim Harig wrote: > On 2009-06-29, Lawrence D'Oliveiro > wrote: >> Sounds more like broken OS with no integrated package management. > > Package managers with dependency tracking were all the rage when I first > started using Linux. So I tried Red Hat and everything worked great until > the depency database corrupted itself. I have been using and administering various flavours of Linux--Red Hat, SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about the last decade, and I have NEVER seen this mythical dependency database corruption of which you speak. If you thought they were "all the rage" before, they're pretty much mandatory now. From usernet at ilthio.net Tue Jun 30 04:28:14 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:28:14 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-30, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> Package managers with dependency tracking were all the rage when I first >> started using Linux. So I tried Red Hat and everything worked great until >> the depency database corrupted itself. > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about > the last decade, and I have NEVER seen this mythical dependency database > corruption of which you speak. Its usually referred to as RPM hell (like DLL hell) although it can happen to DEB packages as well. You end up in a situation with cyclic dependencies where you cannot delete one application because it depends on a second but you cannot remove the second because it depends on the first. What can I say. It happens. It happened to me. > If you thought they were "all the rage" before, they're pretty much > mandatory now. I have been happy for years using my own heavily modified version of Slackware for installing the base system. After that, I install everything from source. Incidently, a similar discussion has started in a subthread of comp.unix.shell. From usernet at ilthio.net Tue Jun 30 04:36:03 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:36:03 GMT Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> <0bc58d9a-37cf-4e09-a28f-5edb0489ea30@h8g2000yqm.googlegroups.com> Message-ID: On 2009-06-30, NurAzije wrote: > On Jun 29, 11:04?am, Tim Harig wrote: >> On 2009-06-29, NurAzije wrote: >> > I am working on a study and I need expert opinion, I did not work with >> > Python before, can anyone help me with a comparison betweenWhizBase >> > (www.whizbase.com) and Python please. >> Given posts like:http://groups.google.com/group/Server-side-programing/browse_thread/t... >> is this just thinly veiled spam? ?The domain and the posting IP address are >> both out of Sarajevo, Bosnia. > I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, > for that it is interesting for me. >From your post in Server-side-programming you *do* heavily endorse the product and must therefore know about the product itself. I don't know what I can tell you about Python any more then to mention that it is a genteral purpose programming language. It can be used very effectively for creating websites. It could easily be used to create a program that does what the WhizBase product does; and, it can be used for tasks far outside of creating websites. Perhaps, if you give us a little more specific idea of what you want to know about it, we could be more helpful to you. From gruszczy at gmail.com Tue Jun 30 04:44:39 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Tue, 30 Jun 2009 10:44:39 +0200 Subject: Specific iterator in one line Message-ID: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> This is purely sport question. I don't really intend to use the answer in my code, but I am wondering, if such a feat could be done. I have a following problem: I have a list based upon which I would like to construct a different one. I could simply use list comprehensions, but there is an additional trick: for some elements on this list, I would like to return two objects. For example I have a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I would like to add 2 'b', like this: [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] The easy way is to return a tuple ('b', 'b') for 1s and then flatten them. But this doesn't seem very right - I'd prefer to create a nice iterable right away. Is it possible to achieve this? Curiosly, the other way round is pretty simple to achieve, because you can filter objects using if in list comprehension. -- Filip Gruszczy?ski From gruszczy at gmail.com Tue Jun 30 04:45:16 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Tue, 30 Jun 2009 10:45:16 +0200 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <1be78d220906300145g1fa118cekd6619f70e66389b3@mail.gmail.com> Oh, and there is additional requirement: it must be a one liner with at most 80 characters ;-) W dniu 30 czerwca 2009 10:44 u?ytkownik Filip Gruszczy?ski napisa?: > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. > > > -- > Filip Gruszczy?ski > -- Filip Gruszczy?ski From steven at REMOVE.THIS.cybersource.com.au Tue Jun 30 04:48:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 08:48:34 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: > >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> >> Package managers with dependency tracking were all the rage when I >> first started using Linux. So I tried Red Hat and everything worked >> great until the depency database corrupted itself. > > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over > about the last decade, and I have NEVER seen this mythical dependency > database corruption of which you speak. Really? I've seen it, or at least something that looks like it if you squint. In my experience, it can usually be fixed by: yum clean all on recent Redhat based systems. Worst case, there may be a lockfile that needs deleting as well. -- Steven From rajat.dudeja at aeroflex.com Tue Jun 30 04:50:37 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Tue, 30 Jun 2009 04:50:37 -0400 Subject: Access NtQueryInformationProces() from Python Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> Hi, I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. Can anyone direct me to some examples where they have been successfully called through Python? Thanks and regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Tue Jun 30 04:56:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:56:16 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-30, Steven D'Aprano wrote: > On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: >> In message , Tim Harig wrote: >>> Package managers with dependency tracking were all the rage when I >>> first started using Linux. So I tried Red Hat and everything worked >>> great until the depency database corrupted itself. >> I have been using and administering various flavours of Linux--Red Hat, >> SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over >> about the last decade, and I have NEVER seen this mythical dependency >> database corruption of which you speak. > Really? I've seen it, or at least something that looks like it if you > squint. In my experience, it can usually be fixed by: > yum clean all Yum wasn't available then and I have never used it. Maybe it does a better job these days. I don't know. I get along fine without it. From pdpinheiro at gmail.com Tue Jun 30 04:57:24 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 30 Jun 2009 01:57:24 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> <7x4otzykoi.fsf@ruckus.brouhaha.com> <7aqmfiF1vh4vfU1@mid.individual.net> Message-ID: <977b3568-eaf9-4653-8825-1312cf0eeed3@n30g2000vba.googlegroups.com> On Jun 29, 3:17?am, greg wrote: > Paul Rubin wrote: > > Steven D'Aprano writes: > > >>But that depends on what you call "things"... if electron shells are real > >>(and they seem to be) and discontinuous, and the shells are predicted/ > >>specified by eigenvalues of some continuous function, is the continuous > >>function part of nature or just a theoretical abstraction? > > Another thing to think about: If you put the atom in a > magnetic field, the energy levels of the electrons get > shifted slightly. To the extent that you can vary the > magnetic field continuously, you can continuously > adjust the energy levels. > > This of course raises the question of whether it's > really possible to continuously adjust a magnetic field. > But it's at least possible to do so with much finer > granularity than the differences between energy levels > in an atom. > > So if there is a fundamentally discrete model > underlying everything, it must be at a much finer > granularity than anything we've so far observed, and > the discrete things that we have observed probably > aren't direct reflections of it. > > -- > Greg Electron shells and isolated electrons stuck in a magnetic field are different phenomena that can't be directly compared. Or, at least, such a comparison requires you to explain why it's proper. From rhodri at wildebst.demon.co.uk Tue Jun 30 04:57:27 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 09:57:27 +0100 Subject: pep 8 constants In-Reply-To: <4A497A5B.4040503@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> <4A497A5B.4040503@harvee.org> Message-ID: On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson wrote: > Steven D'Aprano wrote: > >> Why do you think a smart editing environment is in opposition to coding >> conventions? Surely an editor smart enough to know a variable name >> spoken >> as "pear tree" is an instance and therefore spelled as pear_tree (to use >> your own example) would be smart enough to know a variable name spoken >> as >> "red" is a constant and therefore spelled "RED"? > > no. I think a smart editing environment should support a coding > convention. If > an editor is smart enough to track type and instance information, yes. > It should > be able to generate the right strings for symbols. The question is, how > do we > get such a smart editor. as far as I know, none exist and the smart > ones so far > seem to be oriented towards hand use and are almost inaccessible to > speech. But is it really possible for an editor to be smart enough -- Rhodri James *-* Wildebeest Herder to the Masses From clp2 at rebertia.com Tue Jun 30 04:58:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Jun 2009 01:58:07 -0700 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <50697b2c0906300158tba3f511paa3de95615524066@mail.gmail.com> 2009/6/30 Filip Gruszczy?ski : > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. >>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) ['b', 'b', 'a', 'a', 'b', 'b'] 69 chars long (plus or minus how the input list is written). Where's my golf trophy? ;) Cheers, Chris -- Goes to burn this shameful code... http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Tue Jun 30 05:03:11 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 10:03:11 +0100 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> <4A497A5B.4040503@harvee.org> Message-ID: On Tue, 30 Jun 2009 09:57:27 +0100, Rhodri James wrote: > On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson > wrote: > >> Steven D'Aprano wrote: >> >>> Why do you think a smart editing environment is in opposition to coding >>> conventions? Surely an editor smart enough to know a variable name >>> spoken >>> as "pear tree" is an instance and therefore spelled as pear_tree (to >>> use >>> your own example) would be smart enough to know a variable name spoken >>> as >>> "red" is a constant and therefore spelled "RED"? >> >> no. I think a smart editing environment should support a coding >> convention. If >> an editor is smart enough to track type and instance information, yes. >> It should >> be able to generate the right strings for symbols. The question is, how >> do we >> get such a smart editor. as far as I know, none exist and the smart >> ones so far >> seem to be oriented towards hand use and are almost inaccessible to >> speech. > > But is it really possible for an editor to be smart enough Gah. Ignore me. I hit 'send' instead of 'cancel', after my musings concluded that yes, an editor could be smart enough, but it would have to embed a hell of a lot of semantic knowledge of Python and it still wouldn't eliminate the need to speak the keyboard at times. -- Rhodri James *-* Wildebeest Herder to the Masses From mail at timgolden.me.uk Tue Jun 30 05:10:29 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 30 Jun 2009 10:10:29 +0100 Subject: Access NtQueryInformationProces() from Python In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> Message-ID: <4A49D685.5020109@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. > > Can anyone direct me to some examples where they have been successfully called through Python? You want to look at ctypes: http://docs.python.org/library/ctypes.html?highlight=ctypes#module-ctypes TJG From http Tue Jun 30 05:18:06 2009 From: http (Paul Rubin) Date: 30 Jun 2009 02:18:06 -0700 Subject: Specific iterator in one line References: Message-ID: <7xzlbqdqr5.fsf@ruckus.brouhaha.com> Filip Gruszczy?ski writes: > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] Using itertools: >>> list(chain(*imap([['a'],['b','b']].__getitem__, [1,0,0,1]))) ['b', 'b', 'a', 'a', 'b', 'b'] From bruno.42.desthuilliers at websiteburo.invalid Tue Jun 30 05:19:54 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 30 Jun 2009 11:19:54 +0200 Subject: Specific iterator in one line In-Reply-To: References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <4a49d8b4$0$445$426a74cc@news.free.fr> Chris Rebert a ?crit : (snip) >>>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) > ['b', 'b', 'a', 'a', 'b', 'b'] > > 69 chars long (plus or minus how the input list is written). You can save 4 more characters using tumple dispatch instead of dict dispatch: reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1])) > Where's my golf trophy? ;) golf ? Why golf ?-) From rhodri at wildebst.demon.co.uk Tue Jun 30 05:26:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 10:26:33 +0100 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: On Tue, 30 Jun 2009 09:44:39 +0100, Filip Gruszczy?ski wrote: > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. > If you'll allow me a prior "import itertools", >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] does the job in 62 characters. -- Rhodri James *-* Wildebeest Herder to the Masses From clp2 at rebertia.com Tue Jun 30 05:31:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Jun 2009 02:31:09 -0700 Subject: Specific iterator in one line In-Reply-To: <4a49d8b4$0$445$426a74cc@news.free.fr> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <4a49d8b4$0$445$426a74cc@news.free.fr> Message-ID: <50697b2c0906300231t2a616d7fo3c82f81b1af4ab5a@mail.gmail.com> On Tue, Jun 30, 2009 at 2:19 AM, Bruno Desthuilliers wrote: > Chris Rebert a ?crit : > (snip) >>>>> >>>>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) >> >> ['b', 'b', 'a', 'a', 'b', 'b'] >> >> 69 chars long (plus or minus how the input list is written). > > You can save 4 more characters using tumple dispatch instead of dict > dispatch: > > reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1])) > >> Where's my golf trophy? ;) > > golf ? Why golf ?-) http://en.wikipedia.org/wiki/Code_golf It's the sport the OP is playing. Cheers, Chris From andreas.tawn at ubisoft.com Tue Jun 30 05:42:48 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 11:42:48 +0200 Subject: Specific iterator in one line In-Reply-To: References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> > > This is purely sport question. I don't really intend to use the answer > > in my code, but I am wondering, if such a feat could be done. > > > > I have a following problem: I have a list based upon which I would > > like to construct a different one. I could simply use list > > comprehensions, but there is an additional trick: for some elements on > > this list, I would like to return two objects. For example I have a > > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > > would like to add 2 'b', like this: > > > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > > them. But this doesn't seem very right - I'd prefer to create a nice > > iterable right away. Is it possible to achieve this? Curiosly, the > > other way round is pretty simple to achieve, because you can filter > > objects using if in list comprehension. > > > If you'll allow me a prior "import itertools", > > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] > > does the job in 62 characters. list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) 50 characters. Do I win ?5? From python.list at tim.thechases.com Tue Jun 30 06:00:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 05:00:18 -0500 Subject: pep 8 constants In-Reply-To: <4A48E307.50804@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> Message-ID: <4A49E232.6090101@tim.thechases.com> Eric S. Johansson wrote: > Tim Chase wrote: > It sounds like the issue should be one of making your screen-reader >> smarter, not dumbing down Python conventions. I don't know what SR >> you're using (Jaws? Window Eyes? yasr? screeder? speakup? > > Naturally speaking is speech recognition (speech in text out) it is not text to > speech although it does have a pluging for that Sorry...I didn't catch that you were using speech-recognition (SR) instead of text-to-speech (TTS). I didn't see it mentioned in another thread-branch after I had posted. While I have used SR in some testing, I've found that while it's passable for prose (and even that, proclamations of "95% accuracy" sound good until you realize how many words comprise 5% of your daily typing :), it's not so good for code unless you have a very specific programming-language+SR designed editing environment...as you've been griping. However, the problem seems not to be PEP-8, but rather the inabilities of your SR combined with the failings of your editor. For coding, you might want to investigate a tool like Dasher[1] which offers an alternate form of input. It allows for custom vocabularies/keymaps if you need, as well as more precise specification of a full keyboard (caps vs. mixed-case, specific punctuation characters, etc). The predictive entry should be smart enough to pick up previously entered constants/terms saving you entry speed. It can also be driven by a wide variety of pointing devices (mouse, trackball, touchpad, head-tracker, gyro-input, etc). You might also experiment with other editors that allow for more efficient editing. Hope these give you another option to consider, if SR plus your current editor aren't cutting it for you, -tkc [1] http://www.inference.phy.cam.ac.uk/dasher/ http://en.wikipedia.org/wiki/Dasher http://www.youtube.com/results?search_query=dasher http://video.google.com/videosearch?q=dasher From rhodri at wildebst.demon.co.uk Tue Jun 30 06:06:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 11:06:45 +0100 Subject: pep 8 constants In-Reply-To: <4A496FE5.9060005@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> <4A496FE5.9060005@harvee.org> Message-ID: [Trimming for length, sorry if that impacts too much on intelligibility] On Tue, 30 Jun 2009 02:52:37 +0100, Eric S. Johansson wrote: > let's use an example. Admittedly, this is a very simple example but > hopefully it > illustrates my point > > What I dictate is: > > from pots is class telephone > > What should generate is: > > class Telephone (pots): > > as you can see, taken from the simplistic expression, we generate the > right > pep-8 convention. (I think). This is not the only grammar one can use > but, it's > one that comes to mind that doesn't have a lot of dead ends. [snip fuller example] > at each stage of the way, names get transformed into the pep-8 form > without me > having to say anything special. The environment knows what form it wants > and > does the transformation automatically. I'm surprised people aren't > doing this > already for their handcrafted code. It's one less bit of detail you need > to pay > attention to. This goes a long way, but it doesn't eliminate the need for some forms of escape coming up on a moderately frequent basis. Consider "Coffee strength equals five" for example: this could mean either coffee_strength = 5 or COFFEE_STRENGTH = 5 depending on whether we will later be using it as a constant or not. Python doesn't have syntactic constants, which is precisely why PEP-8 is useful. You might have enough smarts in your system for it to remember after the first time you use "coffee strength", and it might be unambiguous, but at the very least you need to be able to say "Constant coffee strength equals five" first time round. This isn't the only occasion when you simply don't have the context to avoid verbal disambiguation. Are you accessing attributes of the class MyClass or its instance my_class, for instance? In your initial post you seemed to be claiming that having to do this disambiguation textually was bad, and PEP-8 should therefore be rejected. Given that I'm not prepared to lose the productivity increase that comes with being able to disambiguate visually at a glance, I don't see that it's avoidable. Incidentally, since what you're proposing is essentially templating, wouldn't it be better to do it as post-processing on the speech recognition rather than building it directly into an editor? to resolve -- Rhodri James *-* Wildebeest Herder to the Masses From andreas.tawn at ubisoft.com Tue Jun 30 06:11:24 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 12:11:24 +0200 Subject: Specific iterator in one line In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> > > > This is purely sport question. I don't really intend to use the answer > > > in my code, but I am wondering, if such a feat could be done. > > > > > > I have a following problem: I have a list based upon which I would > > > like to construct a different one. I could simply use list > > > comprehensions, but there is an additional trick: for some elements on > > > this list, I would like to return two objects. For example I have a > > > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > > > would like to add 2 'b', like this: > > > > > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > > > > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > > > them. But this doesn't seem very right - I'd prefer to create a nice > > > iterable right away. Is it possible to achieve this? Curiosly, the > > > other way round is pretty simple to achieve, because you can filter > > > objects using if in list comprehension. > > > > > If you'll allow me a prior "import itertools", > > > > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] > > > > does the job in 62 characters. > > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > > 50 characters. Do I win ?5? list("".join([("a","bb")[x] for x in [1,0,0,1]]) Or 49 :o) From tkjthingone at gmail.com Tue Jun 30 06:17:59 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Tue, 30 Jun 2009 03:17:59 -0700 Subject: The Python Way for module configuration? In-Reply-To: References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: On Sun, Jun 28, 2009 at 10:22 AM, kj wrote: > In <87fxdlujds.fsf at benfinney.id.au> Ben Finney > > writes: > > >(Even if you don't want to receive email, could you please give your > >actual name in the ?From? field instead of just initials? It makes > >conversation less confusing.) > > I don't know why, but for as long as I can remember everyone calls > me kj, even my mom. My name is Keaweikekahiali?iokamoku > Jallalahwallalruwalpindi > > kj > > -- > http://mail.python.org/mailman/listinfo/python-list > > Is that Mongolian? :) (poor joke) Anyway, I tend to just use the name of a character from the most recent book I've read. People often can't tell the difference (though this one is something of a stretch) and I get to maintain my illusion of anonymous. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Jun 30 06:19:22 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Jun 2009 12:19:22 +0200 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: Andreas Tawn wrote: >> > > This is purely sport question. I don't really intend to use the >> > > answer in my code, but I am wondering, if such a feat could be done. >> > > >> > > I have a following problem: I have a list based upon which I would >> > > like to construct a different one. I could simply use list >> > > comprehensions, but there is an additional trick: for some elements >> > > on this list, I would like to return two objects. For example I have >> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I >> > > would like to add 2 'b', like this: >> > > >> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] >> > > >> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten >> > > them. But this doesn't seem very right - I'd prefer to create a nice >> > > iterable right away. Is it possible to achieve this? Curiosly, the >> > > other way round is pretty simple to achieve, because you can filter >> > > objects using if in list comprehension. >> > > >> > If you'll allow me a prior "import itertools", >> > >> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] >> > >> > does the job in 62 characters. >> >> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >> >> 50 characters. Do I win ?5? > > list("".join([("a","bb")[x] for x in [1,0,0,1]]) > > Or 49 :o) >>> len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""") 48 >>> sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[]) ['b', 'b', 'a', 'a', 'b', 'b'] From http Tue Jun 30 06:26:39 2009 From: http (Paul Rubin) Date: 30 Jun 2009 03:26:39 -0700 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <7x7hyu2f1c.fsf@ruckus.brouhaha.com> "Andreas Tawn" writes: > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > 50 characters. Do I win ??5? Er, missing right paren. Try: list("".join(("a","bb")[x] for x in [1,0,0,1])) From python.list at tim.thechases.com Tue Jun 30 06:29:58 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 05:29:58 -0500 Subject: Specific iterator in one line In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> Message-ID: <4A49E926.8060209@tim.thechases.com> >> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >> >> 50 characters. Do I win ?5? > > list("".join([("a","bb")[x] for x in [1,0,0,1]]) > > Or 49 :o) Well, you have a missing ")" character, but that would be the 49th. You can[*] abuse python's parsing by removing certain spaces with list(''.join([('a','bb')[x]for x in[1,0,0,1]])) bringing you down to 47. In more recent versions of Python, you can then pass a generator instead of a list-comprehension: list(''.join(('a','bb')[x]for x in[1,0,0,1])) bringing you to 45. -tkc [*] not *should*, but *can* From sk8in_zombi at yahoo.com.au Tue Jun 30 06:34:15 2009 From: sk8in_zombi at yahoo.com.au (Mr SZ) Date: Tue, 30 Jun 2009 03:34:15 -0700 (PDT) Subject: Learning to use decorators with classes Message-ID: <370202.47877.qm@web54504.mail.re2.yahoo.com> Hi, I'm writing an LDAP plugin for my TG2 application. In this I wrote a small class based decorator with args to set up a connection and call the necessary functionality but I'm having problems with it. Here's my code: class getConnection(object): def __init__(self, settings, credentials): self.settings = settings self.credentials = credentials def __call__(self, f): def wrapped_f(*args, **kw): ...code snipped... try: if tls: connection.start_tls_s() if anon: con.simple_bind_s() else: con.simple_bind_s( dn, pw ) except ldap.LDAPError, e: print e.message['info'] else: kw['conn'] = connection try: f(*args, **kw) except Exception, e: print 'Exception in Plugin execution: %s' % e finally: connection.unbind() return wrapped_f class LdapPlugin(Plugin): ... def __init__(self, **kw): Plugin.__init__(self) @getConnection(self._settings, self.__cred__) def search(self, **kw): print 'Searching' ... Here the base class constructor(Plugin) fetches plugin specific settings from the web framework and stores it in self._settings and user info in self.__cred__ . Now when the method is invoked, this is the error I get: File '.../plugins/ldap/ldap/__init__.py', line 69 in LdapPlugin @getConnection(self._settings, self.__cred__) NameError: name 'self' is not defined I can simply write a method that gets a connection and deal with it but I wanted to know and learn why decorators is not working in this case. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From __peter__ at web.de Tue Jun 30 06:34:44 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Jun 2009 12:34:44 +0200 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: Peter Otten wrote: > Andreas Tawn wrote: > >>> > > This is purely sport question. I don't really intend to use the >>> > > answer in my code, but I am wondering, if such a feat could be done. >>> > > >>> > > I have a following problem: I have a list based upon which I would >>> > > like to construct a different one. I could simply use list >>> > > comprehensions, but there is an additional trick: for some elements >>> > > on this list, I would like to return two objects. For example I have >>> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I >>> > > would like to add 2 'b', like this: >>> > > >>> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] >>> > > >>> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten >>> > > them. But this doesn't seem very right - I'd prefer to create a nice >>> > > iterable right away. Is it possible to achieve this? Curiosly, the >>> > > other way round is pretty simple to achieve, because you can filter >>> > > objects using if in list comprehension. >>> > > >>> > If you'll allow me a prior "import itertools", >>> > >>> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] >>> > >>> > does the job in 62 characters. >>> >>> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >>> >>> 50 characters. Do I win ?5? >> >> list("".join([("a","bb")[x] for x in [1,0,0,1]]) >> >> Or 49 :o) > >>>> len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""") > 48 >>>> sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[]) > ['b', 'b', 'a', 'a', 'b', 'b'] forgot one extra space: >>> sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[]) ['b', 'b', 'a', 'a', 'b', 'b'] >>> len("""sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[])""") 47 From venutaurus539 at gmail.com Tue Jun 30 06:46:36 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 30 Jun 2009 03:46:36 -0700 (PDT) Subject: Passing parameters for a C program in Linux. Message-ID: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Hi all, I have to write an automted script which will test my c program. That program when run will ask for the commands. For example: local-host# ./cli Enter 1 for add Enter 2 for sub Enter 3 for mul 1 -------Our option Enter two numbers 44 33 -------- Our option Result is 77 As shown in the above example it lists all the options and waits for user input and once given, it does some operations and waits for some more. This has to be automated. Can someone give suggestions how to do this in Python (Linux Platform in particular). Thank you, Venu. From shenyute at gmail.com Tue Jun 30 06:54:35 2009 From: shenyute at gmail.com (Shen, Yu-Teh) Date: Tue, 30 Jun 2009 03:54:35 -0700 (PDT) Subject: python extend c++ module Message-ID: <03d476cc-b633-44d4-b68f-46c64285d253@j32g2000yqh.googlegroups.com> I have written a c++ extend module and I use distutils to build. setup.py ---------------- from distutils.core import setup, Extension setup(name="noddy", version="1.0", ext_modules=[ Extension("noddy3", ["noddy3.cpp", "a.cpp"]) ]) I found it's quite strange when compiling. I didn't use extern "C" at all , how can python get the right c++ funciton name without any compile error?? I found that it first use gcc to compile noddy3.cpp and then link by g+ +. Could anyone explain what it's all about? Thanks a lot!! here is the compiling message. --------------------------------------- running install running build running build_ext building 'noddy3' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp -o build/temp.linux-i686-2.6/noddy3.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so running install_lib copying build/lib.linux-i686-2.6/noddy3.so -> /usr/local/lib/python2.6/site-packages running install_egg_info Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg- info Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info From andreas.tawn at ubisoft.com Tue Jun 30 06:55:21 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 12:55:21 +0200 Subject: Specific iterator in one line In-Reply-To: <7x7hyu2f1c.fsf@ruckus.brouhaha.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <7x7hyu2f1c.fsf@ruckus.brouhaha.com> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE47A@PDC-MAIL3.ubisoft.org> > -----Original Message----- > From: python-list-bounces+andreas.tawn=ubisoft.com at python.org [mailto:python- > list-bounces+andreas.tawn=ubisoft.com at python.org] On Behalf Of Paul Rubin > Sent: Tuesday, June 30, 2009 11:27 AM > To: python-list at python.org > Subject: Re: Specific iterator in one line > > "Andreas Tawn" writes: > > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > > 50 characters. Do I win ??5? > > Er, missing right paren. Try: > > list("".join(("a","bb")[x] for x in [1,0,0,1])) > -- Indeed. Stupid paste ;o) From jeanmichel at sequans.com Tue Jun 30 07:00:34 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Jun 2009 13:00:34 +0200 Subject: pep 8 constants In-Reply-To: <4A4912D4.5070900@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> <4A490707.3040207@stoneleaf.us> <4A4912D4.5070900@harvee.org> Message-ID: <4A49F052.7050004@sequans.com> Eric S. Johansson wrote: > Ethan Furman wrote: > >> Eric S. Johansson wrote: >> >>> yup how long will i[t] be before you become disablesd? maybe not as >>> badly as I am >>> but you should start feeling some hand problems in your later 40's to >>> early 50's >>> and it goes down hill from there. self preservation/interest comes to >>> mind as a >>> possible motive for action. I thought 15 years would be enough for >>> somebody >>> else to push the isssue but no. if it is going to be, it has to be me. >>> >> For anyone who is still able to use their hands for typing, especially >> if you're beginning to encounter the painful wrists, consider switching >> to a Dvorak layout. It was a system I was curious about even before I >> needed it, and when I did need it I was able to create the layout in >> assembler (now, of course, it's widely available as a standard keyboard >> layout). I started noticing the pain in my late twenties (aggravated, >> I'm sure, by arthritis), but with switching to Dvorak the pain left and >> has only very rarely been noticable again. It will mostly likely be a >> challenge to switch, but well worth it. >> > > a good suggestion but not really addressing the point I'm trying to make of > building a system that would help people more profoundly injured. for example, > I've tried Dvorak and the act of typing was so painful that I couldn't learn it > You must previously define what you are calling "more profoundly injured". Which disabled abilities are you talking about ? What about people that have difficulties to speak because of partial jaw paralysis. They would need systems that recognize eye blinks to write down code. What about blind people, color blind ... ? Would a new disabled friendly PEP 8 version fits all their needs ? To come back to a more python related subject, I don't think it falls into PEP responsibility to take into account all the disabled abilities you can find in the dev community. This falls into the tools they used to workaround their issues and there's surely much work to be done here. In the end, as someone mentioned before, PEPs are only guidelines, and you are entitled to break them if the rule hurts you. This is one of the many beauties of python, it's flexible. Jean-Michel From grante at visi.com Tue Jun 30 07:19:13 2009 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Jun 2009 06:19:13 -0500 Subject: Drawing in PDF References: Message-ID: On 2009-06-30, Eduardo Lenz wrote: > Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: >> In message > >> d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: >> > ... is there open source solution ? >> >> Poppler? > > pypdf -- http://pybrary.net/pyPdf/ > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > * extracting document information (title, author, ...), > * splitting documents page by page, > * merging documents page by page, > * cropping pages, > * merging multiple pages into a single page, > * encrypting and decrypting PDF files. While it may be a pure-python library, the problem is that AFAICT it doesn't actually solve the problem at hand. The requirement is to "draw" on the pages of an existing PDF document (add annotations). > By being Pure-Python, it should run on any Python platform > without any dependencies on external libraries. It can also > work entirely on StringIO objects rather than file streams, > allowing for PDF manipulation in memory. It is therefore a > useful tool for websites that manage or manipulate PDFs. True, but does it allow you to add text/lines/etc. to a page? -- Grant From bearophileHUGS at lycos.com Tue Jun 30 07:30:01 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 30 Jun 2009 04:30:01 -0700 (PDT) Subject: Specific iterator in one line References: Message-ID: Filip Gruszczy?ski: > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] I like this version (43 golf holes), it's readable enough: [c for d in[1,0,0,1]for c in("a","bb")[d]] Bye, bearophile From nobody at nowhere.com Tue Jun 30 07:30:42 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 30 Jun 2009 12:30:42 +0100 Subject: Using Python for file packing References: Message-ID: On Mon, 29 Jun 2009 14:16:34 -0700, Scott David Daniels wrote: >>> Do you mean like a zip or tar file? >>> >>> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >>> >> >> I had no idea you could access a single file from a ZIP or TAR without >> explicitly extracting it somewhere. Thanks. > > You will find the zip format works better if you are compressing. The > zipfile compression is per file in the archive, rather than applied to > the entire archive (as in tarfile). The results of the tar format > decision is that extracting the last file in a .tgz (.tar.gz) or > .tar.bz2 (sometimes called .tbz) requires the expansion of the entire > archive, while extraction on a .zip is reposition, read, and possibly > expand. Even without compression, the tar format is ill-suited to random access. If you can choose the format, use a zip file. From harsha.reddy at db.com Tue Jun 30 07:45:40 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:15:40 +0530 Subject: Help me plsss... Message-ID: Hi All, Environment :- Solaris Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 Oracle version :- 10.2.0.3 Below is the library path echo $LD_LIBRARY_PATH /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib: /data/oracle/product/10.2.0.3/lib Issue :- We have been recently migrated from 9i to 10g database and also from AIX to Solaris. When we were using 9i i can able to import cx_oracle library... But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... newprd$ python ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. PLs help meee ... Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco.bizzarri at gmail.com Tue Jun 30 08:10:05 2009 From: marco.bizzarri at gmail.com (Marco Bizzarri) Date: Tue, 30 Jun 2009 14:10:05 +0200 Subject: Help me plsss... In-Reply-To: References: Message-ID: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- ? ? ? ? ? ? ? ? Solaris > Python Version :- ? ? ? ? ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > ? ? ? ? ? ? ? ? ? ? ? ? Python 2.4.3 (#1, Apr ?3 2006, 18:34:02) [C] on sunos5 > Oracle version :- ? ? ? ? 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr ?3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > ? File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ From harsha.reddy at db.com Tue Jun 30 08:13:42 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:43:42 +0530 Subject: Help me plsss... In-Reply-To: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Message-ID: Hi Marc, Thanks for the replyyyy... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/dbcom at DBEMEA cc python-list at python.org Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harsha.reddy at db.com Tue Jun 30 08:15:13 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:45:13 +0530 Subject: Help me plsss... In-Reply-To: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Message-ID: Hi Marc, Thanks for the replyyyy... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/dbcom at DBEMEA cc python-list at python.org Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From user at example.net Tue Jun 30 08:16:21 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 14:16:21 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/29 MRAB : > >>superpollo wrote: >> >>>hi folks. >>> >>>the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >>>not work? (prints stuff forever) >>> >>> 1 #!/usr/bin/python >>> 2 >>> 3 import threading >>> 4 import sys >>> 5 >>> 6 t = threading.Timer(3.0, sys.exit) >>> 7 t.start() >>> 8 while True: >>> 9 print "stuff ", >>> >> >>The Timer runs the function in another thread. Perhaps sys.exit is just >>exiting that thread and not the main thread. > > > sys.exit raises a SystemExit exception, which will get handled in the > new thread (where it won't do anything). Conceded, this isn't > particularly intuitive. > > For a non-toy example, you'd probably create an Event object, use your > timer to set the event, and your while loop would do while > event.is_set(), so the problem wouldn't arise. thank u paul. if u dont mind, would you give me a more detailed piece of code that does what i mean? tia From petr.messner at gmail.com Tue Jun 30 08:42:10 2009 From: petr.messner at gmail.com (Petr Messner) Date: Tue, 30 Jun 2009 14:42:10 +0200 Subject: Passing parameters for a C program in Linux. In-Reply-To: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <67c97cd90906300542o3479f4fdha81390b84965c469@mail.gmail.com> Hi, this can be done using module "subprocess"; there is also function popen() in module "os" and module popen2, but they are deprecated since Python 2.6. PM 2009/6/30 venutaurus539 at gmail.com : > Hi all, > I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1 -------Our option > Enter two numbers > 44 33 -------- Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. > -- > http://mail.python.org/mailman/listinfo/python-list > From david.lyon at preisshare.net Tue Jun 30 08:44:06 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 30 Jun 2009 08:44:06 -0400 Subject: ANN: Package Manager GUI for Python (Windows) In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: Hi All, I'm pleased to announce a GUI package manager (v 0.12) for Python versions 2.x under Windows. http://sourceforge.net/projects/pythonpkgmgr/ It's tightly linked to the pypi repository and offers the following functions: - search packages on pypi by name - install (via easyinstall or pip) - deinstall/remove packages - see package documentation - see package examples - install .EGG packages - Generate package manifest If you find any issues, please don't hesitate to report them via our tracker on the project page. Regards David From bruno.42.desthuilliers at websiteburo.invalid Tue Jun 30 08:48:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 30 Jun 2009 14:48:23 +0200 Subject: Learning to use decorators with classes In-Reply-To: References: Message-ID: <4a4a0991$0$418$426a74cc@news.free.fr> Mr SZ a ?crit : > Hi, > > I'm writing an LDAP plugin for my TG2 application. In this I wrote a small class based decorator with args to set up a connection and call the necessary > functionality but I'm having problems with it. Here's my code: > (snip code) > > class LdapPlugin(Plugin): > ... > def __init__(self, **kw): > Plugin.__init__(self) > > @getConnection(self._settings, self.__cred__) Don't use '__name__', they are reserved for the implementation. And FWIW, don't use '__name' unless you have a really compelling reason to do so. > def search(self, **kw): > print 'Searching' > ... This can't work, and it's a FAQ FWIW - but since there's no official c.l.py FAQ, we won't hold it against you !-) def and class are both *executable* statements (yes, classes and functions creation - like almost anything in Python - are run-time operations). The first one creates a function object - *wherever* it happens - and bind the function object to the function's name in the current namespace. Think of it as an equivalent of the following javascript snippet: var func_name = function(arg) { /* function's body */ }; The second statement - class - builds a class object from the names defined in the class statement's body (that is, names defined in the class statement's body will become attributes of the class object). Now about the 'methods' and 'self' stuff... First understand that there's *nothing* magical with 'self'. It's *not* a keyword. It's only a naming convention, and you could use any legal Python identified instead. The reason we have to explicitly mention it as first argument of the function is that it's the only way the function's body can get access to the current instance. What happens is (overly simplified) that during attribute resolution, when the found attribute happens to be a function, this function is wrapped - together with the instance on which the attribute was looked up and it's class - into a callable method object. Then when you call this method object, it inserts the instance as first argument to the function call, and returns the result of the function call (if you want to read more about this and how computed attributes are implemented in Python, google for 'descriptor protocol'). IOW, and to make a long story short, calling instance.method is the same as calling Class.method(instance). Ok, now to the point: when you call getConnection within the class statement's body, there's no magical "self" keyword poiting to an instance, and since the class itself doesn't yet exists, so there's *no* way you could get at an instance of it anyway !-) There are many ways to solve your problem, the simplest bing probably to write another decorator calling on the first one, ie: def connected_method(func): def connected(self, *args, **kw): wrapped = getConnection(self.__this, self.__that)(func) return wrapped(*args, **kw) return connected Note that this may not be that efficient - you'll have quite a few function calls involved here. While we're at it, a couple comments on your code... First, please read pep08 (naming and coding conventions) on python.org. Conventions are very important in Python. wrt/ error handling: try: if tls: connection.start_tls_s() if anon: con.simple_bind_s() else: con.simple_bind_s(dn, pw) except ldap.LDAPError, e: print e.message['info'] This kind of "error handling" is more than useless - it's worse than no error handling at all. If you cannot handle the problem (I really mean *handle*, you know, like do something to fix it), just let the exception propagate - you'll get a nice traceback with all the necessary debugging informations. Users of your package can always add a top-level "catch-all" exception handler that will log tracebacks, send alert mails to the team, and present the end-user with a nicely formatted error message (and even possibly a way to handle the problem - like providing appropriate connection data (credentials, url, whatever) !-) Also note that sys.stdout is for *normal* program outputs. Error messages belongs to sys.stderr. else: kw['conn'] = connection try: f(*args, **kw) except Exception, e: print 'Exception in Plugin execution: %s' % e Same as above : if you can't handle the exception, leave it alone. HTH From p.f.moore at gmail.com Tue Jun 30 08:54:21 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 30 Jun 2009 13:54:21 +0100 Subject: timer In-Reply-To: <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <79990c6b0906300554j1062668du8f4cb2c8acf990df@mail.gmail.com> 2009/6/30 superpollo : > Paul Moore wrote: >> For a non-toy example, you'd probably create an Event object, use your >> timer to set the event, and your while loop would do while >> event.is_set(), so the problem wouldn't arise. > > thank u paul. if u dont mind, would you give me a more detailed piece of > code that does what i mean? No problem: import threading e = threading.Event() t = threading.Timer(3.0, e.set) t.start() while not e.is_set(): print "Hello, threading world" Hope this helps, Paul From user at example.net Tue Jun 30 09:04:11 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:04:11 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/29 MRAB : > >>superpollo wrote: >> >>>hi folks. >>> >>>the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >>>not work? (prints stuff forever) >>> >>> 1 #!/usr/bin/python >>> 2 >>> 3 import threading >>> 4 import sys >>> 5 >>> 6 t = threading.Timer(3.0, sys.exit) >>> 7 t.start() >>> 8 while True: >>> 9 print "stuff ", >>> >> >>The Timer runs the function in another thread. Perhaps sys.exit is just >>exiting that thread and not the main thread. > > > sys.exit raises a SystemExit exception, which will get handled in the > new thread (where it won't do anything). Conceded, this isn't > particularly intuitive. > > For a non-toy example, you'd probably create an Event object, use your > timer to set the event, and your while loop would do while > event.is_set(), so the problem wouldn't arise. > > Paul. so why this does not work? 1 #!/usr/bin/python 2 3 import threading 4 5 e = threading.Event() 6 t = threading.Timer(3.0, e.set()) 7 t.start() 8 while not e.isSet(): 9 print "stuff ", it does *NOT* print (but it should, shouldn't it?), then exits after 3 sec but with error: Exception in thread Thread-1:Traceback (most recent call last): File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap self.run() File "/usr/lib/python2.3/threading.py", line 575, in run self.function(*self.args, **self.kwargs) TypeError: 'NoneType' object is not callable what gives? From venutaurus539 at gmail.com Tue Jun 30 09:05:34 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 30 Jun 2009 06:05:34 -0700 (PDT) Subject: Passing parameters for a C program in Linux. References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> On Jun 30, 5:42?pm, Petr Messner wrote: > Hi, > > this can be done using module "subprocess"; there is also function > popen() in module "os" and module popen2, but they are deprecated > since Python 2.6. > > PM > > 2009/6/30 venutaurus... at gmail.com : > > > Hi all, > > ? ? ? I have to write an automted script which will test my c > > program. That program when run will ask for the commands. For example: > > > local-host# ./cli > > Enter 1 for add > > Enter 2 for sub > > Enter 3 for mul > > 1 ? ? ? ? ? ?-------Our option > > Enter two numbers > > 44 33 ?-------- Our option > > Result is 77 > > > As shown in the above example it lists all the options and waits for > > user input and once given, it does some operations and waits for some > > more. This has to be automated. > > > Can someone give suggestions how to do this in Python (Linux Platform > > in particular). > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Can you give some more explanation about how exactly this can be done.. Thanks for reply, Venu From user at example.net Tue Jun 30 09:06:10 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:06:10 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <4a4a0dc3$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/30 superpollo : > >>Paul Moore wrote: >> >>>For a non-toy example, you'd probably create an Event object, use your >>>timer to set the event, and your while loop would do while >>>event.is_set(), so the problem wouldn't arise. >> >>thank u paul. if u dont mind, would you give me a more detailed piece of >>code that does what i mean? > > > No problem: > > import threading > > e = threading.Event() > t = threading.Timer(3.0, e.set) > t.start() > > while not e.is_set(): > print "Hello, threading world" > > Hope this helps, > Paul hi while i was waiting 4 ur reply, i posted an almost equal example, but it does not work... From paul.nospam at rudin.co.uk Tue Jun 30 09:08:38 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 30 Jun 2009 14:08:38 +0100 Subject: timer References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <87vdmdrhrd.fsf@rudin.co.uk> superpollo writes: > so why this does not work? > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 > 5 e = threading.Event() > 6 t = threading.Timer(3.0, e.set()) The second arg needs to be a callable - maybe you meant e.set without the brackets? From user at example.net Tue Jun 30 09:09:05 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:09:05 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/30 superpollo : > >>Paul Moore wrote: >> >>>For a non-toy example, you'd probably create an Event object, use your >>>timer to set the event, and your while loop would do while >>>event.is_set(), so the problem wouldn't arise. >> >>thank u paul. if u dont mind, would you give me a more detailed piece of >>code that does what i mean? > > > No problem: > > import threading > > e = threading.Event() > t = threading.Timer(3.0, e.set) > t.start() > > while not e.is_set(): > print "Hello, threading world" > > Hope this helps, > Paul do not bother answering... my fault. i wrote e.set() and not e.set thanks again From mail at timgolden.me.uk Tue Jun 30 09:09:43 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 30 Jun 2009 14:09:43 +0100 Subject: timer In-Reply-To: <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <4A4A0E97.3070103@timgolden.me.uk> superpollo wrote: > so why this does not work? > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 > 5 e = threading.Event() > 6 t = threading.Timer(3.0, e.set()) > 7 t.start() > 8 while not e.isSet(): > 9 print "stuff ", > > it does *NOT* print (but it should, shouldn't it?), then exits after 3 > sec but with error: Nice try, but you're passing *the result of calling e.set* as the function parameter to Timer. And the result of calling e.set () is None. So you're passing None as the function-to-call. Which it does. And then... > TypeError: 'NoneType' object is not callable Try passing the function instead: threading.Timer (3.0, e.set).start () TJG From user at example.net Tue Jun 30 09:11:09 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:11:09 +0200 Subject: timer In-Reply-To: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> Message-ID: <4a4a0eee$0$18931$4fafbaef@reader2.news.tin.it> i would like to thank each and everyone for help given, and aplologise for my inaccuracy. thanks 10**3! superchicken From p.f.moore at gmail.com Tue Jun 30 09:19:47 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 30 Jun 2009 14:19:47 +0100 Subject: timer In-Reply-To: <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <79990c6b0906300619y681a0871g3ea438331c4f726@mail.gmail.com> 2009/6/30 superpollo : > Paul Moore wrote: >> >> 2009/6/30 superpollo : >> >>> Paul Moore wrote: >>> >>>> For a non-toy example, you'd probably create an Event object, use your >>>> timer to set the event, and your while loop would do while >>>> event.is_set(), so the problem wouldn't arise. >>> >>> thank u paul. if u dont mind, would you give me a more detailed piece of >>> code that does what i mean? >> >> >> No problem: >> >> import threading >> >> e = threading.Event() >> t = threading.Timer(3.0, e.set) >> t.start() >> >> while not e.is_set(): >> ? ?print "Hello, threading world" >> >> Hope this helps, >> Paul > > do not bother answering... my fault. > > i wrote e.set() and not e.set > > > > thanks again No problem - I made the same mistake while I was writing the sample :-) (I also forgot t.start() the first time. So I'm winning 2-1 on trivial mistakes :-)) Paul. From roop at forwardbias.in Tue Jun 30 09:27:32 2009 From: roop at forwardbias.in (roop) Date: Tue, 30 Jun 2009 06:27:32 -0700 (PDT) Subject: ImageEnhance.Contrast - is this fishy or what? References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> <-OadnW9hvbHbbqrXnZ2dnUVZ_s-dnZ2d@pdx.net> Message-ID: <15c1e087-17af-4df9-b882-ae548dc0a486@j19g2000vbp.googlegroups.com> On Jun 17, 12:38?am, Scott David Daniels wrote: > > Over on image-sig, Fredrik Lundh responded: > ?> And the award for finding the oldest bug in PIL goes to... (that code > ?> was last touched in 1996). > ?> > > Congrats, roop, on getting this discovered just in the nick of time. > /me takes a bow :) From petr.messner at gmail.com Tue Jun 30 09:59:35 2009 From: petr.messner at gmail.com (Petr Messner) Date: Tue, 30 Jun 2009 15:59:35 +0200 Subject: Passing parameters for a C program in Linux. In-Reply-To: <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> Message-ID: <67c97cd90906300659l54004ec6t86e54a42146767e@mail.gmail.com> 2009/6/30 venutaurus539 at gmail.com : ... > Can you give some more explanation about how exactly this can be > done.. Popen object enables you to run any program in a newly-created child process, write to its standard input and read from its standard and error outputs. There is an example how your test program could look like: import subprocess p = subprocess.Popen("./cli", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) result, errs = p.communicate("1\n44 33\n") assert not errs assert result.splitlines()[-1] == "Result is 77" Popen objects have also attributes stdin, stdout and stderr, you can use them if you do not want to use communicate(). Be aware that you if you call stdout.read(), it reads everything and blocks until EOF occurrs (usually until the popen-ed program quits). You can also use readline(), but this can also block until the subprocess writes any line. In cases where this could be a problem (i think this automated test programs are not that cases) polling, nonblocking I/O or threads can be used. I have pasted complete example (with a script simulating your "cli" program) here: http://paste.pocoo.org/show/125944/ PM From thaisiang at gmail.com Tue Jun 30 10:43:10 2009 From: thaisiang at gmail.com (ts) Date: Tue, 30 Jun 2009 07:43:10 -0700 (PDT) Subject: python3 fail to start Message-ID: <788ec223-9894-4168-b1f8-758cd51a47ad@r16g2000vbn.googlegroups.com> i just install the python 3.1 dmg onto my mac. when i run python3, it fail with : Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: Abort trap couldnt understand the problem. anyone can help? From pdpinheiro at gmail.com Tue Jun 30 10:52:10 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 30 Jun 2009 07:52:10 -0700 (PDT) Subject: Passing parameters for a C program in Linux. References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <4c1476cc-075e-4b5b-b370-012124505902@b15g2000yqd.googlegroups.com> On Jun 30, 11:46?am, "venutaurus... at gmail.com" wrote: > Hi all, > ? ? ? ?I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1 ? ? ? ? ? ?-------Our option > Enter two numbers > 44 33 ?-------- Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. The easiest (and ugliest) way to do this would probably be to write a file input.txt and a file output.txt with each input/output value, and then to do this on the command prompt: ./a.out < input.txt | diff output.txt - this will run a.out (assuming that's your program's name), feed in input.txt as input, and pipe that into diff to compute the differences between its output and output.txt From Scott.Daniels at Acm.Org Tue Jun 30 11:00:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 08:00:44 -0700 Subject: identify checksum type? In-Reply-To: References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Message-ID: <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> Christian Heimes wrote: > PK schrieb: >> Given a checksum value, whats the best way to find out what type it is? >> >> meaning. I can use hashlib module and compute a md5 or sha1 for a given data >> etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats >> the best way for me to identify if its a sha1 or md5 or anyother sum type >> for that matter? >> >> is there a nice way to do this in python? > > As far as I know there is no way to identify a checksum by its value. A > checksum is just a number. You can try an educated guess based on the > length of the checksum. Or you can try all hash algorithms until you get > a hit but that may lead to security issues. > > Some applications prefix the hash value with an identifier like "{MD5}" > or "{SHA1}". > > Christian > fortunately, the hashlib checksums can be distinguished by their length On the newly minted 3.1: import hashlib text = b'BDFL forever; FLUFL for frequently' for name in 'md5 sha1 sha224 sha256 sha384 sha512'.split(): result = getattr(hashlib, name)(text).hexdigest() print('%6s:%3d %s' % (name, len(result), result)) md5: 32 457484d2817fbe475ab582bff2014e82 sha1: 40 242076dffbd432062b439335438f08ba53387897 sha224: 56 89c0439b1cf3ec7489364a4b8e50b3ba196706eecdb5e5aec6d6290f sha256: 64 e10938435e4b5b54c9276c05d5f5d7c4401997fbd7f27f4d4...807d sha384: 96 3fe7c7bf3e83d70dba7d59c3b79f619cf821a798040be2177...edb7 sha512:128 fe50d9f0c5780edb8a8a41e317a6936ec6305d856c78ccb8e...1fa0 You'll have to guess for adler32 vs. crc32 vs. seeded crc32, ... --Scott David Daniels Scott.Daniels at Acm.Org From sk8in_zombi at yahoo.com.au Tue Jun 30 11:02:30 2009 From: sk8in_zombi at yahoo.com.au (sk8in_zombi at yahoo.com.au) Date: Tue, 30 Jun 2009 08:02:30 -0700 (PDT) Subject: Learning to use decorators with classes Message-ID: <517138.79282.qm@web54507.mail.re2.yahoo.com> --- On Tue, 30/6/09, Bruno Desthuilliers wrote: > > Don't use '__name__', they are reserved for the > implementation. And FWIW, don't use '__name' unless you have > a really compelling reason to do so. > That was an honest mistake!. Noted :) > > >? ???def search(self, **kw): > >? ? ? ???print > 'Searching' > >? ? ? ???... > > > This can't work, and it's a FAQ FWIW - but since there's no > official c.l.py FAQ, we won't hold it against you !-) > Can you please point me to the FAQ related to this snippet. I would be grateful. > def and class are both *executable* statements (yes, > classes and functions creation - like almost anything in > Python - are run-time operations). > > The first one creates a function object - *wherever* it > happens - and bind the function object to the function's > name in the current namespace. Think of it as an equivalent > of the following javascript snippet: > > ???var func_name = function(arg) { /* > function's body */ }; > > The second statement - class - builds a class object from > the names defined in the class statement's body (that is, > names defined in the class statement's body will become > attributes of the class object). > > Now about the 'methods' and 'self' stuff... > > First understand that there's *nothing* magical with > 'self'. It's *not* a keyword. It's only a naming convention, > and you could use any legal Python identified instead. > > The reason we have to explicitly mention it as first > argument of the function is that it's the only way the > function's body can get access to the current instance. What > happens is (overly simplified) that during attribute > resolution, when the found attribute happens to be a > function,? this function is wrapped - together with the > instance on which the attribute was looked up and it's class > -? into a callable method object. Then when you call > this method object, it inserts the instance as first > argument to the function call, and returns the result of the > function call (if you want to read more about this and how > computed attributes are implemented in Python, google for > 'descriptor protocol'). > > IOW, and to make a long story short, calling > instance.method is the same as calling > Class.method(instance). > > Thank you very much for your explanation. I will remember these points by heart. > Ok, now to the point: when you call getConnection within > the class statement's body, there's no magical "self" > keyword poiting to an instance, and since the class itself > doesn't yet exists, so there's *no* way you could get at an > instance of it anyway !-) > > There are many ways to solve your problem, the simplest > bing probably to write another decorator calling on the > first one, ie: > > > def connected_method(func): > ? ? def connected(self, *args, **kw): > ? ? ? ? wrapped = > getConnection(self.__this, self.__that)(func) > ? ? ? ? return wrapped(*args, **kw) > > ? ? return connected > > > Note that this may not be that efficient - you'll have > quite a few function calls involved here. > I was trying follow the concept of decorators with arguments and I can now understand why it failed, thanks. Thanks and regards, SZ Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From esj at harvee.org Tue Jun 30 11:06:08 2009 From: esj at harvee.org (Eric S. Johansson) Date: Tue, 30 Jun 2009 11:06:08 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> <4A496FE5.9060005@harvee.org> Message-ID: <4A4A29E0.6050603@harvee.org> Rhodri James wrote: > [Trimming for length, sorry if that impacts too much on intelligibility] no problem, one of the hazards of speech recognition uses you become very verbose. > This goes a long way, but it doesn't eliminate the need for some forms > of escape coming up on a moderately frequent basis. Consider "Coffee > strength equals five" for example: this could mean either > > coffee_strength = 5 > > or > > COFFEE_STRENGTH = 5 > > depending on whether we will later be using it as a constant or not. > Python doesn't have syntactic constants, which is precisely why PEP-8 > is useful. You might have enough smarts in your system for it to > remember after the first time you use "coffee strength", and it might > be unambiguous, but at the very least you need to be able to say > "Constant coffee strength equals five" first time round. right. The initial state of a symbol is always a chatty moment. It sets the context and background information for subsequent use. My initial reaction is that when you do coffee strength equals five, it would pop up a simple dialog asking variable or constant? You would say "variable" and it would format everything the right way. This is a form of interactive dialogue that would be used consistently throughout the rest of the environment. > > This isn't the only occasion when you simply don't have the context > to avoid verbal disambiguation. Are you accessing attributes of the > class MyClass or its instance my_class, for instance? In your initial > post you seemed to be claiming that having to do this disambiguation > textually was bad, and PEP-8 should therefore be rejected. Given > that I'm not prepared to lose the productivity increase that comes > with being able to disambiguate visually at a glance, I don't see > that it's avoidable. I don't mind verbal disambiguation if it's infrequent. What I object to is being forced to disambiguate every time I use a symbol. The reason being is one is a minor increase in vocal load and can be made a dumb template (maybe) where is the other is just doing a bunch of makework over and over again. As for your my class example, you never ever use my_class unless it's prefaced by an instance of the class MyClass. And if you say something like My class yields fall class or fall class is my class or fall class = my class You have sufficient information to know that my class is a class name.and that you have some number of arguments and the system can run you through a dialogue to fill in the arguments. I wish I had the tools to create a simulation of what the editing sequence with the dialog box pop-ups in nice little animated movie. Heck, if I could just capture time lapse I could do it with paper and pencil and a voiceover. It would remind you of Gumby meets South Park but... I digress > > Incidentally, since what you're proposing is essentially templating, > wouldn't it be better to do it as post-processing on the speech > recognition rather than building it directly into an editor? > to resolve if my template in, you mean a system that can receive type information from somewhere about every single symbol in the system and then load up a grammar, handle the dialogs for disambiguation at the same time as providing an editing environment that lets you refer to symbols by their verbose name instead of their codename and still operate on. For example, replace an argument should pop up a dialog box with the second argument of the first method on the line. You then can change things by their names like second string or array index. Then sure, maybe a templating system would work. But I don't think it will thank you for continuing in this dialogue. From ronn.ross at gmail.com Tue Jun 30 11:11:15 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Tue, 30 Jun 2009 11:11:15 -0400 Subject: packaging apps Message-ID: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> I have a simple application that has a glade file and a .py file. How would I package that into an installer for Windows, Mac, and a deb file? Can anyone point me in the right direction? -------------- next part -------------- An HTML attachment was scrubbed... URL: From esj at harvee.org Tue Jun 30 11:27:33 2009 From: esj at harvee.org (Eric S. Johansson) Date: Tue, 30 Jun 2009 11:27:33 -0400 Subject: pep 8 constants In-Reply-To: <4A49E232.6090101@tim.thechases.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> Message-ID: <4A4A2EE5.8040301@harvee.org> Tim Chase wrote: > Eric S. Johansson wrote: > np. I get this confusion often. > > While I have used SR in some testing, I've found that while it's > passable for prose (and even that, proclamations of "95% accuracy" sound > good until you realize how many words comprise 5% of your daily typing > :), it's not so good for code unless you have a very specific > programming-language+SR designed editing environment...as you've been > griping. However, the problem seems not to be PEP-8, but rather the > inabilities of your SR combined with the failings of your editor. I've been working with speech recognition for 15 years. I've written something on the order of 10,000 lines of Python code both as open source and private projects. I've tried it least two dozen editors and they all fail miserably because they're focused on keyboard use (but understandable) I get good recognition accuracy because I train the system and then I let it train me. > > For coding, you might want to investigate a tool like Dasher[1] which > offers an alternate form of input. It allows for custom > vocabularies/keymaps if you need, as well as more precise specification > of a full keyboard (caps vs. mixed-case, specific punctuation > characters, etc). The predictive entry should be smart enough to pick > up previously entered constants/terms saving you entry speed. It can > also be driven by a wide variety of pointing devices (mouse, trackball, > touchpad, head-tracker, gyro-input, etc). I've tried it, it's quite promising but my hands term are sufficiently that I can't target accurately. This is a problem for me with mice as well. Maybe these tiny little spit dot icons and webpages drive me insane because it takes me two or three tries to put the right spot. but still, you would have the basic problem of getting the information about the code into language model of dasher so it could predict what might be chosen based on the previous context. It' 80% the same work and, doesn't help those of us with really bad hands. > > You might also experiment with other editors that allow for more > efficient editing. I've tried a whole bunch, like I said at least a dozen. They all fail for first reasons such as inability to access all functionality through keystrokes (easiest interface method from speech recognition) to virtually no autoformatting or worse yet, inconsistent autoformatting. The classic example is auto indentation based on previous lines. Emacs does a relatively right. I know this is also counter to the Python way but having something marking and outdent would be really useful so that a vocal driven command to indent or outdent a block would be practical. Oh, another failure point. Have you ever tried to selected beach and by voice. I mean I should say have you ever tried to select a region by voice. Doesn't work very well. Nuance has something called selective and say but it only works in very special Windows edit controls. Or, if you're doing toolkit supports the right signals/events. Nobody does in the the linux world and it doesn't look like they support them in the Windows world either. > > Hope these give you another option to consider, if SR plus your current > editor aren't cutting it for you, maybe we should have a conversation off list about different editors if you don't mind. I'm certainly open to alternatives but, I do have fairly high standards and one of them is that ^X^S doesn't crash the editor. :-) I have been using Emacs for too many years and it is such a reflex. Another alternative would be to help fix the NaturallySpeaking Emacs gateway vr-mode. While it doesn't truly improve the problem, it makes it a little more manageable. thank you for your time From lists at cheimes.de Tue Jun 30 11:34:22 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 30 Jun 2009 17:34:22 +0200 Subject: identify checksum type? In-Reply-To: <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> Message-ID: Scott David Daniels wrote: > fortunately, the hashlib checksums can be distinguished by their length Unfortunately the world knows more hash algorithms than the Python standard library. :) Christian From milesck at umich.edu Tue Jun 30 11:44:50 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 30 Jun 2009 11:44:50 -0400 Subject: Passing parameters for a C program in Linux. In-Reply-To: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: On Jun 30, 2009, at 6:46 AM, venutaurus539 at gmail.com wrote: > I have to write an automted script which will test my c > program. That program when run will ask for the commands. Keep in mind that, if your test script checks the program's output before giving it input, you can run into problems with buffering. The standard C library uses line-based buffering when a program is using a terminal for output, but when it's outputting to a pipe it uses block buffering. This can be a problem when running a process using subprocess--your program will buffer the prompt, and your test script won't see it, so the test will deadlock. The problem can also exist in the opposite direction. Possible solutions: - Explicitly set both your test script and your program to have line- buffered output. - Add a flush statement whenever you finish writing output and expect input. - Use pexpect, which uses a pseudo-tty and will make C stdio default to line buffering. - Use pdpi's solution, which, since it doesn't wait for a prompt before supplying input, doesn't have this issue. From lenz at joinville.udesc.br Tue Jun 30 11:51:37 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 30 Jun 2009 08:51:37 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <200906300851.37718.lenz@joinville.udesc.br> Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: > In message > d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: > > ... is there open source solution ? > > Poppler? pypdf -- http://pybrary.net/pyPdf/ A Pure-Python library built as a PDF toolkit. It is capable of: * extracting document information (title, author, ...), * splitting documents page by page, * merging documents page by page, * cropping pages, * merging multiple pages into a single page, * encrypting and decrypting PDF files. By being Pure-Python, it should run on any Python platform without any dependencies on external libraries. It can also work entirely on StringIO objects rather than file streams, allowing for PDF manipulation in memory. It is therefore a useful tool for websites that manage or manipulate PDFs. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From rhvonlehe at gmail.com Tue Jun 30 12:01:31 2009 From: rhvonlehe at gmail.com (rhvonlehe at gmail.com) Date: Tue, 30 Jun 2009 09:01:31 -0700 (PDT) Subject: using input(), raw_input() to allow user to run different functions References: Message-ID: <2916135b-530b-4493-9dcd-01242e7a1cbd@a36g2000yqc.googlegroups.com> On Jun 29, 5:22?pm, MRAB wrote: > rhvonl... at gmail.com wrote: > > Something's been giving me difficulty.. > > > We have a USB-attached device that we frequently debug with simple > > python scripts. ?The model has always been that each script logs on to > > the device, does something, then logs off. ?As it turns out, we have > > mostly written scripts as unit tests for each API command. ?So, we'll > > call one script that will configure a process on the device, and a > > separate script that will retrieve the results of that process. > > > The model is changing inside the device such that all settings will be > > lost when we log off. ?This means we'll have to merge a bunch of > > scripts in various ways. > > > I thought it would be neat if I could have one master python script do > > the logon, then allow the user to input the name of a previously- > > written script he wanted to execute while logged on. ?Finally, when > > exiting the master script, the user would logout from the device. > > > I'm trying to test this by using input() or raw_input() to get the > > function the user wants to execute. ?I'm not having much luck. ?Here's > > an example: > > > Shell.py: > > #! /usr/bin/env python > > from CollectNDResults import * > > ... > > request = input('Script shell >>> ') > > print request > > exec (request) ? ## I realize the parentheses are not needed > > ... > > > When I run Shell.py I get this: > > > Script shell >>> CollectNDResults > > > > Traceback (most recent call last): > > ? File "./Shell.py", line 35, in ? > > ? ? Shell(sys.argv[1:]) > > ? File "./Shell.py", line 24, in Shell > > ? ? exec (request) > > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > > name into the code object that I want to execute? ?Is there a better > > way to do what I'm trying to do? > > ?>>> def foo(): > ? ? ? ? print "running foo" > > ?>>> import sys > ?>>> func_name = "foo" > ?>>> getattr(sys.modules[__name__], func_name)() > running foo Excellent replies, both. I'll get a lot of mileage out of this, thanks! From javier.collado at gmail.com Tue Jun 30 12:02:53 2009 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 30 Jun 2009 18:02:53 +0200 Subject: packaging apps In-Reply-To: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> References: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> Message-ID: Hello, Regarding packaging for debian (.deb), the best reference I've found is: https://wiki.ubuntu.com/PackagingGuide/Python However, all that mess probably won't be needed anymore once this is finished: https://blueprints.edge.launchpad.net/ubuntu/+spec/desktop-karmic-automagic-python-build-system Best regards, Javier 2009/6/30 Ronn Ross : > I have a simple application that has a glade file and a .py file. How would > I package that into an installer for Windows, Mac, and a deb file? Can > anyone point me in the right direction? > > -- > http://mail.python.org/mailman/listinfo/python-list > > From jerome.fuselier at gmail.com Tue Jun 30 12:05:42 2009 From: jerome.fuselier at gmail.com (=?ISO-8859-1?Q?J=E9r=F4me_Fuselier?=) Date: Tue, 30 Jun 2009 09:05:42 -0700 (PDT) Subject: Problem with uuid package when embedding a python interpreter Message-ID: <7d5cfbf0-38d5-4505-a93a-f321d0da74b8@c36g2000yqn.googlegroups.com> Hello, I've tried to import a script in an embedded python intrepreter but this script fails when it imports the uuid module. I have a segmentation fault in Py_Finalize(). Here is a simple program which imitate my problem. main.c : #include "Python.h" void test() { Py_Initialize(); PyImport_Import(PyString_FromString("uuid")); Py_Finalize(); } main(int argc, char **argv) { for (i=0 ; i < 10; i++) test(); } For my application, I have to call Py_initialize and Py_Finalize several times so factorizing them in the main function is not an easy solution for me. The core which is produced gives me this error : Program terminated with signal 11, Segmentation fault. #0 0x00190ef6 in type_dealloc (type=0x291320) at Objects/typeobject.c: 2609 2609 _PyObject_GC_UNTRACK(type); Thanks for your help Jerome From dickinsm at gmail.com Tue Jun 30 12:08:03 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 30 Jun 2009 09:08:03 -0700 (PDT) Subject: python3 fail to start References: <788ec223-9894-4168-b1f8-758cd51a47ad@r16g2000vbn.googlegroups.com> Message-ID: <577baa71-930a-4cdc-9c78-cb5df318632c@l31g2000yqb.googlegroups.com> On Jun 30, 3:43?pm, ts wrote: > i just install the python 3.1 dmg onto my mac. when i run python3, it > fail with : > > Fatal Python error: Py_Initialize: can't initialize sys standard > streams > LookupError: unknown encoding: > Abort trap > > couldnt understand the problem. anyone can help? Hmm. It's working fine for me (OS X 10.5.7/Macbook Pro). What version of OS X are you using? How are you running python3---by typing 'python3' at a Terminal prompt, I assume? What's the output of the 'locale' command on your system? Mark From lenz at joinville.udesc.br Tue Jun 30 12:37:34 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 30 Jun 2009 09:37:34 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <200906300937.34534.lenz@joinville.udesc.br> Em Ter 30 Jun 2009, ?s 04:19:13, Grant Edwards escreveu: > On 2009-06-30, Eduardo Lenz wrote: > > Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: > >> In message >> > >> d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: > >> > ... is there open source solution ? > >> > >> Poppler? > > > > pypdf -- http://pybrary.net/pyPdf/ > > > > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > > > * extracting document information (title, author, ...), > > * splitting documents page by page, > > * merging documents page by page, > > * cropping pages, > > * merging multiple pages into a single page, > > * encrypting and decrypting PDF files. > > While it may be a pure-python library, the problem is that > AFAICT it doesn't actually solve the problem at hand. The > requirement is to "draw" on the pages of an existing PDF > document (add annotations). > > > By being Pure-Python, it should run on any Python platform > > without any dependencies on external libraries. It can also > > work entirely on StringIO objects rather than file streams, > > allowing for PDF manipulation in memory. It is therefore a > > useful tool for websites that manage or manipulate PDFs. > > True, but does it allow you to add text/lines/etc. to a page? being a pure python library makes "easy" to add those features. And also, one can ask for those features for the developers. I think that this list is a good place to point the existing solutions (not always the exact solution) and also to collect valuable information about python libraries. Please, lets keep in mind that this is not the debian list :). []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From python.list at tim.thechases.com Tue Jun 30 12:39:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 11:39:29 -0500 Subject: pep 8 constants In-Reply-To: <4A4A2EE5.8040301@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> <4A4A2EE5.8040301@harvee.org> Message-ID: <4A4A3FC1.5000108@tim.thechases.com> > I've tried it least two dozen editors and they all fail > miserably because they're focused on keyboard use (but > understandable) [...snip...] > I've tried a whole bunch, like I said at least a dozen. They > all fail for first reasons such as inability to access all > functionality through keystrokes (easiest interface method > from speech recognition) I'm not sure I follow which you want...you kvetch that they're too focused on keyboard use, but then that you can't access all functionality through the keyboard. [warning, blatant vim fanaticism follows] I use vim and can't remember the last time I used the mouse with it (save for occasionally lazily scrolling with the mouse-wheel, but you can scroll with the keyboard too), so it meets your "must be fully accessible through the keyboard" constraint. It also has single keystroke commands for indenting/exdenting the current line as you mention: > I know this is also counter to the Python way but having > something marking and outdent would be really useful so > that a vocal driven command to indent or outdent a block > would be practical. which can be done in insert-mode with control+D, control+T, and if you want to clear all indentation (all the way back to the first column), you can use "0" followed by control+D. Vim also allows for fairly detailed control over auto-indentation settings so you can match them to your preferences. I suspect Emacs may be configurable to offer similar functionality but I'd have to defer to the emacsen on the list. That said, I'll be the first to admit that the vi/vim learning curve is more like a brick wall than a curve. However, I find the efficiency gains abundantly than repaid the time I invested to learn it well. >> Dasher[1] > > I've tried it, it's quite promising but my hands term are > sufficiently that I can't target accurately. Last I tried it, it scaled the target sizes based on probability. You might also try unconventional pointing devices for better precision. I've seen web-cam eye-tracking tools which might make it a bit easier. Or try a tablet input (where the motion corresponds linearly, as opposed to accelerated mouse motion). Such input options are listed on the Dasher website, at least for those they tested. > Oh, another failure point. Have you ever tried to selected > beach and by voice. I mean I should say have you ever tried to > select a region by voice. yes, not a pleasant experience. Again, vim's modal interface allows for using text-objects so you can issue short-hand commands like ci" to "[c]hange the contents [i]nside the double-quotes I'm currently on/withing". The operator+motion and operator+textobject command syntax obviates a lot selection. While vim does offer a "visual" mode (akin to selection in other editors), I use it much less because of the power provided by the operator+[motion/textobject]. > maybe we should have a conversation off list about different > editors if you don't mind. I'm certainly open to alternatives > but, I do have fairly high standards and one of them is that > ^X^S doesn't crash the editor. :-) I have been using Emacs for > too many years and it is such a reflex. as you're an emacs user, my vim suggestions may sound like heresy. ;-) But I suspect a skilled emacs user (or perhaps asking on an emacs-users list) could mimic much of the vim functionality. I just can't be of much assistance there. You're welcome to move it off-list...it's kinda drifted from python to general accessibility issues. CC'ing c.p.l for this one in case any emacsen care to chime in on their suggested tweaks. -tkc From skip at pobox.com Tue Jun 30 12:48:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 30 Jun 2009 11:48:29 -0500 Subject: Timeout when connecting to sybase DBS In-Reply-To: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> References: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> Message-ID: <19018.16861.439118.984635@montanaro.dyndns.org> Gil> I have looked for a timeout parameter to limit the 4 minutes to Gil> something more reasonable but couldn't find one. Can anyone please Gil> help? Gil> BTW, I'm using Sybase.connect(, , , Gil> datetime='auto') We use the Sybase module where I work, but I've never encountered this problem (or a timeout parameter of any kind). At any rate, you'll probably have more luck asking on the python-sybase mailing list: python-sybase-misc at lists.sourceforge.net -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From fetchinson at googlemail.com Tue Jun 30 12:56:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 30 Jun 2009 09:56:19 -0700 Subject: ANN: Package Manager GUI for Python (Windows) In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: > Hi All, > > I'm pleased to announce a GUI package manager (v 0.12) for > Python versions 2.x under Windows. > > http://sourceforge.net/projects/pythonpkgmgr/ > > It's tightly linked to the pypi repository and offers > the following functions: > > - search packages on pypi by name > > - install (via easyinstall or pip) > > - deinstall/remove packages > > - see package documentation > > - see package examples > > - install .EGG packages > > - Generate package manifest > > If you find any issues, please don't hesitate to report > them via our tracker on the project page. Another time machine! The Release Notes for version 0.11 on http://www.preisshare.net/pythonpkgmgr/ says it was released on 10/09/09 :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jenn.duerr at gmail.com Tue Jun 30 13:27:57 2009 From: jenn.duerr at gmail.com (noydb) Date: Tue, 30 Jun 2009 10:27:57 -0700 (PDT) Subject: string character count Message-ID: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> If I have a string for a file name such that I want to find the number of characters to the left of the dot, how can that be done? I did it this way: x = "text12345.txt" dot = x.find('.') print dot Was curious to see what method others would use - helps me learn. I guess I was most curious to see if it could be done in one line. And, how would a char count be done with no dot -- like if the string were "textstringwithoutdot" or "no dot in text string"? From jayshree06comp at gmail.com Tue Jun 30 13:43:23 2009 From: jayshree06comp at gmail.com (jayshree) Date: Tue, 30 Jun 2009 10:43:23 -0700 (PDT) Subject: python+encryption Message-ID: I have the key pair generated by the GPG. Now I want to use the public key for encrypting the password. I need to make a function in Python. Can somebody guide me on how to do this ? to encrypt password by the public key ..how can i do this ,which library is best and easy to prefer.i have to work on ssh secure shell client. thanks From bieffe62 at gmail.com Tue Jun 30 13:44:35 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 30 Jun 2009 10:44:35 -0700 (PDT) Subject: Unexpected behaviour of inner functions/ decorators Message-ID: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Hi all, I found a strange (for me) behaviour of inner function. If I execute the following code: # file in_f.py ----------- def dec_f(f): def inner_f(): if f.enabled: f() return inner_f @dec_f def funct(): print "Ciao" funct.enabled = True funct() # end of file ----------------- I get the following exception: File "/Users/fb/Documents/Prove python/in_f.py", line 15, in funct() File "/Users/fb/Documents/Prove python/in_f.py", line 5, in inner_f if f.enabled: AttributeError: 'function' object has no attribute 'enabled' The same happens when I rebind explicitely the function name instead of using the decorator: def funct(): print "Ciao" funct = dec_f(funct) It looks like the decorator uses an older instance of 'funct', which does not yet have the attribute dinamically attached to it. This seem to be confirmed by the fact that adding the attribute before rebinding the function name, the problem disappear: def funct(): print "Ciao" funct.enabled = False # this fixes the problem funct = dec_f(funct) So I have a workaround, but still don't understant why the original code does not work. Anyone can point me to an explanation? Thanks in advance Ciao ------- FB From python at mrabarnett.plus.com Tue Jun 30 13:56:39 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Jun 2009 18:56:39 +0100 Subject: string character count In-Reply-To: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> Message-ID: <4A4A51D7.6040602@mrabarnett.plus.com> noydb wrote: > If I have a string for a file name such that I want to find the number > of characters to the left of the dot, how can that be done? > > I did it this way: > x = "text12345.txt" > dot = x.find('.') > print dot > > Was curious to see what method others would use - helps me learn. I > guess I was most curious to see if it could be done in one line. > >>> print "text12345.txt".find('.') 9 > And, how would a char count be done with no dot -- like if the string > were "textstringwithoutdot" or "no dot in text string"? If there's no dot then find() returns -1. If you wanted to know the number of characters before the dot, if present, or in total otherwise, then you could use split(): >>> len("text12345.txt".split(".", 1)[0]) 9 >>> len("textstringwithoutdot".split(".", 1)[0]) 20 From gagsl-py2 at yahoo.com.ar Tue Jun 30 14:02:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 15:02:13 -0300 Subject: Problem with uuid package when embedding a python interpreter References: <7d5cfbf0-38d5-4505-a93a-f321d0da74b8@c36g2000yqn.googlegroups.com> Message-ID: En Tue, 30 Jun 2009 13:05:42 -0300, J?r?me Fuselier escribi?: > I've tried to import a script in an embedded python intrepreter but > this script fails when it imports the uuid module. I have a > segmentation fault in Py_Finalize(). > > #include "Python.h" > > void test() { > Py_Initialize(); > PyImport_Import(PyString_FromString("uuid")); > Py_Finalize(); > } > > main(int argc, char **argv) > { > for (i=0 ; i < 10; i++) > test(); > } > > For my application, I have to call Py_initialize and Py_Finalize > several times so factorizing them in the main function is not an easy > solution for me. Are you sure you can't do that? Not even using Py_IsInitialized? Try to avoid repeatedly calling Py_Initialize - won't work. Python 2.x does not have a way to "un-initialize" an extension module (that's a big flaw in Python design). Modules that contain global state are likely to crash the interpreter when used by the second time. (Python 3 attempts to fix that) -- Gabriel Genellina From kaffeen at gmail.com Tue Jun 30 14:02:21 2009 From: kaffeen at gmail.com (kaffeen) Date: Tue, 30 Jun 2009 13:02:21 -0500 Subject: Noob Message-ID: Hello all, just joined this list and am just beginning to learn Python. Thanks to everyone for making this a great place to learn and their contributions. As mentioned, I'm new to Python (but have experience with other programming languages/scripting). I have a couple of questions... 1) Where might I find a comprehensive list of changes between Python 2.x and 3.x? 2) What are the differences between IPython and IDLE, is one better than the other, why? 3) Is there an IDE for Python development, which is the best? 4) I can't seem to install IPython for my 3.x branch (and I did install readline), I get the following error via Windows executable installation, *** run_installscript: internal error 0xFFFFFFFF ***.........it installs fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If not compatible, is there a timeline for compatibility? Regards, ~kaffeen -- If you understand, things are just as they are. If you do not understand, things are just as they are. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dstanek at dstanek.com Tue Jun 30 14:12:40 2009 From: dstanek at dstanek.com (David Stanek) Date: Tue, 30 Jun 2009 14:12:40 -0400 Subject: Unexpected behaviour of inner functions/ decorators In-Reply-To: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> References: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Message-ID: On Tue, Jun 30, 2009 at 1:44 PM, Francesco Bochicchio wrote: > [snip] > It looks like the decorator uses an older ?instance of 'funct', which > does not yet > have the attribute dinamically attached to it. This seem to be > confirmed by the fact that adding the attribute before > rebinding the function name, the problem disappear: The decorator is using the original function that you defined. By decorating 'funct' you are actually rebinding that name to the 'inner_f' function. So the statement 'funct.enabled = True' is actually creating an enabled property on the 'inner_f' function. Take a look at this code: >>> def def_f(f): ... def inner_f(): ... if iam.enabled: ... f() ... iam = inner_f ... return inner_f ... >>> @def_f ... def funct(): ... print 'Ciao' ... >>> funct.enabled = True >>> funct() Ciao -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From cripplemeal at gmail.com Tue Jun 30 14:15:24 2009 From: cripplemeal at gmail.com (Crip) Date: Tue, 30 Jun 2009 11:15:24 -0700 (PDT) Subject: Python/Pygame question Message-ID: I have been experimenting with pygame. I would like to know how to go about placing an image of my creation as the background of the generated window. To where should I save the image, and what should it be saved as? From Scott.Daniels at Acm.Org Tue Jun 30 14:27:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 11:27:09 -0700 Subject: Unexpected behaviour of inner functions/ decorators In-Reply-To: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> References: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Message-ID: Francesco Bochicchio wrote: > def dec_f(f): > def inner_f(): > if f.enabled: > f() > return inner_f > @dec_f > def funct(): > print "Ciao" The three lines above should behave a lot like: def funct_original(): print "Ciao" funct = dec_f(funct_original) > funct.enabled = True > funct() This is decorating "funct", but inner_f is testing the argument it was passed (funct_original), not inner_f (which is now called funct). No wonder it finds no "enabled" attribute. > So I have a workaround, but still don't understant why the original > code does not work. > Anyone can point me to an explanation? So, you can fix this like so: def dec_f(f): def inner_f(): if inner_f.enabled: f() return inner_f Or even: def dec_f(f): def inner_f(): if inner_f.enabled: f() inner_f.enabled = False return inner_f Thus testing the thing that you were marking with funct.enabled = True. Does this help explain? --Scott David Daniels Scott.Daniels at Acm.Org From benjamin at python.org Tue Jun 30 14:32:14 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 30 Jun 2009 18:32:14 +0000 (UTC) Subject: python+encryption References: Message-ID: jayshree gmail.com> writes: > > I have the key pair generated by the GPG. Now I want to use the public > key for encrypting the password. I need to make a function in Python. > Can somebody guide me on how to do this ? PyCrypto From gagsl-py2 at yahoo.com.ar Tue Jun 30 14:39:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 15:39:29 -0300 Subject: Noob References: Message-ID: En Tue, 30 Jun 2009 15:02:21 -0300, kaffeen escribi?: > Hello all, just joined this list and am just beginning to learn Python. > Thanks to everyone for making this a great place to learn and their > contributions. Welcome! > As mentioned, I'm new to Python (but have experience with other > programming > languages/scripting). I have a couple of questions... > > 1) Where might I find a comprehensive list of changes between Python 2.x > and > 3.x? You may read the "What's new?" documents for 3.0 and 3.1: http://docs.python.org/3.1/whatsnew/index.html If you're learning Python the differences aren't so important now (the most obvious being that the print statement becomes a function). If you're using a book covering Python 2.x, install the latest on that series (2.6.2). Support for Python 3 is increasing but many 3rd party libraries have not been ported yet. > 3) Is there an IDE for Python development, which is the best? Look in the wiki: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments or search past messages in this list. The topic arises every two months or so. There is no definitive answer. > 4) I can't seem to install IPython for my 3.x branch (and I did install > readline), I get the following error via Windows executable installation, > *** run_installscript: internal error 0xFFFFFFFF ***.........it installs > fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If > not > compatible, is there a timeline for compatibility? Ask the IPython team; but unless a project explicitely states that it's compatible with Python 3, you should assume it isn't. -- Gabriel Genellina From SridharR at activestate.com Tue Jun 30 15:20:46 2009 From: SridharR at activestate.com (Sridhar Ratnakumar) Date: Tue, 30 Jun 2009 12:20:46 -0700 Subject: ANN: ActivePython 3.1.0.1 is now available Message-ID: I'm happy to announce that ActivePython 3.1.0.1 is now available for download from: http://www.activestate.com/activepython/python3/ This is a major release that updates ActivePython3 to core Python 3.1. What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. 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. See this page for full details: http://docs.activestate.com/activepython/3.1/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/3.1/ 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") Extra Bits ---------- ActivePython releases also include the following: - ActivePython31.chm: An MS compiled help collection of the full ActivePython documentation set. Linux users of applications such as xCHM might find this useful. This package is installed by default on Windows. Extra bits are available from: http://downloads.activestate.com/ActivePython/etc/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From tjreedy at udel.edu Tue Jun 30 15:32:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Jun 2009 15:32:57 -0400 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: <4A4971DD.9080707@ilm.com> References: <4A4963E9.30202@ilm.com> <4A4971DD.9080707@ilm.com> Message-ID: I do not like top posting. Some thoughts in randon order: Introspection is version-specific. Call-time introspection is different from definition-time introspection. Do what is easy and works. Do not use recipes that depend on version-specific stuff you do not understand. Code objects, I believe, know the names of parameters. That question and responses were only about methods, not non-class functions. You get to match these responses to your post ;-). Terry David Hirschfield wrote: > Yeah, it definitely seems like having two separate decorators is the > solution. But the strange thing is that I found this snippet after some > deep googling, that seems to do something *like* what I want, though I > don't understand the descriptor stuff nearly well enough to get what's > happening: > > http://stackoverflow.com/questions/306130/python-decorator-makes-function-forget-that-it-belongs-to-a-class > > > answer number 3, by ianb. It seems to indicate there's a way to > introspect and determine the class that the function is going to be > bound to...but I don't get it, and I'm not sure it's applicable to my case. > > I'd love an explanation of what is going on in that setup, and if it > isn't usable for my situation, why not? > Thanks again, > -David > > Terry Reedy wrote: >> David Hirschfield wrote: >>> I'm having a little problem with some python metaprogramming. I want >>> to have a decorator which I can use either with functions or methods >>> of classes, which will allow me to swap one function or method for >>> another. It works as I want it to, except that I want to be able to >>> do some things a little differently depending on whether I'm swapping >>> two functions, or two methods of a class. >> >> Unbounds methods are simply functions which have become attributes of >> a class. Especially in Py3, there is *no* difference. >> >> Bound methods are a special type of partial function. In Python, both >> are something else, though still callables. Conceptually, a partial >> function *is* a function, just with fewer parameters. >> >>> Trouble is, it appears that when the decorator is called the function >>> is not yet bound to an instance, so no matter whether it's a method >>> or function, it looks the same to the decorator. >> >> Right. Whether it is an A or an A, it looks like an A. >> >> Worse: when the decorator is called, there is no class for there to be >> instances of. >>> >>> This simple example illustrates the problem: >> >> Add a second parameter to tell the decorator which variant of behavior >> you want. Or write two variations of the decorator and use the one you >> want. >> >> tjr >> > From ziade.tarek at gmail.com Tue Jun 30 15:41:48 2009 From: ziade.tarek at gmail.com (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Tue, 30 Jun 2009 21:41:48 +0200 Subject: PEP 376 Message-ID: <94bdd2610906301241i6607ea27l19b7c7625dc328@mail.gmail.com> Hello, I would like to propose this PEP for inclusion into Python 2.7 / 3.2 http://www.python.org/dev/peps/pep-0376/ It has been discussed a lot already in the distutils-SIG, but new feedbacks are welcome there's an implementation prototype here : http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py Regards Tarek -- Tarek Ziad? | http://ziade.org From beni.cherniavsky at gmail.com Tue Jun 30 16:24:15 2009 From: beni.cherniavsky at gmail.com (Beni Cherniavsky) Date: Tue, 30 Jun 2009 13:24:15 -0700 (PDT) Subject: It's ... References: Message-ID: On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote: > Also note that you can iterate over a file several times: > > f = open('foo.txt') > for line in f: > print line[0] # prints the first character of every line > for line in f: > print line[1] #prints the second character of every line > No, you can't. The second loop prints nothing! A file by default advances forward. Once you reach the end, you stay there. You could explicitly call f.seek(0, 0) to rewind it. Note that not all file objects are seekable (e.g. pipes and sockets aren't). The cleaner way to read a regular file twice is to *open* it time: for line in open('foo.txt'): print line[0] # prints the first character of every line for line in open('foo.txt'): print line[1] # prints the second character of every line Quick recap for Angus: for loops work on "iterables" - objects that can be asked for an "iterator". Python iterators are unseekable - once exhausted they stay empty. Most iterables (e.g. lists) return a new iterator every time you ask, so you can iterate over the same data many times. But if you already have an iterator, you can use it in a for loop - when asked for an iterator, it will offer itself (in other words an iterator is a degenerate kind of iterable). This is what happened with the file object - it's an iterator and can't be reused. Reusing the same iterator between for loops is sometimes useful if you exit the first loop mid-way: f = open('foo.mail') # skip headers until you see an empty line for line in f: if not line.strip(): break # print remainer or file for line in f: sys.stdout.write(line) P.S. Warning: after you use ``for line in f``, it's dangerous to use ``f.read()`` and ``f.readline()`` (buffering mess - just don't.) > Glad you're enjoying Beazley. ?I would look for something more > up-to-date. ?Python's come a long way since 2.1. ?I'd hate for you to > miss out on all the iterators, booleans, codecs, subprocess, yield, > unified int/longs, decorators, decimals, sets, context managers and > new-style classes that have come since then. > Seconded - 2.1 is ancient. If you continue with the book, here is a quick list of the most fundamental improvements to keep in mind: 1. Iterators, generators, generator expressions. 2. Working nested scopes. 3. Decorators. 4. with statement. 5. set & bool types. 6. Descriptors (if confusing, just understand properties). 7. from __future__ import division, // operator. and the most refreshing modules added: - subprocess - ctypes - itertools - ElementTree - optparse and not new but I just love introducing it people: - doctest From pruebauno at latinmail.com Tue Jun 30 16:43:03 2009 From: pruebauno at latinmail.com (nn) Date: Tue, 30 Jun 2009 13:43:03 -0700 (PDT) Subject: string character count References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> Message-ID: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> On Jun 30, 1:56?pm, MRAB wrote: > noydb wrote: > > If I have a string for a file name such that I want to find the number > > of characters to the left of the dot, how can that be done? > > > I did it this way: > > x = "text12345.txt" > > dot = x.find('.') > > print dot > > > Was curious to see what method others would use - helps me learn. ?I > > guess I was most curious to see if it could be done in one line. > > ?>>> print "text12345.txt".find('.') > 9 > > > And, how would a char count be done with no dot -- like if the string > > were "textstringwithoutdot" or "no dot in text string"? > > If there's no dot then find() returns -1. > > If you wanted to know the number of characters before the dot, if > present, or in total otherwise, then you could use split(): > > ?>>> len("text12345.txt".split(".", 1)[0]) > 9 > ?>>> len("textstringwithoutdot".split(".", 1)[0]) > 20 Also: len("text12345.txt".partition('.')[0]) 9 From MLMLists at Comcast.net Tue Jun 30 16:49:34 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 16:49:34 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: In Python 3, how should super() be used to invoke a method defined in C that overrides its two superclasses A and B, in particular __init__? class A: def __init__(self): print('A') class B: def __init__(self): print('B') class C(A, B): def __init__(self): super().__init__() print('C') C() Output is: A C I've discovered the surprising fact described in the documentation of super that specifying a class as the first argument of super means to skip that class when scanning the mro so that if C.__init__ includes the line super(A, self).__init__() what gets called is B.__init__, so that if I want to call __init__ of both classes the definition of C should have both of the following lines: super().__init__() super(A, self).__init__() and that super(B, self).__init__() does nothing because B is the last class in the mro. This seems weird. Would someone please give a clear example and explanation of the recommended way of initializing both superclasses in a simple multiple inheritance situation? Note: I am EXTREMELY knowledgeable about OO, Python, and many OOLs. I don't mean to be arrogant, I just want to focus the discussion not open it to a broad interchange about multiple inheritance, the ways it can be used or avoided, etc. I just want to know how to use super. The documentation states the following: "There are two typical use cases for super. In a class hierarchy with single inheritance, super can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable." "The second use case is to support cooperative multiple inheritance in a dynamic execution environment. This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance. This makes it possible to implement "diamond diagrams" where multiple base classes implement the same method." "For both use cases, a typical superclass call looks like this: class C(B): def method(self, arg): super().method(arg) # This does the same thing as: # super(C, self).method(arg) " Though it claims to be demonstrating both cases, it is only demonstrating single inheritance and a particular kind of multiple inheritance where the method is found in only one class in the mro. This avoids situations where you want to call the method anywhere it is found in the mro, or at least in the direct superclasses. Perhaps __init__ is a special case, but I don't see how to figure out how to __init__ two superclasses of a class from the documentation. I often file "bug reports" about documentation ambiguities, vagueness, incompletenesses, etc., but I don't want to do so for this case until I've heard something definitive about how it should be handled. Thanks in advance. From shaibani at ymail.com Tue Jun 30 18:20:59 2009 From: shaibani at ymail.com (Ala) Date: Tue, 30 Jun 2009 23:20:59 +0100 Subject: Ubigraph vs Matplotlib (dynamic plotting, event handling) Message-ID: <300620092320590209%shaibani@ymail.com> Hello everyone, I intend to use python for some network graph plotting, with event handling (clicking on network nodes, zooming in/out etc..) and so far I have come across two good candidates which are Matplotlib and Ubigraph. Did anyone have any experience with either of them for dynamic plotting (a slider bar on a Qt interface causing the graph to be replotted for each value for example), as well as event handling? (it seems on first notice that Ubigraph will have an upperhand on that), as well as event handling such as mouse clicks? (on this one Matplotlib has good documentation showing it does achieve that while I find ubigraph's documentation lacking, but I'd preffere to have the opinion of those who have used them before). Thank you. From cs at zip.com.au Tue Jun 30 18:39:41 2009 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 1 Jul 2009 08:39:41 +1000 Subject: handling https sites In-Reply-To: Message-ID: <20090630223941.GA8395@cskk.homeip.net> On 26Jun2009 09:34, cgoldberg wrote: | > Is there any module in python to open https | > sites through a proxy. | | yes, you can use "urllib2". | | from the urllib2 docs: | "The default is to read the list of proxies from the environment | variables" | | So if you have a proxy setup, it should detect it from your | environment vars. If you want to specify something different, you | want to build an opener with a ProxyHandler: | | http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler Except that HTTPS through a proxy doesn't work: http://bugs.python.org/issue1424152 There's a patch under review. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From pavlovevidence at gmail.com Tue Jun 30 18:52:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 15:52:04 -0700 (PDT) Subject: PEP 376 References: Message-ID: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> On Jun 30, 12:41?pm, Tarek Ziad? wrote: > Hello, > > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > http://www.python.org/dev/peps/pep-0376/ > > It has been discussed a lot already in the distutils-SIG, but new > feedbacks are welcome > > there's an implementation prototype here :http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py +1 This seems to be a well-designed solution that corrects the ad-hoc- ness of installation while keeping its effects on existing tools small. I hate those egg-info files but I would be very happy if they'd at least always be in an accounted-for place. Maybe I'd even consider making use of them some day. As for setuptools, I'm sure it will accommodate the change and probably improve itself in the process. (And if the setuptools doesn't change then some other tool will grow into its niche; either way it'd be an improvement.) Carl Banks From emile at fenx.com Tue Jun 30 18:58:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Jun 2009 15:58:17 -0700 Subject: string character count In-Reply-To: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> Message-ID: <4A4A9889.30606@fenx.com> On 6/30/2009 1:43 PM nn said... > On Jun 30, 1:56 pm, MRAB wrote: >> >>> len("text12345.txt".split(".", 1)[0]) >> 9 >> >>> len("textstringwithoutdot".split(".", 1)[0]) >> 20 > > Also: > > >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> unless you've got file names like text.12345.txt, where you might prefer rpartition. >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> Emile From emile at fenx.com Tue Jun 30 18:58:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Jun 2009 15:58:17 -0700 Subject: string character count In-Reply-To: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> Message-ID: <4A4A9889.30606@fenx.com> On 6/30/2009 1:43 PM nn said... > On Jun 30, 1:56 pm, MRAB wrote: >> >>> len("text12345.txt".split(".", 1)[0]) >> 9 >> >>> len("textstringwithoutdot".split(".", 1)[0]) >> 20 > > Also: > > >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> unless you've got file names like text.12345.txt, where you might prefer rpartition. >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> Emile From python at mrabarnett.plus.com Tue Jun 30 19:06:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Jul 2009 00:06:48 +0100 Subject: pep 8 constants In-Reply-To: <4A4A2EE5.8040301@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> <4A4A2EE5.8040301@harvee.org> Message-ID: <4A4A9A88.2040302@mrabarnett.plus.com> Eric S. Johansson wrote: > > I've been working with speech recognition for 15 years. I've written something > on the order of 10,000 lines of Python code both as open source and private > projects. I've tried it least two dozen editors and they all fail miserably > because they're focused on keyboard use (but understandable) I get good > recognition accuracy because I train the system and then I let it train me. > A bit OT, but relevant(ish): Microsoft Vista Speech Recognition Tested - Perl Scripting http://www.youtube.com/watch?v=KyLqUf4cdwc From Scott.Daniels at Acm.Org Tue Jun 30 19:49:18 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 16:49:18 -0700 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Mitchell L Model wrote: > In Python 3, how should super() be used to invoke a method defined in C > that overrides its two superclasses A and B, in particular __init__? > ... > I've discovered the surprising fact described in the documentation of super > > that specifying a class as the first argument of super means to skip that class when > scanning the mro so that .... > > This seems weird. Would someone please give a clear example and explanation of > the recommended way of initializing both superclasses in a simple multiple inheritance > situation? OK, in Diamond inheritance in Python (and all multi-inheritance is diamond-shaped in Python), the common ancestor must have a method in order to properly use super. The mro is guaranteed to have the top of the split (C below) before its children in the mro, and the join point (object or root below) after all of the classes from which it inherits. So, the correct way to do what you want: class A: def __init__(self): super().__init__() print('A') class B: def __init__(self): super().__init__() print('B') class C(A, B): def __init__(self): super().__init__() print('C') C() And, if you are doing it with a message not available in object: class root: def prints(self): print('root') # or pass if you prefer class A(root): def prints(self): super().prints() print('A') class B(root): def prints(self): super().prints() print('B') class C(A, B): def prints(self): super().prints() print('C') C().prints() --Scott David Daniels Scott.Daniels at Acm.Org From sato.photo at gmail.com Tue Jun 30 20:23:42 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Tue, 30 Jun 2009 17:23:42 -0700 (PDT) Subject: MIT OpenCourseWare Introduction to Computer Science and Programming Message-ID: I am wondering if anyone else is also going through the MIT OpenCourseWare Intro to CS class. http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/CourseHome/index.htm I've been doing the assignments and, as this class didn't include any answer key, was hoping to see what others did and perhaps collaborate on assignments. -Daniel From MLMLists at Comcast.net Tue Jun 30 20:34:02 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 20:34:02 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Allow me to add to my previous question that certainly the superclass methods can be called explicitly without resorting to super(), e.g.: class C(A, B): def __init__(self): A.__init__(self) B.__init__(self) My question is really whether there is any way of getting around the explicit class names by using super() and if not, shouldn't the documentation of super point out that if more than one class on the mro defines a method only the first will get called? What's strange is that it specifically mentions diamond patterns, which is an important case to get right, but it doesn't show how. I suspect we should have a Multiple Inheritance HOWTO, though details and recommendations would be controversial. I've accumulated lots of abstract examples along the lines of my question, using multiple inheritance both to create combination classes (the kinds that are probably best done with composition instead of inheritance) and mixins. I like mixins, and I like abstract classes. And yes I understand the horrors of working with a large component library that uses mixins heavily, because I've experienced many of them, going all the way back to Lisp-Machine Lisp's window system with very many combo classes such as FancyFontScrollingTitledMinimizableWindow, or whatever. Also, I understand that properties might be better instead of multiple inheritance for some situations. What I'm trying to do is puzzle out what the reasonable uses of multiple inheritance are in Python 3 and how classes and methods that follow them should be written. From sato.photo at gmail.com Tue Jun 30 20:36:20 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Tue, 30 Jun 2009 17:36:20 -0700 (PDT) Subject: MIT OpenCourseWare Introduction to Computer Science and Programming References: Message-ID: I should note that the course utilized python when teaching computer science. On Jun 30, 5:23?pm, "sato.ph... at gmail.com" wrote: > I am wondering if anyone else is also going through the MIT > OpenCourseWare Intro to CS class. > > http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science... > > I've been doing the assignments and, as this class didn't include any > answer key, was hoping to see what others did and perhaps collaborate > on assignments. > > -Daniel From ziade.tarek at gmail.com Tue Jun 30 20:47:51 2009 From: ziade.tarek at gmail.com (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Wed, 1 Jul 2009 02:47:51 +0200 Subject: PEP 376 In-Reply-To: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> References: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> Message-ID: <94bdd2610906301747h7b805012xb42cd80a89727ec8@mail.gmail.com> On Wed, Jul 1, 2009 at 12:52 AM, Carl Banks wrote: > On Jun 30, 12:41?pm, Tarek Ziad? wrote: >> Hello, >> >> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >> >> http://www.python.org/dev/peps/pep-0376/ >> >> It has been discussed a lot already in the distutils-SIG, but new >> feedbacks are welcome >> >> there's an implementation prototype here :http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py > > +1 > > This seems to be a well-designed solution that corrects the ad-hoc- > ness of installation while keeping its effects on existing tools > small. > > I hate those egg-info files but I would be very happy if they'd at > least always be in an accounted-for place. ?Maybe I'd even consider > making use of them some day. > > As for setuptools, I'm sure it will accommodate the change and > probably improve itself in the process. ?(And if the setuptools > doesn't change then some other tool will grow into its niche; either > way it'd be an improvement.) > Yes exactly, the plan is to try to make distutils a reference layer for third party package managers and if possible to become a "smaller" package later on the road. Cheers Tarek From pavlovevidence at gmail.com Tue Jun 30 20:50:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 17:50:20 -0700 (PDT) Subject: Determining if a function is a method of a class within a decorator References: Message-ID: On Jun 29, 6:01?pm, David Hirschfield wrote: > So is there > a pattern I can follow that will allow me to determine whether the > objects I'm given are plain functions or belong to a class? > > Thanks in advance, class HomemadeUnboundMethod(object): def __init__(self,func): self.func = func def __call__(self,*args,**kwargs): print "is a function: %s" % self.func.func_name return self.func(*args,**kwargs) def __get__(self,obj,owner): return HomemadeBoundMethod(obj,self.func) class HomemadeBoundMethod(object): def __init__(self,obj,func): self.obj = obj self.func = func def __call__(self,*args,**kwargs): print "is a method: %s" % self.func.func_name return self.func(self.obj,*args,**kwargs) class A(object): @HomemadeUnboundMethod def method(self): pass @HomemadeUnboundMethod def function(): pass A().method() function() Just override the __call__ functions to do what you want the decorated function to do. There are other little improvements you might make (account for the owner parameter of __get__ for instance) but you get the idea. Carl Banks From ldo at geek-central.gen.new_zealand Tue Jun 30 20:55:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 01 Jul 2009 12:55:17 +1200 Subject: PEP 376 References: Message-ID: In message , Tarek Ziad? wrote: > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > http://www.python.org/dev/peps/pep-0376/ Why are you using MD5? From pavlovevidence at gmail.com Tue Jun 30 21:03:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:03:00 -0700 (PDT) Subject: PEP 376 References: Message-ID: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> On Jun 30, 5:55?pm, Lawrence D'Oliveiro wrote: > In message , Tarek > > Ziad? wrote: > > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > >http://www.python.org/dev/peps/pep-0376/ > > Why are you using MD5? I doubt it's the design aim for eggs to be cryptographically secure, and MD5 is sufficient to detect changes. Carl Banks From norseman at hughes.net Tue Jun 30 21:08:44 2009 From: norseman at hughes.net (norseman) Date: Tue, 30 Jun 2009 18:08:44 -0700 Subject: csv blank fields In-Reply-To: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> Message-ID: <4A4AB71C.4000608@hughes.net> Mag Gam wrote: > I am using the csv package to parse a compressed .csv.gz file. So far > its working perfectly fine but it fails when I have a missing value in > on of the fields. > > For example, I have this > > Abc,def,,jkl > > Is it possible to fill the missing column with a null? > > I want, > Abc,def,NULL,jkl > > TIA ======================== Ideally you need to test each field for a zero length and put at least a single space in any that are BEFORE porting to another format. If you are going to a fixed field format (SDF) then place that field's width spaces into the SDF field. In any case, DO NOT USE NULLS! There are many programs that will crash on them. HTH Steve From davidh at ilm.com Tue Jun 30 21:14:11 2009 From: davidh at ilm.com (David Hirschfield) Date: Tue, 30 Jun 2009 18:14:11 -0700 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: References: Message-ID: <4A4AB863.1020205@ilm.com> Unfortunately that still requires two separate decorators, when I was hoping there was a way to determine if I was handed a function or method from within the same decorator. Seems like there really isn't, so two decorators is the way to go. Thanks, -David Carl Banks wrote: > On Jun 29, 6:01 pm, David Hirschfield wrote: > >> So is there >> a pattern I can follow that will allow me to determine whether the >> objects I'm given are plain functions or belong to a class? >> >> Thanks in advance, >> > > > > class HomemadeUnboundMethod(object): > def __init__(self,func): > self.func = func > def __call__(self,*args,**kwargs): > print "is a function: %s" % self.func.func_name > return self.func(*args,**kwargs) > def __get__(self,obj,owner): > return HomemadeBoundMethod(obj,self.func) > > class HomemadeBoundMethod(object): > def __init__(self,obj,func): > self.obj = obj > self.func = func > def __call__(self,*args,**kwargs): > print "is a method: %s" % self.func.func_name > return self.func(self.obj,*args,**kwargs) > > class A(object): > @HomemadeUnboundMethod > def method(self): pass > > @HomemadeUnboundMethod > def function(): pass > > A().method() > function() > > > > Just override the __call__ functions to do what you want the decorated > function to do. There are other little improvements you might make > (account for the owner parameter of __get__ for instance) but you get > the idea. > > > Carl Banks > -- Presenting: mediocre nebula. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Jun 30 21:23:11 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:23:11 -0700 (PDT) Subject: invoking a method from two superclasses References: Message-ID: <31fe4bef-6738-4de5-b9bb-c0dc42c695a7@o6g2000yqj.googlegroups.com> On Jun 30, 5:34?pm, Mitchell L Model wrote: > Allow me to add to my previous question that certainly the superclass > methods can be called explicitly without resorting to super(), e.g.: > > ? ? class C(A, B): > ? ? ? ? def __init__(self): > ? ? ? ? ? ? A.__init__(self) > ? ? ? ? ? ? B.__init__(self) > > My question is really whether there is any way of getting around the > explicit class names by using super() Yes there is: just make sure that all subclasses also call super. class A: def __init__(self): super().__init__() print('A') class B: def __init__(self): super().__init__() print('B') class C(A, B): def __init__(self): super().__init__() print('C') Bam, that's it. What's happening is that A's super calls B. That is likely to seem wrong to someone who is very familiar with OOP, but it's how Python's MI works. Read this essay/rant that explains how super works and why the author thinks it's not useful. Then ignore the last part, because I and many others have found it very useful, desipte its drawbacks. http://fuhm.net/super-harmful/ Carl Banks From pavlovevidence at gmail.com Tue Jun 30 21:33:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:33:42 -0700 (PDT) Subject: invoking a method from two superclasses References: <31fe4bef-6738-4de5-b9bb-c0dc42c695a7@o6g2000yqj.googlegroups.com> Message-ID: On Jun 30, 6:23?pm, Carl Banks wrote: > On Jun 30, 5:34?pm, Mitchell L Model wrote: > > > Allow me to add to my previous question that certainly the superclass > > methods can be called explicitly without resorting to super(), e.g.: > > > ? ? class C(A, B): > > ? ? ? ? def __init__(self): > > ? ? ? ? ? ? A.__init__(self) > > ? ? ? ? ? ? B.__init__(self) > > > My question is really whether there is any way of getting around the > > explicit class names by using super() > > Yes there is: just make sure that all subclasses also call super. And by subclasses I mean base classes, of course. ugh Carl Banks From magawake at gmail.com Tue Jun 30 21:52:18 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 30 Jun 2009 21:52:18 -0400 Subject: Multi thread reading a file Message-ID: <1cbd6f830906301852t4febbb02q99528f2d6ec94a82@mail.gmail.com> Hello All, I am very new to python and I am in the process of loading a very large compressed csv file into another format. I was wondering if I can do this in a multi thread approach. Here is the pseudo code I was thinking about: Let T = Total number of lines in a file, Example 1000000 (1 million files) Let B = Total number of lines in a buffer, for example 10000 lines Create a thread to read until buffer Create another thread to read buffer+buffer ( So we have 2 threads now. But since the file is zipped I have to wait until the first thread is completed. Unless someone knows of a clever technique. Write the content of thread 1 into a numpy array Write the content of thread 2 into a numpy array But I don't think we are capable of multiprocessing tasks for this.... Any ideas? Has anyone ever tackled a problem like this before? From david.lyon at preisshare.net Tue Jun 30 22:12:09 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 30 Jun 2009 22:12:09 -0400 Subject: packaging apps In-Reply-To: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> References: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> Message-ID: On Tue, 30 Jun 2009 11:11:15 -0400, Ronn Ross wrote: > I have a simple application that has a glade file and a .py file. How would > I package that into an installer for Windows, Mac, and a deb file? Can > anyone point me in the right direction? I don't think there is a simple way to do that just yet... Of course, you could make a source distribution and do it for each of these platforms using the documentation available at: http://docs.python.org/distutils/ I'm struggling with that myself.. I can never remember command lines.. So maybe it is time that I try to throw together a tool a little bit like the package manager except that it does the building.. for all those platforms... I think it's time for distutils to have some sort of gui build tool... and I've been talking about it for too long now... haha David From Scott.Daniels at Acm.Org Tue Jun 30 23:11:38 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 20:11:38 -0700 Subject: PEP 376 In-Reply-To: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> References: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> Message-ID: <1fSdnV38IJnYT9fXnZ2dnUVZ_g2dnZ2d@pdx.net> Carl Banks wrote: > On Jun 30, 5:55 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Tarek >> >> Ziad? wrote: >>> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >>> http://www.python.org/dev/peps/pep-0376/ >> Why are you using MD5? > > I doubt it's the design aim for eggs to be cryptographically secure, > and MD5 is sufficient to detect changes. On the other hand, SHA1 is easily within the reach of current and older CPUs, while problems have already been found with forgeble MD5 puns, and we cannot expect the cases to shrink. I don't see much harm in going for SHA1 now as something likely to last a few years. --Scott David Daniels Scott.Daniels at Acm.Org From Joachim at Strombergson.com Tue Jun 30 23:19:52 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Wed, 01 Jul 2009 05:19:52 +0200 Subject: PEP 376 In-Reply-To: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> References: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> Message-ID: <4A4AD5D8.9060208@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! Carl Banks wrote: > On Jun 30, 5:55 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Tarek >> >> Ziad? wrote: >>> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >>> http://www.python.org/dev/peps/pep-0376/ >> Why are you using MD5? > > I doubt it's the design aim for eggs to be cryptographically secure, > and MD5 is sufficient to detect changes. Even so, choosing md5 in 2009 for something that (hopefully) will be used in years is a bad design decision. It creates a dependency for to an algorithm that all sensible recommendations point you to move away from. Just check hashlib documentation for example: http://docs.python.org/library/hashlib.html I would suggest to use the SHA-256 in the library. The reason for this is that md5 and SHA-1 are weak. The computational complexity of SHA-256 is bigger, but since it probably wont be done many thousands of times during an egg installation, it shouldn't add a noticable delay. - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpK1dgACgkQZoPr8HT30QEwRACg0vhO6TO1k0Pesm5qQOJVen/H vxwAoKdNZZkrDvm/CtQVbr0kZog0sX/U =Frss -----END PGP SIGNATURE----- From MLMLists at Comcast.net Tue Jun 30 23:39:16 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 23:39:16 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: >From: Scott David Daniels >Date: Tue, 30 Jun 2009 16:49:18 -0700 >Message-ID: >Subject: Re: invoking a method from two superclasses > >Mitchell L Model wrote: >>In Python 3, how should super() be used to invoke a method defined in C > > that overrides its two superclasses A and B, in particular __init__? >>... >>I've discovered the surprising fact described in the documentation of super >> >>that specifying a class as the first argument of super means to skip that class when >>scanning the mro so that .... >> >>This seems weird. Would someone please give a clear example and explanation of >>the recommended way of initializing both superclasses in a simple multiple inheritance >>situation? > >OK, in Diamond inheritance in Python (and all multi-inheritance is >diamond-shaped in Python), the common ancestor must have a method >in order to properly use super. The mro is guaranteed to have the >top of the split (C below) before its children in the mro, and the >join point (object or root below) after all of the classes from >which it inherits. > >So, the correct way to do what you want: > class A: > def __init__(self): > super().__init__() > print('A') > > class B: > def __init__(self): > super().__init__() > print('B') > > class C(A, B): > def __init__(self): > super().__init__() > print('C') > > C() > >And, if you are doing it with a message not available in object: > > class root: > def prints(self): > print('root') # or pass if you prefer > > class A(root): > def prints(self): > super().prints() > print('A') > > class B(root): > def prints(self): > super().prints() > print('B') > > class C(A, B): > def prints(self): > super().prints() > print('C') > > C().prints() > >--Scott David Daniels >Scott.Daniels at Acm.Org > Great explanation, and 1/2 a "duh" to me. Thanks. What I was missing is that each path up to and including the top of the diamond must include a definition of the method, along with super() calls to move the method calling on its way up. Is this what the documentation means by "cooperative multiple inheritance"? If your correction of my example, if you remove super().__init__ from B.__init__ the results aren't affected, because object.__init__ doesn't do anything and B comes after A in C's mro. However, if you remove super().__init__ from A.__init__, it stops the "supering" process dead in its tracks. It would appear that "super()" really means something like CLOS's call-next-method. I've seen various discussions in people's blogs to the effect that super() doesn't really mean superclass, and I'm beginning to develop sympathy with that view. I realize that implementationally super is a complicated proxy; understanding the practical implications isn't so easy. While I've seen all sorts of arguments and discussions, including the relevant PEP(s), I don't think I've ever seen anyone lay out an example such as we are discussing with the recommendation that basically if you are using super() in multiple inheritance situations, make sure that the methods of all the classes in the mro up to at least the top of a diamond all call super() so it can continue to move the method calls along the mro. The documentation of super(), for instance, recommends that all the methods in the diamond should have the same signature, but and it says that super() can be used to implement the diamond, but it never actually comes out and says that each method below the top must call super() at the risk of the chain of calls being broken. I do wonder whether this should go in the doc of super, the tutorial, or a HOWTO -- it just seems to important and subtle to leave for people to discover. Again, many thanks for the quick and clear response. From Scott.Daniels at Acm.Org Tue Jun 30 23:57:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 20:57:27 -0700 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Mitchell L Model wrote: >> From: Scott David Daniels >> Date: Tue, 30 Jun 2009 16:49:18 -0700 >> Message-ID: >> Subject: Re: invoking a method from two superclasses >> >> Mitchell L Model wrote: >>> In Python 3, how should super() be used to invoke a method defined in C >>> that overrides its two superclasses A and B, in particular __init__? >>> ... >>> I've discovered the surprising fact described in the documentation of super >>> >>> that specifying a class as the first argument of super means to skip that class when >>> scanning the mro so that .... >>> >>> This seems weird. Would someone please give a clear example and explanation of >>> the recommended way of initializing both superclasses in a simple multiple inheritance >>> situation? >> OK, in Diamond inheritance in Python (and all multi-inheritance is >> diamond-shaped in Python), the common ancestor must have a method >> in order to properly use super. The mro is guaranteed to have the >> top of the split (C below) before its children in the mro, and the >> join point (object or root below) after all of the classes from >> which it inherits. >> >> So, the correct way to do what you want: >> class A: >> def __init__(self): >> super().__init__() >> print('A') >> >> class B: >> def __init__(self): >> super().__init__() >> print('B') >> >> class C(A, B): >> def __init__(self): >> super().__init__() >> print('C') >> >> C() >> >> And, if you are doing it with a message not available in object: >> >> class root: >> def prints(self): >> print('root') # or pass if you prefer >> >> class A(root): >> def prints(self): >> super().prints() >> print('A') >> >> class B(root): >> def prints(self): >> super().prints() >> print('B') >> >> class C(A, B): >> def prints(self): >> super().prints() >> print('C') >> >> C().prints() >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org >> > > Great explanation, and 1/2 a "duh" to me. Thanks. > What I was missing is that each path up to and including the top of the diamond > must include a definition of the method, along with super() calls to move the method > calling on its way up. Is this what the documentation means by > "cooperative multiple inheritance"? I expect so. > ... Again, many thanks for the quick and clear response. Since you know exactly what is confusing right now, and what the resolution is, could I lean on you to take a stab at improving the explanation? I think I know what the solution is, but I don't have a good handle on what needs explaining and what is easily understood. If you do something, others can fix it where it doesn't work. --Scott David Daniels Scott.Daniels at Acm.Org From wuwei23 at gmail.com Mon Jun 1 00:24:19 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 May 2009 21:24:19 -0700 (PDT) Subject: try except inside exec References: Message-ID: <451db527-8616-4f7c-96d7-4bc85dca2392@s21g2000vbb.googlegroups.com> Michele Petrazzo wrote: > I want to execute a python code inside a string and so I use the exec > statement. The strange thing is that the try/except couple don't catch > the exception and so it return to the main code. > Is there a solution to convert or make this code work? > > My code: > > STR = """ > err = 0 > try: > ? ?def a_funct(): > ? ? ?1/0 > except: > ? ?import traceback > ? ?err = traceback.format_exc() > """ > > env = {} > exec STR in env > env["a_funct"]() > print env["err"] Hello Michele, >From your code, I'm not sure if you're aware that functions are themselves objects within Python. You could avoid the use of exec entirely by doing something like the following: import traceback class FuncTester(object): def __init__(self, function): self.function = function def test(self, *args, **kwargs): self.result, self.error = None, None try: self.result = self.function(*args, **kwargs) success = True except: self.error = traceback.format_exc() success = False return success >>> def f(x): return 'f does this: %s' % x ... >>> ft = FuncTester(f) # note that we're referring to the function directly >>> ft.test('foo') True >>> ft.result 'f does this: foo' >>> ft.test() False >>> print ft.error Traceback (most recent call last): File "tester.py", line 10, in test self.result = self.function(*args, **kwargs) TypeError: f() takes exactly 1 argument (0 given) I think you'll find this approach to be a lot more flexible than using exec. Hope this helps, alex23 From aahz at pythoncraft.com Mon Jun 1 01:06:16 2009 From: aahz at pythoncraft.com (Aahz) Date: 31 May 2009 22:06:16 -0700 Subject: pygame error: file is not a windows bmp file References: Message-ID: In article , Djames Suhanko wrote: > >"pygame error: file is not a windows bmp file" > > I couldn't found a solution for this problem. >My python script run fine in local machine using cxfreeze, but don't >work when copied to my live linux system. >If I put bmp image, works fine, but png don't. >Can you help me? Convert with PIL? http://www.pythonware.com/products/pil/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From wuwei23 at gmail.com Mon Jun 1 01:23:19 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 May 2009 22:23:19 -0700 (PDT) Subject: Compiling and transporting modules/libraries in python References: <249dbf4f-ef3e-495e-975e-05d848279d39@u10g2000vbd.googlegroups.com> Message-ID: <69a7961c-c394-4df1-bcb7-cc18aa162817@z14g2000yqa.googlegroups.com> On May 31, 2:27?am, Abe wrote: > ? ? I use python at a home office and in a university computer lab, > but I don't have the administrative rights to install libraries on the > lab computers. ?It would be really nice if there were a way I could > put, say, all of numpy into a file "my_numpy.pyc" and treat it as a > single (large) module. You should be able to use virtualenv to provide this functionality: http://pypi.python.org/pypi/virtualenv Create the environment you want on your home computer, then copy it wholesale to your lab computer or even use it directly from a USB device. You might also want to look into one of the portable Python set ups. This way you can have a fully portable environment that you control completely: Portable Python: http://www.portablepython.com/ Movable Python: http://www.voidspace.org.uk/python/movpy/ Hope this helps. alex23 From aleksandar27 at BRISIOVOnet.hr Mon Jun 1 02:05:49 2009 From: aleksandar27 at BRISIOVOnet.hr (alejandro) Date: Mon, 1 Jun 2009 08:05:49 +0200 Subject: Is there any module for sea tides? Message-ID: I found some in C but could not find in Python.... From CGenie at gmail.com Mon Jun 1 02:24:46 2009 From: CGenie at gmail.com (P. Kaminski) Date: Sun, 31 May 2009 23:24:46 -0700 (PDT) Subject: automated web with python? References: Message-ID: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> OK, thanks, I'll give it a try, From stefan_ml at behnel.de Mon Jun 1 02:38:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Jun 2009 08:38:52 +0200 Subject: Turning HTMLParser into an iterator In-Reply-To: <94817710-8bca-4cad-84f5-32d3c5d44ce7@s21g2000vbb.googlegroups.com> References: <94817710-8bca-4cad-84f5-32d3c5d44ce7@s21g2000vbb.googlegroups.com> Message-ID: <4a23777c$0$31339$9b4e6d93@newsspool4.arcor-online.net> samwyse wrote: > I'm processing some potentially large datasets stored as HTML. I've > subclassed HTMLParser so that handle_endtag() accumulates data into a > list, which I can then fetch when everything's done. I'd prefer, > however, to have handle_endtag() somehow yield values while the input > data is still streaming in. I'm sure someone's done something like > this before, but I can't figure it out. Can anyone help? Thanks. If you can afford stepping away from HTMLParser, you could give lxml a try. Its iterparse() function supports HTML parsing. http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk Stefan From lie.1296 at gmail.com Mon Jun 1 03:18:58 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 01 Jun 2009 07:18:58 GMT Subject: Metaclass mystery In-Reply-To: <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> Message-ID: LittleGrasshopper wrote: > On May 31, 2:03 pm, a... at pythoncraft.com (Aahz) wrote: >> In article , >> >> LittleGrasshopper wrote: >>>> On May 31, 12:19=A0am, Arnaud Delobelle wrote: >>>>> [1]http://www.python.org/download/releases/2.2.3/descrintro/ >>> I'm about 2/3 of the way through this paper (although I don't claim to >>> understand all of it.) There is some heavy duty material in there, >>> enough to make me feel really stupid and frustrated at times. I'm >>> making connections as I go though, hopefully everything will sink in >>> eventually. >>> Is this stuff actually tough, or am I just a dummy? >> Definitely tough! Metaclasses can cause dain bramage. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- >> on-a-new-machine-ly y'rs - tim > > Good to know, I'll stick to it and persevere. Will check doctor > regularly for dain bramage though. Fortunately python makes it rare that we actually need to use metaclass. Especially with class decorators and such... With that said, the rare cases where it is really needed; brain hemorrhage is not only possible but when. From CGenie at gmail.com Mon Jun 1 03:26:42 2009 From: CGenie at gmail.com (P. Kaminski) Date: Mon, 1 Jun 2009 00:26:42 -0700 (PDT) Subject: automated web with python? References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: Ech... The problem is that mechanize doesn't support JavaScript, and these web forms are full of various JS functions... Maybe someone knows a way out of this? Doesn't have to be Python... From michele.simionato at gmail.com Mon Jun 1 03:42:31 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Jun 2009 00:42:31 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> Message-ID: <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> On May 31, 2:32?am, LittleGrasshopper wrote: > Seriously, metaclasses are making my brain hurt. How do people like > Michele Simionato and David Mertz figure these things out? Does it all > come to looking at the C source code for the CPython interpreter? Actually I never looked at the C source code. I performed lots of experiments and figured things out the hard way, with trial and errors. Metaclasses are not that hard, descriptors and super were much harder to grasp at that time, since there was next to zero documentation and a set of subtle bugs. For descriptors now there is Raymond Hettinger essay and for super there are my blog posts on Artima: http://www.artima.com/weblogs/index.jsp?blogger=micheles&start=45&thRange=15 (there are also two posts of mine about metaclasses in Python 3.0 that you may want to read) HTH, Michele From jeremiah.dodds at gmail.com Mon Jun 1 04:22:24 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Mon, 1 Jun 2009 09:22:24 +0100 Subject: automated web with python? In-Reply-To: References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: <12cbbbfc0906010122s9733ae9l2496a30cd6894684@mail.gmail.com> On Mon, Jun 1, 2009 at 8:26 AM, P. Kaminski wrote: > Ech... The problem is that mechanize doesn't support JavaScript, and > these web forms are full of various JS functions... Maybe someone > knows a way out of this? Doesn't have to be Python... > -- > http://mail.python.org/mailman/listinfo/python-list > Selenium _might_ be able to help you out. Otherwise, a method you can use (tedious at first, but can speed things up significantly) would be to either use firefox and grab the headers you're sending during a session (the site may use javascript really heavily, but in the end all that matters is that you're sending the same POST/GET requests), and then use mechanize, or read the javascript, and then use mechanize. At my job, I've had to automate a few really javascript-heavy web applications. Firefox+FireBug+HTTPFox with python and mechanize can be a lifesaver here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Jun 1 05:01:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Jun 2009 06:01:40 -0300 Subject: [Tutor] Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: En Mon, 01 Jun 2009 00:28:12 -0300, Michael H. Goldwasser escribi?: > Hi Kent, > > Thanks for your thoughts. > > For the original example code, you are correct that we could make it > work by having B provide the one-arg constructor to match A's > constructor signature. But I don't see this as a general solution. > > Having B.__deepcopy__() make a call to A.__deepcopy__() assumes that A > supports __deepcopy__ either direclty or indirectly. This is not > guaranteed as __deepcopy__ is not supported all the way back to the > object base class. It could be that the author of A has guaranteed > that the syntax deepcopy(instanceA) is properly supported, but that > could be done by other means without an explicit __deepcopy__ (such as > relying on a true deep copy, or using getstate/setstate to affect both > pickling and deepcopy). In general, you have to know whether A implements __deepcopy__ or not. This is a small price for the flexibility (or anarchy) in the copy/pickle interfases: there are several ways to implement the same thing, and you have to know which one your base class has chosen in order to extend it. The following is a possible implementation that doesn't use __init__ at all, so their different signature is not an issue: # class A: def __deepcopy__(self, memo={}): dup = type(self).__new__(type(self)) dup.__aTag = self.__aTag dup.__aList = copy.deepcopy(self.__aList, memo) dup.__aList.reverse() return dup # class B: def __deepcopy__(self, memo={}): dup = A.__deepcopy__(self, memo) dup.__bTag = self.__bTag dup.__bList = copy.deepcopy(self.__bList, memo) return dup Note that A.__deepcopy__ does two things: a) create a new, empty, instance; and b) transfer state. B.__deepcopy__ handles *its* portion of state only. This can be written in a more generic way, relying on __getstate__/__setstate__ (the methods that should return the current state of the object): # class A: def __deepcopy__(self, memo={}): dup = type(self).__new__(type(self)) if hasattr(self, '__getstate__'): state = self.__getstate__() else: state = self.__dict__ state = copy.deepcopy(state, memo) if hasattr(dup, '__setstate__'): dup.__setstate__(state) else: dup.__dict__.update(state) dup.__aList.reverse() return dup # remove __deepcopy__ definition from class B Now, B (and any other subclass) is concerned only with __getstate__ / __setstate__, and only when the default implementation isn't appropriate. > As another basic puzzle, consider a class definition for B where B has > a registry list that it doesn't want cloned for the new instance (but > it does want pickled when serialized). This would seem to require > that B implement its own __deepcopy__. We want to somehow rely on > the class definition for A to enact the cloning fo the state defined > by A. But without knowing about how A supports the deepcopy > semantics, I don't see how to accomplish this goal. I don't understand such bizarre requirement, but anyway, you can override __deepcopy__ (make B fix only the part that the default implementation doesn't implement well) # A.__deepcopy__ as above # class B: def __deepcopy__(self, memo={}): dup = A.__deepcopy__(self, memo) dup.__registry = self.__registry return dup This [the need to know how certain feature is implemented in the base class] is not special or peculiar to pickle/copy, although the multiple (and confusing) ways in which a class can implement pickling doesn't help to understand the issue very well. Consider the + operator: when some subclass wants to implement addition, it must know which of the several special methods involved (__add__, __iadd__, __radd__) are implemented in the base class, in order to extend/override them. Same for __cmp__/__eq__/__hash__: you can't just ignore what your base class implements. All of this applies to other languages too, but in Python, there is an additional consideration: the mere *existence* of some methods/attributes can have consequences on how the object behaves. In short, you can't blindly write __special__ methods. -- Gabriel Genellina From piet at cs.uu.nl Mon Jun 1 05:07:02 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 11:07:02 +0200 Subject: what I would like python.el to do (and maybe it does) References: <85ljolfgaa.fsf@agentultra.com> <87prdsxapj.fsf@agentultra.com> Message-ID: >>>>> J Kenneth King (JKK) wrote: >JKK> Well, that's the thing -- type a statement into a python interpreter and >JKK> you just get a new prompt. >JKK> LISP has a REPL, so you get some sort of feedback printed. iPython also has a REPL, but only when you enter the Python code manually in the iPython window. >JKK> However, some sort of visual cue on the emacs side would be nice. Either >JKK> just flash the block of code being sent or a minibuffer message would be >JKK> nice. >JKK> Look for some SLIME tutorial videos on youtube to see some great >JKK> interpreter <-> editor interaction. I have tried out SLIME with SBCL (just some simple code) but I didn't like the feedback. I got unnecessary compiler warnings, and it was difficult to find some useful information in it. >JKK> The stock Python interpreter probably wouldn't cut it close to something >JKK> like SLIME in terms of features, but the iPython package might be a >JKK> start. For now the iPython package for me has more options than I have had time to try out. On the other hand when you execute some code form a Python file (with C-c C-c or C-c |) you get this ## working on region in file /tmp/python-26084kfr.py... in the *Python* buffer which is very uninformative. This is generated by python-mode, not by iPython. You do get any output printed in the code, however, as well as exceptions. I have made a change in my Python mode such that the ## working on region in file /tmp/python-26084kfr.py... message will be replaced by the actual code executed, if that code is not too big (size configurable). And that looks nicer. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jeanmichel at sequans.com Mon Jun 1 05:21:28 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Jun 2009 11:21:28 +0200 Subject: NameError function not found In-Reply-To: <5700df6b0905291213y4ee08697xb336797adeb468a2@mail.gmail.com> References: <5700df6b0905291213y4ee08697xb336797adeb468a2@mail.gmail.com> Message-ID: <4A239D98.9070107@sequans.com> Cameron Pulsford wrote: > Hey everyone, I am extremely stumped on this. I have 2 functions.. > > def _determinant(m): > return m[0][0] * m[1][1] - m[1][0] * m[0][1] > > def cofactor(self): > """Returns the cofactor of a matrix.""" > newmatrix = [] > for i, minor in enumerate(self.minors()): > newmatrix.append(_determinant(minor.matrix) * ((i%2) * -1)) > return newmatrix > > And I get the following error when I try to run a.cofactor()... > > "NameError: global name '_determinant' is not defined" > > When I put the _determinant function nested within the cofactor > function it works fine. Normally I would do this, but a lot of other > methods use the _determinant method. They are both in the same class, > and they are at the same level, they are even in that order so I know > it should be able to see it. I have a lot of functions that call > other functions in this class and everything is fine. [Also for the > picky, I know my cofactor method isn't mathematically correct yet ;-) > ] Am I missing something obvious here? Also if it helps the rest of > the code is > herehttp://github.com/dlocpuwons/pymath/blob/d1997329e4473f8f6b5c7f11635dbd719d4a14fa/matrix.py though > it is not the latest. Maybe someone has already answered... Looks like cofactor is in a class, so I'm assuming _determinant is in that class as well. 3 solutions: - declare _determinant outside of the class, making it a private module function - declare _determinant as method of the instance : def _determinant(self) - if you want to keep _determinant as part of your class, it's up to you but you have to declare it as staticmethod (goolge it for details) For isntance : class MyClass def _determant()m: ... _determant = staticmethod(_determinant) def cofactor(self): ... x = MyClass._determinant(y) # this is how you call static Class method, but rarely these methods are set private (_ prefix) Jean-Michel From piet at cs.uu.nl Mon Jun 1 05:38:05 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 11:38:05 +0200 Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: >>>>> LittleGrasshopper (L) wrote: >L> On May 31, 3:59?pm, Carl Banks wrote: >>> On May 31, 3:52?pm, LittleGrasshopper wrote: >>> >>> >>> >>> > This is some simple code which I got from Guido's paper on the >>> > unification of classes and types, which Arnaud suggested to improve my >>> > knowledge of metaclasses: >>> >>> > class M1(type): >>> > ? ? pass >>> > class M2(M1): >>> > ? ? pass >>> > class M3(M2): >>> > ? ? pass >>> > class C1: >>> > ? ? __metaclass__ = M1 >>> > class C2(C1): >>> > ? ? __metaclass__ = M2 >>> > class C3(C1, C2): >>> > ? ? __metaclass__ = M3 >>> >>> > It is failing when processing C3: >>> > Traceback (most recent call last): >>> > ? File "metaerror.py", line 18, in >>> > ? ? class C3(C1, C2): >>> > TypeError: Error when calling the metaclass bases >>> > ? ? Cannot create a consistent method resolution >>> > order (MRO) for bases C2, C1 [snip] >L> I guess the resulting MROs do not satisfy monotonicity, I >L> just have to find out how to derive the MRO. I had the notion that it >L> was constructed by listing the current class, followed by the MROs of >L> each base in order, and then retaining the rightmost instance of each >L> class in the MRO list, but I think that might be an >L> oversimplification, since in this case that would be: >L> (C1, object) >L> (C2, C1, object) >L> (C3, C2, C1, object) >L> And I don't see any issues. But I'll read the paper to figure out what >L> the problem is, thanks. Here is exactly the problem. Merging the two MRO's as you state would give C3, C2, C1, object, i.e. C2 before C1. But your class definition: class C3(C1, C2): says that C1 should be before C2. Conflict!! Change it to class C3(C2, C1): You see it has nothing to do with the metaclasses. The following code gives the same error: class C1(object): pass class C2(C1): pass class C3(C1, C2): pass -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From visco31 at gmail.com Mon Jun 1 06:40:50 2009 From: visco31 at gmail.com (Visco Shaun) Date: Mon, 01 Jun 2009 16:10:50 +0530 Subject: "TypeError: 'int' object is not callable" Message-ID: <1243852850.5259.4.camel@ajc> when I was executing the below code I got "TypeError: 'int' object is not callable" exception. Why is it so? if type(c) == type(ERROR): c can be a string or an integer representing an error -- Thanks & Regards visco From ldo at geek-central.gen.new_zealand Mon Jun 1 06:41:44 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Jun 2009 22:41:44 +1200 Subject: Ah, ctypes Message-ID: I wrote some code months ago to output 1-bit-per-pixel PNG files from Python, doing direct calls to libpng using ctypes, because PIL didn't give me sufficient control over colour tables and pixel depths. I thought the code was working fine. I left it aside for some months, came back to it a week or two ago, and found it was crashing. I was creating CFUNCTYPE objects to do callbacks to my own I/O routines, and with GDB I was able to narrow down the crashes to the point where libpng was trying to invoke one of my callbacks. What had changed? I had switched my OS from Gentoo to Debian Unstable. I chrooted back to the Gentoo system, tried my script again--still crashed. Went back to the doc and tried the qsort callback example. Worked fine! And then I noticed this little bit: Important note for callback functions: Make sure you keep references to CFUNCTYPE objects as long as they are used from C code. ctypes doesn?t, and if you don?t, they may be garbage collected, crashing your program when a callback is made. Yup, that was it. I changed my installation of the callbacks from png.png_set_write_fn \ ( write_struct, None, ct.CFUNCTYPE(None, ct.c_void_p, ct.c_void_p, ct.c_size_t)(write_data), ct.CFUNCTYPE(None, ct.c_void_p)(flush_write) ) to cb_write_data = ct.CFUNCTYPE(None, ct.c_void_p, ct.c_void_p, ct.c_size_t)(write_data) cb_flush_write = ct.CFUNCTYPE(None, ct.c_void_p)(flush_write) png.png_set_write_fn \ ( write_struct, None, cb_write_data, cb_flush_write ) and it works again. From piet at cs.uu.nl Mon Jun 1 06:44:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 01 Jun 2009 12:44:17 +0200 Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: >>>>> Piet van Oostrum (I) wrote: >I> But your class definition: >I> class C3(C1, C2): >I> says that C1 should be before C2. Conflict!! >I> Change it to class C3(C2, C1): Of course the C1 is then superfluous. I wonder why you want this. What is the problem you want to solve? Apart from the metaclasses (that you still can use with `class C3(C2)') I could think of the following use case: class C1(object): def m1(self): return 'C1.m1' class C2(C1): # override m1 def m1(self): return 'C2.m1' def m2(self): return 'C2.m2'+self.m1() class C3(C1, C2): def test(self): print self.m1()+self.m2() i.e. in C3 we `ignore' the override of m1 in C2 but still want to make use of the m2 from C2. The question that arises then is: the self.m1() inside m2, which m1 should it use? For an instance of C3 it would use C1.m1, but for an instance of C2 it would use C2.m2. However, every instance of C3 can also be considered an instance of C2, (Liskov substitution principle), therefore there is a conflict. That is exactly the conflict that the MRO signals. If you want that kind of behaviour it can be solved by using a mixin class for the m2 method: class C1(object): __metaclass__ = M1 def m1(self): return 'C1.m1' class Cmix(object): def m2(self): return 'C2.m2'+self.m1() class C2(C1, Cmix): __metaclass__ = M2 # override m1 def m1(self): return 'C2.m1' class C3(C1, Cmix): __metaclass__ = M3 def test(self): print self.m1()+self.m2() -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From R.Brodie at rl.ac.uk Mon Jun 1 06:45:29 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 1 Jun 2009 11:45:29 +0100 Subject: "TypeError: 'int' object is not callable" References: Message-ID: "Visco Shaun" wrote in message news:mailman.966.1243852864.8015.python-list at python.org... > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): You've probably assigned to type somewhere in your code. What does print repr(type) give? From steve at holdenweb.com Mon Jun 1 06:45:48 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Jun 2009 06:45:48 -0400 Subject: Not going to let this drop ... Message-ID: <4A23B15C.3090403@holdenweb.com> If you have a few minutes to read this message you might just be able to make a big difference to the lives of some very disadvantaged people. If you can't help, don't worry. Sorry for bothering you. There's a project that needs help. The chuzer project is moribund (the rest of this message explains what it is). I accept responsibility for that. I have had a lot on my plate recently, but everything is relative, and my information from other sources tells me that some recipients of this email have far worse problems than I. Paul McNett said in a recent email "this seems like too noble a project to die", and I agree with him. It seems to me that a really quite small amount of development time could see us producing a system that would add a huge amount to the lives of some of the most needy people we can imagine. Or not. Frankly, it's the imagining that scares me. I am having real difficulty imagining what it might be like to be in a position where I can't easily tell someone what I need. The chuzer project will allow severely disabled people to express the most basic needs. Maybe "what I want for pudding" wasn't a particularly good example, but it was the one the project was motivated by, and it's hard to think how frustrating it must be when being able to tell someone what you want for pudding represents an improvement in your quality of life. There are quadriplegics out there with such a limited range of expressive ability that the only way they can express any choice at all is to watch a series of selections tick by until the right one comes up, and then puff into a pipe or bite down on something - basically, perform one of the very few movements of which they are capable - to say "that's what I want". Yes, it might be "what I want for pudding", but how about even more basic choices: a) I need to pee b) I have to take a dump c) I am hungry d) I am thirsty e) Please hug me f) My bedsores are hurting The big problem for a lot of quadriplegics, as far as I understand it, is that uninformed people treat them as though their brains were as damaged as their bodies. Most readers of this email will be able-bodied. Please try and imagine what it would be like to be entombed in a full-body plaster cast and be unable to speak, but to still retain your full mental faculties. Don't you think you might really appreciate even something as simple as a choice program? I was intending to try and recruit assistance at PyCon, but sadly on the Saturday I received news of my mother's death, so that kind of put the kibosh on that, and I had to leave early. I also recently realized rather too late that this project would be an excellent candidate for a Google Summer of Code project, but that's already underway now. Again, I apologize for not having the time to bring chuzer to enough people's attention to get it on the GSoc radar. My bad. I don't know if Google are planning to run a Highly-Open Participation event this year, but if they are then maybe we could establish a few tasks for that. Basically this is a project that really needs some help right now. There's a basic working model, around which an image-selection and audio-recording infrastructure needs to be built so that it's easy for carers to set up appropriate choices and easy for users to indicate choices. It's not rocket science, it just needs a few of us to care enough to keep moving this project forward until it's done. It would make an excellent wxPython learning project. If anyone who reads this email has anything to offer - time, money, equipment, whatever, I'd be *really* grateful to hear from them. I can put you in touch with people who know about things like the range of interface devices available for paraplegic and quadriplegic people. Ideally the program would be adaptable to a wide range of hardware accommodating a broad spectrum of disability, but many quadriplegics use equipment that emulates a standard keyboard and/or mouse, so that would be a great start. Please help, even if only by publicizing this project. You don't even have to code, just to help with ideas for recruiting coding assistance. http://chuzer.org/ Even better, please join the mailing list linked on the site, and help to make the world a better place. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ From andreengels at gmail.com Mon Jun 1 06:48:34 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 1 Jun 2009 12:48:34 +0200 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: <6faf39c90906010348y21167e7ancf5421ef5098d827@mail.gmail.com> On Mon, Jun 1, 2009 at 12:40 PM, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error Could you please give a larger piece of code, preferably such that it can functions as a small stand-alone program that gives the same error message? It looks to me that the problem is most likely in a previous or subsequent line. -- Andr? Engels, andreengels at gmail.com From clp2 at rebertia.com Mon Jun 1 06:50:31 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 03:50:31 -0700 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: <50697b2c0906010350u8c970a3i3edcf7f055993dcd@mail.gmail.com> On Mon, Jun 1, 2009 at 3:40 AM, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error Please also, now and in the future, provide the full error traceback as it is very necessary in order to determine the problem. Cheers, Chris -- http://blog.rebertia.com From CGenie at gmail.com Mon Jun 1 07:14:12 2009 From: CGenie at gmail.com (P. Kaminski) Date: Mon, 1 Jun 2009 04:14:12 -0700 (PDT) Subject: automated web with python? References: <5a3da7fb-c987-4d2b-9a0e-ad801369ac32@c36g2000yqn.googlegroups.com> Message-ID: <74dbd67c-7a64-4df1-9ef9-6903b1b01c1c@o14g2000vbo.googlegroups.com> OK, I found a solution -- Selenium, from http://selenium.org. I downloaded Selenium RC and this works fantastic! I'll get the job done by tomorrow ;) From djames.suhanko at gmail.com Mon Jun 1 07:16:54 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 1 Jun 2009 08:16:54 -0300 Subject: BMP32 for linux Message-ID: Hello, all! Did you know the bmp32 module for linux? This module can to load bmp image with alpha channel where is not supported others images formats. But I couldn't to found this module to install in my linux box. :-( do you have tips? Thanks ! -- Djames Suhanko LinuxUser 158.760 From rhodri at wildebst.demon.co.uk Mon Jun 1 07:16:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 01 Jun 2009 12:16:57 +0100 Subject: "TypeError: 'int' object is not callable" In-Reply-To: <1243852850.5259.4.camel@ajc> References: <1243852850.5259.4.camel@ajc> Message-ID: On Mon, 01 Jun 2009 11:40:50 +0100, Visco Shaun wrote: > when I was executing the below code I got "TypeError: 'int' object is > not callable" exception. Why is it so? > > if type(c) == type(ERROR): > > c can be a string or an integer representing an error In the absence of the rest of your code this is a wild guess, but have you used `type` as a variable? If you have, that would mask the builtin name `type`, and would give you this error assuming `type` contains an integer. Moral: don't use builtin names for variables. -- Rhodri James *-* Wildebeeste Herder to the Masses From electriclightheads at gmail.com Mon Jun 1 08:49:11 2009 From: electriclightheads at gmail.com ('2+) Date: Mon, 1 Jun 2009 21:49:11 +0900 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) Message-ID: <1078018b0906010549y6f3bd5ebu1270d047644841ef@mail.gmail.com> would like to take advantage of the wave module found a good example here: http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 hmm .. i don't get how to write a stereo .. i mean i can set nchannels .. but how do i actually take control of each ch individually? and what's the range(in float) of the data i can set in wav_file.writeframes(struct.pack('h', data))? tia -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml and supplying oil.py for free: http://oilpy.blogspot.com/ From ed at leafe.com Mon Jun 1 09:00:25 2009 From: ed at leafe.com (Ed Leafe) Date: Mon, 1 Jun 2009 09:00:25 -0400 Subject: Dabo 0.9.2 released Message-ID: At long last, we are finally releasing Dabo 0.9.2. This fixes the errors that were found in 0.9.1; adds a brand-new Web Update implementation that should make keeping current much easier, as well as a whole bunch of improvements under the hood. You can grab the latest version at http://dabodev.com/download. -- Ed Leafe From john.center at villanova.edu Mon Jun 1 09:05:52 2009 From: john.center at villanova.edu (John Center) Date: Mon, 1 Jun 2009 06:05:52 -0700 (PDT) Subject: Problem building 64-bit python 2.6.2 on Solaris 10 References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> Message-ID: <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> On May 29, 7:13?pm, "Martin v. L?wis" wrote: > > Ah, too much text - I was confused by you reporting two issues in a > single email message. That has exhausted my capacity for quick message > scanning. > Sorry about that. I have a tendency to over document... > So this is a ctypes problem. You'll have to ignore it - there is > absolutely no way that you could possibly build the ctypes module > with Sun CC (short of rewriting ctypes to support it, of course). > Use gcc if you need the ctypes module, or accept not having the ctypes > module available. > I was afraid that would be the case. I have gcc4sparc, but I usually build with Sun Studio. I believe gcc4sparc uses the Sun Studio backend. I'll try this, but do you know if I would need to do anything different to get the ctypes code to compile? > Unfortunately, no. It is definitely *not* Python who is searching for > these libraries. That you had been passing them to ld during linkage > doesn't help at all. Linking succeeds just fine; Python then tries > to load the the _ssl module, which in turn causes the *dynamic* linker > (ld.so.1) to search for the shared library; it doesn't find it and > therefore gives up loading _ssl.so. > Ok, so it looks like the only option here is to use LD_LIBRARY_PATH. Thanks, Martin. -John From emin.shopper at gmail.com Mon Jun 1 09:06:18 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 09:06:18 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser Message-ID: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> Dear Experts, I am having some issues with the subprocess module and how it interacts with win32security.ImpersonateLoggedOnUser. Specifically, I use the latter to change users but the new user does not seem to be properly inherited when I spawn further subprocesses. I am doing something like import win32security, win32con handle = win32security.LogonUser( user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(handle) Then spawning subprocesses but the subprocesses cannot read the same UNC paths that that the parent could. Any advice on either spawning subprocesses which inherit parent user properly or changing users in a better way on Windows would be greatly appreciated. Thanks, -Emin From jeanmichel at sequans.com Mon Jun 1 09:30:38 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Jun 2009 15:30:38 +0200 Subject: Class Methods help In-Reply-To: References: <_QvUl.14954$y61.8697@news-server.bigpond.net.au> Message-ID: <4A23D7FE.1000102@sequans.com> FYI, same without decorators, if you python version does not support it. class MyClass: def some_func(x): return x+2 some_func = staticmethod(some_func) JM bd satish wrote: > Thanks to Tim Chase & Lie Ryan !! That was exactly what I was looking for !! > > It's time for me to now read the documentation of "decorators" and > @classmethod and also @staticmethod. > > I'm quite new to decorators... > > > -- Satish BD > > > On Sun, May 31, 2009 at 4:44 PM, Lie Ryan wrote: > >> bdsatish wrote: >> >>> Hi, >>> >>> I have a question regarding the difference b/w "class methods" and >>> "object methods". Consider for example: >>> >>> class MyClass: >>> x = 10 >>> >>> Now I can access MyClass.x -- I want a similar thing for functions. I >>> tried >>> >>> class MyClass: >>> def some_func(x): >>> return x+2 >>> >>> When I call MyClass.some_func(10) -- it fails, with error message: >>> >>> >>> TypeError: unbound method some_func() must be called with MyClass >>> instance as first argument (got int instance instead) >>> >>> OK. I figured out that something like this works: >>> obj = MyClass() >>> y = obj.some_func(10) >>> >>> BUT, this means that we have functions applying for instances. That is >>> we have "instance method". Now, how do I implement some function which >>> I can invoke with the class name itself ? Instead of creating a dummy >>> object & then calling.... In short, how exactly do I create "class >>> methods" ?? >>> >> with staticmethod decorator: >> >> >>>>> class MyClass: >>>>> >> ... @staticmethod >> ... def some_func(x): >> ... return x+2 >> ... >> >>>>> MyClass.some_func(10) >>>>> >> 12 >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> From mail at timgolden.me.uk Mon Jun 1 09:38:47 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 01 Jun 2009 14:38:47 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> Message-ID: <4A23D9E7.1080700@timgolden.me.uk> Emin.shopper Martinian.shopper wrote: > Dear Experts, > > I am having some issues with the subprocess module and how it > interacts with win32security.ImpersonateLoggedOnUser. Specifically, I > use the latter to change users but the new user does not seem to be > properly inherited when I spawn further subprocesses. > > I am doing something like > > import win32security, win32con > handle = win32security.LogonUser( > user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, > win32con.LOGON32_PROVIDER_DEFAULT) > > win32security.ImpersonateLoggedOnUser(handle) > > Then spawning subprocesses but the subprocesses cannot read the same > UNC paths that that the parent could. http://support.microsoft.com/kb/111545 """ Even if a thread in the parent process impersonates a client and then creates a new process, the new process still runs under the parent's original security context and not the under the impersonation token. """ TJG From emin.shopper at gmail.com Mon Jun 1 09:45:37 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 09:45:37 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <4A23D9E7.1080700@timgolden.me.uk> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> Message-ID: <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> Thanks. But how do I fix this so that the subprocess does inherit the impersonated stuff? On Mon, Jun 1, 2009 at 9:38 AM, Tim Golden wrote: > Emin.shopper Martinian.shopper wrote: >> >> Dear Experts, >> >> I am having some issues with the subprocess module and how it >> interacts with win32security.ImpersonateLoggedOnUser. Specifically, I >> use the latter to change users but the new user does not seem to be >> properly inherited when I spawn further subprocesses. >> >> I am doing something like >> >> ? ?import win32security, win32con >> ? ?handle = win32security.LogonUser( >> ? ? ? ?user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, >> ? ? ? ?win32con.LOGON32_PROVIDER_DEFAULT) >> >> ? ?win32security.ImpersonateLoggedOnUser(handle) >> >> Then spawning subprocesses but the subprocesses cannot read the same >> UNC paths that that the parent could. > > http://support.microsoft.com/kb/111545 > > """ > Even if a thread in the parent process impersonates a client and then > creates a new process, the new process still runs under the parent's > original security context and not the under the impersonation token. """ > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Mon Jun 1 10:03:45 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 01 Jun 2009 15:03:45 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> Message-ID: <4A23DFC1.6070209@timgolden.me.uk> [slightly rearranged for top-to-bottom reading...] > On Mon, Jun 1, 2009 at 9:38 AM, Tim Golden wrote: >> Emin.shopper Martinian.shopper wrote: >>> Dear Experts, >>> >>> I am having some issues with the subprocess module and how it >>> interacts with win32security.ImpersonateLoggedOnUser. Specifically, I >>> use the latter to change users but the new user does not seem to be >>> properly inherited when I spawn further subprocesses. >>> >>> I am doing something like >>> >>> import win32security, win32con >>> handle = win32security.LogonUser( >>> user,domain,password,win32con.LOGON32_LOGON_INTERACTIVE, >>> win32con.LOGON32_PROVIDER_DEFAULT) >>> >>> win32security.ImpersonateLoggedOnUser(handle) >>> >>> Then spawning subprocesses but the subprocesses cannot read the same >>> UNC paths that that the parent could. >> http://support.microsoft.com/kb/111545 >> >> """ >> Even if a thread in the parent process impersonates a client and then >> creates a new process, the new process still runs under the parent's >> original security context and not the under the impersonation token. """ >> >> TJG >> -- >> http://mail.python.org/mailman/listinfo/python-list Emin.shopper Martinian.shopper wrote: > Thanks. But how do I fix this so that the subprocess does inherit the > impersonated stuff? > The source for subprocess just uses CreateProcess. Which means that, short of monkey-patching it, you're going to have to roll your own subprocess-like code (I think). Basically, you'll need to run CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit of a pig in terms of getting the right combination of parameters and privileges, I seem to remember. Haven't got time right now to fish for an example, I'm afraid: maybe someone else on the list has a canned example...? Also worth cross-posting this to the python-win32 list where more win32 expertise resides. TJG From dudekksoft at gmail.com Mon Jun 1 10:16:07 2009 From: dudekksoft at gmail.com (dudekksoft at gmail.com) Date: Mon, 1 Jun 2009 07:16:07 -0700 (PDT) Subject: PyQt4 + WebKit References: Message-ID: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> On 31 Maj, 02:32, David Boddie wrote: > On Saturday 30 May 2009 17:39, dudekks... at gmail.com wrote: > > > I need to grab clicked links in QWebView. Everything is fine when I > > use linkClicked() signal. LinkDelegationPolicy is set to > > DelegateAllLinks and there is a problem. If some site has Javascript > > my procedure receives QUrl from linkClicked, next calls: > > > webView.setUrl(url) #Where "url" is received QUrl > > > Certainly this method doesn't work. Site loads again (in most cases > > it's calledhttp://mywwwsite.net/#). > > OK, so if I understand correctly, you don't know how to handle these > special links if you use a delegation policy, and you would prefer it > if they were handled by WebKit. > > > As I use > > QWebPage::DelegateExternalLinks it happens the same, because my > > procedure grabs links with Javascript. I don't know how to cope with > > this problem. Maybe it's possible to set own policy in > > QWebPage.LinkDelegationPolicy? Or maybe some other method to grab > > protocol, host(if external or not) when user clicks link in webView? > > So, you only want to handle certain links, and pass on to WebKit those which > you can't handle? Is that correct? > > David Yes, I want to handle external links (out of my host) and links starting with download://... (my specific protocol). From emin.shopper at gmail.com Mon Jun 1 10:29:16 2009 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Mon, 1 Jun 2009 10:29:16 -0400 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: <4A23DFC1.6070209@timgolden.me.uk> References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> <4A23DFC1.6070209@timgolden.me.uk> Message-ID: <32e43bb70906010729m298ffd71m94d3995a9b1fa878@mail.gmail.com> > The source for subprocess just uses CreateProcess. Which means that, > short of monkey-patching it, you're going to have to roll your own > subprocess-like code (I think). Basically, you'll need to run > CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit > of a pig in terms of getting the right combination of parameters > and privileges, Thanks. I tried rolling my own via CreateProcessAsUser but it complained about needing some special permissions so its probably not going to work. I'd like to try CreateProcessAsLogonW but can't see how to access that via python. I will start a new thread on the python-win32 list about that. Thanks, -Emin From james at agentultra.com Mon Jun 1 11:00:42 2009 From: james at agentultra.com (J Kenneth King) Date: Mon, 01 Jun 2009 11:00:42 -0400 Subject: what I would like python.el to do (and maybe it does) References: <85ljolfgaa.fsf@agentultra.com> <87prdsxapj.fsf@agentultra.com> Message-ID: <85ljocc82t.fsf@agentultra.com> Piet van Oostrum writes: >>>>>> J Kenneth King (JKK) wrote: > >>JKK> Well, that's the thing -- type a statement into a python interpreter and >>JKK> you just get a new prompt. > >>JKK> LISP has a REPL, so you get some sort of feedback printed. > > iPython also has a REPL, but only when you enter the Python code > manually in the iPython window. > >>JKK> However, some sort of visual cue on the emacs side would be nice. Either >>JKK> just flash the block of code being sent or a minibuffer message would be >>JKK> nice. > >>JKK> Look for some SLIME tutorial videos on youtube to see some great >>JKK> interpreter <-> editor interaction. > > I have tried out SLIME with SBCL (just some simple code) but I didn't > like the feedback. I got unnecessary compiler warnings, and it was > difficult to find some useful information in it. > >>JKK> The stock Python interpreter probably wouldn't cut it close to something >>JKK> like SLIME in terms of features, but the iPython package might be a >>JKK> start. > > For now the iPython package for me has more options than I have had time > to try out. > On the other hand when you execute some code form a Python file (with > C-c C-c or C-c |) you get this > ## working on region in file /tmp/python-26084kfr.py... in the *Python* > buffer which is very uninformative. This is generated by python-mode, > not by iPython. You do get any output printed in the code, however, as > well as exceptions. > > I have made a change in my Python mode such that the > ## working on region in file /tmp/python-26084kfr.py... > message will be replaced by the actual code executed, if that code is > not too big (size configurable). And that looks nicer. > -- > Piet van Oostrum > URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] > Private email: piet at vanoostrum.org If you have a patch file for that, I'd be interested in trying it out. :) From pataphor at gmail.com Mon Jun 1 11:11:00 2009 From: pataphor at gmail.com (pataphor) Date: Mon, 01 Jun 2009 17:11:00 +0200 Subject: Generating all combinations In-Reply-To: <78g79iF1l1i8bU1@mid.dfncis.de> References: <78g79iF1l1i8bU1@mid.dfncis.de> Message-ID: Johannes Bauer wrote: > Any help is appreciated! This is on the fringe of exploitation, but hey, maybe the code helps you think about the algorithm. IMHO the following code is a glaring complaint about the injustice of omission itertools inflicts on the perfectly natural and obvious procedure of repeat_each (whatever it's name ought to be): from itertools import izip, islice, cycle def repeat_each(seq,n): while True: for x in seq: for i in range(n): yield x def repeat_all(seq,n): while True: for i in range(n): for x in seq: yield x def product(X): N = [] total = 1 for x in X: N.append(total) total *= len(x) R = [repeat_all(repeat_each(x,k),n) for x,k,n in izip(X,N,reversed(N))] return islice(izip(*R),total) def test1(): L = ['a', 'bc','def' ] for x in product(L): print x print def test2(): repeat_all = cycle test1() if __name__ == '__main__': test1() test2() See? Repeat_all and repeat_each are almost brothers, just separated by the tiniest rearrangement of their genetic code (or should I say code genetics?). Yet one is included as 'itertools.cycle' and the other is doomed to live in limbo. Such injustice! Can it be that 'itertools.repeat' has usurped repeat_each's rightful position? P. From martin at v.loewis.de Mon Jun 1 11:16:38 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 01 Jun 2009 17:16:38 +0200 Subject: Building PIL under Cygwin & Python 2.5 In-Reply-To: References: Message-ID: <4a23f0d6$0$7169$9b622d9e@news.freenet.de> > I think this is an issue that probably needs to be addressed by PIL > maintainers that fully understand the root of the problem (and it > should probably go in the PIL FAQ), but in the meantime does anyone > out there know how to get around this issue? Why do you need to use Cygwin Python? Regards, Martin From nick at craig-wood.com Mon Jun 1 11:29:44 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 01 Jun 2009 10:29:44 -0500 Subject: Ah, ctypes References: Message-ID: Lawrence D'Oliveiro wrote: > I wrote some code months ago to output 1-bit-per-pixel PNG files from > Python, doing direct calls to libpng using ctypes, because PIL didn't give > me sufficient control over colour tables and pixel depths. > > I thought the code was working fine. I left it aside for some months, came > back to it a week or two ago, and found it was crashing. I was creating > CFUNCTYPE objects to do callbacks to my own I/O routines [snip] > Make sure you keep references to CFUNCTYPE objects as long as they are > used from C code. ctypes doesn?t, and if you don?t, they may be garbage > collected, crashing your program when a callback is made. > > Yup, that was it. I changed my installation of the callbacks from [snip] As a ctypes user I found this an interesting story - thanks for posting it! ctypes could potentially note that function types don't have enough references to them when passed in as arguments to C functions? It might slow it down microscopically but it would fix this problem. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From martin.hellwig at dcuktec.org Mon Jun 1 11:50:02 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 01 Jun 2009 16:50:02 +0100 Subject: subprocess and win32security.ImpersonateLoggedOnUser In-Reply-To: References: <32e43bb70906010606s72c21e6bn4dfca4557fdcb3f9@mail.gmail.com> <4A23D9E7.1080700@timgolden.me.uk> <32e43bb70906010645k6efac486w147d8de2399a6ae0@mail.gmail.com> <4A23DFC1.6070209@timgolden.me.uk> Message-ID: <-OidnR8Bs7AtZb7XnZ2dnUVZ8jydnZ2d@bt.com> Emin.shopper Martinian.shopper wrote: >> The source for subprocess just uses CreateProcess. Which means that, >> short of monkey-patching it, you're going to have to roll your own >> subprocess-like code (I think). Basically, you'll need to run >> CreateProcessAsUser or CreateProcessAsLogonW. They're both a bit >> of a pig in terms of getting the right combination of parameters >> and privileges, > > Thanks. I tried rolling my own via CreateProcessAsUser but it > complained about needing some special permissions so its probably not > going to work. I'd like to try CreateProcessAsLogonW but can't see how > to access that via python. I will start a new thread on the > python-win32 list about that. > > Thanks, > -Emin Maybe this post on my blog http://blog.dcuktec.com/2009/05/python-on-windows-from-service-launch.html can be of some help for you, although it was more thought to run under LocalSystem instead of another active user. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From Scott.Daniels at Acm.Org Mon Jun 1 11:53:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 08:53:57 -0700 Subject: BMP32 for linux In-Reply-To: References: Message-ID: Djames Suhanko wrote: > Hello, all! > Did you know the bmp32 module for linux? This module can to load bmp > image with alpha channel where is not supported others images formats. Hmmm, why do you think PNG and TGA do not support alpha? --Scott David Daniels Scott.Daniels at Acm.Org From martin at v.loewis.de Mon Jun 1 12:13:39 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 01 Jun 2009 18:13:39 +0200 Subject: Problem building 64-bit python 2.6.2 on Solaris 10 In-Reply-To: <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> Message-ID: <4a23fe33$0$20453$9b622d9e@news.freenet.de> > Ok, so it looks like the only option here is to use LD_LIBRARY_PATH. Not really: there is also crle, and LD_RUN_PATH. Regards, Martin From pruebauno at latinmail.com Mon Jun 1 12:19:59 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 1 Jun 2009 09:19:59 -0700 (PDT) Subject: Illegal seek with os.popen Message-ID: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Should I open a bug report for this? Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') >>> Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> os.popen('cat','w') Traceback (most recent call last): File "", line 1, in File "/Python-3.1rc1/Lib/os.py", line 641, in popen return _wrap_close(io.TextIOWrapper(proc.stdin), proc) IOError: [Errno 29] Illegal seek >>> From djames.suhanko at gmail.com Mon Jun 1 12:40:14 2009 From: djames.suhanko at gmail.com (Djames Suhanko) Date: Mon, 1 Jun 2009 13:40:14 -0300 Subject: BMP32 for linux In-Reply-To: References: Message-ID: Thank you for answer, Scott ! The python in my embbeded system have not support to others formats. :-( Then, I found a tip about bmp32 with alpha channel, but I don't have this module (bmp32) in Ubuntu. I'm using the cx_Freeze to compile my program, but when I put them in my embbeded system, the png images aren't supported anymore. I did use of pygame.image.get_extended() function. In my desktop it return 1, but when put in my system, this function returns 0. Do you have some tip more? Thank you again!! On Mon, Jun 1, 2009 at 12:53 PM, Scott David Daniels wrote: > Djames Suhanko wrote: >> >> Hello, all! >> Did you know the bmp32 module for linux? This module can to load bmp >> image with alpha channel where is not supported others images formats. > > Hmmm, why do you think PNG and TGA do not support alpha? > > --Scott David Daniels > Scott.Daniels at Acm.Org > -- > http://mail.python.org/mailman/listinfo/python-list > -- Djames Suhanko LinuxUser 158.760 From kiran-siddiqui at hotmail.com Mon Jun 1 12:50:50 2009 From: kiran-siddiqui at hotmail.com (Kiran Siddiqui) Date: Mon, 1 Jun 2009 21:50:50 +0500 Subject: No subject Message-ID: hi have to parse a very complex dumps(whatever it is), i have done the parsing thruogh python.since the parsed data is very huge in amount, i have to feed it in the database (SQL), I have also done this... now the thing is i have to compare the data now present in the sql. in actual i have to compare the data of 1st dump with the data of the 2nd dump..... the both dump have the same fields(attributes) but the values of their field may be change... so i have to detect this change.. for this i have to do the comparison... i.e, let i have a tableA ,its 1st row carry the data of dump1 and then on the 2nd day the data comes from dump2 go into the next row of tableA. and i have to compare both rows. but i dont have the idea how to do this all using python as my front end. plz plzzzz anyone help me:( _________________________________________________________________ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/products/events.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From seattlehanks at yahoo.com Mon Jun 1 13:08:50 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 10:08:50 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <433738df-e6d3-4c77-bf06-c46958002173@h2g2000yqg.googlegroups.com> Message-ID: <197458b7-ff38-4ad7-b265-f76ccba689f7@t10g2000vbg.googlegroups.com> On Jun 1, 12:18?am, Lie Ryan wrote: > LittleGrasshopper wrote: > > On May 31, 2:03 pm, a... at pythoncraft.com (Aahz) wrote: > >> In article , > > >> LittleGrasshopper ? wrote: > >>>> On May 31, 12:19=A0am, Arnaud Delobelle wrote: > >>>>> [1]http://www.python.org/download/releases/2.2.3/descrintro/ > >>> I'm about 2/3 of the way through this paper (although I don't claim to > >>> understand all of it.) There is some heavy duty material in there, > >>> enough to make me feel really stupid and frustrated at times. I'm > >>> making connections as I go though, hopefully everything will sink in > >>> eventually. > >>> Is this stuff actually tough, or am I just a dummy? > >> Definitely tough! ?Metaclasses can cause dain bramage. > >> -- > >> Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > >> my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- > >> ? ? on-a-new-machine-ly y'rs ?- tim > > > Good to know, I'll stick to it and persevere. Will check doctor > > regularly for dain bramage though. > > Fortunately python makes it rare that we actually need to use metaclass. > Especially with class decorators and such... > > With that said, the rare cases where it is really needed; brain > hemorrhage is not only possible but when. Lie, I understand what you mean about metaclasses not being something that everybody needs to master on an everyday basis. Unfortunately, I'm the type of person that has to know how things work. I consider this an unfortunate defect, due to the fact that I am unable to compromise and let go even when practical considerations would dictate that is the appropriate course of action. I'm going to stick with this. I haven't even read the official Reference manual, so maybe I'm getting ahead of myself though. My plans are to read the reference manual, then selected parts of the library manual, and take it from there. From Scott.Daniels at Acm.Org Mon Jun 1 13:12:03 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 10:12:03 -0700 Subject: BMP32 for linux In-Reply-To: References: Message-ID: (1) Please don't top post; it is not the norm here. Re-arrange and prune as I've done below. Djames Suhanko wrote: > wrote: >> Djames Suhanko wrote: >>> Hello, all! >>> ... the bmp32 module for linux? This module can to load bmp image >>> with alpha channel where is not supported others images formats. >> Hmmm, why do you think PNG and TGA do not support alpha? > The python in my embbeded system have not support to others formats. :-( > Then, I found a tip about bmp32 with alpha channel, but I don't have > this module (bmp32) in Ubuntu. Sounds like this might be a capability problem on your embedded system. Look for and install PIL (the Python Imaging Library). It might help if you are not simply running up against hardware issues. --Scott David Daniels Scott.Daniels at Acm.Org From seattlehanks at yahoo.com Mon Jun 1 13:18:22 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 10:18:22 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> Message-ID: <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> On Jun 1, 12:42?am, Michele Simionato wrote: > On May 31, 2:32?am, LittleGrasshopper wrote: > > > Seriously, metaclasses are making my brain hurt. How do people like > > Michele Simionato and David Mertz figure these things out? Does it all > > come to looking at the C source code for the CPython interpreter? > > Actually I never looked at the C source code. I performed lots of > experiments > and figured things out the hard way, with trial and errors. > Metaclasses > are not that hard, descriptors and super were much harder to grasp at > that > time, since there was next to zero documentation and a set of subtle > bugs. > For descriptors now there is Raymond Hettinger essay and for super > there are my blog posts > on Artima:http://www.artima.com/weblogs/index.jsp?blogger=micheles&start=45&thR... > (there are also two posts of mine about metaclasses in Python 3.0 that > you may want to > read) > > HTH, > > ? ? ? ? ? ? Michele I have to thank you for all the invaluable materials you have provided to the python community. The process that you followed must have been incredibly arduous. A while back I gathered a lot of papers, many of which you either authored or co-authored, and they have been a great help. Just yesterday I went through your paper on the MRO on the advice of Carl Banks, and it absolutely clarified how the C3 MRO rules work. Once you understand how the MRO works it is actually quite intuitive, and your paper helped me understand this. Thanks for pointing your Artima papers on super(). A few days ago I hit a brick wall due to the terminology used regarding "bound" and "unbound" super objects, so I went on a search for suitable materials, and of course I found your papers on super(). I skimmed through them enough to understand the issues that were escaping me at the moment, but I intend to go through them completely at some point. It was quite fortunate that your papers acted as a catalyst for the change of the official documentation on super() in 2.6. The original documentation was very misleading. As you mentioned, Raymond Hettinger paper on descriptors is excellent as well, and I highly recommend it. Regards, Lukas From goldwamh at slu.edu Mon Jun 1 13:19:19 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Mon, 1 Jun 2009 12:19:19 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> Message-ID: <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Chris, Thanks for your well-written reply. Your analogy to the complexities of other special methods is well noted. I'll accept the "small price for flexibility" that you note, if necessary. However, I still desire a cleaner solution. I can examine the inherited slots to see which special methods are there, and to implement my own __deepcopy__ accordingly. But to do so well seems to essentially require reimplementing the complicated logic of the copy.deepcopy function. That is, if my new class is the first to be implementing an explicit __deepcopy__ function, I seem to have no easy way to invoke the inherited version of "deepcopy(self)". I wonder if the logic inherent in the copy.deepcopy function could instead be implemented directly within object.__deepcopy__ (rather than the current model in which object does not have __deepcopy__). Then I would always have a means for simulating a call to deepcopy(self) based upon the super.__deepcopy__ logic. I wouldn't be surprised if I'm overlooking some undesirable consequence of such a major change in the model, but I don't see one upon first thought. Michael On Monday June 1, 2009, Gabriel Genellina wrote: > In general, you have to know whether A implements __deepcopy__ or not. > This is a small price for the flexibility (or anarchy) in the copy/pickle > interfases: there are several ways to implement the same thing, and you > have to know which one your base class has chosen in order to extend it. > > The following is a possible implementation that doesn't use __init__ at > all, so their different signature is not an issue: > > # class A: > def __deepcopy__(self, memo={}): > dup = type(self).__new__(type(self)) > dup.__aTag = self.__aTag > dup.__aList = copy.deepcopy(self.__aList, memo) > dup.__aList.reverse() > return dup > > # class B: > def __deepcopy__(self, memo={}): > dup = A.__deepcopy__(self, memo) > dup.__bTag = self.__bTag > dup.__bList = copy.deepcopy(self.__bList, memo) > return dup > > Note that A.__deepcopy__ does two things: a) create a new, empty, > instance; and b) transfer state. B.__deepcopy__ handles *its* portion of > state only. This can be written in a more generic way, relying on > __getstate__/__setstate__ (the methods that should return the current > state of the object): > > # class A: > def __deepcopy__(self, memo={}): > dup = type(self).__new__(type(self)) > if hasattr(self, '__getstate__'): state = self.__getstate__() > else: state = self.__dict__ > state = copy.deepcopy(state, memo) > if hasattr(dup, '__setstate__'): dup.__setstate__(state) > else: dup.__dict__.update(state) > dup.__aList.reverse() > return dup > > # remove __deepcopy__ definition from class B > > Now, B (and any other subclass) is concerned only with __getstate__ / > __setstate__, and only when the default implementation isn't appropriate. > > > As another basic puzzle, consider a class definition for B where B has > > a registry list that it doesn't want cloned for the new instance (but > > it does want pickled when serialized). This would seem to require > > that B implement its own __deepcopy__. We want to somehow rely on > > the class definition for A to enact the cloning fo the state defined > > by A. But without knowing about how A supports the deepcopy > > semantics, I don't see how to accomplish this goal. > > I don't understand such bizarre requirement, but anyway, you can override > __deepcopy__ (make B fix only the part that the default implementation > doesn't implement well) > > # A.__deepcopy__ as above > > # class B: > def __deepcopy__(self, memo={}): > dup = A.__deepcopy__(self, memo) > dup.__registry = self.__registry > return dup > > This [the need to know how certain feature is implemented in the base > class] is not special or peculiar to pickle/copy, although the multiple > (and confusing) ways in which a class can implement pickling doesn't help > to understand the issue very well. > > Consider the + operator: when some subclass wants to implement addition, > it must know which of the several special methods involved (__add__, > __iadd__, __radd__) are implemented in the base class, in order to > extend/override them. Same for __cmp__/__eq__/__hash__: you can't just > ignore what your base class implements. All of this applies to other > languages too, but in Python, there is an additional consideration: the > mere *existence* of some methods/attributes can have consequences on how > the object behaves. In short, you can't blindly write __special__ methods. > > -- > Gabriel Genellina From albert at spenarnc.xs4all.nl Mon Jun 1 13:46:19 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Jun 2009 17:46:19 GMT Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: In article , Roy Smith wrote: >In article , > Bar Shirtcliff wrote: > >> I can't say a thing about other editors, except that when some shell >> script perversely dumped me into vi a month ago, I felt as horrified >> as if some actually living bugs had crawled out of my own reflection >> on the computer screen and fallen, clicking and scraping, onto the >> keyboard. That's a personal reaction - totally irrelevant, of course. > > : q ! Make that : q ! >All the vi you ever need to know :-) Now some kind soul give a similar sequence for emacs. > >The real problem is when you get dumped into some editor other than you one >you expected and don't realize it for a while. It's really amazing how >much damage you can do to a file by typing (for example) emacs commands at >vi. Especially if you accidentally stumble upon the sequence for "save >file". Exactly. An indication of how one can see one is in emacs is also appreciated. [Especially insidious is helpful help that lands you in emacs-ing help file for powerful searching (not!).] Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Mon Jun 1 13:53:57 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 01 Jun 2009 17:53:57 GMT Subject: What text editor is everyone using for Python References: Message-ID: In article , Lawrence D'Oliveiro wrote: >In message , Lie Ryan wrote: > >> norseman wrote: >> >>> Suggestion: >>> Take a look at the top two most used OS you use and learn the default >>> (most often available) text editors that come with them. >> >> Which means Notepad on Windows? > >Or you could take a Linux preinstallation on a Live CD/DVD or USB stick. >There's no Windows system so brain-dead it can't be fixed with a simple >ctrl-alt-del. :) > You can carry vim (or Edwin's editor for that matter) on a FAT stick. (As they say: "Speak softly, and carry a large stick.") Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From michele.simionato at gmail.com Mon Jun 1 14:11:02 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Jun 2009 11:11:02 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> Message-ID: <4ffc2806-9d57-40ce-ba25-9841be8a6c71@t21g2000yqi.googlegroups.com> On Jun 1, 7:18?pm, LittleGrasshopper wrote: > I have to thank you for all the invaluable materials you have provided > to the python community. The process that you followed must have been > incredibly arduous. *Incredibly ardous* is an exaggeration, but in the case of the MRO I needed to do some work of reverse engineering in order to go from code (which was posted by Samuele Pedroni on python-dev http://mail.python.org/pipermail/python-dev/2002-October/029176.html) to the rules and to figure out the algorithm. Anyway, there are things much more complicated than the C3 algorithm or metaclasses, nowadays I am fighting with the Scheme module system and I know what I am talking about ;-) From Scott.Daniels at Acm.Org Mon Jun 1 14:13:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 01 Jun 2009 11:13:22 -0700 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> Message-ID: Michael H. Goldwasser wrote: > Chris, > > Thanks for your well-written reply. Your analogy to the > complexities of other special methods is well noted. I'll accept > the "small price for flexibility" that you note, if necessary. > However, I still desire a cleaner solution. You seem to think that "deepcopy" is a well-defined concept. It is not and cannot be. A copy that understands its own abstractions can work, but sometimes a container is used as a simple abstraction, and sometimes it is used as a container. The choice between the two is not one of structure, but one of intent. A true deepcopy could survive making a copy of the number 23, but might fail as it makes a copy of None, True, or False. Certainly a dictionary might or might not be copied, depending on how the dictionary is used. --Scott David Daniels Scott.Daniels at Acm.Org From seattlehanks at yahoo.com Mon Jun 1 14:21:26 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 11:21:26 -0700 (PDT) Subject: Metaclass mystery References: <31ff6dcb-7dce-4262-a834-a81196b33bbe@w40g2000yqd.googlegroups.com> <179d61c7-0834-4eb1-b0ce-6e191353702e@k2g2000yql.googlegroups.com> <43be1b12-3356-42e7-920c-cf87668f7e64@n4g2000vba.googlegroups.com> <4ffc2806-9d57-40ce-ba25-9841be8a6c71@t21g2000yqi.googlegroups.com> Message-ID: On Jun 1, 11:11?am, Michele Simionato wrote: > On Jun 1, 7:18?pm, LittleGrasshopper wrote: > > > I have to thank you for all the invaluable materials you have provided > > to the python community. The process that you followed must have been > > incredibly arduous. > > *Incredibly ardous* is an exaggeration, but in the case of the MRO > I needed to do some work of reverse engineering in order to go > from code (which was posted by Samuele Pedroni on python-devhttp://mail.python.org/pipermail/python-dev/2002-October/029176.html) > to the rules and to figure out the algorithm. Anyway, there are > things much more complicated than the C3 algorithm or metaclasses, > nowadays I am fighting with the Scheme module system and I know > what I am talking about ;-) I saw that you were involved right now in Scheme/Lisp. Good luck with it! From mensanator at aol.com Mon Jun 1 14:23:35 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 11:23:35 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> Message-ID: <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> On Jun 1, 10:11?am, pataphor wrote: > Johannes Bauer wrote: > > Any help is appreciated! > > This is on the fringe of exploitation, but hey, maybe the code helps you > think about the algorithm. > > IMHO the following code is a glaring complaint about the injustice of > omission itertools inflicts on the perfectly natural and obvious > procedure of repeat_each (whatever it's name ought to be): I believe the name you're looking for is combinations_with_replacement. It is one of the features being added to 3.1 which should give all the subsets of the Cartesian Product: permutations_with_replacement: product() combinations_with_replacement: combinations_with_replacement() permutations_without_replacement: permutations() combinations_without_replacement: combinations() > > from itertools ?import izip, islice, cycle > > def repeat_each(seq,n): > ? ? ?while True: > ? ? ? ? ?for x in seq: > ? ? ? ? ? ? ?for i in range(n): > ? ? ? ? ? ? ? ? ?yield x > > def repeat_all(seq,n): > ? ? ?while True: > ? ? ? ? ?for i in range(n): > ? ? ? ? ? ? ?for x in seq: > ? ? ? ? ? ? ? ? ?yield x > > def product(X): > ? ? ?N = [] > ? ? ?total = 1 > ? ? ?for x in X: > ? ? ? ? ?N.append(total) > ? ? ? ? ?total *= len(x) > ? ? ?R = [repeat_all(repeat_each(x,k),n) > ? ? ? ? ? ? ? ? ? ? ?for x,k,n in izip(X,N,reversed(N))] > ? ? ?return islice(izip(*R),total) > > def test1(): > ? ? ?L = ['a', 'bc','def' ] > ? ? ?for x in product(L): > ? ? ? ? ?print x > ? ? ?print > > def test2(): > ? ? ?repeat_all = cycle > ? ? ?test1() > > if __name__ == '__main__': > ? ? ?test1() > ? ? ?test2() > > See? Repeat_all and repeat_each are almost brothers, just separated by > the tiniest rearrangement of their genetic code (or should I say code > genetics?). Yet one is included as 'itertools.cycle' and the other is > doomed to live in limbo. Such injustice! Can it be that > 'itertools.repeat' has usurped repeat_each's rightful position? > > P. From norseman at hughes.net Mon Jun 1 14:26:20 2009 From: norseman at hughes.net (norseman) Date: Mon, 01 Jun 2009 11:26:20 -0700 Subject: Python, Tkinter and popen problem In-Reply-To: References: Message-ID: <4A241D4C.6010700@hughes.net> Piet van Oostrum wrote: >>>>>> norseman (n) wrote: > >> n> Piet van Oostrum wrote: >>>>>>>>> norseman (n) wrote: >> n> I have tried both and Popen2.popen2(). >> n> os.popen runs both way, contrary to docs. >>>> What do you mean `os.popen runs both way'? > >> n> It reads from child while console writes directly to child - thus >> n> eliminating the problem of coding a pass through from master. > > Yes, but that is not `both way': popen connects the parent to the child > through a pipe. The pipe works one way: from the child to the parent > with 'r' (default), from the parent to the child with 'w'. You can't > communicate the other way through the pipe. So the communication from > the parent process to the child through the popen is ONE WAY. If you > want TWO WAY communication you can use popen2, or better use > subprocess.Popen. We are actually saying the same thing - you do say it better. > > A child process always inherits stdin, stdout and stderr from the parent > unless you change that (e.g. by redirecting to a pipe, like popen does > for one of them). It doesn't matter whether you use os.popen, > subprocess.Popen, os.system, or os.fork to create the child process. So > in your case if the parent inputs from the console, so does the child. > But note: this is not communication from the parent process to the > child, but from YOU to the child. So the parent-child communication is > ONE WAY. > >> n> "... >>>> doesn't work as the iterator for a file, including pipes, does a >>>> read ahead (see the doc on file.next()) and therefore is not suitable >>>> for interactive use. >> n> ..." > >> n> If I understand you the above can be stated as: > >> n> The above does not work as an iterator for any file type, including >> n> pipes, but it does do read aheads .... and therefore is not suitable for >> n> interactive use. > > For files in general it is no problem because the contents of the file > is not interactively generated. Read ahead on a file works as long as > you do'nt use readline() on the file in between the iterator actions. > For a socket it could be the same problem if the other side generates > the output interactively. > >> n> If that is correct then read ahead is simply buffered file reads (grab a >> n> chunk, parcel it out on demand) - yes? > > I don't know, I have looked into the source code but it isn't clear to > me. I noticed that iteration didn't work and then looked up the > documentation. It talks about read ahead for efficiency. > >> n> As for "... not suitable for interactive ..." Really? Except for >> n> special purpose use the current interactive components are all buffered >> n> for read ahead use. Check the actual code for your keyboard, your mouse >> n> and so forth. It's the read ahead that allows faster time to completion. >> n> It's why C-code has the putch function. > > Yes, but they only read what is available. The iterator apparently tries > to read more and then has to wait. In actuality the read ahead does 'run off the end' and then waits. Specifics are coder dependent. But I think I understand what you mean. It may not be treating the incoming buffer as circular. That could explain a few things I'm seeing. > >> n> Yes - Sync IS the bigger hammer! If that is what is needed - so be it. >> n> All character readers (byte at a time) should obey a flush(). Depending >> n> on type, code for the reader controls whether or not it flushes >> n> incomplete "lines" in the in-buffer(s). Proper implementation limits lost >> n> data on system crash. > > I don't understand what you say here. As I told before it has nothing to > do with sync(). Also for reading there is no flush(); the flush() is > done on the other side of the pipe. Yes, and sync() has to do with > system crashes but that is not what we are talking about in this thread. > The line with Sync is just a comment. Sync'ing the whole system just to force a singular flush is not a good way to proceed. The comment is not actually connected to the comments on readers. >> n> In trying to use flush at the master side I keep getting messages >> n> indicating strings (completed or not) are not flushable. Strange practice. > > If you print to the console in the master the flush is done > automatically. The symptoms have been otherwise. Going back to your comments on iterators not proceeding with 'in-line' processing but rather holding onto the bytes until later would give the effect of flush not working. > >> n> --- >> n> from subprocess import Popen, PIPE >> n> xx = Popen(["z6.py"], stdout=PIPE).stdout > >> n> while True: >> n> line = xx.readline() >> n> if not line: break >> n> print "\t" + line, >> n> --- >> n> DOES WORK on Python 2.5.2 on Slackware 10.2 - THANK YOU VERY MUCH!!! >> n> Isn't working on Windows. error message comes as one of two forms. >> n> 1- %1 not found #as shown above >> n> 2- file not found #as ...["python z6.py"]... >> n> same #as #2 even with full paths given > > That should be Popen(["python", "z6.py"], stdout=PIPE).stdout > And then with both python and z6.py given as full paths. > >> n> I get the impression subprocess ignores system things on Windows. >> n> The routines it purposes to replace do use them. At any rate, subprocess >> n> is NOT consistent across platforms. > > subprocess is, but Windows isn't. On Unix-like systems, the python > command is usually in your PATH, so just giving "python" works. In > Windows PATH is underused, and commands like python often are not in > PATH, unless you as a user has adapted the path, or maybe there is an > installation option to adapt the PATH. The reason probably is that in > Windows almost nobody uses the command line but only clicks and the PATH > is not relevant. "The reason" most certainly "is ...." Yep!! Technically - the path is passed as part of the click, but since it is transparent it is easy to forget its presence. > >> n> Some questions: >> n> 1) "...], stdout=PIPE).stdout >> n> ^ ^ why the double use? > > It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen > object, not a file object. If you add .stdout you get the stdout > attribute of the Popen object of which you just before stated that it > should be a pipe. So the stdout=PIPE parameter makes it create a pipe, > and the .stdout returns you that pipe. > I rather thought it might be something like the military: Company - Dress Right - Dress Get the attention, state what is to be done, order it done. :) Python goes to great lengths to "be helpful" but drops the ball on the obvious. stdout=PIPE means the user wants stdout piped back so it should be helpful and do the obvious rather than have the user be redundant. Subprocess - run file - redirect stdout - run redirected ^ redundant :) Subprocess - run I/O redirected file - (closing ')' means) run 1 percent of 100 characters typed is 1 (error). 1 percent of 10,000 characters typed is 100 (errors, minimum, not factoring in fatigue) The more the typing the more the errors and the longer to completion. The less specific the verb, the more the research. >> n> 2) "if not line: break" what tells what to look for EOL >> n> or is the use of 'line' missleading? >> n> is it a byte at a time output? > > No, line is a line, as indicated by the readline() call. The > "if not line" is a test for end of file. In this case the end of the > child process (pipe closed). Got it - that helps! > >> n> how much CPU usage does the loop use? > > Not much, It is mainly waiting for input but that doesn't consume CPU. > >> n> is there something in that loop that >> n> uses the system pipe triggers to >> n> reduce excessive CPU waste or does it >> n> constantly poll? If so where does >> n> what code get put to signal (or set) >> n> the courtesy semiphores so it does >> n> not hog the system? > > It doesn't poll or use semaphores. The beauty of a pipe is that it > automatically synchronises the reader and writer processes. If you do a > read on a pipe and it is empty the OS just blocks you. When the other > end writes something in the pipe, the OS will unblock you. > Unless the OS is using interrupts to signal things - looping is expensive. Yes - interrupts are NOT a good idea for general computing software. The use of interrupts is especially bad in multi-user, multi-tasking environments. The way you stated the process indicates a loop and thus the program is removed from the processing list until the unblock re-instates processing. Some clarity- Interrupts halt all processing until released. They effectively knock the system unconscious until released. Process polling creates an entry in the circular cue for switching the program pointer (and associated registers and maybe memory paging) to the next 'running' process so it gets it's slice of execution time. The effect of multi-processing is realized but the CPU only executes one program at a time, in intermixed pieces. The time slice is the gain. Different processes can have different lengths of run time. Instructions are ignored except during their time slice. Then the current is put on hold and the next in list is run for it's time slice. So if process polling is used and and the program is frozen at the readline that would explain why the program apparently freezes. In fact it does. Master has readline, readline is frozen so master is frozen. Keyboard instructions to child are not passed to child because master is frozen. Thus keyboard 'continue' isn't transmitted, but CTRL-C (tell OS to crash program) is intercepted by OS. GUI interface is separate so mouse clicks still work and at crash (end program) the buffers are dumped. Facts all fit. Solution to problem: 1) read byte at a time from pipe, compositing my own string 2) send self/test for EOD to exit loop, preventing endless loop. Old School - but it works unless Python screws up byte by byte reads. Piet - Thanks for the help. Steve From lh at google.com Mon Jun 1 14:27:41 2009 From: lh at google.com (Leslie Hawthorn) Date: Mon, 1 Jun 2009 11:27:41 -0700 Subject: Not going to let this drop ... In-Reply-To: <4A235A7D.4020507@holdenweb.com> References: <4A235A7D.4020507@holdenweb.com> Message-ID: <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> On Sun, May 31, 2009 at 9:35 PM, Steve Holden wrote: > I don't know if Google are planning to run a Highly-Open Participation > event this year, but if they are then maybe we could establish a few > tasks for that. > We are planning to do so in Q4 of this year, further details TBD. I'll make sure Titus Brown is in the loop when we get started planning so he can point me to the right folks who'd like to help with the PSF's participation in GHOP this year. Cheers, LH -- Leslie Hawthorn Program Manager - Open Source Google Inc. http://code.google.com/opensource/ I blog here: http://google-opensource.blogspot.com - http://www.hawthornlandings.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From 2myemailaddress at gmail.com Mon Jun 1 14:45:04 2009 From: 2myemailaddress at gmail.com (babypython) Date: Mon, 1 Jun 2009 11:45:04 -0700 (PDT) Subject: Parsing Data Message-ID: <23820003.post@talk.nabble.com> I am trying to parse through this data for analysis. I am new to python and wondering what would be the quickest way to extract the data from this file. The data files consists of comments (starting with ! and #). Then, the data follows. All I want is the data in array ( I don't care about the comments),and the data format is freq[], s11[real], s11[imag], s21[real],s21[imag] Any help will be appreciated. Thanks. !Date: Jan 29, 2008 14:40:26 !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) !Measurements: S11, S21: ! Freq S11[real, imag] S21[real,imag] 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 -- View this message in context: http://www.nabble.com/Parsing-Data-tp23820003p23820003.html Sent from the Python - python-list mailing list archive at Nabble.com. From python at mrabarnett.plus.com Mon Jun 1 14:48:53 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Jun 2009 19:48:53 +0100 Subject: Python, Tkinter and popen problem In-Reply-To: <4A241D4C.6010700@hughes.net> References: <4A241D4C.6010700@hughes.net> Message-ID: <4A242295.1040704@mrabarnett.plus.com> norseman wrote: > Piet van Oostrum wrote: >> norseman (n) wrote: [snip] >>> n> Some questions: >>> n> 1) "...], stdout=PIPE).stdout >>> n> ^ ^ why the double use? >> >> It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen >> object, not a file object. If you add .stdout you get the stdout >> attribute of the Popen object of which you just before stated that it >> should be a pipe. So the stdout=PIPE parameter makes it create a pipe, >> and the .stdout returns you that pipe. >> > > I rather thought it might be something like the military: > Company - Dress Right - Dress > Get the attention, state what is to be done, order it done. :) > > Python goes to great lengths to "be helpful" but drops the ball on the > obvious. stdout=PIPE means the user wants stdout piped back so it > should be helpful and do the obvious rather than have the user be > redundant. > What if the user requests both stdin and stdout? and what about all the other useful bits which the returned object provides? From db3l.net at gmail.com Mon Jun 1 14:51:04 2009 From: db3l.net at gmail.com (David Bolen) Date: Mon, 01 Jun 2009 14:51:04 -0400 Subject: Ah, ctypes References: Message-ID: Nick Craig-Wood writes: > ctypes could potentially note that function types don't have enough > references to them when passed in as arguments to C functions? It > might slow it down microscopically but it would fix this problem. Except that ctypes can't know the lifetime needed for the callbacks. If the callbacks are only used while the called function is executing (say, perhaps for a progress indicator or internal completion callback) then it's safe to create the function wrapper just within the function call. -- David From steve at holdenweb.com Mon Jun 1 14:51:53 2009 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Jun 2009 14:51:53 -0400 Subject: Not going to let this drop ... In-Reply-To: <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> References: <4A235A7D.4020507@holdenweb.com> <4869cee70906011127h3f4787d8la1018ee9b558c862@mail.gmail.com> Message-ID: <4A242349.9070606@holdenweb.com> Leslie Hawthorn wrote: > > > On Sun, May 31, 2009 at 9:35 PM, Steve Holden > wrote: > > I don't know if Google are planning to run a Highly-Open Participation > event this year, but if they are then maybe we could establish a few > tasks for that. > > > We are planning to do so in Q4 of this year, further details TBD. I'll > make sure Titus Brown is in the loop when we get started planning so he > can point me to the right folks who'd like to help with the PSF's > participation in GHOP this year. > Thanks for letting me know. I am sure the PSF will be delighted to pitch in, and Titus will be an entirely satisfactory first point of contact. Hope you are well. Good to hear from you. Won't be at OSCON this year, but maybe next year. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Watch PyCon on video now! http://pycon.blip.tv/ From goldwamh at slu.edu Mon Jun 1 15:02:06 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Mon, 1 Jun 2009 14:02:06 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: <18980.9646.476988.35123@Michael-Goldwassers-Computer.local> On Monday June 1, 2009, Scott David Daniels wrote: > Michael H. Goldwasser wrote: > > Chris, > > > > Thanks for your well-written reply. Your analogy to the > > complexities of other special methods is well noted. I'll accept > > the "small price for flexibility" that you note, if necessary. > > However, I still desire a cleaner solution. > > You seem to think that "deepcopy" is a well-defined concept. It is > not and cannot be. A copy that understands its own abstractions can > work, but sometimes a container is used as a simple abstraction, and > sometimes it is used as a container. The choice between the two is > not one of structure, but one of intent. A true deepcopy could > survive making a copy of the number 23, but might fail as it makes > a copy of None, True, or False. Certainly a dictionary might or > might not be copied, depending on how the dictionary is used. > > --Scott David Daniels > Scott.Daniels at Acm.Org Hi Scott, It is clear from my original statement of the question that there is a need for classes to be able to customize their own semantics for supporting the deepcopy function. That is why the deepcopy function looks for a __deepcopy__ method within a class as a hook. My concern involves the challenge of providing a valid implementation for __deepcopy__ at one level of inheritance without being overly dependent on the internal mechanism used by ancestor classes in supporting deepcopy. I don't see how your comments address that question. Michael From clp2 at rebertia.com Mon Jun 1 15:10:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 12:10:21 -0700 Subject: Parsing Data In-Reply-To: <23820003.post@talk.nabble.com> References: <23820003.post@talk.nabble.com> Message-ID: <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> On Mon, Jun 1, 2009 at 11:45 AM, babypython <2myemailaddress at gmail.com> wrote: > > I am trying to parse through ?this data for analysis. I am new to python and > wondering what would be the quickest way to extract the data from this file. > The data files consists of comments (starting with ! and #). Then, the data > follows. All I want is the data in array ( I don't care about the > comments),and the data format is ?freq[], s11[real], s11[imag], > s21[real],s21[imag] > > ?Any help will be appreciated. Thanks. > > > !Date: Jan 29, 2008 14:40:26 > !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) > !Measurements: S11, S21: > ! Freq ?S11[real, imag] ?S21[real,imag] > 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 > 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 > 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 > 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 > 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 > 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 > 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 > 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 > 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 > 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 > 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 #completely untested data = [] for line in the_file: if line.startswith("!"): continue fields = line.strip().split() datapoint = [int(fields[0]), complex(float(fields[1]), float(fields[2])), complex(float(fields[3]), float(fields[4]))] data.append(datapoint) Cheers, Chris -- http://blog.rebertia.com From nathan.charles.summer at gmail.com Mon Jun 1 15:16:06 2009 From: nathan.charles.summer at gmail.com (nathan.charles.summer at gmail.com) Date: Mon, 1 Jun 2009 12:16:06 -0700 (PDT) Subject: How can I install a newer version of python Message-ID: I am on MacOS 10.5. It has python 2.5.1 installed. How can I install a newer version of python (e.g. 3.1) without breaking my current environment (I am not sure what programs/scripts are using the python comes with MacOS). I just want to use the newer version of python for my own project. I found this "http://wiki.python.org/moin/MacPython/Leopard", but i have no idea what that is related to my situation. Thank you for any tip. From clp2 at rebertia.com Mon Jun 1 15:34:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 12:34:07 -0700 Subject: How can I install a newer version of python In-Reply-To: References: Message-ID: <50697b2c0906011234sf3b95eev3f4a6fce2a12ed25@mail.gmail.com> On Mon, Jun 1, 2009 at 12:16 PM, nathan.charles.summer at gmail.com wrote: > I am on MacOS 10.5. It has python 2.5.1 installed. > > How can I install a newer version of python (e.g. 3.1) without > breaking my current environment (I am not sure what programs/scripts > are using the python comes with MacOS). I just want to use the newer > version of python for my own project. > > I found this "http://wiki.python.org/moin/MacPython/Leopard", but i > have no idea what that is related to my situation. > > Thank you for any tip. I think you can just use the normal Mac installer from http://www.python.org/download/. As it says on http://wiki.python.org/moin/MacPython/Leopard, this doesn't clobber the default Apple Python install. Cheers, Chris -- http://blog.rebertia.com From david at boddie.org.uk Mon Jun 1 16:05:18 2009 From: david at boddie.org.uk (David Boddie) Date: Mon, 01 Jun 2009 22:05:18 +0200 Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On Monday 01 June 2009 16:16, dudekksoft at gmail.com wrote: > On 31 Maj, 02:32, David Boddie wrote: >> So, you only want to handle certain links, and pass on to WebKit those >> which you can't handle? Is that correct? > > Yes, I want to handle external links (out of my host) and links > starting with download://... (my specific protocol). If you want to handle them in a different way to normal Web pages, it seems that calling setForwardUnsupportedContent(True) on the QWebPage is the way to do it. However, if you want to handle those links and present the content for the browser to render then you may need to override the browser's network access manager, as discussed in this message: http://lists.trolltech.com/pipermail/qt-interest/2009-March/004279.html I experimented a little and added an example to the PyQt Wiki: http://www.diotavelli.net/PyQtWiki/Using a Custom Protocol with QtWebKit I hope it helps to get you started with your own custom protocol. David From ubuntu.exe at gmail.com Mon Jun 1 16:21:23 2009 From: ubuntu.exe at gmail.com (ubuntu.exe at gmail.com) Date: Mon, 1 Jun 2009 13:21:23 -0700 (PDT) Subject: screen scraping Message-ID: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> Hello, does anybody have a simple tutorial for screen scrapping? I want to extract IP addresses from particular web page, reading documentation for a couple of days and writing some really simple scripts, but cant get it to work. Did anybody see any manual explicittly for screen scraping? Thanks. From 2myemailaddress at gmail.com Mon Jun 1 16:29:00 2009 From: 2myemailaddress at gmail.com (babypython) Date: Mon, 1 Jun 2009 13:29:00 -0700 (PDT) Subject: Parsing Data In-Reply-To: <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> References: <23820003.post@talk.nabble.com> <50697b2c0906011210h5ab4fe6bxd3e13b339cfe1454@mail.gmail.com> Message-ID: <23821445.post@talk.nabble.com> Thanks a lot. That works for me. Chris Rebert-6 wrote: > > On Mon, Jun 1, 2009 at 11:45 AM, babypython <2myemailaddress at gmail.com> > wrote: >> >> I am trying to parse through ?this data for analysis. I am new to python >> and >> wondering what would be the quickest way to extract the data from this >> file. >> The data files consists of comments (starting with ! and #). Then, the >> data >> follows. All I want is the data in array ( I don't care about the >> comments),and the data format is ?freq[], s11[real], s11[imag], >> s21[real],s21[imag] >> >> ?Any help will be appreciated. Thanks. >> >> >> !Date: Jan 29, 2008 14:40:26 >> !Correction: S11(Full 2 Port(1,2)) S21(Full 2 Port(1,2)) >> !Measurements: S11, S21: >> ! Freq ?S11[real, imag] ?S21[real,imag] >> 1400000000 -2.104572e+001 4.153887e+001 -4.084314e+001 8.417739e+001 >> 1400250000 -2.089971e+001 4.028599e+001 -4.087196e+001 7.026196e+001 >> 1400500000 -2.114216e+001 4.086434e+001 -4.055134e+001 6.559201e+001 >> 1400750000 -2.112057e+001 3.681709e+001 -4.024515e+001 5.503412e+001 >> 1401000000 -2.110984e+001 3.622524e+001 -4.056519e+001 5.162795e+001 >> 1401250000 -2.123562e+001 3.602308e+001 -4.125660e+001 4.330296e+001 >> 1401500000 -2.152193e+001 3.345480e+001 -4.035107e+001 3.937940e+001 >> 1401750000 -2.144410e+001 3.189340e+001 -4.097492e+001 2.802726e+001 >> 1402000000 -2.155891e+001 3.002732e+001 -4.146297e+001 1.666007e+001 >> 1402250000 -2.170474e+001 2.896428e+001 -4.146934e+001 1.514847e+001 >> 1402500000 -2.185459e+001 2.863795e+001 -4.053018e+001 1.130192e+001 > > #completely untested > data = [] > for line in the_file: > if line.startswith("!"): continue > fields = line.strip().split() > datapoint = [int(fields[0]), complex(float(fields[1]), > float(fields[2])), complex(float(fields[3]), float(fields[4]))] > data.append(datapoint) > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Parsing-Data-tp23820003p23821445.html Sent from the Python - python-list mailing list archive at Nabble.com. From philr at aspexconsulting.co.nz Mon Jun 1 16:30:53 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 2 Jun 2009 08:30:53 +1200 Subject: which database is suitable for small applications In-Reply-To: References: <8ca278430905260133n3cdd12dcq667a5cdeada29e1e@mail.gmail.com> <52801358-c037-458d-8857-a78c2d881ddb@z16g2000prd.googlegroups.com> Message-ID: Hi Lawrence, I appreciate your remarks. However database engines cache their table/views to support sequential accessing within a set. With a good accessing scheme and with enough cache memory you will have all your small tables in memory. So the simplest thing is let the DBMS do its thing. The good ones will cope quite happily. You then have the advantage that the app can grow without program changes. It is a long time since I delved into DBMS internals (25 years) but I cannot see that they will have changed from what I have said above, however I am sure to be corrected if I am wrong. ;-) Cheers, phil -----Original Message----- From: Lawrence D'Oliveiro [mailto:ldo at geek-central.gen.new_zealand] Sent: Sunday, 31 May 2009 11:21 p.m. To: python-list at python.org Subject: Re: which database is suitable for small applications In message <52801358-c037-458d-8857- a78c2d881ddb at z16g2000prd.googlegroups.com>, Ankit wrote: > If your application does not require you to add very heavy data then > you can also use flat files to do your stuff. > Its always a better to use Databases ... It's not always better to use databases. By definition, data for a ?small? application is bound to fit entirely in RAM. So certainly the simplest thing to do is read a whole data file in at the start, and write the entire updated data structure back out again at the end. From kdawg44 at gmail.com Mon Jun 1 17:23:19 2009 From: kdawg44 at gmail.com (K-Dawg) Date: Mon, 1 Jun 2009 17:23:19 -0400 Subject: Urllib2 proxy settings Message-ID: <5caea3690906011423t538cbb5bg2fe02ee03bf11108@mail.gmail.com> Hello, I am having trouble with an application running on a linux server. It keeps reverting to old proxy settings and messing up the web application. I have checked everything I can think of, and since the application is written in Python and uses urllib to call a web service (which is where the error is occurring) I thought that I could open up the interpreter, import URLLib2 and then see what it thinks the proxy is. How can I just echo this in the interpreter? Thanks. Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Mon Jun 1 17:28:16 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 01 Jun 2009 23:28:16 +0200 Subject: how to get the path of a module (myself) ? Message-ID: <4A2447F0.2050905@gmail.com> hello, I've pictures stored in a path relative to my python source code. To get a picture, I need to know what path I'm on in each python module. I thought __file__ would do the job, but apparently I didn't read the documentation carefully enough, because file is the path to the module that called my module. Any ways to get the path of "myself" ? thanks, Stef Mientki From nick at craig-wood.com Mon Jun 1 17:29:44 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 01 Jun 2009 16:29:44 -0500 Subject: Ah, ctypes References: Message-ID: David Bolen wrote: > Nick Craig-Wood writes: > > > ctypes could potentially note that function types don't have enough > > references to them when passed in as arguments to C functions? It > > might slow it down microscopically but it would fix this problem. > > Except that ctypes can't know the lifetime needed for the callbacks. If > the callbacks are only used while the called function is executing (say, > perhaps for a progress indicator or internal completion callback) then > it's safe to create the function wrapper just within the function > call. Good point... However I wouldn't mind if ctypes emitted a warning or even threw an exception in this case too though as the other case is so invidious. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From david.lyon at preisshare.net Mon Jun 1 18:23:04 2009 From: david.lyon at preisshare.net (David Lyon) Date: Mon, 01 Jun 2009 18:23:04 -0400 Subject: how to get the path of a module (myself) =?UTF-8?Q?=3F?= In-Reply-To: <4A2447F0.2050905@gmail.com> References: <4A2447F0.2050905@gmail.com> Message-ID: <662715f21fdf486785783086cec9cda3@preisshare.net> On Mon, 01 Jun 2009 23:28:16 +0200, Stef Mientki wrote: > hello, > > I've pictures stored in a path relative to my python source code. > To get a picture, I need to know what path I'm on in each python module. > I thought __file__ would do the job, > but apparently I didn't read the documentation carefully enough, > because file is the path to the module that called my module. > > Any ways to get the path of "myself" ? This ain't the official way... but the hackers way..... Check site.path (import site)... If your module got loaded, and it's own succinct directory or .egg, then it will have been added to site.path. You might have to parse the values in site.path but we're only talking a few lines of code because you already know the package name. If not, there's another way through pkg_utils... Regards David From python at mrabarnett.plus.com Mon Jun 1 18:37:04 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Jun 2009 23:37:04 +0100 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A2447F0.2050905@gmail.com> References: <4A2447F0.2050905@gmail.com> Message-ID: <4A245810.4090704@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I've pictures stored in a path relative to my python source code. > To get a picture, I need to know what path I'm on in each python module. > I thought __file__ would do the job, > but apparently I didn't read the documentation carefully enough, > because file is the path to the module that called my module. > > Any ways to get the path of "myself" ? > I'm not sure what you mean. I just did a quick test. # File: C:\Quick test\child.py print "name is %s" % __name__ print "file is %s" % __file__ # File: C:\Quick test\parent.py import child print "name is %s" % __name__ print "file is %s" % __file__ # Output: name is child file is C:\Quick test\child.py name is __main__ file is C:\Quick test\parent.py From ldo at geek-central.gen.new_zealand Mon Jun 1 18:52:35 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:52:35 +1200 Subject: Ah, ctypes References: Message-ID: In message , Nick Craig- Wood wrote: > As a ctypes user I found this an interesting story - thanks for > posting it! By the way, I hate wildcard imports. In the ctypes docs, they recommend you do this from ctypes import * but I prefer this: import ctypes as ct which explains the "ct." prefixes in my sample code, in case you were wondering. From ldo at geek-central.gen.new_zealand Mon Jun 1 18:53:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:53:42 +1200 Subject: What text editor is everyone using for Python References: Message-ID: In message , Albert van der Horst wrote: > You can carry vim (or Edwin's editor for that matter) on a FAT > [USB] stick. > (As they say: "Speak softly, and carry a large stick.") I like that. :) From ldo at geek-central.gen.new_zealand Mon Jun 1 18:54:48 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 02 Jun 2009 10:54:48 +1200 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: In message , Albert van der Horst wrote: > An indication of how one can see one is in emacs is also appreciated. How about, hit CTRL/G and see if the word "Quit" appears somewhere. From seattlehanks at yahoo.com Mon Jun 1 19:05:30 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 16:05:30 -0700 (PDT) Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: On Jun 1, 2:38?am, Piet van Oostrum wrote: > >>>>> LittleGrasshopper (L) wrote: > >L> On May 31, 3:59?pm, Carl Banks wrote: > >>> On May 31, 3:52?pm, LittleGrasshopper wrote: > > >>> > This is some simple code which I got from Guido's paper on the > >>> > unification of classes and types, which Arnaud suggested to improve my > >>> > knowledge of metaclasses: > > >>> > class M1(type): > >>> > ? ? pass > >>> > class M2(M1): > >>> > ? ? pass > >>> > class M3(M2): > >>> > ? ? pass > >>> > class C1: > >>> > ? ? __metaclass__ = M1 > >>> > class C2(C1): > >>> > ? ? __metaclass__ = M2 > >>> > class C3(C1, C2): > >>> > ? ? __metaclass__ = M3 > > >>> > It is failing when processing C3: > >>> > Traceback (most recent call last): > >>> > ? File "metaerror.py", line 18, in > >>> > ? ? class C3(C1, C2): > >>> > TypeError: Error when calling the metaclass bases > >>> > ? ? Cannot create a consistent method resolution > >>> > order (MRO) for bases C2, C1 > > [snip] > > >L> I guess the resulting MROs do not satisfy monotonicity, I > >L> just have to find out how to derive the MRO. I had the notion that it > >L> was constructed by listing the current class, followed by the MROs of > >L> each base in order, and then retaining the rightmost instance of each > >L> class in the MRO list, but I think that might be an > >L> oversimplification, since in this case that would be: > >L> (C1, object) > >L> (C2, C1, object) > >L> (C3, C2, C1, object) > >L> And I don't see any issues. But I'll read the paper to figure out what > >L> the problem is, thanks. > > Here is exactly the problem. Merging the two MRO's as you state would > give C3, C2, C1, object, i.e. C2 before C1. > > But your class definition: > > class C3(C1, C2): > says that C1 should be before C2. Conflict!! > Change it to class C3(C2, C1): > > You see it has nothing to do with the metaclasses. The following code > gives the same error: > > class C1(object): > ? ? pass > class C2(C1): > ? ? pass > class C3(C1, C2): > ? ? pass > > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org Thank you, Piet. You are correct. I actually went through the whole C3 MRO paper from Michele and I realized the issue (local precedence is not maintained.) And, like you said, the way to fix it is to change the order of the bases in C3. From david at abbottdavid.com Mon Jun 1 19:10:24 2009 From: david at abbottdavid.com (David) Date: Mon, 01 Jun 2009 19:10:24 -0400 Subject: screen scraping In-Reply-To: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> References: <5eccdb21-c285-4bef-98c0-edecd3930587@x6g2000vbg.googlegroups.com> Message-ID: <4A245FE0.4010409@abbottdavid.com> ubuntu.exe at gmail.com wrote: > Hello, > does anybody have a simple tutorial for screen scrapping? > > I want to extract IP addresses from particular web page, reading > documentation for a couple of days and writing some really simple > scripts, but cant get it to work. > > Did anybody see any manual explicittly for screen scraping? > > Thanks. How about this: http://iwiwdsmp.blogspot.com/2007/02/how-to-use-python-and-beautiful-soup-to.html -- Powered by Gentoo GNU/Linux http://linuxcrazy.com From seattlehanks at yahoo.com Mon Jun 1 19:14:05 2009 From: seattlehanks at yahoo.com (LittleGrasshopper) Date: Mon, 1 Jun 2009 16:14:05 -0700 (PDT) Subject: Simple metaclass code failing References: <41ef2397-6e9b-48b1-a818-60991244cea7@f19g2000yqo.googlegroups.com> <991ff8ec-f38a-46db-9a40-93db8561337e@l12g2000yqo.googlegroups.com> Message-ID: On Jun 1, 3:44?am, Piet van Oostrum wrote: > >>>>> Piet van Oostrum (I) wrote: > >I> But your class definition: > >I> class C3(C1, C2): > >I> says that C1 should be before C2. Conflict!! > >I> Change it to class C3(C2, C1): > > Of course the C1 is then superfluous. > > I wonder why you want this. What is the problem you want to solve? > > Apart from the metaclasses (that you still can use with `class C3(C2)') > I could think of the following use case: > > class C1(object): > ? ? ? def m1(self): > ? ? ? ? ? return 'C1.m1' > > class C2(C1): > ? ? ? # override m1 > ? ? ? def m1(self): > ? ? ? ? ? return 'C2.m1' > ? ? ? def m2(self): > ? ? ? ? ? return 'C2.m2'+self.m1() > > class C3(C1, C2): > ? ? ? def test(self): > ? ? ? ? ? print self.m1()+self.m2() > > i.e. in C3 we `ignore' the override of m1 in C2 but still want to make > use of the m2 from C2. > > The question that arises then is: the self.m1() inside m2, which m1 > should it use? For an instance of C3 it would use C1.m1, but for an > instance of C2 it would use C2.m2. > > However, every instance of C3 can also be considered an instance of C2, > (Liskov substitution principle), therefore there is a conflict. That is > exactly the conflict that the MRO signals. > > If you want that kind of behaviour it can be solved by using a mixin > class for the m2 method: > > class C1(object): > ? ? ?__metaclass__ = M1 > ? ? ?def m1(self): > ? ? ? ? ?return 'C1.m1' > class Cmix(object): > ? ? ?def m2(self): > ? ? ? ? ?return 'C2.m2'+self.m1() > class C2(C1, Cmix): > ? ? ?__metaclass__ = M2 > ? ? ?# override m1 > ? ? ?def m1(self): > ? ? ? ? ?return 'C2.m1' > class C3(C1, Cmix): > ? ? ?__metaclass__ = M3 > ? ? ?def test(self): > ? ? ? ? ?print self.m1()+self.m2() > > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org Your discussion of this scenario, why it justifiably fails, and the alternative solution using a mixing, is all excellent. I am going to keep this for future reference. I am at a stage of my Python journey that some of these things seem rather mysterious, so I especially appreciate this very detailed discussion. To answer your question, I actually got this hierarchy directly from Guido's paper on class unification that came out with 2.2.3. From norseman at hughes.net Mon Jun 1 19:24:28 2009 From: norseman at hughes.net (norseman) Date: Mon, 01 Jun 2009 16:24:28 -0700 Subject: Python, Tkinter and popen problem In-Reply-To: <4A242295.1040704@mrabarnett.plus.com> References: <4A241D4C.6010700@hughes.net> <4A242295.1040704@mrabarnett.plus.com> Message-ID: <4A24632C.3050106@hughes.net> MRAB wrote: > norseman wrote: >> Piet van Oostrum wrote: >>> norseman (n) wrote: > [snip] >>>> n> Some questions: >>>> n> 1) "...], stdout=PIPE).stdout >>>> n> ^ ^ why the double use? >>> >>> It is not a double use. Popen(["z6.py"], stdout=PIPE) gives you a Popen >>> object, not a file object. If you add .stdout you get the stdout >>> attribute of the Popen object of which you just before stated that it >>> should be a pipe. So the stdout=PIPE parameter makes it create a pipe, >>> and the .stdout returns you that pipe. >>> >> >> I rather thought it might be something like the military: >> Company - Dress Right - Dress >> Get the attention, state what is to be done, order it done. :) >> >> Python goes to great lengths to "be helpful" but drops the ball on the >> obvious. stdout=PIPE means the user wants stdout piped back so it >> should be helpful and do the obvious rather than have the user be >> redundant. >> > What if the user requests both stdin and stdout? and what about all the > other useful bits which the returned object provides? --------------------------- "... stdin and stdout?..." I tried that - results were even worse. Have to kill the window to get out. (both redirects are to master who is not running, until child dies. meanwhile keyboard is effectively locked out) "... other useful bits..." Beauty is in the eye of the beholder. Or so the saying goes. "Useful" to one may not be so to another. It is kinda like this: I have been in some beautifully painted cars. Really great workmanship. They had lots of 'extras' too. Soft leather seats, built in two way radios and built in mobile phones and built in ice makers and the list goes on. But in the USofA Western States that have lots of dirt and gravel roads they are a complete waste of time, effort and money. Two weeks and they look like any other beat up jalopy. The dust gets into everything. Ever wanted to put ice cubes full of frozen dust and grit into your favorite drink? The ice maker had been installed into a friend's old pickup a week or so earlier. A month or so later I noticed it had been removed. "Useful" is a vague measurement at best. By the way - bits and pieces as told by yourself and Peter and Piet have accomplished painting a useful picture for me. My thanks to all three of you. Steve From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 19:40:33 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jun 2009 23:40:33 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> Message-ID: <0234597b$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > I believe the name you're looking for is combinations_with_replacement. > It is one of the features being added to 3.1 which should give all the > subsets of the Cartesian Product: > > permutations_with_replacement: product() > combinations_with_replacement: combinations_with_replacement() > permutations_without_replacement: permutations() > combinations_without_replacement: combinations() What, no partitions? http://en.wikipedia.org/wiki/Partition_of_a_set -- Steven From stef.mientki at gmail.com Mon Jun 1 19:46:23 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 01:46:23 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A245810.4090704@mrabarnett.plus.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <4A24684F.3090109@gmail.com> MRAB wrote: > Stef Mientki wrote: >> hello, >> >> I've pictures stored in a path relative to my python source code. >> To get a picture, I need to know what path I'm on in each python module. >> I thought __file__ would do the job, >> but apparently I didn't read the documentation carefully enough, >> because file is the path to the module that called my module. >> >> Any ways to get the path of "myself" ? >> > I'm not sure what you mean. I just did a quick test. > > # File: C:\Quick test\child.py > print "name is %s" % __name__ > print "file is %s" % __file__ > > # File: C:\Quick test\parent.py > import child > > print "name is %s" % __name__ > print "file is %s" % __file__ > > # Output: > name is child > file is C:\Quick test\child.py > name is __main__ > file is C:\Quick test\parent.py Yes, that's what I (and many others) thought, but now put your code in a file, let's say the file "test.py", and now run this file by : execfile ( 'test.py' ) cheers, Stef From stef.mientki at gmail.com Mon Jun 1 19:46:37 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 01:46:37 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <662715f21fdf486785783086cec9cda3@preisshare.net> References: <4A2447F0.2050905@gmail.com> <662715f21fdf486785783086cec9cda3@preisshare.net> Message-ID: <4A24685D.5000500@gmail.com> Thanks David, but .... David Lyon wrote: > On Mon, 01 Jun 2009 23:28:16 +0200, Stef Mientki > wrote: > >> hello, >> >> I've pictures stored in a path relative to my python source code. >> To get a picture, I need to know what path I'm on in each python module. >> I thought __file__ would do the job, >> but apparently I didn't read the documentation carefully enough, >> because file is the path to the module that called my module. >> >> Any ways to get the path of "myself" ? >> > > This ain't the official way... but the hackers way..... > > Check site.path (import site)... > always return None in my case > If your module got loaded, and it's own succinct directory or .egg, then > it will have been added to site.path. > > You might have to parse the values in site.path but we're only talking > a few lines of code because you already know the package name. > > If not, there's another way through pkg_utils... > I don't seem to have pkg_utils, only pkgutil, which doesn't have an apropiate function. But I found another way, don't know if that's reliable: import inspect print inspect.currentframe().f_code.co_filename cheers, Stef > Regards > > David > > From eric.pruitt at gmail.com Mon Jun 1 19:54:21 2009 From: eric.pruitt at gmail.com (Eric Pruitt) Date: Mon, 1 Jun 2009 18:54:21 -0500 Subject: Creating a Google Code project for GSoC Message-ID: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> Hello everyone, I am a student working on GSoC 2009 for PSF. My proposal involves making changes to the subprocess module and subprocess.Popen. I wish to create a Google Code project to host my changes so that I can receive feedback from the community. Some of the code I have incorporated falls under an MIT license. Python's license is not GPL but is GPL compatible. What license should the Google Code project fall under? MIT, GPL or something else? Eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 19:57:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Jun 2009 23:57:38 GMT Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> Message-ID: <02345d7c$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 10:54:48 +1200, Lawrence D'Oliveiro wrote: > In message , Albert van der Horst wrote: > >> An indication of how one can see one is in emacs is also appreciated. > > How about, hit CTRL/G and see if the word "Quit" appears somewhere. Ah, one has to love user interfaces designed with mnemonic keyboard commands so as to minimize the burden of rote learning on the user. Presumably it is G for "Get me the frack outta here!". Having noted that the word "Quit" does appear, how do you then *actually* Quit? Apart from taunting the user, what is it that Ctrl-G is actually doing when it displays the word "Quit" in what seems to be some sort of status bar? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 20:00:49 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 00:00:49 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <02345e3a$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 01:46:23 +0200, Stef Mientki wrote: > MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. To >>> get a picture, I need to know what path I'm on in each python module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, but now put your code in a > file, let's say the file "test.py", and now run this file by : > execfile ( 'test.py' ) In that case, test.py is not a module. It's just a file that by accident has a .py extension, which is read into memory and executed. If you bypass the module mechanism, don't be surprised that you've bypassed the module mechanism :) What are you trying to do? Using execfile is probably not the right solution. -- Steven From davea at ieee.org Mon Jun 1 20:10:28 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 01 Jun 2009 20:10:28 -0400 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A24684F.3090109@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <4A24684F.3090109@gmail.com> Message-ID: <4A246DF4.4@ieee.org> Stef Mientki wrote: >
MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. >>> To get a picture, I need to know what path I'm on in each python >>> module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > execfile ( 'test.py' ) > > cheers, > Stef > >
> Your original post asked about "what path I'm on in each python module". Now it turns out you're using execfile(), which doesn't create a module, it shortcircuits most of that. So why not import the file as a module instead of using execfile? Maybe using __import__() ? From emile at fenx.com Mon Jun 1 20:13:53 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Jun 2009 17:13:53 -0700 Subject: What text editor is everyone using for Python In-Reply-To: <02345d7c$0$8244$c3e8da3@news.astraweb.com> References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 6/1/2009 4:57 PM Steven D'Aprano said... > Having noted that the word "Quit" does appear, how do you then *actually* > Quit? Apart from taunting the user, what is it that Ctrl-G is actually > doing when it displays the word "Quit" in what seems to be some sort of > status bar? Ahhh.. memories of discovering that F7 gets you out of WordPerfect... Emile From python at mrabarnett.plus.com Mon Jun 1 20:14:22 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 01:14:22 +0100 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A24684F.3090109@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <4A24684F.3090109@gmail.com> Message-ID: <4A246EDE.80802@mrabarnett.plus.com> Stef Mientki wrote: > MRAB wrote: >> Stef Mientki wrote: >>> hello, >>> >>> I've pictures stored in a path relative to my python source code. >>> To get a picture, I need to know what path I'm on in each python module. >>> I thought __file__ would do the job, >>> but apparently I didn't read the documentation carefully enough, >>> because file is the path to the module that called my module. >>> >>> Any ways to get the path of "myself" ? >>> >> I'm not sure what you mean. I just did a quick test. >> >> # File: C:\Quick test\child.py >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # File: C:\Quick test\parent.py >> import child >> >> print "name is %s" % __name__ >> print "file is %s" % __file__ >> >> # Output: >> name is child >> file is C:\Quick test\child.py >> name is __main__ >> file is C:\Quick test\parent.py > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > execfile ( 'test.py' ) > You didn't say you were using execfile. # File: C:\Quick test\main.py parent_path = r"C:\Quick test\parent.py" execfile(parent_path, {"__file__": parent_path}) # Output: name is child file is C:\Quick test\child.pyc name is __builtin__ file is C:\Quick test\parent.py Notice how the extension of the child is now .pyc because it has already been compiled. From python at mrabarnett.plus.com Mon Jun 1 20:19:42 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 01:19:42 +0100 Subject: What text editor is everyone using for Python In-Reply-To: References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A24701E.8050304@mrabarnett.plus.com> Emile van Sebille wrote: > On 6/1/2009 4:57 PM Steven D'Aprano said... >> Having noted that the word "Quit" does appear, how do you then >> *actually* Quit? Apart from taunting the user, what is it that Ctrl-G >> is actually doing when it displays the word "Quit" in what seems to be >> some sort of status bar? > > Ahhh.. memories of discovering that F7 gets you out of WordPerfect... > And if you need help, just press F1, uh, I mean F3... :-) From mensanator at aol.com Mon Jun 1 20:24:49 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 17:24:49 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> Message-ID: <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> On Jun 1, 6:40?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > > I believe the name you're looking for is combinations_with_replacement. > > It is one of the features being added to 3.1 which should give all the > > subsets of the Cartesian Product: > > > permutations_with_replacement: ? ?product() > > combinations_with_replacement: ? ?combinations_with_replacement() > > permutations_without_replacement: permutations() > > combinations_without_replacement: combinations() > > What, no partitions? Itertools does partitions? > > http://en.wikipedia.org/wiki/Partition_of_a_set I didn't see any reference to Cartesian Product there. > > -- > Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 20:40:26 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 00:40:26 GMT Subject: Absolute imports in Python 2.4 Message-ID: <02346783$0$8244$c3e8da3@news.astraweb.com> I have a package which includes a module which shadows a module in the standard library. For example: package +-- __init__.py +-- ham.py +-- spam.py +-- sys.py Inside that package, I want to import the standard library sys. In other words, I want an absolute import. In Python 2.7, absolute imports will be the default, and "import sys" will import the standard library module. To get to the package.sys module, I'll need "from . import sys". In Python 2.5 and 2.6, relative imports are the default, and package.sys will shadow the std lib version. I can say: from __future__ import absolute_import to use the Python 2.7 behaviour. What can I do in Python 2.4 to get an absolute import? I've read PEP 328 and googled, but haven't found any useful advice other than "well don't do that then". Plenty of pages complaining about relative imports, but I haven't found any work-arounds others than renaming the offending module. Are there any other ways around this? http://www.python.org/dev/peps/pep-0328/ -- Steven From stef.mientki at gmail.com Mon Jun 1 20:55:13 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 02:55:13 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <02345e3a$0$8244$c3e8da3@news.astraweb.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A247871.5090804@gmail.com> Steven D'Aprano wrote: > On Tue, 02 Jun 2009 01:46:23 +0200, Stef Mientki wrote: > > >> MRAB wrote: >> >>> Stef Mientki wrote: >>> >>>> hello, >>>> >>>> I've pictures stored in a path relative to my python source code. To >>>> get a picture, I need to know what path I'm on in each python module. >>>> I thought __file__ would do the job, >>>> but apparently I didn't read the documentation carefully enough, >>>> because file is the path to the module that called my module. >>>> >>>> Any ways to get the path of "myself" ? >>>> >>>> >>> I'm not sure what you mean. I just did a quick test. >>> >>> # File: C:\Quick test\child.py >>> print "name is %s" % __name__ >>> print "file is %s" % __file__ >>> >>> # File: C:\Quick test\parent.py >>> import child >>> >>> print "name is %s" % __name__ >>> print "file is %s" % __file__ >>> >>> # Output: >>> name is child >>> file is C:\Quick test\child.py >>> name is __main__ >>> file is C:\Quick test\parent.py >>> >> Yes, that's what I (and many others) thought, but now put your code in a >> file, let's say the file "test.py", and now run this file by : >> execfile ( 'test.py' ) >> > > In that case, test.py is not a module. It's just a file that by accident > has a .py extension, which is read into memory and executed. > > If you bypass the module mechanism, don't be surprised that you've > bypassed the module mechanism :) > > What are you trying to do? Using execfile is probably not the right > solution. > > Maybe you're right, and it's not the best solution for my problem. I've written a program, that contains many files, both python files and data files, and I would like to distribute the program. For Linux, I'll just bundle the files in a zip-file, but for windows I want to make a one button installer, and the files generated by Py2Exe, don't work at all. Through this discussion, I discovered another problem, because __file__ isn't the current file, I can't run 1 module(file) from another module (file) . The structure of my files is something like this: Base_Path Main_Program_Path Main_Program_1.py Main_Program_2.py Brick_Path Brick_1.py Brick_2.py Support_Libraries Support_Library_1.py Support_Library_2.py Sounds_Path Sound_1.wav Sound_2.wav Picture_Path Picture_1.png Picture_2.bmp The Main_Programs, should be able to "run/launch" other Main_Programs and Support_Libraries, in several ways (wait / nowait, fetch output or not, ... ). So each Support_Libraries will have a "main-section". Everything is highly dynamical, just dumping a new py-file in the Brick_Path, will make the py-files available ( i.e. directly visible and usable to the user) in all Main_Programs. Moving the complete file-structure to Linux or Windows works good. Distributing the files through Py2Exe doesn't work at all. So I was thinking of a hack: - make dummy programs, that will start Main_Program_x.py through a execfile function - Create executables with Py2Exe of the dummy programs - add manually the whole directory structure to the files generated by Py2Exe - automate the above process by Inno setup Any suggestions ? thanks, Stef > > From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 21:28:53 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 01:28:53 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> Message-ID: <023472dd$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > On Jun 1, 6:40?pm, Steven D'Aprano cybersource.com.au> wrote: >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: >> > I believe the name you're looking for is >> > combinations_with_replacement. It is one of the features being added >> > to 3.1 which should give all the subsets of the Cartesian Product: >> >> > permutations_with_replacement: ? ?product() >> > combinations_with_replacement: ? ?combinations_with_replacement() >> > permutations_without_replacement: permutations() >> > combinations_without_replacement: combinations() >> >> What, no partitions? > > Itertools does partitions? Er, no. That's why I asked "What, no partitions?" instead of saying "Look, itertools also does partitions!" >> http://en.wikipedia.org/wiki/Partition_of_a_set > > I didn't see any reference to Cartesian Product there. Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it in if you think it needs to be there. While you're at it, there is no mention of Cartesian Product in any of http://en.wikipedia.org/wiki/Permutations http://en.wikipedia.org/wiki/Combinations http://mathworld.wolfram.com/Permutation.html http://mathworld.wolfram.com/k-Subset.html either. Are you sure that permutations and combinations are subsets of the Cartesian Product? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Jun 1 21:51:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2009 01:51:20 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> Message-ID: <0234781f$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 02:55:13 +0200, Stef Mientki wrote: >> What are you trying to do? Using execfile is probably not the right >> solution. >> >> > Maybe you're right, and it's not the best solution for my problem. I've > written a program, that contains many files, both python files and data > files, > and I would like to distribute the program. For Linux, I'll just bundle > the files in a zip-file, but for windows I want to make a one button > installer, and the files generated by Py2Exe, don't work at all. Define "don't work at all". > Through this discussion, I discovered another problem, because __file__ > isn't the current file, I can't run 1 module(file) from another module > (file) . ... It sounds like you are trying to fight Python's module system instead of working with it. In Python programs, you don't "run" other modules, you import them, then call functions inside the module. You treat the modules you write exactly the same as standard library modules. As a general rule, you would never say: execfile('/usr/lib/python2.5/os.py') Instead you would say: import os os.some_function() The same rule applies for your modules. As a general rule, NEVER say: execfile('mymodule.py') instead do: import mymodule mymodule.some_function() mymodule.another_function() (There are exceptions, but if you need to ask what they are, you're not ready to learn them! *wink*) > The structure of my files is something like this: > > Base_Path > Main_Program_Path > Main_Program_1.py > Main_Program_2.py > Brick_Path > Brick_1.py > Brick_2.py > Support_Libraries > Support_Library_1.py > Support_Library_2.py > Sounds_Path > Sound_1.wav > Sound_2.wav > Picture_Path > Picture_1.png > Picture_2.bmp Are these packages? Or just random folders with random files in them? > The Main_Programs, should be able to "run/launch" other Main_Programs > and Support_Libraries, > in several ways (wait / nowait, fetch output or not, ... ). So each > Support_Libraries will have a "main-section". Sounds like a horribly fragile, complicated and complex way of doing things. > Everything is highly > dynamical, just dumping a new py-file in the Brick_Path, will make the > py-files available ( i.e. directly visible and usable to the user) in > all Main_Programs. Sounds like you're trying to implement plugins. For that, __import__() is your friend. execfile() is *not* your friend -- you might think it is, but don't listen to it. It's like one of those guys who calls you "buddy" and talks you into doing things that you regret the next day. Trust me, use execfile() and you'll end up waking up naked in an alleyway in Vegas married to someone called Lula-Mae, with no memory of the last three days and a tattoo of Paris Hilton on your butt. > Distributing the files through Py2Exe doesn't work at all. So I was > thinking of a hack: As soon as you start thinking of using a hack in production code, go take a cold shower and lie down until the urge goes away. > Any suggestions ? Have you tried to find out why Py2Exe is broken and fix that? -- Steven From jyoung79 at kc.rr.com Mon Jun 1 22:15:20 2009 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Tue, 2 Jun 2009 2:15:20 +0000 Subject: Installing 3.1 questions Message-ID: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> Can anyone give me info on what and where Python installs on OS X? I ran the installers for version 2.6 and 3.0 and only installed Python (not IDLE, etc). I then added this to my .profile: PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}" PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" PATH="/System/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" export PATH Seems to work, but I'd like to know where Python installs its items. I'm wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' file (not sure of the difference between it and the 'Gzipped' one). Do I need to run some sort of 'install' command from the Terminal to get 3.1 to work? Or can I manually drag the items to a correct location and then update my .profile? Thanks for taking the time to look at my questions. Jay From pavlovevidence at gmail.com Mon Jun 1 22:25:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Jun 2009 19:25:41 -0700 (PDT) Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> Message-ID: <43095f7e-3111-4b0f-baf8-540047bc687a@l32g2000vba.googlegroups.com> On Jun 1, 4:46?pm, Stef Mientki wrote: > MRAB wrote: > > Stef Mientki wrote: > >> hello, > > >> I've pictures stored in a path relative to my python source code. > >> To get a picture, I need to know what path I'm on in each python module. > >> I thought __file__ would do the job, > >> but apparently I didn't read the documentation carefully enough, > >> because file is the path to the module that called my module. > > >> Any ways to get the path of "myself" ? > > > I'm not sure what you mean. I just did a quick test. > > > # File: C:\Quick test\child.py > > print "name is %s" % __name__ > > print "file is %s" % __file__ > > > # File: C:\Quick test\parent.py > > import child > > > print "name is %s" % __name__ > > print "file is %s" % __file__ > > > # Output: > > name is child > > file is C:\Quick test\child.py > > name is __main__ > > file is C:\Quick test\parent.py > > Yes, that's what I (and many others) thought, > but now put your code in a file, let's say the file "test.py", > and now run this file by : > ? ? execfile ( 'test.py' ) How can you execfile test.py without knowing the path to it? Whatever path you used to locate test.py is where the file is. If you're just execfiling a bare filename, then it's in the current directory, so just construct a relative pathname. Carl Banks From python.list at tim.thechases.com Mon Jun 1 22:35:00 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Jun 2009 21:35:00 -0500 Subject: Not going to let this drop ... In-Reply-To: <4A23B15C.3090403@holdenweb.com> References: <4A23B15C.3090403@holdenweb.com> Message-ID: <4A248FD4.8030902@tim.thechases.com> > If anyone who reads this email has anything to offer - time, > money, equipment, whatever, I'd be *really* grateful to hear > from them. I can put you in touch with people who know about > things like the range of interface devices available for > paraplegic and quadriplegic people. Ideally the program would > be adaptable to a wide range of hardware accommodating a broad > spectrum of disability, but many quadriplegics use equipment > that emulates a standard keyboard and/or mouse, so that would > be a great start. While I don't have too much to offer, I'll pass along what I do have: A) An OLPC (mostly Python-based kit) project[1] to provide simple icons-to-speech that sounds a bit like what you're describing. My addition to the thread is about Dasher[2], posted as Gumnos. A Dasher-like interface may allow for a greater range of expression with minimal "2-axis plus sip-puff" selection. If I were mobility-impaired, I'd use Dasher to communicate & code (perhaps even coding Python atoms/tokens as their own entities for ease of entry :) B) There are also groups of folks such as the IGDA (Independent Game Developers Association)'s SIG-Access[3] which focuses on promoting accessibility in gaming. Robert Florio[4] is one of the folks in the SIG and has a vested interest in improving accessibility for mobility-impaired gamers (others on the list have particular interests/focii in visual, auditory or mental challenges). I mention this group first because they have some innovative solutions for taking existing applications/games and either retrofitting accessibility solutions as well as exploring new design goals to make applications/games accessible upon launch. Other similar groups exist for things like web-accessibility (WCAG WG[5], WAG[6]) but that seems a little outside your focus. Hope this gives you some ideas/connections that help you out. -tkc [1] http://www.olpcnews.com/software/applications/free_icon-to-speech_open-source_speech_for_disabled.html [2] http://www.inference.phy.cam.ac.uk/dasher/ [3] http://www.igda.org/wiki/index.php/Game_Accessibility_SIG [4] http://www.robertflorio.com [5] http://www.w3.org/WAI/PA/ [6] http://www.bristol.ac.uk/webaccessibility/ From wuwei23 at gmail.com Mon Jun 1 23:00:01 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Jun 2009 20:00:01 -0700 (PDT) Subject: Is there any module for sea tides? References: Message-ID: "alejandro" wrote: > I found some in C but could not find in Python.... The best I could find was a reference to some in-house code used by the US National Oceanoic & Atmospheric Association: http://tinyurl.com/mct9zz You might be able to contact the email address at the bottom and inquire about the code. Another alternative is to look into using the ctypes module to create bindings for the C libs you found... From benjamin.kaplan at case.edu Tue Jun 2 00:32:36 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 2 Jun 2009 00:32:36 -0400 Subject: Installing 3.1 questions In-Reply-To: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> References: <20090602021520.2HIDI.28900.root@hrndva-web11-z02> Message-ID: On Mon, Jun 1, 2009 at 10:15 PM, wrote: > Can anyone give me info on what and where Python installs on OS X? > I ran the installers for version 2.6 and 3.0 and only installed Python > (not IDLE, etc). I then added this to my .profile: > > PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}" > PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" > > PATH="/System/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" > export PATH > > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? Or can I manually drag the items to a correct location and > then update my .profile? > > Thanks for taking the time to look at my questions. > I take it you've never compiled anything yourself before, so I'll go through it step by step. The bzip and gzip are just two different compression methods, so it doesn't matter which tarball you download. In order to go further, you'll need to register at developer.apple.com and download Xcode. You won't need to use Xcode itself, but you need the compilers that come with it. It's a pretty big download, so this will take a while. Once you install Xcode, open up a terminal (/Applications/Utilities/Terminal.app) and cd (change directory) to wherever you put the extracted tarball. In that directory, run the configure file. Since your on OS X, you probably want a framework build (installed to /Library/Frameworks) instead of a normal build, which installs to /usr/local. To do this, execute the command "./configure --enable-framework". If you want to look up the other options, run "./configure --help". You'll probably get an error about missing dependencies. The easiest place to find these is in a package manager such as fink (www.finkproject.org) or macports (www.macports.org). Fink is easier and faster, but macports is usually more up-to-date and flexible since it compiles everything locally. Both of them will work. Just don't forget to add the paths (macports is in /opt/local/ and fink is in /sw/) Once the configure command works successfully, run the commands "make" and "sudo make install". The first one will compile everything, the second will put it where it's supposed to be. After running the latter, you'll be prompted to enter your password. That should install it to /Library/Frameworks/Python.framework/versions/3.1. I haven't installed 3.1 myself but assuming it does the same thing as 3.0, it should a python3.1 executable (symlink actually) to /usr/local/bin so you shouldn't need to add anything to the path. > > Jay > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jun 2 00:51:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 01:51:35 -0300 Subject: Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser escribi?: > I can examine the inherited slots to see which special methods are > there, and to implement my own __deepcopy__ accordingly. But to do > so well seems to essentially require reimplementing the complicated > logic of the copy.deepcopy function. That is, if my new class is > the first to be implementing an explicit __deepcopy__ function, I > seem to have no easy way to invoke the inherited version of > "deepcopy(self)". Yes, that's a problem. But there is a workaround: since __deepcopy__ is searched *in the instance* (unlike many other __special__ methods, that are usually searched in the class itself) you can fool the copy logic into thinking there is no __deepcopy__ method defined, just by (temporarily) setting an instance attribute __deepcopy__ to None. (It's a hack, anyway) import copy class A(object): def __init__(self, x, y): self.x = x self.y = y # these two methods implement copy and pickle behaviour # we can't change them def __reduce__(self): return (self.__newobj__, (), self.__dict__) @classmethod def __newobj__(cls, *args): return cls.__new__(cls, *args) class B(A): def __init__(self, x, y, filename): A.__init__(self, x, y) self.file = open(filename, "at") def __deepcopy__(self, memo): # Problem: how to call the inherited __deepcopy__ implementation # when there is none? # The logic is inside the copy.deepcopy function, not in # object.__deepcopy__ # hack: make deepcopy() think this method doesn't exist self.__deepcopy__ = None try: dup = copy.deepcopy(self, memo) del dup.__deepcopy__ finally: del self.__deepcopy__ # now, do the special stuff dup.file = open(self.file.name, "at") return dup obj = B(1, 2, "testfile") print "obj", obj, vars(obj) dup = copy.deepcopy(obj) print "obj", obj, vars(obj) print "dup", dup, vars(dup) obj <__main__.B object at 0x00BEC0F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46C00>} obj <__main__.B object at 0x00BEC0F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46C00>} dup <__main__.B object at 0x00BEC7F0> {'y': 2, 'x': 1, 'file': < open file 'testfile', mode 'at' at 0x00B46CA0>} > I wonder if the logic inherent in the copy.deepcopy function could > instead be implemented directly within object.__deepcopy__ (rather > than the current model in which object does not have __deepcopy__). > Then I would always have a means for simulating a call to > deepcopy(self) based upon the super.__deepcopy__ logic. > I wouldn't be surprised if I'm overlooking some undesirable > consequence of such a major change in the model, but I don't see one > upon first thought. This deserves to be looked at with more detail. Try the python-ideas list, or submit a RFE to http://bugs.python.org/ -- Gabriel Genellina From lepto.python at gmail.com Tue Jun 2 01:18:25 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 13:18:25 +0800 Subject: Dabo 0.9.2 released Message-ID: <6a4f17690906012218v45f4e8b8of300c08b1ea9cbc8@mail.gmail.com> I have to say: please let dabo use english if it does not find any langauge resource! I have 'e:\prg\py\sap-24\python e:\prg\py\pure_pylib\_dabo\tools\remove_dLocalize.py .', but then the scripts says 'I don't know _" From mensanator at aol.com Tue Jun 2 01:20:16 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 22:20:16 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: On Jun 1, 8:28?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > > On Jun 1, 6:40?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > >> > I believe the name you're looking for is > >> > combinations_with_replacement. It is one of the features being added > >> > to 3.1 which should give all the subsets of the Cartesian Product: > > >> > permutations_with_replacement: ? ?product() > >> > combinations_with_replacement: ? ?combinations_with_replacement() > >> > permutations_without_replacement: permutations() > >> > combinations_without_replacement: combinations() > > >> What, no partitions? > > > Itertools does partitions? > > Er, no. That's why I asked "What, no partitions?" instead of saying > "Look, itertools also does partitions!" > > >>http://en.wikipedia.org/wiki/Partition_of_a_set > > > I didn't see any reference to Cartesian Product there. > > Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it > in if you think it needs to be there. While you're at it, there is no > mention of Cartesian Product in any of > > http://en.wikipedia.org/wiki/Permutationshttp://en.wikipedia.org/wiki/Combinations > > http://mathworld.wolfram.com/Permutation.htmlhttp://mathworld.wolfram.com/k-Subset.html > > either. You might have better luck with Google. > Are you sure that permutations and combinations are subsets of > the Cartesian Product? Sure looks that way (SQL examples): Cartesian Product (Permutaions w/replacement) SELECT B.q, A.p FROM A, B; q p a a a b b a b b Permutaions wo/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)<>[B].[q])); q p a b b a Combinations w/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)>=[B].[q])); q p a a a b b b Combinations wo/replacement SELECT B.q, A.p FROM A, B WHERE (((A.p)>[B].[q])); q p a b I couldn't do that if they weren't subsets. > > -- > Steven From tonal at promsoft.ru Tue Jun 2 01:25:36 2009 From: tonal at promsoft.ru (Alexandr N Zamaraev) Date: Tue, 02 Jun 2009 12:25:36 +0700 Subject: Why date do not construct from date? Message-ID: <4A24B7D0.501@promsoft.ru> Simple example: [code] Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 >>> import datetime as dt >>> dt.date(2009, 10, 15) datetime.date(2009, 10, 15) >>> d = dt.date(2009, 10, 15) >>> dt.date(d) Traceback (most recent call last): File "", line 1, in TypeError: function takes exactly 3 arguments (1 given) >>> [/code] Why int form int, str from str, Decumal from Decumal can construct bat date from date not? From gagsl-py2 at yahoo.com.ar Tue Jun 2 01:37:04 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 02:37:04 -0300 Subject: Absolute imports in Python 2.4 References: <02346783$0$8244$c3e8da3@news.astraweb.com> Message-ID: En Mon, 01 Jun 2009 21:40:26 -0300, Steven D'Aprano escribi?: > I have a package which includes a module which shadows a module in the > standard library. For example: > > package > +-- __init__.py > +-- ham.py > +-- spam.py > +-- sys.py > > Inside that package, I want to import the standard library sys. In other > words, I want an absolute import. [...] > What can I do in Python 2.4 to get an absolute import? sys = __import__("sys", {}) The import statement uses the global namespace to determine which package it is called on; if you pass an empty namespace, it cannot infer package information. Anyway, the best move would be to rename the offending module... -- Gabriel Genellina From mensanator at aol.com Tue Jun 2 01:45:27 2009 From: mensanator at aol.com (Mensanator) Date: Mon, 1 Jun 2009 22:45:27 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: <70591a8c-4213-461f-8952-e0a69dca9678@z9g2000yqi.googlegroups.com> On Jun 1, 8:28?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote: > > On Jun 1, 6:40?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote: > >> > I believe the name you're looking for is > >> > combinations_with_replacement. It is one of the features being added > >> > to 3.1 which should give all the subsets of the Cartesian Product: > > >> > permutations_with_replacement: ? ?product() > >> > combinations_with_replacement: ? ?combinations_with_replacement() > >> > permutations_without_replacement: permutations() > >> > combinations_without_replacement: combinations() > > >> What, no partitions? > > > Itertools does partitions? > > Er, no. That's why I asked "What, no partitions?" instead of saying > "Look, itertools also does partitions!" > > >>http://en.wikipedia.org/wiki/Partition_of_a_set > > > I didn't see any reference to Cartesian Product there. > > Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it > in if you think it needs to be there. While you're at it, there is no > mention of Cartesian Product in any of > > http://en.wikipedia.org/wiki/Permutationshttp://en.wikipedia.org/wiki/Combinations > > http://mathworld.wolfram.com/Permutation.htmlhttp://mathworld.wolfram.com/k-Subset.html > > either. Are you sure that permutations and combinations are subsets of > the Cartesian Product? Didn't notice this before - it says so in the docs! itertools.product(*iterables[, repeat])? Cartesian product of input iterables. The code for permutations() can be also expressed as a subsequence of product(), filtered to exclude entries with repeated elements (those from the same position in the input pool): The code for combinations() can be also expressed as a subsequence of permutations() after filtering entries where the elements are not in sorted order (according to their position in the input pool): > > -- > Steven From martin at v.loewis.de Tue Jun 2 02:01:07 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Tue, 02 Jun 2009 08:01:07 +0200 Subject: Installing 3.1 questions In-Reply-To: References: Message-ID: <4A24C023.7070208@v.loewis.de> > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? You need to build it. Read the README file in the source distribution. If you don't know what a "tar ball" is, read tar(1). Regards, Martin From martin at v.loewis.de Tue Jun 2 02:01:07 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Tue, 02 Jun 2009 08:01:07 +0200 Subject: Installing 3.1 questions In-Reply-To: References: Message-ID: <4A24C023.7070208@v.loewis.de> > Seems to work, but I'd like to know where Python installs its items. I'm > wanting to test version 3.1 and downloaded the 'Bzipped source tar ball' > file (not sure of the difference between it and the 'Gzipped' one). Do I > need to run some sort of 'install' command from the Terminal to get > 3.1 to work? You need to build it. Read the README file in the source distribution. If you don't know what a "tar ball" is, read tar(1). Regards, Martin From clp2 at rebertia.com Tue Jun 2 02:14:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Jun 2009 23:14:22 -0700 Subject: Why date do not construct from date? In-Reply-To: <4A24B7D0.501@promsoft.ru> References: <4A24B7D0.501@promsoft.ru> Message-ID: <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev wrote: > Simple example: > [code] > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] > on win32 >>>> import datetime as dt >>>> dt.date(2009, 10, 15) > datetime.date(2009, 10, 15) >>>> d = dt.date(2009, 10, 15) >>>> dt.date(d) > Traceback (most recent call last): > ?File "", line 1, in > TypeError: function takes exactly 3 arguments (1 given) >>>> > [/code] > Why int form int, str from str, Decumal from Decumal can construct bat date > from date not? Probably because the function signatures would be so different. str(), int(), etc *always* take *exactly one* argument -- the object to convert. In contrast, date() takes several integers corresponding to the year, month, and day. Adding a second signature to it that took exactly one argument (of type `date`) and copied it would be significantly different from its other signature; in idiomatic Python, one would typically make a separate, new function for this drastically different signature. However, the `date` type is immutable, so there's no reason at all to try and copy a new instance from an existing one anyway, thus a single-argument copy-constructor is completely unnecessary, hence why there isn't one. Cheers, Chris -- http://blog.rebertia.com From pataphor at gmail.com Tue Jun 2 02:53:34 2009 From: pataphor at gmail.com (pataphor) Date: Tue, 02 Jun 2009 08:53:34 +0200 Subject: Generating all combinations In-Reply-To: References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: Mensanator wrote: > I couldn't do that if they weren't subsets. Right. Sometimes one just has to assume things are different even if they look the same on the surface. That is because else one wouldn't be able to produce the other generators. I guess it would also work the other way around, assuming things are the same even when they look different. For example see my two functions: def repeat_each(seq,n): while True: for x in seq: for i in range(n): yield x def repeat_all(seq,n): while True: for i in range(n): for x in seq: yield x (I should probably not smoke stuff before posting, but anyway) They are the same, except for switching two lines of code. But for the second one ('repeat_all') the argument 'n' seems redundant. What does it even mean to repeat a sequence n times, and do that forever? Isn't that the same as just repeating the sequence itself, forever? So that's how we arrive at itertools.cycle . The second argument is there, but it would be foolish to include it, so it is left out. But now let's look at how itertools.repeat should really be. It should look like 'repeat_each' above. Here second argument ('n') *is* necessary, or else the generator would just infinitely repeat only the first element of the sequence, which is obviously nonsense. But that is exactly why itertools.repeat does not accept a sequence (like cycle, its virtual brother) but instead it has degenerated into something that just repeats only one thing n times, which is stupid. So to set things right one has to forget everything and just write complete balderdash if necessary, if it only leads to finally understanding how the two are related. Then one can see that itertools.repeat should be an infinite generator *on sequences* that however still needs a second argument specifying how many times each individual item should be repeated, and that itertools.cycle's second argument is there but hidden. P. From gagsl-py2 at yahoo.com.ar Tue Jun 2 03:05:08 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 04:05:08 -0300 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert escribi?: > On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev > wrote: >>>>> import datetime as dt >>>>> d = dt.date(2009, 10, 15) >>>>> dt.date(d) >> Traceback (most recent call last): >> ?File "", line 1, in >> TypeError: function takes exactly 3 arguments (1 given) >> Why int form int, str from str, Decumal from Decumal can construct bat >> date from date not? > > Probably because the function signatures would be so different. str(), > int(), etc *always* take *exactly one* argument -- the object to > convert. In contrast, date() takes several integers corresponding to > the year, month, and day. Adding a second signature to it that took > exactly one argument (of type `date`) and copied it would be > significantly different from its other signature; in idiomatic Python, > one would typically make a separate, new function for this drastically > different signature. That doesn't convince me. It's not very consistent along the various types: int("3ab0",16) is rather different than int(3.2) but they're the same function... > However, the `date` type is immutable, so there's no reason at all to > try and copy a new instance from an existing one anyway, thus a > single-argument copy-constructor is completely unnecessary, hence why > there isn't one. Isn't the same for all other examples (int, float, str, Decimal...)? They're all immutable types, and some have several and rather different constructor signatures: py> Decimal((0, (1, 5, 0, 0), -3)) Decimal('1.500') py> Decimal(Decimal('1.500')) Decimal('1.500') If one can say float(3.0), str("hello"), etc -- what's so wrong with date(another_date)? -- Gabriel Genellina From __peter__ at web.de Tue Jun 2 03:45:19 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Jun 2009 09:45:19 +0200 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > If one can say float(3.0), str("hello"), etc -- what's so wrong with > date(another_date)? You can do x = float(x) when you don't know whether x is a float, int, or str. Not terribly useful, but sometimes convenient because making the float() call idempotent allows you to skip the type check. def subtract(a, b): if isinstance(a, str): a = float(b) if isinstance(b, str): b = float(b) return a - b becomes def subtract(a, b): return float(a) - float(b) For date you'd have to make the type check anyway, e. g. if isinstance(x, tuple): x = date(*x) else: x = date(x) # useless will only succeed if x already is a date as there would be no other way to create a date from a single value. So the date() call in the else branch is completely redundant unless you change date() to accept multiple types via the same signature: for x in "2000-01-01", datetime.now(), (2000, 1, 1): print date(x) Peter From cdsd at d.com Tue Jun 2 03:51:29 2009 From: cdsd at d.com (ssd) Date: Tue, 2 Jun 2009 09:51:29 +0200 Subject: python 2.6 packages in python 3.0 Message-ID: Hi, I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. When is planned that these packages are supported in Python 3.0? Seen this i would say that is not recommendable to use Python 3.0 at the moment? most of 2.6 packages are not available, not working in python 3.0. Thanks, Bye, From clp2 at rebertia.com Tue Jun 2 04:01:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Jun 2009 01:01:52 -0700 Subject: python 2.6 packages in python 3.0 In-Reply-To: References: Message-ID: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> On Tue, Jun 2, 2009 at 12:51 AM, ssd wrote: > Hi, > > I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. > > When is planned that these packages are supported in Python 3.0? That would depend on the individual packages and their maintainers. Check their respective websites. There is not, as of yet, any concerted/coordinated effort to port third-party libraries to 3.0. > Seen this i would say that is not recommendable to use Python 3.0 at the > moment? most of 2.6 packages are not available, not working in python 3.0. Yes, that's basically the state of things at the moment. We're in a transitional phase while people port everything to Python 3.0 and/or wait for the libraries they require to be ported to 3.0. Cheers, Chris -- http://blog.rebertia.com From tiskanto at gmail.com Tue Jun 2 05:04:49 2009 From: tiskanto at gmail.com (Teguh Iskanto) Date: Tue, 2 Jun 2009 19:04:49 +1000 Subject: No subject In-Reply-To: References: Message-ID: how about this : - dump those data with sort enabled - use diff to those two dumps , eg: diff dump_a dump_b if you don't know what diff is , try : man diff HTH On Tue, Jun 2, 2009 at 2:50 AM, Kiran Siddiqui wrote: > hi have to parse a very complex dumps(whatever it is), i have done the > parsing thruogh python.since the parsed data is very huge in amount, i have > to feed it in the database (SQL), I have also done this... now the thing is > i have to compare the data now present in the sql. > > > > in actual i have to compare the data of 1st dump with the data of the 2nd > dump..... the both dump have the same fields(attributes) but the values of > their field may be change... so i have to detect this change.. for this i > have to do the comparison... > > > > i.e, let i have a tableA ,its 1st row carry the data of dump1 and then on > the 2nd day the data comes from dump2 go into the next row of tableA. and i > have to compare both rows. > > > > but i dont have the idea how to do this all using python as my front end. > > > > plz plzzzz anyone help me:( > > > > ------------------------------ > See all the ways you can stay connected to friends and family > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Tue Jun 2 05:11:30 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 2 Jun 2009 11:11:30 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A247871.5090804@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <4A247871.5090804@gmail.com> Message-ID: <9fdb569a0906020211t2c4c5d3w7df511570ee41640@mail.gmail.com> 2009/6/2 Stef Mientki : ... > and the files generated by Py2Exe, don't work at all. > > Through this discussion, I discovered another problem, > because __file__ isn't the current file, > I can't run 1 module(file) from another module (file) . > > -- > http://mail.python.org/mailman/listinfo/python-list > There are already answers regarding other more topical issues with the initial problem; but just in case the main problem would be the use of __file__ ... It seems, that the exe files generated from py2exe don't recognise this variable; sometimes I used code like try: __file__ except NameError: # py2exe __file__ = sys.path[0] cf. e.g. http://mail.python.org/pipermail/python-list/2001-May/085384.html I'm not sure, whether there are any drawbacks, but it works in the respective context (accessing text and image files in parallel directories). vbr From HeinTest at web.de Tue Jun 2 05:28:43 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 02 Jun 2009 11:28:43 +0200 Subject: Seach for encrypted socket wrapper Message-ID: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Hello experts, I'm looking for secure way to pass messages from a python program to a c-library in both ways. This scenario is given: display client Calculation module in COBOL (yes, big, old but it works well) (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with display client The network connection should be encrypted. And fail save. Has someone an idea what to use ? I have had a short look on xml rpc which can run over a https server but this seems quite fat. Better ideas ?! Importand is also that the C-Lib on the cobol side should be coded as simple as possible. Platforms: Windows, *ix Thanks a lot. Hans From tjreedy at udel.edu Tue Jun 2 05:29:40 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Jun 2009 05:29:40 -0400 Subject: python 2.6 packages in python 3.0 In-Reply-To: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> References: <50697b2c0906020101x2d0cd254h44c3adfd2d76f7c3@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Tue, Jun 2, 2009 at 12:51 AM, ssd wrote: >> Hi, >> >> I usually works with packages like pyserial, numpy, mathplotlib,pyUSB, etc.. >> >> When is planned that these packages are supported in Python 3.0? > > That would depend on the individual packages and their maintainers. > Check their respective websites. There is not, as of yet, any > concerted/coordinated effort to port third-party libraries to 3.0. That is more likely to happen after 3.1 final is released in a month or less. >> Seen this i would say that is not recommendable to use Python 3.0 at the >> moment? most of 2.6 packages are not available, not working in python 3.0. If you need the packages, then 3.0 is not for you. > Yes, that's basically the state of things at the moment. We're in a > transitional phase while people port everything to Python 3.0 and/or > wait for the libraries they require to be ported to 3.0. I expect people to port directly to 3.1 and not worry about whether there are minor incompatibilities with 3.0. tjr From lie.1296 at gmail.com Tue Jun 2 06:34:43 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 20:34:43 +1000 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: Gabriel Genellina wrote: > En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser > escribi?: > >> I can examine the inherited slots to see which special methods are >> there, and to implement my own __deepcopy__ accordingly. But to do >> so well seems to essentially require reimplementing the complicated >> logic of the copy.deepcopy function. That is, if my new class is >> the first to be implementing an explicit __deepcopy__ function, I >> seem to have no easy way to invoke the inherited version of >> "deepcopy(self)". > > Yes, that's a problem. But there is a workaround: since __deepcopy__ is > searched *in the instance* (unlike many other __special__ methods, that > are usually searched in the class itself) you can fool the copy logic > into thinking there is no __deepcopy__ method defined, just by > (temporarily) setting an instance attribute __deepcopy__ to None. (It's > a hack, anyway) I've never really used pickle before but maybe you could try pickling then unpickling? It is a hack, but for some objects that does not have __deepcopy__ it might be sufficient. From roy at panix.com Tue Jun 2 06:55:20 2009 From: roy at panix.com (Roy Smith) Date: Tue, 02 Jun 2009 06:55:20 -0400 Subject: Is there any module for sea tides? References: Message-ID: In article , alex23 wrote: > "alejandro" wrote: > > I found some in C but could not find in Python.... > > The best I could find was a reference to some in-house code used by > the US National Oceanoic & Atmospheric Association: > > http://tinyurl.com/mct9zz > > You might be able to contact the email address at the bottom and > inquire about the code. > > Another alternative is to look into using the ctypes module to create > bindings for the C libs you found... This is really off-topic for a Python group, but... http://www.flaterco.com/xtide/index.html From lie.1296 at gmail.com Tue Jun 2 07:07:32 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 11:07:32 GMT Subject: Why date do not construct from date? In-Reply-To: References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert > escribi?: > >> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >> wrote: > >>>>>> import datetime as dt >>>>>> d = dt.date(2009, 10, 15) >>>>>> dt.date(d) >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: function takes exactly 3 arguments (1 given) > >>> Why int form int, str from str, Decumal from Decumal can construct >>> bat date from date not? >> >> Probably because the function signatures would be so different. str(), >> int(), etc *always* take *exactly one* argument -- the object to >> convert. In contrast, date() takes several integers corresponding to >> the year, month, and day. Adding a second signature to it that took >> exactly one argument (of type `date`) and copied it would be >> significantly different from its other signature; in idiomatic Python, >> one would typically make a separate, new function for this drastically >> different signature. > > That doesn't convince me. It's not very consistent along the various > types: int("3ab0",16) is rather different than int(3.2) but they're the > same function... Strictly speaking int("3ab0",16) does not create an int from an int, instead it creates an int from a string. Maybe you want to say int(3) -> 3 ? >> However, the `date` type is immutable, so there's no reason at all to >> try and copy a new instance from an existing one anyway, thus a >> single-argument copy-constructor is completely unnecessary, hence why >> there isn't one. > > Isn't the same for all other examples (int, float, str, Decimal...)? > They're all immutable types, and some have several and rather different > constructor signatures: int(ob), float(ob), and str(ob) are type casting (strictly speaking it is not a type casting, but you get the idea); while date() is a constructor for the date object. Strictly speaking int(ob), float(ob), and str(ob) merely calls the special ob.__int__, ob.__float__, and ob.__str__. These special functions are there to convert the current object into int, float, or str wherever defined. It just happens that calling int.__int__, float.__float__, and str.__str__ just returns themselves. For Decimal, (I think) it is as a symmetry to float since Decimal is intended to be used whenever IEEE 764 behavior does not suit you. From lepto.python at gmail.com Tue Jun 2 07:10:18 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 19:10:18 +0800 Subject: do replacement evenly Message-ID: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> I have some strings, and I want to write them into a text files, one string one line but there is a requirement: every line has a max length of a certain number(for example, 10), so I have to replace extra SPACE*3 with SPACE*2, at the same time, I want to make the string looks good, so, for "I am123456line123456three"(to show the SPACE clearly, I type it with a number), the first time, I replace the first SPACE, and get "I am23456line123456three", then I must replace at the second SPACE block, so I get "I am23456line23456three", and so on, if no SPACE*3 is found, I have to aString.replace(SPACE*2, SPACE). I hope I have stated my case clear. Then the question is, is there a nice solution? thanx From lie.1296 at gmail.com Tue Jun 2 07:23:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Jun 2009 11:23:27 GMT Subject: Why date do not construct from date? In-Reply-To: References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: Lie Ryan wrote: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert >> escribi?: >> >>> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >>> wrote: >>>>>>> import datetime as dt >>>>>>> d = dt.date(2009, 10, 15) >>>>>>> dt.date(d) >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: function takes exactly 3 arguments (1 given) >>>> Why int form int, str from str, Decumal from Decumal can construct >>>> bat date from date not? >>> Probably because the function signatures would be so different. str(), >>> int(), etc *always* take *exactly one* argument -- the object to >>> convert. In contrast, date() takes several integers corresponding to >>> the year, month, and day. Adding a second signature to it that took >>> exactly one argument (of type `date`) and copied it would be >>> significantly different from its other signature; in idiomatic Python, >>> one would typically make a separate, new function for this drastically >>> different signature. >> That doesn't convince me. It's not very consistent along the various >> types: int("3ab0",16) is rather different than int(3.2) but they're the >> same function... > > Strictly speaking int("3ab0",16) does not create an int from an int, > instead it creates an int from a string. > > Maybe you want to say int(3) -> 3 ? > >>> However, the `date` type is immutable, so there's no reason at all to >>> try and copy a new instance from an existing one anyway, thus a >>> single-argument copy-constructor is completely unnecessary, hence why >>> there isn't one. >> Isn't the same for all other examples (int, float, str, Decimal...)? >> They're all immutable types, and some have several and rather different >> constructor signatures: > > int(ob), float(ob), and str(ob) are type casting (strictly speaking it > is not a type casting, but you get the idea); while date() is a > constructor for the date object. Strictly speaking int(ob), float(ob), > and str(ob) merely calls the special ob.__int__, ob.__float__, and > ob.__str__. These special functions are there to convert the current > object into int, float, or str wherever defined. It just happens that > calling int.__int__, float.__float__, and str.__str__ just returns > themselves. > > For Decimal, (I think) it is as a symmetry to float since Decimal is > intended to be used whenever IEEE 764 behavior does not suit you. In fact, the doc of int and float says "Convert a string or number to an integer, if possible" and "Convert a string or number to a floating point number, if possible" respectively. There is no mention that they are constructors at all... While the doc for str says "Return a nice string representation of the object." the argument still holds since the "nice string representation" for a string is the string itself... Decimal is the rotten apple here since it just mimics float(). But that is why Decimal is in separate module and there is no decimal() built-in. Classes in modules are free to do anything they want to do... including mimicking float() or deciding not to accept its own self as a valid initializer. From iainking at gmail.com Tue Jun 2 07:33:56 2009 From: iainking at gmail.com (Iain King) Date: Tue, 2 Jun 2009 04:33:56 -0700 (PDT) Subject: do replacement evenly References: Message-ID: <27432761-1f86-4996-852d-34324526f303@q14g2000vbn.googlegroups.com> On Jun 2, 12:10?pm, oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get ?"I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? > > thanx Assuming you want to crush all spaces into single space, you can: while " " in s: s = s.replace(" ", " ") readable but not efficient. Better: s = " ".join((x for x in s.split(" ") if x)) Note that this will strip leading and trailing spaces. Or you can use regexps: import re s = re.sub(" {2,}", " ", s) Iain From nadiasvertex at gmail.com Tue Jun 2 08:20:11 2009 From: nadiasvertex at gmail.com (Christopher) Date: Tue, 2 Jun 2009 05:20:11 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: On May 25, 1:35?pm, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, and why. I normally use vi, and just got > into Python, so I am looking for suitable syntax files for it, and > extra utilities. I dabbled with emacs at some point, but couldn't get > through the key bindings for commands. I've never tried emacs with vi > keybindings (I forgot the name of it) but I've been tempted. > > So what do you guys use, and why? Hopefully we can keep this civil. I use Eclipse with PyDev for serious projects. However, when that is too heavy or not available I use: 1) nano over ssh with syntax highlighting for python turned on 2) notepad++ on standalone Windows systems where I need to do quick edits or fixes. I used to use Crimson Editor, but it is not being developed anymore, and notepad++ does everything crimson used to do and more. -={C}=- From john.center at villanova.edu Tue Jun 2 08:25:42 2009 From: john.center at villanova.edu (John Center) Date: Tue, 2 Jun 2009 05:25:42 -0700 (PDT) Subject: Problem building 64-bit python 2.6.2 on Solaris 10 References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> <4a23fe33$0$20453$9b622d9e@news.freenet.de> Message-ID: Hi Martin, I was able to compile ctypes with gcc4sparc without many changes to the CFLAGS, etc. I had another weird error, but upgrading to the latest gcc4sparc fixed it. One thing I'm not clear about is how extensions are built. I noticed that my CFLAGS are not being passed to gcc when building the extensions, so some of them are failing to find the correct includes & libraries. How does one pass these flags? Thanks. -John From mk.fraggod at gmail.com Tue Jun 2 08:42:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 2 Jun 2009 18:42:55 +0600 Subject: do replacement evenly In-Reply-To: References: Message-ID: <20090602184255.1abf7948@coercion> On Tue, 2 Jun 2009 19:10:18 +0800 oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get "I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? Not so nice, but it should be faster than whole lot of string manipulations, especially on longer lines: len_line = 55 line = 'Thats a whole line of some utter nonsense ;)' words = line.split() count_space = len_line - len(''.join(words)) count_span = len(words) - 1 span_min = (count_space // count_span) * ' ' count_span_max = count_space - (count_span * len(span_min)) line = buffer(words[0]) for word in words[1:]: if count_span_max: count_span_max -= 1 line += span_min + ' ' else: line += span_min line += word print '%d chars: %r'%(len(line), line) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lepto.python at gmail.com Tue Jun 2 08:45:57 2009 From: lepto.python at gmail.com (oyster) Date: Tue, 2 Jun 2009 20:45:57 +0800 Subject: do replacement evenly In-Reply-To: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> References: <6a4f17690906020410g75116d30hdbccb3d01020713b@mail.gmail.com> Message-ID: <6a4f17690906020545w22508949g765fb0f14cd11e27@mail.gmail.com> here is what I get [code] import re reSplitObj=re.compile('([ \t]*)|([^ \t]*)') def evenReplace(aStr, length): aStr=aStr.rstrip() tmp=reSplitObj.split(aStr) tmp=[i for i in tmp if i not in ['', None]] lenStr=[[0, len(i)][i.strip()!=''] for i in tmp] lenSpc=[[0, len(i)][i.strip()==''] for i in tmp] while sum(lenStr)+sum(lenSpc)>length: if sum(lenSpc): lenSpc[lenSpc.index(max(lenSpc))]-=1 else: break newSpc=[' '*i for i in lenSpc] _=[] for i in range(len(tmp)): item=tmp[i] if item.strip()!='': _.append(item+newSpc[i]) else: _.append(newSpc[i]) return ''.join(_) if __name__=='__main__': a='hello world' b= evenReplace(a, 5) print 'a="%s", len=%0i' %(a, len(a)) print 'b="%s", len=%0i' %(b, len(b)) print a='hello world yeah event even ' b= evenReplace(a, 27) print 'a="%s", len=%0i' %(a, len(a)) print 'b="%s", len=%0i' %(b, len(b)) print [/code] 2009/6/2 oyster : > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number(for example, 10), so I have to replace extra SPACE*3 with > SPACE*2, at the same time, I want to make the string looks good, so, > for "I am123456line123456three"(to show the SPACE clearly, I type it > with a number), the first time, I replace the first SPACE, and get "I > am23456line123456three", then I must replace at the second SPACE > block, so I get ?"I am23456line23456three", and so on, if no SPACE*3 > is found, I have to aString.replace(SPACE*2, SPACE). > I hope I have stated my case clear. > > Then the question is, is there a nice solution? > > thanx > From Scott.Daniels at Acm.Org Tue Jun 2 09:18:53 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 02 Jun 2009 06:18:53 -0700 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> Message-ID: Michael H. Goldwasser wrote: > On Monday June 1, 2009, Scott David Daniels wrote: > >> Michael H. Goldwasser wrote: >> > .... I'll accept the "small price for flexibility" that you >> > note, if necessary. However, I still desire a cleaner solution. >> >> You seem to think that "deepcopy" is a well-defined concept. .... > > It is clear from my original statement of the question that there is > a need for classes to be able to customize their own semantics for > supporting the deepcopy function. That is why the deepcopy function > looks for a __deepcopy__ method within a class as a hook. > > My concern involves the challenge of providing a valid > implementation for __deepcopy__ at one level of inheritance without > being overly dependent on the internal mechanism used by ancestor > classes in supporting deepcopy. I don't see how your comments > address that question. I only meant to say, if you are looking for something neater, consider whether there is such a thing. Issues with deepcopy may be (and I suspect are) inherently messy. Further, inheritance usually provides (in practice) a "built from" relationship, not an "is a" relationship. "Liskov Substitutability," is a design goal, honored except in corner cases and where inconvenient. --Scott David Daniels Scott.Daniels at Acm.Org From petshmidt at googlemail.com Tue Jun 2 09:32:46 2009 From: petshmidt at googlemail.com (someone) Date: Tue, 2 Jun 2009 06:32:46 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres Message-ID: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> Hi, I'm using pyPgSQL for accessing Postgres and do some update and select queries. and getting WARNING: there is already a transaction in progress if I run runUpdate more than once. So, what happens is following: 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- __existRecord 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- again __existRecord and here I'm getting the warning. Can anyone explain me please what the problem is? I do select, then delete transaction and then select again which doesn't work Regards, Pet class Bla: def __init__: pass def runUpdate(self, number=5): data = {} data = self.__getUpdateItems(number) for row in data: try: if self.__existRecord(row['q']): self.__delQuery(row['q']) except Exception, e: print "Exception", e def __delQuery(self, name): query = """ BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; """ try: self.db.execute(query, name) except Exception, e: print "Exception: ", e return True def __existRecord(self, search): query = """ SELECT address FROM address WHERE LOWER(address) = LOWER (%s); """ try: self.db.execute(query, search) except Exception, e: print "Exception: ", e return self.db.fetchall() def __getUpdateItems(self,number=5): values = [number] query = """ SELECT * FROM failed WHERE id IS NULL ORDER BY up DESC LIMIT %s; """ result = [] try: self.db.execute(query, *values) result = self.db.fetchall() except Exception, e: print "Exception getUpdateItems: ", e return result From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Jun 2 09:44:40 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 2 Jun 2009 13:44:40 +0000 (UTC) Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: Hans M?ller wrote: > Hello experts, > > I'm looking for secure way to pass messages from a python program to a c-library in both ways. > > This scenario is given: > > display client Calculation module in COBOL (yes, big, old but it works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. > Has someone an idea what to use ? > > I have had a short look on xml rpc which can run over a https server but this seems quite fat. > Better ideas ?! Standard TCP connection, forwarded via stunnel or ssh, Should be no brainer if the COBOL side is running on a reasonably modern unix. -- ----------------------------------------------------------- | 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 Scott.Daniels at Acm.Org Tue Jun 2 09:55:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 02 Jun 2009 06:55:48 -0700 Subject: do replacement evenly In-Reply-To: References: Message-ID: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> oyster wrote: > I have some strings, and I want to write them into a text files, one > string one line > but there is a requirement: every line has a max length of a certain > number ... If you are doing this to fill and justify text, I seem to remember a research result stating that filled text (with smooth left and right margins) works well for proportional fonts, but decreases readability for fixed pitch fonts, where ragged right (or ragged left) works better. Sadly, I have no idea where I read that as it is only in the recesses of my somewhat addled brain. --Scott David Daniels Scott.Daniels at Acm.Org From paul at boddie.org.uk Tue Jun 2 09:58:53 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 2 Jun 2009 06:58:53 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> Message-ID: <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> On 2 Jun, 15:32, someone wrote: > Hi, > I'm using pyPgSQL for accessing Postgres and do some update and select > queries. > and getting WARNING: ?there is already a transaction in progress if I > run runUpdate more than once. I think this is because you're using explicit transaction statements amongst the SQL statements you're sending to the database system, whereas pyPgSQL probably starts transactions on your behalf if you've not enabled autocommit. > So, what happens is following: > > 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > __existRecord > 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery > 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > again __existRecord > and here I'm getting the warning. Here, statement #3 may well start a new transaction - a convenience introduced by pyPgSQL in order to provide DB-API compliance and automatic transactions - and when __delQuery is invoked, PostgreSQL will complain that you are trying to start another transaction. Really, you should use the commit method on the cursor object (self.db, I presume) and the rollback method when you want to start a new transaction without changing anything. Alternatively, you could set autocommit to true on the connection object and be sure to always use transaction statements (BEGIN, COMMIT, ROLLBACK) where appropriate. Paul From rustompmody at gmail.com Tue Jun 2 10:15:36 2009 From: rustompmody at gmail.com (rustom) Date: Tue, 2 Jun 2009 07:15:36 -0700 (PDT) Subject: what I would like python.el to do (and maybe it does) References: Message-ID: <6193e4aa-9bcf-4ef4-a9bb-097f83008f0b@b1g2000vbc.googlegroups.com> > But since i like to do it The Right Way, I would > like to let the python-mode worry about this... > > Sorry if this is just a bunch of obvious thoughts to most of you. > > Regards, > Giovanni I dont see whats the problem. Heres my attempt to show you my emacs windows using python-mode (python.el never worked for me) ## Window 1 file foo.py (python mode) x = 1 y = 2 ## Window 2 python interpreter >>> #### Goto the python file (foo.py) Select the x=1 line C-c | (which is py-execute-region) Goto python interpreter window >>> x 1 >>> y ... NameError: y not defined What more/less/else do you want? Are you using python-mode.el or python.el? From python at bdurham.com Tue Jun 2 10:44:04 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 02 Jun 2009 10:44:04 -0400 Subject: do replacement evenly In-Reply-To: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> References: <5uudnccVjfthsLjXnZ2dnUVZ_hSdnZ2d@pdx.net> Message-ID: <1243953844.12516.1318388745@webmail.messagingengine.com> Here's how we normalize whitespace in multiline blocks of text. Perhaps you can adapt this routine to your needs? Watch for line wrap. # clean up duplicate whitespace, leading/trailing whitespace, triple CRLF's def fixwhitespace( text ): output = [] lastLine = '' # split text into list of individual lines lines = text.strip().splitlines() for line in lines: # remove leading, trailing, and duplicate whitespace within a line line = ' '.join( line.split( None ) ) # ignore multiple blank lines if not line and not lastLine: pass else: output.append( line ) lastLine = line return '\n'.join( output ) Regards, Malcolm From petshmidt at googlemail.com Tue Jun 2 10:49:02 2009 From: petshmidt at googlemail.com (Tep) Date: Tue, 2 Jun 2009 07:49:02 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> Message-ID: On Jun 2, 3:58?pm, Paul Boddie wrote: > On 2 Jun, 15:32, someone wrote: > > > Hi, > > I'm using pyPgSQL for accessing Postgres and do some update and select > > queries. > > and getting WARNING: ?there is already a transaction in progress if I > > run runUpdate more than once. > > I think this is because you're using explicit transaction statements > amongst the SQL statements you're sending to the database system, > whereas pyPgSQL probably starts transactions on your behalf if you've > not enabled autocommit. > > > So, what happens is following: > > > 1. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > > __existRecord > > 2. BEGIN;DELETE FROM failed WHERE uquery = %s;COMMIT; -- __delQuery > > 3. SELECT address FROM address WHERE LOWER(address) = LOWER(%s); -- > > again __existRecord > > and here I'm getting the warning. > > Here, statement #3 may well start a new transaction - a convenience > introduced by pyPgSQL in order to provide DB-API compliance and > automatic transactions - and when __delQuery is invoked, PostgreSQL > will complain that you are trying to start another transaction. Ok, that make sense > > Really, you should use the commit method on the cursor object You mean connection object, do you? I've tried that, but forgotten to remove BEGIN;COMMIT; statements from my queries Now, I do commit on connection object after _each_ query and it seems to work :) > (self.db, I presume) and the rollback method when you want to start a > new transaction without changing anything. Alternatively, you could > set autocommit to true on the connection object and be sure to always > use transaction statements (BEGIN, COMMIT, ROLLBACK) where > appropriate. In that way it works too, which means, everything is clear now Thanks for help! > > Paul From icanbob at gmail.com Tue Jun 2 11:23:49 2009 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 2 Jun 2009 08:23:49 -0700 (PDT) Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: <413087c0-bca7-4f43-98cf-b31221a47962@e24g2000vbe.googlegroups.com> On Jun 2, 5:28 am, Hans M?ller wrote: > Hello experts, > > I'm looking for secure way to pass messages from a python program to a c-library in both ways. > > This scenario is given: > > display client Calculation module in COBOL (yes, big, old but it works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. > Has someone an idea what to use ? > > I have had a short look on xml rpc which can run over a https server but this seems quite fat. > Better ideas ?! > Importand is also that the C-Lib on the cobol side should be coded as simple as possible. > Platforms: Windows, *ix > > Thanks a lot. > > Hans The SIMPL toolkit is quite lightweight (http://www.icanprogram.com/ simpl). It can be used to join a Python program to a C program. However, SIMPL messages are treated as blocks of bytes from the prespective of the toolkit. It should be quite straightforward to graft an encription layer above this to do what you want. If you want some "hello world" level Python-SIMPL examples you can look here: http://www.icanprogram.com/06py/main.html bob From aahz at pythoncraft.com Tue Jun 2 11:27:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 08:27:02 -0700 Subject: hash and __eq__ References: <003e1491$0$9723$c3e8da3@news.astraweb.com> Message-ID: In article <003e1491$0$9723$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sun, 31 May 2009 07:24:09 +0100, Arnaud Delobelle wrote: >> >> AFAIK, 'complexity' means 'worst case complexity' unless otherwise >> stated. > >No, it means "average or typical case" unless otherwise specified. >Consult almost any comp sci text book and you'll see hash tables with >chaining (like Python dicts) described as O(1) rather than O(N), >Quicksort as O(N log N) instead of O(N**2), and similar. If the default >was "worst case unless otherwise specified", then Quicksort would be >called "Slower than Bubblesort Sort". > >(Both are O(N**2), but Quicksort does more work.) > >Here's a quote on-line: > >"You should be clear about which cases big-oh notation describes. By >default it usually refers to the average case, using random data. >However, the characteristics for best, worst, and average cases can be >very different..." > >http://leepoint.net/notes-java/algorithms/big-oh/bigoh.html When talking about big-oh, I prefer to define "worst-case" as "real world likely worst-case" -- for example, feeding an already-sorted list to Quicksort. However, the kind of worst-case that causes a dict to have O(N) behavior I would call "pathological case". I generally try to define big-oh in terms of what I call worst-case, because I think it's important to keep track of where your algorithm is likely to run into problems, but I don't think it's worth the effort in most cases to worry about pathological cases. In the case of dicts, it's important to remember that pathological cases are far more likely to arise from poorly designed hashable user classes than from data problems per se; Python's hashing of built-in types has almost twenty years of tuning. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From paul at boddie.org.uk Tue Jun 2 13:38:09 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 2 Jun 2009 10:38:09 -0700 (PDT) Subject: pyPgSql there is already a transaction in progres References: <734b7247-a273-49c9-b1c6-f63789c0ddb8@f19g2000yqh.googlegroups.com> <80a4e836-e632-4296-9e87-a098b30d939e@o18g2000yqi.googlegroups.com> Message-ID: <64e2243a-4270-4b4d-a4d8-5c09a1bbbf3c@h23g2000vbc.googlegroups.com> On 2 Jun, 16:49, Tep wrote: > On Jun 2, 3:58?pm, Paul Boddie wrote: > > Really, you should use the commit method on the cursor object > > You mean connection object, do you? Yes, I meant the connection object. :-) > I've tried that, but forgotten to remove BEGIN;COMMIT; statements from > my queries > Now, I do commit on connection object after _each_ query and it seems > to work :) You should probably use rollback in order to close transactions just in case you've issued a statement which changes the database. Think of it as kind of a synchronisation operation. [...] > In that way it works too, which means, everything is clear now Great! Paul From robert.kern at gmail.com Tue Jun 2 13:42:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 12:42:47 -0500 Subject: Creating a Google Code project for GSoC In-Reply-To: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> References: <171e8a410906011654i10a4bb4ek980233b9be5e9201@mail.gmail.com> Message-ID: On 2009-06-01 18:54, Eric Pruitt wrote: > Hello everyone, > > I am a student working on GSoC 2009 for PSF. My proposal involves making > changes to the subprocess module and subprocess.Popen. I wish to create > a Google Code project to host my changes so that I can receive feedback > from the community. Some of the code I have incorporated falls under an > MIT license. Python's license is not GPL but is GPL compatible. What > license should the Google Code project fall under? MIT, GPL or something > else? You should talk to your mentor and the PSF GSoC coordinator, but generally code intended for inclusion in Python itself needs to be licensed under the Apache License v2.0 or the Academic Free License v2.1: http://www.python.org/psf/contrib/ You will also need to sign a contributor agreement. But talk to your mentor. -- 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 stef.mientki at gmail.com Tue Jun 2 15:24:28 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 02 Jun 2009 21:24:28 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: <0234781f$0$8244$c3e8da3@news.astraweb.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> Message-ID: <4A257C6C.4080502@gmail.com> > The same rule applies for your modules. As a general rule, NEVER say: > > execfile('mymodule.py') > > instead do: > > import mymodule > mymodule.some_function() > mymodule.another_function() > > > (There are exceptions, but if you need to ask what they are, you're not > ready to learn them! *wink*) > > > hi Steven, maybe you hit the nail right on his head. But I finally want to release my program, with or without proper imports, but working correctly. And I'll leave the "import details" to some other guru. thanks, Stef From mrstevegross at gmail.com Tue Jun 2 15:40:56 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 2 Jun 2009 12:40:56 -0700 (PDT) Subject: Safe to import __builtin__ ? Message-ID: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Is it generally safe to explicitly import __builtin__ in python? That is, my code reads like this: === foo.py === import __builtin__ ... print __builtin__.type('a') === EOF === It seems like it should be a safe import, but I just want to make sure. Thanks, --Steve From robert.kern at gmail.com Tue Jun 2 15:52:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 14:52:04 -0500 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A257C6C.4080502@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: On 2009-06-02 14:24, Stef Mientki wrote: > >> The same rule applies for your modules. As a general rule, NEVER say: >> >> execfile('mymodule.py') >> >> instead do: >> >> import mymodule >> mymodule.some_function() >> mymodule.another_function() >> >> >> (There are exceptions, but if you need to ask what they are, you're >> not ready to learn them! *wink*) >> >> > hi Steven, > maybe you hit the nail right on his head. > But I finally want to release my program, with or without proper > imports, but working correctly. > And I'll leave the "import details" to some other guru. Getting the "import details" right is how you get it to work correctly. -- 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 Tue Jun 2 16:44:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Jun 2009 21:44:58 +0100 Subject: Safe to import __builtin__ ? In-Reply-To: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <4A258F4A.6040402@mrabarnett.plus.com> mrstevegross wrote: > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: > > === foo.py === > import __builtin__ > ... > print __builtin__.type('a') > === EOF === > > It seems like it should be a safe import, but I just want to make > sure. > Why do you want to import it? See http://docs.python.org/library/__builtin__.html From joseph.h.garvin at gmail.com Tue Jun 2 16:50:24 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Tue, 2 Jun 2009 15:50:24 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) Message-ID: So I was curious whether it's possible to use the ctypes module with C++ and if so how difficult it is. I figure in principal it's possible if ctypes knows about each compiler's name mangling scheme. So I searched for "ctypes c++" on Google. The third link will be "Using ctypes to Wrap C++ Libraries". If you follow the link, it's broken. If you view the cache of the link, it's someone pointing to another blog, retrograde-orbit.blogspot.com, saying they discovered a way to do it easily. If you follow that link, you get taken a page does not exist error. Clearly there's some way to use ctypes with C++ and there's a vast conspiracy preventing it from reaching the masses ;) What's even stranger is that this link, despite being broken, has seemingly been near the top of google's results for these terms for a couple weeks (that's when I last tried), as if there were some underground group of rebels trying to hint the truth to us... ;) More seriously -- how difficult is it to use ctypes instead of saying, boost::python, and why isn't this in a FAQ somewhere? ;) From deets at nospam.web.de Tue Jun 2 17:11:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 02 Jun 2009 23:11:58 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78lit5F1mviblU1@mid.uni-berlin.de> Joseph Garvin schrieb: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) Because it's much more needed than name-mangling. Name mangling is (amongst other things) one thing to prevent C++-inter-compiler-interoperability which results from differing C++ ABIs. I'm not an expert on this, but AFAIK no common ABI exists, especially not amongst VC++ & G++. Which means that to work for C++, ctypes would need to know about the internals of both compilers, potentially in several versions, and possibly without prior notice to changes. Instead of dealing with this truly daunting task, tools such as SIP and SWIG or boost::python deal with this by utilizing the one tool that really knows about the ABI in use - the compiler itself. So while I'd loved to be proven wrong, I fear your curiosity won't be satisfied - or at least not in the positive sense you certainly envisioned. Diez From gagsl-py2 at yahoo.com.ar Tue Jun 2 17:23:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Jun 2009 18:23:03 -0300 Subject: Challenge supporting custom deepcopy with inheritance References: <18978.63514.319199.287551@Michael-Goldwassers-Computer.local> <1c2a2c590905311858x4fa7ec79t5a876c45b78ad6a1@mail.gmail.com> <18978.5438.755496.633709@Michael-Goldwassers-Computer.local> <18979.19148.208649.805972@Michael-Goldwassers-Computer.local> <18980.3479.234994.204687@Michael-Goldwassers-Computer.local> Message-ID: En Tue, 02 Jun 2009 07:34:43 -0300, Lie Ryan escribi?: > Gabriel Genellina wrote: >> En Mon, 01 Jun 2009 14:19:19 -0300, Michael H. Goldwasser >> escribi?: >> >>> I can examine the inherited slots to see which special methods are >>> there, and to implement my own __deepcopy__ accordingly. But to do >>> so well seems to essentially require reimplementing the complicated >>> logic of the copy.deepcopy function. That is, if my new class is >>> the first to be implementing an explicit __deepcopy__ function, I >>> seem to have no easy way to invoke the inherited version of >>> "deepcopy(self)". >> >> Yes, that's a problem. But there is a workaround: since __deepcopy__ is >> searched *in the instance* (unlike many other __special__ methods, that >> are usually searched in the class itself) you can fool the copy logic >> into thinking there is no __deepcopy__ method defined, just by >> (temporarily) setting an instance attribute __deepcopy__ to None. (It's >> a hack, anyway) > > I've never really used pickle before but maybe you could try pickling > then unpickling? It is a hack, but for some objects that does not have > __deepcopy__ it might be sufficient. deepcopy essencially does that, without the intermediate storage. The problem is, how to customize deepcopy(something) in a derived class, if there is no way to call the inherited behavior from its base class. -- Gabriel Genellina From sh00le1 at gmail.com Tue Jun 2 17:39:59 2009 From: sh00le1 at gmail.com (sh00le) Date: Tue, 2 Jun 2009 14:39:59 -0700 (PDT) Subject: Creating Mac OS X app Message-ID: Hi, This is my first post here, hope this is the right group, and sorry for my broken English. So, let's start. I have created small PyQt application Simple Task Timer (http://code.google.com/p/simpletasktimer/). Also I created windows binary distro with py2exe, and Linux packages (.rpm and .deb). I would like to have Mac OS X .app binary distro but I don't have Mac OS, and I can't install Mac OS as guest on Virtual Box. Now, I'm searching for some volunteers with Mac OS who would like to test application on Mac OS, and (if it's possible) to create .app binary for Simple Task Timer. Any help would be appreciated. Tnx for reading. From mrstevegross at gmail.com Tue Jun 2 17:45:17 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 2 Jun 2009 14:45:17 -0700 (PDT) Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <3a22049a-6da3-4650-a90e-d355a026eb87@s16g2000vbp.googlegroups.com> > Why do you want to import it? > > Seehttp://docs.python.org/library/__builtin__.html I'm using a weird python environment that overloads a few builtin functions. In order to run them, I need to explicitly invoke "__builtin__.foo()" to make sure I get the real builtin version, not the overloaded one. --Steve From trhaynes at gmail.com Tue Jun 2 17:56:42 2009 From: trhaynes at gmail.com (trhaynes) Date: Tue, 2 Jun 2009 14:56:42 -0700 (PDT) Subject: py2app and OpenGL, "No module named util" in ctypes References: <4b5d6a4d-975e-4459-af9a-926b19aaa7d4@y10g2000prc.googlegroups.com> Message-ID: On May 28, 6:28?pm, Carl Banks wrote: > On May 28, 11:06?am, trhaynes wrote: > > > > > I'm trying to use py2app to package an OpenGL app, so first I tried to > > build the example here > > >http://svn.pythonmac.org/py2app/py2app/trunk/examples/PyOpenGL/ > > > and I get the error: > > > > ?File "/opt/local/lib/python2.5/site-packages/PyOpenGL-3.0.0c1-py2.5.egg/OpenGL/platform/darwin.py", line 24, in > > > ? ?import ctypes, ctypes.util > > >ImportError: No module named util > > >2009-05-28 13:55:06.819 lesson5[19965:10b] lesson5 Error > > >2009-05-28 13:55:06.821 lesson5[19965:10b] lesson5 Error > > >An unexpected error has occurred during execution of the main script > > > >ImportError: No module named util > > > But when I open up my python interactive interpreter and "import > > ctypes.util", it works fine (using lesson5.app/Contents/MacOS/python, > > too). > > > Thanks for the help. > > What has happened is that py2app didn't bundle ctypes.util with the > app, because py2app failed to detect that it was imported for some > reason. > > A typical workaround is to imported in maually in your main script to > make it explicit to py2app that it should be packaged. > > A word of caution: PyOpenGL uses entry hooks and that can cause a lot > of trouble for application builder utilities like py2exe and py2app. > In fact, I decided to stop using PyOpenGL in my projects in large part > because of that issue (I use my own OpenGL wrapper now). ?It's > possible py2app has learned to deal with entry hooks by now, but these > days I refuse to use packages that require entry hooks so I wouldn't > know. > > Carl Banks Thanks all. I had to add ctypes.util to the list of includes for it to work. From BrianVanderburg2 at aim.com Tue Jun 2 18:02:47 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Tue, 02 Jun 2009 18:02:47 -0400 Subject: Copying objects and multiple inheritance Message-ID: <4A25A187.3050908@aim.com> What is the best way to copy an object that has multiple inheritance with the copy module. Particularly, some of the instances in the hierarchy use the __copy__ method to create a copy (because even for shallow copies they need some information updated a little differently), so how can I make sure all the information is copied as it is supposed to be even for the base classes that have special requirements. Brian Vanderburg II From rtw at freenet.co.uk Tue Jun 2 18:13:59 2009 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 02 Jun 2009 17:13:59 -0500 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) References: Message-ID: '2+ wrote in news:mailman.1017.1243932401.8015.python-list at python.org in comp.lang.python: > would like to take advantage of the wave module > found a good example here: > http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 > > hmm .. i don't get how to write a stereo .. i mean i can set nchannels > .. but how do i actually take control of each ch individually? Interleave the channels, one sample for the left then one sample for the right (or maybe its the other way around). > and what's the range(in float) of the data i can set in The range of a signed 16 bit int, -2**15 to 2**15 - 1. > wav_file.writeframes(struct.pack('h', data))? Example: import wave from StringIO import StringIO out = StringIO() AMPLITUDE = 2 ** 15 w = wave.open( out, "w" ) w.setnchannels( 2 ) w.setsampwidth( 2 ) #BYTES w.setframerate( 22000 ) from array import array import math F = 261.626 F2 = F * (2 ** (5 / 12.)) ang = 0.0 ang2 = 0.0 delta = ( math.pi * 2 * F ) / 22000.0 delta2 = ( math.pi * 2 * F2 ) / 22000.0 for cycle in xrange( 4 ): data = array( 'h' ) for pos in xrange( 22000 ): amp = AMPLITUDE * (pos / 22000.0) amp2 = AMPLITUDE - amp if cycle & 1: amp, amp2 = amp2, amp data.append( int( ( amp * math.sin( ang ) ) ) ) data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) ang += delta ang2 += delta2 w.writeframes( data.tostring() ) w.close() sample = out.getvalue() out.close() #a wx player import wx app = wx.PySimpleApp() class Frame( wx.Dialog ): def __init__( self, *args ): wx.Dialog.__init__( self, *args ) b = wx.Button( self, -1, "Ok" ) b.Bind( wx.EVT_BUTTON, self.button ) def button( self, event ): self.sound = wx.SoundFromData( sample ) self.sound.Play( wx.SOUND_ASYNC ) frame = Frame( None ) frame.Show() app.MainLoop() Rob. -- http://www.victim-prime.dsl.pipex.com/ From nick at craig-wood.com Tue Jun 2 18:29:43 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 02 Jun 2009 17:29:43 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Joseph Garvin schrieb: > > So I was curious whether it's possible to use the ctypes module with > > C++ and if so how difficult it is. I figure in principal it's possible > > if ctypes knows about each compiler's name mangling scheme. So I > > searched for "ctypes c++" on Google. [snip] > > More seriously -- how difficult is it to use ctypes instead of saying, > > boost::python, and why isn't this in a FAQ somewhere? ;) > > Because it's much more needed than name-mangling. Name mangling is > (amongst other things) one thing to prevent > C++-inter-compiler-interoperability which results from differing C++ ABIs. > > I'm not an expert on this, but AFAIK no common ABI exists, especially > not amongst VC++ & G++. Which means that to work for C++, ctypes would > need to know about the internals of both compilers, potentially in > several versions, and possibly without prior notice to changes. Probably depends on how far you want to dig into C++. I'm sure it will work fine for simple function calls, passing classes as anonymous pointers etc. If you want to dig into virtual classes with multiple bases or the STL then you are probably into the territory you describe. That said I've used C++ with ctypes loads of times, but I always wrap the exported stuff in extern "C" { } blocks. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From a.cavallo at mailsnare.com Tue Jun 2 18:58:34 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Tue, 2 Jun 2009 23:58:34 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906022358.35256.a.cavallo@mailsnare.com> Mmmm, not really a conspiracy but it is not that trivial.... In wrapping c++ you might find useful the commands nm with c++filt although they work under linux there is the same pair for every platform (under windows I remember there is objdump): they should only you need to wrap a c++ library. I've been wrapping in the past c++ using boost and it was trivial although I haven't tried enough to break it. swig, in older versions, is really bad: I can't comment on newer versions but I'd have a look to the generated code before using it. sip it looks quite difficult to use, but is well maintained. If you have a moderate control on the library design the ctype is the best approach IMHO. Regards, Antonio On Tuesday 02 June 2009 21:50:24 Joseph Garvin wrote: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) From stef.mientki at gmail.com Tue Jun 2 19:00:15 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Jun 2009 01:00:15 +0200 Subject: how to get the path of a module (myself) ? In-Reply-To: References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: <4A25AEFF.5030506@gmail.com> Robert Kern wrote: > On 2009-06-02 14:24, Stef Mientki wrote: >> >>> The same rule applies for your modules. As a general rule, NEVER say: >>> >>> execfile('mymodule.py') >>> >>> instead do: >>> >>> import mymodule >>> mymodule.some_function() >>> mymodule.another_function() >>> >>> >>> (There are exceptions, but if you need to ask what they are, you're >>> not ready to learn them! *wink*) >>> >>> >> hi Steven, >> maybe you hit the nail right on his head. >> But I finally want to release my program, with or without proper >> imports, but working correctly. >> And I'll leave the "import details" to some other guru. > > Getting the "import details" right is how you get it to work correctly. > Sorry, but I realy don't understand the difference between the documents on my desk and a python file in a subpath. cheers, Stef From basti.wiesner at gmx.net Tue Jun 2 19:11:39 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Wed, 03 Jun 2009 01:11:39 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: > Diez B. Roggisch wrote: >> Joseph Garvin schrieb: >> > So I was curious whether it's possible to use the ctypes module with >> > C++ and if so how difficult it is. I figure in principal it's possible >> > if ctypes knows about each compiler's name mangling scheme. So I >> > searched for "ctypes c++" on Google. > [snip] >> > More seriously -- how difficult is it to use ctypes instead of saying, >> > boost::python, and why isn't this in a FAQ somewhere? ;) >> >> Because it's much more needed than name-mangling. Name mangling is >> (amongst other things) one thing to prevent >> C++-inter-compiler-interoperability which results from differing C++ >> ABIs. >> >> I'm not an expert on this, but AFAIK no common ABI exists, especially >> not amongst VC++ & G++. Which means that to work for C++, ctypes would >> need to know about the internals of both compilers, potentially in >> several versions, and possibly without prior notice to changes. > > Probably depends on how far you want to dig into C++. I'm sure it > will work fine for simple function calls, passing classes as anonymous > pointers etc. If you want to dig into virtual classes with multiple > bases or the STL then you are probably into the territory you > describe. Name mangeling starts with namespaces, and namespaces are a thing often seen in well-designed C++-libraries. So even a simple C++-function call could become rather difficult to do using ctypes ... > That said I've used C++ with ctypes loads of times, but I always wrap > the exported stuff in extern "C" { } blocks. No wonder, you have never actually used C++ with C types. An extern "C" clause tells the compiler to generate C functions (more precisely, functions that conform to the C ABI conventions), so effectively you're calling into C, not into C++. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From robert.kern at gmail.com Tue Jun 2 19:19:41 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Jun 2009 18:19:41 -0500 Subject: how to get the path of a module (myself) ? In-Reply-To: <4A25AEFF.5030506@gmail.com> References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> <4A25AEFF.5030506@gmail.com> Message-ID: On 2009-06-02 18:00, Stef Mientki wrote: > Robert Kern wrote: >> On 2009-06-02 14:24, Stef Mientki wrote: >>> >>>> The same rule applies for your modules. As a general rule, NEVER say: >>>> >>>> execfile('mymodule.py') >>>> >>>> instead do: >>>> >>>> import mymodule >>>> mymodule.some_function() >>>> mymodule.another_function() >>>> >>>> >>>> (There are exceptions, but if you need to ask what they are, you're >>>> not ready to learn them! *wink*) >>>> >>>> >>> hi Steven, >>> maybe you hit the nail right on his head. >>> But I finally want to release my program, with or without proper >>> imports, but working correctly. >>> And I'll leave the "import details" to some other guru. >> >> Getting the "import details" right is how you get it to work correctly. >> > Sorry, > but I realy don't understand the difference between the documents on my > desk and a python file in a subpath. I really don't understand what relevance you think that has to writing correct Python programs. Yes, Python files are, indeed, files. But the correct way to write Python programs in multiple Python files is to organize them into modules and packages and use Python's import mechanism to make them reference each other. Please read the tutorial: http://docs.python.org/tutorial/modules.html -- 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 davea at ieee.org Tue Jun 2 19:43:04 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 02 Jun 2009 19:43:04 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <4A25B908.5090807@ieee.org> Joseph Garvin wrote: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. I figure in principal it's possible > if ctypes knows about each compiler's name mangling scheme. So I > searched for "ctypes c++" on Google. > > The third link will be "Using ctypes to Wrap C++ Libraries". If you > follow the link, it's broken. If you view the cache of the link, it's > someone pointing to another blog, retrograde-orbit.blogspot.com, > saying they discovered a way to do it easily. If you follow that link, > you get taken a page does not exist error. > > Clearly there's some way to use ctypes with C++ and there's a vast > conspiracy preventing it from reaching the masses ;) What's even > stranger is that this link, despite being broken, has seemingly been > near the top of google's results for these terms for a couple weeks > (that's when I last tried), as if there were some underground group of > rebels trying to hint the truth to us... ;) > > More seriously -- how difficult is it to use ctypes instead of saying, > boost::python, and why isn't this in a FAQ somewhere? ;) > > There are two possibilities here. You might have an existing DLL, written entirely in C++, with thoroughly mangled exports. Or you might have a body of code, to which you're willing to make modifications for the interface. It's only the second I would attack with ctypes. In fact, the name mangling itself varies between versions of the same compiler, never mind between different brands. You should be able to export a class factory, defined as an extern("c"), and use that to get into the DLL. Once you have that, you can call any virtual functions of the class without any additional exports or name mangling needed. As long as the methods you're using are virtual, and singly inherited, it's just a question of walking the vtable. So you should be able to build wrappers, using ctypes, for each of those methods. Note: I haven't actually done it, as the machine with the C++ compiler installed as been down for longer than I've had Python, and I haven't wanted C++ enough to want to install it on my notebook computer. But this is the approach I'd try. From sam at samuelwan.com Tue Jun 2 19:44:40 2009 From: sam at samuelwan.com (Samuel Wan) Date: Tue, 2 Jun 2009 16:44:40 -0700 Subject: "Exploding" (**myvariable) a dict with unicode keys Message-ID: <1d3db2990906021644j5228355l8fb347ca7f39f1d1@mail.gmail.com> I started using python last week and ran into exceptions thrown when unicode dictionary keys are exploded into function arguments. In my case, decoded json dictionaries did not work as function arguments. There was a thread from Oct 2008 (http://www.gossamer-threads.com/lists/python/python/684379) about the same problem. Here is my workaround: ------------------ start code --------------- def safe_dict(d): """Recursively clone json structure with UTF-8 dictionary keys""" if isinstance(d, dict): return dict([(k.encode('utf-8'), safe_dict(v)) for k,v in d.iteritems()]) elif isinstance(d, list): return [safe_dict(x) for x in d] else: return d #Example foo = { 'a':1, 'b':{'b1':2, 'b2':3}, 'c':[ 4, {'D1':2, 'D2':3}, ] } #generate and re-parse json to simulate dictionary with unicode keys dictionary = json.loads(json.dumps(foo)) # shows unicode keys, like u"a" print dictionary # shows utf8 keys, like "a" converted_dictionary = safe_dict(dictionary) fun(**converted_dictionary) ------------------ end code --------------- I really like python! Hope this contributes to the thread. -Sam On Oct 3, 1:57 pm, Peter Otten <__pete... at web.de> wrote: > "Martin v. L?wis" wrote: > > Devin wrote: > >> So Python can have unicode variable names but you can't > >> "explode" (**myvariable) a dict with unicode keys? WTF? > > > That works fine for me. > > The OP probably means > > >>> def f(a=1): return a > ... > >>> f(**{"a": 42}) > 42 > >>> f(**{u"a": 42}) > > Traceback (most recent call last): > File "", line 1, in > TypeError: f() keywords must be strings > > Peter Yes, that's exactly what I mean. From roy at panix.com Tue Jun 2 19:56:06 2009 From: roy at panix.com (Roy Smith) Date: Tue, 02 Jun 2009 19:56:06 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In article <78lit5F1mviblU1 at mid.uni-berlin.de>, "Diez B. Roggisch" wrote: > > More seriously -- how difficult is it to use ctypes instead of saying, > > boost::python, and why isn't this in a FAQ somewhere? ;) > > Because it's much more needed than name-mangling. Name mangling is > (amongst other things) one thing to prevent > C++-inter-compiler-interoperability which results from differing C++ ABIs. Indeed. Name mangling is the most trivial way in which different C++ compilers do not interoperate. Some other thorny issues include exception handling, template instantiation, physical layout of struct and class elements (i.e. padding/alignment), and how references are returned (i.e. Return Value Optimization). I'm sure I've left out several critical items. It's an ugly world out there. From Eric_Dexter at msn.com Tue Jun 2 21:52:32 2009 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: Tue, 2 Jun 2009 18:52:32 -0700 (PDT) Subject: is anyone using text to speech to read python documentation Message-ID: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> I wrote a small pre-processor for python documentation and I am looking for advice on how to get the most natural sounding reading. I uploaded an example of a reading of lxml documentation as a podcast1 http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. From samwyse at gmail.com Tue Jun 2 22:15:50 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 2 Jun 2009 19:15:50 -0700 (PDT) Subject: Missing codecs in Python 3.0 Message-ID: I have a Python 2.6 program (a code generator, actually) that tries several methods of compressing a string and chooses the most compact. It then writes out something like this: { encoding='bz2_codec', data = '...'} I'm having two problems converting this to Py3. First is the absence of the bz2_codec, among others. It was very convenient for my program to delay selection of the decoding method until run-time and then have an easy way to load the appropriate code. Is this gone forever from the standard libraries? Second, I would write my data out using the 'string_escape' codec. It, too, has been removed; there's a 'unicode_escape' codec which is similar, but I would rather use a 'byte_escape' codec to produce literals of the form b'asdf'. Unfortunately, there isn't one that I can find. I could use the repr function, but that seems less efficient. Does anyone have any ideas? Thanks. From ben+python at benfinney.id.au Tue Jun 2 22:16:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Jun 2009 12:16:54 +1000 Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <87fxeirrhl.fsf@benfinney.id.au> mrstevegross writes: > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: > > === foo.py === > import __builtin__ > ... > print __builtin__.type('a') > === EOF === > > It seems like it should be a safe import, but I just want to make > sure. Yes, it's safe (and this is what the ?__builtin__? module is intended for: ). Be careful, though: there's a separate name, ?__builtins__?, that is *not* meant to be imported. It's also implementation-specific, so shouldn't be relied upon. My advice: don't use ?__builtins__? at all, but be aware that it exists so you spell ?__builtin__? correctly. -- \ ?This world in arms is not spending money alone. It is spending | `\ the sweat of its laborers, the genius of its scientists, the | _o__) hopes of its children.? ?Dwight Eisenhower, 1953-04-16 | Ben Finney From aahz at pythoncraft.com Tue Jun 2 22:23:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 19:23:50 -0700 Subject: how to find the last decorator of a chain References: Message-ID: In article , Gabriel wrote: > >I have something like this: > >@render(format="a") >@render(format="b") >@.... >def view(format, data): > return data > >Each render will do something with 'data' if format match, and nothing >if not. > >But if there is no more renders to eval, the last one is the default, >and must run even if the format doesn't match. My inclination would be to make this explicit with something like this: def make_render(func, format_list): def tmp(format, data): for f in format_list: if MATCH(format, f): render(data) break else: render(data) return tmp def view(format, data): return data view = make_render(view, ['a', 'b']) IOW, just because we have decorators doesn't mean that they're the best solution for all function-wrapping problems. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From clp2 at rebertia.com Tue Jun 2 22:35:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Jun 2009 19:35:23 -0700 Subject: Missing codecs in Python 3.0 In-Reply-To: References: Message-ID: <50697b2c0906021935o417a5907re53abbaecbc72629@mail.gmail.com> On Tue, Jun 2, 2009 at 7:15 PM, samwyse wrote: > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > ?{ encoding='bz2_codec', data = '...'} > > I'm having two problems converting this to Py3. ?First is the absence > of the bz2_codec, among others. ?It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. ?Is this gone forever from > the standard libraries? That appears to be the case. "bz2" is not listed on http://docs.python.org/3.0/library/codecs.html , but it is listed on the counterpart 2.6 doc page. You can always use the `bz2` module instead. Or write your own encoder/decoder for bz2 and register it with the `codecs` module. > Second, I would write my data out using the 'string_escape' codec. > It, too, has been removed; there's a 'unicode_escape' codec which is > similar, but I would rather use a 'byte_escape' codec to produce > literals of the form b'asdf'. ?Unfortunately, there isn't one that I > can find. ?I could use the repr function, but that seems less > efficient. ?Does anyone have any ideas? ?Thanks. Well, if you can guarantee the string contains only ASCII, you can just unicode_escape it, and then prepend a "b". On the other hand, I don't see any reason why repr() would be inefficient as compared to the codec method. Cheers, Chris -- http://blog.rebertia.com From aahz at pythoncraft.com Tue Jun 2 22:51:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 2 Jun 2009 19:51:19 -0700 Subject: Challenge supporting custom deepcopy with inheritance References: Message-ID: In article , Michael H. Goldwasser wrote: > >Assume that class B inherits from class A, and that class A has >legitimately customized its deepcopy semantics (but in a way that is >not known to class B). If we want a deepcopy of B to be defined so >that relevant state inherited from A is copied as would be done for >class A, and with B able to control how to deepcopy the extra state >that it introduces. I cannot immediately find a general way to >properly implement the deepcopy of B. > > [...] > >class A(object): > def __init__(self, aTag): > self.__aTag = aTag > self.__aList = [] IMO, your problem starts right here. Not only are you using customized attributes for each class, you're using class-private identifiers. You would vastly simplify your work if you switch to single-underscore attributes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ my-python-code-runs-5x-faster-this-month-thanks-to-dumping-$2K- on-a-new-machine-ly y'rs - tim From pavlovevidence at gmail.com Tue Jun 2 22:59:06 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Jun 2009 19:59:06 -0700 (PDT) Subject: Missing codecs in Python 3.0 References: Message-ID: <471fae80-b732-4db3-8ca8-155130346c25@s21g2000vbb.googlegroups.com> On Jun 2, 7:35?pm, Chris Rebert wrote: > On Tue, Jun 2, 2009 at 7:15 PM, samwyse wrote: > > I have a Python 2.6 program (a code generator, actually) that tries > > several methods of compressing a string and chooses the most compact. > > It then writes out something like this: > > ?{ encoding='bz2_codec', data = '...'} > > > I'm having two problems converting this to Py3. ?First is the absence > > of the bz2_codec, among others. ?It was very convenient for my program > > to delay selection of the decoding method until run-time and then have > > an easy way to load the appropriate code. ?Is this gone forever from > > the standard libraries? > > That appears to be the case. "bz2" is not listed onhttp://docs.python.org/3.0/library/codecs.html, but it is listed on > the counterpart 2.6 doc page. > You can always use the `bz2` module instead. Or write your own > encoder/decoder for bz2 and register it with the `codecs` module. IIRC, they decided the codecs would only be used for bytes<->unicode encodings in Python 3.0 (which was their intended use all along), moving other mappings (like bz2) elsewhere. Not sure where they all went, though. It was convenient, admittedly, but also confusing to throw all the other codecs in with Unicode codecs. Carl Banks From ldo at geek-central.gen.new_zealand Tue Jun 2 23:51:56 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 15:51:56 +1200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In message , Sebastian Wiesner wrote: > > >> That said I've used C++ with ctypes loads of times, but I always wrap >> the exported stuff in extern "C" { } blocks. > > No wonder, you have never actually used C++ with C types. An extern "C" > clause tells the compiler to generate C functions (more precisely, > functions that conform to the C ABI conventions), so effectively you're > calling into C, not into C++. Seems like the only sane way to do it. In all other directions lies madness. From ldo at geek-central.gen.new_zealand Tue Jun 2 23:54:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 15:54:23 +1200 Subject: Seach for encrypted socket wrapper References: <4a24f0cc$0$3278$8e6e7893@newsreader.ewetel.de> Message-ID: In message <4a24f0cc$0$3278$8e6e7893 at newsreader.ewetel.de>, Hans M?ller wrote: > display client Calculation module in COBOL (yes, big, old but it > works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from > COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. Not sure what you mean by "fail save". But I have used protocols built on this sort of framework in several projects now. From martin at v.loewis.de Wed Jun 3 00:46:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 06:46:07 +0200 Subject: Missing codecs in Python 3.0 In-Reply-To: References: Message-ID: <4A26000F.5060703@v.loewis.de> samwyse wrote: > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > { encoding='bz2_codec', data = '...'} > > I'm having two problems converting this to Py3. First is the absence > of the bz2_codec, among others. It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. Is this gone forever from > the standard libraries? bz2 compression is certainly not gone from the standard library; it is still available from the bz2 module. I recommend that you write it like { decompressor = bz2.decompress, data = '...'} Then you can still defer invocation of the decompressor until you need the data. > Second, I would write my data out using the 'string_escape' codec. > It, too, has been removed; there's a 'unicode_escape' codec which is > similar, but I would rather use a 'byte_escape' codec to produce > literals of the form b'asdf'. Unfortunately, there isn't one that I > can find. I could use the repr function, but that seems less > efficient. Does anyone have any ideas? Why does the repr() function seem less efficient? Did you measure anything to make it seem so? I would recommend to use repr() exactly. Regards, Martin From kay at fiber-space.de Wed Jun 3 00:52:22 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Tue, 2 Jun 2009 21:52:22 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: On 3 Jun., 05:51, Lawrence D'Oliveiro wrote: > In message , Sebastian Wiesner wrote: > > > > > >> That said I've used C++ with ctypes loads of times, but I always wrap > >> the exported stuff in extern "C" { } blocks. > > > No wonder, you have never actually used C++ with C types. An extern "C" > > clause tells the compiler to generate C functions (more precisely, > > functions that conform to the C ABI conventions), so effectively you're > > calling into C, not into C++. > > Seems like the only sane way to do it. In all other directions lies madness. Yes but creating C stubs is also hard in presence of everything that is not basic C++. How would you wrap the STL? I suspect one ends up in creating a variant of SWIG and I wonder if it's not a good idea to just use SWIG then. From thebiggestbangtheory at gmail.com Wed Jun 3 00:54:02 2009 From: thebiggestbangtheory at gmail.com (thebiggestbangtheory at gmail.com) Date: Tue, 2 Jun 2009 21:54:02 -0700 (PDT) Subject: problem with sockets and transferring binary files Message-ID: Dear all, I am a python newbie. I am now progressing to writing a network app in python to learn more about it. I have a client and a server in python. The client sends a msg to the server asking it to tar a binary .dbxml file and then send it over to it. The steps are: from the 1. Client sends msg to server 2. Server tars up binary file and Encrypts it using ezpycrypto 3. Server sends it to client 4. Client receives file and decrypts it and untars it Surprisingly, the sha1 hash of the encrypted data before it is sent from server is different from the encrypted file data received by the client. I post some code below to provide more info about what I am doing. [code] #client after sending initial msg #get server replywhich sends back the .dbxml file myHost = '127.0.0.1' myPort = 20001 s1 = socket(AF_INET, SOCK_STREAM) # create a TCP socket s1.bind((myHost, myPort)) # bind it to the server port s1.listen(1) # allow 1 simultaneous # pending connections connection, address = s1.accept() # connection is a new socket while 1: data = connection.recv(10000000) # receive up to 10000000 bytes if data: info=decryptfile(data) #we have recieved a compressed .tar.gz file #write out info to a file buf = open(currentpath+'received-container.tar.gz', 'w') buf.write(info) buf.close() #testing code: must be removed os.system('sudo sha1sum '+currentpath+'received-xml- container.tar.gz') #uncompress os.system('sudo tar -xvzf '+currentpath+'received-xml- container.tar.gz') [/code] [code] #the server after receiving the msg from client #dump the binary file os.system('sudo cp '+'/'+path+'1.binary '+currentpath +'1.binary') #compress the file os.system('sudo tar -cvzf '+currentpath+'1.bin.tar.gz '+currentpath+'1.binary') #encrypt the file specified in command line cipher=encryptfile(secretkey, currentpath+'1.bin.tar.gz') #send it over to sender send_to_sender(cipher, senderaddress) #testing code: needs to be removed buf = open(currentpath+'cipher', 'w') buf.write(cipher) buf.close() os.system('sudo sha1sum '+currentpath+'cipher') [/code] [code] #function code def send_to_sender(cipher, servername): PORT = 20001 BUFF = 10000000 clientSocket = socket(AF_INET, SOCK_STREAM) HOST = servername ADDR = (HOST, PORT) clientSocket.connect(ADDR) clientSocket.send(cipher) clientSocket.close() [/code] What I see at the client side is 7105b60d3167f2424d9e2806c49cca86c00577ba received-container.tar.gz gzip: stdin: unexpected end of file tar: Unexpected EOF in archive tar: Unexpected EOF in archive tar: Error is not recoverable: exiting now da39a3ee5e6b4b0d3255bfef95601890afd80709 received-container.tar.gz gzip: stdin: unexpected end of file tar: Child returned status 1 tar: Error exit delayed from previous errors It seems two file pieces are received! but why? The buffer size is big enough to accept the whole thing in one go. The binary file is about 460K in size. Any pointers, comments will be greatly appreciated :-). Thanks From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:29:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:29:55 -0300 Subject: problem with sockets and transferring binary files References: Message-ID: En Wed, 03 Jun 2009 01:54:02 -0300, escribi?: > I am a python newbie. I am now progressing to writing a > network app in python to learn more about it. [...] > Surprisingly, the sha1 hash of the encrypted data before it is sent > from server is different from the encrypted file data received by the > client. > data = connection.recv(10000000) # receive up to 10000000 > bytes recv returns *up* *to* 10000000 bytes: maybe only one byte. You'll have to keep recv'ing the pieces until you get an empty string (when client closes the connection), or send the file size first and then the actual data. > buf = open(currentpath+'received-container.tar.gz', 'w') > buf.write(info) > buf.close() If you're on Linux it doesn't matter, but the 'w' above should be 'wb' for a binary file. > def send_to_sender(cipher, servername): > ... > clientSocket.send(cipher) Similar to recv above: send() might not send the whole string at once (try sendall instead). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:32:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:32:03 -0300 Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <4A247871.5090804@gmail.com> <9fdb569a0906020211t2c4c5d3w7df511570ee41640@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 06:11:30 -0300, Vlastimil Brom escribi?: > [...] just in case the main problem would be the > use of __file__ ... > It seems, that the exe files generated from py2exe don't recognise > this variable; > sometimes I used code like > > try: > __file__ > except NameError: # py2exe > __file__ = sys.path[0] I think you meant __file__ = sys.argv[0] > cf. e.g. > http://mail.python.org/pipermail/python-list/2001-May/085384.html That's a rather old post. The "right" way to obtain a resource from a package is using pkgutil.get_data(), and py2exe should support it by now. (I haven't tested, but I think it does). http://docs.python.org/library/pkgutil.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jun 3 01:44:34 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 02:44:34 -0300 Subject: Why date do not construct from date? References: <4A24B7D0.501@promsoft.ru> <50697b2c0906012314m5c1700cbgd25472dbe76234fe@mail.gmail.com> Message-ID: En Tue, 02 Jun 2009 08:07:32 -0300, Lie Ryan escribi?: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 03:14:22 -0300, Chris Rebert >> escribi?: >>> On Mon, Jun 1, 2009 at 10:25 PM, Alexandr N Zamaraev >>> wrote: >> >>>>>>> import datetime as dt >>>>>>> d = dt.date(2009, 10, 15) >>>>>>> dt.date(d) >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: function takes exactly 3 arguments (1 given) >> >>>> Why int form int, str from str, Decumal from Decumal can construct >>>> bat date from date not? >>> >>> Probably because the function signatures would be so different. str(), >>> int(), etc *always* take *exactly one* argument -- the object to >>> convert. In contrast, date() takes several integers corresponding to >>> the year, month, and day. Adding a second signature to it that took >>> exactly one argument (of type `date`) and copied it would be >>> significantly different from its other signature; in idiomatic Python, >>> one would typically make a separate, new function for this drastically >>> different signature. >> >> That doesn't convince me. It's not very consistent along the various >> types: int("3ab0",16) is rather different than int(3.2) but they're the >> same function... > > Strictly speaking int("3ab0",16) does not create an int from an int, > instead it creates an int from a string. > Maybe you want to say int(3) -> 3 ? I was replying to the argument "different signature => separate function". >>> However, the `date` type is immutable, so there's no reason at all to >>> try and copy a new instance from an existing one anyway, thus a >>> single-argument copy-constructor is completely unnecessary, hence why >>> there isn't one. >> >> Isn't the same for all other examples (int, float, str, Decimal...)? >> They're all immutable types, and some have several and rather different >> constructor signatures: > > int(ob), float(ob), and str(ob) are type casting (strictly speaking it > is not a type casting, but you get the idea); while date() is a > constructor for the date object. Strictly speaking int(ob), float(ob), > and str(ob) merely calls the special ob.__int__, ob.__float__, and > ob.__str__. Well, not really: py> "10".__int__ Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute '__int__' py> "10".__float__ Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute '__float__' int() and float() do the work themselves when given a string (they look more like "true" constructors than str(), which delegates to __str__ as you already said) En Tue, 02 Jun 2009 08:23:27 -0300, Lie Ryan escribi?: > In fact, the doc of int and float says "Convert a string or number to an > integer, if possible" and "Convert a string or number to a floating > point number, if possible" respectively. There is no mention that they > are constructors at all... I think this comes from the prehistoric ages when int/float/str were functions, not built-in types. En Tue, 02 Jun 2009 04:45:19 -0300, Peter Otten <__peter__ at web.de> escribi?: > For date you'd have to make the type check anyway, e. g. > > if isinstance(x, tuple): > x = date(*x) > else: > x = date(x) # useless will only succeed if x already is a date > > as there would be no other way to create a date from a single value. > > So the date() call in the else branch is completely redundant unless you > change date() to accept multiple types via the same signature: > > for x in "2000-01-01", datetime.now(), (2000, 1, 1): > print date(x) That's a more pragmatic response, in the line "because it isn't very useful". I can accept this other too: "because whoever wrote the datetime module didn't care to provide such constructor". -- Gabriel Genellina From thebiggestbangtheory at gmail.com Wed Jun 3 01:52:40 2009 From: thebiggestbangtheory at gmail.com (thebiggestbangtheory at gmail.com) Date: Tue, 2 Jun 2009 22:52:40 -0700 (PDT) Subject: problem with sockets and transferring binary files References: Message-ID: On Jun 2, 10:29?pm, "Gabriel Genellina" wrote: > En Wed, 03 Jun 2009 01:54:02 -0300, ? > escribi?: > > > ? ? ? ? ? ?I am a python newbie. I am now progressing to writing a > > network app in python to learn more about it. [...] > > Surprisingly, the sha1 hash of the encrypted data before it is sent > > from server is different ?from the encrypted file data received by the > > client. > > ? ? ? ? ? data = connection.recv(10000000) # receive up to 10000000 > > bytes > > recv returns *up* *to* 10000000 bytes: maybe only one byte. > You'll have to keep recv'ing the pieces until you get an empty string ? > (when client closes the connection), or send the file size first and then ? > the actual data. > > > ? ? ? ? ? ? buf = open(currentpath+'received-container.tar.gz', 'w') > > ? ? ? ? ? ? buf.write(info) > > ? ? ? ? ? ? buf.close() > > If you're on Linux it doesn't matter, but the 'w' above should be 'wb' for ? > a binary file. > > > def send_to_sender(cipher, servername): > > ? ? ... > > ? ? clientSocket.send(cipher) > > Similar to recv above: send() might not send the whole string at once (try ? > sendall instead). > > -- > Gabriel Genellina Thanks! :-) very helpful From kochhar.mw at gmail.com Wed Jun 3 02:15:49 2009 From: kochhar.mw at gmail.com (shailesh) Date: Tue, 2 Jun 2009 23:15:49 -0700 (PDT) Subject: Wrapping methods of built-in dict References: <6f21d89b-755d-40b8-a42b-0510e5580f93@g22g2000pra.googlegroups.com> Message-ID: <4fce42a0-894c-485f-b1f3-c83340ff1358@a7g2000yqk.googlegroups.com> On May 21, 10:13?pm, George Sakkis wrote: > On May 21, 5:55?pm, shailesh wrote: > > > There doesn't seem to be a predicate returning method wrappers. Is > > there an alternate way to query an object for attributes that are of > > method wrappers? > > Sure:>>> MethodWrapper = type({}.__init__) > >>> isinstance([].__len__, MethodWrapper) > > True > > But you're better off catching everything by checking with callable() > (or equivalently hasattr(obj, '__call__')). > > > This exercise also makes me question if I'm going about this > > correctly. If I want to add functionality to the methods of a class or > > an object are decorators and the inspect module the pythonic way to go > > about it? I can think of alternative implementations either through > > metaclasses or proxy objects. > > In my experience, it's quite unlikely to really want to decorate > indiscriminately *all* methods of a class/instance, let alone all the > special methods (e.g. __getattribute__ very rarely needs to be > overridden). Do you have an actual use case or are you just playing > around ? The use case I'm exploring is automatic lock acquisition and release. I've been trying to create a decorator which protects objects against concurrent modification by placing all attribute behind a mutex. More fine grained locking will probably perform better, but the convenience and reliability of auto-locking is nice. Suggestions for alternate implementations are most welcome. - Shailesh From pete at shinners.org Wed Jun 3 02:24:24 2009 From: pete at shinners.org (peteshinners) Date: Tue, 2 Jun 2009 23:24:24 -0700 (PDT) Subject: Python reimport Message-ID: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> I've implemented a working reimport that, "does what you want". After a bit of testing with friends, I'm releasing version 1.0 tonight. http://code.google.com/p/reimport/ There's still work to do, but this already does a bit of fancy transmuting to push the reimport changes into the runtime. This is not a fully solveable problem, but this also allows modules to define callbacks that can assist the process. Looking for a wider audience to test with. At minimum, my friends and I are using this as a huge relief to alternative workarounds. At best this release will spur wider adoption and further development. From martin at v.loewis.de Wed Jun 3 02:49:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 08:49:37 +0200 Subject: Problem building 64-bit python 2.6.2 on Solaris 10 In-Reply-To: References: <4a1f0a2c$0$30886$9b622d9e@news.freenet.de> <4a206c2f$0$13438$9b622d9e@news.freenet.de> <224ac3e2-a072-4518-9fab-3f81d83c55c6@l28g2000vba.googlegroups.com> <4a23fe33$0$20453$9b622d9e@news.freenet.de> Message-ID: <4A261D01.1080001@v.loewis.de> > I was able to compile ctypes with gcc4sparc without many changes to > the CFLAGS, etc. I had another weird error, but upgrading to the > latest gcc4sparc fixed it. One thing I'm not clear about is how > extensions are built. I noticed that my CFLAGS are not being passed > to gcc when building the extensions, so some of them are failing to > find the correct includes & libraries. How does one pass these flags? The most reliable strategy is to edit Modules/Setup, and uncomment the modules where you want to pass flags. These will then not be built through setup.py (but become builtin by default). Regards, Martin From ben+python at benfinney.id.au Wed Jun 3 02:54:32 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Jun 2009 16:54:32 +1000 Subject: Python reimport References: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> Message-ID: <87hbyxremv.fsf@benfinney.id.au> peteshinners writes: > I've implemented a working reimport that, "does what you want". After > a bit of testing with friends, I'm releasing version 1.0 tonight. When making an announcement of a new version of a project, please summarise in the announcement what that project is (i.e. what the program does), in a way that makes clear why it's relevant for the forum where you announce it. -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so (hiccup), but Kevin Costner with an English accent?? ?_Pinky | _o__) and The Brain_ | Ben Finney From martin at v.loewis.de Wed Jun 3 02:55:42 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 08:55:42 +0200 Subject: FILE object in Python3.0 extension modules In-Reply-To: References: Message-ID: <4A261E6E.5010005@v.loewis.de> > The purpose is to dump the contents of a Python extension type to disk > as binary data using C's fwrite() function. This isn't really possible anymore - the Python IO library has stopped using stdio. There are a couple of alternatives: 1. don't use fwrite(3) to write the binary data, but instead use PyObject_CallMethod to call .write on the file object. 2. don't use fwrite(3), but write(2). To do so, fetch the file descriptor from the Python file object, and use that. Make sure you flush the stream before writing to it, or else you may get the data in the wrong order. 3. use fdopen to obtain a FILE*; the comments for 2) apply. In addition, make sure to flush and discard the FILE* before letting Python continue to write to the file. Regards, Martin From gagsl-py2 at yahoo.com.ar Wed Jun 3 02:57:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 03:57:20 -0300 Subject: Copying objects and multiple inheritance References: <4A25A187.3050908@aim.com> Message-ID: En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II escribi?: > What is the best way to copy an object that has multiple inheritance > with the copy module. Particularly, some of the instances in the > hierarchy ("...some of the classes in...", I presume?) > use the __copy__ method to create a copy (because even for shallow > copies they need some information updated a little differently), so how > can I make sure all the information is copied as it is supposed to be > even for the base classes that have special requirements. If you don't control all the clases involved, there is little hope for a method like __copy__ to work at all... All classes must be written with cooperation in mind, using super() the "right" way. See "Python's Super Considered Harmful" [1] and "Things to Know About Python Super" [2][3][4] That said, and since multiple inheritance is the heart of the problem, maybe you can redesign your solution *without* using MI? Perhaps using delegation instead? [1] http://fuhm.net/super-harmful/ [2] http://www.artima.com/weblogs/viewpost.jsp?thread=236275 [3] http://www.artima.com/weblogs/viewpost.jsp?thread=236278 [4] http://www.artima.com/weblogs/viewpost.jsp?thread=237121 -- Gabriel Genellina From zhiyongfore at gmail.com Wed Jun 3 03:08:03 2009 From: zhiyongfore at gmail.com (fuzziy) Date: Wed, 3 Jun 2009 00:08:03 -0700 (PDT) Subject: why does my python's program die after change computer system time? Message-ID: <843f1445-4c15-4c9b-aa83-50ea3321eba3@z19g2000vbz.googlegroups.com> Microsoft windowsXP ???python2.6?????????????????????????????????????? ????????????????????????????after(200, tick)??????????????????????????? ???? import Tkinter import time curtime = '' clock_label = Tkinter.Label() clock_label.pack() def tick(): global curtime #print("1:") newtime = time.strftime('%Y-%m-%d %H:%M:%S') if newtime != curtime: curtime = newtime clock_label.config(text=curtime) clock_label.config(text=newtime) clock_label.after(200, tick) #print(curtime) tick() clock_label.mainloop() From deets at nospam.web.de Wed Jun 3 04:19:59 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 10:19:59 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78mq1fF1mjiv1U1@mid.uni-berlin.de> A. Cavallo schrieb: > Mmmm, > not really a conspiracy but it is not that trivial.... > > In wrapping c++ you might find useful the commands nm with c++filt > although they work under linux there is the same pair for every platform > (under windows I remember there is objdump): they should only you need to wrap > a c++ library. > > I've been wrapping in the past c++ using boost and it was trivial although I > haven't tried enough to break it. > > swig, in older versions, is really bad: I can't comment on newer versions but > I'd have a look to the generated code before using it. > > sip it looks quite difficult to use, but is well maintained. I don't think it's (more) difficult. It's just stripping down the c++-header-file for the easy cases,providing explicit type-marshalling code for complex arguments, and potentially writing explicit method/function-bodies for certain hard cases. All of this is done pretty much alike in boost. Diez From dksreddy at gmail.com Wed Jun 3 04:25:23 2009 From: dksreddy at gmail.com (Sandy) Date: Wed, 3 Jun 2009 01:25:23 -0700 (PDT) Subject: How to get a window ID in linux using python? Message-ID: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> Hi all, Is there a way to get window ID in linux using python by just using the window name (say 'VPython')? This can be done in (Microsoft) windows (got it from somewhere else, not tested). import win32gui self.VP = win32gui.FindWindow ( None, 'VPython' ) In Linux, we can get window info by executing 'xwininfo' and then selecting the desired window manually. Can this be done automatically in python? Thanks, Sandy From martin at v.loewis.de Wed Jun 3 04:58:51 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 03 Jun 2009 10:58:51 +0200 Subject: How to get a window ID in linux using python? In-Reply-To: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> References: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> Message-ID: <4a263b4b$0$20458$9b622d9e@news.freenet.de> > In Linux, we can get window info by executing 'xwininfo' and then > selecting the desired window manually. Can this be done automatically > in python? You can run "xwininfo -tree -root", and then parse the output. HTH, Martin From ldo at geek-central.gen.new_zealand Wed Jun 3 05:13:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 03 Jun 2009 21:13:01 +1200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In message , Kay Schluehr wrote: > On 3 Jun., 05:51, Lawrence D'Oliveiro central.gen.new_zealand> wrote: > >> In message , Sebastian Wiesner wrote: >> >> > >> >> >> That said I've used C++ with ctypes loads of times, but I always wrap >> >> the exported stuff in extern "C" { } blocks. >> >> > No wonder, you have never actually used C++ with C types. An extern >> > "C" clause tells the compiler to generate C functions (more precisely, >> > functions that conform to the C ABI conventions), so effectively you're >> > calling into C, not into C++. >> >> Seems like the only sane way to do it. In all other directions lies >> madness. > > Yes but creating C stubs is also hard in presence of everything that > is not basic C++. How would you wrap the STL? What does the STL offer that Python doesn't already do more flexibly and more simply? From 42flicks at gmail.com Wed Jun 3 05:21:10 2009 From: 42flicks at gmail.com (Mike) Date: Wed, 3 Jun 2009 21:21:10 +1200 Subject: unittest - what is the best way to reuse test data? Message-ID: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Hello, I'm writing an application that needs to fetch a json file from a webserver. I'm writing the tests and have a question: if I have the following methods: def test_headers(self): headers = libary.get_data(data) check header status def test_get_info info = libary.get_info(libary.get_data(data)) This way I call the url twice, even though I have the data available from the first test. my application would just variables such as: h = libary.get_data(data) i = libary.get_info(h) so only one call. What is the best way to set up tests to resuse the data more? I'm new to using the testing framework so I'm not sure on best practises and such. Is introducing persistance by using sql lite the best way? I should be able to just reuse data within the object. Or is my design wrong? Any tips or suggestions would be appreciated! - Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.cavallo at mailsnare.com Wed Jun 3 06:10:38 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 11:10:38 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031110.38489.a.cavallo@mailsnare.com> > >> > No wonder, you have never actually used C++ with C types. An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively > >> > you're calling into C, not into C++. > >> > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? Couldn't agree more:) The following is the STL equivalent of: print [ x*2 for range(10) in data if (x%2 == 0) ] It will take more than digging into the STL documentation..... #include #include #include #include #include #include using __gnu_cxx::compose1; class Range { public: Range(int start=0) : m_start(start) {} virtual ~Range() {} int operator()() { return m_start++; } private: int m_start; }; class Times { public: Times(int val) : m_val(val) {} int operator()(int x) const { return x*m_val; } private: int m_val; }; int main(int argc, char * argv[]) { std::vector data(10); std::generate(data.begin(), data.end(), Range(0)); std::vector::iterator new_end = std::remove_if(data.begin(), data.end(), compose1(std::bind2nd(std::equal_to(), 0), std::bind2nd(std::modulus(), 2))); data.erase(new_end, data.end()); std::transform(data.begin(), data.end(), data.begin(), Times(2)); std::copy(data.begin(), data.end(), std::ostream_iterator(std::cout, "\n")); return 0; } From anthra.norell at bluewin.ch Wed Jun 3 06:16:13 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 03 Jun 2009 12:16:13 +0200 Subject: OT: Can;'t find a Mozilla user group Message-ID: <4A264D6D.8030002@bluewin.ch> I can't run Firefox and Thunderbird without getting these upgrade ordering windows. I don't touch them, because I have reason to suspect that they are some (Russian) virus that hijacks my traffic. Occasionally one of these window pops up the very moment I hit a key and next a confirmation message appears "reassuring" me that the upgrade will be installed the next time I start. I meant to ask Mozilla about their upgrade policy and facilities but for all the googling I do I can't find a contact address, nor an active user group. Hints will be greatly appreciated. Thanks! Frederic From gagsl-py2 at yahoo.com.ar Wed Jun 3 06:18:54 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 07:18:54 -0300 Subject: why does my python's program die after change computer system time? References: <843f1445-4c15-4c9b-aa83-50ea3321eba3@z19g2000vbz.googlegroups.com> Message-ID: En Wed, 03 Jun 2009 04:08:03 -0300, fuzziy escribi?: > [why does my python's program die after change computer system time?] > def tick(): > ...show current time... > clock_label.after(200, tick) What do you mean by "die"? Did you set the system time to an earlier value? Suppose now it is 09:15:00.000; your program says after(200, tick), that means that at 09:15:00.200 the tick() function will be called. If you set the time back to 09:00:00 your program has 15 minutes still to wait. It hasn't died, it's just waiting for the right time to arrive. I'm not sure if this can be considered a bug, or not, or who's responsible (tcl? tk? tkinter? python?...) -- Gabriel Genellina From paul at boddie.org.uk Wed Jun 3 06:39:42 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Wed, 3 Jun 2009 03:39:42 -0700 (PDT) Subject: How to get a window ID in linux using python? References: <3aae46b3-ac8a-4c88-b36d-cd0aeeab0cdd@v4g2000vba.googlegroups.com> <4a263b4b$0$20458$9b622d9e@news.freenet.de> Message-ID: <64c5d275-27fe-4242-883e-14ccb4dfbd07@k8g2000yqn.googlegroups.com> On 3 Jun, 10:58, "Martin v. L?wis" wrote: > > In Linux, we can get window info by executing 'xwininfo' and then > > selecting the desired window manually. Can this be done automatically > > in python? > > You can run "xwininfo -tree -root", and then parse the output. The desktop.windows module provides some support for inspecting windows under X11. Here's the repository for the desktop package: https://hg.boddie.org.uk/desktop Looking at the time since the last release, maybe it's time to make another release with the most recent fixes, especially since I've just spotted something which would probably obstruct the operation of the module when performing the work required in this case. Paul From kay at fiber-space.de Wed Jun 3 08:35:05 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Wed, 3 Jun 2009 05:35:05 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: On 3 Jun., 11:13, Lawrence D'Oliveiro wrote: > In message c0e4-479a-85ed-91c26d3bf... at c36g2000yqn.googlegroups.com>, Kay Schluehr > wrote: > > > > > On 3 Jun., 05:51, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > > >> In message , Sebastian Wiesner wrote: > > >> > > > >> >> That said I've used C++ with ctypes loads of times, but I always wrap > >> >> the exported stuff in extern "C" { } blocks. > > >> > No wonder, you have never actually used C++ with C types. An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively you're > >> > calling into C, not into C++. > > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? I do not quite understand your concern? Wasn't the whole point of Josephs post that he intended to create C++ bindings effectively s.t. ctypes can be used? From roy at panix.com Wed Jun 3 09:05:35 2009 From: roy at panix.com (Roy Smith) Date: Wed, 03 Jun 2009 09:05:35 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: Message-ID: In article , "A. Cavallo" wrote: > The following is the STL equivalent of: > > print [ x*2 for range(10) in data if (x%2 == 0) ] Are you sure about that? I haven't tested the following code, but I believe it is a much more direct match the the behavior of your Python code (at least on Python 2.5.1). #include int main(int argc, char * argv[]) { std::cout << "SyntaxError: can't assign to function call"; std::cout << endl; } From BrianVanderburg2 at aim.com Wed Jun 3 09:20:35 2009 From: BrianVanderburg2 at aim.com (Brian Allen Vanderburg II) Date: Wed, 03 Jun 2009 09:20:35 -0400 Subject: Copying objects and multiple inheritance In-Reply-To: References: <4A25A187.3050908@aim.com> Message-ID: <4A2678A3.1080602@aim.com> Gabriel Genellina wrote: > En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II > escribi?: > >> What is the best way to copy an object that has multiple inheritance >> with the copy module. Particularly, some of the instances in the >> hierarchy > > ("...some of the classes in...", I presume?) > >> use the __copy__ method to create a copy (because even for shallow >> copies they need some information updated a little differently), so >> how can I make sure all the information is copied as it is supposed >> to be even for the base classes that have special requirements. > > If you don't control all the clases involved, there is little hope for > a method like __copy__ to work at all... All classes must be written > with cooperation in mind, using super() the "right" way. See "Python's > Super Considered Harmful" [1] and "Things to Know About Python Super" > [2][3][4] > > That said, and since multiple inheritance is the heart of the problem, > maybe you can redesign your solution *without* using MI? Perhaps using > delegation instead? > > [1] http://fuhm.net/super-harmful/ > [2] http://www.artima.com/weblogs/viewpost.jsp?thread=236275 > [3] http://www.artima.com/weblogs/viewpost.jsp?thread=236278 > [4] http://www.artima.com/weblogs/viewpost.jsp?thread=237121 > I do control the classes involved. A problem I was having, but I think I now got solved, is if using super, the copy would not have the same class type. Also, a problem was if using super, but some class in the hierarchy didn't implement __copy__, then it's data would not be copied at all. This was also fixed by copying the entire __dict__ in the base __copy__. This is an idea of what I got, it seems to be working fine: import copy class _empty(object): pass class Base(object): def __init__(self): pass def __copy__(self): // don't use copy = Base() // Also don't call self.__class__() because it may have a custom // __init__ which take additional parameters copy = _empty() copy.__class__ = self.__class__ // In case a class does not have __copy__ (such as B below), make // sure all items are copied copy.__dict__.update(self.__dict__) return copy class A(Base): def __init__(self): super(A, self).__init__() self.x = 13 def __copy__(self): copy = super(A, self).__copy__() copy.x = self.x * 2 return copy class B(Base): def __init__(self): super(B, self).__init__() self.y = 14 #def __copy__(self): # copy = super(B, self).__copy__() # copy.y = self.y / 2 # return copy class C(A, B): def __init__(self): super(C, self).__init__() self.z = 64 def __copy__(self): copy = super(C, self).__copy__() copy.z = self.z * self.z return copy o1 = C() o2 = copy.copy(o1) print type(o1), o1.x, o1.y, o1.z print type(o2), o2.x, o2.y, o2.z From a.cavallo at mailsnare.com Wed Jun 3 10:13:00 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 15:13:00 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031513.00920.a.cavallo@mailsnare.com> On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > In article , > > "A. Cavallo" wrote: > > The following is the STL equivalent of: > > > > print [ x*2 for range(10) in data if (x%2 == 0) ] > > Are you sure about that? I haven't tested the following code, but I > believe it is a much more direct match the the behavior of your Python code > (at least on Python 2.5.1). > > #include > int main(int argc, char * argv[]) > { > std::cout << "SyntaxError: can't assign to function call"; > std::cout << endl; > } Ahahaha you're right! print [ x*2 for range(10) in data if (x%2 == 0) ] and it should work just fine: I've still left 9 minutes to match what I've spent in order to write the C++ version including wandering through the STL docs, compiling, fix the syntax errors, finding the gnu STL hasn't compose1 in the expected header file........ Regards, Antonio btw. From a.cavallo at mailsnare.com Wed Jun 3 10:14:44 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 3 Jun 2009 15:14:44 +0100 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <200906031514.44302.a.cavallo@mailsnare.com> On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > #include > int main(int argc, char * argv[]) > { > std::cout << "SyntaxError: can't assign to function call"; > std::cout << endl; > } Ops, I've forgotten .... a.cpp: In function ?int main(int, char**)?: a.cpp:5: error: ?endl? was not declared in this scope Oh C++ joy! Regards, Antonio From Eric_Dexter at msn.com Wed Jun 3 10:32:12 2009 From: Eric_Dexter at msn.com (edexter) Date: Wed, 3 Jun 2009 07:32:12 -0700 (PDT) Subject: is anyone using text to speech to read python documentation References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <31ce59b5-19fe-41dd-a207-ba8ec0fddefb@f16g2000vbf.googlegroups.com> On Jun 2, 7:52?pm, "Eric_Dex... at msn.com" wrote: > ? ? ?I wrote a small pre-processor for python documentation and I am > looking for advice on how to get the most natural sounding reading. ?I > uploaded an example of a reading of lxml documentation as a podcast1 > > http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. I take it identifing html tags and changing the wording would help : ( I will fix that.. From pecora at anvil.nrl.navy.mil Wed Jun 3 11:19:29 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 03 Jun 2009 11:19:29 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Sebastian Wiesner wrote: > > > > > > >> That said I've used C++ with ctypes loads of times, but I always wrap > >> the exported stuff in extern "C" { } blocks. > > > > No wonder, you have never actually used C++ with C types. An extern "C" > > clause tells the compiler to generate C functions (more precisely, > > functions that conform to the C ABI conventions), so effectively you're > > calling into C, not into C++. > > Seems like the only sane way to do it. In all other directions lies madness. Agreed. I've done this several times and it works fine. Once I'm in C I'm really in C++ and can use all my C++ code and libraries. Not a big problem really. But maybe I'm missing something. -- -- Lou Pecora From pete at shinners.org Wed Jun 3 11:27:05 2009 From: pete at shinners.org (peteshinners) Date: Wed, 3 Jun 2009 08:27:05 -0700 (PDT) Subject: Python reimport References: <91402a9a-6d27-4893-af9b-77bca8598ea8@3g2000yqk.googlegroups.com> <87hbyxremv.fsf@benfinney.id.au> Message-ID: On Jun 2, 11:54?pm, Ben Finney wrote: > When making an announcement of a new version of a project, please > summarise in the announcement what that project is (i.e. what the > program does) This module has a reimport function that works as a replacement for the reload builtin. It does a respectable job of updating the changes into the interpreter runtime. It also includes a function to find all changed python modules on disk. From wjxiaoshen at gmail.com Wed Jun 3 11:29:57 2009 From: wjxiaoshen at gmail.com (Jianli Shen) Date: Wed, 3 Jun 2009 10:29:57 -0500 Subject: float("1,009.67") error Message-ID: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> I want to converter a string 1,009.67 to float, I got: python ValueError: invalid literal for float() how do I handle this. 1,009.67 is generated by some other program. It could be 2,898.88 3,554,545.66 etc. Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From giles.thomas at resolversystems.com Wed Jun 3 11:36:34 2009 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Wed, 3 Jun 2009 08:36:34 -0700 (PDT) Subject: ANN: Resolver One 1.5 released Message-ID: We are proud to announce the release of Resolver One, version 1.5. Resolver One is a Windows-based spreadsheet that integrates Python deeply into its recalculation loop, making the models you build more reliable and more maintainable. For version 1.5, we've added a console; this new command-line window gives you a way to interact with your spreadsheet using Python statements. Here's a screencast showing why this is worth doing: We have a 31-day free trial version, so if you would like to take a look, you can download it from our website: If you want to use Resolver One in an Open Source project, we offer free licenses for that: Best regards, Giles -- Giles Thomas giles.thomas at resolversystems.com +44 (0) 20 7253 6372 Win up to $17,000 for a spreadsheet: 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From clp2 at rebertia.com Wed Jun 3 11:42:26 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Jun 2009 08:42:26 -0700 Subject: float("1,009.67") error In-Reply-To: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> References: <95ab42e10906030829o6fcc805m13f060e3bc35e253@mail.gmail.com> Message-ID: <50697b2c0906030842j39e8379exd6bb02a81ed0f8cf@mail.gmail.com> On Wed, Jun 3, 2009 at 8:29 AM, Jianli Shen wrote: > I want to converter a string 1,009.67 to float, I got: > python ValueError: invalid literal for float() > how do I handle this. > > 1,009.67 is generated by some other program. It could be 2,898.88 > 3,554,545.66 etc. Python's literal float syntax does not allow the use of commas as a thousands separator. Eliminate the commas before passing the string to float(). This can be done by calling .replace(',','') on the string and passing the result to float(). You would also be well advised to read the Python tutorial if you haven't already. Cheers, Chris -- http://blog.rebertia.com From ebonak at hotmail.com Wed Jun 3 11:53:35 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 11:53:35 -0400 Subject: easiest way to plot x,y graphically during run-time? Message-ID: Hi all, I am trying to visualize a number of small objects moving over a 2D surface during run-time. I was wondering what would the easiest way to accomplish this using Python? Ideally I am looking for a shallow learning curve and efficient implementation :-) These objects may be graphically represented as dots, or preferably as small arrow heads/pointy triangles moving about as their x,y coordinates change during run-time. Thanks, Esmail From aahz at pythoncraft.com Wed Jun 3 11:58:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 08:58:45 -0700 Subject: How do I change the behavior of the 'python-docs' action in IDLE? References: <166e0bf0-cb84-405c-84fb-d10abcd8d241@p4g2000vba.googlegroups.com> <16b92b10-95cf-49ed-868c-8f66c8160e31@r3g2000vbp.googlegroups.com> Message-ID: In article <16b92b10-95cf-49ed-868c-8f66c8160e31 at r3g2000vbp.googlegroups.com>, samwyse wrote: > >I just installed Python 3.0.1 via the Windows 32-bit installer. >Opening "Python Docs" takes me to http://docs.python.org/dev/3.0/, >which doesn't exist. Renaming python301.chm to python30.chm or >python300.chm doesn't seem to help find that file. HELP! IIRC, there's a bug report on this and it's fixed for 3.1 -- please be patient (you can look at bugs.python.org if you want to check the status). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From gokhansever at gmail.com Wed Jun 3 12:03:41 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 3 Jun 2009 11:03:41 -0500 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: Message-ID: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> It seems like you want to animate your data. You may want to take a look at Matplotlib examples or Mayavi for 3D animations ( http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab_animating.html?highlight=animation ) G?khan On Wed, Jun 3, 2009 at 10:53 AM, Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. > > Thanks, > Esmail > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Wed Jun 3 12:05:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 18:05:00 +0200 Subject: easiest way to plot x,y graphically during run-time? References: Message-ID: <78nl48F1n46o4U1@mid.uni-berlin.de> Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. pygame certainly suited, but also Tk with it's canvas-object. Diez From ebonak at hotmail.com Wed Jun 3 12:15:02 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 12:15:02 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> Message-ID: <4A26A186.90900@hotmail.com> G?khan SEVER wrote: > It seems like you want to animate your data. > > You may want to take a look at Matplotlib examples or Mayavi for 3D I've used Matplotlib to plot points that were saved during runtime to a file. I wonder if I could skip that step and directly plot during runtime updating the graph as values changed .. I've only heard about Mayavi, so I'll check it out. Thanks G?khan, Esmail From aljosa.mohorovic at gmail.com Wed Jun 3 12:16:13 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Wed, 3 Jun 2009 09:16:13 -0700 (PDT) Subject: private pypi repository Message-ID: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> i'm looking for a effective way to setup private pypi repository, i've found: - PloneSoftwareCenter - http://code.google.com/p/pypione/ - http://pypi.python.org/pypi/haufe.eggserver what are you using? what would you recommend? Aljosa Mohorovic From ebonak at hotmail.com Wed Jun 3 12:16:57 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 12:16:57 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78nl48F1n46o4U1@mid.uni-berlin.de> References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A26A1F9.1070803@hotmail.com> Hello Diez, Diez B. Roggisch wrote: > > pygame certainly suited, but also Tk with it's canvas-object. I used pygame a long time ago, barely remember it, but I think it was pretty easy to use. Tk seems a bit more complex .. but I really don't know much about it and its interface with Python to make any sort of judgments as to which option would be better. Thanks for the suggestions, I'll take a look, Esmail From gokhansever at gmail.com Wed Jun 3 12:20:06 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 3 Jun 2009 11:20:06 -0500 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78nl48F1n46o4U1@mid.uni-berlin.de> References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> I don't know how easy to use pygame or pyOpenGL for data animation comparing to Mayavi. Mayavi uses VTK as its visualization engine which is an OpenGL based library. I would like to learn more about how alternative tools might be beneficial say for example atmospheric particle simulation or realistic cloud simulation. Esmail, you may ask your question in Matplotlib users group for more detailed input. G?khan On Wed, Jun 3, 2009 at 11:05 AM, Diez B. Roggisch wrote: > Esmail wrote: > > pygame certainly suited, but also Tk with it's canvas-object. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jun 3 12:33:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:33:19 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <200906031110.38489.a.cavallo@mailsnare.com> References: <200906031110.38489.a.cavallo@mailsnare.com> Message-ID: A. Cavallo wrote: > > print [ x*2 for range(10) in data if (x%2 == 0) ] I hope you meant print [ x*2 for x in range(10) if (x%2 == 0) ] From tjreedy at udel.edu Wed Jun 3 12:40:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:40:51 -0400 Subject: unittest - what is the best way to reuse test data? In-Reply-To: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Message-ID: Mike wrote: > Hello, > > I'm writing an application that needs to fetch a json file from a > webserver. I'm writing the tests and have a question: > > if I have the following methods: > > def test_headers(self): > headers = libary.get_data(data) > check header status With no json experience specifically.... Checking I/O is nasty since the test running correctly depends on external resources running correctly and not just your program. I would separate I/O tests from 'process the data' checks and do the latter with canned data. If the canned data built into the test is the same as that on the test server, then testing the fetch is an equality test. > > def test_get_info > info = libary.get_info(libary.get_data(data)) > > This way I call the url twice, even though I have the data available > from the first test. > > my application would just variables such as: > h = libary.get_data(data) > i = libary.get_info(h) > > so only one call. > > What is the best way to set up tests to resuse the data more? I'm new to > using the testing framework so I'm not sure on best practises and such. > > Is introducing persistance by using sql lite the best way? I should be > able to just reuse data within the object. Or is my design wrong? > > Any tips or suggestions would be appreciated! > > - Mike > From tjreedy at udel.edu Wed Jun 3 12:43:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 12:43:52 -0400 Subject: How do I change the behavior of the 'python-docs' action in IDLE? In-Reply-To: References: <166e0bf0-cb84-405c-84fb-d10abcd8d241@p4g2000vba.googlegroups.com> <16b92b10-95cf-49ed-868c-8f66c8160e31@r3g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > In article <16b92b10-95cf-49ed-868c-8f66c8160e31 at r3g2000vbp.googlegroups.com>, > samwyse wrote: >> I just installed Python 3.0.1 via the Windows 32-bit installer. >> Opening "Python Docs" takes me to http://docs.python.org/dev/3.0/, >> which doesn't exist. Renaming python301.chm to python30.chm or >> python300.chm doesn't seem to help find that file. HELP! > > IIRC, there's a bug report on this and it's fixed for 3.1 -- please be > patient (you can look at bugs.python.org if you want to check the > status). Or switch now to 3.1rc1, which should have fewer bugs than 3.0.1. From deets at nospam.web.de Wed Jun 3 13:11:36 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Jun 2009 19:11:36 +0200 Subject: private pypi repository References: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> Message-ID: <78np13F1moin0U1@mid.uni-berlin.de> Aljosa Mohorovic wrote: > i'm looking for a effective way to setup private pypi repository, i've > found: > - PloneSoftwareCenter > - http://code.google.com/p/pypione/ > - http://pypi.python.org/pypi/haufe.eggserver > > what are you using? what would you recommend? We use eggbasket [1], in an actually rather heavily patched local incarnation that adds support for version sets. [1] http://www.chrisarndt.de/projects/eggbasket/ Diez From ebonak at hotmail.com Wed Jun 3 13:28:07 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 13:28:07 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> Message-ID: <4A26B2A7.7000606@hotmail.com> G?khan SEVER wrote: > I don't know how easy to use pygame or pyOpenGL for data animation > comparing to Mayavi. > > Mayavi uses VTK as its visualization engine which is an OpenGL based > library. I would like to learn more about how alternative tools might be > beneficial say for example atmospheric particle simulation or realistic > cloud simulation. I've just started to read more about Particle Swarm Optimization and since I plan to implement this in Python, I thought it would be nice to visualize the process too, without spending too much on the nitty gritty details of graphics. > Esmail, you may ask your question in Matplotlib users group for more > detailed input. good idea, thanks, Esmail From bblais at bryant.edu Wed Jun 3 13:32:13 2009 From: bblais at bryant.edu (Brian Blais) Date: Wed, 03 Jun 2009 13:32:13 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <4A26A186.90900@hotmail.com> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> <4A26A186.90900@hotmail.com> Message-ID: <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> On Jun 3, 2009, at 12:15 , Esmail wrote: > G?khan SEVER wrote: >> It seems like you want to animate your data. >> You may want to take a look at Matplotlib examples or Mayavi for 3D > > I've used Matplotlib to plot points that were saved during runtime to > a file. I wonder if I could skip that step and directly plot during > runtime updating the graph as values changed .. here is a sample. again, direct questions to the matplotlib list for possible better ideas. from pylab import * # initial positions x0=rand(5) y0=rand(5) ion() # interactive on for t in linspace(0,10,100): x=x0+0.1*cos(t) y=y0+0.1*sin(t) if t==0: # first time calling h=plot(x,y,'o') else: h[0].set_data(x,y) draw() bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais -------------- next part -------------- An HTML attachment was scrubbed... URL: From mabdelkader at gmail.com Wed Jun 3 13:54:39 2009 From: mabdelkader at gmail.com (ma) Date: Wed, 3 Jun 2009 13:54:39 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <4A26B2A7.7000606@hotmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> <4A26B2A7.7000606@hotmail.com> Message-ID: <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> Try out PyChart, it's a very complete and has a great interface. I use it to generate statistics for some of our production machines: http://home.gna.org/pychart/ On Wed, Jun 3, 2009 at 1:28 PM, Esmail wrote: > G?khan SEVER wrote: >> >> I don't know how easy to use pygame or pyOpenGL for data animation >> comparing to Mayavi. >> >> Mayavi uses VTK as its visualization engine which is an OpenGL based >> library. I would like to learn more about how alternative tools might be >> beneficial say for example atmospheric particle simulation or realistic >> cloud simulation. > > I've just started to read more about Particle Swarm Optimization and > since I plan to implement this in Python, I thought it would be nice > to visualize the process too, without spending too much on the nitty > gritty details of graphics. > >> Esmail, you may ask your question in Matplotlib users group for more >> detailed input. > > good idea, thanks, > > Esmail > > -- > http://mail.python.org/mailman/listinfo/python-list > From mensanator at aol.com Wed Jun 3 14:09:45 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 11:09:45 -0700 (PDT) Subject: easiest way to plot x,y graphically during run-time? References: Message-ID: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> On Jun 3, 10:53?am, Esmail wrote: > Hi all, > > I am trying to visualize a number of small objects moving over > a 2D surface during run-time. I was wondering what would the easiest > way to accomplish this using Python? Try Turtle Graphics using goto's. With pen up! :-) > Ideally I am looking for a shallow > learning curve and efficient implementation :-) > > These objects may be graphically represented as dots, or preferably > as small arrow heads/pointy triangles moving about as their x,y > coordinates change during run-time. > > Thanks, > Esmail From pavlovevidence at gmail.com Wed Jun 3 14:26:19 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Jun 2009 11:26:19 -0700 (PDT) Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: <78lit5F1mviblU1@mid.uni-berlin.de> Message-ID: <914d66d1-3b75-4a10-8948-e10577918b50@f10g2000vbf.googlegroups.com> On Jun 3, 2:13?am, Lawrence D'Oliveiro wrote: > In message c0e4-479a-85ed-91c26d3bf... at c36g2000yqn.googlegroups.com>, Kay Schluehr > wrote: > > > > > > > On 3 Jun., 05:51, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > > >> In message , Sebastian Wiesner wrote: > > >> > > > >> >> That said I've used C++ with ctypes loads of times, but I always wrap > >> >> the exported stuff in extern "C" { } blocks. > > >> > No wonder, you have never actually used C++ with C types. ?An extern > >> > "C" clause tells the compiler to generate C functions (more precisely, > >> > functions that conform to the C ABI conventions), so effectively you're > >> > calling into C, not into C++. > > >> Seems like the only sane way to do it. In all other directions lies > >> madness. > > > Yes but creating C stubs is also hard in presence of everything that > > is not basic C++. How would you wrap the STL? > > What does the STL offer that Python doesn't already do more flexibly and > more simply? The opportunity to type several lines of ASCII line noise just to do something really simple like iterate through a vector. Carl Banks From stef.mientki at gmail.com Wed Jun 3 14:28:40 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Jun 2009 20:28:40 +0200 Subject: is anyone using text to speech to read python documentation In-Reply-To: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <4A26C0D8.1000304@gmail.com> Eric_Dexter at msn.com wrote: > I wrote a small pre-processor for python documentation and I am > looking for advice on how to get the most natural sounding reading. I > uploaded an example of a reading of lxml documentation as a podcast1 > > http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. > > Depends what OS you want to use, on Windows it's very easy: import win32com.client s = win32com.client.Dispatch("SAPI.SpVoice") s.Speak('Is this punthoofd ') cheers, Stef From ebonak at hotmail.com Wed Jun 3 14:33:02 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 14:33:02 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> References: <040c618e-55f7-4757-a318-5b062d1e44dd@r13g2000vbr.googlegroups.com> Message-ID: Mensanator wrote: > On Jun 3, 10:53 am, Esmail wrote: >> Hi all, >> >> I am trying to visualize a number of small objects moving over >> a 2D surface during run-time. I was wondering what would the easiest >> way to accomplish this using Python? > > Try Turtle Graphics using goto's. With pen up! :-) hehe .. yes, I briefly considered this too ... From ebonak at hotmail.com Wed Jun 3 14:36:16 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 14:36:16 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <49d6b3500906030920o6c54542cj7827ba503b8cabca@mail.gmail.com> <4A26B2A7.7000606@hotmail.com> <148918f0906031054v4d1eb536i52806b4e04733170@mail.gmail.com> Message-ID: <4A26C2A0.3030602@hotmail.com> ma wrote: > Try out PyChart, it's a very complete and has a great interface. I use > it to generate statistics for some of our production machines: > http://home.gna.org/pychart/ Thanks for the suggestion and link, I'm not familiar with this, but will check it out. If I can get matlibplot to work it would be fine since I've already used it a bit before - so there would be less of a learning curve. Regards, Esmail From kiorky at cryptelium.net Wed Jun 3 14:52:59 2009 From: kiorky at cryptelium.net (kiorky) Date: Wed, 03 Jun 2009 20:52:59 +0200 Subject: private pypi repository In-Reply-To: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> References: <1d94c5f2-27df-4877-b87f-98084a3fbf23@f19g2000yqh.googlegroups.com> Message-ID: <4A26C68B.3010805@cryptelium.net> Aljosa Mohorovic a ?crit : > i'm looking for a effective way to setup private pypi repository, i've > found: > - PloneSoftwareCenter > - http://code.google.com/p/pypione/ > - http://pypi.python.org/pypi/haufe.eggserver > > what are you using? what would you recommend? > > Aljosa Mohorovic You have also http://pypi.python.org/pypi/ClueReleaseManager -- -- Cordialement, KiOrKY GPG Key FingerPrint: 0x1A1194B7681112AF From allen.fowler at yahoo.com Wed Jun 3 14:54:52 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Wed, 3 Jun 2009 11:54:52 -0700 (PDT) Subject: Project source code layout? Message-ID: <159391.58127.qm@web45611.mail.sp1.yahoo.com> Hello, I'm new to Python, and am looking for some suggestions as to the source code layout for a new project. The project will be a tg/pylons daemon, a static website, and a collection of other scripts that will interact with the app and DB. Here is what I am thinking so far: root_folder/ - app/ -- Code for pylons/TG web app - web/ -- Public static web files (and wsgi / fastCGI connector files) - db/ -- SQlite DB - scripts/ -- Various custom programs that will also interact with the DB / app. (Some cron, some interactive.) - config/ -- 3-rd party API tokens, DB parameters, etc. However, I am still wondering about a few items: 1) Where to create the virtualpython installation that will be used by both the app and the scripts. 2) Where to put our in-house created python modules so that they can be imported by both the TG app and our own scripts. 3) How to cleanly provide the various config settings to both the web app and scripts. Any suggestions? ideas? fwiw, I am planing on keeping the whole thing in a Mercurial repository. Thank you, Allen :) From benjamin at python.org Wed Jun 3 14:57:29 2009 From: benjamin at python.org (Benjamin Peterson) Date: Wed, 3 Jun 2009 18:57:29 +0000 (UTC) Subject: Safe to import =?utf-8?b?X19idWlsdGluX18=?= ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: mrstevegross gmail.com> writes: > > Is it generally safe to explicitly import __builtin__ in python? That > is, my code reads like this: ... > > It seems like it should be a safe import, but I just want to make > sure. Yes, that's fine. I'm not sure why you don't just use type(), though. From gregturn at mindspring.com Wed Jun 3 15:09:32 2009 From: gregturn at mindspring.com (Goldfish) Date: Wed, 3 Jun 2009 12:09:32 -0700 (PDT) Subject: Spring Python 1.0.0-RC2 has been released Message-ID: Spring Python takes the concepts implemented by the Java-based Spring Framework, and applies them to Python. This provides a powerful library of functionality to help you get back to writing the code that makes you money. It includes features like data access, transaction management, remoting, security, a command-line tool, and an IoC container. Today, release 1.0.0 (RC2) has been released. See http://blog.springpython.webfactional.com/2009/06/03/spring-python-100-rc2-is-released/ for more details about this release, including release notes, links, and other information. From benjamin at python.org Wed Jun 3 15:16:41 2009 From: benjamin at python.org (Benjamin Peterson) Date: Wed, 3 Jun 2009 19:16:41 +0000 (UTC) Subject: Missing codecs in Python 3.0 References: Message-ID: samwyse gmail.com> writes: > > I have a Python 2.6 program (a code generator, actually) that tries > several methods of compressing a string and chooses the most compact. > It then writes out something like this: > { encoding='bz2_codec', data = '...'} In 3.x, all codecs which don't directly map between unicode and bytestrings have been removed. > > I'm having two problems converting this to Py3. First is the absence > of the bz2_codec, among others. It was very convenient for my program > to delay selection of the decoding method until run-time and then have > an easy way to load the appropriate code. Is this gone forever from > the standard libraries? No, just use the bz2 module in the stdlib. > > Second, I would write my data out using the 'string_escape' codec. Why does the repr seem less efficient? From ebonak at hotmail.com Wed Jun 3 15:32:24 2009 From: ebonak at hotmail.com (esmail bonakdarian) Date: Wed, 3 Jun 2009 15:32:24 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> References: <49d6b3500906030903v3a18bca9g9d47c0aef005939e@mail.gmail.com> <4A26A186.90900@hotmail.com> <69E0AC26-62B4-4EBE-84A8-B699030F8EA7@bryant.edu> Message-ID: Hi Brian, Thanks for the code sample, that looks quite promising. I can run it and understand most of it - my knowledge of pylab/matplotlib is still quite rudimentary. I wish there was a good manual/tutorial that could be printed off (or for that matter a book) on this as it seems quite cabable and feature rich. Esmail --- here is a sample. again, direct questions to the matplotlib list for possible better ideas. from pylab import * # initial positions x0=rand(5) y0=rand(5) ion() # interactive on for t in linspace(0,10,100): x=x0+0.1*cos(t) y=y0+0.1*sin(t) if t==0: # first time calling h=plot(x,y,'o') else: h[0].set_data(x,y) draw() bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais _________________________________________________________________ Windows Live? SkyDrive?: Get 25 GB of free online storage. http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_SD_25GB_062009 From aahz at pythoncraft.com Wed Jun 3 15:36:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 12:36:40 -0700 Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Message-ID: In article <7c93031a-235e-4e13-bd37-7c9dbc6e889c at r16g2000vbn.googlegroups.com>, wrote: >Should I open a bug report for this? > >Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > >Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> os.popen('cat','w') >Traceback (most recent call last): > File "", line 1, in > File "/Python-3.1rc1/Lib/os.py", line 641, in popen > return _wrap_close(io.TextIOWrapper(proc.stdin), proc) >IOError: [Errno 29] Illegal seek What happens in 2.6 and 3.0? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From me at nikosapi.org Wed Jun 3 15:44:05 2009 From: me at nikosapi.org (Nick Nobody) Date: Wed, 03 Jun 2009 15:44:05 -0400 Subject: urllib.FancyURLopener.redirect_internal behavior Message-ID: Hello, I've recently been playing around with urllib.FancyURLopener and noticed that under certain conditions it can block after calling open() on a url. It only happens on specific servers and when the "Range" HTTP header is in use. The server doesn't close the connection and redirect_internal gets stuck while trying to do a read (it's gets stuck at the line containing "void = fp.read()"). Here is a simple example that demonstrates this problem: #!/usr/bin/env python import urllib # A url which causes a 302 on the server. url = 'http://chkpt.zdnet.com/chkpt/1pcast.bole/http://podcast' url += '-files.cnet.com/podcast/cnet_buzzoutloud_060209.mp3' d = urllib.FancyURLopener() # This header causes this particular server (most servers behave # normally) to keep the connection open for whatever reason... d.addheader('Range', 'bytes=100-') # The program will block here as we wait for redirect_internal to # do it's "void = fp.read()" but since the server doesn't close the # connection we end up waiting for the connection to timeout. d.open(url) To work around this, I subclass FancyURLopener and define my own version of redirect_internal that has the "void = fp.read()" line commented out. What I'd like to know is what's the point of doing the read() and not using the result? Is this a bug in urllib? Or am I simply doing something wrong? Thanks, nick From Scott.Daniels at Acm.Org Wed Jun 3 16:29:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 03 Jun 2009 13:29:35 -0700 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > ... Tk seems a bit more complex .. but I really don't know much about > it and its interface with Python to make any sort of judgments as > to which option would be better. This should look pretty easy: import Tkinter as tk class Mover(object): def __init__(self, canvas, tag_or_id): self.canvas = canvas self.ident = tag_or_id self.x = self.y = 0 def start(self, event): self.x = event.x self.y = event.y def move(self, event): if event.x != self.x or event.y != self.y: dx = event.x - self.x dy = event.y - self.y self.x = event.x self.y = event.y self.canvas.move(self.ident, dx, dy) def setup(root=None): if root is None: root = tk.Tk() root.geometry('400x400+5+5') # experiment: -- place and size canvas = tk.Canvas(root) canvas.pack(expand=1, fill=tk.BOTH) # ovals are x1, y1, x2, y2 a = canvas.create_oval((50, 100, 70, 140), fill='red') b = canvas.create_oval((100, 200, 140, 290), fill='blue') c = canvas.create_oval((300, 300, 390, 330), fill='green') canvas.itemconfig(a, fill='#55AADD') # using internet colors canvas.move(a, 5, 5) # move a down right 5 pixels mover = [Mover(canvas, ident) for ident in (a, b, c)] canvas.bind("", mover[0].move) canvas.bind("", mover[0].start) canvas.bind("", mover[1].move) canvas.bind("", mover[1].start) canvas.bind("", mover[2].move) canvas.bind("", mover[2].start) return canvas, mover if __name__ == '__main__': c, m = setup() tk.mainloop() If you want to experiment, use something like: python -m idlelib.idle -n or $ python /Lib/idlelib/idle.py -n or C:\> C:\Python25\python C:\Python25\Lib\idlelib\idle.py -n To get an idle window with the -n switch on (so you are using the idle "in-process") to see the effects of each Tkinter operation as you go. You can then run these operations in place, seeing results and effects. --Scott David Daniels Scott.Daniels at Acm.Org From paul.blast.walker at googlemail.com Wed Jun 3 16:38:58 2009 From: paul.blast.walker at googlemail.com (tooshiny) Date: Wed, 3 Jun 2009 13:38:58 -0700 (PDT) Subject: accessing the XML attribute value noNamespaceSchemaLocation thru Python 2.5 Message-ID: I am currently successfully using lxml and ElementTree to validate and to access the XML contained data. I can however not find any functional call to access the schema location ie the attribute value noNamespaceSchemaLocation. A simple function call would be so much nicer than the other route of file reading / string chopping etc Can anybody help Many thanks From goldwamh at slu.edu Wed Jun 3 16:45:07 2009 From: goldwamh at slu.edu (Michael H. Goldwasser) Date: Wed, 3 Jun 2009 15:45:07 -0500 Subject: Challenge supporting custom deepcopy with inheritance In-Reply-To: References: Message-ID: <18982.57555.922256.416888@Michael-Goldwassers-Computer.local> On June 2, 2009, Aahz wrote: > >class A(object): > > def __init__(self, aTag): > > self.__aTag = aTag > > self.__aList = [] > > IMO, your problem starts right here. Not only are you using customized > attributes for each class, you're using class-private identifiers. You > would vastly simplify your work if you switch to single-underscore > attributes. Hi Aahz, I intentionally chose the class-private identifiers in my artificial example to emphasize that I was looking for a solution in which class B did not have to rely on particular knowledge of class A's implementation. That said, switching to single-underscores does not address the issue raised in the original post. Michael From gagsl-py2 at yahoo.com.ar Wed Jun 3 16:50:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Jun 2009 17:50:32 -0300 Subject: Copying objects and multiple inheritance References: <4A25A187.3050908@aim.com> <4A2678A3.1080602@aim.com> Message-ID: En Wed, 03 Jun 2009 10:20:35 -0300, Brian Allen Vanderburg II escribi?: > Gabriel Genellina wrote: >> En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II >> escribi?: >> >>> What is the best way to copy an object that has multiple inheritance >>> with the copy module. Particularly, some of the instances in the >>> hierarchy >>> use the __copy__ method to create a copy (because even for shallow >>> copies they need some information updated a little differently) >> > I do control the classes involved. A problem I was having, but I think > I now got solved, is if using super, the copy would not have the same > class type. Normally, one would use type(self)(...init arguments...) to create an instance of the same type. But if the __init__ signature may change, use type(self).__new__(type(self)) to bypass __init__ (should not matter in this case). > Also, a problem was if using super, but some class in the hierarchy > didn't implement __copy__, then it's data would not be copied at all. > This was also fixed by copying the entire __dict__ in the base > __copy__. This is an idea of what I got, it seems to be working fine: Looks fine. See also a very recent thread about __deepcopy__ for another generic version. -- Gabriel Genellina From starglider101 at gmail.com Wed Jun 3 16:58:20 2009 From: starglider101 at gmail.com (Jorge) Date: Wed, 3 Jun 2009 21:58:20 +0100 Subject: Get the hard disk hardware serial number Message-ID: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Hi there, I need to know how to get the hardware serial number of a hard disk in python. Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Jun 3 17:09:10 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Jun 2009 22:09:10 +0100 Subject: Get the hard disk hardware serial number In-Reply-To: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <4A26E676.6070209@mrabarnett.plus.com> Jorge wrote: > Hi there, > > I need to know how to get the hardware serial number of a hard disk in > python. > > Thank you in advance. > For Windows, see http://www.daniweb.com/forums/thread187326.html From tjreedy at udel.edu Wed Jun 3 17:13:51 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 17:13:51 -0400 Subject: Get the hard disk hardware serial number In-Reply-To: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: Jorge wrote: > Hi there, > > I need to know how to get the hardware serial number of a hard disk in > python. That will be system specific. One semi-general approacy using CPython would be to ask "How would I do this with C on this specific system" and then use ctypes. From 42flicks at gmail.com Wed Jun 3 17:27:33 2009 From: 42flicks at gmail.com (Mike) Date: Thu, 4 Jun 2009 09:27:33 +1200 Subject: unittest - what is the best way to reuse test data? In-Reply-To: References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> Message-ID: <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy wrote: > Mike wrote: > >> Hello, >> >> I'm writing an application that needs to fetch a json file from a >> webserver. I'm writing the tests and have a question: >> >> if I have the following methods: >> >> def test_headers(self): >> headers = libary.get_data(data) >> check header status >> > > With no json experience specifically.... > > Checking I/O is nasty since the test running correctly depends on external > resources running correctly and not just your program. I would separate I/O > tests from 'process the data' checks and do the latter with canned data. If > the canned data built into the test is the same as that on the test server, > then testing the fetch is an equality test. > > Thanks, I think I need to separate the tests. The way JSON works is: Open a url with a request <- this returns a file like object, the JSON libary reads the file like object and returns a list of dictionary objects. So first I want to make sure when I do the request I get a 200 OK response, second I want to make sure the JSON object matches my predefined object for it (to ensure no API changes). I think I'll have an external test, which will do two calls (unless I can use the result of the response check test). And if this test passes I will then run my mock test which tests for functionality (and can be run offline). If the first fails then its an indication that the api may have changed and I need to change my mocks. Is this a good testing method/ approach? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrstevegross at gmail.com Wed Jun 3 17:33:02 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Wed, 3 Jun 2009 14:33:02 -0700 (PDT) Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> <87fxeirrhl.fsf@benfinney.id.au> Message-ID: > Yes, it's safe (and this is what the ?__builtin__? module is intended > for: ). > > Be careful, though: there's a separate name, ?__builtins__?, that is > *not* meant to be imported. It's also implementation-specific, so > shouldn't be relied upon. My advice: don't use ?__builtins__? at all, > but be aware that it exists so you spell ?__builtin__? correctly. > Thanks --Steve From news123 at free.fr Wed Jun 3 17:55:04 2009 From: news123 at free.fr (News123) Date: Wed, 03 Jun 2009 23:55:04 +0200 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: References: Message-ID: <4a26f138$0$6545$426a74cc@news.free.fr> Anthra Norell wrote: > I can't run Firefox and Thunderbird without getting these upgrade > ordering windows. I don't touch them, because I have reason to suspect > that they are some (Russian) virus that hijacks my traffic. Occasionally > one of these window pops up the very moment I hit a key and next a > confirmation message appears "reassuring" me that the upgrade will be > installed the next time I start. I meant to ask Mozilla about their > upgrade policy and facilities but for all the googling I do I can't find > a contact address, nor an active user group. Hints will be greatly > appreciated. Thanks! > > Frederic > I don't know a Mozilla news group, but in Settings Advanced -> Settings -> Updates you can choose if updats will be installed automatically or if you want to be asked. Additionally you could check your SW version in the Help->About Menu and then go to the Firefox / Thunderbird web site and look at which version they are? So you know at least whether there is a pending update From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 18:54:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jun 2009 22:54:30 GMT Subject: Safe to import __builtin__ ? References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> Message-ID: <0236f1a1$0$8244$c3e8da3@news.astraweb.com> On Wed, 03 Jun 2009 18:57:29 +0000, Benjamin Peterson wrote: > mrstevegross gmail.com> writes: > > >> Is it generally safe to explicitly import __builtin__ in python? That >> is, my code reads like this: > ... >> >> It seems like it should be a safe import, but I just want to make sure. > > Yes, that's fine. I'm not sure why you don't just use type(), though. I'm not sure why you think type() is a substitute for __builtin__. Here's a typical use-case for __builtin__: import __builtin__ def map(*args): # shadow a built-in # pre-processing goes here result = __builtin__.map(*args) # post-processing goes here return result How does type() help you? -- Steven From robert.kern at gmail.com Wed Jun 3 19:11:51 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Jun 2009 18:11:51 -0500 Subject: Safe to import __builtin__ ? In-Reply-To: <0236f1a1$0$8244$c3e8da3@news.astraweb.com> References: <287de9eb-d736-4053-8a73-53785b322a17@t11g2000vbc.googlegroups.com> <0236f1a1$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 2009-06-03 17:54, Steven D'Aprano wrote: > On Wed, 03 Jun 2009 18:57:29 +0000, Benjamin Peterson wrote: > >> mrstevegross gmail.com> writes: >> >> >>> Is it generally safe to explicitly import __builtin__ in python? That >>> is, my code reads like this: >> ... >>> It seems like it should be a safe import, but I just want to make sure. >> Yes, that's fine. I'm not sure why you don't just use type(), though. > > I'm not sure why you think type() is a substitute for __builtin__. Here's > a typical use-case for __builtin__: > > > import __builtin__ > def map(*args): # shadow a built-in > # pre-processing goes here > result = __builtin__.map(*args) > # post-processing goes here > return result > > > How does type() help you? It doesn't in that sense. The example that Benjamin elided used __builtin__.type() for no discernible reason (unlike your example which creates a shadow function that overrides the builtin version). Benjamin was asking what the motivation was, since it was not evident. -- 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 Wed Jun 3 19:22:20 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 19:22:20 -0400 Subject: unittest - what is the best way to reuse test data? In-Reply-To: <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> Message-ID: Mike wrote: > > > On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy > wrote: > > Mike wrote: > > Hello, > > I'm writing an application that needs to fetch a json file from > a webserver. I'm writing the tests and have a question: > > if I have the following methods: > > def test_headers(self): > headers = libary.get_data(data) > check header status > > > With no json experience specifically.... > > Checking I/O is nasty since the test running correctly depends on > external resources running correctly and not just your program. I > would separate I/O tests from 'process the data' checks and do the > latter with canned data. If the canned data built into the test is > the same as that on the test server, then testing the fetch is an > equality test. > > Thanks, I think I need to separate the tests. > > The way JSON works is: Open a url with a request <- this returns a file > like object, the JSON libary reads the file like object and returns a > list of dictionary objects. > > So first I want to make sure when I do the request I get a 200 OK > response, second I want to make sure the JSON object matches my > predefined object for it (to ensure no API changes). > > I think I'll have an external test, which will do two calls (unless I > can use the result of the response check test). And if this test passes > I will then run my mock test which tests for functionality (and can be > run offline). If the first fails then its an indication that the api may > have changed and I need to change my mocks. > > Is this a good testing method/ approach? Let us back up a bit. The purpose of a unit test is to test a unit of functionality that you have written code for -- usually with the assumption, possibly false, that the interpreter and libraries are bug-free with respect to your usage. Without knowing what you have written, and therefore, what you should be testing, I am reluctant to say more than that you seem to be on the right track. But some of what you say above seems to be describing higher level integration testing, in particular, interfacing with a changing environment. One thing I will say: once you have tests passing, you can change either your code or the system-code-data it works with, but should not do both (lest you drive yourself mad). The point of mock objects is to have a stable environment in which to work. So I would try to separate 'testing my code (which I control)' from 'testing for undisclosed changes in external servers (that I do not control)'. Terry Jan Reedy From tjreedy at udel.edu Wed Jun 3 19:31:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Jun 2009 19:31:11 -0400 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: <4a26f138$0$6545$426a74cc@news.free.fr> References: <4a26f138$0$6545$426a74cc@news.free.fr> Message-ID: News123 wrote: > > Anthra Norell wrote: >> I can't run Firefox and Thunderbird without getting these upgrade >> ordering windows. I don't touch them, because I have reason to suspect >> that they are some (Russian) virus that hijacks my traffic. Occasionally >> one of these window pops up the very moment I hit a key and next a >> confirmation message appears "reassuring" me that the upgrade will be >> installed the next time I start. I meant to ask Mozilla about their >> upgrade policy and facilities but for all the googling I do I can't find >> a contact address, nor an active user group. Hints will be greatly >> appreciated. Thanks! >> >> Frederic >> > > I don't know a Mozilla news group, > but in Settings Advanced -> Settings -> Updates > you can choose if updats will be installed automatically or if you want > to be asked. In my copies of Firefox and Thunderbird: Tools - Options - Advanced - Update I have 'ask me' checked because auto updates do not seem to work in non-admin accounts. So at my convenience, I switch to admin, go to Help - Check for Updates, and when it finds it, click install. > Additionally you could check your SW version in the Help->About Menu and > then go to the Firefox / Thunderbird web site and look at which version > they are? > > So you know at least whether there is a pending update From aahz at pythoncraft.com Wed Jun 3 19:45:39 2009 From: aahz at pythoncraft.com (Aahz) Date: 3 Jun 2009 16:45:39 -0700 Subject: Challenge supporting custom deepcopy with inheritance References: Message-ID: In article , Michael H. Goldwasser wrote: >On June 2, 2009, Aahz wrote: >>Michael Goldwasser: >>> >>>class A(object): >>> def __init__(self, aTag): >>> self.__aTag = aTag >>> self.__aList = [] >> >> IMO, your problem starts right here. Not only are you using customized >> attributes for each class, you're using class-private identifiers. You >> would vastly simplify your work if you switch to single-underscore >> attributes. > > I intentionally chose the class-private identifiers in my artificial > example to emphasize that I was looking for a solution in which > class B did not have to rely on particular knowledge of class A's > implementation. That said, switching to single-underscores does not > address the issue raised in the original post. Not directly, but it does simplify possible solutions. For example, you could use a straightforward getattr() approach where the class contains an attribute listing all the deep-copyable attributes. You could even use name-munging so that attributes can have an accompanying ATTR_deepcopy() method for custom code so that your main __deepcopy__ method stays the same in subclasses. (Obviously, this trick does in fact still work if you use private attributes and do the name-mangling yourself, but I find that distasteful for production code unless it's absolutely required.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 19:57:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Jun 2009 23:57:06 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> Message-ID: <0237004c$0$8244$c3e8da3@news.astraweb.com> On Mon, 01 Jun 2009 22:20:16 -0700, Mensanator wrote: >> Are you sure that permutations and combinations are subsets of the >> Cartesian Product? > > Sure looks that way (SQL examples): [snip] > I couldn't do that if they weren't subsets. Permutations and combinations are arrangements of a single set. The Cartesian product, on the other hand, are the arrangements of multiple sets, one item from each set. As a general rule, for arbitrary arguments, the items you get from product() aren't even the same size as the items you get from permutations(): >>> data = (0, 1, 2) >>> set(itertools.product(data)) {(2,), (0,), (1,)} >>> set(itertools.permutations(data)) {(2, 1, 0), (0, 1, 2), (1, 0, 2), (2, 0, 1), (0, 2, 1), (1, 2, 0)} Perhaps you mean that, in the special case of the Cartesian product of a set with itself sufficient times, the permutations and combinations of that set are subsets of the product? I could live with that: >>> S = set(itertools.product(data, data, data)) >>> s = set(itertools.permutations(data)) >>> s.issubset(S) True >>> s = set(itertools.combinations(data, 3)) >>> s.issubset(S) True Oh, there's another type of arrangement missing from the collection... dearrangements. That's the arrangements where every item appears in the "wrong" place, i.e. in a position where it *didn't* start off: e.g. given (1, 2, 3), the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: you have N addressed letters and envelopes, but someone has shuffled the letters before putting them into the envelopes. How many ways are there such that no letter will be delivered to the intended recipient? -- Steven From roy at panix.com Wed Jun 3 20:02:51 2009 From: roy at panix.com (Roy Smith) Date: Wed, 03 Jun 2009 20:02:51 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) References: Message-ID: In article , "A. Cavallo" wrote: > On Wednesday 03 June 2009 14:05:35 Roy Smith wrote: > > #include > > int main(int argc, char * argv[]) > > { > > std::cout << "SyntaxError: can't assign to function call"; > > std::cout << endl; > > } > > Ops, > I've forgotten .... > > a.cpp: In function ???int main(int, char**)???: > a.cpp:5: error: ???endl??? was not declared in this scope > > Oh C++ joy! I suppose I *did* deserve that :-) From 42flicks at gmail.com Wed Jun 3 20:03:39 2009 From: 42flicks at gmail.com (Mike) Date: Thu, 4 Jun 2009 12:03:39 +1200 Subject: unittest - what is the best way to reuse test data? In-Reply-To: References: <2b54d4370906030221o38067352j204973b5bb6cc8da@mail.gmail.com> <2b54d4370906031427i5e8ce7c8h84a8b095a6185cb8@mail.gmail.com> Message-ID: <2b54d4370906031703h7d7990c6mfbdde9d9440ebac3@mail.gmail.com> On Thu, Jun 4, 2009 at 11:22 AM, Terry Reedy wrote: > Mike wrote: > > >> >> On Thu, Jun 4, 2009 at 4:40 AM, Terry Reedy > tjreedy at udel.edu>> wrote: >> >> Mike wrote: >> >> Hello, >> >> I'm writing an application that needs to fetch a json file from >> a webserver. I'm writing the tests and have a question: >> >> if I have the following methods: >> >> def test_headers(self): >> headers = libary.get_data(data) >> check header status >> >> >> With no json experience specifically.... >> >> Checking I/O is nasty since the test running correctly depends on >> external resources running correctly and not just your program. I >> would separate I/O tests from 'process the data' checks and do the >> latter with canned data. If the canned data built into the test is >> the same as that on the test server, then testing the fetch is an >> equality test. >> >> Thanks, I think I need to separate the tests. >> >> The way JSON works is: Open a url with a request <- this returns a file >> like object, the JSON libary reads the file like object and returns a list >> of dictionary objects. >> >> So first I want to make sure when I do the request I get a 200 OK >> response, second I want to make sure the JSON object matches my predefined >> object for it (to ensure no API changes). >> >> I think I'll have an external test, which will do two calls (unless I can >> use the result of the response check test). And if this test passes I will >> then run my mock test which tests for functionality (and can be run >> offline). If the first fails then its an indication that the api may have >> changed and I need to change my mocks. >> >> Is this a good testing method/ approach? >> > > Let us back up a bit. The purpose of a unit test is to test a unit of > functionality that you have written code for -- usually with the assumption, > possibly false, that the interpreter and libraries are bug-free with respect > to your usage. Without knowing what you have written, and therefore, what > you should be testing, I am reluctant to say more than that you seem to be > on the right track. But some of what you say above seems to be describing > higher level integration testing, in particular, interfacing with a changing > environment. > > One thing I will say: once you have tests passing, you can change either > your code or the system-code-data it works with, but should not do both > (lest you drive yourself mad). The point of mock objects is to have a > stable environment in which to work. So I would try to separate 'testing my > code (which I control)' from 'testing for undisclosed changes in external > servers (that I do not control)'. > > Terry Jan Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks Terry, I appreciate your assistance. I was mixing my application tests with integration tests (testing against a changing system). My new method will be: Run the integration test, this will save a JSON file to my machine. A successful run will pass all tests and leave me with a file on my machine. When running application tests the setup will load the JSON file from the machine and my tests will be based on this. This will give me the separation required. I'm writing a basic twitter interfacing application :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Wed Jun 3 20:21:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 00:21:32 GMT Subject: Absolute imports in Python 2.4 References: <02346783$0$8244$c3e8da3@news.astraweb.com> Message-ID: <02370606$0$8244$c3e8da3@news.astraweb.com> On Tue, 02 Jun 2009 02:37:04 -0300, Gabriel Genellina wrote: > En Mon, 01 Jun 2009 21:40:26 -0300, Steven D'Aprano > escribi?: > >> I have a package which includes a module which shadows a module in the >> standard library. For example: >> >> package >> +-- __init__.py >> +-- ham.py >> +-- spam.py >> +-- sys.py >> >> Inside that package, I want to import the standard library sys. In >> other words, I want an absolute import. [...] What can I do in Python >> 2.4 to get an absolute import? > > sys = __import__("sys", {}) > > The import statement uses the global namespace to determine which > package it is called on; if you pass an empty namespace, it cannot infer > package information. Oh that's very cunning! Nice trick. > Anyway, the best move would be to rename the offending module... I agree. But it's nice to know the work-around if I need it. -- Steven From ebonak at hotmail.com Wed Jun 3 21:03:59 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 03 Jun 2009 21:03:59 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A271D7F.3070802@hotmail.com> Scott David Daniels wrote: > Esmail wrote: >> ... Tk seems a bit more complex .. but I really don't know much about >> it and its interface with Python to make any sort of judgments as >> to which option would be better. > > This should look pretty easy: Thanks Scott for taking the time to share this code with me, it will give me something to study. I'm not sure if I'd say it looks easy (but then again I am not very familiar with Tk :-) Best, Esmail From mensanator at aol.com Wed Jun 3 21:21:37 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 18:21:37 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> On Jun 3, 6:57?pm, Steven D'Aprano wrote: > On Mon, 01 Jun 2009 22:20:16 -0700, Mensanator wrote: > >> Are you sure that permutations and combinations are subsets of the > >> Cartesian Product? > > > Sure looks that way (SQL examples): > [snip] > > I couldn't do that if they weren't subsets. > > Permutations and combinations are arrangements of a single set. The OP *did* say combinations, didn't he? So the thread *was* in the context of a single set, wasn't it? > The > Cartesian product, on the other hand, are the arrangements of multiple > sets, one item from each set. And the Cartesian Product of a set with itself gives you permutations with replacement. > As a general rule, for arbitrary arguments, > the items you get from product() aren't even the same size as the items > you get from permutations(): But I wasn't talking about that case. What I *was* talking about is this quote from the 3.1 What's New page: The itertools.combinations_with_replacement() function is one of four for generating combinatorics including permutations and Cartesian products. Is there some reason I *shouldn't* assume that the "four for generating combinatorics" are not permutations vs combinations & with vs without replacement? Does the fact that product() can do more than operate on a single set change that? I never said it couldn't. > > Perhaps you mean that, in the special case of the Cartesian product of a > set with itself sufficient times, the permutations and combinations of > that set are subsets of the product? I could live with that: That *is*, in fact, what I was refering to. I never intended my comment to be a complete tutorial on all that can be done with itertools. I was replying to pataphor's bitching about the itertools being incomplete, that that issue has been addressed. What did I say wrong? Was *I* the one who was complaing? (I try not to do that anymore.) > > Oh, there's another type of arrangement missing from the collection... > dearrangements. Is that "one of four for generating combinatorics"? Maybe you should be talking to the itertools developers? > That's the arrangements where every item appears in the > "wrong" place, i.e. in a position where it *didn't* start off: e.g. given > (1, 2, 3), the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: > you have N addressed letters and envelopes, but someone has shuffled the > letters before putting them into the envelopes. How many ways are there > such that no letter will be delivered to the intended recipient? Ok, but isn't that not within the scope of what we're discussing? > > -- > Steven From python at rcn.com Wed Jun 3 22:21:36 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 19:21:36 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> Message-ID: <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> > What, no partitions? > > http://en.wikipedia.org/wiki/Partition_of_a_set Seems like you could roll your own (using combinations as a starting point): def pairwise(iterable): a, b = tee(iterable) next(b, None) return izip(a, b) def partition(s): n = len(s) for i in range(n): for div in combinations(range(1,n), i): yield map(s.__getitem__, starmap(slice, pairwise(chain ([0], div, [n])))) pprint(list(partition('abcd'))) [['abcd'], ['a', 'bcd'], ['ab', 'cd'], ['abc', 'd'], ['a', 'b', 'cd'], ['a', 'bc', 'd'], ['ab', 'c', 'd'], ['a', 'b', 'c', 'd']] From python at rcn.com Wed Jun 3 23:27:56 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 20:27:56 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> Message-ID: <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> > > What, no partitions? > > >http://en.wikipedia.org/wiki/Partition_of_a_set Simpler version: def partition(s): n = len(s) parts = range(1, n) for i in range(n): for div in combinations(parts, i): print map(s.__getslice__, chain([0], div), chain(div, [n])) >>> partition('abcd') ['abcd'] ['a', 'bcd'] ['ab', 'cd'] ['abc', 'd'] ['a', 'b', 'cd'] ['a', 'bc', 'd'] ['ab', 'c', 'd'] ['a', 'b', 'c', 'd'] From steven at REMOVE.THIS.cybersource.com.au Wed Jun 3 23:48:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 03:48:11 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: On Wed, 03 Jun 2009 20:27:56 -0700, Raymond Hettinger wrote: >> > What, no partitions? >> >> >http://en.wikipedia.org/wiki/Partition_of_a_set > > Simpler version: > > def partition(s): > n = len(s) > parts = range(1, n) > for i in range(n): > for div in combinations(parts, i): > print map(s.__getslice__, chain([0], div), chain(div, > [n])) Nice one! Raymond, as perhaps *the* principle contributor to itertools, do you feel that the combinatorics-related tools should be in their own module? Or is that dividing the module too fine? Would you consider moving permutations() and friends into a module together with functions for calculating the number of permutations etc? e.g. permutations(iterable[, r]) --> permutations object nPr(n, r) --> int and similar. -- Steven From mnordhoff at mattnordhoff.com Wed Jun 3 23:52:40 2009 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Thu, 04 Jun 2009 03:52:40 +0000 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: <4A264D6D.8030002@bluewin.ch> References: <4A264D6D.8030002@bluewin.ch> Message-ID: <4A274508.608@mattnordhoff.com> Anthra Norell wrote: > I can't run Firefox and Thunderbird without getting these upgrade > ordering windows. I don't touch them, because I have reason to suspect > that they are some (Russian) virus that hijacks my traffic. Occasionally > one of these window pops up the very moment I hit a key and next a > confirmation message appears "reassuring" me that the upgrade will be > installed the next time I start. I meant to ask Mozilla about their > upgrade policy and facilities but for all the googling I do I can't find > a contact address, nor an active user group. Hints will be greatly > appreciated. Thanks! > > Frederic Mozilla software updates automatically by default, so that Joe User won't run some out-of-date, insecure version. Mozilla's newsgroups are available on , or you can subscribe to the mailing list gateways at . -- From steven at REMOVE.THIS.cybersource.com.au Wed Jun 3 23:53:45 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 03:53:45 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> Message-ID: On Wed, 03 Jun 2009 18:21:37 -0700, Mensanator wrote: [mass snippage] > What I *was* talking about is this quote from the 3.1 What's New page: > > > The itertools.combinations_with_replacement() function is one of four > for generating combinatorics including permutations and Cartesian > products. > > > Is there some reason I *shouldn't* assume that the "four for generating > combinatorics" are not permutations vs combinations & with vs without > replacement? Does the fact that product() can do more than operate on a > single set change that? I never said it couldn't. Settle down Mensanator! Don't take it so personally! You're sounding awfully agitated. The quoted doc doesn't imply that there are only four combinatorics functions, only that there are four *in itertools*. Nor does it say that permutations etc are subsets of the Cartesian Product, because *without clarification* that is a fairly dubious thing to say. Remember, these are terms with very precise technical meanings, and if you say to a mathematician "the permutations P of some set S are a subset of the Cartesian Product with no specified arguments", they'll probably react just as I did -- with confusion. Now that I've narrowed down what you actually meant, I'm happy to agree with you, at least informally. >> Perhaps you mean that, in the special case of the Cartesian product of >> a set with itself sufficient times, the permutations and combinations >> of that set are subsets of the product? I could live with that: > > > > That *is*, in fact, what I was refering to. I never intended my comment > to be a complete tutorial on all that can be done with itertools. Dear me. Did I say it was? > I was > replying to pataphor's bitching about the itertools being incomplete, > that that issue has been addressed. What did I say wrong? Was *I* the > one who was complaing? (I try not to do that anymore.) The only thing you did "wrong" was to be less pedantic than me. All I was trying to do was narrow down in exactly what sense you meant that arrangements of a single set are subsets of the product of two or more sets. >> Oh, there's another type of arrangement missing from the collection... >> dearrangements. > > Is that "one of four for generating combinatorics"? Obviously not. If it's *missing* how could it be one of the four? > Maybe you should be talking to the itertools developers? If I had a good use-case for dearrangements, or a fast, reliable implementation, then maybe I would. >> That's the arrangements where every item appears in the "wrong" place, >> i.e. in a position where it *didn't* start off: e.g. given (1, 2, 3), >> the dearrangements are: (2, 3, 1), (3, 1, 2). Typical problem: you have >> N addressed letters and envelopes, but someone has shuffled the letters >> before putting them into the envelopes. How many ways are there such >> that no letter will be delivered to the intended recipient? > > Ok, but isn't that not within the scope of what we're discussing? In the context of Pataphor complaining about itertools having an incomplete set of combinatorics tools, missing partions() and dearrangements() are certainly within the scope. Whether they are serious lacks is another question. -- Steven From ldo at geek-central.gen.new_zealand Thu Jun 4 00:13:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Jun 2009 16:13:50 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > I'm new to Python, and am looking for some suggestions as to the source > code layout for a new project. Is this the development layout or the deployment layout? The two need not bear any resemblance. From allen.fowler at yahoo.com Thu Jun 4 01:00:19 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Wed, 3 Jun 2009 22:00:19 -0700 (PDT) Subject: Project source code layout? In-Reply-To: References: Message-ID: <127570.41907.qm@web45615.mail.sp1.yahoo.com> > > I'm new to Python, and am looking for some suggestions as to the source > > code layout for a new project. > > Is this the development layout or the deployment layout? The two need not > bear any resemblance. > Looking for suggestions on both. I was hoping to keep the dev layout as close to deployment possible. Thank you, :) From mensanator at aol.com Thu Jun 4 01:00:26 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Jun 2009 22:00:26 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3c9e6fd0-555e-4b94-b35b-181d079a1e48@k2g2000yql.googlegroups.com> <023472dd$0$8244$c3e8da3@news.astraweb.com> <0237004c$0$8244$c3e8da3@news.astraweb.com> <28af877c-e6bf-44ff-a09d-6fcfc2b36b41@c9g2000yqm.googlegroups.com> Message-ID: On Jun 3, 10:53?pm, Steven D'Aprano wrote: > On Wed, 03 Jun 2009 18:21:37 -0700, Mensanator wrote: > > [mass snippage] > Settle down Mensanator! Don't take it so personally! You're sounding > awfully agitated. Don't worry, I'm not. > > Now that I've narrowed down what you actually meant, I'm happy to agree > with you, at least informally. Ok. End of thread. > > If I had a good use-case for dearrangements, or a fast, reliable > implementation, then maybe I would. *I* happen to have a good user-case for "partitions of DEPTH indistinguishable items into WIDTH ordered bins such that DEPTH >= WIDTH and each bin must contain at least 1 item". That comes up in the Collatz Conjecture, specifically, a list of WIDTH integers that sums to DEPTH such that the list cannot be empty nor contain any number less than 1. Horribly important. For example, 7 items into 4 bins would be: import collatz_functions as cf for i in cf.partition_generator(7,4): print i ## [1, 1, 1, 4] ## [1, 1, 2, 3] ## [1, 1, 3, 2] ## [1, 1, 4, 1] ## [1, 2, 1, 3] ## [1, 2, 2, 2] ## [1, 2, 3, 1] ## [1, 3, 1, 2] ## [1, 3, 2, 1] ## [1, 4, 1, 1] ## [2, 1, 1, 3] ## [2, 1, 2, 2] ## [2, 1, 3, 1] ## [2, 2, 1, 2] ## [2, 2, 2, 1] ## [2, 3, 1, 1] ## [3, 1, 1, 2] ## [3, 1, 2, 1] ## [3, 2, 1, 1] ## [4, 1, 1, 1] But, as you can see, I already know how to calculate it and I doubt anyone but me would be interested in such a thing. From willgun at live.cn Thu Jun 4 01:15:39 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 13:15:39 +0800 Subject: import sqlite3 Message-ID: Hi,everyone! When i run the following in IDLE: IDLE 2.6.1 >>> import sqlite3 >>> con =sqlite3.connect (r'g:\db1') >>> everything goes well,but when i save these to a .py file and run it: >>> Traceback (most recent call last): File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in import sqlite3 File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in con=sqlite3.connect(r'g:\db1') AttributeError: 'module' object has no attribute 'connect' Anyone can tell me why? Thanks first! From gagsl-py2 at yahoo.com.ar Thu Jun 4 01:53:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 02:53:40 -0300 Subject: import sqlite3 References: Message-ID: En Thu, 04 Jun 2009 02:15:39 -0300, willgun escribi?: > Traceback (most recent call last): > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in > import sqlite3 > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in > con=sqlite3.connect(r'g:\db1') > AttributeError: 'module' object has no attribute 'connect' > > Anyone can tell me why? Your own script is named sqlite3, right? When you execute "import sqlite3" you end up importing your own script, not the library module... -- Gabriel Genellina From andrewm at object-craft.com.au Thu Jun 4 01:55:36 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 15:55:36 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: <344386A5-EC20-45D1-BA49-9E9988522950@object-craft.com.au> On 04/06/2009, at 3:15 PM, willgun wrote: > > When i run the following in IDLE: > IDLE 2.6.1 >>>> import sqlite3 >>>> con =sqlite3.connect (r'g:\db1') >>>> > everything goes well,but when i save these to a .py file and run it: > >>>> > Traceback (most recent call last): > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in > import sqlite3 > File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in > con=sqlite3.connect(r'g:\db1') > AttributeError: 'module' object has no attribute 'connect' > > Anyone can tell me why? What did you call the .py file? sqlite3.py? If so, you've just imported your own module again. 8-) After the import, try "print sqlite3.__file__", which will tell you where the module came from. From willgun at live.cn Thu Jun 4 02:10:37 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 14:10:37 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Gabriel Genellina ??: > En Thu, 04 Jun 2009 02:15:39 -0300, willgun escribi?: > >> Traceback (most recent call last): >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in >> import sqlite3 >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in >> con=sqlite3.connect(r'g:\db1') >> AttributeError: 'module' object has no attribute 'connect' >> >> Anyone can tell me why? > > Your own script is named sqlite3, right? When you execute "import > sqlite3" you end up importing your own script, not the library module... > Thanks,I am quiet surprised to be applied so soon. From willgun at live.cn Thu Jun 4 02:14:18 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 14:14:18 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Andrew McNamara ??: > > On 04/06/2009, at 3:15 PM, willgun wrote: >> >> When i run the following in IDLE: >> IDLE 2.6.1 >>>>> import sqlite3 >>>>> con =sqlite3.connect (r'g:\db1') >>>>> >> everything goes well,but when i save these to a .py file and run it: >> >>>>> >> Traceback (most recent call last): >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in >> import sqlite3 >> File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in >> con=sqlite3.connect(r'g:\db1') >> AttributeError: 'module' object has no attribute 'connect' >> >> Anyone can tell me why? > > What did you call the .py file? sqlite3.py? If so, you've just imported > your own module again. 8-) > > After the import, try "print sqlite3.__file__", which will tell you > where the module came from. Thank you all the same. I'm a student from China.It's painful for us to read python documentation entirely due to poor english.So I often make these mistakes. From python at rcn.com Thu Jun 4 02:27:50 2009 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Jun 2009 23:27:50 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: > Nice one! It only does partitions of a sequence. I haven't yet looked at a way to do partitions of a set. Any ideas? > Raymond, as perhaps *the* principle contributor to itertools, do you feel > that the combinatorics-related tools should be in their own module? Or is > that dividing the module too fine? I like having them in itertools because they form part of the "iterator algebra" for splitting, filtering, joining, and combining streams of iterators. > Would you consider moving permutations() and friends into a module > together with functions for calculating the number of permutations etc? > > e.g. permutations(iterable[, r]) --> permutations object > ? ? ?nPr(n, r) --> int Looked at this a while back. If the nPr style functions go in, they will probably be in the math module (or a new module for integer functions like gcd and whatnot). The reason for not keeping them together is that the use cases are likely disjoint -- when I go to my calculator for nCr I don't expect a listing -- when I need to loop over permutations, I typically only care about the contents of the permutation, not the total number of them (except for purposes of estimating how long a search will take). People look to the math module for things they find on their calculator and to the itertools module for high-speed looping constructs. Also, there is a issue of naming the functions. For combinations, you you might think to look for ncombs() or somesuch, but binomial_coefficient() is what someone else may be searching for. What would be nice is to turn the itertool combinatorics into classes with a len() method, an ability to index to the n-th iteration, or to find at an arbitrary iteration: >>> c = combinations('monte', 3) >>> len(c) 10 >>> c[2] ('m', 'o', 'e') >>> c.find(('m', 't', 'e')) 5 >>> random.choice(c) ('o', 'n', 'e') If the input iterable contains repeats, the find() method would find the first match. These things are interesting and fun, but they also smell of feeping-creaturism. Raymond From gagsl-py2 at yahoo.com.ar Thu Jun 4 02:31:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 03:31:24 -0300 Subject: how to get rid of pyc files ? References: <26252295-7cd9-4c36-a966-c63b5250be8f@j18g2000yql.googlegroups.com> <6cf0f5dc-e9c6-4cf6-b6f7-d8f3814222da@n21g2000vba.googlegroups.com> Message-ID: [please keep the discussion on the list] > may be python need a parameter to regenerate .pyo/pyc explicit ,not > depending on magic number and modification time. > but i just wander if you simply just clear all .pyc than generate in > one system manually, can than program run without error in another > system? Yes, you can always remove the .pyc files before starting, forcing a recompile. Also, see the compileall module. Provided that both systems use the same Python version, you can precompile .pyc files on one and copy them to the other. Even more, some people deploy only .pyc files. -- Gabriel Genellina From andrewm at object-craft.com.au Thu Jun 4 02:33:23 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 16:33:23 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: <7A248558-5530-4D96-9B89-2333FB7B2AB6@object-craft.com.au> On 04/06/2009, at 4:14 PM, willgun wrote: >> What did you call the .py file? sqlite3.py? If so, you've just >> imported your own module again. 8-) >> After the import, try "print sqlite3.__file__", which will tell you >> where the module came from. > Thank you all the same. > I'm a student from China.It's painful for us to read python > documentation entirely due to poor english.So I often make these > mistakes. Don't worry - even experienced Python coders get caught by this one. Just remember the "print module.__file__" trick for next time something odd happens. When you import a module in python, it is only imported the first time you request it (which is why your import did not become recursive and raise an error). From anthra.norell at bluewin.ch Thu Jun 4 03:13:32 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Thu, 04 Jun 2009 09:13:32 +0200 Subject: OT: Can;'t find a Mozilla user group In-Reply-To: References: <4a26f138$0$6545$426a74cc@news.free.fr> Message-ID: <4A27741C.70007@bluewin.ch> Terry Reedy wrote: > News123 wrote: >> >> Anthra Norell wrote: >>> I can't run Firefox and Thunderbird without getting these upgrade >>> ordering windows. I don't touch them, because I have reason to suspect >>> that they are some (Russian) virus that hijacks my traffic. >>> Occasionally >>> one of these window pops up the very moment I hit a key and next a >>> confirmation message appears "reassuring" me that the upgrade will be >>> installed the next time I start. I meant to ask Mozilla about their >>> upgrade policy and facilities but for all the googling I do I can't >>> find >>> a contact address, nor an active user group. Hints will be greatly >>> appreciated. Thanks! >>> >>> Frederic >>> >> >> I don't know a Mozilla news group, >> but in Settings Advanced -> Settings -> Updates >> you can choose if updats will be installed automatically or if you want >> to be asked. > > In my copies of Firefox and Thunderbird: > Tools - Options - Advanced - Update > > I have 'ask me' checked because auto updates do not seem to work in > non-admin accounts. So at my convenience, I switch to admin, go to > Help - Check for Updates, and when it finds it, click install. > >> Additionally you could check your SW version in the Help->About Menu and >> then go to the Firefox / Thunderbird web site and look at which version >> they are? >> >> So you know at least whether there is a pending update > Thank you all! Great advice! Frederic From mail at microcorp.co.za Thu Jun 4 03:25:35 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 09:25:35 +0200 Subject: Winter Madness - Passing Python objects as Strings Message-ID: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> When the days get colder and the nights longer, then evil things are hatched. A can is like a pickle, in that it is a string, but anything can be canned. Unlike a pickle, a can cannot leave the process, though, unless the object it points to lives in shared memory. Here is the output of a test session: > python -i cantest.py dir(Can) yields: ['__doc__', '__file__', '__name__', 'can', 'uncan'] Testing string object s is: The quick brown fox jumps over the lazy dog id(s) is: 47794404772392 ps = can(s) : 47794404772392 t = uncan(ps): The quick brown fox jumps over the lazy dog t is s gives: True Testing q = Queue.Queue() q is: id(q) is: 47794404845616 pq = can(q) : 47794404845616 r = uncan(pq): r is q gives: True Testing banana class object b = banana() <__main__.banana object at 0x73d190> id(b) is: 7590288 pb = can(c) : 7590288 c = uncan(pb): <__main__.banana object at 0x73d190> c is b gives: True That's it, folks! >>> pcan = can(Can.can) >>> pcan '47794404843816' >>> griz = uncan(pcan) >>> griz is can True >>> z = 'foo' >>> griz(z) '7557840' >>> uncan(_) 'foo' >>> griz >>> # uncanny! >>> Now I have only tested it on my system, which is 64 bit SuSe Linux. I suspect it is fragile. I know it is dangerous - if you uncan a random number, then if you are lucky, you will get a segfault. If you are not lucky, your life will be completely changed. If you have any interest, contact me and I will send you the source. - Hendrik From nick at craig-wood.com Thu Jun 4 04:29:42 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 03:29:42 -0500 Subject: easiest way to plot x,y graphically during run-time? References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > Scott David Daniels wrote: > > Esmail wrote: > >> ... Tk seems a bit more complex .. but I really don't know much about > >> it and its interface with Python to make any sort of judgments as > >> to which option would be better. > > > > This should look pretty easy: > > Thanks Scott for taking the time to share this code with me, it > will give me something to study. I'm not sure if I'd say it looks > easy (but then again I am not very familiar with Tk :-) Here is a demo with pygame... import pygame from pygame.locals import * from random import randrange size = width, height = 640, 480 background_colour = 0x00, 0x00, 0x00 foreground_colour = 0x51, 0xd0, 0x3c def main(): pygame.init() screen = pygame.display.set_mode(size, 0, 32) pygame.display.set_caption("A test of Pygame - press Up and Down") pygame.mouse.set_visible(0) clock = pygame.time.Clock() dots = [ (randrange(width), randrange(height)) for _ in range(100) ] radius = 10 while True: clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: raise SystemExit(0) elif event.type == KEYDOWN: if event.key == K_ESCAPE: raise SystemExit(0) elif event.key == K_UP: radius += 1 elif event.key == K_DOWN: radius -= 1 screen.fill(background_colour) for dot in dots: pygame.draw.circle(screen, foreground_colour, dot, radius, 1) dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in dots ] pygame.display.flip() if __name__ == "__main__": main() -- Nick Craig-Wood -- http://www.craig-wood.com/nick From theller at python.net Thu Jun 4 04:43:57 2009 From: theller at python.net (Thomas Heller) Date: Thu, 04 Jun 2009 10:43:57 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: Message-ID: <78pfqeF1n4jf3U1@mid.individual.net> Joseph Garvin schrieb: > So I was curious whether it's possible to use the ctypes module with > C++ and if so how difficult it is. There have been some attempts to use ctypes to access C++ objects. We (Roman Yakovenko and myself) made some progress. We were able to handle C++ name mangling, the special C++ calling convention, access virtual, non-virtual, overloaded functions, but finally gave up because the binary layout (function tables, member variables, and so on) of C++ objects is way too complicated and undocumented. Our attempts are documented in posts to the ctypes-users mailing list, most of them have the word 'cpptypes' in the subject line. Thomas From jonas.esp at googlemail.com Thu Jun 4 05:01:52 2009 From: jonas.esp at googlemail.com (Kless) Date: Thu, 4 Jun 2009 02:01:52 -0700 (PDT) Subject: Access from a class attribute Message-ID: Why can not to access from a class attribute to a function of that class? ----------------- class Foo(object): attr = __class__.__name__ attr = self.__class__.__name__ ----------------- From ben+python at benfinney.id.au Thu Jun 4 05:24:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Jun 2009 19:24:19 +1000 Subject: Access from a class attribute References: Message-ID: <87hbywnygs.fsf@benfinney.id.au> Kless writes: > Why can not to access from a class attribute to a function of that > class? > > ----------------- > class Foo(object): > attr = __class__.__name__ > attr = self.__class__.__name__ > ----------------- The ?self? name is not magical. If you want it bound to something, you have to bind it explicitly; it's exactly like any other name. You will have noticed this being done in methods of a class: class Foo(object): attr = 'spam' def frobnicate(self, bar): self.attr = str(bar) The statements in the method are evaluated in the context of a specific call to that method, where the parameters have been passed and bound to the parameter names. -- \ ?I got some new underwear the other day. Well, new to me.? ?Emo | `\ Philips | _o__) | Ben Finney From electriclightheads at gmail.com Thu Jun 4 05:28:35 2009 From: electriclightheads at gmail.com ('2+) Date: Thu, 4 Jun 2009 18:28:35 +0900 Subject: what is the biggest number that i can send to Wave_write.writeframes(data) In-Reply-To: References: Message-ID: <20090604092835.GA3388@buyobuyo.sarigama.net> thanx for the example! somehow on juanty gui comes up but no sound .. anyway i shortened the script this way and could aplay it import wave AMPLITUDE = 2 ** 15 w = wave.open( "out.wav", "w" ) w.setnchannels( 2 ) w.setsampwidth( 2 ) #BYTES w.setframerate( 22000 ) from array import array import math F = 261.626 F2 = F * (2 ** (5 / 12.)) ang = 0.0 ang2 = 0.0 delta = ( math.pi * 2 * F ) / 22000.0 delta2 = ( math.pi * 2 * F2 ) / 22000.0 for cycle in xrange( 4 ): data = array( 'h' ) for pos in xrange( 22000 ): amp = AMPLITUDE * (pos / 22000.0) amp2 = AMPLITUDE - amp if cycle & 1: amp, amp2 = amp2, amp data.append( int( ( amp * math.sin( ang ) ) ) ) data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) ang += delta ang2 += delta2 w.writeframes( data.tostring() ) w.close() On Tue, Jun 02, 2009 at 05:13:59PM -0500, Rob Williscroft wrote: > '2+ wrote in news:mailman.1017.1243932401.8015.python-list at python.org in > comp.lang.python: > > > would like to take advantage of the wave module > > found a good example here: > > http://www.python-forum.org/pythonforum/viewtopic.php?f=2&t=10644 > > > > hmm .. i don't get how to write a stereo .. i mean i can set nchannels > > .. but how do i actually take control of each ch individually? > > Interleave the channels, one sample for the left then one sample > for the right (or maybe its the other way around). > > > and what's the range(in float) of the data i can set in > > The range of a signed 16 bit int, -2**15 to 2**15 - 1. > > > wav_file.writeframes(struct.pack('h', data))? > > Example: > > import wave > from StringIO import StringIO > > out = StringIO() > > AMPLITUDE = 2 ** 15 > > w = wave.open( out, "w" ) > w.setnchannels( 2 ) > w.setsampwidth( 2 ) #BYTES > w.setframerate( 22000 ) > > from array import array > import math > > F = 261.626 > F2 = F * (2 ** (5 / 12.)) > ang = 0.0 > ang2 = 0.0 > delta = ( math.pi * 2 * F ) / 22000.0 > delta2 = ( math.pi * 2 * F2 ) / 22000.0 > > for cycle in xrange( 4 ): > data = array( 'h' ) > for pos in xrange( 22000 ): > amp = AMPLITUDE * (pos / 22000.0) > amp2 = AMPLITUDE - amp > if cycle & 1: > amp, amp2 = amp2, amp > > data.append( int( ( amp * math.sin( ang ) ) ) ) > data.append( int( ( amp2 * math.sin( ang2 ) ) ) ) > > ang += delta > ang2 += delta2 > > w.writeframes( data.tostring() ) > > w.close() > > sample = out.getvalue() > out.close() > > #a wx player > > import wx > > app = wx.PySimpleApp() > > class Frame( wx.Dialog ): > def __init__( self, *args ): > wx.Dialog.__init__( self, *args ) > b = wx.Button( self, -1, "Ok" ) > b.Bind( wx.EVT_BUTTON, self.button ) > > def button( self, event ): > self.sound = wx.SoundFromData( sample ) > self.sound.Play( wx.SOUND_ASYNC ) > > frame = Frame( None ) > frame.Show() > > app.MainLoop() > > Rob. > -- > http://www.victim-prime.dsl.pipex.com/ -- '2+ http://sarigama.namaste.jp/ is podcasting his microtuned music http://www002.upp.so-net.ne.jp/buyobuyo/micro/rss.xml From nick at craig-wood.com Thu Jun 4 05:29:42 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 04:29:42 -0500 Subject: Get the hard disk hardware serial number References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: MRAB wrote: > Jorge wrote: > > I need to know how to get the hardware serial number of a hard disk in > > python. > > > For Windows, see http://www.daniweb.com/forums/thread187326.html For linux I'd run this and parse the results. # smartctl -i /dev/sda smartctl version 5.38 [i686-pc-linux-gnu] Copyright (C) 2002-8 Bruce Allen Home page is http://smartmontools.sourceforge.net/ === START OF INFORMATION SECTION === Model Family: Seagate Momentus 7200.2 Device Model: ST9200420AS Serial Number: 7QW138AK Firmware Version: 3.AAA User Capacity: 200,049,647,616 bytes Device is: In smartctl database [for details use: -P show] ATA Version is: 7 ATA Standard is: Exact ATA specification draft version not indicated Local Time is: Thu Jun 4 09:30:23 2009 BST SMART support is: Available - device has SMART capability. SMART support is: Enabled According to the man page smartctl also runs under windows/mac/solaris etc -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ldo at geek-central.gen.new_zealand Thu Jun 4 05:33:13 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 04 Jun 2009 21:33:13 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > I was hoping to keep the dev layout as close to deployment possible. Completely different purposes. For example, the actual production database and config files form no part of your development project, do they? And conversely, utility scripts that might be used, for example, to set up a database, should not be part of the production installation. Here's one layout I used in a production system for an online shop: /home/shop/bin -- binaries (CGI and daemon) /home/shop/lib -- common libraries for binaries /home/shop/config -- configuration files, incl format templates /home/shop/state -- socket for interprocess communication, log files From bruno.42.desthuilliers at websiteburo.invalid Thu Jun 4 06:00:59 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Jun 2009 12:00:59 +0200 Subject: Access from a class attribute In-Reply-To: References: Message-ID: <4a279b4f$0$20805$426a34cc@news.free.fr> Kless a ?crit : > Why can not to access from a class attribute to a function of that > class? > > ----------------- > class Foo(object): > attr = __class__.__name__ > attr = self.__class__.__name__ > ----------------- "class" is an executable statement that instanciate a new class object and bind it to the class name in the current namespace. The class object doesn't yet exists when the body of the class statement is eval'd, so you can't access it, obviously - nor any of it's instances FWIW. Also, there's nothing magical wrt/ 'self' - it's just a naming convention for the "current instance" argument of functions that are intented to be used as methods (Python's 'methods' being just thin wrappers around the function, the class and the instance). If you want to mess with the class attributes, you can either do so after the class is created (that is, after the end of the class statement's body), or use a custom metaclass. From wiggly at wiggly.org Thu Jun 4 07:23:49 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 12:23:49 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <4A27AEC5.8010809@wiggly.org> Hendrik van Rooyen wrote: > > If you have any interest, contact me and I will > send you the source. Maybe you could tell people what the point is... n From noone at example.com Thu Jun 4 07:30:35 2009 From: noone at example.com (Jon Bendtsen) Date: Thu, 04 Jun 2009 13:30:35 +0200 Subject: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers In-Reply-To: <4A1E4D09.60402@example.com> References: <4A1E4D09.60402@example.com> Message-ID: <4A27B05B.9040102@example.com> Jon Bendtsen wrote: > Dennis Lee Bieber wrote: >> On Wed, 27 May 2009 14:25:58 +0200, Jon Bendtsen >> declaimed the following in gmane.comp.python.general: >> >>> 'From: root at laerdal.dk\nSubject: testing\nNewsgroups: test\nBody: >>> \n\n\nfoobar\n\n\n.\n\n\n' >>> >> I believe NNTP, like SMTP, requires \r\n line termination. > > I will try it, but why does it then work when it posts the file? The > file is a std. unix file, so it should also only have \n line > termination. I have now tried adding \r infront of all \n. That didnt help. I tried making a tempfile.TemporaryFile(dir='/tmp') which did not work either. Message is still: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers From willgun at live.cn Thu Jun 4 07:42:01 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 19:42:01 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Andrew McNamara ??: > > On 04/06/2009, at 4:14 PM, willgun wrote: > >>> What did you call the .py file? sqlite3.py? If so, you've just >>> imported your own module again. 8-) >>> After the import, try "print sqlite3.__file__", which will tell you >>> where the module came from. > >> Thank you all the same. >> I'm a student from China.It's painful for us to read python >> documentation entirely due to poor english.So I often make these >> mistakes. > > Don't worry - even experienced Python coders get caught by this one. > Just remember the "print module.__file__" trick for next time something > odd happens. > > When you import a module in python, it is only imported the first time > you request it (which is why your import did not become recursive and > raise an error). I know it well now.Thanks.It seems that the mailing list is much greater than most forums in China. From willgun at live.cn Thu Jun 4 07:45:49 2009 From: willgun at live.cn (willgun) Date: Thu, 04 Jun 2009 19:45:49 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: By the way ,what does 'best regards' means at the end of a mail? From noone at example.com Thu Jun 4 07:58:30 2009 From: noone at example.com (Jon Bendtsen) Date: Thu, 04 Jun 2009 13:58:30 +0200 Subject: nntplib.NNTPTemporaryError: 441 Article has no body -- just headers In-Reply-To: <4A27B05B.9040102@example.com> References: <4A1E4D09.60402@example.com> <4A27B05B.9040102@example.com> Message-ID: Jon Bendtsen wrote: > Jon Bendtsen wrote: >> Dennis Lee Bieber wrote: >>> On Wed, 27 May 2009 14:25:58 +0200, Jon Bendtsen >>> declaimed the following in gmane.comp.python.general: >>> >>>> 'From: root at laerdal.dk\nSubject: testing\nNewsgroups: test\nBody: >>>> \n\n\nfoobar\n\n\n.\n\n\n' >>>> >>> I believe NNTP, like SMTP, requires \r\n line termination. >> I will try it, but why does it then work when it posts the file? The >> file is a std. unix file, so it should also only have \n line >> termination. > > I have now tried adding \r infront of all \n. That didnt help. > > I tried making a tempfile.TemporaryFile(dir='/tmp') which did not > work either. Message is still: > > nntplib.NNTPTemporaryError: 441 Article has no body -- just headers with the help of #python on Freenode i found the problem. I didnt seek back to 0. With seeking stringio works, and then i will use that. From mail at microcorp.co.za Thu Jun 4 08:53:41 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 14:53:41 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> Message-ID: <003d01c9e513$893597e0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > > > If you have any interest, contact me and I will > > send you the source. > > Maybe you could tell people what the point is... Well its a long story, but you did ask... I am working on an i/o system, running in an ebox - it is basically a 486 with 128 meg running slackware, and its job is to serve as an i/o server, reading inputs and setting relay and other outputs. A nice slow 300 Mhz machine - not fast at all. Now the thread that does the i/o gets commands over a queue from a socket , so they are strings, and they look like this: "A,10101010,00010010" where the "A" means its an I/O command, and the ascii binary is stuff that must be written. The response looks the same, but it has more fields as it reflects both the state of the current inputs and the current outputs. The responses are written to an output queue that is serviced by another thread. Now I did not want to waste any cycles deciding how to unpack the incoming stuff, so I just use split(','). So then I wanted to add a command to change masters, passing an alternate output queue, so that the changeover is confirmed. But a queue is not a string, and you can also not pickle it. So I messed around for a while passing the name of the new queue, and doing exec magic. This worked, but only if the new queue was a global, which was kind of yucky. So then I started thinking - why can't I just pass a simple pointer to the object, and the can was the result. It is not really something that is all that useful - only if you want to pass the reference "as part of a string". It is now working in the ebox too, but it does not look as good - the strings look like negative numbers, but they uncan fine. - Hendrik From andrewm at object-craft.com.au Thu Jun 4 09:07:42 2009 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Thu, 4 Jun 2009 23:07:42 +1000 Subject: import sqlite3 In-Reply-To: References: Message-ID: On 04/06/2009, at 9:45 PM, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? The correspondent is wishing you well. You'll also see things like "kind regards", "best wishes" and so on. "Regard" essentially means respect. From pdpinheiro at gmail.com Thu Jun 4 09:12:32 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 4 Jun 2009 06:12:32 -0700 (PDT) Subject: import sqlite3 References: Message-ID: On Jun 4, 12:45?pm, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? "regard" means roughly "care". Its use as "best regards" closing a letter (or, in this case, email), means that you care for the person you're saying goodbye to. It's just a polite way to end a letter :) From news at schwertberger.de Thu Jun 4 09:15:25 2009 From: news at schwertberger.de (Dietmar Schwertberger) Date: Thu, 04 Jun 2009 15:15:25 +0200 Subject: Get the hard disk hardware serial number In-Reply-To: References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <78pvnhF1n1gpeU1@mid.individual.net> MRAB schrieb: > Jorge wrote: >> I need to know how to get the hardware serial number of a hard disk in >> python. >> > For Windows, see http://www.daniweb.com/forums/thread187326.html This recipe uses the function GetVolumeInformation(), which does not return the hardware serial number. From the microsoft documentation: This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber. The WMI method is e.g. described here: http://www.velocityreviews.com/forums/t359670-wmi-help.html import wmi c = wmi.WMI() for pm in c.Win32_PhysicalMedia(): print pm.Tag, pm.SerialNumber or to retrieve the serial number for the installation drive: serial = c.Win32_PhysicalMedia(["SerialNumber"], Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip() Regards, Dietmar From wiggly at wiggly.org Thu Jun 4 09:18:44 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 14:18:44 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <003d01c9e513$893597e0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> Message-ID: <4A27C9B4.4070302@wiggly.org> Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> Hendrik van Rooyen wrote: >>> If you have any interest, contact me and I will >>> send you the source. >> Maybe you could tell people what the point is... > > Well its a long story, but you did ask... [snip] Maybe I should have said "why should people care" or "why would someone use this" or "what problem does this solve" Your explanation doesn't make a whole lot of sense to me, I'm sure it does to you. Why, for example, would someone use your system to pass objects between processes (I think this is the main thing you are providing?) rather than POSH or some other system? Regards, n From philip at semanchuk.com Thu Jun 4 09:21:56 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 09:21:56 -0400 Subject: import sqlite3 In-Reply-To: References: Message-ID: <81EE3446-0180-4B8D-A973-9AF4DFE3F4B7@semanchuk.com> On Jun 4, 2009, at 7:45 AM, willgun wrote: > By the way ,what does 'best regards' means at the end of a mail? "regards" is just respectful (and slightly formal) goodbye. Have a look at the definition: http://dictionary.reference.com/search?q=regards It's used much more in written communication than in spoken. At the end of a letter (or email), you might also see simply "regards", or "warm regards" (which is especially friendly) or "kind regards". At the end of a meeting of two friends A and B, A might say to B, "Give my regards to X" where X is a person that both A and B know that B will soon see. A is asking B to "carry" good wishes to X. Instead, A could have said to B, "When you see X, please tell her I'm thinking of her fondly". One can also say, "I hold him in high regard", meaning, "I respect and admire him". I'm in the USA; other English speakers might see this differently. bye Philip From pataphor at gmail.com Thu Jun 4 09:37:45 2009 From: pataphor at gmail.com (pataphor) Date: Thu, 4 Jun 2009 13:37:45 +0000 (UTC) Subject: Making the case for repeat Message-ID: This probably has a snowballs change in hell of ending up in builtins or even some in some module, but such things should not prevent one to try and present the arguments for what one thinks is right. Else one would end up with consequentialism and that way lies madness and hyperreality. So here is my proposed suggestion for a once and for all reconciliation of various functions in itertools that can not stand on their own and keep a straight face. Because of backwards compatibility issues we cannot remove them but we can boldly jump forward and include the right repeat in the builtin namespace, which I think would be the best thing. Alternatively -- the second best solution -- would be to give this function its own namespace where it can supersede the old incongruencies in itertools. Combiniter or combinator? P. from itertools import count from functools import partial def repeat(iterable, cycles = None, times = 1): L = [] for x in iterable: for i in xrange(times): yield x L.append(x) counter = count if cycles is None else partial(xrange,cycles-1) for _ in counter(): for x in L: for i in xrange(times): yield x def test(): #making the case for repeat from itertools import islice, cycle times = 2 n = 3 cycles = 2 L = range(n) #look ma, no islice! print list(repeat(L, cycles)) print list(repeat(L, cycles, times)) #repeat without extra args works like itertools.cycle: print list(islice(repeat(L),len(L)*cycles)) print list(islice(cycle(L),len(L)*cycles)) #enclosing a single item in a list emulates #itertools.repeat functionality: print list(repeat(['Mr. Anderson'],cycles)) if __name__ == '__main__': test() From albert at spenarnc.xs4all.nl Thu Jun 4 09:41:37 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 04 Jun 2009 13:41:37 GMT Subject: hash and __eq__ References: <003e1491$0$9723$c3e8da3@news.astraweb.com> <0233137f$0$8244$c3e8da3@news.astraweb.com> Message-ID: In article <0233137f$0$8244$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Sun, 31 May 2009 12:08:33 +0100, Arnaud Delobelle wrote: > >> Anyway, it's good to know that quicksort is O(n^2) in the worst case - >> and that this worst case can crop up very easily in some situations, >> especially if not too much care has been taken implementing it. > >The naive quicksort algorithm, where you recursively split the list into >two halves, performs badly if the list is already sorted (or nearly so). No it isn't (in general). It only does so if you use the first element as a pivot, resulting in a set with one element and a set with n-1 elements. It is an incredible long time ago that someone implemented qsort this very naive way, especially since in the 80's Knuth warned about it. A current naive way is use element (m+n)/2 when sorting the range m..n. This is nearly optimal for a sorted set. For a random set the chance for a consistent bad choice is astronomically low. I have a QSORT implemented in the library for my lina Forth and didn't bother to do better than this. (Used in some of the demanding problems in projecteuler.net). More sophisticated qsorts select three elements at random and use best of three. The worst behaviour is still O(n^2) but the multiplication factor is lower and the chance is astronomically low to the third power. >It's easy to fix that: randomise the list before you sort! You can do >that with a single pass of the list. That has the advantage of ensuring >that no specific input can cause degraded performance, so an attacker >can't DOS your application by passing sorted lists to be sorted. >Another strategy is to randomly exchange the pivot element when sorting. choose? A good sort utility with facilities for records with fields (using a modified heap sort, and using disk base merge sort for very large sets) can be find on my site below (called ssort). Because of the heap sort even the worst case is O(Nlog(N)) if the O(N^2) behaviour of qsort is your worry. >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From Scott.Daniels at Acm.Org Thu Jun 4 09:52:21 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 06:52:21 -0700 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Esmail wrote: > Scott David Daniels wrote: >> Esmail wrote: >>> ... Tk seems a bit more complex .. but I really don't know much about >>> it and its interface with Python to make any sort of judgments as >>> to which option would be better. >> >> This should look pretty easy: > > Thanks Scott for taking the time to share this code with me, it > will give me something to study. I'm not sure if I'd say it looks > easy (but then again I am not very familiar with Tk :-) I threw in too much, I think. The reason for the "idle -n" trick is to share the Tkinter mainloop with idle itself, so you can experiment with using Tkinter and see the effects of a single command, just after you type it in (and thus get a nice intuitive feel for the possibilities). The tricky part to understand is the switch from imperative programming to interrupt driven programming. gui stuff has to switch to interrupt driven so that it can respond to things like mouse drags, windows repaints, and so on when they happen, rather than when the software asks for them. Typically, a GUI program sets some stuff up (in imperative mode), and then switches to event-driven code and drops into an event loop. It is also typical of most GUI programs that the display manipulating code (the actual painting) must all be done in a single thread (the display thread) where the events happen. Small calculations can occur inside these events, but slow calculations leave your GUI unresponsive and unable to do things like restore hidden parts as you drag another window across it. So, big or slow calculations are either done in a separate threads (or single calculation thread) that communicate back with the display thread, or the big slow calculation are done in bite-sized pieces in the display thread, doing a piece and moving the rest on to another event. A Tkinter canvas is nice to use because you can draw things on it, move those things around (separately or in groups), change their shape or color, make them visible or invisible, and the canvas keeps track of drawing them. import Tkinter as tk # First set up Tkinter and a root window (idle -n fakes part) root = tk.Tk() # Set that window's size (400x400) and loc (5,5) root.geometry('400x400+5+5') # make a canvas (2-D drawing area) in that window canvas = tk.Canvas(root) #make the canvas fill the window (even as the window is resized) canvas.pack(expand=1, fill=tk.BOTH) # draw a red filled oval on the canvas bounded by (50,100), (70,140) a = canvas.create_oval((50, 100, 70, 140), fill='red') # the hard-to-get part about the example is that the Mover class # takes a canvas element or tag (such as a above), and provides a # couple of methods (.start(event) and .move(event)) for associating # with the mouse. ".start" when the button goes down, and ".move" # as the button is dragged with the mouse down. canvas.itemconfig(a, fill='#55AADD') # Change to oval to near cyan canvas.move(a, 5, 5) # move it down right 5 pixels single_mover = Mover(canvas, a) # associate motion with our oval # make the "left button down" on canvas call our start method # which just gives u a point to move around from. canvas.bind("", single_mover.start) # make motion while left button is down call our move method. # there we will compare the mouse position to our saved location, # move our oval (in this case) a corresponding distance, and # update the saved location. canvas.bind("", single_mover.move) # at this point we have our behavior wired up. If in idle, "just # try it", but if not: tk.mainloop() # stays there until you click the close window. Also, a Tkinter Canvas can be saved as an encapsulated postscript file, thus allowing you pretty pictures into PDFs. --Scott David Daniels Scott.Daniels at Acm.Org From fuzzyman at gmail.com Thu Jun 4 09:52:32 2009 From: fuzzyman at gmail.com (Fuzzyman) Date: Thu, 4 Jun 2009 06:52:32 -0700 (PDT) Subject: Replacing module with a stub for unit testing References: <852e3d2d-80a5-4de8-b948-f545e4bbcf9e@e21g2000yqb.googlegroups.com> Message-ID: <4fca99cf-dd1b-44bb-a5f5-a4a5cc949e07@l28g2000vba.googlegroups.com> On May 23, 2:00?pm, pigmart... at gmail.com wrote: > Hi, > > I'm working on a unit test framework for a module. ?The module I'm > testing indirectly calls another module which is expensive to access > --- CDLLs whose functions access a database. > > ? ? test_MyModule --->MyModule--->IntermediateModule--- > > >ExpensiveModule > > I want to create a stub of ExpensiveModule and have that be accessed > by IntermediateModule instead of the real version > > ? ? test_MyModule --->MyModule--->IntermediateModule--- > > >ExpensiveModuleStub > > I tried the following in my unittest: > > ? ? import ExpensiveModuleStub > ? ? sys.modules['ExpensiveModule'] = ExpensiveModuleStub # Doesn't > work > > But, import statements in the IntermediateModule still access the real > ExpensiveModule, not the stub. > > The examples I can find of creating and using Mock or Stub objects > seem to all follow a pattern where the fake objects are passed in as > arguments to the code being tested. ?For example, see the "Example > Usage" section here:http://python-mock.sourceforge.net. ?But that > doesn't work in my case as the module I'm testing doesn't directly use > the module that I want to replace. > > Can anybody suggest something? > My Mock module, and in particular the patch decorator is designed explicitly to do this. You need to be careful because modules and module level globals (including things your module imports) are global state. If you change them for the purpose of a test you must *guarantee* to restore them after the test. http://www.voidspace.org.uk/python/mock/ http://www.voidspace.org.uk/python/mock/patch.html In your case if you are testing a module which imports ExpensiveModule then by ExpensiveModule lives in the *namespace of the module under test*. You could patch it like this: from mock import patch import module @patch('module.ExpensiveModule) def testModule(self, mockExpensiveModule): .... Whilst the test is running 'module' has'ExpensiveModule' mocked out (replaced) with a Mock instance. This is passed into your test so that you can setup behaviour and make assertions about how it is used. After the test is completed the patching is undone. All the best, Michael Foord -- http://www.ironpythoninaction.com/ From steve at REMOVE-THIS-cybersource.com.au Thu Jun 4 09:53:21 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2009 13:53:21 GMT Subject: Making the case for repeat References: Message-ID: <0043ac60$0$9686$c3e8da3@news.astraweb.com> On Thu, 04 Jun 2009 13:37:45 +0000, pataphor wrote: > This probably has a snowballs change in hell of ending up in builtins or > even some in some module, but such things should not prevent one to try > and present the arguments for what one thinks is right. Else one would > end up with consequentialism and that way lies madness and hyperreality. It would be cruel of me to say "Too late", so I shall merely ask, what on earth are you going on about? > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Because of backwards compatibility issues we > cannot remove them but we can boldly jump forward and include the right > repeat in the builtin namespace, which I think would be the best thing. What is "the right repeat"? What's wrong with the old one? If you're going to make a proposal, you have to actually *make the proposal* and not just say "Here, have some code, now put it in the builtins because the rest of itertools is teh suxor!!!". That rarely goes down well. (I don't know if that's exactly what you're trying to say, but it seems that way to me.) I've run your test code, and I don't know what I'm supposed to be impressed by. -- Steven From vincent at vincentdavis.net Thu Jun 4 10:08:31 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 08:08:31 -0600 Subject: import _sqlite3 no module named error Message-ID: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> I volunteered to help Marijo Mihel?i? who was looking for someone with a mac the help him build a mac binary using py2app for his simpletasktimer http://code.google.com/p/simpletasktimer/wiki/Installation when I try to run his app I get the no module named _sqlite3 , I am not sure what this is caused by as it looks to me like sqlite3 is trying to import it. Any idea how to fix this? Other than the obvious of getting _sqlite3 somehow, or maby it is that simple. here is what i get Traceback (most recent call last): File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/KTaskTimer.py", line 13, in from lib import KTaskEditDialog, KTaskReport, KTaskTimerDB File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/lib/KTaskReport.py", line 10, in from lib import KTaskTimerDB File "/Users/vincentdavis/simpletasktimer-read-only/simpletasktimer/lib/KTaskTimerDB.py", line 8, in import sqlite3 as lite File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/sqlite3/__init__.py", line 24, in from dbapi2 import * File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named _sqlite3 logout Thanks Vincent Davis 720-301-3003 From python at mrabarnett.plus.com Thu Jun 4 10:18:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Jun 2009 15:18:48 +0100 Subject: import sqlite3 In-Reply-To: References: Message-ID: <4A27D7C8.9020001@mrabarnett.plus.com> Andrew McNamara wrote: > > On 04/06/2009, at 9:45 PM, willgun wrote: > >> By the way ,what does 'best regards' means at the end of a mail? > > The correspondent is wishing you well. You'll also see things like "kind > regards", "best wishes" and so on. "Regard" essentially means respect. There's also "high regard", which means "much admiration or respect", and the phrase "to hold someone in high regard" means to admire and respect that person greatly, for example, "we hold Guido in high regard". :-) From albert at spenarnc.xs4all.nl Thu Jun 4 10:20:45 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 04 Jun 2009 14:20:45 GMT Subject: What text editor is everyone using for Python References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In article , Emile van Sebille wrote: >On 6/1/2009 4:57 PM Steven D'Aprano said... >> Having noted that the word "Quit" does appear, how do you then *actually* >> Quit? Apart from taunting the user, what is it that Ctrl-G is actually >> doing when it displays the word "Quit" in what seems to be some sort of >> status bar? > >Ahhh.. memories of discovering that F7 gets you out of WordPerfect... Memories of Atari 260/520/1040 that had a keyboard with a key actually marked ... HELP. (Sometimes hitting it provided you with help...) > >Emile > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- like all pyramid schemes -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From abeGong at gmail.com Thu Jun 4 10:27:52 2009 From: abeGong at gmail.com (Abe) Date: Thu, 4 Jun 2009 07:27:52 -0700 (PDT) Subject: Compiling and transporting modules/libraries in python References: <249dbf4f-ef3e-495e-975e-05d848279d39@u10g2000vbd.googlegroups.com> <69a7961c-c394-4df1-bcb7-cc18aa162817@z14g2000yqa.googlegroups.com> Message-ID: <52803436-9726-4331-96aa-332f02308464@o30g2000vbc.googlegroups.com> alex23 - Thanks for the tips. I'm using portable python and it's working great so far. I'll come back and try virtualenv if I get stuck again. - Abe From pataphor at gmail.com Thu Jun 4 10:34:53 2009 From: pataphor at gmail.com (pataphor) Date: Thu, 4 Jun 2009 14:34:53 +0000 (UTC) Subject: Making the case for repeat References: <0043ac60$0$9686$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I've run your test code, and I don't know what I'm supposed to be > impressed by. Thank you for trying out the code. That you're unimpressed actually is a huge encouragement because code should just run the way people expect, without unnecessary surprises. P. From aahz at pythoncraft.com Thu Jun 4 10:45:27 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 07:45:27 -0700 Subject: "Exploding" (**myvariable) a dict with unicode keys References: Message-ID: In article , Samuel Wan wrote: > >I started using python last week and ran into exceptions thrown when >unicode dictionary keys are exploded into function arguments. In my >case, decoded json dictionaries did not work as function arguments. >There was a thread from Oct 2008 >(http://www.gossamer-threads.com/lists/python/python/684379) about the >same problem. Here is my workaround: When posting to threads like this, please make sure to specify which version(s) of Python you're using -- this is a Python 2.x issue. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From mail at microcorp.co.za Thu Jun 4 10:49:42 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 4 Jun 2009 16:49:42 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> Message-ID: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > "Nigel Rantor" wrote: > > > >> Hendrik van Rooyen wrote: > >>> If you have any interest, contact me and I will > >>> send you the source. > >> Maybe you could tell people what the point is... > > > > Well its a long story, but you did ask... > > [snip] > > Maybe I should have said > > "why should people care" > > or > > "why would someone use this" > > or > > "what problem does this solve" > > Your explanation doesn't make a whole lot of sense to me, I'm sure it > does to you. > > Why, for example, would someone use your system to pass objects between > processes (I think this is the main thing you are providing?) rather > than POSH or some other system? > I can see that my explanation passes you by completely. I said, in my original post, that a can could not leave a process. A can is exactly the same as a C pointer, only its value has been converted to a string, so that you can pass it "in band" as part of a string. That is all it does. No more, no less. Passing it to an outside process makes no sense, unless it points at an object in shared memory - else it guarantees a segfault. It is not something that would find common use - in fact, I have never, until I started struggling with my current problem, ever even considered the possibility of converting a pointer to a string and back to a pointer again, and I would be surprised if anybody else on this list has done so in the past, in a context other than debugging. Which is why I posted. This is supposed to be a newsgroup, and this is a rare occurrence, and hence news. - Hendrik From allen.fowler at yahoo.com Thu Jun 4 11:12:44 2009 From: allen.fowler at yahoo.com (Allen Fowler) Date: Thu, 4 Jun 2009 08:12:44 -0700 (PDT) Subject: Project source code layout? In-Reply-To: References: Message-ID: <64186.34279.qm@web45614.mail.sp1.yahoo.com> > > I was hoping to keep the dev layout as close to deployment possible. > > Completely different purposes. For example, the actual production database > and config files form no part of your development project, do they? And > conversely, utility scripts that might be used, for example, to set up a > database, should not be part of the production installation. > The data will certainly be different. Good point. (Though for now even the production DB will be sqlite.) > Here's one layout I used in a production system for an online shop: > > /home/shop/bin -- binaries (CGI and daemon) > /home/shop/lib -- common libraries for binaries > /home/shop/config -- configuration files, incl format templates > /home/shop/state -- socket for interprocess communication, log files > > Thank you. Couple of questions: 1) Do you use virtualpython? 2) How do you load the modules in your lib directory? 3) How do you reference your configuration directives from within your modules and CGI/daemon scripts? Thank you, Allen From daniel.cotton at gmail.com Thu Jun 4 11:41:18 2009 From: daniel.cotton at gmail.com (Daniel Cotton) Date: Thu, 4 Jun 2009 16:41:18 +0100 Subject: PEP 315: Enhanced While Loop Message-ID: <965c376b0906040841n1ad4cdb8r4a82903731536231@mail.gmail.com> During some random surfing I became interested in the below piece of code: > while : > > and while : > > and while : > > else: It strikes me that the 'and while' syntax has some power that you may not have considered. Consider that if an 'and while' were to be executed under some condition: if : and while : you would then have a live loop condition that applied to subsequent iterations only if conditionX was met. Under this circumstance I wondered if you might also want a method of cancelling while conditions? For example: cancel while : where the 'cancel while' command removes conditionY from the list of conditions that the loop will terminate on. You could then also use this syntax to cancel the initial while condition. I also wondered if 'or while' might be better, so that you could add different types of prefix to a while condition, i.e. 'and while'. I'm a python novice so this could well be something you want to ignore but I wasn't doing anything anyway. Let me know what you think. --Daniel. From exarkun at divmod.com Thu Jun 4 12:04:49 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 4 Jun 2009 12:04:49 -0400 Subject: Project source code layout? In-Reply-To: Message-ID: <20090604160449.22176.786488841.divmod.quotient.1898@henry.divmod.com> On Thu, 04 Jun 2009 21:33:13 +1200, Lawrence D'Oliveiro wrote: >In message , Allen >Fowler wrote: > >> I was hoping to keep the dev layout as close to deployment possible. > >Completely different purposes. For example, the actual production database >and config files form no part of your development project, do they? And >conversely, utility scripts that might be used, for example, to set up a >database, should not be part of the production installation. If you don't use the "utility scripts" in your development environment, how do you know they work with the code you're developing? If production has a completely different set of configuration files from your development env, how do you know how your code will work when combined with them? Any time there is a difference, there is the potential for bugs which you cannot catch until you deploy your code, and that's a recipe for failure. Minimizing differences between development and deployment is a *great* thing. There are certainly cases where differences are necessary, but one should strive to make them the exception, not the rule. Jean-Paul From exarkun at divmod.com Thu Jun 4 12:23:33 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 4 Jun 2009 12:23:33 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <20090604162333.22176.668277797.divmod.quotient.1904@henry.divmod.com> On Thu, 4 Jun 2009 16:49:42 +0200, Hendrik van Rooyen wrote: > [snip] > >It is not something that would find common use - in fact, I have >never, until I started struggling with my current problem, ever even >considered the possibility of converting a pointer to a string and >back to a pointer again, and I would be surprised if anybody else >on this list has done so in the past, in a context other than debugging. So, do you mind sharing your current problem? Maybe then it'll make more sense why one might want to do this. Jean-Paul From iamelgringo at gmail.com Thu Jun 4 12:42:27 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Thu, 4 Jun 2009 09:42:27 -0700 (PDT) Subject: Feedparser problem Message-ID: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> I'm trying to add a feedreader element to my django project. I'm using Mark Pilgrim's great feedparser library. I've used it before without any problems. I'm getting a TypeError I can't figure out. I've tried searching google, bing, google groups to no avail. Here's the dpaste of what I'm trying to do and the result I'm getting: http://dpaste.com/51406/ I've tried checking my firewall settings. I'm using Windows 7 and Python 2.6. Win 7 is allowing other Python programs through. I've tried several different RSS urls with the same result. Any thoughts would be greatly appreciated. From xahlee at gmail.com Thu Jun 4 12:46:44 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Jun 2009 09:46:44 -0700 (PDT) Subject: multi-core software Message-ID: Of interest: ? Why Must Software Be Rewritten For Multi-Core Processors? http://xahlee.org/UnixResource_dir/writ/multi-core_software.html plain text version follows. -------------------------------------------------- Why Must Software Be Rewritten For Multi-Core Processors? Xah Lee, 2009-06-04 I had a revelation today, namely, that it is necessary to rewrite software to use multi-processor in order to benefit from it. This may sound stupid, but is a revelation to me. For the past decade, the question has been on my mind, about why should software needs to be rewritten to take advantage of multi-processors. Because, in my mind, i thought that software are at some fundamental level just algorithms, and algorithms, have nothing to do with hardware implementation aspects such as number of processors. I always felt, that those talks about the need or difficulty of rewriting software for multi-processor (or multi-core these days) must be the product of idiocy of industrial imperative coding monkies. In particular, some languages such as java, the way they deal with it, seems to me extremely stupid. e.g. the concept of threads. In my mind, there should be a layer between the software and the hardware, such as the operating system, or the compiler, that should be able to automatically handle or compile the software so that it FULLY use the multi-processors when present. In short, i thought that a algorithm really has nothing to do with hardware details. I never really thought hard about this issue, but today, since i got a quad-core PC, so i looked into the issue, and thought about it, and i realized the answer. The gist is that, algorithm, fundamentally means manipulating some hardware, in fact, algorithm is a step by step instruction about some form of hardware, even the hardware may be abstract or virtual. For example, let's say the simplest case of 1+1. It is a algorithm, but where is the hardware? You may say it's abstract concept, or it being a mathematical model. What you call 1+1 depends on the context, but in our context, those numbers are the hardware. To see this, lets say more complex example of listing primes by sieve. Again, it comes down to ?what is a number?? Here, numbers can be stones, or arrangement of beads on abacus, it's hardware! As another example, say sorting. To begin with, you have to have some something to sort, that's hardware. Another way to see this is that, for a given computing problem, there are infinite number of algorithms to achieve the same thing. Some, will be better ones, requiring less steps, or requiring less storage. All these are concrete manipulation issues, and the thing being manipulated, ultimately we have to call it hardware. So, when hardware changes, say from one cpu to multi-cpu, there's no way for the algorithm to magically change and adopt the changed hardware. If you need a algorithm that is catered to the new hardware, you need a new algorithm. One might think that there might be algorithm Omega, such that it takes input of old hardware O, new hardware N, and a algorithm A, and output a algorithm B, such that B has the same behavior as A, but N+B performs better than O+A. This is like asking for Strong AI. One thing we often forgot is that algorithms ultimately translates to manipulating hardware. In a modern digital computer, that means software algorithms ultimately becomes machine instructions in CPU, which manipulate the 1s and 0s in register, or electricity voltage in transisters. In a more mundane point of view, a automatic system for software to work on multi-processors is a problem of breaking a problem into discrete units (so that they can be computed in parallel). The problem of finding a algorithm is entirely different from the problem of breaking a problem into distinct units. The problem of breaking a problem into distinct units is a entire new branch of mathematics. For example, let's say factoring. Factoring is a well defined mathematical problem. There are millions algorithms to do it, each class has different properties such as number of steps or storage units. However, if we look at these algorithms from the point of view of distinct units, it's a new perspective on classification of algorithms. Software are in general too ill-defined and fuzzy and complex, the software we use on personal computers such as email, browsers, games, don't even have mathematical models. They don't even have mathematical models of their inputs and outputs. To talk about automatic system of unitizing software, would be more like a AI fantasy. Roughly, a term that describes this aspect of research is Parallel computing. In the Wikipedia article, it talks about types of parallelism: Bit- level parallelism, Instruction-level parallelism, Data parallelism, Task parallelism. Then it also discusses hardware aspects classes: multicore, symmetric multiprocessing, distributed computing, cluster, grid. The subjects mentioned there more close to this essay are ?data parallelism? and ?task parallelism?. However, neither are high level enough as i discussed here. The issue discussed here would be like ?algorithmic parallelism?. Indeed, Wikipedia mentioned ?Automatic parallelization?, which is exactly what i'm talking about here. Quote: Automatic parallelization of a sequential program by a compiler is the holy grail of parallel computing. Despite decades of work by compiler researchers, automatic parallelization has had only limited success.[40] Mainstream parallel programming languages remain either explicitly parallel or (at best) partially implicit, in which a programmer gives the compiler directives for parallelization. A few fully implicit parallel programming languages exist ? SISAL, Parallel Haskell, and (for FPGAs) Mitrion-C. It says ?A few fully implicit parallel programming languages exist?. If you are a comp lang nutcase, don't get carried away by what those words might seem to mean. (Note: Wikipedia has a dedicated article on the subject: Automatic parallelization) Xah ? http://xahlee.org/ ? From mensanator at aol.com Thu Jun 4 12:47:05 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Jun 2009 09:47:05 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> Message-ID: <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> On Jun 4, 1:27?am, Raymond Hettinger wrote: > > Nice one! > > It only does partitions of a sequence. ?I haven't yet looked at a way > to > do partitions of a set. ?Any ideas? > > > Raymond, as perhaps *the* principle contributor to itertools, do you feel > > that the combinatorics-related tools should be in their own module? Or is > > that dividing the module too fine? > > I like having them in itertools because they form part of the > "iterator algebra" > for splitting, filtering, joining, and combining streams of iterators. > > > Would you consider moving permutations() and friends into a module > > together with functions for calculating the number of permutations etc? > > > e.g. permutations(iterable[, r]) --> permutations object > > ? ? ?nPr(n, r) --> int > > Looked at this a while back. ?If the nPr style functions go in, they > will > probably be in the math module (or a new module for integer functions > like gcd and whatnot). ?The reason for not keeping them together is > that > the use cases are likely disjoint -- when I go to my calculator for > nCr > I don't expect a listing -- when I need to loop over permutations, I > typically only care about the contents of the permutation, not the > total > number of them (except for purposes of estimating how long a search > will > take). ?People look to the math module for things they find on their > calculator and to the itertools module for high-speed looping > constructs. > > Also, there is a issue of naming the functions. ?For combinations, you > you might think to look for ncombs() or somesuch, but > binomial_coefficient() > is what someone else may be searching for. > > What would be nice is to turn the itertool combinatorics into > classes with a len() method, an ability to index to the n-th > iteration, or to find at an arbitrary iteration: > > >>> c = combinations('monte', 3) > >>> len(c) > 10 > >>> c[2] > ('m', 'o', 'e') > >>> c.find(('m', 't', 'e')) > 5 > >>> random.choice(c) > > ('o', 'n', 'e') > > If the input iterable contains repeats, the find() method > would find the first match. > > These things are interesting and fun, but they also smell > of feeping-creaturism. After all, everybody knows that for m items taken n at a time, the counts are perm w/repl = m**n comb w/repl = (m+n-1)!/(n!(m-1)!) perm wo/repl = m!/(m-n)! comb wo/repl = m!/(n!(m-n)!) > > Raymond From skip at pobox.com Thu Jun 4 12:58:48 2009 From: skip at pobox.com (skip at pobox.com) Date: Thu, 4 Jun 2009 11:58:48 -0500 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <18983.64840.555702.403634@montanaro.dyndns.org> Hendrik> A can is like a pickle, in that it is a string, but anything Hendrik> can be canned. Unlike a pickle, a can cannot leave the Hendrik> process, though, unless the object it points to lives in shared Hendrik> memory. Got some use cases? Thx, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From stefan_ml at behnel.de Thu Jun 4 13:41:13 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Jun 2009 19:41:13 +0200 Subject: accessing the XML attribute value noNamespaceSchemaLocation thru Python 2.5 In-Reply-To: References: Message-ID: <4a280739$0$31337$9b4e6d93@newsspool4.arcor-online.net> tooshiny wrote: > I am currently successfully using lxml and ElementTree to validate and > to access the XML contained data. I can however not find any > functional call to access the schema location ie the attribute value > noNamespaceSchemaLocation. > > A simple function call would be so much nicer than the other route of > file reading / string chopping etc I'm not quite sure what you are trying to do here, but to access an attribute of an Element object, you can use its get() method, as in root.get("{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation") Or did you mean to do something else? Stefan From tjreedy at udel.edu Thu Jun 4 13:48:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 13:48:17 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > I can see that my explanation passes you by completely. > > I said, in my original post, that a can could not leave a process. > A can is exactly the same as a C pointer, only its value has been > converted to a string, so that you can pass it "in band" as > part of a string. That is all it does. No more, no less. If I understand correctly, your problem and solution was this: You have multiple threads within a long running process. One thread repeatedly reads a socket. You wanted to be able to occasionally send an object to that thread. Rather than rewrite the thread to also poll a queue.Queue(), which for CPython sends objects by sending a pointer, you converted pointers to strings and sent (multiplex) them via the text stream the thread was already reading -- and modified the thread to decode and act on the new type of message. And you are willing to share the can code with someone who has a similar rare need and understands the danger of interpreting ints as addresses. Correct? tjr From chris.morisset at gmail.com Thu Jun 4 13:53:23 2009 From: chris.morisset at gmail.com (Chris) Date: Thu, 4 Jun 2009 10:53:23 -0700 (PDT) Subject: "where" in python Message-ID: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> I am a newby in Python and I'm first looking for equivalent to things I already manage: IDL. For example, I want to plot a sub-set of points, selected from a bigger set by applying some filter. In my example, I want to select only the values > 0. I succeed to write 5 different ways to do this, which one is the more efficient, the quicker, the more Python? It seems the 4th method give wrong results, but I don't know why... Thanks for your tips, Christophe ------------------------------------------------------------------------------------------ import pylab as pylab import numpy as numpy #Read the data d=pylab.load('Tabla_General2.cvs',comments='#',delimiter=';') # Define the columns to plot i_x = 10 i_y = 5 # Select the points to plot, 1rst method b_where = (d[:,i_x]>0) & (d[:,i_y]>0) xb = d[b_where,i_x] yb = d[b_where,i_y] # 2nd method xb2=pylab.compress(b_where,d[:,i_x]) yb2=pylab.compress(b_where,d[:,i_y]) # 3rd method i_where = pylab.where((d[:,i_x]>0) & (d[:,i_y]>0),1,0) xi = d[i_where,i_x] yi = d[i_where,i_y] # 4th method xi2=pylab.compress(i_where,d[:,i_x]) yi2=pylab.compress(i_where,d[:,i_y]) #5th method in_where = numpy.transpose(numpy.where((d[:,i_x]>0) & (d[:,i_y]>0))) xin = d[in_where,i_x] yin = d[in_where,i_y] ------------------------------------------------------------------------------ From monogeo at gmail.com Thu Jun 4 13:55:28 2009 From: monogeo at gmail.com (monogeo) Date: Thu, 4 Jun 2009 10:55:28 -0700 (PDT) Subject: python way to automate IE8's File Download dialog Message-ID: <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3@n4g2000vba.googlegroups.com> Hello, I am able to use PAMIE 2.0 to automate IE7's File Download dialog, but the same approach/code fails on IE8. You can see the details and code at http://tech.groups.yahoo.com/group/Pamie_UsersGroup/message/675 Please help if you are able to automate IE8's File Download dialog (with three buttons; Open, Save, Cancel) via python script. Thanks in advance. Jimmy From tjreedy at udel.edu Thu Jun 4 14:02:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 14:02:33 -0400 Subject: Get the hard disk hardware serial number In-Reply-To: <78pvnhF1n1gpeU1@mid.individual.net> References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> <78pvnhF1n1gpeU1@mid.individual.net> Message-ID: Dietmar Schwertberger wrote: > The WMI method is e.g. described here: > http://www.velocityreviews.com/forums/t359670-wmi-help.html > > > import wmi Not in the stdlib, but available here: http://pypi.python.org/pypi/WMI/1.3 and requires in turn pywin32: http://pypi.python.org/pypi/pywin32/210 > c = wmi.WMI() > for pm in c.Win32_PhysicalMedia(): > print pm.Tag, pm.SerialNumber > > or to retrieve the serial number for the installation drive: > > serial = c.Win32_PhysicalMedia(["SerialNumber"], > Tag=r"\\.\PHYSICALDRIVE0")[0].SerialNumber.strip() > > > Regards, > > Dietmar From wiggly at wiggly.org Thu Jun 4 14:16:48 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Thu, 04 Jun 2009 19:16:48 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <4A280F90.7050506@wiggly.org> Hendrik van Rooyen wrote: > It is not something that would find common use - in fact, I have > never, until I started struggling with my current problem, ever even > considered the possibility of converting a pointer to a string and > back to a pointer again, and I would be surprised if anybody else > on this list has done so in the past, in a context other than debugging. Okay, well, I think that's probably because it sounds like a fairly good way of making things slower and hard to port to another interpreter. Obviously depending on how you're achieving this. If you need to pass infomation to a thread then I would suggest there's better, quicker, more reliable, portable and comprehensible ways of doing it. It just smells to me that you've created this elaborate and brittle hack to work around the fact that you couldn't think of any other way of getting the thread to change it's behaviour whilst waiting on input. Just my 0.02p n From paul at boddie.org.uk Thu Jun 4 14:24:02 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 4 Jun 2009 11:24:02 -0700 (PDT) Subject: Get the hard disk hardware serial number References: <6e5b31840906031358q1e1cf592wcacf194889a4b894@mail.gmail.com> Message-ID: <7ffc43b2-63e2-468c-bcb5-ae3260cf1a75@g37g2000yqn.googlegroups.com> On 4 Jun, 11:29, Nick Craig-Wood wrote: > > For linux I'd run this and parse the results. > > # smartctl -i /dev/sda Also useful is hdparm, particularly with the drive identification and detailed information options shown respectively below: # hdparm -i /dev/sda # hdparm -I /dev/sda Paul From nad at acm.org Thu Jun 4 14:33:17 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 11:33:17 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> Message-ID: In article <77e831100906040708l1a8bf638n19bbff05607b3d4a at mail.gmail.com>, Vincent Davis wrote: > I volunteered to help Marijo Mihel?i? who was looking for someone with > a mac the help him build a mac binary using py2app for his > simpletasktimer > http://code.google.com/p/simpletasktimer/wiki/Installation > > when I try to run his app I get the no module named _sqlite3 , I am > not sure what this is caused by as it looks to me like sqlite3 is > trying to import it. Any idea how to fix this? Other than the obvious > of getting _sqlite3 somehow, or maby it is that simple. > > here is what i get [...] > "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/s > qlite3/dbapi2.py", > line 27, in > from _sqlite3 import * > ImportError: No module named _sqlite3 > logout >From the path names, it appears you are using the MacPorts python2.5. Try: sudo port install py25-sqlite3 which will bring along sqlite3 if not already installed. It should be that simple. -- Ned Deily, nad at acm.org From see_website at mindprod.com.invalid Thu Jun 4 14:35:03 2009 From: see_website at mindprod.com.invalid (Roedy Green) Date: Thu, 04 Jun 2009 11:35:03 -0700 Subject: multi-core software References: Message-ID: On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee wrote, quoted or indirectly quoted someone who said : >? Why Must Software Be Rewritten For Multi-Core Processors? Threads have been part of Java since Day 1. Using threads complicates your code, but even with a single core processor, they can improve performance, particularly if you are doing something like combing multiple websites. The nice thing about Java is whether you are on a single core processor or a 256 CPU machine (We got to run our Athena Integer Java spreadsheet engine on such a beast), does not concern your code. You just have to make sure your threads don't interfere with each other, and Java/the OS, handle exploiting all the CPUs available. -- Roedy Green Canadian Mind Products http://mindprod.com Never discourage anyone... who continually makes progress, no matter how slow. ~ Plato 428 BC died: 348 BC at age: 80 From avazquezr at grm.uci.cu Thu Jun 4 14:51:38 2009 From: avazquezr at grm.uci.cu (Ariel Vazquez Riveron) Date: Thu, 04 Jun 2009 14:51:38 -0400 Subject: DUDA !!!!!!!!!! Message-ID: <20090604145138.17384ek58glbpi80@correo.grm.uci.cu> Hola: Hoy en d?a me encuentro iniciandome dentro del python, en estos momentos quiero saber de que forma puedo eliminar un archivo de un compactado, ya sea zip, rar o cualquier otro. Estudie las librer?as zipfile pero no tiene ninguna funcion que me permita hacerlo. Trabajo con python 2.5 salu2 Ariel ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From vincent at vincentdavis.net Thu Jun 4 14:51:49 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 12:51:49 -0600 Subject: import _sqlite3 no module named error In-Reply-To: References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> Message-ID: <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> >> when I try to run his app I get the no module named _sqlite3 , I am >> not sure what this is caused by as it looks to me like sqlite3 is >> trying to import it. Any idea how to fix this? Other than the obvious >> of getting _sqlite3 somehow, or maby it is that simple >> ? "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/s >> ? qlite3/dbapi2.py", >> line 27, in >> ? ? from _sqlite3 import * >> ImportError: No module named _sqlite3 >> logout > >From the path names, it appears you are using the MacPorts python2.5. > Try: > > ? ?sudo port install py25-sqlite3 > > which will bring along sqlite3 if not already installed. Yes I am using macports I think sqlite is installed? here is what I get when I run sudo port install py25-sqlite3 vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 Skipping org.macports.activate (py25-sqlite3 ) since this port is already active ---> Cleaning py25-sqlite3 vincent-daviss-macbook-pro-2:~ vmd$ From theller at ctypes.org Thu Jun 4 15:35:21 2009 From: theller at ctypes.org (Thomas Heller) Date: Thu, 04 Jun 2009 21:35:21 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> Message-ID: <4A2821F9.6080901@ctypes.org> [Please keep the discussion on the list] Joseph Garvin schrieb: > On Thu, Jun 4, 2009 at 3:43 AM, Thomas Heller wrote: >> There have been some attempts to use ctypes to access C++ objects. >> We (Roman Yakovenko and myself) made some progress. We were able to >> handle C++ name mangling, the special C++ calling convention, >> access virtual, non-virtual, overloaded functions, but finally gave up >> because the binary layout (function tables, member variables, and so on) >> of C++ objects is way too complicated and undocumented. > > Have you read the book Inside The C++ Object Model?: I haven't, but considered to buy it ;-) > http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545/ref=sr_1_1?ie=UTF8&s=books&qid=1244139929&sr=8-1 > > It's probably out of date now, but I'm about halfway through it and it > documents a ton of the little unexpected optimizations and such that > cause the binary layout to be complex. How did you get as far as you > did without having figured out the layout? (e.g. if you could access > virtual functions you must have known how to get at the virtual table) I found a lot of material on the web, also I used the (very good) visual studio debugger, and finally I did a lot of experimentation. We were only able to access some very simple C++ objects. There is also a patent or patents from MS about the vtable. All in all, as I said, IMO it is too complicated to figure out the binary layout of the C++ objects (without using a C++ compiler), also there are quite some Python packages for accessing them. -- Thanks, Thomas From kkylheku at gmail.com Thu Jun 4 15:37:59 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Thu, 4 Jun 2009 19:37:59 +0000 (UTC) Subject: multi-core software References: Message-ID: <20090616103324.200@gmail.com> ["Followup-To:" header set to comp.lang.lisp.] On 2009-06-04, Roedy Green wrote: > On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee > wrote, quoted or indirectly quoted someone who said : > >>? Why Must Software Be Rewritten For Multi-Core Processors? > > Threads have been part of Java since Day 1. Unfortunately, not sane threads designed by people who actually understand multithreading. > The nice thing about Java is whether you are on a single core > processor or a 256 CPU machine (We got to run our Athena Integer Java > spreadsheet engine on such a beast), does not concern your code. You are dreaming if you think that there are any circumstances (other than circumstances in which performance doesn't matter) in which you don't have to concern yourself about the difference between a uniprocessor and a 256 CPU machine. From nad at acm.org Thu Jun 4 15:41:15 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 12:41:15 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> Message-ID: In article <77e831100906041151g70868dbre1546cdb01082ba3 at mail.gmail.com>, Vincent Davis wrote: > Yes I am using macports I think sqlite is installed? here is what I > get when I run > sudo port install py25-sqlite3 > > vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 > Skipping org.macports.activate (py25-sqlite3 ) since this port is already > active > ---> Cleaning py25-sqlite3 > vincent-daviss-macbook-pro-2:~ vmd$ Hmm! This is on 10.5.7, BTW. $ sudo port version Version: 1.710 $ sudo port info py25-sqlite3 py25-sqlite3 @2.5.4 (python, databases) [...] $ /opt/local/bin/python2.5 Python 2.5.4 (r254:67916, May 4 2009, 01:40:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from _sqlite3 import * >>> A quick web search shows that there were apparently some issues with MacPort's py25-sqlite3 in the not too distant past. Perhaps your ports need to be upgraded? $ sudo port selfupdate or $ sudo port sync $ sudo port upgrade installed -- Ned Deily, nad at acm.org From mgarrana at mantrac.com.eg Thu Jun 4 15:42:23 2009 From: mgarrana at mantrac.com.eg (Mohamed Garrana) Date: Thu, 4 Jun 2009 22:42:23 +0300 Subject: Is socket.shutdown(1) useless Message-ID: <2D121496476B834D87FEF0AFA9A78A2538E9D4@MAN-EXCL-02.mantrac.win2k.dom> Hello This is is in answer for Is socket.shutdown(1) useless Shutdown(1) , forces the socket no to send any more data This is usefull in Buffer flushing Strange error detection Safe guarding Let me explain more , when you send a data , it's not guaranteed to be sent to your peer , it's only guaranteed to be sent to the os buffer , which in turn sends it to the peer os buffer So by doing shutdown(1) , you flush your buffer and an error is raised if the buffer is not empty ie: data has not been sent to the peer yet Howoever this is irrevesable , so you can do that after you completely sent all your data and you want to be sure that it's atleast at the peer os buffer Everything's ok in the end...if it's not ok, then its not the end. P save paper... -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Thu Jun 4 15:50:25 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 15:50:25 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <4A2821F9.6080901@ctypes.org> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <2510655A-6F23-4B27-A5CD-AE8EC0D3587D@semanchuk.com> On Jun 4, 2009, at 3:35 PM, Thomas Heller wrote: > [Please keep the discussion on the list] > > Joseph Garvin schrieb: >> On Thu, Jun 4, 2009 at 3:43 AM, Thomas Heller >> wrote: >>> There have been some attempts to use ctypes to access C++ objects. >>> We (Roman Yakovenko and myself) made some progress. We were able to >>> handle C++ name mangling, the special C++ calling convention, >>> access virtual, non-virtual, overloaded functions, but finally >>> gave up >>> because the binary layout (function tables, member variables, and >>> so on) >>> of C++ objects is way too complicated and undocumented. >> >> Have you read the book Inside The C++ Object Model?: > It's probably out of date now, but I'm about halfway through it and it >> >> documents a ton of the little unexpected optimizations and such that >> cause the binary layout to be complex. How did you get as far as you >> did without having figured out the layout? (e.g. if you could access >> virtual functions you must have known how to get at the virtual >> table) > > I found a lot of material on the web, also I used the (very good) > visual > studio debugger, and finally I did a lot of experimentation. We > were only > able to access some very simple C++ objects. > > There is also a patent or patents from MS about the vtable. > > All in all, as I said, IMO it is too complicated to figure out the > binary > layout of the C++ objects (without using a C++ compiler), also there > are > quite some Python packages for accessing them. Hi Thomas, We're weighing options for accessing C++ objects via Python. I know of SIWG and Boost; are there others that you think deserve consideration? I've been happy with ctypes in my limited exposure to it and would love to find a way to make that work. This thread has been very interesting to me. Thanks Philip From theller at python.net Thu Jun 4 16:07:10 2009 From: theller at python.net (Thomas Heller) Date: Thu, 04 Jun 2009 22:07:10 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <78qnreF1nkqu7U1@mid.individual.net> Philip Semanchuk schrieb: > Hi Thomas, > We're weighing options for accessing C++ objects via Python. I know of > SIWG and Boost; are there others that you think deserve consideration? I haven't used any of them myself. A common suggestion is SIP, less known are pybindgen and Robin. But there may be many more, and others with more experience might have much more to say about them. Also there is Roman Yokavenko's pygccxml which has a lot of stuff. > I've been happy with ctypes in my limited exposure to it and would > love to find a way to make that work. This thread has been very > interesting to me. Unfortunately there is no solution in sight, with ctypes. From gagsl-py2 at yahoo.com.ar Thu Jun 4 16:14:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 17:14:26 -0300 Subject: import sqlite3 References: Message-ID: En Thu, 04 Jun 2009 03:14:18 -0300, willgun escribi?: > I'm a student from China.It's painful for us to read python > documentation entirely due to poor english.So I often make these > mistakes. Try "chinese python group" at Google - I see some promising results at least... -- Gabriel Genellina From pruebauno at latinmail.com Thu Jun 4 16:17:35 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Thu, 4 Jun 2009 13:17:35 -0700 (PDT) Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> Message-ID: <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> On Jun 3, 3:36?pm, a... at pythoncraft.com (Aahz) wrote: > In article <7c93031a-235e-4e13-bd37-7c9dbc6e8... at r16g2000vbn.googlegroups.com>, > > > > ? wrote: > >Should I open a bug report for this? > > >Python 2.5.1 (r251:54863, Sep 19 2007, 14:58:06) [C] on aix5 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> import os > >>>> os.popen('cat','w') > > > > >Python 3.1rc1 (r31rc1:73054, Jun ?1 2009, 10:49:24) [C] on aix5 > >Type "help", "copyright", "credits" or "license" for more information. > >>>> os.popen('cat','w') > >Traceback (most recent call last): > > ?File "", line 1, in > > ?File "/Python-3.1rc1/Lib/os.py", line 641, in popen > > ? ?return _wrap_close(io.TextIOWrapper(proc.stdin), proc) > >IOError: [Errno 29] Illegal seek > > What happens in 2.6 and 3.0? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "Given that C++ has pointers and typecasts, it's really hard to have a > serious conversation about type safety with a C++ programmer and keep a > straight face. ?It's kind of like having a guy who juggles chainsaws > wearing body armor arguing with a guy who juggles rubber chickens wearing > a T-shirt about who's in more danger." ?--Roy Smith, c.l.py, 2004.05.23 Python 2.6.2 (r262:71600, Jun 4 2009, 16:07:26) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') >>> Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.popen('cat','w') So it seems to be something in 3.1 that causes it to fail. BTW it is not like I use os.popen a lot. I found this problem while trying to use help(). Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> help(open) Traceback (most recent call last): File "", line 1, in File "/Python-3.1rc1/Lib/site.py", line 429, in __call__ return pydoc.help(*args, **kwds) File "/Python-3.1rc1/Lib/pydoc.py", line 1709, in __call__ self.help(request) File "/Python-3.1rc1/Lib/pydoc.py", line 1756, in help else: doc(request, 'Help on %s:') File "/Python-3.1rc1/Lib/pydoc.py", line 1505, in doc pager(render_doc(thing, title, forceload)) File "/Python-3.1rc1/Lib/pydoc.py", line 1320, in pager pager(text) File "/Python-3.1rc1/Lib/pydoc.py", line 1340, in return lambda text: pipepager(text, 'less') File "/Python-3.1rc1/Lib/pydoc.py", line 1359, in pipepager pipe = os.popen(cmd, 'w') File "/Python-3.1rc1/Lib/os.py", line 641, in popen return _wrap_close(io.TextIOWrapper(proc.stdin), proc) IOError: [Errno 29] Illegal seek >>> From Brian.Mingus at colorado.edu Thu Jun 4 16:23:36 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 14:23:36 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <78qnreF1nkqu7U1@mid.individual.net> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> Message-ID: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> What is the goal of this conversation that goes above and beyond what Boost.Python + pygccxml achieve? Boost has published a variety of libraries that will be included into the next c++ standard. It's hard to imagine a better designed python/c++ interface library than Boost.Python. Further, pygccxml is amazing with regards to scanning your source code using gcc itself and then using that xml representation to write out the Boost.Python code. What more do people in this conversation want? On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller wrote: > Philip Semanchuk schrieb: > > > Hi Thomas, > > We're weighing options for accessing C++ objects via Python. I know of > > SIWG and Boost; are there others that you think deserve consideration? > > I haven't used any of them myself. A common suggestion is SIP, > less known are pybindgen and Robin. But there may be many more, > and others with more experience might have much more to say about them. > Also there is Roman Yokavenko's pygccxml which has a lot of stuff. > > > I've been happy with ctypes in my limited exposure to it and would > > love to find a way to make that work. This thread has been very > > interesting to me. > > Unfortunately there is no solution in sight, with ctypes. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Thu Jun 4 16:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 04 Jun 2009 15:29:41 -0500 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 02 Jun 2009 10:54:48 +1200, Lawrence D'Oliveiro wrote: > > > In message , Albert van der Horst wrote: > > > >> An indication of how one can see one is in emacs is also appreciated. > > > > How about, hit CTRL/G and see if the word "Quit" appears somewhere. > > Ah, one has to love user interfaces designed with mnemonic keyboard > commands so as to minimize the burden of rote learning on the user. > Presumably it is G for "Get me the frack outta here!". > > Having noted that the word "Quit" does appear, how do you then *actually* > Quit? Apart from taunting the user, what is it that Ctrl-G is actually > doing when it displays the word "Quit" in what seems to be some sort of > status bar? I love the idea of emacs taunting the user - it is like all that lisp code suddenly became self aware and decided to join in ;-) Ctrl-G is the emacs interrupt sequence. It cancels what you are doing. Kind of like Ctrl-C in the shell. You quit emacs with Ctrl-X Ctrl-C. Save a document with Ctrl-X Ctrl-S that that is probably enough for the emacs survival guide! If you run emacs in a windowing environment (eg X-Windows or Windows) you actually get menus you can choose save and quit off! Anyway, wrenching the thread back on topic - I use emacs for all my python editing needs (on linux, windows and mac) with pymacs or python-mode (depending on distro). I use the subversion integration extensively. The interactive features of emacs are really useful for testing python code - even more useful than the python interactive prompt for bits of code longer than a line or too. (Open a new window in python mode, type stuff, press Ctrl-C Ctrl-C and have the output shown in a different window. If you messed up, clicking on the error will put the cursor in the right place in the code). -- Nick Craig-Wood -- http://www.craig-wood.com/nick From tjreedy at udel.edu Thu Jun 4 16:41:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 16:41:31 -0400 Subject: Illegal seek with os.popen In-Reply-To: <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> Message-ID: pruebauno at latinmail.com wrote: > Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 > Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > > So it seems to be something in 3.1 that causes it to fail. > BTW it is not like I use os.popen a lot. I found this problem while > trying to use help(). > > Python 3.1rc1 (r31rc1:73054, Jun 1 2009, 10:49:24) [C] on aix5 > Type "help", "copyright", "credits" or "license" for more information. >>>> help(open) On Windows xp, this works fine. > Traceback (most recent call last): > File "", line 1, in > File "/Python-3.1rc1/Lib/site.py", line 429, in __call__ > return pydoc.help(*args, **kwds) > File "/Python-3.1rc1/Lib/pydoc.py", line 1709, in __call__ > self.help(request) > File "/Python-3.1rc1/Lib/pydoc.py", line 1756, in help > else: doc(request, 'Help on %s:') > File "/Python-3.1rc1/Lib/pydoc.py", line 1505, in doc > pager(render_doc(thing, title, forceload)) > File "/Python-3.1rc1/Lib/pydoc.py", line 1320, in pager > pager(text) > File "/Python-3.1rc1/Lib/pydoc.py", line 1340, in > return lambda text: pipepager(text, 'less') > File "/Python-3.1rc1/Lib/pydoc.py", line 1359, in pipepager > pipe = os.popen(cmd, 'w') > File "/Python-3.1rc1/Lib/os.py", line 641, in popen > return _wrap_close(io.TextIOWrapper(proc.stdin), proc) > IOError: [Errno 29] Illegal seek Now is the time to file a bug report for this and os.popen problem;) From python at mrabarnett.plus.com Thu Jun 4 16:49:01 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Jun 2009 21:49:01 +0100 Subject: multi-core software In-Reply-To: <20090616103324.200@gmail.com> References: <20090616103324.200@gmail.com> Message-ID: <4A28333D.6030304@mrabarnett.plus.com> Kaz Kylheku wrote: > ["Followup-To:" header set to comp.lang.lisp.] > On 2009-06-04, Roedy Green wrote: >> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >> wrote, quoted or indirectly quoted someone who said : >> >>> ? Why Must Software Be Rewritten For Multi-Core Processors? >> Threads have been part of Java since Day 1. > > Unfortunately, not sane threads designed by people who actually understand > multithreading. > >> The nice thing about Java is whether you are on a single core >> processor or a 256 CPU machine (We got to run our Athena Integer Java >> spreadsheet engine on such a beast), does not concern your code. > > You are dreaming if you think that there are any circumstances (other than > circumstances in which performance doesn't matter) in which you don't have to > concern yourself about the difference between a uniprocessor and a 256 CPU > machine. If you're interested in parallel programming, have a look at Flow-Based Programming: http://www.jpaulmorrison.com/fbp/ From philip at semanchuk.com Thu Jun 4 16:54:01 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 4 Jun 2009 16:54:01 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> On Jun 4, 2009, at 4:23 PM, Brian wrote: > What is the goal of this conversation that goes above and beyond what > Boost.Python + pygccxml achieve? Boost has published a variety of > libraries > that will be included into the next c++ standard. It's hard to > imagine a > better designed python/c++ interface library than Boost.Python. > Further, > pygccxml is amazing with regards to scanning your source code using > gcc > itself and then using that xml representation to write out the > Boost.Python > code. What more do people in this conversation want? Hi Brian, I've only experimented with SWIG (and ctypes for wrapping a C library). We're not yet sold on using SWIG to wrap our C++ libraries and so we're exploring alternatives. Before I started with SWIG, I did some research to see what other folks were using. The arguments I recall reading that swayed me to try SWIG before Boost were -- - Boost involves more "magic" than SWIG which means it does a bit more work for you, but when things go wrong (i.e. interface won't compile or doesn't work as expected) it is very difficult to debug. - Boost-ed code requires a Boost runtime library. This isn't a showstopper problem, obviously, but it's a mark against since it adds yet another prerequisite to our install process. - Boost's generated code can take a long time to compile. I don't know what pygccxml adds to the equation, so perhaps some of those disadvantages disappear with Boost.Python + pygccxml versus just plain Boost.Python. If you'd like to expound on this, feel free. I'd appreciate the education. I don't know about what Boost (or any other tool) generates, but the interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm amazed at what it can do. Nevertheless the generated interface has all the charm of a Babelfish translation. I imagine lots of autogenerated code looks "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are lost and it's eminently clear that it was not created by a native speaker. Until there's an interface generation tool that can build an interface that makes the wrapped library look completely Pythonic, then choosing a tool will be a matter of choosing which compromises you want to make. As long as that's true, I think there's room for multiple library-wrapping packages, just like there's room for more than one programming language in the world. Cheers Philip > > > On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller > wrote: > >> Philip Semanchuk schrieb: >> >>> Hi Thomas, >>> We're weighing options for accessing C++ objects via Python. I >>> know of >>> SIWG and Boost; are there others that you think deserve >>> consideration? >> >> I haven't used any of them myself. A common suggestion is SIP, >> less known are pybindgen and Robin. But there may be many more, >> and others with more experience might have much more to say about >> them. >> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >> >>> I've been happy with ctypes in my limited exposure to it and would >>> love to find a way to make that work. This thread has been very >>> interesting to me. >> >> Unfortunately there is no solution in sight, with ctypes. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From Brian.Mingus at colorado.edu Thu Jun 4 17:01:17 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 15:01:17 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> Message-ID: <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> Well you'll just have to try Boost.Python. There is a pygccxml gui gets you started in about 15 minutes. You'll be able to see how well it groks your code and what that generated code is. Boost is the best. People complain about it because they don't understand C++ templates and they don't realize how incredibly well designed it is. If you don't know the basics it's this: Boost.Python uses meta template programming. This allows it to use the C++ preprocessor for what other binding systems generally write a custom tool for. Long compile times are not a real problem for anyone - it's easy to set up a compile farm and the benefit is that your runtime code is blazing fast. In my opinion Boost is more sophisticated, SWIG, etc.. is more of a hack. Of course they all help you get the job done. On Thu, Jun 4, 2009 at 2:54 PM, Philip Semanchuk wrote: > > On Jun 4, 2009, at 4:23 PM, Brian wrote: > > What is the goal of this conversation that goes above and beyond what >> Boost.Python + pygccxml achieve? Boost has published a variety of >> libraries >> that will be included into the next c++ standard. It's hard to imagine a >> better designed python/c++ interface library than Boost.Python. Further, >> pygccxml is amazing with regards to scanning your source code using gcc >> itself and then using that xml representation to write out the >> Boost.Python >> code. What more do people in this conversation want? >> > > Hi Brian, > I've only experimented with SWIG (and ctypes for wrapping a C library). > We're not yet sold on using SWIG to wrap our C++ libraries and so we're > exploring alternatives. Before I started with SWIG, I did some research to > see what other folks were using. The arguments I recall reading that swayed > me to try SWIG before Boost were -- > - Boost involves more "magic" than SWIG which means it does a bit more work > for you, but when things go wrong (i.e. interface won't compile or doesn't > work as expected) it is very difficult to debug. > - Boost-ed code requires a Boost runtime library. This isn't a showstopper > problem, obviously, but it's a mark against since it adds yet another > prerequisite to our install process. > - Boost's generated code can take a long time to compile. > > I don't know what pygccxml adds to the equation, so perhaps some of those > disadvantages disappear with Boost.Python + pygccxml versus just plain > Boost.Python. If you'd like to expound on this, feel free. I'd appreciate > the education. > > I don't know about what Boost (or any other tool) generates, but the > interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm > amazed at what it can do. Nevertheless the generated interface has all the > charm of a Babelfish translation. I imagine lots of autogenerated code looks > "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are > lost and it's eminently clear that it was not created by a native speaker. > > Until there's an interface generation tool that can build an interface that > makes the wrapped library look completely Pythonic, then choosing a tool > will be a matter of choosing which compromises you want to make. As long as > that's true, I think there's room for multiple library-wrapping packages, > just like there's room for more than one programming language in the world. > > Cheers > Philip > > > > > >> >> On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller wrote: >> >> Philip Semanchuk schrieb: >>> >>> Hi Thomas, >>>> We're weighing options for accessing C++ objects via Python. I know of >>>> SIWG and Boost; are there others that you think deserve consideration? >>>> >>> >>> I haven't used any of them myself. A common suggestion is SIP, >>> less known are pybindgen and Robin. But there may be many more, >>> and others with more experience might have much more to say about them. >>> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >>> >>> I've been happy with ctypes in my limited exposure to it and would >>>> love to find a way to make that work. This thread has been very >>>> interesting to me. >>>> >>> >>> Unfortunately there is no solution in sight, with ctypes. >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> -- >> 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 Brian.Mingus at colorado.edu Thu Jun 4 17:27:11 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 4 Jun 2009 15:27:11 -0600 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> <9BA14FF4-DAE9-479E-8859-139D8BACDC4B@semanchuk.com> <9839a05c0906041401jcc9e1bco4dda57416f58603c@mail.gmail.com> Message-ID: <9839a05c0906041427l270b9be8m94e7dcc89b18d9af@mail.gmail.com> Just to expound a bit on pygccxml, which really makes boost worth it. pygccxml enables you to do all of your binding work from within Python. It calls gccxml, which is an xml backend to gcc that outputs the parse tree in an xml format. Pygccxml provides a very high level interface between the gcc xml representation and the pygccxml boost code generator. It's really a great thing. You just have to learn to read the code that pygccxml outputs for boost, and then go back to python and use the high level interface to modify the code that it outputs. It has all sorts of selectors so you can operate on all code that has certain arbitrary properties all at the same time. Play with it before deciding on swig. It's frikkin' cool :) On Thu, Jun 4, 2009 at 3:01 PM, Brian wrote: > Well you'll just have to try Boost.Python. There is a pygccxml gui gets you > started in about 15 minutes. You'll be able to see how well it groks your > code and what that generated code is. > > Boost is the best. People complain about it because they don't understand > C++ templates and they don't realize how incredibly well designed it is. > > If you don't know the basics it's this: Boost.Python uses meta template > programming. This allows it to use the C++ preprocessor for what other > binding systems generally write a custom tool for. Long compile times are > not a real problem for anyone - it's easy to set up a compile farm and the > benefit is that your runtime code is blazing fast. > > In my opinion Boost is more sophisticated, SWIG, etc.. is more of a hack. > Of course they all help you get the job done. > > > On Thu, Jun 4, 2009 at 2:54 PM, Philip Semanchuk wrote: > >> >> On Jun 4, 2009, at 4:23 PM, Brian wrote: >> >> What is the goal of this conversation that goes above and beyond what >>> Boost.Python + pygccxml achieve? Boost has published a variety of >>> libraries >>> that will be included into the next c++ standard. It's hard to imagine a >>> better designed python/c++ interface library than Boost.Python. Further, >>> pygccxml is amazing with regards to scanning your source code using gcc >>> itself and then using that xml representation to write out the >>> Boost.Python >>> code. What more do people in this conversation want? >>> >> >> Hi Brian, >> I've only experimented with SWIG (and ctypes for wrapping a C library). >> We're not yet sold on using SWIG to wrap our C++ libraries and so we're >> exploring alternatives. Before I started with SWIG, I did some research to >> see what other folks were using. The arguments I recall reading that swayed >> me to try SWIG before Boost were -- >> - Boost involves more "magic" than SWIG which means it does a bit more >> work for you, but when things go wrong (i.e. interface won't compile or >> doesn't work as expected) it is very difficult to debug. >> - Boost-ed code requires a Boost runtime library. This isn't a showstopper >> problem, obviously, but it's a mark against since it adds yet another >> prerequisite to our install process. >> - Boost's generated code can take a long time to compile. >> >> I don't know what pygccxml adds to the equation, so perhaps some of those >> disadvantages disappear with Boost.Python + pygccxml versus just plain >> Boost.Python. If you'd like to expound on this, feel free. I'd appreciate >> the education. >> >> I don't know about what Boost (or any other tool) generates, but the >> interface I got out of SWIG was not pretty. That's no knock on SWIG -- I'm >> amazed at what it can do. Nevertheless the generated interface has all the >> charm of a Babelfish translation. I imagine lots of autogenerated code looks >> "babelfish-ed": meaning is preserved, albeit crudely, but all the idioms are >> lost and it's eminently clear that it was not created by a native speaker. >> >> Until there's an interface generation tool that can build an interface >> that makes the wrapped library look completely Pythonic, then choosing a >> tool will be a matter of choosing which compromises you want to make. As >> long as that's true, I think there's room for multiple library-wrapping >> packages, just like there's room for more than one programming language in >> the world. >> >> Cheers >> Philip >> >> >> >> >> >>> >>> On Thu, Jun 4, 2009 at 2:07 PM, Thomas Heller >>> wrote: >>> >>> Philip Semanchuk schrieb: >>>> >>>> Hi Thomas, >>>>> We're weighing options for accessing C++ objects via Python. I know of >>>>> SIWG and Boost; are there others that you think deserve consideration? >>>>> >>>> >>>> I haven't used any of them myself. A common suggestion is SIP, >>>> less known are pybindgen and Robin. But there may be many more, >>>> and others with more experience might have much more to say about them. >>>> Also there is Roman Yokavenko's pygccxml which has a lot of stuff. >>>> >>>> I've been happy with ctypes in my limited exposure to it and would >>>>> love to find a way to make that work. This thread has been very >>>>> interesting to me. >>>>> >>>> >>>> Unfortunately there is no solution in sight, with ctypes. >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >>>> >>>> -- >>> 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 aahz at pythoncraft.com Thu Jun 4 17:28:07 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 14:28:07 -0700 Subject: Illegal seek with os.popen References: <7c93031a-235e-4e13-bd37-7c9dbc6e889c@r16g2000vbn.googlegroups.com> <5edde6ee-4446-4f53-91ee-ad3aea4b5603@q37g2000vbi.googlegroups.com> Message-ID: [posted & e-mailed] In article <5edde6ee-4446-4f53-91ee-ad3aea4b5603 at q37g2000vbi.googlegroups.com>, wrote: > >Python 3.0.1 (r301:69556, Jun 4 2009, 16:07:22) [C] on aix5 >Type "help", "copyright", "credits" or "license" for more information. >>>> import os >>>> os.popen('cat','w') > > >So it seems to be something in 3.1 that causes it to fail. >BTW it is not like I use os.popen a lot. I found this problem while >trying to use help(). Please file a report on bugs.python.org and send a note to python-dev. Thanks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From reagle at mit.edu Thu Jun 4 17:30:58 2009 From: reagle at mit.edu (Joseph Reagle) Date: Thu, 04 Jun 2009 17:30:58 -0400 Subject: MultiReplace (performance and unordered dicts) Message-ID: I have programs that do lots of string-to-string replacements, so I'm trying to create a speedy implementation (tons of .replace statements has become unwieldy). My MultiReplace object does as well as the function regexp, which both do better than the for loop function, any other suggestions? def multi_repl(text, subs): for ori, sub in subs: text = text.replace(ori, sub) return text import string latex_esc_dic = dict(latex_esc) latex_esc_ori, latex_esc_rep = zip(*latex_esc) def symbol_replace(match, get=latex_esc_dic.get): return get(match.group(1), "") symbol_pattern = re.compile( "(" + string.join(map(re.escape, latex_esc_ori), "|") + ")" ) class MultiReplace(object): """ Replace multiple instances from a list of ori/rep pairs. I use an object for performance: compiled regexes persist. Table is a list of pairs, I have to convert to dict for regex replace function, don't use a dict natively since they aren't ordered. """ def __init__(self, table): print "initing object" self.originals, self.replacements = zip(*table) self.pattern = re.compile( "(" + string.join(map(re.escape, self.originals), "|") + ")" ) self.table_dic = dict(table) def _get_replacement(self, match): # passed match #print "replacing %s with %s" % (match.group(1), self.table_dic.get(match.group(1), "")) return self.table_dic.get(match.group(1), "") # use match to return replacement def replace(self, line): return self.pattern.sub(self._get_replacement, line) # pass replacement function mr = MultiReplace(latex_esc) ... #line = multi_repl(line, latex_esc) # 0.406 #line = symbol_pattern.sub(symbol_replace, line) #0.385 line = mr.replace(line) #0.385 From brian at sweetapp.com Thu Jun 4 17:40:07 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 14:40:07 -0700 Subject: Odd closure issue for generators Message-ID: <4A283F37.3020703@sweetapp.com> This is from Python built from the py3k branch: >>> c = (lambda : i for i in range(11, 16)) >>> for q in c: ... print(q()) ... 11 12 13 14 15 >>> # This is expected >>> c = (lambda : i for i in range(11, 16)) >>> d = list(c) >>> for q in d: ... print(q()) ... 15 15 15 15 15 >>> # I was very surprised Looking at the implementation, I see why this happens: >>> c = (lambda : i for i in range(11, 16)) >>> for q in c: ... print(id(q.__closure__[0])) ... 3847792 3847792 3847792 3847792 3847792 >>> # The same closure is used by every lambda But it seems very odd to me and it can lead to some problems that are a real pain in the ass to debug. Cheers, Brian From joseph.h.garvin at gmail.com Thu Jun 4 18:16:07 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Thu, 4 Jun 2009 17:16:07 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: On Thu, Jun 4, 2009 at 3:23 PM, Brian wrote: > What is the goal of this conversation that goes above and beyond what > Boost.Python + pygccxml achieve? I can't speak for others but the reason I was asking is because it's nice to be able to define bindings from within python. At a minimum, compiling bindings means a little extra complexity to address with whatever build tools you're using. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:19:57 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:19:57 +1200 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In message , Nick Craig- Wood wrote: > You quit emacs with Ctrl-X Ctrl-C. That's "save-buffers-kill-emacs". If you don't want to save buffers, the exit sequence is alt-tilde, f, e. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:20:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:20:26 +1200 Subject: What text editor is everyone using for Python References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: In message , Albert van der Horst wrote: > Memories of Atari 260/520/1040 that had a keyboard with a key actually > marked ... HELP. And the OLPC machines have a key marked "reveal source". From joseph.h.garvin at gmail.com Thu Jun 4 18:23:45 2009 From: joseph.h.garvin at gmail.com (Joseph Garvin) Date: Thu, 4 Jun 2009 17:23:45 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <4A2821F9.6080901@ctypes.org> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: On Thu, Jun 4, 2009 at 2:35 PM, Thomas Heller wrote: > [Please keep the discussion on the list] > > All in all, as I said, IMO it is too complicated to figure out the binary > layout of the C++ objects (without using a C++ compiler), also there are > quite some Python packages for accessing them. Requiring that the C++ compiler used to make the dll's/so's to be the same one Python is compiled with wouldn't be too burdensome would it? Because then you could have it run a bunch of configure tests to determine information exposing the layout. I don't know if everything is testable, but you can for example (I learned this from the object model book btw) write a C++ program that determines whether the virtual function table is stored at the beginning or the end of an object by comparing the address of an object with a virtual function to the address of its first data member. If they're different, it's because the vptr is stored there, otherwise it's on the end (theoretically it could be in the middle but there's no reason for compiler writers to do that). cpptypes could then use information generated by tests like this that are run when the interpreter is compiled. From ldo at geek-central.gen.new_zealand Thu Jun 4 18:26:34 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 10:26:34 +1200 Subject: Project source code layout? References: Message-ID: In message , Allen Fowler wrote: > 1) Do you use virtualpython? No idea what that is. > 2) How do you load the modules in your lib directory? At the beginning of my scripts, I have a sequence like test_mode = False # True for testing, False for production if test_mode : home_dir = "/home/shop-test" else : home_dir = "/home/shop" #end if sys.path.append(home_dir + "/lib") import common [etc] I have an installation script that looks for that "test_mode = True/False" assignment and edits it accordingly. That flag is used to select the top- level directory (as above) as well as the database name, etc. This allows me to run two complete parallel sets of code and data, so I can mess around with the testing version without impacting the production system. > 3) How do you reference your configuration directives from within your > modules and CGI/daemon scripts? For my last project using the above system, I used XML as the config file format. From robert.kern at gmail.com Thu Jun 4 18:44:43 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Jun 2009 17:44:43 -0500 Subject: "where" in python In-Reply-To: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> References: <8a4beed5-8e59-4ab0-bee8-cc0d32218f4d@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-04 12:53, Chris wrote: > I am a newby in Python and I'm first looking for equivalent to things > I already manage: IDL. > For example, I want to plot a sub-set of points, selected from a > bigger set by applying some filter. In my example, I want to select > only the values> 0. > I succeed to write 5 different ways to do this, which one is the more > efficient, the quicker, the more Python? You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists The 1st method. The rest just do a lot of extra work or use old APIs. > It seems the 4th method give wrong results, but I don't know why... > Thanks for your tips, > Christophe > ------------------------------------------------------------------------------------------ > import pylab as pylab > import numpy as numpy You don't need to use "as" unless if you are renaming the modules. -- 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 gagsl-py2 at yahoo.com.ar Thu Jun 4 19:02:35 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 20:02:35 -0300 Subject: Odd closure issue for generators References: <4A283F37.3020703@sweetapp.com> Message-ID: En Thu, 04 Jun 2009 18:40:07 -0300, Brian Quinlan escribi?: > This is from Python built from the py3k branch: It's not new; same thing happens with 2.x A closure captures (part of) the enclosing namespace, so names are resolved in that environment even after the enclosing block has finished execution. As always, the name->value evaluation happens when it is required at runtime, not earlier ("late binding"). So, in the generator expression (lambda : i for i in range(11, 16)) the 'i' is searched in the enclosing namespace when the lambda is evaluated, not when the lambda is created. Your first example: > [1] >>> c = (lambda : i for i in range(11, 16)) > [2] >>> for q in c: > [3] ... print(q()) > ... > 11 > 12 > 13 > 14 > 15 > >>> # This is expected This code means: [1] create a generator expression and name it `c` [2] ask `c` for an iterator. A generator is its own iterator, so returns itself. Loop begins: Ask the iterator a new item (the first one, in fact). So the generator executes one cycle, yields a lambda expression, and freezes. Note that the current value of `i` (in that frozen environment) is 11. Name the yielded object (the lambda) `q`. [3] Call the q object. That means, execute the lambda. It returns the current value of i, 11. Print it. Back to [2]: ask the iterator a new item. The generator resumes, executes another cycle, yields another lambda expression, and freezes. Now, i is 12 inside the frozen environment. [3] execute the lambda -> 12 etc. Your second example: > [4] >>> c = (lambda : i for i in range(11, 16)) > [5] >>> d = list(c) > [6] >>> for q in d: > [7] ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 > >>> # I was very surprised [4] creates a generator expression same as above. [5] ask for an iterator (c itself). Do the iteration NOW until exhaustion, and collect each yielded object into a list. Those objects will be lambdas. The current (and final) value of i is 15, because the range() iteration has finished. [6] iterate over the list... [7] ...and execute each lambda. At this time, `i` is always 15. > Looking at the implementation, I see why this happens: > >>> c = (lambda : i for i in range(11, 16)) > >>> for q in c: > ... print(id(q.__closure__[0])) > ... > 3847792 > 3847792 > 3847792 > 3847792 > 3847792 > >>> # The same closure is used by every lambda ...because all of them refer to the same `i` name. > But it seems very odd to me and it can lead to some problems that are a > real pain in the ass to debug. Yes, at least if one is not aware of the consequences. I think this (or a simpler example) should be explained in the FAQ. The question comes in this list again and again... -- Gabriel Genellina From Scott.Daniels at Acm.Org Thu Jun 4 19:07:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 16:07:54 -0700 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: Joseph Garvin wrote: > On Thu, Jun 4, 2009 at 2:35 PM, Thomas Heller wrote: >> [Please keep the discussion on the list] >> >> All in all, as I said, IMO it is too complicated to figure out the binary >> layout of the C++ objects (without using a C++ compiler), also there are >> quite some Python packages for accessing them. > > Requiring that the C++ compiler used to make the dll's/so's to be the > same one Python is compiled with wouldn't be too burdensome would it? And what gave you then impression that Python is compiled with a C++ compiler? --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Thu Jun 4 19:18:32 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 4 Jun 2009 16:18:32 -0700 (PDT) Subject: Odd closure issue for generators References: Message-ID: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> On Jun 4, 2:40?pm, Brian Quinlan wrote: > This is from Python built from the py3k branch: > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> for q in c: > ... ? ? print(q()) > ... > 11 > 12 > 13 > 14 > 15 > ?>>> # This is expected > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> d = list(c) > ?>>> for q in d: > ... ? ? print(q()) > ... > 15 > 15 > 15 > 15 > 15 > ?>>> # I was very surprised > > Looking at the implementation, I see why this happens: > ?>>> c = (lambda : i for i in range(11, 16)) > ?>>> for q in c: > ... ? ? print(id(q.__closure__[0])) > ... > 3847792 > 3847792 > 3847792 > 3847792 > 3847792 > ?>>> # The same closure is used by every lambda > > But it seems very odd to me and it can lead to some problems that are a > real pain in the ass to debug. It's really the only sane way to handle it, odd though it may seem in this narrow case. In Python nested functions have to be able to reference the current value of a variable because of use cases like this: def func(): def printx(): print x x = 1 printx() x = 2 printx() Referencing a nonlocal variable always uses the current (or last) value of that variable, not the value it had when the nested function was defined. The way to handle the issue you are seeing is to create a new scope with a variable the remains at the value you want to close upon: create_const_function(value): def func(): return value c = (create_const_function(i) for i in range(11, 16)) Or you can do it the slacker way and use a default argument: c = (lambda i=i: i for i in range(11, 16)) Carl Banks From ppearson at nowhere.invalid Thu Jun 4 19:24:46 2009 From: ppearson at nowhere.invalid (Peter Pearson) Date: 4 Jun 2009 23:24:46 GMT Subject: easiest way to plot x,y graphically during run-time? References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <78r3dtF1nmabfU1@mid.individual.net> On Thu, 04 Jun 2009 03:29:42 -0500, Nick Craig-Wood wrote: [snip] > Here is a demo with pygame... [snip] And just for completeness, here is a demo with PyGUI, written in similar style. (I'm a PyGUI newbie, so constructive criticism would be appreciated.) from GUI import Window, View, application, Color, Task from random import randrange class Brownian( View ): def __init__( self, **kwargs ): View.__init__( self, **kwargs ) width, height = self.size self.dots = [ (randrange(width), randrange(height)) for _ in range( 100 ) ] def step( self ): self.dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2)) for dot in self.dots ] self.invalidate() def draw( self, canvas, rectangle ): canvas.set_backcolor( Color( 0, 0, 0 ) ) canvas.set_forecolor( Color( 0.3, 0.85, 0.25 ) ) radius = 10 canvas.erase_rect( rectangle ) for dot in self.dots: canvas.stroke_oval( ( dot[0]-radius, dot[1]-radius, dot[0]+radius, dot[1]+radius ) ) def main(): size = 640, 480 win = Window( size = size, title = "A test of PyGUI" ) b = Brownian( size = size ) win.add( b ) win.show() t = Task( b.step, interval = 0.02, repeat = True, start = True ) application().run() if __name__ == "__main__": main() -- To email me, substitute nowhere->spamcop, invalid->net. From Scott.Daniels at Acm.Org Thu Jun 4 19:42:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 04 Jun 2009 16:42:07 -0700 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: Brian Quinlan wrote: > This is from Python built from the py3k branch: > >>> c = (lambda : i for i in range(11, 16)) > >>> for q in c: > ... print(q()) > ... > 11 > 12 > 13 > 14 > 15 > >>> # This is expected > >>> c = (lambda : i for i in range(11, 16)) > >>> d = list(c) > >>> for q in d: > ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 > >>> # I was very surprised You are entitled to be surprised. Then figure out what is going on. Hint: it is the moral equivalent of what is happening here: >>> c = [] >>> for i in range(11, 16): c.append(lambda: i) >>> i = 'Surprise!' >>> print([f() for f in c]) ['Surprise!', 'Surprise!', 'Surprise!', 'Surprise!', 'Surprise!'] >>> i = 0 >>> print([f() for f in c]) [0, 0, 0, 0, 0] The body of your lambda is an un-evaluated expression with a reference, not an expression evaluated at the time of loading c. TO get what you expected, try this: >>> c = [] >>> for i in range(11, 16): c.append(lambda i=i: i) >>> i = 'Surprise!' >>> print([f() for f in c]) [11, 12, 13, 14, 15] When you evaluate a lambda expression, the default args are evaluated, but the expression inside the lambda body is not. When you apply that evaluated lambda expression, the expression inside the lambda body is is evaluated and returned. --Scott David Daniels Scott.Daniels at Acm.Org From ebonak at hotmail.com Thu Jun 4 19:49:18 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:49:18 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: Nick Craig-Wood wrote: > > Here is a demo with pygame... > Thanks Nick, I'll be studying this too :-) Esmail From ebonak at hotmail.com Thu Jun 4 19:49:43 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:49:43 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: <78r3dtF1nmabfU1@mid.individual.net> References: <78nl48F1n46o4U1@mid.uni-berlin.de> <78r3dtF1nmabfU1@mid.individual.net> Message-ID: Peter Pearson wrote: > On Thu, 04 Jun 2009 03:29:42 -0500, Nick Craig-Wood wrote: > [snip] >> Here is a demo with pygame... > [snip] > > And just for completeness, here is a demo with PyGUI, written > in similar style. Thanks for this too! Esmail From ebonak at hotmail.com Thu Jun 4 19:52:38 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 04 Jun 2009 19:52:38 -0400 Subject: easiest way to plot x,y graphically during run-time? In-Reply-To: References: <78nl48F1n46o4U1@mid.uni-berlin.de> Message-ID: <4A285E46.1090704@hotmail.com> Scott David Daniels wrote: > Esmail wrote: >> Scott David Daniels wrote: >>> Esmail wrote: >>>> ... Tk seems a bit more complex .. but I really don't know much about >>>> it and its interface with Python to make any sort of judgments as >>>> to which option would be better. >>> >>> This should look pretty easy: >> >> Thanks Scott for taking the time to share this code with me, it >> will give me something to study. I'm not sure if I'd say it looks >> easy (but then again I am not very familiar with Tk :-) > > I threw in too much, I think. :-) Tk seems quite capable, perhaps a bit more than I need for my simple visualization task at the moment (visualizing a PSO), but I'll probably investigate it when I have more ambitious GUI needs or am doing more than plotting the movement of particles on a 2D surface. Thanks again for sharing your code and explanations with me, a great way to learn. Esmail From vincent at vincentdavis.net Thu Jun 4 20:18:32 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 18:18:32 -0600 Subject: import _sqlite3 no module named error In-Reply-To: References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> Message-ID: <77e831100906041718k4b4f54d9v29729449c50f3cb@mail.gmail.com> On Thu, Jun 4, 2009 at 1:41 PM, Ned Deily wrote: > In article > <77e831100906041151g70868dbre1546cdb01082ba3 at mail.gmail.com>, > ?Vincent Davis wrote: >> Yes I am using macports I think sqlite is installed? here is what I >> get when I run >> sudo port install py25-sqlite3 >> >> vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3 >> Skipping org.macports.activate (py25-sqlite3 ) since this port is already >> active >> ---> ?Cleaning py25-sqlite3 >> vincent-daviss-macbook-pro-2:~ vmd$ > > Hmm! ?This is on 10.5.7, BTW. > > $ sudo port version > Version: 1.710 > $ sudo port info py25-sqlite3 > py25-sqlite3 @2.5.4 (python, databases) > [...] > $ /opt/local/bin/python2.5 > Python 2.5.4 (r254:67916, May ?4 2009, 01:40:08) > [GCC 4.0.1 (Apple Inc. build 5490)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> from _sqlite3 import * >>>> > > A quick web search shows that there were apparently some issues with > MacPort's py25-sqlite3 in the not too distant past. ?Perhaps your ports > need to be upgraded? > > $ sudo port selfupdate > or > $ sudo port sync > > $ sudo port upgrade installed Also 10.5.7 my self, I have completely removed and reinstall macport and all the ports. All befor posting this thread... here is what i get, jhgfjhgfjhg it is working now, I have no clue. I went on a bike ride and now it works? Thanks for you help. What do you know about python_select, .bash_profile and .profile? From johnnyz86 at gmail.com Thu Jun 4 20:37:42 2009 From: johnnyz86 at gmail.com (Johnny Chang) Date: Thu, 4 Jun 2009 17:37:42 -0700 (PDT) Subject: Printing list/tuple elements on separate lines Message-ID: I have a large list of strings that I am unpacking and splitting, and I want each one to be on a new line. Someone showed me how to do it and I got it working, except it is not printing each on its own separate line as his did, making it incredibly hard to read. He did it without adding a new line for anything. I can't get in touch with him right now. An example: recs = 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' [(rec.split('f')) for rec in recs] output: [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] desired output: [['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', '']] From apt.shansen at gmail.com Thu Jun 4 20:46:33 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 4 Jun 2009 17:46:33 -0700 Subject: Printing list/tuple elements on separate lines In-Reply-To: References: Message-ID: <7a9c25c20906041746m3a27ac3fxe0ff6c40bc5020af@mail.gmail.com> On Thu, Jun 4, 2009 at 5:37 PM, Johnny Chang wrote: > I have a large list of strings that I am unpacking and splitting, and > I want each one to be on a new line. Someone showed me how to do it > and I got it working, except it is not printing each on its own > separate line as his did, making it incredibly hard to read. He did > it without adding a new line for anything. I can't get in touch with > him right now. > How about-- import pprint > recs = 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' > pprint.pprint([(rec.split('f')) for rec in recs]) > --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Thu Jun 4 21:08:20 2009 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 4 Jun 2009 18:08:20 -0700 (PDT) Subject: unladen swallow: python and llvm Message-ID: I am very excited by this project (as well as by pypy) and I read all their plan, which looks quite practical and impressive. But I must confess that I can't understand why LLVM is so great for python and why it will make a difference. AFAIK, LLVM is alot of things at the same time (a compiler infrastructure, a compilation strategy, a virtual instruction set, etc). I am also confussed at their use of the term "jit" (is LLVM a jit? Can it be used to build a jit?). Is it something like the .NET or JAVA jit? Or it can be used to implement a custom jit (ala psyco, for example)? Also, as some pypy folk said, it seems they intend to do "upfront compilation". How? Is it something along the lines of the V8 javascript engine (no interpreter, no intermediate representation)? Or it will be another interpreter implementation? If so, how will it be any better...? Well, these are a lot of questions and they only show my confussion... I would highly appreciate if someone knowledgeable sheds some light on this for me... Thanks in advance! Luis From emile at fenx.com Thu Jun 4 21:15:09 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 04 Jun 2009 18:15:09 -0700 Subject: What text editor is everyone using for Python In-Reply-To: References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > In message , Nick Craig- > Wood wrote: > >> You quit emacs with Ctrl-X Ctrl-C. > > That's "save-buffers-kill-emacs". If you don't want to save buffers, the > exit sequence is alt-tilde, f, e. > Ha ha ha ha ha! No -- really? Emile From rNOSPAMon at flownet.com Thu Jun 4 21:18:24 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 04 Jun 2009 18:18:24 -0700 Subject: Yet another unicode WTF Message-ID: Python 2.6.2 on OS X 10.5.7: [ron at mickey:~]$ echo $LANG en_US.UTF-8 [ron at mickey:~]$ cat frob.py #!/usr/bin/env python print u'\u03BB' [ron at mickey:~]$ ./frob.py ? [ron at mickey:~]$ ./frob.py > foo Traceback (most recent call last): File "./frob.py", line 2, in print u'\u03BB' UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in position 0: ordinal not in range(128) (That's supposed to be a small greek lambda, but I'm using a brain-damaged news reader that won't let me set the character encoding. It shows up correctly in my terminal.) According to what I thought I knew about unix (and I had fancied myself a bit of an expert until just now) this is impossible. Python is obviously picking up a different default encoding when its output is being piped to a file, but I always thought one of the fundamental invariants of unix processes was that there's no way for a process to know what's on the other end of its stdout. Clues appreciated. Thanks. rg From ben+python at benfinney.id.au Thu Jun 4 21:22:35 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 11:22:35 +1000 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <87r5xzmq3o.fsf@benfinney.id.au> Emile van Sebille writes: > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > > In message , Nick Craig- > > Wood wrote: > > > >> You quit emacs with Ctrl-X Ctrl-C. > > > > That's "save-buffers-kill-emacs". If you don't want to save buffers, > > the exit sequence is alt-tilde, f, e. This is an invocation of the menu system, driven by the keyboard. (Also, it's not Alt+tilde (which would be Alt+Shift+`), it's Alt+` i.e. no Shift.) It's an alternate command, and IMO is just adding confusion to the discussion. > Ha ha ha ha ha! > > No -- really? Not really. If you don't want to save buffers, you just answer ?No? when prompted by ?save-buffers-kill-emacs?, so Ctrl+X Ctrl+C is all you need to know to exit Emacs. -- \ ?Consider the daffodil. And while you're doing that, I'll be | `\ over here, looking through your stuff.? ?Jack Handey | _o__) | Ben Finney From emailamit at gmail.com Thu Jun 4 21:22:44 2009 From: emailamit at gmail.com (Amit Gupta) Date: Thu, 4 Jun 2009 18:22:44 -0700 (PDT) Subject: ctype question Message-ID: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> Hi, I have been using ctype.cdll to load a library, but I am unable to figure out how to load multiple libraries that depends on each other. E.g. I have two libraries A.so and B.so. A.so has some undefined references, and those symbols are defined in B.so. When I try to load ctypes.cdll.LoadLibrary("A.so"), it gives errors about the undefined Symbols. Even if I load B.so before loading A.so, the error remains the same (which is expected). Can someone help me to find out, how to load A.so by telling it to look for undefined symbols in B.so as well? Thanks, Amit From zac256 at gmail.com Thu Jun 4 21:24:48 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 4 Jun 2009 18:24:48 -0700 Subject: __file__ access extremely slow Message-ID: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> The section of code below, which simply gets the __file__ attribute of the imported modules, takes more than 1/3 of the total startup time. Given that many modules are complicated and even have dynamic population this figure seems very high to me. it would seem very high if one just considered the time it would take to load the pyc files off the disk vs... whatever happens when module.__file__ happens. The calculation appears to be cached though, so a subsequent check does not take very long. >From once python starts and loads the main module to after all the imports occur and this section executes takes 1.3sec. This section takes 0.5sec. Total module count is ~800. Python version is 2.5.1 Code: ################################ for module in sys.modules: try: path = module.__file__ except (AttributeError, ImportError): return ################################ -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From cdalten at gmail.com Thu Jun 4 21:26:49 2009 From: cdalten at gmail.com (chad) Date: Thu, 4 Jun 2009 18:26:49 -0700 (PDT) Subject: How do I continue after the error? Message-ID: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Let's say I have a list of 5 files. Now lets say that one of the files reads nude333.txt instead of nude3.txt. When this happens, the program generates an error and quits. What I want it to do is just skip over the bad file and continue on with the next one. Below is the actual code. It only works on the local bbs that I hang out on. Sorry. I couldn't think of the simple case that could isolate my problem. #!/usr/bin/python #The original code was written by Mr.Pardue, which sounds a lot like #fuck you import telnetlib, os import time import glob my_porn_collection = ["nude.txt", "nude2.txt", "nude333.txt", "nude4.txt", "nude5.txt"] path = 'porn/' #my_porn_collection = [] def get_files(): for infile in glob.glob( os.path.join(path, '*.txt*')): my_porn_collection.append(infile) def generate(some_naked_bitches): try: f = open(some_naked_bitches, "r") except: pass art = f.read() f.close() return art def get_name(): user = raw_input("\nUsername: ") password = raw_input("Password: ") enter_party(user, password) def enter_party(user, password): now = telnetlib.Telnet("m-net.arbornet.org") now.read_until("login: ") print "\nEntered username.." now.write(user + "\n") now.read_until("Password:") now.write(password + "\n" ) print "Entered pass.." now.read_until("m-net%") now.write("party\n") print "Entered into party.." scroll_some_porn(now) def scroll_some_porn(now): while 1: for some_titty_porn in my_porn_collection: now.write(" \n") bitch_please = generate(some_titty_porn) now.write(bitch_please) time.sleep(10) now.write(" \n") if __name__ == "__main__": #get_files() get_name() From zac256 at gmail.com Thu Jun 4 21:29:45 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 4 Jun 2009 18:29:45 -0700 Subject: __file__ access extremely slow In-Reply-To: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: <333edbe80906041829x74f51caene02a3a949ea855d7@mail.gmail.com> Sorry, there is a typo. The code should read as below to repro the problem: ################################ for module in sys.modules.itervalues(): try: path = module.__file__ except (AttributeError, ImportError): return ################################ -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jun 4, 2009 at 6:24 PM, Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > > The calculation appears to be cached though, so a subsequent check > does not take very long. > > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > ? ? ? ?try: > ? ? ? ? ? ? ? ?path = module.__file__ > ? ? ? ?except (AttributeError, ImportError): > ? ? ? ? ? ? ? ?return > ################################ > > > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games > From brian at sweetapp.com Thu Jun 4 21:34:41 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 18:34:41 -0700 Subject: Odd closure issue for generators In-Reply-To: References: <4A283F37.3020703@sweetapp.com> Message-ID: <4A287631.6090904@sweetapp.com> Gabriel Genellina wrote: > En Thu, 04 Jun 2009 18:40:07 -0300, Brian Quinlan > escribi?: > >> This is from Python built from the py3k branch: > > It's not new; same thing happens with 2.x > > A closure captures (part of) the enclosing namespace, so names are > resolved in that environment even after the enclosing block has finished > execution. > As always, the name->value evaluation happens when it is required at > runtime, not earlier ("late binding"). So, in the generator expression > (lambda : i for i in range(11, 16)) the 'i' is searched in the enclosing > namespace when the lambda is evaluated, not when the lambda is created. OK, I talked myself into agreeing that it is better for the generator comprehension to share a context amongst every enclosed generator expression (rather than having one context per generator expression) for consistency reasons. Thanks! Cheers, Brian From greg at cosc.canterbury.ac.nz Thu Jun 4 21:35:07 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 05 Jun 2009 13:35:07 +1200 Subject: What text editor is everyone using for Python In-Reply-To: References: <02345d7c$0$8244$c3e8da3@news.astraweb.com> Message-ID: <78ravuF1nbh1pU1@mid.individual.net> Albert van der Horst wrote: > Memories of Atari 260/520/1040 that had a keyboard with a key actually > marked ... HELP. Modern day Mac keyboards have one of those, too. -- Greg From jnoller at gmail.com Thu Jun 4 21:41:43 2009 From: jnoller at gmail.com (Jesse Noller) Date: Thu, 4 Jun 2009 21:41:43 -0400 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <4222a8490906041841q6d89d5c9x623a6d9ab7ff168c@mail.gmail.com> You can email these questions to the unladen-swallow mailing list. They're very open to answering questions. 2009/6/4 Luis M. Gonz?lez : > I am very excited by this project (as well as by pypy) and I read all > their plan, which looks quite practical and impressive. > But I must confess that I can't understand why LLVM is so great for > python and why it will make a difference. > > AFAIK, LLVM is alot of things at the same time (a compiler > infrastructure, a compilation strategy, a virtual instruction set, > etc). > I am also confussed at their use of the term "jit" (is LLVM a jit? Can > it be used to build a jit?). > Is it something like the .NET or JAVA jit? Or it can be used to > implement a custom jit (ala psyco, for example)? > > Also, as some pypy folk said, it seems they intend to do "upfront > compilation". How? > Is it something along the lines of the V8 javascript engine (no > interpreter, no intermediate representation)? > Or it will be another interpreter implementation? If so, how will it > be any better...? > > Well, these are a lot of questions and they only show my confussion... > I would highly appreciate if someone knowledgeable sheds some light on > this for me... > > Thanks in advance! > Luis > -- > http://mail.python.org/mailman/listinfo/python-list > From gagsl-py2 at yahoo.com.ar Thu Jun 4 21:44:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 22:44:58 -0300 Subject: Making the case for repeat References: Message-ID: En Thu, 04 Jun 2009 10:37:45 -0300, pataphor escribi?: > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Because of backwards compatibility issues we > cannot remove them but we can boldly jump forward and include the right > repeat in the builtin namespace, which I think would be the best thing. > Alternatively -- the second best solution -- would be to give this > function its own namespace where it can supersede the old incongruencies > in itertools. Combiniter or combinator? Ok, you're proposing a "bidimensional" repeat. I prefer to keep things simple, and I'd implement it in two steps. First, something similar to your repeat_each function in another post: py> thing = ['1','2','3','4'] py> chain.from_iterable(repeat(elem, 3) for elem in thing) py> list(_) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] Note that this doesn't require any additional storage. Second step would be to build a bidimensional repeat: py> one = chain.from_iterable(repeat(elem, 3) for elem in thing) py> two = chain.from_iterable(tee(one, 2)) py> list(two) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] Short and simple, but this one requires space for one complete run (3*4 items in the example). Another variant that only requires space for freezing the original iterable (4 items in the example) is: >>> thing = ['1','2','3','4'] >>> items = list(thing) # ok, silly in this case, but not for a generic >>> iterable >>> chain.from_iterable(chain.from_iterable(repeat(elem, 3) for elem in >>> items) f or rownumber in range(2)) >>> list(_) ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4'] All of them run at full speed, using the optimized itertools machinery written in C. -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Thu Jun 4 21:47:03 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 13:47:03 +1200 Subject: Yet another unicode WTF References: Message-ID: In message , Ron Garret wrote: > Python 2.6.2 on OS X 10.5.7: Same result, Python 2.6.1-3 on Debian Unstable. My $LANG is en_NZ.UTF-8. > ... I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. Well, there have long been functions like isatty(3). That's probably what's involved here. From TrevorOKennedy at gmail.com Thu Jun 4 21:49:10 2009 From: TrevorOKennedy at gmail.com (Trevor) Date: Thu, 4 Jun 2009 18:49:10 -0700 (PDT) Subject: 2d barcode library? References: <0d33db03-cc89-4057-bbc6-5a76dd4b8045@s20g2000vbp.googlegroups.com> Message-ID: > > Christian > > [1]https://cybernetics.hudora.biz/projects/wiki/huBarcode Thanks guys! huBarcode will work.. From ben+python at benfinney.id.au Thu Jun 4 21:53:19 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 11:53:19 +1000 Subject: Yet another unicode WTF References: Message-ID: <87my8nmoog.fsf@benfinney.id.au> Ron Garret writes: > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. It certainly can. If you're using GNU and a terminal that declares support for colour, examine the difference between these two: $ ls --color=auto $ ls --color=auto > foo ; cat foo > Clues appreciated. Thanks. Research ?man 3 isatty? for the function most commonly used to determine whether a file descriptor represents a terminal. -- \ ?If you are unable to leave your room, expose yourself in the | `\ window.? ?instructions in case of fire, hotel, Finland | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Jun 4 22:01:56 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:01:56 +1000 Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: <87iqjbmoa3.fsf@benfinney.id.au> chad writes: > Let's say I have a list of 5 files. Now lets say that one of the files > reads nude333.txt instead of nude3.txt. When this happens, the program > generates an error and quits. What I want it to do is just skip over > the bad file and continue on with the next one. Have you worked thoroughly through the Python tutorial ? You will exercise many fundamental concepts, including the exception handling system. > Below is the actual code. It only works on the local bbs that I hang > out on. Sorry. I couldn't think of the simple case that could isolate > my problem. You achieve this by one of two methods: * start with a program that does extermely little, and add as little as possible until you have a very small program which demonstrates the behaviour. Once you have this, continue below. * remove apparently-irrelevant parts from the program until the behaviour stops occuring; the most recent removal, then, is at least related to the behaviour. Add it back in. Repeat these until you have aprogram which can't have any part of it removed without losing the behaviour that's confusing you. Once you have that, post it here with your question. -- \ ?Good morning, Pooh Bear?, said Eeyore gloomily. ?If it is a | `\ good morning?, he said. ?Which I doubt?, said he. ?A. A. Milne, | _o__) _Winnie-the-Pooh_ | Ben Finney From rNOSPAMon at flownet.com Thu Jun 4 22:06:25 2009 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 04 Jun 2009 19:06:25 -0700 Subject: Yet another unicode WTF References: Message-ID: In article , Lawrence D'Oliveiro wrote: > In message , Ron > Garret wrote: > > > Python 2.6.2 on OS X 10.5.7: > > Same result, Python 2.6.1-3 on Debian Unstable. My $LANG is en_NZ.UTF-8. > > > ... I always thought one of the fundamental > > invariants of unix processes was that there's no way for a process to > > know what's on the other end of its stdout. > > Well, there have long been functions like isatty(3). That's probably what's > involved here. Oh. Right. Duh. I am having an unbelievably bad day involving lawyers. (And not language lawyers, real ones.) Found the answer here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=415968 rg From ben+python at benfinney.id.au Thu Jun 4 22:06:27 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:06:27 +1000 Subject: Yet another unicode WTF References: Message-ID: <87eitzmo2k.fsf@benfinney.id.au> Ron Garret writes: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's certainly not desirable; the terminal, the shell, and the filesystem are all using UTF-8 so it should work fine. You might be best advised to report this as a bug to the Python bug tracker . -- \ ?I fly Air Bizarre. You buy a combination one-way round-trip | `\ ticket. Leave any Monday, and they bring you back the previous | _o__) Friday. That way you still have the weekend.? ?Steven Wright | Ben Finney From gagsl-py2 at yahoo.com.ar Thu Jun 4 22:09:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 23:09:47 -0300 Subject: Yet another unicode WTF References: Message-ID: En Thu, 04 Jun 2009 22:18:24 -0300, Ron Garret escribi?: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) > > > (That's supposed to be a small greek lambda, but I'm using a > brain-damaged news reader that won't let me set the character encoding. > It shows up correctly in my terminal.) > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. It may be hard to know *who* is at the other end of the pipe, but it's easy to know *what* kind of file it is. Lots of programs detect whether stdout is a tty or not (using isatty(3)) and adapt their output accordingly; ls is one example. Python knows the terminal encoding (or at least can make a good guess), but a file may use *any* encoding you want, completely unrelated to your terminal settings. So when stdout is redirected, Python refuses to guess its encoding; see the PYTHONIOENCODING environment variable. -- Gabriel Genellina From ben+python at benfinney.id.au Thu Jun 4 22:20:40 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 12:20:40 +1000 Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> <87iqjbmoa3.fsf@benfinney.id.au> Message-ID: <87ab4nmnev.fsf@benfinney.id.au> Ben Finney writes: > You achieve this by one of two methods: Failed to update this statement after an edit. That should be ?by following this method?. -- \ ?I used to be a proofreader for a skywriting company.? ?Steven | `\ Wright | _o__) | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:21:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:21:07 GMT Subject: __file__ access extremely slow References: Message-ID: On Thu, 04 Jun 2009 18:24:48 -0700, Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. How do you know? What are you using to time it? [...] > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section takes > 0.5sec. Total module count is ~800. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > try: > path = module.__file__ > except (AttributeError, ImportError): > return > ################################ You corrected this to: for module in sys.modules.itervalues(): try: path = module.__file__ except (AttributeError, ImportError): return (1) You're not importing anything inside the try block. Why do you think ImportError could be raised? (2) This will stop processing on the first object in sys.modules that doesn't have a __file__ attribute. Since these objects aren't *guaranteed* to be modules, this is a subtle bug waiting to bite you. -- Steven From benjamin.kaplan at case.edu Thu Jun 4 22:28:13 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 4 Jun 2009 22:28:13 -0400 Subject: Yet another unicode WTF In-Reply-To: <87eitzmo2k.fsf@benfinney.id.au> References: <87eitzmo2k.fsf@benfinney.id.au> Message-ID: On Thu, Jun 4, 2009 at 10:06 PM, Ben Finney > wrote: > Ron Garret writes: > > > Python 2.6.2 on OS X 10.5.7: > > > > [ron at mickey:~]$ echo $LANG > > en_US.UTF-8 > > [ron at mickey:~]$ cat frob.py > > #!/usr/bin/env python > > print u'\u03BB' > > > > [ron at mickey:~]$ ./frob.py > > ? > > [ron at mickey:~]$ ./frob.py > foo > > Traceback (most recent call last): > > File "./frob.py", line 2, in > > print u'\u03BB' > > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > > position 0: ordinal not in range(128) > > I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's > certainly not desirable; the terminal, the shell, and the filesystem are > all using UTF-8 so it should work fine. > > You might be best advised to report this as a bug to the Python bug > tracker . > Please don't. This isn't a bug- it's actually a good default. If the user doesn't specify an encoding, Python refuses to guess. In the case of the terminal, python doesn't have to guess because the environment variables give the encoding. When it's writing to a file, there is no way to know what encoding to use so it just sticks with ascii. > > -- > \ ?I fly Air Bizarre. You buy a combination one-way round-trip | > `\ ticket. Leave any Monday, and they bring you back the previous | > _o__) Friday. That way you still have the weekend.? ?Steven Wright | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Thu Jun 4 22:31:12 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 19:31:12 -0700 Subject: import _sqlite3 no module named error References: <77e831100906040708l1a8bf638n19bbff05607b3d4a@mail.gmail.com> <77e831100906041151g70868dbre1546cdb01082ba3@mail.gmail.com> <77e831100906041718k4b4f54d9v29729449c50f3cb@mail.gmail.com> Message-ID: In article <77e831100906041718k4b4f54d9v29729449c50f3cb at mail.gmail.com>, Vincent Davis wrote: > On Thu, Jun 4, 2009 at 1:41 PM, Ned Deily wrote: >[...] > > $ /opt/local/bin/python2.5 > > Python 2.5.4 (r254:67916, May ?4 2009, 01:40:08) > > [GCC 4.0.1 (Apple Inc. build 5490)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > >>>> from _sqlite3 import * > >>>> >[...] > Also 10.5.7 my self, I have completely removed and reinstall macport > and all the ports. All befor posting this thread... > > here is what i get, jhgfjhgfjhg it is working now, I have no clue. I > went on a bike ride and now it works? Thanks for you help. Good. Wish I could claim to have magic powers that made it all work. > What do you know about python_select, .bash_profile and .profile? python_select is a shell script to manage multiple versions of MacPorts-supplied pythons. MacPorts allows you to install multiple versions of python, say python2.4 and python2.5. With python_select, you can select which version will be invoked by default, i.e. by /opt/local/bin/python. It does this by creating the proper symlinks within /opt/local which is the directory sub-tree containing MacPorts-installed files. There is more information in its man page. Things get even more complicated with python.org-installed pythons, each version of which has its own bin directory within a framework and which may have symlinks to it from /usr/local/bin. .bash_profile and .profile are two of the various startup files read by the various shells out there. In general, when dealing with multiple versions of the same command name, you can add commands to the appropriate shell startup files to modify the value of the PATH environment variable, which is what specifies the search path for commands. For example, if /opt/local/bin comes before /usr/bin in $PATH, the command "python" will invoke the MacPorts default python rather than the Apple-supplied python. PATH and shell startup files are all garden-variety Unix-y topics; there is plenty of info about them out there on the web. Another way to deal with multiple versions is to avoid ambiguity by always specifying the absolute path to the desired python, as in my earlier example above. There are other tactics, too, like defining shell aliases. Of course, each approach has its pluses and minuses. Hope that helps. -- Ned Deily, nad at acm.org From gagsl-py2 at yahoo.com.ar Thu Jun 4 22:33:52 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Jun 2009 23:33:52 -0300 Subject: __file__ access extremely slow References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: En Thu, 04 Jun 2009 22:24:48 -0300, Zac Burns escribi?: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > Code: [fixed] > ################################ > for module in sys.modules.itervalues(): > try: > path = module.__file__ > except (AttributeError, ImportError): > return > ################################> __file__ is just an instance attribute of module objects. Although a custom importer *might* define a special module type which *could* use a special computed attribute, I doubt so... module.__file__ just returns a string, when it exists. Built-in modules have no __file__ attribute set, and some entries in sys.modules may be set to None. These should be the only exceptions. > The calculation appears to be cached though, so a subsequent check > does not take very long. > From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. Are you sure you posted the actual code? That "return" statement would stop the iteration as soon as it hits a builtin module, or a None flag. I'd say the time is spent somewhere else, or you're misinterpreting your results. BTW, what's the point of all this? -- Gabriel Genellina From michele.simionato at gmail.com Thu Jun 4 22:35:59 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Jun 2009 19:35:59 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> Message-ID: <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> On Jun 5, 1:18?am, Carl Banks wrote: > It's really the only sane way to handle it, odd though it may seem in > this narrow case. ?In Python nested functions have to be able to > reference the current value of a variable because of use cases like > this: > > def func(): > ? ? def printx(): > ? ? ? ? print x > ? ? x = 1 > ? ? printx() > ? ? x = 2 > ? ? printx() > > Referencing a nonlocal variable always uses the current (or last) > value of that variable, not the value it had when the nested function > was defined. This is not a good argument. Counter example: Scheme works exactly like Python (define (func) (define x 1) (define (printx) (display x) (newline)) (printx) (set! x 2) (printx)) ;; prints 1 and 2 but it is still possible to have a list comprehension working as the OP wants: (list-of (lambda () i) (i in (range 11 16))) Actually, in Scheme one would have to fight to define a list comprehension (more in general loops) working as in Python: the natural definition works as the OP wants. See http://www.artima.com/weblogs/viewpost.jsp?thread=251156 and the comments below for the details. From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:36:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:36:13 GMT Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote: > Let's say I have a list of 5 files. Now lets say that one of the files > reads nude333.txt instead of nude3.txt. When this happens, the program > generates an error and quits. What I want it to do is just skip over the > bad file and continue on with the next one. This should give you some hints. import errno for name in list_of_file_names: try: f = open(name, 'r') except IOError, e: if e.errno == errno.ENOENT: # or just use 2 if you're lazy # no such file, skip continue # some other more serious error, re-raise the exception raise do_something_with(f) [...] > def scroll_some_porn(now): > while 1: > for some_titty_porn in my_porn_collection: > now.write(" \n") > bitch_please = generate(some_titty_porn) > now.write(bitch_please) > time.sleep(10) > now.write(" \n") Shouldn't you have some way of escaping from the infinite loop other than typing Ctrl-C at the console? I imagine your hands will be busy. -- Steven From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 22:40:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 02:40:01 GMT Subject: __file__ access extremely slow References: Message-ID: On Fri, 05 Jun 2009 02:21:07 +0000, Steven D'Aprano wrote: > You corrected this to: > > for module in sys.modules.itervalues(): > try: > path = module.__file__ > except (AttributeError, ImportError): > return > > (1) You're not importing anything inside the try block. Why do you think > ImportError could be raised? > > (2) This will stop processing on the first object in sys.modules that > doesn't have a __file__ attribute. Since these objects aren't > *guaranteed* to be modules, this is a subtle bug waiting to bite you. In fact, not all modules have a __file__ attribute. >>> import errno >>> errno.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute '__file__' -- Steven From rcdailey at gmail.com Thu Jun 4 22:42:29 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Thu, 4 Jun 2009 19:42:29 -0700 (PDT) Subject: urlretrieve() failing on me Message-ID: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Hey guys, try using urlretrieve() in Python 3.0.1 on the following URL: http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip Have it save the ZIP to any destination directory. For me, this only downloads about 40KB before it stops without any error at all. Any reason why this isn't working? From tjreedy at udel.edu Thu Jun 4 22:53:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Jun 2009 22:53:37 -0400 Subject: __file__ access extremely slow In-Reply-To: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> References: <333edbe80906041824i77e9a388r65537ef8323a17f4@mail.gmail.com> Message-ID: Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startup time. > Given that many modules are complicated and even have dynamic > population this figure seems very high to me. it would seem very high > if one just considered the time it would take to load the pyc files > off the disk vs... whatever happens when module.__file__ happens. > > The calculation appears to be cached though, so a subsequent check > does not take very long. > >>From once python starts and loads the main module to after all the > imports occur and this section executes takes 1.3sec. This section > takes 0.5sec. Total module count is ~800. Perhaps some of the modules use a delayed import mechanism. > > Python version is 2.5.1 > > Code: > ################################ > for module in sys.modules: > try: > path = module.__file__ > except (AttributeError, ImportError): > return If any modules lack the attribute, you will not scan them all. Perhaps you meant 'continue'? > ################################ > > > > -- > Zachary Burns > (407)590-4814 > Aim - Zac256FL > Production Engineer (Digital Overlord) > Zindagi Games From nad at acm.org Thu Jun 4 22:56:17 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 19:56:17 -0700 Subject: Yet another unicode WTF References: Message-ID: In article , Ron Garret wrote: > Python 2.6.2 on OS X 10.5.7: > > [ron at mickey:~]$ echo $LANG > en_US.UTF-8 > [ron at mickey:~]$ cat frob.py > #!/usr/bin/env python > print u'\u03BB' > > [ron at mickey:~]$ ./frob.py > ? > [ron at mickey:~]$ ./frob.py > foo > Traceback (most recent call last): > File "./frob.py", line 2, in > print u'\u03BB' > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in > position 0: ordinal not in range(128) > > > (That's supposed to be a small greek lambda, but I'm using a > brain-damaged news reader that won't let me set the character encoding. > It shows up correctly in my terminal.) > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. > > Clues appreciated. Thanks. $ python2.6 -c 'import sys; print sys.stdout.encoding, \ sys.stdout.isatty()' UTF-8 True $ python2.6 -c 'import sys; print sys.stdout.encoding, \ sys.stdout.isatty()' > foo ; cat foo None False -- Ned Deily, nad at acm.org From aahz at pythoncraft.com Thu Jun 4 23:00:26 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 20:00:26 -0700 Subject: Feedparser problem References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: In article <89d21aec-5d39-4d1f-91b9-776da3506145 at i6g2000yqj.googlegroups.com>, Jonathan Nelson wrote: > >I'm trying to add a feedreader element to my django project. I'm >using Mark Pilgrim's great feedparser library. I've used it before >without any problems. I'm getting a TypeError I can't figure out. >I've tried searching google, bing, google groups to no avail. > >Here's the dpaste of what I'm trying to do and the result I'm >getting: > >http://dpaste.com/51406/ You're lucky that I felt like taking a look -- that's short enough you should have just posted it here. Anyway, that's pretty clearly not a firewall issue, and the only thing I can think of to figure it out given the lack of a real traceback is to poke around in the feedparser internals. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From cdalten at gmail.com Thu Jun 4 23:10:50 2009 From: cdalten at gmail.com (chad) Date: Thu, 4 Jun 2009 20:10:50 -0700 (PDT) Subject: How do I continue after the error? References: <4dc14c43-a271-4754-8210-1f637f7eda6e@u10g2000vbd.googlegroups.com> Message-ID: <571b6d7e-c9cb-4fcd-9977-38f47aeccf19@o18g2000yqi.googlegroups.com> On Jun 4, 7:36?pm, Steven D'Aprano wrote: > On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote: > > Let's say I have a list of 5 files. Now lets say that one of the files > > reads nude333.txt instead of nude3.txt. When this happens, the program > > generates an error and quits. What I want it to do is just skip over the > > bad file and continue on with the next one. > > This should give you some hints. > > import errno > > for name in list_of_file_names: > ? ? try: > ? ? ? ? f = open(name, 'r') > ? ? except IOError, e: > ? ? ? ? if e.errno == errno.ENOENT: ?# or just use 2 if you're lazy > ? ? ? ? ? ? # no such file, skip > ? ? ? ? ? ? continue > ? ? ? ? # some other more serious error, re-raise the exception > ? ? ? ? raise > ? ? do_something_with(f) > > [...] > > > def scroll_some_porn(now): > > ? ? while 1: > > ? ? ? ? for some_titty_porn in my_porn_collection: > > ? ? ? ? ? ? now.write(" \n") > > ? ? ? ? ? ? bitch_please = generate(some_titty_porn) > > ? ? ? ? ? ? now.write(bitch_please) > > ? ? ? ? ? ? time.sleep(10) > > ? ? ? ? ? ? now.write(" \n") > > Shouldn't you have some way of escaping from the infinite loop other than > typing Ctrl-C at the console? I imagine your hands will be busy. > Like what? All the program is meant to do is scroll ASCII art in a chat room. From sjmachin at lexicon.net Thu Jun 4 23:12:25 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 5 Jun 2009 03:12:25 +0000 (UTC) Subject: =?utf-8?b?X19maWxlX18=?= access extremely slow References: Message-ID: Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes: > > On Fri, 05 Jun 2009 02:21:07 +0000, Steven D'Aprano wrote: > > > You corrected this to: > > > > for module in sys.modules.itervalues(): > > try: > > path = module.__file__ > > except (AttributeError, ImportError): > > return > > > > (1) You're not importing anything inside the try block. Why do you think > > ImportError could be raised? > > > > (2) This will stop processing on the first object in sys.modules that > > doesn't have a __file__ attribute. Since these objects aren't > > *guaranteed* to be modules, Definitely not guaranteed to be modules. Python itself drops non-modules in there! Python 2.3 introduced four keys mapped to None -- one of these was dropped in 2.4, but the other three are still there in 2.5 and 2.6: C:\junk>\python23\python -c "import sys; print [k for (k, v) in sys.modules.items() if v is None]" ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', 'encodings.types'] C:\junk>\python24\python -c "import sys; print [k for (k, v) in sys.modules.items() if v is None]" ['encodings.codecs', 'encodings.exceptions', 'encodings.types'] > this is a subtle bug waiting to bite you. > > In fact, not all modules have a __file__ attribute. > > >>> import errno > >>> errno.__file__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute '__file__' Yep, none of the built-in modules has a __file__ attribute. So, as already pointed out, the loop is likely to stop rather early, making the huge 0.5 seconds look even more suspicious. Looking forward to seeing the OP's timing code plus a count of the actual number of loop gyrations ... Cheers, John From vincent at vincentdavis.net Thu Jun 4 23:12:43 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 4 Jun 2009 21:12:43 -0600 Subject: How to develop a python application? Message-ID: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> This might be a off topic but this also seemed like a good place to ask. I have an application (several) I would like to develop. Parts of it I can do but parts I would like to outsource. I am thinking mostly of outsourcing most of my django (or similar) work and otherwise have some custom classes written. I would like to do this small bits (that is the out sourcing) at a time for many reasons but I realize there are down sides to doing this (I probably don't know all them) I have a this specific project in mind but don't mind this topic being rather broad. I would like to read and learn more about developing software (commercial or open source) My questions How do I find programs interested in small projects. How do they expect to be paid or how should I pay. Are sites like elance.com good? What do I not know to ask? That is what should I be considering? Any suggestions would be appreciated. Very brief description of the project. The app would take GPS, Heartrate, Power(bicycle) data from a Garmin GPS and other devises and upload it to a database. After that I have several calculations and analysis of the data. Then display graphs and other statistics. This is a very brief explanation. There are several examples of similar python projects, but not web based. Granola pygarmin garmin-sync The closest web based example would be Training Peaks http://home.trainingpeaks.com/personal-edition/training-log-and-food-diary.aspx Thanks Vincent Davis 720-301-3003 From steven at REMOVE.THIS.cybersource.com.au Thu Jun 4 23:25:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 03:25:16 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 09:47:05 -0700, Mensanator wrote: > After all, everybody knows that for m items taken n at a time, the > counts are > > perm w/repl = m**n > comb w/repl = (m+n-1)!/(n!(m-1)!) > perm wo/repl = m!/(m-n)! > comb wo/repl = m!/(n!(m-n)!) "Everybody" knows? Be careful with those sweeping generalizations. Combinatorics is a fairly specialized area not just of programming but mathematics as well. I've done a spot poll of four developers here (two juniors and two seniors) and *not one* could give all four formulae correctly first go. One guy didn't recognize the terms (although on being reminded, he got two of the four formula). Another one, a self-professed maths-geek, worked them out from first principles. -- Steven From brian at sweetapp.com Thu Jun 4 23:25:47 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 04 Jun 2009 20:25:47 -0700 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: <4A28903B.4020301@sweetapp.com> Scott David Daniels wrote: [snipped] > When you evaluate a lambda expression, the default args are evaluated, > but the expression inside the lambda body is not. When you apply that > evaluated lambda expression, the expression inside the lambda body is > is evaluated and returned. But that's not really the issue. I knew that the lambda was not evaluated but thought each generator expression got its own context rather than sharing one. Taken in isolation, having one context per expression has more compelling semantics but it is inconsistent with the obvious transliteration of the generator into a loop. Cheers, Brian From ben+python at benfinney.id.au Thu Jun 4 23:31:13 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 13:31:13 +1000 Subject: Yet another unicode WTF References: Message-ID: <8763fbmk5a.fsf@benfinney.id.au> Ned Deily writes: > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > sys.stdout.isatty()' > UTF-8 True > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > sys.stdout.isatty()' > foo ; cat foo > None False So shouldn't the second case also detect UTF-8? The filesystem knows it's UTF-8, the shell knows it too. Why doesn't Python know it? -- \ ?When I was born I was so surprised I couldn't talk for a year | `\ and a half.? ?Gracie Allen | _o__) | Ben Finney From davea at ieee.org Thu Jun 4 23:56:33 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Jun 2009 23:56:33 -0400 Subject: Project source code layout? In-Reply-To: References: Message-ID: <4A289771.1050009@ieee.org> Lawrence D'Oliveiro wrote: > In message , Allen > Fowler wrote: > > >> 1) Do you use virtualpython? >> > > No idea what that is. > > >> 2) How do you load the modules in your lib directory? >> > > At the beginning of my scripts, I have a sequence like > > test_mode = False # True for testing, False for production > > if test_mode : > home_dir = "/home/shop-test" > else : > home_dir = "/home/shop" > #end if > > sys.path.append(home_dir + "/lib") > > import common > [etc] > > I have an installation script that looks for that "test_mode = True/False" > assignment and edits it accordingly. That flag is used to select the top- > level directory (as above) as well as the database name, etc. This allows me > to run two complete parallel sets of code and data, so I can mess around > with the testing version without impacting the production system. > > >> 3) How do you reference your configuration directives from within your >> modules and CGI/daemon scripts? >> > > For my last project using the above system, I used XML as the config file > format. > > > Rather than editing the source files at install time, consider just using an environment variable in your testing environment, which would be missing in production environment. Each command shell has its own set of environment variables, so this would make testing pretty easy, without the risk of things getting out of synch. Alternatively, if the script is located in a fixed place, relative to the home directory, just do some manipulation of the __file__ string. From davea at ieee.org Fri Jun 5 00:06:38 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 05 Jun 2009 00:06:38 -0400 Subject: Odd closure issue for generators In-Reply-To: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> Message-ID: <4A2899CE.1060809@ieee.org> Carl Banks wrote: > > > The way to handle the issue you are seeing is to create a new scope > with a variable the remains at the value you want to close upon: > > create_const_function(value): > def func(): > return value > c =create_const_function(i) for i in range(11, 16)) > > Or you can do it the slacker way and use a default argument: > > c =lambda i=i: i for i in range(11, 16)) > > > Carl Banks > > I agree with most of what you say, but I think you missed the last line of the function: create_const_function(value): def func(): return value return func From no.email at please.post Fri Jun 5 00:07:19 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 04:07:19 +0000 (UTC) Subject: how to iterate over several lists? Message-ID: Suppose I have two lists, list_a and list_b, and I want to iterate over both as if they were a single list. E.g. I could write: for x in list_a: foo(x) for x in list_b: foo(x) But is there a less cumbersome way to achieve this? I'm thinking of something in the same vein as Perl's: for $x in (@list_a, @list_b) { foo($x); } TIA! kynn -- From clp2 at rebertia.com Fri Jun 5 00:13:18 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Jun 2009 21:13:18 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <50697b2c0906042113x2e6355afm382cc8d5a11e3d22@mail.gmail.com> On Thu, Jun 4, 2009 at 9:07 PM, kj wrote: > > > Suppose I have two lists, list_a and list_b, and I want to iterate > over both as if they were a single list. ?E.g. I could write: > > for x in list_a: > ? ?foo(x) > for x in list_b: > ? ?foo(x) > > But is there a less cumbersome way to achieve this? ?I'm thinking > of something in the same vein as Perl's: > > for $x in (@list_a, @list_b) { > ?foo($x); > } Just add the lists together. for x in list_a + list_b: foo(x) Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Fri Jun 5 00:28:26 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 04:28:26 GMT Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <4A245810.4090704@mrabarnett.plus.com> <02345e3a$0$8244$c3e8da3@news.astraweb.com> <0234781f$0$8244$c3e8da3@news.astraweb.com> <4A257C6C.4080502@gmail.com> Message-ID: On Wed, 03 Jun 2009 01:00:15 +0200, Stef Mientki wrote: > Sorry, > but I realy don't understand the difference between the documents on my > desk and a python file in a subpath. Let's say you have a file called "parrot", containing some arbitrary data. You read it with open('parrot').read(), and then you can do anything you want with the data inside: If the data is a JPEG image, you can pass the data to a graphics program and display it. If the data is plain text, you can manipulate the text. If the data is Perl code, you can pass it to the Perl interpreter and run it. And if the data is Python code, you can call "exec data" and execute it. execfile() does just that. It doesn't care that the file name you pass is "myfile.py" instead of "parrot" -- it's just a file. You could call it "flooble.TIFF" and it wouldn't care: >>> open('flooble.TIFF', 'w').write('print "FLOOBLE!!!"\n') >>> execfile('flooble.TIFF') FLOOBLE!!! On the other hand, modules are special. A module is an actual Python data type, like str, int, list and so forth, on more complex. All sorts of magic takes place when you say "import module_name". The most important is that, unlike execfile, an actual module object is created, complete with __file__ and __name__ attributes. (Usually -- built-in modules don't have a __file__ attribute.) If you don't go through the import mechanism, you don't get a module. -- Steven From ben+python at benfinney.id.au Fri Jun 5 00:30:05 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 14:30:05 +1000 Subject: how to iterate over several lists? References: Message-ID: <871vpzmhf6.fsf@benfinney.id.au> Chris Rebert writes: > On Thu, Jun 4, 2009 at 9:07 PM, kj wrote: > > > > > > Suppose I have two lists, list_a and list_b, and I want to iterate > > over both as if they were a single list. [?] > Just add the lists together. > > for x in list_a + list_b: > foo(x) Which, more precisely, creates a *new* list as the concatenation of the two existing lists. -- \ ?A good politician is quite as unthinkable as an honest | `\ burglar.? ?Henry L. Mencken | _o__) | Ben Finney From no.email at please.post Fri Jun 5 00:31:24 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 04:31:24 +0000 (UTC) Subject: how to iterate over several lists? References: Message-ID: In Chris Rebert writes: >Just add the lists together. >for x in list_a + list_b: > foo(x) Cool! Thanks! kynn -- From metolone+gmane at gmail.com Fri Jun 5 00:35:12 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 4 Jun 2009 21:35:12 -0700 Subject: import sqlite3 References: Message-ID: "willgun" wrote in message news:h08c5e$aub$1 at news.cn99.com... > By the way ,what does 'best regards' means at the end of a mail? I think ?? may be a good translation. -Mark From gallium.arsenide at gmail.com Fri Jun 5 00:36:05 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Thu, 4 Jun 2009 21:36:05 -0700 (PDT) Subject: Printing list/tuple elements on separate lines References: Message-ID: On Jun 4, 8:37?pm, Johnny Chang wrote: > I have a large list of strings that I am unpacking > and splitting, and I want each one to be on a new line. > > An example: > > recs = > 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' > [(rec.split('f')) for rec in recs] > > output: > > [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', > 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] > > desired output: > > [['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', '']] Your friend may have used pprint: >>> from pprint import pprint >>> pprint(recs) [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] John From fetchinson at googlemail.com Fri Jun 5 00:44:07 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 4 Jun 2009 21:44:07 -0700 Subject: Printing list/tuple elements on separate lines In-Reply-To: References: Message-ID: >> I have a large list of strings that I am unpacking >> and splitting, and I want each one to be on a new line. >> >> An example: >> >> recs = >> 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' >> [(rec.split('f')) for rec in recs] >> >> output: >> >> [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', >> 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] >> >> desired output: >> >> [['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', '']] By slightly modifying your requirements this might be good too: print '\n'.join( [ 'aaaaaa', 'bbbbbbb', 'cccccccc', 'dddddddd', 'eeeeeeee' ] ) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From aahz at pythoncraft.com Fri Jun 5 00:49:15 2009 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2009 21:49:15 -0700 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: In article <05937a34-5490-4b31-9f07-a319b44ddb09 at r33g2000yqn.googlegroups.com>, Michele Simionato wrote: > >Actually, in Scheme one would have to fight to define >a list comprehension (more in general loops) working as >in Python: the natural definition works as the OP wants. See >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156 and the >comments below for the details. This URL isn't working for me, gives 500. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From stefan_ml at behnel.de Fri Jun 5 00:52:57 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 05 Jun 2009 06:52:57 +0200 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <4a28a4a9$0$31340$9b4e6d93@newsspool4.arcor-online.net> kj wrote: > Suppose I have two lists, list_a and list_b, and I want to iterate > over both as if they were a single list. E.g. I could write: > > for x in list_a: > foo(x) > for x in list_b: > foo(x) > > But is there a less cumbersome way to achieve this? Take a look at the itertools module, especially itertools.chain(). Stefan From ldo at geek-central.gen.new_zealand Fri Jun 5 01:47:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:47:53 +1200 Subject: Project source code layout? References: Message-ID: In message , Dave Angel wrote: > Rather than editing the source files at install time, consider just > using an environment variable in your testing environment, which would > be missing in production environment. I'd still need to define that environment variable in a wrapper script, which means editing that script at install time ... back to square one ... From ldo at geek-central.gen.new_zealand Fri Jun 5 01:50:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:50:17 +1200 Subject: Yet another unicode WTF References: Message-ID: In message , Gabriel Genellina wrote: > Python knows the terminal encoding (or at least can make a good guess), > but a file may use *any* encoding you want, completely unrelated to your > terminal settings. It should still respect your localization settings, though. From ldo at geek-central.gen.new_zealand Fri Jun 5 01:51:49 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:51:49 +1200 Subject: python way to automate IE8's File Download dialog References: <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3@n4g2000vba.googlegroups.com> Message-ID: In message <4f4f3e86-170a-4ad9-934d-4fa5b7d238b3 at n4g2000vba.googlegroups.com>, monogeo wrote: > I am able to use PAMIE 2.0 to automate IE7's File Download dialog, but > the same approach/code fails on IE8. I don't understand why you need to automate a GUI front-end, meant for human use, to a function that can be directly performed without that front-end anyway. From ldo at geek-central.gen.new_zealand Fri Jun 5 01:52:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 17:52:42 +1200 Subject: Project source code layout? References: Message-ID: In message , Jean-Paul Calderone wrote: > On Thu, 04 Jun 2009 21:33:13 +1200, Lawrence D'Oliveiro > wrote: > >>In message , Allen >>Fowler wrote: >> >>> I was hoping to keep the dev layout as close to deployment possible. >> >>Completely different purposes. For example, the actual production database >>and config files form no part of your development project, do they? And >>conversely, utility scripts that might be used, for example, to set up a >>database, should not be part of the production installation. > > If you don't use the "utility scripts" in your development environment, > how do you know they work with the code you're developing? Because they're used during development. From theller at python.net Fri Jun 5 01:54:10 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 07:54:10 +0200 Subject: ctype question In-Reply-To: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> References: <9f22c4b5-1f1c-4f26-9758-44330151e9b0@j18g2000yql.googlegroups.com> Message-ID: <78rq82F1mu5vtU1@mid.individual.net> Amit Gupta schrieb: > Hi, > > I have been using ctype.cdll to load a library, but I am unable to > figure out how to load multiple libraries that depends on each other. > E.g. I have two libraries A.so and B.so. A.so has some undefined > references, and those symbols are defined in B.so. > > When I try to load ctypes.cdll.LoadLibrary("A.so"), it gives errors > about the undefined Symbols. Even if I load B.so before loading A.so, > the error remains the same (which is expected). Can someone help me to > find out, how to load A.so by telling it to look for undefined symbols > in B.so as well? You could try to pass ctypes.RTLD_GLOBAL as the 'mode' parameter to ctypes.CDLL when you load the library. Thomas From nad at acm.org Fri Jun 5 01:58:13 2009 From: nad at acm.org (Ned Deily) Date: Thu, 04 Jun 2009 22:58:13 -0700 Subject: Odd closure issue for generators References: <4A28903B.4020301@sweetapp.com> Message-ID: In article <4A28903B.4020301 at sweetapp.com>, Brian Quinlan wrote: > Scott David Daniels wrote: > [snipped] > > When you evaluate a lambda expression, the default args are evaluated, > > but the expression inside the lambda body is not. When you apply that > > evaluated lambda expression, the expression inside the lambda body is > > is evaluated and returned. > > But that's not really the issue. I knew that the lambda was not > evaluated but thought each generator expression got its own context > rather than sharing one. Each? Maybe that's a source of confusion. There is only one generator expression in your example. >>> c = (lambda : i for i in range(11, 16)) >>> c at 0x114e90> >>> d = list(c) >>> d [ at 0x119348>, at 0x119390>, at 0x1193d8>, at 0x119420>, at 0x119468>] -- Ned Deily, nad at acm.org From xahlee at gmail.com Fri Jun 5 02:07:39 2009 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Jun 2009 23:07:39 -0700 (PDT) Subject: The Complexity And Tedium of Software Engineering References: Message-ID: On Jun 3, 11:50 pm, Xah Lee wrote: > Of interest: > ? The Complexity And Tedium of Software Engineering > http://xahlee.org/UnixResource_dir/writ/programer_frustration.html Addendum: The point in these short examples is not about software bugs or problems. It illustrates, how seemingly trivial problems, such as networking, transferring files, running a app on Mac or Windwos, upgrading a app, often involves a lot subtle complexities. For mom and pop users, it simply stop them dead. For a senior industrial programer, it means some conceptually 10-minutes task often ends up in hours of tedium. In some ?theoretical? sense, all these problems are non-problems. But in practice, these are real, non-trivial problems. These are complexities that forms a major, multi-discipline, almost unexplored area of software research. I'm trying to think of a name that categorize this issue. I think it is a mix of software interface, version control, release control, formal software specification, automated upgrade system, etc. The ultimate scenario is that, if one needs to transfer files from one machine to another, one really should just press a button and expect everything to work. Software upgrade should be all automatic behind the scenes, to the degree that users really don't need fucking to know what so-called ?version? of software he is using. Today, with so-called ?exponential? scientific progress, and software has progress tremendously too. In our context, that means there are a huge proliferation of protocols and standards. For example, unicode, gazillion networking related protocols, version control systems, automatic update technologies, all comes into play here. However, in terms of the above visionary ideal, these are only the beginning. There needs to be more protocols, standards, specifications, and more strict ones, and unified ones, for the ideal scenario to take place. Xah ? http://xahlee.org/ ? On Jun 3, 11:50 pm, Xah Lee wrote: > Of interest: > ? The Complexity And Tedium of Software Engineering > http://xahlee.org/UnixResource_dir/writ/programer_frustration.html > > in particular, there are 2 issues with emacs that might be interesting > here. > > plain text version follows > -------------------------------------------------- > > The Complexity And Tedium of Software Engineering > > Xah Lee, 2009-06-02 > > This page is a blog of a experience of few examples that illustrates > some seemingly trivial task can become quite tedius and complicated in > the software industry. > > A Complexity with Emacs > > Discovered a emacs problem. > > Summary: > > ? Seems that emacs 23 will have a problem loading a css-mode written > by Stefan Monnier > > ? The css-mode.el file does not contain any sort of version number, > which makes the problem worse. > > Detail: I have a Mac running emacs 22 with OS X, and i have PC running > emacs 23 and Windows Vista. When i use the emacs 23 to load css mode, > it gives this error: ?if: Wrong type argument: integerp, (0 . 8)?. > > The problem seems simple in retrospect, but wasn't simple at all when > you trying to get things done and things don't work as expected. > Here's the story. > > Emacs 22 does not have a css mode, emacs 23 does. There's one css mode > written by Stefan. I've been using it on the Mac for the past couple > of years. The same package is now bundled into emacs 23, which i'm > using on PC. However, the code in the 2 files are not identical. I > have my emacs setup to load css mode. Since i am migrating to PC, > alone with my whole emacs system, and am setting up a Mac and PC and > network that'd let me work with either machine harmoniously. On the > PC, when i start css mode, it gives error, but not always. You don't > know what's wrong. It could be a fuckup in the emacs distro i'm using > on PC (which is emacsW32), or it could be emacs 23 problem (emacs 23 > is still in beta), or it could be something in my emacs customization > that works perfectly well on the Mac but not on the PC with whole new > environment. Eventually, i realized that's because sometimes i started > plain emacs 23 without loading my own setup, it was using the bundled > css mode, so no error, but when i loaded my own emacs setup, it gives > error. This seems still simple in retrospect, but wasn't then. I added > a version check to my emacs init file(s), so that if emacs is 23, > don't load my css mode. The next day, same symptom occurs. Eventually > I realized that's because the load path is set so that my own version > of css mode comes before the bundled css mode, so that, when i load > css, again my old version is loaded. Eventually, the solution is to > check if css mode bundled with emacsW32 runs ok on emacs 22 on my Mac; > if so, simply use that as the single source for my Mac and PC. When > doing this work on checking what versions are the files, i realized > that the 2 css mode's files don't contain version number at all. All > this takes 5 minutes to read, but was one of the gazillion seemingly > trivial issues and problems when setting my Mac/PC networking > environment with cygwin and all. This took me one week, and haven't > gotten to wholly converting my Mac files to PC. Added the time to > google for for the answer, possibly write a report to the emacsers, > etc, all in all, i'd say this problem caused me 4 hours. > > Here's the emacs version i'm using. On the Mac: ?GNU Emacs 22.2.1 > (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0) of 2008-04-05 on > g5.tokyo.stp.isas.jaxa.jp?. On Windows ?GNU Emacs 23.0.94.1 (i386- > mingw-nt6.0.6001) of 2009-05-28 on LENNART-69DE564 (patched)? > > -------------------------------------------------- > URL Encoding > > Discovered a subtle issue with automating url encoding. In url, if you > have the ampersand ?&? char, and if this url is to be inside a html > doc as a link, then, there's no automated procedure that determines > correctly whether the char should be encoded as ?%26? or ?&?. If > the char is used as part of the file name or path, then it should be > encoded as ?&?, but if it is used as a separator for CGI > parameters, then it should be encoded as ?%26?. > > The rule for Percent encoding the char is that the ampersand is a > reserved char, therefore it must be percent encoded if it is used for > normal file path names. So, when it is NOT used as part of path names, > but used as CGI parameter separaters, with GET method of HTTP request, > then it must be left as it is. Now, in html, the ampersand char must > be encoded as html entities ?&? when adjacent chars are not space > (basically). So, it becomes ?&?. > > In summary, if the url in html link contains ?&?, and the char is a > CGI param separator, then encode it to ?&?, else, encode it as > ?%26?, and my discovery is that the purpose of the char used in url > cannot be syntactically determined with 100% accuracy. > > Of course, in practice, all this matters shit. Just use ?&? plainly > and it all works in 99.999% of situations. > > -------------------------------------------------- > Unicode File Names > > Unison and Unicode File Names > > Summary: Unison does not support unicode chars. > > When using Unison version 2.27, to sync files from Mac to PC, the file > name on the mac is ???_flag.jpg?, it is copied to PC using Unison > 2.27, and the file name became ?????-?_flag.jpg? when viewed under > Windows, but the file name shows up correctly when viewed in EmacsW32. > > Mac version: 10.4.11, Windows Vista SP1. > > This may indicate that Unison encode file names in utf8, or just > ascii. Indeed, it is said on Wikipedia that unicode have problems with > non-ascii file names. > > When the file is copied from Mac to Windows or Windows to Mac, > operating either on Windows or Mac as the local machine, using either > OS's file manager, the file name is copied correctly. > > Setting up Unison itself is not so trivial. It is trivial in concept, > but actually took hours. I have Unison on my Mac installed, and use it > few times a year, since about 2006, so i'm familiar with it. On PC, > first you have to install cygwin. I know there are Unison binaries for > Windows but since i use cygwin, so my first choice is staying with > cygwin, since it contains the whole unix environment. Installing > cygwin is another story, but once you installed Unison in cygwin, and > tried to test sync my Mac and PC, you run into the problem that sshd > must be turned on in one of the machines. Namely, sshd should run on > the ?remote? machine. (setting up a local network among Win and Mac is > another complex and tedious story) Then, there's the issue of deciding > which machine you want sshd to run or both. On the Mac, i can turn on > sshd in a minute. On Windows, i'm not sure. I'm not sure if Windows > Vista home edition provide ssh server, and am not sure how to turn it > on if so. As far as i know, Windows Vista Home does not come with a > ssh client. In the process, also realize that firewall must be turned > off for ssh port. So, you spend 30 min or possibly hours (here and > there) reading or probing with Windows Firewall control panel and > whatnot other admin tools. After a while, i decided it's easier just > to turn on sshd on the Mac then Unison from the Windows side to the > Mac. At least, have this direction work first, and when that works, i > can play with the other direction. After all this done, i tried to > Unison, but Unison reports that the Unison version on my Mac and PC is > not the same, so it doesn't work. Geeze. The one on my Mac turns out > to be Unison 2.13.x, and the one i have in Cygwin is 2.31.x. Now, i > figured that with each release of Unison, it probably obsolete some > older versions. So, back to digging Unison docs and the web. The > simplest solution comes to mind is to update my Unison on my Mac to > latest, of which, the unison on fink haven't been updated for a couple > of years. I use Fink, and am fairly familiar with using Fink. However, > after ?fink selfupdate? etc, then ?fink desc Unison?, the version > there reported seems to be 2.13. Then, searching web on fink home page > indicates they have unisone-2.27.57-1007, for my OS 10.4 PowerPC. So, > why doesn't it show up in my fink? I remember i had a case last year > where fink had obsolete mirror databases, a fault entirely on their > end. After spending maybe some more 30 min, i decided to install > Unison from a website, binary download. After that done, i got Unison > 2.27.x on the Mac. I tried to sync again, still no go. So, it seems > like that the Unison version number must be the same or very close. > Checking on Unison website, it looks like the current stable release > is 2.27.x, so, my cygwin's 2.31.x is actually a beta. Damn. So, now > back to cygwin. Luckily, it appears there are several version of > Unison there to be installed, and i easily installed 2.27. Then, > finally, test sync is successful. Now, i go back to get my files ready > in a state to be synced. (long story there. See: Perl Script for > Removing Mac Resource Fork and Switching from Mac/Unix To PC/Windows ) > When finally i'm ready to Unison, then there's the Chinese character > problem! > > -------------------------------------------------- > Emacs on Windows and Unicode File Names > > When using emacsW32, dired has problem dealing with files with chinese > char on remote machine. Consequently, when trying to copy, delete, > etc, the behavior may be dangerous. > > e.g. i have this file ???.jpg on a Mac. I use emacsW32 on Windows to > view it thru network. (e.g. the path is //169.254.145.104/xah/ > web/ ... ) the file name shows up as ?_viu0y~a.jpg? in dired. > > ?GNU Emacs 23.0.94.1 (i386-mingw-nt6.0.6001) of 2009-05-28 on > LENNART-69DE564 (patched)?, Mac version: 10.4.11, Windows Vista SP1. > > Xah > ?http://xahlee.org/ > > ? From mensanator at aol.com Fri Jun 5 02:10:33 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Jun 2009 23:10:33 -0700 (PDT) Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Jun 4, 10:25?pm, Steven D'Aprano wrote: > On Thu, 04 Jun 2009 09:47:05 -0700, Mensanator wrote: > > After all, everybody knows that for m items taken n at a time, the > > counts are > > > perm ?w/repl = m**n > > comb ?w/repl = (m+n-1)!/(n!(m-1)!) > > perm wo/repl = m!/(m-n)! > > comb wo/repl = m!/(n!(m-n)!) > > "Everybody" knows? Be careful with those sweeping generalizations. > Combinatorics is a fairly specialized area not just of programming but > mathematics as well. I would expect that. That was supposed to be funny. :-) > > I've done a spot poll of four developers here (two juniors and two > seniors) and *not one* could give all four formulae correctly first go. > One guy didn't recognize the terms (although on being reminded, he got > two of the four formula). Another one, a self-professed maths-geek, > worked them out from first principles. I didn't know all of them either. I had to look them up in the source code of the combinatorics library I wrote for myself (I use that stuff a lot in my research). BTW, I really appreciate the links posted a while ago on how to search for text in .py files on Windows. Could not have found them otherwise. I must have a dozen copies of the module on each of 4 disks (two hard & 2 flash) but the comments containing those formulae was only in a single place. There was a subtle point. A function that would return such counts is fine - provided you don't have to actually count them! I'm sure Mr. Hettinger knows that. > > -- > Steven From ben+python at benfinney.id.au Fri Jun 5 02:11:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 16:11:54 +1000 Subject: Yet another unicode WTF References: Message-ID: <87skifky51.fsf@benfinney.id.au> "Gabriel Genellina" writes: > Python knows the terminal encoding (or at least can make a good > guess), but a file may use *any* encoding you want, completely > unrelated to your terminal settings. It may, yes, and the programmer is free to specify any encoding. > So when stdout is redirected, Python refuses to guess its encoding; But Python doesn't have to guess; the terminal encoding is as specified in either case, no? > see the PYTHONIOENCODING environment variable. For the standard streams, the specified terminal encoding available to every program makes the most sense ? certainly more sense than a Python-specific variable, or the ?default to ASCII? of the current behaviour. -- \ ?Holy uncanny photographic mental processes, Batman!? ?Robin | `\ | _o__) | Ben Finney From command.bbs at alexbbs.twbbs.org Fri Jun 5 02:16:06 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 05 Jun 2009 06:16:06 GMT Subject: how to create a big list of list Message-ID: <4gI9c7$wD1@alexbbs.twbbs.org> if i want to create a list of list which size is 2**25 how should i do it? i have try [ [] for x in xrange(2**25) ] but it take too long to initial the list is there any suggestion? Thanks a lot! -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From ldo at geek-central.gen.new_zealand Fri Jun 5 02:53:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 18:53:51 +1200 Subject: Odd closure issue for generators References: Message-ID: In message , Brian Quinlan wrote: > >>> c = (lambda : i for i in range(11, 16)) > >>> d = list(c) > >>> for q in d: > ... print(q()) > ... > 15 > 15 > 15 > 15 > 15 Try >>> c = ((lambda i : lambda : i)(i) for i in range(11, 16)) >>> d = list(c) >>> for q in d : ... print q() ... 11 12 13 14 15 From michele.simionato at gmail.com Fri Jun 5 02:55:32 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 4 Jun 2009 23:55:32 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <5539c26b-c39c-4ee2-88e6-5953ad21fe2b@r37g2000yqd.googlegroups.com> On Jun 5, 6:49?am, a... at pythoncraft.com (Aahz) wrote: > In article <05937a34-5490-4b31-9f07-a319b44dd... at r33g2000yqn.googlegroups.com>, > Michele Simionato ? wrote: > > > > >Actually, in Scheme one would have to fight to define > >a list comprehension (more in general loops) working as > >in Python: the natural definition works as the OP wants. See > >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156and the > >comments below for the details. > > This URL isn't working for me, gives 500. This happens sometimes with Artima. Usually it is just a matter of waiting a few minutes. From nad at acm.org Fri Jun 5 03:03:30 2009 From: nad at acm.org (Ned Deily) Date: Fri, 05 Jun 2009 00:03:30 -0700 Subject: Yet another unicode WTF References: <8763fbmk5a.fsf@benfinney.id.au> Message-ID: In article <8763fbmk5a.fsf at benfinney.id.au>, Ben Finney wrote: > Ned Deily writes: > > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > > sys.stdout.isatty()' > > UTF-8 True > > $ python2.6 -c 'import sys; print sys.stdout.encoding, \ > > sys.stdout.isatty()' > foo ; cat foo > > None False > > So shouldn't the second case also detect UTF-8? The filesystem knows > it's UTF-8, the shell knows it too. Why doesn't Python know it? The filesystem knows what is UTF-8? While the setting of the locale environment variables may influence how the file system interprets the *name* of a file, it has no direct influence on what the *contents* of a file is or is supposed to be. Remember in python 2.x, a file is a just sequence of bytes. If you want to write encode Unicode to the file, you need to use something like codecs.open to wrap the file object with the proper streamwriter encoder. What confuses matters in 2.x is the print statement's under-the-covers implicit Unicode encoding for files connected to a terminal: http://bugs.python.org/issue612627 http://bugs.python.org/issue4947 http://wiki.python.org/moin/PrintFails >>> x = u'\u0430\u0431\u0432' >>> print x [nice looking characters here] >>> sys.stdout.write(x) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> sys.stdout.encoding 'UTF-8' In python 3.x, of course, the encoding happens automatically but you still have to tell python, via the "encoding" argument to open, what the encoding of the file's content is (or accept python's default which may not be very useful): >>> open('foo1','w').encoding 'mac-roman' WTF, indeed. -- Ned Deily, nad at acm.org From michele.simionato at gmail.com Fri Jun 5 03:04:11 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 00:04:11 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> On Jun 5, 6:49?am, a... at pythoncraft.com (Aahz) wrote: > In article <05937a34-5490-4b31-9f07-a319b44dd... at r33g2000yqn.googlegroups.com>, > Michele Simionato ? wrote: > > > > >Actually, in Scheme one would have to fight to define > >a list comprehension (more in general loops) working as > >in Python: the natural definition works as the OP wants. See > >http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156and the > >comments below for the details. > > This URL isn't working for me, gives 500. Anyway, the point is that to explain Python behavior with closures in list/generator comprehension it is not enough to invoke late bindings (Scheme has late bindings too but list comprehension works differently). The crux is in the behavior of the for loop: in Python there is a single scope and the loop variable is *mutated* at each iteration, whereas in Scheme (or Haskell or any other functional language) a new scope is generated at each iteration and there is actually a new loop variable at each iteration: no mutation is involved. Common Lisp works like Python. It is a design decision which at the end comes down to personal preference and different languages make different choices with no clear cut winner (I personally prefer the more functional way). From mobiledreamers at gmail.com Fri Jun 5 03:16:42 2009 From: mobiledreamers at gmail.com (mobiledreamers at gmail.com) Date: Fri, 5 Jun 2009 00:16:42 -0700 Subject: unified way or cookbook to access cheetah from other frameworks django/webpy/pylons Message-ID: can you or tavis or one of the cheetah masters please show us how to use cheetah from webpy the only useful thing webpy cheetah.py does is replace the #include with the content of the files Can you share a simple snippet/cookbook example on how to hook up cheetah from other frameworks such as django/webpy/pylons, if there is a unified way to access the cheetah template then the problems will be easier to fix? Thanks a lot... for trying to help... -- Bidegg worlds best auction site http://bidegg.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Jun 5 03:22:30 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Jun 2009 09:22:30 +0200 Subject: Feedparser problem References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: Jonathan Nelson wrote: > I'm trying to add a feedreader element to my django project. I'm > using Mark Pilgrim's great feedparser library. I've used it before > without any problems. I'm getting a TypeError I can't figure out. > I've tried searching google, bing, google groups to no avail. > > Here's the dpaste of what I'm trying to do and the result I'm > getting: > >>>import feedparser > >>>url='http://feeds.nytimes.com/nyt/rss/Technology' > >>>d=feedparser.parse(url) > >>>d > {'bozo':1, > 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), > 'encoding': 'utf-8', > 'entries': [], > 'feed':{}, > 'version': None} > I've tried checking my firewall settings. I'm using Windows 7 and > Python 2.6. Win 7 is allowing other Python programs through. I've > tried several different RSS urls with the same result. > > Any thoughts would be greatly appreciated. Which version of feedparser are you using? In the 4.1 source 'timeout' occurs only in a comment. Peter From davea at ieee.org Fri Jun 5 03:29:59 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 05 Jun 2009 03:29:59 -0400 Subject: Project source code layout? In-Reply-To: References: Message-ID: <4A28C977.2040303@ieee.org> Lawrence D'Oliveiro wrote: > In message , Dave Angel > wrote: > > >> Rather than editing the source files at install time, consider just >> using an environment variable in your testing environment, which would >> be missing in production environment. >> > > I'd still need to define that environment variable in a wrapper script, > which means editing that script at install time ... back to square one ... > > > No, the whole point is it's an environment variable which is *missing" in production environment. Make sure you make it an obscure name, like set MyProductName_TestingMode=1 So the way you know you're in a production environment is that you do not have such an environment variable. From ldo at geek-central.gen.new_zealand Fri Jun 5 03:31:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 19:31:23 +1200 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> Message-ID: In message <78180b4c-68b2-4a0c-8594-50fb1ea2f414 at c19g2000yqc.googlegroups.com>, Michele Simionato wrote: > The crux is in the behavior of the for loop: > in Python there is a single scope and the loop variable is > *mutated* at each iteration, whereas in Scheme (or Haskell or any > other functional language) a new scope is generated at each > iteration and there is actually a new loop variable at each iteration: > no mutation is involved. I think it's a bad design decision to have the loop index be a variable that can be assigned to in the loop. From jpthing at online.no Fri Jun 5 03:32:05 2009 From: jpthing at online.no (John Thingstad) Date: Fri, 05 Jun 2009 09:32:05 +0200 Subject: The Complexity And Tedium of Software Engineering References: Message-ID: P? Fri, 05 Jun 2009 08:07:39 +0200, skrev Xah Lee : > On Jun 3, 11:50 pm, Xah Lee wrote: > The point in these short examples is not about software bugs or > problems. It illustrates, how seemingly trivial problems, such as > networking, transferring files, running a app on Mac or Windwos, > upgrading a app, often involves a lot subtle complexities. For mom and > pop users, it simply stop them dead. For a senior industrial > programer, it means some conceptually 10-minutes task often ends up in > hours of tedium. What on earth gave you the idea that this is a trivial problem? Networks have been researched and improved for the last 40 years! It is a marvel of modern engineering that they work as well as they do. > > In some ?theoretical? sense, all these problems are non-problems. But > in practice, these are real, non-trivial problems. These are > complexities that forms a major, multi-discipline, almost unexplored > area of software research. Again, it is it not a trivial problem theoretically. Unexplored? What world are you on? > I'm trying to think of a name that > categorize this issue. I think it is a mix of software interface, > version control, release control, formal software specification, > automated upgrade system, etc. The ultimate scenario is that, if one > needs to transfer files from one machine to another, one really should > just press a button and expect everything to work. Software upgrade > should be all automatic behind the scenes, to the degree that users > really don't need fucking to know what so-called ?version? of software > he is using. > Actually they mostly are. At least on my machine. (I use Windows XP and Ubuntu Linux.) > Today, with so-called ?exponential? scientific progress, and software > has progress tremendously too. In our context, that means there are a > huge proliferation of protocols and standards. For example, unicode, > gazillion networking related protocols, version control systems, > automatic update technologies, all comes into play here. However, in > terms of the above visionary ideal, these are only the beginning. > There needs to be more protocols, standards, specifications, and more > strict ones, and unified ones, for the ideal scenario to take place. > No, there are already to many protocols and the ideas of how a network infrastructure should be built are mostly in place. I think we would benefit from "cleaning up" the existing interface. That is by removing redundancy. What does need further research is distributed processing. Again this is a highly complex problem and a lot of work has been put into trying to make simpler and more manageable interfaces and protocol's. See for example the languages Erlang and Oz to get an idea. --------------------- John Thingstad From Eric_Dexter at msn.com Fri Jun 5 03:52:49 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 5 Jun 2009 00:52:49 -0700 (PDT) Subject: is anyone using text to speech to read python documentation References: <70f20cdd-e751-49ab-8e84-f620890ff2e4@x6g2000vbg.googlegroups.com> Message-ID: <758cd757-d63e-493c-b460-f9488751da76@r33g2000yqn.googlegroups.com> On Jun 3, 12:28?pm, Stef Mientki wrote: > Eric_Dex... at msn.com wrote: > > ? ? ?I wrote a small pre-processor for python documentation and I am > > looking for advice on how to get the most natural sounding reading. ?I > > uploaded an example of a reading of lxml documentation as a podcast1 > > >http://dexrow.blogspot.com/2009/06/python-voice-preprocessor.html. > > Depends what OS you want to use, on Windows it's very easy: > > import win32com.client ? ? ? ? ? ? ? ? ? ? ? ? ? > s = win32com.client.Dispatch("SAPI.SpVoice") ? ? > s.Speak('Is this punthoofd ') ? ? ? ? ? ? ? ? ? ? > > cheers, > Stef That is intresting and might be useful but isn't what I am doing. alot of the time you will see stuff like >>> that needs to be changed into other wording so you have one file that gets transformed into another text that makes more sense when read. I haven't changed html tags into something that makes more sense when spoken so my example is a little defective.... From theller at python.net Fri Jun 5 04:03:59 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 10:03:59 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78qnreF1nkqu7U1@mid.individual.net> <9839a05c0906041323u73cf625ahc33bd8f28f6f4f86@mail.gmail.com> Message-ID: <78s1rgF1narmcU1@mid.individual.net> Joseph Garvin schrieb: > On Thu, Jun 4, 2009 at 3:23 PM, Brian wrote: >> What is the goal of this conversation that goes above and beyond what >> Boost.Python + pygccxml achieve? > > I can't speak for others but the reason I was asking is because it's > nice to be able to define bindings from within python. At a minimum, > compiling bindings means a little extra complexity to address with > whatever build tools you're using. AFAIU, pybindgen takes this approach. And, AFAIK, pygccxml can generate pybindgen code. From jeremiah.dodds at gmail.com Fri Jun 5 04:25:50 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Fri, 5 Jun 2009 09:25:50 +0100 Subject: How to develop a python application? In-Reply-To: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> References: <77e831100906042012o6ffe621eob70c500b1778589a@mail.gmail.com> Message-ID: <12cbbbfc0906050125m570a0692waf299fb33456e465@mail.gmail.com> On Fri, Jun 5, 2009 at 4:12 AM, Vincent Davis wrote: > This might be a off topic but this also seemed like a good place to ask. > > I have an application (several) I would like to develop. Parts of it I > can do but parts I would like to outsource. I am thinking mostly of > outsourcing most of my django (or similar) work and otherwise have > some custom classes written. > I would like to do this small bits (that is the out sourcing) at a > time for many reasons but I realize there are down sides to doing this > (I probably don't know all them) > > I have a this specific project in mind but don't mind this topic being > rather broad. I would like to read and learn more about developing > software (commercial or open source) > > My questions > How do I find programs interested in small projects. > How do they expect to be paid or how should I pay. > Are sites like elance.com good? > What do I not know to ask? That is what should I be considering? > > Any suggestions would be appreciated. > > > > Very brief description of the project. > The app would take GPS, Heartrate, Power(bicycle) data from a Garmin > GPS and other devises and upload it to a database. After that I have > several calculations and analysis of the data. Then display graphs and > other statistics. This is a very brief explanation. > > There are several examples of similar python projects, but not web based. > Granola > pygarmin > garmin-sync > The closest web based example would be Training Peaks > > http://home.trainingpeaks.com/personal-edition/training-log-and-food-diary.aspx > > Thanks > Vincent Davis > 720-301-3003 > -- > http://mail.python.org/mailman/listinfo/python-list > With regards to sites like elance, I can only offer advice here from a coder's perspective, so I may be missing some things, but here goes: You can probably find people on elance or rentacoder, or similar sites to work on your app. You will need to be very careful about who you hire though - the sites are filled with incompetent coders, and bots that represent _teams_ of incompetent programmers. I used to do a good bit of work on sites like that, and a lot of my work was fixing apps that got written by other people on those sites that had no idea what they were doing. We're talking about 10,000 lines of PHP that got changed into ~2500 with simple, mostly automated refactoring because the people who wrote it had apparently never heard of a for loop. Payment is normally done through an escrow service. The price you're willing to pay generally gets decided on before work begins, and the people who want to work on it can make bids saying how much they want for the work, and you can talk to them - make sure they know what they're talking about, haggle price, etc. There tends to be protection for both the person paying and the person working to avoid you not paying them if they did what they were supposed to, and to avoid you having to pay them if they didn't. All in all, using sites like elance can get your work done, and it can get it done well and on the cheap - but you'll have to spend a significant amount of time weeding through automated responses and making sure you're getting the right person to work on your stuff. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Fri Jun 5 04:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 05 Jun 2009 03:29:41 -0500 Subject: What text editor is everyone using for Python References: <4A1C0806.2090802@seehart.com> <02345d7c$0$8244$c3e8da3@news.astraweb.com> <87r5xzmq3o.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Emile van Sebille writes: > > > On 6/4/2009 3:19 PM Lawrence D'Oliveiro said... > > > In message , Nick Craig- > > > Wood wrote: > > > > > >> You quit emacs with Ctrl-X Ctrl-C. > > > > > > That's "save-buffers-kill-emacs". If you don't want to save buffers, > > > the exit sequence is alt-tilde, f, e. > > This is an invocation of the menu system, driven by the keyboard. (Also, > it's not Alt+tilde (which would be Alt+Shift+`), it's Alt+` i.e. no > Shift.) It's an alternate command, and IMO is just adding confusion to > the discussion. Also, according to my emacs e==>Exit Emacs (C-x C-c) so Alt-` f e is exactly the same as Ctrl-x Ctrl-c anyway! If the OP really want to quit emacs without being prompted to save any buffes then run the 'kill-emacs' command which isn't bound to a key by default. You would do this with Alt-X kill-emacs But the fact that it isn't bound to a key by default means that it isn't recommended (and I've never used it in 10 years of using emacs!) - just use Ctrl-X Ctrl-C as Richard Stallman intended ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ben+python at benfinney.id.au Fri Jun 5 04:34:26 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 18:34:26 +1000 Subject: how to create a big list of list References: <4gI9c7$wD1@alexbbs.twbbs.org> Message-ID: <87k53rkrjh.fsf@benfinney.id.au> command.bbs at alexbbs.twbbs.org (???M???v???@????) writes: > if i want to create a list of list which size is 2**25 > > how should i do it? > > i have try [ [] for x in xrange(2**25) ] > > but it take too long to initial the list > > is there any suggestion? What is it you want to do with the result? If you want to lazy-evaluate the expression, what you're looking for is a generator. You can get one easily by writing a generator expression: >>> foo = ([] for x in xrange(2**25)) >>> foo >>> for item in foo: ... do_interesting_stuff_with(item) If what you want is to have a huge multi-dimensional array for numerical analysis, lists may not be the best option. Instead, install the third-party NumPy library and use its types. You don't show what kind of data you want in your array, but assuming you want integers initialised to zero: >>> import numpy >>> foo = numpy.zeros((2**25, 0), int) >>> foo array([], shape=(33554432, 0), dtype=int32) Other quick ways of constructing NumPy arrays exist, see . -- \ ?Prediction is very difficult, especially of the future.? | `\ ?Niels Bohr | _o__) | Ben Finney From gagsl-py2 at yahoo.com.ar Fri Jun 5 04:47:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 05:47:41 -0300 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey escribi?: > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > URL: > > http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip > > Have it save the ZIP to any destination directory. For me, this only > downloads about 40KB before it stops without any error at all. Any > reason why this isn't working? I could not reproduce it. I downloaded about 300K without error (Python 3.0.1 on Windows) -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 04:54:47 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 10:54:47 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <18983.64840.555702.403634@montanaro.dyndns.org> Message-ID: <002d01c9e5bf$aaead240$0d00a8c0@Hendrik> wrote: > Got some use cases? plural cases - no. I did it for the reason already described. to elucidate, the code looks something like this: rec = input_q.get() # <=== this has its origen in a socket, as a netstring. reclist = rec.split(',') if reclist[0] == 'A': do something with the outputs get hold of the latest inputs return the result by putting a message on the normal output q. continue # up to here this is the code that is done in 99.9999% of cases. # note that it has to run as fast as possible, in a very cripple processor. if reclist[0] == "B": # This means we have to change state, # it comes from another thread that did # not exist before an event. new_output_q = uncan(reclist[1]) # <== This is where it is used while True: do similar stuff until normality is re established, discarding the incoming "A" records, using new "C" records and new_output_q. Terminated by a "D" record. It is simply a different way of saying "use this one", in an in band way. In the above, it avoids a double unpacking step - once to get to the record type, and then to get to the actual data. It only makes sense here because I know that the stuff that comes in is basically an unending stream of more of the same, and it happens - I would say thousands of times a second, but it is more like a hundred or so, given the lack of speed of the processor. So I am quite prepared to trade off the slight inefficiency during the seldom occurring changeover for the railroad like chugging along in the vast majority of cases. "seldom" here is like once a day for a few minutes. And it sure beats the hell out of passing the queue name as a string and mucking around with exec or eval - That is what I did first, and I liked it even less, as the queue passed in such a way had to be a global for the exec to work. It all started because I was not prepared to waste precious cycles in an extra unpacking stage. So I wrote the Can extension module, and I thought it weird enough to make it public: - Hands up those who have ever passed a pointer as a string ! - Hendrik From steven at REMOVE.THIS.cybersource.com.au Fri Jun 5 04:55:50 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2009 08:55:50 GMT Subject: Generating all combinations References: <78g79iF1l1i8bU1@mid.dfncis.de> <09d66eff-f7f2-4928-8b42-4021bad9745f@h23g2000vbc.googlegroups.com> <0234597b$0$8244$c3e8da3@news.astraweb.com> <3d721bbb-e880-4f64-b6b7-9295887b1404@b9g2000yqm.googlegroups.com> <7d410eb0-4db0-4fa1-b33a-e040883ecdaa@j18g2000yql.googlegroups.com> <60590ab9-0204-4236-9a80-a322e20e6417@k20g2000vbp.googlegroups.com> Message-ID: On Thu, 04 Jun 2009 23:10:33 -0700, Mensanator wrote: >> "Everybody" knows? Be careful with those sweeping generalizations. >> Combinatorics is a fairly specialized area not just of programming but >> mathematics as well. > > I would expect that. That was supposed to be funny. I knew that! I was just testing to see if everyone else did... *wink* -- Steven From cournape at gmail.com Fri Jun 5 04:56:05 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 5 Jun 2009 17:56:05 +0900 Subject: PYTHONPATH and multiple python versions Message-ID: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> Hi, As I don't have admin privileges on my main dev machine, I install a good deal of python modules somewhere in my $HOME, using PYTHONPATH to point my python intepreter to the right location. I think PEP370 (per-user site-packages) does exactly what I need, but it works only for python 2.6 and above. Am I out of luck for versions below ? David From paul at boddie.org.uk Fri Jun 5 05:11:22 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 5 Jun 2009 02:11:22 -0700 (PDT) Subject: Yet another unicode WTF References: Message-ID: On 5 Jun, 03:18, Ron Garret wrote: > > According to what I thought I knew about unix (and I had fancied myself > a bit of an expert until just now) this is impossible. ?Python is > obviously picking up a different default encoding when its output is > being piped to a file, but I always thought one of the fundamental > invariants of unix processes was that there's no way for a process to > know what's on the other end of its stdout. The only way to think about this (in Python 2.x, at least) is to consider stream and file objects as things which only understand plain byte strings. Consequently, use of the codecs module is required if receiving/sending Unicode objects from/to streams and files. Paul From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:15:43 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:15:43 -0300 Subject: __file__ access extremely slow References: Message-ID: En Fri, 05 Jun 2009 00:12:25 -0300, John Machin escribi?: >> > (2) This will stop processing on the first object in sys.modules that >> > doesn't have a __file__ attribute. Since these objects aren't >> > *guaranteed* to be modules, > > Definitely not guaranteed to be modules. Python itself drops non-modules > in > there! Python 2.3 introduced four keys mapped to None -- one of these was > dropped in 2.4, but the other three are still there in 2.5 and 2.6: In case someone wonders what all those None are: they're a "flag" telling the import machinery that those modules don't exist (to avoid doing a directory scan over and over, because Python<2.7 attempts first to do a relative import, and only if unsuccessful attempts an absolute one) > C:\junk>\python23\python -c "import sys; print [k for (k, v) in > sys.modules.items() if v is None]" > ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', > 'encodings.types'] In this case, somewhere inside the encodings package, there are statements like "import types" or "from types import ...", and Python could not find types.py in the package directory. -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 05:24:52 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 11:24:52 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> Message-ID: <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > It just smells to me that you've created this elaborate and brittle hack > to work around the fact that you couldn't think of any other way of > getting the thread to change it's behaviour whilst waiting on input. I am beginning to think that you are a troll, as all your comments are haughty and disparaging, while you either take no trouble to follow, or are incapable of following, my explanations. In the event that this is not the case, please try to understand my reply to Skip, and then suggest a way that will perform better in my use case, out of your vast arsenal of better, quicker, more reliable, portable and comprehensible ways of doing it. - Hendrik From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:26:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:26:11 -0300 Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: En Fri, 05 Jun 2009 01:49:15 -0300, Aahz escribi?: > In article > <05937a34-5490-4b31-9f07-a319b44ddb09 at r33g2000yqn.googlegroups.com>, > Michele Simionato wrote: >> >> Actually, in Scheme one would have to fight to define >> a list comprehension (more in general loops) working as >> in Python: the natural definition works as the OP wants. See >> http://www.artima.com/weblogs/viewpost.jsp?thread=3D251156 > > This URL isn't working for me, gives 500. Mmm, the URL ends with: thread, an equals sign, and the number 251156 If you see =3D -- that's the "=" encoded as quoted-printable... -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 05:29:14 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 11:29:14 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <20090604162333.22176.668277797.divmod.quotient.1904@henry.divmod.com> Message-ID: <001201c9e5c0$1e853e20$0d00a8c0@Hendrik> "Jean-Paul Calderone" wrote: > So, do you mind sharing your current problem? Maybe then it'll make more > sense why one might want to do this. Please see my reply to Skip that came in and was answered by email. - Hendrik From nick at craig-wood.com Fri Jun 5 05:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 05 Jun 2009 04:29:41 -0500 Subject: unladen swallow: python and llvm References: Message-ID: Luis M Gonz?lez wrote: > I am very excited by this project (as well as by pypy) and I read all > their plan, which looks quite practical and impressive. > But I must confess that I can't understand why LLVM is so great for > python and why it will make a difference. CPython uses a C compiler to compile the python code (written in C) into native machine code. unladen-swallow uses an llvm-specific C compiler to compile the CPython code (written in C) into LLVM opcodes. The LLVM virtual machine executes those LLVM opcodes. The LLVM virtual machine also has a JIT (just in time compiler) which converts the LLVM op-codes into native machine code. So both CPython and unladen-swallow compile C code into native machine code in different ways. So why use LLVM? This enables unladen swallow to modify the python virtual machine to target LLVM instead of the python vm opcodes. These can then be run using the LLVM JIT as native machine code and hence run all python code much faster. The unladen swallow team have a lot more ideas for optimisations, but this seems to be the main one. It is an interesting idea for a number of reasons, the main one as far as I'm concerned is that it is more of a port of CPython to a new architecture than a complete re-invention of python (like PyPy / IronPython / jython) so stands a chance of being merged back into CPython. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jonas.esp at googlemail.com Fri Jun 5 05:39:31 2009 From: jonas.esp at googlemail.com (Kless) Date: Fri, 5 Jun 2009 02:39:31 -0700 (PDT) Subject: Uppercase/Lowercase on unicode Message-ID: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Is there any librery that works ok with unicode at converting to uppercase or lowercase? -------------- >>> foo = u'??????' >>> print(foo.upper()) ???????????? -------------- From ben+python at benfinney.id.au Fri Jun 5 05:51:03 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 19:51:03 +1000 Subject: Yet another unicode WTF References: Message-ID: <878wk7knzs.fsf@benfinney.id.au> Paul Boddie writes: > The only way to think about this (in Python 2.x, at least) is to > consider stream and file objects as things which only understand plain > byte strings. Consequently, use of the codecs module is required if > receiving/sending Unicode objects from/to streams and files. Actually strings in Python 2.4 or later have the ?encode? method, with no need for importing extra modules: ===== $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' ? $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > foo ; cat foo ? ===== -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From ben+python at benfinney.id.au Fri Jun 5 05:54:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 19:54:25 +1000 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: <874ouvknu6.fsf@benfinney.id.au> Kless writes: > Is there any librery that works ok with unicode at converting to > uppercase or lowercase? > > -------------- > >>> foo = u'??????' > > >>> print(foo.upper()) > ???????????? > -------------- Works fine for me. What do you get when trying to replicate this: >>> import sys >>> sys.version '2.5.4 (r254:67916, Feb 18 2009, 04:30:07) \n[GCC 4.3.3]' >>> sys.stdout.encoding 'UTF-8' >>> foo = u'??????' >>> print(foo.upper()) ?????? -- \ ?I was sad because I had no shoes, until I met a man who had no | `\ feet. So I said, ?Got any shoes you're not using??? ?Steven | _o__) Wright | Ben Finney From redforks at gmail.com Fri Jun 5 05:56:35 2009 From: redforks at gmail.com (Red Forks) Date: Fri, 5 Jun 2009 17:56:35 +0800 Subject: multi-core software In-Reply-To: <4A28333D.6030304@mrabarnett.plus.com> References: <20090616103324.200@gmail.com> <4A28333D.6030304@mrabarnett.plus.com> Message-ID: <3f18b3f10906050256w791ba4ecj67969252ea6824ef@mail.gmail.com> Single - thread programming is great! clean, safe!!! I'm trying schedual task to several work process (not thread). On Fri, Jun 5, 2009 at 4:49 AM, MRAB wrote: > Kaz Kylheku wrote: > >> ["Followup-To:" header set to comp.lang.lisp.] >> On 2009-06-04, Roedy Green wrote: >> >>> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >>> wrote, quoted or indirectly quoted someone who said : >>> >>> ? Why Must Software Be Rewritten For Multi-Core Processors? >>>> >>> Threads have been part of Java since Day 1. >>> >> >> Unfortunately, not sane threads designed by people who actually understand >> multithreading. >> >> The nice thing about Java is whether you are on a single core >>> processor or a 256 CPU machine (We got to run our Athena Integer Java >>> spreadsheet engine on such a beast), does not concern your code. >>> >> >> You are dreaming if you think that there are any circumstances (other than >> circumstances in which performance doesn't matter) in which you don't have >> to >> concern yourself about the difference between a uniprocessor and a 256 CPU >> machine. >> > > If you're interested in parallel programming, have a look at Flow-Based > Programming: > > http://www.jpaulmorrison.com/fbp/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Jun 5 05:59:07 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 06:59:07 -0300 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: En Fri, 05 Jun 2009 06:39:31 -0300, Kless escribi?: > Is there any librery that works ok with unicode at converting to > uppercase or lowercase? > > -------------- >>>> foo = u'??????' > >>>> print(foo.upper()) > ???????????? > -------------- Looks like Python thinks your terminal uses utf-8, but it actually uses another encoding (latin1?) Or, you saved the script as an utf-8 file but the encoding declaration says otherwise. This works fine for me: py> foo = u'??????' py> print foo ?????? py> print foo.upper() ?????? -- Gabriel Genellina From mail at microcorp.co.za Fri Jun 5 06:00:24 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 12:00:24 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org><002501c9e524$2af8c6a0$0d00a8c0@Hendrik> Message-ID: <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> "Terry Reedy" wrote: > If I understand correctly, your problem and solution was this: > > You have multiple threads within a long running process. One thread > repeatedly reads a socket. Yes and it puts what it finds on a queue. - it is a pre defined simple comma delimited record. > You wanted to be able to occasionally send > an object to that thread. Close - to another thread that reads the queue, actually. > Rather than rewrite the thread to also poll a > queue.Queue(), which for CPython sends objects by sending a pointer, It is in fact reading a queue, and what it gets out in the vast majority of cases is the record that came from the socket. >you > converted pointers to strings and sent (multiplex) them via the text > stream the thread was already reading -- and modified the thread to > decode and act on the new type of message. Basically yes - the newly created thread just puts a special text string onto the queue. As I pointed out in my reply to Skip, this makes the unpacking at the output of the queue standard, just using split(','), and it is this simplicity that I wanted to preserve, as it happens almost all of the time. > And you are willing to share the can code with someone who has a similar > rare need and understands the danger of interpreting ints as addresses. > Correct? Absolutely right on - I do not think that it is the kind of thing that should be in the std lib, except as a kind of Hara Kiri bomb - uncan(a random number string), and die! It would also help if someone who is more knowledgable about python would have a look at the C code to make it more robust. There are only 2 routines that matter - it is about a screenfull. - Hendrik From redforks at gmail.com Fri Jun 5 06:04:50 2009 From: redforks at gmail.com (Red Forks) Date: Fri, 5 Jun 2009 18:04:50 +0800 Subject: PYTHONPATH and multiple python versions In-Reply-To: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> References: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> Message-ID: <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> maybe a shell script to switch PYTHONPATH, like: start-python-2.5 start-python-2.4 ... On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau wrote: > Hi, > > As I don't have admin privileges on my main dev machine, I install a > good deal of python modules somewhere in my $HOME, using PYTHONPATH to > point my python intepreter to the right location. I think PEP370 > (per-user site-packages) does exactly what I need, but it works only > for python 2.6 and above. Am I out of luck for versions below ? > > David > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.esp at googlemail.com Fri Jun 5 06:09:49 2009 From: jonas.esp at googlemail.com (Kless) Date: Fri, 5 Jun 2009 03:09:49 -0700 (PDT) Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: On 5 jun, 09:59, "Gabriel Genellina" wrote: > En Fri, 05 Jun 2009 06:39:31 -0300, Kless ? > escribi?: > > > Is there any librery that works ok with unicode at converting to > > uppercase or lowercase? > > > -------------- > >>>> foo = u'??????' > > >>>> print(foo.upper()) > > ???????????? > > -------------- > > Looks like Python thinks your terminal uses utf-8, but it actually uses ? > another encoding (latin1?) > Or, you saved the script as an utf-8 file but the encoding declaration ? > says otherwise. > > This works fine for me: > > py> foo = u'??????' > py> print foo > ?????? > py> print foo.upper() > ?????? > > -- > Gabriel Genellina I just to check it in the python shell and it's correct. Then the problem is by iPython that I was testing it from there. From michele.simionato at gmail.com Fri Jun 5 06:20:24 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 03:20:24 -0700 (PDT) Subject: a problem with concurrency Message-ID: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> At work we have a Web application acting as a front-end to a database (think of a table-oriented interface, similar to an Excel sheet). The application is accessed simultaneously by N people (N < 10). When a user posts a requests he changes the underlying database table. The issue is that if more users are editing the same set of rows the last user will override the editing of the first one. Since this is an in-house application with very few users, we did not worry to solve this issue, which happens very rarely. However, I had a request from the people using the application, saying that this issue indeed happens sometimes and that they really would like to be able to see if some other user is editing a row. In that case, the web interface should display the row as not editable, showing the name of the user which is editing it. Moreover, when posting a request involving non-editable rows, there should be a clear error message and the possibility to continue anyway (a message such as "do you really want to override the editing made by user XXX?"). Looks like a lot of work for an application which is very low priority for us. Also, I do not feel too confident with managing concurrency directly. However, just for the sake of it I have written a prototype with the basic functionality and I am asking here for some advice, since I am sure lots of you have already solved this problem. My constraint are: the solution must work with threads (the web app uses the Paste multithreaded server) but also with processes (while the server is running a batch script could run and set a few rows). It also must be portable across databases, since we use both PostgreSQL and MS SQLServer. The first idea that comes to my mind is to add a field 'lockedby' to the database table, containing the name of the user which is editing that row. If the content of 'lockedby' is NULL, then the row is editable. The field is set at the beginning (the user will click a check button to signal - via Ajax - that he is going to edit that row) to the username and reset to NULL after the editing has been performed. This morning I had a spare hour, so I wrote a 98 lines prototype which has no web interface and does not use an ORM, but has the advantage of being easy enough to follow; you can see the code here: http://pastebin.com/d1376ba05 The prototype uses SQLite and works in autocommit mode (the real application works in autocommit mode too, even if with different databases). I have modelled the real tables with a simple table like this: CREATE TABLE editable_data ( rowid INTEGER PRIMARY KEY, text VARCHAR(256), lockedby VARCHAR(16)) There is thread for each user. The test uses 5 threads; there is no issue of scalability, since I will never have more than 10 users. The basic idea is to use a RowLock object with signature RowLock(connection, username, tablename, primarykeydict) with __enter__ and __exit__ methods setting and resetting the lockedby field of the database table respectively. It took me more time to write this email than to write the prototype, so I do not feel confident with it. Will it really work for multiple threads and multiple processes? I have always managed to stay away from concurrency in my career ;-) Michele Simionato From michele.simionato at gmail.com Fri Jun 5 06:22:26 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 03:22:26 -0700 (PDT) Subject: Odd closure issue for generators References: <24d0eacd-b9fe-4fa1-adba-a700f12f7ed0@j20g2000vbp.googlegroups.com> <05937a34-5490-4b31-9f07-a319b44ddb09@r33g2000yqn.googlegroups.com> Message-ID: <52fa32e4-d946-4c27-80b0-62a13e1ce624@k38g2000yqh.googlegroups.com> On Jun 5, 11:26?am, "Gabriel Genellina" wrote: > Mmm, the URL ends with: thread, an equals sign, and the number 251156 > If you see =3D -- that's the "=" encoded as quoted-printable... Actually this is the right URL: http://www.artima.com/weblogs/viewpost.jsp?thread=251156 From thudfoo at opensuse.us Fri Jun 5 06:29:41 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Fri, 5 Jun 2009 03:29:41 -0700 Subject: Feedparser problem In-Reply-To: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> References: <89d21aec-5d39-4d1f-91b9-776da3506145@i6g2000yqj.googlegroups.com> Message-ID: <3d881a310906050329h54560f21u4f0047b7598b4eb0@mail.gmail.com> On 6/4/09, Jonathan Nelson wrote: > I'm trying to add a feedreader element to my django project. I'm > using Mark Pilgrim's great feedparser library. I've used it before > without any problems. I'm getting a TypeError I can't figure out. > I've tried searching google, bing, google groups to no avail. > > Here's the dpaste of what I'm trying to do and the result I'm > getting: > > http://dpaste.com/51406/ > > I've tried checking my firewall settings. I'm using Windows 7 and > Python 2.6. Win 7 is allowing other Python programs through. I've > tried several different RSS urls with the same result. > > Any thoughts would be greatly appreciated. > from feedparser 4.1 documentation: bozo_exception The exception raised when attempting to parse a non-well-formed feed. I suspect that unexpected keyword "timeout" appears in the feed's xml document. You could download the document yourself and have a look. > -- > http://mail.python.org/mailman/listinfo/python-list > From tkjthingone at gmail.com Fri Jun 5 06:35:25 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 5 Jun 2009 03:35:25 -0700 Subject: Am I doing this the python way? (list of lists + file io) Message-ID: Hello, I'm a fairly new python programmer (aren't I unique!) and a somewhat longer C/++ programmer (4 classes at a city college + lots and lots of tinkering on my own). I've started a pet project (I'm really a blacksheep!); the barebones of it is reading data from CSV files. Each CSV file is going to be between 1 and ~500 entries/lines, I can't see them being much bigger than that, though 600 entries/lines might be possible. As for the total number of CSV files I will be reading in, I can't see my self going over several hundred (200-300), though 500 isn't to much of a stretch and 1000 files *could* happen in the distant future. So, I read the data in from the CSV file and store each line as an entry in a list, like this (I have slightly more code, but this is basically what I'm doing) *FilepathVar = "my/file/path/csv.txt" import csv reader = csv.reader(open(FilepathVar,"rb"), delimiter=',') entryGrouping = [] # create a list for entry in reader: entryGrouping.append(entry)* This produces a list (entryGrouping) where I can do something like ( *print entryGrouping[0]* ) and get the first row/entry of the CSV file. I could also do ( *print entryGrouping[0][0]* ) and get the first item in the first row. All is well and good, codewise, I hope? Then, since I wanted to be able to write in multiple CSV files (they have the same structure, the data relates to different things) I did something like this to store multiple entryGroupings... *masterList = [] # create a list masterList.append(entryGrouping) # ... # load another CSV file into entryGrouping # ... masterList.append(entryGrouping)* Which lets me write code like this... * print masterList[0] # prints an entire entryGrouping print masterList[0][0] # prints the first entry in entryGrouping print masterList[0][0][0] # prints the first item in the first row of the first entryGrouping... * So, my question (because I did have one!) is thus: I'm I doing this in a pythonic way? Is a list of lists (of lists?) a good way to handle this? As I start adding more CSV files, will my program grind to a halt? To answer that, you might need some more information, so I'll try and provide a little right now as to what I expect to be doing... (It's still very much in the planning phases, and a lot of it is all in my head) So, Example: I'll read in a CSV file (just one, for now.) and store it into a list. Sometime later, I'll get another CSV file, almost identical/related to the first. However, a few values might have changed, and there might be a few new lines (entries) or maybe a few less. I would want to compare the CSV file I have in my list (in memory) to new CSV file (which I would probably read into a temporary list). I would then want to track and log the differences between the two files. After I've figured out what's changed, I would either update the original CSV file with the new CSV's information, or completely discard the original and replace it with the new one (whichever involves less work). Basically, lots of iterating through each entry of each CSV file and comparing to other information (either hard coded or variable). So, to reiterate, are lists what I want to use? Should I be using something else? (even if that 'something else' only really comes into play when storing and operating on LOTS of data, I would still love to hear about it!) Thank you for taking the time to read this far. I apologize if I've mangled any accepted terminology in relation to python or CSV files. - Ira (P.S. I've read this through twice now and tried to catch as many errors as I could. It's late (almost 4AM) so I'm sure to have missed some. If something wasn't clear, point it out please. See you in the morning! - er, more like afternoon!) -------------- next part -------------- An HTML attachment was scrubbed... URL: From javier.collado at gmail.com Fri Jun 5 06:37:27 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 5 Jun 2009 12:37:27 +0200 Subject: PYTHONPATH and multiple python versions In-Reply-To: <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> References: <5b8d13220906050156w6ae7c0fr514ad34ddb56239e@mail.gmail.com> <3f18b3f10906050304x43dd4275r9e6d44a9b9d9d648@mail.gmail.com> Message-ID: Hello, I think that virtualenv could also do the job. Best regards, Javier 2009/6/5 Red Forks : > maybe a shell script to switch PYTHONPATH, like: > start-python-2.5 > start-python-2.4 ... > On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau wrote: >> >> Hi, >> >> As I don't have admin privileges on my main dev machine, I install a >> good deal of python modules somewhere in my $HOME, using PYTHONPATH to >> point my python intepreter to the right location. I think PEP370 >> (per-user site-packages) does exactly what I need, but it works only >> for python 2.6 and above. Am I out of luck for versions below ? >> >> David >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From gagsl-py2 at yahoo.com.ar Fri Jun 5 06:54:30 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 07:54:30 -0300 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: En Fri, 05 Jun 2009 07:00:24 -0300, Hendrik van Rooyen escribi?: > "Terry Reedy" wrote: > >> You have multiple threads within a long running process. One thread >> repeatedly reads a socket. > > Yes and it puts what it finds on a queue. - it is a pre defined simple > comma > delimited record. > >> You wanted to be able to occasionally send >> an object to that thread. > > Close - to another thread that reads the queue, actually. > >> Rather than rewrite the thread to also poll a >> queue.Queue(), which for CPython sends objects by sending a pointer, > > It is in fact reading a queue, and what it gets out in the vast majority > of > cases is the record that came from the socket. Ah... I had the same impression as Mr. Reedy, that you were directly reading from a socket and processing right there, so you *had* to use strings for everything. But if you already have a queue, you may put other objects there (instead of "canning" them). Testing the object type with isinstance(msg, str) is pretty fast, and if you bind locally those names I'd say the overhead is negligible. -- Gabriel Genellina From pataphor at gmail.com Fri Jun 5 07:04:37 2009 From: pataphor at gmail.com (pataphor) Date: Fri, 5 Jun 2009 11:04:37 +0000 (UTC) Subject: Making the case for repeat References: Message-ID: Gabriel Genellina wrote: > Ok, you're proposing a "bidimensional" repeat. I prefer to keep things > simple, and I'd implement it in two steps. But what is simple? I am currently working on a universal feature creeper that could replace itertools.cycle, itertools.repeat, itertools.chain and reverse and also helps to severely cut down on itertools.islice usage. All within virtually the same parameter footprint as the last function I posted. The problem is posting *this* function would kill my earlier repeat for sure. And it already had a problem with parameters < 0 (Hint: that last bug has now become a feature in the unpostable repeat implementation) > Note that this doesn't require any additional storage. Second step would > be to build a bidimensional repeat: Thanks for reminding me, but the storage savings only work for a 'single cycle' function call. But I guess one could special case for that. > py> one = chain.from_iterable(repeat(elem, 3) for elem in thing) > py> two = chain.from_iterable(tee(one, 2)) > py> list(two) > ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4', '1', '1', > '1', '2', > '2', '2', '3', '3', '3', '4', '4', '4'] > > Short and simple, but this one requires space for one complete run (3*4 > items in the example). Really? I count 4 nested functions and an iterator comprehension. I guess it's a tradeoff between feature creep and function nesting creep. P. From paul at boddie.org.uk Fri Jun 5 07:06:50 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 5 Jun 2009 04:06:50 -0700 (PDT) Subject: Yet another unicode WTF References: <878wk7knzs.fsf@benfinney.id.au> Message-ID: On 5 Jun, 11:51, Ben Finney wrote: > > Actually strings in Python 2.4 or later have the ?encode? method, with > no need for importing extra modules: > > ===== > $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > ? > > $ python -c 'import sys; sys.stdout.write(u"\u03bb\n".encode("utf-8"))' > foo ; cat foo > ? > ===== Those are Unicode objects, not traditional Python strings. Although strings do have decode and encode methods, even in Python 2.3, the former is shorthand for the construction of a Unicode object using the stated encoding whereas the latter seems to rely on the error-prone automatic encoding detection in order to create a Unicode object and then encode the result - in effect, recoding the string. As I noted, if one wants to remain sane and not think about encoding everything everywhere, creating a stream using a codecs module function or class will permit the construction of something which deals with Unicode objects satisfactorily. Paul From ldo at geek-central.gen.new_zealand Fri Jun 5 07:17:25 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:17:25 +1200 Subject: Project source code layout? References: Message-ID: In message , Dave Angel wrote: > Lawrence D'Oliveiro wrote: > >> In message , Dave >> Angel wrote: >> >>> Rather than editing the source files at install time, consider just >>> using an environment variable in your testing environment, which would >>> be missing in production environment. >>> >> >> I'd still need to define that environment variable in a wrapper script, >> which means editing that script at install time ... back to square one >> ... >> > No, the whole point is it's an environment variable which is *missing" > in production environment. Make sure you make it an obscure name, like > set MyProductName_TestingMode=1 > > So the way you know you're in a production environment is that you do > not have such an environment variable. Sounds like a very roundabout solution to the wrong problem. From jeanmichel at sequans.com Fri Jun 5 07:23:23 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Jun 2009 13:23:23 +0200 Subject: Messing up with classes and their namespace Message-ID: <4A29002B.4070100@sequans.com> Hello world, I had recently a very nasty bug in my python application. The context is quite complex, but in the end the problem can be resume as follow: 2 files in the same directory : lib.py: >import foo >foo.Foo.BOOM='lib' foo.py: >class Foo: > BOOM = 'Foooo' > >if __name__=='__main__': > import lib # I'm expecting BOOM to be set to 'lib' > print Foo.BOOM I was expecting 'lib' as output, but I got 'Fooo'. I don't really understand what python mechanism I'm messing with but I have the feeling I've misunderstood a very basic concept about class, namespace or whatever import notion. This is how I made it work: >if __name__=='__main__': > from lib import Foo # make sure Foo comes from lib > print Foo.BOOM I guess there is 2 different objects for the same class Foo. How I do I make both Foo objects the same object ? Jean-Michel From ldo at geek-central.gen.new_zealand Fri Jun 5 07:25:51 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:25:51 +1200 Subject: Adding a Par construct to Python? References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <02200d22$0$20645$c3e8da3@news.astraweb.com> <_vidnQW0dJoGg43XnZ2dnUVZ_hpi4p2d@posted.usinternet> <0220260f$0$20645$c3e8da3@news.astraweb.com> <77as23F1fhj3uU1@mid.uni-berlin.de> Message-ID: In message <77as23F1fhj3uU1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: >> But reduce()? I can't see how you can parallelize reduce(). By its >> nature, it has to run sequentially: it can't operate on the nth item >> until it is operated on the (n-1)th item. > > That depends on the operation in question. Addition for example would > work. My math-skills are a bit too rusty to qualify the exact nature of > the operation, commutativity springs to my mind. Associativity: ((A op B) op C) = (A op (B op C)) So for example A op B op C op D could be grouped into (A op B) op (C op D) and the two parenthesized subexpressions evaluated concurrently. But this would only give you a speedup that was logarithmic in the number of op's. From ldo at geek-central.gen.new_zealand Fri Jun 5 07:35:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 05 Jun 2009 23:35:07 +1200 Subject: Adding a Par construct to Python? References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <1e6e1616-c888-43a3-a5b5-0739b8f77236@m24g2000vbp.googlegroups.com> <477992d9-271f-4c0c-a7f8-b0c98bdefe55@q14g2000vbn.googlegroups.com> Message-ID: In message , Steven D'Aprano wrote: > threads = [PMapThread(datapool) for i in xrange(numthreads)] Shouldn?t that ?PMapThread? be ?thread?? From no.email at please.post Fri Jun 5 07:50:50 2009 From: no.email at please.post (kj) Date: Fri, 5 Jun 2009 11:50:50 +0000 (UTC) Subject: fastest way to test file for string? Message-ID: Hi. I need to implement, within a Python script, the same functionality as that of Unix's grep -rl some_string some_directory I.e. find all the files under some_directory that contain the string "some_string". I imagine that I can always resort to the shell for this, but is there an efficient way of doing it within Python? (BTW, portability is not high on my list here; this will run on a Unix system, and non-portable Unix-specific solutions are fine with me.) TIA! -- From enleverLesX_XXmcX at XmclavXeauX.com Fri Jun 5 08:46:25 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Fri, 05 Jun 2009 13:46:25 +0100 Subject: python way to automate IE8's File Download dialog References: Message-ID: <4a290592$0$17084$ba4acef3@news.orange.fr> Hi! Suppose that the (web) site give the file only after several seconds, and after the user click a confirm (example: RapidFile). Suppose that the (web) site give the file only after the user input a code, controled by a javascript script. @-salutations -- Michel Claveau From ebonak at hotmail.com Fri Jun 5 08:50:48 2009 From: ebonak at hotmail.com (Esmail) Date: Fri, 05 Jun 2009 08:50:48 -0400 Subject: pylint naming conventions? Message-ID: Hi, as someone who is still learning a lot about Python I am making use of all the tools that can help me, such as pyflakes, pychecker and pylint. I am confused by pylint's naming conventions, I don't think the are in tune with Python's style recommendations (PEP 8?) Anyone else think this? Is there an easy way to get this in compliance? Or lacking this just turn this off (I'd rather not turn it off if it's easy to get in tune with the standards). Or am I wrong about my assertion with regard to the naming conventions? Thanks, Esmail ps: if anyone else wants to toss in some other recommendations for useful tools feel free to do so! From skip at pobox.com Fri Jun 5 08:54:16 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 07:54:16 -0500 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <18985.5496.307567.338917@montanaro.dyndns.org> >> Requiring that the C++ compiler used to make the dll's/so's to be the >> same one Python is compiled with wouldn't be too burdensome would it? Scott> And what gave you then impression that Python is compiled with a Scott> C++ compiler? I don't think it's too much to expect that a C++ compiler be available for the configure step if Python is being built in a C++ shop. The C compiler used to build Python proper should be compatible with the C++ compiler available to build C++ extension modules or C++ libraries dynamically linked into Python. If there is no C++ compiler available then the proposed layout sniffing just wouldn't be done and either a configure error would be emitted or a run-time exception raised if a program attempted to use that feature. (Or the sniffing could be explicitly enabled/disabled by a configure flag.) -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From python.list at tim.thechases.com Fri Jun 5 08:59:22 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Jun 2009 07:59:22 -0500 Subject: a problem with concurrency In-Reply-To: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> References: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> Message-ID: <4A2916AA.1000501@tim.thechases.com> > When a user posts a requests he changes the underlying database > table. The issue is that if more users are editing the > same set of rows the last user will override the editing of the > first one. Since this is an in-house application with very few > users, we did not worry to solve this issue, which happens > very rarely. However, I had a request from the people using > the application, saying that this issue indeed happens sometimes > and that they really would like to be able to see if some other > user is editing a row. In that case, the web interface should > display the row as not editable, showing the name of the user > which is editing it. Moreover, when posting a request involving > non-editable rows, there should be a clear error message and > the possibility to continue anyway (a message such as > "do you really want to override the editing made by user XXX?"). The common way to do this is to not bother with the "somebody else is editing this record" because it's nearly impossible with the stateless web to determine when somebody has stopped browsing a web page. Instead, each record simply has a "last modified on $TIMESTAMP by $USERID" pair of field. When you read the record to display to the user, you stash these values into the page as $EXPECTED_TIMESTAMP and $EXPECTED_USERID. If, when the user tries to save the record, your web-server app updates the record only if the timestamp+username+rowid match: cursor.execute(""" UPDATE MyTable SET Field1=?, Field2=?, Field3=? WHERE id=? AND LastModified=? AND LastModifiedBy=?""", (field1, field2, field3, rowid, expected_lastmodified, expecteduserid) ) if cursor.rowcount: cursor.commit() print "Yay!" else: cursor.execute(""" SELECT u.name, t.lastmodified FROM MyTable t INNER JOIN MyUsers u ON u.id = t.LastModifiedBy WHERE t.id = ?""", (rowid,)) # maybe a little try/except around this in case # the record was deleted instead of modified? name, when = cursor.fetchone() print "This information has been modified " \ "(by %s at %s) since you last viewed it (at %s)" % ( name, when, expected_lastmodified) If you wanted to be really snazzy, you could pull up the existing new record alongside the data they tried to submit, and allow them to choose the correct value for each differing field. This also encourages awareness of conflicting edits and hopefully increases communication between your users ("Why is Pat currently editing this record...I'm working on it?!" [calls/IMs/emails Pat to get matters straight]) > The first idea that comes to my mind is to add a field 'lockedby' > to the database table, containing the name of the user which is > editing that row. If the content of 'lockedby' is NULL, then the > row is editable. The field is set at the beginning (the user will > click a check button to signal - via Ajax - that he is going > to edit that row) to the username and reset to NULL after the > editing has been performed. Locking is the easy part -- it's knowing when to *unlock* that it becomes a problem. What happens if a user locks a record at 4:59pm on Friday afternoon and then goes on vacation for a week preventing folks from editing this record? If the locks are scoped to a single request, they do no good. The locks have to span multiple requests. I'd just ignore locking. -tkc From willgun at live.cn Fri Jun 5 09:00:44 2009 From: willgun at live.cn (willgun) Date: Fri, 05 Jun 2009 21:00:44 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Mark Tolonen ??: > > "willgun" wrote in message > news:h08c5e$aub$1 at news.cn99.com... >> By the way ,what does 'best regards' means at the end of a mail? > > I think ?? may be a good translation. > > -Mark > > O(?_?)O?? Glad to meet a foreigner know Chinese, :-) . But in my opinion,?? means congratulation,while ? means best regards. From xahlee at gmail.com Fri Jun 5 09:03:45 2009 From: xahlee at gmail.com (Xah Lee) Date: Fri, 5 Jun 2009 06:03:45 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: On May 25, 10:35 am, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, and why. I normally use vi, and just got > into Python, so I am looking for suitable syntax files for it, and > extra utilities. I dabbled with emacs at some point, but couldn't get > through the key bindings for commands. I've never tried emacs with vi > keybindings (I forgot the name of it) but I've been tempted. > > So what do you guys use, and why? Hopefully we can keep this civil. I use emacs. If you never tried emacs, you might check out: ? Xah's Emacs Tutorial http://xahlee.org/emacs/emacs.html ? Xah's Emacs Lisp Tutorial http://xahlee.org/emacs/elisp.html you can use python to write emacs commands: ? Elisp Wrapper For Perl Scripts http://xahlee.org/emacs/elisp_perl_wrapper.html Emacs keyboard shortcuts is problematic indeed. See: ? Why Emacs's Keyboard Shortcuts Are Painful http://xahlee.org/emacs/emacs_kb_shortcuts_pain.html However, you can completely fix that. See: ? Ergoemacs Keybindings http://xahlee.org/emacs/ergonomic_emacs_keybinding.html Xah ? http://xahlee.org/ ? From willgun at live.cn Fri Jun 5 09:04:49 2009 From: willgun at live.cn (willgun) Date: Fri, 05 Jun 2009 21:04:49 +0800 Subject: import sqlite3 In-Reply-To: References: Message-ID: Gabriel Genellina ??: > En Thu, 04 Jun 2009 03:14:18 -0300, willgun escribi?: > >> I'm a student from China.It's painful for us to read python >> documentation entirely due to poor english.So I often make these >> mistakes. > > Try "chinese python group" at Google - I see some promising results at > least... > Good idea. But I try to improve my english via visiting english ones. 15 days later,I'll go up for my english examination. From michele.simionato at gmail.com Fri Jun 5 09:08:46 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 15:08:46 +0200 Subject: a problem with concurrency In-Reply-To: <4A2916AA.1000501@tim.thechases.com> References: <5bba753a-0598-45f1-bf1c-0a0a6392bc7d@k2g2000yql.googlegroups.com> <4A2916AA.1000501@tim.thechases.com> Message-ID: <4edc17eb0906050608v509ef337n89dcf009d9821bab@mail.gmail.com> On Fri, Jun 5, 2009 at 2:59 PM, Tim Chase wrote: > The common way to do this is to not bother with the "somebody else is > editing this record" because it's nearly impossible with the stateless web > to determine when somebody has stopped browsing a web page. ?Instead, each > record simply has a "last modified on $TIMESTAMP by $USERID" pair of field. > ?When you read the record to display to the user, you stash these values > into the page as $EXPECTED_TIMESTAMP and $EXPECTED_USERID. ?If, when the > user tries to save the record, your web-server app updates the record only > if the timestamp+username+rowid match This is much easier to implement than the locking mechanism since I already have the fields $EXPECTED_TIMESTAMP and $EXPECTED_USERID in the db! It looks quite sufficient for my use case. From ben+python at benfinney.id.au Fri Jun 5 09:12:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Jun 2009 23:12:54 +1000 Subject: pylint naming conventions? References: Message-ID: <87skiekend.fsf@benfinney.id.au> Esmail writes: > I am confused by pylint's naming conventions, I don't think the are in > tune with Python's style recommendations (PEP 8?) > > Anyone else think this? It's hard to know, without examples. Can you give some output of pylint that you think doesn't agree with PEP 8? -- \ ?Are you thinking what I'm thinking, Pinky?? ?Uh... yeah, | `\ Brain, but where are we going to find rubber pants our size?? | _o__) ?_Pinky and The Brain_ | Ben Finney From python.list at tim.thechases.com Fri Jun 5 09:14:36 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Jun 2009 08:14:36 -0500 Subject: fastest way to test file for string? In-Reply-To: References: Message-ID: <4A291A3C.2010904@tim.thechases.com> > Hi. I need to implement, within a Python script, the same > functionality as that of Unix's > > grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". I'd do something like this untested function: def find_files_containing(base_dir, string_to_find): for path, files, dirs in os.walk(base_dir): for fname in files: full_name = os.path.join(path, fname) f = file(full_name) for line in f: if string_to_find in line: f.close() yield full_name break else: f.close() for filename in find_files_containing( "/path/to/wherever/", "some_string" ): print filename It's not very gracious regarding binary files, but caveat coder. -tkc From aahz at pythoncraft.com Fri Jun 5 09:24:38 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 06:24:38 -0700 Subject: Odd closure issue for generators References: <78180b4c-68b2-4a0c-8594-50fb1ea2f414@c19g2000yqc.googlegroups.com> Message-ID: In article , Lawrence D'Oliveiro wrote: >In message ><78180b4c-68b2-4a0c-8594-50fb1ea2f414 at c19g2000yqc.googlegroups.com>, Michele >Simionato wrote: >> >> The crux is in the behavior of the for loop: in Python there is a >> single scope and the loop variable is *mutated* at each iteration, >> whereas in Scheme (or Haskell or any other functional language) a new >> scope is generated at each iteration and there is actually a new loop >> variable at each iteration: no mutation is involved. > >I think it's a bad design decision to have the loop index be a variable >that can be assigned to in the loop. Why? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From python at mrabarnett.plus.com Fri Jun 5 09:38:11 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Jun 2009 14:38:11 +0100 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: References: Message-ID: <4A291FC3.7010808@mrabarnett.plus.com> John Thingstad wrote: > P? Fri, 05 Jun 2009 08:07:39 +0200, skrev Xah Lee : > >> On Jun 3, 11:50 pm, Xah Lee wrote: > >> The point in these short examples is not about software bugs or >> problems. It illustrates, how seemingly trivial problems, such as >> networking, transferring files, running a app on Mac or Windwos, >> upgrading a app, often involves a lot subtle complexities. For mom and >> pop users, it simply stop them dead. For a senior industrial >> programer, it means some conceptually 10-minutes task often ends up in >> hours of tedium. > > What on earth gave you the idea that this is a trivial problem? > Networks have been researched and improved for the last 40 years! > It is a marvel of modern engineering that they work as well as they do. > [snip] The actual phrase was "/seemingly/ trivial problems", ie it /looks/ simple at first glance. From pruebauno at latinmail.com Fri Jun 5 09:54:15 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 5 Jun 2009 06:54:15 -0700 (PDT) Subject: fastest way to test file for string? References: Message-ID: On Jun 5, 7:50?am, kj wrote: > Hi. ?I need to implement, within a Python script, the same > functionality as that of Unix's > > ? ?grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". > > I imagine that I can always resort to the shell for this, but is > there an efficient way of doing it within Python? > > (BTW, portability is not high on my list here; this will run on a > Unix system, and non-portable Unix-specific solutions are fine with > me.) > > TIA! > -- You can write your own version of grep in python using os.walk, open, read and find. I don't know why one would want to do that unless for portability reasons. It will be pretty hard to beat grep in efficiency and succinctness. The most sensible thing IMHO is a shell script or call grep using os.system (or using subprocess). From theller at python.net Fri Jun 5 10:13:22 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 16:13:22 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> Message-ID: <78sng2F1lbbekU1@mid.individual.net> skip at pobox.com schrieb: > >> Requiring that the C++ compiler used to make the dll's/so's to be the > >> same one Python is compiled with wouldn't be too burdensome would it? > > Scott> And what gave you then impression that Python is compiled with a > Scott> C++ compiler? > > I don't think it's too much to expect that a C++ compiler be available for > the configure step if Python is being built in a C++ shop. The C compiler > used to build Python proper should be compatible with the C++ compiler > available to build C++ extension modules or C++ libraries dynamically linked > into Python. > > If there is no C++ compiler available then the proposed layout sniffing just > wouldn't be done and either a configure error would be emitted or a run-time > exception raised if a program attempted to use that feature. (Or the > sniffing could be explicitly enabled/disabled by a configure flag.) > Hm, on Linux, gccxml (if its version is compatible with that of the C++ compiler) can probably help a lot. At runtime, no configure step needed. Unfortunately not on Windows. Thomas From rcdailey at gmail.com Fri Jun 5 10:30:26 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 07:30:26 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: On Jun 5, 3:47?am, "Gabriel Genellina" wrote: > En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey ? > escribi?: > > > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > > URL: > > >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > > Have it save the ZIP to any destination directory. For me, this only > > downloads about 40KB before it stops without any error at all. Any > > reason why this isn't working? > > I could not reproduce it. I downloaded about 300K without error ?(Python ? > 3.0.1 on Windows) > > -- > Gabriel Genellina Can you show me your test code please? From brian at sweetapp.com Fri Jun 5 10:36:32 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 05 Jun 2009 07:36:32 -0700 Subject: Odd closure issue for generators In-Reply-To: References: <4A28903B.4020301@sweetapp.com> Message-ID: <4A292D70.9020801@sweetapp.com> Ned Deily wrote: > In article <4A28903B.4020301 at sweetapp.com>, > Brian Quinlan wrote: >> Scott David Daniels wrote: >> [snipped] >>> When you evaluate a lambda expression, the default args are evaluated, >>> but the expression inside the lambda body is not. When you apply that >>> evaluated lambda expression, the expression inside the lambda body is >>> is evaluated and returned. >> But that's not really the issue. I knew that the lambda was not >> evaluated but thought each generator expression got its own context >> rather than sharing one. > > Each? Maybe that's a source of confusion. There is only one generator > expression in your example. > >>>> c = (lambda : i for i in range(11, 16)) >>>> c > at 0x114e90> >>>> d = list(c) >>>> d > [ at 0x119348>, at 0x119390>, > at 0x1193d8>, at 0x119420>, > at 0x119468>] > Sorry, I wasn't as precise as I should have been. If you consider this example: ( for x in y) I thought that every time that was evaluated, it would be done in a new closure with x bound to the value of x at the time that the closure was created. Instead, a new closure is created for the entire generator expression and x is updated inside that closure. Cheers, Brian From iamelgringo at gmail.com Fri Jun 5 10:39:11 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Fri, 5 Jun 2009 07:39:11 -0700 (PDT) Subject: Feedparser Problem Message-ID: <985f7729-c301-40d9-b712-d671c136dd1e@k38g2000yqh.googlegroups.com> I'm working with Feedparser on months old install of Windows 7, and now programs that ran before are broken, and I'm getting wierd messages that are rather opaque to me. Google, Bing, News groups have all left me empty handed. I was wondering if I could humbly impose upon the wizards of comp.lang.python to lend me their wisdom and insight to this problem that is too difficult for my little mind. Here's what I'm going through: >>>from feedparser import parse >>>url='http://feeds.nytimes.com/nyt/rss/Technology' >>>url2='http://feeds.washingtonpost.com/wp-dyn/rss/technology/index_xml' >>>d = parse(url) >>>d2= parse(url2) >>>d {'bozo':1, 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), 'encoding': 'utf-8', 'entries': [], 'feed':{}, 'version': None} >>>d2 {'bozo': 1, 'bozo_exception': TypeError("__init__() got an unexpected keyword argument 'timeout'",), 'encoding': 'utf-8', 'entries': [], 'feed': {}, 'version': None} I've checked my firewall settings, and python is allowed. Other python programs can get data from the web. I know that the 'bozo' is for malformed xml. I've searched through both of those rss feeds, and I can't find the argument 'timeout' anywhere in them. Any ideas, thoughts or directions in which I might go? Thanks to all in advance, Jonathan From philip at semanchuk.com Fri Jun 5 11:21:28 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 5 Jun 2009 11:21:28 -0400 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: <78sng2F1lbbekU1@mid.individual.net> References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78sng2F1lbbekU1@mid.individual.net> Message-ID: <218BBFD2-2F5A-4FD5-8BEC-9D89622CAB18@semanchuk.com> On Jun 5, 2009, at 10:13 AM, Thomas Heller wrote: > skip at pobox.com schrieb: >>>> If there is no C++ compiler available then the proposed layout >>>> sniffing just >> wouldn't be done and either a configure error would be emitted or a >> run-time >> exception raised if a program attempted to use that feature. (Or the >> sniffing could be explicitly enabled/disabled by a configure flag.) >> > > Hm, on Linux, gccxml (if its version is compatible with that of the C > ++ compiler) > can probably help a lot. At runtime, no configure step needed. > Unfortunately not on Windows. I'm not a gccxml user, but its install page has a section for Windows: http://www.gccxml.org/HTML/Install.html HTH P From __peter__ at web.de Fri Jun 5 11:31:43 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Jun 2009 17:31:43 +0200 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: Robert Dailey wrote: > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey >> escribi?: >> >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following >> > URL: >> >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... >> >> > Have it save the ZIP to any destination directory. For me, this only >> > downloads about 40KB before it stops without any error at all. Any >> > reason why this isn't working? >> >> I could not reproduce it. I downloaded about 300K without error (Python >> 3.0.1 on Windows) >> >> -- >> Gabriel Genellina > > Can you show me your test code please? Here's mine: $ cat retriever.py import urllib.request import os def report(*args): print(args) url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.10.zip" filename = url.rsplit("/")[-1] urllib.request.urlretrieve(url, filename=filename, reporthook=report) print(os.path.getsize(filename)) $ If you had shown your code in the first place the problem might have been solved by now... Peter From theller at python.net Fri Jun 5 11:33:01 2009 From: theller at python.net (Thomas Heller) Date: Fri, 05 Jun 2009 17:33:01 +0200 Subject: Using C++ and ctypes together: a vast conspiracy? ;) In-Reply-To: References: <78pfqeF1n4jf3U1@mid.individual.net> <4A2821F9.6080901@ctypes.org> <78sng2F1lbbekU1@mid.individual.net> Message-ID: <78ss5dF1nntrpU1@mid.individual.net> Philip Semanchuk schrieb: > On Jun 5, 2009, at 10:13 AM, Thomas Heller wrote: > >> skip at pobox.com schrieb: >>>>> If there is no C++ compiler available then the proposed layout >>>>> sniffing just >>> wouldn't be done and either a configure error would be emitted or a >>> run-time >>> exception raised if a program attempted to use that feature. (Or the >>> sniffing could be explicitly enabled/disabled by a configure flag.) >>> >> >> Hm, on Linux, gccxml (if its version is compatible with that of the C >> ++ compiler) >> can probably help a lot. At runtime, no configure step needed. >> Unfortunately not on Windows. > > I'm not a gccxml user, but its install page has a section for Windows: > http://www.gccxml.org/HTML/Install.html Yes, it runs on Windows (*). However, there are two problems: 1. gccxml refuses to parse quite some include files from the Window SDK. That's probably not the fault of gccxml but MS using non-standard C++ constructs. (There is a workaround inside gccxml: it installs patched Windows header files, but the patches must be created first by someone) 2. You cannot expect gccxml (which is mostly GCC inside) to use the MSVC algorithm for C++ object layout, so unfortuately it does not help in the most important use-case. Thomas (*) And there is even use for it on Windows to parse C header files and generate ctypes wrappers, in the ctypeslib project. From mail at microcorp.co.za Fri Jun 5 11:33:04 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 17:33:04 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: <004201c9e5f3$c6809920$0d00a8c0@Hendrik> "Gabriel Genellina" wrote: >Ah... I had the same impression as Mr. Reedy, that you were directly >reading from a socket and processing right there, so you *had* to use >strings for everything. not "had to" - "chose to" - to keep the most used path as short as I could. > >But if you already have a queue, you may put other objects there (instead >of "canning" them). Testing the object type with isinstance(msg, str) is >pretty fast, and if you bind locally those names I'd say the overhead is >negligible. Maybe you are right and I am pre optimising - but the heart of this box really is that silly loop and the processor really is not fast at all. I felt it was right to keep the processing of the stuff coming out of the queue standard with the split(','), as the brainless way seemed to be the best - anything else I could think of just added overhead. I thought of putting the string in a list, with the record type being the first item, and the string the second, with a queue replacing the string for the state change record. I basically rejected this as it would have added extra processing both at the entry and the exit of the critical queue, for every record. I admit that I did not think of testing the type with isinstance, but even if the overhead is minimal, it does add extra cycles to the innermost loop, for every one of the thousands of times that nothing of importance is detected. This is what I was trying to avoid, as it is important to get as much performance out of the box as I can (given that I am using Python to get the job done fast, because that is also important). So it is a kind of juggling with priorities - "make it fast" would imply do not use python, but "get it done quickly" implies using python, and it looks to me that if I am careful and think more like an assembler programmer, the real time performance will be adequate. And I do not want to do anything that could conceivably compromise that. Even if it means jumping through a funny hoop like I am doing now, and inventing a weird way to pass an object. "adequate" here is up to now quite good - if I set up a client on the LAN and I reflect the inputs back to the outputs, then to my human senses there is no difference in the way the output relays chatter and bounce when I play with a wire on the inputs, to what I would expect of a locally hard wired setup. So to a large extent I think that I am doing the job as fast as it is possible - the comma delimited input string is a fact, decided on between myself and the customer a long time ago, and it comes over a socket, so it has to be a string. The least I can do with it is nothing before I put it on the critical queue. Then when it comes out of the queue, I have to break it up into its constituent parts, and I would think that split is the canonical way of doing that. Then there follows some jiggery pokery to get the outputs out and the inputs in, that involves some ctypes stuff to address the real hardware, and then the input results have to be sent back to the client(s), over and over. That is basically what the box does, until another connection is made (from a control room) and the local "master" client is pre empted and the outputs from the new "master" must be obeyed, and the results reflected back to the new connection too. It is a fairly simple state machine, and it has to be as fast as possible, as twice its loop time plus the network round trip time defines its responsiveness. I would really appreciate it if someone can dream up a faster way of getting round this basic loop. (even if it involves other equally weird constructs as "canning") - Hendrik From wiggly at wiggly.org Fri Jun 5 11:35:38 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Fri, 05 Jun 2009 16:35:38 +0100 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> Message-ID: <4A293B4A.1090000@wiggly.org> Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> It just smells to me that you've created this elaborate and brittle hack >> to work around the fact that you couldn't think of any other way of >> getting the thread to change it's behaviour whilst waiting on input. > > I am beginning to think that you are a troll, as all your comments are > haughty and disparaging, while you either take no trouble to follow, > or are incapable of following, my explanations. > > In the event that this is not the case, please try to understand my > reply to Skip, and then suggest a way that will perform better > in my use case, out of your vast arsenal of better, quicker, > more reliable, portable and comprehensible ways of doing it. Well, why not have a look at Gabriel's response. That seems like a much more portable way of doing it if nothing else. I'm not trolling, you just seem to be excited about something that sounds like a fundamentally bad idea. n From gdamjan at gmail.com Fri Jun 5 11:37:11 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Fri, 05 Jun 2009 17:37:11 +0200 Subject: Uppercase/Lowercase on unicode References: <4ef0ae1b-56de-4f87-bcb8-364700d84abb@l12g2000yqo.googlegroups.com> Message-ID: <7mqnf6-q09.ln1@archaeopteryx.softver.org.mk> > I just to check it in the python shell and it's correct. > Then the problem is by iPython that I was testing it from there. yes, iPython has a bug like that https://bugs.launchpad.net/ipython/+bug/339642 -- ?????? ( http://softver.org.mk/damjan/ ) A: Because it reverses the logical flow of conversation. Q: Why is top posting frowned upon? From mail at microcorp.co.za Fri Jun 5 11:37:25 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 17:37:25 +0200 Subject: fastest way to test file for string? References: Message-ID: <004301c9e5f3$c75acc80$0d00a8c0@Hendrik> "kj" wrote: > > Hi. I need to implement, within a Python script, the same > functionality as that of Unix's > > grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". > > I imagine that I can always resort to the shell for this, but is > there an efficient way of doing it within Python? > > (BTW, portability is not high on my list here; this will run on a > Unix system, and non-portable Unix-specific solutions are fine with > me.) Use grep. You will not beat it's performance. - Hendrik From nrook at wesleyan.edu Fri Jun 5 12:14:10 2009 From: nrook at wesleyan.edu (Nathaniel Rook) Date: Fri, 05 Jun 2009 12:14:10 -0400 Subject: numpy 00 character bug? Message-ID: Hello, all! I've recently encountered a bug in NumPy's string arrays, where the 00 ASCII character ('\x00') is not stored properly when put at the end of a string. For example: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> print numpy.version.version 1.3.0 >>> arr = numpy.empty(1, 'S2') >>> arr[0] = 'ab' >>> arr array(['ab'], dtype='|S2') >>> arr[0] = 'c\x00' >>> arr array(['c'], dtype='|S2') It seems that the string array is using the 00 character to pad strings smaller than the maximum size, and thus is treating any 00 characters at the end of a string as padding. Obviously, as long as I don't use smaller strings, there is no information lost here, but I don't want to have to re-add my 00s each time I ask the array what it is holding. Is this a well-known bug already? I couldn't find it on the NumPy bug tracker, but I could have easily missed it, or it could be triaged, deemed acceptable because there's no better way to deal with arbitrary-length strings. Is there an easy way to avoid this problem? Pretty much any performance-intensive part of my program is going to be dealing with these arrays, so I don't want to just replace them with a slower dictionary instead. I can't imagine this issue hasn't come up before; I encountered it by using NumPy arrays to store Python structs, something I can imagine is done fairly often. As such, I apologize for bringing it up again! Nathaniel From mail at microcorp.co.za Fri Jun 5 12:16:37 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 5 Jun 2009 18:16:37 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <4A280F90.7050506@wiggly.org> <002e01c9e5bf$ac3a83c0$0d00a8c0@Hendrik> <4A293B4A.1090000@wiggly.org> Message-ID: <000a01c9e5f9$19e18fc0$0d00a8c0@Hendrik> "Nigel Rantor" wrote: > Well, why not have a look at Gabriel's response. I have, and have responded at some length, further explaining what I am doing, and why. > That seems like a much more portable way of doing it if nothing else. There is nothing portable in what I am doing - it is aimed at the eBox, as the i/o stuff is specific to the Vortex processor. Even without the can and uncan, if you were to try to run it on any other machine, it would segfault because of the underlying C routines called via ctypes to access the non standard parallel port. > I'm not trolling, you just seem to be excited about something that > sounds like a fundamentally bad idea. Glad to hear it, and I am aware of the dangers, but I am aiming at a very specific speed objective, and I really cannot think of a way that achieves the result in fewer machine cycles than this weird way of passing an object, in a case such as mine. (barring of course writing the whole thing in C, which would never get the job done in time) - Hendrik From aahz at pythoncraft.com Fri Jun 5 12:37:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 09:37:09 -0700 Subject: numpy 00 character bug? References: Message-ID: In article , Nathaniel Rook wrote: > >I've recently encountered a bug in NumPy's string arrays, where the 00 >ASCII character ('\x00') is not stored properly when put at the end of a >string. You should ask about this on the NumPy mailing lists and/or report it on the NumPy tracker: http://scipy.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From Scott.Daniels at Acm.Org Fri Jun 5 12:47:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 09:47:44 -0700 Subject: Messing up with classes and their namespace In-Reply-To: References: Message-ID: Jean-Michel Pichavant wrote: > Hello world, > > I had recently a very nasty bug in my python application. The context is > quite complex, but in the end the problem can be resume as follow: > > 2 files in the same directory : > > lib.py: > >import foo > >foo.Foo.BOOM='lib' > > foo.py: > >class Foo: > > BOOM = 'Foooo' > > > >if __name__=='__main__': > > import lib # I'm expecting BOOM to be set to 'lib' > > print Foo.BOOM > > I was expecting 'lib' as output, but I got 'Fooo'. I don't really > understand what python mechanism I'm messing with but I have the feeling > I've misunderstood a very basic concept about class, namespace or > whatever import notion. > > I guess there is 2 different objects for the same class Foo. How I do I > make both Foo objects the same object ? OK, here is one solution (from which you may infer the problem): lib.py: import __main__ __main__.Foo.BOOM = 'lib' foo.py: class Foo: BOOM = 'Foooo' if __name__ == '__main__': import lib # I'm expecting BOOM to be set to 'lib' print(Foo.BOOM) Here is another solution: lib.py: import foo foo.Foo.BOOM = 'lib' foo.py: class Foo: BOOM = 'Foooo' if __name__ == '__main__': import sys sys.modules['foo'] = sys.modules['__main__'] import lib # I'm expecting BOOM to be set to 'lib' print(Foo.BOOM) Here is a demo of what is actually going wrong: foo.py: class Foo: inside = __name__ import foo if __name__ == '__main__': print(Foo is foo.Foo) print(Foo.inside, foo.Foo.inside) And here is a fix foo.py: if __name__ == '__main__': import sys sys.modules['foo'] = sys.modules['__main__'] class Foo: inside = __name__ import foo if __name__ == '__main__': print(Foo is foo.Foo) print(Foo.inside, foo.Foo.inside) --Scott David Daniels Scott.Daniels at Acm.Org From inVINCEable667 at gmail.com Fri Jun 5 13:02:59 2009 From: inVINCEable667 at gmail.com (inVINCable) Date: Fri, 5 Jun 2009 10:02:59 -0700 (PDT) Subject: Way to use proxies & login to site? References: <36bb20c2-2199-42bb-a123-171bf380182c@y10g2000prc.googlegroups.com> <629c75b1-9e67-44fb-9de0-0a23ff6c306b@v23g2000pro.googlegroups.com> Message-ID: On May 5, 12:51?pm, Kushal Kumaran wrote: > On Wed, Apr 29, 2009 at 8:21 AM, inVINCable wrote: > > On Apr 27, 7:40?pm, inVINCable wrote: > >> Hello, > > >> I have been using ClientForm to log in to sites & ClientCookie so I > >> can automatically log into my site to do some penetration testing, > >> although, I cannot figure out a solution to use proxies with this > >> logging in automatically. Does anyone have any solutions? > > >> Thanks :) > > >> Vince > > > Any ideas? > > If, like the example athttp://wwwsearch.sourceforge.net/ClientForm/, > you are using urllib2, you can read the documentation for that module. > ?It also has examples for working with proxies. > > -- > kushal Ok, I gotcha. Sounds neat, but the problem is, do you know if I can work with proxies and then connect to a site? From sevenbark at gmail.com Fri Jun 5 13:20:12 2009 From: sevenbark at gmail.com (Tom) Date: Fri, 05 Jun 2009 12:20:12 -0500 Subject: how to iterate over several lists? References: Message-ID: On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj wrote: > > >Suppose I have two lists, list_a and list_b, and I want to iterate >over both as if they were a single list. E.g. I could write: > >for x in list_a: > foo(x) >for x in list_b: > foo(x) > >But is there a less cumbersome way to achieve this? I'm thinking >of something in the same vein as Perl's: > >for $x in (@list_a, @list_b) { > foo($x); >} > >TIA! > >kynn def chain(*args): return (item for seq in args for item in seq) for x in chain(list_a, list_b): foo(x) From Scott.Daniels at Acm.Org Fri Jun 5 13:21:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 10:21:09 -0700 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > "Gabriel Genellina" wrote: > >> Ah... I had the same impression as Mr. Reedy, that you were directly >> reading from a socket and processing right there, so you *had* to use >> strings for everything. > > not "had to" - "chose to" - to keep the most used path as short as I could. > >> But if you already have a queue, you may put other objects there (instead >> of "canning" them). Testing the object type with isinstance(msg, str) is >> pretty fast, and if you bind locally those names I'd say the overhead is >> negligible. I can think of use cases for can, and from that use an alternate construct. The use case is passing a reference out over a wire (TCP port?) that will be used later. Sub cases: (1) Handing work over the wire along with a callback to invoke with the results. (2) Handing work over the wire along with a progress callback. (3) Handing work over the wire along with a pair of result functions, where the choice of functions is made on the far side of the wire. The "can" can be used to send the function(s) out. Alternatively, for use case 1: class Holder(object): def __init__(self): self.key = 0 self.holds = {} def handle(self, something): key = str(self.key) # may need to lock w/ next for threads self.key += 1 self.holds[key] = something return key def use(self, handle): return self.holds.pop(handle) Otherwise a simple dictionary with separate removal may be needed. If you might abandon an element w/o using it, use a weakref dictionary, but then you need a scheme to keep the thing alive long enough for needed operations (as you also need with a can). In use case 1, the dictionary becomes that holding point. The counter-as-key idea allows you to keep separate references to the same thing, so the reference is held for precisely as long as needed. It (counter-as-key) beats the str(id(obj)) of can because it tracks the actual object, not simply the id that can be reused. --Scott David Daniels Scott.Daniels at Acm.Org From nad at acm.org Fri Jun 5 13:22:41 2009 From: nad at acm.org (Ned Deily) Date: Fri, 05 Jun 2009 10:22:41 -0700 Subject: Yet another unicode WTF References: <8763fbmk5a.fsf@benfinney.id.au> Message-ID: In article , Ned Deily wrote: > In python 3.x, of course, the encoding happens automatically but you > still have to tell python, via the "encoding" argument to open, what the > encoding of the file's content is (or accept python's default which may > not be very useful): > > >>> open('foo1','w').encoding > 'mac-roman' > > WTF, indeed. BTW, I've opened a 3.1 release blocker issue about 'mac-roman' as a default on OS X. Hard to believe none of us has noticed this up to now! http://bugs.python.org/issue6202 -- Ned Deily, nad at acm.org From vend82 at virgilio.it Fri Jun 5 13:26:20 2009 From: vend82 at virgilio.it (Vend) Date: Fri, 5 Jun 2009 10:26:20 -0700 (PDT) Subject: multi-core software References: Message-ID: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> On Jun 4, 8:35?pm, Roedy Green wrote: > On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee > wrote, quoted or indirectly quoted someone who said : > > >? Why Must Software Be Rewritten For Multi-Core Processors? > > Threads have been part of Java since Day 1. ?Using threads complicates > your code, but even with a single core processor, they can improve > performance, particularly if you are doing something like combing > multiple websites. > > The nice thing about Java is whether you are on a single core > processor or a 256 CPU machine (We got to run our Athena Integer Java > spreadsheet engine on such a beast), does not concern your code. > > You just have to make sure your threads don't interfere with each > other, and Java/the OS, handle exploiting all the CPUs available. You need to decompose your problem in 256 independent tasks. It can be trivial for some problems and difficult or perhaps impossible for some others. From pruebauno at latinmail.com Fri Jun 5 13:38:51 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Fri, 5 Jun 2009 10:38:51 -0700 (PDT) Subject: DUDA !!!!!!!!!! References: Message-ID: <8ba8824a-11af-4a7a-9b2d-1d562a0bb9bd@l32g2000vba.googlegroups.com> On Jun 4, 2:51?pm, "Ariel Vazquez Riveron" wrote: > Hola: > ? Hoy en d?a me encuentro iniciandome dentro del python, en estos ? > momentos quiero saber de que forma puedo eliminar un archivo de un ? > compactado, ya sea zip, rar o cualquier otro. Estudie las librer?as ? > zipfile pero no tiene ninguna funcion que me permita hacerlo. Trabajo ? > con python 2.5 > > salu2 Ariel > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. En esta lista la mayoria no entiende castellano sino ingles. Mejor pregunta en esta lista: http://dir.gmane.org/gmane.org.user-groups.python.argentina From hdreschhoff at gmail.com Fri Jun 5 14:10:38 2009 From: hdreschhoff at gmail.com (Jan-Heiner Dreschhoff) Date: Fri, 5 Jun 2009 20:10:38 +0200 Subject: [wxpython] change the language of a menubar Message-ID: Hi Guys, i am new to wxpython an i have trouble with the menubar. i tried to write a dynamic menubar that can read the itemnames from an sqlite3 database, so i can change the language very easy. like this. def MakeMenuBar(self): self.dbCursor.execute("SELECT " + self.lang[self.langSelect] +" FROM menu") self.menuwords = self.dbCursor.fetchall() menu = wx.Menu() ##Filemenu item = menu.Append(ID_CONNECT, "%s" %self.menuwords[3]) . . . this works fine, when i draw the menu for the first time, when i want to change language in runtime, i can not get the menu to redraw. can someone help me out on this one? thanks heiner -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Jun 5 14:14:13 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Jun 2009 20:14:13 +0200 Subject: Messing up with classes and their namespace In-Reply-To: References: Message-ID: <4A296075.8090501@sequans.com> Scott David Daniels wrote: > Jean-Michel Pichavant wrote: >> Hello world, >> >> I had recently a very nasty bug in my python application. The context >> is quite complex, but in the end the problem can be resume as follow: >> >> 2 files in the same directory : >> >> lib.py: >> >import foo >> >foo.Foo.BOOM='lib' >> >> foo.py: >> >class Foo: >> > BOOM = 'Foooo' >> > >> >if __name__=='__main__': >> > import lib # I'm expecting BOOM to be set to 'lib' >> > print Foo.BOOM >> >> I was expecting 'lib' as output, but I got 'Fooo'. I don't really >> understand what python mechanism I'm messing with but I have the >> feeling I've misunderstood a very basic concept about class, >> namespace or whatever import notion. >> > >> I guess there is 2 different objects for the same class Foo. How I do >> I make both Foo objects the same object ? > > OK, here is one solution (from which you may infer the problem): > > lib.py: > import __main__ > __main__.Foo.BOOM = 'lib' > > foo.py: > class Foo: > BOOM = 'Foooo' > > if __name__ == '__main__': > import lib # I'm expecting BOOM to be set to 'lib' > print(Foo.BOOM) > > Here is another solution: > > lib.py: > import foo > foo.Foo.BOOM = 'lib' > > foo.py: > class Foo: > BOOM = 'Foooo' > > if __name__ == '__main__': > import sys > sys.modules['foo'] = sys.modules['__main__'] > import lib # I'm expecting BOOM to be set to 'lib' > print(Foo.BOOM) > > Here is a demo of what is actually going wrong: > > foo.py: > class Foo: > inside = __name__ > > import foo > > if __name__ == '__main__': > print(Foo is foo.Foo) > print(Foo.inside, foo.Foo.inside) > > And here is a fix > foo.py: > if __name__ == '__main__': > import sys > sys.modules['foo'] = sys.modules['__main__'] > > class Foo: > inside = __name__ > > import foo > > if __name__ == '__main__': > print(Foo is foo.Foo) > print(Foo.inside, foo.Foo.inside) > > > --Scott David Daniels > Scott.Daniels at Acm.Org Thanks for the explanation. I'll have to give it a second thought, I'm still missing something but I'll figure it out. Jean-Michel From kkylheku at gmail.com Fri Jun 5 14:15:00 2009 From: kkylheku at gmail.com (Kaz Kylheku) Date: Fri, 5 Jun 2009 18:15:00 +0000 (UTC) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> Message-ID: <20090617091529.242@gmail.com> On 2009-06-05, Vend wrote: > On Jun 4, 8:35?pm, Roedy Green > wrote: >> On Thu, 4 Jun 2009 09:46:44 -0700 (PDT), Xah Lee >> wrote, quoted or indirectly quoted someone who said : >> >> >? Why Must Software Be Rewritten For Multi-Core Processors? >> >> Threads have been part of Java since Day 1. ?Using threads complicates >> your code, but even with a single core processor, they can improve >> performance, particularly if you are doing something like combing >> multiple websites. >> >> The nice thing about Java is whether you are on a single core >> processor or a 256 CPU machine (We got to run our Athena Integer Java >> spreadsheet engine on such a beast), does not concern your code. >> >> You just have to make sure your threads don't interfere with each >> other, and Java/the OS, handle exploiting all the CPUs available. > > You need to decompose your problem in 256 independent tasks. > > It can be trivial for some problems and difficult or perhaps > impossible for some others. Even for problems where it appears trivial, there can be hidden issues, like false cache coherency communication where no actual sharing is taking place. Or locks that appear to have low contention and negligible performance impact on ``only'' 8 processors suddenly turn into bottlenecks. Then there is NUMA. A given address in memory may be RAM attached to the processor accessing it, or to another processor, with very different access costs. From minesh at gmail.com Fri Jun 5 14:37:49 2009 From: minesh at gmail.com (Minesh Patel) Date: Fri, 5 Jun 2009 11:37:49 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: On Fri, Jun 5, 2009 at 10:20 AM, Tom wrote: > On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj > wrote: > >> >> >>Suppose I have two lists, list_a and list_b, and I want to iterate >>over both as if they were a single list. ?E.g. I could write: >> >>for x in list_a: >> ? ?foo(x) >>for x in list_b: >> ? ?foo(x) >> >>But is there a less cumbersome way to achieve this? ?I'm thinking >>of something in the same vein as Perl's: >> >>for $x in (@list_a, @list_b) { >> ?foo($x); >>} >> >>TIA! >> >>kynn > > def chain(*args): > ?return (item for seq in args for item in seq) > > for x in chain(list_a, list_b): > ? ?foo(x) > -- > http://mail.python.org/mailman/listinfo/python-list > If they are the same length, you can try the zip built-in function. -- Thanks, --Minesh From grenander at gmail.com Fri Jun 5 15:04:47 2009 From: grenander at gmail.com (Art) Date: Fri, 5 Jun 2009 12:04:47 -0700 (PDT) Subject: distutils extension configuration problem References: Message-ID: On May 26, 11:10?pm, Ron Garret wrote: > I'm trying to build PyObjC on an Intel Mac running OS X 10.5.7. ?The > build is breaking because distutils seems to want to build extension > modules as universal binaries, but some of the libraries it depends on > are built for intel-only, i.e.: > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ python2.6 > setup.py build > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils > /dist.py:266: UserWarning: Unknown distribution option: 'options' > ? warnings.warn(msg) > running build > running build_py > running build_ext > building 'ScreenSaver._inlines' extension > gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g > -bundle -undefined dynamic_lookup > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o -o > build/lib.macosx-10.3-i386-2.6/ScreenSaver/_inlines.so -framework > ScreenSaver > ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file > is not of required architecture for architecture ppc > collect2: ld returned 1 exit status > lipo: can't open input file: > /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-//ccMFYRkt.out (No such > file or directory) > error: command 'gcc' failed with exit status 1 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o: Mach-O > universal binary with 2 architectures > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture ppc): Mach-O object ppc > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture i386): ? Mach-O object i386 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > /usr/local/lib/libtiff.dylib > /usr/local/lib/libtiff.dylib: Mach-O dynamically linked shared library > i386 > > How do I get distutils to stop trying to build extensions as universal > binaries? > > Thanks, > rg I have the same questions but haven't found anything. I got this idea from the apple site: http://developer.apple.com/releasenotes/OpenSource/PerlExtensionsRelNotes/index.html so I tried: env CFLAGS='-arch i386' LDFLAGS='-arch i386' python setup.py build and this removes the -arch ppc flags at least for the compiles but not the links. Maybe something in this direction will work. This didn't work: env ARCHFLAGS='-arch i386' python setup.py install Art From Scott.Daniels at Acm.Org Fri Jun 5 15:20:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 12:20:37 -0700 Subject: fastest way to test file for string? In-Reply-To: References: Message-ID: <79KdncqfhecO87TXnZ2dnUVZ_oGdnZ2d@pdx.net> Tim Chase wrote: >> Hi. I need to implement, within a Python script, [functionality like]: >> grep -rl some_string some_directory > > I'd do something like this untested function: > > def find_files_containing(base_dir, string_to_find): > for path, files, dirs in os.walk(base_dir): Note order wrong here > ... > > for filename in find_files_containing( > "/path/to/wherever/", > "some_string" > ): > print filename I like results in a nice order, so I do something more like: def find_files_containing(base_dir, string_to_find): for path, dirs, files in os.walk(base_dir): # note order for fname in sorted(files): # often endswith in here full_name = os.path.join(path, fname) try: with open(full_name) as f: for line in f: if string_to_find in line: yield full_name break except IOError, why: print ("On %s in %s: %s' % (fname, path, why)) # usually several subdirs to avoid dirs[:] = sorted([d for d in dirs if d[0] != '.' and d not in ('RCS', 'CVS')]) --Scott David Daniels Scott.Daniels at Acm.Org From skip at pobox.com Fri Jun 5 15:20:40 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 14:20:40 -0500 (CDT) Subject: Programming language comparison examples? Message-ID: <20090605192040.C5A6310ED608@montanaro.dyndns.org> I thought there was a website which demonstrated how to program a bunch of small problems in a number of different languages. I know about the Programming Language Shootout: http://shootout.alioth.debian.org/ but that's not what I was thinking of. I thought there was a site with a bunch of smaller examples. I'm looking for a site with this sort of information to pass along to my son who's entering his sophomore year of college, has one Java course under his belt, and will take a second course in the fall. I'm hoping to reach him before his brain turns to mush. ;-) Thx, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From dudekksoft at gmail.com Fri Jun 5 15:33:26 2009 From: dudekksoft at gmail.com (dudekksoft at gmail.com) Date: Fri, 5 Jun 2009 12:33:26 -0700 (PDT) Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On 1 Cze, 22:05, David Boddie wrote: > On Monday 01 June 2009 16:16, dudekks... at gmail.com wrote: > > > On 31 Maj, 02:32, David Boddie wrote: > >> So, you only want to handle certain links, and pass on to WebKit those > >> which you can't handle? Is that correct? > > > Yes, I want to handle external links (out of my host) and links > > starting with download://... (my specific protocol). > > If you want to handle them in a different way to normal Web pages, it seems > that calling setForwardUnsupportedContent(True) on the QWebPage is the way > to do it. > > However, if you want to handle those links and present the content for the > browser to render then you may need to override the browser's network access > manager, as discussed in this message: > > ?http://lists.trolltech.com/pipermail/qt-interest/2009-March/004279.html > > I experimented a little and added an example to the PyQt Wiki: > > ?http://www.diotavelli.net/PyQtWiki/Usinga Custom Protocol with QtWebKit > > I hope it helps to get you started with your own custom protocol. > > David Thank You David for Your help. You made a piece of good work :) From philip.groeger at googlemail.com Fri Jun 5 15:35:29 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Fri, 5 Jun 2009 21:35:29 +0200 Subject: Create multiple variables (with a loop?) Message-ID: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Hi, I need to create multiple variables (lets say 10x10x10 positions of atoms). Is it possible to create them through a loop with some kind of indexing like atom000, atom001, etc? Or is this a very bad idea? Thing is ... i want to create a grid of atoms in vpython and then calculate the forces for each of them (to their neighbours). Don't know how else I could do that. Maybe a huuuge matrix? Thx for your help! - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikle3 at gmail.com Fri Jun 5 15:42:02 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 12:42:02 -0700 (PDT) Subject: MD6 in Python Message-ID: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> As every one related to security probably knows, Rivest (and his friends) have a new hashing algorithm which is supposed to have none of the weaknesses of MD5 (and as a side benefit - not too many rainbow tables yet). His code if publicly available under the MIT license. Is there a reason not to add it to the standard lib, following the hashlib "protocol"? From clp2 at rebertia.com Fri Jun 5 15:43:15 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:43:15 -0700 Subject: Create multiple variables (with a loop?) In-Reply-To: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Message-ID: <50697b2c0906051243t36d0e6d0nc9b9c444484ca7a2@mail.gmail.com> On Fri, Jun 5, 2009 at 12:35 PM, Philip Gr?ger wrote: > Hi, > I need to create multiple variables (lets say 10x10x10 positions of atoms). > Is it possible to create them through a loop with some kind of indexing like > atom000, atom001, etc? > Or is this a very bad idea? Yes, very bad idea. Use a collection of some sort instead (list, dict, set). Dynamic variable names are usually evil. > Thing is ... i want to create a grid of atoms in vpython and then calculate > the forces for each of them (to their neighbours). Don't know how else I > could do that. Maybe a huuuge matrix? Yup, that sounds like a promising possibility. You might want to look at NumPy - http://numpy.scipy.org/ Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Fri Jun 5 15:45:48 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:45:48 -0700 Subject: Programming language comparison examples? In-Reply-To: <20090605192040.C5A6310ED608@montanaro.dyndns.org> References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: <50697b2c0906051245s42a3f5b8wba296c610607b1dc@mail.gmail.com> On Fri, Jun 5, 2009 at 12:20 PM, wrote: > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. ?I know about the > Programming Language Shootout: > > ? ?http://shootout.alioth.debian.org/ > > but that's not what I was thinking of. ?I thought there was a site with a > bunch of smaller examples. PLEAC (Programming Language Examples Alike Cookbook) is one option: http://pleac.sourceforge.net/ Cheers, Chris -- Hope my brain doesn't turn to mush. http://blog.rebertia.com From clp2 at rebertia.com Fri Jun 5 15:46:54 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 12:46:54 -0700 Subject: how to iterate over several lists? In-Reply-To: References: Message-ID: <50697b2c0906051246u78bf7d46uc79191e58b6a1eba@mail.gmail.com> On Fri, Jun 5, 2009 at 11:37 AM, Minesh Patel wrote: > On Fri, Jun 5, 2009 at 10:20 AM, Tom wrote: >> On Fri, 5 Jun 2009 04:07:19 +0000 (UTC), kj >> wrote: >> >>> >>> >>>Suppose I have two lists, list_a and list_b, and I want to iterate >>>over both as if they were a single list. ?E.g. I could write: >>> >>>for x in list_a: >>> ? ?foo(x) >>>for x in list_b: >>> ? ?foo(x) >>> >>>But is there a less cumbersome way to achieve this? ?I'm thinking >>>of something in the same vein as Perl's: >>> >>>for $x in (@list_a, @list_b) { >>> ?foo($x); >>>} >>> >>>TIA! >>> >>>kynn >> >> def chain(*args): >> ?return (item for seq in args for item in seq) >> >> for x in chain(list_a, list_b): >> ? ?foo(x) >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > If they are the same length, you can try the zip built-in function. But he doesn't want to iterate over them in parallel... Cheers, Chris -- http://blog.rebertia.com From bearophileHUGS at lycos.com Fri Jun 5 15:55:59 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Fri, 5 Jun 2009 12:55:59 -0700 (PDT) Subject: Programming language comparison examples? References: Message-ID: someone: > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. http://www.rosettacode.org/wiki/Main_Page http://en.literateprograms.org/LiteratePrograms:Welcome http://www.codecodex.com/wiki/index.php?title=Main_Page http://merd.sourceforge.net/pixel/language-study/scripting-language/ http://pleac.sourceforge.net/ http://www.angelfire.com/tx4/cus/shapes/index.html Bye, bearophile From kentilton at gmail.com Fri Jun 5 16:03:33 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Fri, 05 Jun 2009 16:03:33 -0400 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: References: Message-ID: <4a297a08$0$31258$607ed4bc@cv.net> Xah Lee wrote: > On Jun 3, 11:50 pm, Xah Lee wrote: >> Of interest: >> ? The Complexity And Tedium of Software Engineering >> http://xahlee.org/UnixResource_dir/writ/programer_frustration.html > > Addendum: > > The point in these short examples is not about software bugs or > problems. It illustrates, how seemingly trivial problems, such as > networking, transferring files, running a app on Mac or Windwos, > upgrading a app, often involves a lot subtle complexities. For mom and > pop users, it simply stop them dead. For a senior industrial > programer, it means some conceptually 10-minutes task often ends up in > hours of tedium. Quibble: those are not /tedious/. Those are as fascinating as an episode of House, trying not only to get new information but how to get it and how to figure out when some information already in hand is actually misinformation, a classic solution to hard problems. Also figuring out coincidences mistaken for cause and effect. But that is just a quibble, ie, I think you need a different word, and it is OK if it still conveys some form of unleasantness. Hair-pulling? Head-banging? > > In some ?theoretical? sense, all these problems are non-problems. But > in practice, these are real, non-trivial problems. These are > complexities that forms a major, multi-discipline, almost unexplored > area of software research. I'm trying to think of a name that > categorize this issue. I think it is a mix of software interface, > version control, release control, formal software specification, > automated upgrade system, etc. The ultimate scenario is that, if one > needs to transfer files from one machine to another, one really should > just press a button and expect everything to work. Software upgrade > should be all automatic behind the scenes, to the degree that users > really don't need fucking to know what so-called ?version? of software > he is using. I think you are looking for an immaculate road system on a volcanic island still growing ten feet a day. > > Today, with so-called ?exponential? scientific progress, and software > has progress tremendously too. In our context, that means there are a > huge proliferation of protocols and standards. For example, unicode, > gazillion networking related protocols, version control systems, > automatic update technologies, all comes into play here. However, in > terms of the above visionary ideal, these are only the beginning. > There needs to be more protocols, standards, specifications, and more > strict ones, and unified ones, for the ideal scenario to take place. But when would we write the software? Even with all the head-banging, look what we have been able to do with computers, leaving aside for the moment the flight control algorithms of the Airbus? When progress stops we will have time to polish our systems, not before. But then you will be able to use the word "tedium". kt From cylix at solace.info Fri Jun 5 16:04:45 2009 From: cylix at solace.info (Frederick Reeve) Date: Fri, 5 Jun 2009 15:04:45 -0500 Subject: python 3.1 - io.BufferedReader.peek() incomplete or change of behaviour. Message-ID: <20090605150445.417b3ecb@cylix> Hello, I have sent this message to the authors as well as to this list. If this is the wrong list please let me know where I should be sending it... dev perhaps? First the simple questions: The versions of io.BufferedReader.peek() have different behavior which one is going to stay long term? Is the C version of the reader incomplete or simply changing the behavior? lastly will you consider my input on the api (see below)? Now a full explanation. I am working on writing a multipart parser for html returns in python 3.1. The email parser being used by cgi does not work currently and cgi is broken at the moment especially when used with the wsgiref.simple_server as it is currently implemented. This is what has pushed me to write my own implementation to _part_ of cgi.py. My thinking being that if it works well in the end I might submit a patch as it needs one anyway. My questions revolve around io.BufferedReader.peek(). There are two implementations one writen in python and one in C. At least in python3.1 C is used by default. The version written in python behaves as follows: want = min(n, self.buffer_size) have = len(self._read_buf) - self._read_pos if have < want or have <= 0: to_read = self.buffer_size - have current = self.raw.read(to_read) if current: self._read_buf = self._read_buf[self._read_pos:] + current self._read_pos = 0 return self._read_buf[self._read_pos:] This basically means it will always return the requested number of bytes up to buffersize and will preform a read on the underlying stream to get extra data if the buffer has less than requested (upto full buffersize). It also will not return a longer buffer than the number of bytes requested. I have verified this is the behaviour of this. The C version works a little different. The C version works as follows: Py_ssize_t have, r; have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t); /* Constraints: 1. we don't want to advance the file position. 2. we don't want to lose block alignment, so we can't shift the buffer to make some place. Therefore, we either return `have` bytes (if > 0), or a full buffer. */ if (have > 0) { return PyBytes_FromStringAndSize(self->buffer + self->pos, have); } /* Fill the buffer from the raw stream, and copy it to the result. */ _BufferedReader_reset_buf(self); r = _BufferedReader_fill_buffer(self); if (r == -1) return NULL; if (r == -2) r = 0; self->pos = 0; return PyBytes_FromStringAndSize(self->buffer, r); Which basically means it returns what ever is in the buffer period. It will not fill the buffer any more from the raw stream to allow us to peek up to one buffersize like the python version and it always returns whats in the buffer regardless of how much you request. The only exception to this is if the buffer is empty. In that case it will read it full then return it. So it can be said this function is guaranteed to return 1 byte unless a raw read is not possible. The author says they cannot shift the buffer. This is true to retain file alignment. Double buffers maybe a solution if the python versions behavior is wanted. I have not yet checked how buffering is implemented fully. In writing the parser I found that being able to peek a number of bytes was helpful but I need to be able to peek more than 1 consistently (70 in my case) to meet the rfc I am implementing. This meant the C version of peek would not work. Fine I wrote a wrapper class that adds a buffer... This seemed dumb as I was already using a buffered reader so I detach the stream and use my wrapper. But now the logic and buffer handling is in the slower python where I would rather not have it. This defeats the purpose of the C buffer reader implementation almost. The C version still has a valid use for being able to read arbitrary size reads but that is really all the buffer reader is doing and I can do block oriented reads and buffering in my wrapper since I have to buffer anyway. Unless I only need a guaranteed peek of 1 byte (baring EOF, etc.) the c version doesn't seem very useful other than for random read cases. This is not a full explanation of course but may give you the picture as I see it. In light of the above and my questions I would like to give my input, hopefully to be constructive. This is what I think the api _should_ be the peek impementation. I may have missed things of course but none the less here it is: --------------------- read(n): Current be behavior read1(n): If n is greater than 0 return n or upto current buffer contents bytes advancing the stream position. If n is less than 0 or None return the the buffer contents and advance the position. If the buffer is empty and EOF has not been reached return None. If the buffer is empty and EOF has been reached return b''. peek(n): If n is less than 0 or None return buffer contents with out advancing stream position. Return n bytes up to _buffer size_(not contents) with out advancing the stream position. If the buffer contents is less than n, buffer an additional block from the "raw" stream before hand. This may require a double buffer or such. If EOF is encountered during the raw read then return return as much as we can upto n. leftover(): Return the number (an int) of bytes in the buffer. This is not strictly necessary with the new implementations of peek and read1 being like above but I thought still useful. I could be wrong and am not tied to this idea personally. --------------------- I feel that what I and possibly others would want from a _buffered reader_ is a best try behaviour. So the functions give you what you want except when its very bad or impossible to do so. Very bad meaning losing block alignment and imposible in this case being reading past EOF (or stream out of data). I'm sorry I'm probably not very good at explaining but I do try. I would love to here your input and I would be willing to work on patches for the C version of the buffered reader to implement this _if_ these changes are supported by the authors and the community and _if_ the authors will not will not write the changes but but still support them. Regardless I would need my questions answered if possible. Thanks so much! Frederick Reeve From geoff.bache at gmail.com Fri Jun 5 16:07:26 2009 From: geoff.bache at gmail.com (geoff.bache at gmail.com) Date: Fri, 5 Jun 2009 13:07:26 -0700 (PDT) Subject: A simpler logging configuration file format? Message-ID: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Hi all, I wonder if there are others out there who like me have tried to use the logging module's configuration file and found it bloated and over- complex for simple usage (i.e. a collection of loggers writing to files) At the moment, if I want to add a new logger "foo" writing to its own file "foo" to my config file, I have to repeat the name 7(!) times, editing 3 different sections in the process: 1) Add "foo" to [loggers] and [handlers]. (These seem completely pointless and were apparently added in anticipation of new functionality that never happened). 2) Create the section [logger_foo] handler:foo qualname:foo level:INFO 3) Create the section [handler_foo] class: FileHandler args:("foo", "a") Wondering how it got like this, I found this blog from soon after it was released in 2004: http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Python_s_logging_module Some of the verdicts are "full of dead chickens and error prone", "horribly complicated" , "over-engineered". So along comes the "basicConfig" method in 2005 which is supposed to address thes concerns. But this can only be applied globally, not even to individual loggers, so is only helpful for extremely basic usage (everything to one target) as far as I can see. The config file is still much as it was then. I'd really like to see the concept extended to encompass multiple loggers and the config file. Allowing Logger.basicConfig should be trivial. Writing a configuration format which took a section and passed all the options in it to basicConfig would in my view lead to a much friendlier syntax for normal usage. From lists at cheimes.de Fri Jun 5 16:46:02 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 05 Jun 2009 22:46:02 +0200 Subject: MD6 in Python In-Reply-To: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: mikle3 at gmail.com schrieb: > As every one related to security probably knows, Rivest (and his > friends) have a new hashing algorithm which is supposed to have none > of the weaknesses of MD5 (and as a side benefit - not too many rainbow > tables yet). His code if publicly available under the MIT license. > > Is there a reason not to add it to the standard lib, following the > hashlib "protocol"? Somebody has to write and add a md6 wrapper to the standard library. It's going to take some time, at least 18 months until Python 2.8 and 3.2 are going to be released. Do you need a wrapper for md6? I could easily write one in about an hour. Christian From david at boddie.org.uk Fri Jun 5 16:51:10 2009 From: david at boddie.org.uk (David Boddie) Date: Fri, 05 Jun 2009 22:51:10 +0200 Subject: PyQt4 + WebKit References: <1873ad4c-0461-4fe9-9430-86ae8affbf05@q2g2000vbr.googlegroups.com> Message-ID: On Friday 05 June 2009 21:33, dudekksoft at gmail.com wrote: > On 1 Cze, 22:05, David Boddie wrote: >> I experimented a little and added an example to the PyQt Wiki: >> >> http://www.diotavelli.net/PyQtWiki/Usinga Custom Protocol with QtWebKit >> >> I hope it helps to get you started with your own custom protocol. >> >> David > > Thank You David for Your help. You made a piece of good work :) No problem. I've since found some issues with another example I've been working on, so I may well update that page soon. :-) David From tjreedy at udel.edu Fri Jun 5 17:07:39 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 17:07:39 -0400 Subject: Messing up with classes and their namespace In-Reply-To: <4A296075.8090501@sequans.com> References: <4A296075.8090501@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Thanks for the explanation. I'll have to give it a second thought, I'm > still missing something but I'll figure it out. Perhaps it is this: 1. When you run foo.py as a script, the interpreter creates module '__main__' by executing the code in foo.py. 2. When that code does 'import lib', the interpreter looks for an existing module named 'lib', does not find it, and creates module 'lib' by executing the code in lib.py. 3. When that code does 'import foo', the interpreter looks for an existing module named 'foo', does not find it, and creates module 'foo' by executing (again) the code in foo.py. Module 'foo' is slightly different from module '__main__', created from the same code, because of the section conditioned by 'if __name__ == '__main__', that being the purpose of that incantation. But each of the two modules have their own class Foo. You sort of guessed this ... > I guess there is 2 different objects for the same class Foo. They are the same in content, but not in identify, until you change one of then. > How I do I make both Foo objects the same object ? As Scott hinted, by not making two of them, and you do that by not making two modules from the same file. Terry Jan Reedy From mikle3 at gmail.com Fri Jun 5 17:09:59 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 14:09:59 -0700 (PDT) Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: On Jun 5, 11:46?pm, Christian Heimes wrote: > mik... at gmail.com schrieb: > > > As every one related to security probably knows, Rivest (and his > > friends) have a new hashing algorithm which is supposed to have none > > of the weaknesses of MD5 (and as a side benefit - not too many rainbow > > tables yet). His code if publicly available under the MIT license. > > > Is there a reason not to add it to the standard lib, following the > > hashlib "protocol"? > > Somebody has to write and add a md6 wrapper to the standard library. > It's going to take some time, at least 18 months until Python 2.8 and > 3.2 are going to be released. > > Do you need a wrapper for md6? I could easily write one in about an hour. > > Christian It's not that I need it, I can sure use it. I can also write a wrapper myself. My secret agenda is too see if other people want it and write it as an addition to the standard lib, thus wetting my feet in Python Core Development without actually breaking anything :) From FSet.SLB at gmail.com Fri Jun 5 17:24:26 2009 From: FSet.SLB at gmail.com (Scott Burson) Date: Fri, 5 Jun 2009 14:24:26 -0700 (PDT) Subject: multi-core software References: Message-ID: On Jun 4, 9:46?am, Xah Lee wrote: > Of interest: > > ? Why Must Software Be Rewritten For Multi-Core Processors? > ?http://xahlee.org/UnixResource_dir/writ/multi-core_software.html > > plain text version follows. > > -------------------------------------------------- > Why Must Software Be Rewritten For Multi-Core Processors? > > Xah Lee, 2009-06-04 > > I had a revelation today, namely, that it is necessary to rewrite > software to use multi-processor in order to benefit from it. > > This may sound stupid, but is a revelation to me. For the past decade, > the question has been on my mind, about why should software needs to > be rewritten to take advantage of multi-processors. Because, in my > mind, i thought that software are at some fundamental level just > algorithms, and algorithms, have nothing to do with hardware > implementation aspects such as number of processors. I always felt, > that those talks about the need or difficulty of rewriting software > for multi-processor (or multi-core these days) must be the product of > idiocy of industrial imperative coding monkies. In particular, some > languages such as java, the way they deal with it, seems to me > extremely stupid. e.g. the concept of threads. In my mind, there > should be a layer between the software and the hardware, such as the > operating system, or the compiler, that should be able to > automatically handle or compile the software so that it FULLY use the > multi-processors when present. In short, i thought that a algorithm > really has nothing to do with hardware details. > > I never really thought hard about this issue, but today, since i got a > quad-core PC, so i looked into the issue, and thought about it, and i > realized the answer. The gist is that, algorithm, fundamentally means > manipulating some hardware, in fact, algorithm is a step by step > instruction about some form of hardware, even the hardware may be > abstract or virtual. For example, let's say the simplest case of 1+1. > It is a algorithm, but where is the hardware? You may say it's > abstract concept, or it being a mathematical model. What you call 1+1 > depends on the context, but in our context, those numbers are the > hardware. To see this, lets say more complex example of listing primes > by sieve. Again, it comes down to ?what is a number?? Here, numbers > can be stones, or arrangement of beads on abacus, it's hardware! As > another example, say sorting. To begin with, you have to have some > something to sort, that's hardware. > > Another way to see this is that, for a given computing problem, there > are infinite number of algorithms to achieve the same thing. Some, > will be better ones, requiring less steps, or requiring less storage. > All these are concrete manipulation issues, and the thing being > manipulated, ultimately we have to call it hardware. So, when hardware > changes, say from one cpu to multi-cpu, there's no way for the > algorithm to magically change and adopt the changed hardware. If you > need a algorithm that is catered to the new hardware, you need a new > algorithm. > > One might think that there might be algorithm Omega, such that it > takes input of old hardware O, new hardware N, and a algorithm A, and > output a algorithm B, such that B has the same behavior as A, but N+B > performs better than O+A. This is like asking for Strong AI. > > One thing we often forgot is that algorithms ultimately translates to > manipulating hardware. In a modern digital computer, that means > software algorithms ultimately becomes machine instructions in CPU, > which manipulate the 1s and 0s in register, or electricity voltage in > transisters. > > In a more mundane point of view, a automatic system for software to > work on multi-processors is a problem of breaking a problem into > discrete units (so that they can be computed in parallel). The problem > of finding a algorithm is entirely different from the problem of > breaking a problem into distinct units. The problem of breaking a > problem into distinct units is a entire new branch of mathematics. For > example, let's say factoring. Factoring is a well defined mathematical > problem. There are millions algorithms to do it, each class has > different properties such as number of steps or storage units. > However, if we look at these algorithms from the point of view of > distinct units, it's a new perspective on classification of > algorithms. Software are in general too ill-defined and fuzzy and > complex, the software we use on personal computers such as email, > browsers, games, don't even have mathematical models. They don't even > have mathematical models of their inputs and outputs. To talk about > automatic system of unitizing software, would be more like a AI > fantasy. Roughly, a term that describes this aspect of research is > Parallel computing. > > In the Wikipedia article, it talks about types of parallelism: Bit- > level parallelism, Instruction-level parallelism, Data parallelism, > Task parallelism. Then it also discusses hardware aspects classes: > multicore, symmetric multiprocessing, distributed computing, cluster, > grid. The subjects mentioned there more close to this essay are ?data > parallelism? and ?task parallelism?. However, neither are high level > enough as i discussed here. The issue discussed here would be like > ?algorithmic parallelism?. Indeed, Wikipedia mentioned ?Automatic > parallelization?, which is exactly what i'm talking about here. Quote: > > ? ? Automatic parallelization of a sequential program by a compiler is > the holy grail of parallel computing. Despite decades of work by > compiler researchers, automatic parallelization has had only limited > success.[40] > > ? ? Mainstream parallel programming languages remain either explicitly > parallel or (at best) partially implicit, in which a programmer gives > the compiler directives for parallelization. A few fully implicit > parallel programming languages exist ? SISAL, Parallel Haskell, and > (for FPGAs) Mitrion-C. > > It says ?A few fully implicit parallel programming languages exist?. > If you are a comp lang nutcase, don't get carried away by what those > words might seem to mean. > > (Note: Wikipedia has a dedicated article on the subject: Automatic > parallelization) > > ? Xah > ?http://xahlee.org/ > > ? From tjreedy at udel.edu Fri Jun 5 17:38:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 17:38:19 -0400 Subject: Adding a Par construct to Python? In-Reply-To: References: <52152a4a-334a-40d0-ad57-4b348d40eb0c@o20g2000vbh.googlegroups.com> <02200d22$0$20645$c3e8da3@news.astraweb.com> <_vidnQW0dJoGg43XnZ2dnUVZ_hpi4p2d@posted.usinternet> <0220260f$0$20645$c3e8da3@news.astraweb.com> <77as23F1fhj3uU1@mid.uni-berlin.de> Message-ID: Lawrence D'Oliveiro wrote: > In message <77as23F1fhj3uU1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: > >>> But reduce()? I can't see how you can parallelize reduce(). By its >>> nature, it has to run sequentially: it can't operate on the nth item >>> until it is operated on the (n-1)th item. >> That depends on the operation in question. Addition for example would >> work. My math-skills are a bit too rusty to qualify the exact nature of >> the operation, commutativity springs to my mind. > > Associativity: > > ((A op B) op C) = (A op (B op C)) > > So for example > > A op B op C op D > > could be grouped into > > (A op B) op (C op D) > > and the two parenthesized subexpressions evaluated concurrently. But this > would only give you a speedup that was logarithmic in the number of op's. It is worth noting, I think, that many realistic operations are not associative. If op combines a summary and an item to create an updated summary, it will probably croak or give a wrong answer when given a summary and a summary. Combining two summaries might be possible, but would be a different operation. For a specific example, consider list.append(some_list, some_item) versus list.extend(some_list, another_list). Imagine for that moment that these methods returned some_list. Then [].append(a).append(b).append(c).append(d) # parentheses left out would have to be conceptually converted to the associative [].extend([a]).extend([b]).extend([c]).extend([d]) before being grouped something like (([].extend([a])).extend([b].extend([c]))).extend([d]) Of course, one would not do the conversion to the slower associative operation unless one knew that there would be a compensating speedup due to the grouping. Terry Jan Reedy From robert.kern at gmail.com Fri Jun 5 17:38:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Jun 2009 16:38:56 -0500 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: On 2009-06-05 16:09, mikle3 at gmail.com wrote: > On Jun 5, 11:46 pm, Christian Heimes wrote: >> mik... at gmail.com schrieb: >> >>> As every one related to security probably knows, Rivest (and his >>> friends) have a new hashing algorithm which is supposed to have none >>> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >>> tables yet). His code if publicly available under the MIT license. >>> Is there a reason not to add it to the standard lib, following the >>> hashlib "protocol"? >> Somebody has to write and add a md6 wrapper to the standard library. >> It's going to take some time, at least 18 months until Python 2.8 and >> 3.2 are going to be released. >> >> Do you need a wrapper for md6? I could easily write one in about an hour. >> >> Christian > > It's not that I need it, I can sure use it. I can also write a wrapper > myself. > My secret agenda is too see if other people want it and write it as an > addition to the standard lib, thus wetting my feet in Python Core > Development without actually breaking anything :) My gut feeling is that it's too new. In a year, the current round of the SHA-3 competition will be over, you will have much more information about how MD6 fares against its competitors, and you will still have some time to get it into Python 2.8/3.2. We don't actually *know* that it doesn't have equivalent weaknesses until the cryptanalysts try to break it for a year or so. :-) -- 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 Fri Jun 5 17:57:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Jun 2009 14:57:20 -0700 (PDT) Subject: numpy 00 character bug? References: Message-ID: <971181bd-062f-481c-8e71-fd566edeb49a@s21g2000vbb.googlegroups.com> On Jun 5, 9:14?am, Nathaniel Rook wrote: > Hello, all! > > I've recently encountered a bug in NumPy's string arrays, where the 00 > ASCII character ('\x00') is not stored properly when put at the end of a > string. > > For example: > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import numpy > ?>>> print numpy.version.version > 1.3.0 > ?>>> arr = numpy.empty(1, 'S2') > ?>>> arr[0] = 'ab' > ?>>> arr > array(['ab'], > ? ? ? ?dtype='|S2') > ?>>> arr[0] = 'c\x00' > ?>>> arr > array(['c'], > ? ? ? ?dtype='|S2') > > It seems that the string array is using the 00 character to pad strings > smaller than the maximum size, and thus is treating any 00 characters at > the end of a string as padding. ?Obviously, as long as I don't use > smaller strings, there is no information lost here, but I don't want to > have to re-add my 00s each time I ask the array what it is holding. I am going to guess that it is done this way for the sake of interoperability with Fortran, and that it is deliberate behavior. Also, if it were accidental behavior, then it would probably happen for internal nul bytes, but it doesn't. The workaround I recommend is to add a superfluous character on the end: >>> numpy.array(['a\0x'],'S3') array(['a\x00x'], dtype='|S3') Then chop off the last character. (However it might turn out that padding as necessary performs better.) > Is this a well-known bug already? ?I couldn't find it on the NumPy bug > tracker, but I could have easily missed it, or it could be triaged, > deemed acceptable because there's no better way to deal with > arbitrary-length strings. ?Is there an easy way to avoid this problem? > Pretty much any performance-intensive part of my program is going to be > dealing with these arrays, so I don't want to just replace them with a > slower dictionary instead. > > I can't imagine this issue hasn't come up before; I encountered it by > using NumPy arrays to store Python structs, something I can imagine is > done fairly often. ?As such, I apologize for bringing it up again! I doubt a very high percentage of people who use numpy do character manipulation, so I could see it as something that hasn't come up before. Carl Banks From tjreedy at udel.edu Fri Jun 5 18:06:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:06:09 -0400 Subject: Odd closure issue for generators In-Reply-To: <4A292D70.9020801@sweetapp.com> References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> Message-ID: Brian Quinlan wrote: > > Sorry, I wasn't as precise as I should have been. > > If you consider this example: > ( for x in y) > > I thought that every time that was evaluated, it would be done in > a new closure with x bound to the value of x at the time that the > closure was created. > > Instead, a new closure is created for the entire generator expression > and x is updated inside that closure. Thanks you for explaining your confusion. Knowing what sort of other-language-baggage people are being mislead by can only help in explaining Python. But here is my question. In Python, g = ( for x in iterable) is essentially an abbreviation for, and means the same as def _(it): for x in it: yield g = _(iterable) del _ Are there language in which a similar construct has an essentially different meaning? Terry Jan Reedy From castironpi at gmail.com Fri Jun 5 18:43:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 5 Jun 2009 15:43:55 -0700 (PDT) Subject: fastest way to test file for string? References: Message-ID: <084363ef-d2ee-41bd-910b-fdb1c920c9c6@m19g2000yqk.googlegroups.com> On Jun 5, 5:50?am, kj wrote: > Hi. ?I need to implement, within a Python script, the same > functionality as that of Unix's > > ? ?grep -rl some_string some_directory > > I.e. find all the files under some_directory that contain the string > "some_string". snip The 'mmap.mmap' class has a 'find' method. Not what you asked for, put possibly an alternative. No regex 'search' method either. From tjreedy at udel.edu Fri Jun 5 18:50:53 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:50:53 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Christian Heimes wrote: > mikle3 at gmail.com schrieb: >> As every one related to security probably knows, Rivest (and his >> friends) have a new hashing algorithm which is supposed to have none >> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >> tables yet). His code if publicly available under the MIT license. >> >> Is there a reason not to add it to the standard lib, following the >> hashlib "protocol"? > > Somebody has to write and add a md6 wrapper to the standard library. > It's going to take some time, at least 18 months until Python 2.8 and 2.7 is next From tjreedy at udel.edu Fri Jun 5 18:53:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 18:53:21 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Robert Kern wrote: > On 2009-06-05 16:09, mikle3 at gmail.com wrote: >> It's not that I need it, I can sure use it. I can also write a wrapper >> myself. >> My secret agenda is too see if other people want it and write it as an >> addition to the standard lib, thus wetting my feet in Python Core >> Development without actually breaking anything :) > > My gut feeling is that it's too new. In a year, the current round of the > SHA-3 competition will be over, you will have much more information > about how MD6 fares against its competitors, and you will still have A wrapper could go on PyPI now so it can be tested in use *before* going in the stdlib. No commit or pre-review needed either. From iamelgringo at gmail.com Fri Jun 5 19:17:36 2009 From: iamelgringo at gmail.com (Jonathan Nelson) Date: Fri, 5 Jun 2009 16:17:36 -0700 (PDT) Subject: Feedparser Problem References: <985f7729-c301-40d9-b712-d671c136dd1e@k38g2000yqh.googlegroups.com> Message-ID: Thanks for the responses. I've tried the same script on a Server 2003 install, and Python 2.5 and it ran without a hitch. So, it's either a problem with Python 2.6 or with Windows 7. Thanks for all the responses. You've been great. Best, Jonathan On Jun 5, 7:39?am, Jonathan Nelson wrote: > I'm working with Feedparser on months old install of Windows 7, and > now programs that ran before are broken, and I'm getting wierd > messages that are rather opaque to me. ? Google, Bing, News groups > have all left me empty handed. > > I was wondering if I could humbly impose upon the wizards of > comp.lang.python to lend me their wisdom and insight to this problem > that is too difficult for my little mind. > > Here's what I'm going through: > > >>>from feedparser import parse > >>>url='http://feeds.nytimes.com/nyt/rss/Technology' > >>>url2='http://feeds.washingtonpost.com/wp-dyn/rss/technology/index_xml' > >>>d = parse(url) > >>>d2= parse(url2) > >>>d > > {'bozo':1, > 'bozo_exception': TypeError("__init__() got an unexpected keyword > argument 'timeout'",), > 'encoding': 'utf-8', > 'entries': [], > 'feed':{}, > 'version': None}>>>d2 > > {'bozo': 1, > ?'bozo_exception': TypeError("__init__() got an unexpected keyword > argument 'timeout'",), > ?'encoding': 'utf-8', > ?'entries': [], > ?'feed': {}, > ?'version': None} > > I've checked my firewall settings, and python is allowed. ?Other > python programs can get data from the web. ?I know that the 'bozo' is > for malformed xml. ?I've searched through both of those rss feeds, and > I can't find the argument 'timeout' anywhere in them. > > Any ideas, thoughts or directions in which I might go? > > Thanks to all in advance, > Jonathan From see_website at mindprod.com.invalid Fri Jun 5 19:26:37 2009 From: see_website at mindprod.com.invalid (Roedy Green) Date: Fri, 05 Jun 2009 16:26:37 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> Message-ID: <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku wrote, quoted or indirectly quoted someone who said : >Even for problems where it appears trivial, there can be hidden >issues, like false cache coherency communication where no actual >sharing is taking place. Or locks that appear to have low contention and >negligible performance impact on ``only'' 8 processors suddenly turn into >bottlenecks. Then there is NUMA. A given address in memory may be >RAM attached to the processor accessing it, or to another processor, >with very different access costs. Could what you are saying be summed up by saying, "The more threads you have the more important it is to keep your threads independent, sharing as little data as possible." -- Roedy Green Canadian Mind Products http://mindprod.com Never discourage anyone... who continually makes progress, no matter how slow. ~ Plato 428 BC died: 348 BC at age: 80 From lists at cheimes.de Fri Jun 5 19:46:28 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 01:46:28 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy schrieb: > Christian Heimes wrote: >> mikle3 at gmail.com schrieb: >>> As every one related to security probably knows, Rivest (and his >>> friends) have a new hashing algorithm which is supposed to have none >>> of the weaknesses of MD5 (and as a side benefit - not too many rainbow >>> tables yet). His code if publicly available under the MIT license. >>> >>> Is there a reason not to add it to the standard lib, following the >>> hashlib "protocol"? >> >> Somebody has to write and add a md6 wrapper to the standard library. >> It's going to take some time, at least 18 months until Python 2.8 and > > 2.7 is next > 2.7rc1 is already out. There is no way a new piece of code will land in the 2.7 release. Christian From lists at cheimes.de Fri Jun 5 19:47:21 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 01:47:21 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy wrote: > A wrapper could go on PyPI now so it can be tested in use *before* going > in the stdlib. No commit or pre-review needed either. Here you go http://pypi.python.org/pypi/md6 It's still a bit rough, totally untested but it should work. Christian From aahz at pythoncraft.com Fri Jun 5 20:01:31 2009 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2009 17:01:31 -0700 Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: In article , Christian Heimes wrote: >Terry Reedy schrieb: >> Christian Heimes wrote: >>> >>> Somebody has to write and add a md6 wrapper to the standard library. >>> It's going to take some time, at least 18 months until Python 2.8 and >> >> 2.7 is next > >2.7rc1 is already out. There is no way a new piece of code will land in >the 2.7 release. Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is that 2.7 is mostly restricted to code landed in 3.1, so your second statement is roughly correct. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Given that C++ has pointers and typecasts, it's really hard to have a serious conversation about type safety with a C++ programmer and keep a straight face. It's kind of like having a guy who juggles chainsaws wearing body armor arguing with a guy who juggles rubber chickens wearing a T-shirt about who's in more danger." --Roy Smith, c.l.py, 2004.05.23 From Scott.Daniels at Acm.Org Fri Jun 5 20:14:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 05 Jun 2009 17:14:47 -0700 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Christian Heimes wrote: > ... > 2.7rc1 is already out. There is no way a new piece of code will land in > the 2.7 release. > > Christian 3.1rc1 is out, but 2.7 is not even in alpha. See pep 373 for the 2.7 schedule; 3.1's schedule is on pep 375. --Scott David Daniels Scott.Daniels at Acm.Org From lists at cheimes.de Fri Jun 5 20:17:39 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 06 Jun 2009 02:17:39 +0200 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is > that 2.7 is mostly restricted to code landed in 3.1, so your second > statement is roughly correct. Oh, d...! Of course you are right, Aahz. As far as I can remember 2.7 will only contain backports of 3.1 features or features related to 2to3 migration. Christian From tjreedy at udel.edu Fri Jun 5 20:30:55 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Jun 2009 20:30:55 -0400 Subject: MD6 in Python In-Reply-To: References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: Aahz wrote: > Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is > that 2.7 is mostly restricted to code landed in 3.1, so your second > statement is roughly correct. My understanding is that 2.7 will come out about the same time as 3.2 and will contain 3.2 backports also. New features are being marked on the issue tracker as for 2.7/3.2. There may or may not be a 2.8. (It was once intended that 2.7 come out with 3.1, but that changed when it was decided to cut the life of 3.0 and bring out 3.1 after 6 months.) tjr From vend82 at virgilio.it Fri Jun 5 20:49:38 2009 From: vend82 at virgilio.it (Vend) Date: Fri, 5 Jun 2009 17:49:38 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <1489cda9-cb03-4159-8cfe-021895da251f@j18g2000yql.googlegroups.com> On Jun 6, 1:26?am, Roedy Green wrote: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : > > >Even for problems where it appears trivial, there can be hidden > >issues, like false cache coherency communication where no actual > >sharing is taking place. Or locks that appear to have low contention and > >negligible performance impact on ``only'' 8 processors suddenly turn into > >bottlenecks. Then there is NUMA. A given address in memory may be > >RAM attached to the processor accessing it, or to another processor, > >with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." Besides technical issues such as cache conflicts and synchronization latencies, there are more theoretical issues of task decomposability. It seems it is not always feasible to decompose an algorithm into subprograms that can be executed in parallel. From rcdailey at gmail.com Fri Jun 5 20:53:50 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 17:53:50 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> Message-ID: <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> On Jun 5, 10:31?am, Peter Otten <__pete... at web.de> wrote: > Robert Dailey wrote: > > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: > >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey > >> escribi?: > > >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > >> > URL: > > >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > >> > Have it save the ZIP to any destination directory. For me, this only > >> > downloads about 40KB before it stops without any error at all. Any > >> > reason why this isn't working? > > >> I could not reproduce it. I downloaded about 300K without error ?(Python > >> 3.0.1 on Windows) > > >> -- > >> Gabriel Genellina > > > Can you show me your test code please? > > Here's mine: > > $ cat retriever.py > import urllib.request > import os > > def report(*args): > ? ? print(args) > > url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1..." > filename = url.rsplit("/")[-1] > > urllib.request.urlretrieve(url, filename=filename, reporthook=report) > print(os.path.getsize(filename)) > $ > > If you had shown your code in the first place the problem might have been solved by now... > > Peter Well I did not post the code because it is fairly complex and its hard to give you the whole picture without giving you too much code. But here you go, you get what you ask for: def Download( self ): PrintSubStatus( 'Downloading...' ) destination = normalize( '{0}/{1}'.format( self._info.outdir, self._info.file_ext ) ) print( self._info.url ) print( destination ) urlretrieve( self._info.url, destination ) Both print statements are shown as below: http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip I really can't figure out why this isn't working. From michele.simionato at gmail.com Fri Jun 5 21:24:19 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 5 Jun 2009 18:24:19 -0700 (PDT) Subject: Odd closure issue for generators References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> Message-ID: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> On Jun 6, 12:06?am, Terry Reedy wrote: > Brian Quinlan wrote: > > > Sorry, I wasn't as precise as I should have been. > > > If you consider this example: > > ( for x in y) > > > I thought that every time that was evaluated, it would be done in > > a new closure with x bound to the value of x at the time that the > > closure was created. > > > Instead, a new closure is created for the entire generator expression > > and x is updated inside that closure. > > Thanks you for explaining your confusion. ?Knowing what sort of > other-language-baggage people are being mislead by can only help in > explaining Python. ?But here is my question. ?In Python, > > g = ( for x in iterable) > > is essentially an abbreviation for, and means the same as > > def _(it): > ? ?for x in it: > ? ? ?yield > g = _(iterable) > del _ > > Are there language in which a similar construct has an essentially > different meaning? > > Terry Jan Reedy Yes, most functional languages have the concept of streams. You can even define a stream-comprehension that looks like Python generator comprehension but it is an essentially different thing. See for instance http://www.artima.com/weblogs/viewpost.jsp?thread=251159 From skip at pobox.com Fri Jun 5 21:32:43 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 5 Jun 2009 20:32:43 -0500 Subject: Programming language comparison examples? In-Reply-To: References: Message-ID: <18985.51003.874220.895047@montanaro.dyndns.org> >> http://www.rosettacode.org/wiki/Main_Page >> http://en.literateprograms.org/LiteratePrograms:Welcome >> http://www.codecodex.com/wiki/index.php?title=Main_Page >> http://merd.sourceforge.net/pixel/language-study/scripting-language/ >> http://pleac.sourceforge.net/ >> http://www.angelfire.com/tx4/cus/shapes/index.html Thanks for the extensive list of sites! Skip From rcdailey at gmail.com Fri Jun 5 21:34:00 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 18:34:00 -0700 (PDT) Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: On Jun 5, 7:53?pm, Robert Dailey wrote: > On Jun 5, 10:31?am, Peter Otten <__pete... at web.de> wrote: > > > > > > > Robert Dailey wrote: > > > On Jun 5, 3:47 am, "Gabriel Genellina" wrote: > > >> En Thu, 04 Jun 2009 23:42:29 -0300, Robert Dailey > > >> escribi?: > > > >> > Hey guys, try using urlretrieve() in Python 3.0.1 on the following > > >> > URL: > > > >> >http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1... > > > >> > Have it save the ZIP to any destination directory. For me, this only > > >> > downloads about 40KB before it stops without any error at all. Any > > >> > reason why this isn't working? > > > >> I could not reproduce it. I downloaded about 300K without error ?(Python > > >> 3.0.1 on Windows) > > > >> -- > > >> Gabriel Genellina > > > > Can you show me your test code please? > > > Here's mine: > > > $ cat retriever.py > > import urllib.request > > import os > > > def report(*args): > > ? ? print(args) > > > url = "http://softlayer.dl.sourceforge.net/sourceforge/wxwindows/wxMSW-2.8.1..." > > filename = url.rsplit("/")[-1] > > > urllib.request.urlretrieve(url, filename=filename, reporthook=report) > > print(os.path.getsize(filename)) > > $ > > > If you had shown your code in the first place the problem might have been solved by now... > > > Peter > > Well I did not post the code because it is fairly complex and its hard > to give you the whole picture without giving you too much code. But > here you go, you get what you ask for: > > ? ?def Download( self ): > ? ? ? PrintSubStatus( 'Downloading...' ) > ? ? ? destination = normalize( '{0}/{1}'.format( self._info.outdir, > self._info.file_ext ) ) > ? ? ? print( self._info.url ) > ? ? ? print( destination ) > ? ? ? urlretrieve( self._info.url, destination ) > > Both print statements are shown as below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10... > D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip > > I really can't figure out why this isn't working. Wow how stupid... I was using: mxMSW-2.8.10.zip There is an "m" at the front, and it needs to be "w". wxMSW-2.8.10.zip This URL isn't even valid, can't believe I didn't get an exception! From gokhansever at gmail.com Fri Jun 5 21:44:29 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Fri, 5 Jun 2009 20:44:29 -0500 Subject: Create multiple variables (with a loop?) In-Reply-To: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> Message-ID: <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> You could use locals() for dynamic variable names creation. Additionally, you can give to Mayavi a try for visualization of your data: http://code.enthought.com/projects/mayavi/ G?khan On Fri, Jun 5, 2009 at 2:35 PM, Philip Gr?ger wrote: > Hi, > I need to create multiple variables (lets say 10x10x10 positions of atoms). > Is it possible to create them through a loop with some kind of indexing like > atom000, atom001, etc? > Or is this a very bad idea? > > Thing is ... i want to create a grid of atoms in vpython and then calculate > the forces for each of them (to their neighbours). Don't know how else I > could do that. Maybe a huuuge matrix? > > Thx for your help! > - Philip > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rcdailey at gmail.com Fri Jun 5 21:56:52 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 18:56:52 -0700 (PDT) Subject: Scope objects Message-ID: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Is it possible to create an object in Python that will clean itself up at function exit? I realize destruction of objects may not occur immediately and can be garbage collected, but this functionality would still be great to have. Consider the following function: def do_stuff(): foo = scope_object() # Do stuff... foo.Cleanup() It would be nice to avoid the explicit "Cleanup()" call above, and have 'foo' just act as if it has a C++ destructor and evoke some method at the exit point of a function. From clp2 at rebertia.com Fri Jun 5 21:57:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 18:57:52 -0700 Subject: Create multiple variables (with a loop?) In-Reply-To: <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> References: <386f361c0906051235p65852adao8e0be916efe39e7b@mail.gmail.com> <49d6b3500906051844w13e926a6s98a110263bf98ec5@mail.gmail.com> Message-ID: <50697b2c0906051857j9e95b61r57701a23b1ae4bd@mail.gmail.com> On Fri, Jun 5, 2009 at 6:44 PM, G?khan SEVER wrote: > You could use locals() for dynamic variable names creation. Not really. Quoting http://docs.python.org/library/functions.html#locals (emphasis mine): locals() Update and return a dictionary representing the current local symbol table. Note: The contents of this dictionary should not be modified; **changes may not affect the values of local variables used by the interpreter**. It does happen to work it certain cases, but it should not be relied upon. Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Fri Jun 5 22:06:26 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 06 Jun 2009 14:06:26 +1200 Subject: urlretrieve() failing on me In-Reply-To: References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: <78u16mF1l5n4qU1@mid.individual.net> Robert Dailey wrote: > This URL isn't even valid, can't believe I didn't get an exception! My guess is that if you look at the data it downloaded, you'll find it's a 404 response page or something similar. -- Greg From apt.shansen at gmail.com Fri Jun 5 22:07:03 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Jun 2009 19:07:03 -0700 Subject: Scope objects In-Reply-To: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <7a9c25c20906051907p34369d4ak1da12107ae4bdb14@mail.gmail.com> On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > foo = scope_object() > # Do stuff... > foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. Generally, in CPython at least, 'foo' -would- be destroyed immediately with the Reference Counting semantics, and thus you could just do whatever cleanup you needed to in __del__. This isn't the case for other Python implementations. Its sorta best to not rely on reference counting, but.. sometimes its nice. Otherwise your only option is the "with statement" in 2.5 (using "from __future__ import with_statement") or 2.6. In that, you would do: def do_stuff(): with scope_object(): stuff The object returned by scope_object() would have its __enter__() and __exit__() methods called right away. That's the official way to do 'cleaning up code' really these days. If you need to access the scope object, you'd do "with scope_object() as foo:" HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Jun 5 22:07:58 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Jun 2009 19:07:58 -0700 Subject: Scope objects In-Reply-To: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <50697b2c0906051907w64b45969hf54b155f51f2394e@mail.gmail.com> On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > ? ?foo = scope_object() > ? ?# Do stuff... > ? ?foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. This is exactly what the new `with` statement lets you do. You just need to define an appropriate context manager. With one, you can code that as: def do_stuff(): with scope_object() as foo: #do stuff More info: http://www.python.org/dev/peps/pep-0343/ Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:16:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:16:27 GMT Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: <0045ac0e$0$9732$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 01:47:21 +0200, Christian Heimes wrote: > Terry Reedy wrote: >> A wrapper could go on PyPI now so it can be tested in use *before* >> going in the stdlib. No commit or pre-review needed either. > > Here you go http://pypi.python.org/pypi/md6 > > It's still a bit rough, totally untested but it should work. Oh you're a cruel, cruel man! The OP wanted to do that :) -- Steven From sjmachin at lexicon.net Fri Jun 5 22:16:53 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 5 Jun 2009 19:16:53 -0700 (PDT) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: On Jun 6, 5:45?am, Chris Rebert wrote: > PLEAC (Programming Language Examples Alike Cookbook) is one option:http://pleac.sourceforge.net/ """The latest version of Python is 2.4""" Appears to be a translation of parts of the Perl Cookbook: """Examples which translate the original Perl closely but which are unPythonic are prefixed with a comment stating "DON'T DO THIS".""" From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:19:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:19:20 GMT Subject: how to iterate over several lists? References: Message-ID: <0045acbb$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 11:37:49 -0700, Minesh Patel wrote: >> def chain(*args): >> ?return (item for seq in args for item in seq) >> >> for x in chain(list_a, list_b): >> ? ?foo(x) >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > If they are the same length, you can try the zip built-in function. Which does something *completely different* from what the Original Poster was asking for. Given alist = [1, 2, 3], blist = [4, 5, 6], the OP wants to process: 1, 2, 3, 4, 5, 6 but zip will give: (1, 3), (2, 5), (3, 6) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:19:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:19:45 GMT Subject: fastest way to test file for string? References: Message-ID: <0045acd4$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 17:37:25 +0200, Hendrik van Rooyen wrote: > "kj" wrote: >> >> Hi. I need to implement, within a Python script, the same >> functionality as that of Unix's >> >> grep -rl some_string some_directory >> >> I.e. find all the files under some_directory that contain the string >> "some_string". >> >> I imagine that I can always resort to the shell for this, but is there >> an efficient way of doing it within Python? >> >> (BTW, portability is not high on my list here; this will run on a Unix >> system, and non-portable Unix-specific solutions are fine with me.) > > Use grep. You will not beat it's performance. What makes you think that performance of the find itself is the only, or even the main, consideration? -- Steven From greg at cosc.canterbury.ac.nz Fri Jun 5 22:20:03 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 06 Jun 2009 14:20:03 +1200 Subject: how to create a big list of list In-Reply-To: <4gI9c7$wD1@alexbbs.twbbs.org> References: <4gI9c7$wD1@alexbbs.twbbs.org> Message-ID: <78u20aF1npma3U1@mid.individual.net> command.bbs at alexbbs.twbbs.org wrote: > i have try [ [] for x in xrange(2**25) ] Are you really going to be adding data to all of those sublists? If you're only using them sparsely, it may be better to use a dictionary in place of the top level list, and only add sublists as and when necessary. Recent Python versions have a built-in type called defaultdict that makes this kind of thing easy. -- Greg From gagsl-py2 at yahoo.com.ar Fri Jun 5 22:21:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 23:21:40 -0300 Subject: Making the case for repeat References: Message-ID: En Fri, 05 Jun 2009 08:04:37 -0300, pataphor escribi?: > But what is simple? I am currently working on a universal feature > creeper that could replace itertools.cycle, itertools.repeat, > itertools.chain and reverse and also helps to severely cut down on > itertools.islice usage. All within virtually the same parameter > footprint as the last function I posted. The problem is posting *this* > function would kill my earlier repeat for sure. And it already had a > problem with parameters < 0 (Hint: that last bug has now become a > feature in the unpostable repeat implementation) Plans to conquer the world, second desk, over there. -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Fri Jun 5 22:32:48 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 02:32:48 GMT Subject: Making the case for repeat References: Message-ID: <0045afe3$0$9732$c3e8da3@news.astraweb.com> On Fri, 05 Jun 2009 23:21:40 -0300, Gabriel Genellina wrote: > En Fri, 05 Jun 2009 08:04:37 -0300, pataphor > escribi?: > >> But what is simple? I am currently working on a universal feature >> creeper that could replace itertools.cycle, itertools.repeat, >> itertools.chain and reverse and also helps to severely cut down on >> itertools.islice usage. All within virtually the same parameter >> footprint as the last function I posted. The problem is posting *this* >> function would kill my earlier repeat for sure. And it already had a >> problem with parameters < 0 (Hint: that last bug has now become a >> feature in the unpostable repeat implementation) > > Plans to conquer the world, second desk, over there. He'll have to go to the end of the queue though. Why is it that it's (almost) always newbies with about five minutes' worth of experience with Python that come up with these grandiose plans to replace entire modules with a single function? -- Steven From gagsl-py2 at yahoo.com.ar Fri Jun 5 22:39:02 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Jun 2009 23:39:02 -0300 Subject: python way to automate IE8's File Download dialog References: <4a290592$0$17084$ba4acef3@news.orange.fr> Message-ID: En Fri, 05 Jun 2009 09:46:25 -0300, <""Michel Claveau - MVP"> escribi?: > Suppose that the (web) site give the file only after several seconds, > and after the user click a confirm (example: RapidFile). > Suppose that the (web) site give the file only after the user input a > code, controled by a javascript script. The (web) site only receives HTTP requests; javascript runs only on the client side. If you generate an equivalent HTTP request in code, you're done. By example, the wait timer and captcha of rapidshare can be easily skipped; but the "no more than one download per IP" limitation cannot, because it is enforced on the server side. Of course, figuring out how to do that in each particular case has a cost (time and required skills), and it may be more convenient to do browser automation as you imply. -- Gabriel Genellina From pavlovevidence at gmail.com Fri Jun 5 23:05:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 5 Jun 2009 20:05:08 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <858c9c29-ce01-4707-869e-9cf9754fc72c@l28g2000vba.googlegroups.com> On Jun 4, 6:44?pm, "Gabriel Genellina" wrote: > En Thu, 04 Jun 2009 10:37:45 -0300, pataphor escribi?: > > > So here is my proposed suggestion for a once and for all reconciliation > > of various functions in itertools that can not stand on their own and > > keep a straight face. Because of backwards compatibility issues we > > cannot remove them but we can boldly jump forward and include the right > > repeat in the builtin namespace, which I think would be the best thing. > > Alternatively -- the second best solution -- would be to give this > > function its own namespace where it can supersede the old incongruencies > > in itertools. Combiniter or combinator? > > Ok, you're proposing a "bidimensional" repeat. I prefer to keep things > simple, and I'd implement it in two steps. That's brings up a good software engineering question: What is better, to have one function with lots of functionality, or many functions with a single functionality? Before anyone follows up with the obvious answer, hear me out. Small functions that do one thing well are almost always a good thing, but there is a significant benefit to cramming a lot of functionality into one function: it forces you to hit all corners of a problem. That is, at least for problems where it makes sense to hit all the corners of the input space. The subprocess module is the best example of this. Pretty much any combination of arguments to subprocess.Popen makes sense. If I want to spawn a process with pipes to standard input and standard error, but not standard output, that allows me to specify a custom environment, that uses no buffering, and that goes through the shell... I can! Not so with the mish-mash of other calls. By having a single function doing all that it enabled all those combinations, something that wouldn't have happened with lots of small functions. (I suddenly wonder what other languages have such easy versatilty in spawning subprocesses.) So... there is something to be said for pataphor's unified repeat function. Having said that, the nature of iterators is that they are easily recombinable. This is very much unlike the different options with subprocesses. It's not like you can make an extra call just to tack on some behavior to a simple subprocess-spawning function, but with iterators you can. In fact, iterators are (almost) orthogonally recombinable; the whole input space of a problem can be spanned simply by combining simple iterators. So, I will have to ultimately agree with Gabriel: itertools are best kept simple and complex interator behavior like you suggest is best done by combining simple iterators. Carl Banks From rcdailey at gmail.com Fri Jun 5 23:16:31 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Fri, 5 Jun 2009 20:16:31 -0700 (PDT) Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: On Jun 5, 9:07?pm, Chris Rebert wrote: > On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > > Is it possible to create an object in Python that will clean itself up > > at function exit? I realize destruction of objects may not occur > > immediately and can be garbage collected, but this functionality would > > still be great to have. Consider the following function: > > > def do_stuff(): > > ? ?foo = scope_object() > > ? ?# Do stuff... > > ? ?foo.Cleanup() > > > It would be nice to avoid the explicit "Cleanup()" call above, and > > have 'foo' just act as if it has a C++ destructor and evoke some > > method at the exit point of a function. > > This is exactly what the new `with` statement lets you do. You just > need to define an appropriate context manager. With one, you can code > that as: > > def do_stuff(): > ? ? with scope_object() as foo: > ? ? ? ? #do stuff > > More info: ?http://www.python.org/dev/peps/pep-0343/ > > Cheers, > Chris > --http://blog.rebertia.com Thanks! This is PERFECT! From mikle3 at gmail.com Sat Jun 6 00:11:19 2009 From: mikle3 at gmail.com (mikle3 at gmail.com) Date: Fri, 5 Jun 2009 21:11:19 -0700 (PDT) Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> <0045ac0e$0$9732$c3e8da3@news.astraweb.com> Message-ID: On Jun 6, 5:16?am, Steven D'Aprano wrote: > On Sat, 06 Jun 2009 01:47:21 +0200, Christian Heimes wrote: > > Terry Reedy wrote: > >> A wrapper could go on PyPI now so it can be tested in use *before* > >> going in the stdlib. ?No commit or pre-review needed either. > > > Here you gohttp://pypi.python.org/pypi/md6 > > > It's still a bit rough, totally untested but it should work. > > Oh you're a cruel, cruel man! The OP wanted to do that :) > > -- > Steven Hehe, well I sure did learn my lesson here :) I guess I can still say it was my idea, and the fact that someone done is good for the community. I'll just have to find something else and not tell you bastards about it. From gagsl-py2 at yahoo.com.ar Sat Jun 6 00:43:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 01:43:37 -0300 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> <4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik> <4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> <004201c9e5f3$c6809920$0d00a8c0@Hendrik> Message-ID: En Fri, 05 Jun 2009 12:33:04 -0300, Hendrik van Rooyen escribi?: > "Gabriel Genellina" wrote: > >> But if you already have a queue, you may put other objects there >> (instead >> of "canning" them). Testing the object type with isinstance(msg, str) is >> pretty fast, and if you bind locally those names I'd say the overhead is >> negligible. > > Maybe you are right and I am pre optimising - but the heart of this > box really is that silly loop and the processor really is not fast at > all. From your description of the problem, it seems you are acting upon messages received from a serial port. You have to process the message *before* the next one arrives -- but you gain nothing doing that much faster. In other words, even with a blazingly fast processor, you can't do things faster than the rate of incoming messages. In any case, you have to test-and-branch in the code. Either with isinstance(rec,str), either with rec_list[0]=="B", or something. I'm unsure if this is the fastest approach - intuition doesn't play well with timings in Python, better to actually measure times. > This is what I was trying to avoid, as it is important to get as much > performance out of the box as I can (given that I am using Python to > get the job done fast, because that is also important). So it is a kind > of > juggling with priorities - "make it fast" would imply do not use python, > but "get it done quickly" implies using python, and it looks to me that > if I am careful and think more like an assembler programmer, the > real time performance will be adequate. And I do not want to do > anything that could conceivably compromise that. Even if it means > jumping through a funny hoop like I am doing now, and inventing > a weird way to pass an object. If it works and you feel it's adequate, that's fine. I cannot count how many times I've used an integer property to attach a pointer to another object (in other languages), but I felt "dirty" doing that. And never did something like that in Python... > So to a large extent I think that I am doing the job as fast as it is > possible - the comma delimited input string is a fact, decided on > between myself and the customer a long time ago, and it comes over > a socket, so it has to be a string. The least I can do with it is > nothing > before I put it on the critical queue. Then when it comes out of the > queue, I have to break it up into its constituent parts, and I would > think > that split is the canonical way of doing that. Ok, what if you split *before* putting in the queue? In the receiving side of the queue, just remove the split(",") part (it's already done). This does not add anything to the critical path - the split must be done anyway. Now, instead of building a fake string "B,cannedobject" and uncanning on the other side, you can simply put a tuple in the queue ("B", the_object) and just get the object on the other side. If I'm not misunderstanding your problem, I think this is the cleanest way to do that. -- Gabriel Genellina From ajith at iuac.res.in Sat Jun 6 01:34:10 2009 From: ajith at iuac.res.in (Ajith Kumar) Date: Sat, 06 Jun 2009 11:04:10 +0530 Subject: Error in linalg.inv ?? Message-ID: <4A29FFD2.1030609@iuac.res.in> Hello, I ran the following code (Using Debian 5.0) from numpy import * a = arange(1.,10.) b = reshape(a, [3,3]) c = linalg.inv(b) print b print c print dot(b,c) print dot(c,b) And the result is [[ 1. 2. 3.] [ 4. 5. 6.] [ 7. 8. 9.]] [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] [[-0.5 -1. -1. ] [-1. -2. 2. ] [-1.5 -3. 1. ]] [[ 5.5 8. 10.5] [ 3. 0. -3. ] [ -1. 0. -3. ]] NOT the identity matrix. Any help ? Thanks Ajith Kumar From s0suk3 at gmail.com Sat Jun 6 02:03:34 2009 From: s0suk3 at gmail.com (s0suk3 at gmail.com) Date: Fri, 5 Jun 2009 23:03:34 -0700 (PDT) Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> Message-ID: <78711541-1fe7-4201-9bee-c31747e86d7c@k2g2000yql.googlegroups.com> On Jun 5, 8:56?pm, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consider the following function: > > def do_stuff(): > ? ? foo = scope_object() > ? ? # Do stuff... > ? ? foo.Cleanup() > > It would be nice to avoid the explicit "Cleanup()" call above, and > have 'foo' just act as if it has a C++ destructor and evoke some > method at the exit point of a function. I don't know what you mean by: "I realize destruction of objects may not occur immediately and can be garbage collected" Aren't you just missing ordinary destructors (__del__() methods)? These are closest to C++ destructors AFAICS. As far as I know, these are guaranteed to be called when an object goes out of scope. (Note that destruction and garbage collection are different operations; an object may be destructed without being immediately garbage-collected afterwards.) >>> import sys >>> class Simple: ... def __init__(self): sys.stdout.write("Simple.__init__()\n") ... def __del__(self): sys.stdout.write("Simple.__del__()\n") ... >>> def f(): ... s = Simple() ... sys.stdout.write("f()\n") ... # 's' now going out of scope... ... >>> f() Simple.__init__() f() Simple.__del__() >>> Sebastian From gagsl-py2 at yahoo.com.ar Sat Jun 6 02:15:39 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 03:15:39 -0300 Subject: python 3.1 - io.BufferedReader.peek() incomplete or change of behaviour. References: <20090605150445.417b3ecb@cylix> Message-ID: En Fri, 05 Jun 2009 17:04:45 -0300, Frederick Reeve escribi?: > I have sent this message to the authors as well as to this list. If > this is the wrong list please let me know where I should be sending > it... dev perhaps? I think the best place is the bug tracker: http://bugs.python.org/ -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Sat Jun 6 02:44:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 18:44:01 +1200 Subject: spammers on pypi References: Message-ID: In message , joep wrote: > Is there a way to ban spammers from pypi? Yes, but it doesn't work. From sanal.vikram at gmail.com Sat Jun 6 02:58:27 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Fri, 5 Jun 2009 23:58:27 -0700 (PDT) Subject: openhook Message-ID: Can anybody tell me what is meant by 'openhook' ? From zac256 at gmail.com Sat Jun 6 03:08:42 2009 From: zac256 at gmail.com (Zac Burns) Date: Sat, 6 Jun 2009 00:08:42 -0700 Subject: __file__ access extremely slow In-Reply-To: References: Message-ID: <333edbe80906060008r6f9dea51jc674988148cff6f9@mail.gmail.com> I think I have figured this out, thanks for your input. The time comes from lazy modules related to e-mail importing on attribute access, which is acceptable. Hence of course why ImportError was sometime raised. I originally was thinking that accessing __file__ was triggering some mechanism that caused an attempt at importing other modules, but the lazy import explanation makes much more sense. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Fri, Jun 5, 2009 at 2:15 AM, Gabriel Genellina wrote: > En Fri, 05 Jun 2009 00:12:25 -0300, John Machin > escribi?: > >>> > (2) This will stop processing on the first object in sys.modules that >>> > doesn't have a __file__ attribute. Since these objects aren't >>> > *guaranteed* to be modules, >> >> Definitely not guaranteed to be modules. Python itself drops non-modules >> in >> there! Python 2.3 introduced four keys mapped to None -- one of these was >> dropped in 2.4, but the other three are still there in 2.5 and 2.6: > > In case someone wonders what all those None are: they're a "flag" telling > the import machinery that those modules don't exist (to avoid doing a > directory scan over and over, because Python<2.7 attempts first to do a > relative import, and only if unsuccessful attempts an absolute one) > >> C:\junk>\python23\python -c "import sys; print [k for (k, v) in >> sys.modules.items() if v is None]" >> ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions', >> 'encodings.types'] > > In this case, somewhere inside the encodings package, there are statements > like "import types" or "from types import ...", and Python could not find > types.py in the package directory. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From sjmachin at lexicon.net Sat Jun 6 03:15:36 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 6 Jun 2009 00:15:36 -0700 (PDT) Subject: Error in linalg.inv ?? References: Message-ID: <34f2bdc6-353d-48dd-a3af-cf3dd43fe41d@3g2000yqk.googlegroups.com> On Jun 6, 3:34?pm, Ajith Kumar wrote: > Hello, > ?I ran the following code (Using Debian 5.0) > > from numpy import * > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. ?2. ?3.] > ?[ 4. ?5. ?6.] > ?[ 7. ?8. ?9.]] > > [[ ?3.15221191e+15 ?-6.30442381e+15 ? 3.15221191e+15] > ?[ -6.30442381e+15 ? 1.26088476e+16 ?-6.30442381e+15] > ?[ ?3.15221191e+15 ?-6.30442381e+15 ? 3.15221191e+15]] > > [[-0.5 -1. ?-1. ] > ?[-1. ?-2. ? 2. ] > ?[-1.5 -3. ? 1. ]] > > [[ ?5.5 ? 8. ? 10.5] > ?[ ?3. ? ?0. ? -3. ] > ?[ -1. ? ?0. ? -3. ]] > > NOT the identity matrix. Any help ? It's a longer time than I care to divulge since I took courses in matrix algebra, but I do have a vague recollection that if determinant (B) is zero, inverse(B) is not defined ... seeing the rows and columns in B are linear (as are those of C), IIRC that means the determinants are zero, and you are out of luck. Are you ignoring exceptions? Is that _exactly_ what you typed in? Try running it again, print the calculated determinants of B and C, and tell what version of (a) numpy (b) Python you are using. Isn't there a mailing list for numpy? HTH, John From nick at craig-wood.com Sat Jun 6 03:29:40 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 02:29:40 -0500 Subject: Error in linalg.inv ?? References: Message-ID: Ajith Kumar wrote: > I ran the following code (Using Debian 5.0) > > from numpy import * > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > [[-0.5 -1. -1. ] > [-1. -2. 2. ] > [-1.5 -3. 1. ]] > > [[ 5.5 8. 10.5] > [ 3. 0. -3. ] > [ -1. 0. -3. ]] > > NOT the identity matrix. Any help ? The matrix you are trying to invert is singular (can't be inverted), ie its determinant is zero. >> a = arange(1.,10.) >>> b = reshape(a, [3,3]) >>> linalg.det(b) -9.5171266700777579e-16 >>> Which is zero but with a bit of rounding errors which I guess numpy doesn't notice. Double checking like this >>> a,b,c,d,e,f,g,h,i=range(1,10) >>> a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g 0 >>> So I guess it is a bug that numpy didn't throw numpy.linalg.linalg.LinAlgError("Singular matrix") Like it does normally -- Nick Craig-Wood -- http://www.craig-wood.com/nick From verec at mac.com Sat Jun 6 03:34:45 2009 From: verec at mac.com (verec) Date: Sat, 6 Jun 2009 08:34:45 +0100 Subject: The Complexity And Tedium of Software Engineering References: <4a297a08$0$31258$607ed4bc@cv.net> Message-ID: <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> On 2009-06-05 21:03:33 +0100, Kenneth Tilton said: > When progress stops we will have time to polish our systems, not before. Is that an endorsement of mediocrity? -- JFB From __peter__ at web.de Sat Jun 6 04:00:04 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Jun 2009 10:00:04 +0200 Subject: urlretrieve() failing on me References: <49edfa67-1818-411f-b3be-6cf2c5c96255@j32g2000yqh.googlegroups.com> <84918d26-3f6d-4b05-8228-e87a1a91195b@c19g2000yqc.googlegroups.com> Message-ID: Robert Dailey wrote: >> Well I did not post the code because it is fairly complex and its hard >> to give you the whole picture without giving you too much code. But >> here you go, you get what you ask for: >> >> def Download( self ): >> PrintSubStatus( 'Downloading...' ) >> destination = normalize( '{0}/{1}'.format( self._info.outdir, >> self._info.file_ext ) ) >> print( self._info.url ) >> print( destination ) >> urlretrieve( self._info.url, destination ) >> >> Both print statements are shown as >> below:http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10... >> D:\IT\personal\haresvn\temp\mxMSW-2.8.10.zip >> >> I really can't figure out why this isn't working. > > Wow how stupid... I was using: > > mxMSW-2.8.10.zip > > There is an "m" at the front, and it needs to be "w". Time and again posting the code does help ;) > wxMSW-2.8.10.zip > > This URL isn't even valid, can't believe I didn't get an exception! Sourceforge is (un)helpfully redirecting your request and Python is (un)helpfully following. I looks like you can avoid this by using a URLopener instead of the FancyURLopener implicitly used by urlretrieve(): >>> URLopener().retrieve("http://easynews.dl.sourceforge.net/sourceforge/wxwindows/mxMSW-2.8.10.zip", filename="tmp.zip") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.0/urllib/request.py", line 1476, in retrieve fp = self.open(url, data) File "/usr/lib/python3.0/urllib/request.py", line 1444, in open return getattr(self, name)(url) File "/usr/lib/python3.0/urllib/request.py", line 1622, in open_http return self._open_generic_http(http.client.HTTPConnection, url, data) File "/usr/lib/python3.0/urllib/request.py", line 1618, in _open_generic_http response.status, response.reason, response.msg, data) File "/usr/lib/python3.0/urllib/request.py", line 1638, in http_error return self.http_error_default(url, fp, errcode, errmsg, headers) File "/usr/lib/python3.0/urllib/request.py", line 1644, in http_error_default raise HTTPError(url, errcode, errmsg, headers, None) urllib.error.HTTPError: HTTP Error 302: Found Peter From kushal.kumaran+python at gmail.com Sat Jun 6 04:16:09 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sat, 6 Jun 2009 13:46:09 +0530 Subject: Way to use proxies & login to site? In-Reply-To: References: <36bb20c2-2199-42bb-a123-171bf380182c@y10g2000prc.googlegroups.com> <629c75b1-9e67-44fb-9de0-0a23ff6c306b@v23g2000pro.googlegroups.com> Message-ID: <1e364c4e0906060116u31bed4e9x71155fe7e36d9f68@mail.gmail.com> On Fri, Jun 5, 2009 at 10:32 PM, inVINCable wrote: > On May 5, 12:51?pm, Kushal Kumaran wrote: >> On Wed, Apr 29, 2009 at 8:21 AM, inVINCable wrote: >> > On Apr 27, 7:40?pm, inVINCable wrote: >> >> Hello, >> >> >> I have been using ClientForm to log in to sites & ClientCookie so I >> >> can automatically log into my site to do some penetration testing, >> >> although, I cannot figure out a solution to use proxies with this >> >> logging in automatically. Does anyone have any solutions? >> >> >> Thanks :) >> >> >> Vince >> >> > Any ideas? >> >> If, like the example athttp://wwwsearch.sourceforge.net/ClientForm/, >> you are using urllib2, you can read the documentation for that module. >> ?It also has examples for working with proxies. >> > > Ok, I gotcha. Sounds neat, but the problem is, do you know if I can > work with proxies and then connect to a site? You can, if you read the examples section in the urllib2 documentation. http://docs.python.org/library/urllib2.html -- kushal From milesck at umich.edu Sat Jun 6 04:23:44 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 6 Jun 2009 04:23:44 -0400 Subject: Winter Madness - Passing Python objects as Strings In-Reply-To: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: > A can is like a pickle, in that it is a string, but anything > can be canned. > Unlike a pickle, a can cannot leave the process, though, > unless the object it points to lives in shared memory. > > If you have any interest, contact me and I will > send you the source. Sounds like di(), which can be written: import _ctypes di = _ctypes.PyObj_FromPtr def can(o): return str(id(o)) def uncan(s): return di(int(s)) http://www.friday.com/bbum/2007/08/24/python-di/ -Miles From raw at RawMBP.local Sat Jun 6 04:59:06 2009 From: raw at RawMBP.local (Raymond Wiker) Date: Sat, 06 Jun 2009 10:59:06 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Roedy Green writes: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : > >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." Absolutely... not a new observation, either, as it follows directly from Amdahl's law. From mail at microcorp.co.za Sat Jun 6 05:37:50 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 11:37:50 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik> Message-ID: <00ac01c9e699$a79340c0$0d00a8c0@Hendrik> "Scott David Daniels" wrote: > I can think of use cases for can, and from that use an alternate > construct. The use case is passing a reference out over a wire > (TCP port?) that will be used later. This will work, provided the thing is still alive and in the same place when the can eventually finds its way back and gets uncanned. As it is now, no attempt has been made to handle refcounting issues. > Sub cases: > (1) Handing work over the wire along with a callback to invoke > with the results. > (2) Handing work over the wire along with a progress callback. > (3) Handing work over the wire along with a pair of result functions, > where the choice of functions is made on the far side of the wire. > > The "can" can be used to send the function(s) out. > Alternatively, for use case 1: > > class Holder(object): > def __init__(self): > self.key = 0 > self.holds = {} > def handle(self, something): > key = str(self.key) # may need to lock w/ next for threads > self.key += 1 > self.holds[key] = something > return key > def use(self, handle): > return self.holds.pop(handle) This is nice - you are making a simple index. Dammit! why did I not think of something like this - It keeps it all in Python, without a C extension. In my case I would need a global so that I would know where to look it up in, but that is a non issue as it can be made at startup. I really should keep the maxim in mind: There is no problem in computer science that can not be solved by means of the introduction of another layer of indirection. :-) Thanks for this post Scott - it has helped to straighten out my one track minded thinking - I got hung up on the idea of passing the reference, to the extent that I expended what was for me heroic effort to get it across. What causes me real chagrin is that I am already keeping a list of queues - the active queue list that keeps the list of output queues for the various clients that have connected. And I am too dim witted to think of a dict... > > Otherwise a simple dictionary with separate removal may be needed. > If you might abandon an element w/o using it, use a weakref dictionary, > but then you need a scheme to keep the thing alive long enough > for needed operations (as you also need with a can). In my use case the queue would have stayed alive because the thread that created it would have kept it going until it was no longer needed, as would the reference created by the binding of the local name in the thread. > > In use case 1, the dictionary becomes that holding point. > The counter-as-key idea allows you to keep separate references > to the same thing, so the reference is held for precisely as long > as needed. It (counter-as-key) beats the str(id(obj)) of can > because it tracks the actual object, not simply the id that can > be reused. The can just looks like str(id(obj)) - at the C level, it actually comes from the PyObject *, gets stringified, and the uncan returns the original PyObject *. So if I understand it correctly, after the uncanning, it __is__ the original object. (if it is still there) As I said above, I have paid no attention to refcounting issues, - it really needs someone knowledgeable to work over my C code, as this was my first venture into the wonderful world of extending python. But it hardly seems worth while now... - Hendrik From gagsl-py2 at yahoo.com.ar Sat Jun 6 05:44:47 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Jun 2009 06:44:47 -0300 Subject: Scope objects References: <6b2ea723-ccf7-42c4-bdc3-71cfdd6794a0@f19g2000yqo.googlegroups.com> <78711541-1fe7-4201-9bee-c31747e86d7c@k2g2000yql.googlegroups.com> Message-ID: En Sat, 06 Jun 2009 03:03:34 -0300, escribi?: > On Jun 5, 8:56?pm, Robert Dailey wrote: >> Is it possible to create an object in Python that will clean itself up >> at function exit? I realize destruction of objects may not occur >> immediately and can be garbage collected, but this functionality would >> still be great to have. > > I don't know what you mean by: > > "I realize destruction of objects may not occur immediately and can be > garbage collected" > > Aren't you just missing ordinary destructors (__del__() methods)? > These are closest to C++ destructors AFAICS. As far as I know, these > are guaranteed to be called when an object goes out of scope. (Note > that destruction and garbage collection are different operations; an > object may be destructed without being immediately garbage-collected > afterwards.) No, that's not how it works in Python (and I think you're mistaken for C++ too). See http://docs.python.org/reference/datamodel.html and specially http://docs.python.org/reference/datamodel.html#object.__del__ "Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether." CPython uses a "reference count" scheme - an object is destroyed as soon as it loses its last reference. Other implementations may choose another strategy - in fact, Jython relies on garbage collection instead; object destruction may be delayed an arbitrary amount of time. (CPython has a garbage collector too, but its purpose is to detect and break object cycles.) So the OP is right - you can't rely on object destruction to perform any cleanup; use try/finally or a with statement instead. >>>> import sys >>>> class Simple: > ... def __init__(self): sys.stdout.write("Simple.__init__()\n") > ... def __del__(self): sys.stdout.write("Simple.__del__()\n") > ... >>>> def f(): > ... s = Simple() > ... sys.stdout.write("f()\n") > ... # 's' now going out of scope... > ... >>>> f() > Simple.__init__() > f() > Simple.__del__() This behaviour isn't guaranteed and you should not rely on it. Also, try again with: def f(): s = Simple() t = Simple() s.x = t t.x = s sys.stdout.write("f()\n") -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Sat Jun 6 06:41:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 22:41:23 +1200 Subject: A simpler logging configuration file format? References: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Message-ID: In message <30db8a0b-5b19-47e4-9364-54cbd7a7cacf at h23g2000vbc.googlegroups.com>, geoff.bache at gmail.com wrote: > At the moment, if I want to add a new logger "foo" writing to its own > file "foo" to my config file, I have to repeat the name 7(!) times, > editing 3 different sections in the process: I suppose there's always the Sendmail solution: stick an m4 wrapper on top to hide the details of the process. :) From ldo at geek-central.gen.new_zealand Sat Jun 6 06:42:14 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 06 Jun 2009 22:42:14 +1200 Subject: Christian Audigier Bikinis References: Message-ID: In message , tanvon19 at gmail.com wrote: > Please check our web ... Wow, you have a web. I always wanted to have one of those. From davea at ieee.org Sat Jun 6 06:45:13 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Jun 2009 06:45:13 -0400 Subject: Messing up with classes and their namespace In-Reply-To: <4A296075.8090501@sequans.com> References: <4A296075.8090501@sequans.com> Message-ID: <4A2A48B9.1050307@ieee.org> Jean-Michel Pichavant wrote: >
Scott > David Daniels wrote: >> Jean-Michel Pichavant wrote: >>> Hello world, >>> >>> I had recently a very nasty bug in my python application. The >>> context is quite complex, but in the end the problem can be resume >>> as follow: >>> >>> 2 files in the same directory : >>> >>> lib.py: >>> >import foo >>> >foo.Foo.BOOM='lib' >>> >>> foo.py: >>> >class Foo: >>> > BOOM = 'Foooo' >>> > >>> >if __name__=='__main__': >>> > import lib # I'm expecting BOOM to be set to 'lib' >>> > print Foo.BOOM >>> >>> I was expecting 'lib' as output, but I got 'Fooo'. I don't really >>> understand what python mechanism I'm messing with but I have the >>> feeling I've misunderstood a very basic concept about class, >>> namespace or whatever import notion. >>> >> >>> I guess there is 2 different objects for the same class Foo. How I >>> do I make both Foo objects the same object ? >> >> OK, here is one solution (from which you may infer the problem): >> >> lib.py: >> import __main__ >> __main__.Foo.BOOM = 'lib' >> >> foo.py: >> class Foo: >> BOOM = 'Foooo' >> >> if __name__ == '__main__': >> import lib # I'm expecting BOOM to be set to 'lib' >> print(Foo.BOOM) >> >> Here is another solution: >> >> lib.py: >> import foo >> foo.Foo.BOOM = 'lib' >> >> foo.py: >> class Foo: >> BOOM = 'Foooo' >> >> if __name__ == '__main__': >> import sys >> sys.modules['foo'] = sys.modules['__main__'] >> import lib # I'm expecting BOOM to be set to 'lib' >> print(Foo.BOOM) >> >> Here is a demo of what is actually going wrong: >> >> foo.py: >> class Foo: >> inside = __name__ >> >> import foo >> >> if __name__ == '__main__': >> print(Foo is foo.Foo) >> print(Foo.inside, foo.Foo.inside) >> >> And here is a fix >> foo.py: >> if __name__ == '__main__': >> import sys >> sys.modules['foo'] = sys.modules['__main__'] >> >> class Foo: >> inside = __name__ >> >> import foo >> >> if __name__ == '__main__': >> print(Foo is foo.Foo) >> print(Foo.inside, foo.Foo.inside) >> >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Thanks for the explanation. I'll have to give it a second thought, I'm > still missing something but I'll figure it out. > > Jean-Michel > >
> In general, two or more modules with mutual imports can cause problems. If modulea.py imports moduleb, and moduleb.py imports modulea, you can end up with difficulties. But even more gross difficulties come from importing the module that started the execution, as it's got another name, "__main__" If you import it again with its traditional name, these two do not get combined, and you end up with multiple instances of things you thought were safe. Scott has given you a solution for the second problem. But the first problem is more general, and should perhaps be the one you try first. The simplest answer in many cases is to factor the script into two separate files. One will have "library" functions and classes, like the Foo in your example. And the other will have the logic for parsing command line arguments and suchlike. The general problem isn't unique to Python. You can also end up with problems in C, where one header includes a second one, which re-includes the first. The workarounds for it are well known, but most of them also contain subtle difficulties. If it's possible, factor out mutual dependencies into a separate module. From mail at microcorp.co.za Sat Jun 6 06:47:39 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 12:47:39 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik><4A27AEC5.8010809@wiggly.org> <003d01c9e513$893597e0$0d00a8c0@Hendrik><4A27C9B4.4070302@wiggly.org> <002501c9e524$2af8c6a0$0d00a8c0@Hendrik> <001501c9e5c4$7b5839a0$0d00a8c0@Hendrik><004201c9e5f3$c6809920$0d00a8c0@Hendrik> Message-ID: <00ad01c9e699$a89fcec0$0d00a8c0@Hendrik> "Gabriel Genellina" wrote: > From your description of the problem, it seems you are acting upon >messages received from a serial port. You have to process the message >*before* the next one arrives -- but you gain nothing doing that much >faster. In other words, even with a blazingly fast processor, you can't do >things faster than the rate of incoming messages. This is what I said, but it is only half of the truth. The actual code is a little bit better. What I have been describing here for simplicity's sake, is the path taken when there is actually something in the queue. The non blocking queue.get() sits in a try except, and if the queue is empty, it actually gathers the inputs and then examines them for change. If there are changes, it makes up response messages to the various clients and puts them on the output queues. If there are no changes, and if it has been a while since the last responses were sent, it sends responses as well. Else it sleeps for a very short time and then examines the incoming queue again. This arrangement minimises the network usage to what is essential, while also reassuring the clients that all is well when nothing is happening. It also uses the time when there is no new output to scan the inputs, and it is this that I was talking about when I defined the responsiveness. > >In any case, you have to test-and-branch in the code. Either with >isinstance(rec,str), either with rec_list[0]=="B", or something. I'm Yes - but this is the second test, that is only reached in the very seldom case that the first one is not true, so it does not add to the normal critical timing path. >unsure if this is the fastest approach - intuition doesn't play well with >timings in Python, better to actually measure times. > You have never said a truer thing - at one stage I was using a loop in C to scan the inputs and put them in memory, but I went back to python because it was faster to use a small time.sleep than the equivalent usleep in C. I still do not understand how that could be, but my oscilloscope does not lie. 8<---------------------------- >If it works and you feel it's adequate, that's fine. I cannot count how >many times I've used an integer property to attach a pointer to another >object (in other languages), but I felt "dirty" doing that. And never did >something like that in Python... I think that the dirty feeling is caused by the FUD that has been created by C's pointer types, and the magic that happens when you add 1 to a pointer and it actually increments by the size of a whole structure, invisibly. It makes one forget that the pointer is just a number representing a memory address. And we have all been bitten in some way or another by pointer arithmetic. And if you look at this thread's title, it is not called Winter Madness by accident... :-) 8<---------------- >Ok, what if you split *before* putting in the queue? In the receiving side >of the queue, just remove the split(",") part (it's already done). This >does not add anything to the critical path - the split must be done anyway. This is good thinking, thank you. It cuts the knot. > >Now, instead of building a fake string "B,cannedobject" and uncanning on >the other side, you can simply put a tuple in the queue ("B", the_object) >and just get the object on the other side. If I'm not misunderstanding >your problem, I think this is the cleanest way to do that. You are spot on, and you are not misunderstanding anything. This will work, and work well. Thank you again. So now I have two viable alternatives to the can - yours, and Scott's. So it looks like it is time to can the Can. So I can have a productive day throwing code away. Thanks again. - Hendrik From mail at microcorp.co.za Sat Jun 6 07:26:09 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 6 Jun 2009 13:26:09 +0200 Subject: Winter Madness - Passing Python objects as Strings References: <002401c9e4e5$b0e1c6c0$0d00a8c0@Hendrik> Message-ID: <00ae01c9e699$a94f48a0$0d00a8c0@Hendrik> "Miles Kaufmann" wrote: > On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: > > > A can is like a pickle, in that it is a string, but anything > > can be canned. > > Unlike a pickle, a can cannot leave the process, though, > > unless the object it points to lives in shared memory. > > > > If you have any interest, contact me and I will > > send you the source. > > Sounds like di(), which can be written: > > import _ctypes > di = _ctypes.PyObj_FromPtr > > def can(o): return str(id(o)) > def uncan(s): return di(int(s)) > > http://www.friday.com/bbum/2007/08/24/python-di/ There is nothing new... Normally it takes a long time before something is re invented. In this case it looks like less than two years. Thank you for the link - Hendrik From mark.dufour at gmail.com Sat Jun 6 08:15:18 2009 From: mark.dufour at gmail.com (srepmub) Date: Sat, 6 Jun 2009 05:15:18 -0700 (PDT) Subject: interval arithmetic libraries Message-ID: <410afd39-e1e0-403d-aa23-e1e85742351c@z14g2000yqa.googlegroups.com> Hi all, I'm looking for libraries that allow one to calculate with sets of (date) intervals. So for example, I'd like to be able to calculate the overlap between two sets of intervals, the union etc. Preferrably, this works with datetime objects, is written in pure Python, and has reasonably good (algorithmic) performance. The neatest library I've found so far is this one: http://members.cox.net/apoco/interval/ >From an API standpoint, it looks rather nice, but the performance could be better (for example, calculating an overlap now involves looping quadratically over both interval sets), and it doesn't work fully with datetime objects (Inf doesn't work). Thanks for any pointers, Mark Dufour. (author of Shedskin, an experimental (restricted-)Python-to-C++ compiler, http://shedskin.googlecode.com) From samwyse at gmail.com Sat Jun 6 08:28:30 2009 From: samwyse at gmail.com (samwyse) Date: Sat, 6 Jun 2009 05:28:30 -0700 (PDT) Subject: py3k printing generators -- not! Message-ID: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> The one thing that's killing me in Python 3000 is that every time I try to print something, it seems like I get at 0x01BAF508>. Googling only found one reference, a posting elsewhere by one Carl Johnson (aka carlj7, http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), which apparently was never answered. Is anyone else finding this bothersome, or is it entirely due to my FP background? Always saying "print(','.join(x))" gets tiresome in a hurry. I've thought about defining my own function "prnt" that wraps print and fixes generators, but that requires me to get their type, which despite the claims of "help(type(x for x in range(0)))" cannot be found in builtins. How are other solving this? From kentilton at gmail.com Sat Jun 6 08:38:10 2009 From: kentilton at gmail.com (Kenneth Tilton) Date: Sat, 06 Jun 2009 08:38:10 -0400 Subject: The Complexity And Tedium of Software Engineering In-Reply-To: <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> References: <4a297a08$0$31258$607ed4bc@cv.net> <4a2a1c15$0$513$5a6aecb4@news.aaisp.net.uk> Message-ID: <4a2a6321$0$31269$607ed4bc@cv.net> verec wrote: > On 2009-06-05 21:03:33 +0100, Kenneth Tilton said: > >> When progress stops we will have time to polish our systems, not before. > > Is that an endorsement of mediocrity? No, of General Patton. hth, kt From aahz at pythoncraft.com Sat Jun 6 08:50:12 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Jun 2009 05:50:12 -0700 Subject: MD6 in Python References: <6d90f372-9d59-4e36-a67a-8852f99b1775@s16g2000vbp.googlegroups.com> Message-ID: In article , Terry Reedy wrote: >Aahz wrote: >> >> Um, what? You mean 3.1rc1, right? Nevertheless, my understanding is >> that 2.7 is mostly restricted to code landed in 3.1, so your second >> statement is roughly correct. > >My understanding is that 2.7 will come out about the same time as 3.2 >and will contain 3.2 backports also. New features are being marked on >the issue tracker as for 2.7/3.2. There may or may not be a 2.8. > >(It was once intended that 2.7 come out with 3.1, but that changed when >it was decided to cut the life of 3.0 and bring out 3.1 after 6 months.) Right, but it was my understanding that work on releasing 2.7 would commence immediately after 3.1, and that 3.2 would happen after 2.7. Maybe we should take this to python-dev... ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From pavlovevidence at gmail.com Sat Jun 6 08:58:53 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Jun 2009 05:58:53 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: On Jun 6, 5:28?am, samwyse wrote: > The one thing that's killing me in Python 3000 is that every time I > try to print something, it seems like I get at 0x01BAF508>. ?Googling only found one reference, a > posting elsewhere by one Carl Johnson (aka carlj7,http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), > which apparently was never answered. ?Is anyone else finding this > bothersome, or is it entirely due to my FP background? > > Always saying "print(','.join(x))" gets tiresome in a hurry. ? What about print(list(x)) > I've > thought about defining my own function "prnt" that wraps print and > fixes generators, but that requires me to get their type, which > despite the claims of "help(type(x for x in range(0)))" cannot be > found in builtins. Interestingly, the fact that it wasn't in builtins didn't stop you from being able to pass the type to the help() function. I wonder if you can use the same trick to obtain the type for use in your prnt() function. (Failing that, you could use "from types import GeneratorType".) >?How are other solving this? In my experience, if you want a custom print function that prints things the way you want, you have to write it yourself. People's expectations are too different. Carl Banks From bearophileHUGS at lycos.com Sat Jun 6 08:59:39 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 05:59:39 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: samwyse: > Always saying "print(','.join(x))" gets tiresome in a hurry. ?I've > thought about defining my own function "prnt" that wraps print and > fixes generators, but that requires me to get their type, Why do you need to know their type? Isn't something like this enough? def pr(it): txt = "".join(map(str, it)) print(txt) That little function can be improved in many ways. > despite the claims of "help(type(x for x in range(0)))" > cannot be found in builtins. Python can yield mixed types (nearly never recommended): def foo(): yield 1 yield "hello" yield 1.5 Bye, bearophile From bearophileHUGS at lycos.com Sat Jun 6 09:01:12 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 06:01:12 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: Carl Banks: > What about print(list(x)) Right, better than mine :-) Bye, bearophile From pieterprovoost at gmail.com Sat Jun 6 09:02:26 2009 From: pieterprovoost at gmail.com (Pieter Provoost) Date: Sat, 6 Jun 2009 15:02:26 +0200 Subject: PyQt icon problem Message-ID: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> Hi, My application has a QSystemTrayIcon, which needs to be changed once in a while. The PNG icons are converted into a module using pyrcc4. When I run the Python script on my Windows system everything works fine, but when run it on Ubuntu or when I use py2exe, the icons are not visible (there's only empty space in the tray). Any thoughts? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Sat Jun 6 09:42:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 06:42:12 -0700 Subject: spammers on pypi In-Reply-To: References: Message-ID: Lawrence D'Oliveiro wrote: > In message > , joep > wrote: > >> Is there a way to ban spammers from pypi? > > Yes, but it doesn't work. > And if you ever do discover something that _does_ work: (1) You'll have discovered perpetual motion. (2) You'll probably get terribly rich from selling it. (3) You'll probably advertize your new solution via bulk e-mail to all e-mail addresses you know of that might be interested in learning of your great discovery. :-) --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jun 6 09:47:34 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 06:47:34 -0700 Subject: openhook In-Reply-To: References: Message-ID: Gaudha wrote: > Can anybody tell me what is meant by 'openhook' ? Certainly someone can. From tsangpo.newsgroup at gmail.com Sat Jun 6 11:07:58 2009 From: tsangpo.newsgroup at gmail.com (tsangpo) Date: Sat, 6 Jun 2009 23:07:58 +0800 Subject: can it be shorter? Message-ID: I want to ensure that the url ends with a '/', now I have to do thisa like below. url = url + '' if url[-1] == '/' else '/' Is there a better way? From samwyse at gmail.com Sat Jun 6 11:11:32 2009 From: samwyse at gmail.com (samwyse) Date: Sat, 6 Jun 2009 08:11:32 -0700 (PDT) Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: On Jun 6, 7:58?am, Carl Banks wrote: > On Jun 6, 5:28?am, samwyse wrote: > > Always saying "print(','.join(x))" gets tiresome in a hurry. ? > > What about print(list(x)) Yeah, I like that. Or, to save some typing: prnt = lambda x: print(list(x)) > Interestingly, the fact that it wasn't in builtins didn't stop you > from being able to pass the type to the help() function. ?I wonder if > you can use the same trick to obtain the type for use in your prnt() > function. Of course, but it would mean evaluating an expression every time I defined my function. That just seems unhygenic > (Failing that, you could use "from types import GeneratorType".) Ah! I should've thought of that. > In my experience, if you want a custom print function that prints > things the way you want, you have to write it yourself. ?People's > expectations are too different. Well, that's why I rferenced the other article, http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), to show that other people have the same expectations. (In the article, Carl Johnson correctly points out that the real problem is that str() responds to generators differently than do the other collection types.) From akindo01 at hotmail.com Sat Jun 6 11:12:12 2009 From: akindo01 at hotmail.com (akindo) Date: Sat, 6 Jun 2009 16:12:12 +0100 Subject: Iterating Over Dictionary From Arbitrary Location Message-ID: Hi all. I am new to Python and have a problem regarding data structures. In my application I will be having several messages and my own type of IDs (Lamport clocks) to go with these messages. I will need to frequently ask for specific messages based on the ID. Hence a dictionary seems a better choice than a list, as I will be using my own IDs to index into the data structure. However, the problem is that I will also at times ask for a specific message based on the ID key, but then want _all_ messages with a higher ID returned as well. :shock: From my research, there are two problems with a dictionary then: 1. it can't be sorted (only returns a sorted list), 2. even if it was possible to sort a dictionary, it is not possible to iterate over it from a given location. So, it seems I want the best of both worlds: specific indexing using my own IDs/keys (not just by list element location), sorting and the ability to start iterating from a specific location. I am trying to prevent having to scan through a list from the beginning to find the desired ID, and then return all elements after that. Is there another data structure or design pattern which will do what I want? Thanks a lot for any help! :) From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 11:16:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 15:16:38 GMT Subject: can it be shorter? References: Message-ID: <023a7abc$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 23:07:58 +0800, tsangpo wrote: > I want to ensure that the url ends with a '/', now I have to do thisa > like below. > url = url + '' if url[-1] == '/' else '/' > > Is there a better way? if not url.endswith('/'): url += '/' -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 11:19:45 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 15:19:45 GMT Subject: openhook References: Message-ID: <023a7b76$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote: > Gaudha wrote: >> Can anybody tell me what is meant by 'openhook' ? > Certainly someone can. It's just like closehook, only different. -- Steven From pieterprovoost at gmail.com Sat Jun 6 11:36:06 2009 From: pieterprovoost at gmail.com (Pieter Provoost) Date: Sat, 6 Jun 2009 17:36:06 +0200 Subject: PyQt icon problem In-Reply-To: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> References: <944a84700906060602r66351f45p244ad43d49c6e867@mail.gmail.com> Message-ID: <944a84700906060836g6837ef0cw4b90e3268b6503a2@mail.gmail.com> Correction: when using py2exe, no icon, empty space or message is visible (the app is running though). On Ubuntu, there is an empty space but messages are not displayed. 2009/6/6 Pieter Provoost > Hi, > > My application has a QSystemTrayIcon, which needs to be changed once in a > while. The PNG icons are converted into a module using pyrcc4. When I run > the Python script on my Windows system everything works fine, but when run > it on Ubuntu or when I use py2exe, the icons are not visible (there's only > empty space in the tray). > > Any thoughts? > Thanks > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sat Jun 6 11:53:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 06 Jun 2009 17:53:54 +0200 Subject: Iterating Over Dictionary From Arbitrary Location In-Reply-To: References: Message-ID: <78vhoiF1oi28oU1@mid.uni-berlin.de> akindo schrieb: > Hi all. I am new to Python and have a problem regarding data structures. > > In my application I will be having several messages and my own type of > IDs (Lamport clocks) to go with these messages. I will need to > frequently ask for specific messages based on the ID. Hence a dictionary > seems a better choice than a list, as I will be using my own IDs to > index into the data structure. However, the problem is that I will also > at times ask for a specific message based on the ID key, but then want > _all_ messages with a higher ID returned as well. :shock: From my > research, there are two problems with a dictionary then: 1. it can't be > sorted (only returns a sorted list), 2. even if it was possible to sort > a dictionary, it is not possible to iterate over it from a given location. > > So, it seems I want the best of both worlds: specific indexing using my > own IDs/keys (not just by list element location), sorting and the > ability to start iterating from a specific location. I am trying to > prevent having to scan through a list from the beginning to find the > desired ID, and then return all elements after that. Is there another > data structure or design pattern which will do what I want? Thanks a lot > for any help! :) you could use a list which is sorted and then use the bisect-module to look up your keys in O(log n). You could also map keys to list-indices. Diez From no.email at please.post Sat Jun 6 11:59:37 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 15:59:37 +0000 (UTC) Subject: can it be shorter? References: Message-ID: In "tsangpo" writes: >I want to ensure that the url ends with a '/', now I have to do thisa like >below. >url = url + '' if url[-1] == '/' else '/' >Is there a better way? It's a pity that in python regexes are an "extra", as it were. Otherwise I'd propose: url = re.sub("/?$", "/", url) kynn (lowest-of-the-low python noob) From bearophileHUGS at lycos.com Sat Jun 6 12:06:26 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 09:06:26 -0700 (PDT) Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: akindo: > So, it seems I want the best of both worlds: specific indexing using ? > my own IDs/keys (not just by list element location), sorting and the ? > ability to start iterating from a specific location. A sorted associative map may be fit. A data structure based on a search tree, like a red-black tree, etc. The Python std lib doesn't contain such data structure. Do you need to add items to your data structure? Diez has suggested a possible solution. You can keep a copy of the items in a sorted list, but this isn't handy if you have to add and remove items frequently. Or you may be able to find somewhere a sorted associative array data structure (tree-based). Bye, bearophile From martin.hellwig at dcuktec.org Sat Jun 6 12:17:37 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 06 Jun 2009 17:17:37 +0100 Subject: openhook In-Reply-To: <023a7b76$0$20636$c3e8da3@news.astraweb.com> References: <023a7b76$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 06 Jun 2009 06:47:34 -0700, Scott David Daniels wrote: > >> Gaudha wrote: >>> Can anybody tell me what is meant by 'openhook' ? >> Certainly someone can. > > It's just like closehook, only different. > > Just like the flipflophook, the quantumhook and captain hook. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From tsangpo.newsgroup at gmail.com Sat Jun 6 12:21:45 2009 From: tsangpo.newsgroup at gmail.com (tsangpo) Date: Sun, 7 Jun 2009 00:21:45 +0800 Subject: can it be shorter? In-Reply-To: References: Message-ID: "kj" ???? news:h0e3p9$85t$1 at reader1.panix.com... > In "tsangpo" > writes: > >>I want to ensure that the url ends with a '/', now I have to do thisa like >>below. >>url = url + '' if url[-1] == '/' else '/' > >>Is there a better way? > > It's a pity that in python regexes are an "extra", as it were. > Otherwise I'd propose: > > url = re.sub("/?$", "/", url) > > kynn (lowest-of-the-low python noob) look nice, but: >>> re.sub('/?$/', '/', 'aaabbb') 'aaabbb' has no effect. what a pity. From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:23:32 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:23:32 GMT Subject: py3k printing generators -- not! References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: <023a8a69$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 05:28:30 -0700, samwyse wrote: > The one thing that's killing me in Python 3000 Python 3000 was vapourware. When the vapour condensed into liquid, it was renamed Python 3. Right now, the only vapourware is Python4000, which may or may not be created by Guido's heir some time in the 2020s. > is that every time I try > to print something, it seems like I get at > 0x01BAF508>. "Every time"? Really? Even when you print an object which isn't a generator? > Googling only found one reference, a posting elsewhere by > one Carl Johnson (aka carlj7, > http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), > which apparently was never answered. Ignoring Carl's totally pointless "mycond()" function, he apparently wants type(iterable)(i for i in iterable) to give iterable: >>> it = [1, 2] >>> type(it)(i for i in it) [1, 2] But that can't work for arbitrary iterables: >>> it = {1:2, 3:4} >>> type(it)(i for i in it) Traceback (most recent call last): File "", line 1, in TypeError: cannot convert dictionary update sequence element #0 to a sequence Nor will it work for generator objects themselves: >>> it = (1+x for x in range(5)) >>> type(it)(i for i in it) Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'generator' instances So Carl's suggestion can't be applied universally, it can only hold for some iterables. It doesn't even hold for all sequences, with strings a conspicuous example. In fact, that's what Carl is complaining about: >>> it = "abc" >>> type(it)(i for i in it) ' at 0xb7ce3d24>' He apparently would prefer str(i for i in "abc") to return "abc". However, you seem to prefer "a,b,c" instead. So what you would prefer, and what Carl would prefer, are different. Either way though, there's a fatal flaw in the idea: printing an object shouldn't consume the object, but that's what you want. Unlike a list or a tuple, a generator is *code*, not a data type. It produces values when and as asked. So there's no way to peek inside a generator and see the values that it will produce, consequently, for str() to behave as you and Carl want, it has to run the generator to completion, performing an arbitrarily large amount of work (and perhaps, for non-terminating generators, never finishing!) before you can print it. And then, having printed it, the generator is now exhausted. Try to print it again, and you'll get the empty string. Calling list() on a generator is different: it is *designed* to exhaust the generator. I'd be upset if print() and/or str() did the same thing. I'd also be upset if generators looked like a string when they're not: >>> x = (c.lower() for c in "ABC") >>> x 'abc' >>> x.upper() # x looks like a string, but it isn't Traceback (most recent call last): File "", line 1, in AttributeError: 'generator' object has no attribute 'upper' [...] > I've > thought about defining my own function "prnt" that wraps print and fixes > generators, but that requires me to get their type, which despite the > claims of "help(type(x for x in range(0)))" cannot be found in builtins. > How are other solving this? I'm not "solving" this, because I don't think this is a problem that needs solving. But if you want a custom print function, this should work: def print(*values, **kwargs): from builtins import print as pr gen = type(x for x in [1,2]) values = [','.join(str(s) for s in obj) if type(obj) is gen else obj for obj in values] pr(*values, **kwargs) -- Steven From woodchips at rochester.rr.com Sat Jun 6 12:34:34 2009 From: woodchips at rochester.rr.com (woodchips at rochester.rr.com) Date: Sat, 6 Jun 2009 09:34:34 -0700 (PDT) Subject: python repository? Message-ID: Hi, I've written a large body of my work in MATLAB over the years. But it looks like I'll need to move to Python soon. Is there a common resource where people can post files for others to use such as the MATLAB central file exchange? Thanks, John From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:34:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:34:38 GMT Subject: can it be shorter? References: Message-ID: <023a8d04$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: > In "tsangpo" > writes: > >>I want to ensure that the url ends with a '/', now I have to do thisa >>like below. >>url = url + '' if url[-1] == '/' else '/' > >>Is there a better way? > > It's a pity that in python regexes are an "extra", as it were. Otherwise > I'd propose: > > url = re.sub("/?$", "/", url) Thank goodness regexs are an "extra" in Python, because it discourages noobs from pulling out the 80 pound sledgehammer of the regex engine to crack the peanut of a test-and-concatenate: >>> from timeit import Timer >>> min(Timer( ... "if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) 0.70030903816223145 >>> min(Timer( ... "sub('/?$', '/', s)", "from re import sub; s = 'abcd/efgh'").repeat()) 7.6922709941864014 That's more than ten times slower. Really, a regex is massive overkill for a task that simple. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jun 6 12:38:27 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2009 16:38:27 GMT Subject: can it be shorter? References: Message-ID: <023a8de9$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 00:21:45 +0800, tsangpo wrote: > "kj" ???? news:h0e3p9$85t $1 at reader1.panix.com... >> In "tsangpo" >> writes: >> >>>I want to ensure that the url ends with a '/', now I have to do thisa >>>like below. >>>url = url + '' if url[-1] == '/' else '/' >> >>>Is there a better way? >> >> It's a pity that in python regexes are an "extra", as it were. >> Otherwise I'd propose: >> >> url = re.sub("/?$", "/", url) >> >> kynn (lowest-of-the-low python noob) > > look nice, but: > >>>> re.sub('/?$/', '/', 'aaabbb') > 'aaabbb' > > has no effect. what a pity. That's because you're doing it wrong. You've added an extra slash: you're asking the regex engine to match a backslash *after* the end of the string. Obviously that will never match. >>> re.sub('/?$/', '/', 'aaabbb') # extra / 'aaabbb' >>> re.sub('/?$', '/', 'aaabbb') # no extra / 'aaabbb/' But before you get too excited, see my previous post: the regex solution is more than ten times slower than test-and-concatenate. -- Steven From emile at fenx.com Sat Jun 6 12:39:31 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 06 Jun 2009 09:39:31 -0700 Subject: openhook In-Reply-To: References: Message-ID: On 6/6/2009 6:47 AM Scott David Daniels said... > Gaudha wrote: >> Can anybody tell me what is meant by 'openhook' ? > Certainly someone can. OK -- kidding aside, the only python related reference I find is in a proposal and patch [1] made by Anthony Roy for changes to the fileinput module. It's an argument passed into FileInput class initialization and apparently allows for a custom file open routine to be used to open the target file -- ergo openhook - a hook for opening. Emile [1] http://bugs.python.org/issue1613500 From kwatch at gmail.com Sat Jun 6 12:44:42 2009 From: kwatch at gmail.com (kwatch) Date: Sat, 6 Jun 2009 09:44:42 -0700 (PDT) Subject: ANN: pyTenjin 0.8.0 - much faster template engine than Django Message-ID: I have released pyTenjin 0.8.0 http://www.kuwata-lab.com/tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) * Goole AppEngine supported. http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine Changes from 0.7.0 ------------------ * !!IMPORTANT!! HTML helper function 'tagattr()' is renamed to 'tagattrs()'. (Notice that new 'tagattr()' is added. See below.) * 'tagattrs()' is changed to add ' ' (space) at the first character. ex. (0.7.0) tagattr(klass='error') #=> 'class="error"' (0.7.1) tagattrs(klass='error') #=> ' class="error"' * 'tagattrs()' is changed to handle 'checked', 'selected', and 'disabled' attributes. ex. >>> from tenjin.helpers.html import * >>> tagattrs(checked=True, selected='Y', disabled=1) ' checked="checked" selected="selected" disabled="disabled"' >>> tagattrs(checked=False, selected='', disabled=0) '' Bugfix ------ * !!IMPORTANT!! Template caching is changed to keep template file's timestamp instead of create time of cached object. See http://groups.google.com/group/kuwata-lab-products/browse_thread/thread/a0d447c282fb383d#msg_de39557405c9b656 for details. (Thanks Steve) Enhancements ------------ * Add new HTML helper function 'tagattr()'. (Notice that 'tagattr()' in 0.7.0 is renamed into 'tagattrs()'.) ex. >>> from tenjin.helpers.html import * >>> tagattr('size', 20) ' size="20"' >>> tagattr('size', 0) '' >>> tagattr('size', 20, 'large') ' size="large"' >>> size = 20 # you can use tagattrs() instead of tagattr () >>> tagattrs(size=(size and 'large')) ' size="large"' * Add new HTML helper function 'new_cycle()'. ex. >>> from tenjin.helpers.html import * >>> cycle = new_cycle('odd, 'even') >>> cycle() 'odd' >>> cycle() 'even' >>> cycle() 'odd' >>> cycle() 'even' * (experimental) Template converter is changed to add dummy if- statement when first Python statement is indented. (Thanks Steve) ex. $ cat ex.pyhtml
  • ${item}
$ pytenjin -sb ex.pyhtml _buf.extend(('''
    \n''', )); if True: ## dummy for item in items: _buf.extend(('''
  • ''', escape(to_str(item)), '''
  • \n''', )); #end _buf.extend(('''
\n''', )); * Update User's Guide and FAQ. Have fun! -- regards, makoto kuwata From simon at brunningonline.net Sat Jun 6 12:49:31 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sat, 6 Jun 2009 17:49:31 +0100 Subject: Programming language comparison examples? In-Reply-To: References: Message-ID: <8c7f10c60906060949x3586aades12b431a51a3f0571@mail.gmail.com> 2009/6/5 : > someone: >> I thought there was a website which demonstrated how to program a bunch of >> small problems in a number of different languages. > > http://www.rosettacode.org/wiki/Main_Page > http://en.literateprograms.org/LiteratePrograms:Welcome > http://www.codecodex.com/wiki/index.php?title=Main_Page > http://merd.sourceforge.net/pixel/language-study/scripting-language/ > http://pleac.sourceforge.net/ > http://www.angelfire.com/tx4/cus/shapes/index.html And my favorite: http://99-bottles-of-beer.net/ -- Cheers, Simon B. From no.email at please.post Sat Jun 6 13:42:32 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 17:42:32 +0000 (UTC) Subject: can it be shorter? References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: >> In "tsangpo" >> writes: >> >>>I want to ensure that the url ends with a '/', now I have to do thisa >>>like below. >>>url = url + '' if url[-1] == '/' else '/' >> >>>Is there a better way? >> >> It's a pity that in python regexes are an "extra", as it were. Otherwise >> I'd propose: >> >> url = re.sub("/?$", "/", url) >Thank goodness regexs are an "extra" in Python, because it discourages >noobs from pulling out the 80 pound sledgehammer of the regex engine to >crack the peanut of a test-and-concatenate: I was just responding to the OP's subject line. Whatever else one may say about my proposal, it *is* shorter. But thanks for the tip with timeit. That looks like a good module to know. kynn From benjamin.kaplan at case.edu Sat Jun 6 13:44:49 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 6 Jun 2009 13:44:49 -0400 Subject: python repository? In-Reply-To: References: Message-ID: On Saturday, June 6, 2009, wrote: > Hi, > > I've written a large body of my work in MATLAB over the years. But it > looks like I'll need to move to Python soon. Is there a common > resource where people can post files for others to use such as the > MATLAB central file exchange? > > Thanks, > John > -- For small code snippets that solve general problems, look at the recipies on ActiveState's website (code.activestate.com). Large projects are listed on the python package index (pypi.python.org) though they aren't hosted there. > http://mail.python.org/mailman/listinfo/python-list > From nick at craig-wood.com Sat Jun 6 14:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 13:29:41 -0500 Subject: openhook References: Message-ID: Gaudha wrote: > Can anybody tell me what is meant by 'openhook' ? http://docs.python.org/library/fileinput.html?highlight=openhook Maybe ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Sat Jun 6 14:29:41 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 06 Jun 2009 13:29:41 -0500 Subject: can it be shorter? References: Message-ID: tsangpo wrote: > > "kj" ???? news:h0e3p9$85t$1 at reader1.panix.com... > > In "tsangpo" > > writes: > > > >>I want to ensure that the url ends with a '/', now I have to do thisa like > >>below. > >>url = url + '' if url[-1] == '/' else '/' > > > >>Is there a better way? > > > > It's a pity that in python regexes are an "extra", as it were. > > Otherwise I'd propose: > > > > url = re.sub("/?$", "/", url) > > > > kynn (lowest-of-the-low python noob) > > look nice, but: > > >>> re.sub('/?$/', '/', 'aaabbb') > 'aaabbb' > > has no effect. what a pity. That is because you typoed what kynn wrote. >>> re.sub('/?$', '/', 'aaabbb') 'aaabbb/' >>> That solution is very perl-ish I'd say, IMHO if not url.endswith("/"): url += "/" is much more pythonic and immediately readable. In fact even someone who doesn't know python could understand what it does, unlike the regexp solution which requires a little bit of thought. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gneuner2 at comcast.net Sat Jun 6 15:46:51 2009 From: gneuner2 at comcast.net (George Neuner) Date: Sat, 06 Jun 2009 15:46:51 -0400 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green wrote: >On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who >said : > >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > >Could what you are saying be summed up by saying, "The more threads >you have the more important it is to keep your threads independent, >sharing as little data as possible." And therein lies the problem of leveraging many cores. There is a lot of potential parallelism in programs (even in Java :) that is lost because it is too fine a grain for threads. Even the lightest weight user space ("green") threads need a few hundred instructions, minimum, to amortize the cost of context switching. Add to that the fact that programmers have shown themselves, on average, to be remarkably bad at figuring out what _should_ be done in parallel - as opposed to what _can_ be done - and you've got a clear indicator that threads, as we know them, are not scalable except under a limited set of conditions. George From pdlemper at earthlink.net Sat Jun 6 15:48:29 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 06 Jun 2009 14:48:29 -0500 Subject: Is it possible to use multidimensional arrays ? Message-ID: All attempts have failed. import WConio import array screen = array.array('H',[0]*75,[0]*24) ERR array takes at most 2 arguments screen = array.array('H',[0]*75[0]*24) TypeErr int object is unsubscriptable screen = array.array('H',[0]*75)('H',[0]*24) ERR object is not callable screen - array.array('H',[0]*75*24) Goes through but results are, of course, unacceptable On-line docs and Programming in Python 3 are no help. Should I give up on arrays and use lists, or go to NumPy ? Thanks From v.donati at email.it Sat Jun 6 16:35:04 2009 From: v.donati at email.it (v.donati at email.it) Date: 6 Jun 2009 22:35:04 +0200 Subject: Servizio aziende : messaggio per python-list@python.org Message-ID: <20090606203144.2A279C041@smtp-out08.email.it>

Offriamo :

Servizi di consulenza  per :  marketing ,  informatica , traduzioni

Assistenza nazionale ed internazionale

Per maggiori informazioni e preventivi clicca qui

Per reclami inviare mail a SMINI

Se non vuoi ricevere altri messaggi invia una mail a SMINI UNSUBSCRIBE

Messaggio per : python-list at python.org



We offer :

Consulting for : marketing , information , translating services

National and international assistance

To ask for further information and estimates click here

To complain send an email to SMINI

In case you do not want to receive further messages, send a mail toSMINI UNSUBSCRIBE

Message for : python-list at python.org

-- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f Sponsor: Legal.email.it: posta elettronica certificata per l'invio di email con valore legale e SMS di notifica Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid?78&d=6-6 From jpthing at online.no Sat Jun 6 16:47:32 2009 From: jpthing at online.no (John Thingstad) Date: Sat, 06 Jun 2009 22:47:32 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: P? Sat, 06 Jun 2009 21:46:51 +0200, skrev George Neuner : > On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green > > Add to that the fact that programmers have shown themselves, on > average, to be remarkably bad at figuring out what _should_ be done in > parallel - as opposed to what _can_ be done - and you've got a clear > indicator that threads, as we know them, are not scalable except under > a limited set of conditions. > > George I find the dataflow model of concurrency on Oz to be interesting and to address many of the issues you just mentioned. See in particular: 'Dataflow variables and declarative concurrency' and onward. http://en.wikipedia.org/wiki/Oz_(programming_language) --------------------- John Thingstad From no.email at please.post Sat Jun 6 17:14:00 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 21:14:00 +0000 (UTC) Subject: Is it possible to use multidimensional arrays ? References: Message-ID: In pdlemper at earthlink.net writes: >All attempts have failed. > import WConio > import array > screen = array.array('H',[0]*75,[0]*24) > ERR array takes at most 2 arguments > screen = array.array('H',[0]*75[0]*24) > TypeErr int object is unsubscriptable > screen = array.array('H',[0]*75)('H',[0]*24) > ERR object is not callable > screen - array.array('H',[0]*75*24) > Goes through but results are, of course, unacceptable >On-line docs and Programming in Python 3 are no help. >Should I give up on arrays and use lists, or go to NumPy ? Thanks I guess you could do something like screen = [array.array('H', [0]*75) for i in range(24)] but I doubt that the resulting structure would be that much more efficient than the pure-list equivalent... kynn -- lowest-of-the-low python noob From robert.kern at gmail.com Sat Jun 6 17:15:01 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 16:15:01 -0500 Subject: Error in linalg.inv ?? In-Reply-To: <4A29FFD2.1030609@iuac.res.in> References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 00:34, Ajith Kumar wrote: > Hello, > I ran the following code (Using Debian 5.0) > > from numpy import * Please ask numpy questions on the numpy mailing list, not here: http://www.scipy.org/Mailing_Lists > a = arange(1.,10.) > b = reshape(a, [3,3]) > c = linalg.inv(b) > print b > print c > print dot(b,c) > print dot(c,b) > > And the result is > > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > [[-0.5 -1. -1. ] > [-1. -2. 2. ] > [-1.5 -3. 1. ]] > > [[ 5.5 8. 10.5] > [ 3. 0. -3. ] > [ -1. 0. -3. ]] > > NOT the identity matrix. Any help ? You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it numerically and expect sensible results. -- 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 Jun 6 17:18:00 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 16:18:00 -0500 Subject: Is it possible to use multidimensional arrays ? In-Reply-To: References: Message-ID: On 2009-06-06 14:48, pdlemper at earthlink.net wrote: > All attempts have failed. > > import WConio > import array > > screen = array.array('H',[0]*75,[0]*24) > ERR array takes at most 2 arguments > > screen = array.array('H',[0]*75[0]*24) > TypeErr int object is unsubscriptable > > screen = array.array('H',[0]*75)('H',[0]*24) > ERR object is not callable > > screen - array.array('H',[0]*75*24) > Goes through but results are, of course, unacceptable > On-line docs and Programming in Python 3 are no help. > Should I give up on arrays and use lists, or go to NumPy ? Thanks Go to numpy, probably. -- 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 Sat Jun 6 17:25:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 17:25:05 -0400 Subject: Odd closure issue for generators In-Reply-To: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> References: <4A28903B.4020301@sweetapp.com> <4A292D70.9020801@sweetapp.com> <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> Message-ID: Michele Simionato wrote: > Yes, most functional languages have the concept of streams. > You can even define a stream-comprehension that looks like > Python generator comprehension but it is an essentially different > thing. See for instance > > http://www.artima.com/weblogs/viewpost.jsp?thread=251159 I read that. It seems that streams are virtual or lazy linked-lists(1). I think, though, that comparing them to iterators is misleading. They are iterables, but with a different iteration protocol. Python iterables are generally reiterable just like streams. chars = 'abc' for c in chars: print(c,end=' ') for c in chars: print(c,end=' ') produces repeatable output just like your stream example. Python *could* have given iterables .first and .rest methods instead of .__iter__, but that works best for linked lists and awfully for arrays. Anyway, I realize now that having generator comprehensions produce an *iterator* rathar than an *iterable* or *generator function* is something of an anomaly Set, dict, and list comprehensions in Python produce iterables, of course, as does a stream comprehension in Scheme and, I presume, comprehensions in other languages. A generator expression could have been defined in Python to just produce a generator function, without calling it, but the intent of the abbreviation was for one-use situations. Multi-use gfs should be defined with a def statement. Terry Jan Reedy (1) Calling the first and rest methods 'car' and 'cdr' convinces me that schemers really do not want scheme to be popular, but prefer it to remain a small cult language. From no.email at please.post Sat Jun 6 17:56:45 2009 From: no.email at please.post (kj) Date: Sat, 6 Jun 2009 21:56:45 +0000 (UTC) Subject: can it be shorter? References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: In kj writes: >In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >>On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: >>> In "tsangpo" >>> writes: >>> >>>>I want to ensure that the url ends with a '/', now I have to do thisa >>>>like below. >>>>url = url + '' if url[-1] == '/' else '/' >>> >>>>Is there a better way? >>> >>> It's a pity that in python regexes are an "extra", as it were. Otherwise >>> I'd propose: >>> >>> url = re.sub("/?$", "/", url) >>Thank goodness regexs are an "extra" in Python, because it discourages >>noobs from pulling out the 80 pound sledgehammer of the regex engine to >>crack the peanut of a test-and-concatenate: >I was just responding to the OP's subject line. Whatever else one >may say about my proposal, it *is* shorter. >But thanks for the tip with timeit. That looks like a good module >to know. And actually, if speed is the criterion, then one should also avoid endswith: >>> from timeit import Timer >>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) 0.18654584884643555 >>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) 0.43395113945007324 kynn From tjreedy at udel.edu Sat Jun 6 18:07:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 18:07:07 -0400 Subject: Error in linalg.inv ?? In-Reply-To: <4A29FFD2.1030609@iuac.res.in> References: <4A29FFD2.1030609@iuac.res.in> Message-ID: Ajith Kumar wrote: > [[ 1. 2. 3.] > [ 4. 5. 6.] > [ 7. 8. 9.]] Another way to see that this is singular is notice or calculate that (1,2,3) - 2*(4,5,6) + (7,8,9) = (0,0,0) Same is true for the columns. From sjmachin at lexicon.net Sat Jun 6 18:09:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 6 Jun 2009 22:09:57 +0000 (UTC) Subject: Error in linalg.inv ?? References: <4A29FFD2.1030609@iuac.res.in> Message-ID: Robert Kern gmail.com> writes: > > On 2009-06-06 00:34, Ajith Kumar wrote: > > from numpy import * > > Please ask numpy questions on the numpy mailing list, not here: > > http://www.scipy.org/Mailing_Lists > > > a = arange(1.,10.) > > b = reshape(a, [3,3]) > > c = linalg.inv(b) > > > > And the result is > > > > [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] > > [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] > > [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] (gibberish) > > You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it > numerically and expect sensible results. Is raising an exception (as documented (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not a "sensible result"? From python at mrabarnett.plus.com Sat Jun 6 18:24:11 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Jun 2009 23:24:11 +0100 Subject: can it be shorter? In-Reply-To: References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: <4A2AEC8B.2020109@mrabarnett.plus.com> kj wrote: > In kj writes: > >> In <023a8d04$0$20636$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: > >>> On Sat, 06 Jun 2009 15:59:37 +0000, kj wrote: > >>>> In "tsangpo" >>>> writes: >>>> >>>>> I want to ensure that the url ends with a '/', now I have to do thisa >>>>> like below. >>>>> url = url + '' if url[-1] == '/' else '/' >>>>> Is there a better way? >>>> It's a pity that in python regexes are an "extra", as it were. Otherwise >>>> I'd propose: >>>> >>>> url = re.sub("/?$", "/", url) > > >>> Thank goodness regexs are an "extra" in Python, because it discourages >>> noobs from pulling out the 80 pound sledgehammer of the regex engine to >>> crack the peanut of a test-and-concatenate: > >> I was just responding to the OP's subject line. Whatever else one >> may say about my proposal, it *is* shorter. > >> But thanks for the tip with timeit. That looks like a good module >> to know. > > > > And actually, if speed is the criterion, then one should also avoid endswith: > >>>> from timeit import Timer >>>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) > 0.18654584884643555 >>>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) > 0.43395113945007324 > If there's any chance that the string could be empty (len(s) == 0) then use: if s[-1 : ] != '/' s += '/' From Scott.Daniels at Acm.Org Sat Jun 6 18:28:16 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 06 Jun 2009 15:28:16 -0700 Subject: can it be shorter? In-Reply-To: References: <023a8d04$0$20636$c3e8da3@news.astraweb.com> Message-ID: <1Z-dnR0WYuSScbfXnZ2dnUVZ_tadnZ2d@pdx.net> kj wrote: > ... And actually, if speed is the criterion, then one should also avoid endswith: > >>>> from timeit import Timer >>>> min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat()) > 0.18654584884643555 >>>> min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat()) > 0.43395113945007324 _but_, try this with s = '', and you are in trouble. So, try: if s[-1:] != '/': s += '/' To be a trifle more reliable. But, for more normal semantics, you might prefer either: if s[-1:] != '/': s = (s or '.') + '/' or: if s and s[-1] != '/': s += '/' --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Sat Jun 6 18:31:10 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 17:31:10 -0500 Subject: Error in linalg.inv ?? In-Reply-To: References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 17:09, John Machin wrote: > Robert Kern gmail.com> writes: > >> On 2009-06-06 00:34, Ajith Kumar wrote: > >>> from numpy import * >> Please ask numpy questions on the numpy mailing list, not here: >> >> http://www.scipy.org/Mailing_Lists >> >>> a = arange(1.,10.) >>> b = reshape(a, [3,3]) >>> c = linalg.inv(b) >>> >>> And the result is >>> >>> [[ 3.15221191e+15 -6.30442381e+15 3.15221191e+15] >>> [ -6.30442381e+15 1.26088476e+16 -6.30442381e+15] >>> [ 3.15221191e+15 -6.30442381e+15 3.15221191e+15]] > > (gibberish) > >> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it >> numerically and expect sensible results. > > Is raising an exception (as documented > (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv.html)) not > a "sensible result"? That's not the way I was using the phrase, but you have a point. We depend on the underlying LAPACK routine to tell us if the array is singular or not. It will inform us if it stopped prematurely because of singularity. In this case, I think it happens to complete simply because it is so small and the subroutine did not detect the singularity. A (5,5) matrix constructed the same way will raise the exception, for example. However, the condition number of a matrix is not a binary property. A matrix can be poorly conditioned but not precisely singular, and the inversion routine will give you a correct result (within the limits of floating point arithmetic) rather than an exception, but you will still get mostly nonsense out if you try to use that result. You still need to apply care in interpreting the result and not rely on our throwing an exception even if we could catch all singular inputs. -- 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 bearophileHUGS at lycos.com Sat Jun 6 18:46:26 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sat, 6 Jun 2009 15:46:26 -0700 (PDT) Subject: Is it possible to use multidimensional arrays ? References: Message-ID: <087de8e9-4eb1-40f6-a0e8-ee1699c54d95@y7g2000yqa.googlegroups.com> pdlem... at earthlink.net, if you are using Psyco and you aren't using NumPy and you want max speed you may use: NROWS = 24 NCOLS = 75 screen = array("H", [0]) * (NROWS * NCOLS) and then you can use items like this: screen[r * NCOLS + c] (If NCOLS is equal or a bit lower than a power of 2 it's better to use a shift). But in most situations using lists of lists or NumPy is better. Bye, bearophile From mh at pixar.com Sat Jun 6 18:48:14 2009 From: mh at pixar.com (mh at pixar.com) Date: Sat, 06 Jun 2009 22:48:14 GMT Subject: #! to two different pythons? Message-ID: I've got a bunch of python programs on linux that start with: #!/usr/anim/menv/bin/pypix Now I'm moving some to the mac, where I'm changing that to: #!/Users/mh/py/bin/python What's the best way to handle this? I've got an install script that rewrites the first line, but if I could eliminate that step I would be quite happy, since it's the only thing the install step does. TIA!! Mark -- Mark Harrison Pixar Animation Studios From tjreedy at udel.edu Sat Jun 6 18:58:09 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 18:58:09 -0400 Subject: py3k printing generators -- not! In-Reply-To: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> References: <43b45091-26bc-471d-b8af-6091c8269acd@q2g2000vbr.googlegroups.com> Message-ID: samwyse wrote: > The one thing that's killing me in Python 3000 py3.0 or py3.1, but the 'problem' you complain about has nothing to do with those versions in particular. > is that every time I try to print something, it seems like I get at 0x01BAF508>. Nor does it have anything is particular to do with generator objects. Str(function/class/module/and-many-others) prints similarly. Since forever, str(ob) == ob.__str__() == type(ob).__str__(ob). And what you see above is the default template filled in for a particular object. Built-in concrete collections over-ride the default and return a string with their contents because they can do that without harm other than possibly producing a very long string. When the collections are large, one might want a custom function that instead formats a string with a limited number of examples and the total count. A 3.0 range object, a virtual collection, could do that too, but since there is a regular pattern, it prints a condensed representation. Aren't you glad, actually, that range(1000000000) prints as "range(0, 1000000000)" instead of listing the billion numbers it produces when iterated, as you seem to be asking for? > Googling only found one reference, a > posting elsewhere by one Carl Johnson (aka carlj7, > http://www.artima.com/forums/flat.jsp?forum=106&thread=211200#275387), A bogus complaint that the constructor for highly specialized class str acts differently from those of the general collection classes set, tuple, and list. Str is actually not a collection class in the way that set, tuple, list, dict, and many others are. Terry Jan Reedy From benjamin at python.org Sat Jun 6 19:01:55 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Jun 2009 23:01:55 +0000 (UTC) Subject: #! to two different pythons? References: Message-ID: pixar.com> writes: > What's the best way to handle this? #!/usr/bin/env python From pavlovevidence at gmail.com Sat Jun 6 19:08:52 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Jun 2009 16:08:52 -0700 (PDT) Subject: Error in linalg.inv ?? References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On Jun 6, 3:31?pm, Robert Kern wrote: > On 2009-06-06 17:09, John Machin wrote: > > Robert Kern ?gmail.com> ?writes: > >> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it > >> numerically and expect sensible results. > > > Is raising an exception (as documented > > (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv....)) not > > a "sensible result"? > > That's not the way I was using the phrase, but you have a point. > > We depend on the underlying LAPACK routine to tell us if the array is singular > or not. Perhaps the documentation should be updated to say "Raises LinAlgError if inv() detects that 'a' a singular matrix". Anyone with much experience with linear algebra libraries should know that these routines are shaky when ill-conditioned, but it could help newbies and computer science experts to be explicit about it. Carl Banks From robert.kern at gmail.com Sat Jun 6 19:23:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 06 Jun 2009 18:23:56 -0500 Subject: Error in linalg.inv ?? In-Reply-To: References: <4A29FFD2.1030609@iuac.res.in> Message-ID: On 2009-06-06 18:08, Carl Banks wrote: > On Jun 6, 3:31 pm, Robert Kern wrote: >> On 2009-06-06 17:09, John Machin wrote: >>> Robert Kern gmail.com> writes: >>>> You have a very singular matrix (2*a[1] - a[0] == a[2]). You cannot invert it >>>> numerically and expect sensible results. >>> Is raising an exception (as documented >>> (http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.inv....)) not >>> a "sensible result"? >> That's not the way I was using the phrase, but you have a point. >> >> We depend on the underlying LAPACK routine to tell us if the array is singular >> or not. > > Perhaps the documentation should be updated to say "Raises LinAlgError > if inv() detects that 'a' a singular matrix". > > Anyone with much experience with linear algebra libraries should know > that these routines are shaky when ill-conditioned, but it could help > newbies and computer science experts to be explicit about it. By all means, please do. http://docs.scipy.org/numpy/Front%20Page/ -- 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 Sat Jun 6 19:30:02 2009 From: aahz at pythoncraft.com (Aahz) Date: 6 Jun 2009 16:30:02 -0700 Subject: Odd closure issue for generators References: <9c8dc8ab-7155-4d37-9105-34ff6ec7727f@o18g2000yqi.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > >(1) Calling the first and rest methods 'car' and 'cdr' convinces me that >schemers really do not want scheme to be popular, but prefer it to >remain a small cult language. What, you don't get a warm, fuzzy feeling from saying, "Today is the car of the cdr of your life"? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From mh at pixar.com Sat Jun 6 19:46:47 2009 From: mh at pixar.com (mh at pixar.com) Date: Sat, 06 Jun 2009 23:46:47 GMT Subject: #! to two different pythons? References: Message-ID: Benjamin Peterson wrote: > #!/usr/bin/env python But how can I handle this with two differently named pythons? #!/usr/anim/menv/bin/pypix #!/Users/mh/py/bin/python Thanks! Mark -- Mark Harrison Pixar Animation Studios From cs at zip.com.au Sat Jun 6 20:09:51 2009 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 7 Jun 2009 10:09:51 +1000 Subject: #! to two different pythons? In-Reply-To: Message-ID: <20090607000951.GA7293@cskk.homeip.net> On 06Jun2009 23:46, mh at pixar.com wrote: | Benjamin Peterson wrote: | > #!/usr/bin/env python | | But how can I handle this with two differently named pythons? | | #!/usr/anim/menv/bin/pypix | #!/Users/mh/py/bin/python Well, it depends _why_ you have a python named "pypix", but two solutions suggest themselves: - Keep the "#!/usr/bin/env python" and then: ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python Presumes no other python, and /usr/local/bin might become ~/bin or something like that. - Write a small wrapper shell script and use: #!/usr/bin/env my-wrapper-script Regarding the first approach, on a personal basis I have two bin directories: ~/bin and ~/bin-local on the machines I use. The former it copied from my home account and is always the same - a bunch of useful scripts. The latter is per-host customisation and is largely symlinks to preferred versions of apps, apps installed out of the main paths, and host-specific wrapper scripts. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Soon, Grasshopper, all will understand. And dispair. The government that defines what is good for you, will also dictate what is bad. - Curt Howland "Ace" DoD#0663 EGFC#011 EFF#569 howland at Priss.com '82 V45 Sabre From mh at pixar.com Sat Jun 6 20:17:20 2009 From: mh at pixar.com (mh at pixar.com) Date: Sun, 07 Jun 2009 00:17:20 GMT Subject: #! to two different pythons? References: Message-ID: Cameron Simpson wrote: > - Keep the "#!/usr/bin/env python" and then: > ln -s /usr/anim/menv/bin/pypix /usr/local/bin/python Ah, that's a good idea. The pypix is a company-wide maintained python, but ln -s python pypix on my local Mac laptop python install makes the env work quite nicely. The ~/bin and ~/bin-local is a great idea too... I've symlinked to my dropbox account for bonus convenience. thanks!!! Mark -- Mark Harrison Pixar Animation Studios From timr at probo.com Sat Jun 6 22:32:31 2009 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Jun 2009 19:32:31 -0700 Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> Message-ID: <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Steven D'Aprano wrote: > >Why is it that it's (almost) always newbies with about five minutes' >worth of experience with Python that come up with these grandiose plans >to replace entire modules with a single function? Well, many great innovations in history have come from people who did not have enough experience to know that what they were doing was impossible... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From http Sat Jun 6 22:58:55 2009 From: http (Paul Rubin) Date: 06 Jun 2009 19:58:55 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: <7xskicoikw.fsf@ruckus.brouhaha.com> George Neuner writes: > Even the lightest weight > user space ("green") threads need a few hundred instructions, minimum, > to amortize the cost of context switching. I thought the definition of green threads was that multiplexing them doesn't require context switches. From massung at gmail.com Sat Jun 6 23:08:29 2009 From: massung at gmail.com (Jeff M.) Date: Sat, 6 Jun 2009 20:08:29 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> Message-ID: On Jun 6, 9:58?pm, Paul Rubin wrote: > George Neuner writes: > > Even the lightest weight > > user space ("green") threads need a few hundred instructions, minimum, > > to amortize the cost of context switching. > > I thought the definition of green threads was that multiplexing them > doesn't require context switches. There's always a context switch. It's just whether or not you are switching in/out a virtual stack and registers for the context or the hardware stack/registers. Jeff M. From tjreedy at udel.edu Sat Jun 6 23:24:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Jun 2009 23:24:22 -0400 Subject: Making the case for repeat In-Reply-To: <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Message-ID: Tim Roberts wrote: > Steven D'Aprano wrote: >> Why is it that it's (almost) always newbies with about five minutes' >> worth of experience with Python that come up with these grandiose plans >> to replace entire modules with a single function? > > Well, many great innovations in history have come from people who did not > have enough experience to know that what they were doing was impossible... Along with many of the great follies and frauds ;-) From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 01:20:51 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 05:20:51 GMT Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> Message-ID: <023b4095$0$20636$c3e8da3@news.astraweb.com> On Sat, 06 Jun 2009 19:32:31 -0700, Tim Roberts wrote: > Steven D'Aprano wrote: >> >>Why is it that it's (almost) always newbies with about five minutes' >>worth of experience with Python that come up with these grandiose plans >>to replace entire modules with a single function? > > Well, many great innovations in history have come from people who did > not have enough experience to know that what they were doing was > impossible... So the old saw goes. Like most old saws, it's a load of codswallop. If you scratch beneath the surface, you soon discover that the people who supposedly "didn't know it was impossible" actually had a great deal of experience of what was and wasn't possible in the subject at hand. They might have been outsiders, but they were *knowledgeable* outsiders. e.g. the Wright Brothers weren't lone inventors working at a time when everyone knew powered flight was impossible, they were experienced engineers and glider-pilots who paid a lot of attention to research done by their many competitors. -- Steven From http Sun Jun 7 02:56:52 2009 From: http (Paul Rubin) Date: 06 Jun 2009 23:56:52 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> Message-ID: <7x8wk4351n.fsf@ruckus.brouhaha.com> "Jeff M." writes: > > > Even the lightest weight > > > user space ("green") threads need a few hundred instructions, minimum, > > > to amortize the cost of context switching.... > There's always a context switch. It's just whether or not you are > switching in/out a virtual stack and registers for the context or the > hardware stack/registers. I don't see the hundreds of instructions in that case. http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 shows GHC doing 50 million lightweight thread switches in 8.47 seconds, passing a token around a thread ring. Almost all of that is probably spent acquiring and releasing the token's lock as the token is passed from one thread to another. That simply doesn't leave time for hundreds of instructions per switch. From duncan.booth at invalid.invalid Sun Jun 7 05:43:54 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Jun 2009 09:43:54 GMT Subject: #! to two different pythons? References: Message-ID: mh at pixar.com wrote: > Benjamin Peterson wrote: >> #!/usr/bin/env python > > But how can I handle this with two differently named pythons? > > #!/usr/anim/menv/bin/pypix > #!/Users/mh/py/bin/python > > Thanks! > Mark > If you install using with a setup.py that uses distutils then one of the features is that any script whose first line begins '#!' and contains 'python' has that first line replaced by the current interpreter. So in this example if you install your code with: /usr/anim/menv/bin/pypix setup.py install "#!/usr/bin/env python" would be replaced by your desired "#!/usr/anim/menv/bin/pypix". Of course for your current purposes using setup.py might be overkill. From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 06:42:20 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 10:42:20 GMT Subject: Is reduce() foldl() or foldr()? Message-ID: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Calling all functional programming fans... is Python's built-in reduce() a left-fold or a right-fold? Wikipedia says it's a left-fold: http://en.wikipedia.org/wiki/Fold_(higher-order_function) but other people say it's a right-fold, e.g.: "... there is a `foldr` in Haskell that just works like `reduce()`" http://mail.python.org/pipermail/python-list/2007-November/638647.html and "Note that Python already has a variation of foldr, called reduce." http://blog.sigfpe.com/2008/02/purely-functional-recursive-types-in.html So which is correct? Or is it that different people have different definitions of foldl() and foldr()? -- Steven From jonas.esp at googlemail.com Sun Jun 7 07:45:26 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 04:45:26 -0700 (PDT) Subject: Properties for several keywords Message-ID: I've to write properties for several keywords with the same code, it only changes the name of each property: ----------------------------- @property def foo(self): return self._foo @foo.setter def foo(self, txt): self._foo = self._any_function(txt) # ---------------- @property def bar(self): return self._bar @bar.setter def bar(self, txt): self._bar = self._any_function(txt) ----------------------------- Is possible to simplify it? From jonas.esp at googlemail.com Sun Jun 7 07:57:09 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 04:57:09 -0700 (PDT) Subject: Properties for several keywords References: Message-ID: <0086478b-536d-4213-b257-690b1040fae4@t11g2000vbc.googlegroups.com> On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > ----------------------------- > @property > ? ?def foo(self): > ? ? ? return self._foo > > @foo.setter > ? ?def foo(self, txt): > ? ? ? self._foo = self._any_function(txt) > > # ---------------- > > @property > ? ?def bar(self): > ? ? ? return self._bar > > @bar.setter > ? ?def bar(self, txt): > ? ? ? self._bar = self._any_function(txt) > ----------------------------- > > Is possible to simplify it? Sorry for indent the decorator. From Scott.Daniels at Acm.Org Sun Jun 7 08:18:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 05:18:48 -0700 Subject: multi-core software In-Reply-To: <7x8wk4351n.fsf@ruckus.brouhaha.com> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Jeff M." writes: >>>> Even the lightest weight >>>> user space ("green") threads need a few hundred instructions, minimum, >>>> to amortize the cost of context switching.... >> There's always a context switch. It's just whether or not you are >> switching in/out a virtual stack and registers for the context or the >> hardware stack/registers. > > I don't see the hundreds of instructions in that case. > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. That simply doesn't leave time > for hundreds of instructions per switch. Remember, he said, "to amortize the cost of the context switch," not to perform the switch itself. I stutter-stepped there myself. One not completely obvious place is in blowing the instruction and likely the data) cache. I suspect it is tough to measure when that cost applies, but I expect he's likely right, except on artificial benchmarks, and the nub of the problem is not on the benchmarks. There is something to be said for the good old daays when you looked up the instruction timings that you used in a little document for your machine, and could know the cost of any loop. We are faster now, but part of the cost of that speed is that timing is a black art. Perhaps modern operating systems need the syyem call that was implemented in the Stanfor AI Lab's operating system -- phase of the moon. --Scott David Daniels Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sun Jun 7 08:20:46 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 05:20:46 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <3f3d0619-76bb-465a-ae91-fda5d293b275@l12g2000yqo.googlegroups.com> pataphor: > The problem is posting *this* > function would kill my earlier repeat for sure. And it already had a > problem with parameters < 0 (Hint: that last bug has now become a > feature in the unpostable repeat implementation) Be bold, kill your precedent ideas, and post the Unpostable :-) Despite people here complaining a bit, you can't hurt posting some lines of safe code here :-) But I agree with Steven D'Aprano, adding some explaining words to your proposals helps. Bye, bearophile From T.P.Northover at sms.ed.ac.uk Sun Jun 7 08:34:26 2009 From: T.P.Northover at sms.ed.ac.uk (Tim Northover) Date: Sun, 07 Jun 2009 13:34:26 +0100 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: <87vdn8dxyl.fsf@hal9000.lan> Steven D'Aprano writes: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? I get: >>> reduce(lambda a, b: a/b, [1.0, 2.0, 3.0]) 0.16666666666666666 which looks like a left fold to me. Tim. From __peter__ at web.de Sun Jun 7 08:41:31 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Jun 2009 14:41:31 +0200 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? > > Wikipedia says it's a left-fold: > > http://en.wikipedia.org/wiki/Fold_(higher-order_function) Wikipedia is correct: >>> from __future__ import division >>> (1/(2/(3/(4/5)))) # right 1.875 >>> ((((1/2)/3)/4)/5) # left 0.0083333333333333332 >>> reduce(lambda x, y: x/y, range(1, 6)) 0.0083333333333333332 > but other people say it's a right-fold, e.g.: > > "... there is a `foldr` in Haskell that just works like `reduce()`" > http://mail.python.org/pipermail/python-list/2007-November/638647.html > > > and > > "Note that Python already has a variation of foldr, called reduce." > http://blog.sigfpe.com/2008/02/purely-functional-recursive-types-in.html The explicit foldr() function given in this blog agrees with Wikipedia's definition: >>> def foldr(a, b, l): ... if l == []: ... return b ... else: ... return a(l[0], foldr(a, b, l[1:])) ... >>> foldr(lambda x, y: x/y, 5, range(1, 5)) 1.875 Peter From no.i.dont at want.mail.from.spammers.com Sun Jun 7 08:49:57 2009 From: no.i.dont at want.mail.from.spammers.com (Fencer) Date: Sun, 07 Jun 2009 14:49:57 +0200 Subject: Keeping console window open Message-ID: <791rbmF1okia2U1@mid.individual.net> Hello, I need to write a simple utility program that will be used under Windows. I want to write the utility in python and it will be run by double-clicking the the .py-file. I put a raw_input('Press enter to exit) at the end so the console window wouldn't just disappear when the program is finished. Anyway, I wrote a few lines of code and when I first tried to run it by double-clicking the .py-file the console window still disappeared right away. So, in order to see what was happening, I ran it from a shell and it turned out to be a missing import. My question is how can I trap errors encountered by the interpreter (if that is the right way to put it) in order to keep the console window open so one has a chance to see the error message? - Fencer From Scott.Daniels at Acm.Org Sun Jun 7 08:53:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 05:53:28 -0700 Subject: Is reduce() foldl() or foldr()? In-Reply-To: <023b8bec$0$20636$c3e8da3@news.astraweb.com> References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? ... > So which is correct? Or is it that different people have different > definitions of foldl() and foldr()? Just test. Floating point addition is not associative, so: >>> a = reduce(float.__add__, (4095 * 2. **n for n in range(100))) >>> b = reduce(float.__add__,(4095*2.**n for n in reversed(range(100)))) >>> a - b 5.7646075230342349e+17 So, since a > b, it must be foldl (the first addition happens to the first of the list). Foldl is the eager-beaver's dream; foldr is the procrastinator's dream. --Scott David Daniels Scott.Daniels at Acm.Org From higerinbeijing at gmail.com Sun Jun 7 08:55:08 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 05:55:08 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code Message-ID: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> My file contains such strings : \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a I want to read the content of this file and transfer it to the corresponding gbk code,a kind of Chinese character encode style. Everytime I was trying to transfer, it will output the same thing no matter which method was used. It seems like that when Python reads it, Python will taks '\' as a common char and this string at last will be represented as "\\xe6\\x97\ \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' output,but that's not what I want to get. Anyone can help me? Thanks in advance. From tomasz.zielinski at pyconsultant.eu Sun Jun 7 08:55:57 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Sun, 7 Jun 2009 05:55:57 -0700 (PDT) Subject: Keeping console window open References: <791rbmF1okia2U1@mid.individual.net> Message-ID: On 7 Cze, 14:49, Fencer wrote: > My question is how can I trap > errors encountered by the interpreter (if that is the right way to put > it) in order to keep the console window open so one has a chance to see > the error message? > Interpreter errors are same beasts as exceptions, so you can try:...except: them. -- Tomasz Zieli?ski http://pyconsultant.eu From xuecan at gmail.com Sun Jun 7 09:14:13 2009 From: xuecan at gmail.com (Can Xue) Date: Sun, 7 Jun 2009 21:14:13 +0800 Subject: Keeping console window open In-Reply-To: <791rbmF1okia2U1@mid.individual.net> References: <791rbmF1okia2U1@mid.individual.net> Message-ID: 2009/6/7 Fencer > Anyway, I wrote a few lines of code and when I first tried to run it by > double-clicking the .py-file the console window still disappeared right > away. So, in order to see what was happening, I ran it from a shell and it > turned out to be a missing import. My question is how can I trap errors > encountered by the interpreter (if that is the right way to put it) in order > to keep the console window open so one has a chance to see the error > message? > > I don't think this (force a console window to be kept openning only for debug purpose) is a good idea. If you just write some lines to learn something, you may run your script in a console window or in an IDE. If you are writing a big project, you'd better catch those exception and store logs in some files. However, if you still need force a console window be kept openning after the script end, you may use module atexit. -- XUE Can -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Sun Jun 7 09:23:01 2009 From: ebonak at hotmail.com (Esmail) Date: Sun, 07 Jun 2009 09:23:01 -0400 Subject: pylint naming conventions? In-Reply-To: <87skiekend.fsf@benfinney.id.au> References: <87skiekend.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Esmail writes: > >> I am confused by pylint's naming conventions, I don't think the are in >> tune with Python's style recommendations (PEP 8?) >> >> Anyone else think this? > > It's hard to know, without examples. Can you give some output of pylint > that you think doesn't agree with PEP 8? Sure, I will next time I have a nice self-contained example. Perhaps not that many people are using pylint? I was expecting a bunch of messages either contradicting my observation or agreeing with it :-) .. but perhaps this indicates that there's no issue. I'll try to come up with a nice short code example in the next few days to demonstrate what I think the problem is and post it, thanks for the suggestion. Esmail From Scott.Daniels at Acm.Org Sun Jun 7 09:26:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 06:26:00 -0700 Subject: Keeping console window open In-Reply-To: References: <791rbmF1okia2U1@mid.individual.net> Message-ID: Tomasz Zieli?ski wrote: > On 7 Cze, 14:49, Fencer wrote: >> My question is how can I trap >> errors encountered by the interpreter (if that is the right way to put >> it) in order to keep the console window open so one has a chance to see >> the error message? > > Interpreter errors are same beasts as exceptions, > so you can try:...except: them. To be a trifle more explicit, turn: ... if __name__ == '__main__': main() into: ... if __name__ == '__main__': try: main() except Exception, why: print 'Failed:', why import sys, traceback traceback.print_tb(sys.exc_info()[2]) raw_input('Leaving: ') Note that building your script like this also allows you to open the interpretter, and type: import mymodule mymodule.main() in order to examine how it runs. --Scott David Daniels Scott.Daniels at Acm.Org From jan.persson at gmail.com Sun Jun 7 09:28:16 2009 From: jan.persson at gmail.com (jpersson) Date: Sun, 7 Jun 2009 06:28:16 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken Message-ID: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Hi, >From the description the library pysync seems to be a perfect match for some of the things I would like to accomplish in my own project. The problem is that all the download links seems to be broken, so I cannot download the code. http://freshmeat.net/projects/pysync/ I've also tried to mail the author, but the mail bounces. Is there anyone out there who happens to have a tarball of this library and who could send me a copy I would be very grateful. Cheers //Jan Persson From no.i.dont at want.mail.from.spammers.com Sun Jun 7 09:39:50 2009 From: no.i.dont at want.mail.from.spammers.com (Fencer) Date: Sun, 07 Jun 2009 15:39:50 +0200 Subject: Keeping console window open In-Reply-To: References: <791rbmF1okia2U1@mid.individual.net> Message-ID: <791u96F1onh1qU1@mid.individual.net> Scott David Daniels wrote: > To be a trifle more explicit, turn: > > ... > if __name__ == '__main__': > main() > > into: > ... > if __name__ == '__main__': > try: > main() > except Exception, why: > print 'Failed:', why > import sys, traceback > traceback.print_tb(sys.exc_info()[2]) > raw_input('Leaving: ') > > Note that building your script like this also allows you to > open the interpretter, and type: > import mymodule > mymodule.main() > in order to examine how it runs. Thanks alot, this was exactly what I was looking for! > > --Scott David Daniels > Scott.Daniels at Acm.Org From rdmurray at bitdance.com Sun Jun 7 10:13:45 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Sun, 7 Jun 2009 14:13:45 +0000 (UTC) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: higer wrote: > My file contains such strings : > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a If those bytes are what is in the file (and it sounds like they are), then the data in your file is not in UTF8 encoding, it is in ASCII encoded as hexidecimal escape codes. > I want to read the content of this file and transfer it to the > corresponding gbk code,a kind of Chinese character encode style. You'll have to convert it from hex-escape into UTF8 first, then. Perhaps better would be to write the original input files in UTF8, since it sounds like that is what you were intending to do. -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From massung at gmail.com Sun Jun 7 10:23:56 2009 From: massung at gmail.com (Jeff M.) Date: Sun, 7 Jun 2009 07:23:56 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <9869d28a-1b7e-4190-a69f-ffb68585c794@t11g2000vbc.googlegroups.com> On Jun 7, 1:56?am, Paul Rubin wrote: > "Jeff M." writes: > > > > Even the lightest weight > > > > user space ("green") threads need a few hundred instructions, minimum, > > > > to amortize the cost of context switching.... > > There's always a context switch. It's just whether or not you are > > switching in/out a virtual stack and registers for the context or the > > hardware stack/registers. > > I don't see the hundreds of instructions in that case. ? > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&... > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. ?Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. ?That simply doesn't leave time > for hundreds of instructions per switch. Who said there has to be? Sample code below (just to get the point across): struct context { vir_reg pc, sp, bp, ... ; object* stack; // ... context* next; }; struct vm { context* active_context; }; void switch_context(vm* v) { // maybe GC v->active_context before switching v->active_context = v->active_context->next; } Also, there isn't "hundreds of instructions" with multiplexing, either. It's all done in hardware. Take a look at the disassembly for any application: one that uses native threads on a platform that supports preemption. You won't see any instructions anywhere in the program that perform a context switch. If you did that would be absolutely horrible. Imagine if the compiler did something like this: while(1) { // whatever } do_context_switch_here(); That would suck. ;-) That's not to imply that there isn't a cost; there's always a cost. The example above just goes to show that for green threads, the cost [of the switch] can be reduced down to a single pointer assignment. Jeff M. From piet at cs.uu.nl Sun Jun 7 10:36:24 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 07 Jun 2009 16:36:24 +0200 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> <87vdn8dxyl.fsf@hal9000.lan> Message-ID: >>>>> Tim Northover (TN) escribi?: >TN> Steven D'Aprano writes: >>> Calling all functional programming fans... is Python's built-in reduce() >>> a left-fold or a right-fold? >TN> I get: >>>>> reduce(lambda a, b: a/b, [1.0, 2.0, 3.0]) >TN> 0.16666666666666666 >TN> which looks like a left fold to me. Yes, see the Haskell result: Prelude> foldl (/) 1.0 [1.0, 2.0, 3.0] 0.16666666666666666 Prelude> foldr (/) 1.0 [1.0, 2.0, 3.0] 1.5 -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jon at ffconsultancy.com Sun Jun 7 11:14:56 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:14:56 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Roedy Green wrote: > On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. Or locks that appear to have low contention and >>negligible performance impact on ``only'' 8 processors suddenly turn into >>bottlenecks. Then there is NUMA. A given address in memory may be >>RAM attached to the processor accessing it, or to another processor, >>with very different access costs. > > Could what you are saying be summed up by saying, "The more threads > you have the more important it is to keep your threads independent, > sharing as little data as possible." I see no problem with mutable shared state. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From noone at lewscanon.com Sun Jun 7 11:16:46 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 11:16:46 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: > the nub of the problem is not on the benchmarks. There is something > to be said for the good old daays when you looked up the instruction > timings that you used in a little document for your machine, and could > know the cost of any loop. We are faster now, but part of the cost of > that speed is that timing is a black art. Those good old days never existed. Those manuals never accounted for things that affected timing even then, like memory latency or refresh time. SRAM cache made things worse, since the published timings never mentioned cache-miss delays. Though memory cache might seem a recent innovation, it's been around a while. It would be challenging to find any published timing since the commercialization of computers that would actually tell the cost of any loop. Things got worse when chips like the '86 family acquired multiple instructions for doing loops, still worse when pre-fetch pipelines became deeper and wider, absolutely Dark Art due to multi-level memory caches becoming universal, and throw-your-hands-up-and-leave-for-the-corner-bar with multiprocessor NUMA systems. OSes and high-level languages complicate the matter - you never know how much time slice you'll get or how your source got compiled or optimized by run-time. So the good old days are a matter of degree and self-deception - it was easier to fool ourselves then that we could at least guess timings proportionately if not absolutely, but things definitely get more unpredictable over evolution. -- Lew From jon at ffconsultancy.com Sun Jun 7 11:20:56 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:20:56 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> Message-ID: George Neuner wrote: > On Fri, 05 Jun 2009 16:26:37 -0700, Roedy Green > wrote: >>On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku >> wrote, quoted or indirectly quoted someone who >>said : >>>Even for problems where it appears trivial, there can be hidden >>>issues, like false cache coherency communication where no actual >>>sharing is taking place. Or locks that appear to have low contention and >>>negligible performance impact on ``only'' 8 processors suddenly turn into >>>bottlenecks. Then there is NUMA. A given address in memory may be >>>RAM attached to the processor accessing it, or to another processor, >>>with very different access costs. >> >>Could what you are saying be summed up by saying, "The more threads >>you have the more important it is to keep your threads independent, >>sharing as little data as possible." > > And therein lies the problem of leveraging many cores. There is a lot > of potential parallelism in programs (even in Java :) that is lost > because it is too fine a grain for threads. That will always be true so it conveys no useful information to the practitioner. > Even the lightest weight > user space ("green") threads need a few hundred instructions, minimum, > to amortize the cost of context switching. Work items in Cilk are much faster than that. > Add to that the fact that programmers have shown themselves, on > average, to be remarkably bad at figuring out what _should_ be done in > parallel - as opposed to what _can_ be done - and you've got a clear > indicator that threads, as we know them, are not scalable except under > a limited set of conditions. Parallelism is inherently not scalable. I see no merit in speculating about the ramifications of "average" programmers alleged inabilities. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jon at ffconsultancy.com Sun Jun 7 11:21:58 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 16:21:58 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Jeff M." writes: >> > > Even the lightest weight >> > > user space ("green") threads need a few hundred instructions, >> > > minimum, to amortize the cost of context switching.... >> There's always a context switch. It's just whether or not you are >> switching in/out a virtual stack and registers for the context or the >> hardware stack/registers. > > I don't see the hundreds of instructions in that case. > > http://shootout.alioth.debian.org/u32q/benchmark.php?test=threadring&lang=ghc&id=3 > > shows GHC doing 50 million lightweight thread switches in 8.47 > seconds, passing a token around a thread ring. Almost all of that is > probably spent acquiring and releasing the token's lock as the token > is passed from one thread to another. That simply doesn't leave time > for hundreds of instructions per switch. And Haskell is not exactly fast... -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From sjmachin at lexicon.net Sun Jun 7 11:25:15 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 08:25:15 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> On Jun 7, 10:55 pm, higer wrote: > My file contains such strings : > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a Are you sure? Does that occupy 9 bytes in your file or 36 bytes? > > I want to read the content of this file and transfer it to the > corresponding gbk code,a kind of Chinese character encode style. > Everytime I was trying to transfer, it will output the same thing no > matter which method was used. > It seems like that when Python reads it, Python will taks '\' as a > common char and this string at last will be represented as "\\xe6\\x97\ > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' > output,but that's not what I want to get. > > Anyone can help me? > try this: utf8_data = your_data.decode('string-escape') unicode_data = utf8_data.decode('utf8') # unicode derived from your sample looks like this ??? is that what you expected? gbk_data = unicode_data.encode('gbk') If that "doesn't work", do three things: (1) give us some unambiguous hard evidence about the contents of your data: e.g. # assuming Python 2.x your_data = open('your_file.txt', 'rb').read(36) print repr(your_data) print len(your_data) print your_data.count('\\') print your_data.count('x') (2) show us the source of the script that you used (3) Tell us what "doesn't work" means in this case Cheers, John From dcest61 at hotmail.com Sun Jun 7 11:35:01 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 15:35:01 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > Roedy Green wrote: >> On Fri, 5 Jun 2009 18:15:00 +0000 (UTC), Kaz Kylheku >> wrote, quoted or indirectly quoted someone who >> said : >>> Even for problems where it appears trivial, there can be hidden >>> issues, like false cache coherency communication where no actual >>> sharing is taking place. Or locks that appear to have low contention and >>> negligible performance impact on ``only'' 8 processors suddenly turn into >>> bottlenecks. Then there is NUMA. A given address in memory may be >>> RAM attached to the processor accessing it, or to another processor, >>> with very different access costs. >> Could what you are saying be summed up by saying, "The more threads >> you have the more important it is to keep your threads independent, >> sharing as little data as possible." > > I see no problem with mutable shared state. > In which case, Jon, you're in a small minority. AHS From Scott.Daniels at Acm.Org Sun Jun 7 11:46:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 08:46:28 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Lew wrote: > Scott David Daniels wrote: >> the nub of the problem is not on the benchmarks. There is something >> to be said for the good old daays when you looked up the instruction >> timings that you used in a little document for your machine, and could >> know the cost of any loop. We are faster now, but part of the cost of >> that speed is that timing is a black art. > > Those good old days never existed. Those manuals never accounted for > things that affected timing even then, like memory latency or refresh > time. Well, as Gilbert and Sullivan wrote: - What, never? - No, never! - What, "Never"? - Well, hardly ever. Look up the LGP-30. It was quite predictable. It has been a while. --Scott David Daniels Scott.Daniels at Acm.Org From luismgz at gmail.com Sun Jun 7 11:53:31 2009 From: luismgz at gmail.com (Neuruss) Date: Sun, 7 Jun 2009 08:53:31 -0700 (PDT) Subject: unladen swallow: python and llvm References: Message-ID: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> On 5 jun, 06:29, Nick Craig-Wood wrote: > Luis M ?Gonz?lez wrote: > > > ?I am very excited by this project (as well as by pypy) and I read all > > ?their plan, which looks quite practical and impressive. > > ?But I must confess that I can't understand why LLVM is so great for > > ?python and why it will make a difference. > > CPython uses a C compiler to compile the python code (written in C) > into native machine code. > > unladen-swallow uses an llvm-specific C compiler to compile the CPython > code (written in C) into LLVM opcodes. > > The LLVM virtual machine executes those LLVM opcodes. ?The LLVM > virtual machine also has a JIT (just in time compiler) which converts > the LLVM op-codes into native machine code. > > So both CPython and unladen-swallow compile C code into native machine > code in different ways. > > So why use LLVM? ?This enables unladen swallow to modify the python > virtual machine to target LLVM instead of the python vm opcodes. > These can then be run using the LLVM JIT as native machine code and > hence run all python code much faster. > > The unladen swallow team have a lot more ideas for optimisations, but > this seems to be the main one. > > It is an interesting idea for a number of reasons, the main one as far > as I'm concerned is that it is more of a port of CPython to a new > architecture than a complete re-invention of python (like PyPy / > IronPython / jython) so stands a chance of being merged back into > CPython. > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Thanks Nick, ok, let me see if I got it: The Python vm is written in c, and generates its own bitecodes which in turn get translated to machine code (one at a time). Unladen Swallow aims to replace this vm by one compiled with the llvm compiler, which I guess will generate different bytecodes, and in addition, supplies a jit for free. Is that correct? It's confussing to think about a compiler which is also a virtual machine, which also has a jit... Another thing that I don't understand is about the "upfront" compilation. Actually, the project plan doesn't mention it, but I read a comment on pypy's blog about a pycon presentation, where they said it would be upfront compilation (?). What does it mean? I guess it has nothing to do with the v8 strategy, because unladen swallow will be a virtual machine, while v8 compiles everything to machine code on the first run. But I still wonder what this mean and how this is different. By the way, I already posted a couple of question on unladen's site. But now I see the discussion is way to "low level" for me, and I wouldn't want to interrupt with my silly basic questions... Luis From stef.mientki at gmail.com Sun Jun 7 12:16:26 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 07 Jun 2009 18:16:26 +0200 Subject: pyc-files contains absolute paths, is this a bug ? Message-ID: <4A2BE7DA.8060801@gmail.com> hello, AFAIK I read that pyc files can be transferred to other systems. I finally got a windows executable working through py2exe, but still have some troubles, moving the directory around. I use Python 2.5.2. I use py2exe to make a distro I can unpack the distro, on a clean computer, anywhere where I like, and it runs fine. Now when I've run it once, I move the subdirectory to another location, at it doesn't run. Looking with a hex editor into some pyc-files, I see absolute paths to the old directory. Is this normal, or am I doing something completely wrong ? thanks, Stef Mientki From tuomas.vesterinen at iki.fi Sun Jun 7 12:31:07 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 19:31:07 +0300 Subject: Python preprosessor Message-ID: <4a2beb4b$0$24760$9b536df3@news.fv.fi> I am developing a Python application as a Python2.x and Python3.0 version. A common code base would make the work easier. So I thought to try a preprosessor. GNU cpp handles this kind of code correct: #ifdef python2 print u'foo', u'bar' #endif #ifdef python3 print('foo', 'bar') #endif results: > cpp -E -Dpython2 test_cpp.py ... print u'foo', u'bar' Any other suggestions? Tuomas Vesterinen From aahz at pythoncraft.com Sun Jun 7 12:42:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 7 Jun 2009 09:42:11 -0700 Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: In article , akindo wrote: > >So, it seems I want the best of both worlds: specific indexing using >my own IDs/keys (not just by list element location), sorting and the >ability to start iterating from a specific location. I am trying to >prevent having to scan through a list from the beginning to find the >desired ID, and then return all elements after that. Is there another >data structure or design pattern which will do what I want? Thanks a >lot for any help! :) One option is to maintain both a dict and a list; it doesn't cost much memory because the individual elements don't get copied. See various "ordered dictionary" implementations for ideas on coding this. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From __peter__ at web.de Sun Jun 7 12:55:48 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Jun 2009 18:55:48 +0200 Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: Tuomas Vesterinen wrote: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > Any other suggestions? http://docs.python.org/dev/3.1/library/2to3.html From steve at REMOVE-THIS-cybersource.com.au Sun Jun 7 12:58:44 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Jun 2009 16:58:44 GMT Subject: pyc-files contains absolute paths, is this a bug ? References: Message-ID: <023be422$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 18:16:26 +0200, Stef Mientki wrote: > hello, > > AFAIK I read that pyc files can be transferred to other systems. I > finally got a windows executable working through py2exe, but still have > some troubles, moving the directory around. Sounds like a py2exe problem, not a Python problem. Perhaps you should ask them? https://lists.sourceforge.net/lists/listinfo/py2exe-users > I use Python 2.5.2. > I use py2exe to make a distro > I can unpack the distro, on a clean computer, anywhere where I like, and > it runs fine. > > Now when I've run it once, > I move the subdirectory to another location, at it doesn't run. Define "doesn't run". You mean the exe file doesn't launch at all? Does Windows display an error message? Or perhaps it launches, then immediately exists? Launches, then crashes? Does it show up in the process list at all? Or something else? -- Steven From no.email at please.post Sun Jun 7 13:11:41 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 17:11:41 +0000 (UTC) Subject: How to get local copy of docs? Message-ID: What's the best way to get a local copy of the documentation at http://docs.python.org? (The goal is to have access to this documentation even when offline.) TIA! kynn -- From http Sun Jun 7 13:25:41 2009 From: http (Paul Rubin) Date: 07 Jun 2009 10:25:41 -0700 Subject: Is reduce() foldl() or foldr()? References: <023b8bec$0$20636$c3e8da3@news.astraweb.com> Message-ID: <7x63f8dkh6.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Calling all functional programming fans... is Python's built-in reduce() > a left-fold or a right-fold? It's a left fold. > but other people say it's a right-fold, e.g.: > "... there is a `foldr` in Haskell that just works like `reduce()`" That is correct in the sense that a coding situation where you'd use reduce in Python would often lead you to use foldr (with its different semantics) in Haskell. This is because of Haskell's lazy evaluation. Example: suppose you have a list of lists, like xss = [[1,2],[3,4,5],[6,7]] and you want to concatenate them all. (++) is Haskell's list concatenation function, like Python uses + for list concatenation. So you could say ys = foldl (++) [] xss but if I have it right, that would have to traverse the entire input list before it gives you any of the answer, which can be expensive for a long list, or fail totally for an infinite list. foldr on the other hand can generate the result lazily, in sync with the way the caller consumes the elements, like writing a generator in Haskell. The tutorial http://learnyouahaskell.com/higher-order-functions#folds explains this a bit more. You might also like the Real World Haskell book: http://book.realworldhaskell.org From python at mrabarnett.plus.com Sun Jun 7 13:34:46 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Jun 2009 18:34:46 +0100 Subject: unladen swallow: python and llvm In-Reply-To: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> References: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> Message-ID: <4A2BFA36.1030305@mrabarnett.plus.com> Neuruss wrote: > On 5 jun, 06:29, Nick Craig-Wood wrote: >> Luis M Gonz?lez wrote: >> >>> I am very excited by this project (as well as by pypy) and I read all >>> their plan, which looks quite practical and impressive. >>> But I must confess that I can't understand why LLVM is so great for >>> python and why it will make a difference. >> CPython uses a C compiler to compile the python code (written in C) >> into native machine code. >> >> unladen-swallow uses an llvm-specific C compiler to compile the CPython >> code (written in C) into LLVM opcodes. >> >> The LLVM virtual machine executes those LLVM opcodes. The LLVM >> virtual machine also has a JIT (just in time compiler) which converts >> the LLVM op-codes into native machine code. >> >> So both CPython and unladen-swallow compile C code into native machine >> code in different ways. >> >> So why use LLVM? This enables unladen swallow to modify the python >> virtual machine to target LLVM instead of the python vm opcodes. >> These can then be run using the LLVM JIT as native machine code and >> hence run all python code much faster. >> >> The unladen swallow team have a lot more ideas for optimisations, but >> this seems to be the main one. >> >> It is an interesting idea for a number of reasons, the main one as far >> as I'm concerned is that it is more of a port of CPython to a new >> architecture than a complete re-invention of python (like PyPy / >> IronPython / jython) so stands a chance of being merged back into >> CPython. >> >> -- >> Nick Craig-Wood --http://www.craig-wood.com/nick > > Thanks Nick, > ok, let me see if I got it: > The Python vm is written in c, and generates its own bitecodes which > in turn get translated to machine code (one at a time). > Unladen Swallow aims to replace this vm by one compiled with the llvm > compiler, which I guess will generate different bytecodes, and in > addition, supplies a jit for free. Is that correct? > [snip] No. CPython is written in C (hence the name). It compiles Python source code to bytecodes. The bytecodes are instructions for a VM which is written in C, and they are interpreted one by one. There's no compilation to machine code. From tuomas.vesterinen at iki.fi Sun Jun 7 14:09:30 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 21:09:30 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: <4a2c025a$0$24756$9b536df3@news.fv.fi> Peter Otten wrote: > Tuomas Vesterinen wrote: > >> I am developing a Python application as a Python2.x and Python3.0 >> version. A common code base would make the work easier. So I thought to >> try a preprosessor. GNU cpp handles this kind of code correct: > >> Any other suggestions? > > http://docs.python.org/dev/3.1/library/2to3.html > > I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the other in py3. When changing the code I have to do things to 2 separate codebase in the repository. There are no patch2to3 or patch3to2, So I thought that for ensuring the common functionality of both version it would be nice to bring both versions into a common codebase. So I can update only one code and automate builds and tests for both versions. Tuomas Vesterinen From nick at craig-wood.com Sun Jun 7 14:29:39 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sun, 07 Jun 2009 13:29:39 -0500 Subject: unladen swallow: python and llvm References: <7df3ced4-e12f-45ba-801d-1c166771a5c3@q14g2000vbn.googlegroups.com> Message-ID: Neuruss wrote: > ok, let me see if I got it: > The Python vm is written in c, and generates its own bitecodes which > in turn get translated to machine code (one at a time). > Unladen Swallow aims to replace this vm by one compiled with the llvm > compiler, which I guess will generate different bytecodes, and in > addition, supplies a jit for free. Is that correct? Pretty good I think! > It's confussing to think about a compiler which is also a virtual > machine, which also has a jit... Well the compiler is actually gcc with a llvm opcodes backend. > Another thing that I don't understand is about the "upfront" > compilation. > Actually, the project plan doesn't mention it, but I read a comment on > pypy's blog about a pycon presentation, where they said it would be > upfront compilation (?). What does it mean? I don't know, I'm afraid. > I guess it has nothing to do with the v8 strategy, because unladen > swallow will be a virtual machine, while v8 compiles everything to > machine code on the first run. But I still wonder what this mean and > how this is different. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From jon at ffconsultancy.com Sun Jun 7 14:41:43 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 19:41:43 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> I see no problem with mutable shared state. > > In which case, Jon, you're in a small minority. No. Most programmers still care about performance and performance means mutable state. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jon at ffconsultancy.com Sun Jun 7 14:43:25 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 19:43:25 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: Scott David Daniels wrote: > Lew wrote: >> Scott David Daniels wrote: >>> the nub of the problem is not on the benchmarks. There is something >>> to be said for the good old daays when you looked up the instruction >>> timings that you used in a little document for your machine, and could >>> know the cost of any loop. We are faster now, but part of the cost of >>> that speed is that timing is a black art. >> >> Those good old days never existed. Those manuals never accounted for >> things that affected timing even then, like memory latency or refresh >> time. > > Well, as Gilbert and Sullivan wrote: > - What, never? > - No, never! > - What, "Never"? > - Well, hardly ever. > Look up the LGP-30. It was quite predictable. It has been a while. Same for early ARMs. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From no.email at please.post Sun Jun 7 14:44:51 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 18:44:51 +0000 (UTC) Subject: fileinput.input(f,inplace=True,...) preserves perms? Message-ID: Does fileinput.input(files, inplace=True, ...) preserve the permissions of the file? (I.e. does it ensure that the new file has the same permissions as the original file?) TIA! kynn -- From tomasz.zielinski at pyconsultant.eu Sun Jun 7 15:15:22 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Sun, 7 Jun 2009 12:15:22 -0700 (PDT) Subject: How to get local copy of docs? References: Message-ID: <2dbd9a27-78b0-4194-89eb-4b5a953c9e20@x3g2000yqa.googlegroups.com> On 7 Cze, 19:11, kj wrote: > What's the best way to get a local copy of the documentation athttp://docs.python.org??(The goal is to have access to this > documentation even when offline.) They have also CHM version (I'm not not sure where I got it from, but I think it was Windows installer). -- Tomasz Zieli?ski http://pyconsultant.eu From danwgrace at gmail.com Sun Jun 7 15:21:46 2009 From: danwgrace at gmail.com (Daniel) Date: Sun, 7 Jun 2009 12:21:46 -0700 (PDT) Subject: 403 error for python webpage Message-ID: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> I created a page with a ".py" extension but the browser does not like it. Here is what I did: I edited httpd.conf file and added the line: AddHandler cgi-script .cgi .py Then I stopped and restarted apache. Next I created a hello world file as on this page: http://deron.meranda.us/python/webserving/helloworld.html I stored the file in htdocs and then went to the corresponding http://127.0.0.1/python/testhw.py in my browser. But the browser gives a 403 error. I am running from internet explorer on windows xp. From Pidgeot18 at verizon.invalid Sun Jun 7 15:35:34 2009 From: Pidgeot18 at verizon.invalid (Joshua Cranmer) Date: Sun, 07 Jun 2009 15:35:34 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > No. Most programmers still care about performance and performance means > mutable state. [ Citation needed ]. Most programmers I've met could care less about performance. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth From jonas.esp at googlemail.com Sun Jun 7 16:14:49 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 13:14:49 -0700 (PDT) Subject: Get the class name Message-ID: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Is there any way of to get the class name to avoid to have that write it? --------------- class Foo: super(Foo, self) --------------- * Using Py 2.6.2 From dcest61 at hotmail.com Sun Jun 7 16:19:16 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 20:19:16 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <8hVWl.29780$Db2.10968@edtnps83> Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> I see no problem with mutable shared state. >> In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance and performance means > mutable state. Quite apart from performance and mutable state, I believe we were talking about mutable _shared_ state. And this is something that gets a _lot_ of people into trouble. AHS From fossilx at gmail.com Sun Jun 7 16:24:06 2009 From: fossilx at gmail.com (TonyM) Date: Sun, 7 Jun 2009 13:24:06 -0700 (PDT) Subject: How to get local copy of docs? References: Message-ID: On Jun 7, 1:11?pm, kj wrote: > What's the best way to get a local copy of the documentation athttp://docs.python.org??(The goal is to have access to this > documentation even when offline.) > > TIA! > > kynn > -- http://docs.python.org/download.html From bearophileHUGS at lycos.com Sun Jun 7 16:25:48 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 13:25:48 -0700 (PDT) Subject: Iterating Over Dictionary From Arbitrary Location References: Message-ID: <66d43d81-92c0-4d2f-825f-05d4f0be5736@c9g2000yqm.googlegroups.com> Aahz: > See various "ordered dictionary" implementations > for ideas on coding this. But be careful to not confuse ordered dictionaries with sorted ones :-) Bye, bearophile From bearophileHUGS at lycos.com Sun Jun 7 16:35:33 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 13:35:33 -0700 (PDT) Subject: unladen swallow: python and llvm References: Message-ID: Luis M. Gonz?lez: > it seems they intend to do "upfront > compilation". How? Unladen swallow developers want to try everything (but black magic and necromancy) to increase the speed of Cpython. So they will try to compile up-front if/where they can (for example most regular expressions are known at compile time, so there's no need to compile them at run time. I don't know if Cpython compiles them before running time). What I like of Unladen swallow is that it's a very practical approach, very different in style from ShedSkin and PyPy (and it's more ambitious than Psyco). I also like Unladen swallow because they are the few people that have the boldness to do something to increase the performance of Python for real. They have a set of reference benchmarks that are very real, not synthetic at all, so for example they refuse to use Pystones and the like. What I don't like of Unladen swallow is that integrating LLVM with the CPython codebase looks like a not much probable thing. Another thing I don't like is the name of such project, it's not easy to pronounce for non-English speaking people. Bye, bearophile From tuomas.vesterinen at iki.fi Sun Jun 7 16:41:37 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Sun, 07 Jun 2009 23:41:37 +0300 Subject: Get the class name In-Reply-To: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <4a2c2600$0$6277$9b536df3@news.fv.fi> Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > super(Foo, self) > --------------- > > > * Using Py 2.6.2 >>> class Foo(object): ... def cls(self): ... return self.__class__ ... >>> Foo().cls() From aljosa.mohorovic at gmail.com Sun Jun 7 16:54:19 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Sun, 7 Jun 2009 13:54:19 -0700 (PDT) Subject: pypi compatible software Message-ID: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> i've been searching for a recommended way to setup private pypi repository and i've found several options: - PloneSoftwareCenter - http://code.google.com/p/pypione/ - http://pypi.python.org/pypi/haufe.eggserver - http://www.chrisarndt.de/projects/eggbasket/ - http://pypi.python.org/pypi/ClueReleaseManager so now i have a few questions: - is code behind pypi.python.org available and why i can't find some up-to-date official document or howto for private pypi repository (maybe it exists but i just can't find it)? - since python is used in commercial environments i guess they actually have private pypi repositories, where can i find docs that defines what pypi is and how to implement it? - can you recommend 1 option (software providing pypi like service) that can be easily installed and configured as a service running on apache2/mod_wsgi, has an active community and docs howto setup? - i did found http://www.python.org/dev/peps/pep-0381/ - is this the spec that above mentioned software is based upon? any additional info or comments appreciated. Aljosa Mohorovic From pats at acm.org Sun Jun 7 17:04:49 2009 From: pats at acm.org (Patricia Shanahan) Date: Sun, 07 Jun 2009 14:04:49 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> I see no problem with mutable shared state. >> In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance and performance means > mutable state. > I don't see why that would affect whether one thinks there are problems. In my opinion, shared mutable state has a lot of problems. It is also sometimes the best design for performance reasons. Patricia From pengmeister at gmail.com Sun Jun 7 17:06:17 2009 From: pengmeister at gmail.com (=?ISO-8859-1?Q?S=F8ren_=2D_Peng_=2D_Pedersen?=) Date: Sun, 7 Jun 2009 14:06:17 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken References: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Message-ID: I think what you are looking for can be found at: http://www.google.com/codesearch/p?hl=en#RncWxgazS6A/pysync-2.24/test/testdata.py&q=pysync%20package:%22http://minkirri.apana.org.au/~abo/projects/pysync/arc/pysync-2.24.tar.bz2%22%20lang:python or http://shortlink.dk/58664133 I am not affiliated with the project in any way, and I can't find a way to download the entire thing in one go. So if you do salvage a working copy please let me (and the rest of the community) know. //S?ren - Peng - Pedersen From jon at ffconsultancy.com Sun Jun 7 17:29:06 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:29:06 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Jon Harrop wrote: >>>> I see no problem with mutable shared state. >>> >>> In which case, Jon, you're in a small minority. >> >> No. Most programmers still care about performance and performance means >> mutable state. > > Quite apart from performance and mutable state, I believe we were > talking about mutable _shared_ state. And this is something that gets a > _lot_ of people into trouble. Nonsense. Scientists have been writing parallel programs for decades using shared state extensively without whining about it. Databases are mutable shared state but millions of database programmers solve real problems every day without whining about it. Use your common sense and you can write efficient parallel programs today with little difficulty. I do. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From jonas.esp at googlemail.com Sun Jun 7 17:33:16 2009 From: jonas.esp at googlemail.com (Kless) Date: Sun, 7 Jun 2009 14:33:16 -0700 (PDT) Subject: Properties for several keywords References: Message-ID: On 7 jun, 11:45, Kless wrote: > I've to write properties for several keywords with the same code, it > only changes the name of each property: > > ----------------------------- > @property > ? ?def foo(self): > ? ? ? return self._foo > > @foo.setter > ? ?def foo(self, txt): > ? ? ? self._foo = self._any_function(txt) > > # ---------------- > > @property > def bar(self): > ? ?return self._bar > > @bar.setter > def bar(self, txt): > ? ?self._bar = self._any_function(txt) > ----------------------------- > > Is possible to simplify it? Please, is there any solution for this problem? From no.email at please.post Sun Jun 7 17:35:49 2009 From: no.email at please.post (kj) Date: Sun, 7 Jun 2009 21:35:49 +0000 (UTC) Subject: How to get local copy of docs? References: Message-ID: In TonyM writes: >http://docs.python.org/download.html Perfect. Thanks! kynn -- From jon at ffconsultancy.com Sun Jun 7 17:38:33 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:38:33 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Joshua Cranmer wrote: > Jon Harrop wrote: >> No. Most programmers still care about performance and performance means >> mutable state. > > [ Citation needed ]. > > Most programmers I've met could care less about performance. Then they have no need for parallelism in the first place. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From http Sun Jun 7 17:40:23 2009 From: http (Paul Rubin) Date: 07 Jun 2009 14:40:23 -0700 Subject: unladen swallow: python and llvm References: Message-ID: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> bearophileHUGS at lycos.com writes: > What I like of Unladen swallow is that it's a very practical approach, > very different in style from ShedSkin and PyPy (and it's more > ambitious than Psyco). I also like Unladen swallow because they are > the few people that have the boldness to do something to increase the > performance of Python for real. IMHO the main problem with the Unladen Swallow approach is that it would surprise me if CPython really spends that much of its time interpreting byte code. Is there some profiling output around? My guess is that CPython spends an awful lot of time in dictionary lookups for method calls, plus incrementing and decrementing ref counts and stuff like that. Plus, the absence of a relocating garbage collector may mess up cache hit ratios pretty badly. Shed Skin as I understand it departs in some ways from Python semantics in order to get better compiler output, at the expense of breaking some Python programs. I think that is the right approach, as long as it's not done too often. That's the main reason why I think it's unfortunate that Python 3.0 broke backwards compatibility at the particular time that it did. From massung at gmail.com Sun Jun 7 17:41:39 2009 From: massung at gmail.com (Jeff M.) Date: Sun, 7 Jun 2009 14:41:39 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> Message-ID: <6c5eab9d-a35d-43df-b45c-d2559c7b2623@f10g2000vbf.googlegroups.com> On Jun 7, 3:19?pm, Arved Sandstrom wrote: > Jon Harrop wrote: > > Arved Sandstrom wrote: > >> Jon Harrop wrote: > >>> I see no problem with mutable shared state. > >> In which case, Jon, you're in a small minority. > > > No. Most programmers still care about performance and performance means > > mutable state. > > Quite apart from performance and mutable state, I believe we were > talking about mutable _shared_ state. And this is something that gets a > _lot_ of people into trouble. > Mutable shared state gets _bad_ (err.. perhaps "inexperienced" would be a better adjective) programmers - who don't know what they are doing - in trouble. There are many problem domains that either benefit greatly from mutable shared states or can't [easily] be done without them. Unified memory management being an obvious example... there are many more. Unshared state has its place. Immutable state has its place. Shared immutable state has its place. Shared mutable place has its place. Jeff M. From noone at lewscanon.com Sun Jun 7 17:45:13 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 17:45:13 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: >>>> I see no problem with mutable shared state. >>> In which case, Jon, you're in a small minority. Patricia Shanahan wrote: > In my opinion, shared mutable state has a lot of problems. It is also > sometimes the best design for performance reasons. As Dr. Jon pointed out upthread, one can write decent code with mutable shared state. It is also true that mutable state presents a lot of problems - potential problems, ones that can be solved, but not ones that can be solved thoughtlessly. On the flip side, one can write a tremendous amount of effective multi-threaded code involving shared mutable state with attention to a few rules of thumb, like always synchronize access and don't use different monitors to do so. Unlike some environments (e.g., database management systems), Java's tools to manage concurrency are explicit and low level. The programmer's job is to make sure those tools are used correctly to avoid problems. As long as they do that, then there is no special problem with shared mutable state. There is, however, a cost. Certain things must happen slower when you share mutable state, than when you share immutable state or don't share state. Certain things must happen when you share mutable state, regardless of speed, because without them your code doesn't work. For some reason, concurrent programming is an area often not well understood by a significant percentage of workaday programmers. When problems do arise, they tend to be probabilistic in nature and vary widely with system characteristics like attempted load. So the meeting ground is, yes, concurrent mutable state can present problems if not properly managed. Properly managing such is not necessarily a huge burden, but it must be borne. When done properly, shared mutable state will not present problems in production. -- Lew From jon at ffconsultancy.com Sun Jun 7 17:51:48 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 22:51:48 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <8hVWl.29780$Db2.10968@edtnps83> <6c5eab9d-a35d-43df-b45c-d2559c7b2623@f10g2000vbf.googlegroups.com> Message-ID: Jeff M. wrote: > On Jun 7, 3:19?pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >> > Arved Sandstrom wrote: >> >> Jon Harrop wrote: >> >>> I see no problem with mutable shared state. >> >> In which case, Jon, you're in a small minority. >> >> > No. Most programmers still care about performance and performance means >> > mutable state. >> >> Quite apart from performance and mutable state, I believe we were >> talking about mutable _shared_ state. And this is something that gets a >> _lot_ of people into trouble. > > Mutable shared state gets _bad_ (err.. perhaps "inexperienced" would > be a better adjective) programmers - who don't know what they are > doing - in trouble. There are many problem domains that either benefit > greatly from mutable shared states or can't [easily] be done without > them. Unified memory management being an obvious example... there are > many more. Unshared state has its place. Immutable state has its > place. Shared immutable state has its place. Shared mutable place has > its place. Exactly. I don't believe that shared mutable state is any harder to do correctly than the next solution and it is almost always the most efficient solution and the sole purpose of writing parallel programs to leverage multicores is performance. A bad developer can screw up anything. I see no reason to think that shared mutable state is any more fragile than the next thing a bad developer can screw up. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From martin at v.loewis.de Sun Jun 7 17:54:43 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 07 Jun 2009 23:54:43 +0200 Subject: pypi compatible software In-Reply-To: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> References: <662fabac-6229-4af2-a6d2-3dd49fe68fc4@m19g2000yqk.googlegroups.com> Message-ID: <4a2c3724$0$13985$9b622d9e@news.freenet.de> > - is code behind pypi.python.org available and why i can't find some > up-to-date official document or howto for private pypi repository > (maybe it exists but i just can't find it)? The code is at https://svn.python.org/packages/ Instructions for installing it are at http://wiki.python.org/moin/CheeseShopDev I don't know why you can't find it, perhaps you didn't search long enough. > - since python is used in commercial environments i guess they > actually have private pypi repositories, where can i find docs that > defines what pypi is and how to implement it? IMO, there can't possibly be a "private pypi repository". By (my) definition, PyPI is *the* Python Package Index - anything else holding packages can't be *the* index. So: pypi is a short name for the machine pypi.python.org, and it is not possible to "implement" it elsewhere, unless you have write access to the nameserver of python.org. Maybe you are asking for a specification of how setuptools and easy_install access the index, to build package repositories other than PyPI. This is specified at http://peak.telecommunity.com/DevCenter/EasyInstall#package-index-api If you are asking for something else, please be more explicit what it is that you ask for. > - can you recommend 1 option (software providing pypi like service) > that can be easily installed and configured as a service running on > apache2/mod_wsgi, has an active community and docs howto setup? If you want a plain package repository, I recommend to use Apache without any additional software. It's possible to provide a package repository completely out of static files - no dynamic code is necessary. > - i did found http://www.python.org/dev/peps/pep-0381/ - is this the > spec that above mentioned software is based upon? No, that's what the title of the document says: a "Mirroring infrastructure for PyPI". Regards, Martin From noone at lewscanon.com Sun Jun 7 18:03:48 2009 From: noone at lewscanon.com (Lew) Date: Sun, 07 Jun 2009 18:03:48 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Jon Harrop wrote: > I agree entirely but my statements were about parallelism and not > concurrency. Parallel and concurrent programming have wildly different > characteristics and solutions. I don't believe shared mutable state is > overly problematic in the context of parallelism. Indeed, I think it is > usually the best solution in that context. Interesting distinction. Would it be fair to compare concurrent programming to the bricks used to build the parallel program's edifice? -- Lew From jon at ffconsultancy.com Sun Jun 7 18:03:49 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 07 Jun 2009 23:03:49 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > As Dr. Jon pointed out upthread, one can write decent code with mutable > shared > state. It is also true that mutable state presents a lot of problems - > potential problems, ones that can be solved, but not ones that can be > solved > thoughtlessly. On the flip side, one can write a tremendous amount of > effective multi-threaded code involving shared mutable state with > attention to a few rules of thumb, like always synchronize access and > don't use different monitors to do so. > > Unlike some environments (e.g., database management systems), Java's tools > to > manage concurrency are explicit and low level. The programmer's job is to > make sure those tools are used correctly to avoid problems. As long as > they do that, then there is no special problem with shared mutable state. > > There is, however, a cost. Certain things must happen slower when you > share mutable state, than when you share immutable state or don't share > state. Certain things must happen when you share mutable state, regardless > of speed, > because without them your code doesn't work. For some reason, concurrent > programming is an area often not well understood by a significant > percentage > of workaday programmers. When problems do arise, they tend to be > probabilistic in nature and vary widely with system characteristics like > attempted load. > > So the meeting ground is, yes, concurrent mutable state can present > problems > if not properly managed. Properly managing such is not necessarily a huge > burden, but it must be borne. When done properly, shared mutable state > will not present problems in production. I agree entirely but my statements were about parallelism and not concurrency. Parallel and concurrent programming have wildly different characteristics and solutions. I don't believe shared mutable state is overly problematic in the context of parallelism. Indeed, I think it is usually the best solution in that context. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From nowhere at home.com Sun Jun 7 18:11:11 2009 From: nowhere at home.com (Ken T.) Date: 07 Jun 2009 22:11:11 GMT Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: > So the good old days are a matter of degree and self-deception - it was > easier to fool ourselves then that we could at least guess timings > proportionately if not absolutely, but things definitely get more > unpredictable over evolution. As I recall I could get exact timings on my 6502 based Commodore 64. The issues you speak of simply weren't issues. -- Ken T. http://www.electricsenator.net Never underestimate the power of stupid people in large groups. From Scott.Daniels at Acm.Org Sun Jun 7 18:13:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 07 Jun 2009 15:13:09 -0700 Subject: Properties for several keywords In-Reply-To: References: Message-ID: Kless wrote: > On 7 jun, 11:45, Kless wrote: >> I've to write properties for several keywords with the same code, it >> only changes the name of each property: ... >> Is possible to simplify it? > Please, is there any solution for this problem? Read up on property. It is the core of your answer. That being said, from your recent messages, it looks a lot like you are fighting the language, rather than using it. Pythonic code is clear about what it is doing; avoid tricky automatic stuff. def mangled(name, doc_text=None): funny_name = '_' + name def getter(self): return getattr(self, funny_name) def setter(self, text): setattr(self, funny_name, self._mangle(text)) return property(getter, setter, doc=doc_text) class MangledParts(object): blue = mangled('blue', "our side") red = mangled('red', "their side") white = mangled('white', "the poor civilians") def _mangle(self, text): print text return text.join('<>') --Scott David Daniels Scott.Daniels at Acm.Org From bearophileHUGS at lycos.com Sun Jun 7 18:31:15 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Sun, 7 Jun 2009 15:31:15 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> Message-ID: <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> Paul Rubin: >IMHO the main problem with the Unladen Swallow approach is that it would surprise me if CPython really spends that much of its time interpreting byte code.< Note that Py3 already has a way to speed up byte code interpretation where compiled by GCC or Intel compiler (it's a very old strategy used by Forth compilers, that in Py3 is used only partially. The strongest optimizations used many years ago in Forth aren't used yet in Py3, probably to keep the Py3 virtual machine simpler, or maybe because there are not enough Forth experts among them). Unladen swallow developers are smart and they attack the problem from every side they can think of, plus some sides they can't think of. Be ready for some surprises :-) >Is there some profiling output around?< I am sure they swim every day in profiler outputs :-) But you have to ask to them. >Plus, the absence of a relocating garbage collector may mess up cache hit ratios pretty badly.< I guess they will try to add a relocating GC too, of course. Plus some other strategy. And more. And then some cherries on top, with whipped cream just to be sure. >Shed Skin as I understand it departs in some ways from Python semantics in order to get better compiler output, at the expense of breaking some Python programs. I think that is the right approach, as long as it's not done too often.< ShedSkin (SS) is a beast almost totally different from CPython, SS compiles an implicitly static subset of Python to C++. So it breaks most real Python programs, and it doesn't use the Python std lib (it rebuilds one in C++ or compiled Python), and so on. SS may be useful for people that don't want to mess with the intricacies of Cython (ex-Pyrex) and its tricky reference count, to create compiled python extensions. But so far I think nearly no one is using SS for such purpose, so it may be a failed experiment (SS is also slow in compiling, it's hard to make it compile more than 1000-5000 lines of code). Bye, bearophile From Brian.Mingus at colorado.edu Sun Jun 7 18:40:07 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Sun, 7 Jun 2009 16:40:07 -0600 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> On Fri, Jun 5, 2009 at 3:29 AM, Nick Craig-Wood wrote: > > > It is an interesting idea for a number of reasons, the main one as far > as I'm concerned is that it is more of a port of CPython to a new > architecture than a complete re-invention of python (like PyPy / > IronPython / jython) so stands a chance of being merged back into > CPython. > Blatant fanboyism. PyPy also has a chance of being merged back into Python trunk. -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Sun Jun 7 18:45:09 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 7 Jun 2009 15:45:09 -0700 (PDT) Subject: can it be shorter? References: Message-ID: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> On Jun 6, 8:07?am, "tsangpo" wrote: > I want to ensure that the url ends with a '/', now I have to do thisa like > below. > url = url + '' if url[-1] == '/' else '/' > > Is there a better way? url+= { '/': '' }.get( url[ -1 ], '/' ) Shorter is always better. From Brian.Mingus at colorado.edu Sun Jun 7 18:59:36 2009 From: Brian.Mingus at colorado.edu (Brian) Date: Sun, 7 Jun 2009 16:59:36 -0600 Subject: can it be shorter? In-Reply-To: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <9839a05c0906071559l6103ae9bq5dfd782751b85648@mail.gmail.com> Since extra slashes at the end of a URL are ignored, that means I win! url+='/' On Sun, Jun 7, 2009 at 4:45 PM, Aaron Brady wrote: > On Jun 6, 8:07 am, "tsangpo" wrote: > > I want to ensure that the url ends with a '/', now I have to do thisa > like > > below. > > url = url + '' if url[-1] == '/' else '/' > > > > Is there a better way? > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Shorter is always better. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Jun 7 19:13:58 2009 From: http (Paul Rubin) Date: 07 Jun 2009 16:13:58 -0700 Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <7x63f7iqmh.fsf@ruckus.brouhaha.com> Aaron Brady writes: > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Shorter is always better. url = url.rstrip('/') + '/' From dcest61 at hotmail.com Sun Jun 7 19:21:14 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Sun, 07 Jun 2009 23:21:14 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > Jon Harrop wrote: >> I agree entirely but my statements were about parallelism and not >> concurrency. Parallel and concurrent programming have wildly different >> characteristics and solutions. I don't believe shared mutable state is >> overly problematic in the context of parallelism. Indeed, I think it is >> usually the best solution in that context. > > Interesting distinction. Would it be fair to compare concurrent > programming to the bricks used to build the parallel program's edifice? Way too much of a fine distinction. While they are in fact different, the point of concurrent programming is to structure programs as a group of computations, which can be executed in parallel (however that might actually be done depending on how many processors there are). Parallel computing means to carry out many computations simultaneously. These are interleaved definitions. And they are *not* wildly different. If you talk about shared mutable state, it is not as easy to use as Dr Harrop seems to think it is. Maybe in his experience it has been, but in general it's no trivial thing to manage. Lew, you probably summarized it best a few posts upstream. AHS From rogerb at rogerbinns.com Sun Jun 7 19:36:54 2009 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 07 Jun 2009 16:36:54 -0700 Subject: Python preprosessor In-Reply-To: <4a2c025a$0$24756$9b536df3@news.fv.fi> References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> <4a2c025a$0$24756$9b536df3@news.fv.fi> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tuomas Vesterinen wrote: > I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the > other in py3. The expectation would be that you only maintain the py2 code and automatically generate the py3 code on demand using 2to3. It is possible to have the same code run under both versions, but not recommended. As an example I do this for the APSW test suite, mostly because the test code deliberately explores various corner cases that 2to3 could not convert (nor should it try!). Here is how I do the whole Unicode thing: if py3: # defined earlier UPREFIX="" else: UPREFIX="u" def u(x): # use with raw strings return eval(UPREFIX+"'''"+x+"'''") # Example of use u(r"\N${BLACK STAR}\u234") You can pull similar stunts for bytes (I use buffers in py2), long ints (needing L suffix in some py2 versions), the next() builtin from py3, exec syntax differences etc. You can see more details in the first 120 lines of http://code.google.com/p/apsw/source/browse/apsw/trunk/tests.py Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkosTxEACgkQmOOfHg372QS4rQCgl1ymNME2kdHTBUoc7/f2e+W6 cbMAmwf7mArr7hVA8k/US53JE59ChnIt =pQ92 -----END PGP SIGNATURE----- From python at rcn.com Sun Jun 7 19:46:23 2009 From: python at rcn.com (Raymond Hettinger) Date: Sun, 7 Jun 2009 16:46:23 -0700 (PDT) Subject: Making the case for repeat References: Message-ID: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> [pataphor] > So here is my proposed suggestion for a once and for all reconciliation > of various functions in itertools that can not stand on their own and > keep a straight face. Interesting phraseology ;-) Enticing and yet fallacious in its presumption of known and accepted usability problems. FWIW, when I designed the module, I started by researching constructs that had proven success in functional languages and then adapted them to the needs of Python applications. That being said, I'm always open to hearing new ideas. After reading this thread a couple times, I have a few thoughts to offer. 1. The Pythonic Way(tm) is to avoid combining too much functionality in a single function, preferring to split when possible. That is why ifilter() and ifilterfalse() are separate functions. (FWIW, the principle is considered pythonic because it was articulated by Guido and has been widely applied throughout the language.) There is a natural inclination to do the opposite. We factor code to eliminate redundancy, but that is not always a good idea with an API. The goal for code factoring is to minimize redundancy. The goal for API design is having simple parts that are easily learned and can be readily combined (i.e. the notion of an iterator algebra). It is not progress to mush the parts together in a single function requiring multiple parameters. 2. I question the utility of some combining repeat() and cycle() because I've not previously seen the two used together. OTOH, there may be some utility to producing a fixed number of cycles (see the ncycles() recipe in the docs). Though, if I thought this need arose very often (it has never been requested), the straight-forward solution would be to add a "times" argument to cycle(), patterned after repeat()'s use of a "times" argument. 3. Looking at the sample code provided in your post, I would suggest rewriting it as a factory function using the existing tools as components. That way, the result of the function will still run at C speed and not be slowed by corner cases or unused parameters. (see the ncycles recipe for an example of how to do this). 4. The suggested combined function seems to emphasize truncated streams (i.e. a fixed number of repetitions or cycles). This is at odds with the notion of a toolset designed to allow lazy infinite iterators to be fed to consumer functions that truncate on the shortest iterable. For example, the toolset supports: izip(mydata, count(), repeat(datetime.now())) in preference to: izip(mydata, islice(count(), len(mydata)), repeat(datetime.now (),times=len(mydata))) To gain a better appreciation for this style (and for the current design of itertools), look at the classic Hughes' paper "Why Functional Programming Matters". http://www.math.chalmers.se/~rjmh/Papers/whyfp.pdf Raymond From sjmachin at lexicon.net Sun Jun 7 19:47:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 16:47:22 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: On Jun 8, 12:13?am, "R. David Murray" wrote: > higer wrote: > > My file contains such strings : > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > If those bytes are what is in the file (and it sounds like they are), > then the data in your file is not in UTF8 encoding, it is in ASCII > encoded as hexidecimal escape codes. OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or r"\xe6" by what mechanism in which parallel universe? From jon at ffconsultancy.com Sun Jun 7 19:59:52 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 00:59:52 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Arved Sandstrom wrote: > Lew wrote: >> Interesting distinction. Would it be fair to compare concurrent >> programming to the bricks used to build the parallel program's edifice? > > Way too much of a fine distinction. While they are in fact different, > the point of concurrent programming is to structure programs as a group > of computations, which can be executed in parallel (however that might > actually be done depending on how many processors there are). No. Concurrent programming is about interleaving computations in order to reduce latency. Nothing to do with parallelism. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From python at mrabarnett.plus.com Sun Jun 7 20:20:43 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 01:20:43 +0100 Subject: how to transfer my utf8 code saved in a file to gbk code In-Reply-To: References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <4A2C595B.3080301@mrabarnett.plus.com> John Machin wrote: > On Jun 8, 12:13 am, "R. David Murray" wrote: >> higer wrote: >>> My file contains such strings : >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a >> If those bytes are what is in the file (and it sounds like they are), >> then the data in your file is not in UTF8 encoding, it is in ASCII >> encoded as hexidecimal escape codes. > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > r"\xe6" by what mechanism in which parallel universe? Maybe he means that the file itself is in ASCII. From jon at ffconsultancy.com Sun Jun 7 20:22:00 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 01:22:00 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Lew wrote: > Jon Harrop wrote: >> I agree entirely but my statements were about parallelism and not >> concurrency. Parallel and concurrent programming have wildly different >> characteristics and solutions. I don't believe shared mutable state is >> overly problematic in the context of parallelism. Indeed, I think it is >> usually the best solution in that context. > > Interesting distinction. Would it be fair to compare concurrent > programming to the bricks used to build the parallel program's edifice? Concurrent programming certainly underpins the foundations of almost all parallel programs. Not least at the level of the OS scheduling the threads than run the parallel programs. However, that knowledge is probably more confusing than helpful here. In essence, concurrent programming is concerned with reducing latency (e.g. evading blocking) by interleaving computations whereas parallel programming is concerned with maximizing throughput by performing computations at the same time. Historically, concurrency has been of general interest on single core machines in the context of operating systems and IO and has become more important recently due to the ubiquity of web programming. Parallelism was once only important to computational scientists programming shared-memory supercomputers and enterprise developers programming distributed-memory clusters but the advent of multicore machines on the desktop and in the games console has pushed parallelism into the lime light for ordinary developers when performance is important. Solutions for concurrent and parallel programming are also wildly different. Concurrent programming typically schedules work items that are expected to block on a shared queue for a pool of dozens or even hundreds of threads. Parallel programming typically schedules work items that are expected to not block on wait-free work-stealing queues for a pool of "n" threads where "n" is the number of cores. Solutions for concurrent programming (such as the .NET thread pool and asynchronous workflows in F#) can be used as a poor man's solution for parallel programming but the overheads are huge because they were not designed for this purpose so performance is much worse than necessary. Solutions for parallel programming (e.g. Cilk, the Task Parallel Library) are virtually useless for concurrent programming because you quickly end up with all "n" threads blocked and the whole program stalls. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From pats at acm.org Sun Jun 7 20:31:26 2009 From: pats at acm.org (Patricia Shanahan) Date: Sun, 07 Jun 2009 17:31:26 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: <0KGdnabuMMt8xrHXnZ2dnUVZ_jBi4p2d@earthlink.com> Jon Harrop wrote: ... > Historically, concurrency has been of general interest on single core > machines in the context of operating systems and IO and has become more > important recently due to the ubiquity of web programming. Parallelism was > once only important to computational scientists programming shared-memory > supercomputers and enterprise developers programming distributed-memory > clusters but the advent of multicore machines on the desktop and in the > games console has pushed parallelism into the lime light for ordinary > developers when performance is important. ... Parallelism has also been important, for a long time, to multiprocessor operating system developers. I got my first exposure to parallel programming, in the 1980's, working on NCR's VRX operating system. Patricia From sjmachin at lexicon.net Sun Jun 7 20:32:58 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 7 Jun 2009 17:32:58 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: <407c363b-fe3c-4789-9048-4de79de8ac31@t11g2000vbc.googlegroups.com> On Jun 8, 10:20?am, MRAB wrote: > John Machin wrote: > > On Jun 8, 12:13 am, "R. David Murray" wrote: > >> higer wrote: > >>> My file contains such strings : > >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > >> If those bytes are what is in the file (and it sounds like they are), > >> then the data in your file is not in UTF8 encoding, it is in ASCII > >> encoded as hexidecimal escape codes. > > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > > r"\xe6" by what mechanism in which parallel universe? > > Maybe he means that the file itself is in ASCII. Maybe indeed, but only so because hex escape codes are by design in ASCII. "in ASCII" is redundant ... I can't imagine how the OP parsed "ASCII encoded" given that his native tongue's grammar varies from that of English in several interesting ways :-) From mattleftbody at gmail.com Sun Jun 7 20:37:03 2009 From: mattleftbody at gmail.com (mattleftbody at gmail.com) Date: Sun, 7 Jun 2009 17:37:03 -0700 (PDT) Subject: pythoncom and writing file "summary" info on Windows Message-ID: Hello, I was trying to put together a script that would write things like the Author and Title metadata fields of a file under Windows. I got the win32 extensions installed and found a few things that look like they should work, though I'm not getting the result I would expect. Hopefully someone has worked through this area and can point me in the right direction. so after various imports I try the following: file=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0 , pythoncom.IID_IPropertySetStorage) summ=file.Create(pythoncom.FMTID_SummaryInformation, pythoncom.IID_IPropertySetStorage, storagecon.PROPSETFLAG_DEFAULT, storagecon.STGM_READWRITE|storagecon.STGM_CREATE| storagecon.STGM_SHARE_EXCLUSIVE) everything seems fine so far, until I try and write which doesn't seem to do anything. I tried the following three ways: summ.WriteMultiple((storagecon.PIDSI_AUTHOR, storagecon.PIDSI_TITLE), ('Author', 'Title')) summ.WriteMultiple((4,2 ), ('Author', 'Title')) summ.WritePropertyNames((4,2 ), ('Author', 'Title')) Any advice would be most appreciated! Matt From davea at ieee.org Sun Jun 7 20:41:27 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 07 Jun 2009 20:41:27 -0400 Subject: Keeping console window open In-Reply-To: <791u96F1onh1qU1@mid.individual.net> References: <791rbmF1okia2U1@mid.individual.net> <791u96F1onh1qU1@mid.individual.net> Message-ID: <4A2C5E37.1000108@ieee.org> Fencer wrote: >
Scott > David Daniels wrote: >> To be a trifle more explicit, turn: >> >> ... >> if __name__ == '__main__': >> main() >> >> into: >> ... >> if __name__ == '__main__': >> try: >> main() >> except Exception, why: >> print 'Failed:', why >> import sys, traceback >> traceback.print_tb(sys.exc_info()[2]) >> raw_input('Leaving: ') >> >> Note that building your script like this also allows you to >> open the interpretter, and type: >> import mymodule >> mymodule.main() >> in order to examine how it runs. > > Thanks alot, this was exactly what I was looking for! > >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > >
> Notice also that you'd then move all the imports inside main(), rather than putting them at outer scope. Now some imports, such as sys and os, may want to be at outer scope, but if they don't work,. your system is seriously busted. From robert.kern at gmail.com Sun Jun 7 20:59:12 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 07 Jun 2009 19:59:12 -0500 Subject: Get the class name In-Reply-To: <4a2c2600$0$6277$9b536df3@news.fv.fi> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> <4a2c2600$0$6277$9b536df3@news.fv.fi> Message-ID: On 2009-06-07 15:41, Tuomas Vesterinen wrote: > Kless wrote: >> Is there any way of to get the class name to avoid to have that write >> it? >> >> --------------- >> class Foo: >> super(Foo, self) >> --------------- >> >> >> * Using Py 2.6.2 > > >>> class Foo(object): > ... def cls(self): > ... return self.__class__ > ... > >>> Foo().cls() > You definitely don't want to use that for super(). If you actually have an instance of a subclass of Foo, you will be giving the wrong information. Basically, there is no (sane) way to do what the OP wants. If there were, that information would not be necessary to give to super(). -- 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 davea at ieee.org Sun Jun 7 21:00:32 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 07 Jun 2009 21:00:32 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> Message-ID: <4A2C62B0.6080602@ieee.org> Lew wrote: >
Scott > David Daniels wrote: >> the nub of the problem is not on the benchmarks. There is something >> to be said for the good old daays when you looked up the instruction >> timings that you used in a little document for your machine, and could >> know the cost of any loop. We are faster now, but part of the cost of >> that speed is that timing is a black art. > > Those good old days never existed. Those manuals never accounted for > things that affected timing even then, like memory latency or refresh > time. SRAM cache made things worse, since the published timings never > mentioned cache-miss delays. Though memory cache might seem a recent > innovation, it's been around a while. It would be challenging to find > any published timing since the commercialization of computers that > would actually tell the cost of any loop. > > Things got worse when chips like the '86 family acquired multiple > instructions for doing loops, still worse when pre-fetch pipelines > became deeper and wider, absolutely Dark Art due to multi-level memory > caches becoming universal, and > throw-your-hands-up-and-leave-for-the-corner-bar with multiprocessor > NUMA systems. OSes and high-level languages complicate the matter - > you never know how much time slice you'll get or how your source got > compiled or optimized by run-time. > > So the good old days are a matter of degree and self-deception - it > was easier to fool ourselves then that we could at least guess timings > proportionately if not absolutely, but things definitely get more > unpredictable over evolution. > Nonsense. The 6502 with static memory was precisely predictable, and many programmers (working in machine language, naturally) counted on it. Similarly the Novix 4000, when programmed in its native Forth. And previous to that, I worked on several machines (in fact, I wrote the assembler and debugger for two of them) where the only variable was the delay every two milliseconds for dynamic memory refresh. Separate control memory and data memory, and every instruction precisely clocked. No instruction prefetch, no cache memory. What you see is what you get. Would I want to go back there? No. Sub-megaherz clocks with much less happening on each clock means we were operating at way under .01% of present day. From jon at ffconsultancy.com Sun Jun 7 21:39:40 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 02:39:40 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> Message-ID: Ken T. wrote: > On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: >> So the good old days are a matter of degree and self-deception - it was >> easier to fool ourselves then that we could at least guess timings >> proportionately if not absolutely, but things definitely get more >> unpredictable over evolution. > > As I recall I could get exact timings on my 6502 based Commodore 64. The > issues you speak of simply weren't issues. Let's not forget Elite for the 6502 exploiting predictable performance in order to switch graphics modes partway down the vsync! -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From dcest61 at hotmail.com Sun Jun 7 21:42:08 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Mon, 08 Jun 2009 01:42:08 GMT Subject: multi-core software In-Reply-To: <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Lew wrote: >>> Interesting distinction. Would it be fair to compare concurrent >>> programming to the bricks used to build the parallel program's edifice? >> Way too much of a fine distinction. While they are in fact different, >> the point of concurrent programming is to structure programs as a group >> of computations, which can be executed in parallel (however that might >> actually be done depending on how many processors there are). > > No. Concurrent programming is about interleaving computations in order to > reduce latency. Nothing to do with parallelism. Jon, I do concurrent programming all the time, as do most of my peers. Way down on the list of why we do it is the reduction of latency. AHS From pavlovevidence at gmail.com Sun Jun 7 22:13:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 7 Jun 2009 19:13:47 -0700 (PDT) Subject: Get the class name References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <5d7ba12e-d9bd-4fd1-bc18-b99629ee03a1@j12g2000vbl.googlegroups.com> On Jun 7, 1:14?pm, Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > ? ?super(Foo, self) > --------------- > > * Using Py 2.6.2 If you are using emacs you can use the put the following elisp code in your .emacs file, defines a command to automatically insert the a super call with the class and method name filled in: http://code.activestate.com/recipes/522990/ Carl Banks From higerinbeijing at gmail.com Sun Jun 7 22:32:59 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 19:32:59 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> <613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> Message-ID: <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> On Jun 7, 11:25 pm, John Machin wrote: > On Jun 7, 10:55 pm, higer wrote: > > > My file contains such strings : > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > Are you sure? Does that occupy 9 bytes in your file or 36 bytes? > It was saved in a file, so it occupy 36 bytes. If I just use a variable to contain this string, it can certainly work out correct result,but how to get right answer when reading from file. > > > > I want to read the content of this file and transfer it to the > > corresponding gbk code,a kind of Chinese character encode style. > > Everytime I was trying to transfer, it will output the same thing no > > matter which method was used. > > It seems like that when Python reads it, Python will taks '\' as a > > common char and this string at last will be represented as "\\xe6\\x97\ > > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' > > output,but that's not what I want to get. > > > Anyone can help me? > > try this: > > utf8_data = your_data.decode('string-escape') > unicode_data = utf8_data.decode('utf8') > # unicode derived from your sample looks like this ??? is that what > you expected? You are right , the result is ?? which I just expect. If you save the string in a variable, you surely can get the correct result. But it is just a sample, so I give a short string, what if so many characters in a file? > gbk_data = unicode_data.encode('gbk') > I have tried this method which you just told me, but unfortunately it does not work(mess code). > If that "doesn't work", do three things: > (1) give us some unambiguous hard evidence about the contents of your > data: > e.g. # assuming Python 2.x My Python versoin is 2.5.2 > your_data = open('your_file.txt', 'rb').read(36) > print repr(your_data) > print len(your_data) > print your_data.count('\\') > print your_data.count('x') > The result is: '\\xe6\\x97\\xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a' 36 9 9 > (2) show us the source of the script that you used def UTF8ToChnWords(): f = open("123.txt","rb") content=f.read() print repr(content) print len(content) print content.count("\\") print content.count("x") pass if __name__ == '__main__': UTF8ToChnWords() > (3) Tell us what "doesn't work" means in this case It doesn't work because no matter in what way we deal with it we often get 36 bytes string not 9 bytes.Thus, we can not get the correct answer. > > Cheers, > John Thank you very much, higer From higerinbeijing at gmail.com Sun Jun 7 22:36:57 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 19:36:57 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: On Jun 8, 8:20?am, MRAB wrote: > John Machin wrote: > > On Jun 8, 12:13 am, "R. David Murray" wrote: > >> higer wrote: > >>> My file contains such strings : > >>> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > >> If those bytes are what is in the file (and it sounds like they are), > >> then the data in your file is not in UTF8 encoding, it is in ASCII > >> encoded as hexidecimal escape codes. > > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > > r"\xe6" by what mechanism in which parallel universe? > > Maybe he means that the file itself is in ASCII. Yes,my file itself is in ASCII. From jon at ffconsultancy.com Sun Jun 7 22:42:32 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 08 Jun 2009 03:42:32 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Lew wrote: >>>> Interesting distinction. Would it be fair to compare concurrent >>>> programming to the bricks used to build the parallel program's edifice? >>> Way too much of a fine distinction. While they are in fact different, >>> the point of concurrent programming is to structure programs as a group >>> of computations, which can be executed in parallel (however that might >>> actually be done depending on how many processors there are). >> >> No. Concurrent programming is about interleaving computations in order to >> reduce latency. Nothing to do with parallelism. > > Jon, I do concurrent programming all the time, as do most of my peers. > Way down on the list of why we do it is the reduction of latency. What is higher on the list? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From nowhere at home.com Mon Jun 8 00:28:20 2009 From: nowhere at home.com (Ken T.) Date: 08 Jun 2009 04:28:20 GMT Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> Message-ID: <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> On Mon, 08 Jun 2009 02:39:40 +0100, Jon Harrop wrote: > Ken T. wrote: >> On Sun, 07 Jun 2009 11:16:46 -0400, Lew wrote: >>> So the good old days are a matter of degree and self-deception - it >>> was easier to fool ourselves then that we could at least guess timings >>> proportionately if not absolutely, but things definitely get more >>> unpredictable over evolution. >> >> As I recall I could get exact timings on my 6502 based Commodore 64. >> The issues you speak of simply weren't issues. > > Let's not forget Elite for the 6502 exploiting predictable performance > in order to switch graphics modes partway down the vsync! That actually didn't require predictable timing. You could tell the video chip to send you an interrupt when it got to a given scan line. I used this myself. Elite was cool though. I wasted many hours playing that game. -- Ken T. http://www.electricsenator.net Duct tape is like the force. It has a light side, and a dark side, and it holds the universe together ... -- Carl Zwanzig From dstanek at dstanek.com Mon Jun 8 01:08:10 2009 From: dstanek at dstanek.com (David Stanek) Date: Mon, 8 Jun 2009 01:08:10 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> Message-ID: On Sun, Jun 7, 2009 at 9:23 AM, Esmail wrote: > Ben Finney wrote: >> >> Esmail writes: >> >>> I am confused by pylint's naming conventions, I don't think the are in >>> tune with Python's style recommendations (PEP 8?) >>> >>> Anyone else think this? >> >> It's hard to know, without examples. Can you give some output of pylint >> that you think doesn't agree with PEP 8? > > Sure, I will next time I have a nice self-contained example. Perhaps not > that > many people are using pylint? I was expecting a bunch of messages either > contradicting my observation or agreeing with it :-) .. but perhaps this > indicates that there's no issue. It is my understanding that it does check for PEP8 names. Even if it doesn't it is really easy to change. If you run 'pylint --generate-rcfile' (i think) it will output the configuration that it is using. You can then save this off and customize it. > > I'll try to come up with a nice short code example in the next few days > to demonstrate what I think the problem is and post it, thanks for the > suggestion. If you didn't have an example handy what prompted you to start this thread? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From rdmurray at bitdance.com Mon Jun 8 01:10:28 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 05:10:28 +0000 (UTC) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com> Message-ID: John Machin wrote: > On Jun 8, 12:13?am, "R. David Murray" wrote: > > higer wrote: > > > My file contains such strings : > > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a > > > > If those bytes are what is in the file (and it sounds like they are), > > then the data in your file is not in UTF8 encoding, it is in ASCII > > encoded as hexidecimal escape codes. > > OK, I'll bite: what *ASCII* character is encoded as either "\xe6" or > r"\xe6" by what mechanism in which parallel universe? Well, you are correct that the OP might have had trouble parsing my English. My English is more or less valid ("[the file] is _in_ ASCII", ie: consists of ASCII characters, "encoded as hexideicmal escape codes", which specifies the encoding used). But better perhaps would have been to just say that the data is encoded as hexidecimal escape sequences. --David From rdmurray at bitdance.com Mon Jun 8 01:16:21 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 05:16:21 +0000 (UTC) Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: Tuomas Vesterinen wrote: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > > > #ifdef python2 > print u'foo', u'bar' > #endif > #ifdef python3 > print('foo', 'bar') > #endif > > > results: > > cpp -E -Dpython2 test_cpp.py > ... > print u'foo', u'bar' > > Any other suggestions? There's a Google Summer of Code project to create a 3to2 processor. That would let you maintain the code in 3.x, and have it automatically translated on demand so that it will run under 2.x (where x goes back to at least 5, I think, but I'm not sure). Of course, it isn't finished yet, so it won't do you any good right at the moment :( -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From ben+python at benfinney.id.au Mon Jun 8 01:34:12 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Jun 2009 15:34:12 +1000 Subject: pylint naming conventions? References: <87skiekend.fsf@benfinney.id.au> Message-ID: <87my8je1bf.fsf@benfinney.id.au> David Stanek writes: > On Sun, Jun 7, 2009 at 9:23 AM, Esmail wrote: > > I'll try to come up with a nice short code example in the next few > > days to demonstrate what I think the problem is and post it, thanks > > for the suggestion. > > If you didn't have an example handy what prompted you to start this > thread? My understanding of Esmail's original message was that, like many of us on first running ?pylint? against an existing code base, the output is astonishingly verbose and tedious to read. By the above I presume he's being a good forum member and trying to find a minimal example that shows the problem clearly :-) -- \ ?Kill myself? Killing myself is the last thing I'd ever do.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From metolone+gmane at gmail.com Mon Jun 8 01:58:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 7 Jun 2009 22:58:16 -0700 Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com><613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> Message-ID: "higer" wrote in message news:0c786326-1651-42c8-ba39-4679f3558660 at r13g2000vbr.googlegroups.com... > On Jun 7, 11:25 pm, John Machin wrote: >> On Jun 7, 10:55 pm, higer wrote: >> >> > My file contains such strings : >> > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a >> > > >> Are you sure? Does that occupy 9 bytes in your file or 36 bytes? >> > > It was saved in a file, so it occupy 36 bytes. If I just use a > variable to contain this string, it can certainly work out correct > result,but how to get right answer when reading from file. Did you create this file? If it is 36 characters, it contains literal backslash characters, not the 9 bytes that would correctly encode as UTF-8. If you created the file yourself, show us the code. > >> >> >> > I want to read the content of this file and transfer it to the >> > corresponding gbk code,a kind of Chinese character encode style. >> > Everytime I was trying to transfer, it will output the same thing no >> > matter which method was used. >> > It seems like that when Python reads it, Python will taks '\' as a >> > common char and this string at last will be represented as "\\xe6\\x97\ >> > \xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a" , then the "\" can be 'correctly' >> > output,but that's not what I want to get. >> >> > Anyone can help me? >> >> try this: >> >> utf8_data = your_data.decode('string-escape') >> unicode_data = utf8_data.decode('utf8') >> # unicode derived from your sample looks like this ??? is that what >> you expected? > > You are right , the result is ?? which I just expect. If you save the > string in a variable, you surely can get the correct result. But it is > just a sample, so I give a short string, what if so many characters in > a file? > >> gbk_data = unicode_data.encode('gbk') >> > > I have tried this method which you just told me, but unfortunately it > does not work(mess code). How are you determining this is 'mess code'? How are you viewing the result? You'll need to use a viewer that understands GBK encoding, such as "Chinese Window's Notepad". > > >> If that "doesn't work", do three things: >> (1) give us some unambiguous hard evidence about the contents of your >> data: >> e.g. # assuming Python 2.x > > My Python versoin is 2.5.2 > >> your_data = open('your_file.txt', 'rb').read(36) >> print repr(your_data) >> print len(your_data) >> print your_data.count('\\') >> print your_data.count('x') >> > > The result is: > > '\\xe6\\x97\\xa5\\xe6\\x9c\\x9f\\xef\\xbc\\x9a' > 36 > 9 > 9 > >> (2) show us the source of the script that you used > > def UTF8ToChnWords(): > f = open("123.txt","rb") > content=f.read() > print repr(content) > print len(content) > print content.count("\\") > print content.count("x") Try: utf8data = content.decode('string-escape') unicodedata = utf8data.decode('utf8') gbkdata = unicodedata.encode('gbk') print len(gbkdata),repr(gbkdata) open("456.txt","wb").write(gbkdata) The print should give: 6 '\xc8\xd5\xc6\xda\xa3\xba' This is correct for GBK encoding. 456.txt should contain the 6 bytes of GBK data. View the file with a program that understand GBK encoding. -Mark From kay at fiber-space.de Mon Jun 8 02:00:29 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sun, 7 Jun 2009 23:00:29 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> Message-ID: <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> On 8 Jun., 00:31, bearophileH... at lycos.com wrote: > ShedSkin (SS) is a beast almost totally different from CPython, SS > compiles an implicitly static subset of Python to C++. So it breaks > most real Python programs, and it doesn't use the Python std lib (it > rebuilds one in C++ or compiled Python), and so on. > SS may be useful for people that don't want to mess with the > intricacies of Cython (ex-Pyrex) and its tricky reference count, to > create compiled python extensions. Don't understand your Cython compliant. The only tricky part of Cython is the doublethink regarding Python types and C types. I attempted once to write a ShedSkin like code transformer from Python to Cython based on type recordings but never found the time for this because I have to work on EasyExtend on all fronts at the same time. Maybe next year or when Unladen Swallow becomes a success - never. The advantage of this approach over ShedSkin was that every valid Cython program is also a Python extension module, so one can advance the translator in small increments and still make continuous progress on the execution speed front. From higerinbeijing at gmail.com Mon Jun 8 02:15:39 2009 From: higerinbeijing at gmail.com (higer) Date: Sun, 7 Jun 2009 23:15:39 -0700 (PDT) Subject: how to transfer my utf8 code saved in a file to gbk code References: <9cf8e174-4aeb-4382-b1ee-ea43180cd6f6@u10g2000vbd.googlegroups.com><613624fd-80f4-4ee5-b8cf-b10568deed36@r13g2000vbr.googlegroups.com> <0c786326-1651-42c8-ba39-4679f3558660@r13g2000vbr.googlegroups.com> Message-ID: Thank you Mark, that works. Firstly using 'string-escape' to decode the content is the key point,so I can get the Chinese characters now. Regards, -higer From tim.wintle at teamrubber.com Mon Jun 8 02:48:28 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 08 Jun 2009 07:48:28 +0100 Subject: unladen swallow: python and llvm In-Reply-To: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> References: <9839a05c0906071540r13b06df2j85a7e755e3a1d92c@mail.gmail.com> Message-ID: <1244443708.593.27.camel@tim-laptop> On Sun, 2009-06-07 at 16:40 -0600, Brian wrote: > On Fri, Jun 5, 2009 at 3:29 AM, Nick Craig-Wood > wrote: > It is an interesting idea for a number of reasons, the main > one as far > as I'm concerned is that it is more of a port of CPython to a > new > architecture than a complete re-invention of python (like > PyPy / > IronPython / jython) so stands a chance of being merged back > into > CPython. > > Blatant fanboyism. PyPy also has a chance of being merged back into > Python trunk. How? I believe that unladen swallow has already had many of it's optimisations back-ported to CPython, but I can't see how backporting a python interpreter written in python into C is going to be as easy as merging from Unladen swallow, which is (until the llvm part) a branch of CPython. Personally, I think that PyPy is a much better interpreter from a theoretical point of view, and opens up massive possibilities for writing interpreters in general. Unladen Swallow on the other hand is something we can use _now_ - on real work, on real servers. It's a more interesting engineering project, and something that shouldn't require re-writing of existing python code. Tim W > > From rossberg at mpi-sws.org Mon Jun 8 04:05:44 2009 From: rossberg at mpi-sws.org (rossberg at mpi-sws.org) Date: Mon, 8 Jun 2009 01:05:44 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> Message-ID: On Jun 8, 6:28?am, "Ken T." wrote: > > > Let's not forget Elite for the 6502 exploiting predictable performance > > in order to switch graphics modes partway down the vsync! > > That actually didn't require predictable timing. ?You could tell the > video chip to send you an interrupt when it got to a given scan line. ?I > used this myself. ? I don't know what Elite did, but I know for sure that it was a common trick on the Atari ST to switch color palettes or graphics mode at a fixed point *in each single scan line* to get more colors, or display graphics on the screen borders. That required "synchronous programming", i.e. counting clock cycles of machine instructions such that for every point in the program you knew exactly where the electron ray would be. The Atari ST had an M68000 with exactly 8 MHz, which made this possible. There were no caches in those times, and clock cycles were entirely predictable. From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 04:09:36 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 08:09:36 GMT Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> Message-ID: <023cb998$0$20636$c3e8da3@news.astraweb.com> On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: > We factor code > to eliminate redundancy, but that is not always a good idea with an API. > The goal for code factoring is to minimize redundancy. The goal for API > design is having simple parts that are easily learned and can be readily > combined (i.e. the notion of an iterator algebra). Wonderfully said! That has articulated something which I only recently came to appreciate, but couldn't put into words. -- Steven From ben+python at benfinney.id.au Mon Jun 8 04:30:37 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Jun 2009 18:30:37 +1000 Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> Message-ID: <87eitvdt5e.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: > > > We factor code to eliminate redundancy, but that is not always a > > good idea with an API. The goal for code factoring is to minimize > > redundancy. The goal for API design is having simple parts that are > > easily learned and can be readily combined (i.e. the notion of an > > iterator algebra). > > Wonderfully said! That has articulated something which I only recently > came to appreciate, but couldn't put into words. As originally defined by Martin Fowler, re-factoring always means the external behaviour is unchanged . So, there's no such thing as a re-factoring that changes the API. Anything that changes an external attribute of the code is a different kind of transformation, not a re-factoring. -- \ ?Better not take a dog on the space shuttle, because if he | `\ sticks his head out when you're coming home his face might burn | _o__) up.? ?Jack Handey | Ben Finney From piet at cs.uu.nl Mon Jun 8 04:35:34 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 08 Jun 2009 10:35:34 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: By the way, there is a series of articles about concurrency on ACM Queue which may be interesting for those participating in or just following this discussion: http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency Here is one introductory paragraph from one of the articles: Parallel programming poses many new challenges to the developer, one of which is synchronizing concurrent access to shared memory by multiple threads. Programmers have traditionally used locks for synchronization, but lock-based synchronization has well-known pitfalls. Simplistic coarse-grained locking does not scale well, while more sophisticated fine-grained locking risks introducing deadlocks and data races. Furthermore, scalable libraries written using fine-grained locks cannot be easily composed in a way that retains scalability and avoids deadlock and data races. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jkn_gg at nicorp.f9.co.uk Mon Jun 8 04:39:45 2009 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 8 Jun 2009 01:39:45 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> Message-ID: <67e28245-7c52-4bc1-b96a-d7e383e52c33@n8g2000vbb.googlegroups.com> On Jun 8, 9:30?am, Ben Finney wrote: [...] > > As originally defined by Martin Fowler, re-factoring always means the > external behaviour is unchanged . > > So, there's no such thing as a re-factoring that changes the API. > Anything that changes an external attribute of the code is a different > kind of transformation, not a re-factoring. ... and Steven was not calling the two things by the same name. He, and Raymond, were distinguishing between refactoring, and API design. That was their point, I think. Jon N From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 05:44:30 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 09:44:30 GMT Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> Message-ID: <023ccfd6$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 18:30:37 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 07 Jun 2009 16:46:23 -0700, Raymond Hettinger wrote: >> >> > We factor code to eliminate redundancy, but that is not always a good >> > idea with an API. The goal for code factoring is to minimize >> > redundancy. The goal for API design is having simple parts that are >> > easily learned and can be readily combined (i.e. the notion of an >> > iterator algebra). >> >> Wonderfully said! That has articulated something which I only recently >> came to appreciate, but couldn't put into words. > > As originally defined by Martin Fowler, re-factoring always means the > external behaviour is unchanged . > > So, there's no such thing as a re-factoring that changes the API. > Anything that changes an external attribute of the code is a different > kind of transformation, not a re-factoring. Possibly a *factoring*, without the "re-", just like Raymond said. Also, keep in mind that when creating a new API, you have no existing API to re-factor. -- Steven From jkn_gg at nicorp.f9.co.uk Mon Jun 8 05:56:19 2009 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 8 Jun 2009 02:56:19 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <023cb998$0$20636$c3e8da3@news.astraweb.com> <87eitvdt5e.fsf@benfinney.id.au> <023ccfd6$0$20636$c3e8da3@news.astraweb.com> Message-ID: > Possibly a *factoring*, without the "re-", just like Raymond said. > > Also, keep in mind that when creating a new API, you have no existing API > to re-factor. Exactly. I think this has come up before, but I can't remember the answers; any suggestions for pointer to examples of very well-designed APIs, and maybe some background as to how the design was achieved? Thanks jon N From bearophileHUGS at lycos.com Mon Jun 8 06:13:25 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 03:13:25 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> Message-ID: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Kay Schluehr: >Don't understand your Cython compliant. The only tricky part of Cython is the doublethink regarding Python types and C types. I attempted once to write a ShedSkin like code transformer from Python to Cython based on type recordings but never found the time for this because I have to work on EasyExtend on all fronts at the same time.< I have tried to create a certain data structure with a recent version of Pyrex on Windows, and I have wasted lot of time looking for missing reference count updates that didn't happen, or memory that didn't get freed. The C code produced by ShedSkin is a bit hairy but it's 50 times more readable than the C jungle produced by Pyrex, where I have lost lot of time looking for the missing reference counts, etc. In the end I have used D with Pyd to write an extension in a very quick way. For me writing D code is much simpler than writing Pyrex code. Never used Pyrex ever since. I'm sure lot of people like Cython, but I prefer a more transparent language, that doesn't hide me how it works inside. Bye, bearophile From castironpi at gmail.com Mon Jun 8 06:45:59 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 8 Jun 2009 03:45:59 -0700 (PDT) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> Message-ID: <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> On Jun 7, 6:13?pm, Paul Rubin wrote: > Aaron Brady writes: > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > > Shorter is always better. > > url = url.rstrip('/') + '/' I was joking. Sheesh. From mfmdevine at gmail.com Mon Jun 8 07:14:18 2009 From: mfmdevine at gmail.com (Mark Devine) Date: Mon, 8 Jun 2009 12:14:18 +0100 Subject: urllib2.URLError: error using twill with python Message-ID: <8249b1d00906080414w576cbd8bycf6d57cb17fb355d@mail.gmail.com> Hi I wonder if someone could point me in the right direction. I used the following code to access gmail but I got a urllib2.URLError: error when I ran it. I have included the Traceback import twill, string, os b=twill.commands.get_browser() b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() b.go('http://www.gmail.com') f=b.get_form("1") b.showforms() f['Email']= email f['Passwd'] =password b.clicked(f, f) b.submit() When I run the code I get: Traceback (most recent call last): File "", line 1, in ? File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line 115, in go self._journey('open', u) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line 540, in _journey r = func(*args, **kwargs) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 573, in http_response response = self.parent.error( File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 573, in http_response response = self.parent.error( File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 191, in open response = meth(req, response) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/utils.py", line 455, in http_response "refresh", msg, hdrs) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 208, in error result = apply(self._call_chain, args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py", line 129, in http_error_302 return self.parent.open(new) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 156, in open return self._mech_open(url, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py", line 182, in _mech_open response = UserAgentBase.open(self, request, data) File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py", line 180, in open response = urlopen(self, req, data) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 381, in _open 'unknown_open', req) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 1053, in unknown_open raise URLError('unknown url type: %s' % type) urllib2.URLError: Thanks M From ebonak at hotmail.com Mon Jun 8 07:30:00 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 08 Jun 2009 07:30:00 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> Message-ID: <4A2CF638.1000503@hotmail.com> Hi David, David Stanek wrote: > > It is my understanding that it does check for PEP8 names. Even if it doesn't > it is really easy to change. If you run 'pylint --generate-rcfile' (i think) > it will output the configuration that it is using. You can then save this > off and customize it. Thanks, I'll see if I can customize it this way. I looked at it once briefly. >> I'll try to come up with a nice short code example in the next few days >> to demonstrate what I think the problem is and post it, thanks for the >> suggestion. > > If you didn't have an example handy what prompted you to start this thread? :-) I have had number of examples, but they are rather long, so I think it will be better if I can provide a short example with the (rather lengthy pylint) output that shows the problem. I thought lots of people are using pylint and I would hear one way or the other about the name checks (ie people agreeing or telling me I'm way off :) .. in which case perhaps my recollection/reading of PEP 8 is not accurate. Esmail From ebonak at hotmail.com Mon Jun 8 07:32:35 2009 From: ebonak at hotmail.com (Esmail) Date: Mon, 08 Jun 2009 07:32:35 -0400 Subject: pylint naming conventions? In-Reply-To: <87my8je1bf.fsf@benfinney.id.au> References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> Message-ID: <4A2CF6D3.5010400@hotmail.com> Ben Finney wrote: > > > My understanding of Esmail's original message was that, like many of us > on first running ?pylint? against an existing code base, the output is > astonishingly verbose and tedious to read. By the above I presume he's > being a good forum member and trying to find a minimal example that > shows the problem clearly :-) Yes, that is my intention .. because the code I was checking was rather long, combined with the long pylint output it would make for a rather big posting. I'm going to go back and re-read PEP 8 and see if I perhaps don't recall the right guidelines since no one else here seems to have had the same observation. Esmail From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 07:58:29 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 11:58:29 GMT Subject: urllib2.URLError: error using twill with python References: Message-ID: <023cef3d$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote: > Hi > I wonder if someone could point me in the right direction. I used the > following code to access gmail but I got a > urllib2.URLError: > error when I ran it. I have included the Traceback > > import twill, string, os > b=twill.commands.get_browser() > b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; > rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() > b.go('http://www.gmail.com') > f=b.get_form("1") > b.showforms() > f['Email']= email > f['Passwd'] =password > b.clicked(f, f) > b.submit() My bet is that the above is not the actual code you have run. I bet that the offending line is actually something like the following: b.go("'http://www.gmail.com") Note that there is a single character difference. Consider the last two lines of the traceback: > raise URLError('unknown url type: %s' % type) > urllib2.URLError: It seems to be saying that the url type is 'http -- note the leading single quote. -- Steven From roland.em0001 at googlemail.com Mon Jun 8 08:00:51 2009 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Mon, 8 Jun 2009 15:00:51 +0300 Subject: 403 error for python webpage In-Reply-To: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> References: <934dc284-2ee8-46d7-a018-04a16536067b@z9g2000yqi.googlegroups.com> Message-ID: <42dbeab40906080500o24af293ap634524b87efa2115@mail.gmail.com> 2009/6/7 Daniel > I created a page with a ".py" extension but the browser does not like > it. > Here is what I did: I edited httpd.conf file and added the line: > AddHandler cgi-script .cgi .py > Then I stopped and restarted apache. Next I created a hello world file > as on this page: > http://deron.meranda.us/python/webserving/helloworld.html > I stored the file in htdocs and then went to the corresponding > http://127.0.0.1/python/testhw.py in my browser. But the browser gives > a 403 error. > I am running from internet explorer on windows xp. > -- > http://mail.python.org/mailman/listinfo/python-list > This sounds like an setup problem for Apache + CGI. You should study the Apache logs. Don't know their location in WIN32, in Linux there are some files named "error_log" and also "access_log". Typically, Apache writes the reason for error messages there. BR, Roland -------------- next part -------------- An HTML attachment was scrubbed... URL: From tuomas.vesterinen at iki.fi Mon Jun 8 08:10:35 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Mon, 08 Jun 2009 15:10:35 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: <4a2cffbb$0$24772$9b536df3@news.fv.fi> R. David Murray wrote: > Tuomas Vesterinen wrote: >> I am developing a Python application as a Python2.x and Python3.0 >> version. A common code base would make the work easier. So I thought to >> try a preprosessor. GNU cpp handles this kind of code correct: >> >> >> #ifdef python2 >> print u'foo', u'bar' >> #endif >> #ifdef python3 >> print('foo', 'bar') >> #endif >> >> >> results: >> > cpp -E -Dpython2 test_cpp.py >> ... >> print u'foo', u'bar' >> >> Any other suggestions? > > There's a Google Summer of Code project to create a 3to2 processor. > That would let you maintain the code in 3.x, and have it automatically > translated on demand so that it will run under 2.x (where x goes back > to at least 5, I think, but I'm not sure). > > Of course, it isn't finished yet, so it won't do you any good right at > the moment :( > > -- > R. David Murray http://www.bitdance.com > IT Consulting System Administration Python Programming > I found also a ready made py3to2-tool (test/develop/integrate python 3.0 code natively under robust, software-rich python 2.5 environment) at: http://code.activestate.com/recipes/574436/ It seems so complicated that I don't dare to try before some more experienced people has commented it. TV From tuomas.vesterinen at iki.fi Mon Jun 8 08:11:58 2009 From: tuomas.vesterinen at iki.fi (Tuomas Vesterinen) Date: Mon, 08 Jun 2009 15:11:58 +0300 Subject: Python preprosessor In-Reply-To: References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> <4a2c025a$0$24756$9b536df3@news.fv.fi> Message-ID: <4a2d000e$0$24772$9b536df3@news.fv.fi> Roger Binns wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Tuomas Vesterinen wrote: >> I am intensively using 2to3.py. So I have 2 codebase: one in py2 and the >> other in py3. > > The expectation would be that you only maintain the py2 code and > automatically generate the py3 code on demand using 2to3. > > It is possible to have the same code run under both versions, but not > recommended. As an example I do this for the APSW test suite, mostly > because the test code deliberately explores various corner cases that > 2to3 could not convert (nor should it try!). Here is how I do the whole > Unicode thing: > > if py3: # defined earlier > UPREFIX="" > else: > UPREFIX="u" > > def u(x): # use with raw strings > return eval(UPREFIX+"'''"+x+"'''") > > # Example of use > u(r"\N${BLACK STAR}\u234") > > You can pull similar stunts for bytes (I use buffers in py2), long ints > (needing L suffix in some py2 versions), the next() builtin from py3, > exec syntax differences etc. You can see more details in the first 120 > lines of http://code.google.com/p/apsw/source/browse/apsw/trunk/tests.py > > Roger > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkosTxEACgkQmOOfHg372QS4rQCgl1ymNME2kdHTBUoc7/f2e+W6 > cbMAmwf7mArr7hVA8k/US53JE59ChnIt > =pQ92 > -----END PGP SIGNATURE----- > You have interesting solutions. TV From roland.em0001 at googlemail.com Mon Jun 8 08:25:51 2009 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Mon, 8 Jun 2009 15:25:51 +0300 Subject: can it be shorter? In-Reply-To: <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> <5e340702-aba5-4237-8e09-6cdf86593047@s21g2000vbb.googlegroups.com> Message-ID: <42dbeab40906080525l65c76d1dk5b9fd8929d7af860@mail.gmail.com> 2009/6/8 Aaron Brady > On Jun 7, 6:13 pm, Paul Rubin wrote: > > Aaron Brady writes: > > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > > > > Shorter is always better. > > > > url = url.rstrip('/') + '/' > > I was joking. Sheesh. > -- > http://mail.python.org/mailman/listinfo/python-list > my two cents: a solution based on regex: the pattern replaces all slashes at the end of the string with a single one. The * usage matches also the empty group of slashes (example s2) >>> print s1 aaaaa/ >>> print s2 bbbb >>> re.sub('[/]*$','/', s1) 'aaaaa/' >>> re.sub('[/]*$','/', s2) 'bbbb/' -Roland -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Mon Jun 8 08:44:05 2009 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 8 Jun 2009 05:44:05 -0700 (PDT) Subject: spammers on pypi References: Message-ID: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> On Jun 5, 1:39?pm, joep wrote: > Is there a way to ban spammers from pypi? Can you provide some examples? It's possible that we can apply SpamBayes to PyPI submissions in much the same way that we apply it in other non- mail areas. Thx, Skip Montanaro From xkenneth at gmail.com Mon Jun 8 09:35:07 2009 From: xkenneth at gmail.com (xkenneth) Date: Mon, 8 Jun 2009 06:35:07 -0700 (PDT) Subject: Wrapping LabVIEW and DAQmx Libraries for Python Message-ID: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> All, I've started wrapping the DAQmx and other LabVIEW libraries for python using ctypes. I really like doing some things in python and other in LabVIEW, so I'd like to have the same functionality available for both. I've hosted the tiniest bit of code (mostly just proof of concept) on github. Let me know if anyone else would be interested in this. I'd love some help hashing it out. - Ken http://github.com/erdosmiller/pydaqmx/tree/master From pruebauno at latinmail.com Mon Jun 8 10:00:08 2009 From: pruebauno at latinmail.com (pruebauno at latinmail.com) Date: Mon, 8 Jun 2009 07:00:08 -0700 (PDT) Subject: interval arithmetic libraries References: <410afd39-e1e0-403d-aa23-e1e85742351c@z14g2000yqa.googlegroups.com> Message-ID: On Jun 6, 8:15?am, srepmub wrote: > Hi all, > > I'm looking for libraries that allow one to calculate with sets of > (date) intervals. So for example, I'd like to be able to calculate the > overlap between two sets of intervals, the union etc. Preferrably, > this works with datetime objects, is written in pure Python, and has > reasonably good (algorithmic) performance. The neatest library I've > found so far is this one: > > http://members.cox.net/apoco/interval/ > > From an API standpoint, it looks rather nice, but the performance > could be better (for example, calculating an overlap now involves > looping quadratically over both interval sets), and it doesn't work > fully with datetime objects (Inf doesn't work). > > Thanks for any pointers, > Mark Dufour. > (author of Shedskin, an experimental (restricted-)Python-to-C++ > compiler,http://shedskin.googlecode.com) For some pointers look at this thread where I posted a similar question: http://groups.google.com/group/comp.lang.python/browse_frm/thread/1a1d2ed9d05d11d0/56684b795fc527cc#56684b795fc527cc I am surprised that libraries to do that are not more common. I guess everybody rolls his own. From skip at pobox.com Mon Jun 8 10:03:50 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 8 Jun 2009 09:03:50 -0500 Subject: unladen swallow: python and llvm In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <18989.6726.518491.972526@montanaro.dyndns.org> bearophile> I'm sure lot of people like Cython, but I prefer a more bearophile> transparent language, that doesn't hide me how it works bearophile> inside. Why not just write extension modules in C then? -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ America's vaunted "free press" notwithstanding, story ideas that expose the unseemly side of actual or potential advertisers tend to fall by the wayside. Not quite sure why. -- Jim Thornton From paul at boddie.org.uk Mon Jun 8 10:07:10 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 8 Jun 2009 07:07:10 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <17551522-51af-49d1-ae8a-5f80624e7773@j20g2000vbp.googlegroups.com> On 8 Jun, 12:13, bearophileH... at lycos.com wrote: > > The C code produced by ShedSkin is a bit hairy but it's 50 times more > readable than the C jungle produced by Pyrex, where I have lost lot of > time looking for the missing reference counts, etc. The C++ code produced by Shed Skin can actually provide an explicit, yet accurate summary of the implicit type semantics present in a program, in the sense that appropriate parameterisations of template classes may be chosen for the C++ program in order to model the data structures used in the original program. The analysis required to achieve this is actually rather difficult, and it's understandable that in languages like OCaml that are widely associated with type inference, one is encouraged (if not required) to describe one's types in advance. People who claim (or imply) that Shed Skin has removed all the dynamicity from Python need to look at how much work the tool still needs to do even with all the restrictions imposed on input programs. Paul From pw at panix.com Mon Jun 8 10:33:36 2009 From: pw at panix.com (Paul Wallich) Date: Mon, 08 Jun 2009 10:33:36 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <1fhl25d01jaecem232smgaf1isgu527e1u@4ax.com> <7xskicoikw.fsf@ruckus.brouhaha.com> <7x8wk4351n.fsf@ruckus.brouhaha.com> <4a2c3aff$0$11556$ec3e2dad@news.usenetmonster.com> <4a2c9364$0$11539$ec3e2dad@news.usenetmonster.com> Message-ID: rossberg at mpi-sws.org wrote: > On Jun 8, 6:28 am, "Ken T." wrote: >>> Let's not forget Elite for the 6502 exploiting predictable performance >>> in order to switch graphics modes partway down the vsync! >> That actually didn't require predictable timing. You could tell the >> video chip to send you an interrupt when it got to a given scan line. I >> used this myself. > > I don't know what Elite did, but I know for sure that it was a common > trick on the Atari ST to switch color palettes or graphics mode at a > fixed point *in each single scan line* to get more colors, or display > graphics on the screen borders. That required "synchronous > programming", i.e. counting clock cycles of machine instructions such > that for every point in the program you knew exactly where the > electron ray would be. > > The Atari ST had an M68000 with exactly 8 MHz, which made this > possible. There were no caches in those times, and clock cycles were > entirely predictable. The usual trick for these machines was an exact multiple of the NTSC "color clock", which was approx 3.58 MHz. The 8-bit atari video games and home computers all used this technique, as did the C-64/128. 68000-based machines (such as the ST and the Amiga) could not only exploit that synchrony, they could also (this was the days before memory wall) exploit the fact that a 680x0 typically accessed memory only once every 4 clock cycles to do DMA from the same memory when the CPU wasn't using it. High display resolutions would lock the processor out of RAM except during blanking intervals. (Talk about contention and hot spots.) Figuring out how to reuse resources most effectively was pretty much the same as the register-allocation problem for compilers, and was sometimes solved using the same kinds of graph-coloring algorithms... From youssef_edward3000 at yahoo.com Mon Jun 8 10:38:12 2009 From: youssef_edward3000 at yahoo.com (youssef_edward3000 at yahoo.com) Date: Mon, 8 Jun 2009 07:38:12 -0700 (PDT) Subject: 10 Easy Steps to Speed Up Your Computer - Without Upgrading Message-ID: <7204841b-c2f3-4d90-8a5d-76fcf3ca36c3@r16g2000vbn.googlegroups.com> It seems that the longer you own your computer, the slower it gets! A lot of people will keep their computer until it gets so slow that they feel they need a newer, faster model. Some feel like the reason it is getting slower is because it is getting older, when that is just not the case. Your computer should run just as fast as the day you brought it home if you follow these 10 Easy Steps to Speed Up Your Computer. 1. Empty the Temp directory regularly. After a short while, the temp directory fills up with hundreds of temp files that always get scanned over when Windows starts up and when programs launch. This slows everything down immensely. Rule of thumb for Temp Files: If you dont have any programs open (and nothing minimized in the bar below), then you shouldnt have ANY temp files in your temp directory. If you do, delete them. To delete Temp files, make sure NO programs are open, and a. In Windows 95, 98 or Me, go to C:WindowsTemp and delete everything inside the Temp folder. b. In Windows 2000 or XP, it is a little trickier. First, make sure that you can see hidden folders. Double-click My Computer. Click on the Tools pull-down menu, and then on Folder Options. Click on the View tab. Scroll down and click on Show Hidden Files and Folders. Click Ok. Now you can go to the C:Documents and SettingsAdministratorLocal SettingsTemp folder. Delete everything here. 2. Empty the Temporary Internet Files regularly. To empty Temporary Internet Files, go to your Control Panel and double-click the Internet Options icon. Choose to Delete Cookies, and to Delete Files. This will clear all of your Temporary Internet Files. 3. Check your hard disks for problems. a. For Windows 95, 98, or Me, double-click My Computer. Right-click the C-drive and click on Properties. Click on the Tools tab and choose to check the computer for problems. If you choose to do a Thorough Scan, this will do the hardware check for physical disk damage or sector damage. Choose to fix any errors it finds. b. For Windows 2000 and XP, double-click My Computer. Right-click the C-drive and click Properties. Click on the Tools tab and choose to check the computer for problems. Click on Check Now. You will then have two check boxes. The top option is for the file check, and the second option is for the hardware (physical disk) check. Check either one, or both. At least check the top one. Hit ok, and reboot. This may take some time, but let it run. 4. An even more thorough disk check, would be to use a 3rd party utility. One of my favorites is TuneUp Utilities 2004. It does cost $39.99, but they do offer a FREE download trial of 15 days. This program does a really good job of fixing software and physical hard drive problems. It also tunes up your system for increased speed, and streamlines your operating system for peak performance. Download it HERE... http://www.lapeertechgroup.com/downloads.asp 5. Or, you can do a few of the performance tweaks yourself, if you have Windows XP. By default, EVERYTHING is turned on in Windows XP. It isnt very streamlined for performance, but rather for appearance. You can turn off a few of the unnecessary features, and Windows will still work just fine, and maybe a little faster. To do this, right-click on My Computer and click on Properties. Click on the Advanced tab. Under the Performance section, click on the Settings button. On the Visual Effects tab, you will see a list of check boxes. By default, these are all on. You really dont need any of them for Windows to run. Go through the check boxes one by one, and determine which ones you can and cant live without. 6. Turn off Active Desktop. Active Desktop turns your desktop into a web page, and allows you to have things like a real-time calendar, and up-to-the-minute weather or stocks. These are nice, but really slow down your computer. And even if you dont use Active Desktop for anything, just having it active can cause a performance decrease. Turn it off. a. In Windows 95, 98 and Me, right-click on the desktop and in the pop- up menu, choose Active Desktop. Inside that option, uncheck Active Desktop. If there is no check next to it, then it isnt on. Dont choose it. Instead, just click the desktop again to get out of the menu. b. In Windows 2000, right-click on the desktop and in the pop-up menu, choose Active Desktop. Inside that option, uncheck Show Web Content. Again, if there is no check next to it, then it is not on. Do not check it. c. In Windows XP, right-click on the desktop and in the pop-up menu, choose Properties. On the Desktop tab, choose Customize Desktop. Now, on the Web tab, make sure that there are no websites chosen here. If there arent any, then Active Desktop is not on. Cancel and go back to the desktop. 7. Install and run a good AntiVirus program to keep out viruses that can take over your system. One of my favorites is AVG. It is not only a really good AntiVirus program, but it is also FREE! If you dont have any AntiVirus software on your computer, get AVG AntiVirus NOW by downloading HERE... http://www.lapeertechgroup.com/downloads.asp 8. Get rid of Spyware. A lot of computer users have Spyware and dont even know they have it, much less how to get rid of it. If your computer has been taking you to websites that you dont want to go to, or if you get pop-ups when you arent even on the Internet, or if your computer has been running extremely slowly lately, for no reason, you probably have Spyware. On all of the computers that I setup, I install two different AntiSpyware programs: AdAware SE and SpyBot. These two programs are highly recommended by TechTV (G4) and other computer authorities (including my own research on Spyware) and work very well together. They compliment each other and catch Spyware that the other misses, but together, do a very good job. Get SpyBot HERE... http://www.lapeertechgroup.com/downloads.asp. Download all updates and run the Immunize option a couple of times. AdAware SE does a good job when you keep up on the updates and manually scan your system with AdAware. Get it HERE... http://www.lapeertechgroup.com/downloads.asp In some cases, when the Spyware has become too entwined into your system, even a computer repair technician cant get rid of the Spyware. At this point, it is better to just backup only what you need and have the operating system reinstalled. Believe me, when your computer gets to this point, you dont want to just put a band-aid on it. Just start from scratch with a clean system. Its the best way to go. 9. Streamline MSCONFIG. One thing that really causes a HUGE performance decrease is to have unnecessary programs running in the background. Some of these programs can be seen in your System Tray (located next to the clock). These are tiny programs that are robbing you of memory and processing power. Some of them you need, while most you dont. Some of the programs you DONT need are printer icons, CD burning icons, shortcuts to programs (such as video settings), AOL, any Instant Messaging Programs, etc. Just because these programs arent always running, doesnt mean that you still cant print, burn CDs or Instant Message. They can all be run from a shortcut. You can use a utility, called MSCONFIG, to turn OFF unnecessary Start Up items. a. In Windows 98, Me, and XP, click on StartRun and type msconfig. Click on the Startup tab. This is a list of everything that is running in the background, some of which show up in the System Tray. Now, be careful, some of these you do need. Some items to keep are Ctfmon.exe (XP), Scan Registry (Win98, Me), Task Monitor (Win98, Me), System Tray (Win98, Me), LoadPowerProfile (Win98, Me), Rundll.32, any AntiVirus programs (such as McAfee, Norton, or AVG). Others, you can uncheck, such as NeroCheck, ypager, qttask, AOL, and any other Instant Messaging programs, or printing programs. Remember, if something doesnt work, because you turned it off, it can always be turned back on. You just have to reboot every time you make a change here. But, as you uncheck the unnecessary programs that run in the background, you will see that Windows loads much faster, that there are less icons in the System Tray, and that your system is much more snappy and quick to respond. Read more about computers at http://tips-made-easy.info/computer From youssef_edward3000 at yahoo.com Mon Jun 8 10:49:42 2009 From: youssef_edward3000 at yahoo.com (youssef_edward3000 at yahoo.com) Date: Mon, 8 Jun 2009 07:49:42 -0700 (PDT) Subject: Career Track: Computer Programmer Message-ID: <46355271-cd9d-4095-886c-01077360c95f@k20g2000vbp.googlegroups.com> Roles and Responsibilities : The primary role of a Computer Programmer is to write programs according to the instructions determined primarily by computer software engineers and systems analysts. In a nutshell, Computer Programmers are the ones that take the completed designs and convert them into the instructions that the computer can actually follow. The instructions are coded into a programming language. In some cases, programmers are also expected to know platform specific languages used in database programming. Many programmers at the enterprise level are also expected to know platform-specific languages used in database programming. Responsibilities include updating; repairing, modifying and expanding existing programs as well as running tests to authenticate that the program will produce the desired outcome. Applications Programmers are the ones that actually write programs to handle very specific jobs, revise existing software or customize generic applications while Systems Programmers write programs to maintain and control computer systems software such as operating systems, database and/or networked systems. In some smaller organizations, the programmers may also be responsible for systems analysis and the actual programming. In many cases, however, technology is replacing the need to write basic code which doesn't bode well for those considering entering the field. According to the U.S. Department of Labor, however, the "demand for programmers with strong object-oriented programming capabilities and technical specialization in areas such as client/server programming, wireless applications, multimedia technology, and graphic user interface (GUI) should arise from the expansion of intranets, extranets, and Internet applications. Programmers also will be needed to create and maintain expert systems and embed these technologies in more products. Finally, growing emphasis on cyber-security will lead to increased demand for programmers who are familiar with digital security issues and skilled in using appropriate security technology." Advancement Opportunities : The advancement opportunities for computer Programmers are many and usually start with a promotion to a Lead Programmer. A Lead Programmer position will more than likely include supervisory duties. System programming is usually the next career step for Computer Programmers who have completed systems software courses. Programmer Analysts and Systems Analysts are also logical steps. Many programmers are also finding that independent contracting and consulting gives them the freedom to pick and choose their projects. Advancement Opportunities : The advancement opportunities for computer Programmers are many and usually start with a promotion to a Lead Programmer. A Lead Programmer position will more than likely include supervisory duties. System programming is usually the next career step for Computer Programmers who have completed systems software courses. Programmer Analysts and Systems Analysts are also logical steps. Many programmers are also finding that independent contracting and consulting gives them the freedom to pick and choose their projects. Educational Requirements : Although required skills and training will vary dependent upon the position and industry in which you're working, the demand for skill sets is even more driven by technological changes. In some positions, graduate degrees may be required. While traditional language knowledge is still important, C++ and Java are the programming languages of choice. GUI and systems programming skills are also sought after. In addition, general business skills will be an asset in any organization. Systems programmers usually need a 4-year degree in computer science and extensive knowledge of a variety of operating systems. They are usually also expected to be proficient in database systems such as DB2, Sybase and/or Oracle. Salary Potential : (As reported by the U.S. Dept. of Labor) Position Salary Range (2003) Median Average Earnings $60.290 Starting salary for graduates with B.A. in Computer Programming $45,558 Salary range for Applications Development Programmers $51,500 - $80,500 Salary range for Software Developers $55,000 - $87,750 Salary range for Mainframe Programmers $53,250 - $68,750 for more information about programming and computers visit http://tips-made-easy.info/computer From jeanmichel at sequans.com Mon Jun 8 10:50:43 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Jun 2009 16:50:43 +0200 Subject: can it be shorter? In-Reply-To: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <4A2D2543.4020805@sequans.com> Aaron Brady wrote: > Shorter is always better. > > url+= { '/': '' }.get( url[ -1 ], '/' ) Why bother with spaces or 3 letter-wide token, check this :o) : x+={'/':''}.get(x[-1],'/') Apart from joking, the following proposed solution is by **far** the one I prefer > if not url.endswith('/'): > url += '/' Maybe not the shorter, but the most concise and clear to me. Jean-Michel From usernet at ilthio.net Mon Jun 8 11:12:57 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 08 Jun 2009 15:12:57 GMT Subject: GD Library References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: On 2009-06-08, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? GD library has a Python binding: http://www.libgd.org/Main_Page From xahlee at gmail.com Mon Jun 8 11:13:37 2009 From: xahlee at gmail.com (Xah Lee) Date: Mon, 8 Jun 2009 08:13:37 -0700 (PDT) Subject: is there python image lib that does imagemagick? Message-ID: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> is there a python image library that does pretty much what imagemagick does? all i need is for converting png/jpg, and scaling images. No need other fancy things imagemagick does. i know there's a python wrapper for imagemagick, but i need independent ones that doesn't require shell calls. Basically i have a python script that works in os x that process a dir of html files and generate thumbnails. I'm porting to Windows and wish to get rid of imagemagick dependence. Thanks. Xah ? http://xahlee.org/ ? From usernet at ilthio.net Mon Jun 8 11:16:18 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 08 Jun 2009 15:16:18 GMT Subject: PIL Python Imaging Library References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <6X9Xl.20875$8_3.20375@flpi147.ffdc.sbc.com> On 2009-06-08, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? http://www.pythonware.com/products/pil/ From jan.persson at gmail.com Mon Jun 8 11:18:48 2009 From: jan.persson at gmail.com (jpersson) Date: Mon, 8 Jun 2009 08:18:48 -0700 (PDT) Subject: The pysync library - Looking for the code, but all download links are broken References: <130026e7-0913-4dc3-b360-4833747e3b3b@b9g2000yqm.googlegroups.com> Message-ID: <8238ec2e-5e25-40e4-9f64-1f9baf089ec2@z19g2000vbz.googlegroups.com> Thanks for the help. I will let the community know as soon as I have salvaged a working copy. Cheers //Jan Persson On 7 Juni, 23:06, S?ren - Peng - Pedersen wrote: > I think what you are looking for can be found at: > > http://www.google.com/codesearch/p?hl=en#RncWxgazS6A/pysync-2.24/test... > orhttp://shortlink.dk/58664133 > > I am not affiliated with the project in any way, and I can't find a > way to download the entire thing in one go. So if you do salvage a > working copy please let me (and the rest of the community) know. > > //S?ren - Peng - Pedersen From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 11:22:57 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 15:22:57 GMT Subject: is there python image lib that does imagemagick? References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <023d1f27$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 08:13:37 -0700, Xah Lee wrote: > is there a python image library that does pretty much what imagemagick > does? Python Imaging Library (PIL). http://pypi.python.org/pypi/PIL/1.1.6 -- Steven From gherron at islandtraining.com Mon Jun 8 11:33:26 2009 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Jun 2009 08:33:26 -0700 Subject: Get the class name In-Reply-To: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <4A2D2F46.8030304@islandtraining.com> Kless wrote: > Is there any way of to get the class name to avoid to have that write > it? > > --------------- > class Foo: > super(Foo, self) > --------------- > > > * Using Py 2.6.2 > The question does not make sense: "to have WHAT write WHAT", and the code is wrong: the call to super fails But even so, perhaps this will answer your question >>> class Foo: ... pass ... >>> print Foo.__name__ Foo >>> c = Foo >>> print c.__name__ Foo >>> ob = Foo() >>> print ob.__class__.__name__ Foo Gary Herron From python at mrabarnett.plus.com Mon Jun 8 11:50:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 16:50:12 +0100 Subject: can it be shorter? In-Reply-To: <4A2D2543.4020805@sequans.com> References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <4A2D2543.4020805@sequans.com> Message-ID: <4A2D3334.3020708@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Aaron Brady wrote: >> Shorter is always better. >> url+= { '/': '' }.get( url[ -1 ], '/' ) > > Why bother with spaces or 3 letter-wide token, check this :o) : > x+={'/':''}.get(x[-1],'/') > Even shorter: x+='/'*(x[-1]!='/') > Apart from joking, the following proposed solution is by **far** the one > I prefer > >> if not url.endswith('/'): >> url += '/' > > Maybe not the shorter, but the most concise and clear to me. > Definitely. From orsenthil at gmail.com Mon Jun 8 12:07:49 2009 From: orsenthil at gmail.com (Phoe6) Date: Mon, 8 Jun 2009 09:07:49 -0700 (PDT) Subject: problems while using pexpect: pexcept.TIMEOUT always Message-ID: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> I have been trying to use pexpect and I am failing with pexpect.TIMEOUT for all my attempts. In order to troubleshoot, I decided to go with simplest possible one. Here is my ssh to localhost: [21:29:14 senthil]$ssh localhost -l senthil senthil at localhost's password: senthil at ubuntu:~$ And here is my pexpect script: http://paste.pocoo.org/show/121788/ And the output I get is: True None None Traceback (most recent call last): File "4.py", line 17, in print child.read() File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 858, in read self.expect (self.delimiter) # delimiter default is EOF File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1311, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1325, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "/usr/local/lib/python2.6/site-packages/pexpect.py", line 1409, in expect_loop raise TIMEOUT (str(e) + '\n' + str(self)) pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). Complete Traceback is here: http://paste.pocoo.org/show/121790/ Can someone help me what I am doing wrong here? Why is not working for such a simple thing as ssh to my localhost.? I am getting the same problem while trying to login to remote host also. Thanks, Senthil From francesco.pietra at accademialucchese.it Mon Jun 8 12:13:50 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Mon, 8 Jun 2009 18:13:50 +0200 Subject: Extract value and average Message-ID: I come 'naked', which is unusual and unfair. However, I find it difficult to give a correct start. The files consist, among other things, of a huge number of blocks of the type NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 Density = 0.9896 Ewald error estimate: 0.8252E-05 (in attachment what surely is a correct reproduction of columns) I would like to extract values corresponding to variable DIHED (here 4660.1650) and getting also the mean value from all DIHED. Thanks for giving a possible attack francesco pietra -------------- next part -------------- NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 Density = 0.9896 Ewald error estimate: 0.8252E-05 From deets at nospam.web.de Mon Jun 8 12:15:07 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Jun 2009 18:15:07 +0200 Subject: pyc-files contains absolute paths, is this a bug ? References: Message-ID: <794rinF1pb3g4U1@mid.uni-berlin.de> Stef Mientki wrote: > hello, > > AFAIK I read that pyc files can be transferred to other systems. > I finally got a windows executable working through py2exe, > but still have some troubles, moving the directory around. > > I use Python 2.5.2. > I use py2exe to make a distro > I can unpack the distro, on a clean computer, anywhere where I like, and > it runs fine. > > Now when I've run it once, > I move the subdirectory to another location, > at it doesn't run. > > Looking with a hex editor into some pyc-files, > I see absolute paths to the old directory. It is normal, because they refer to the location of the source-files, which are needed for stacktraces (or at least something like that) But execution itself is independent from this. > Is this normal, > or am I doing something completely wrong ? Dunno anything about py2exe, but it sure sounds a bit awkward what you do - changing locations of files after installation is calling for trouble in lots of software. But I might not have understood what you actually did - and "doesn't" run isn't helping much in that regard..... Diez From python at mrabarnett.plus.com Mon Jun 8 12:21:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 17:21:38 +0100 Subject: Extract value and average In-Reply-To: References: Message-ID: <4A2D3A92.6080908@mrabarnett.plus.com> Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 > Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 > BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 > 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 > EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 > EAMBER (non-restraint) = -176251.1698 > EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 > Density = 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack > The first thing that comes to mind is a regular expression to extract the DIHED values from the file contents, something like: pattern = re.compile(r'DIHED\s+=\s+(\d+\.\d+)') From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 12:29:12 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 16:29:12 GMT Subject: Extract value and average References: Message-ID: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > I come 'naked', which is unusual and unfair. ??? > However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = > 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = > -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED > = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 > VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = > 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = > -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME > = 669299.5681 > Density = > 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack Assuming no DIHED value will ever be split over two lines: data = open(filename) values = [] for line in data: if line and line.strip(): # ignore blanks words = line.strip().split() try: i = words.index("DIHED") except IndexError: continue values.append(float(words[i+2])) mean = sum(values)/len(values) should do the job. -- Steven From python.list at tim.thechases.com Mon Jun 8 12:36:52 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Jun 2009 11:36:52 -0500 Subject: Extract value and average In-Reply-To: References: Message-ID: <4A2D3E24.2060302@tim.thechases.com> > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. To just pull the DIHED values, you can use this: import re find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) total = count = 0 for line in file('file.txt'): m = find_dihed_re.search(line) if m: str_value = m.group(1) try: f = float(str_value) total += f count += 1 except: print "Not a float: %s" % str_value print "Total:", total print "Count:", count if count: print "Average:", total/count If you want a general parser for the file, it takes a bit more work. -tkc From python at mrabarnett.plus.com Mon Jun 8 12:50:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 17:50:15 +0100 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: <4A2D4147.9060104@mrabarnett.plus.com> Steven D'Aprano wrote: > On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > >> I come 'naked', which is unusual and unfair. > > ??? > >> However, I find it >> difficult to give a correct start. The files consist, among other >> things, of a huge number of blocks of the type >> >> >> NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = >> 89.4 Etot = -134965.2123 EKtot = 41282.1781 EPtot = >> -176247.3905 BOND = 1771.7644 ANGLE = 6893.3003 DIHED >> = 4660.1650 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 >> VDWAALS = 19047.1551 EELEC = -218354.9960 EHBOND = >> 0.0000 RESTRAINT = 3.7793 EAMBER (non-restraint) = >> -176251.1698 EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME >> = 669299.5681 >> Density = >> 0.9896 >> Ewald error estimate: 0.8252E-05 >> >> >> >> (in attachment what surely is a correct reproduction of columns) >> >> I would like to extract values corresponding to variable DIHED (here >> 4660.1650) and getting also the mean value from all DIHED. >> >> Thanks for giving a possible attack > > > Assuming no DIHED value will ever be split over two lines: > > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() > try: > i = words.index("DIHED") > except IndexError: > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) > > > should do the job. > str.index raises ValueError, not IndexError. Anyway, your code could be shortened slightly: data = open(filename) values = [] for line in data: words = line.split() try: i = words.index("DIHED") values.append(float(words[i + 2])) except ValueError: pass mean = sum(values) / len(values) From dstanek at dstanek.com Mon Jun 8 12:57:24 2009 From: dstanek at dstanek.com (David Stanek) Date: Mon, 8 Jun 2009 12:57:24 -0400 Subject: Odd closure issue for generators In-Reply-To: References: Message-ID: On Thu, Jun 4, 2009 at 7:42 PM, Scott David Daniels wrote: > Brian Quinlan wrote: >> >> This is from Python built from the py3k branch: >> ?>>> c = (lambda : i for i in range(11, 16)) >> ?>>> for q in c: >> ... ? ? print(q()) >> ... >> 11 >> 12 >> 13 >> 14 >> 15 >> ?>>> # This is expected >> ?>>> c = (lambda : i for i in range(11, 16)) >> ?>>> d = list(c) >> ?>>> for q in d: >> ... ? ? print(q()) >> ... >> 15 >> 15 >> 15 >> 15 >> 15 >> ?>>> # I was very surprised > > You are entitled to be surprised. ?Then figure out what is going on. > Hint: it is the moral equivalent of what is happening here: > > ? ?>>> c = [] > ? ?>>> for i in range(11, 16): > ? ? ? ? ? ?c.append(lambda: i) > > ? ?>>> i = 'Surprise!' > ? ?>>> print([f() for f in c]) > ? ?['Surprise!', 'Surprise!', 'Surprise!', 'Surprise!', 'Surprise!'] > > ? ?>>> i = 0 > ? ?>>> print([f() for f in c]) > ? ?[0, 0, 0, 0, 0] > > The body of your lambda is an un-evaluated expression with a reference, > not an expression evaluated at the time of loading c. ?TO get what you > expected, try this: > > ? ?>>> c = [] > ? ?>>> for i in range(11, 16): > ? ? ? ? ? ?c.append(lambda i=i: i) > > ? ?>>> i = 'Surprise!' > ? ?>>> print([f() for f in c]) > ? ?[11, 12, 13, 14, 15] > > When you evaluate a lambda expression, the default args are evaluated, > but the expression inside the lambda body is not. ?When you apply that > evaluated lambda expression, the expression inside the lambda body is > is evaluated and returned. > Getting around this can be pretty easy: c = (lambda i=i: i for i in range(11, 16)) for q in (list(c)): print(q()) -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From rhodri at wildebst.demon.co.uk Mon Jun 8 12:57:41 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 08 Jun 2009 17:57:41 +0100 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Mon, 08 Jun 2009 17:29:12 +0100, Steven D'Aprano wrote: > On Mon, 08 Jun 2009 18:13:50 +0200, Francesco Pietra wrote: > >> I come 'naked', which is unusual and unfair. > > ??? Yeah, I had to go and scrub my brain out :-) > Assuming no DIHED value will ever be split over two lines: > > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() > try: > i = words.index("DIHED") > except IndexError: Should be ValueError, not IndexError. > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) > > > should do the job. You don't need the second strip(), words = line.split() should be sufficient. (And we're back to the 'naked' bit again...) -- Rhodri James *-* Wildebeeste Herder to the Masses From rdmurray at bitdance.com Mon Jun 8 13:19:30 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:19:30 +0000 (UTC) Subject: problems while using pexpect: pexcept.TIMEOUT always References: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> Message-ID: Phoe6 wrote: > I have been trying to use pexpect and I am failing with > pexpect.TIMEOUT for all my attempts. In order to troubleshoot, I > decided to go with simplest possible one. > [...] > > Can someone help me what I am doing wrong here? > Why is not working for such a simple thing as ssh to my localhost.? I would suggest using the 'setlog' method of child to get more debugging information from pexpect. I've found that the best way to diagnose the source of a timeout. -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From Scott.Daniels at Acm.Org Mon Jun 8 13:39:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 08 Jun 2009 10:39:12 -0700 Subject: Extract value and average In-Reply-To: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> References: <023d2eaf$0$20636$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > ... > Assuming no DIHED value will ever be split over two lines: > > data = open(filename) > values = [] > for line in data: > if line and line.strip(): # ignore blanks > words = line.strip().split() words = line.split() # does the same as above > try: > i = words.index("DIHED") > except IndexError: > continue > values.append(float(words[i+2])) > mean = sum(values)/len(values) Or similarly (with error checks): values = [] with open('/imports/file.txt') as data: for line in data: parts = line.split(' DIHED ') # assume spaces around DIHED if len(parts) > 1: if len(parts) > 2: # make sure only one DIHED found raise ValueError('Line has DIHED twice: %s' % line) # break the post-DIHED part into '=', , words = parts[1].split(None, 2) values.append(float(tokens[1])) mean = sum(values) / len(values) --Scott David Daniels Scott.Daniels at Acm.Org From orsenthil at gmail.com Mon Jun 8 13:40:54 2009 From: orsenthil at gmail.com (Senthil Kumaran) Date: Mon, 8 Jun 2009 10:40:54 -0700 (PDT) Subject: problems while using pexpect: pexcept.TIMEOUT always References: <804a2630-2bd4-47d8-80df-2362f0ed62fe@s28g2000vbp.googlegroups.com> Message-ID: <33656c07-ef56-4865-91ee-e42e8433c43d@37g2000yqp.googlegroups.com> On Jun 8, 10:19?pm, "R. David Murray" wrote: > I would suggest using the 'setlog' method of child to get > more debugging information from pexpect. ?I've found that the > best way to diagnose the source of a timeout. > setlog method seems to be deprecated and 'not allowed' too as the help says. But, I just figured out with help from another forum (bangpypers) that I was not closing the ssh session. so doing child.sendline('logout') and then doing child.read() in my script worked out. Thanks, Senthil From rdmurray at bitdance.com Mon Jun 8 13:41:55 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:41:55 +0000 (UTC) Subject: pylint naming conventions? References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> <4A2CF6D3.5010400@hotmail.com> Message-ID: Esmail wrote: > Ben Finney wrote: > > My understanding of Esmail's original message was that, like many of us > > on first running ?pylint? against an existing code base, the output is > > astonishingly verbose and tedious to read. By the above I presume he's > > being a good forum member and trying to find a minimal example that > > shows the problem clearly :-) > > Yes, that is my intention .. because the code I was checking was rather > long, combined with the long pylint output it would make for a rather > big posting. > > I'm going to go back and re-read PEP 8 and see if I perhaps don't > recall the right guidelines since no one else here seems to have had > the same observation. Well, I for one looked at that long pylint output when I first tried it, and switched to another tool :) (pyflakes...but I don't think it does PEP 8) -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From rdmurray at bitdance.com Mon Jun 8 13:51:19 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Mon, 8 Jun 2009 17:51:19 +0000 (UTC) Subject: Am I doing this the python way? (list of lists + file io) References: Message-ID: Horace Blegg wrote: > So, Example: I'll read in a CSV file (just one, for now.) and store it into > a list. Sometime later, I'll get another CSV file, almost identical/related > to the first. However, a few values might have changed, and there might be a > few new lines (entries) or maybe a few less. I would want to compare the CSV > file I have in my list (in memory) to new CSV file (which I would probably > read into a temporary list). I would then want to track and log the > differences between the two files. After I've figured out what's changed, I > would either update the original CSV file with the new CSV's information, or > completely discard the original and replace it with the new one (whichever > involves less work). Basically, lots of iterating through each entry of each > CSV file and comparing to other information (either hard coded or variable). > > So, to reiterate, are lists what I want to use? Should I be using something > else? (even if that 'something else' only really comes into play when > storing and operating on LOTS of data, I would still love to hear about it!) Given your description, I don't see any reason to prefer any alternate data structure. 1000 small CSV files should fit in a modern computer's memory with no problem...and if it does become an issue, worry about it then. One thought, though: you might want to create a list subclass to hold your data, so that you can put useful-to-you methods on the subclass... -- R. David Murray http://www.bitdance.com IT Consulting System Administration Python Programming From smacrae319 at live.ca.invalid Mon Jun 8 14:00:41 2009 From: smacrae319 at live.ca.invalid (Seamus MacRae) Date: Mon, 08 Jun 2009 14:00:41 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: Piet van Oostrum wrote: > By the way, there is a series of articles about concurrency on ACM Queue > which may be interesting for those participating in or just following > this discussion: > > http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency > > Here is one introductory paragraph from one of the articles: > > Parallel programming poses many new challenges to the developer, one of > which is synchronizing concurrent access to shared memory by multiple > threads. Programmers have traditionally used locks for synchronization, > but lock-based synchronization has well-known pitfalls. Simplistic > coarse-grained locking does not scale well, while more sophisticated > fine-grained locking risks introducing deadlocks and data races. > Furthermore, scalable libraries written using fine-grained locks cannot > be easily composed in a way that retains scalability and avoids deadlock > and data races. Is that the one about transactional memory? From madigreece at yahoo.gr Mon Jun 8 14:02:02 2009 From: madigreece at yahoo.gr (madigreece at yahoo.gr) Date: Mon, 8 Jun 2009 11:02:02 -0700 (PDT) Subject: error: an integer is required Message-ID: I execute my code in linux environment. My code is: from os import * def insert_text_file(self, strng): t=open("elements_file.txt", "a") t.write(strng) t.close() I'm getting this error: : an integer is required Where is the mistake? Help me, please!! From p.f.moore at gmail.com Mon Jun 8 14:07:25 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 8 Jun 2009 11:07:25 -0700 (PDT) Subject: Is it possible to disable readline in the interactive interpreter? Message-ID: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> I run Python on Windows. I have the (pure Python) pyreadline package installed for (occasional) use by IPython. However, when I use the normal Python interactive prompt, the mere fact that the readline module exists means that it gets used. Is there a way of disabling this? (Preferably by default, rather than on a per-session basis). I don't want to get into usability arguments, but the standard Windows command line history and editing is fine for me, and consistency with other apps is more important in this case than configurability (or any other benefits of readline). And yes, the default behaviour of readline *is* different, in small but irritating ways. Paul. From python.list at tim.thechases.com Mon Jun 8 14:08:16 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Jun 2009 13:08:16 -0500 Subject: Extract value and average In-Reply-To: <4A2D3E24.2060302@tim.thechases.com> References: <4A2D3E24.2060302@tim.thechases.com> Message-ID: <4A2D5390.1070505@tim.thechases.com> Tim Chase wrote: >> I would like to extract values corresponding to variable DIHED (here >> 4660.1650) and getting also the mean value from all DIHED. > > To just pull the DIHED values, you can use this: > > import re > find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) > total = count = 0 > for line in file('file.txt'): > m = find_dihed_re.search(line) > if m: > str_value = m.group(1) > try: > f = float(str_value) > total += f > count += 1 > except: > print "Not a float: %s" % str_value > print "Total:", total > print "Count:", count > if count: > print "Average:", total/count > > If you want a general parser for the file, it takes a bit more work. Just because I was a little bored: import re pair_re = re.compile(r'\b([^=:]+)\s*[=:]\s*([-.e\d]+)', re.I) def builder(fname='file.txt'): thing = {} for line in file(fname): if not line.strip(): continue line = line.upper() if 'NSTEP' in line: # 1 # it's a new thing # 1 if thing: # 1 yield thing # 1 thing = {} # 1 thing.update(dict( (k.strip(), float(v)) for k,v in pair_re.findall(line) )) #if 'EWALD' in line: # 2 # # it's a new thing # 2 # if thing: # 2 # yield thing # 2 # thing = {} # 2 if thing: yield thing # average the various values to demo total = count = 0 for thing in builder(): total += thing.get('DIHED', 0) count += 1 print "Total:", total print "Count:", count if count: print "Average:", total/count This makes a more generic parser (comment/uncomment the corresponding "# 1" or "# 2" code based on whether a new block is found by a first line containing "NSTEP" or a last line containing "EWALD"). This yields a dictionary for each item in the input file. You can pull out whichever value(s) you want to manipulate. -tkc From python at mrabarnett.plus.com Mon Jun 8 14:26:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Jun 2009 19:26:23 +0100 Subject: error: an integer is required In-Reply-To: References: Message-ID: <4A2D57CF.6010109@mrabarnett.plus.com> madigreece at yahoo.gr wrote: > I execute my code in linux environment. > My code is: > > from os import * > > def insert_text_file(self, strng): > t=open("elements_file.txt", "a") > t.write(strng) > t.close() > > I'm getting this error: > > : an integer is required > > Where is the mistake? > Help me, please!! The os module has a function called 'open'. When you imported all of the os module you hid the builtin 'open' with the one in the os module. Wildcarded imports are generally not recommended for this reason. Just use "import os" and then prefix with "os." wherever it's needed. From mail at timgolden.me.uk Mon Jun 8 14:31:01 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Jun 2009 19:31:01 +0100 Subject: Is it possible to disable readline in the interactive interpreter? In-Reply-To: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: <4A2D58E5.7040405@timgolden.me.uk> Paul Moore wrote: > I run Python on Windows. I have the (pure Python) pyreadline package > installed for (occasional) use by IPython. However, when I use the > normal Python interactive prompt, the mere fact that the readline > module exists means that it gets used. I used to get round this by installing pyreadline within the iPython package, so it only appeared to exist from that app's POV. TJG From lczancanella at gmail.com Mon Jun 8 14:43:56 2009 From: lczancanella at gmail.com (lczancanella) Date: Mon, 8 Jun 2009 11:43:56 -0700 (PDT) Subject: MD5 hash of object Message-ID: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Hi, in hashlib the hash methods have as parameters just string, i want to know how can i digest an object to get a md5 hash of them. Thankz Luiz From tjreedy at udel.edu Mon Jun 8 14:46:07 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Jun 2009 14:46:07 -0400 Subject: error: an integer is required In-Reply-To: References: Message-ID: madigreece at yahoo.gr wrote: > I execute my code in linux environment. > My code is: > > from os import * > > def insert_text_file(self, strng): > t=open("elements_file.txt", "a") > t.write(strng) > t.close() > > I'm getting this error: > > : an integer is required > > Where is the mistake? > Help me, please!! Tell us the Python version and give the *full* traceback message, not just the last line. I am pretty sure you also left out an important part of the code you executed to get that message. tjr From p.f.moore at gmail.com Mon Jun 8 14:48:43 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 8 Jun 2009 11:48:43 -0700 (PDT) Subject: Is it possible to disable readline in the interactive interpreter? References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: On Jun 8, 7:31?pm, Tim Golden wrote: > Paul Moore wrote: > > I run Python on Windows. I have the (pure Python) pyreadline package > > installed for (occasional) use by IPython. However, when I use the > > normal Python interactive prompt, the mere fact that the readline > > module exists means that it gets used. > > I used to get round this by installing pyreadline within the > iPython package, so it only appeared to exist from that > app's POV. Interesting approach - I hadn't thought of that. I might give that a try. Nevertheless, if it isn't possible to disable readline, I may just raise a bug report as well... Paul. From theller at python.net Mon Jun 8 15:10:30 2009 From: theller at python.net (Thomas Heller) Date: Mon, 08 Jun 2009 21:10:30 +0200 Subject: Is it possible to disable readline in the interactive interpreter? In-Reply-To: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> References: <448cf013-ae96-42e1-9485-99f9e66d8437@p4g2000vba.googlegroups.com> Message-ID: <795617F1oa81gU1@mid.individual.net> Paul Moore schrieb: > I run Python on Windows. I have the (pure Python) pyreadline package > installed for (occasional) use by IPython. However, when I use the > normal Python interactive prompt, the mere fact that the readline > module exists means that it gets used. > > Is there a way of disabling this? (Preferably by default, rather than > on a per-session basis). > > I don't want to get into usability arguments, but the standard Windows > command line history and editing is fine for me, and consistency with > other apps is more important in this case than configurability (or any > other benefits of readline). And yes, the default behaviour of > readline *is* different, in small but irritating ways. This has also disturbed me. However, tab-completion is really nice sometimes. I wonder if there is a way to to configure readline to that it behaves on 'up' or 'down' keypresses in the same way as the windows console. Does someone have such a configuration? Thomas From robert.kern at gmail.com Mon Jun 8 15:14:32 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Jun 2009 14:14:32 -0500 Subject: spammers on pypi In-Reply-To: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: On 2009-06-08 07:44, Skip Montanaro wrote: > On Jun 5, 1:39 pm, joep wrote: >> Is there a way to ban spammers from pypi? > > Can you provide some examples? It's possible that we can apply > SpamBayes > to PyPI submissions in much the same way that we apply it in other non- > mail > areas. I suspect he might talking about all of the "1.0.1" releases of projects on June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" (obfuscated to avoid helping them out). Most of them appear to be removed, now. These chuckleheads even have a blog post complaining about it. I can collect a list from my Cheeseshop RSS history if you like. I don't think a SpamBayes approach will work for this particular guy. It's not like completely fake metadata was uploaded with links to spam sites. There actually is Python code for some of them. Maybe even some that is marginally useful. But only marginally (Linked Lists for Python? Really?). All of the code appears to use their proprietary, unreleased package. -- 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 bearophileHUGS at lycos.com Mon Jun 8 15:28:09 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 12:28:09 -0700 (PDT) Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <6272ad2e-bce4-48ad-a729-80400c59e929@z9g2000yqi.googlegroups.com> s... at pobox.com: > Why not just write extension modules in C then? In the past I have used some C for that purpose, but have you tried the D language (used from Python with Pyd)? It's way better, especially if you for example use libs similar to itertools functions, etc :-) Bye, bearophile From bearophileHUGS at lycos.com Mon Jun 8 15:30:59 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 12:30:59 -0700 (PDT) Subject: Am I doing this the python way? (list of lists + file io) References: Message-ID: R. David Murray: > Given your description, I don't see any reason to prefer any alternate > data structure. ?1000 small CSV files should fit in a modern computer's > memory with no problem...and if it does become an issue, worry about it > then. The OP can also try the "diff" command that can be found implemented both on Linux and Windows. Bye, bearophile From jnoller at gmail.com Mon Jun 8 15:32:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 8 Jun 2009 15:32:39 -0400 Subject: spammers on pypi In-Reply-To: References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> On Mon, Jun 8, 2009 at 3:14 PM, Robert Kern wrote: > On 2009-06-08 07:44, Skip Montanaro wrote: >> >> On Jun 5, 1:39 pm, joep ?wrote: >>> >>> Is there a way to ban spammers from pypi? >> >> Can you provide some examples? ?It's possible that we can apply >> SpamBayes >> to PyPI submissions in much the same way that we apply it in other non- >> mail >> areas. > > I suspect he might talking about all of the "1.0.1" releases of projects on > June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" > (obfuscated to avoid helping them out). Most of them appear to be removed, > now. These chuckleheads even have a blog post complaining about it. I can > collect a list from my Cheeseshop RSS history if you like. > > I don't think a SpamBayes approach will work for this particular guy. It's > not like completely fake metadata was uploaded with links to spam sites. > There actually is Python code for some of them. Maybe even some that is > marginally useful. But only marginally (Linked Lists for Python? Really?). > All of the code appears to use their proprietary, unreleased package. > None of the code was useful, and I swear it all seemed like one giant ruse to bump google rankings for his pay-for-play sites and downloads. It was all just series of URLs back linking to his crap-sites. From robert.kern at gmail.com Mon Jun 8 15:39:39 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Jun 2009 14:39:39 -0500 Subject: spammers on pypi In-Reply-To: <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> <4222a8490906081232q4b1626d5nd49946d96aeecc45@mail.gmail.com> Message-ID: On 2009-06-08 14:32, Jesse Noller wrote: > On Mon, Jun 8, 2009 at 3:14 PM, Robert Kern wrote: >> On 2009-06-08 07:44, Skip Montanaro wrote: >>> On Jun 5, 1:39 pm, joep wrote: >>>> Is there a way to ban spammers from pypi? >>> Can you provide some examples? It's possible that we can apply >>> SpamBayes >>> to PyPI submissions in much the same way that we apply it in other non- >>> mail >>> areas. >> I suspect he might talking about all of the "1.0.1" releases of projects on >> June 5th from "v y p e r l o g i x . c o m" or "p y p i . i n f o" >> (obfuscated to avoid helping them out). Most of them appear to be removed, >> now. These chuckleheads even have a blog post complaining about it. I can >> collect a list from my Cheeseshop RSS history if you like. >> >> I don't think a SpamBayes approach will work for this particular guy. It's >> not like completely fake metadata was uploaded with links to spam sites. >> There actually is Python code for some of them. Maybe even some that is >> marginally useful. But only marginally (Linked Lists for Python? Really?). >> All of the code appears to use their proprietary, unreleased package. > > None of the code was useful, and I swear it all seemed like one giant > ruse to bump google rankings for his pay-for-play sites and downloads. > It was all just series of URLs back linking to his crap-sites. Come now! I'm sure pyLotto has some measurable (but tiny!) amount of expected value to it. :-) The main point is that the code isn't gibberish. It might even do what it claims to do if one had the dependencies. Only a human examining it could determine that the code was actually useless and part of a spam-like campaign. -- 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 clp2 at rebertia.com Mon Jun 8 15:47:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 12:47:00 -0700 Subject: MD5 hash of object In-Reply-To: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> References: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Message-ID: <50697b2c0906081247m23c6fdf3of876d120f60ac75b@mail.gmail.com> On Mon, Jun 8, 2009 at 11:43 AM, lczancanella wrote: > Hi, > > in hashlib the hash methods have as parameters just string, i want to > know how can i digest an object to get a md5 hash of them. Hashes are only defined to operate on bytestrings. Since Python is a high-level language and doesn't permit you to view the internal binary representation of objects, you're going to have to properly convert the object to a bytestring first, a process called "serialization". The `pickle` and `json` serialization modules are included in the standard library. These modules can convert objects to bytestrings and back again. Once you've done the bytestring conversion, just run the hash method on the bytestring. Be careful when serializing dictionaries and sets though, because they are arbitrarily ordered, so two dictionaries containing the same items and which compare equal may have a different internal ordering, thus different serializations, and thus different hashes. Cheers, Chris -- http://blog.rebertia.com From stef.mientki at gmail.com Mon Jun 8 15:49:59 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 08 Jun 2009 21:49:59 +0200 Subject: Wrapping LabVIEW and DAQmx Libraries for Python In-Reply-To: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> References: <8875cc2a-fbc4-461a-8060-1f09da9ca796@q2g2000vbr.googlegroups.com> Message-ID: <4A2D6B67.30803@gmail.com> hi Ketteth, I was waiting for someone, making these available. The hardware modules of NI are very good, and they have a huge range of DAQ cards, even relative cheap ones. We use USB 6009 and 9162 container a lot ( now in Delphi, because the lack of Python drivers :-( I took a biref look at your code, but couldn't find any continous sampling routines. Are you plan to create them ? cheers, Stef xkenneth wrote: > All, > > I've started wrapping the DAQmx and other LabVIEW libraries for > python using ctypes. I really like doing some things in python and > other in LabVIEW, so I'd like to have the same functionality available > for both. I've hosted the tiniest bit of code (mostly just proof of > concept) on github. Let me know if anyone else would be interested in > this. I'd love some help hashing it out. > > - Ken > > http://github.com/erdosmiller/pydaqmx/tree/master > From castironpi at gmail.com Mon Jun 8 15:57:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 8 Jun 2009 12:57:58 -0700 (PDT) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: On Jun 8, 9:50?am, Jean-Michel Pichavant wrote: > Aaron Brady wrote: > > Shorter is always better. > > > url+= { '/': '' }.get( url[ -1 ], '/' ) > > Why bother with spaces or 3 letter-wide token, check this ?:o) : > x+={'/':''}.get(x[-1],'/') > > Apart from joking, the following proposed solution is by **far** the one > I prefer > > > if not url.endswith('/'): > > ? ?url += '/' > > Maybe not the shorter, but the most concise and clear to me. Why won't Python permit: url.endswith( '/' ) or url.append( '/' ) ? Should it? Do we find it just as concise and clear? Does it outweigh the priority of the immutability of strings? It works on lists, for example. A sole mutating operation could create a highly and finely tempered compromise with immutability. Would it be 'append'? I like Scott's and MRAB's idea for slicing, not indexing, the last character. The most literal translation of the original natural language is: >>> #ensure that the url ends with a '/' >>> ensure( url, string.endswith, '/' ) (Is it not?) But the parameters aren't sufficient to define 'ensure' generally, and it won't be able to mutate 'url' regardless. From jeff at jmcneil.net Mon Jun 8 16:18:02 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 8 Jun 2009 13:18:02 -0700 (PDT) Subject: Get the class name References: <48a1ff20-8a8e-4b15-9ccf-8f74df76f027@x5g2000yqk.googlegroups.com> Message-ID: <1141201e-9fe6-4c08-9d85-fcc87e52ffba@o36g2000vbi.googlegroups.com> On Jun 8, 11:33?am, Gary Herron wrote: > Kless wrote: > > Is there any way of to get the class name to avoid to have that write > > it? > > > --------------- > > class Foo: > > ? ?super(Foo, self) > > --------------- > > > * Using Py 2.6.2 > > The question does not make sense: > ? ? "to have WHAT write WHAT", > and the code is wrong: > ? ? the call to super fails > But even so, perhaps this will answer your question > > ?>>> class Foo: > ... ? pass > ... > > ?>>> print Foo.__name__ > Foo > > ?>>> c = Foo > ?>>> print c.__name__ > Foo > > ?>>> ob = Foo() > ?>>> print ob.__class__.__name__ > Foo > > Gary Herron I think the OP wants to call super without having to explicitly name the type. If you use the self.__class__ approach in that scenario, you can enter into a recursion loop with further inheritance. class T(object): """I'm a standard class""" def f(self): print "function" class S(T): """I call super using self.__class__""" def f(self): super(self.__class__, self).f() class J(S): """I don't know about S' odd call.""" j = J() j.f() # <--- Bombs From enleverLesX_XXmcX at XmclavXeauX.com Mon Jun 8 16:45:39 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Mon, 08 Jun 2009 21:45:39 +0100 Subject: is there python image lib that does imagemagick? References: <39a7c7e2-a80c-4c64-8f0e-f13a14115cf5@j32g2000yqh.googlegroups.com> Message-ID: <4a2d6a64$0$12625$ba4acef3@news.orange.fr> Hi! On Windows, you can drive (manage?) ImageMagick from Python, via COM. See: http://www.imagemagick.org/script/api.php#com+ @-salutations -- Michel Claveau From mail at timgolden.me.uk Mon Jun 8 17:19:30 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Jun 2009 22:19:30 +0100 Subject: pythoncom and writing file "summary" info on Windows In-Reply-To: References: Message-ID: <4A2D8062.1040806@timgolden.me.uk> mattleftbody at gmail.com wrote: > Hello, > I was trying to put together a script that would write things like the > Author and Title metadata fields of a file under Windows. I got the > win32 extensions installed and found a few things that look like they > should work, though I'm not getting the result I would expect. > Hopefully someone has worked through this area and can point me in the > right direction. FWIW, this works for me: import os, sys from win32com.shell import shell, shellcon import pythoncom from win32com import storagecon filepath = sys.argv[1] pidl, flags = shell.SHILCreateFromPath (os.path.abspath (filepath), 0) property_set_storage = shell.SHGetDesktopFolder ().BindToStorage ( pidl, None, pythoncom.IID_IPropertySetStorage ) summary_info = property_set_storage.Open ( pythoncom.FMTID_SummaryInformation, storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE ) summary_info.WriteMultiple ([storagecon.PIDSI_TITLE], ["BLAHBLAH2"]) BUT... you need to be aware that working with files -- typically media files such as JPEGs etc. -- can play strange tricks with this info as they implement their own property handlers to provide extra file-specific info. On my system, for example, altho' the Summary tab offers Title and Author and I can fill them in an Apply, nothing happens. They're not there when I come back, and likewise the code above won't affect them. Maybe this is what you're seeing. TJG From mh at pixar.com Mon Jun 8 17:36:51 2009 From: mh at pixar.com (mh at pixar.com) Date: Mon, 08 Jun 2009 21:36:51 GMT Subject: preferring [] or () in list of error codes? Message-ID: Is there any reason to prefer one or the other of these statements? if e.message.code in [25401,25402,25408]: if e.message.code in (25401,25402,25408): I'm currently using [], but only coz I think it's prettier than (). context: these are database errors and e is database exception, so there's probably been zillions of instructions and io's handling that already. Many TIA! Mark -- Mark Harrison Pixar Animation Studios From apt.shansen at gmail.com Mon Jun 8 17:56:24 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Jun 2009 14:56:24 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: <7a9c25c20906081456obcc469by89f5e29d59ee7fc9@mail.gmail.com> On Mon, Jun 8, 2009 at 2:36 PM, wrote: > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). I like to use tuples / () if the sequence literal is ultimately static. Purely because in my mind that just makes it a little more clear-- a list is mutable, so I use it when it should be or may be mutated; if it never would, I use a tuple. It just seems clearer to me that way. But a tuple also takes up a little space in memory, so it's a bit more efficient that way. I have absolutely no idea if reading / checking for contents in a list vs tuple has any performance difference, but would suspect it'd be tiny (and probably irrelevant in a small case like that), but still. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Mon Jun 8 18:15:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 08 Jun 2009 15:15:07 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: mh at pixar.com wrote: > Is there any reason to prefer one or the other of these statements? > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > I'm currently using [], but only coz I think it's prettier > than (). > context: these are database errors and e is database exception, > so there's probably been zillions of instructions and io's > handling that already. I lightly prefer the (a, b, c) -- you do put spaces after the comma, don't you? A tuple can be kept as a constant, but it requires (not very heavy) program analysis to determine that the list need not be constructed each time the statement is executed. In addition, a tuple is allocated as a single block, while a list is a pair of allocations. The cost is tiny, however, and your sense of aesthetics is part of your code. So unless you only very slightly prefer brackets, if I were you I'd go with the list form. --Scott David Daniels Scott.Daniels at Acm.Org From sjmachin at lexicon.net Mon Jun 8 19:28:42 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 8 Jun 2009 23:28:42 +0000 (UTC) Subject: preferring [] or () in list of error codes? References: Message-ID: pixar.com> writes: > > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > >From the viewpoint of relative execution speed, in the above case if it matters at all it matters only on Python 2.4 AFAICT: | >>> L=lambda x:x in[25401,25402,25408]; T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (25401) 6 LOAD_CONST 2 (25402) 9 LOAD_CONST 3 (25408) 12 BUILD_LIST 3 15 COMPARE_OP 6 (in) 18 RETURN_VALUE 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 4 ((25401, 25402, 25408)) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE Earlier versions build the list or tuple at run time (as for the list above); later versions detect that the list can't be mutated and generate the same code for both the list and tuple. However there are limits to the analysis that can be performed e.g. if the list is passed to a function, pursuit halts at the county line: [Python 2.6.2] | >>> F=lambda y,z:y in z;L=lambda x:F(x,[25401,25402,25408]); T=lambda x:F(x,(25401,25402,25408));import dis;dis.dis(L);dis.dis(T) 1 0 LOAD_GLOBAL 0 (F) 3 LOAD_FAST 0 (x) 6 LOAD_CONST 0 (25401) 9 LOAD_CONST 1 (25402) 12 LOAD_CONST 2 (25408) 15 BUILD_LIST 3 18 CALL_FUNCTION 2 21 RETURN_VALUE 1 0 LOAD_GLOBAL 0 (F) 3 LOAD_FAST 0 (x) 6 LOAD_CONST 3 ((25401, 25402, 25408)) 9 CALL_FUNCTION 2 12 RETURN_VALUE So in general anywhere I had a "list constant" I'd make it a tuple -- I'm not aware of any way that performance gets worse by doing that, and it can get better. Background: I'm supporting packages that run on 2.1 to 2.6 in one case and 2.4 to 2.6 in the other; every little unobtrusive tweak helps :-) HTH, John From ben+python at benfinney.id.au Mon Jun 8 19:43:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 09:43:45 +1000 Subject: preferring [] or () in list of error codes? References: Message-ID: <87zlcicmvi.fsf@benfinney.id.au> mh at pixar.com writes: > Is there any reason to prefer one or the other of these statements? > > if e.message.code in [25401,25402,25408]: > if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). Use a list when the semantic meaning of an item doesn't depend on all the other items: it's ?only? a collection of values. Your list of message codes is a good example: if a value appears at index 3, that doesn't make it mean something different from the same value appearing at index 2. Use a tuple when the semantic meaning of the items are bound together, and it makes more sense to speak of all the items as a single structured value. The classic examples are point coordinates and timestamps: rather than a collection of values, it makes more sense to think of each coordinate set or timestamp as a single complex value. The value 7 appearing at index 2 would have a completely different meaning from the value 7 appearing at index 3. James Tauber explains this at . -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so, Brain, but pantyhose are so uncomfortable in the | _o__) summertime.? ?_Pinky and The Brain_ | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Mon Jun 8 19:44:10 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Jun 2009 23:44:10 GMT Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> Message-ID: <023d949e$0$20636$c3e8da3@news.astraweb.com> On Mon, 08 Jun 2009 12:57:58 -0700, Aaron Brady wrote: > Why won't Python permit: > > url.endswith( '/' ) or url.append( '/' ) > > ? Because: (1) Strings are immutable, so that won't work. (2) Even if it did, you're programming by side-effect, which is bad style often leading to bugs, and so should be avoided. > Should it? Heavens no! It's bad enough that similar expressions are allowed for lists. Just because they're allowed, doesn't mean we should use them! > Do we find it just as concise and clear? No. It *looks* like a boolean expression which is produced then thrown away uselessly. If not for append() on lists having a side-effect, I'd call it an expensive no-op. > Does it > outweigh the priority of the immutability of strings? Certainly not. Special cases aren't special enough to break the rules. Strings have nice consistent behaviour. You're suggesting making their behaviour inconsistent. > It works on > lists, for example. A sole mutating operation could create a highly and > finely tempered compromise with immutability. You're not thinking it through. You can't say "strings are immutable, except for append, which mutates them". If you allow *one* mutable operation, then the type is mutable, full stop. > Would it be 'append'? > > I like Scott's and MRAB's idea for slicing, not indexing, the last > character. > > The most literal translation of the original natural language is: > >>>> #ensure that the url ends with a '/' >>>> ensure( url, string.endswith, '/' ) > > (Is it not?) But the parameters aren't sufficient to define 'ensure' > generally, and it won't be able to mutate 'url' regardless. This suggestion appears to be a pie-in-the-sky impractical suggestion. It requires a function ensure() with close to human intelligence to "do what I mean". As such, I can't take it seriously. -- Steven From shaibani at ymail.com Mon Jun 8 20:17:05 2009 From: shaibani at ymail.com (Ala) Date: Tue, 09 Jun 2009 01:17:05 +0100 Subject: Network Simulator Message-ID: <090620090117055672%shaibani@ymail.com> Hello everyone. I plan on starting to write a network simulator on python for testing a modified version of TCP. I am wondering if a python network simulator exists? Also, if anyone tried using simpy for doing a simulation. Thank you From shaibani at ymail.com Mon Jun 8 20:18:13 2009 From: shaibani at ymail.com (Ala) Date: Tue, 09 Jun 2009 01:18:13 +0100 Subject: networking simulator on python Message-ID: <090620090118139750%shaibani@ymail.com> Hello everyone. I plan on starting to write a network simulator on python for testing a modified version of TCP. I am wondering if a python network simulator exists? Also, if anyone tried using simpy for doing a simulation. Thank you From pavlovevidence at gmail.com Mon Jun 8 20:37:28 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Jun 2009 17:37:28 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> On Jun 8, 4:43?pm, Ben Finney wrote: > m... at pixar.com writes: > > Is there any reason to prefer one or the other of these statements? > > > ? ? ? ? if e.message.code in [25401,25402,25408]: > > ? ? ? ? if e.message.code in (25401,25402,25408): > > > I'm currently using [], but only coz I think it's prettier > > than (). > > Use a list when the semantic meaning of an item doesn't depend on all > the other items: it's ?only? a collection of values. > > Your list of message codes is a good example: if a value appears at > index 3, that doesn't make it mean something different from the same > value appearing at index 2. > > Use a tuple when the semantic meaning of the items are bound together, > and it makes more sense to speak of all the items as a single structured > value. If you want to go strictly by the book, I would say he ought to be using a set since his collection of numbers has no meaningful order nor does it make sense to list any item twice. I don't think it's very important, however, to stick to rules like that for objects that don't live for more than a single line of code. Carl Banks From greg at cosc.canterbury.ac.nz Mon Jun 8 20:48:40 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 09 Jun 2009 12:48:40 +1200 Subject: Pyrex and refcounts (Re: unladen swallow: python and llvm) In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <4A2DB168.4050204@cosc.canterbury.ac.nz> bearophileHUGS at lycos.com wrote: > I have tried to create a certain data structure with a recent version > of Pyrex on Windows, and I have wasted lot of time looking for missing > reference count updates that didn't happen, or memory that didn't get > freed. Can you elaborate on those problems? The only way you should be able to get reference count errors in Pyrex code is if you're casting between Python and non-Python types. -- Greg From ptmcg at austin.rr.com Mon Jun 8 20:50:32 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Mon, 8 Jun 2009 17:50:32 -0700 (PDT) Subject: networking simulator on python References: <090620090118139750%shaibani@ymail.com> Message-ID: <2e404cd7-2e71-40c1-803e-1432b970bdc1@j32g2000yqh.googlegroups.com> On Jun 8, 7:18?pm, Ala wrote: > Hello everyone. > > I plan on starting to write a network simulator on python for testing a > modified version of TCP. > > I am wondering if a python network simulator exists? Also, if anyone > tried using simpy for doing a simulation. > > Thank you There was an article on just this topic in the April issue of Python Magazine. -- Paul From ben+python at benfinney.id.au Mon Jun 8 21:02:54 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 11:02:54 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> Message-ID: <87my8icj7l.fsf@benfinney.id.au> Carl Banks writes: > If you want to go strictly by the book, I would say he ought to be > using a set since his collection of numbers has no meaningful order > nor does it make sense to list any item twice. Yes, a set would be best for this specific situation. > I don't think it's very important, however, to stick to rules like > that for objects that don't live for more than a single line of code. It's important to the extent that it's important to express one's *meaning*. Program code should be written primarily as a means of communicating with other programmers, and only incidentally for the computer to execute. -- \ ?Laurie got offended that I used the word ?puke?. But to me, | `\ that's what her dinner tasted like.? ?Jack Handey | _o__) | Ben Finney From ndbecker2 at gmail.com Mon Jun 8 21:09:46 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 08 Jun 2009 21:09:46 -0400 Subject: unladen swallow: python and llvm References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> <6272ad2e-bce4-48ad-a729-80400c59e929@z9g2000yqi.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > s... at pobox.com: >> Why not just write extension modules in C then? > > In the past I have used some C for that purpose, but have you tried > the D language (used from Python with Pyd)? It's way better, > especially if you for example use libs similar to itertools functions, > etc :-) > > Bye, > bearophile Is Pyd maintained? I'm interested, but was scared away when I noticed that it had not been updated for some time. (I haven't looked recently). From heweiwei at gmail.com Mon Jun 8 21:15:22 2009 From: heweiwei at gmail.com (BigHand) Date: Mon, 8 Jun 2009 18:15:22 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() Message-ID: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Hi,All I have an embedded python application. which is a MFC app with Python interpreter embedded. In the App, I have a separate thread to execute a Python script (using the PyRun_File), but if the user want to stop the executing script, how should I do? A possible way is terminate the thread of executing the scripts by TerminateThread(). but TerminateThread() is unsafe and not recommended. guys, could you guide me on this? B.R. Harry From pavlovevidence at gmail.com Mon Jun 8 21:28:38 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Jun 2009 18:28:38 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> On Jun 8, 6:02?pm, Ben Finney wrote: > Carl Banks writes: > > If you want to go strictly by the book, I would say he ought to be > > using a set since his collection of numbers has no meaningful order > > nor does it make sense to list any item twice. > > Yes, a set would be best for this specific situation. > > > I don't think it's very important, however, to stick to rules like > > that for objects that don't live for more than a single line of code. > > It's important to the extent that it's important to express one's > *meaning*. Program code should be written primarily as a means of > communicating with other programmers, and only incidentally for the > computer to execute. Which is precisely why isn't not very important for an object that exists for one line. No programmer is ever going to be confused about the meaning of this: if a in (1,2,3): Carl Banks From charles at declareSub.com Mon Jun 8 21:56:53 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 8 Jun 2009 21:56:53 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <2eba581f-cc3c-4666-9b45-0cb73c6b1a28@f10g2000vbf.googlegroups.com> Message-ID: On Jun 8, 2009, at 9:28 PM, Carl Banks wrote: > On Jun 8, 6:02 pm, Ben Finney wrote: >> Carl Banks writes: >>> If you want to go strictly by the book, I would say he ought to be >>> using a set since his collection of numbers has no meaningful order >>> nor does it make sense to list any item twice. >> >> Yes, a set would be best for this specific situation. >> >>> I don't think it's very important, however, to stick to rules like >>> that for objects that don't live for more than a single line of >>> code. >> >> It's important to the extent that it's important to express one's >> *meaning*. Program code should be written primarily as a means of >> communicating with other programmers, and only incidentally for the >> computer to execute. > > Which is precisely why isn't not very important for an object that > exists for one line. No programmer is ever going to be confused about > the meaning of this: > > if a in (1,2,3): > Actually, I might be -- I think of a tuple first as a single thing, as opposed to a list or map, which I see first as a collection of other things. Charles Yeomans From samwyse at gmail.com Mon Jun 8 21:57:34 2009 From: samwyse at gmail.com (samwyse) Date: Mon, 8 Jun 2009 18:57:34 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> Message-ID: <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> On Jun 8, 7:37?pm, Carl Banks wrote: > On Jun 8, 4:43?pm, Ben Finney wrote: > > m... at pixar.com writes: > > > Is there any reason to prefer one or the other of these statements? > > > > ? ? ? ? if e.message.code in [25401,25402,25408]: > > > ? ? ? ? if e.message.code in (25401,25402,25408): > > If you want to go strictly by the book, I would say he ought to be > using a set since his collection of numbers has no meaningful order > nor does it make sense to list any item twice. As the length of the list increases, the increased speeds of looking something up makes using a set makes more sense. But what's the best way to express this? Here are a few more comparisons (using Python 3.0)... >>> S=lambda x:x in set((25401,25402,25408)) >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_GLOBAL 0 (set) 6 LOAD_CONST 3 ((25401, 25402, 25408)) 9 CALL_FUNCTION 1 12 COMPARE_OP 6 (in) 15 RETURN_VALUE >>> S=lambda x:x in{25401,25402,25408} >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 0 (25401) 6 LOAD_CONST 1 (25402) 9 LOAD_CONST 2 (25408) 12 BUILD_SET 3 15 COMPARE_OP 6 (in) 18 RETURN_VALUE >>> S=lambda x:x in{(25401,25402,25408)} >>> dis(S) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 3 ((25401, 25402, 25408)) 6 BUILD_SET 1 9 COMPARE_OP 6 (in) 12 RETURN_VALUE I conclude that using constructors is generally a bad idea, since the compiler doesn't know if you're calling the builtin or something with an overloaded name. I presume that the compiler will eventually optimize the second example to match the last, but both of them use the BUILD_SET opcode. I expect that this can be expensive for long lists, so I don't think that it's a good idea to use set constants inside loops. Instead it should be assigned to a global or class variable. From bearophileHUGS at lycos.com Mon Jun 8 22:02:19 2009 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: Mon, 8 Jun 2009 19:02:19 -0700 (PDT) Subject: Pyrex and refcounts (Re: unladen swallow: python and llvm) References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> <4A2DB168.4050204@cosc.canterbury.ac.nz> Message-ID: Greg: >Can you elaborate on those problems?< I can't, I am sorry, I don't remember the details anymore. Feel free to ignore what I have written about Pyrex, lot of people appreciate it, so it must be good enough, even if I was not smart/ expert enough to use it well. I have even failed in using it on Windows for several days, so probably I am/was quite ignorant. I use Python also because it's handy. For programmers being lazy is sometimes a quality :-) ----------------- This part is almost OT, I hope it will be tolerated. Neal Becker: >Is Pyd maintained? I'm interested, but was scared away when I noticed that it had not been updated for some time. (I haven't looked recently).< I think Pyd works (with no or small changes) with a D1 compiler like DMD, but you have to use the Phobos Standard library, that is worse than Tango. If you have problems with Pyd you will probably find people willing to help you on the D IRC channel. The problem is that the D language isn't used by lot of people, and most libraries are developed by few university students that stop mantaining the libraries once they find a job. So most D libraries are almost abandoned. There is just not enough people in the D community. And some people don't like to develop new libs because the D2 language (currently in Alpha still) makes D1 look like a dead end. On the other hand this is also a good thing, because D1 language has stopped evolving, so you are often able to compile even "old" code. Using Pyd is quite easy, but D1 language is not as simple as Python, despite being three times simpler than C++ :-) The good thing is that it's not difficult to adapt C code to D, it's almost a mechanical translation (probably a tool simpler than 2to3 can be enough to perform such translation of C to D, but of course no one has written such thing). Another problem with Pyd is that it may have scalability problems, that is it may have problems if you want to wrap hundreds of classes and functions. So before using it for real projects it's better to test it well. I have no idea if D will ever have some true success, even if it's nice. The hystory of Informatics is full of thousands of nice dead languages. In the meantime I'll keep using it and writing libs, etc. I have seen than several Python-lovers like D. The new LDC compiler allows D1 code to be most times about as fast as C++. This is more than enough. At the moment it seems that D is appreciated by people that write video games. Bye, bearophile From skip at pobox.com Mon Jun 8 22:15:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 8 Jun 2009 21:15:29 -0500 Subject: spammers on pypi In-Reply-To: References: <4b331464-aa06-4d10-9055-8ce12f759e8b@o20g2000vbh.googlegroups.com> Message-ID: <18989.50625.738941.862481@montanaro.dyndns.org> Robert> I don't think a SpamBayes approach will work for this particular Robert> guy. It's not like completely fake metadata was uploaded with Robert> links to spam sites. There actually is Python code for some of Robert> them. Maybe even some that is marginally useful. But only Robert> marginally (Linked Lists for Python? Really?). All of the code Robert> appears to use their proprietary, unreleased package. You might be surprised how well SpamBayes could single out this guy's stuff as spam. In his form submission he has to provide some references to his site. Those URLs (or at least fragments of them like domain names) or product references (seems everything has "vyper" in it) would probably become very spammy clues. I'll contact the PyPI software folks. I've used SpamBayes for similar sorts of things (like RoundUp). Somebody even built a SpamBayes for YouTube browser extension: http://userscripts.org/scripts/show/13839 Skip From lczancanella at gmail.com Mon Jun 8 22:23:03 2009 From: lczancanella at gmail.com (lczancanella) Date: Mon, 8 Jun 2009 19:23:03 -0700 (PDT) Subject: Unbound Method Error Message-ID: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Hi, i am brand new in Python, so sorry if this question is too basic, but i have tried a lot and dont have success... I have the following code... class Funcoes: def CifradorDeCesar(mensagem, chave, funcao): mensagem_encriptada='' if funcao == 1: for byte in mensagem: if byte.isalpha(): byte_encriptado=chr(ord(byte)+chave) if byte.isupper() and ord(byte_encriptado) > 90: byte_encriptado=chr(ord(byte_encriptado)-26) if byte.islower() and ord(byte_encriptado) > 122: byte_encriptado=chr(ord(byte_encriptado)-26) else: byte_encriptado=byte mensagem_encriptada+=byte_encriptado else: for byte in mensagem: if byte.isalpha(): byte_encriptado=chr(ord(byte)-chave) if byte.isupper() and ord(byte_encriptado) < 65: byte_encriptado=chr(ord(byte_encriptado)+26) if byte.islower() and ord(byte_encriptado) < 97: byte_encriptado=chr(ord(byte_encriptado)+26) else: byte_encriptado=byte mensagem_encriptada+=byte_encriptado return mensagem_encriptada class MC(Funcoes, type): def __init__(cls, clsname, bases, ns): def addtrace(f): def t(self, *args, **kwargs): for att in self.__crypt__: atribcripto = getattr(self, att) atribdescripto = Funcoes.CifradorDeCesar (atribcripto, 3, 2) setattr(self, att, atribdescripto) ret = f(self, *args, **kwargs) for att in self.__crypt__: atribdescripto = getattr(self, att) atribcripto = Funcoes.CifradorDeCesar (atribdescripto, 3, 1) setattr(self, att, atribcripto) # aqui seta __signature__ vazio, assina e atribui __signature__ return ret return t from types import FunctionType for name,obj in ns.items(): if type(obj) == FunctionType: setattr(cls, name, addtrace(ns[name])) class C(): __metaclass__ = MC __crypt__ = ["_a", "_b"] _a = 1 _b = 2 def add(self, a, b): _a = a _b = b return a+b then i call >>> i = C() >>> i.add(2,2) and the error: File "C:\Users\Junior\Desktop\Python\T2.py", line 37, in t atribdescripto = Funcoes.CifradorDeCesar(atribcripto, 3, 2) TypeError: unbound method CifradorDeCesar() must be called with Funcoes instance as first argument (got int instance instead) From clp2 at rebertia.com Mon Jun 8 22:30:22 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 19:30:22 -0700 Subject: Unbound Method Error In-Reply-To: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <50697b2c0906081930w60adeb8elcdb5e49ba18b2c2@mail.gmail.com> On Mon, Jun 8, 2009 at 7:23 PM, lczancanella wrote: > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > ? ?def CifradorDeCesar(mensagem, chave, funcao): > ? ? ? ?mensagem_encriptada='' > ? ? ? ?if funcao == 1: > ? ? ? ? ? ?for byte in mensagem: > ? ? ? ? ? ? ? ?if byte.isalpha(): > ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte)+chave) > ? ? ? ? ? ? ? ? ? ?if byte.isupper() and ord(byte_encriptado) > 90: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)-26) > ? ? ? ? ? ? ? ? ? ?if byte.islower() and ord(byte_encriptado) > 122: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)-26) > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?byte_encriptado=byte > ? ? ? ? ? ? ? ?mensagem_encriptada+=byte_encriptado > ? ? ? ?else: > ? ? ? ? ? ?for byte in mensagem: > ? ? ? ? ? ? ? ?if byte.isalpha(): > ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte)-chave) > ? ? ? ? ? ? ? ? ? ?if byte.isupper() and ord(byte_encriptado) < 65: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)+26) > ? ? ? ? ? ? ? ? ? ?if byte.islower() and ord(byte_encriptado) < 97: > ? ? ? ? ? ? ? ? ? ? ? ?byte_encriptado=chr(ord(byte_encriptado)+26) > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?byte_encriptado=byte > ? ? ? ? ? ? ? ?mensagem_encriptada+=byte_encriptado > > ? ? ? ?return mensagem_encriptada > > class MC(Funcoes, type): > ? ?def __init__(cls, clsname, bases, ns): > ? ? ? ?def addtrace(f): > ? ? ? ? ? ?def t(self, *args, **kwargs): > ? ? ? ? ? ? ? ?for att in self.__crypt__: > ? ? ? ? ? ? ? ? ? ?atribcripto = getattr(self, att) > ? ? ? ? ? ? ? ? ? ?atribdescripto = Funcoes.CifradorDeCesar > (atribcripto, 3, 2) > ? ? ? ? ? ? ? ? ? ?setattr(self, att, atribdescripto) > ? ? ? ? ? ? ? ?ret = f(self, *args, **kwargs) > ? ? ? ? ? ? ? ?for att in self.__crypt__: > ? ? ? ? ? ? ? ? ? ?atribdescripto = getattr(self, att) > ? ? ? ? ? ? ? ? ? ?atribcripto = Funcoes.CifradorDeCesar > (atribdescripto, 3, 1) > ? ? ? ? ? ? ? ? ? ?setattr(self, att, atribcripto) > ? ? ? ? ? ? ? ?# aqui seta __signature__ vazio, assina e atribui > __signature__ > ? ? ? ? ? ? ? ?return ret > ? ? ? ? ? ?return t > ? ? ? ?from types import FunctionType > ? ? ? ?for name,obj in ns.items(): > ? ? ? ? ? ?if type(obj) == FunctionType: > ? ? ? ? ? ? ? ?setattr(cls, name, addtrace(ns[name])) > > class C(): > > ? ?__metaclass__ = MC > ? ?__crypt__ = ["_a", "_b"] > > ? ?_a = 1 > ? ?_b = 2 > > ? ?def add(self, a, b): > ? ? ? ?_a = a > ? ? ? ?_b = b > ? ? ? ?return a+b > > then i call > >>>> i = C() >>>> i.add(2,2) > > and the error: > > File "C:\Users\Junior\Desktop\Python\T2.py", line 37, in t > ? ?atribdescripto = Funcoes.CifradorDeCesar(atribcripto, 3, 2) > TypeError: unbound method CifradorDeCesar() must be called with > Funcoes instance as first argument (got int instance instead) `CifradorDeCesar` is an instance method of the class `Funcoes`, and thus can only be used on instances of the class, *NOT the class itself*. Since it appears to be just a normal function (as suggested by the name of the class and the fact that it lacks `self` as its first parameter), you should scrap the class entirely and just define `CifradorDeCesar` in the toplevel body of the module. Unlike Java, it is *not* good Python style to unnecessarily cram functions into classes. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Jun 8 23:06:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Jun 2009 20:06:19 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <50697b2c0906082006s3531dfccg5f738705fe6849d8@mail.gmail.com> On Mon, Jun 8, 2009 at 6:57 PM, samwyse wrote: > On Jun 8, 7:37?pm, Carl Banks wrote: >> On Jun 8, 4:43?pm, Ben Finney wrote: >> > m... at pixar.com writes: >> > > Is there any reason to prefer one or the other of these statements? >> >> > > ? ? ? ? if e.message.code in [25401,25402,25408]: >> > > ? ? ? ? if e.message.code in (25401,25402,25408): >> >> If you want to go strictly by the book, I would say he ought to be >> using a set since his collection of numbers has no meaningful order >> nor does it make sense to list any item twice. > > As the length of the list increases, the increased speeds of looking > something up makes using a set makes more sense. ?But what's the best > way to express this? ?Here are a few more comparisons (using Python > 3.0)... > >>>> S=lambda x:x in set((25401,25402,25408)) >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_GLOBAL ? ? ? ? ? ? ?0 (set) > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > ? ? ? ? ? ? ?9 CALL_FUNCTION ? ? ? ? ? ?1 > ? ? ? ? ? ? 12 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 15 RETURN_VALUE >>>> S=lambda x:x in{25401,25402,25408} >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 0 (25401) > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 1 (25402) > ? ? ? ? ? ? ?9 LOAD_CONST ? ? ? ? ? ? ? 2 (25408) > ? ? ? ? ? ? 12 BUILD_SET ? ? ? ? ? ? ? ?3 > ? ? ? ? ? ? 15 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 18 RETURN_VALUE >>>> S=lambda x:x in{(25401,25402,25408)} >>>> dis(S) > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > ? ? ? ? ? ? ?6 BUILD_SET ? ? ? ? ? ? ? ?1 > ? ? ? ? ? ? ?9 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > ? ? ? ? ? ? 12 RETURN_VALUE > > I conclude that using constructors is generally a bad idea, since the > compiler doesn't know if you're calling the builtin or something with > an overloaded name. ?I presume that the compiler will eventually > optimize the second example to match the last, but both of them use > the BUILD_SET opcode. ?I expect that this can be expensive for long Erm, unless I misunderstand you somehow, the second example will and should *never* match the last. The set {25401,25402,25408}, containing 3 integer elements, is quite distinct from the set {(25401,25402,25408)}, containing one element and that element is a tuple. set(X) != {X}; set([X]) = {X} Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Jun 8 23:18:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 03:18:24 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: On Tue, 09 Jun 2009 11:02:54 +1000, Ben Finney wrote: > Carl Banks writes: > >> If you want to go strictly by the book, I would say he ought to be >> using a set since his collection of numbers has no meaningful order nor >> does it make sense to list any item twice. > > Yes, a set would be best for this specific situation. > >> I don't think it's very important, however, to stick to rules like that >> for objects that don't live for more than a single line of code. > > It's important to the extent that it's important to express one's > *meaning*. Program code should be written primarily as a means of > communicating with other programmers, and only incidentally for the > computer to execute. But practicality beats purity -- there are many scenarios where we make compromises in our meaning in order to get correct, efficient code. E.g. we use floats, despite them being a poor substitute for the abstract Real numbers we mean. In addition, using a tuple or a list in this context: if e.message.code in (25401,25402,25408): is so idiomatic, that using a set in it's place would be distracting. Rather that efficiently communicating the programmer's intention, it would raise in my mind the question "that's strange, why are they using a set there instead of a tuple?". -- Steven From jeff at jmcneil.net Mon Jun 8 23:20:26 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Mon, 8 Jun 2009 20:20:26 -0700 (PDT) Subject: MD5 hash of object References: <345ec0b8-de70-4a89-8eae-c8dfbb546642@f16g2000vbf.googlegroups.com> Message-ID: On Jun 8, 3:47?pm, Chris Rebert wrote: > On Mon, Jun 8, 2009 at 11:43 AM, lczancanella wrote: > > Hi, > > > in hashlib the hash methods have as parameters just string, i want to > > know how can i digest an object to get a md5 hash of them. > > Hashes are only defined to operate on bytestrings. Since Python is a > high-level language and doesn't permit you to view the internal binary > representation of objects, you're going to have to properly convert > the object to a bytestring first, a process called "serialization". > The `pickle` and `json` serialization modules are included in the > standard library. These modules can convert objects to bytestrings and > back again. > Once you've done the bytestring conversion, just run the hash method > on the bytestring. > > Be careful when serializing dictionaries and sets though, because they > are arbitrarily ordered, so two dictionaries containing the same items > and which compare equal may have a different internal ordering, thus > different serializations, and thus different hashes. > > Cheers, > Chris > --http://blog.rebertia.com I'd think that using the hash of the pickled representation of an object might be problematic, no? The pickle protocol handles object graphs in a way that allows it to preserve references back to identical objects. Consider the following (contrived) example: import pickle from hashlib import md5 class Value(object): def __init__(self, v): self._v = v class P1(object): def __init__(self, name): self.name = Value(name) self.other_name = self.name class P2(object): def __init__(self, name): self.name = Value(name) self.other_name = Value(name) h1 = md5(pickle.dumps(P1('sabres'))).hexdigest() h2 = md5(pickle.dumps(P2('sabres'))).hexdigest() print h1 == h2 >>> False Just something to be aware of. Depending on what you're trying to accomplish, it may make sense to simply define a method which generates a byte string representation of your object's state and just return the hash of that value. Thanks, -Jeff mcjeff.blogspot.com From ben+python at benfinney.id.au Mon Jun 8 23:43:08 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 13:43:08 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <87ab4icbsj.fsf@benfinney.id.au> Steven D'Aprano writes: > In addition, using a tuple or a list in this context: > > if e.message.code in (25401,25402,25408): > > is so idiomatic, that using a set in it's place would be distracting. I think a list in that context is fine, and that's the idiom I see far more often than a tuple. > Rather that efficiently communicating the programmer's intention, it > would raise in my mind the question "that's strange, why are they > using a set there instead of a tuple?". The fact that literal set syntax is a relative newcomer is the primary reason for that, I'd wager. -- \ ?If you are unable to leave your room, expose yourself in the | `\ window.? ?instructions in case of fire, hotel, Finland | _o__) | Ben Finney From emile at fenx.com Tue Jun 9 01:30:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 08 Jun 2009 22:30:17 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <87ab4icbsj.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> Message-ID: On 6/8/2009 8:43 PM Ben Finney said... > Steven D'Aprano writes: > >> In addition, using a tuple or a list in this context: >> >> if e.message.code in (25401,25402,25408): >> >> is so idiomatic, that using a set in it's place would be distracting. > > I think a list in that context is fine, and that's the idiom I see far > more often than a tuple. > >> Rather that efficiently communicating the programmer's intention, it >> would raise in my mind the question "that's strange, why are they >> using a set there instead of a tuple?". > > The fact that literal set syntax is a relative newcomer is the primary > reason for that, I'd wager. > Well, no. It really is more, "that's odd... why use set?" Emile From myopc at aaa.com Tue Jun 9 01:50:47 2009 From: myopc at aaa.com (myopc) Date: Tue, 9 Jun 2009 13:50:47 +0800 Subject: multi-thread python interpreaters and c++ program Message-ID: hi, all I am ruuning a c++ program (boost python) , which create many python interpreaters and each run a python script with use multi-thread (threading). when the c++ main program exit, I want to shut down python interpreaters, but it crashed. I have googled a lot but cant get any clue. here is my code, your suggestion will be greatly appreciated. c++ : /**** test multi interpreaters ***/ #include #include #include #include #include using namespace boost::python; static const char* strs[3]={ "m1","m2","m3" }; static void xxx(const char* abc){ fprintf(stderr, "this is xxx %s\n", abc); } PyThreadState* testPy(int i){ char buf[128]; PyThreadState* ts = Py_NewInterpreter(); object main_namespace = import("__main__").attr("__dict__"); main_namespace["xxx"]= xxx; main_namespace["aaa"]= i+1; main_namespace["strs"]= strs[i]; sprintf(buf, "execfile('pyinter/%d.py')",i+1); if(!PyRun_SimpleString(buf)){ return ts; }else return 0; } int main(int argc, char** argv){ PyThreadState *ts[3]; Py_InitializeEx(0); PyEval_InitThreads(); for(int i=0 ; i< 3; i++){ ts[i]= testPy(i); if(! ts[i] ){ printf("run %d error\n",i); } else { printf("run %d ok\n",i); } } PyEval_ReleaseLock(); /// release the lock, interpreaters run Sleep(3500); for(int i=0; i< 3; i++){ if(! ts[i])continue; printf("delete %d ", i); PyEval_AcquireThread(ts[i]); Py_Finalize(); ///shut down interpreaters ,crash here PyEval_ReleaseLock(); Sleep(10); printf(" ok\n"); } Sleep(1500); printf("exit...\n"); } each interpreater uses the same python script: class MyTimer(object): def __init__(self, interval, function, args=[], kwargs={}): self.interval = interval self.function = function self.args = args self.kwargs = kwargs def start(self): self.stop() import threading self._timer = threading.Timer(self.interval, self._run) self._timer.setDaemon(True) self._timer.start() ### start a python thread, keep running def restart(self): self.start() def stop(self): if self.__dict__.has_key("_timer"): self._timer.cancel() del self._timer def _run(self): try: self.function(strs) except: pass self.restart() abc= MyTimer(aaa,xxx); abc.start(); From piet at cs.uu.nl Tue Jun 9 02:00:12 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 08:00:12 +0200 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: >>>>> Seamus MacRae (SM) wrote: >SM> Piet van Oostrum wrote: >>> By the way, there is a series of articles about concurrency on ACM Queue >>> which may be interesting for those participating in or just following >>> this discussion: >>> >>> http://queue.acm.org/listing.cfm?item_topic=Concurrency&qc_type=theme_list&filter=Concurrency&page_title=Concurrency >>> >>> Here is one introductory paragraph from one of the articles: >>> >>> Parallel programming poses many new challenges to the developer, one of >>> which is synchronizing concurrent access to shared memory by multiple >>> threads. Programmers have traditionally used locks for synchronization, >>> but lock-based synchronization has well-known pitfalls. Simplistic >>> coarse-grained locking does not scale well, while more sophisticated >>> fine-grained locking risks introducing deadlocks and data races. >>> Furthermore, scalable libraries written using fine-grained locks cannot >>> be easily composed in a way that retains scalability and avoids deadlock >>> and data races. >SM> Is that the one about transactional memory? Yes -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From alia_khouri at yahoo.com Tue Jun 9 02:30:19 2009 From: alia_khouri at yahoo.com (Alia Khouri) Date: Mon, 8 Jun 2009 23:30:19 -0700 (PDT) Subject: python version in snow leopard? Message-ID: Does anyone know what version of python will appear in snow leopard which is apparently being released in September? From francesco.pietra at accademialucchese.it Tue Jun 9 02:38:44 2009 From: francesco.pietra at accademialucchese.it (Francesco Pietra) Date: Tue, 9 Jun 2009 08:38:44 +0200 Subject: Fwd: Extract value and average In-Reply-To: References: <4A2D3E24.2060302@tim.thechases.com> <4A2D5E54.20403@tim.thechases.com> Message-ID: Sorry, I missed the last part of the message This makes a more generic parser (comment/uncomment the corresponding "# 1" or "# 2" code based on whether a new block is found by a first line containing "NSTEP" or a last line containing "EWALD"). This > yields a dictionary for each item in the input file. You can pull out whichever value(s) you want to manipulate. I recognize now that I did not define "block" correctly. The EWALD line, although separated by a blank line, makes part of the block. The layout of all other blocks in the output file is the same. francesco ---------- Forwarded message ---------- From: Francesco Pietra Date: Mon, Jun 8, 2009 at 11:55 PM Subject: Re: Extract value and average To: Tim Chase On Mon, Jun 8, 2009 at 8:54 PM, Tim Chase wrote: >> Of the various suggestions, of which I am most grateful, I >> first tried this one. I probably fixed a couple of indent >> problems, but I don't understand the last one: > > Since Python considers whitespace valueable, indentation needs to match. > ?When I transfer code into email, I tend to use two-space indentation so > lines don't wrap (in my regular coding, I tend to use hard-tabs with a > tabstop-du-jour of either 2/3/4 spaces-per-tab) and indent it one level to > offset it from the email body text. > > If you use Vim, you can copy/paste my emailed code and simply use > > ?:%s/ ?/\t/g > ?:%s/^\t > > to expand the two-space indents to actual tabs and then the second one > strips off the leading indentation. That done, previous code (for DIHED only) works fine with both the example file.txt francesco at deb32:~/tmp$ python tim.py Total: 4660.165 Count: 1 Average: 4660.165 and a file of 102 instances of DIHED: francesco at deb32:~/tmp1$ python tim.simple.edited.prod1.py Total: 465628.4416 Count: 102 Average: 4564.98472157 francesco at deb32:~/tmp1$ Incidentally, that solves my current problems. Thanks indeed for your generous help. ==================== The more complex parser also worked fine with file.txt: francesco at deb32:~/tmp$ python tim.py Total: 4660.165 Count: 1 Average: 4660.165 while (replacing in the parser 'file.txt' with 'prod1.out') with the 102 count file above it reported: francesco at deb32:~/tmp$ python tim.prod1.py Traceback (most recent call last): ?File "tim.prod1.py", line 27, in ? ?for thing ? in ? ? ?builder(): ?File "tim.prod1.py", line 15, in builder ? ?for k,v ? ? in ? ? ?pair_re.findall(line) ?File "tim.prod1.py", line 15, in ? ?for k,v ? ? in ? ? ?pair_re.findall(line) ValueError: invalid literal for float(): E I did the filename replacement with vim, though it is likely that I did some other mistake. If not, and you are interested in the prod1.out file, I can send it (82 kB). francesco > > From the code you sent, it looks like whitespace didn't get copied into your > script file correctly or your un-indentation didn't take place on every line > (the last 4 lines look like they have an extra space). ?Once you fix the > whitespace, it should run. ?For convenience, I've repasted below with > 4-spaces-per-tab and no offsetting indentation. > > -tkc > > ---------------------------- > import re > find_dihed_re = re.compile(r'\bDIHED\s*=\s*([.-e\d]+)', re.I) > total = count = 0 > for line in file('file.txt'): > ? ?m = find_dihed_re.search(line) > ? ?if m: > ? ? ? ?str_value = m.group(1) > ? ? ? ?try: > ? ? ? ? ? ?f = float(str_value) > ? ? ? ? ? ?total += f > ? ? ? ? ? ?count += 1 > ? ? ? ?except: > ? ? ? ? ? ?print "Not a float: %s" % str_value > print "Total:", total > print "Count:", count > if count: > ? ?print "Average:", total/count > > > > > > From wuwei23 at gmail.com Tue Jun 9 02:39:28 2009 From: wuwei23 at gmail.com (alex23) Date: Mon, 8 Jun 2009 23:39:28 -0700 (PDT) Subject: Making the case for repeat References: <0045afe3$0$9732$c3e8da3@news.astraweb.com> <7k9m25tc3t207kugik7pkv3k4t2l86f6j3@4ax.com> <023b4095$0$20636$c3e8da3@news.astraweb.com> Message-ID: <64578fa7-8d5c-462a-b266-ffe3edac8bdb@q14g2000vbn.googlegroups.com> Steven D'Aprano wrote: > e.g. the Wright Brothers weren't lone inventors working at a time when > everyone knew powered flight was impossible, they were experienced > engineers and glider-pilots who paid a lot of attention to research done > by their many competitors. Be careful, the idea that human knowledge is a process of incremental improvements rather than pulled complete and inviolate out of the minds of a handful of individuals is pretty unpopular in this day and age. It's a lot harder to assert the existence of "intellectual property" that way, and there's just no money in *that* ;) cynically y'rs, - alex23 From gagsl-py2 at yahoo.com.ar Tue Jun 9 02:58:10 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 03:58:10 -0300 Subject: Python preprosessor References: <4a2beb4b$0$24760$9b536df3@news.fv.fi> Message-ID: En Sun, 07 Jun 2009 13:31:07 -0300, Tuomas Vesterinen escribi?: > I am developing a Python application as a Python2.x and Python3.0 > version. A common code base would make the work easier. So I thought to > try a preprosessor. GNU cpp handles this kind of code correct: > > > #ifdef python2 > print u'foo', u'bar' > #endif > #ifdef python3 > print('foo', 'bar') > #endif > See ifdef.py in the Tools/scripts directory for a pure Python preprocessor. -- Gabriel Genellina From mail at microcorp.co.za Tue Jun 9 03:25:12 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 09:25:12 +0200 Subject: Function/method returning list of chars in string? Message-ID: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> One can go from lb = ['b','a','n','a','n','a'] to s = "banana" by using s = "".join(lb) Is there a way to go the reverse route? I have not been able to find one. It is obviously easy to write a for char in s loop or list comprehension, but there seems to be no function or string method to return a list of characters. using lb = s.split("") would have been nice as a complement to s = "".join(lb). Split is already full of magic, it could do with more. - Hendrik From 4564 at 755189.45 Tue Jun 9 03:28:27 2009 From: 4564 at 755189.45 (Enrico) Date: Tue, 9 Jun 2009 09:28:27 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> "lczancanella" ha scritto nel messaggio news:32bf5ccb-5bfd-49a5-b423-9d41180a0ddb at l28g2000vba.googlegroups.com... > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > def CifradorDeCesar(mensagem, chave, funcao): A quick look to your code suggests to me to rewrite the above lines as: class Funcoes: @classmethod def CifradorDeCesar(self, mensagem, chave, funcao): @classmethod is needed since you call: > atribdescripto = Funcoes.CifradorDeCesar (atribcripto, 3, 2) Best regards, Enrico From clp2 at rebertia.com Tue Jun 9 03:32:46 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 00:32:46 -0700 Subject: Function/method returning list of chars in string? In-Reply-To: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> Message-ID: <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> On Tue, Jun 9, 2009 at 12:25 AM, Hendrik van Rooyen wrote: > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? lb = list("banana") Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 9 03:32:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Jun 2009 09:32:50 +0200 Subject: Function/method returning list of chars in string? In-Reply-To: References: Message-ID: <796hh2F1p7fpkU1@mid.uni-berlin.de> Hendrik van Rooyen schrieb: > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? > > I have not been able to find one. > > It is obviously easy to write a for char in s loop > or list comprehension, but there seems to be > no function or string method to return a list > of characters. > > using lb = s.split("") would have been nice > as a complement to s = "".join(lb). > > Split is already full of magic, it could do with more. I think lb = list(s) is good enough. Diez From jonvspython at gmail.com Tue Jun 9 03:39:40 2009 From: jonvspython at gmail.com (jon vs. python) Date: Tue, 9 Jun 2009 09:39:40 +0200 Subject: Function/method returning list of chars in string? In-Reply-To: <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Sorry, I didn't realize that you already proposed list comprehension. There is some kind of asymmetry in several areas.I guess that's somehow related to this post: http://www.zedshaw.com/blog/2009-05-29.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Tue Jun 9 03:40:47 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 9 Jun 2009 00:40:47 -0700 (PDT) Subject: python version in snow leopard? References: Message-ID: <998336ef-1156-4493-a2c4-0cddb648fe19@f19g2000yqo.googlegroups.com> On Jun 9, 7:30?am, Alia Khouri wrote: > Does anyone know what version of python will appear in snow leopard > which is apparently being released in September? The python-dev thread starting at http://mail.python.org/pipermail/python-3000/2008-September/014816.html suggests that back in September 2008, there was a 'MajorOS Vendor (tm)' who was interested in getting Python 2.6 into their next OS release, provided that it (Python 2.6) was released by October 1st. Make of that what you will. Mark From glauco.uri at prometeia.it Tue Jun 9 03:45:23 2009 From: glauco.uri at prometeia.it (Glauco) Date: Tue, 09 Jun 2009 09:45:23 +0200 Subject: Extract value and average In-Reply-To: References: Message-ID: Francesco Pietra ha scritto: > I come 'naked', which is unusual and unfair. However, I find it > difficult to give a correct start. The files consist, among other > things, of a huge number of blocks of the type > > > NSTEP = 1000 TIME(PS) = 152.000 TEMP(K) = 298.54 PRESS = 89.4 > Etot = -134965.2123 EKtot = 41282.1781 EPtot = -176247.3905 > BOND = 1771.7644 ANGLE = 6893.3003 DIHED = 4660.1650 > 1-4 NB = 1931.6071 1-4 EEL = 7799.8343 VDWAALS = 19047.1551 > EELEC = -218354.9960 EHBOND = 0.0000 RESTRAINT = 3.7793 > EAMBER (non-restraint) = -176251.1698 > EKCMT = 16048.2253 VIRIAL = 14755.8154 VOLUME = 669299.5681 > Density = 0.9896 > Ewald error estimate: 0.8252E-05 > > > > (in attachment what surely is a correct reproduction of columns) > > I would like to extract values corresponding to variable DIHED (here > 4660.1650) and getting also the mean value from all DIHED. > > Thanks for giving a possible attack > > francesco pietra > If this format is fixed... vals = [ float(l.split('=')[-1].strip()) for l in file('file.txt','r') if ' DIHED ' in l ] mean = sum(vals) / len(vals) print vals print mean Glauco From sjmachin at lexicon.net Tue Jun 9 03:50:06 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 9 Jun 2009 07:50:06 +0000 (UTC) Subject: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen microcorp.co.za> writes: > > One can go from lb = ['b','a','n','a','n','a'] > to s = "banana" by using s = "".join(lb) > > Is there a way to go the reverse route? | >>> list('Hendrik') ['H', 'e', 'n', 'd', 'r', 'i', 'k'] Bonus extras: try tuple() and set() > I have not been able to find one. > > It is obviously easy to write a for char in s loop > or list comprehension, Aha! try a functional equivalent of a list comp: | >>> map(None, 'Hendrik') ['H', 'e', 'n', 'd', 'r', 'i', 'k'] > using lb = s.split("") would have been nice > as a complement to s = "".join(lb). object_of_type_X(something) is nicer IMHO. > Split is already full of magic, it could do with more. Both str.split and re.split are /too/ full of magic IMHO. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 9 04:02:33 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 08:02:33 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote: > Use a list when the semantic meaning of an item doesn't depend on all > the other items: it's ?only? a collection of values. > > Your list of message codes is a good example: if a value appears at > index 3, that doesn't make it mean something different from the same > value appearing at index 2. That advice would seem to imply that lists shouldn't be ordered. If a list of values has an order, it implies that "first place" (index 0) is different from "second place", by virtue of the positions they appear in the list. The lists: presidential_candidates_sorted_by_votes = ['Obama', 'McCain'] presidential_candidates_sorted_by_votes = ['McCain', 'Obama'] have very different meanings. Prohibiting the use of lists in the context of ordered data is surely is an unfortunate consequence of your advice. > James Tauber explains this at > python_tuples_are_not_just_constant_lists/>. He doesn't really explain anything though, he merely states it as revealed wisdom. The closest he comes to an explanation is to declare that in tuples "the index in a tuple has an implied semantic. The point of a tuple is that the i-th slot means something specific. In other words, it's a index-based (rather than name based) datastructure." But he gives no reason for why we should accept that as true for tuples but not lists. It may be that that's precisely the motivation Guido had when he introduced tuples into Python, but why should we not overload tuples with more meanings than Guido (hypothetically) imagined? In other words, why *shouldn't* we treat tuples as immutable lists, if that helps us solve a problem effectively? To put it another way, I think the question of whether or not tuples are immutable lists has the answer Mu. Sometimes they are, sometimes they're not. I have no problem with the title of the quoted blog post -- that tuples are not *just* constant lists -- but I do dispute that there is any reason for declaring that tuples must not be used as constant lists. As tuples are defined in Python, they quack like immutable lists, they walk like immutable lists, and they swim like immutable lists. Why shouldn't we treat them as immutable lists? Phillip Eby states that "Lists are intended to be homogeneous sequences, while tuples are heterogeneous data structures." (Notice the subtle shift there: lists are "intended", while tuples "are". But in fact, there's nothing to stop you from putting homogeneous data into a tuple, so Eby is wrong to say that tuples *are* heterogeneous.) Perhaps Eby intends lists to be homogeneous, perhaps Guido does too, but this is Python, where we vigorously defend the right to shoot ourselves in the foot. We strongly discourage class creators from trying to enforce their intentions by using private attributes, and even when we allow such a thing, the nature of Python is that nothing is truly private. Why should homogeneity and heterogeneity of lists and tuples be sacrosanct? Nothing stops me from putting hetereogeneous data into a list, or homogeneous data into a tuple, and there doesn't appear to be any ill- effects from doing so. Why give lose sleep over the alleged lack of purity? -- Steven From piet at cs.uu.nl Tue Jun 9 04:36:02 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 10:36:02 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> Message-ID: >>>>> "Enrico" <4564 at 755189.45> (E) wrote: >E> "lczancanella" ha scritto nel messaggio >E> news:32bf5ccb-5bfd-49a5-b423-9d41180a0ddb at l28g2000vba.googlegroups.com... >>> Hi, i am brand new in Python, so sorry if this question is too basic, >>> but i have tried a lot and dont have success... I have the following >>> code... >>> >>> class Funcoes: >>> def CifradorDeCesar(mensagem, chave, funcao): >E> A quick look to your code suggests to me to rewrite the above lines as: >E> class Funcoes: >E> @classmethod >E> def CifradorDeCesar(self, mensagem, chave, funcao): >E> @classmethod is needed since you call: >>> atribdescripto = Funcoes.CifradorDeCesar (atribcripto, >E> 3, 2) The method doesn't need the class at all, so a staticmethod would be preferable: class Funcoes: @staticmethod def CifradorDeCesar(self, mensagem, chave, funcao): But as been mentioned in this thread before, there might be no reason to use the class anyway. The next thing you will run into is that you call CifradorDeCesar with an int as parameter (mensagem) but it expects a string (or byte string, at least something iterable). -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From alia_khouri at yahoo.com Tue Jun 9 04:47:52 2009 From: alia_khouri at yahoo.com (Alia K) Date: Tue, 9 Jun 2009 01:47:52 -0700 (PDT) Subject: python version in snow leopard? References: <998336ef-1156-4493-a2c4-0cddb648fe19@f19g2000yqo.googlegroups.com> Message-ID: Mark Dickinson wrote: > The python-dev thread starting at > > http://mail.python.org/pipermail/python-3000/2008-September/014816.html > > suggests that back in September 2008, there was a 'MajorOS Vendor > (tm)' > who was interested in getting Python 2.6 into their next OS release, > provided that it (Python 2.6) was released by October 1st. > > Make of that what you will. Thanks for the response/link. Looks like it will be 2.6 then, but I'd even be happy with 2.5.4 (-: AK From jeanmichel at sequans.com Tue Jun 9 04:49:25 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Jun 2009 10:49:25 +0200 Subject: Start the interactive shell within an application Message-ID: <4A2E2215.1090405@sequans.com> I was wondering if there is a way to start an interactive shell within a script/application. I'm sometimes tired of adding prints to scan the current namespace so I'd like to pause the execution and give the user the shell prompt. This is obviously for debugging purpose. I know that I may use the raw_input and eval the captured text but honestly, this requires some coding and I won't benefit from the shell features. Would it be even possible to use a shell like Ipython ? By the way, if anyone has cunning ways for debugging code to share, he would be much welcome. Jean-Michel From eglyph at gmail.com Tue Jun 9 05:22:50 2009 From: eglyph at gmail.com (eGlyph) Date: Tue, 9 Jun 2009 02:22:50 -0700 (PDT) Subject: Start the interactive shell within an application References: Message-ID: On Jun 9, 11:49?am, Jean-Michel Pichavant wrote: > I'm sometimes tired of adding prints to scan the current namespace so > I'd like to pause the execution and give the user the shell prompt. > This is obviously for debugging purpose. This is definitely doable, have look at rhythmbox or gedit - they provide an interactive console. Also, have a look at IPython, they have a recipe and an example of embedding IPython into a user's application. From javier.collado at gmail.com Tue Jun 9 05:29:45 2009 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 9 Jun 2009 11:29:45 +0200 Subject: Start the interactive shell within an application In-Reply-To: References: Message-ID: Take a look either at code.interact or at IPython.ipapi.launch_new_instance. Basically, the only thing that you have to provide is a dictionary object that contains the namespace that you would like to have in your shell once it's launched. Best regards, Javier 2009/6/9 eGlyph : > On Jun 9, 11:49?am, Jean-Michel Pichavant > wrote: >> I'm sometimes tired of adding prints to scan the current namespace so >> I'd like to pause the execution and give the user the shell prompt. >> This is obviously for debugging purpose. > > This is definitely doable, have look at rhythmbox or gedit - they > provide an interactive console. > Also, have a look at IPython, they have a recipe and an example of > embedding IPython into a user's application. > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at microcorp.co.za Tue Jun 9 05:32:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:32:10 +0200 Subject: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: <005301c9e8e7$af006d60$0d00a8c0@Hendrik> jon vs. python wrote: >Sorry, I didn't realize that you already proposed list comprehension. > > >There is some kind of asymmetry in several areas.I guess that's somehow related to this post: >http://www.zedshaw.com/blog/2009-05-29.html Thanks for the link - I am not quite as rabid, but it would be nice. - Hendrik From mail at microcorp.co.za Tue Jun 9 05:42:27 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:42:27 +0200 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> "Chris Rebert" wrote: > lb = list("banana") Aaargh! I should have known - you use a string method to get a list of words, but you have to go to the list to get a list of characters from a string. There is no string method to do it, which is what I am complaining about. Is there a reason for this, or is the lack of symmetry just an historical artefact? The link that jon vs python supplied is interesting. - Hendrik From mail at microcorp.co.za Tue Jun 9 05:47:53 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 9 Jun 2009 11:47:53 +0200 Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <005501c9e8e7$b24dc3a0$0d00a8c0@Hendrik> "Diez B. Roggisch" wrote: > > I think > > lb = list(s) > > is good enough. It does the job, of course, but it is not a string method. - Hendrik From clp2 at rebertia.com Tue Jun 9 06:02:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 03:02:43 -0700 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: <50697b2c0906090302n74d4a762u77315e721bbc02fb@mail.gmail.com> On Tue, Jun 9, 2009 at 2:42 AM, Hendrik van Rooyen wrote: > "Chris Rebert" wrote: > >> lb = list("banana") > > Aaargh! > > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. > There is no string method to do it, which is what I am complaining > about. > > Is there a reason for this, or is the lack of symmetry just an historical > artefact? I think most would agree that having join() be a method of `str` rather than `list` can be understandably confusing to newbies, so the apparent asymmetry lies on the other side of the list-str boundary (i.e. why don't I use a list method to convert a list of strings to a string?). The reason join() is a method of `str` is so that it doesn't have to be reimplemented for every container type (e.g. tuple, set, list, user-defined containers, etc). You can look at it the same way for why a `str` method isn't used to produce a list of characters -- what would you do for every other container type (i.e. what if I want a set of the characters in a string)? Having the container type rather than the string take care of it solves this problem. Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 9 06:05:14 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Jun 2009 12:05:14 +0200 Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <796q93F1p879rU1@mid.uni-berlin.de> Hendrik van Rooyen wrote: > "Diez B. Roggisch" wrote: > >> >> I think >> >> lb = list(s) >> >> is good enough. > > It does the job, of course, but it is not a string method. And that is a bad thing because of what? Also as list-comps are going away and are replaced by list() I'd say it's much more consistent when faced with the task of creating a list of anything that's iterable one uses the list() idiom. Diez From marco at sferacarta.com Tue Jun 9 06:06:12 2009 From: marco at sferacarta.com (Marco Mariani) Date: Tue, 09 Jun 2009 12:06:12 +0200 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> Message-ID: Hendrik van Rooyen wrote: >> lb = list("banana") > > Aaargh! > > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. As they say, "Python is not Java". Strings support the sequence protocol (aka interface), hence they can be given as input to the list constructor. It would not make much sense to add methods (to the N concrete implementations, mind you) that replicate functionality available by the builtin constructors through implicit interfaces. Would you also ask for '43'.as_int() or stuff like that? From naruvimama at gmail.com Tue Jun 9 06:40:02 2009 From: naruvimama at gmail.com (Chandramouli) Date: Tue, 9 Jun 2009 03:40:02 -0700 (PDT) Subject: using libraries not installed on campus computers (numpy) Message-ID: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> I built and installed Numpy on my campus account, the install couldn't be done on the python install location. So I did it on my local storage location but I am clueless about how to use it I was expecting to see a numpy.py in the install dir so I could I suppose just give import numpy and expect it to work like normal but I am not sure how this works From cournape at gmail.com Tue Jun 9 07:29:52 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 9 Jun 2009 20:29:52 +0900 Subject: using libraries not installed on campus computers (numpy) In-Reply-To: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> References: <987cc0cb-a32a-464c-abb0-95e09b6151b5@r34g2000vba.googlegroups.com> Message-ID: <5b8d13220906090429q6e17147w99009c9cb9023f6c@mail.gmail.com> On Tue, Jun 9, 2009 at 7:40 PM, Chandramouli wrote: > I built and installed Numpy on my campus account, the install couldn't > be done on the python install location. So I did it on my local > storage location but I am clueless about how to use it I was expecting > to see a numpy.py in the install dir > so I could I suppose just give > import numpy > > and expect it to work like normal but I am not sure how this works python expects to find modules (such as numpy) into a list of directories, some of which are hardcoded at installation time for python. You can prepend a directory (or a set of directories) using the PYTHONPATH environment variable. For example, installing numpy insto $HOME/local: python setup.py install --prefix=$HOME/local numpy will be installed in $HOME/local/lib/python2.5/site-packages (for python 2.5), and you should set your PYTHONPATH to $HOME/local/lib/python2.5/site-packages for python to find it: PYTHONPATH=$HOME/local/lib/python2.5/site-packages:$PYTHONPATH python -c "import numpy" David From samwyse at gmail.com Tue Jun 9 07:47:16 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 04:47:16 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <932aa351-a531-49db-904c-22593563b293@r16g2000vbn.googlegroups.com> On Jun 8, 10:06?pm, Chris Rebert wrote: > On Mon, Jun 8, 2009 at 6:57 PM, samwyse wrote: > > On Jun 8, 7:37?pm, Carl Banks wrote: > >> On Jun 8, 4:43?pm, Ben Finney wrote: > >> > m... at pixar.com writes: > >> > > Is there any reason to prefer one or the other of these statements? > > >> > > ? ? ? ? if e.message.code in [25401,25402,25408]: > >> > > ? ? ? ? if e.message.code in (25401,25402,25408): > > >> If you want to go strictly by the book, I would say he ought to be > >> using a set since his collection of numbers has no meaningful order > >> nor does it make sense to list any item twice. > > > As the length of the list increases, the increased speeds of looking > > something up makes using a set makes more sense. ?But what's the best > > way to express this? ?Here are a few more comparisons (using Python > > 3.0)... > > >>>> S=lambda x:x in set((25401,25402,25408)) > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_GLOBAL ? ? ? ? ? ? ?0 (set) > > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > > ? ? ? ? ? ? ?9 CALL_FUNCTION ? ? ? ? ? ?1 > > ? ? ? ? ? ? 12 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 15 RETURN_VALUE > >>>> S=lambda x:x in{25401,25402,25408} > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 0 (25401) > > ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 1 (25402) > > ? ? ? ? ? ? ?9 LOAD_CONST ? ? ? ? ? ? ? 2 (25408) > > ? ? ? ? ? ? 12 BUILD_SET ? ? ? ? ? ? ? ?3 > > ? ? ? ? ? ? 15 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 18 RETURN_VALUE > >>>> S=lambda x:x in{(25401,25402,25408)} > >>>> dis(S) > > ?1 ? ? ? ? ? 0 LOAD_FAST ? ? ? ? ? ? ? ?0 (x) > > ? ? ? ? ? ? ?3 LOAD_CONST ? ? ? ? ? ? ? 3 ((25401, 25402, 25408)) > > ? ? ? ? ? ? ?6 BUILD_SET ? ? ? ? ? ? ? ?1 > > ? ? ? ? ? ? ?9 COMPARE_OP ? ? ? ? ? ? ? 6 (in) > > ? ? ? ? ? ? 12 RETURN_VALUE > > > I conclude that using constructors is generally a bad idea, since the > > compiler doesn't know if you're calling the builtin or something with > > an overloaded name. ?I presume that the compiler will eventually > > optimize the second example to match the last, but both of them use > > the BUILD_SET opcode. ?I expect that this can be expensive for long > > Erm, unless I misunderstand you somehow, the second example will and > should *never* match the last. > The set {25401,25402,25408}, containing 3 integer elements, is quite > distinct from the set {(25401,25402,25408)}, containing one element > and that element is a tuple. > set(X) != {X}; set([X]) = {X} D'oh! I was thinking about how you can initialize a set from an iterator and for some reason thought that you could do the same with a set constant. From samwyse at gmail.com Tue Jun 9 07:57:48 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 04:57:48 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> Message-ID: <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> On Jun 8, 8:57?pm, samwyse wrote: > I conclude that using constructors is generally a bad idea, since the > compiler doesn't know if you're calling the builtin or something with > an overloaded name. ?I presume that the compiler will eventually > optimize the second example to match the last, but both of them use > the BUILD_SET opcode. ?I expect that this can be expensive for long > lists, so I don't think that it's a good idea to use set constants > inside loops. ?Instead it should be assigned to a global or class > variable. Time to test things! I'm going to compare three things using Python 3.0: X={...}\nS=lambda x: x in X S=lambda x: x in {...} S=lambda x: x in (...) where the ... is replaced by lists of integers of various lengths. Here's the test bed: from random import seed, sample from timeit import Timer maxint = 2**31-1 values = list(map(lambda n: 2**n-1, range(1,16))) def append_numbers(k, setup): seed(1968740928) for i in sample(range(maxint), k): setup.append(str(i)) setup.append(',') print('==', 'separate set constant') for n in values[::2]: print('===', n, 'values') setup = ['X={'] append_numbers(n, setup) setup.append('}\nS=lambda x: x in X') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) print('==', 'in-line set constant') for n in values[:4]: print('===', n, 'values') setup = ['S=lambda x: x in {'] append_numbers(n, setup) setup.append('}') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) print('==', 'in-line list constant') for n in values: print('===', n, 'values') setup = ['S=lambda x: x in ('] append_numbers(n, setup) setup.append(')') t = Timer('S(88632719)', ''.join(setup)) print(t.repeat()) And here are the results. There's something interesting at the very end. == separate set constant === 1 values [0.26937306277753176, 0.26113626173158877, 0.26000092190487889] === 7 values [0.26583266867716426, 0.27223543774418268, 0.27681646689732919] === 31 values [0.25089725090758752, 0.25562690230182894, 0.25844625504079444] === 127 values [0.32404313956103392, 0.33048948958596691, 0.34487930728626104] === 511 values [0.27574566041214732, 0.26991838348169983, 0.28309016928129083] === 2047 values [0.27826162263639631, 0.27337357122204065, 0.26888752620793976] === 8191 values [0.27479134917985437, 0.27955955295994261, 0.27740676538498654] === 32767 values [0.26189725230441319, 0.25949247739587022, 0.2537356004743625] == in-line set constant === 1 values [0.43579086168772818, 0.4231755711968983, 0.42178740594125852] === 3 values [0.54712875519095228, 0.55325048295244272, 0.54346991028189251] === 7 values [1.1897654590178366, 1.1763383335032813, 1.2009900699669931] === 15 values [1.7661906750718313, 1.7585005915556291, 1.7405896559478933] == in-line list constant === 1 values [0.23651385860493335, 0.24746972031361381, 0.23778469051234197] === 3 values [0.23710750947396875, 0.23205630883254713, 0.23345592805789295] === 7 values [0.24607764394636789, 0.23551903943099006, 0.24241377046524093] === 15 values [0.2279376289444599, 0.22491908887861456, 0.24076747184349045] === 31 values [0.22860084172708994, 0.233022074034551, 0.23138639128715965] === 63 values [0.23671639831319169, 0.23404259479906031, 0.22269394573891077] === 127 values [0.22754176857673158, 0.22818151468971593, 0.22711154629987718] === 255 values [0.23503126794047802, 0.24493699618247788, 0.26690207833677349] === 511 values [0.24518255811842238, 0.23878118587697728, 0.22844830837438934] === 1023 values [0.23285585179122137, 0.24067220833932623, 0.23807439213642922] === 2047 values [0.24206484343680756, 0.24352201187581102, 0.24366253252857462] === 4095 values [0.24624526301527183, 0.23692145230748807, 0.23829956041899081] === 8191 values [0.22246514570986164, 0.22435309515595137, 0.22220114567633331] === 16383 values [194.29462683106374, 193.21789529116128, 193.25843228678508] === 32767 values You will note that testing against a list constant is just as fast as testing against a set. This was surprising for me; apparently the __contains__ operator turns a tuple into a set. You will also note that performance to fall off drastically for the last set of values. I'm not sure what happens there; I guess I'll file a bug report. From brendandetracey at yahoo.com Tue Jun 9 08:38:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:38:46 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: <98d95066-48c4-41c1-ac6e-9d78c1fcd3a0@f16g2000vbf.googlegroups.com> I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought From brendandetracey at yahoo.com Tue Jun 9 08:38:46 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:38:46 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: <05102193-3c85-4fc6-83ee-9f4b1a32cd26@o20g2000vbh.googlegroups.com> I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought From brendandetracey at yahoo.com Tue Jun 9 08:54:15 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 05:54:15 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling Message-ID: I was hoping to use pywin32 to automate some rather tedious filling in of Word forms. I thought the process would be analogous to dealing with xml documents or DOM but find myself somewhat lost in the word object reference manual (http://msdn.microsoft.com/en-us/library/ bb244515.aspx) . I was hoping to easily load all document objects into a list so that I could poke around, examine and experiment with them. So far all I have managed to do is load the page content as a string, not particularly helpful. Could someone please point me in the right direction? Also, help, __doc__ and dir do not return anything meaningful(to me anyway) or helpful. There seem to be no exposed methods or properties. e.g. I have a word document object: wd = wordapp.Documents.Open('blah.dic') But: >>> dir(wd) ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__', '__getattr__', '__getitem__', '__init__', '__int__', '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__', '__setitem__', '__str__', '_builtMethods_', '_enum_', '_find_dispatch_type_', '_get_good_object_', '_get_good_single_object_', '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] And: >>> print wd.__doc__ The dynamic class used as a last resort. The purpose of this overriding of dynamic.CDispatch is to perpetuate the policy of using the makepy generated wrapper Python class instead of dynamic.CDispatch if/when possible. Furthermore: >>> help(wd) Help on instance of CDispatch in module win32com.client object: class instance(object) | instance(class[, dict]) | | Create an instance without calling its __init__() method. | The class must be a classic class. | If present, dict must be a dictionary or None. | | Methods defined here: | | __abs__(...) | x.__abs__() <==> abs(x) ~ ~ snip ~ ~ | __truediv__(...) | x.__truediv__(y) <==> x/y | | __xor__(...) | x.__xor__(y) <==> x^y | | next(...) | x.next() -> the next value, or raise StopIteration | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T What gives? From ben+python at benfinney.id.au Tue Jun 9 08:56:17 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Jun 2009 22:56:17 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: <8763f5d0r2.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote: > > > Use a list when the semantic meaning of an item doesn't depend on > > all the other items: it's ?only? a collection of values. > > > > Your list of message codes is a good example: if a value appears at > > index 3, that doesn't make it mean something different from the same > > value appearing at index 2. > > That advice would seem to imply that lists shouldn't be ordered. No such implication. Order is important in a list, it just doesn't change the semantic meaning of the value. > If a list of values has an order, it implies that "first place" (index > 0) is different from "second place", by virtue of the positions they > appear in the list. The lists: > > presidential_candidates_sorted_by_votes = ['Obama', 'McCain'] > presidential_candidates_sorted_by_votes = ['McCain', 'Obama'] > > have very different meanings. But the semantic meaning if each value is unchanged: each is still a presidential candidate's surname. The additional semantic meaning of putting it in a list is no more than the position in the sequence. A list is the right choice, for that reason. Whereas, for example, in this tuple: dodge_city = (1781, 1870, 1823) (population, feet_above_sea_level, establishment_year) = dodge_city each index in the sequence implies something very different about each value. The semantic meaning of each index is *more* than just the position in the sequence; it matters *for interpreting that component*, and that component would not mean the same thing in a different index position. A tuple is the right choice, for that reason. -- \ ?Are you pondering what I'm pondering?? ?Umm, I think so, Don | `\ Cerebro, but, umm, why would Sophia Loren do a musical?? | _o__) ?_Pinky and The Brain_ | Ben Finney From 4564 at 755189.45 Tue Jun 9 10:16:06 2009 From: 4564 at 755189.45 (Enrico) Date: Tue, 9 Jun 2009 16:16:06 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> Message-ID: <4a2e6edd$0$1114$4fafbaef@reader4.news.tin.it> "Piet van Oostrum" ha scritto nel messaggio news:m2ljo1ajnx.fsf at cs.uu.nl... > The method doesn't need the class at all, so a staticmethod would be > preferable: > class Funcoes: > @staticmethod > def CifradorDeCesar(self, mensagem, chave, funcao): Yes, in this case self is not needed. > > But as been mentioned in this thread before, there might be no reason to > use the class anyway. I agree but the code is not very clear about the use of this class as ancestor of MC. >>class MC(Funcoes, type): ? Enrico From brendandetracey at yahoo.com Tue Jun 9 11:17:15 2009 From: brendandetracey at yahoo.com (Brendan) Date: Tue, 9 Jun 2009 08:17:15 -0700 (PDT) Subject: pywin32 - word object reference module - automating form filling References: Message-ID: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> On Jun 9, 9:54?am, Brendan wrote: > I was hoping to use pywin32 to automate some rather tedious filling in > of Word forms. I thought the process would be analogous to dealing > with xml documents or DOM but find myself somewhat lost in the word > object reference manual (http://msdn.microsoft.com/en-us/library/ > bb244515.aspx) . ?I was hoping to easily load all document objects > into a list so that I could poke around, examine and experiment with > them. So far all I have managed to do is load the page content as a > string, not particularly helpful. > > Could someone please point me in the right direction? > > Also, help, __doc__ and dir do not return anything meaningful(to me > anyway) or helpful. There seem to be no exposed methods or properties. > e.g. I have a word document object: > wd = wordapp.Documents.Open('blah.dic') > But:>>> dir(wd) > > ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', > '_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__', > '__doc__', '__getattr__', '__getitem__', '__init__', '__int__', > '__len__', '__module__', '__nonzero__', '__repr__', '__setattr__', > '__setitem__', '__str__', '_builtMethods_', '_enum_', > '_find_dispatch_type_', '_get_good_object_', > '_get_good_single_object_', '_lazydata_', '_make_method_', > '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_', > '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_'] > > And: > > >>> print wd.__doc__ > > ? ? The dynamic class used as a last resort. > ? ? The purpose of this overriding of dynamic.CDispatch is to > perpetuate the policy > ? ? of using the makepy generated wrapper Python class instead of > dynamic.CDispatch > ? ? if/when possible. > > Furthermore:>>> help(wd) > > Help on instance of CDispatch in module win32com.client object: > > class instance(object) > ?| ?instance(class[, dict]) > ?| > ?| ?Create an instance without calling its __init__() method. > ?| ?The class must be a classic class. > ?| ?If present, dict must be a dictionary or None. > ?| > ?| ?Methods defined here: > ?| > ?| ?__abs__(...) > ?| ? ? ?x.__abs__() <==> abs(x) > > ~ ~ snip ~ ~ > > | ?__truediv__(...) > ?| ? ? ?x.__truediv__(y) <==> x/y > ?| > ?| ?__xor__(...) > ?| ? ? ?x.__xor__(y) <==> x^y > ?| > ?| ?next(...) > ?| ? ? ?x.next() -> the next value, or raise StopIteration > ?| > ?| > ---------------------------------------------------------------------- > ?| ?Data and other attributes defined here: > ?| > ?| ?__new__ = > ?| ? ? ?T.__new__(S, ...) -> a new object with type S, a subtype of T > > What gives? Hmmm. The VB examples in the Word Object Reference give the best idea of how to play with Word documents. No further help required on this although I am still curious about why the python does not return the "real" objects and methods for the COM object. From Scott.Daniels at Acm.Org Tue Jun 9 11:19:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 09 Jun 2009 08:19:13 -0700 Subject: Unbound Method Error In-Reply-To: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: lczancanella wrote: > Hi, i am brand new in Python, so sorry if this question is too basic, > but i have tried a lot and dont have success... I have the following > code... > > class Funcoes: > def CifradorDeCesar(mensagem, chave, funcao): > ... > You've gotten some "interesting" advice. You want one of: class Funcoes: @staticmethod def CifradorDeCesar(mensagem, chave, funcao): ... or: class Funcoes: def CifradorDeCesar(self, mensagem, chave, funcao): ... or: class Funcoes: @class_method def CifradorDeCesar(class_, mensagem, chave, funcao): ... --Scott David Daniels Scott.Daniels at Acm.Org From samwyse at gmail.com Tue Jun 9 11:20:04 2009 From: samwyse at gmail.com (samwyse) Date: Tue, 9 Jun 2009 08:20:04 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> Message-ID: <508492d1-7268-417f-bfbc-ecc464bf080c@f16g2000vbf.googlegroups.com> On Jun 9, 12:30?am, Emile van Sebille wrote: > On 6/8/2009 8:43 PM Ben Finney said... > > The fact that literal set syntax is a relative newcomer is the primary > > reason for that, I'd wager. > > Well, no. ?It really is more, "that's odd... why use set?" Until I ran some timing tests this morning, I'd have said that sets could determine membership faster than a list, but that's apparently not true, assuming that the list has less than 8K members. Above 16K members, sets are much faster than lists. I'm not sure where the break is, or even why there's a break. From mail at timgolden.me.uk Tue Jun 9 11:24:52 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Jun 2009 16:24:52 +0100 Subject: pywin32 - word object reference module - automating form filling In-Reply-To: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> References: <698da9c7-c6f9-4d0c-8510-e3a293bf5b37@n4g2000vba.googlegroups.com> Message-ID: <4A2E7EC4.1000007@timgolden.me.uk> Brendan wrote: > Hmmm. The VB examples in the Word Object Reference give the best idea > of how to play with Word documents. No further help required on this > although I am still curious about why the python does not return the > "real" objects and methods for the COM object. Try doing it this way: import win32com.client word = win32com.client.gencache.EnsureDispatch ("Word.Application") help (word) doc = win32com.client.gencache.EnsureDispatch (word.Documents.Add ()) help (doc) or just run the makepy util first. TJG From pavlovevidence at gmail.com Tue Jun 9 11:37:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 08:37:33 -0700 (PDT) Subject: Function/method returning list of chars in string? References: <796hh2F1p7fpkU1@mid.uni-berlin.de> Message-ID: <9f6beb7a-c7bd-461f-877e-82e335dfdf06@z7g2000vbh.googlegroups.com> On Jun 9, 2:47?am, "Hendrik van Rooyen" wrote: > "Diez B. Roggisch" wrote: > > > I think > > > lb = list(s) > > > is good enough. > > It does the job, of course, but it is not a string method. A. Your post's subject included the words "function/method" B. Who cares Carl Banks From redplusbluemakespurple at gmail.com Tue Jun 9 11:38:34 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Tue, 9 Jun 2009 08:38:34 -0700 (PDT) Subject: List comprehension and string conversion with formatting Message-ID: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> I'd like to convert a list of floats to a list of strings constrained to one .1f format. These don't work. Is there a better way? [".1f" % i for i in l] or [(".1f" % i) for i in l] StephenB From bcharrow at csail.mit.edu Tue Jun 9 11:40:49 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Tue, 09 Jun 2009 11:40:49 -0400 Subject: Start the interactive shell within an application In-Reply-To: References: Message-ID: <4A2E8281.6000305@csail.mit.edu> If you're looking to debug your program, try "import pdb" and then wherever you want to debug put: pdb.set_trace() Your program will then enter the debugger when it executes that line. It's quite nice really. If you get confused on what to do, just type "help" http://docs.python.org/library/pdb.html Cheers, Ben Javier Collado wrote: > Take a look either at code.interact or at > IPython.ipapi.launch_new_instance. Basically, the only thing that you > have to provide is a dictionary object that contains the namespace > that you would like to have in your shell once it's launched. > > Best regards, > Javier > > 2009/6/9 eGlyph : >> On Jun 9, 11:49 am, Jean-Michel Pichavant >> wrote: >>> I'm sometimes tired of adding prints to scan the current namespace so >>> I'd like to pause the execution and give the user the shell prompt. >>> This is obviously for debugging purpose. >> This is definitely doable, have look at rhythmbox or gedit - they >> provide an interactive console. >> Also, have a look at IPython, they have a recipe and an example of >> embedding IPython into a user's application. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> From pavlovevidence at gmail.com Tue Jun 9 11:43:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 08:43:12 -0700 (PDT) Subject: List comprehension and string conversion with formatting References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> Message-ID: <8e203cda-f3e7-41d5-aaff-5fb5fd3dcb39@l28g2000vba.googlegroups.com> On Jun 9, 8:38?am, stephen_b wrote: > I'd like to convert a list of floats to a list of strings constrained > to one .1f format. These don't work. Is there a better way? > > [".1f" % i for i in l] > or > [(".1f" % i) for i in l] You need a % in there, chief. [ "%.1f" % x for x in lst ] BTW, I took the liberty of making a few style choices, highly recommended: not to use "i" for floating points ("i" strongly suggests integer value to many programmers), and not using "l" (the letter ell) as a name, it can be hard to distinguish from a "1" (the number one). Carl Banks From jaime.frio at gmail.com Tue Jun 9 11:48:55 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Tue, 9 Jun 2009 17:48:55 +0200 Subject: List comprehension and string conversion with formatting In-Reply-To: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> Message-ID: <97a8f1a70906090848x5458cd0dn50492fe61ba292bc@mail.gmail.com> On Tue, Jun 9, 2009 at 5:38 PM, stephen_b wrote: > I'd like to convert a list of floats to a list of strings constrained > to one .1f format. These don't work. Is there a better way? > > [".1f" % i for i in l] > or > [(".1f" % i) for i in l] There's a missing %, this does work... ["%.1f" % i for i in l] Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From redplusbluemakespurple at gmail.com Tue Jun 9 11:51:18 2009 From: redplusbluemakespurple at gmail.com (stephen_b) Date: Tue, 9 Jun 2009 08:51:18 -0700 (PDT) Subject: List comprehension and string conversion with formatting References: <24cb94ed-b887-451c-98d2-2ec692b67e23@q37g2000vbi.googlegroups.com> <8e203cda-f3e7-41d5-aaff-5fb5fd3dcb39@l28g2000vba.googlegroups.com> Message-ID: <5df04182-d24d-4457-adc7-f0bf4f296c68@21g2000vbk.googlegroups.com> On Jun 9, 10:43?am, Carl Banks wrote: > You need a % in there, chief. > > Carl Banks You are so right. Thanks. From Krzysztof.Retel at googlemail.com Tue Jun 9 11:57:00 2009 From: Krzysztof.Retel at googlemail.com (kretel) Date: Tue, 9 Jun 2009 08:57:00 -0700 (PDT) Subject: Using logging module to log into flash drive Message-ID: Hi All, I am trying to implement the following functionality: 1. log messages to the flash drive 2. if the flash drive is not available, switch handler to the BufferringHandler and log into buffer, 3. once the flash drive is plugged in and available store the logs from BufferHandler into that flash drive and switch the handler into RotateFileHandler. Which approach would you suggest to use while implementing this functionality? One that come into my mind is to have one process or thread to check periodically if the flashdrive is available, and have a flag that will indicate that we can store the logs into the flash drive. But I don't particularly like this approach. Would you do it different way? Any suggestions are appreciated. Cheers, Krzysztof From pavlovevidence at gmail.com Tue Jun 9 12:16:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 09:16:33 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> Message-ID: <4d4f86e5-8a73-4f72-a38c-77be250d15b6@p4g2000vba.googlegroups.com> On Jun 9, 4:57?am, samwyse wrote: > On Jun 8, 8:57?pm, samwyse wrote: > > > I conclude that using constructors is generally a bad idea, since the > > compiler doesn't know if you're calling the builtin or something with > > an overloaded name. ?I presume that the compiler will eventually > > optimize the second example to match the last, but both of them use > > the BUILD_SET opcode. ?I expect that this can be expensive for long > > lists, so I don't think that it's a good idea to use set constants > > inside loops. ?Instead it should be assigned to a global or class > > variable. > > Time to test things! ? I'm going to compare three things using Python > 3.0: > ? X={...}\nS=lambda x: x in X > ? S=lambda x: x in {...} > ? S=lambda x: x in (...) > where the ... is replaced by lists of integers of various lengths. > Here's the test bed: > > from random import seed, sample > from timeit import Timer > maxint = 2**31-1 > values = list(map(lambda n: 2**n-1, range(1,16))) > def append_numbers(k, setup): > ? ? seed(1968740928) > ? ? for i in sample(range(maxint), k): > ? ? ? ? setup.append(str(i)) > ? ? ? ? setup.append(',') > print('==', 'separate set constant') > for n in values[::2]: > ? ? print('===', n, 'values') > ? ? setup = ['X={'] > ? ? append_numbers(n, setup) > ? ? setup.append('}\nS=lambda x: x in X') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) > print('==', 'in-line set constant') > for n in values[:4]: > ? ? print('===', n, 'values') > ? ? setup = ['S=lambda x: x in {'] > ? ? append_numbers(n, setup) > ? ? setup.append('}') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) > print('==', 'in-line list constant') > for n in values: > ? ? print('===', n, 'values') > ? ? setup = ['S=lambda x: x in ('] > ? ? append_numbers(n, setup) > ? ? setup.append(')') > ? ? t = Timer('S(88632719)', ''.join(setup)) > ? ? print(t.repeat()) It looks like you are evaluating the list/set/tuple every pass, and then, for lists and tuples, always indexing the first item. > And here are the results. ?There's something interesting at the very > end. [snip results showing virtually identical performance for list, set, and tuple] > You will note that testing against a list constant is just as fast as > testing against a set. ?This was surprising for me; apparently the > __contains__ operator turns a tuple into a set. Given the way you wrote the test it this is hardly surprising. I would expect "item in list" to have comparable execution time to "item in set" if item is always the first element in list. Furthermore, the Python compiler appears to be optimizing this specific case to always use a precompiled set. Well, almost always.... >?You will also note > that ?performance to fall off drastically for the last set of values. > I'm not sure what happens there; I guess I'll file a bug report. Please don't; it's not a bug. The slowdown is because at sizes above a certain threshold the Python compiler doesn't try to precompile in- line lists, sets, and tuples. The last case was above that limit. Carl Banks From pavlovevidence at gmail.com Tue Jun 9 12:21:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 09:21:25 -0700 (PDT) Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> <87ab4icbsj.fsf@benfinney.id.au> <508492d1-7268-417f-bfbc-ecc464bf080c@f16g2000vbf.googlegroups.com> Message-ID: <7c28e7cd-03d4-4591-99a4-02dd3322333f@o30g2000vbc.googlegroups.com> On Jun 9, 8:20?am, samwyse wrote: > On Jun 9, 12:30?am, Emile van Sebille wrote: > > > On 6/8/2009 8:43 PM Ben Finney said... > > > The fact that literal set syntax is a relative newcomer is the primary > > > reason for that, I'd wager. > > > Well, no. ?It really is more, "that's odd... why use set?" > > Until I ran some timing tests this morning, I'd have said that sets > could determine membership faster than a list, but that's apparently > not true, See my reply to that post. I believe your tests were flawed. > assuming that the list has less than 8K members. ?Above 16K > members, sets are much faster than lists. ?I'm not sure where the > break is, or even why there's a break. The break comes from the compiler, not the objects themselves. Carl Banks From David.Shapiro at sas.com Tue Jun 9 12:22:20 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Tue, 9 Jun 2009 12:22:20 -0400 Subject: python and getopt and spaces in option Message-ID: Hello, I have been trying to find an example of how to deal with options that have spaces in them. I am using jython, which is the same I think as python 2.2.3. I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). The code is as follows: try: (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) except getopt.GetoptError: usage() for opt in opts: (key, value) = opt if (key in ("-v", "--version")): print "Version: " + version sys.exit(1) if (key in ("-h", "--help")): usage() if (key in ("-s", "--server")): server = value if (key in ("-p", "--port")): port = value if (key in ("-n", "--dsName")): dsName = value if (key in ("-j", "--jndiName")): jndiName = value if (key in ("-d", "--driverName")): driverName = value if (key in ("-l", "--driverURL")): driverURL = value if (key in ("-u", "--user")): user = value if (key in ("-c", "--passWD")): passWD = value if (key in ("-t", "--targetServer")): targetServer = value if (key in ("-q", "--testTableName")): testTableName = value if (key in ("-w", "--whereProp")): whereProp = value print "server: " + server print "port: " + port print "dsName: " + dsName print "jndiName: " + jndiName print "driverName: " + driverName print "driverURL: " + driverURL print "user: " + user print "passWD: " + passWD print "testtable: " + testTableName print "targetServer: " + targetServer print "whereProp: " + whereProp The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get it to return the whole thing that is in double quotes? David From mh at pixar.com Tue Jun 9 12:40:42 2009 From: mh at pixar.com (mh at pixar.com) Date: Tue, 09 Jun 2009 16:40:42 GMT Subject: preferring [] or () in list of error codes? References: Message-ID: John Machin wrote: > T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) I've learned a lot from this thread, but this is the niftiest bit I've picked up... thanks! -- Mark Harrison Pixar Animation Studios From lie.1296 at gmail.com Tue Jun 9 12:41:26 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 09 Jun 2009 16:41:26 GMT Subject: multi-thread python interpreaters and c++ program In-Reply-To: References: Message-ID: myopc wrote: > hi, all > I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python > interpreaters, but it crashed. I have googled a lot but cant get any clue. > here is my code, your suggestion will be greatly appreciated. > There is no clean way to terminate a thread cleanly from outside. You need to let the thread terminates by itself. If it is a pure python code, this can be done by one of: 1) setting a global/thread stop value that is checked by each threads 2) inserting a QUIT event to the event-loop I have never used boost before, so I don't know what it can and cannot do from outside the python's interpreter. However, this should give you an idea of what to do... From a.cavallo at mailsnare.com Tue Jun 9 13:10:18 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Tue, 9 Jun 2009 18:10:18 +0100 Subject: Using logging module to log into flash drive In-Reply-To: References: Message-ID: <200906091810.19234.a.cavallo@mailsnare.com> Hi, the problem screams for a separate thread. Anyway there's a TimedRotatingFileHandler handler in the logging package: you can derive from it and change the emit/doRollover pair to hold the records until a device is not ready. Regards, Antonio On Tuesday 09 June 2009 16:57:00 kretel wrote: > Hi All, > > I am trying to implement the following functionality: > 1. log messages to the flash drive > 2. if the flash drive is not available, switch handler to the > BufferringHandler and log into buffer, > 3. once the flash drive is plugged in and available store the logs > from BufferHandler into that flash drive and switch the handler into > RotateFileHandler. > > Which approach would you suggest to use while implementing this > functionality? One that come into my mind is to have one process or > thread to check periodically if the flashdrive is available, and have > a flag that will indicate that we can store the logs into the flash > drive. But I don't particularly like this approach. > Would you do it different way? > Any suggestions are appreciated. > > Cheers, > Krzysztof From clp2 at rebertia.com Tue Jun 9 13:27:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Jun 2009 10:27:57 -0700 Subject: Unbound Method Error In-Reply-To: References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> Message-ID: <50697b2c0906091027l4c285971y90eb5e7ccc985f84@mail.gmail.com> On Tue, Jun 9, 2009 at 8:19 AM, Scott David Daniels wrote: > lczancanella wrote: >> >> Hi, i am brand new in Python, so sorry if this question is too basic, >> but i have tried a lot and dont have success... I have the following >> code... >> >> class Funcoes: >> ? ?def CifradorDeCesar(mensagem, chave, funcao): >> ? ? ? ?... >> > > You've gotten some "interesting" advice. > > You want one of: > > ? ?class Funcoes: > ? ? ? ?@staticmethod > ? ? ? ?def CifradorDeCesar(mensagem, chave, funcao): > ? ? ? ? ? ?... > or: > ? ?class Funcoes: > ? ? ? ?def CifradorDeCesar(self, mensagem, chave, funcao): > ? ? ? ? ? ?... > or: > ? ?class Funcoes: > ? ? ? ?@class_method There's no underscore in "classmethod" last time I checked. > ? ? ? ?def CifradorDeCesar(class_, mensagem, chave, funcao): > ? ? ? ? ? ?... You forgot one more option (the preferred one, IMHO): #module toplevel def CifradorDeCesar(mensagem, chave, funcao): Cheers, Chris -- http://blog.rebertia.com From Krzysztof.Retel at googlemail.com Tue Jun 9 13:37:48 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Tue, 9 Jun 2009 10:37:48 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: <70177935-7b83-4bde-9c89-db51f1690c4f@o36g2000vbi.googlegroups.com> On Jun 9, 6:10?pm, "A. Cavallo" wrote: > Hi, > the problem screams for a separate thread. I was thinking about that, as mentioned in the first post. Although, I was wonder if there is another way to tackle the problem. > Anyway there's a TimedRotatingFileHandler handler in the logging package: > you can derive from it and change the emit/doRollover pair to hold the records > until a device is not ready. Hm, that might be the way to go. Will have a try. If anyone has other thoughts, please share them. Thanks, Krzysztof From toby at telegraphics.com.au Tue Jun 9 13:47:11 2009 From: toby at telegraphics.com.au (toby) Date: Tue, 9 Jun 2009 10:47:11 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On Jun 7, 2:41?pm, Jon Harrop wrote: > Arved Sandstrom wrote: > > Jon Harrop wrote: > >> I see no problem with mutable shared state. > > > In which case, Jon, you're in a small minority. > > No. Most programmers still care about performance Frequently when they shouldn't. > and performance means > mutable state. Hm, not sure Erlangers would wholly agree. > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u From ebonak at hotmail.com Tue Jun 9 13:50:09 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 13:50:09 -0400 Subject: pylint naming conventions? In-Reply-To: References: <87skiekend.fsf@benfinney.id.au> <87my8je1bf.fsf@benfinney.id.au> <4A2CF6D3.5010400@hotmail.com> Message-ID: <4A2EA0D1.4050107@hotmail.com> R. David Murray wrote: > > Well, I for one looked at that long pylint output when I first tried it, > and switched to another tool :) > > (pyflakes...but I don't think it does PEP 8) :-) Ok, so I'm not the only one who thinks the output is rather lengthy. I've since dug into the docs and searched on the web and found that --reports=n on the command line will truncate the various tables output at the end. Esmail From ken at jots.org Tue Jun 9 13:52:46 2009 From: ken at jots.org (Ken D'Ambrosio) Date: Tue, 9 Jun 2009 13:52:46 -0400 (EDT) Subject: Unbuffered keyboard input? Message-ID: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> I need to have some non-buffered keyboard interaction with a Python script (on Linux). Back in the day, I fired up Curses to do this in Perl. Any idea if that's still how I have to fly? Or is there a different mechanism? Thanks! -Ken -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From piet at cs.uu.nl Tue Jun 9 14:05:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 09 Jun 2009 20:05:47 +0200 Subject: Unbound Method Error References: <32bf5ccb-5bfd-49a5-b423-9d41180a0ddb@l28g2000vba.googlegroups.com> <4a2e0f52$0$1105$4fafbaef@reader3.news.tin.it> <4a2e6edd$0$1114$4fafbaef@reader4.news.tin.it> Message-ID: >>>>> "Enrico" <4564 at 755189.45> (E) wrote: >E> "Piet van Oostrum" ha scritto nel messaggio >E> news:m2ljo1ajnx.fsf at cs.uu.nl... >>> The method doesn't need the class at all, so a staticmethod would be >>> preferable: >>> class Funcoes: >>> @staticmethod >>> def CifradorDeCesar(self, mensagem, chave, funcao): >E> Yes, in this case self is not needed. >>> >>> But as been mentioned in this thread before, there might be no reason to >>> use the class anyway. >E> I agree but the code is not very clear about the use of this class as >E> ancestor of MC. >>>> class MC(Funcoes, type): >E> ? I hadn't even noted this peculiarity. Maybe it was thought to be necessary because CifradorDeCesar is used in MC. But as it is explicitly used as Funcoes.CifradorDeCesar the Funcoes in the base classes is useless and therefore confusing. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From Krzysztof.Retel at googlemail.com Tue Jun 9 14:10:08 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Tue, 9 Jun 2009 11:10:08 -0700 (PDT) Subject: Using logging module to log into flash drive References: <70177935-7b83-4bde-9c89-db51f1690c4f@o36g2000vbi.googlegroups.com> Message-ID: <0f4bfca0-ec16-4dbe-8c5d-dbf7ae19292f@e21g2000yqb.googlegroups.com> > > Anyway there's a TimedRotatingFileHandler handler in the logging package: > > you can derive from it and change the emit/doRollover pair to hold the records > > until a device is not ready. > > Hm, that might be the way to go. Will have a try. I had another look at the logging package. The class TimedRotatingFileHandler within the initialisation method uses the FileHandler.__init__. Whereas the FileHandler.__init__ method opens the stream in the 'append' mode (mode='a'). If the flash drive is not available while you start the script, which equals that you can't open a file in the append mode, then the TimedRotatingFileHandler (or FileHandler) fails. In my opinion the only way to go through this is to use two different handlers and once the flash drive is available then start to use the FileHandler. Still not sure if I want to use separate thread for checking the flash drive availability. Probably I need to build it this way. Regards Krzysztof From milesck at umich.edu Tue Jun 9 14:21:30 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 9 Jun 2009 14:21:30 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <796q93F1p879rU1@mid.uni-berlin.de> References: <796hh2F1p7fpkU1@mid.uni-berlin.de> <796q93F1p879rU1@mid.uni-berlin.de> Message-ID: <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> On Jun 9, 2009, at 6:05 AM, Diez B. Roggisch wrote: > Also as list-comps are going away and are replaced by > > list() Where did you hear that? -Miles From mrstevegross at gmail.com Tue Jun 9 14:22:36 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 11:22:36 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? Message-ID: I'm trying to write a try/catch block to handle an "interrupted system call". However, I can't seem to locate information on the actual typename of the exception. Does anyone know what it would be? I want my code to look like this: try: ... except InterruptedSystemCall # what's the right name? ... Thanks, --Steve From tjreedy at udel.edu Tue Jun 9 14:29:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 14:29:47 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: >> James Tauber explains this at >> > python_tuples_are_not_just_constant_lists/>. > > > He doesn't really explain anything though, he merely states it as > revealed wisdom. The closest he comes to an explanation is to declare > that in tuples "the index in a tuple has an implied semantic. The point > of a tuple is that the i-th slot means something specific. In other > words, it's a index-based (rather than name based) datastructure." But he > gives no reason for why we should accept that as true for tuples but not > lists. > > It may be that that's precisely the motivation Guido had when he > introduced tuples into Python, but why should we not overload tuples with > more meanings than Guido (hypothetically) imagined? In other words, why > *shouldn't* we treat tuples as immutable lists, if that helps us solve a > problem effectively? I believe that we should overload tuples with *less* specific meaning than originally. In 3.0, tuples have *all* the general sequence operations and methods, including .index() and .count(). This was not true in 2.5 (don't know about 2.6), which is why tuples are yet not documented as having those two methods (reported in http://bugs.python.org/issue4966 ). Operationally, they are now general immutable sequences. Period. Terry Jan Reedy From tjreedy at udel.edu Tue Jun 9 14:32:17 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 14:32:17 -0400 Subject: preferring [] or () in list of error codes? In-Reply-To: References: Message-ID: mh at pixar.com wrote: > John Machin wrote: >> T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T) > > I've learned a lot from this thread, but this is the > niftiest bit I've picked up... thanks! If you are doing a lot of dissing, starting with from dis import dis saves subsequent typing. tjr From rkmr.em at gmail.com Tue Jun 9 14:38:53 2009 From: rkmr.em at gmail.com (rkmr.em at gmail.com) Date: Tue, 9 Jun 2009 11:38:53 -0700 Subject: spawning a process using os.spawn Message-ID: hi im spawning a script that runs for a long from a web app like this: os.spawnle(os.P_NOWAIT, "../bin/producenotify.py", "producenotify.py", "xx",os.environ) the script is spawned and it runs, but till it gets over i am not able to free the port that is used by the web app, or in other words i am not able to restart the web app. how do i spawn off a process and make it completely independent of the web app? thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid Tue Jun 9 14:44:37 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 09 Jun 2009 13:44:37 -0500 Subject: Unbuffered keyboard input? References: Message-ID: On 2009-06-09, Ken D'Ambrosio wrote: > I need to have some non-buffered keyboard interaction with a Python script > (on Linux). Back in the day, I fired up Curses to do this in Perl. Any > idea if that's still how I have to fly? Or is there a different > mechanism? Same as it ever was (in the order I'd probably try): 1. You can switch stdin to raw mode using standard termios calls (just like in C). 2. You can use ncurses. 3. You can use some other UI library like newt/slang, wxWidgets, etc. 4. You can shove long rusty needles through your eyeballs into your brain until you no longer want to do non-buffered keyboard interaction. 5. You can make Xlib calls. Once you've tried #5, #4 doesn't sound so bad... -- Grant Edwards grante Yow! Where's th' DAFFY at DUCK EXHIBIT?? visi.com From malaclypse2 at gmail.com Tue Jun 9 14:52:53 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 9 Jun 2009 14:52:53 -0400 Subject: Unbuffered keyboard input? In-Reply-To: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> References: <2ec146455327b54dcf3070c4ed0b432b.squirrel@webmail.jots.org> Message-ID: <16651e80906091152g328fdb8fo8fa3358a9a7b0529@mail.gmail.com> On Tue, Jun 9, 2009 at 1:52 PM, Ken D'Ambrosio wrote: > I need to have some non-buffered keyboard interaction with a Python script > (on Linux). Assuming you're running your code from a command prompt, something like this recipe might do the trick: http://code.activestate.com/recipes/134892/ -- Jerry From jeanmichel at sequans.com Tue Jun 9 14:54:32 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Jun 2009 20:54:32 +0200 Subject: What is the actual type of "interrupted system call"? In-Reply-To: References: Message-ID: <4A2EAFE8.40609@sequans.com> mrstevegross wrote: > I'm trying to write a try/catch block to handle an "interrupted system > call". However, I can't seem to locate information on the actual > typename of the exception. Does anyone know what it would be? I want > my code to look like this: > > try: > ... > except InterruptedSystemCall # what's the right name? > ... > > > Thanks, > --Steve > pick up your choice: exceptions.ArithmeticError exceptions.OSError exceptions.UnicodeTranslateError exceptions.AssertionError exceptions.OverflowError exceptions.UserWarning exceptions.AttributeError exceptions.OverflowWarning exceptions.ValueError exceptions.DeprecationWarning exceptions.PendingDeprecationWarning exceptions.Warning exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError exceptions.EnvironmentError exceptions.RuntimeError exceptions.__class__ exceptions.Exception exceptions.RuntimeWarning exceptions.__delattr__ exceptions.FloatingPointError exceptions.StandardError exceptions.__dict__ exceptions.FutureWarning exceptions.StopIteration exceptions.__doc__ exceptions.IOError exceptions.SyntaxError exceptions.__getattribute__ exceptions.ImportError exceptions.SyntaxWarning exceptions.__hash__ exceptions.IndentationError exceptions.SystemError exceptions.__init__ exceptions.IndexError exceptions.SystemExit exceptions.__name__ exceptions.KeyError exceptions.TabError exceptions.__new__ exceptions.KeyboardInterrupt exceptions.TypeError exceptions.__reduce__ exceptions.LookupError exceptions.UnboundLocalError exceptions.__reduce_ex__ exceptions.MemoryError exceptions.UnicodeDecodeError exceptions.__repr__ exceptions.NameError exceptions.UnicodeEncodeError exceptions.__setattr__ exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ CTRL+C (SIG_INT) is KeyboardInterrupt Jean-Michel From pavlovevidence at gmail.com Tue Jun 9 14:57:12 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 11:57:12 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: On Jun 9, 8:57?am, kretel wrote: > Hi All, > > I am trying to implement the following functionality: > 1. log messages to the flash drive > 2. if the flash drive is not available, switch handler to the > BufferringHandler and log into buffer, > 3. once the flash drive is plugged in and available store the logs > from BufferHandler into that flash drive and switch the handler into > RotateFileHandler. > > Which approach would you suggest to use while implementing this > functionality? One that come into my mind is to have one process or > thread to check periodically if the flashdrive is available, and have > a flag that will indicate that we can store the logs into the flash > drive. But I don't particularly like this approach. > Would you do it different way? > Any suggestions are appreciated. I'd refactor the steps this way: 1. log messages to a buffer 2. periodically flush the buffer to the flash drive, if it's available The "periodically" part could be accomplished with a thread or scheduled delays, however suits your application. It might not be a final if you need to log messages promptly, but that's how I'd begin. Carl Banks From jon at ffconsultancy.com Tue Jun 9 14:59:41 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 09 Jun 2009 19:59:41 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: toby wrote: > On Jun 7, 2:41?pm, Jon Harrop wrote: >> Arved Sandstrom wrote: >> > Jon Harrop wrote: >> >> I see no problem with mutable shared state. >> >> > In which case, Jon, you're in a small minority. >> >> No. Most programmers still care about performance > > Frequently when they shouldn't. I disagree. A lot of software is still far too slow because the programmers failed to pay attention to performance. Blogspot in Firefox being one example: it can barely keep up with my typing! >> and performance means mutable state. > > Hm, not sure Erlangers would wholly agree. Erlang is about concurrency. This thread is about parallelism. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From mrstevegross at gmail.com Tue Jun 9 14:59:43 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 11:59:43 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> > exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError >... > exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ Is there a single parent exception to all those? Or should I just write it as: try: ... catch Exception: ... Thanks, --Steve From jeff at jmcneil.net Tue Jun 9 15:06:00 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 9 Jun 2009 12:06:00 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: On Jun 9, 2:22?pm, mrstevegross wrote: > I'm trying to write a try/catch block to handle an "interrupted system > call". However, I can't seem to locate information on the actual > typename of the exception. Does anyone know what it would be? I want > my code to look like this: > > try: > ? ... > except InterruptedSystemCall # what's the right name? > ? ... > > Thanks, > --Steve You'll get that error when an async. event (signal) is delivered to your application during a system call. It's a result of 'errno' being set to errno.EINTR (4). I check for a few such specific conditions in some of my code and I usually do it like so: try: .... except EnvironmentError, e: if e.errno == errno.EINTR: do_something_with_eintr_error() else: raise That works for me. There isn't an "InterruptedSystemCall" error or equivalent in the standard exception hierarchy. EnvironmentError is the parent of OSError & IOError, which is where you'll most likely be encountering that state. Thanks, Jeff mcjeff.blogspot.com From bretrouse at gmail.com Tue Jun 9 15:09:15 2009 From: bretrouse at gmail.com (Bret) Date: Tue, 9 Jun 2009 12:09:15 -0700 (PDT) Subject: csv.reader has trouble with comma inside quotes inside brackets Message-ID: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> i have a csv file like so: row1,field1,[field2][text in field2 "quote, quote"],field3,field row2,field1,[field2]text in field2 "quote, quote",field3,field using csv.reader to read the file, the first row is broken into two fields: [field2][text in field2 "quote and quote" while the second row is read correctly with: [field2]text in field2 "quote, quote" being one field. any ideas how to make csv.reader work correctly for the first case? the problem is the comma inside the quote inside the brackets, ie: [","] From robert.kern at gmail.com Tue Jun 9 15:27:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 14:27:05 -0500 Subject: Start the interactive shell within an application In-Reply-To: <4A2E2215.1090405@sequans.com> References: <4A2E2215.1090405@sequans.com> Message-ID: On 2009-06-09 03:49, Jean-Michel Pichavant wrote: > I was wondering if there is a way to start an interactive shell within a > script/application. > I'm sometimes tired of adding prints to scan the current namespace so > I'd like to pause the execution and give the user the shell prompt. > This is obviously for debugging purpose. > > I know that I may use the raw_input and eval the captured text but > honestly, this requires some coding and I won't benefit from the shell > features. Would it be even possible to use a shell like Ipython ? http://ipython.scipy.org/doc/stable/html/interactive/reference.html#embedding-ipython > By the way, if anyone has cunning ways for debugging code to share, he > would be much welcome. You would do well to learn to use the standard Python debugger: http://docs.python.org/library/pdb -- 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 mrstevegross at gmail.com Tue Jun 9 15:29:17 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 9 Jun 2009 12:29:17 -0700 (PDT) Subject: What is the actual type of "interrupted system call"? References: Message-ID: <410f4586-8f45-42eb-ac96-e1d937a71129@o36g2000vbi.googlegroups.com> > That works for me. ?There isn't an "InterruptedSystemCall" error or > equivalent in the standard exception hierarchy. ?EnvironmentError is > the parent of OSError & IOError, which is where you'll most likely be > encountering that state. Thanks! --Steve From tjreedy at udel.edu Tue Jun 9 15:42:49 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 15:42:49 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: Hendrik van Rooyen wrote: > I should have known - you use a string method to get a list of words, > but you have to go to the list to get a list of characters from a string. That is symmetry. > There is no string method to do it, which is what I am complaining > about. That would be asymmetry. > > Is there a reason for this, or is the lack of symmetry just an historical > artefact? A lack of perception to see the symmetry that is there. Classes create instances of the class when called. Sometimes alternate constructors are needed when there is more than one possible way to create an instance from a given input. In the case of str(iterable), one could want either a string representing the iterable itself, just as with non-iterables, or a string representing the concatenated contents of the iterable. Str.join implements the second choice, with an added string parameter to allow a constant string to be interpolated between the joined items. > The link that jon vs python supplied is interesting. Yes. Mr. Shaw suffers from the same disease of 'neglect' that he accuses others of. See my other response in this thread. Terry Jan Reedy From tjreedy at udel.edu Tue Jun 9 15:43:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 15:43:02 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: jon vs. python wrote: > Sorry, I didn't realize that you already proposed list comprehension. > > > There is some kind of asymmetry in several areas.I guess that's > somehow related to this post: > http://www.zedshaw.com/blog/2009-05-29.html The premise of this post by Zed the Insightful is that Python developers are like a homegenous bunch of brain-damaged people. Instead, they are a heterogenous group of volunteers, with rotating membership, at least some of whom are aware of the various issues he mentions, but who are constrained by both time limits and back compatibility. The constraint of back compatibility was loosened for 3.0. What contribution did Zed Shaw make toward improving the deficiencies he noted when he had a chance? I do not remember any. His excuse: "If I had the time I would try to fix this stuff, but I realize that none of this will be fixed until there?s a cultural shift in Python away from this habit of Neglect." This bogus excuse is Neglect on his part. I strongly suspect, based on experience with other Professional Critics / Ignored Prophets like him, that efforts to help him contribute would be ignored or rejected. Python and the stdlib is all open source. If he were to submit a patch, and it were ignored or rejected for whatever reason, he could still release it and register it on PyPI. I just checked and NONE of the 6710 submissions are his. "There?s many more places where this kind of neglect is found, but these days I just accept it and move on unless I seriously get pissed off. The last tool I did this to was argparse and optparse which I replaced with a much nicer system in Lamson." Perhaps someday he will share his "improved" version and let others judge and possibly use it. "For the longest time (at least until 2000 when I last looked)" he writes on 2009-05-29, NINE years later. A decent reviewer would look for updated info before criticizing. I happen to agree with the design principle of pairing inverse operations, but 1) starting the presentation of that principle with bogus ad hominen attacks discredits it; 2) there may be more than one way to implement the principle in particular, and people may reasonably disagree on the best way. See my other response in this thread on str.join. Terry Jan Reedy From mh at pixar.com Tue Jun 9 16:06:55 2009 From: mh at pixar.com (mh at pixar.com) Date: Tue, 09 Jun 2009 20:06:55 GMT Subject: setting program name, like $0= in perl? Message-ID: I'm sure this is a FAQ, but I certainly haven't been able to find an answer. Is it possible to set the program name as seen by the operating system or lower-level libraries? I'm connecting to a database, and the runtime helpfully sends some information to the server, such as username, pid, and program name. Unfortunately, all my python programs get the name '/usr/bin/python', and I would like to force that to be the names of the individual scripts. Many TIA! Mark -- Mark Harrison Pixar Animation Studios From gneuner2 at comcast.net Tue Jun 9 16:07:07 2009 From: gneuner2 at comcast.net (George Neuner) Date: Tue, 09 Jun 2009 16:07:07 -0400 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On Tue, 9 Jun 2009 10:47:11 -0700 (PDT), toby wrote: >On Jun 7, 2:41?pm, Jon Harrop wrote: >> Arved Sandstrom wrote: >> > Jon Harrop wrote: >> >> performance means mutable state. > >Hm, not sure Erlangers would wholly agree. Erlang uses quite a bit of mutable state behind the scenes ... the programmers just don't see it. George From robert.kern at gmail.com Tue Jun 9 16:20:56 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 15:20:56 -0500 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: On 2009-06-09 14:43, Terry Reedy wrote: > jon vs. python wrote: >> Sorry, I didn't realize that you already proposed list comprehension. >> >> >> There is some kind of asymmetry in several areas.I guess that's >> somehow related to this post: http://www.zedshaw.com/blog/2009-05-29.html > > The premise of this post by Zed the Insightful is that Python developers > are like a homegenous bunch of brain-damaged people. Instead, they are a > heterogenous group of volunteers, with rotating membership, at least > some of whom are aware of the various issues he mentions, but who are > constrained by both time limits and back compatibility. > > The constraint of back compatibility was loosened for 3.0. What > contribution did Zed Shaw make toward improving the deficiencies he > noted when he had a chance? I do not remember any. > > His excuse: "If I had the time I would try to fix this stuff, but I > realize that none of this will be fixed until there?s a cultural shift > in Python away from this habit of Neglect." This bogus excuse is Neglect > on his part. I strongly suspect, based on experience with other > Professional Critics / Ignored Prophets like him, that efforts to help > him contribute would be ignored or rejected. > > Python and the stdlib is all open source. If he were to submit a patch, > and it were ignored or rejected for whatever reason, he could still > release it and register it on PyPI. I just checked and NONE of the 6710 > submissions are his. > > "There?s many more places where this kind of neglect is found, but these > days I just accept it and move on unless I seriously get pissed off. The > last tool I did this to was argparse and optparse which I replaced with > a much nicer system in Lamson." > > Perhaps someday he will share his "improved" version and let others > judge and possibly use it. To be fair: http://pypi.python.org/pypi/zapps/ http://pypi.python.org/pypi/lamson/ http://pypi.python.org/pypi/vellum/ http://pypi.python.org/pypi/idiopidae -- 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 Tue Jun 9 16:46:35 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 16:46:35 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> References: <796hh2F1p7fpkU1@mid.uni-berlin.de> <796q93F1p879rU1@mid.uni-berlin.de> <596EAC72-AD3E-44C0-AE8E-0FE4187EEC42@umich.edu> Message-ID: Miles Kaufmann wrote: > On Jun 9, 2009, at 6:05 AM, Diez B. Roggisch wrote: > >> Also as list-comps are going away and are replaced by >> >> list() > > Where did you hear that? Perhaps in the discussion of possible changes for 3.0 about 18 months ago. The idea was rejected because set/list/dict(genexp) is too much slower (say 2x) than the direct implementation of set/list/dict comprehensions. tjr From sjmachin at lexicon.net Tue Jun 9 17:03:30 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 9 Jun 2009 21:03:30 +0000 (UTC) Subject: csv.reader has trouble with comma inside quotes inside brackets References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: Bret gmail.com> writes: > > i have a csv file like so: > row1,field1,[field2][text in field2 "quote, quote"],field3,field > row2,field1,[field2]text in field2 "quote, quote",field3,field > > using csv.reader to read the file, the first row is broken into two > fields: > [field2][text in field2 "quote > and > quote" > > while the second row is read correctly with: > [field2]text in field2 "quote, quote" > being one field. > > any ideas how to make csv.reader work correctly for the first case? > the problem is the comma inside the quote inside the brackets, ie: > [","] I can't reproduce the behaviour that you describe based on these reasonable assumptions: Python 2.6, delimiter=',', quotechar='"': C:\junk\weird_csv>\python26\python Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. |>>> import pprint, csv |>>> open('weird.csv', 'rb').read() 'row1,field1,[field2][text in field2 "quote, quote"],field3,field\r\nrow2,field1 ,[field2]text in field2 "quote, quote",field3,field\r\n' >>> pprint.pprint(list(csv.reader(open('weird.csv', 'rb')))) [['row1', 'field1', '[field2][text in field2 "quote', ' quote"]', 'field3', 'field'], ['row2', 'field1', '[field2]text in field2 "quote', ' quote"', 'field3', 'field']] |>>> As you can see, it treats both lines in the same way. Opening the file with each of Microsoft Excel 2003, OpenOffice.org Calc 3, and Gnumeric has exactly the same effect. The problem is that your data has not been prepared using the generally accepted rules for quoting in CSV files: [pseudocode] if field contains any of quotechar, delimiter, newline, maybe others: field = (quotechar + field.replace(quotechar, quotechar + quotechar) + quotechar) which would change your first line from row1,field1,[field2][text in field2 "quote, quote"],field3,field to row1,field1,"[field2][text in field2 ""quote, quote""]",field3,field There's no option in the csv module to get around this, AFAICT. You'd have to roll your own, something along these lines (assumes no embedded newlines etc): 8<--- parse_unquoted_csv.py def parse_unquoted_csv(line, delimiter=',', quotechar='"'): line = line.strip() inside_quotes = False fields = [] field = '' for c in line: if inside_quotes: if c == quotechar: inside_quotes = False field += c else: if c == delimiter: fields.append(field) field = '' else: if c == quotechar: inside_quotes = True field += c if inside_quotes: print repr(line) print fields print repr(field) raise Exception("Quotes not balanced") fields.append(field) return fields if __name__ == "__main__": tests = [ 'row1,field1,[field2][text in field2 "quote, quote"],field3,field', 'row2,field1,[field2]text in field2 "quote, quote",field3,field', 'a,b,c', 'a,b,', '', 'Look,here"s,a,typo', ] for test in tests: print repr(test) print parse_unquoted_csv(test) print 8<--- HTH, John From bretrouse at gmail.com Tue Jun 9 17:15:14 2009 From: bretrouse at gmail.com (Bret) Date: Tue, 9 Jun 2009 14:15:14 -0700 (PDT) Subject: csv.reader has trouble with comma inside quotes inside brackets References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: <7fcdc208-3a11-4de6-bfb3-06debd56eb75@d31g2000vbm.googlegroups.com> Thanks John, I didn't realize that the quotes were supposed to surround the entire field. I ended up making a quick script to replace comma's outside quotes with tabs. I was just trying to clean this crazy "csv" file to import into msyql. thanks again, bret From fetchinson at googlemail.com Tue Jun 9 17:16:31 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 9 Jun 2009 14:16:31 -0700 Subject: setting program name, like $0= in perl? In-Reply-To: References: Message-ID: > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. I don't know the answer to your question but I would start by trying to figure out what information is really sent to the db. I mean it is probably an environment variable or something like that, and once you figure out exactly what it is, you will know what variable to set. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From emile at fenx.com Tue Jun 9 17:16:49 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 14:16:49 -0700 Subject: setting program name, like $0= in perl? In-Reply-To: References: Message-ID: On 6/9/2009 1:06 PM mh at pixar.com said... > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. If you include the shebang as first line and execute the script directly I think it'll work. ---- test.py---- #!/usr/bin/python import sys print sys.argv[0] ---------------- Emile > > Many TIA! > Mark > From tjreedy at udel.edu Tue Jun 9 17:27:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 17:27:13 -0400 Subject: csv.reader has trouble with comma inside quotes inside brackets In-Reply-To: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> References: <51fa0a3a-1870-4d14-8ac6-03750cc4fd98@v4g2000vba.googlegroups.com> Message-ID: Bret wrote: > i have a csv file like so: > row1,field1,[field2][text in field2 "quote, quote"],field3,field > row2,field1,[field2]text in field2 "quote, quote",field3,field > > using csv.reader to read the file, the first row is broken into two > fields: > [field2][text in field2 "quote > and > quote" > > while the second row is read correctly with: > [field2]text in field2 "quote, quote" > being one field. > > any ideas how to make csv.reader work correctly for the first case? > the problem is the comma inside the quote inside the brackets, ie: > [","] When posting, give version, minimum code that has problem, and actual output. Cut and past latter two. Reports are less credible otherwise. Using 3.1rc1 txt = [ '''row1,field1,[field2][text in field2 "quote, quote"],field3,field''', '''row2,field1,[field2] text in field2 "quote, quote", field3,field''', '''row2,field1, field2 text in field2 "quote, quote", field3,field''', ] import csv for row in csv.reader(txt): print(len(row),row) produces 6 ['row1', 'field1', '[field2][text in field2 "quote', ' quote"]', field3', 'field'] 6 ['row2', 'field1', '[field2] text in field2 "quote', ' quote"', ' field3', 'field'] 6 ['row2', 'field1', ' field2 text in field2 "quote', ' quote"', ' field3', 'field'] In 3.1 at least, the presence or absence of brackets is irrelevant, as I expected it to be. For double quotes to protect the comma delimiter, the *entire field* must be quoted, not just part of it. If you want to escape the delimiter without quoting entire fields, use an escape char and change the dialect. For example txt = [ '''row1,field1,[field2][text in field2 "quote`, quote"],field3,field''', '''row2,field1,[field2] text in field2 "quote`, quote", field3,field''', '''row2,field1, field2 text in field2 "quote`, quote", field3,field''', ] import csv for row in csv.reader(txt, quoting=csv.QUOTE_NONE, escapechar = '`'): print(len(row),row) produces what you desire 5 ['row1', 'field1', '[field2][text in field2 "quote, quote"]', 'field3', 'field'] 5 ['row2', 'field1', '[field2] text in field2 "quote, quote"', ' field3', 'field'] 5 ['row2', 'field1', ' field2 text in field2 "quote, quote"', ' field3', 'field'] Terry Jan Reedy From malkia at mac.com Tue Jun 9 17:28:54 2009 From: malkia at mac.com (Dimiter "malkia" Stanev) Date: Tue, 09 Jun 2009 14:28:54 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: > Erlang uses quite a bit of mutable state behind the scenes ... the > programmers just don't see it. > > George Heh... "The CPUs use quite a bit of mutable state behind the scenes ... the programmers just don't see it." Actually with CPU they see it more, than... say Erlang (that's why you need to use fences/barriers/locked access here and there). From ebonak at hotmail.com Tue Jun 9 17:33:39 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 17:33:39 -0400 Subject: random number including 1 - i.e. [0,1] Message-ID: Hi, random.random() will generate a random value in the range [0, 1). Is there an easy way to generate random values in the range [0, 1]? I.e., including 1? I am implementing an algorithm and want to stay as true to the original design specifications as possible though I suppose the difference between the two max values might be minimal. Thanks, Esmail ps: I'm confused by the docs for uniform(): random.uniform(a, b) Return a random floating point number N such that a <= N <= b for a <= b this seems to imply an inclusive range, ie. [a,b] but this seems to contradict it: In [3]: random.uniform? Type: instancemethod Base Class: String Form: > Namespace: Interactive File: /usr/lib/python2.6/random.py Definition: random.uniform(self, a, b) Docstring: Get a random number in the range [a, b). From tjreedy at udel.edu Tue Jun 9 17:34:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Jun 2009 17:34:19 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2009-06-09 14:43, Terry Reedy wrote: >> jon vs. python wrote: >> Python and the stdlib is all open source. If he were to submit a patch, >> and it were ignored or rejected for whatever reason, he could still >> release it and register it on PyPI. I just checked and NONE of the 6710 >> submissions are his. > To be fair: > > http://pypi.python.org/pypi/zapps/ > http://pypi.python.org/pypi/lamson/ > http://pypi.python.org/pypi/vellum/ > http://pypi.python.org/pypi/idiopidae Important correction noted. But how did you find those? When I search for 'Shaw' with the search box (I tried it again), I only get a couple of other, irrelevant hits. Is the search box buggy? tjr From emile at fenx.com Tue Jun 9 17:40:04 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 14:40:04 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> Message-ID: On 6/9/2009 11:59 AM Jon Harrop said... > toby wrote: >> On Jun 7, 2:41 pm, Jon Harrop wrote: >>> No. Most programmers still care about performance >> Frequently when they shouldn't. > > I disagree. A lot of software is still far too slow because the programmers > failed to pay attention to performance. For a properly written spec, performance is spec'd and paid for. > Blogspot in Firefox being one > example: it can barely keep up with my typing! There are so many ways that's not the program. Performance,accuracy,cost -- pick two sacrifice one. Emile From steven.klass at gmail.com Tue Jun 9 18:00:51 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 15:00:51 -0700 (PDT) Subject: .pth files and figuring out valid paths.. Message-ID: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> I have a .pth file which has some logic in it - but it isn't quite enough... It started with this.. import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], "tools/python/modules")) But that eventually evolved into.. import os, site; site.addsitedir(os.path.join(os.environ.get ("TECHROOT", "/home/tech"), "tools/python/modules")) But now I want to check to make sure this directory exists or fall back to "/home/tech". That was the point of the environ.get but what if someone sets TECHROOT to /dev/null. Well that will break things... I tried this but no go. Can someone help me out.. import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- packages")) Apparently there is a problem with the if statement??? Thanks From pavlovevidence at gmail.com Tue Jun 9 18:06:21 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 9 Jun 2009 15:06:21 -0700 (PDT) Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> Message-ID: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> On Jun 9, 12:42?pm, Terry Reedy wrote: > Hendrik van Rooyen wrote: > > I should have known - you use a string method to get a list of words, > > but you have to go to the list to get a list of characters from a string. > > That is symmetry. > > > There is no string method to do it, which is what I am complaining > > about. > > That would be asymmetry. > > > > > Is there a reason for this, or is the lack of symmetry just an historical > > artefact? > > A lack of perception to see the symmetry that is there. > > Classes create instances of the class when called. > > Sometimes alternate constructors are needed when there is more than one > possible way to create an instance from a given input. ?In the case of > str(iterable), one could want either a string representing the iterable > itself, just as with non-iterables, or a string representing the > concatenated contents of the iterable. ?Str.join implements the second > choice, with an added string parameter to allow a constant string to be > interpolated between the joined items. But then how do you rationalize str.split(), which is a method of str but a constructor of list? Perhaps instead of worrying about symmetry all the time we should just accept the inevitability that things will always be asymmetric and impure from someone's perspective. Terry's symmetry is Hendrik's asymmetry and vice versa. Carl Banks From stef.mientki at gmail.com Tue Jun 9 18:07:12 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 10 Jun 2009 00:07:12 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? Message-ID: <4A2EDD10.6090608@gmail.com> hello, I want to make a distro for Ubuntu, and run under Windows. I packed all sources with zipfile, but the compression doesn't seem to be very good. If run the created file through 7zip, it becomes anout half the size. Is there a way to accomplish the same task with zipfile ( the documentation isn't overwhelming). thanks, Stef Mientki From robert.kern at gmail.com Tue Jun 9 18:11:19 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 17:11:19 -0500 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: On 2009-06-09 16:34, Terry Reedy wrote: > Robert Kern wrote: >> On 2009-06-09 14:43, Terry Reedy wrote: >>> jon vs. python wrote: > >>> Python and the stdlib is all open source. If he were to submit a patch, >>> and it were ignored or rejected for whatever reason, he could still >>> release it and register it on PyPI. I just checked and NONE of the 6710 >>> submissions are his. > >> To be fair: >> >> http://pypi.python.org/pypi/zapps/ >> http://pypi.python.org/pypi/lamson/ >> http://pypi.python.org/pypi/vellum/ >> http://pypi.python.org/pypi/idiopidae > > Important correction noted. But how did you find those? When I search > for 'Shaw' with the search box (I tried it again), I only get a couple > of other, irrelevant hits. Is the search box buggy? I suspect so. I knew of most of them already, and Googling site:pypi.python.org picked up the rest. -- 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 Jun 9 18:17:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 17:17:14 -0500 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: On 2009-06-09 17:06, Carl Banks wrote: > On Jun 9, 12:42 pm, Terry Reedy wrote: >> Hendrik van Rooyen wrote: >>> I should have known - you use a string method to get a list of words, >>> but you have to go to the list to get a list of characters from a string. >> That is symmetry. >> >>> There is no string method to do it, which is what I am complaining >>> about. >> That would be asymmetry. >> >> >> >>> Is there a reason for this, or is the lack of symmetry just an historical >>> artefact? >> A lack of perception to see the symmetry that is there. >> >> Classes create instances of the class when called. >> >> Sometimes alternate constructors are needed when there is more than one >> possible way to create an instance from a given input. In the case of >> str(iterable), one could want either a string representing the iterable >> itself, just as with non-iterables, or a string representing the >> concatenated contents of the iterable. Str.join implements the second >> choice, with an added string parameter to allow a constant string to be >> interpolated between the joined items. > > But then how do you rationalize str.split(), which is a method of str > but a constructor of list? There is a difference between a "constructor of a type" and just "a method that returns a particular type". str.join() and str.split() are really examples of the latter. > Perhaps instead of worrying about symmetry all the time we should just > accept the inevitability that things will always be asymmetric and > impure from someone's perspective. Terry's symmetry is Hendrik's > asymmetry and vice versa. There is much wisdom in 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 emile at fenx.com Tue Jun 9 18:28:23 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Jun 2009 15:28:23 -0700 Subject: .pth files and figuring out valid paths.. In-Reply-To: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: On 6/9/2009 3:00 PM rh0dium said... > I have a .pth file which has some logic in it - but it isn't quite > enough... > > It started with this.. > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], > "tools/python/modules")) > > But that eventually evolved into.. > import os, site; site.addsitedir(os.path.join(os.environ.get > ("TECHROOT", "/home/tech"), "tools/python/modules")) > > But now I want to check to make sure this directory exists or fall > back to "/home/tech". That was the point of the environ.get but what > if someone sets TECHROOT to /dev/null. Well that will break > things... I tried this but no go. Can someone help me out.. > You're not really putting all this on one line are you? If so, that's a problem. > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if > not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > packages")) > Try it this way... import os, site smsc = os.environ.get("TECHROOT", "/home/tech") if not os.path.isdir(smsc): smsc = "/home/tech" site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site-packages")) Emile > Apparently there is a problem with the if statement??? > > Thanks > From mensanator at aol.com Tue Jun 9 19:05:05 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 16:05:05 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. > > Thanks, > Esmail > > ps: I'm confused by the docs for uniform(): > > random.uniform(a, b) > ? ? ?Return a random floating point number N such that a <= N <= b for a <= b That's wrong. Where did you get it? >>> help(random.uniform) Help on method uniform in module random: uniform(self, a, b) method of random.Random instance Get a random number in the range [a, b). > > this seems to imply an inclusive range, ie. [a,b] > > but this seems to contradict it: > > In [3]: random.uniform? > Type: ? ? ? ? ? instancemethod > Base Class: ? ? > String Form: ? ?> > Namespace: ? ? ?Interactive > File: ? ? ? ? ? /usr/lib/python2.6/random.py > Definition: ? ? random.uniform(self, a, b) > Docstring: > ? ? ?Get a random number in the range [a, b). From gagsl-py2 at yahoo.com.ar Tue Jun 9 19:05:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 20:05:45 -0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? I think you shouldn't worry about that - the difference may be as small as 2**-53, or 0.0000000000000001 > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. > > ps: I'm confused by the docs for uniform(): > > random.uniform(a, b) > Return a random floating point number N such that a <= N <= b for a > <= b > > this seems to imply an inclusive range, ie. [a,b] random() guarantees a semi-open interval (could return 0, but never 1). But once you start to operate with the numbers, the limits become fuzzy. a0 => n.a a=10.0 py> b=11.0 py> z = 0.9999999999999999 # assume random.random returned this py> z<1 True py> a+(b-a)*z < b # the expression used for uniform(a,b) False py> a+(b-a)*z 11.0 The docs are already updated to reflect this: http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=68724&r2=68723&pathrev=68724 -- Gabriel Genellina From robert.kern at gmail.com Tue Jun 9 19:12:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Jun 2009 18:12:52 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: On 2009-06-09 18:05, Mensanator wrote: > On Jun 9, 4:33 pm, Esmail wrote: >> Hi, >> >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? >> >> I am implementing an algorithm and want to stay as true to the >> original design specifications as possible though I suppose the >> difference between the two max values might be minimal. >> >> Thanks, >> Esmail >> >> ps: I'm confused by the docs for uniform(): >> >> random.uniform(a, b) >> Return a random floating point number N such that a<= N<= b for a<= b > > That's wrong. Where did you get it? http://docs.python.org/library/random -- 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 milesck at umich.edu Tue Jun 9 19:16:57 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 9 Jun 2009 19:16:57 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> On Jun 9, 2009, at 7:05 PM, Mensanator wrote: > On Jun 9, 4:33 pm, Esmail wrote: >> Hi, >> >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? >> >> I am implementing an algorithm and want to stay as true to the >> original design specifications as possible though I suppose the >> difference between the two max values might be minimal. I'm curious what algorithm calls for random numbers on a closed interval. >> ps: I'm confused by the docs for uniform(): >> >> random.uniform(a, b) >> Return a random floating point number N such that a <= N <= b >> for a <= b > > That's wrong. Where did you get it? http://docs.python.org/library/random.html -Miles From steven.klass at gmail.com Tue Jun 9 19:30:06 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 16:30:06 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> On Jun 9, 3:28?pm, Emile van Sebille wrote: > On 6/9/2009 3:00 PM rh0dium said... > > > > > > > I have a .pth file which has some logic in it - but it isn't quite > > enough... > > > It started with this.. > > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], > > "tools/python/modules")) > > > But that eventually evolved into.. > > import os, site; site.addsitedir(os.path.join(os.environ.get > > ("TECHROOT", "/home/tech"), "tools/python/modules")) > > > But now I want to check to make sure this directory exists or fall > > back to "/home/tech". ?That was the point of the environ.get but what > > if someone sets TECHROOT to /dev/null. ?Well that will break > > things... ?I tried this but no go. ?Can someone help me out.. > > You're not really putting all this on one line are you? ?If so, that's a > problem. > > > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if > > not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir > > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > > packages")) > > Try it this way... > > import os, site > smsc = os.environ.get("TECHROOT", "/home/tech") > if not os.path.isdir(smsc): > ? ? ?smsc = "/home/tech" > site.addsitedir (os.path.join(smsc, > "tools/python/Linux/%arch/lib/python2.5/site-packages")) > > Emile > > > > > Apparently there is a problem with the if statement??? > > > Thanks No for .pth files this needs to be on a single line.. From steve at REMOVE-THIS-cybersource.com.au Tue Jun 9 19:40:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Jun 2009 23:40:04 GMT Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <55fd7965-91e7-4346-933e-ac1a42900fe9@c36g2000yqn.googlegroups.com> <02cc2269-491a-44db-8cb4-7bb6f1419503@f16g2000vbf.googlegroups.com> Message-ID: <023ee521$0$20636$c3e8da3@news.astraweb.com> On Tue, 09 Jun 2009 04:57:48 -0700, samwyse wrote: > Time to test things! I'm going to compare three things using Python > 3.0: > X={...}\nS=lambda x: x in X > S=lambda x: x in {...} > S=lambda x: x in (...) > where the ... is replaced by lists of integers of various lengths. > Here's the test bed: [snip] Hmmm... I think your test-bed is unnecessarily complicated, making it difficult to see what is going on. Here's my version, with lists included for completeness. Each test prints the best of five trials of one million repetitions of ten successful searches, then does the same thing again for unsuccessful searches. from timeit import Timer def test(size): global s, l, t, targets print("Testing search with size %d" % size) rng = range(size) s, l, t = set(rng), list(rng), tuple(rng) # Calculate a (more or less) evenly distributed set of ten # targets to search for, including both end points. targets = [i*size//9 for i in range(9)] + [size-1] assert len(targets) == 10 setup = "from __main__ import targets, %s" body = "for i in targets: i in %s" # Run a series of successful searches. for name in "s l t".split(): obj = globals()[name] secs = min(Timer(body % name, setup % name).repeat(repeat=5)) print("Successful search in %s: %f s" % (type(obj), secs)) # Also run unsuccessful tests. targets = [size+x for x in targets] for name in "s l t".split(): obj = globals()[name] secs = min(Timer(body % name, setup % name).repeat(repeat=5)) print("Unsuccessful search in %s: %f s" % (type(obj), secs)) Results are: >>> test(1) Testing search with size 1 Successful search in : 1.949509 s Successful search in : 1.838387 s Successful search in : 1.876309 s Unsuccessful search in : 1.998207 s Unsuccessful search in : 2.148660 s Unsuccessful search in : 2.137041 s >>> >>> >>> test(10) Testing search with size 10 Successful search in : 1.943664 s Successful search in : 3.659786 s Successful search in : 3.569164 s Unsuccessful search in : 1.935553 s Unsuccessful search in : 5.833665 s Unsuccessful search in : 5.573177 s >>> >>> >>> test(100) Testing search with size 100 Successful search in : 1.907839 s Successful search in : 21.704032 s Successful search in : 21.391875 s Unsuccessful search in : 1.916241 s Unsuccessful search in : 41.178029 s Unsuccessful search in : 41.856226 s >>> >>> >>> test(1000) Testing search with size 1000 Successful search in : 2.256150 s Successful search in : 189.991579 s Successful search in : 187.349630 s Unsuccessful search in : 1.869202 s Unsuccessful search in : 398.451284 s Unsuccessful search in : 388.544178 s As expected, lists and tuples are equally as fast (or slow if you prefer). Successful searches are about twice as fast as unsuccessful ones, and performance suffers as the size of the list/tuple increases. However, sets are nearly just as fast no matter the size of the set, or whether the search is successfully or unsuccessful. > You will note that testing against a list constant is just as fast as > testing against a set. This was surprising for me; apparently the > __contains__ operator turns a tuple into a set. I doubt that very much. -- Steven From gagsl-py2 at yahoo.com.ar Tue Jun 9 19:41:25 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Jun 2009 20:41:25 -0300 Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > I have an embedded python application. which is a MFC app with > Python interpreter embedded. > > In the App, I have a separate thread to execute a Python script > (using the PyRun_File), but if the user want to stop the executing > script, how should I do? > > A possible way is terminate the thread of executing the scripts by > TerminateThread(). but TerminateThread() is unsafe and not > recommended. > > guys, could you guide me on this? You could use PyThreadState_SetAsyncExc (to "inject" an exception), or perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a KeyboardInterrupt). This should work fine for well-behaved scripts, but if it ignores all exceptions like this: try: ... except: pass you'll have to look at ceval.c how to break out of the running loop. (this is yet another argument against indiscriminately using a bare except clause...) -- Gabriel Genellina From ebonak at hotmail.com Tue Jun 9 19:53:22 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:53:22 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: <4A2EF5F2.9080902@hotmail.com> Gabriel Genellina wrote: > En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > >> random.random() will generate a random value in the range [0, 1). >> >> Is there an easy way to generate random values in the range [0, 1]? >> I.e., including 1? > > I think you shouldn't worry about that - the difference may be as small > as 2**-53, or 0.0000000000000001 Ok, that's what I thought ... > random() guarantees a semi-open interval (could return 0, but never 1). > But once you start to operate with the numbers, the limits become fuzzy. > > a0 => n.a > The above holds for real numbers but not always for floating point > arithmetic, so one cannot guarantee the semi-open interval anymore: > > py> a=10.0 > py> b=11.0 > py> z = 0.9999999999999999 # assume random.random returned this > py> z<1 > True > py> a+(b-a)*z < b # the expression used for uniform(a,b) > False > py> a+(b-a)*z > 11.0 > > The docs are already updated to reflect this: > http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=68724&r2=68723&pathrev=68724 Thanks for the information Gabriel, Esmail From ebonak at hotmail.com Tue Jun 9 19:54:15 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:54:15 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Robert Kern wrote: > On 2009-06-09 18:05, Mensanator wrote: >> On Jun 9, 4:33 pm, Esmail wrote: >> >> >> That's wrong. Where did you get it? > > http://docs.python.org/library/random What he said :-) (thanks Robert) From ebonak at hotmail.com Tue Jun 9 19:57:50 2009 From: ebonak at hotmail.com (Esmail) Date: Tue, 09 Jun 2009 19:57:50 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> References: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> Message-ID: <4A2EF6FE.4080506@hotmail.com> Miles Kaufmann wrote: > > I'm curious what algorithm calls for random numbers on a closed interval. I'm implementing a Particle Swarm Optimizer. Depending on what paper you read you'll see mention of required random values "between 0 and 1" which is somewhat ambiguous. I came across one paper that specified the range [0,1], so inclusive 1, which was the reason for my question. (I'm still looking for other papers to see if I can get more information exactly on the range) I think in the end it probably doesn't matter if it's [0, 1) or [0, 1] as the max values for each will probably be very close. Esmail From david.lyon at preisshare.net Tue Jun 9 19:58:37 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 09 Jun 2009 19:58:37 -0400 Subject: .pth files and figuring out valid paths.. In-Reply-To: <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: <77c1ea77978b97f67b133cfe02c7441c@preisshare.net> On Tue, 9 Jun 2009 16:30:06 -0700 (PDT), rh0dium wrote: >> > Apparently there is a problem with the if statement??? >> >> > Thanks > > No for .pth files this needs to be on a single line.. I can't really see why you need conditional code... If you want to add more locations... Simply create another .PTH file..... Having multiple paths or multiple .PTH files isn't a problem for python. David From mensanator at aol.com Tue Jun 9 20:27:13 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 17:27:13 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 6:12?pm, Robert Kern wrote: > On 2009-06-09 18:05, Mensanator wrote: > > > > > > > On Jun 9, 4:33 pm, Esmail ?wrote: > >> Hi, > > >> random.random() will generate a random value in the range [0, 1). > > >> Is there an easy way to generate random values in the range [0, 1]? > >> I.e., including 1? > > >> I am implementing an algorithm and want to stay as true to the > >> original design specifications as possible though I suppose the > >> difference between the two max values might be minimal. > > >> Thanks, > >> Esmail > > >> ps: I'm confused by the docs for uniform(): > > >> random.uniform(a, b) > >> ? ? ? Return a random floating point number N such that a<= N<= b for a<= b > > > That's wrong. Where did you get it? > > http://docs.python.org/library/random Ok, but the 2.6.1 docs say random.uniform(a, b) Return a random floating point number N such that a <= N < b for a <= b and b <= N < a for b < a. Is that a new feature of 2.6.2? > > -- > 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- Hide quoted text - > > - Show quoted text - From ptmcg at austin.rr.com Tue Jun 9 20:39:10 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Jun 2009 17:39:10 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > Are you trying to generate a number in the range [0,n] by multiplying a random function that returns [0,1] * n? If so, then you want to do this using: int(random.random()*(n+1)) This will give equal chance of getting any number from 0 to n. If you had a function that returned a random in the range [0,1], then multiplying by n and then truncating would give only the barest sliver of a chance of giving the value n. You could try rounding, but then you get this skew: 0 for values [0, 0.5) (width of 0.5) 1 for value [0.5, 1.5) (width of 1) ... n for value [n-0.5, n] (width of ~0.50000000000000001) Still not a uniform die roll. You have only about 1/2 the probability of getting 0 or n as any other value. If you want to perform a fair roll of a 6-sided die, you would start with int(random.random() * 6). This gives a random number in the range [0,5], with each value of the same probability. How to get our die roll that goes from 1 to 6? Add 1. Thus: die_roll = lambda : int(random.random() * 6) + 1 Or for a n-sided die: die_roll = lambda n : int(random.random() * n) + 1 This is just guessing on my part, but otherwise, I don't know why you would care if random.random() returned values in the range [0,1) or [0,1]. -- Paul From mensanator at aol.com Tue Jun 9 20:45:05 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 17:45:05 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > En Tue, 09 Jun 2009 18:33:39 -0300, Esmail escribi?: > > > random.random() will generate a random value in the range [0, 1). > > > Is there an easy way to generate random values in the range [0, 1]? > > I.e., including 1? > > I think you shouldn't worry about that - the difference may be as small as ? > 2**-53, or 0.0000000000000001 > > > I am implementing an algorithm and want to stay as true to the > > original design specifications as possible though I suppose the > > difference between the two max values might be minimal. > > > ps: I'm confused by the docs for uniform(): > > > random.uniform(a, b) > > ? ? ?Return a random floating point number N such that a <= N <= b for a ? > > <= b > > > this seems to imply an inclusive range, ie. [a,b] > > random() guarantees a semi-open interval (could return 0, but never 1). ? > But once you start to operate with the numbers, the limits become fuzzy. > > a0 => n.a > The above holds for real numbers but not always for floating point ? > arithmetic, so one cannot guarantee the semi-open interval anymore: > > py> a=10.0 > py> b=11.0 > py> z = 0.9999999999999999 ?# assume random.random returned this > py> z<1 > True That means the interval is still [0,1). To put it another way: >>> z=0.9999999999999999 >>> z==1 False > py> a+(b-a)*z < b # the expression used for uniform(a,b) > False > py> a+(b-a)*z > 11.0 What you do with the number after it's created is not random's concern. > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... The docs are now wrong. Why would they do that? > > -- > Gabriel Genellina From matt at tplus1.com Tue Jun 9 21:12:59 2009 From: matt at tplus1.com (Matthew Wilson) Date: Wed, 10 Jun 2009 01:12:59 GMT Subject: Where should I store docs in my project? Message-ID: I used paster to create a project named pitz. I'm writing a bunch of user documentation. Where should I put it? The project looks a little like this: /home/matt/projects/pitz setup.py pitz/ __init__.py # has my project code docs/ # has my reST files tests # has some tests Is there a convention for where to put the docs folder? From gallium.arsenide at gmail.com Tue Jun 9 21:28:23 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 18:28:23 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 8:45?pm, Mensanator wrote: > On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > False > > py> a+(b-a)*z > > 11.0 > > What you do with the number after it's created is not > random's concern. Mensanator, you missed Gabriel's point. What he's saying is that, effectively, random.uniform(a, b) returns a + (b - a) * random.random (). So z may not be random()'s concern, but it very much is uniform ()'s concern. > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... > > The docs are now wrong. Why would they do that? The docs are now... sort of correct. For some values of a and b, uniform() can never return b. Notably, I believe uniform(0, 1) is equivalent to random(), and will never return 1. However, uniform(1, 2) CAN return 2, if this is any indication: >>> a=0.0 >>> b=1.0 >>> a+(b-a)*z < b True >>> a=1.0 >>> b=2.0 >>> a+(b-a)*z < b False John From gallium.arsenide at gmail.com Tue Jun 9 21:32:57 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 18:32:57 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> Message-ID: On Jun 9, 8:39?pm, Paul McGuire wrote: > Are you trying to generate a number in the > range [0,n] by multiplying a random function that > returns [0,1] * n? ?If so, then you want to do > this using: int(random.random()*(n+1)) ?This will > give equal chance of getting any number from 0 to n. Better still is simply random.randint(0, n) For other discrete random choices, you may find randrange() or choice () useful. John From myopc at aaa.com Tue Jun 9 21:39:58 2009 From: myopc at aaa.com (myopc) Date: Wed, 10 Jun 2009 09:39:58 +0800 Subject: multi-thread python interpreaters and c++ program References: Message-ID: thanks for your reply! "Lie Ryan" $y61.12599 at news-server.bigpond.net.au... > myopc wrote: >> hi, all >> I am ruuning a c++ program (boost python) , which create many python >> interpreaters and each run a python script with use multi-thread >> (threading). >> when the c++ main program exit, I want to shut down python >> interpreaters, but it crashed. I have googled a lot but cant get any >> clue. >> here is my code, your suggestion will be greatly appreciated. >> > > There is no clean way to terminate a thread cleanly from outside. You > need to let the thread terminates by itself. If it is a pure python > code, this can be done by one of: > 1) setting a global/thread stop value that is checked by each threads > 2) inserting a QUIT event to the event-loop > > > I have never used boost before, so I don't know what it can and cannot > do from outside the python's interpreter. However, this should give you > an idea of what to do... From kongcheng1400 at gmail.com Tue Jun 9 21:44:07 2009 From: kongcheng1400 at gmail.com (kongcheng1400 at gmail.com) Date: Tue, 9 Jun 2009 18:44:07 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: <34c08046-aeae-460f-87e9-dd72e0639b8d@v4g2000vba.googlegroups.com> On Jun 10, 7:41?am, "Gabriel Genellina" wrote: > En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > > > ? ?I have an embedded python application. which is ?a MFC app with > > Python interpreter embedded. > > > ? ?In the App, I have a separate thread to execute a Python script > > (using the PyRun_File), but if the user want to stop the executing > > script, how should I do? > > > A possible way is terminate the thread of executing the scripts by > > TerminateThread(). but TerminateThread() is unsafe and not > > recommended. > > > guys, could you guide me on this? > > You could use PyThreadState_SetAsyncExc (to "inject" an exception), or ? > perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a ? > KeyboardInterrupt). This should work fine for well-behaved scripts, but if ? > it ignores all exceptions like this: > ? ? ? ? try: ... > ? ? ? ? except: pass > you'll have to look at ceval.c how to break out of the running loop. > > (this is yet another argument against indiscriminately using a bare except ? > clause...) > > -- > Gabriel Genellina Thanks Very much, You are always kindly helping me. From dcest61 at hotmail.com Tue Jun 9 22:08:36 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Wed, 10 Jun 2009 02:08:36 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Lew wrote: >>>>> Interesting distinction. Would it be fair to compare concurrent >>>>> programming to the bricks used to build the parallel program's edifice? >>>> Way too much of a fine distinction. While they are in fact different, >>>> the point of concurrent programming is to structure programs as a group >>>> of computations, which can be executed in parallel (however that might >>>> actually be done depending on how many processors there are). >>> No. Concurrent programming is about interleaving computations in order to >>> reduce latency. Nothing to do with parallelism. >> Jon, I do concurrent programming all the time, as do most of my peers. >> Way down on the list of why we do it is the reduction of latency. > > What is higher on the list? Correctness. I'm not being facetious. I write applications that run on application servers, and from time to time I have had to write various special purpose servers. This kind of programming is all about managing concurrent execution of computations. The overarching concern is reliability and correct function. For many corporate situations, even with hundreds of users, the actual load at any instant is low enough that the various servers involved are nowhere close to being stressed out - performance is a secondary issue. AHS From steven at REMOVE.THIS.cybersource.com.au Tue Jun 9 23:24:07 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 03:24:07 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > The docs are now... sort of correct. For some values of a and b, > uniform() can never return b. Notably, I believe uniform(0, 1) is > equivalent to random(), and will never return 1. However, uniform(1, 2) > CAN return 2, if this is any indication: > > >>>> a=0.0 >>>> b=1.0 >>>> a+(b-a)*z < b > True >>>> a=1.0 >>>> b=2.0 >>>> a+(b-a)*z < b > False But you haven't shown what value z has, so there's no way of interpreting that example. I'd say that uniform(1, 2) should NOT return 2, at least for systems which round correctly. Given a random z such that: 0 <= z < 1 and two floats a, b such that: a < b (b is strictly the larger of the two) then: 0 <= z < 1 Multiply all sides by (b-a): 0 <= (b-a)*z < (b-a) Add a to all sides: a <= a + (b-a)*z < b Hence uniform(a, b) should always return a result less than b, and greater or equal to a. However, there is one proviso: floats are not reals. The above holds true for real numbers, but floats are subject to weird rounding effects. That means that there may be weird edge cases where Bad Things happen and things cancel catastrophically or round incorrectly. A realistic edge case is that a + (b-a) doesn't always give b: >>> a = -1e90 >>> b = 1.0 >>> a < b True >>> a + (b-a) == b False >>> a + (b-a) 0.0 However, even in this case, it merely narrows the range of possible results, it doesn't widen it. -- Steven From mr.william.clifford at gmail.com Tue Jun 9 23:58:54 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Tue, 9 Jun 2009 20:58:54 -0700 (PDT) Subject: graph edge generators Message-ID: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> I've become interested in basic graphs and networks and I'm wondering about what algorithms are there for generating basic regular graphs like the simplex graph or dodecahedron graph, etc (I'm sure there are many). I'm particularly keen on understanding the very basic functions for determining edges in the graphs. If one didn't want the complete graph but just a function generates the edges connected to a given node. I've been surfing around for this sort of info, but I'm having trouble finding stuff at my level. If anyone knows of any resources or tutorials or that sort of thing, I'd like to hear about those too. Thanks! -- William Clifford From wuwei23 at gmail.com Wed Jun 10 00:01:46 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:01:46 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> Message-ID: <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> On Jun 10, 11:32?am, John Yeung wrote: > On Jun 9, 8:39?pm, Paul McGuire wrote: > > Are you trying to generate a number in the > > range [0,n] by multiplying a random function that > > returns [0,1] * n? ?If so, then you want to do > > this using: int(random.random()*(n+1)) ?This will > > give equal chance of getting any number from 0 to n. > > Better still is simply > > ? random.randint(0, n) There's a big difference between randint - which generates _integers_ in the range 0 & n - and the OPs request for generating random floating point values between & inclusive of 0 & n. From rvf0068 at gmail.com Wed Jun 10 00:03:58 2009 From: rvf0068 at gmail.com (Rafael) Date: Tue, 09 Jun 2009 23:03:58 -0500 Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: <87iqj4d9ap.fsfhello@somewhere.com> William Clifford writes: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs > like the simplex graph or dodecahedron graph, etc (I'm sure there are > many). I'm particularly keen on understanding the very basic functions > for determining edges in the graphs. If one didn't want the complete > graph but just a function generates the edges connected to a given > node. probably the SAGE system (www.sagemath.org) would be of interest to you. From mensanator at aol.com Wed Jun 10 00:04:49 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 21:04:49 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 8:28?pm, John Yeung wrote: > On Jun 9, 8:45?pm, Mensanator wrote: > > > On Jun 9, 6:05?pm, "Gabriel Genellina" wrote: > > > py> a+(b-a)*z < b # the expression used for uniform(a,b) > > > False > > > py> a+(b-a)*z > > > 11.0 > > > What you do with the number after it's created is not > > random's concern. > > Mensanator, you missed Gabriel's point. ?What he's saying is that, > effectively, random.uniform(a, b) returns a + (b - a) * random.random > (). ?So z may not be random()'s concern, but it very much is uniform > ()'s concern. > > > > The docs are already updated to reflect this:http://svn.python.org/view/python/trunk/Doc/library/random.rst?r1=687... > > > The docs are now wrong. Why would they do that? > > The docs are now... sort of correct. ? I'm not actually disputing that. I'm simply puzzled why this issue was swept under the rug by pretending it's supposed to work that way. We're not children here, you can explain that what is supposed to work in theory sometimes has problems in practice. We're not all going to abandon Python and run out and buy Mathematica. Look at how the change of random to the Mersenne Twister was handled. That's what we, the users, want to see. Otherwise, it creates endless confusion. Maybe something along the lines of "Changed in 2.6.2 to reflect the realities of floating point math." That way, when a contradiction arises, we'll know why. > For some values of a and b, > uniform() can never return b. ?Notably, I believe uniform(0, 1) is > equivalent to random(), and will never return 1. ?However, uniform(1, > 2) CAN return 2, if this is any indication: > > >>> a=0.0 > >>> b=1.0 > >>> a+(b-a)*z < b > True > >>> a=1.0 > >>> b=2.0 > >>> a+(b-a)*z < b > > False > > John From danb_83 at yahoo.com Wed Jun 10 00:06:49 2009 From: danb_83 at yahoo.com (AggieDan04) Date: Tue, 9 Jun 2009 21:06:49 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <1243c288-ee59-4110-becc-004b926d6def@i6g2000yqj.googlegroups.com> On Jun 9, 4:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? You could do random.uniform(0, 1.0000000000000002). Due to floating- point rounding, there are TWO original values that would return 1.0: 0.99999999999999978 or 0.99999999999999989; this may give you more 1.0's than you expected, and that's not even considering that Python's PRNG could be non-uniformly-distributed over the 53-bit fractions. If you're nit-picky enough to care about the less-than-winning-the- lottery chance of getting the maximum random value in the first place, this might be a problem. From wuwei23 at gmail.com Wed Jun 10 00:07:27 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:07:27 -0700 (PDT) Subject: Start the interactive shell within an application References: Message-ID: <64a786dd-eb62-40dc-98c9-05ec865546d0@s28g2000vbp.googlegroups.com> On Jun 10, 1:40?am, Ben Charrow wrote: > If you're looking to debug your program, try "import pdb" Another option, if you wish to debug an error, is to run python using the -i parameter. This will leave you inside the interpreter at the point that execution stops. Very handy. - alex23 From 504crank at gmail.com Wed Jun 10 00:13:33 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:13:33 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator Message-ID: By what method would a string be inserted at each instance of a RegEx match? For example: string = '123 abc 456 def 789 ghi' newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Here's the code I started with: >>> rePatt = re.compile('\d+\s') >>> iterator = rePatt.finditer(string) >>> count = 0 >>> for match in iterator: if count < 1: print string[0:match.start()] + ' INSERT ' + string[match.start ():match.end()] elif count >= 1: print ' INSERT ' + string[match.start():match.end()] count = count + 1 My code returns an empty string. I'm new to Python, but I'm finding it really enjoyable (with the exception of this challenging puzzle). Thanks in advance. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 00:15:00 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 04:15:00 GMT Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 20:58:54 -0700, William Clifford wrote: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs like > the simplex graph or dodecahedron graph, etc (I'm sure there are many). > I'm particularly keen on understanding the very basic functions for > determining edges in the graphs. If one didn't want the complete graph > but just a function generates the edges connected to a given node. > > I've been surfing around for this sort of info, but I'm having trouble > finding stuff at my level. If anyone knows of any resources or tutorials > or that sort of thing, I'd like to hear about those too. I'm not sure what your level is, but you might find these helpful: http://www.python.org/doc/essays/graphs/ http://neopythonic.blogspot.com/2009/01/detecting-cycles-in-directed-graph.html -- Steven From roy at panix.com Wed Jun 10 00:19:08 2009 From: roy at panix.com (Roy Smith) Date: Wed, 10 Jun 2009 00:19:08 -0400 Subject: How to insert string in each match using RegEx iterator References: Message-ID: In article , "504crank at gmail.com" <504crank at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' If you want to do what I think you are saying, you should be looking at the join() string method. I'm thinking something along the lines of: groups = match_object.groups() newstring = " INSERT ".join(groups) From wuwei23 at gmail.com Wed Jun 10 00:19:41 2009 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Jun 2009 21:19:41 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> Message-ID: <45c999ce-ec0d-4470-b337-fd77ea6196b8@j20g2000vbp.googlegroups.com> On Jun 10, 8:00?am, rh0dium wrote: > Apparently there is a problem with the if statement??? Try restructuring the if as a ternary condition: import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); smsc = smsc if os.path.isdir(smsc) else "/home/tech"; site.addsitedir (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- packages")) From ebonak at hotmail.com Wed Jun 10 00:23:11 2009 From: ebonak at hotmail.com (Esmail) Date: Wed, 10 Jun 2009 00:23:11 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Here is part of the specification of an algorithm I'm implementing that shows the reason for my original query: vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) xid = xid + vid (1b) where c1 and c2 are two positive constants, rand() and Rand() are two random functions in the range [0,1], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and w is the inertia weight. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 00:28:56 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 04:28:56 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 21:04:49 -0700, Mensanator wrote: > On Jun 9, 8:28?pm, John Yeung wrote: >> On Jun 9, 8:45?pm, Mensanator wrote: >> >> > On Jun 9, 6:05?pm, "Gabriel Genellina" >> > wrote: >> > > py> a+(b-a)*z < b # the expression used for uniform(a,b) False >> > > py> a+(b-a)*z >> > > 11.0 >> >> > What you do with the number after it's created is not random's >> > concern. >> >> Mensanator, you missed Gabriel's point. ?What he's saying is that, >> effectively, random.uniform(a, b) returns a + (b - a) * random.random >> (). ?So z may not be random()'s concern, but it very much is uniform >> ()'s concern. >> >> > > The docs are already updated to reflect >> > > this:http://svn.python.org/view/python/trunk/Doc/library/ random.rst?r1=687... >> >> > The docs are now wrong. Why would they do that? >> >> The docs are now... sort of correct. ? > > I'm not actually disputing that. Funny, saying "The docs are now wrong" sure sounds like you're disputing that they're correct to me! > I'm simply puzzled why this issue was > swept under the rug by pretending it's supposed to work that way. I'm completely confused. What is "this issue", and why are we "pretending" that it's supposed to work "that way"? Yes, I've read the thread. I still have no idea what you are complaining about. > We're > not children here, you can explain that what is supposed to work in > theory sometimes has problems in practice. We're not all going to > abandon Python and run out and buy Mathematica. > > Look at how the change of random to the Mersenne Twister was handled. > That's what we, the users, want to see. Speak for yourself. What about the change that you think "we, the users", want to see? > Otherwise, it creates endless confusion. Not as confused as this discussion. -- Steven From steven.klass at gmail.com Wed Jun 10 00:30:09 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 21:30:09 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <45c999ce-ec0d-4470-b337-fd77ea6196b8@j20g2000vbp.googlegroups.com> Message-ID: <2efd72e8-a683-46f3-bfc6-241626f181bf@l12g2000yqo.googlegroups.com> On Jun 9, 9:19?pm, alex23 wrote: > On Jun 10, 8:00?am, rh0dium wrote: > > > Apparently there is a problem with the if statement??? > > Try restructuring the if as a ternary condition: > > import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); smsc > = smsc if os.path.isdir(smsc) else "/home/tech"; site.addsitedir > (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site- > packages")) Bingo - Nice Job!! Thanks! I had to look up ternary conditions!! That's new for me (http://en.wikipedia.org/wiki/Ternary_operation) From steven.klass at gmail.com Wed Jun 10 00:33:56 2009 From: steven.klass at gmail.com (rh0dium) Date: Tue, 9 Jun 2009 21:33:56 -0700 (PDT) Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: On Jun 9, 4:58?pm, David Lyon wrote: > On Tue, 9 Jun 2009 16:30:06 -0700 (PDT), rh0dium > wrote: > > >> > Apparently there is a problem with the if statement??? > > >> > Thanks > > > No for .pth files this needs to be on a single line.. > > I can't really see why you need conditional code... > > If you want to add more locations... > > Simply create another .PTH file..... > > Having multiple paths or multiple .PTH files isn't a > problem for python. > > David We use it for our dev tree before we roll to production. Once dev is QA'd then we (integrate) those changes to main and release. From 504crank at gmail.com Wed Jun 10 00:35:37 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:35:37 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 9, 11:19?pm, Roy Smith wrote: > In article > , > > ?"504cr... at gmail.com" <504cr... at gmail.com> wrote: > > By what method would a string be inserted at each instance of a RegEx > > match? > > > For example: > > > string = '123 abc 456 def 789 ghi' > > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > If you want to do what I think you are saying, you should be looking at the > join() string method. ?I'm thinking something along the lines of: > > groups = match_object.groups() > newstring = " INSERT ".join(groups) Fast answer, Roy. Thanks. That would be a graceful solution if it works. I'll give it a try and post a solution. Meanwhile, I know there's a logical problem with the way I was concatenating strings in the iterator loop. Here's a single instance example of what I'm trying to do: >>> string = 'abc 123 def 456 ghi 789' >>> match = rePatt.search(string) >>> print string[0:match.start()] + 'INSERT ' + string[match.end():len(string)] abc INSERT def 456 ghi 789 From david.lyon at preisshare.net Wed Jun 10 00:37:15 2009 From: david.lyon at preisshare.net (David Lyon) Date: Wed, 10 Jun 2009 00:37:15 -0400 Subject: .pth files and figuring out valid paths.. In-Reply-To: References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: <955209ed293fd8185186e966b4b92892@preisshare.net> On Tue, 9 Jun 2009 21:33:56 -0700 (PDT), rh0dium wrote: >> Having multiple paths or multiple .PTH files isn't a >> problem for python. > .. > We use it for our dev tree before we roll to production. Once dev is > QA'd then we (integrate) those changes to main and release. Makes sense... :-) I was just wondering... From 504crank at gmail.com Wed Jun 10 00:52:36 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Tue, 9 Jun 2009 21:52:36 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 9, 11:35?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > On Jun 9, 11:19?pm, Roy Smith wrote: > > > > > In article > > , > > > ?"504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > > match? > > > > For example: > > > > string = '123 abc 456 def 789 ghi' > > > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > > If you want to do what I think you are saying, you should be looking at the > > join() string method. ?I'm thinking something along the lines of: > > > groups = match_object.groups() > > newstring = " INSERT ".join(groups) > > Fast answer, Roy. Thanks. That would be a graceful solution if it > works. I'll give it a try and post a solution. > > Meanwhile, I know there's a logical problem with the way I was > concatenating strings in the iterator loop. > > Here's a single instance example of what I'm trying to do: > > >>> string = 'abc 123 def 456 ghi 789' > >>> match = rePatt.search(string) > >>> print string[0:match.start()] + 'INSERT ' + string[match.end():len(string)] > > abc INSERT def 456 ghi 789 Thanks Roy. A little closer to a solution. I'm still processing how to step forward, but this is a good start: >>> string = 'abc 123 def 456 ghi 789' >>> rePatt = re.compile('\s\d+\s') >>> foundGroup = rePatt.findall(string) >>> newstring = ' INSERT '.join(foundGroup) >>> print newstring 123 INSERT 456 What I really want to do is return the full string, not just the matches -- concatenated around the ' INSERT ' string. From gallium.arsenide at gmail.com Wed Jun 10 01:21:26 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 22:21:26 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 9, 11:24?pm, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > > The docs are now... sort of correct. ?For some values of a and b, > > uniform() can never return b. ?Notably, I believe uniform(0, 1) is > > equivalent to random(), and will never return 1. ?However, uniform(1, 2) > > CAN return 2, if this is any indication: > > >>>> a=0.0 > >>>> b=1.0 > >>>> a+(b-a)*z < b > > True > >>>> a=1.0 > >>>> b=2.0 > >>>> a+(b-a)*z < b > > False > > But you haven't shown what value z has, so there's no way of interpreting > that example. I'm pretty aggressive about snipping. I left off the quote of z from Gabriel. He chose z to be the largest value that random.random() can return; namely, the largest float smaller than 1. I've just carried over that value into my example. The point of my example is, with z < 1, uniform(0, 1) is always less than 1, but with z < 1, uniform(1, 2) can be 2, according to Gabriel's description of uniform(). Therefore, to me the most up-to-date docs (which say that uniform(a, b) returns a float in the closed interval [a, b]) is closer to correct than before, but still fails to point out the full subtlety of the behavior. John From gallium.arsenide at gmail.com Wed Jun 10 01:24:55 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 22:24:55 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> Message-ID: <0581c89e-4e61-4a9b-9032-cfcd1b88ef81@y9g2000yqg.googlegroups.com> On Jun 10, 12:01?am, alex23 wrote: > On Jun 10, 11:32?am, John Yeung wrote: > > > On Jun 9, 8:39?pm, Paul McGuire wrote: > > > Are you trying to generate a number in the > > > range [0,n] by multiplying a random function that > > > returns [0,1] * n? ?If so, then you want to do > > > this using: int(random.random()*(n+1)) ?This will > > > give equal chance of getting any number from 0 to n. > > > Better still is simply > > > ? random.randint(0, n) > > There's a big difference between randint - which generates _integers_ > in the range 0 & n - and the OPs request for generating random > floating point values between & inclusive of 0 & n. Alex, did you bother to read what I quoted? Paul McGuire suggested an alternative in case the OP was choosing integers in a roundabout way. I was merely pointing out that Paul's solution can be more simply achieved using a library function. John From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 01:52:01 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Jun 2009 05:52:01 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > On Jun 9, 11:24?pm, Steven D'Aprano > wrote: >> On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: >> > The docs are now... sort of correct. ?For some values of a and b, >> > uniform() can never return b. ?Notably, I believe uniform(0, 1) is >> > equivalent to random(), and will never return 1. ?However, uniform(1, >> > 2) CAN return 2, if this is any indication: >> >> >>>> a=0.0 >> >>>> b=1.0 >> >>>> a+(b-a)*z < b >> > True >> >>>> a=1.0 >> >>>> b=2.0 >> >>>> a+(b-a)*z < b >> > False >> >> But you haven't shown what value z has, so there's no way of >> interpreting that example. > > I'm pretty aggressive about snipping. I left off the quote of z from > Gabriel. He chose z to be the largest value that random.random() can > return; namely, the largest float smaller than 1. I've just carried > over that value into my example. > > The point of my example is, with z < 1, uniform(0, 1) is always less > than 1, but with z < 1, uniform(1, 2) can be 2, according to Gabriel's > description of uniform(). Ah, that explains it. And you're right: >>> import random >>> class MyRandom(random.Random): ... def random(self): ... return 1.0 - 2**-53 ... >>> r = MyRandom() >>> r.uniform(1, 2) < 2 False However: >>> r.uniform(1, 10) < 10 True > Therefore, to me the most up-to-date docs (which say that uniform(a, b) > returns a float in the closed interval [a, b]) is closer to correct than > before, but still fails to point out the full subtlety of the behavior. Which is? -- Steven From mensanator at aol.com Wed Jun 10 01:54:21 2009 From: mensanator at aol.com (Mensanator) Date: Tue, 9 Jun 2009 22:54:21 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <6bdfae00-db9a-42f4-865f-500eaf35881a@e21g2000yqb.googlegroups.com> On Jun 9, 11:28?pm, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 21:04:49 -0700, Mensanator wrote: > > On Jun 9, 8:28 pm, John Yeung wrote: > >> On Jun 9, 8:45 pm, Mensanator wrote: > > >> > On Jun 9, 6:05 pm, "Gabriel Genellina" > >> > wrote: > >> > > py> a+(b-a)*z < b # the expression used for uniform(a,b) False > >> > > py> a+(b-a)*z > >> > > 11.0 > > >> > What you do with the number after it's created is not random's > >> > concern. > > >> Mensanator, you missed Gabriel's point. What he's saying is that, > >> effectively, random.uniform(a, b) returns a + (b - a) * random.random > >> (). So z may not be random()'s concern, but it very much is uniform > >> ()'s concern. > > >> > > The docs are already updated to reflect > >> > > this:http://svn.python.org/view/python/trunk/Doc/library/ > > random.rst?r1=687... > > > > >> > The docs are now wrong. Why would they do that? > > >> The docs are now... sort of correct. > > > I'm not actually disputing that. > > Funny, saying "The docs are now wrong" sure sounds like you're disputing > that they're correct to me! Those statements were made over two hours apart. Things can change in two hours. > > > I'm simply puzzled why this issue was > > swept under the rug by pretending it's supposed to work that way. > > I'm completely confused. What is "this issue", [0,1) vs. [0,1] > and why are we > "pretending" that it's supposed to work "that way"? By changing the documentation without explaining why. If the intention was [0,1), as implied by the 2.6.1 docs, but wasn't actually doing that, it should be so stated. This isn't simply fixing a typo. > > Yes, I've read the thread. I still have no idea what you are complaining > about. According to your reply to John Young, you know exactly what the problem is. > > > We're > > not children here, you can explain that what is supposed to work in > > theory sometimes has problems in practice. We're not all going to > > abandon Python and run out and buy Mathematica. > > > Look at how the change of random to the Mersenne Twister was handled. > > That's what we, the users, want to see. > > Speak for yourself. What about the change that you think "we, the users", > want to see? Things like this: "Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence." Is that strictly necessary in the random documentation that defines what the random module does? _I_ appreciate it being there and am glad someone made the effort to put it there. If there is a change from a<=N > > Otherwise, it creates endless confusion. > > Not as confused as this discussion. I thought you said you read the thread? > > -- > Steven From davea at ieee.org Wed Jun 10 01:58:52 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 10 Jun 2009 01:58:52 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <4A2F4B9C.5080205@ieee.org> Steven D'Aprano wrote: > On Tue, 09 Jun 2009 18:28:23 -0700, John Yeung wrote: > > >> The docs are now... sort of correct. For some values of a and b, >> uniform() can never return b. Notably, I believe uniform(0, 1) is >> equivalent to random(), and will never return 1. However, uniform(1, 2) >> CAN return 2, if this is any indication: >> >> >> >>>>> a=0.0 >>>>> b=1.0 >>>>> a+(b-a)*z < b >>>>> >> True >> >>>>> a=1.0 >>>>> b=2.0 >>>>> a+(b-a)*z < b >>>>> >> False >> > > > But you haven't shown what value z has, so there's no way of interpreting > that example. > > I'd say that uniform(1, 2) should NOT return 2, at least for systems > which round correctly. Given a random z such that: > > 0 <= z < 1 > > and two floats a, b such that: > > a < b > > (b is strictly the larger of the two) then: > > 0 <= z < 1 > > Multiply all sides by (b-a): > 0 <= (b-a)*z < (b-a) > > Add a to all sides: > a <= a + (b-a)*z < b > > > Hence uniform(a, b) should always return a result less than b, and > greater or equal to a. > > However, there is one proviso: floats are not reals. The above holds true > for real numbers, but floats are subject to weird rounding effects. That > means that there may be weird edge cases where Bad Things happen and > things cancel catastrophically or round incorrectly. > > A realistic edge case is that a + (b-a) doesn't always give b: > > >>>> a = -1e90 >>>> b = 1.0 >>>> a < b >>>> > True > >>>> a + (b-a) == b >>>> > False > >>>> a + (b-a) >>>> > 0.0 > > > However, even in this case, it merely narrows the range of possible > results, it doesn't widen it. > > > Did you try to find the edge case for z ? For the following, I'm using Python 2.6.2, running on XP, on a Pentium Core Duo. I figure the highest theoretical value that random.random() should return is a number just under 1.0 The easiest way to generate that value is using the fromhex() method of float. >>> z = float.fromhex("0x1.fffffffffffffp-1") >>> z 0.99999999999999989 >>> z<1.0 True >>> z2 = 1.0 + z >>> z2 2.0 >>> z2 < 2.0 False From debatem1 at gmail.com Wed Jun 10 02:15:07 2009 From: debatem1 at gmail.com (CTO) Date: Tue, 9 Jun 2009 23:15:07 -0700 (PDT) Subject: graph edge generators References: <6c2beed1-9e7c-4796-8792-6bd34dca3e82@j32g2000yqh.googlegroups.com> Message-ID: On Jun 9, 11:58?pm, William Clifford wrote: > I've become interested in basic graphs and networks and I'm wondering > about what algorithms are there for generating basic regular graphs > like the simplex graph or dodecahedron graph, etc (I'm sure there are > many). I'm particularly keen on understanding the very basic functions > for determining edges in the graphs. If one didn't want the complete > graph but just a function generates the edges connected to a given > node. > > I've been surfing around for this sort of info, but I'm having trouble > finding stuff at my level. If anyone knows of any resources or > tutorials or that sort of thing, I'd like to hear about those too. > > Thanks! > > -- > William Clifford Depending on how much of a basis you have in CS, you may want to take a look at http://www.amazon.com/Combinatorial-Algorithms-Enumeration-Mathematics-Applications/dp/084933988X which I found to be an excellent book that covers a lot of the ground you're talking about. Also, check out graphine (graphine.org)- I think its a pretty easy-to-use graph package for python, although as the primary author I'm pretty biased. Geremy Condra From __peter__ at web.de Wed Jun 10 02:24:57 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 08:24:57 +0200 Subject: How to insert string in each match using RegEx iterator References: Message-ID: 504crank at gmail.com wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Have a look at re.sub(): >>> s = '123 abc 456 def 789 ghi' >>> re.compile(r"(\d+\s)").sub(r"INSERT \1", s) 'INSERT 123 abc INSERT 456 def INSERT 789 ghi' Peter From gallium.arsenide at gmail.com Wed Jun 10 02:25:39 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Tue, 9 Jun 2009 23:25:39 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: On Jun 10, 1:52?am, Steven D'Aprano wrote: > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > Therefore, to me the most up-to-date docs (which say > > that uniform(a, b) returns a float in the closed > > interval [a, b]) is closer to correct than before, > > but still fails to point out the full subtlety of > > the behavior. > > Which is? That uniform(a, b) will return a random float in the semi-open interval [a, b) for certain values of a and b; and in the closed interval [a, b] for other values of a and b. (Swap a and b if a > b.) To me, the fact that you sometimes get a semi-open interval and sometimes a closed interval is worth noting in the docs. John From vs at it.uu.se Wed Jun 10 03:07:00 2009 From: vs at it.uu.se (Virgil Stokes) Date: Wed, 10 Jun 2009 09:07:00 +0200 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <4A2F5B94.8010102@it.uu.se> An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Wed Jun 10 03:19:49 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Jun 2009 10:19:49 +0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: Miles Kaufmann writes: [...] > I'm curious what algorithm calls for random numbers on a closed > interval. The Box-Muller transform, polar form. At least Wikipedia says so. From Krzysztof.Retel at googlemail.com Wed Jun 10 03:19:49 2009 From: Krzysztof.Retel at googlemail.com (Krzysztof Retel) Date: Wed, 10 Jun 2009 00:19:49 -0700 (PDT) Subject: Using logging module to log into flash drive References: Message-ID: <8929b4e5-148a-4564-b1aa-20920c297a00@t11g2000vbc.googlegroups.com> On Jun 9, 7:57?pm, Carl Banks wrote: > On Jun 9, 8:57?am, kretel wrote: > > > > > Hi All, > > > I am trying to implement the following functionality: > > 1. log messages to the flash drive > > 2. if the flash drive is not available, switch handler to the > > BufferringHandler and log into buffer, > > 3. once the flash drive is plugged in and available store the logs > > from BufferHandler into that flash drive and switch the handler into > > RotateFileHandler. > > > Which approach would you suggest to use while implementing this > > functionality? One that come into my mind is to have one process or > > thread to check periodically if the flashdrive is available, and have > > a flag that will indicate that we can store the logs into the flash > > drive. But I don't particularly like this approach. > > Would you do it different way? > > Any suggestions are appreciated. > > I'd refactor the steps this way: > > 1. log messages to a buffer > 2. periodically flush the buffer to the flash drive, if it's available > > The "periodically" part could be accomplished with a thread or > scheduled delays, however suits your application. ?It might not be a > final if you need to log messages promptly, but that's how I'd begin. > > Carl Banks Hi Carl, Thanks for the advice. I haven't think about it this way, but it looks like that might be the starting point. Thanks, Krzysztof From gatti at dsdata.it Wed Jun 10 03:22:14 2009 From: gatti at dsdata.it (Lorenzo Gatti) Date: Wed, 10 Jun 2009 00:22:14 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <4e9b6c1c-46fc-446d-8ed8-38ac038bc606@g19g2000yql.googlegroups.com> On 10 Giu, 06:23, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive constants, > rand() and Rand() are two random functions in the range [0,1], > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > and w is the inertia weight. 1) I second John Yeung's suggestion: use random integers between 0 and N-1 or N inclusive and divide by N to obtain a maximum value of (N-1)/ N or 1 as you prefer. Note that N doesn't need to be very large. 2) I'm not sure a pseudo-closed range is different from a pseudo-open one. You are perturbing vid and xid by random amounts, scaled by arbitrary coefficients c1 and c2: if you multiply or divide these coefficients by (N-1)/N the minimum and maximum results for the two choices can be made identical up to floating point mangling. Regards, Lorenzo Gatti From wuwei23 at gmail.com Wed Jun 10 03:28:31 2009 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Jun 2009 00:28:31 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <9fe39d20-abdd-4a28-b74f-721c11514b8c@z14g2000yqa.googlegroups.com> <2087640c-695c-42f6-aa02-ff94d5917bb0@z5g2000vba.googlegroups.com> <0581c89e-4e61-4a9b-9032-cfcd1b88ef81@y9g2000yqg.googlegroups.com> Message-ID: <247ae78a-961d-494f-a13e-4fa9943ab74e@z19g2000vbz.googlegroups.com> On Jun 10, 3:24?pm, John Yeung wrote: > Alex, did you bother to read what I quoted? ?Paul McGuire suggested an > alternative in case the OP was choosing integers in a roundabout way. > I was merely pointing out that Paul's solution can be more simply > achieved using a library function. My apologies, John. I *did* read the quote, my brain just didn't parse it correctly. Sorry about that :) From andreengels at gmail.com Wed Jun 10 03:30:49 2009 From: andreengels at gmail.com (Andre Engels) Date: Wed, 10 Jun 2009 09:30:49 +0200 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <6faf39c90906100030i7eff28efk5c942156abe5f424@mail.gmail.com> On Wed, Jun 10, 2009 at 8:25 AM, John Yeung wrote: > That uniform(a, b) will return a random float in the semi-open > interval [a, b) for certain values of a and b; and in the closed > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > To me, the fact that you sometimes get a semi-open interval and > sometimes a closed interval is worth noting in the docs. If it is important whether "b" is included or not, apparently the difference between "b" and "the largest float smaller than b" is important. If a difference as small as that makes a difference, you should not be using floats, or random generators giving floats, anyway, but something with a higher precision. In other words, if you do care about the difference between [a, b) and [a, b], the random module is not giving what you meet even if it does give the 'right' one of those. -- Andr? Engels, andreengels at gmail.com From jpiitula at ling.helsinki.fi Wed Jun 10 03:35:01 2009 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Jun 2009 10:35:01 +0300 Subject: random number including 1 - i.e. [0,1] References: Message-ID: Esmail writes: > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. You could generate from a larger range and reject the values that you do not want: generate from [0, 2), say, until you get a value in [0, 1]. If you generate from [0, 1 + epsilon) with small epsilon, rejections will be rare. (I didn't notice this suggestion in the thread, so I'm voicing it just in case it's not there yet.) From nick at craig-wood.com Wed Jun 10 04:29:37 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 10 Jun 2009 03:29:37 -0500 Subject: setting program name, like $0= in perl? References: Message-ID: mh at pixar.com wrote: > I'm sure this is a FAQ, but I certainly haven't been able > to find an answer. > > Is it possible to set the program name as seen by the > operating system or lower-level libraries? > > I'm connecting to a database, and the runtime helpfully > sends some information to the server, such as username, > pid, and program name. > > Unfortunately, all my python programs get the name > '/usr/bin/python', and I would like to force that to > be the names of the individual scripts. You can use this module http://code.google.com/p/procname/ Just for fun I made a pure python version using ctypes ------------------------------------------------------------ #!/usr/bin/python """ Attempt to set the process name with ctypes """ import os from subprocess import Popen, PIPE from ctypes import pythonapi, c_int, c_char_p, POINTER, addressof, pointer, CDLL, memmove, memset from ctypes.util import find_library Py_GetArgcArgv = pythonapi.Py_GetArgcArgv c_lib = CDLL(find_library("c")) PR_SET_NAME = 15 # linux specific argc_t = POINTER(c_char_p) Py_GetArgcArgv.restype = None Py_GetArgcArgv.argtypes = [POINTER(c_int), POINTER(argc_t)] def set_name(name): argv = c_int(0) argc = argc_t() Py_GetArgcArgv(argv, pointer(argc)) name0 = name+"\0" memset(argc.contents, 0, 256) # could do this better! memmove(argc.contents, name0, len(name0)) # prctl doesn't seem to be needed on linux? c_lib.prctl(PR_SET_NAME, name+"\0", 0, 0, 0) def ps(): print Popen(["ps", "v", str(os.getpid())], stdout=PIPE).communicate()[0] def main(): print "Before" ps() set_name("sausage") print "After" ps() if __name__ == "__main__": main() ------------------------------------------------------------ This prints $ ./procname.py Before PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 9159 pts/7 S+ 0:00 0 1000 5551 3404 0.1 /usr/bin/python ./procname.py After PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 9159 pts/7 S+ 0:00 0 1000 5551 3420 0.1 sausage -- Nick Craig-Wood -- http://www.craig-wood.com/nick From dickinsm at gmail.com Wed Jun 10 05:01:18 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 02:01:18 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> Message-ID: <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> On Jun 10, 7:25?am, John Yeung wrote: > On Jun 10, 1:52?am, Steven D'Aprano > > wrote: > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > Therefore, to me the most up-to-date docs (which say > > > that uniform(a, b) returns a float in the closed > > > interval [a, b]) is closer to correct than before, > > > but still fails to point out the full subtlety of > > > the behavior. > > > Which is? > > That uniform(a, b) will return a random float in the semi-open > interval [a, b) for certain values of a and b; and in the closed > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > To me, the fact that you sometimes get a semi-open interval and > sometimes a closed interval is worth noting in the docs. Do you want to submit a doc patch? For practical purposes, I think you'd be hard-pressed to find a statistical test that could reliably distinguish between a large sample of values from random.uniform(a, b) and a sample from a 'perfect' uniform distribution on the closed interval [a, b]. It's true that there are values of a and b such that random.uniform(a, b) can never produce b. But for given a and b, not too close together, there may be many other values that can't be produced as well, so it hardly seems worth pointing out one particular value that can never be produced. Example: on a typical system there are almost 2**62 floats in the range [0, 1); the vast majority of these can never be produced by random.random(), which can only ever return one of 2**53 distinct values (it essentially just returns a value of the form n/2**53 with n an integer in the range [0, 2**53)). So random.uniform(0, 1) will miss lots of possible values. On the other hand, it's easy to find examples of a and b such that random.uniform(a, b) has a significant chance of producing b. For example, take a = 10**16, b = 10**16 + 4, then there's about a 1 in 4 chance of getting b. Or for a more extreme example, simply take a = b. Hence the doc change. Mark From jeanmichel at sequans.com Wed Jun 10 05:05:46 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Jun 2009 11:05:46 +0200 Subject: What is the actual type of "interrupted system call"? In-Reply-To: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> References: <4fc591ec-ed11-4a7c-ac60-f3bcf50b42ab@z19g2000vbz.googlegroups.com> Message-ID: <4A2F776A.8040703@sequans.com> mrstevegross wrote: >> exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError >> ... >> exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ >> > > Is there a single parent exception to all those? Or should I just > write it as: > > try: > ... > catch Exception: > ... > > Thanks, > --Steve > You're right, Exception is the parent of (almost) all exceptions. I wouldn't advise writing such block catching all exceptions, it makes error tracking quite difficult. However if you don't know the type of exception involved in a particular case, you can write try: ... except Exception, excInstance: print excInstance.__class__.__name__ print excInstance.__dict__ If you know how to trigger the exception, it should print the class name of the exception, along with its attributes. It will help you then write a more focused except clause. Jean-Michel From dfnsonfsduifb at gmx.de Wed Jun 10 05:29:41 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 11:29:41 +0200 Subject: Compiling Python3.1 Message-ID: <799co4F1pdqgeU1@mid.dfncis.de> Hello group, I just wanted to switch from Py3.0 to Py3.1. No luck here: [...] ar rc libpython3.1.a Python/_warnings.o Python/Python-ast.o Python/asdl.o Python/ast.o Python/bltinmodule.o Python/ceval.o Python/compile.o Python/codecs.o Python/errors.o Python/frozen.o Python/frozenmain.o Python/future.o Python/getargs.o Python/getcompiler.o Python/getcopyright.o Python/getplatform.o Python/getversion.o Python/graminit.o Python/import.o Python/importdl.o Python/marshal.o Python/modsupport.o Python/mystrtoul.o Python/mysnprintf.o Python/peephole.o Python/pyarena.o Python/pyctype.o Python/pyfpe.o Python/pymath.o Python/pystate.o Python/pythonrun.o Python/structmember.o Python/symtable.o Python/sysmodule.o Python/traceback.o Python/getopt.o Python/pystrcmp.o Python/pystrtod.o Python/dtoa.o Python/formatter_unicode.o Python/dynload_shlib.o Python/thread.o ar rc libpython3.1.a Modules/config.o Modules/getpath.o Modules/main.o Modules/gcmodule.o ar rc libpython3.1.a Modules/_threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/errnomodule.o Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o Modules/_weakref.o Modules/_functoolsmodule.o Modules/_localemodule.o Modules/_iomodule.o Modules/iobase.o Modules/fileio.o Modules/bytesio.o Modules/bufferedio.o Modules/textio.o Modules/stringio.o Modules/zipimport.o Modules/symtablemodule.o Modules/xxsubtype.o ranlib libpython3.1.a gcc -pthread -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython3.1.a -lpthread -ldl -lutil -lm Traceback (most recent call last): File "./setup.py", line 1675, in main() File "./setup.py", line 1670, in main "Tools/scripts/2to3"] File "/home/joe/Python-3.1rc1/Lib/distutils/core.py", line 149, in setup dist.run_commands() File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 921, in run_commands self.run_command(cmd) File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 940, in run_command cmd_obj.run() File "/home/joe/Python-3.1rc1/Lib/distutils/command/build.py", line 128, in run self.run_command(cmd_name) File "/home/joe/Python-3.1rc1/Lib/distutils/cmd.py", line 315, in run_command self.distribution.run_command(command) File "/home/joe/Python-3.1rc1/Lib/distutils/dist.py", line 940, in run_command cmd_obj.run() File "/home/joe/Python-3.1rc1/Lib/distutils/command/build_ext.py", line 347, in run self.build_extensions() File "./setup.py", line 102, in build_extensions missing = self.detect_modules() File "./setup.py", line 728, in detect_modules f = open(f).read() File "/home/joe/Python-3.1rc1/Lib/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 917: ordinal not in range(128) make: *** [sharedmods] Fehler 1 What can I do about that? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From deets at nospam.web.de Wed Jun 10 05:30:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 11:30:00 +0200 Subject: Where should I store docs in my project? References: Message-ID: <799ciuF1q5c4mU1@mid.uni-berlin.de> Matthew Wilson wrote: > I used paster to create a project named pitz. I'm writing a bunch of > user documentation. Where should I put it? > > The project looks a little like this: > > /home/matt/projects/pitz > setup.py > pitz/ > __init__.py # has my project code > docs/ # has my reST files > tests # has some tests > > Is there a convention for where to put the docs folder? I wouldn't put it into the pitz-package - because then these get (potentially) installed into site-packages - where no one is going to see them anyway. I'd put the docs-folder one the root-level, besides the setup.py Diez From ptmcg at austin.rr.com Wed Jun 10 06:17:01 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Jun 2009 03:17:01 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > Some might say that using a parsing library for this problem is overkill, but let me just put this out there as another data point for you. Pyparsing (http://pyparsing.wikispaces.com) supports callbacks that allow you to embellish the matched tokens, and create a new string containing the modified text for each match of a pyparsing expression. Hmm, maybe the code example is easier to follow than the explanation... from pyparsing import Word, nums, Regex # an integer is a 'word' composed of numeric characters integer = Word(nums) # or use this if you prefer integer = Regex(r'\d+') # attach a parse action to prefix 'INSERT ' before the matched token integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) # use transformString to search through the input, applying the # parse action to all matches of the given expression test = '123 abc 456 def 789 ghi' print integer.transformString(test) # prints # INSERT 123 abc INSERT 456 def INSERT 789 ghi I offer this because often the simple examples that get posted are just the barest tip of the iceberg of what the poster eventually plans to tackle. Good luck in your Pythonic adventure! -- Paul From dmitrey.kroshko at scipy.org Wed Jun 10 07:01:47 2009 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 10 Jun 2009 04:01:47 -0700 (PDT) Subject: easiest way to check python version? Message-ID: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> hi all, what is easiest way to check python version (to obtain values like 2.4, 2.5, 2.6, 3.0 etc) from Python env? I don't mean "python -V" from command prompt. Thank you in advance, D. From martin.hellwig at dcuktec.org Wed Jun 10 07:18:08 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Jun 2009 12:18:08 +0100 Subject: easiest way to check python version? In-Reply-To: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: dmitrey wrote: > hi all, > what is easiest way to check python version (to obtain values like > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > I don't mean "python -V" from command prompt. > Thank you in advance, D. You don't mean: >>> sys.version either? -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From sjmachin at lexicon.net Wed Jun 10 07:25:22 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 10 Jun 2009 04:25:22 -0700 (PDT) Subject: easiest way to check python version? References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> On Jun 10, 9:01?pm, dmitrey wrote: > hi all, > what is easiest way ?to check python version (to obtain values like > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > I don't mean "python -V" from command prompt. | >>> import sys | >>> sys.version | '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]' | >>> sys.version_info | (2, 6, 2, 'final', 0) | >>> "easiest" depends on purpose; e.g. version for display or for logging exactly what the customer is running. version_info (or a prefix of it) is the best for things like conditional imports etc E.g. py_version = sys.version_info[:2] if py_version == (2, 3): from sets import Set as set Cheers, John From a.cavallo at mailsnare.com Wed Jun 10 07:38:47 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Wed, 10 Jun 2009 12:38:47 +0100 Subject: easiest way to check python version? In-Reply-To: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> Message-ID: <200906101238.48205.a.cavallo@mailsnare.com> A common way to do it is (it is widely accepted): python -c 'import sys; print sys.version[:3]' Regards, Antonio On Wednesday 10 June 2009 12:25:22 John Machin wrote: > On Jun 10, 9:01 pm, dmitrey wrote: > > hi all, > > what is easiest way to check python version (to obtain values like > > 2.4, 2.5, 2.6, 3.0 etc) from Python env? > > I don't mean "python -V" from command prompt. > > > | >>> import sys > | >>> sys.version > | > | '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit > > (Intel)]' > > | >>> sys.version_info > | > | (2, 6, 2, 'final', 0) > > "easiest" depends on purpose; e.g. version for display or for logging > exactly what the customer is running. version_info (or a prefix of it) > is the best for things like conditional imports etc > > E.g. > py_version = sys.version_info[:2] > if py_version == (2, 3): > from sets import Set as set > > Cheers, > John From ken at seehart.com Wed Jun 10 07:40:34 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Jun 2009 04:40:34 -0700 Subject: xmlrpclib and generators Message-ID: <4A2F9BB2.6010005@seehart.com> It would be really cool if an rpc call could return a generator. I know that there are a few reasons why one would not expect it to be part of the library (e.g. the client would need to receive asynchronous messages, and it's not part of the rpc standard), however below I show a possible implementation, given that the client is also able to be a server... I am aware of MultiCall, but that is actually something like the inverse of what I want. I need a consumer. Example: ------------------------------------------------------------------------ # hypothetical client code (running at "http://rpc.myserver.com") from fancyxmlrpc import FancyXMLRPCServer server = FancyXMLRPCServer(('localhost', 9000)) def primes(): n = 2 p = [] while True: if not any( n % f == 0 for f in p ): yield n p.append( n ) n += 1 server.register_generator(primes) server.serve_forever() ------------------------------------------------------------------------ # hypothetical client code (running at http://www.mywebsite.com): from fancyxmlrpc import FancyServerProxy server_url = "http://rpc.myserver.com" local_url = "http://www.mywebsite.com" server = FancyServerProxy(server_url, local_url) g = server.examples.getStateNames() for x in g: print x ------------------------------------------------------------------------ Okay, so to implement this, the trick would be to implement the generator wrapper as a hidden xmlrpc conversation. On the client side, FancyServerProxy would encapsulate a hidden RPC server with a function that receives each item that is yielded by the server and queues them while the client generator consumes the queue and yields the items. The practical constraints of my specific application are: 1. The rpc server is a highly specialized slave system that does heavy duty work. 2. The rpc client is itself a web server that dispatches work requests to the rpc server(s) and displays the current status of work done so far. 3. The generators will typically run for a long time (hours) and yield data periodically (perhaps once a minute). 4. Trusted users will write generators on the server and consumers on the client (web site) and use the web site to make requests. 5. It would be even better if my generator yields numpy arrays rather than lists. 6. It would be nice to be able to scale to allow the web site to dispatch to multiple work servers. So my questions are: 1. Does using xmlrpc make any sense for this? 2. I am missing an easier way to do this? 3. Any good examples of things like this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From floris.bruynooghe at gmail.com Wed Jun 10 07:56:51 2009 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Wed, 10 Jun 2009 04:56:51 -0700 (PDT) Subject: multi-thread python interpreaters and c++ program References: Message-ID: <6deac4c8-b208-4fbf-8098-8dc7af7f881b@r34g2000vba.googlegroups.com> On Jun 9, 6:50?am, "myopc" wrote: > ? I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python interpreaters, > but it crashed. Your threads are daemonic, you could be seeing http://bugs.python.org/issue1856 You'll have to check your stack in a debugger to know. But as said this can be avoided by making the threads finish themself and joining them. Regards Floris From heweiwei at gmail.com Wed Jun 10 08:59:26 2009 From: heweiwei at gmail.com (BigHand) Date: Wed, 10 Jun 2009 05:59:26 -0700 (PDT) Subject: Any idea of stopping the execution of PyRun_File() References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> Message-ID: <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> On Jun 10, 7:41?am, "Gabriel Genellina" wrote: > En Mon, 08 Jun 2009 22:15:22 -0300, BigHand escribi?: > > > ? ?I have an embedded python application. which is ?a MFC app with > > Python interpreter embedded. > > > ? ?In the App, I have a separate thread to execute a Python script > > (using the PyRun_File), but if the user want to stop the executing > > script, how should I do? > > > A possible way is terminate the thread of executing the scripts by > > TerminateThread(). but TerminateThread() is unsafe and not > > recommended. > > > guys, could you guide me on this? > > You could use PyThreadState_SetAsyncExc (to "inject" an exception), or ? > perhaps PyErr_SetInterrupt (to emulate ^C, which in turn generates a ? > KeyboardInterrupt). This should work fine for well-behaved scripts, but if ? > it ignores all exceptions like this: > ? ? ? ? try: ... > ? ? ? ? except: pass > you'll have to look at ceval.c how to break out of the running loop. > > (this is yet another argument against indiscriminately using a bare except ? > clause...) > > -- > Gabriel Genellina hello.Gabriel. PyThreadState_SetAsyncExc cause me a win32 exception of "Stack overflow" > msvcr80d.dll!_getptd_noexit() Line 592 C msvcr80d.dll!_getptd() Line 658 + 0x5 bytes C msvcr80d.dll!_LocaleUpdate::_LocaleUpdate(localeinfo_struct * plocinfo=0x00000000) Line 264 + 0x5 bytes C++ msvcr80d.dll!_output_l(_iobuf * stream=0x10311d40, const char * format=0x1e26e0ac, localeinfo_struct * plocinfo=0x00000000, char * argptr=0x000333c4) Line 1028 C++ msvcr80d.dll!fprintf(_iobuf * str=0x10311d40, const char * format=0x1e26e0ac, ...) Line 70 + 0x13 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2000 + 0x19 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C python30_d.dll!PyErr_Occurred() Line 133 + 0x5 bytes C python30_d.dll!Py_FatalError(const char * msg=0x1e26a2d4) Line 2001 + 0x5 bytes C python30_d.dll!PyThreadState_Get() Line 349 + 0xa bytes C My app is a MFC app, it have the main thread and the sub thread, the sub thread run the script(Py_RunFile), That I am looking for a way to stop the Py_RunFile from the main thread. that looks like I have to use the TerminateThread() . thanks.Gabriel, could you find some example for me? From David.Shapiro at sas.com Wed Jun 10 09:08:56 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 09:08:56 -0400 Subject: getop or optparse with option with spaces? In-Reply-To: <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Hello, I have been trying to find an example of how to deal with options that have spaces in them. I am using jython, which is the same I think as python 2.2.3. I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). The code is as follows: try: (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) except getopt.GetoptError: usage() for opt in opts: (key, value) = opt if (key in ("-v", "--version")): print "Version: " + version sys.exit(1) if (key in ("-h", "--help")): usage() if (key in ("-s", "--server")): server = value if (key in ("-p", "--port")): port = value if (key in ("-n", "--dsName")): dsName = value if (key in ("-j", "--jndiName")): jndiName = value if (key in ("-d", "--driverName")): driverName = value if (key in ("-l", "--driverURL")): driverURL = value if (key in ("-u", "--user")): user = value if (key in ("-c", "--passWD")): passWD = value if (key in ("-t", "--targetServer")): targetServer = value if (key in ("-q", "--testTableName")): testTableName = value if (key in ("-w", "--whereProp")): whereProp = value print "server: " + server print "port: " + port print "dsName: " + dsName print "jndiName: " + jndiName print "driverName: " + driverName print "driverURL: " + driverURL print "user: " + user print "passWD: " + passWD print "testtable: " + testTableName print "targetServer: " + targetServer print "whereProp: " + whereProp The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get it to return the whole thing that is in double quotes? Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. Also, it just seem weird I have to do a work around like that. I could have swore using double quotes should have fixed this issue, but they do not seem to work. David From dickinsm at gmail.com Wed Jun 10 09:13:53 2009 From: dickinsm at gmail.com (dickinsm at gmail.com) Date: 10 Jun 2009 13:13:53 GMT Subject: random number including 1 - i.e. [0,1] References: Message-ID: <4a2fb191$0$90265$14726298@news.sunsite.dk> Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > [...] Here are three recipes, each more pedantic than the last. They all assume that Python floats are IEEE 754 binary64 format (which they almost certainly are on your machine), and that randrange generates all values with equal likelihood (which it almost certainly doesn't, but the assumption should be good enough for government work). import random def random1(): """Random float in [0, 1]. Generates all floats of the form n/2**53, 0 <= n <= 2**53, with equal probability. """ return random.randrange(2**53+1)/2.**53 def random2(): """Random float in [0, 1]. Generates all floats of the forn n/2**53, 0 <= n <= 2**53, with values in (0.0, 1.0) equally likely, and the endpoints 0.0 and 1.0 occuring with half the probability of any other value. This is equivalent to generating a random real number uniformly on the closed interval [0, 1] and then rounding that real number to the nearest float of the form n/2**53. """ return (random.randrange(2**54)+1)//2/2.**53 def random3(): """Random float in [0, 1]. Generates *all* floats in the interval [0.0, 1.0] (including 0.0 and 1.0, but excluding -0.0). Each float is generated with a probability corresponding to the size of the subinterval of [0, 1] that rounds to the given float under round-to-nearest. This is equivalent to generating a random real number uniformly on the closed interval [0, 1] and then rounding that real number to the nearest representable floating-point number. """ m = (random.randrange(2**53)+1)//2 e = 1022 while random.randrange(2) and e: e -= 1 return (m+2**52) * 2.**(e-1075) if e else m*2.**-1074 -- Mark Dickinson From javier.collado at gmail.com Wed Jun 10 09:37:46 2009 From: javier.collado at gmail.com (Javier Collado) Date: Wed, 10 Jun 2009 15:37:46 +0200 Subject: getop or optparse with option with spaces? In-Reply-To: References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Hello, It's strange behaviour. Have you tried argparse (http://code.google.com/p/argparse/)? I've been using it for long time without any problem like that? Best regards, Javier 2009/6/10 David Shapiro : > Hello, > > I have been trying to find an example of how to deal with options that have spaces in them. ?I am using jython, which is the same I think as python 2.2.3. ? I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). ? The code is as follows: > > ? ?try: > ? ? ? ?(opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > ? ?except getopt.GetoptError: > ? ? ? ?usage() > > ? ?for opt in opts: > ? ? ? ?(key, value) = opt > ? ? ? ?if (key in ("-v", "--version")): > ? ? ? ? ? ? ? ?print "Version: " + version > ? ? ? ? ? ? ? ?sys.exit(1) > ? ? ? ?if (key in ("-h", "--help")): > ? ? ? ? ? ? ? ?usage() > ? ? ? ?if (key in ("-s", "--server")): > ? ? ? ? ? ? ? ?server = value > ? ? ? ?if (key in ("-p", "--port")): > ? ? ? ? ? ? ? ?port = value > ? ? ? ?if (key in ("-n", "--dsName")): > ? ? ? ? ? ? ? ?dsName = value > ? ? ? ?if (key in ("-j", "--jndiName")): > ? ? ? ? ? ? ? ?jndiName = value > ? ? ? ?if (key in ("-d", "--driverName")): > ? ? ? ? ? ? ? ?driverName = value > ? ? ? ?if (key in ("-l", "--driverURL")): > ? ? ? ? ? ? ? ?driverURL = value > ? ? ? ?if (key in ("-u", "--user")): > ? ? ? ? ? ? ? ?user = value > ? ? ? ?if (key in ("-c", "--passWD")): > ? ? ? ? ? ? ? ?passWD = value > ? ? ? ?if (key in ("-t", "--targetServer")): > ? ? ? ? ? ? ? ?targetServer = value > ? ? ? ?if (key in ("-q", "--testTableName")): > ? ? ? ? ? ? ? ?testTableName = value > ? ? ? ?if (key in ("-w", "--whereProp")): > ? ? ? ? ? ? ? ?whereProp = value > > > print "server: " + server > print "port: " + port > print "dsName: " + dsName > print "jndiName: " + jndiName > print "driverName: " + driverName > print "driverURL: " + driverURL > print "user: " + user > print "passWD: " + passWD > print "testtable: " + testTableName > print "targetServer: " + targetServer > print "whereProp: " + whereProp > > The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". ?It returns back just SQL. ?How do I get it to return the whole thing that is in double quotes? ?Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? > > If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. ?A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. ?Also, it just seem weird I have to do a work around like that. ?I could have swore using double quotes should have fixed this issue, but they do not seem to work. > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From ptmcg at austin.rr.com Wed Jun 10 09:40:58 2009 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Jun 2009 06:40:58 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: <471f2ab3-b210-48d3-b1d5-57b6c3a79808@h11g2000yqb.googlegroups.com> On Jun 9, 11:23?pm, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive constants, > rand() and Rand() are two random functions in the range [0,1], > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > and w is the inertia weight. It is entirely possible that the documentation you have for the original rand() and Rand() functions have misstated their range. In my experience, rand() functions that I have worked with have always been [0,1). -- Paul From eckhardt at satorlaser.com Wed Jun 10 09:41:00 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 10 Jun 2009 15:41:00 +0200 Subject: retrieve bitwise float representation Message-ID: Hi! I need to pack a floating point value into a vector of 32-bit unsigned values in IEEE format. Further, I maintain a CRC32 checksum for integrity checking. For the latter, I actually need the float as integral value. What I currently do is this: tmp = struct.pack("=f", f) (i,) = struct.unpack("=L", tmp) IOW, I pack and unpack the float using the struct module, which works. What I'm wondering is whether there are any better or alternative ways to achieve this, the overhead now seems enormous and unnecessary to me here. Thank you! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From David.Shapiro at sas.com Wed Jun 10 09:47:54 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 09:47:54 -0400 Subject: getop or optparse with option with spaces? In-Reply-To: References: <7d1eb0f6-7e66-40eb-bf00-c2231ed4f57c@v4g2000vba.googlegroups.com> <10d8ba3a-c9b1-42b3-9009-187afbaf3b81@s16g2000vbp.googlegroups.com> Message-ID: Unfortunately, I had no luck installing argparse, which is really confusing because I would need to use some old version pre-optik to use I think. The Jython I use is like python 2.2.3. I spent all of yesterday trying to get either getopt, argparse, or optparse to work. Even with optparse I had to modify a module. For example, in textwrap.py, they have @ line 124 in the module: if self.replace_whitespace: #if isinstance(text,str): # text = text.translate(self.whitespace_trans) #elif isinstances(text,Unicode): text = text.translate(self.unicode_whitespace_trans) return text I had to comment out the if isinstance(text,str) and elif. Is the double quotes supposed to work? -----Original Message----- From: Javier Collado [mailto:javier.collado at gmail.com] Sent: Wednesday, June 10, 2009 9:38 AM To: David Shapiro Cc: python-list at python.org Subject: Re: getop or optparse with option with spaces? Hello, It's strange behaviour. Have you tried argparse (http://code.google.com/p/argparse/)? I've been using it for long time without any problem like that? Best regards, Javier 2009/6/10 David Shapiro : > Hello, > > I have been trying to find an example of how to deal with options that have spaces in them. ?I am using jython, which is the same I think as python 2.2.3. ? I feebly tried to use optparse and argparse with no success (got gettext, locale, and optparse). ? The code is as follows: > > ? ?try: > ? ? ? ?(opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > ? ?except getopt.GetoptError: > ? ? ? ?usage() > > ? ?for opt in opts: > ? ? ? ?(key, value) = opt > ? ? ? ?if (key in ("-v", "--version")): > ? ? ? ? ? ? ? ?print "Version: " + version > ? ? ? ? ? ? ? ?sys.exit(1) > ? ? ? ?if (key in ("-h", "--help")): > ? ? ? ? ? ? ? ?usage() > ? ? ? ?if (key in ("-s", "--server")): > ? ? ? ? ? ? ? ?server = value > ? ? ? ?if (key in ("-p", "--port")): > ? ? ? ? ? ? ? ?port = value > ? ? ? ?if (key in ("-n", "--dsName")): > ? ? ? ? ? ? ? ?dsName = value > ? ? ? ?if (key in ("-j", "--jndiName")): > ? ? ? ? ? ? ? ?jndiName = value > ? ? ? ?if (key in ("-d", "--driverName")): > ? ? ? ? ? ? ? ?driverName = value > ? ? ? ?if (key in ("-l", "--driverURL")): > ? ? ? ? ? ? ? ?driverURL = value > ? ? ? ?if (key in ("-u", "--user")): > ? ? ? ? ? ? ? ?user = value > ? ? ? ?if (key in ("-c", "--passWD")): > ? ? ? ? ? ? ? ?passWD = value > ? ? ? ?if (key in ("-t", "--targetServer")): > ? ? ? ? ? ? ? ?targetServer = value > ? ? ? ?if (key in ("-q", "--testTableName")): > ? ? ? ? ? ? ? ?testTableName = value > ? ? ? ?if (key in ("-w", "--whereProp")): > ? ? ? ? ? ? ? ?whereProp = value > > > print "server: " + server > print "port: " + port > print "dsName: " + dsName > print "jndiName: " + jndiName > print "driverName: " + driverName > print "driverURL: " + driverURL > print "user: " + user > print "passWD: " + passWD > print "testtable: " + testTableName > print "targetServer: " + targetServer > print "whereProp: " + whereProp > > The one that gives me trouble is with the -q option, because it can look like: -q "SQL 1 TABLE". ?It returns back just SQL. ?How do I get it to return the whole thing that is in double quotes? ?Another problem is that whereProp value is just not seen. Is there a limit to the size for argv? > > If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args instead of values by the way. ?A temporary workaround is to use " ".join(args) and assign that to testTableName, but I worry about what will happen if testTableName is blank or has something with no spaces. ?Also, it just seem weird I have to do a work around like that. ?I could have swore using double quotes should have fixed this issue, but they do not seem to work. > > David > -- > http://mail.python.org/mailman/listinfo/python-list > From flyeng4 at gmail.com Wed Jun 10 09:57:42 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 08:57:42 -0500 Subject: xml application advice Message-ID: <4A2FBBD6.6090806@gmail.com> I am writing a application to calculate pressure drop for a piping network. Namely a building sprinkler system. This will be a command line program at first with the system described in xml (at least that is how I think I want to do it). An important part of this calculation is finding the 'hydraulically most remote' sprinkler. This is something that I could specify with an attribute for now and later think about how to automate it. I need to walk through the dom tree until I find a node of type "sprinkler" that has an attribute of hydraulically_most_remote with a value of True. After I find this I need to break the itterator/for loop and then start walking backwards keeping a running total of the pressure drop until I reach a node that has multiple pipesections and then walk to the end of each branch and calculate the pressure drop, and then add them to the branch that contained the hydraulically most remote sprinkler, and then move on, repeating this until I walk all the way back to the inflow node. I am having trouble finding a decent python/xml resource on the web. I have ordered Python & XML by Jones and Drake, but I am anxious to get something started. The only decent online resource that I can seem to find is http://pyxml.sourceforge.net/topics/howto/xml-howto.html which doesn't seem to be a very comprehensive how-to. Do demonstrate just about everything I know about xml and python I attached t.py and ex.xml. Another thing that is confusing is dir(walker) does not show walker having an attribute currentNode and dir(walker.currentNode) does not show walker.currentNode having an attribute tagName. Bill -------------- next part -------------- A non-text attachment was scrubbed... Name: ex.xml Type: text/xml Size: 572 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: t.py Type: text/x-python Size: 325 bytes Desc: not available URL: From David.Shapiro at sas.com Wed Jun 10 10:11:12 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 10:11:12 -0400 Subject: xml application advice In-Reply-To: <4A2FBBD6.6090806@gmail.com> References: <4A2FBBD6.6090806@gmail.com> Message-ID: How about using web server (tomcat jsp) and then java for the xml part, which would allow you to build a nice gui for you. You can use python for backend work. If you can combine some of the levels of your xml it will be easier to traverse. I am not sure this will work for you, but I put as an example: - - - - - -----Original Message----- From: python-list-bounces+david.shapiro=sas.com at python.org [mailto:python-list-bounces+david.shapiro=sas.com at python.org] On Behalf Of William Purcell Sent: Wednesday, June 10, 2009 9:58 AM To: python-list at python.org Subject: xml application advice I am writing a application to calculate pressure drop for a piping network. Namely a building sprinkler system. This will be a command line program at first with the system described in xml (at least that is how I think I want to do it). An important part of this calculation is finding the 'hydraulically most remote' sprinkler. This is something that I could specify with an attribute for now and later think about how to automate it. I need to walk through the dom tree until I find a node of type "sprinkler" that has an attribute of hydraulically_most_remote with a value of True. After I find this I need to break the itterator/for loop and then start walking backwards keeping a running total of the pressure drop until I reach a node that has multiple pipesections and then walk to the end of each branch and calculate the pressure drop, and then add them to the branch that contained the hydraulically most remote sprinkler, and then move on, repeating this until I walk all the way back to the inflow node. I am having trouble finding a decent python/xml resource on the web. I have ordered Python & XML by Jones and Drake, but I am anxious to get something started. The only decent online resource that I can seem to find is http://pyxml.sourceforge.net/topics/howto/xml-howto.html which doesn't seem to be a very comprehensive how-to. Do demonstrate just about everything I know about xml and python I attached t.py and ex.xml. Another thing that is confusing is dir(walker) does not show walker having an attribute currentNode and dir(walker.currentNode) does not show walker.currentNode having an attribute tagName. Bill From amitds at oversi.com Wed Jun 10 10:19:53 2009 From: amitds at oversi.com (Amit Dor-Shifer) Date: Wed, 10 Jun 2009 17:19:53 +0300 Subject: Printing dictionary values rather than references Message-ID: <4A2FC109.7080709@oversi.com> Hi all. I'd like to print-out a dictionary of objects. The printed values are references. How Do I print the actual objects. class MyClass: def __str__(self): return str(self.__dict__) if __name__ == '__main__': dict = dict() classA = MyClass() setattr(classA, "attr-1", "val-1") dict['a']= classA print classA ''' Desired output: {'attr-1': 'val-1'}''' print dict ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' Thanks, Amit From dickinsm at gmail.com Wed Jun 10 10:24:56 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 14:24:56 GMT Subject: retrieve bitwise float representation References: Message-ID: <4a2fc238$0$90272$14726298@news.sunsite.dk> Ulrich Eckhardt wrote: > Hi! > > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > [...] You could try using frexp to extract the significand and exponent of the float, and then pack those values directly into an integer, following the IEEE 754 format. For example: Python 2.6.2 (r262:71600, Jun 8 2009, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from struct import pack, unpack >>> from math import frexp, copysign >>> x = -34.125 >>> unpack('>> m, e = frexp(abs(x)) >>> (e+125 << 23) + int(m*2.**24) + (2**31 if x < 0.0 else 0) 3255336960L The above formula works for most x that are exactly representable as an IEEE single-precision value, but extra effort would be required to make it work with nans, infinities, zeros or denormals. I'm not sure whether this is any faster than the pack/unpack route, though. Obviously, if you're going to convert many floats then the 2.**24 and 2**31 constants should be precalculated. If your values aren't already exactly representable as IEEE single-precision floats then you may have a problem with rounding: the call to int() in the above would truncate, while the implicit conversion from double to single precision involved in packing with 'f' is more likely to do a round-to-nearest. -- Mark Dickinson From metalzong at 163.com Wed Jun 10 10:25:24 2009 From: metalzong at 163.com (Metal Zong) Date: Wed, 10 Jun 2009 22:25:24 +0800 Subject: Can not dump class object created on runtime Message-ID: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Hello, Can not dump class object created on runtime. Is there anybody can help me? Thank. Following is testing code: import pickle from new import classobj class A: def __str__(self): return self.__class__.name if __name__ == "__main__": c = classobj('B', (A, ), {}) # create class obj on runtime print c print pickle.dumps(c) # get dump string Bellows are outputs: __main__.B Traceback (most recent call last): File "C:\USERS\train\_work\test\test.py", line 11, in print pickle.dumps(c) File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump self.save(obj) File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle : it's not found as __main__.B - Tommy HZ 23026 MP 13958175281 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Samnsparky at gmail.com Wed Jun 10 10:26:22 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 10 Jun 2009 07:26:22 -0700 (PDT) Subject: Connection tester Message-ID: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Hey! I am developing a small application that tests multiple websites and compares their "response time". Some of these sites do not respond to a ping and, for the measurement to be standardized, all sites must have the same action preformed upon them. Another problem is that not all of the sites have the same page size and I am not interested in how long it takes to load a page but instead just how long it takes for the website to respond. Finally, I am looking to keep this script platform independent, if at all possible. Here is the code: try: # Get the starting time origTime = time.time() # Create the socket connection and then close s = socket.socket(AF_INET, SOCK_STREAM) s.connect((targetIP, port)) s.send("GET / HTTP/1.0\r\n\r\n") result = s.recv(1024) s.shutdown(SHUT_RDWR) except: result = "" # Check for problems and report back the time if result == "": return Result((time.time() - origTime) * 1000, True) else: return Result((time.time() - origTime) * 1000, False) Result is just an object that holds the time it took for the method to finish and if there were any errors. What I am worried about is that the socket is potentially closed before the website can finish sending in all the data. Does anyone have any suggestions or is the script fine as it is? From __peter__ at web.de Wed Jun 10 10:26:46 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 16:26:46 +0200 Subject: retrieve bitwise float representation References: Message-ID: Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > What I currently do is this: > > tmp = struct.pack("=f", f) > (i,) = struct.unpack("=L", tmp) > > IOW, I pack and unpack the float using the struct module, which works. > > > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. binascii.crc32() operates on strings, so you don't need to unpack. If you have many float values array.array() should be more effective than struct.pack(). >>> some_floats = map(float, range(5)) >>> binascii.crc32(array.array("f", some_floats)) 1758053516 From briandenzer at gmail.com Wed Jun 10 10:36:33 2009 From: briandenzer at gmail.com (Brian D) Date: Wed, 10 Jun 2009 07:36:33 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 5:17?am, Paul McGuire wrote: > On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put this out there as another data point for > you. ?Pyparsing (http://pyparsing.wikispaces.com) supports callbacks > that allow you to embellish the matched tokens, and create a new > string containing the modified text for each match of a pyparsing > expression. ?Hmm, maybe the code example is easier to follow than the > explanation... > > from pyparsing import Word, nums, Regex > > # an integer is a 'word' composed of numeric characters > integer = Word(nums) > > # or use this if you prefer > integer = Regex(r'\d+') > > # attach a parse action to prefix 'INSERT ' before the matched token > integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) > > # use transformString to search through the input, applying the > # parse action to all matches of the given expression > test = '123 abc 456 def 789 ghi' > print integer.transformString(test) > > # prints > # INSERT 123 abc INSERT 456 def INSERT 789 ghi > > I offer this because often the simple examples that get posted are > just the barest tip of the iceberg of what the poster eventually plans > to tackle. > > Good luck in your Pythonic adventure! > -- Paul Thanks for all of the instant feedback. I have enumerated three responses below: First response: Peter, I wonder if you (or anyone else) might attempt a different explanation for the use of the special sequence '\1' in the RegEx syntax. The Python documentation explains: \number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters. In practice, this appears to be the key to the key device to your clever solution: >>> re.compile(r"(\d+)").sub(r"INSERT \1", string) 'abc INSERT 123 def INSERT 456 ghi INSERT 789' >>> re.compile(r"(\d+)").sub(r"INSERT ", string) 'abc INSERT def INSERT ghi INSERT ' I don't, however, precisely understand what is meant by "the group of the same number" -- or maybe I do, but it isn't explicit. Is this just a shorthand reference to match.group(1) -- if that were valid -- implying that the group match result is printed in the compile execution? Second response: I've encountered a problem with my RegEx learning curve which I'll be posting in a new thread -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 Third response: Paul, Thanks for the referring me to the Pyparsing module. I'm thoroughly enjoying Python, but I'm not prepared right now to say I've mastered the Pyparsing module. As I continue my work, however, I'll be tackling the problem of parsing addresses, exactly as the Pyparsing module example illustrates. I'm sure I'll want to use it then. From 504crank at gmail.com Wed Jun 10 10:39:41 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Wed, 10 Jun 2009 07:39:41 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 5:17?am, Paul McGuire wrote: > On Jun 9, 11:13?pm, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put this out there as another data point for > you. ?Pyparsing (http://pyparsing.wikispaces.com) supports callbacks > that allow you to embellish the matched tokens, and create a new > string containing the modified text for each match of a pyparsing > expression. ?Hmm, maybe the code example is easier to follow than the > explanation... > > from pyparsing import Word, nums, Regex > > # an integer is a 'word' composed of numeric characters > integer = Word(nums) > > # or use this if you prefer > integer = Regex(r'\d+') > > # attach a parse action to prefix 'INSERT ' before the matched token > integer.setParseAction(lambda tokens: "INSERT " + tokens[0]) > > # use transformString to search through the input, applying the > # parse action to all matches of the given expression > test = '123 abc 456 def 789 ghi' > print integer.transformString(test) > > # prints > # INSERT 123 abc INSERT 456 def INSERT 789 ghi > > I offer this because often the simple examples that get posted are > just the barest tip of the iceberg of what the poster eventually plans > to tackle. > > Good luck in your Pythonic adventure! > -- Paul Thanks for all of the instant feedback. I have enumerated three responses below: First response: Peter, I wonder if you (or anyone else) might attempt a different explanation for the use of the special sequence '\1' in the RegEx syntax. The Python documentation explains: \number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters. In practice, this appears to be the key to the key device to your clever solution: >>> re.compile(r"(\d+)").sub(r"INSERT \1", string) 'abc INSERT 123 def INSERT 456 ghi INSERT 789' >>> re.compile(r"(\d+)").sub(r"INSERT ", string) 'abc INSERT def INSERT ghi INSERT ' I don't, however, precisely understand what is meant by "the group of the same number" -- or maybe I do, but it isn't explicit. Is this just a shorthand reference to match.group(1) -- if that were valid -- implying that the group match result is printed in the compile execution? Second response: I've encountered a problem with my RegEx learning curve which I'll be posting in a new thread -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 Third response: Paul, Thanks for the referring me to the Pyparsing module. I'm thoroughly enjoying Python, but I'm not prepared right now to say I've mastered the Pyparsing module. As I continue my work, however, I'll be tackling the problem of parsing addresses, exactly as the Pyparsing module example illustrates. I'm sure I'll want to use it then. From David.Shapiro at sas.com Wed Jun 10 10:41:36 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 10:41:36 -0400 Subject: Connection tester Message-ID: Not al pages suppost GET. If a page pings and returns does not mean it can be logged into and work (maybe database down). Have you seen soapui? ----- Original Message ----- From: python-list-bounces+david.shapiro=sas.com at python.org To: python-list at python.org Sent: Wed Jun 10 10:26:22 2009 Subject: Connection tester Hey! I am developing a small application that tests multiple websites and compares their "response time". Some of these sites do not respond to a ping and, for the measurement to be standardized, all sites must have the same action preformed upon them. Another problem is that not all of the sites have the same page size and I am not interested in how long it takes to load a page but instead just how long it takes for the website to respond. Finally, I am looking to keep this script platform independent, if at all possible. Here is the code: try: # Get the starting time origTime = time.time() # Create the socket connection and then close s = socket.socket(AF_INET, SOCK_STREAM) s.connect((targetIP, port)) s.send("GET / HTTP/1.0\r\n\r\n") result = s.recv(1024) s.shutdown(SHUT_RDWR) except: result = "" # Check for problems and report back the time if result == "": return Result((time.time() - origTime) * 1000, True) else: return Result((time.time() - origTime) * 1000, False) Result is just an object that holds the time it took for the method to finish and if there were any errors. What I am worried about is that the socket is potentially closed before the website can finish sending in all the data. Does anyone have any suggestions or is the script fine as it is? -- http://mail.python.org/mailman/listinfo/python-list From jon at ffconsultancy.com Wed Jun 10 10:44:05 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 10 Jun 2009 15:44:05 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Arved Sandstrom wrote: > Jon Harrop wrote: >> Arved Sandstrom wrote: >>> Jon Harrop wrote: >>>> No. Concurrent programming is about interleaving computations in order >>>> to reduce latency. Nothing to do with parallelism. >>> >>> Jon, I do concurrent programming all the time, as do most of my peers. >>> Way down on the list of why we do it is the reduction of latency. >> >> What is higher on the list? > > Correctness. > > I'm not being facetious. I write applications that run on application > servers, and from time to time I have had to write various special > purpose servers. This kind of programming is all about managing > concurrent execution of computations. The overarching concern is > reliability and correct function. For many corporate situations, even > with hundreds of users, the actual load at any instant is low enough > that the various servers involved are nowhere close to being stressed > out - performance is a secondary issue. In other words, without concurrency the latency would be so high that you would consider the program to be wrong. However you cut it, the real reason is latency. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From mail at microcorp.co.za Wed Jun 10 10:44:10 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 10 Jun 2009 16:44:10 +0200 Subject: xmlrpclib and generators References: <4A2F9BB2.6010005@seehart.com> Message-ID: <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> Ken Seehart wrote: 8< ------------ implementation -------------- >The practical constraints of my specific application are: >1. The rpc server is a highly specialized slave system that does heavy duty work. >2. The rpc client is itself a web server that dispatches work requests to the rpc server(s) and displays the >current status of work done so far. >3. The generators will typically run for a long time (hours) and yield data periodically (perhaps once a minute). If this "yield" can be made to be, or if it is, supply side driven, instead of yielding on demand like a generator, then I would set up a simple TCP/IP peer to peer socket link and just send the result back when it is ready. If you have to "serve" more than one such link, it is a simple matter to keep a list of queues linking the different socket sets to the "generator", and to iterate over the list, putting a copy of the thing that was just produced into each queue. Of course, the thing you want to pass back must be serializable. Have you looked at Pyro? So my questions are: 1. Does using xmlrpc make any sense for this? I think you are going to have to do some heavy lifting to get it to work. 2. I am missing an easier way to do this? Maybe - see above - depends on how the stuff is generated 3. Any good examples of things like this? Don't know. - Hendrik From 504crank at gmail.com Wed Jun 10 10:47:13 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Wed, 10 Jun 2009 07:47:13 -0700 (PDT) Subject: How to escape # hash character in regex match strings Message-ID: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> I've encountered a problem with my RegEx learning curve -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#abc456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 The correct result should be: 123456 I've tried to escape the hash symbol in the match string without result. Any ideas? Is the answer something I overlooked in my lurching Python schooling? From deets at nospam.web.de Wed Jun 10 10:49:20 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 16:49:20 +0200 Subject: xml application advice References: Message-ID: <799v9lF1pj8gqU1@mid.uni-berlin.de> William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). > > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. The only decent online resource that I can > seem to find is > > http://pyxml.sourceforge.net/topics/howto/xml-howto.html > > which doesn't seem to be a very comprehensive how-to. > > Do demonstrate just about everything I know about xml and python I > attached t.py and ex.xml. > > Another thing that is confusing is dir(walker) does not show walker > having an attribute currentNode and dir(walker.currentNode) does not > show walker.currentNode having an attribute tagName. Use lxml2 and xpath. http://codespeak.net/lxml/ http://codespeak.net/lxml/xpathxslt.html See the below piece of code to get you started: import lxml.etree as et xml = """ """ project = et.fromstring(xml) hydraulically_most_remote = project.xpath("//node[@hydraulically_most_remote='True']")[0] print hydraulically_most_remote.attrib["id"] # find node with multiple pipesections that's upwards def find_mp_node(node): pipesections = node.xpath("pipesection") if len(pipesections) > 1: return node parent = node.getparent() if parent is not None: return find_mp_node(parent) print find_mp_node(hydraulically_most_remote).attrib["id"] From massung at gmail.com Wed Jun 10 10:50:37 2009 From: massung at gmail.com (Jeff M.) Date: Wed, 10 Jun 2009 07:50:37 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: On Jun 9, 9:08?pm, Arved Sandstrom wrote: > Jon Harrop wrote: > > > > Arved Sandstrom wrote: > >> > >> Jon, I do concurrent programming all the time, as do most of my peers. > >> Way down on the list of why we do it is the reduction of latency. > > > What is higher on the list? > > Correctness. > IMO, that response is a bit of a cop-out. Correctness is _always_ most important, no matter what application you are creating; without it, you don't have a job and the company you work for goes out of business. But, assuming that your program works and does what it's supposed to, I agree with Jon that performance needs to be right near the top of the list of concerns. Why? Performance isn't about looking good as a programmer, or having fun making a function run in 15 cycles instead of 24, or coming up with some neat bit packing scheme so that your app now only uses 20K instead of 200K. Performance is - pure and simple - about one thing only: money. Programs that use more memory require more money for the hardware of every user. Programs that run slower eat more time per day. If you have 100,000 users, all doing an operation once per day that takes 20 seconds, being able to shave 5 seconds off that saves 5.78 man-days of work. Hell, for some applications, that 20 seconds is just startup time spent at a splash screen. Just imagine if every Google search took even 5 seconds to resolve, how much time would be wasted every day around the world - ignoring the fact that Google wouldn't exist if that were the case ;-). Obviously Google engineers work incredibly hard every day to ensure correct results, but performance better be right up there at the top of the list as well. Jeff M. From Scott.Daniels at Acm.Org Wed Jun 10 11:09:15 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 08:09:15 -0700 Subject: easiest way to check python version? In-Reply-To: <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> <076426ad-ecae-42c9-a10b-9033db61fb1a@g20g2000vba.googlegroups.com> Message-ID: John Machin wrote: > On Jun 10, 9:01 pm, dmitrey wrote: >> hi all, >> what is easiest way to check python version (to obtain values like >> 2.4, 2.5, 2.6, 3.0 etc) from Python env? ... > "easiest" depends on purpose; e.g. version for display or for logging > exactly what the customer is running. version_info (or a prefix of it) > is the best for things like conditional imports etc > > E.g. > py_version = sys.version_info[:2] > if py_version == (2, 3): > from sets import Set as set Note also that the definition of tuple comparison help you here: if (2, 1, 1) < sys.version_info < (2, 3): ... elif (2, 5) <= sys.version_info <= (2, 6, 2, 'final'): ... else: print('Untested') --Scott David Daniels Scott.Daniels at Acm.Org From blume at hana.uchicago.edu Wed Jun 10 11:10:03 2009 From: blume at hana.uchicago.edu (Matthias Blume) Date: Wed, 10 Jun 2009 10:10:03 -0500 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: "Jeff M." writes: > On Jun 9, 9:08?pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >> > >> > Arved Sandstrom wrote: >> >> >> >> Jon, I do concurrent programming all the time, as do most of my peers. >> >> Way down on the list of why we do it is the reduction of latency. >> >> > What is higher on the list? >> >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. Programmer time is vastly more expensive than CPU time, so the money argument often leads to slow ("low performance") solutions as long as they are "good enough" because developing a faster solution would mean spending more valuable programmer time at a cost that cannot be recovered over the life cycle of the product in question. That being said, there are plenty of situations where performance obviously does matter a great deal -- as you correctly pointed out. (It all depends on the above mentioned "product in question" and the nature of its life cycle.) Matthias From dfnsonfsduifb at gmx.de Wed Jun 10 11:10:45 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 17:10:45 +0200 Subject: xml.dom.minidom losing the XML document type attribute Message-ID: <79a0njF1pd0bqU1@mid.dfncis.de> Hello group, when I read in a XML document with the xml.dom.minidom parser and write it out again, an attribute is lost: Input: [...] Output: How can I fix this? Python is Python 3.0rc2 (r30rc2:67114, Nov 16 2008, 15:24:36) Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From __peter__ at web.de Wed Jun 10 11:13:50 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:13:50 +0200 Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I wonder if you (or anyone else) might attempt a different explanation > for the use of the special sequence '\1' in the RegEx syntax. > > The Python documentation explains: > > \number > Matches the contents of the group of the same number. Groups are > numbered starting from 1. For example, (.+) \1 matches 'the the' or > '55 55', but not 'the end' (note the space after the group). This > special sequence can only be used to match one of the first 99 groups. > If the first digit of number is 0, or number is 3 octal digits long, > it will not be interpreted as a group match, but as the character with > octal value number. Inside the '[' and ']' of a character class, all > numeric escapes are treated as characters. > > In practice, this appears to be the key to the key device to your > clever solution: > >>>> re.compile(r"(\d+)").sub(r"INSERT \1", string) > > 'abc INSERT 123 def INSERT 456 ghi INSERT 789' > >>>> re.compile(r"(\d+)").sub(r"INSERT ", string) > > 'abc INSERT def INSERT ghi INSERT ' > > I don't, however, precisely understand what is meant by "the group of > the same number" -- or maybe I do, but it isn't explicit. Is this just > a shorthand reference to match.group(1) -- if that were valid -- > implying that the group match result is printed in the compile > execution? If I understand you correctly you are right. Another example: >>> re.compile(r"([a-z]+)(\d+)").sub(r"number=\2 word=\1", "a1 zzz42") 'number=1 word=a number=42 word=zzz' For every match of "[a-z]+\d+" in the original string "\1" in "number=\2 word=\1" is replaced with the actual match for "[a-z]+" and "\2" is replaced with the actual match for "\d+". The result, e. g. "number=1 word=a", is then used to replace the actual match for group 0, i. e. "a1" in the example. Peter From jeff at jmcneil.net Wed Jun 10 11:15:41 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 10 Jun 2009 08:15:41 -0700 (PDT) Subject: Printing dictionary values rather than references References: Message-ID: On Jun 10, 10:19?am, Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. > > class MyClass: > ? ? def __str__(self): > ? ? ? ? return str(self.__dict__) > > if __name__ == '__main__': > ? ? dict = dict() > ? ? classA = MyClass() > ? ? setattr(classA, "attr-1", "val-1") > > ? ? dict['a']= classA > ? ? print classA > ? ? ''' Desired output: {'attr-1': 'val-1'}''' > ? ? print dict > ? ? ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' > > Thanks, > Amit class MyClass: def __repr__(self): # <--- see http://docs.python.org/library/functions.html#repr return str(self.__dict__) HTH, Jeff mcjeff.blogspot.com From bcharrow at csail.mit.edu Wed Jun 10 11:16:56 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Wed, 10 Jun 2009 11:16:56 -0400 Subject: Printing dictionary values rather than references In-Reply-To: <4A2FC109.7080709@oversi.com> References: <4A2FC109.7080709@oversi.com> Message-ID: <4A2FCE68.2010502@csail.mit.edu> Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. > > Thanks, > Amit How about this: class MyClass: def __str__(self): return str(self.__dict__) def __repr__(self): return str(self.__dict__) if __name__ == '__main__': my_dict = dict() classA = MyClass() setattr(classA, "attr-1", "val-1") my_dict['a']= classA print my_dict ''' Actual output: {'attr-1': 'val-1'}''' Though I'm guessing someone is going to say that this is not how repr is supposed be used. See this for more information: http://docs.python.org/reference/datamodel.html#object.__repr__ Cheers, Ben From http Wed Jun 10 11:22:27 2009 From: http (Paul Rubin) Date: 10 Jun 2009 08:22:27 -0700 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Message-ID: <7xmy8gazbg.fsf@ruckus.brouhaha.com> Jon Harrop writes: > > I'm not being facetious. I write applications that run on application > > servers, and from time to time I have had to write various special > > purpose servers. This kind of programming is all about managing > > concurrent execution of computations. The overarching concern is > > reliability and correct function. For many corporate situations, even > > with hundreds of users, the actual load at any instant is low enough > > that the various servers involved are nowhere close to being stressed > > out - performance is a secondary issue. > > In other words, without concurrency the latency would be so high > that you would consider the program to be wrong. However you cut it, > the real reason is latency. I don't think that follows, if there is two-way communication and dependency between the servers, combined with lack of control over when any particular server decides to initiate an outgoing request. Stuff may have to happen concurrently to avoid complete deadlock. From Scott.Daniels at Acm.Org Wed Jun 10 11:24:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 08:24:47 -0700 Subject: retrieve bitwise float representation In-Reply-To: References: Message-ID: Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. > > What I currently do is ... pack and unpack the float using struct.... > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. If you have just a few values, ignore the overhead. Do you really need more cycles for minesweeper? If you have a vector, look into writing from the array directly -- using cStringIO if you need to get to the result within Python, rather than as an I/O format. --Scott David Daniels Scott.Daniels at Acm.Org From wiggly at wiggly.org Wed Jun 10 11:29:36 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Wed, 10 Jun 2009 16:29:36 +0100 Subject: Connection tester In-Reply-To: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Message-ID: <4A2FD160.6070300@wiggly.org> Sparky wrote: > Hey! I am developing a small application that tests multiple websites > and compares their "response time". Some of these sites do not respond > to a ping and, for the measurement to be standardized, all sites must > have the same action preformed upon them. Another problem is that not > all of the sites have the same page size and I am not interested in > how long it takes to load a page but instead just how long it takes > for the website to respond. Finally, I am looking to keep this script > platform independent, if at all possible. Yes, lots of people block ICMP so you can't use it to reliably tell whether a machine is there or not. At least three possible solutions. 1) Perform a HEAD request against the document root. This is likely to be a static page and making it a HEAD request will make most responses take similar times. 2) Perform an OPTIONS request as specified in the RFC below for the * resource. This doesn't always work. 3) Perform a request you believe will fail so that you are provided with a 4XX error code, the only time this should take any appreciable time is when someone has cute server-generated error pages. HTTP/1.1 RFC - http://www.ietf.org/rfc/rfc2616.txt n From __peter__ at web.de Wed Jun 10 11:31:40 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:31:40 +0200 Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 >>> "".join(re.findall("\d+", "123#abc456")) '123456' > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? re.escape() is used to build the regex from a string that may contain characters that have a special meaning in regular expressions but that you want to treat as literals. You can for example search for r"C:\dir" with >>> re.compile(re.escape(r"C:\dir")).findall(r"C:\dir C:7ir") ['C:\\dir'] Without escaping you'd get >>> re.compile(r"C:\dir").findall(r"C:\dir C:7ir") ['C:7ir'] Peter From __peter__ at web.de Wed Jun 10 11:48:17 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Jun 2009 17:48:17 +0200 Subject: xml application advice References: Message-ID: William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). > > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. The only decent online resource that I can > seem to find is > > http://pyxml.sourceforge.net/topics/howto/xml-howto.html > > which doesn't seem to be a very comprehensive how-to. > > Do demonstrate just about everything I know about xml and python I > attached t.py and ex.xml. > > Another thing that is confusing is dir(walker) does not show walker > having an attribute currentNode and dir(walker.currentNode) does not > show walker.currentNode having an attribute tagName. I'd probably start with a few python classes representing the sprinkler system. The exact layout may change a few times until you have found one that makes your questions clear and the calculations as easy as possible. You can then add a read_model_from_file() function converting the xml into your model using ElementTree or its close relative lxml. My guess is that it'll be a lot more fun this way... Peter From python-url at phaseit.net Wed Jun 10 12:00:39 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Wed, 10 Jun 2009 16:00:39 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 10) Message-ID: QOTW: "Most power systems math can be summed this way: take a really big number and multiply by the square root of two." - iceowl http://everything2.com/index.pl?node_id=1348321 The chuzer project provides a means for severely disabled people to express their most basic needs. The project desperately needs help, or it will die. http://comments.gmane.org/gmane.comp.python.general/625159 Never heard of this - guys competing to see whose is shorter! http://comments.gmane.org/gmane.comp.python.general/625868 Correctly implementing __copy__ and __deepcopy__ with multiple inheritance: http://comments.gmane.org/gmane.comp.python.general/625072 http://comments.gmane.org/gmane.comp.python.general/625291 An overly complicated proposed function leads to discuss good API design principles: http://comments.gmane.org/gmane.comp.python.general/625433 List, tuple, set: when to use each type: http://comments.gmane.org/gmane.comp.python.general/625942 Comparing programming languages: how to do the same thing on several languages: http://comments.gmane.org/gmane.comp.python.general/625637 Generating a dynamic plot of x-y data: http://comments.gmane.org/gmane.comp.python.general/625346 __hash__, __eq__, dictionaries, and the big-Oh notation: http://comments.gmane.org/gmane.comp.python.general/625034 The unladen-swallow project, the LLVM virtual machine, and how they relate to the future of CPython: http://comments.gmane.org/gmane.comp.python.general/625493 Accessing data located in the filesystem, inside a package directory: http://comments.gmane.org/gmane.comp.python.general/625209 Closures in Python don't work exactly the same as in other languages: http://comments.gmane.org/gmane.comp.python.general/625475 How to iterate over several lists, one after another? http://comments.gmane.org/gmane.comp.python.general/625532 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From jeff at jmcneil.net Wed Jun 10 12:01:02 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Wed, 10 Jun 2009 09:01:02 -0700 (PDT) Subject: Connection tester References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> Message-ID: <289503b8-090a-4eff-a67f-7d37ee62e250@l32g2000vba.googlegroups.com> On Jun 10, 10:26?am, Sparky wrote: > Hey! I am developing a small application that tests multiple websites > and compares their "response time". Some of these sites do not respond > to a ping and, for the measurement to be standardized, all sites must > have the same action preformed upon them. Another problem is that not > all of the sites have the same page size and I am not interested in > how long it takes to load a page but instead just how long it takes > for the website to respond. Finally, I am looking to keep this script > platform independent, if at all possible. > > Here is the code: > > ? ? try: > ? ? ? ? # Get the starting time > ? ? ? ? origTime = time.time() > > ? ? ? ? # Create the socket connection and then close > ? ? ? ? s = socket.socket(AF_INET, SOCK_STREAM) > ? ? ? ? s.connect((targetIP, port)) > ? ? ? ? s.send("GET / HTTP/1.0\r\n\r\n") > ? ? ? ? result = s.recv(1024) > ? ? ? ? s.shutdown(SHUT_RDWR) > > ? ? except: > ? ? ? ? result = "" > > ? ? # Check for problems and report back the time > ? ? if result == "": > ? ? ? ? return Result((time.time() - origTime) * 1000, True) > ? ? else: > ? ? ? ? return Result((time.time() - origTime) * 1000, False) > > Result is just an object that holds the time it took for the method to > finish and if there were any errors. What I am worried about is that > the socket is potentially closed before the website can finish sending > in all the data. Does anyone have any suggestions or is the script > fine as it is? ICMP and application-level response times are two different animals. Are you interested in simply whether or not a server is up and responding, or do you care about the actual response time and performance of the web site you're checking? I did something like this recently and there were a few different metrics we wound up using. Connect time, first-byte, page download, DNS resolution, and so on. Since you don't care about any of that, just use a HEAD request. It will return the response headers, but as per specification it will not return a message body. Take a look at "http://www.w3.org/Protocols/ rfc2616/rfc2616-sec9.html" for a full primer on the different verbs. A somewhat simplistic alternative would be to connect to port 80 on the destination server and drop the connection once it has been made. This will tell you how long it took to establish a TCP session and that something is indeed listening on the destination port. That's slightly more information than you would get from an ICMP reply. From grahn+nntp at snipabacken.se Wed Jun 10 12:16:46 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 16:16:46 GMT Subject: Career Track: Computer Programmer References: <46355271-cd9d-4095-886c-01077360c95f@k20g2000vbp.googlegroups.com> Message-ID: On Mon, 8 Jun 2009 07:49:42 -0700 (PDT), youssef_edward3000 at yahoo.com wrote: > Roles and Responsibilities : > > The primary role of a Computer Programmer is to write programs > according to the instructions determined primarily by computer > software engineers and systems analysts. I hope this is a direct quote from a 1976 issue of some sleazy business magazine, not something anyone believes in today. Except for the systems analysts, maybe. > In a nutshell, Computer > Programmers are the ones that take the completed designs and convert > them into the instructions that the computer can actually follow. That's not a programmer, that's a compiler. Or (to at least *pretend* to be on topic) that's the Python interpreter. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From flyeng4 at gmail.com Wed Jun 10 12:18:15 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 11:18:15 -0500 Subject: xml application advice In-Reply-To: <799v9lF1pj8gqU1@mid.uni-berlin.de> References: <799v9lF1pj8gqU1@mid.uni-berlin.de> Message-ID: <4A2FDCC7.6090708@gmail.com> Diez B. Roggisch wrote: > William Purcell wrote: > >> I am writing a application to calculate pressure drop for a piping >> network. Namely a building sprinkler system. This will be a >> command line program at first with the system described in xml (at >> least that is how I think I want to do it). > Use lxml2 and xpath. > > http://codespeak.net/lxml/ > http://codespeak.net/lxml/xpathxslt.html > This looks promising. I will start playing around with it and see what I can come up with. Thanks for the example. Peter Otten wrote: > I'd probably start with a few python classes representing the > sprinkler > system. The exact layout may change a few times until you have > found one > that makes your questions clear and the calculations as easy as > possible. > > You can then add a read_model_from_file() function converting the > xml into > your model using ElementTree or its close relative lxml. > > My guess is that it'll be a lot more fun this way... This was my initial plan, but I have never messed with xml and didn't know if it was what I wanted. I have messed around with plistlib on a mac. If I remember correctly the reader in plistlib returns a dict so I thought I would be getting a dict from an xml reader (but maybe xml and plist aren't as close as I thought). Reading xml seems more complicated than I initially expected, but probably rightfully so. But I digress. I will take your advice and start with some classes and then work on getting the data to my classes. From Scott.Daniels at Acm.Org Wed Jun 10 12:23:10 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 09:23:10 -0700 Subject: xml application advice In-Reply-To: References: Message-ID: William Purcell wrote: > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml.... If you are going to be doing a lot of tree walking, try etree. Simple example: import xml.etree.ElementTree as ET # or wherever you get ElementTree def find_remote_and_path(node, path): for child in node: for result in walks(child, path + [node]): yield result if node.tag == 'node' and node.get('hydraulically_most_remote' ) == 'True': yield node, path tree = ET.parse('ex.xml') for node, path in find_remote_and_path(tree.getroot(), []): for t in path: print ' ', t.tag, t.get('id', '-') print node.tag, ', '.join(sorted('%s=%r' % pair for pair in node.items())) --Scott David Daniels Scott.Daniels at Acm.Org From grahn+nntp at snipabacken.se Wed Jun 10 12:34:29 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 16:34:29 GMT Subject: xml application advice References: Message-ID: On Wed, 10 Jun 2009 08:57:42 -0500, William Purcell wrote: ... > I am writing a application to calculate pressure drop for a piping > network. Namely a building sprinkler system. This will be a > command line program at first with the system described in xml (at > least that is how I think I want to do it). How about (re)using the dot graph language from Graphviz? It's a file format for describing directed graphs, which I suppose a sprinkler system is. It might fit; it might not. > An important part of this calculation is finding the 'hydraulically > most remote' sprinkler. This is something that I could specify with > an attribute for now and later think about how to automate it. I > need to walk through the dom tree until I find a node of type > "sprinkler" that has an attribute of hydraulically_most_remote with > a value of True. > > After I find this I need to break the itterator/for loop and then > start walking backwards keeping a running total of the pressure drop > until I reach a node that has multiple pipesections and then walk to > the end of each branch and calculate the pressure drop, and then add > them to the branch that contained the hydraulically most remote > sprinkler, and then move on, repeating this until I walk all the way > back to the inflow node. > > I am having trouble finding a decent python/xml resource on the web. > I have ordered Python & XML by Jones and Drake, but I am anxious to > get something started. If what you're interested in is to get real work done, why decide to make XML a showstopper? I see two tasks: (a) transforming a text file description of a sprinkler system into a Python data structure, and (b) implementing algorithms to find out important stuff about such a data structure. You do not need (a) before you can do (b). You can even have Python as your input format, and eval() the file. Crude and insecure, but it works, at almost zero cost. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From flyeng4 at gmail.com Wed Jun 10 12:39:33 2009 From: flyeng4 at gmail.com (William Purcell) Date: Wed, 10 Jun 2009 11:39:33 -0500 Subject: xml application advice In-Reply-To: References: Message-ID: <4A2FE1C5.5070604@gmail.com> Scott David Daniels wrote: > William Purcell wrote: >> I am writing a application to calculate pressure drop for a piping >> network. Namely a building sprinkler system. This will be a >> command line program at first with the system described in xml.... > > If you are going to be doing a lot of tree walking, try etree. > Simple example: > > import xml.etree.ElementTree as ET # or wherever you get ElementTree > > def find_remote_and_path(node, path): > for child in node: > for result in walks(child, path + [node]): yield result > if node.tag == 'node' and node.get('hydraulically_most_remote' > ) == 'True': > yield node, path > > > tree = ET.parse('ex.xml') > for node, path in find_remote_and_path(tree.getroot(), []): > for t in path: > print ' ', t.tag, t.get('id', '-') > print node.tag, ', '.join(sorted('%s=%r' % pair > for pair in node.items())) > > > --Scott David Daniels > Scott.Daniels at Acm.Org Scott, Thanks for the reply. I am having a little trouble finding where to import `walks` from. Bill From David.Shapiro at sas.com Wed Jun 10 12:42:44 2009 From: David.Shapiro at sas.com (David Shapiro) Date: Wed, 10 Jun 2009 12:42:44 -0400 Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: Maybe a using a Unicode equiv of # would do the trick. -----Original Message----- From: python-list-bounces+david.shapiro=sas.com at python.org [mailto:python-list-bounces+david.shapiro=sas.com at python.org] On Behalf Of Peter Otten Sent: Wednesday, June 10, 2009 11:32 AM To: python-list at python.org Subject: Re: How to escape # hash character in regex match strings 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 >>> "".join(re.findall("\d+", "123#abc456")) '123456' > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? re.escape() is used to build the regex from a string that may contain characters that have a special meaning in regular expressions but that you want to treat as literals. You can for example search for r"C:\dir" with >>> re.compile(re.escape(r"C:\dir")).findall(r"C:\dir C:7ir") ['C:\\dir'] Without escaping you'd get >>> re.compile(r"C:\dir").findall(r"C:\dir C:7ir") ['C:7ir'] Peter -- http://mail.python.org/mailman/listinfo/python-list From Scott.Daniels at Acm.Org Wed Jun 10 13:06:17 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 10 Jun 2009 10:06:17 -0700 Subject: xml application advice In-Reply-To: References: Message-ID: William Purcell wrote: > Scott David Daniels wrote: >> William Purcell wrote: >>> I am writing a application to calculate pressure drop for a piping >>> network. Namely a building sprinkler system. This will be a >>> command line program at first with the system described in xml.... >> If you are going to be doing a lot of tree walking, try etree. >> Simple example: >> >> import xml.etree.ElementTree as ET # or wherever you get ElementTree >> >> def find_remote_and_path(node, path): >> for child in node: >> for result in walks(child, path + [node]): yield result >> if node.tag == 'node' and node.get('hydraulically_most_remote' >> ) == 'True': >> yield node, path >> >> >> tree = ET.parse('ex.xml') >> for node, path in find_remote_and_path(tree.getroot(), []): >> for t in path: >> print ' ', t.tag, t.get('id', '-') >> print node.tag, ', '.join(sorted('%s=%r' % pair >> for pair in node.items())) >> >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org > > Scott, Thanks for the reply. > > I am having a little trouble finding where to import `walks` from. > > Bill Sorry, renamed and forgot to repaste. walks is just find_remote_and_path From mensanator at aol.com Wed Jun 10 13:21:14 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 10:21:14 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> Message-ID: <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> On Jun 10, 4:01?am, Mark Dickinson wrote: > On Jun 10, 7:25?am, John Yeung wrote: > > > > > > > On Jun 10, 1:52?am, Steven D'Aprano > > > wrote: > > > On Tue, 09 Jun 2009 22:21:26 -0700, John Yeung wrote: > > > > Therefore, to me the most up-to-date docs (which say > > > > that uniform(a, b) returns a float in the closed > > > > interval [a, b]) is closer to correct than before, > > > > but still fails to point out the full subtlety of > > > > the behavior. > > > > Which is? > > > That uniform(a, b) will return a random float in the semi-open > > interval [a, b) for certain values of a and b; and in the closed > > interval [a, b] for other values of a and b. ?(Swap a and b if a > b.) > > > To me, the fact that you sometimes get a semi-open interval and > > sometimes a closed interval is worth noting in the docs. > > Do you want to submit a doc patch? > > For practical purposes, I think you'd be hard-pressed to find a > statistical > test that could reliably distinguish between a large sample of values > from > random.uniform(a, b) and a sample from a 'perfect' uniform > distribution on > the closed interval [a, b]. ?It's true that there are values of a and > b > such that random.uniform(a, b) can never produce b. ? So, the 2.6.2 documentation is STILL wrong. Before it implied it was ALWAYS a semi-open interval, and now it says it's ALWAYS a closed interval. But neither is correct. I think a doc patch is definitely warranted. > But for given a and b, > not too close together, there may be many other values that can't be > produced as well, so it hardly seems worth pointing out one particular > value that can never be produced. > > Example: on a typical system there are almost 2**62 floats in the > range [0, 1); ?the vast majority of these can never be produced by > random.random(), which can only ever return one of 2**53 distinct > values > (it essentially just returns a value of the form n/2**53 with n > an integer in the range [0, 2**53)). ?So random.uniform(0, 1) will > miss lots of possible values. > > On the other hand, it's easy to find examples of a and b such that > random.uniform(a, b) has a significant chance of producing b. > For example, take a = 10**16, b = 10**16 + 4, then there's about a 1 > in 4 chance of getting b. Or for a more extreme example, simply > take a = b. ?Hence the doc change. > > Mark From deets at nospam.web.de Wed Jun 10 13:35:24 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 10 Jun 2009 19:35:24 +0200 Subject: xml application advice References: Message-ID: <79a911F1pth9qU1@mid.uni-berlin.de> > > If what you're interested in is to get real work done, why decide to > make XML a showstopper? > > I see two tasks: (a) transforming a text file description of a sprinkler > system into a Python data structure, and (b) implementing algorithms > to find out important stuff about such a data structure. > > You do not need (a) before you can do (b). You can even have Python as > your input format, and eval() the file. Crude and insecure, but it > works, at almost zero cost. While I certainly agree that XML often means more trouble than it's worth, I don't concur in this concrete case. If the OP has a tree-structure, XPath is a *very* powerful way to operate on that - and as he seems to have questions like "get the one node with the attribute X, then the first one above that having more than one child of kind Y", it can get in handy. Diez From dickinsm at gmail.com Wed Jun 10 13:37:01 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 10:37:01 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> On Jun 10, 6:21?pm, Mensanator wrote: > So, the 2.6.2 documentation is STILL wrong. Before it implied > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > a closed interval. But neither is correct. Exactly which bit of the 2.6.2 documentation do you think is incorrect? The documentation for random.uniform says: """Return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a.""" And that's precisely what it does. Nowhere does the documentation say that *every* floating-point number N in the interval [a, b] can occur. Mark From Samnsparky at gmail.com Wed Jun 10 13:37:59 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 10 Jun 2009 10:37:59 -0700 (PDT) Subject: Connection tester References: <549b976b-74fa-4593-a88a-de9f76e5af56@r34g2000vba.googlegroups.com> <289503b8-090a-4eff-a67f-7d37ee62e250@l32g2000vba.googlegroups.com> Message-ID: <58c2404d-d5c8-4fa8-9541-a2ead43d288b@e20g2000vbc.googlegroups.com> On Jun 10, 10:01?am, Jeff McNeil wrote: > On Jun 10, 10:26?am, Sparky wrote: > > > > > Hey! I am developing a small application that tests multiple websites > > and compares their "response time". Some of these sites do not respond > > to a ping and, for the measurement to be standardized, all sites must > > have the same action preformed upon them. Another problem is that not > > all of the sites have the same page size and I am not interested in > > how long it takes to load a page but instead just how long it takes > > for the website to respond. Finally, I am looking to keep this script > > platform independent, if at all possible. > > > Here is the code: > > > ? ? try: > > ? ? ? ? # Get the starting time > > ? ? ? ? origTime = time.time() > > > ? ? ? ? # Create the socket connection and then close > > ? ? ? ? s = socket.socket(AF_INET, SOCK_STREAM) > > ? ? ? ? s.connect((targetIP, port)) > > ? ? ? ? s.send("GET / HTTP/1.0\r\n\r\n") > > ? ? ? ? result = s.recv(1024) > > ? ? ? ? s.shutdown(SHUT_RDWR) > > > ? ? except: > > ? ? ? ? result = "" > > > ? ? # Check for problems and report back the time > > ? ? if result == "": > > ? ? ? ? return Result((time.time() - origTime) * 1000, True) > > ? ? else: > > ? ? ? ? return Result((time.time() - origTime) * 1000, False) > > > Result is just an object that holds the time it took for the method to > > finish and if there were any errors. What I am worried about is that > > the socket is potentially closed before the website can finish sending > > in all the data. Does anyone have any suggestions or is the script > > fine as it is? > > ICMP and application-level response times are two different animals. > Are you interested in simply whether or not a server is up and > responding, or do you care about the actual response time and > performance of the web site you're checking? I did something like this > recently and there were a few different metrics we wound up using. > Connect time, first-byte, page download, DNS resolution, and so on. > > Since you don't care about any of that, just use a HEAD request. It > will return the response headers, but as per specification it will not > return a message body. ?Take a look at "http://www.w3.org/Protocols/ > rfc2616/rfc2616-sec9.html" for a full primer on the different verbs. > > A somewhat simplistic alternative would be to connect to port 80 on > the destination server and drop the connection once it has been made. > This will tell you how long it took to establish a TCP session and > that something is indeed listening on the destination port. That's > slightly more information than you would get from an ICMP reply. Thank you all for your responses. I will play with everything but the HEAD request seems to be what I was looking for. Sam From smacrae319 at live.ca.invalid Wed Jun 10 13:49:30 2009 From: smacrae319 at live.ca.invalid (Seamus MacRae) Date: Wed, 10 Jun 2009 13:49:30 -0400 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. And when, exactly, did Microsoft go out of business? I hadn't heard it mentioned in the news. :) From mensanator at aol.com Wed Jun 10 13:57:03 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 10:57:03 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> Message-ID: <0a6d1387-c181-4092-82a1-e889458e9a2b@k20g2000vbp.googlegroups.com> On Jun 10, 12:37?pm, Mark Dickinson wrote: > On Jun 10, 6:21?pm, Mensanator wrote: > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > a closed interval. But neither is correct. > > Exactly which bit of the 2.6.2 documentation do you think is > incorrect? ?The documentation for random.uniform says: > > """Return a random floating point number N such that > a <= N <= b for a <= b and b <= N <= a for b < a.""" > > And that's precisely what it does. ? I didn't say it didn't. > Nowhere does the documentation say that *every* Unless qualified otherwise, that statement implies "for all (a,b)". > floating-point number N in the interval [a, b] > can occur. > > Mark From massung at gmail.com Wed Jun 10 14:07:12 2009 From: massung at gmail.com (Jeff M.) Date: Wed, 10 Jun 2009 11:07:12 -0700 (PDT) Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: On Jun 10, 12:49?pm, Seamus MacRae wrote: > Jeff M. wrote: > > On Jun 9, 9:08 pm, Arved Sandstrom wrote: > >> Jon Harrop wrote: > >>> Arved Sandstrom wrote: > >>>> Jon, I do concurrent programming all the time, as do most of my peers. > >>>> Way down on the list of why we do it is the reduction of latency. > >>> What is higher on the list? > >> Correctness. > > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > > important, no matter what application you are creating; without it, > > you don't have a job and the company you work for goes out of > > business. > > And when, exactly, did Microsoft go out of business? I hadn't heard it > mentioned in the news. :) Touche. :) Jeff M. From jcherry7 at gatech.edu Wed Jun 10 14:22:22 2009 From: jcherry7 at gatech.edu (jcherry7 at gatech.edu) Date: Wed, 10 Jun 2009 14:22:22 -0400 (EDT) Subject: How do you insert an image into Powerpoint using python/win32? In-Reply-To: <1020484807.3818011244658074185.JavaMail.root@mail8.gatech.edu> Message-ID: <1315873239.3818291244658142466.JavaMail.root@mail8.gatech.edu> I have python 3.0.1, and have downloaded pywin32 for python 3.x, aka build #213. I ran win32com.client.makepy.py on Microsoft Office 12.0 Object Library and Microsoft PowerPoint 12.0 Object Library. The output files were placed in win32com.gen_py. I renamed them as MSO.py and MSPPT.py, respectively. The following code is located in my c:\Python30 folder. Thinkter is used to prompt the user to choose the image that they want to put onto the slide. THe 10 pointed star was an experiment, to try to import something into the image. Here is the code as I currently have it: from tkinter import * import tkinter.filedialog as tkFileDialog import win32com.client # middleman/translator/messanger between windows and python import win32com.gen_py.MSO as MSO # contains constants refering to Microsoft Office Objects import win32com.gen_py.MSPPT as MSPPT # contains constants refering to Microsoft Office Power Point Objects g = globals() # a dictonary of global vlaues, that will be the constants of the two previous imports for c in dir(MSO.constants): g[c] = getattr(MSO.constants, c) # globally define these for c in dir(MSPPT.constants): g[c] = getattr(MSPPT.constants, c) Application = win32com.client.Dispatch("PowerPoint.Application") Application.Visible = True # shows what's happening, not required, but helpful for now Presentation = Application.Presentations.Add() # adds a new presentation Slide1 = Presentation.Slides.Add(1, ppLayoutBlank) # new slide, at beginning TenptStr = Slide1.Shapes.AddShape(msoShape10pointStar, 100, 100, 200, 200) pictName = tkFileDialog.askopenfilename(title="Please Select the Image you wish to load") print(pictName) Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200) this is the error: Traceback (most recent call last): File "C:\Python30\PowerPointEditer.py", line 21, in Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200)#pictName, pictName, 200, 200, 200, 200) File "C:\Python30\lib\site-packages\win32com\gen_py\MSPPT.py", line 8544, in AddPicture , Height) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None) It seems I'm passing AddPictures the wrong varibles Thanks. -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology From malkia at mac.com Wed Jun 10 14:26:24 2009 From: malkia at mac.com (Dimiter "malkia" Stanev) Date: Wed, 10 Jun 2009 11:26:24 -0700 Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. PC / Video Games definitely fall out of the correctness. As long as the game does not crash your XBOX/PS3/Whatever for certain amount of time, and behaves well then, it's fine. Bugs are already part of the "genre". In reality you can't ship on time, there are always BUGS :) Most important thing in games is (at least for large percent of them) speed of graphics - fluid 60fps, or stable 30fps. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. > > Programs that use more memory require more money for the hardware of > every user. Programs that run slower eat more time per day. If you > have 100,000 users, all doing an operation once per day that takes 20 > seconds, being able to shave 5 seconds off that saves 5.78 man-days of > work. Hell, for some applications, that 20 seconds is just startup > time spent at a splash screen. Just imagine if every Google search > took even 5 seconds to resolve, how much time would be wasted every > day around the world - ignoring the fact that Google wouldn't exist if > that were the case ;-). Obviously Google engineers work incredibly > hard every day to ensure correct results, but performance better be > right up there at the top of the list as well. > > Jeff M. From robert.kern at gmail.com Wed Jun 10 14:47:40 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 13:47:40 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: On 2009-06-09 19:27, Mensanator wrote: > On Jun 9, 6:12 pm, Robert Kern wrote: >> On 2009-06-09 18:05, Mensanator wrote: >> >> >> >> >> >>> On Jun 9, 4:33 pm, Esmail wrote: >>>> Hi, >>>> random.random() will generate a random value in the range [0, 1). >>>> Is there an easy way to generate random values in the range [0, 1]? >>>> I.e., including 1? >>>> I am implementing an algorithm and want to stay as true to the >>>> original design specifications as possible though I suppose the >>>> difference between the two max values might be minimal. >>>> Thanks, >>>> Esmail >>>> ps: I'm confused by the docs for uniform(): >>>> random.uniform(a, b) >>>> Return a random floating point number N such that a<= N<= b for a<= b >>> That's wrong. Where did you get it? >> http://docs.python.org/library/random > > Ok, but the 2.6.1 docs say > > random.uniform(a, b) > Return a random floating point number N such that a<= N< b > for a<= b and b<= N< a for b< a. > > Is that a new feature of 2.6.2? As already pointed out, it's not really a new feature of the method, but rather a fix for the buggy documentation. Because of floating point arithmetic, one cannot guarantee that a+(b-a)*u is strictly in [a,b) even though u is strictly in [0,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 tjreedy at udel.edu Wed Jun 10 14:53:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 14:53:19 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: Mensanator wrote: > So, the 2.6.2 documentation is STILL wrong. Before it implied > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > a closed interval. But neither is correct. If a < x < b is true, then a <= x <= b is true. But docs say that in general end point values might happen. They do not say that in every particular case, they will happen. A full technical discussion does not below in the docs, in my opinion. A wike article would be fine. tjr From dickinsm at gmail.com Wed Jun 10 15:00:45 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 12:00:45 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <4ea4a862-215b-4949-9383-299f702aa2d1@f16g2000vbf.googlegroups.com> <0a6d1387-c181-4092-82a1-e889458e9a2b@k20g2000vbp.googlegroups.com> Message-ID: <933c2e58-108b-49cc-8bfd-412bfae2b93c@x5g2000yqk.googlegroups.com> On Jun 10, 6:57?pm, Mensanator wrote: > On Jun 10, 12:37?pm, Mark Dickinson wrote: > > > On Jun 10, 6:21?pm, Mensanator wrote: > > > > So, the 2.6.2 documentation is STILL wrong. Before it implied > > > it was ALWAYS a semi-open interval, and now it says it's ALWAYS > > > a closed interval. But neither is correct. > > > Exactly which bit of the 2.6.2 documentation do you think is > > incorrect? ?The documentation for random.uniform says: > > > """Return a random floating point number N such that > > a <= N <= b for a <= b and b <= N <= a for b < a.""" > > > And that's precisely what it does. ? > > I didn't say it didn't. > > > Nowhere does the documentation say that *every* > > Unless qualified otherwise, that statement implies "for all (a,b)". Sure. For all a <= b, it's true that a <= uniform(a, b) <= b. And similarly for b <= a. I really don't see the problem: the documentation is both technically correct and useful in practice. The assertion implicit in the name and description of the random.uniform function is that, to a very good approximation, the values produced by random.uniform(a, b) will be uniformly distributed on the closed interval [a, b]. And that's true (at least within the limits of floating-point arithmetic). Can you think of a single practical situation where it would matter that, for some values of a and b, uniform(a, b) can never produce the value b? Mark From msburson at gmail.com Wed Jun 10 15:01:13 2009 From: msburson at gmail.com (Matt Burson) Date: Wed, 10 Jun 2009 14:01:13 -0500 Subject: Restart the interactive python shell like in IDLE Message-ID: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> Is there a way to reproduce the behavior of IDLE's restart shell ability by using a function? I thought there would be since you can exit python by executing the simple quit() function I thought there would be an equally simple function name something like restart(). I'd prefer something like this as opposed to having to exit the shell and then start it up again to refresh it. -- Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Jun 10 15:15:58 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 14:15:58 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: On 2009-06-10 13:53, Terry Reedy wrote: > Mensanator wrote: > >> So, the 2.6.2 documentation is STILL wrong. Before it implied >> it was ALWAYS a semi-open interval, and now it says it's ALWAYS >> a closed interval. But neither is correct. > > If a < x < b is true, then a <= x <= b is true. > But docs say that in general end point values might happen. They do not > say that in every particular case, they will happen. I'm not so sure. Context is important. When discussing the bounds of random number generators, specifying <= instead of < strongly suggests that the bound is one of the possible results. I've had to read a lot of random number generator documentation in my time. To take the point to absurdity, it would be wrong for the function to return just values within (a+0.25*b, a+0.75*b) even though the docs "just" say that the result will be between a and b. > A full technical discussion does not below in the docs, in my opinion. A > wike article would be fine. True. However, a brief note that "Due to floating point arithmetic, for some values of a and b, b may or may not be one of the possible generated results." might be worthwhile. The actual details of *why* this is the case can be discussed elsewhere. -- 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 Wed Jun 10 15:31:32 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 15:31:32 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? In-Reply-To: <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: Carl Banks wrote: >> Sometimes alternate constructors are needed when there is more than one >> possible way to create an instance from a given input. In the case of >> str(iterable), one could want either a string representing the iterable >> itself, just as with non-iterables, or a string representing the >> concatenated contents of the iterable. Str.join implements the second >> choice, with an added string parameter to allow a constant string to be >> interpolated between the joined items. > > But then how do you rationalize str.split(), which is a method of str > but a constructor of list? Str.join takes any iterable of strings and constructs a string. Only str knows how to do that, though it could have a built-in that called a hypothetical .__join__ method. However, Python started with just one string type and there does not seem much use for joining an indefinite number of tuples or lists. (In any case, there is no string equivalent of list.extend, which can be used for joining multiple lists.) Str.split only takes a string arg and splits it up. Only str should know how to split a string. That it returns the pieces as a list is a historical artifact. I could have returned a tuple. It could have been changed in 3.0 to return an iterater, like map and others were. If Python were being designed today with iterators as a basic protocol, and without the baggage of back compatibility, I am fairly sure .split would return an iterator. > Perhaps instead of worrying about symmetry all the time we should just > accept the inevitability that things will always be asymmetric and > impure from someone's perspective. Terry's symmetry is Hendrik's > asymmetry and vice versa. That was one of my implied points ;-). Terry Jan Reedy From manavan.j at gmail.com Wed Jun 10 15:34:56 2009 From: manavan.j at gmail.com (Manavan) Date: Wed, 10 Jun 2009 12:34:56 -0700 (PDT) Subject: object reincarnation Message-ID: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Hello everyone, Since the real world objects often needs to be deleted even if they have some reference from some other object, I am going to use this approach to better model this situation, by cleaning up the attributes and assigning self.__class__ to a different class. Any comment on this approach. class Deleted(object): pass class RealWorldObj(object): def __init__(self, *args): self.attrs = args def getAttrs(self,): return self.attrs def delete(self,): del self.attrs self.__class__ = Deleted >>> a = RealWorldObj(1,2,3) >>> print a.attrs (1, 2, 3) >>> a.delete() >>> a <__main__.Deleted object at 0x893ae2c> >>> a.attrs Traceback (most recent call last): File "", line 1, in AttributeError: 'Deleted' object has no attribute 'attrs' From jon at ffconsultancy.com Wed Jun 10 15:42:09 2009 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 10 Jun 2009 20:42:09 +0100 Subject: multi-core software References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Matthias Blume wrote: > "Jeff M." writes: >> But, assuming that your program works and does what it's supposed to, >> I agree with Jon that performance needs to be right near the top of >> the list of concerns. Why? Performance isn't about looking good as a >> programmer, or having fun making a function run in 15 cycles instead >> of 24, or coming up with some neat bit packing scheme so that your app >> now only uses 20K instead of 200K. Performance is - pure and simple - >> about one thing only: money. > > Programmer time is vastly more expensive than CPU time, so the > money argument often leads to slow ("low performance") solutions as long > as they are "good enough" because developing a faster solution would > mean spending more valuable programmer time at a cost that cannot > be recovered over the life cycle of the product in question. In the context of commercial software, the money to fund developers to improve performance comes from the huge marketing budget because performance is usually more about marketing than anything else. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u From dickinsm at gmail.com Wed Jun 10 15:46:15 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Jun 2009 12:46:15 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> Message-ID: <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> On Jun 10, 8:15?pm, Robert Kern wrote: > On 2009-06-10 13:53, Terry Reedy wrote: > > A full technical discussion does not below in the docs, in my opinion. A > > wike article would be fine. > > True. However, a brief note that "Due to floating point arithmetic, for some > values of a and b, b may or may not be one of the possible generated results." > might be worthwhile. The actual details of *why* this is the case can be > discussed elsewhere. I find it difficult to see how such a disclaimer would have any practical value, without also knowing *which* values of a and b are affected. It can certainly be useful to know that endpoints *aren't* included where that's true. For example, knowing that random.random() can never produce the value 1.0 means that one can safely generate a mean 1 exponential variate with -log(1-random.random()), without worrying about the possibility of taking log of 0. But I don't know why it would be useful to know that endpoints *are* sometimes included, without knowing exactly when. Mark From jcherry7 at gatech.edu Wed Jun 10 15:47:49 2009 From: jcherry7 at gatech.edu (Cherry, Jonathan M) Date: Wed, 10 Jun 2009 15:47:49 -0400 (EDT) Subject: How do you insert an image into Powerpoint using python/win32? In-Reply-To: <1315873239.3818291244658142466.JavaMail.root@mail8.gatech.edu> Message-ID: <1902394141.3844521244663269463.JavaMail.root@mail8.gatech.edu> Never mind, its just that the "choose file" option produces a file path with '/" rather than '\', and python cannot use the former. Thanks anyway ----- Original Message ----- From: jcherry7 at gatech.edu To: python-list at python.org Sent: Wednesday, June 10, 2009 2:22:22 PM GMT -05:00 US/Canada Eastern Subject: How do you insert an image into Powerpoint using python/win32? I have python 3.0.1, and have downloaded pywin32 for python 3.x, aka build #213. I ran win32com.client.makepy.py on Microsoft Office 12.0 Object Library and Microsoft PowerPoint 12.0 Object Library. The output files were placed in win32com.gen_py. I renamed them as MSO.py and MSPPT.py, respectively. The following code is located in my c:\Python30 folder. Thinkter is used to prompt the user to choose the image that they want to put onto the slide. THe 10 pointed star was an experiment, to try to import something into the image. Here is the code as I currently have it: from tkinter import * import tkinter.filedialog as tkFileDialog import win32com.client # middleman/translator/messanger between windows and python import win32com.gen_py.MSO as MSO # contains constants refering to Microsoft Office Objects import win32com.gen_py.MSPPT as MSPPT # contains constants refering to Microsoft Office Power Point Objects g = globals() # a dictonary of global vlaues, that will be the constants of the two previous imports for c in dir(MSO.constants): g[c] = getattr(MSO.constants, c) # globally define these for c in dir(MSPPT.constants): g[c] = getattr(MSPPT.constants, c) Application = win32com.client.Dispatch("PowerPoint.Application") Application.Visible = True # shows what's happening, not required, but helpful for now Presentation = Application.Presentations.Add() # adds a new presentation Slide1 = Presentation.Slides.Add(1, ppLayoutBlank) # new slide, at beginning TenptStr = Slide1.Shapes.AddShape(msoShape10pointStar, 100, 100, 200, 200) pictName = tkFileDialog.askopenfilename(title="Please Select the Image you wish to load") print(pictName) Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200) this is the error: Traceback (most recent call last): File "C:\Python30\PowerPointEditer.py", line 21, in Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200)#pictName, pictName, 200, 200, 200, 200) File "C:\Python30\lib\site-packages\win32com\gen_py\MSPPT.py", line 8544, in AddPicture , Height) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None) It seems I'm passing AddPictures the wrong varibles Thanks. -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology -- Jonathan Cherry jcherry7 at gatech.edu Student Computer Science Major (working on it) Georgia Institute of Technology From tjreedy at udel.edu Wed Jun 10 16:00:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:00:36 -0400 Subject: Function/method returning list of chars in string? In-Reply-To: References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <4d070c130906090039i3aecd19bo3436b6e62e49a0b5@mail.gmail.com> Message-ID: Robert Kern wrote: >> Important correction noted. But how did you find those? When I search >> for 'Shaw' with the search box (I tried it again), I only get a couple >> of other, irrelevant hits. Is the search box buggy? > > I suspect so. I knew of most of them already, and Googling > site:pypi.python.org picked up the rest. Will use that in the future. In the meanwhile, I submitted a bug report. From martin at v.loewis.de Wed Jun 10 16:00:59 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 10 Jun 2009 22:00:59 +0200 Subject: Compiling Python3.1 In-Reply-To: <799co4F1pdqgeU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> Message-ID: <4a3010fb$0$22010$9b622d9e@news.freenet.de> > What can I do about that? Remove the non-ASCII characters from db.h. Regards, Martin From matzke at berkeley.edu Wed Jun 10 16:09:59 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 13:09:59 -0700 Subject: cleaning up an ASCII file? Message-ID: <4A301317.8080607@berkeley.edu> Hi all, So I'm parsing an XML file returned from a database. However, the database entries have occasional non-ASCII characters, and this is crashing my parsers. Is there some handy function out there that will schlep through a file like this, and do something like fix the characters that it can recognize, and delete those that it can't? Basically, like the BBEdit "convert to ASCII" menu option under "Text". I googled some on this, but nothing obvious came up that wasn't specific to fixing one or a few characters. Thanks! Nick -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From tjreedy at udel.edu Wed Jun 10 16:22:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:22:46 -0400 Subject: Printing dictionary values rather than references In-Reply-To: <4A2FC109.7080709@oversi.com> References: <4A2FC109.7080709@oversi.com> Message-ID: Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. You can only print string representations, as defined by type(ob).__str__ and type(ob).__repr__. > > class MyClass: > def __str__(self): > return str(self.__dict__) > > if __name__ == '__main__': > dict = dict() Rebinding built-in names is a bad idea unless you *really* mean to replace the original. > classA = MyClass() > setattr(classA, "attr-1", "val-1") > > dict['a']= classA > print classA > ''' Desired output: {'attr-1': 'val-1'}''' > print dict > ''' Actual output: {'a': <__main__.MyClass instance at 0x79cfc8>}''' > > Thanks, > Amit From robert.kern at gmail.com Wed Jun 10 16:32:05 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 15:32:05 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-10 14:46, Mark Dickinson wrote: > On Jun 10, 8:15 pm, Robert Kern wrote: >> On 2009-06-10 13:53, Terry Reedy wrote: >>> A full technical discussion does not below in the docs, in my opinion. A >>> wike article would be fine. >> True. However, a brief note that "Due to floating point arithmetic, for some >> values of a and b, b may or may not be one of the possible generated results." >> might be worthwhile. The actual details of *why* this is the case can be >> discussed elsewhere. > > I find it difficult to see how such a disclaimer would have any > practical > value, without also knowing *which* values of a and b are affected. > > It can certainly be useful to know that endpoints *aren't* included > where > that's true. For example, knowing that random.random() can never > produce the > value 1.0 means that one can safely generate a mean 1 exponential > variate with > -log(1-random.random()), without worrying about the possibility of > taking log > of 0. > > But I don't know why it would be useful to know that endpoints *are* > sometimes > included, without knowing exactly when. That's a fair point. However, one issue that hasn't been brought up is that it might be confusing to a user why random.random() returns values in a half-open interval while random.uniform() claims a closed interval. Even for reasonably sophisticated floating point users, it's not necessarily obvious that that is the reasoning behind the different claims. -- 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 Jun 10 16:35:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 15:35:14 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On 2009-06-10 15:32, Robert Kern wrote: > On 2009-06-10 14:46, Mark Dickinson wrote: >> But I don't know why it would be useful to know that endpoints *are* >> sometimes >> included, without knowing exactly when. > > That's a fair point. However, one issue that hasn't been brought up is > that it might be confusing to a user why random.random() returns values > in a half-open interval while random.uniform() claims a closed interval. > Even for reasonably sophisticated floating point users, it's not > necessarily obvious that that is the reasoning behind the different claims. Basically, if we can forestall another tedious thread about imagined asymmetry and "hemispatial neglect" with a single sentence, I'm all for 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 tjreedy at udel.edu Wed Jun 10 16:36:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:36:27 -0400 Subject: object reincarnation In-Reply-To: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: Manavan wrote: > Hello everyone, > Since the real world objects often needs to be deleted even if they > have some reference from some other object, I am going to use this > approach to better model this situation, by cleaning up the attributes > and assigning self.__class__ to a different class. > Any comment on this approach. It might be easier to give the class a status variable so instances can be de-activated without destroying info and perhaps re-activated. > > class Deleted(object): > pass > > class RealWorldObj(object): > def __init__(self, *args): > self.attrs = args > def getAttrs(self,): > return self.attrs > def delete(self,): > del self.attrs > self.__class__ = Deleted > > >>>> a = RealWorldObj(1,2,3) >>>> print a.attrs > (1, 2, 3) >>>> a.delete() >>>> a > <__main__.Deleted object at 0x893ae2c> >>>> a.attrs > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'Deleted' object has no attribute 'attrs' From vlastimil.brom at gmail.com Wed Jun 10 16:39:04 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 10 Jun 2009 22:39:04 +0200 Subject: cleaning up an ASCII file? In-Reply-To: <4A301317.8080607@berkeley.edu> References: <4A301317.8080607@berkeley.edu> Message-ID: <9fdb569a0906101339v7da2d55fob77df2c9e2463f3@mail.gmail.com> 2009/6/10 Nick Matzke : > Hi all, > > So I'm parsing an XML file returned from a database. ?However, the database > entries have occasional non-ASCII characters, and this is crashing my > parsers. > > Is there some handy function out there that will schlep through a file like > this, and do something like fix the characters that it can recognize, and > delete those that it can't? ?Basically, like the BBEdit "convert to ASCII" > menu option under "Text". > > I googled some on this, but nothing obvious came up that wasn't specific to > fixing one or a few characters. > > Thanks! > Nick > > > -- > ==================================================== > Nicholas J. Matzke > Ph.D. Candidate, Graduate Student Researcher > Huelsenbeck Lab > Center for Theoretical Evolutionary Genomics > 4151 VLSB (Valley Life Sciences Building) > Department of Integrative Biology > University of California, Berkeley > > Lab websites: > http://ib.berkeley.edu/people/lab_detail.php?lab=54 > http://fisher.berkeley.edu/cteg/hlab.html > Dept. personal page: > http://ib.berkeley.edu/people/students/person_detail.php?person=370 > Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html > Lab phone: 510-643-6299 > Dept. fax: 510-643-6264 > Cell phone: 510-301-0179 > Email: matzke at berkeley.edu > > Mailing address: > Department of Integrative Biology > 3060 VLSB #3140 > Berkeley, CA 94720-3140 > > ----------------------------------------------------- > "[W]hen people thought the earth was flat, they were wrong. When people > thought the earth was spherical, they were wrong. But if you think that > thinking the earth is spherical is just as wrong as thinking the earth is > flat, then your view is wronger than both of them put together." > > Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, > 14(1), 35-44. Fall 1989. > http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm > ==================================================== > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, depending on the circumstances, there are probably more sophisticated ways (what does "fix the characters" mean?), but do you maybe think something like: >>> u"a??b??c??d".encode("ascii", "ignore") 'abcd' ? It might be important to ensure, that you won't loose any useful information; where are the unexpected characters coming from, or couldn't it possibly be fixed in that source? hth, vbr From tjreedy at udel.edu Wed Jun 10 16:41:27 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2009 16:41:27 -0400 Subject: cleaning up an ASCII file? In-Reply-To: <4A301317.8080607@berkeley.edu> References: <4A301317.8080607@berkeley.edu> Message-ID: Nick Matzke wrote: > Hi all, > > So I'm parsing an XML file returned from a database. However, the > database entries have occasional non-ASCII characters, and this is > crashing my parsers. > > Is there some handy function out there that will schlep through a file > like this, and do something like fix the characters that it can > recognize, and delete those that it can't? Basically, like the BBEdit > "convert to ASCII" menu option under "Text". Lookup str.maketrans and str.translate, which can leave alone, replace, or delete each char. From dickinsm at gmail.com Wed Jun 10 16:54:50 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 20:54:50 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: <4a301d9a$0$90270$14726298@news.sunsite.dk> Robert Kern wrote: > On 2009-06-10 14:46, Mark Dickinson wrote: >> On Jun 10, 8:15 pm, Robert Kern wrote: >>> On 2009-06-10 13:53, Terry Reedy wrote: >>>> A full technical discussion does not below in the docs, in my opinion. A >>>> wike article would be fine. >>> True. However, a brief note that "Due to floating point arithmetic, for some >>> values of a and b, b may or may not be one of the possible generated results." >>> might be worthwhile. The actual details of *why* this is the case can be >>> discussed elsewhere. >> >> I find it difficult to see how such a disclaimer would have any >> practical value >> [lots more badly wrapped text snipped... ] > > That's a fair point. However, one issue that hasn't been brought up is that it > might be confusing to a user why random.random() returns values in a half-open > interval while random.uniform() claims a closed interval. Even for reasonably > sophisticated floating point users, it's not necessarily obvious that that is > the reasoning behind the different claims. True. I guess the original post in this thread is good evidence of that. Though I'm not sure I'm capable of coming up with extra wording for the docs that won't just cause more confusion, so I'll leave that to someone else. I seem to recall that when this originally came up in the tracker (issue 4979) the fun part of the analysis was proving that random.uniform(a, b) can never produce values *outside* the interval [a, b]. :-) -- Mark Dickinson From aaron.watters at gmail.com Wed Jun 10 17:08:09 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Wed, 10 Jun 2009 14:08:09 -0700 (PDT) Subject: free chart lib for Python? References: Message-ID: <70761fe3-1753-44e7-9c65-24d5afae5787@q37g2000vbi.googlegroups.com> On May 7, 10:27 pm, oyster wrote: > I mean chart, not plot. If you don't know the difference, you can > checkwww.advsofteng.com, which is a commercial program > > is there such a thing with many kinds ofchart, i.e. pie-chart, > line-chart, ......? > > A long time ago, I programmed a rmchart interface, however rmchart is > windows only, andwww.rmchart.comdisappeared now > > See you I'm about to announce WHIFF/amChart after some more testing. WHIFF/amCharts generates highly sophisticated interactive charts using Adobe/Flash plug-in applets. Documentation here: http://aaron.oirt.rutgers.edu/myapp/amcharts/doc You can get it from the WHIFF mercurial repository for now. http://aaron.oirt.rutgers.edu/cgi-bin/whiffRepo.cgi I will upload a tarball to http://whiff.sourceforge.net soonish. Thanks in advance for any comments. -- Aaron Watters === I want to achieve immortality by not dieing. -- Woody Allen From robert.kern at gmail.com Wed Jun 10 17:09:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 16:09:47 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <4a301d9a$0$90270$14726298@news.sunsite.dk> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> Message-ID: On 2009-06-10 15:54, Mark Dickinson wrote: > Robert Kern wrote: >> On 2009-06-10 14:46, Mark Dickinson wrote: >>> On Jun 10, 8:15 pm, Robert Kern wrote: >>>> On 2009-06-10 13:53, Terry Reedy wrote: >>>>> A full technical discussion does not below in the docs, in my opinion. A >>>>> wike article would be fine. >>>> True. However, a brief note that "Due to floating point arithmetic, for some >>>> values of a and b, b may or may not be one of the possible generated results." >>>> might be worthwhile. The actual details of *why* this is the case can be >>>> discussed elsewhere. >>> I find it difficult to see how such a disclaimer would have any >>> practical value >>> [lots more badly wrapped text snipped... ] >> That's a fair point. However, one issue that hasn't been brought up is that it >> might be confusing to a user why random.random() returns values in a half-open >> interval while random.uniform() claims a closed interval. Even for reasonably >> sophisticated floating point users, it's not necessarily obvious that that is >> the reasoning behind the different claims. > > True. I guess the original post in this thread is good evidence of > that. Though I'm not sure I'm capable of coming up with extra wording > for the docs that won't just cause more confusion, so I'll leave that > to someone else. I did make a concrete suggestion. > I seem to recall that when this originally came up in the tracker > (issue 4979) the fun part of the analysis was proving that > random.uniform(a, b) can never produce values *outside* the interval > [a, b]. :-) I was a bit worried about that part myself for a little bit. :-) -- 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 dfnsonfsduifb at gmx.de Wed Jun 10 17:33:18 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Wed, 10 Jun 2009 23:33:18 +0200 Subject: Compiling Python3.1 In-Reply-To: <4a3010fb$0$22010$9b622d9e@news.freenet.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> Message-ID: <79an4pF1oqpbjU1@mid.dfncis.de> Martin v. L?wis schrieb: >> What can I do about that? > > Remove the non-ASCII characters from db.h. Ehh... $ find -type f | grep -i db.h ./Modules/unicodename_db.h ./Modules/unicodedata_db.h ./Objects/unicodetype_db.h There's no db.h file in the Python-3.1rc1 distribution. The ones above contain thousands of lines (~15k, 5k and 2k) all of which consist of endless arrays of unsigned characters - I really would not know what to remove from those. Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From pavlovevidence at gmail.com Wed Jun 10 17:45:41 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Jun 2009 14:45:41 -0700 (PDT) Subject: random number including 1 - i.e. [0,1] References: Message-ID: On Jun 9, 2:33?pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > > I am implementing an algorithm and want to stay as true to the > original design specifications as possible though I suppose the > difference between the two max values might be minimal. Well, I guess someone should actually describe a solution to this rather than debate the necessity, if only for academic interest. So, in order to do this for real: Generate a random integer the range [0,2**53+1), probably the easiest thing is to get a 64 bit integer and scale it using integer division (which will also help to minimize selection bias). random.randrange probably does something like this already. If the number is exactly 2**53, return 1.0. Else stuff the bits of the number into the mantissa of a double, along with -1 as the exponent, and return that. Implementation left as exercise, mostly because it really won't make a difference. Carl Banks From dickinsm at gmail.com Wed Jun 10 17:47:53 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: 10 Jun 2009 21:47:53 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> Message-ID: <4a302a09$0$90270$14726298@news.sunsite.dk> Robert Kern wrote: > On 2009-06-10 15:54, Mark Dickinson wrote: >> [...] I'm not sure I'm capable of coming up with extra wording >> for the docs that won't just cause more confusion, so I'll leave that >> to someone else. > > I did make a concrete suggestion. Yes, you did. Thank you. Submitted as http://bugs.python.org/issue6261 > >> I seem to recall that when this originally came up in the tracker >> (issue 4979) the fun part of the analysis was proving that >> random.uniform(a, b) can never produce values *outside* the interval >> [a, b]. :-) > > I was a bit worried about that part myself for a little bit. :-) > I think the key was to show that multiplication by (1-2**-53) (the largest possible output of random.random()) always makes any float smaller in magnitude[*], so assuming that a <= b the value of the Python expression random.random()*(b-a) can't be larger than the exact real value of (b-a), which in turn means that a + random.random()*(b-a) can't exceed b. [*] Well, almost. This isn't true for subnormals. But if the result of the subtraction b-a is subnormal then that subtraction was also necessarily exact, so everything works in this case, too. And of course I'm wrong. I shouldn't have said *never*, above: >>> from random import uniform >>> uniform(-1e308, 1e308) inf :-( Somehow this doesn't seem worth either fixing or documenting, though. -- Mark Dickinson From mwilson at the-wire.com Wed Jun 10 17:49:10 2009 From: mwilson at the-wire.com (Mel) Date: Wed, 10 Jun 2009 17:49:10 -0400 Subject: SPAM-LOW: Re: Function/method returning list of chars in string? References: <000b01c9e8d3$6fb2c4a0$0d00a8c0@Hendrik> <50697b2c0906090032t1c4d4a0bk705b3e54545f16b2@mail.gmail.com> <005401c9e8e7$b21b6900$0d00a8c0@Hendrik> <598e7ec7-52d5-48fd-beae-3596a2297d64@s16g2000vbp.googlegroups.com> Message-ID: Terry Reedy wrote: > Str.join takes any iterable of strings and constructs a string. Only > str knows how to do that, though it could have a built-in that called a > hypothetical .__join__ method. However, Python started with just one > string type and there does not seem much use for joining an indefinite > number of tuples or lists. I can imagine numbers = [655, 583, 675, 456, 496, 239, 888] something = numbers.join (2) but I can't imagine what it could possibly be for. Something in the Goedelization line? Mel. From martin at v.loewis.de Wed Jun 10 18:19:08 2009 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 11 Jun 2009 00:19:08 +0200 Subject: Compiling Python3.1 In-Reply-To: <79an4pF1oqpbjU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> <79an4pF1oqpbjU1@mid.dfncis.de> Message-ID: <4a30315c$0$20515$9b622d9e@news.freenet.de> Johannes Bauer wrote: > Martin v. L?wis schrieb: >>> What can I do about that? >> Remove the non-ASCII characters from db.h. > > Ehh... > > $ find -type f | grep -i db.h > ./Modules/unicodename_db.h > ./Modules/unicodedata_db.h > ./Objects/unicodetype_db.h > > There's no db.h file in the Python-3.1rc1 distribution. Correct. I was referring to the db.h from your operating system. See line 728 of setup.py. Regards, Martin From sjmachin at lexicon.net Wed Jun 10 18:23:32 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 10 Jun 2009 15:23:32 -0700 (PDT) Subject: cleaning up an ASCII file? References: Message-ID: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> On Jun 11, 6:09?am, Nick Matzke wrote: > Hi all, > > So I'm parsing an XML file returned from a database. ?However, the > database entries have occasional non-ASCII characters, and this is > crashing my parsers. So fix your parsers. google("unicode"). Deleting stuff that you don't understand is an "interesting" approach to academic research :-( Care to divulge what "crash" means? e.g. the full traceback and error message, plus what version of python on what platform, what version of ElementTree or other XML spftware you are using ... > Center for Theoretical Evolutionary Genomics If your .sig evolves much more, it will consume all available bandwidth in the known universe and then some ;-) From grahn+nntp at snipabacken.se Wed Jun 10 18:24:12 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 22:24:12 GMT Subject: Using logging module to log into flash drive References: Message-ID: On Tue, 9 Jun 2009 18:10:18 +0100, A. Cavallo wrote: [top-posting fixed] > On Tuesday 09 June 2009 16:57:00 kretel wrote: >> Hi All, >> >> I am trying to implement the following functionality: >> 1. log messages to the flash drive >> 2. if the flash drive is not available, switch handler to the >> BufferringHandler and log into buffer, >> 3. once the flash drive is plugged in and available store the logs >> from BufferHandler into that flash drive and switch the handler into >> RotateFileHandler. >> >> Which approach would you suggest to use while implementing this >> functionality? First, to ignore the words "flash drive" and think in terms of "can I open the file named so-and-so for writing?". Unless you absolutely must avoid storing your file on a file system based on some other storage technology. >> One that come into my mind is to have one process or >> thread to check periodically if the flashdrive is available, and have >> a flag that will indicate that we can store the logs into the flash >> drive. But I don't particularly like this approach. >> Would you do it different way? >> Any suggestions are appreciated. > Hi, > the problem screams for a separate thread. I don't hear any screaming. It seems simpler to just def log(something): if logging_to_memore() and seconds_since_i_last_checked() > N: try_to_switch_to_file() do_the_actual_logging(something) unless it's vital that as many of these logs as possible survive a crash (in which case I guess the program would also refuse to exit until the user finds the physical flash memory device somewhere and mounts it correctly -- flashback to ancient floppy-based Macs). Yes, I find the requirements quite odd. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From dw at botanicus.net Wed Jun 10 18:24:13 2009 From: dw at botanicus.net (David Wilson) Date: Wed, 10 Jun 2009 15:24:13 -0700 (PDT) Subject: itertools.intersect? Message-ID: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Hi, During a fun coding session yesterday, I came across a problem that I thought was already solved by itertools, but on investigation it seems it isn't. The problem is simple: given one or more ordered sequences, return only the objects that appear in each sequence, without reading the whole set into memory. This is basically an SQL many-many join. I thought it could be accomplished through recursively embedded generators, but that approach failed in the end. After posting the question to Stack Overflow[0], Martin Geisler proposed a wonderfully succinct and reusable solution (see below, or pretty printed at the Stack Overflow URL). It is my opinion that this particular implementation is a wonderful and incredibly valid use of iterators, and something that could be reused by others, certainly least not myself again in the future. With that in mind I thought it, or something very similar, would be a great addition to the itertools module. My question then is, are there better approaches to this? The heapq- based solution at the Stack Overflow page is potentially more useful still, for its ability to operate on orderless sequences, but in that case, it might be better to simply listify each sequence, and sort it before passing to the ordered-only functions. Thanks, David. Stack Overflow page here: http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-integer-yielding-python-iterators Sweet solution: import operator def intersect(sequences): """Compute intersection of sequences of increasing integers. >>> list(intersect([[1, 100, 142, 322, 12312], ... [2, 100, 101, 322, 1221], ... [100, 142, 322, 956, 1222]])) [100, 322] """ iterators = [iter(seq) for seq in sequences] last = [iterator.next() for iterator in iterators] indices = range(len(iterators)) while True: # The while loop stops when StopIteration is raised. The # exception will also stop the iteration by our caller. if reduce(operator.and_, [l == last[0] for l in last]): # All iterators contain last[0] yield last[0] last = [iterator.next() for iterator in iterators] # Now go over the iterators once and advance them as # necessary. To stop as soon as the smallest iterator we # advance each iterator only once per loop iteration. for i in indices[:-1]: if last[i] < last[i+1]: last[i] = iterators[i].next() if last[i] > last[i+1]: last[i+1] = iterators[i+1].next() From grahn+nntp at snipabacken.se Wed Jun 10 18:32:45 2009 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 10 Jun 2009 22:32:45 GMT Subject: python and getopt and spaces in option References: Message-ID: On Tue, 9 Jun 2009 12:22:20 -0400, David Shapiro wrote: > I have been trying to find an example of how to deal with options > that have spaces in them. I am using jython, which is the same I > think as python 2.2.3. I feebly tried to use optparse and argparse > with no success (got gettext, locale, and optparse). The code is as > follows: > > try: > (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v", > ["help", "server=", "port=", "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"]) > except getopt.GetoptError: > usage() > > for opt in opts: > (key, value) = opt ... > if (key in ("-q", "--testTableName")): ... > The one that gives me trouble is with the -q option, because it can > look like: -q "SQL 1 TABLE". It returns back just SQL. How do I get > it to return the whole thing that is in double quotes? You are probably calling the program incorrectly. A non-broken getopt has no trouble with such things. When executing a program from a normal Unix shell, single or double quotes (like you do above) is enough. I'd expect other environments to behave in the same way. If -q only eats the string "SQL", where does "1 TABLE" go? It cannot just disappear; does it end up in 'args'? /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From cseberino at gmail.com Wed Jun 10 18:38:00 2009 From: cseberino at gmail.com (Chris Seberino) Date: Wed, 10 Jun 2009 15:38:00 -0700 (PDT) Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? Message-ID: How build new elements to replace existing ones using xml.dom.minidom? Specifically, I have an HTML table of numbers. I want to replace those numbers with hyperlinks to create a table of hyperlinks. So I need to build hyperlinks (a elements) with href attribute and replace the text elements (numbers) somehow. How do that? chris From clp2 at rebertia.com Wed Jun 10 19:43:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 16:43:38 -0700 Subject: Can not dump class object created on runtime In-Reply-To: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> References: <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Message-ID: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> On Wed, Jun 10, 2009 at 7:25 AM, Metal Zong wrote: > Hello, > > Can not dump class object created on runtime. > > Is there anybody can help me? Thank. > > Following is testing code: > > import pickle > from new import classobj > > class A: > ??? def __str__(self): > ??????? return self.__class__.name > > if __name__ == "__main__": > ??? c = classobj('B', (A, ), {}) # create class obj on runtime > ??? print c > ??? print pickle.dumps(c) # get dump string > > Bellows are outputs: > > __main__.B > Traceback (most recent call last): > ? File "C:\USERS\train\_work\test\test.py", line 11, in > ??? print pickle.dumps(c) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps > ??? Pickler(file, protocol).dump(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump > ??? self.save(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save > ??? f(self, obj) # Call unbound method with explicit self > ? File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global > ??? (obj, module, name)) > pickle.PicklingError: Can't pickle : it's > not found as __main__.B pickle stores classes by storing their fully-qualified name (eg. "foo.bar.Baz") and NOT by storing the internal Python structures that represent the class (as there are apparently various problem associated with this). So when it unpickles, it just imports the fully-qualified name normally and returns the result of that. Since dynamically-created classes have no fully-qualified name, they can't be stored this way; hence, you get an exception when trying to pickle.dump() them. Also, you shouldn't use `classobj` as I believe that's only for old-style classes, which are being phased out. Its replacement is the built-in `type` metaclass, which creates new-style classes. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Wed Jun 10 19:48:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 16:48:42 -0700 Subject: Restart the interactive python shell like in IDLE In-Reply-To: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> References: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> Message-ID: <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> On Wed, Jun 10, 2009 at 12:01 PM, Matt Burson wrote: > Is there a way to reproduce the behavior of IDLE's restart shell ability by > using a function? I thought there would be since you can exit python by > executing the simple quit() function I thought there would be an equally > simple function name something like restart(). I'd prefer something like > this as opposed to having to exit the shell and then start it up again to > refresh it. I believe IDLE itself implements the "restart" capability by killing and re-launching its Python interpreter subprocess, so it's not like it's using some hidden capability of Python to accomplish this. Is doing Ctrl+D, up-arrow, Enter really that hard? It's even fewer keystrokes than "restart()"... Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Wed Jun 10 19:54:18 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Jun 2009 18:54:18 -0500 Subject: random number including 1 - i.e. [0,1] In-Reply-To: <4a302a09$0$90270$14726298@news.sunsite.dk> References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> <4a301d9a$0$90270$14726298@news.sunsite.dk> <4a302a09$0$90270$14726298@news.sunsite.dk> Message-ID: On 2009-06-10 16:47, Mark Dickinson wrote: > And of course I'm wrong. I shouldn't have said *never*, above: > >>>> from random import uniform >>>> uniform(-1e308, 1e308) > inf > > :-( > > Somehow this doesn't seem worth either fixing or documenting, though. Agreed. -- 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 dcest61 at hotmail.com Wed Jun 10 19:55:00 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Wed, 10 Jun 2009 23:55:00 GMT Subject: multi-core software In-Reply-To: <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> <09udndwb56fpWLLXnZ2dnUVZ8hSdnZ2d@brightview.co.uk> Message-ID: Jon Harrop wrote: > Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon Harrop wrote: >>>>> No. Concurrent programming is about interleaving computations in order >>>>> to reduce latency. Nothing to do with parallelism. >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> >> I'm not being facetious. I write applications that run on application >> servers, and from time to time I have had to write various special >> purpose servers. This kind of programming is all about managing >> concurrent execution of computations. The overarching concern is >> reliability and correct function. For many corporate situations, even >> with hundreds of users, the actual load at any instant is low enough >> that the various servers involved are nowhere close to being stressed >> out - performance is a secondary issue. > > In other words, without concurrency the latency would be so high that you > would consider the program to be wrong. However you cut it, the real reason > is latency. For a certain group of applications and user loads I would concede that point, yes. For quite a few other situations, you could queue up user requests and execute them in order, finishing each before proceeding to the next, and users wouldn't even notice. I wrote a J2SE server a few months ago, to solve a very specific problem associated with an application running on a J2EE server, that could handle dozens of users per second using this strategy. It didn't write it that way because doing so is perverse, but I could have. AHS From jackdied at gmail.com Wed Jun 10 19:59:18 2009 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 10 Jun 2009 19:59:18 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Wed, Jun 10, 2009 at 6:24 PM, David Wilson wrote: > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. After posting the > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > succinct and reusable solution (see below, or pretty printed at the > Stack Overflow URL). > [snip] Here's my version; ?keep a list of (curr_val, iterator) tuples and operate on those. def intersect(seqs): ? ?iter_pairs = [(it.next(), it) for (it) in map(iter, seqs)] ? ?while True: ? ? ? ?min_val = min(iter_pairs)[0] ? ? ? ?max_val = max(iter_pairs)[0] ? ? ? ?if min_val == max_val: ? ? ? ? ? ?yield min_val ? ? ? ? ? ?max_val += 1 # everybody advances ? ? ? ?for i, (val, it) in enumerate(iter_pairs): ? ? ? ? ? ?if val < max_val: ? ? ? ? ? ? ? ?iter_pairs[i] = (it.next(), it) ? ?# end while True Interestingly you don't need to explicitly catch StopIteration and return because only the top level is a generator. ?So both lines where it.next() are called will potentially end the loop. I also tried using a defaultdict(list) as the main structure; it worked but was uglier by far { curr_val => [it1, it2, ..]} with dels and appends. -Jack ps, woops, I forgot to hit reply all the first time. From dcest61 at hotmail.com Wed Jun 10 20:06:08 2009 From: dcest61 at hotmail.com (Arved Sandstrom) Date: Thu, 11 Jun 2009 00:06:08 GMT Subject: multi-core software In-Reply-To: References: <500f8756-fb11-4ac9-b30c-bc6170bab4ce@j20g2000vbp.googlegroups.com> <20090617091529.242@gmail.com> <6baj251aj9jb23ga5b1s0aqng59t66v9rt@4ax.com> <7KudnYRCR5KtzrHXnZ2dnUVZ8kOdnZ2d@brightview.co.uk> Message-ID: Jeff M. wrote: > On Jun 9, 9:08 pm, Arved Sandstrom wrote: >> Jon Harrop wrote: >>> Arved Sandstrom wrote: >>>> Jon, I do concurrent programming all the time, as do most of my peers. >>>> Way down on the list of why we do it is the reduction of latency. >>> What is higher on the list? >> Correctness. >> > > IMO, that response is a bit of a cop-out. Correctness is _always_ most > important, no matter what application you are creating; without it, > you don't have a job and the company you work for goes out of > business. > > But, assuming that your program works and does what it's supposed to, > I agree with Jon that performance needs to be right near the top of > the list of concerns. Why? Performance isn't about looking good as a > programmer, or having fun making a function run in 15 cycles instead > of 24, or coming up with some neat bit packing scheme so that your app > now only uses 20K instead of 200K. Performance is - pure and simple - > about one thing only: money. > > Programs that use more memory require more money for the hardware of > every user. Programs that run slower eat more time per day. If you > have 100,000 users, all doing an operation once per day that takes 20 > seconds, being able to shave 5 seconds off that saves 5.78 man-days of > work. Hell, for some applications, that 20 seconds is just startup > time spent at a splash screen. Just imagine if every Google search > took even 5 seconds to resolve, how much time would be wasted every > day around the world - ignoring the fact that Google wouldn't exist if > that were the case ;-). Obviously Google engineers work incredibly > hard every day to ensure correct results, but performance better be > right up there at the top of the list as well. > > Jeff M. Point taken, but I primarily work on internal government and corporate applications. Might be hundreds or thousands of users at any given time, but not typically tens or hundreds of thousands. Hundreds or thousands of users translates to at least an order of magnitude less "simultaneous" users. Ops people that I talk to who monitor apps I've worked on, or similar apps, rarely report any such where the application itself is presenting a sluggish aspect to users because it's stressing out processors, or consuming gargantuan memory. Typically when latency problems come up, it's because the app has to talk to other servers - databases, LDAP, print servers etc. In other words, the network is coming into play. In fact when we do work on performance, it's typically about minimizing calls to the database or other services. AHS From ken at seehart.com Wed Jun 10 20:09:46 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Jun 2009 17:09:46 -0700 Subject: xmlrpclib and generators In-Reply-To: <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> References: <4A2F9BB2.6010005@seehart.com> <002a01c9e9da$1a476a40$0d00a8c0@Hendrik> Message-ID: <4A304B4A.6050802@seehart.com> Hendrik van Rooyen wrote: > Ken Seehart wrote: > > 8< ------------ implementation -------------- > > >> The practical constraints of my specific application are: >> 1. The rpc server is a highly specialized slave system that does heavy duty >> work. >> >> 2. The rpc client is itself a web server that dispatches work requests to the >> rpc server(s) and displays the >current status of work done so far. >> >> 3. The generators will typically run for a long time (hours) and yield data >> periodically (perhaps once a minute). >> > > > If this "yield" can be made to be, or if it is, supply side driven, instead of > yielding on demand like a > generator, then I would set up a simple TCP/IP peer to peer socket link and just > send the result > back when it is ready. If you have to "serve" more than one such link, it is a > simple matter > to keep a list of queues linking the different socket sets to the "generator", > and to iterate over > the list, putting a copy of the thing that was just produced into each queue. > > Of course, the thing you want to pass back must be serializable. > It is supply side driven, and the content would be serializable. The only reason I want something high level like xmlrpc or Pyro instead of rolling my own stuff with TCP/IP is that I want the client and server to be easily customizable. > Have you looked at Pyro? > Not yet. Looking at it now. Thanks, it looks like Pyro may be very relevant. Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From matzke at berkeley.edu Wed Jun 10 20:52:09 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 17:52:09 -0700 Subject: cleaning up an ASCII file? In-Reply-To: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> Message-ID: <4A305539.1050108@berkeley.edu> Apologies, I figured there was some easy, obvious solution, since there is in BBedit. I will explain further... John Machin wrote: > On Jun 11, 6:09 am, Nick Matzke wrote: >> Hi all, >> >> So I'm parsing an XML file returned from a database. However, the >> database entries have occasional non-ASCII characters, and this is >> crashing my parsers. > > So fix your parsers. google("unicode"). Deleting stuff that you don't > understand is an "interesting" approach to academic research :-( Not if it's just weird versions of dash characters and umlauted characters the like, which is what I bet it is. Those sorts of things and the apparent inability of lots of email readers and websites to deal with them have been annoying me for years, so I tend to move straight towards genocidal tactics when I detect their presence. (My database source is GBIF, they get museum specimen submissions from around the planet, there are zillions of records, I am just a user, so fixing it on their end is not a realistic option.) > Care to divulge what "crash" means? e.g. the full traceback and error > message, plus what version of python on what platform, what version of > ElementTree or other XML spftware you are using ... All that is fine, the problem is actually when I try to print to screen in IPython: ============ UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 293: ordinal not in range(128) ============ Probably this is the line in the file which is causing problems (as displayed in BBedit): ====================== - This document contains data shared through the GBIF Network - see http://data.gbif.org/ for more information. All usage of these data must be in accordance with the GBIF Data Use Agreement - see http://www.gbif.org/DataProviders/Agreements/DUA Please cite these data as follows: Jyväskylä University Museum - The Section of Natural Sciences, Vascular plant collection of Jyvaskyla University Museum (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/462, 2009-06-11) Missouri Botanical Garden, Missouri Botanical Garden (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/621, 2009-06-11) Museo Nacional de Costa Rica, herbario (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/566, 2009-06-11) National Science Museum, Japan, Kurashiki Museum of Natural History (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/599, 2009-06-11) The Swedish Museum of Natural History (NRM), Herbarium of Oskarshamn (OHN) (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/1024, 2009-06-11) Tiroler Landesmuseum Ferdinandeum, Tiroler Landesmuseum Ferdinandeum (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/1509, 2009-06-11) UCD, Database Schema for UC Davis [Herbarium Labels] (accessed through GBIF data portal, http://data.gbif.org/datasets/resource/734, 2009-06-11) - ====================== Presumably "Jyväskylä University Museum" is the problem since there are umlauted a's in there. (Note, though, that I have thousands of records to parse, so there is going to be all kinds of other umlauted & accented stuff in these sorts of search results. So the goal is to replace the characters with un-umlauted versions or some such. Cheers! Nick PS: versions I am using: ======== nick$ python -V Python 2.5.2 |EPD Py25 4.1.30101| ======== >> Center for Theoretical Evolutionary Genomics > > If your .sig evolves much more, it will consume all available > bandwidth in the known universe and then some ;-) ...its easier to have a big sig than to try and remember all that stuff ;-)... -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From mensanator at aol.com Wed Jun 10 20:53:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 10 Jun 2009 17:53:59 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 5:24?pm, David Wilson wrote: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > Why not use SQL? import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.executescript(""" create table test1(p INTEGER); """) cur.executescript(""" create table test2(q INTEGER); """) cur.executescript(""" create table test3(r INTEGER); """) for t in ((1,),(100,),(142,),(322,),(12312,)): cur.execute('insert into test1 values (?)', t) for t in ((2,),(100,),(101,),(322,),(1221,)): cur.execute('insert into test2 values (?)', t) for t in ((100,),(142,),(322,),(956,),(1222,)): cur.execute('insert into test3 values (?)', t) cur.execute(""" SELECT p FROM (test1 INNER JOIN test2 ON p = q) INNER JOIN test3 ON p = r; """) sqlintersect = cur.fetchall() for i in sqlintersect: print i[0], print ## ## 100 322 ## From myopc at aaa.com Wed Jun 10 21:40:11 2009 From: myopc at aaa.com (myopc) Date: Thu, 11 Jun 2009 09:40:11 +0800 Subject: multi-thread python interpreaters and c++ program References: <6deac4c8-b208-4fbf-8098-8dc7af7f881b@r34g2000vba.googlegroups.com> Message-ID: thanks, I use gdb to debug, and cant find any symbol in the stack. I wanna to exit from outside python, without tell anything to the interpreator, but it seems impossible "Floris Bruynooghe" :6deac4c8-b208-4fbf-8098-8dc7af7f881b at r34g2000vba.googlegroups.com... On Jun 9, 6:50 am, "myopc" wrote: > I am ruuning a c++ program (boost python) , which create many python > interpreaters and each run a python script with use multi-thread > (threading). > when the c++ main program exit, I want to shut down python interpreaters, > but it crashed. Your threads are daemonic, you could be seeing http://bugs.python.org/issue1856 You'll have to check your stack in a debugger to know. But as said this can be avoided by making the threads finish themself and joining them. Regards Floris From metalzong at 163.com Wed Jun 10 21:55:02 2009 From: metalzong at 163.com (metalzong) Date: Thu, 11 Jun 2009 09:55:02 +0800 (CST) Subject: Can not dump class object created on runtime In-Reply-To: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> References: <50697b2c0906101643s59cef8c1t52519a0a3b2b6416@mail.gmail.com> <000301c9e9d7$4bfafc30$6500a8c0@nsnintra.net> Message-ID: <8386134.93891244685302147.JavaMail.coremail@bj163app54.163.com> Thanks a lot. ?2009-06-11?"Chris Rebert" ??? On Wed, Jun 10, 2009 at 7:25 AM, Metal Zong wrote: > Hello, > > Can not dump class object created on runtime. > > Is there anybody can help me? Thank. > > Following is testing code: > > import pickle > from new import classobj > > class A: > ??? def __str__(self): > ??????? return self.__class__.name > > if __name__ == "__main__": > ??? c = classobj('B', (A, ), {}) # create class obj on runtime > ??? print c > ??? print pickle.dumps(c) # get dump string > > Bellows are outputs: > > __main__.B > Traceback (most recent call last): > ? File "C:\USERS\train\_work\test\test.py", line 11, in > ??? print pickle.dumps(c) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 1366, in dumps > ??? Pickler(file, protocol).dump(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 224, in dump > ??? self.save(obj) > ? File "c:\USERS\train\Python25\lib\pickle.py", line 286, in save > ??? f(self, obj) # Call unbound method with explicit self > ? File "c:\USERS\train\Python25\lib\pickle.py", line 748, in save_global > ??? (obj, module, name)) > pickle.PicklingError: Can't pickle : it's > not found as __main__.B pickle stores classes by storing their fully-qualified name (eg. "foo.bar.Baz") and NOT by storing the internal Python structures that represent the class (as there are apparently various problem associated with this). So when it unpickles, it just imports the fully-qualified name normally and returns the result of that. Since dynamically-created classes have no fully-qualified name, they can't be stored this way; hence, you get an exception when trying to pickle.dump() them. Also, you shouldn't use `classobj` as I believe that's only for old-style classes, which are being phased out. Its replacement is the built-in `type` metaclass, which creates new-style classes. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Jun 10 22:05:06 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 19:05:06 -0700 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <50697b2c0906101905w4596ebd5s1e11314f4a052c8a@mail.gmail.com> On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > On Jun 10, 5:24?pm, David Wilson wrote: >> Hi, >> >> During a fun coding session yesterday, I came across a problem that I >> thought was already solved by itertools, but on investigation it seems >> it isn't. >> >> The problem is simple: given one or more ordered sequences, return >> only the objects that appear in each sequence, without reading the >> whole set into memory. This is basically an SQL many-many join. >> > > Why not use SQL? Agreed. I seem to recall the last person asking for such a function wanted to use it to combine SQL results. Cheers, Chris -- http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Wed Jun 10 22:06:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Jun 2009 02:06:16 GMT Subject: random number including 1 - i.e. [0,1] References: <0c66e41c-84bb-45dc-9bdd-613e19c6d30b@r33g2000yqn.googlegroups.com> <2c8e3cc6-4b82-4b43-b82d-f6a69a954109@x5g2000yqk.googlegroups.com> <2c9a6836-f785-4b7f-9241-b5f197c1fab0@r34g2000vba.googlegroups.com> <422c6c93-532e-4024-985f-bd5734e137fa@p4g2000vba.googlegroups.com> Message-ID: On Wed, 10 Jun 2009 15:32:05 -0500, Robert Kern wrote: > That's a fair point. However, one issue that hasn't been brought up is > that it might be confusing to a user why random.random() returns values > in a half-open interval while random.uniform() claims a closed interval. > Even for reasonably sophisticated floating point users, it's not > necessarily obvious that that is the reasoning behind the different > claims. Agreed -- the reasoning that a half-open interval [0, 1) for z (random()) leads to a closed interval [a, b] for a+(b-a)*z (uniform()) is *not* obvious even for people who are aware that floats do funny things. I know I got caught out by it. However, rather than a documentation patch, I'd prefer to see uniform() fixed to return a value in the half-open interval. Something like: def uniform(self, a, b): """Get a random number in the range [a, b).""" r = a + (b-a) * self.random() while r == b: # Guard against (rare) rounding to b. r = a + (b-a) * self.random() return r should do the trick. I think. Earlier, Mark Dickinson wrote: "Can you think of a single practical situation where it would matter that, for some values of a and b, uniform(a, b) can never produce the value b?" I would argue that it is a good thing if uniform never returns b. alist[ int(uniform(0, len(alist))) ] can apparently fail for some lists, but not others. Admittedly, I don't have a good reason for using the above rather than sample(), or for truncating the result of uniform() rather than using randrange(). Hopefully if I don't mention it, nobody will notice it... *wink* -- Steven From matzke at berkeley.edu Wed Jun 10 22:22:27 2009 From: matzke at berkeley.edu (Nick Matzke) Date: Wed, 10 Jun 2009 19:22:27 -0700 Subject: cleaning up an ASCII file? In-Reply-To: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> Message-ID: <4A306A63.8050202@berkeley.edu> Looks like this was a solution: 1. Use this guy's unescape function to convert from HTML/XML Entities to unicode http://effbot.org/zone/re-sub.htm#unescape-html 2. Take the unicode and convert to approximate plain ASCII matches with unicodedata (after import unicodedata) ascii_content2 = unescape(line) ascii_content = unicodedata.normalize('NFKD', unicode(ascii_content2)).encode('ascii','ignore') The string "line" would give the error, but ascii_content does not. Cheers! Nick PS: "asciiDammit" is also fun to look at John Machin wrote: > On Jun 11, 6:09 am, Nick Matzke wrote: >> Hi all, >> >> So I'm parsing an XML file returned from a database. However, the >> database entries have occasional non-ASCII characters, and this is >> crashing my parsers. > > So fix your parsers. google("unicode"). Deleting stuff that you don't > understand is an "interesting" approach to academic research :-( > > Care to divulge what "crash" means? e.g. the full traceback and error > message, plus what version of python on what platform, what version of > ElementTree or other XML spftware you are using ... > >> Center for Theoretical Evolutionary Genomics > > If your .sig evolves much more, it will consume all available > bandwidth in the known universe and then some ;-) -- ==================================================== Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: matzke at berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 ----------------------------------------------------- "[W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm ==================================================== From janssonks at gmail.com Wed Jun 10 22:38:14 2009 From: janssonks at gmail.com (Karl Jansson) Date: Wed, 10 Jun 2009 21:38:14 -0500 Subject: installation in mac os x Message-ID: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> Hi, I was doing the tutorial at http://www.python.org/doc/current/ tutorial/, and I came across some code that did not work, and I got the following error: AttributeError: 'str' object has no attribute 'format'. So I downloaded a .dmg of python 2.6.2 and then I installed it. But it's not working. Running the Python launcher, the "new" command in the file menu is grey, and won't work, so I can't make any scripts. Does anyone know how to make python 2.6.2 work in mac os x? Thanks, Stefan From dw at botanicus.net Wed Jun 10 22:43:51 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 19:43:51 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <082b59d6-8841-40f4-bddd-ea9a243287b4@c36g2000yqn.googlegroups.com> On Jun 11, 3:05?am, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > > On Jun 10, 5:24?pm, David Wilson wrote: > >> Hi, > > >> During a fun coding session yesterday, I came across a problem that I > >> thought was already solved by itertools, but on investigation it seems > >> it isn't. > > >> The problem is simple: given one or more ordered sequences, return > >> only the objects that appear in each sequence, without reading the > >> whole set into memory. This is basically an SQL many-many join. > > > Why not use SQL? > > Agreed. I seem to recall the last person asking for such a function > wanted to use it to combine SQL results. > My original use case was a full text indexer. Here's the code: http://code.google.com/p/ghetto-fts/ Let me invert the question and ask: why would I want to use SQL for this? Or in my own words: what kind of girly-code requires an RDBMS just to join some sequences? =) Given that Google reports 14.132 billion occurrences of "the" on the English web, which is about right, given that some estimate the English web at ~15 billion documents, or about 33.8 bits to uniquely identify each document, let's assume we use a 64bit integer, that's theoretically 111.7GiB of data loaded into SQL just for a single word. Introducing SQL quickly results in artificially requiring a database system, when a 15 line function would have sufficed. It also restricts how I store my data, and prevents, say, using a columnar, variable length, or delta encoding on my sequence of document IDs, which would massively improve the storage footprint (say, saving 48-56 bits per element). I'll avoid mention of the performance aspects altogether. "What the hell are you thinking", David > Cheers, > Chris > --http://blog.rebertia.com From higerinbeijing at gmail.com Wed Jun 10 23:11:50 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 10 Jun 2009 20:11:50 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix Message-ID: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> I just want to compare two files,one from windows and the other from unix. But I do not want to compare them through reading them line by line. Then I found there is a filecmp module which is used as file and directory comparisons. However,when I use two same files (one from unix,one from windows,the content of them is the same) to test its cmp function, filecmp.cmp told me false. Later, I found that windows use '\n\r' as new line flag but unix use '\n', so filecmp.cmp think that they are different,then return false. So, can anyone tell me that is there any method like IgnoreNewline which can ignore the difference of new line flag in diffrent platforms? If not,I think filecmp may be not a good file comparison module. Thanks, higer From clp2 at rebertia.com Wed Jun 10 23:44:21 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Jun 2009 20:44:21 -0700 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix In-Reply-To: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> Message-ID: <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: > I just want to compare two files,one from windows and the other from > unix. But I do not want to compare them through reading them line by > line. Then I found there is a filecmp module which is used as file and > directory comparisons. However,when I use two same files (one from > unix,one from windows,the content of them is the same) to test its cmp > function, filecmp.cmp told me false. > > Later, I found that windows use '\n\r' as new line flag but unix use > '\n', so filecmp.cmp think that they are different,then return false. > So, can anyone tell me that is there any method like IgnoreNewline > which can ignore the difference of new line flag in diffrent > platforms? If not,I think filecmp may be not a good file comparison Nope, there's no such flag. You could run the files through either `dos2unix` or `unix2dos` beforehand though, which would solve the problem. Or you could write the trivial line comparison code yourself and just make sure to open the files in Universal Newline mode (add 'U' to the `mode` argument to `open()`). You could also file a bug (a patch to add newline insensitivity would probably be welcome). Cheers, Chris -- http://blog.rebertia.com From dw at botanicus.net Wed Jun 10 23:56:55 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 20:56:55 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: <9baec91e-a371-4949-b7f7-b134daccaeff@y7g2000yqa.googlegroups.com> On Jun 11, 12:59?am, Jack Diederich wrote: > On Wed, Jun 10, 2009 at 6:24 PM, David Wilson wrote: > > During a fun coding session yesterday, I came across a problem that I > > thought was already solved by itertools, but on investigation it seems > > it isn't. > > > The problem is simple: given one or more ordered sequences, return > > only the objects that appear in each sequence, without reading the > > whole set into memory. This is basically an SQL many-many join. > > > I thought it could be accomplished through recursively embedded > > generators, but that approach failed in the end. After posting the > > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > > succinct and reusable solution (see below, or pretty printed at the > > Stack Overflow URL). > > [snip] > > Here's my version; ?keep a list of (curr_val, iterator) tuples and > operate on those. > > def intersect(seqs): > ? ?iter_pairs = [(it.next(), it) for (it) in map(iter, seqs)] > ? ?while True: > ? ? ? ?min_val = min(iter_pairs)[0] > ? ? ? ?max_val = max(iter_pairs)[0] > ? ? ? ?if min_val == max_val: > ? ? ? ? ? ?yield min_val > ? ? ? ? ? ?max_val += 1 # everybody advances > ? ? ? ?for i, (val, it) in enumerate(iter_pairs): > ? ? ? ? ? ?if val < max_val: > ? ? ? ? ? ? ? ?iter_pairs[i] = (it.next(), it) > ? ?# end while True This version is a lot easier to understand. The implicit StopIteration is a double-edged sword for readability, but I like it. :) David > > Interestingly you don't need to explicitly catch StopIteration and > return because only the top level is a generator. ?So both lines where > it.next() are called will potentially end the loop. > I also tried using a defaultdict(list) as the main structure; it > worked but was uglier by far { curr_val => [it1, it2, ..]} with dels > and appends. > > -Jack > > ps, woops, I forgot to hit reply all the first time. From dw at botanicus.net Thu Jun 11 00:03:10 2009 From: dw at botanicus.net (David M. Wilson) Date: Wed, 10 Jun 2009 21:03:10 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 11:24?pm, David Wilson wrote: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. > > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. After posting the > question to Stack Overflow[0], Martin Geisler proposed a wonderfully > succinct and reusable solution (see below, or pretty printed at the > Stack Overflow URL). > > It is my opinion that this particular implementation is a wonderful > and incredibly valid use of iterators, and something that could be > reused by others, certainly least not myself again in the future. With > that in mind I thought it, or something very similar, would be a great > addition to the itertools module. > > My question then is, are there better approaches to this? The heapq- > based solution at the Stack Overflow page is potentially more useful > still, for its ability to operate on orderless sequences, but in that > case, it might be better to simply listify each sequence, and sort it > before passing to the ordered-only functions. > > Thanks, > > David. > > Stack Overflow page here: > > http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-in... > > Sweet solution: > > ? ? import operator > > ? ? def intersect(sequences): > ? ? ? ? """Compute intersection of sequences of increasing integers. > > ? ? ? ? >>> list(intersect([[1, ? 100, 142, 322, 12312], > ? ? ? ? ... ? ? ? ? ? ? ? ? [2, ? 100, 101, 322, 1221], > ? ? ? ? ... ? ? ? ? ? ? ? ? [100, 142, 322, 956, 1222]])) > ? ? ? ? [100, 322] > > ? ? ? ? """ > ? ? ? ? iterators = [iter(seq) for seq in sequences] > ? ? ? ? last = [iterator.next() for iterator in iterators] > ? ? ? ? indices = range(len(iterators)) > ? ? ? ? while True: > ? ? ? ? ? ? # The while loop stops when StopIteration is raised. The > ? ? ? ? ? ? # exception will also stop the iteration by our caller. > ? ? ? ? ? ? if reduce(operator.and_, [l == last[0] for l in last]): > ? ? ? ? ? ? ? ? # All iterators contain last[0] > ? ? ? ? ? ? ? ? yield last[0] > ? ? ? ? ? ? ? ? last = [iterator.next() for iterator in iterators] > > ? ? ? ? ? ? # Now go over the iterators once and advance them as > ? ? ? ? ? ? # necessary. To stop as soon as the smallest iterator we > ? ? ? ? ? ? # advance each iterator only once per loop iteration. > ? ? ? ? ? ? for i in indices[:-1]: > ? ? ? ? ? ? ? ? if last[i] < last[i+1]: > ? ? ? ? ? ? ? ? ? ? last[i] = iterators[i].next() > ? ? ? ? ? ? ? ? if last[i] > last[i+1]: > ? ? ? ? ? ? ? ? ? ? last[i+1] = iterators[i+1].next() I found my answer: Python 2.6 introduces heap.merge(), which is designed exactly for this. Thanks all, David. From pavlovevidence at gmail.com Thu Jun 11 00:06:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Jun 2009 21:06:50 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 10, 7:05?pm, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 5:53 PM, Mensanator wrote: > > On Jun 10, 5:24?pm, David Wilson wrote: > >> Hi, > > >> During a fun coding session yesterday, I came across a problem that I > >> thought was already solved by itertools, but on investigation it seems > >> it isn't. > > >> The problem is simple: given one or more ordered sequences, return > >> only the objects that appear in each sequence, without reading the > >> whole set into memory. This is basically an SQL many-many join. > > > Why not use SQL? > > Agreed. I seem to recall the last person asking for such a function > wanted to use it to combine SQL results. Well if the source data is already in a sql database that would make most sense, but if it isn't and since the iterator is pretty simple I'd say just go with that. Unless you have some other things happening downstream that would also benefit from the source data being in a database, or something. Carl Banks From boris.arloff at yahoo.com Thu Jun 11 00:25:25 2009 From: boris.arloff at yahoo.com (Boris Arloff) Date: Wed, 10 Jun 2009 21:25:25 -0700 (PDT) Subject: Metaclasses Demystified Message-ID: <495278.37325.qm@web65315.mail.ac2.yahoo.com> Hi, I have been studying python metaclasses for a few days now and I believe that slowly but surely I am grasping the subject.? The best article I have found on this is "Metaclass Demystified", by J. LaCour, Python Magazine, July 2008 (http://cleverdevil.org/computing/78/). I replicated the article's Enforcer example in python 3.0 and while I understand its functionality I have trouble understanding the behind the scene behavior.? I created a file containing classes Field, EnforcerMeta, Enforcer and Person, in this order.? The file is then imported with the python ide.? To save space I do not replicate the code here since it is available at the above link.? The following describes events when the file is imported and I hope that someone may offer clarifications on my comments/questions: 1.? First, the EnforcerMeta's __init__ method executes at import and its namespace (ns) shows to contain '__module__' and '__setattr__' attributes.? I did not expect __init__ to execute at this point since there has not been an instantiation yet.? Does this happens because we inherit from type and the python engine instantiates metaclasses? 2. Second, the for loop of EnforcerMeta checks the two attributes to be instances of class Field to add them in the _fields dict.? Since Field has not been instantiated with these attributes, they are not added to the dict.? No problem here, this is expected. 3.? Then,? class Person declaration is encountered with two class variables 'name' and 'age' which are defined as Field(str) and Field(int), respectively.? Hence, we have two instances of class Field each with a corresponding instance ftype attribute.? No problem with this either, as expected. 4.? The next events are somewhat puzzling however.? Class EnforcerMeta's __init__ executes again with a ns containing attributes 'age', 'name', and '__module__' .? The for loop executes and this time 'age' and 'name' are added to the _fields dict, while '__module__' understandably is not added.? However, 4.a.? What happened to attribute '__setattr__'?? Why is it not present anymore in the ns? 4.b.? What kind of magic makes EnforcerMeta to instantiate this second time?? I did not expect this to happen at all.? I can try to rationalize its instance in step 1 above, but I cannot come up with any such explanation for this second instantiation.? Is it because Enforcer doing this by inheriting the metaclass, which in turn is inherited by class Person? I tested the code by creating an instance of class Person and then assigning values to its attributes name and age.? The code works correctly as per the article's example. Any clarifications to the above questions will be greatly appreciated.? I am trying to get versed with the black magic of metaclasses and hope to use them in a personal academic research whereby I will try to create class objects on the fly at runtime out of nothing; or almost nothing. I can attach my code if necessary, but as indicated it is identical to LaCour's in the article with the necessary syntax changes for python 3.0. Thanks Boris -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Thu Jun 11 00:32:47 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Jun 2009 00:32:47 -0400 Subject: installation in mac os x In-Reply-To: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> References: <8CC0A80C-4E5C-4C98-90A0-C9573B18D469@gmail.com> Message-ID: On Jun 10, 2009, at 10:38 PM, Karl Jansson wrote: > Hi, > > I was doing the tutorial at http://www.python.org/doc/current/tutorial/ > , and I came across some code that did not work, and I got the > following error: AttributeError: 'str' object has no attribute > 'format'. > > So I downloaded a .dmg of python 2.6.2 and then I installed it. But > it's not working. Running the Python launcher, the "new" command in > the file menu is grey, and won't work, so I can't make any scripts. > > Does anyone know how to make python 2.6.2 work in mac os x? Hi Stefan, What's "the Python launcher"? What happens if you instead open a Terminal window (/Applications/Utilities/Terminal) and type "python"? bye P From jackdied at gmail.com Thu Jun 11 00:37:32 2009 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 11 Jun 2009 00:37:32 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: [snip] > I found my answer: Python 2.6 introduces heap.merge(), which is > designed exactly for this. Thanks, I knew Raymond added something like that but I couldn't find it in itertools. That said .. it doesn't help. Aside, heapq.merge fits better in itertools (it uses heaps internally but doesn't require them to be passed in). The other function that almost helps is itertools.groupby() and it doesn't return an iterator so is an odd fit for itertools. More specifically (and less curmudgeonly) heap.merge doesn't help for this particular case because you can't tell where the merged values came from. You want all the iterators to yield the same thing at once but heapq.merge muddles them all together (but in an orderly way!). Unless I'm reading your tokenizer func wrong it can yield the same value many times in a row. If that happens you don't know if four "The"s are once each from four iterators or four times from one. All that said your problem is an edge case so I'm happy to say the ten line composite functions that we've been trading can do what you want to do and in clear prose. The stdlib isn't meant to have a one liner for everything. -Jack From sjmachin at lexicon.net Thu Jun 11 00:58:28 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Jun 2009 04:58:28 +0000 (UTC) Subject: cleaning up an ASCII file? References: <1324e21a-9c58-4aed-a547-62ae65583290@z19g2000vbz.googlegroups.com> <4A306A63.8050202@berkeley.edu> Message-ID: Nick Matzke berkeley.edu> writes: > > > Looks like this was a solution: > > 1. Use this guy's unescape function to convert from HTML/XML Entities to > unicode > http://effbot.org/zone/re-sub.htm#unescape-html Looks like you didn't notice "this guy"'s unaccent.py :-) http://effbot.org/zone/unicode-convert.htm [Aside: Has anyone sighted the effbot recently? He's been very quiet.] > 2. Take the unicode and convert to approximate plain ASCII matches with > unicodedata (after import unicodedata) > > ascii_content2 = unescape(line) > > ascii_content = unicodedata.normalize('NFKD', > unicode(ascii_content2)).encode('ascii','ignore') The normalize hack gets you only so far. Many Latin-based characters are not decomposable. Look for the thread in this newsgroup with subject "convert unicode characters to visibly similar ascii characters" around 2008-07-01 or google("hefferon unicode2ascii") Alternative: If you told us which platform you are running on, people familiar with that platform could help you set up your terminal to display non-ASCII characters correctly. HTH, John From sjmachin at lexicon.net Thu Jun 11 01:08:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Thu, 11 Jun 2009 05:08:41 +0000 (UTC) Subject: How should I compare two txt files separately coming from =?utf-8?b?CXdpbmRvd3MvZG9z?= and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: Chris Rebert rebertia.com> writes: > > On Wed, Jun 10, 2009 at 8:11 PM, higer gmail.com> wrote: > > I just want to compare two files,one from windows and the other from > > unix. But I do not want to compare them through reading them line by > > line. Then I found there is a filecmp module which is used as file and > > directory comparisons. However,when I use two same files (one from > > unix,one from windows,the content of them is the same) to test its cmp > > function, filecmp.cmp told me false. > > > > Later, I found that windows use '\n\r' as new line flag but unix use > > '\n', so filecmp.cmp think that they are different,then return false. > > So, can anyone tell me that is there any method like IgnoreNewline > > which can ignore the difference of new line flag in diffrent > > platforms? If not,I think filecmp may be not a good file comparison > > Nope, there's no such flag. You could run the files through either > `dos2unix` or `unix2dos` beforehand though, which would solve the > problem. > Or you could write the trivial line comparison code yourself and just > make sure to open the files in Universal Newline mode (add 'U' to the > `mode` argument to `open()`). > You could also file a bug (a patch to add newline insensitivity would > probably be welcome). Or popen diff ... A /very/ /small/ part of the diff --help output: -E --ignore-tab-expansion Ignore changes due to tab expansion. -b --ignore-space-change Ignore changes in the amount of white space. -w --ignore-all-space Ignore all white space. -B --ignore-blank-lines Ignore changes whose lines are all blank. -I RE --ignore-matching-lines=RE Ignore changes whose lines all match RE. --strip-trailing-cr Strip trailing carriage return on input. Cheers, John From stefan_ml at behnel.de Thu Jun 11 02:22:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 08:22:14 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: References: Message-ID: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> Chris Seberino wrote: > How build new elements to replace existing ones using xml.dom.minidom? > > Specifically, I have an HTML table of numbers. I want to replace > those numbers with hyperlinks to create a table of hyperlinks. > > So I need to build hyperlinks (a elements) with href attribute and > replace the text elements (numbers) somehow. Try lxml.html instead. It makes it really easy to do these things. For example, you can use XPath to find all table cells that contain numbers: td_list = doc.xpath("//td[number() >= 0]") or maybe using regular expressions to make sure it's an int: td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", namespaces={'re':'http://exslt.org/regular-expressions'}) and then replace them by a hyperlink: # assuming links = ['http://...', ...] from lxml.html.builder import A for td in td_list: index = int(td.text) a = A("some text", href=links[index]) td.getparent().replace(td, a) Stefan From stefan_ml at behnel.de Thu Jun 11 02:23:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 08:23:23 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79a0njF1pd0bqU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> Message-ID: <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > when I read in a XML document with the xml.dom.minidom parser and write > it out again, an attribute is lost: > > Input: > > > [...] > > Output: > > > How can I fix this? You don't have to. UTF-8 is the default encoding, so the two lines above are equivalent. Stefan From lie.1296 at gmail.com Thu Jun 11 03:01:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 11 Jun 2009 07:01:04 GMT Subject: How to escape # hash character in regex match strings In-Reply-To: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: 504crank at gmail.com wrote: > I've encountered a problem with my RegEx learning curve -- how to > escape hash characters # in strings being matched, e.g.: > >>>> string = re.escape('123#abc456') >>>> match = re.match('\d+', string) >>>> print match > > <_sre.SRE_Match object at 0x00A6A800> >>>> print match.group() > > 123 > > The correct result should be: > > 123456 > > I've tried to escape the hash symbol in the match string without > result. > > Any ideas? Is the answer something I overlooked in my lurching Python > schooling? As you're not being clear on what you wanted, I'm just guessing this is what you wanted: >>> s = '123#abc456' >>> re.match('\d+', re.sub('#\D+', '', s)).group() '123456' >>> s = '123#this is a comment and is ignored456' >>> re.match('\d+', re.sub('#\D+', '', s)).group() '123456' From higerinbeijing at gmail.com Thu Jun 11 03:09:33 2009 From: higerinbeijing at gmail.com (higer) Date: Thu, 11 Jun 2009 00:09:33 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: On Jun 11, 1:08?pm, John Machin wrote: > Chris Rebert rebertia.com> writes: > > > > > > > On Wed, Jun 10, 2009 at 8:11 PM, higer gmail.com> wrote: > > > I just want to compare two files,one from windows and the other from > > > unix. But I do not want to compare them through reading them line by > > > line. Then I found there is a filecmp module which is used as file and > > > directory comparisons. However,when I use two same files (one from > > > unix,one from windows,the content of them is the same) to test its cmp > > > function, filecmp.cmp told me false. > > > > Later, I found that windows use '\n\r' as new line flag but unix use > > > '\n', so filecmp.cmp think that they are different,then return false. > > > So, can anyone tell me that is there any method like IgnoreNewline > > > which can ignore the difference of new line flag in diffrent > > > platforms? If not,I think filecmp may be not a good file comparison > > > Nope, there's no such flag. You could run the files through either > > `dos2unix` or `unix2dos` beforehand though, which would solve the > > problem. > > Or you could write the trivial line comparison code yourself and just > > make sure to open the files in Universal Newline mode (add 'U' to the > > `mode` argument to `open()`). > > You could also file a bug (a patch to add newline insensitivity would > > probably be welcome). > > Or popen diff ... > > A /very/ /small/ part of the diff --help output: > > ? -E ?--ignore-tab-expansion ?Ignore changes due to tab expansion. > ? -b ?--ignore-space-change ?Ignore changes in the amount of white space. > ? -w ?--ignore-all-space ?Ignore all white space. > ? -B ?--ignore-blank-lines ?Ignore changes whose lines are all blank. > ? -I RE ?--ignore-matching-lines=RE ?Ignore changes whose lines all match RE. > ? --strip-trailing-cr ?Strip trailing carriage return on input. > > Cheers, > John Tool can certainly be used to compare two files,but I just want to compare them using Python code. From higerinbeijing at gmail.com Thu Jun 11 03:12:24 2009 From: higerinbeijing at gmail.com (higer) Date: Thu, 11 Jun 2009 00:12:24 -0700 (PDT) Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> Message-ID: <39379946-16f0-448c-a230-3da19449d40e@k19g2000prh.googlegroups.com> On Jun 11, 11:44?am, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: > > I just want to compare two files,one from windows and the other from > > unix. But I do not want to compare them through reading them line by > > line. Then I found there is a filecmp module which is used as file and > > directory comparisons. However,when I use two same files (one from > > unix,one from windows,the content of them is the same) to test its cmp > > function, filecmp.cmp told me false. > > > Later, I found that windows use '\n\r' as new line flag but unix use > > '\n', so filecmp.cmp think that they are different,then return false. > > So, can anyone tell me that is there any method like IgnoreNewline > > which can ignore the difference of new line flag in diffrent > > platforms? If not,I think filecmp may be not a good file comparison > > Nope, there's no such flag. You could run the files through either > `dos2unix` or `unix2dos` beforehand though, which would solve the > problem. > Or you could write the trivial line comparison code yourself and just > make sure to open the files in Universal Newline mode (add 'U' to the > `mode` argument to `open()`). > You could also file a bug (a patch to add newline insensitivity would > probably be welcome). > > Cheers, > Chris > --http://blog.rebertia.com Thank you very much. Adding 'U' argument can perfectly work, and I think it is definitely to report this as a bug to Python.org as you say. Cheers, higer From wuwei23 at gmail.com Thu Jun 11 03:20:57 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Jun 2009 00:20:57 -0700 (PDT) Subject: object reincarnation References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: On Jun 11, 5:34?am, Manavan wrote: > Since the real world objects often needs to be deleted even if they > have some reference from some other object [...] >From this it sounds like you're trying to implement some form of weak referencing. Are you familiar with weakref? "A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. A primary use for weak references is to implement caches or mappings holding large objects, where it?s desired that a large object not be kept alive solely because it appears in a cache or mapping." http://docs.python.org/library/weakref.html From carlos at pepelabs.net Thu Jun 11 04:34:08 2009 From: carlos at pepelabs.net (Carlos Valiente) Date: Thu, 11 Jun 2009 08:34:08 +0000 (UTC) Subject: can it be shorter? References: <0b296acc-6c78-4d5d-9f4c-7e09e6aa405e@h18g2000yqj.googlegroups.com> <7x63f7iqmh.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > url = url.rstrip('/') + '/' That's what I use: It has the (nice) side effect of ending the URL with a *single* slash. C From clp2 at rebertia.com Thu Jun 11 04:44:28 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 01:44:28 -0700 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: <4A2EDD10.6090608@gmail.com> References: <4A2EDD10.6090608@gmail.com> Message-ID: <50697b2c0906110144g6cfeb6aeq9a6fc91fca14fb3a@mail.gmail.com> On Tue, Jun 9, 2009 at 3:07 PM, Stef Mientki wrote: > hello, > > I want to make a distro for Ubuntu, > and run under Windows. > > I packed all sources with zipfile, > but the compression doesn't seem to be very good. > > If run the created file through 7zip, it becomes anout half the size. Are you sure it's compressing it as a .zip? I know it has its own incompatible .7z format which tends compress things a bit better. > Is there a way to accomplish the same task with zipfile ( the documentation > isn't overwhelming). You can use the `tarfile` module's bz2 compression option; bzip2 tends to compress slightly better than zip. tarfile docs -- http://docs.python.org/library/tarfile.html Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Thu Jun 11 04:59:42 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Jun 2009 10:59:42 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? References: Message-ID: Stef Mientki wrote: > I packed all sources with zipfile, > but the compression doesn't seem to be very good. If you don't specify the compression, the files are not compressed at all. Just in case you didn't know... Peter From pavlovevidence at gmail.com Thu Jun 11 05:11:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Jun 2009 02:11:04 -0700 (PDT) Subject: object reincarnation References: <9e2efa17-8551-4bbb-9569-f891fd3aa7c3@o18g2000yqi.googlegroups.com> Message-ID: On Jun 10, 12:34?pm, Manavan wrote: > Hello everyone, > ? ?Since the real world objects often needs to be deleted even if they > have some reference from some other object, I am going to use this > approach to better model this situation, by cleaning up the attributes > and assigning self.__class__ to a different class. > ?Any comment on this approach. > > class Deleted(object): > ? ? pass > > class RealWorldObj(object): > ? ? def __init__(self, *args): > ? ? ? ? self.attrs = args > ? ? def getAttrs(self,): > ? ? ? ? return self.attrs > ? ? def delete(self,): > ? ? ? ? del self.attrs > ? ? ? ? self.__class__ = Deleted > > >>> a = RealWorldObj(1,2,3) > >>> print a.attrs > (1, 2, 3) > >>> a.delete() > >>> a > > <__main__.Deleted object at 0x893ae2c>>>> a.attrs > > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'Deleted' object has no attribute 'attrs' Cute, but let me suggest that changing the class of the object would make it harder to track down the original error. So just delete the attributes. I'd also recommend using self.__dict__.clear() for that, it gets all of them (usually) and doesn't need to be updated with you add a new attribute to a class. Carl Banks From info at egenix.com Thu Jun 11 05:11:05 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 11 Jun 2009 11:11:05 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.9.0-0.9.8k Message-ID: <4A30CA29.8040403@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.9.0-0.9.8k An easy to install and use repackaged distribution of the pyOpenSSL Python interface for OpenSSL - available on Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.9.0-0.9.8k-1-GA.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy to use installer that includes the most recent OpenSSL library versions in pre-compiled form. pyOpenSSL is an open-source Python add-on (http://pyopenssl.sf.net/) that allows writing SSL aware networking applications as well as certificate management tools. OpenSSL is an open-source implementation of the SSL protocol (http://www.openssl.org/). For more information, please see the product page: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included pyOpenSSL version to 0.9, which includes a new fix for a serious problem in pyOpenSSL 0.8 related to threaded applications. It also comes with an important bug-fix update of OpenSSL, now at version 0.9.8k. The problem causes invalid thread states in the Python interpreter which then result in random core dumps and seg faults when using pyOpenSSL 0.8.0 with multi-threaded applications. The new fix is slightly different than the one we included in 0.8.1 and based on a code analysis we did together with Jean-Paul Calderone to track down the cause of the problem. Binaries are available for Linux x86 and x64 as well as Windows x86 and Mac OS X PPC/Intel. They include both pyOpenSSL and the necessary OpenSSL libraries. For Plone users and friends of buildout scripts, we have added pre-built binaries for Windows. They install just like the Linux versions and allow easy integration of the archives into buildout scripts. For our Mac OS X users, we have included new pre-built binaries for Mac OS X PPC and Intel platforms. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 11 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2009-06-29: EuroPython 2009, Birmingham, UK 17 days to go ::: 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 deets at nospam.web.de Thu Jun 11 05:16:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 11 Jun 2009 11:16:25 +0200 Subject: installation in mac os x References: Message-ID: <79c05cF1q46qkU1@mid.uni-berlin.de> Karl Jansson wrote: > Hi, > > I was doing the tutorial at http://www.python.org/doc/current/ > tutorial/, and I came across some code that did not work, and I got > the following error: AttributeError: 'str' object has no attribute > 'format'. > > So I downloaded a .dmg of python 2.6.2 and then I installed it. But > it's not working. Running the Python launcher, the "new" command in > the file menu is grey, and won't work, so I can't make any scripts. > > Does anyone know how to make python 2.6.2 work in mac os x? What happens if you work on the commandline (Terminal)? Python2.6 should be available from (out of my head) /Library/Frameworks/Python.framework/Versions/2.6/bin/python If that's working, it is successfully installed. Diez From stefan_ml at behnel.de Thu Jun 11 05:21:07 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 11:21:07 +0200 Subject: unladen swallow: python and llvm In-Reply-To: References: Message-ID: <4a30cc84$0$32668$9b4e6d93@newsspool2.arcor-online.net> Nick Craig-Wood wrote: > Luis M Gonz?lez wrote: >> I am very excited by this project (as well as by pypy) and I read all >> their plan, which looks quite practical and impressive. >> But I must confess that I can't understand why LLVM is so great for >> python and why it will make a difference. > > CPython uses a C compiler to compile the python code (written in C) > into native machine code. That would be Cython: compile Python code to (optimised) C code and then run a C compiler over that to get native machine code. http://cython.org/ CPython compiles Python code to *byte-code* and then *interprets* that in a virtual machine (which happens to be written in C, hence the name). Stefan From walkraft at gmail.com Thu Jun 11 05:28:16 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 02:28:16 -0700 (PDT) Subject: Convert integer to fixed length binary string Message-ID: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Hi, I know the bin function converts an int into a binary string. Unfortunately, I need to know the length of the binary string when it is being read in and len(bin(x)) depends on x. Is there any way to limit it to 4 bytes? Thanks for your assistance, Chris From walkraft at gmail.com Thu Jun 11 05:29:45 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 02:29:45 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: Sorry, I didn't quite make it clear. The issue isn't about limiting the length (as I won't be using integers bigger than this). The problem is that sometimes the output is shorter. From stefan_ml at behnel.de Thu Jun 11 05:53:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 11:53:23 +0200 Subject: unladen swallow: python and llvm In-Reply-To: <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> References: <7xzlcjlo3c.fsf@ruckus.brouhaha.com> <1ec0d339-3c5b-4baa-ab61-3f481edbc0d2@o18g2000yqi.googlegroups.com> <6bc7efe8-22ee-49ce-9c36-eab9ce61834e@g19g2000yql.googlegroups.com> <4765bc3a-b411-4bfe-898e-7d81bc2d59ca@k2g2000yql.googlegroups.com> Message-ID: <4a30d413$0$32674$9b4e6d93@newsspool2.arcor-online.net> bearophileHUGS at lycos.com wrote: > Kay Schluehr: >> Don't understand your Cython compliant. The only tricky part of Cython >> is the doublethink regarding Python types and C types. I attempted once >> to write a ShedSkin like code transformer from Python to Cython based on >> type recordings but never found the time for this because I have to work >> on EasyExtend on all fronts at the same time. > > I have tried to create a certain data structure with a recent version > of Pyrex on Windows, and I have wasted lot of time looking for missing > reference count updates that didn't happen, or memory that didn't get > freed. I wonder what you did then. Apparently, you didn't just compile a Python program, but tried to use Pyrex/Cython to avoid writing C code. That can work, but depends on your C expertise. If you only compile Python code, you will not get in touch with any ref-counting or memory leaks (any more than in CPython, that is). You only have to care about freeing memory if you manually allocate that memory through malloc(), in which case it's your own fault if it doesn't get freed. > I'm sure lot of people like Cython, but I prefer a more transparent > language, that doesn't hide me how it works inside. Cython doesn't hide anything. Most of the magic that happens is done in code tree transformations, which you can look up in the compiler code. The code generation is mostly just mapping the final code tree to C code, with some type specialisations. Cython will even copy your complete source code line-by-line into the C code it writes, so that you can easily read up what your code gets translated to. I admit that the generated C code is not always simple and obvious, as it contains lots of runtime type specialisations and optimisations. But that's the price you pay for fast code. And you can make Cython leave out most of the duplicated code (i.e. the pessimistic fallbacks) by adding type hints to your code. Stefan From dickinsm at gmail.com Thu Jun 11 06:01:43 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Jun 2009 03:01:43 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <493e875f-7975-4e4e-8512-615703e9337a@s21g2000vbb.googlegroups.com> On Jun 11, 10:29?am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. Is this what you're looking for? Python 2.6.2 (r262:71600, Jun 8 2009, 14:57:27) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> '{0:032b}'.format(12345) '00000000000000000011000000111001' Mark From dfnsonfsduifb at gmx.de Thu Jun 11 06:18:50 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 11 Jun 2009 12:18:50 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79c404F1psv7kU1@mid.dfncis.de> Stefan Behnel schrieb: > Johannes Bauer wrote: >> when I read in a XML document with the xml.dom.minidom parser and write >> it out again, an attribute is lost: >> >> Input: >> >> >> [...] >> >> Output: >> >> >> How can I fix this? > > You don't have to. UTF-8 is the default encoding, so the two lines above > are equivalent. Can I somehow force Python to generate it anyways? I have software which complains if an explicit encoding is missing... Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From stefan_ml at behnel.de Thu Jun 11 06:54:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 12:54:51 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79c404F1psv7kU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> Message-ID: <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: >> Johannes Bauer wrote: >>> when I read in a XML document with the xml.dom.minidom parser and write >>> it out again, an attribute is lost: >>> >>> Input: >>> >>> >>> [...] >>> >>> Output: >>> >>> >>> How can I fix this? >> You don't have to. UTF-8 is the default encoding, so the two lines above >> are equivalent. > > Can I somehow force Python to generate it anyways? Did you try passing encoding='UTF-8' on serialisation? > I have software which > complains if an explicit encoding is missing... Well, to parse XML, it's best to use an XML parser. ;) Stefan From jeremiah.dodds at gmail.com Thu Jun 11 07:23:10 2009 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Thu, 11 Jun 2009 12:23:10 +0100 Subject: Compiling Python3.1 In-Reply-To: <79an4pF1oqpbjU1@mid.dfncis.de> References: <799co4F1pdqgeU1@mid.dfncis.de> <4a3010fb$0$22010$9b622d9e@news.freenet.de> <79an4pF1oqpbjU1@mid.dfncis.de> Message-ID: <12cbbbfc0906110423i1be854f3m12f4f0ff9b0475d4@mail.gmail.com> On Wed, Jun 10, 2009 at 10:33 PM, Johannes Bauer wrote: > Martin v. L?wis schrieb: > >> What can I do about that? > > > > Remove the non-ASCII characters from db.h. > > Ehh... > > $ find -type f | grep -i db.h > OT: find -type f -iname "db.h" -------------- next part -------------- An HTML attachment was scrubbed... URL: From ebonak at hotmail.com Thu Jun 11 07:34:51 2009 From: ebonak at hotmail.com (Esmail) Date: Thu, 11 Jun 2009 07:34:51 -0400 Subject: random number including 1 - i.e. [0,1] In-Reply-To: References: Message-ID: Thanks everyone, I learned more than I expected about floats :-) and got some good explanations and ideas about all of this. Esmail From eckhardt at satorlaser.com Thu Jun 11 07:40:48 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 11 Jun 2009 13:40:48 +0200 Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <1377g6-4i7.ln1@satorlaser.homedns.org> casebash wrote: > I know the bin function converts an int into a binary string. Binary string sounds ambiguous. Firstly, everything is binary. Secondly, strings are byte strings or Unicode strings. In any case, I'm not 100% sure what you mean - giving an example of input and output would help! > Unfortunately, I need to know the length of the binary string when it > is being read in and len(bin(x)) depends on x. Is there any way to > limit it to 4 bytes? If you need a piece of four bytes which contain a number in a packed format similar to the one used in memory, using bin(x) is the wrong way. Instead, take a look at the struct module: import struct struct.pack('=L', 255) Alternatively, also the array module might help. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From python at mrabarnett.plus.com Thu Jun 11 09:08:45 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Jun 2009 14:08:45 +0100 Subject: OT: Periodic table gets a new element Message-ID: <4A3101DD.70108@mrabarnett.plus.com> Element 112 is to be named. Do you think we could persuade the scientists to name it "Pythonium"? :-) http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm From tpk at kraussfamily.org Thu Jun 11 09:20:27 2009 From: tpk at kraussfamily.org (Tom K.) Date: Thu, 11 Jun 2009 06:20:27 -0700 (PDT) Subject: retrieve bitwise float representation References: Message-ID: On Jun 10, 8:41?am, Ulrich Eckhardt wrote: > I need to pack a floating point value into a vector of 32-bit unsigned > values in IEEE format. Further, I maintain a CRC32 checksum for integrity > checking. For the latter, I actually need the float as integral value. ... > What I'm wondering is whether there are any better or alternative ways to > achieve this, the overhead now seems enormous and unnecessary to me here. Numpy has support for this: import numpy as np a = np.arange(10.) # an array of floats b = a.view(dtype=np.uint32) print b array([ 0, 0, 1072693248, 0, 1073741824, 0, 1074266112, 0, 1074790400, 0, 1075052544, 0, 1075314688, 0, 1075576832, 0, 1075838976, 0, 1075970048, 0], dtype=uint32) b[0]=5 print a array([ 1.06099790e-313, 1.00000000e+000, 2.00000000e+000, 3.00000000e+000, 4.00000000e+000, 5.00000000e+000, 6.00000000e+000, 7.00000000e+000, 8.00000000e+000, 9.00000000e+000]) From dfnsonfsduifb at gmx.de Thu Jun 11 09:20:54 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Thu, 11 Jun 2009 15:20:54 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79celfF1odmrdU1@mid.dfncis.de> Stefan Behnel schrieb: >> Can I somehow force Python to generate it anyways? > > Did you try passing encoding='UTF-8' on serialisation? Uhm... nope - how can I do that? > >> I have software which >> complains if an explicit encoding is missing... > > Well, to parse XML, it's best to use an XML parser. ;) Well, I'm not speaking about my software :-) Actually it's Gnucash which complains if the tag is not explicitly set. This is because they appearently had a ancient version which did not specify the charset, but used a different one than UTF-8. Kind of annoying, but fixing my XML output seems to be easier than convincing the Gnucash people to change their software :-) Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From jeanmichel at sequans.com Thu Jun 11 09:27:46 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Jun 2009 15:27:46 +0200 Subject: OT: Periodic table gets a new element In-Reply-To: <4A3101DD.70108@mrabarnett.plus.com> References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: <4A310652.8030009@sequans.com> Not if this element is to end up in some further ultimate nuclear weapon :-) , unless you are using python to conquer the world (I've been told this is GVR main secret objective). MRAB wrote: > Element 112 is to be named. Do you think we could persuade the > scientists to name it "Pythonium"? :-) > > http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm From stefan_ml at behnel.de Thu Jun 11 09:35:08 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Jun 2009 15:35:08 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79celfF1odmrdU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> Can I somehow force Python to generate it anyways? >> Did you try passing encoding='UTF-8' on serialisation? > > Uhm... nope - how can I do that? Well, depends on what your code currently does. Maybe you could use something like doc.xmlwrite(..., encoding='UTF-8') Stefan From matthew.strax-haber at nasa.gov Thu Jun 11 09:44:24 2009 From: matthew.strax-haber at nasa.gov (Strax-Haber, Matthew (LARC-D320)) Date: Thu, 11 Jun 2009 08:44:24 -0500 Subject: FW: [Tutor] Multi-Threading and KeyboardInterrupt In-Reply-To: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: I sent this to the Tutor mailing list and did not receive a response. Perhaps one of you might be able to offer some sagely wisdom or pointed remarks? Please reply off-list and thanks in advance. Code examples are below in plain text. ------ Forwarded Message > From: Matthew Strax-Haber > Reply-To: Matthew Strax-Haber > Date: Tue, 9 Jun 2009 22:01:33 -0500 > To: Python Tutor > Subject: [Tutor] Multi-Threading and KeyboardInterrupt > > Hey everyone, > > I hope one of you can help me with this. This is my first foray into > multi-threaded programming. I have tried to boil my code down to it's > simplest demonstrative form. > > My program runs interactively by allowing the user to directly > interact with the python prompt. This program has a runAll() method > that runs a series of subprocesses with a cap on how many instances > are running at a time. My intent is to allow the user to use Ctrl-C to > break these subprocesses. Note that while not reflected in the demo > below, each subprocess needs to be able to run clean-up code before > shutting down (in single-threaded mode I just wrap in try-finally). > When I run DB.py, and interrupt it with Ctrl-C, things do not run so > cleanly. Please let me know what I can change to make this work > properly. My intent is to have the following output: > > 'key interrupt 1' > 'key interrupt 2' > 'key interrupt 3' > 'key interrupt 4' > '********* stopped midway ********' > > Here is the code for a demo: > ############################################################################## > DB.py (run this): > ############################################################################## #!/usr/bin/env python from subprocess import Popen from threading import Thread, Semaphore MAX_SUBPROCS = 3 RUN_PERMISSION = Semaphore(MAX_SUBPROCS) def runSingle(i): with RUN_PERMISSION: Popen(['./Sub.py', str(i)]).wait() def runAll(): workers = [ Thread(target = runSingle, args = [i]) for i in xrange(MAX_SUBPROCS + 1) ] try: for w in workers: w.start() except KeyboardInterrupt: ## I want this to be shown on a KeyboardInterrupt print '********* stopped midway ********' for w in workers: w.join() runAll() > ############################################################################## > Sub.py (called by DB.py): > ############################################################################## #!/usr/bin/env python import sys, time try: while True: pass except KeyboardInterrupt: print 'key interrupt %s' % sys.argv[1] raise > ############################################################################## > _______________________________________________ > Tutor maillist - Tutor at python.org > http://mail.python.org/mailman/listinfo/tutor > ------ End of Forwarded Message From motoom at xs4all.nl Thu Jun 11 09:46:03 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 11 Jun 2009 15:46:03 +0200 Subject: OT: Periodic table gets a new element In-Reply-To: <4A3101DD.70108@mrabarnett.plus.com> References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: <4A310A9B.6030709@xs4all.nl> MRAB wrote: > Element 112 is to be named. Do you think we could persuade the > scientists to name it "Pythonium"? :-) What did Python do to deserve this? I think 'Hofmannium' is a more appropriate name ;-) On the other hand, if the scientists used Python on their equipment with which they discovered the new element, the name 'Pythonium' is of course totally acceptable. 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 brousch at gmail.com Thu Jun 11 10:01:55 2009 From: brousch at gmail.com (Ben Rousch) Date: Thu, 11 Jun 2009 14:01:55 +0000 (UTC) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: pobox.com> writes: > > I thought there was a website which demonstrated how to program a bunch of > small problems in a number of different languages. I know about the > Programming Language Shootout: > > http://shootout.alioth.debian.org/ > > but that's not what I was thinking of. I thought there was a site with a > bunch of smaller examples. Rosetta Code has examples of common programming tasks in hundreds of languages: http://rosettacode.org/ From briandenzer at gmail.com Thu Jun 11 10:22:44 2009 From: briandenzer at gmail.com (Brian D) Date: Thu, 11 Jun 2009 07:22:44 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> On Jun 11, 2:01?am, Lie Ryan wrote: > 504cr... at gmail.com wrote: > > I've encountered a problem with my RegEx learning curve -- how to > > escape hash characters # in strings being matched, e.g.: > > >>>> string = re.escape('123#abc456') > >>>> match = re.match('\d+', string) > >>>> print match > > > <_sre.SRE_Match object at 0x00A6A800> > >>>> print match.group() > > > 123 > > > The correct result should be: > > > 123456 > > > I've tried to escape the hash symbol in the match string without > > result. > > > Any ideas? Is the answer something I overlooked in my lurching Python > > schooling? > > As you're not being clear on what you wanted, I'm just guessing this is > what you wanted: > > >>> s = '123#abc456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > '123456' > >>> s = '123#this is a comment and is ignored456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456' Sorry I wasn't more clear. I positively appreciate your reply. It provides half of what I'm hoping to learn. The hash character is actually a desirable hook to identify a data entity in a scraping routine I'm developing, but not a character I want in the scrubbed data. In my application, the hash makes a string of alphanumeric characters unique from other alphanumeric strings. The strings I'm looking for are actually manually-entered identifiers, but a real machine-created identifier shouldn't contain that hash character. The correct pattern should be 'A1234509', but is instead often merely entered as '#12345' when the first character, representing an alphabet sequence for the month, and the last two characters, representing a two-digit year, can be assumed. Identifying the hash character in a RegEx match is a way of trapping the string and transforming it into its correct machine- generated form. I'm surprised it's been so difficult to find an example of the hash character in a RegEx string -- for exactly this type of situation, since it's so common in the real world that people want to put a pound symbol in front of a number. Thanks! From briandenzer at gmail.com Thu Jun 11 10:25:18 2009 From: briandenzer at gmail.com (Brian D) Date: Thu, 11 Jun 2009 07:25:18 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: On Jun 11, 9:22?am, Brian D wrote: > On Jun 11, 2:01?am, Lie Ryan wrote: > > > > > 504cr... at gmail.com wrote: > > > I've encountered a problem with my RegEx learning curve -- how to > > > escape hash characters # in strings being matched, e.g.: > > > >>>> string = re.escape('123#abc456') > > >>>> match = re.match('\d+', string) > > >>>> print match > > > > <_sre.SRE_Match object at 0x00A6A800> > > >>>> print match.group() > > > > 123 > > > > The correct result should be: > > > > 123456 > > > > I've tried to escape the hash symbol in the match string without > > > result. > > > > Any ideas? Is the answer something I overlooked in my lurching Python > > > schooling? > > > As you're not being clear on what you wanted, I'm just guessing this is > > what you wanted: > > > >>> s = '123#abc456' > > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456' > > >>> s = '123#this is a comment and is ignored456' > > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > > '123456' > > Sorry I wasn't more clear. I positively appreciate your reply. It > provides half of what I'm hoping to learn. The hash character is > actually a desirable hook to identify a data entity in a scraping > routine I'm developing, but not a character I want in the scrubbed > data. > > In my application, the hash makes a string of alphanumeric characters > unique from other alphanumeric strings. The strings I'm looking for > are actually manually-entered identifiers, but a real machine-created > identifier shouldn't contain that hash character. The correct pattern > should be 'A1234509', but is instead often merely entered as '#12345' > when the first character, representing an alphabet sequence for the > month, and the last two characters, representing a two-digit year, can > be assumed. Identifying the hash character in a RegEx match is a way > of trapping the string and transforming it into its correct machine- > generated form. > > I'm surprised it's been so difficult to find an example of the hash > character in a RegEx string -- for exactly this type of situation, > since it's so common in the real world that people want to put a pound > symbol in front of a number. > > Thanks! By the way, other forms the strings can take in their manually created forms: A#12345 #1234509 Garbage in, garbage out -- I know. I wish I could tell the people entering the data how challenging it is to work with what they provide, but it is, after all, a screen-scraping routine. From 504crank at gmail.com Thu Jun 11 10:29:45 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Thu, 11 Jun 2009 07:29:45 -0700 (PDT) Subject: How to escape # hash character in regex match strings References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> Message-ID: On Jun 11, 2:01?am, Lie Ryan wrote: > 504cr... at gmail.com wrote: > > I've encountered a problem with my RegEx learning curve -- how to > > escape hash characters # in strings being matched, e.g.: > > >>>> string = re.escape('123#abc456') > >>>> match = re.match('\d+', string) > >>>> print match > > > <_sre.SRE_Match object at 0x00A6A800> > >>>> print match.group() > > > 123 > > > The correct result should be: > > > 123456 > > > I've tried to escape the hash symbol in the match string without > > result. > > > Any ideas? Is the answer something I overlooked in my lurching Python > > schooling? > > As you're not being clear on what you wanted, I'm just guessing this is > what you wanted: > > >>> s = '123#abc456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > '123456' > >>> s = '123#this is a comment and is ignored456' > >>> re.match('\d+', re.sub('#\D+', '', s)).group() > > '123456'- Hide quoted text - > > - Show quoted text - Sorry I wasn't more clear. I positively appreciate your reply. It provides half of what I'm hoping to learn. The hash character is actually a desirable hook to identify a data entity in a scraping routine I'm developing, but not a character I want in the scrubbed data. In my application, the hash makes a string of alphanumeric characters unique from other alphanumeric strings. The strings I'm looking for are actually manually-entered identifiers, but a real machine-created identifier shouldn't contain that hash character. The correct pattern should be 'A1234509', but is instead often merely entered as '#12345' when the first character, representing an alphabet sequence for the month, and the last two characters, representing a two-digit year, can be assumed. Identifying the hash character in a RegEx match is a way of trapping the string and transforming it into its correct machine- generated form. Other patterns the strings can take in their manually-created form: A#12345 #1234509 Garbage in, garbage out -- I know. I wish I could tell the people entering the data how challenging it is to work with what they provide, but it is, after all, a screen-scraping routine. I'm surprised it's been so difficult to find an example of the hash character in a RegEx string -- for exactly this type of situation, since it's so common in the real world that people want to put a pound symbol in front of a number. Thanks! From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:47:46 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:47:46 -0300 Subject: spawning a process using os.spawn References: Message-ID: En Tue, 09 Jun 2009 15:38:53 -0300, rkmr.em at gmail.com escribi?: > im spawning a script that runs for a long from a web app like this: > > os.spawnle(os.P_NOWAIT, "../bin/producenotify.py", "producenotify.py", > "xx",os.environ) > > > the script is spawned and it runs, but till it gets over i am not able to > free the port that is used by the web app, or in other words i am not > able > to restart the web app. how do i spawn off a process and make it > completely > independent of the web app? Try subprocess.Popen instead, setting close_fds=True -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:47:58 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:47:58 -0300 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> Message-ID: En Tue, 09 Jun 2009 05:02:33 -0300, Steven D'Aprano escribi?: > [...] As tuples are defined in Python, they quack like immutable lists, > they > walk like immutable lists, and they swim like immutable lists. Why > shouldn't we treat them as immutable lists? > > Phillip Eby states that "Lists are intended to be homogeneous sequences, > while tuples are heterogeneous data structures." (Notice the subtle shift > there: lists are "intended", while tuples "are". But in fact, there's > nothing to stop you from putting homogeneous data into a tuple, so Eby is > wrong to say that tuples *are* heterogeneous.) > > Perhaps Eby intends lists to be homogeneous, perhaps Guido does too, but > this is Python, where we vigorously defend the right to shoot ourselves > in the foot. We strongly discourage class creators from trying to enforce > their intentions by using private attributes, and even when we allow such > a thing, the nature of Python is that nothing is truly private. Why > should homogeneity and heterogeneity of lists and tuples be sacrosanct? > Nothing stops me from putting hetereogeneous data into a list, or > homogeneous data into a tuple, and there doesn't appear to be any ill- > effects from doing so. Why give lose sleep over the alleged lack of > purity? Yes - but in the past the distinction was very much stronger. I think that tuples didn't have *any* method until Python 2.0 -- so, even if someone could consider a tuple a "read-only list", the illusion disappeared as soon as she tried to write anything more complex that a[i]. Maybe tuples could quack like immutable lists, but they could not swim nor walk... With time, tuples gained more and more methods and are now very similar to lists - they even have an index() method (undocumented but obvious) which is absurd in the original context. Think of tuples as used in relational databases: there is no way in SQL to express the condition "search for this along all values in this tuple", because it usually doesn't make any sense at all (and probably, if it does make sense in a certain case, it's because the database is badly designed.) But *now*, you can express that operation in Python. So I'd say that *now*, the distinction between an "homogeneous container" vs "heterogeneous data structure" has vanished a lot, and it's hard to convince people that tuples aren't just immutable lists. That is, *I* would have used a list in this case: for delay in (0.01, 0.1, 0.5, 1, 2, 5, 10, 30, 60): do_something(delay) but I cannot find a *concrete* reason to support the assertion "list is better". So, for practical purposes, tuples act now as if they were immutable lists -- one should be aware of the different memory allocation strategies, but I see no other relevant differences. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Jun 11 10:48:18 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 11:48:18 -0300 Subject: .pth files and figuring out valid paths.. References: <52f58ef5-194f-4095-b3e9-1da22285b552@j12g2000vbl.googlegroups.com> <2017da1c-f16d-4a4e-ab8b-fcd15caaebff@f16g2000vbf.googlegroups.com> Message-ID: En Tue, 09 Jun 2009 20:30:06 -0300, rh0dium escribi?: > On Jun 9, 3:28?pm, Emile van Sebille wrote: >> On 6/9/2009 3:00 PM rh0dium said... >> >> > I have a .pth file which has some logic in it - but it isn't quite >> > enough... >> >> > It started with this.. >> > import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"], >> > "tools/python/modules")) >> >> > But that eventually evolved into.. >> > import os, site; site.addsitedir(os.path.join(os.environ.get >> > ("TECHROOT", "/home/tech"), "tools/python/modules")) >> >> Try it this way... >> >> import os, site >> smsc = os.environ.get("TECHROOT", "/home/tech") >> if not os.path.isdir(smsc): >> ? ? ?smsc = "/home/tech" >> site.addsitedir (os.path.join(smsc, >> "tools/python/Linux/%arch/lib/python2.5/site-packages")) > > No for .pth files this needs to be on a single line.. Try this instead: import os, site; smsc = os.environ.get("TECHROOT", ""); smsc = smsc if smsc and os.path.isdir(smsc) else "/home/tech"; site.addsitedir(...) >> > But now I want to check to make sure this directory exists or fall >> > back to "/home/tech". ?That was the point of the environ.get but what >> > if someone sets TECHROOT to /dev/null. ?Well that will break >> > things... ?I tried this but no go. ?Can someone help me out.. I'd add the directory unconditionally - then, when initializing the application, I'd check that the required modules can be imported, and inform the user of that specific problem if not. -- Gabriel Genellina From s.dornseifer at gmx.net Thu Jun 11 10:50:06 2009 From: s.dornseifer at gmx.net (S. Dornseifer) Date: Thu, 11 Jun 2009 16:50:06 +0200 Subject: install older Python version parallel Message-ID: <4A31199E.7030809@gmx.net> Hi everybody, The situation: I wrote a GUI, based on Python, TkInter and Pmw. It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 and various Linux Distributions. Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug in the installed blt package), also when I use setitems on Pmw.OptionMenu (I guess this is due to another package, associated with tcl/tk). The target: I have to get my GUI work under openSUSE 11.1 (x86_64). My plan: On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. I would like to know, how to install Python 2.4 along with TkInter and Pmw (and packages that are required by them), parallel to the existing Python 2.6. So that I do not break other software that depends on Python 2.6. If you can think of another plan, I would be also glad to discuss it. Cheers, Simon From 504crank at gmail.com Thu Jun 11 11:14:13 2009 From: 504crank at gmail.com (504crank at gmail.com) Date: Thu, 11 Jun 2009 08:14:13 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: <8714752b-83fe-4d6c-878b-21e251d98748@z9g2000yqi.googlegroups.com> Message-ID: On Jun 10, 10:13?am, Peter Otten <__pete... at web.de> wrote: > 504cr... at gmail.com wrote: > > I wonder if you (or anyone else) might attempt a different explanation > > for the use of the special sequence '\1' in the RegEx syntax. > > > The Python documentation explains: > > > \number > > ? ? Matches the contents of the group of the same number. Groups are > > numbered starting from 1. For example, (.+) \1 matches 'the the' or > > '55 55', but not 'the end' (note the space after the group). This > > special sequence can only be used to match one of the first 99 groups. > > If the first digit of number is 0, or number is 3 octal digits long, > > it will not be interpreted as a group match, but as the character with > > octal value number. Inside the '[' and ']' of a character class, all > > numeric escapes are treated as characters. > > > In practice, this appears to be the key to the key device to your > > clever solution: > > >>>> re.compile(r"(\d+)").sub(r"INSERT \1", string) > > > 'abc INSERT 123 def INSERT 456 ghi INSERT 789' > > >>>> re.compile(r"(\d+)").sub(r"INSERT ", string) > > > 'abc INSERT ?def INSERT ?ghi INSERT ' > > > I don't, however, precisely understand what is meant by "the group of > > the same number" -- or maybe I do, but it isn't explicit. Is this just > > a shorthand reference to match.group(1) -- if that were valid -- > > implying that the group match result is printed in the compile > > execution? > > If I understand you correctly you are right. Another example: > > >>> re.compile(r"([a-z]+)(\d+)").sub(r"number=\2 word=\1", "a1 zzz42") > > 'number=1 word=a number=42 word=zzz' > > For every match of "[a-z]+\d+" in the original string "\1" in > "number=\2 word=\1" is replaced with the actual match for "[a-z]+" and > "\2" is replaced with the actual match for "\d+". > > The result, e. g. "number=1 word=a", is then used to replace the actual > match for group 0, i. e. "a1" in the example. > > Peter- Hide quoted text - > > - Show quoted text - Wow! That is so cool. I had to process it for a little while to get it. >>> s = '111bbb333' >>> re.compile('(\d+)([b]+)(\d+)').sub(r'First string: \1 Second string: \2 Third string: \3', s) 'First string: 111 Second string: bbb Third string: 333' MRI scans would no doubt reveal that people who attain a mastery of RegEx expressions must have highly developed areas of the brain. I wonder where the RegEx part of the brain might be located. That was a really clever teaching device. I really appreciate you taking the time to post it, Peter. I'm definitely getting a schooling on this list. Thanks! From gunterhenriksen at gmail.com Thu Jun 11 12:47:42 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 09:47:42 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <8763f5d0r2.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> Message-ID: > [In this tuple] > dodge_city = (1781, 1870, 1823) > (population, feet_above_sea_level, establishment_year) = dodge_city > each index in the sequence implies something very > different about each value. The semantic meaning > of each index is *more* than just the position in > the sequence; it matters *for interpreting that > component*, and that component would not mean the > same thing in a different index position. A tuple > is the right choice, for that reason. I think I would have difficulty holding a position that this should not be a class (or equivalent via namedtuple()) or a dict. It seems to me like a case could be made that there are far more situations where it makes sense to use tuples as immutable sequences than as objects whose attributes are named implicitly by an index. This dodge_city definitely does not seem to me like a good candidate for a plain tuple. From a.cavallo at mailsnare.com Thu Jun 11 12:51:35 2009 From: a.cavallo at mailsnare.com (A. Cavallo) Date: Thu, 11 Jun 2009 17:51:35 +0100 Subject: install older Python version parallel In-Reply-To: <4A31199E.7030809@gmx.net> References: <4A31199E.7030809@gmx.net> Message-ID: <200906111751.35840.a.cavallo@mailsnare.com> Hi, I'm working on a project of mine that does creates python installation under /opt so they can be installed side by side with a system installed one. There's a web page: http://pyvm.sourceforge.net/ With links to the newest build plus all teh accompaining unitests. But you can use the sources rpm to create a version with python 2.4 (see http://download.opensuse.org/repositories/home:/cavallo71:/opt-python- interpreters/openSUSE_11.1/src/) Let me know if you need more help, Regards, Antoino On Thursday 11 June 2009 15:50:06 S. Dornseifer wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon From phil at riverbankcomputing.com Thu Jun 11 12:56:17 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Thu, 11 Jun 2009 17:56:17 +0100 Subject: Changing Hash Values Across Versions Message-ID: How stable should the implementation of, for example, a string's hash across different Python versions? Is it defined that hash("foo") will return the same value for Python 2.5.1, 2.6.1 and 2.6.2? Thanks, Phil From drobinow at gmail.com Thu Jun 11 13:10:10 2009 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Jun 2009 13:10:10 -0400 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <79celfF1odmrdU1@mid.dfncis.de> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <4eb0089f0906111010p1a7ba147ua09828532568c8b4@mail.gmail.com> On Thu, Jun 11, 2009 at 9:20 AM, Johannes Bauer wrote: > Well, I'm not speaking about my software :-) Actually it's Gnucash which > complains if the tag is not explicitly set. This is because they > appearently had a ancient version which did not specify the charset, but > used a different one than UTF-8. Kind of annoying, but fixing my XML > output seems to be easier than convincing the Gnucash people to change > their software :-) from the GnuCash web page: How can you help? Testing: Test it and help us discover all bugs that might show up in there. Please enter each and every bug into bugzilla. Translating: The new release comes with some new translation strings. If you consider contributing a translation, we invite you to test this release already. A string freeze will be announced in one of the later 2.3.x releases. Please check http://wiki.gnucash.org/wiki/Translation_Status for updates on this. We would like to encourage people to test this and any further releases as much as possible and submit bug reports in order that we can polish GnuCash to be as stable as possible for the 2.4.0 release in a few weeks. Then post any bugs you find to bugzilla (http://bugzilla.gnome.org/enter_bug.cgi?product=GnuCash) From praveen.kariyanahalli at gmail.com Thu Jun 11 13:48:55 2009 From: praveen.kariyanahalli at gmail.com (Praveen Kariyanahalli) Date: Thu, 11 Jun 2009 10:48:55 -0700 Subject: Issues download 2.4 python (for windows) msi Message-ID: Hi I am having issues downloading any msi prior to the 3.X version. All of them appear to be truncated. My old scripts dont compile on the later versions. Can someone please fix this ASAP ? Thanks -Praveen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Thu Jun 11 14:20:58 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 11:20:58 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> Message-ID: <9280e227-f32d-4aca-a48c-3a4ce25c0f11@w9g2000pro.googlegroups.com> On Jun 11, 4:29?am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. This works also: >>> bin(15)[2:].zfill(32) '00000000000000000000000000001111' From mensanator at aol.com Thu Jun 11 14:26:55 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 11:26:55 -0700 (PDT) Subject: OT: Periodic table gets a new element References: <4A3101DD.70108@mrabarnett.plus.com> Message-ID: On Jun 11, 8:27?am, Jean-Michel Pichavant wrote: > Not if this element is to end up in some further ultimate nuclear weapon > ? :-) ? Don't worry, a millisecond half-life is kind of a wet blanket as far as weapon design is concerned. > , unless you are using python to conquer the world (I've been > told this is GVR main secret objective). > > > > MRAB wrote: > > Element 112 is to be named. Do you think we could persuade the > > scientists to name it "Pythonium"? :-) > > >http://news.bbc.co.uk/1/hi/sci/tech/8093374.stm- Hide quoted text - > > - Show quoted text - From Scott.Daniels at Acm.Org Thu Jun 11 14:32:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 11 Jun 2009 11:32:24 -0700 Subject: Changing Hash Values Across Versions In-Reply-To: References: Message-ID: Phil Thompson wrote: > How stable should the implementation of, for example, a string's hash > across different Python versions? > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > 2.6.1 and 2.6.2? > > Thanks, > Phil Pretty certain that A.B.* will always hash the same (unacceptable change as a bugfix), and that there has been no recent need to change the string hash (it gets a _lot_ of use), so in practice I suspect that 2.3.* through 2.8.* all produce the same string hashes. However, the language doesn't guarantee a lot about the value, and I would not be surprised to see a non-CPython implementation use a different hash. Generally it is a good idea to keep the result of hash computations inside the program, and off the persistant store, so I'd want a good excuse to use the hash "outside." --Scott David Daniels Scott.Daniels at Acm.Org From gagsl-py2 at yahoo.com.ar Thu Jun 11 14:40:06 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Jun 2009 15:40:06 -0300 Subject: Changing Hash Values Across Versions References: Message-ID: En Thu, 11 Jun 2009 13:56:17 -0300, Phil Thompson escribi?: > How stable should the implementation of, for example, a string's hash > across different Python versions? I cannot find any such guarantee in the documentation: http://docs.python.org/reference/datamodel.html > Is it defined that hash("foo") will return the same value for Python > 2.5.1, 2.6.1 and 2.6.2? I've tested and it does, all versions since Python 1.5 up to 3.0.1. But you should not rely on that. What do you want to do exactly? -- Gabriel Genellina From tjreedy at udel.edu Thu Jun 11 14:54:13 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2009 14:54:13 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: Jack Diederich wrote: > On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: > [snip] >> I found my answer: Python 2.6 introduces heap.merge(), which is >> designed exactly for this. > > Thanks, I knew Raymond added something like that but I couldn't find > it in itertools. > That said .. it doesn't help. Aside, heapq.merge fits better in > itertools (it uses heaps internally but doesn't require them to be > passed in). The other function that almost helps is > itertools.groupby() and it doesn't return an iterator so is an odd fit > for itertools. > > More specifically (and less curmudgeonly) heap.merge doesn't help for > this particular case because you can't tell where the merged values > came from. You want all the iterators to yield the same thing at once > but heapq.merge muddles them all together (but in an orderly way!). > Unless I'm reading your tokenizer func wrong it can yield the same > value many times in a row. If that happens you don't know if four > "The"s are once each from four iterators or four times from one. David is looking to intersect sorted lists of document numbers with duplicates removed in order to find documents that contain worda and wordb and wordc ... . But you are right that duplicate are a possible fly in the ointment to be removed before merging. From brendandetracey at yahoo.com Thu Jun 11 14:54:57 2009 From: brendandetracey at yahoo.com (Brendan) Date: Thu, 11 Jun 2009 11:54:57 -0700 (PDT) Subject: Alter list items within loop Message-ID: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Can someone please explain what is happening in the output below? The number 3 never gets printed. Does Python make a copy of a list before it iterates through it?: >>> e = range(1,5) >>> for i in e: print i if i == 2 : e.remove(i) 1 2 4 >>> e [1, 3, 4] From tjreedy at udel.edu Thu Jun 11 15:04:22 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2009 15:04:22 -0400 Subject: Restart the interactive python shell like in IDLE In-Reply-To: <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> References: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> <50697b2c0906101648y49f2e450x475dfd808ab72f3c@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Wed, Jun 10, 2009 at 12:01 PM, Matt Burson wrote: >> Is there a way to reproduce the behavior of IDLE's restart shell ability by >> using a function? I thought there would be since you can exit python by >> executing the simple quit() function I thought there would be an equally >> simple function name something like restart(). I'd prefer something like >> this as opposed to having to exit the shell and then start it up again to >> refresh it. > > I believe IDLE itself implements the "restart" capability by killing > and re-launching its Python interpreter subprocess, so it's not like > it's using some hidden capability of Python to accomplish this. > Is doing Ctrl+D, up-arrow, Enter really that hard? It's even fewer > keystrokes than "restart()"... This will do part of what you want: >>> a=1 >>> b=1 >>> globals().clear() >>> a Traceback (most recent call last): File "", line 1, in NameError: name 'a' is not defined That will not reset sys.modules, which is the only other thing I can imagine being worried about. The main reason IDLE has a restart is so that when you run a file after editing, you can be sure the behavior you see is what you get when running the file without IDLE, with a fresh interpreter. Another use of refresh is when creating example interactive sessions for doctest or book examples. Again, one wants to make sure that the example does not depend on previous entries not included in the example. For ordinary interactive exploration, refresh is seldom needed. tjr From stef.mientki at gmail.com Thu Jun 11 15:11:52 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Jun 2009 21:11:52 +0200 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: References: Message-ID: <4A3156F8.1010900@gmail.com> Peter Otten wrote: > Stef Mientki wrote: > > >> I packed all sources with zipfile, >> but the compression doesn't seem to be very good. >> > > If you don't specify the compression, the files are not compressed at all. > Just in case you didn't know... > .. and would you be willing to tell me how I could set the compression ( at maximum) ? thanks, Stef Mientki > Peter > > From emile at fenx.com Thu Jun 11 15:23:16 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Jun 2009 12:23:16 -0700 Subject: Alter list items within loop In-Reply-To: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Message-ID: On 6/11/2009 11:54 AM Brendan said... > Can someone please explain what is happening in the output below? you delete e[2] before displaying it. The > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: No. Mods to a list while passing it is generally not a good idea. Sometimes passing the list backwards works. Emile >>>> e = range(1,5) >>>> for i in e: > print i > if i == 2 : > e.remove(i) > > > 1 > 2 > 4 >>>> e > [1, 3, 4] From clp2 at rebertia.com Thu Jun 11 15:27:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 12:27:19 -0700 Subject: zipfile doesn't compress very good, are there other solutions ? In-Reply-To: <4A3156F8.1010900@gmail.com> References: <4A3156F8.1010900@gmail.com> Message-ID: <50697b2c0906111227r7bd02efdy4f5ec7dc9afa7532@mail.gmail.com> On Thu, Jun 11, 2009 at 12:11 PM, Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >>> I packed all sources with zipfile, >>> but the compression doesn't seem to be very good. >>> >> >> If you don't specify the compression, the files are not compressed at all. >> Just in case you didn't know... >> > > .. and would you be willing to tell me how I could set the compression ( at > maximum) ? If you had glanced @ the docs for 30 seconds: import zipfile z = zipfile.ZipFile(dest_file, "w", zipfile.ZIP_DEFLATED) Cheers, Chris -- http://blog.rebertia.com From usernet at ilthio.net Thu Jun 11 15:32:17 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 19:32:17 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> Message-ID: <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> On 2009-06-11, Brendan wrote: > Can someone please explain what is happening in the output below? The > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: You can see what is happening by printing the list as you work through the loop: >>> e = range(1,5) >>> for i in e: ... print e ... print i ... if i == 2 : ... e.remove(i) ... [1, 2, 3, 4] 1 [1, 2, 3, 4] 2 [1, 3, 4] 4 first loop: i = 0 e[i] = e[0] = 1 second loop i = 1 e[i] = e[1] = 2 third loop i = 2 e[i] = e[2] = 4 > number 3 never gets printed. Does Python make a copy of a list before > it iterates through it?: No, complex types are passed by reference unless explicity copied. You can do what you want by making an explicit copy before entering the loop: >>> e = range(1,5) >>> for i in e[:]: ... print e ... print i ... if i == 2 : ... e.remove(i) ... [1, 2, 3, 4] 1 [1, 2, 3, 4] 2 [1, 3, 4] 3 [1, 3, 4] 4 From __peter__ at web.de Thu Jun 11 15:33:56 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Jun 2009 21:33:56 +0200 Subject: zipfile doesn't compress very good, are there other solutions? References: Message-ID: Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >> >> >>> I packed all sources with zipfile, >>> but the compression doesn't seem to be very good. >>> >> >> If you don't specify the compression, the files are not compressed at >> all. Just in case you didn't know... >> > .. and would you be willing to tell me how I could set the compression ( > at maximum) ? According to the documentation (hint, hint) there is only on and off. zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) Peter From steven.oldner at gmail.com Thu Jun 11 15:44:03 2009 From: steven.oldner at gmail.com (steven.oldner) Date: Thu, 11 Jun 2009 12:44:03 -0700 (PDT) Subject: Blogger Widget web app Message-ID: <7b3f931c-7750-440d-8f91-315c4c04dc72@d2g2000pra.googlegroups.com> Please give me directions on where to start researching for answers. I probably can do the javascript, but I don't know where to start on the Python. 1. Wife has a blogger blog and wants a widget to embed in the posts. 2. Widget will have a form that readers can enter their name and url. 3. Widget also lists in numeric order the name and url of all the readers who signed up in that post. 4. Son has an old PC he turned into a server, and installed Windows IIS on it. What I need to do is to write the cgi scripts to send a list of names and urls for each post on load, validate the input from the form and store the results per blog post. If you have seen Mr. Linky, that's what I'm tring to mimic. This will only be for her blog, so she can have a faster load time and less down time. I have NO intention to build this for more than her. So very simple and easy is the key. I've read the mailing list, I just got the books, Programming Python by Mark Lutz and and Python Web Programming by Steve Holden. There is so much great info I don't know where to start or what I need to start with. Thanks for any pointers. Steve Oldner From madsmaillist at gmail.com Thu Jun 11 15:52:55 2009 From: madsmaillist at gmail.com (Mads Michelsen) Date: Thu, 11 Jun 2009 21:52:55 +0200 Subject: Unhandled exception in thread Message-ID: <5e7a0ce90906111252o484818ckb18a07c55fd693ed@mail.gmail.com> (I'll ask you to bear with the somewhat vague description in advance - I'm a noob in all respects here, with regard to python and the mailing list) I'm getting some error reports sometimes when I quit a script, I've been working on. The reports are extremely uninformative, and I do not notice anything wrong in the script's behaviour, which makes the error very hard to pin down. I'm therefore looking for advice on a way that I can investigate the error. Here's the deal. The script in question is a screen scraping thing which downloads and parses the html in the background using a separate thread (the 'thread' module), while the main program serves up the data to the user, allowing some modicum of interaction. Sometimes, not always (though I cannot see a pattern), when I quit the script, the following error message is printed: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: And that's it! Seems like there's some information missing? What is the error in sys.excepthook? What was the original exception? And where? Any suggestions on how to proceed? - Mads From lists at cheimes.de Thu Jun 11 15:55:40 2009 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Jun 2009 21:55:40 +0200 Subject: Changing Hash Values Across Versions In-Reply-To: References: Message-ID: Phil Thompson schrieb: > How stable should the implementation of, for example, a string's hash > across different Python versions? > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > 2.6.1 and 2.6.2? The hash of an object is an internal implementation detail. The hash() value of an object isn't even stable for the one version of Python. It depends on the architecture (32 vs. 64bit OS, maybe even big vs. little endian). The hash sums of objects like classes may and most likely do change when you restart the interpreter. Python 2.5.4 (r254:67916, Feb 4 2009, 14:25:49) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import struct; struct.calcsize("P") * 8 32 >>> hash("a") -468864544 Python 2.5.4 (r254:67916, Apr 4 2009, 17:56:17) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import struct; struct.calcsize("P") * 8 64 >>> hash("a") 12416037344 $ python2.5 -c "import os; print hash(os)" 140519221134232 $ python2.5 -c "import os; print hash(os)" 139731515618200 $ python2.5 -c "import os; print hash(os)" 140460433757080 $ python2.5 -c "import os; print hash(os)" 140707220554648 From mmrasheed at gmail.com Thu Jun 11 15:56:42 2009 From: mmrasheed at gmail.com (Captain___nemo) Date: Thu, 11 Jun 2009 12:56:42 -0700 (PDT) Subject: =?windows-1252?Q?Voronoi_diagram_algorithm_=28Fortune=92s_sweepline=29?= Message-ID: Hi, I am implementing Voronoi diagram to find out the nearest location in a map visually. Right now I want to do this using integer coordinates (x,y) only in a canvas. Problem is- I am really confused about this algorithm. I read the Computational Geometry book, few more theory on Fortune's algorithm. And I am really confused now. It seems very complex to me when I am going for coding. Please advice me very simple implementation of voronoi diagram (given coordinates). Please advice me simple python code preferably without- hash, multi-threading, Delaunay Traingulation, fancy colors etc (which are confusing). Isn't it possible to implement Voronoi diagram using Fortune's algorithm without multithreading or hash map? Thanks in advance. From aahz at pythoncraft.com Thu Jun 11 15:57:19 2009 From: aahz at pythoncraft.com (Aahz) Date: Thu, 11 Jun 2009 12:57:19 -0700 Subject: EXTENDED: OSCON 2009 early bird (June 23) Message-ID: <20090611195719.GA15733@panix.com> Registration is now open for the O'Reilly Open Source Convention (OSCON). OSCON 2009 will be July 20-24 in San Jose, California. Early registration has been extended and now ends June 23. Use the special discount code 'os09pgm' for an extra 15% off. For more information: http://conferences.oreilly.com/oscon -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From arnodel at googlemail.com Thu Jun 11 16:09:49 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 11 Jun 2009 21:09:49 +0100 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: David Wilson writes: > Hi, > > During a fun coding session yesterday, I came across a problem that I > thought was already solved by itertools, but on investigation it seems > it isn't. > > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. As it is a nice little problem I tried to find a solution today. FWIW, here it is (tested extensively only on the example below :): def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(1, len(v)): while v[0] > v[i]: v[i] = nexts[i]() if v[0] < v[i]: break else: yield v[0] v[0] = nexts[0]() >>> list(intersect([[1, 100, 142, 322, 12312], ... [2, 100, 101, 322, 1221], ... [100, 142, 322, 956, 1222]])) [100, 322] From dickinsm at gmail.com Thu Jun 11 16:18:30 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Jun 2009 13:18:30 -0700 (PDT) Subject: Changing Hash Values Across Versions References: Message-ID: <14e293e1-f52b-4865-a7f8-f54b2ddb4832@c18g2000prh.googlegroups.com> On Jun 11, 8:55?pm, Christian Heimes wrote: > Phil Thompson schrieb: > > > How stable should the implementation of, for example, a string's hash > > across different Python versions? > > > Is it defined that hash("foo") will return the same value for Python 2.5.1, > > 2.6.1 and 2.6.2? > > The hash of an object is an internal implementation detail. The hash() > value of an object isn't even stable for the one version of Python. It > depends on the architecture (32 vs. 64bit OS, maybe even big vs. little > endian). The hash sums of objects like classes may and most likely do > change when you restart the interpreter. What he said. I remember at least one recent hash change: the algorithm for computing the hash of a long is different in Python 2.5.x and Python 2.6.x. Mark From swift at mirohost.net Thu Jun 11 16:24:51 2009 From: swift at mirohost.net (Sydoruk Yaroslav) Date: Thu, 11 Jun 2009 20:24:51 +0000 (UTC) Subject: reading from file Message-ID: Hello all, In a text file aword.txt, there is a string: "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc". There is a first script: f = open ("aword.txt", "r") for line in f: print chardet.detect(line) b = line.decode('cp1251') print b _RESULT_ {'confidence': 1.0, 'encoding': 'ascii'} \xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc There is a second script: line = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" print chardet.detect(line) b = line.decode('cp1251') print b _RESULT_ {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} ???+????????? Why is reading from a file into a string variable is defined as ascii, but when it is clearly defined in the script is defined as cp1251. How do I solve this problem. -- Only one 0_o From bearophileHUGS at lycos.com Thu Jun 11 16:28:34 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 13:28:34 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <2438bcbb-80f7-4f20-900b-a3175b6d2e19@a7g2000yqk.googlegroups.com> Captain___nemo: > Isn't it possible to implement Voronoi diagram using Fortune's > algorithm without multithreading or hash map? Multi-threading isn't part of Fortune's algorithm. Multi-threading can be confusing, but it's better for you to learn to feel at home using hash maps (named dicts in Python), because they are both essential in computer science and in Python. Ask if you need some help regarding dicts and sets. Bye, bearophile From stef.mientki at gmail.com Thu Jun 11 16:41:41 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Jun 2009 22:41:41 +0200 Subject: zipfile doesn't compress very good, are there other solutions? In-Reply-To: References: Message-ID: <4A316C05.4080808@gmail.com> Peter Otten wrote: > Stef Mientki wrote: > > >> Peter Otten wrote: >> >>> Stef Mientki wrote: >>> >>> >>> >>>> I packed all sources with zipfile, >>>> but the compression doesn't seem to be very good. >>>> >>>> >>> If you don't specify the compression, the files are not compressed at >>> all. Just in case you didn't know... >>> >>> >> .. and would you be willing to tell me how I could set the compression ( >> at maximum) ? >> > > According to the documentation (hint, hint) there is only on and off. > > zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) > > sorry guys I made a mistake, I did read the doc, but as there was no default value metioned, I did a few tests, and I made a mistake with these experiments. Indeed the compression is much better now, just 15% larger than 7zip, which is quit acceptable. thanks again, Stef > Peter > > From jeff at jmcneil.net Thu Jun 11 16:45:11 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Thu, 11 Jun 2009 13:45:11 -0700 (PDT) Subject: reading from file References: Message-ID: On Jun 11, 4:24?pm, Sydoruk Yaroslav wrote: > Hello all, > > In a text file aword.txt, there is a string: > ? ? "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc". > > There is a first script: > f = open ("aword.txt", "r") > for line in f: > ? ? print chardet.detect(line) > ? ? b = line.decode('cp1251') > ? ? print b > > _RESULT_ > {'confidence': 1.0, 'encoding': 'ascii'} > \xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc > > There is a second script: > line = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" > print chardet.detect(line) > b = line.decode('cp1251') > print b > > _RESULT_ > {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} > ???+????????? > > Why is reading from a file into a string variable is defined as ascii, > but when it is clearly defined in the script is defined as cp1251. > How do I solve this problem. > > -- > Only one 0_o Is the string in your text file literally "\xea\xe0\xea+\xef\xee \xe7\xe2\xee\xed\xe8\xf2\xfc" as "plain text?" My assumption is that when you're reading that in, Python is interpreting each byte as an ASCII value (and rightfully so) rather than the corresponding '\x' escapes. As an experiment: (t)jeff at marvin:~/t$ cat test.py import chardet s = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" with open('test.txt', 'w') as f: print >>f, s print chardet.detect(open('test.txt').read()) (t)jeff at marvin:~/t$ python test.py {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} (t)jeff at marvin:~/t$ HTH, Jeff mcjeff.blogspot.com From duncan.booth at invalid.invalid Thu Jun 11 16:45:18 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Jun 2009 20:45:18 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: Tim Harig wrote: >> number 3 never gets printed. Does Python make a copy of a list before >> it iterates through it?: > > No, complex types are passed by reference unless explicity copied. *All* types are passed by reference unless explicitly copied. Python does make special cases for simple and complex types. From clp2 at rebertia.com Thu Jun 11 16:58:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 13:58:43 -0700 Subject: zipfile doesn't compress very good, are there other solutions? In-Reply-To: <4A316C05.4080808@gmail.com> References: <4A316C05.4080808@gmail.com> Message-ID: <50697b2c0906111358u400942f1yb2bcb1b33c1ecabe@mail.gmail.com> On Thu, Jun 11, 2009 at 1:41 PM, Stef Mientki wrote: > Peter Otten wrote: >> Stef Mientki wrote: >>> Peter Otten wrote: >>>> Stef Mientki wrote: >>>>> I packed all sources with zipfile, >>>>> but the compression doesn't seem to be very good. >>>>> >>>> >>>> If you don't specify the compression, the files are not compressed at >>>> all. Just in case you didn't know... >>>> >>> >>> .. and would you be willing to tell me how I could set the compression ( >>> at maximum) ? >>> >> >> According to the documentation (hint, hint) there is only on and off. >> >> zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) >> >> > > sorry guys I made a mistake, > I did read the doc, but as there was no default value metioned, Erm... class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]]) Open a ZIP file [...] compression is the ZIP compression method to use when writing the archive, and should be ZIP_STORED or ZIP_DEFLATED; [...] The default is ZIP_STORED. [...] Though I admit the docs could definitely do with having "compression=ZIP_STORED" in the signature part of the doc. Cheers, Chris -- http://blog.rebertia.com From robert.kern at gmail.com Thu Jun 11 17:01:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Jun 2009 16:01:37 -0500 Subject: Voronoi diagram algorithm =?UTF-8?B?KEZvcnR1bmXigJlzIHN3ZWVw?= =?UTF-8?B?bGluZSk=?= In-Reply-To: References: Message-ID: On 2009-06-11 14:56, Captain___nemo wrote: > Hi, > I am implementing Voronoi diagram to find out the nearest location in > a map visually. Right now I want to do this using integer coordinates > (x,y) only in a canvas. > > Problem is- I am really confused about this algorithm. I read the > Computational Geometry book, few more theory on Fortune's algorithm. > And I am really confused now. It seems very complex to me when I am > going for coding. Yup. It is complex. > Please advice me very simple implementation of voronoi diagram (given > coordinates). Please advice me simple python code preferably without- > hash, multi-threading, Delaunay Traingulation, You can't really do the Voronoi diagram without Delaunay Triangulation. They are two ways of looking at the same thing. > fancy colors etc (which > are confusing). You can see a mild modification of Fortune's original C code here: http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/VoronoiDiagramGenerator.cpp > Isn't it possible to implement Voronoi diagram using Fortune's > algorithm without multithreading or hash map? It's possible to do it without multithreading, of course, but Fortune's algorithm does require some sophisticated data structures. Computational geometry is rarely a simple matter. -- 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 aaron.watters at gmail.com Thu Jun 11 17:03:18 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Thu, 11 Jun 2009 14:03:18 -0700 (PDT) Subject: ANN: WHIFF += Flash chart widget support Message-ID: <50bc6bbd-91dd-4dcf-80c9-a101b02ea1a0@w31g2000prd.googlegroups.com> WHIFF.0.3 adds amChart Flash based Charts. The amChart chart widgets [ http://www.amcharts.com ] provide a sophisticated methodology for creating beautiful and interactive statistical charts using Adobe Flash plug-in technology. The WHIFF.0.3 release adds extensive support for embedding amCharts charts in web pages under the ./demo/amcharts demo directory area. Please look at chart examples explained in the documentation at http://aaron.oirt.rutgers.edu/myapp/amcharts/doc Also please try out the "disk usage analysis" pie chart drill down demo at http://aaron.oirt.rutgers.edu/myapp/amcharts/diskUsage Below is more information about WHIFF: === WHIFF -- WSGI/HTTP INTEGRATED FILESYSTEM FRAMES WHIFF is an infrastructure for easily building complex Python/WSGI Web applications by combining smaller and simpler WSGI components organized within file system trees. To DOWNLOAD WHIFF go to the WHIFF project information page at http://sourceforge.net/projects/whiff and follow the download instructions. To GET THE LATEST WHIFF clone the WHIFF Mercurial repository located at http://aaron.oirt.rutgers.edu/cgi-bin/whiffRepo.cgi. To READ ABOUT WHIFF view the WHIFF documentation at http://aaron.oirt.rutgers.edu/myapp/docs/W.intro. To PLAY WITH WHIFF try the demos listed in the demos page at http://aaron.oirt.rutgers.edu/myapp/docs/W1300.testAndDemo. Why WHIFF? ========== WHIFF (WSGI HTTP Integrated Filesystem Frames) is intended to make it easier to create, deploy, and maintain large and complex Python based WSGI Web applications. I created WHIFF to address complexity issues I encounter when creating and fixing sophisticated Web applications which include complex database interactions and dynamic features such as AJAX (Asynchronous JavaScript and XML). The primary tools which reduce complexity are an infrastructure for managing web application name spaces, a configuration template language for wiring named components into an application, and an applications programmer interface for accessing named components from Python and javascript modules. All supporting conventions and tools offered by WHIFF are optional. WHIFF is designed to work well with other modules conformant to the WSGI (Web Service Gateway Interface) standard. Developers and designers are free to use those WHIFF tools that work for them and ignore or replace the others. WHIFF does not provide a "packaged cake mix" for baking a web application. Instead WHIFF is designed to provide a set of ingredients which can be easily combined to make web applications (with no need to refine your own sugar or mill your own wheat). I hope you like it. -- Aaron Watters === less is more From swift at mirohost.net Thu Jun 11 17:06:14 2009 From: swift at mirohost.net (Sydoruk Yaroslav) Date: Thu, 11 Jun 2009 21:06:14 +0000 (UTC) Subject: reading from file References: Message-ID: Jeff McNeil wrote: > Is the string in your text file literally "\xea\xe0\xea+\xef\xee > \xe7\xe2\xee\xed\xe8\xf2\xfc" as "plain text?" My assumption is that > when you're reading that in, Python is interpreting each byte as an > ASCII value (and rightfully so) rather than the corresponding '\x' > escapes. > > As an experiment: > > (t)jeff at marvin:~/t$ cat test.py > import chardet > > s = "\xea\xe0\xea+\xef\xee\xe7\xe2\xee\xed\xe8\xf2\xfc" > with open('test.txt', 'w') as f: > print >>f, s > > print chardet.detect(open('test.txt').read()) > (t)jeff at marvin:~/t$ python test.py > {'confidence': 0.98999999999999999, 'encoding': 'windows-1251'} > (t)jeff at marvin:~/t$ > > HTH, > > Jeff > mcjeff.blogspot.com Thank you for your reply. You are right, Python reads data form the file in bytes and all data in this case is ASCII I solved the problem, just added line = line.decode('string_escape') f = open ("aword.txt", "r") for line in f: line = line.decode('string_escape') ? ? print chardet.detect(line) ? ? b = line.decode('cp1251') ? ? print b -- Only one 0_o From usernet at ilthio.net Thu Jun 11 17:12:07 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 21:12:07 GMT Subject: Alter list items within loop References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: On 2009-06-11, Duncan Booth wrote: > Tim Harig wrote: >>> number 3 never gets printed. Does Python make a copy of a list before >>> it iterates through it?: >> No, complex types are passed by reference unless explicity copied. > *All* types are passed by reference unless explicitly copied. Python does > make special cases for simple and complex types. That is technically true; but, you will not have this issue with simple singlular data types. Technically the difference as to whether you will have this problem depends on whether or not an object is mutable. Simple objects (numbers and strings) are all immutable. Since this issue revolves around changing objects in place, it cannot arise with immutable objects. I am not always conscous of whether I am working with objects that are mutable or immutable; but, I am generally concious of the general complexity of the object. Whenever I am working with objects that are complex, I am reminded to watch out for mutability issues. So, while it is not totally correct to think of it this way, I find it an easier guideline to follow. From bearophileHUGS at lycos.com Thu Jun 11 17:16:47 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 14:16:47 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Robert Kern: > You can see a mild modification of Fortune's original C code here: > > http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/Voro... That's C++; C++ makes simple things hard and hard things possible :-) In Python that code may become much shorter (and slower). Bye, bearophile From jackdied at gmail.com Thu Jun 11 17:27:32 2009 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 11 Jun 2009 17:27:32 -0400 Subject: itertools.intersect? In-Reply-To: References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 11, 2009 at 2:54 PM, Terry Reedy wrote: > Jack Diederich wrote: >> >> On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: >> [snip] >>> >>> I found my answer: Python 2.6 introduces heap.merge(), which is >>> designed exactly for this. >> >> Thanks, I knew Raymond added something like that but I couldn't find >> it in itertools. >> That said .. it doesn't help. ?Aside, heapq.merge fits better in >> itertools (it uses heaps internally but doesn't require them to be >> passed in). ?The other function that almost helps is >> itertools.groupby() and it doesn't return an iterator so is an odd fit >> for itertools. >> >> More specifically (and less curmudgeonly) heap.merge doesn't help for >> this particular case because you can't tell where the merged values >> came from. ?You want all the iterators to yield the same thing at once >> but heapq.merge muddles them all together (but in an orderly way!). >> Unless I'm reading your tokenizer func wrong it can yield the same >> value many times in a row. ?If that happens you don't know if four >> "The"s are once each from four iterators or four times from one. > > David is looking to intersect sorted lists of document numbers with > duplicates removed in order to find documents that contain worda and wordb > and wordc ... . ?But you are right that duplicate are a possible fly in the > ointment to be removed before merging. Ah, in that case the heap.merge solution is both useful and succinct: import heapq import itertools def intersect(its): source = heapq.merge(*its) while True: sames = [source.next()] sames.extend(itertools.takewhile(lambda v:v == sames[0], source)) if len(sames) == len(its): yield sames[0] return -Jack From nick at craig-wood.com Thu Jun 11 17:29:36 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 11 Jun 2009 16:29:36 -0500 Subject: unladen swallow: python and llvm References: <4a30cc84$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel wrote: > Nick Craig-Wood wrote: > > Luis M Gonz?lez wrote: > >> I am very excited by this project (as well as by pypy) and I read all > >> their plan, which looks quite practical and impressive. > >> But I must confess that I can't understand why LLVM is so great for > >> python and why it will make a difference. > > > > CPython uses a C compiler to compile the python code (written in C) > > into native machine code. > > That would be Cython: compile Python code to (optimised) C code and then > run a C compiler over that to get native machine code. Actually I meant "compile the python source code" - sorry if I wasn't clear! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From tanner989 at hotmail.com Thu Jun 11 17:33:18 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Thu, 11 Jun 2009 16:33:18 -0500 Subject: help with errror Message-ID: could some one explain this error to me and possibly how to fix it? Traceback (most recent call last): File "C:\Users\brandon\workspace\tanner's workshop\tanner's workshop\src\WxGlade.py", line 458, in Edit = MyDialog2(None, -1, "") File "C:\Users\brandon\workspace\tanner's workshop\tanner's workshop\src\WxGlade.py", line 27, in __init__ self.Name = wx.StaticText(self.panel_41, -1, "Name") File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 8522, in SetName return _core_.Window_SetName(*args, **kwargs) TypeError: String or Unicode type required _________________________________________________________________ Hotmail? has ever-growing storage! Don?t worry about storage limits. http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Thu Jun 11 17:34:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 11 Jun 2009 14:34:27 -0700 Subject: Unhandled exception in thread In-Reply-To: References: Message-ID: Mads Michelsen wrote: > ...I'm getting some error reports ... looking for advice on a way that > I can investigate the error.... The script ... downloads and... > in the background using a separate thread (the 'thread' module), .... > Sometimes, .... when I quit the script, the following error message is printed: > > Unhandled exception in thread started by > Error in sys.excepthook: > > Original exception was: > > And that's it! Seems like there's some information missing? What is > the error in sys.excepthook? What was the original exception? And > where? > > Any suggestions on how to proceed? (1) Generally, use Threading rather than thread. It says so at the top of the thread docs. (2) Sounds like it might be a timing problem while shutting down. Do you tell the thread to stop, and then stop it? That would generally be the best architecture. (3) From above, what you might want is something like: import Threading import Queue ... def code(commands, replies): for element in iter(commands.get, None): # None: stop signal time.sleep(1) # just here to represent processing time. results = repr(element) # and simulating some results" replies.put(results) replies.put(None) # superfluous indication of end ... def main(): ... commands = queue.Queue() replies = queue.Queue() worker = threading.Thread(target=code, args=(commands, replies)) worker.daemon = True # or use .setDaemon(True) for older for n in range(5): commands.put(n) print 'first couple:', results.get(), results.get() commands.put(None) # tell the worker to stop. worker.join() # wait for the worker to shut down. Making the worker a daemon, telling it to stop with a command, and waiting for it to finish with a .join are all belts-and-suspenders related to the thread shutdown, but it sounds like you have a thread shutdown issue. --Scott David Daniels Scott.Daniels#Acm.Org From robert.kern at gmail.com Thu Jun 11 17:42:07 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Jun 2009 16:42:07 -0500 Subject: Voronoi diagram algorithm =?UTF-8?B?KEZvcnR1bmXigJlzIHN3ZWVw?= =?UTF-8?B?bGluZSk=?= In-Reply-To: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: On 2009-06-11 16:16, Bearophile wrote: > Robert Kern: >> You can see a mild modification of Fortune's original C code here: >> >> http://svn.scipy.org/svn/scikits/trunk/delaunay/scikits/delaunay/Voro... > > That's C++; C++ makes simple things hard and hard things possible :-) The actual algorithm implementation is just Fortune's original C code. The C++ is mostly just wrapped around it. > In Python that code may become much shorter (and slower). Doubtful. The algorithm would mostly be the same. The data structure doesn't really translate to Python very well; it's very pointer-based. Yes, I've tried. -- 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 lyndiechiou at gmail.com Thu Jun 11 17:50:32 2009 From: lyndiechiou at gmail.com (lynvie) Date: Thu, 11 Jun 2009 14:50:32 -0700 (PDT) Subject: what does "lost sys.stdin" error mean? Message-ID: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> I have a very simple program from the first chapter of a book on python 3 (I'm a novice). I called the program tmp.py and the data input file is sum.dat (just a list of numbers, 1 per line). When I type into my command shell "tmp.py < sum.dat" I get an error from "line=input()" -- that's line 7 from the code below. The exact error message is: RuntimeError: input(): lost sys.stdin. print("Type integers, each followed by Enter; or ^D or ^Z to finish") total=0 count=0 while True: try: line=input() if line: number=int(line) total += number count += 1 print("number =",number) except ValueError as err: print(err) continue except EOFError: break if count: print("count =", count, "total =", total, "mean =", total/ count) From ben+python at benfinney.id.au Thu Jun 11 17:55:24 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Jun 2009 07:55:24 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> Message-ID: <87eitqa10z.fsf@benfinney.id.au> Gunter Henriksen writes: > I think I would have difficulty holding a position that this should > not be a class (or equivalent via namedtuple()) or a dict. It seems to > me like a case could be made that there are far more situations where > it makes sense to use tuples as immutable sequences than as objects > whose attributes are named implicitly by an index. This dodge_city > definitely does not seem to me like a good candidate for a plain > tuple. It's a fair cop. (I only meant that for this example a tuple was superior to a list, but you're right that a dict would be better than either.) Try, then, this tuple: event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, minute, second) = event_timestamp A list would be wrong for this value, because each position in the sequence has a specific meaning beyond its mere sequential position. Yet it also matters to the reader that these items are in a specific sequence, since that's a fairly standard ordering for those items. In this case, a tuple is superior to a list because it correctly conveys the semantic meaning of the overall value: the items must retain their sequential order to have the intended meaning, and to alter any one of them is conceptually to create a new timestamp value. -- \ ?[The RIAA] have the patience to keep stomping. They're playing | `\ whack-a-mole with an infinite supply of tokens.? ?kennon, | _o__) http://kuro5hin.org/ | Ben Finney From dorzey at googlemail.com Thu Jun 11 18:02:11 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:02:11 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From dorzey at googlemail.com Thu Jun 11 18:02:20 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:02:20 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From dorzey at googlemail.com Thu Jun 11 18:03:34 2009 From: dorzey at googlemail.com (dorzey) Date: Thu, 11 Jun 2009 15:03:34 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: Found this python implementation: http://www.oxfish.com/python/voronoi.py >From what I understand, not my area of expertise, it would seem to be correct. From rhodri at wildebst.demon.co.uk Thu Jun 11 18:12:38 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Jun 2009 23:12:38 +0100 Subject: How to escape # hash character in regex match strings In-Reply-To: <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: On Thu, 11 Jun 2009 15:22:44 +0100, Brian D wrote: > I'm surprised it's been so difficult to find an example of the hash > character in a RegEx string -- for exactly this type of situation, > since it's so common in the real world that people want to put a pound > symbol in front of a number. It's a character with no special meaning to the regex engine, so I'm not in the least surprised that there aren't many examples containing it. You could just as validly claim that there aren't many examples involving the letter 'q'. By the way, I don't know what you're doing but I'm seeing all of your posts twice, from two different addresses. This is a little confusing, to put it mildly, and doesn't half break the threading. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Thu Jun 11 18:12:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Jun 2009 23:12:39 +0100 Subject: install older Python version parallel In-Reply-To: <4A31199E.7030809@gmx.net> References: <4A31199E.7030809@gmx.net> Message-ID: On Thu, 11 Jun 2009 15:50:06 +0100, S. Dornseifer wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). You might get more helpful responses if you say more than just "it crashes". What's the traceback? -- Rhodri James *-* Wildebeest Herder to the Masses From hari at pillai.co.uk Thu Jun 11 18:18:24 2009 From: hari at pillai.co.uk (Harry) Date: Thu, 11 Jun 2009 23:18:24 +0100 Subject: command line of a process.exe on another host Message-ID: HI , I have number of process run on different windows servers which run's with different command line parameters. for example "process.exe -input statusurl: http://sss.com "., These parameters can vary from host to host. using Psexec I know the PID and process name which are running on these machines, but how I can read the command line parameters of these process. Is there a way to read these command line of the proess via python pls? any feedback appreciated.. thanks Hari From dfnsonfsduifb at gmx.de Thu Jun 11 18:19:31 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:19:31 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> <4a31080c$0$32676$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79de78F1pvp5cU1@mid.dfncis.de> Stefan Behnel schrieb: > Johannes Bauer wrote: >> Stefan Behnel schrieb: >> >>>> Can I somehow force Python to generate it anyways? >>> Did you try passing encoding='UTF-8' on serialisation? >> Uhm... nope - how can I do that? > > Well, depends on what your code currently does. > > Maybe you could use something like > > doc.xmlwrite(..., encoding='UTF-8') Yay! Does the trick, thanks a lot! Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From python.list at tim.thechases.com Thu Jun 11 18:19:33 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Jun 2009 17:19:33 -0500 Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: <4A3182F5.7080106@tim.thechases.com> >> I'm surprised it's been so difficult to find an example of the hash >> character in a RegEx string -- for exactly this type of situation, >> since it's so common in the real world that people want to put a pound >> symbol in front of a number. > > It's a character with no special meaning to the regex engine, so I'm not > in the least surprised that there aren't many examples containing it. > You could just as validly claim that there aren't many examples involving > the letter 'q'. It depends on whether the re.VERBOSE option is passed. If you're using a verbose regexp, you can use "#" to comment portions of it: r = re.compile(r""" \d+ # some digits [aeiou] # some vowels """, re.VERBOSE) -tkc From dfnsonfsduifb at gmx.de Thu Jun 11 18:21:10 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:21:10 +0200 Subject: xml.dom.minidom losing the XML document type attribute In-Reply-To: References: <79a0njF1pd0bqU1@mid.dfncis.de> <4a30a2db$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79c404F1psv7kU1@mid.dfncis.de> <4a30e27b$0$32663$9b4e6d93@newsspool2.arcor-online.net> <79celfF1odmrdU1@mid.dfncis.de> Message-ID: <79deaaF1pvp5cU2@mid.dfncis.de> David Robinow schrieb: > On Thu, Jun 11, 2009 at 9:20 AM, Johannes Bauer wrote: >> Well, I'm not speaking about my software :-) Actually it's Gnucash which >> complains if the tag is not explicitly set. This is because they >> appearently had a ancient version which did not specify the charset, but >> used a different one than UTF-8. Kind of annoying, but fixing my XML >> output seems to be easier than convincing the Gnucash people to change >> their software :-) > > from the GnuCash web page: > How can you help? Well, it's not as if it's a bug of GnuCash. This is a deliberate decision used to ensure backwards compatibility with older versions of GnuCash. So a bug report wouldn't really do good anything at all ("Please remove your backwards compatibility feature, it annoys me and I only use recent versions anyways"). Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From mensanator at aol.com Thu Jun 11 18:23:46 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 11 Jun 2009 15:23:46 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 11, 1:54?pm, Terry Reedy wrote: > Jack Diederich wrote: > > On Thu, Jun 11, 2009 at 12:03 AM, David M. Wilson wrote: > > [snip] > >> I found my answer: Python 2.6 introduces heap.merge(), which is > >> designed exactly for this. > > > Thanks, I knew Raymond added something like that but I couldn't find > > it in itertools. > > That said .. it doesn't help. ?Aside, heapq.merge fits better in > > itertools (it uses heaps internally but doesn't require them to be > > passed in). ?The other function that almost helps is > > itertools.groupby() and it doesn't return an iterator so is an odd fit > > for itertools. > > > More specifically (and less curmudgeonly) heap.merge doesn't help for > > this particular case because you can't tell where the merged values > > came from. ?You want all the iterators to yield the same thing at once > > but heapq.merge muddles them all together (but in an orderly way!). > > Unless I'm reading your tokenizer func wrong it can yield the same > > value many times in a row. ?If that happens you don't know if four > > "The"s are once each from four iterators or four times from one. > > David is looking to intersect sorted lists of document numbers with > duplicates removed in order to find documents that contain worda and > wordb and wordc ... . ?But you are right that duplicate are a possible > fly in the ointment to be removed before merging. Removing the duplicates could be a big problem. With SQL, the duplicates need not have to be removed. All I have to do is change "SELECT" to "SELECT DISTINCT" to change 100 100 100 322 322 322 322 322 322 322 322 into 100 322 From pavlovevidence at gmail.com Thu Jun 11 18:28:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Jun 2009 15:28:30 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: Message-ID: <8d0cb8d0-b7d7-4d12-868b-d0ab6804af7b@p21g2000prn.googlegroups.com> On Jun 11, 2:01?pm, Robert Kern wrote: > On 2009-06-11 14:56, Captain___nemo wrote: > > Please advice me very simple implementation of voronoi diagram (given > > coordinates). Please advice me simple python code preferably without- > > hash, multi-threading, Delaunay Traingulation, > > You can't really do the Voronoi diagram without Delaunay Triangulation. They are > two ways of looking at the same thing. You might not be able to calculate the exact points of a Voronoi without Delaunay triangulation but you can certainly draw one without it. For instance, this code does that: import numpy from PIL import Image def voronoi(points,shape=(500,500)): depthmap = numpy.ones(shape,numpy.float)*1e308 colormap = numpy.zeros(shape,numpy.int) def hypot(X,Y): return (X-x)**2 + (Y-y)**2 for i,(x,y) in enumerate(points): paraboloid = numpy.fromfunction(hypot,shape) colormap = numpy.where(paraboloid < depthmap,i+1,colormap) depthmap = numpy.where(paraboloid < depthmap,paraboloid,depthmap) for (x,y) in points: colormap[x-1:x+2,y-1:y+2] = 0 return colormap def draw_map(colormap): shape = colormap.shape palette = numpy.array([ 0x000000FF, 0xFF0000FF, 0x00FF00FF, 0xFFFF00FF, 0x0000FFFF, 0xFF00FFFF, 0x00FFFFFF, 0xFFFFFFFF, ]) colormap = numpy.transpose(colormap) pixels = numpy.empty(colormap.shape+(4,),numpy.int8) pixels[:,:,3] = palette[colormap] & 0xFF pixels[:,:,2] = (palette[colormap]>>8) & 0xFF pixels[:,:,1] = (palette[colormap]>>16) & 0xFF pixels[:,:,0] = (palette[colormap]>>24) & 0xFF image = Image.fromstring("RGBA",shape,pixels) image.save('voronoi.png') if __name__ == '__main__': draw_map(voronoi(([100,100],[356,301],[400,65],[324,145], [200,399]))) Carl Banks From dfnsonfsduifb at gmx.de Thu Jun 11 18:29:22 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Fri, 12 Jun 2009 00:29:22 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> References: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <79depnF1q8o72U1@mid.dfncis.de> Stefan Behnel schrieb: >> So I need to build hyperlinks (a elements) with href attribute and >> replace the text elements (numbers) somehow. > > Try lxml.html instead. It makes it really easy to do these things. For > example, you can use XPath to find all table cells that contain numbers: > > td_list = doc.xpath("//td[number() >= 0]") > > or maybe using regular expressions to make sure it's an int: > > td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", > namespaces={'re':'http://exslt.org/regular-expressions'}) > > and then replace them by a hyperlink: > > # assuming links = ['http://...', ...] > > from lxml.html.builder import A > for td in td_list: > index = int(td.text) > a = A("some text", href=links[index]) > td.getparent().replace(td, a) Oh no! I was looking for something like this for *ages* but always fought with minidom - where this is a real pain :-( Had I only known before that such a wonderful library exists. I'll definitely use lxml from now on. Does it compile with Python3? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From usernet at ilthio.net Thu Jun 11 19:01:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 23:01:16 GMT Subject: what does "lost sys.stdin" error mean? References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> Message-ID: <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> On 2009-06-11, lynvie wrote: > I have a very simple program from the first chapter of a book on > python 3 (I'm a novice). I called the program tmp.py and the data > input file is sum.dat (just a list of numbers, 1 per line). When I > type into my command shell "tmp.py < sum.dat" I get an error from What OS are you using? I know that pipes cause issues when working with interpreters on Windows. You must call the python interpreter directly or it will not be able to handle the pipe directly. I don't remember exacly how the issue manifests but I remember it has bitten me before on Win32. I don't currenlty have a Windows machine to test on. > "line=input()" -- that's line 7 from the code below. The exact error > message is: > RuntimeError: input(): lost sys.stdin. I am working on Linux and I have been unable to produce your error. My Python version identifies itself as: >>> import sys >>> sys.version '3.0.1 (r301:69556, Mar 17 2009, 11:42:03) \n[GCC 4.1.2]' This is what I have done using your same tmp.py file as pasted from a shell session: 17:52,505$ count=0 17:53,506$ while [ $count -lt 20 ]; do echo $RANDOM >> sum.dat; newcount=`echo "$count + 1" | bc`; count=$newcount; done 17:53,507$ python3.0 tmp.py < sum.dat Type integers, each followed by Enter; or ^D or ^Z to finish number = 22657 count = 1 total = 22657 mean = 22657.0 number = 12223 count = 2 total = 34880 mean = 17440.0 number = 10250 count = 3 total = 45130 mean = 15043.3333333 number = 20919 count = 4 total = 66049 mean = 16512.25 number = 20995 count = 5 total = 87044 mean = 17408.8 number = 28988 count = 6 total = 116032 mean = 19338.6666667 number = 13015 count = 7 total = 129047 mean = 18435.2857143 number = 25701 count = 8 total = 154748 mean = 19343.5 number = 6566 count = 9 total = 161314 mean = 17923.7777778 number = 19396 count = 10 total = 180710 mean = 18071.0 number = 16771 count = 11 total = 197481 mean = 17952.8181818 number = 2039 count = 12 total = 199520 mean = 16626.6666667 number = 655 count = 13 total = 200175 mean = 15398.0769231 number = 27417 count = 14 total = 227592 mean = 16256.5714286 number = 5000 count = 15 total = 232592 mean = 15506.1333333 number = 12015 count = 16 total = 244607 mean = 15287.9375 number = 8746 count = 17 total = 253353 mean = 14903.1176471 number = 29487 count = 18 total = 282840 mean = 15713.3333333 number = 3194 count = 19 total = 286034 mean = 15054.4210526 number = 8225 count = 20 total = 294259 mean = 14712.95 As you can see, it seems to be working as prescribed. From usernet at ilthio.net Thu Jun 11 19:25:08 2009 From: usernet at ilthio.net (Tim Harig) Date: Thu, 11 Jun 2009 23:25:08 GMT Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> Message-ID: On 2009-06-11, Tim Harig wrote: > On 2009-06-11, lynvie wrote: >> I have a very simple program from the first chapter of a book on >> python 3 (I'm a novice). I called the program tmp.py and the data >> input file is sum.dat (just a list of numbers, 1 per line). When I >> type into my command shell "tmp.py < sum.dat" I get an error from > What OS are you using? I know that pipes cause issues when working with > interpreters on Windows. You must call the python interpreter directly or > it will not be able to handle the pipe directly. I don't remember exacly > how the issue manifests but I remember it has bitten me before on Win32. I > don't currenlty have a Windows machine to test on. More info: http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/10d3928277319bef From gunterhenriksen at gmail.com Thu Jun 11 19:34:56 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 16:34:56 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <87eitqa10z.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> Message-ID: > Try, then, this tuple: > > event_timestamp = (2009, 06, 04, 05, 02, 03) > (year, month, day, hour, minute, second) = event_timestamp > > A list would be wrong for this value, because each position in the > sequence has a specific meaning beyond its mere sequential position. Yet > it also matters to the reader that these items are in a specific > sequence, since that's a fairly standard ordering for those items. > > In this case, a tuple is superior to a list because it correctly conveys > the semantic meaning of the overall value: the items must retain their > sequential order to have the intended meaning, and to alter any one of > them is conceptually to create a new timestamp value. I totally agree about anything to do with immutability, I think the relative ordering of the elements in this example may be orthogonal to the concept of a tuple as an object whose elements have a semantic meaning implicitly defined by location in the sequence... in other words knowing that element i+1 is in some sense ordinally smaller than element i does not give me much information about what element i+1 actually is. To me a timestamp could be (date, time), or (days, seconds, microseconds) (as in datetime.timedelta()), so it is not clear to me that using a tuple as something where the semantic meaning of the element at position i should readily apparent would be the best approach for timestamps, or enough to distinguish list and tuple (in other words I am not suggesting a dict or class). In the case of something like (x, y) or (real, imag), or (longitude, latitude), or any case where there is common agreement and understanding, such that using names is arguably superfluous... I think in those cases the concept makes sense of a tuple as a sequence of attributes whose elements have a semantic meaning implicitly defined by position in the sequence. My feeling is the number of cases where tuples are better than lists for that is small relative to the number of cases where tuple adds value as an immutable list. I do not mean to be suggesting that a tuple should only ever be used or thought of as a "frozenlist" though. From bearophileHUGS at lycos.com Thu Jun 11 19:47:30 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 11 Jun 2009 16:47:30 -0700 (PDT) Subject: =?windows-1252?Q?Re=3A_Voronoi_diagram_algorithm_=28Fortune=92s_sweepline?= =?windows-1252?Q?=29?= References: <2497ae6f-b3ea-487c-935c-67b2ca4e9e1a@e21g2000yqb.googlegroups.com> Message-ID: <487b006c-f4ab-448b-90eb-9d7450d15f3a@3g2000yqk.googlegroups.com> dorzey: > Found this python implementation: > http://www.oxfish.com/python/voronoi.py Looks very nice, and it may be ShedSkin-compilable too. Bye, bearophile From ben+python at benfinney.id.au Thu Jun 11 19:56:14 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 12 Jun 2009 09:56:14 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> Message-ID: <878wjy8gv5.fsf@benfinney.id.au> Gunter Henriksen writes: > > Try, then, this tuple: > > > > event_timestamp = (2009, 06, 04, 05, 02, 03) > > (year, month, day, hour, minute, second) = event_timestamp > > I totally agree about anything to do with immutability, I think the > relative ordering of the elements in this example may be orthogonal to > the concept of a tuple as an object whose elements have a semantic > meaning implicitly defined by location in the sequence... in other > words knowing that element i+1 is in some sense ordinally smaller than > element i does not give me much information about what element i+1 > actually is. The point of each position having a different semantic meaning is that tuple unpacking works as above. You need to know the meaning of each position in order to unpack it to separate names, as above. So two tuples that differ only in the sequence of their items are different in meaning. This is unlike a list, where the sequence of items does *not* affect the semantic meaning of each item. Note that I'm well aware that the language doesn't impose this as a hard restriction; but that says more about Python's ?consenting adults? philosophy than anything else. -- \ ?I went to a general store. They wouldn't let me buy anything | `\ specifically.? ?Steven Wright | _o__) | Ben Finney From clp2 at rebertia.com Thu Jun 11 20:36:52 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 17:36:52 -0700 Subject: help with errror In-Reply-To: References: Message-ID: <50697b2c0906111736kc89aceoec7329b294c96478@mail.gmail.com> On Thu, Jun 11, 2009 at 2:33 PM, tanner barnes wrote: > could some one explain this error to me and possibly how to fix it? > > Traceback (most recent call last): > ? File "C:\Users\brandon\workspace\tanner's workshop\tanner's > workshop\src\WxGlade.py", line 458, in > ??? Edit = MyDialog2(None, -1, "") > ? File "C:\Users\brandon\workspace\tanner's workshop\tanner's > workshop\src\WxGlade.py", line 27, in __init__ > ??? self.Name = wx.StaticText(self.panel_41, -1, "Name") > ? File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line > 8522, in SetName > ??? return _core_.Window_SetName(*args, **kwargs) > TypeError: String or Unicode type required Might I suggest you inquire on the WxPython mailinglist: http://www.wxpython.org/maillist.php Cheers, Chris -- http://blog.rebertia.com From gunterhenriksen at gmail.com Thu Jun 11 21:14:35 2009 From: gunterhenriksen at gmail.com (Gunter Henriksen) Date: Thu, 11 Jun 2009 18:14:35 -0700 Subject: preferring [] or () in list of error codes? In-Reply-To: <878wjy8gv5.fsf@benfinney.id.au> References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: > > > event_timestamp = (2009, 06, 04, 05, 02, 03) > > > (year, month, day, hour, minute, second) = event_timestamp > > > > [...] > > The point of each position having a different semantic meaning is that > tuple unpacking works as above. You need to know the meaning of each > position in order to unpack it to separate names, as above. > > So two tuples that differ only in the sequence of their items are > different in meaning. This is unlike a list, where the sequence of items > does *not* affect the semantic meaning of each item. I do not feel the above is significantly different enough from event_timestamp = [2009, 06, 04, 05, 02, 03] (year, month, day, hour, minute, second) = event_timestamp event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, minute, second) = event_timestamp event_timestamp = [2009, 06, 04, 05, 02, 03] [year, month, day, hour, minute, second] = event_timestamp to suggest tuples are really adding significant value in this case, especially when I can do something like event_timestamp = (2009, 06, 04, 05, 02, 03) (year, month, day, hour, second, minute) = event_timestamp and not have any indication I have done the wrong thing. I guess to me, fundamentally, the interpretation of tuple as a sequence whose elements have semantic meaning implicitly defined by position is a relatively abstract intrepretation whose value is dubious relative to the value of immutability, since it seems like a shortcut which sacrifices explicitness for the sake of brevity. I would feel differently if seemed unusual to find good Python code which iterates through the elements of a tuple as a variable length homogenous ordered collection. But then I would be wishing for immutable lists... From drentha at gmail.com Thu Jun 11 21:54:56 2009 From: drentha at gmail.com (Oni) Date: Thu, 11 Jun 2009 18:54:56 -0700 (PDT) Subject: Specify the sorting direction for the various columns/ Message-ID: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Managed to get a dictionary to sort on multiple columns using a tuple to set the sort order (see below). However how can I control that column "date" orders descending and the column "name" orders ascending. Thanks import datetime import pprint import operator faUserFormInput = {'DDPageSortOrder': 'PageAge'} mypages = ["PageName","PageAge","PageAge"] gaValidSortOrder = [ {'OrderType': 'PageName', 'SortOrder': ('name')}, {'OrderType': 'PageAge', 'SortOrder': ('date','name')}, {'OrderType': 'PageAuthor', 'SortOrder': ('username','date')} ] entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] sortorderarr = ('name','date') #if ("DDPageSortOrder" in faUserFormInput): for item in gaValidSortOrder: print "1=%s" % (item["OrderType"]) print "2=%s" % (faUserFormInput["DDPageSortOrder"]) if (item["OrderType"] == faUserFormInput["DDPageSortOrder"]): sortorderarr = item["SortOrder"] #sortorderarr = '\','.join(sortorder) print sortorderarr pp = pprint.PrettyPrinter(depth=2) pp.pprint(entries) bob = entries bob.sort(key=operator.itemgetter(*sortorderarr),reverse=True) pp.pprint(bob) From walkraft at gmail.com Thu Jun 11 22:03:46 2009 From: walkraft at gmail.com (casebash) Date: Thu, 11 Jun 2009 19:03:46 -0700 (PDT) Subject: Convert integer to fixed length binary string References: <59d5d28d-0783-46b9-9462-3fecb52bd4a5@c18g2000prh.googlegroups.com> <1377g6-4i7.ln1@satorlaser.homedns.org> Message-ID: <3e342702-34d2-41fe-8343-3fbb5bb2f878@y6g2000prf.googlegroups.com> Thanks, this is what I needed On Jun 11, 9:40?pm, Ulrich Eckhardt wrote: > casebash wrote: > > I know the bin function converts an int into a binary string. > > Binary string sounds ambiguous. Firstly, everything is binary. Secondly, > strings are byte strings or Unicode strings. In any case, I'm not 100% sure > what you mean - giving an example of input and output would help! > > > Unfortunately, I need to know the length of the binary string when it > > is being read in and len(bin(x)) depends on x. Is there any way to > > limit it to 4 bytes? > > If you need a piece of four bytes which contain a number in a packed format > similar to the one used in memory, using bin(x) is the wrong way. Instead, > take a look at the struct module: > > ? import struct > ? struct.pack('=L', 255) > > Alternatively, also the array module might help. > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jiangsy at gmail.com Thu Jun 11 22:20:27 2009 From: jiangsy at gmail.com (sanyi jiang) Date: Fri, 12 Jun 2009 10:20:27 +0800 Subject: Socket packet timing on Windows 2000 Message-ID: <896de4920906111920h5e2dc687m6b871ab4da0cdc52@mail.gmail.com> hi *Tim Janick,* I encountered same problem, did you ever get some resolution? Brent Jiang, -------------- next part -------------- An HTML attachment was scrubbed... URL: From Nikolaus at rath.org Thu Jun 11 22:28:05 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Thu, 11 Jun 2009 22:28:05 -0400 Subject: Problem with apsw and garbage collection Message-ID: <87tz2mb2yy.fsf@vostro.rath.org> Hi, Please consider this example: -------------- next part -------------- A non-text attachment was scrubbed... Name: vacuum.py Type: text/x-python Size: 1006 bytes Desc: not available URL: -------------- next part -------------- While the first execute("VACUUM") call succeeds, the second does not but raises an apsw.BusyError (meaning that sqlite thinks that it cannot get an exclusive lock on the database). I suspect that the reason for that is that the cursor object that is created in the function is not destroyed when the function is left with raise (rather than return), which in turn prevents sqlite from obtaining the lock. However, if I exchange the VACUUM command by something else (e.g. CREATE TABLE), the program runs fine. I think this casts some doubt on the above explanation, since, AFAIK sqlite always locks the entire file and should therefore have the some problem as before. Can someone explain what exactly is happening here? Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From silverburgh.meryl at gmail.com Thu Jun 11 22:30:14 2009 From: silverburgh.meryl at gmail.com (meryl) Date: Thu, 11 Jun 2009 19:30:14 -0700 (PDT) Subject: Need help in Python regular expression Message-ID: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Hi, I have this regular expression blockRE = re.compile(".*RenderBlock {\w+}") it works if my source is "RenderBlock {CENTER}". But I want it to work with 1. RenderTable {TABLE} So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), but that breaks everything 2. RenderBlock (CENTER) So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), that also breaks everything Can you please tell me how to change my reg exp so that I can support all 3 cases: RenderTable {TABLE} RenderBlock (CENTER) RenderBlock {CENTER} Thank you. From peter at www.pjb.com.au Thu Jun 11 23:32:26 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 12 Jun 2009 03:32:26 GMT Subject: Measuring Fractal Dimension ? Message-ID: Greetings. Are there any modules, packages, whatever, that will measure the fractal dimensions of a dataset, e.g. a time-series ? Like the Correlation Dimension, the Information Dimension, etc... Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From lucius.fox08 at gmail.com Thu Jun 11 23:56:24 2009 From: lucius.fox08 at gmail.com (lucius) Date: Thu, 11 Jun 2009 20:56:24 -0700 (PDT) Subject: TypeError: int argument required Message-ID: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> I am trying to print some values to a file (using c's printf like method). TypeError: int argument required # this works, i see value on screen print w, h, absX, absY # where result is the return value of my regular expression. w, h, absX, absY = result.group(3), result.group(4), result.group (5), result.group(6) w = 100 h = 200 absX = 10.0 absY = 20.0 # this fails, I get "TypeError: int argument required" print >> fo, " " % (absX, absY, w, h) Thank you for any help. From wuwei23 at gmail.com Fri Jun 12 00:01:14 2009 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Jun 2009 21:01:14 -0700 (PDT) Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <1baa40c6-0666-4376-9ad0-47fc2c8326cb@p21g2000prn.googlegroups.com> On Jun 12, 1:56?pm, lucius wrote: > ?w, h, absX, absY = result.group(3), result.group(4), result.group > (5), result.group(6) > > w = 100 > h = 200 > > absX = 10.0 > absY = 20.0 Are you sure those values are ints & floats? I would expect your regexp would be returning strings... Try replacing the %f & %d strsubs with %s and see if that works. (You shouldn't need to typecast the values if you're just reinserting them into a string...) From metolone+gmane at gmail.com Fri Jun 12 00:41:24 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 11 Jun 2009 21:41:24 -0700 Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: "meryl" wrote in message news:2d4d8624-043b-4f5f-ae2d-bf73bca3d51b at p6g2000pre.googlegroups.com... > Hi, > > I have this regular expression > blockRE = re.compile(".*RenderBlock {\w+}") > > it works if my source is "RenderBlock {CENTER}". > > But I want it to work with > 1. RenderTable {TABLE} > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > but that breaks everything > > 2. RenderBlock (CENTER) > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > that also breaks everything > > Can you please tell me how to change my reg exp so that I can support > all 3 cases: > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} [abcd] syntax matches a single character from the set. Use non-grouping parentheses instead: -----------------------code---------------------- import re pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') testdata = '''\ RenderTable {TABLE} RenderBlock (CENTER) RenderBlock {CENTER} RenderTable {TABLE) #shouldn't match ''' print pat.findall(testdata) --------------------------------------------------- Result: ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] -Mark From jstrickler at gmail.com Fri Jun 12 00:47:51 2009 From: jstrickler at gmail.com (John S) Date: Thu, 11 Jun 2009 21:47:51 -0700 (PDT) Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> On Jun 11, 10:30?pm, meryl wrote: > Hi, > > I have this regular expression > blockRE = re.compile(".*RenderBlock {\w+}") > > it works if my source is "RenderBlock {CENTER}". > > But I want it to work with > 1. RenderTable {TABLE} > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > but that breaks everything > > 2. RenderBlock (CENTER) > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > that also breaks everything > > Can you please tell me how to change my reg exp so that I can support > all 3 cases: > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} > > Thank you. Short answer: r = re.compile(r"Render(?:Block|Table)\s+[({](?:TABLE|CENTER)[})]") s = """ blah blah blah blah blah blah RenderBlock {CENTER} blah blah RenderBlock {CENTER} blah blah blah RenderTable {TABLE} blah blah RenderBlock (CENTER) blah blah blah """ print r.findall(s) output: ['RenderBlock {CENTER}', 'RenderBlock {CENTER}', 'RenderTable {TABLE}', 'RenderBlock (CENTER)'] Note that [] only encloses characters, not strings; [foo|bar] matches 'f','o','|','b','a', or 'r', not "foo" or "bar". Use (foo|bar) to match "foo" or "bar"; (?xxx) matches xxx without making a backreference (i.e., without capturing text). HTH -- John Strickler From metolone+gmane at gmail.com Fri Jun 12 00:55:16 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Thu, 11 Jun 2009 21:55:16 -0700 Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Message-ID: "Oni" wrote in message news:018f4fa2-7203-4c98-a313-da5584976bd9 at z20g2000prh.googlegroups.com... > Managed to get a dictionary to sort on multiple columns using a tuple > to set the sort order (see below). However how can I control that > column "date" orders descending and the column "name" orders > ascending. One way is to sort twice...sort on the secondary key first, then the primary key. sort will maintain the order of equal entries. -Mark From stefan_ml at behnel.de Fri Jun 12 01:08:19 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Jun 2009 07:08:19 +0200 Subject: How *build* new elements and *replace* elements with xml.dom.minidom ? In-Reply-To: <79depnF1q8o72U1@mid.dfncis.de> References: <4a30a297$0$32670$9b4e6d93@newsspool2.arcor-online.net> <79depnF1q8o72U1@mid.dfncis.de> Message-ID: <4a31e2c3$0$30231$9b4e6d93@newsspool1.arcor-online.net> Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> So I need to build hyperlinks (a elements) with href attribute and >>> replace the text elements (numbers) somehow. >> Try lxml.html instead. It makes it really easy to do these things. For >> example, you can use XPath to find all table cells that contain numbers: >> >> td_list = doc.xpath("//td[number() >= 0]") >> >> or maybe using regular expressions to make sure it's an int: >> >> td_list = doc.xpath("//td[re:match(., '^[0-9]+$')]", >> namespaces={'re':'http://exslt.org/regular-expressions'}) >> >> and then replace them by a hyperlink: >> >> # assuming links = ['http://...', ...] >> >> from lxml.html.builder import A >> for td in td_list: >> index = int(td.text) >> a = A("some text", href=links[index]) >> td.getparent().replace(td, a) > > Oh no! I was looking for something like this for *ages* but always > fought with minidom - where this is a real pain :-( > > Had I only known before that such a wonderful library exists. I'll > definitely use lxml from now on. Yep, I keep advertising it all over the place, but there are still so many references to minidom on the web that it's hard to become the first hit in Google when you search for "Python XML". ;) Actually, the first hit (for me) is currently PyXML, which is officially unmaintained. Wasn't there 'some' Python developer working for Google? What about fixing their database? > Does it compile with Python3? Sure. :) Stefan From silverburgh.meryl at gmail.com Fri Jun 12 01:20:24 2009 From: silverburgh.meryl at gmail.com (meryl) Date: Thu, 11 Jun 2009 22:20:24 -0700 (PDT) Subject: Need help in Python regular expression References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: On Jun 11, 9:41?pm, "Mark Tolonen" wrote: > "meryl" wrote in message > > news:2d4d8624-043b-4f5f-ae2d-bf73bca3d51b at p6g2000pre.googlegroups.com... > > > > > > > Hi, > > > I have this regular expression > > blockRE = re.compile(".*RenderBlock {\w+}") > > > it works if my source is "RenderBlock {CENTER}". > > > But I want it to work with > > 1. RenderTable {TABLE} > > > So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), > > but that breaks everything > > > 2. RenderBlock (CENTER) > > > So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), > > that also breaks everything > > > Can you please tell me how to change my reg exp so that I can support > > all 3 cases: > > RenderTable {TABLE} > > RenderBlock (CENTER) > > RenderBlock {CENTER} > > [abcd] syntax matches a single character from the set. ?Use non-grouping > parentheses instead: > > -----------------------code---------------------- > import re > pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') > > testdata = '''\ > RenderTable {TABLE} > RenderBlock (CENTER) > RenderBlock {CENTER} > RenderTable {TABLE) ? ? ?#shouldn't match > ''' > > print pat.findall(testdata) > --------------------------------------------------- > > Result: > > ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] > > -Mark Thanks for both of your help. How can i modify the RegExp so that both RenderTable {TABLE} and RenderTable {TABLE} [text with a-zA-Z=SPACE0-9] will match I try adding ".*" at the end , but it ends up just matching the second one. Thanks again. From mk.fraggod at gmail.com Fri Jun 12 01:34:34 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 12 Jun 2009 11:34:34 +0600 Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> Message-ID: <20090612113434.47a84b00@coercion> On Thu, 11 Jun 2009 18:54:56 -0700 (PDT) Oni wrote: > Managed to get a dictionary to sort on multiple columns using a tuple > to set the sort order (see below). However how can I control that > column "date" orders descending and the column "name" orders > ascending. ... > bob = entries > bob.sort(key=operator.itemgetter(*sortorderarr),reverse=True) > pp.pprint(bob) Note that this accomplishes nothing, since bob and entries are the same object, so entries.sort and bob.sort are the same method of the same object. You can use "copy" module to clone list and it's contents (dict objects) or just use list constructor to clone list structure only, leaving contents essencially the same, but in different order. Or, in this case, you can just use "sorted" function which constructs sorted list from any iterable. As for the question, in addition to Mark's suggestion of doing sub-sorting, you can also construct complex index (code below). Dunno which would be more efficient in the particular case... import datetime import pprint entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] entries.sort(lambda x: (x['name'], -time.mktime(x['date'].timetuple()))) Here time is inversed, yielding reverse sort order by that column. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lyndiechiou at gmail.com Fri Jun 12 02:15:04 2009 From: lyndiechiou at gmail.com (lynvie) Date: Thu, 11 Jun 2009 23:15:04 -0700 (PDT) Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> Message-ID: <602fb38b-abdf-498a-8b3b-99eeb1f388ac@s38g2000prg.googlegroups.com> Thanks for the additional info! I had no idea this was an old Windows problem... I'm using Windows XP and I'm up-to-date on all my patches. The good news is I can invoke the script correctly now, thanks to your help! On Jun 11, 4:25?pm, Tim Harig wrote: > On 2009-06-11, Tim Harig wrote: > > > On 2009-06-11, lynvie wrote: > >> I have a very simple program from the first chapter of a book on > >> python 3 (I'm a novice). I called the program tmp.py and the data > >> input file is sum.dat (just a list of numbers, 1 per line). When I > >> type into my command shell "tmp.py < sum.dat" I get an error from > > What OS are you using? ?I know that pipes cause issues when working with > > interpreters on Windows. ?You must call the python interpreter directly or > > it will not be able to handle the pipe directly. ?I don't remember exacly > > how the issue manifests but I remember it has bitten me before on Win32. ?I > > don't currenlty have a Windows machine to test on. > > More info:http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/1... From prasoonthegreat at gmail.com Fri Jun 12 02:17:36 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:17:36 -0700 (PDT) Subject: EOF problem with ENTER Message-ID: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> I am new to python.... I have written the following program in python.It is the solution of problem ETF in SPOJ..... #Euler Totient Function from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): t=input() while(t): x=input() print str(etf(x)) t-=1 if __name__ == "__main__": main() The problem with my code is that whenever I press an extra "Enter" button instead of getting the cursor moved to the next line.....I get an error _SyntaxError- EOF while parsing and the program terminates.........._ How should the code be modified so that even after pressing an extra "Enter" button the cursor get moved to the next line instead to throwing an exception...... Prasoon From clp2 at rebertia.com Fri Jun 12 02:28:20 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 11 Jun 2009 23:28:20 -0700 Subject: EOF problem with ENTER In-Reply-To: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <50697b2c0906112328x52e06d64h4ccfa6fdd24a2158@mail.gmail.com> On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > I am new to python.... > I have written the following program in python.It is the solution of > problem ETF in SPOJ..... > > > #Euler Totient Function > > from math import sqrt > def etf(n): > ? i,res =2,n > ? while(i*i<=n): > ? ? ?if(n%i==0): > ? ? ? ? ? ?res-=res/i > ? ? ?while(n%i==0): > ? ? ? ? ? ?n/=i > ? ? ?i+=1 > ? if(n>1): > ? ? ? ?res-=res/n > ? return res > > def main(): > ?t=input() > ?while(t): > ? ?x=input() > ? ?print str(etf(x)) > ? ?t-=1 > > if __name__ == "__main__": > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > button instead of getting the cursor moved to the next line.....I get > an error > > _SyntaxError- EOF while parsing and the program terminates.........._ > > How should ?the code be modified so that even after ?pressing an extra > "Enter" button the cursor get moved to the next line instead to > throwing an exception...... Use raw_input() instead of input() [at least until you switch to Python 3.x]. input() does an implicit eval() of the keyboard input, which is (in part) causing your problem. Note that you'll need to explicitly convert the string raw_input() reads in using either int() or float() as appropriate. Still, you can't just enter extra lines and expect the program to automatically ignore them. You'll have to write the extra code yourself to handle empty input from the user. Cheers, Chris -- http://blog.rebertia.com From graham.dumpleton at gmail.com Fri Jun 12 02:29:10 2009 From: graham.dumpleton at gmail.com (Graham Dumpleton) Date: Thu, 11 Jun 2009 23:29:10 -0700 (PDT) Subject: FW: [Tutor] Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: On Jun 12, 3:35?pm, Dennis Lee Bieber wrote: > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > declaimed the following in > gmane.comp.python.general: > > > I sent this to the Tutor mailing list and did not receive a response. > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > remarks? > > > Please reply off-list and thanks in advance. Code examples are below in > > plain text. > > ? ? ? ? Sorry -- you post to a public forum, expect to get the response on a > public forum... Bbit off topic, but if you are a proponent of public forums, how come your post on Google Groups shows: """Note: The author of this message requested that it not be archived. This message will be removed from Groups in 6 days (Jun 19, 3:35 pm).""" I always find it a tad annoying that people have this, as you loose posts from the record of a discussion and if that post carries useful information, it is lost. Am also curious as to what mechanism for posting you use that allows you to set an expiration time on the post anyway. Are you using old usenet news reader or something? Graham From prasoonthegreat at gmail.com Fri Jun 12 02:48:01 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:48:01 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <2dbcf0eb-39fa-4492-ab70-6f219f3610c9@w9g2000pro.googlegroups.com> On Jun 12, 11:28?am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python.... > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ..... > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > > ? i,res =2,n > > ? while(i*i<=n): > > ? ? ?if(n%i==0): > > ? ? ? ? ? ?res-=res/i > > ? ? ?while(n%i==0): > > ? ? ? ? ? ?n/=i > > ? ? ?i+=1 > > ? if(n>1): > > ? ? ? ?res-=res/n > > ? return res > > > def main(): > > ?t=input() > > ?while(t): > > ? ?x=input() > > ? ?print str(etf(x)) > > ? ?t-=1 > > > if __name__ == "__main__": > > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > > button instead of getting the cursor moved to the next line.....I get > > an error > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > How should ?the code be modified so that even after ?pressing an extra > > "Enter" button the cursor get moved to the next line instead to > > throwing an exception...... > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > input() does an implicit eval() of the keyboard input, which is (in > part) causing your problem. > Note that you'll need to explicitly convert the string raw_input() > reads in using either int() or float() as appropriate. > > Still, you can't just enter extra lines and expect the program to > automatically ignore them. You'll have to write the extra code > yourself to handle empty input from the user. > > Cheers, > Chris > --http://blog.rebertia.com I am using Python 2.6 I have modified that code def main(): t=int(raw_input()) while(t): x=input() print str(etf(x)) t-=1 what should i do to handle new line and space...... We used to get spaces and newline in C using their ASCII values ...can similar things be done here??? Please write the code snippet(by modifying my code) from which i can understand something......!!!!! From prasoonthegreat at gmail.com Fri Jun 12 02:49:25 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Thu, 11 Jun 2009 23:49:25 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> Message-ID: <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> On Jun 12, 11:28?am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python.... > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ..... > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > > ? i,res =2,n > > ? while(i*i<=n): > > ? ? ?if(n%i==0): > > ? ? ? ? ? ?res-=res/i > > ? ? ?while(n%i==0): > > ? ? ? ? ? ?n/=i > > ? ? ?i+=1 > > ? if(n>1): > > ? ? ? ?res-=res/n > > ? return res > > > def main(): > > ?t=input() > > ?while(t): > > ? ?x=input() > > ? ?print str(etf(x)) > > ? ?t-=1 > > > if __name__ == "__main__": > > ?main() > > > The problem with my code is that whenever I press an extra "Enter" > > button instead of getting the cursor moved to the next line.....I get > > an error > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > How should ?the code be modified so that even after ?pressing an extra > > "Enter" button the cursor get moved to the next line instead to > > throwing an exception...... > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > input() does an implicit eval() of the keyboard input, which is (in > part) causing your problem. > Note that you'll need to explicitly convert the string raw_input() > reads in using either int() or float() as appropriate. > > Still, you can't just enter extra lines and expect the program to > automatically ignore them. You'll have to write the extra code > yourself to handle empty input from the user. > > Cheers, > Chris > --http://blog.rebertia.com I am using Python 2.6 I have modified that code def main(): t=int(raw_input()) while(t): x=int(raw_input()) print str(etf(x)) t-=1 what should i do to handle new line and space...... We used to get spaces and newline in C using their ASCII values ...can similar things be done here??? Please write the code snippet(by modifying my code) from which i can understand something......!!!!! From lepto.python at gmail.com Fri Jun 12 03:07:44 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 12 Jun 2009 15:07:44 +0800 Subject: ANN: WHIFF += Flash chart widget support (Aaron Watters) Message-ID: <6a4f17690906120007t9b886efp64cc54a82044d2e7@mail.gmail.com> nice the only pity is that amcharts is not a money-free product From mail at timgolden.me.uk Fri Jun 12 03:24:26 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Jun 2009 08:24:26 +0100 Subject: command line of a process.exe on another host In-Reply-To: References: Message-ID: <4A3202AA.1010305@timgolden.me.uk> Harry wrote: > HI , > I have number of process run on different windows servers which run's > with different command line parameters. for example "process.exe > -input statusurl: http://sss.com "., These parameters can vary from > host to host. using Psexec I know the PID and process name which are > running on these machines, but how I can read the command line > parameters of these process. Is there a way to read these command line > of the proess via python pls? WMI can get this for you. This example uses my WMI module from here: http://timgolden.me.uk/python/wmi.html but it's not hard to do it with "raw" Python / Windows. import wmi c = wmi.WMI ("other_machine") for p in c.Win32_Process (name="process.exe"): print p.CommandLine TJG From Eric_Dexter at msn.com Fri Jun 12 03:27:47 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 12 Jun 2009 00:27:47 -0700 (PDT) Subject: install older Python version parallel References: Message-ID: On Jun 11, 8:50?am, "S. Dornseifer" wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon 0n windows I had multiple versions installed ex python24 python25 i would write a batch file C:\python24\python.exe test.py pause the pause is there just so that I can see an error message if there is one. I have no idea what would work for the mac or linux though... I suspect something simular might work after all why rewrite all your software because someone else wants you to have a particular version of python not with the amount of disk space that is available now-adays.. From Eric_Dexter at msn.com Fri Jun 12 03:30:14 2009 From: Eric_Dexter at msn.com (edexter) Date: Fri, 12 Jun 2009 00:30:14 -0700 (PDT) Subject: install older Python version parallel References: Message-ID: On Jun 11, 8:50?am, "S. Dornseifer" wrote: > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. > I would like to know, how to install Python 2.4 along with TkInter and > Pmw (and packages that are required by them), parallel to the existing > Python 2.6. So that I do not break other software that depends on Python > 2.6. > > If you can think of another plan, I would be also glad to discuss it. > > Cheers, > Simon I suspect you want to install python 2.4 and then reinstall 2.6 I did that in windows and I don't understand why it wouldn't work in linux From lepto.python at gmail.com Fri Jun 12 03:35:19 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 12 Jun 2009 15:35:19 +0800 Subject: RE replace problem too Message-ID: <6a4f17690906120035u9f0aa6ag3631b84dc9e687e6@mail.gmail.com> in my case, I want to replace all the function name with '', that is sin(1) -> (1) sin(pi*(2+4)) -> (pi*(2+4)) how can I use RE in this situation? thanx From bieffe62 at gmail.com Fri Jun 12 03:56:04 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Fri, 12 Jun 2009 00:56:04 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: On 12 Giu, 08:49, Prasoon wrote: > On Jun 12, 11:28?am, Chris Rebert wrote: > > > > > > > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > > I am new to python.... > > > I have written the following program in python.It is the solution of > > > problem ETF in SPOJ..... > > > > #Euler Totient Function > > > > from math import sqrt > > > def etf(n): > > > ? i,res =2,n > > > ? while(i*i<=n): > > > ? ? ?if(n%i==0): > > > ? ? ? ? ? ?res-=res/i > > > ? ? ?while(n%i==0): > > > ? ? ? ? ? ?n/=i > > > ? ? ?i+=1 > > > ? if(n>1): > > > ? ? ? ?res-=res/n > > > ? return res > > > > def main(): > > > ?t=input() > > > ?while(t): > > > ? ?x=input() > > > ? ?print str(etf(x)) > > > ? ?t-=1 > > > > if __name__ == "__main__": > > > ?main() > > > > The problem with my code is that whenever I press an extra "Enter" > > > button instead of getting the cursor moved to the next line.....I get > > > an error > > > > _SyntaxError- EOF while parsing and the program terminates.........._ > > > > How should ?the code be modified so that even after ?pressing an extra > > > "Enter" button the cursor get moved to the next line instead to > > > throwing an exception...... > > > Use raw_input() instead of input() [at least until you switch to Python 3.x]. > > input() does an implicit eval() of the keyboard input, which is (in > > part) causing your problem. > > Note that you'll need to explicitly convert the string raw_input() > > reads in using either int() or float() as appropriate. > > > Still, you can't just enter extra lines and expect the program to > > automatically ignore them. You'll have to write the extra code > > yourself to handle empty input from the user. > > > Cheers, > > Chris > > --http://blog.rebertia.com > > I am using Python 2.6 > I have modified that code > def main(): > ? t=int(raw_input()) > ? while(t): > ? ? x=int(raw_input()) > ? ? print str(etf(x)) > ? ? t-=1 > > what should i do to handle new line and space...... > We used to get spaces and newline in C using their ASCII values ...can > similar things be done here??? > > Please write the code snippet(by modifying my code) from which i can > understand something......!!!!! > > - Mostra testo citato - You could do: while True: x = raw_input("Enter x=>") if x != "" : break # if you just press enter, raw_input returns an empty string Note that this still leaves out the case when you type something which is not a number. To cover this case, supposing that you need a float, you could do like this (NOT TESTED): while True: x_str = raw_input("Enter x=>") if x_str != "" : # to prevent having the error message on empty imput try: x = float(x_str) break # if it gets here the conversion in float was succesful except ValueError : print "The input '%s' cannot be converted in float" % x_str This code exits from the loop only when you supply a string that represents a floating number Ciao ----- FB From usernet at ilthio.net Fri Jun 12 04:01:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 12 Jun 2009 08:01:44 GMT Subject: Win32 stdin redirection References: <033826f4-6702-4808-b281-3c0c465583c8@v23g2000pro.googlegroups.com> <01gYl.35089$ZP4.3171@nlpi067.nbdc.sbc.com> <602fb38b-abdf-498a-8b3b-99eeb1f388ac@s38g2000prg.googlegroups.com> Message-ID: On 2009-06-12, lynvie wrote: > Thanks for the additional info! I had no idea this was an old Windows > problem... I'm using Windows XP and I'm up-to-date on all my patches. s/problem/feature/ Steve Ballmer, CEO of Microsoft, would prefer that you think of it as a 'feature'. This is a problem that I would suspect has plagued a lot of people because it doesn't seem to be overly documented in any of the popular python learning materials. Even Mark Hammond & Andy Robinson's book _Python Programming on Win32_ doesn't mention the problem directly in its Windowes gotchas section-- though it does mention there are a number of bugs in the Windows implementation of popen(). > The good news is I can invoke the script correctly now, thanks to your > help! Happy Pythoning! From vlastimil.brom at gmail.com Fri Jun 12 04:36:30 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 12 Jun 2009 10:36:30 +0200 Subject: Need help in Python regular expression In-Reply-To: References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: <9fdb569a0906120136o6802769fg6a9c04493904fe1b@mail.gmail.com> 2009/6/12 meryl : > On Jun 11, 9:41?pm, "Mark Tolonen" wrote: >> "meryl" wrote in message >> >> > I have this regular expression >... > I try adding ".*" at the end , but it ends up just matching the second > one. If there can be more matches in a line, maybe the non-greedy quantifier ".*?", and a lookahead assertion can help. You can try something like: (?m)Render(?:Block|Table) (?:\(\w+\)|{\w+})(.+?(?=$|RenderBlock))? (?m) multiline flag - also the end of line can be matched with $ .+? any character - one or more (no greedy, i.e. as little as possible) (?=$|RenderBlock) the lookahead assertion - condition for the following string - not part of the match - here the end of line/string or "RenderBlock" I guess, if you need to add more possibilities or conditions depending on your source data, it might get too complex for a single regular expression to match effectively. hth vbr From higerinbeijing at gmail.com Fri Jun 12 04:55:48 2009 From: higerinbeijing at gmail.com (higer) Date: Fri, 12 Jun 2009 01:55:48 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP Message-ID: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Maybe everyone know that decompyle(hosted on SourceForge.net) is a tool to transfer a .pyc file to .py file and now it does only support Python 2.3 or the below. I have found a project named unpyc which can support Python version 2.5. Unpyc project is build on decompyle which is hosted on google code and if you want you can download it. I build unpyc on Ubuntu successfully and can run it ok. But with some purpose, I just want to use this tool on my WindowsXP, so I tried to build it. I have tried many times and methods, with .net2003 or MingGW, but I failed. So,I come here looking for sombody can help me.I will give the showing error message with different method on the following: 1 Using command : python setup.py install F:\unpyc>python setup.py install running install running build running build_py creating build\lib.win32-2.5 creating build\lib.win32-2.5\unpyc copying unpyc\dis_15.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_16.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_20.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_21.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_22.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_23.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_24.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_25.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_26.py -> build\lib.win32-2.5\unpyc copying unpyc\dis_files.py -> build\lib.win32-2.5\unpyc copying unpyc\magics.py -> build\lib.win32-2.5\unpyc copying unpyc\marshal_files.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_23.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_24.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_25.py -> build\lib.win32-2.5\unpyc copying unpyc\opcode_26.py -> build\lib.win32-2.5\unpyc copying unpyc\Parser.py -> build\lib.win32-2.5\unpyc copying unpyc\Scanner.py -> build\lib.win32-2.5\unpyc copying unpyc\spark.py -> build\lib.win32-2.5\unpyc copying unpyc\verify.py -> build\lib.win32-2.5\unpyc copying unpyc\Walker.py -> build\lib.win32-2.5\unpyc copying unpyc\__init__.py -> build\lib.win32-2.5\unpyc running build_ext building 'unpyc/marshal_25' extension creating build\temp.win32-2.5 creating build\temp.win32-2.5\Release creating build\temp.win32-2.5\Release\unpyc f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / nologo /Ox /MD /W3 /GX /DNDEBU G -IF:\Python25\include -IF:\Python25\PC /Tcunpyc/marshal_25.c /Fobuild \temp.win32-2.5\Release\unpyc /marshal_25.obj marshal_25.c unpyc\marshal_25.c(401) : warning C4273: 'PyMarshal_WriteLongToFile' : inconsistent dll linkage unpyc\marshal_25.c(413) : warning C4273: 'PyMarshal_WriteObjectToFile' : inconsistent dll linkage unpyc\marshal_25.c(1004) : warning C4273: 'PyMarshal_ReadShortFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1015) : warning C4273: 'PyMarshal_ReadLongFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1044) : warning C4273: 'PyMarshal_ReadLastObjectFromFile' : inconsistent dll link age unpyc\marshal_25.c(1087) : warning C4273: 'PyMarshal_ReadObjectFromFile' : inconsistent dll linkage unpyc\marshal_25.c(1101) : warning C4273: 'PyMarshal_ReadObjectFromString' : inconsistent dll linkag e unpyc\marshal_25.c(1116) : warning C4273: 'PyMarshal_WriteObjectToString' : inconsistent dll linkage f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe / DLL /nologo /INCREMENTAL:NO /LI BPATH:F:\Python25\libs /LIBPATH:F:\Python25\PCBuild /EXPORT:initunpyc/ marshal_25 build\temp.win32-2. 5\Release\unpyc/marshal_25.obj /OUT:build\lib.win32-2.5\unpyc/ marshal_25.pyd /IMPLIB:build\temp.win3 2-2.5\Release\unpyc\marshal_25.lib marshal_25.obj : error LNK2001: unresolved external symbol initunpyc/ marshal_25 build\temp.win32-2.5\Release\unpyc\marshal_25.lib : fatal error LNK1120: 1 unresolved externals LINK : fatal error LNK1141: failure during build of exports file error: command '"f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe"' failed with e xit status 1141 2 Using command: python setup.py build -c mingw32 F:\unpyc>python setup.py build -c mingw32 running build running build_py running build_ext building 'unpyc/marshal_25' extension F:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IF:\Python25\include - IF:\Python25\PC -c unpyc/mars hal_25.c -o build\temp.win32-2.5\Release\unpyc\marshal_25.o unpyc/marshal_25.c:1087: warning: 'PyMarshal_ReadObjectFromFile' defined locally after being referen ced with dllimport linkage unpyc/marshal_25.c:1101: warning: 'PyMarshal_ReadObjectFromString' defined locally after being refer enced with dllimport linkage writing build\temp.win32-2.5\Release\unpyc\marshal_25.def F:\mingw\bin\gcc.exe -mno-cygwin -shared -s build \temp.win32-2.5\Release\unpyc\marshal_25.o build\te mp.win32-2.5\Release\unpyc\marshal_25.def -LF:\Python25\libs -LF: \Python25\PCBuild -lpython25 -lmsvc r71 -o build\lib.win32-2.5\unpyc/marshal_25.pyd F:\Python25\libs/libpython25.a(dcbbs00336.o):(.text+0x0): multiple definition of `PyMarshal_ReadObje ctFromString' build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text +0x2958): first defined here F:\Python25\libs/libpython25.a(dcbbs00335.o):(.text+0x0): multiple definition of `PyMarshal_ReadObje ctFromFile' build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text +0x28fb): first defined here Cannot export initunpyc/marshal_25: symbol not defined collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 PS: necessary files has been added in proper path: Python25.dll is in windows/system32; python25.lib and libpython25.a is in Python25/libs; Appreciate that you can do me a favor.Thanks From prasoonthegreat at gmail.com Fri Jun 12 04:58:34 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Fri, 12 Jun 2009 01:58:34 -0700 (PDT) Subject: EOF problem with ENTER References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: > You could do: > > while True: > ? ?x = raw_input("Enter x=>") > ? ?if x != "" : break # if you just press enter, raw_input returns an > empty string > > Note that this still leaves out the case when you type something which > is not a number. > To cover this case, supposing that you need a float, you could do like > this (NOT TESTED): > > while True: > ? ?x_str = raw_input("Enter x=>") > ? ?if x_str != "" : # ?to prevent having the error message on empty > imput > ? ? ? try: > ? ? ? ? ?x = float(x_str) > ? ? ? ? ?break # if it gets here the conversion in float was succesful > ? ? ? except ValueError : > ? ? ? ? ?print "The input '%s' cannot be converted in float" % x_str > > This code exits from the loop only when you supply a string that > represents a floating number > I modified my code to #Euler Totient Function import sys from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): while True: t=raw_input() if t!="":break t=int(t) while(t): while True: x=raw_input() if x!="":break x=int(x) print str(etf(x)) t-=1 if __name__ == "__main__": main() Now it is working fine ....thanks!!! From steve at REMOVETHIS.cybersource.com.au Fri Jun 12 05:07:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 12 Jun 2009 19:07:19 +1000 Subject: Exception inside loop wrongly failing doctest Message-ID: <02420d02$0$20639$c3e8da3@news.astraweb.com> One of my doctests is failing, and I suspect a bug. The test involves matching an exception in a for-loop. Here are two simplified versions of the test, both should pass but only the first does. As a doctest, this passes: >>> for x in [3, 2, 1]: ... print (x, 1.0/x) ... (3, 0.33333333333333331) (2, 0.5) (1, 1.0) However, this fails: >>> for x in [3, 2, 1, 0]: ... print (x, 1.0/x) ... (3, 0.33333333333333331) (2, 0.5) (1, 1.0) Traceback (most recent call last): ... ZeroDivisionError: float division Attached is a simple test script which runs doctest.testmod(). Both tests should pass, with no output printing. However, it does this: $ python doctest_error.py ********************************************************************** File "doctest_error.py", line 14, in __main__ Failed example: for x in [3, 2, 1, 0]: print (x, 1.0/x) Exception raised: Traceback (most recent call last): File "/usr/lib/python2.5/doctest.py", line 1212, in __run compileflags, 1) in test.globs File "", line 2, in print (x, 1.0/x) ZeroDivisionError: float division ********************************************************************** 1 items had failures: 1 of 2 in __main__ ***Test Failed*** 1 failures. I've tested this in Python 2.4, 2.5 and 2.6 and get the same result for all three. Have I missed something, or should I report this as a bug? -- Steven -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: doctest_error.py URL: From lie.1296 at gmail.com Fri Jun 12 05:13:50 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 09:13:50 GMT Subject: Exception inside loop wrongly failing doctest In-Reply-To: <02420d02$0$20639$c3e8da3@news.astraweb.com> References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > One of my doctests is failing, and I suspect a bug. > > The test involves matching an exception in a for-loop. Here are two > simplified versions of the test, both should pass but only the first does. > tell me, what's the result of 1/0? From lie.1296 at gmail.com Fri Jun 12 05:45:11 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 09:45:11 GMT Subject: Exception inside loop wrongly failing doctest In-Reply-To: References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: Lie Ryan wrote: > Steven D'Aprano wrote: >> One of my doctests is failing, and I suspect a bug. >> >> The test involves matching an exception in a for-loop. Here are two >> simplified versions of the test, both should pass but only the first does. >> > > tell me, what's the result of 1/0? Whooopss.. replied too fast... This seems to work: >>> for i in [3, 2, 1, 0]: ... print (i, 1.0/i) ... Traceback (most recent call last): ... ZeroDivisionError: float division it seems that if the expected result is a traceback, the doc result must starts with the traceback keyword: """ The expected output for an exception must *start* with a traceback header, which may be either of the following two lines, indented the same as the first line of the example: Traceback (most recent call last): Traceback (innermost last): """ (emphasizes added) From Simon212 at gmx.de Fri Jun 12 05:54:55 2009 From: Simon212 at gmx.de (Simon212 at gmx.de) Date: Fri, 12 Jun 2009 11:54:55 +0200 Subject: install older Python version parallel In-Reply-To: References: <4A31199E.7030809@gmx.net> Message-ID: <20090612095455.20140@gmx.net> > > Hi everybody, > > > > The situation: > > I wrote a GUI, based on Python, TkInter and Pmw. > > It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are > > installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 > > and various Linux Distributions. > > Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug > > > in the installed blt package), also when I use setitems on > > Pmw.OptionMenu (I guess this is due to another package, associated with > > tcl/tk). > > You might get more helpful responses if you say more than just "it > crashes". > What's the traceback? > Thanks for the suggestion. 1. Here is what it says when I try to use setitems on a Pmw.OptionMenu to refresh its contents: com.read_config_file ./.mWIN/profiles/last.profile Traceback (most recent call last): File "./startMW.py", line 1323, in frontEnd = FrontEnd(root) File "./startMW.py", line 854, in __init__ self.loadProfile() File "./startMW.py", line 1216, in loadProfile self.profileList.setitems(self.com.profile_names) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Pmw/Pmw_1_3/lib/PmwOptionMenu.py", line 67, in setitems self._menu.delete(0, 'end') File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 2675, in delete self.deletecommand(c) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 358, in deletecommand self.tk.deletecommand(name) _tkinter.TclError: can't delete Tcl command 2. In case of the activation of a Pmw.Diaog it just gives me a segmentation vault. -- GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und Telefonanschluss f?r nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02 From vs at it.uu.se Fri Jun 12 05:55:14 2009 From: vs at it.uu.se (Virgil Stokes) Date: Fri, 12 Jun 2009 11:55:14 +0200 Subject: matplotlib installation Message-ID: <4A322602.7090302@it.uu.se> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows Vista platform? --V From steve at REMOVETHIS.cybersource.com.au Fri Jun 12 06:45:41 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 12 Jun 2009 20:45:41 +1000 Subject: Exception inside loop wrongly failing doctest References: <02420d02$0$20639$c3e8da3@news.astraweb.com> Message-ID: <0242240f$0$21875$c3e8da3@news.astraweb.com> Lie Ryan wrote: > Lie Ryan wrote: >> Steven D'Aprano wrote: >>> One of my doctests is failing, and I suspect a bug. ... > it seems that if the expected result is a traceback, the doc result must > starts with the traceback keyword: Ah, that would be it. Not a bug then, a limitation of the doctest module. Thanks, -- Steven From gnewsg at gmail.com Fri Jun 12 06:47:53 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 12 Jun 2009 03:47:53 -0700 (PDT) Subject: command line of a process.exe on another host References: Message-ID: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> On 12 Giu, 00:18, "Harry" wrote: > HI , > I have number of process run on different windows servers which run's with > different command line parameters. for example "process.exe -input > statusurl:http://sss.com"., These parameters can vary from host to host. > using Psexec I know the PID and process name which are running on these > machines, but how I can read the command line parameters of these process. > Is there a way to read these command line of the proess via python pls? > > any feedback appreciated.. > > thanks > Hari You can easily do this with psutil [1]: >>> import psutil, os >>> p = psutil.Process(os.getpid()) >>> p.cmdline ['/usr/bin/python2.4'] >>> Since psutil uses the native Windows calls to retrieve such kind of info it's a lot faster than using any WMI-based solution. [1] http://code.google.com/p/psutil/ --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From mail at timgolden.me.uk Fri Jun 12 07:02:52 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Jun 2009 12:02:52 +0100 Subject: command line of a process.exe on another host In-Reply-To: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> References: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> Message-ID: <4A3235DC.2070504@timgolden.me.uk> Giampaolo Rodola' wrote: > On 12 Giu, 00:18, "Harry" wrote: >> HI , >> I have number of process run on different windows servers which run's with >> different command line parameters. > You can easily do this with psutil [1]: > Since psutil uses the native Windows calls to retrieve such kind of > info it's a lot faster than using any WMI-based solution. Looks great (and it's certainly fast). Can you pick up processes on a different server? The docs don't seem to say so. Did I miss something? (It's not clear that the OP actually wants that altho' I read it that way). TJG From alan.isaac at gmail.com Fri Jun 12 07:33:36 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 12 Jun 2009 11:33:36 GMT Subject: matplotlib installation In-Reply-To: References: Message-ID: On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: > Any suggestions on installing matplotlib for Python 2.6.2 on a Windows > Vista platform? Maintainers for some packages have run into a wall compiling for 2.6. Matplotlib is one of these: http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html Another package I care about is SimpleParse, which also found compiling for 2.6 to be impossible. I do not know if this was the same problem or not, but it means that SimpleParse is *still* not available as an installer for 2.6. I assume this is of great concern to the Python community, but I do not know where the discussion is taking place. Alan Isaac From khemeia at gmail.com Fri Jun 12 07:51:42 2009 From: khemeia at gmail.com (khemeia at gmail.com) Date: Fri, 12 Jun 2009 04:51:42 -0700 (PDT) Subject: trying to understand dictionaries Message-ID: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Hi. As the subject says, I'm a newbie trying to learn python and now dictionaries. I can create a dict, understand it and use it for simple tasks. But the thing is that I don't really get the point on how to use these in real life programing. For example I tryed to create a very simple phonebook code: d = {'fname': [], 'ename': []} name1 = 'ricky' name2 = 'martin' d['fname'].append(name1) d['ename'].append(name2) name1 = 'britney' name2 = 'spears' d['fname'].append(name1) d['ename'].append(name2) This gives me: {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} I wonder if this is a correct usage and thinking about dictioaries in python. Everything in my example is based on a serval lists in a dictionary, and person 1 is == ename[0] & fname[0] and person 2 is == ename[1] & fname[1], it's based on position and indexing. Is this correct if no, how would you do it? if yes, how can I print the result out in a nice way? I need a for- loop that prints: all [0] in all lists all [0] in all lists and so on. thanks /jonas From anthra.norell at bluewin.ch Fri Jun 12 07:56:38 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 12 Jun 2009 13:56:38 +0200 Subject: CAD file format specifications? Message-ID: <4A324276.80804@bluewin.ch> Hi, Anyone working with CAD who knows about numeric data entry? I have 3d coordinates of a construction site on a slope (borders, setbacks and isometric elevation lines). Someone made me aware of Google's Sketch Up. It looks very attractive for the purpose of architectural planning, especially suited to create visual impressions. Doodling seems easy. But I have to start with modeling the terrain and the envelope and the only way to do that seems to be in one of several CAD file formats (skp, dwg, dxf, 3ds, ddf and dem). So I need to cast my numbers into one of these formats. Any suggestions? Thanks Frederic From jeanmichel at sequans.com Fri Jun 12 08:01:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:01:14 +0200 Subject: Need help in Python regular expression In-Reply-To: <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> <450f0e19-d333-4094-acdb-55d2d8944467@r10g2000yqa.googlegroups.com> Message-ID: <4A32438A.5070003@sequans.com> To the OP, I suggest if you haven't yet Kodos, to get it here http://kodos.sourceforge.net/. It's a python regexp debugger, a lifetime saver. Jean-Michel John S wrote: > On Jun 11, 10:30 pm, meryl wrote: > >> Hi, >> >> I have this regular expression >> blockRE = re.compile(".*RenderBlock {\w+}") >> >> it works if my source is "RenderBlock {CENTER}". >> >> But I want it to work with >> 1. RenderTable {TABLE} >> >> So i change the regexp to re.compile(".*Render[Block|Table] {\w+}"), >> but that breaks everything >> >> 2. RenderBlock (CENTER) >> >> So I change the regexp to re.compile(".*RenderBlock {|\(\w+}|\)"), >> that also breaks everything >> >> Can you please tell me how to change my reg exp so that I can support >> all 3 cases: >> RenderTable {TABLE} >> RenderBlock (CENTER) >> RenderBlock {CENTER} >> >> Thank you. >> > > Short answer: > > r = re.compile(r"Render(?:Block|Table)\s+[({](?:TABLE|CENTER)[})]") > > s = """ > blah blah blah > blah blah blah RenderBlock {CENTER} blah blah RenderBlock {CENTER} > blah blah blah RenderTable {TABLE} blah blah RenderBlock (CENTER) > blah blah blah > """ > > print r.findall(s) > > > > output: > ['RenderBlock {CENTER}', 'RenderBlock {CENTER}', 'RenderTable > {TABLE}', 'RenderBlock (CENTER)'] > > > > Note that [] only encloses characters, not strings; [foo|bar] matches > 'f','o','|','b','a', or 'r', not "foo" or "bar". > Use (foo|bar) to match "foo" or "bar"; (?xxx) matches xxx without > making a backreference (i.e., without capturing text). > > HTH > > -- John Strickler > From jeanmichel at sequans.com Fri Jun 12 08:25:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:25:37 +0200 Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: <4A324941.4010408@sequans.com> Basically, dictionaries are a bunch of couples of key and value where key is an immutable object. In fact you'll find a more accurate definition in any python book or online tutorial. The thing is that keys are usually used as an easy and quick way the search and index items. You can see dict as a list that can use strings instead of integers to index its values. phonebook = { 'ricky' : ('ricky', 'martin', 'male'), 'britney' : ('britney', 'spears', 'female'), 'myBestBuddy' : ('barack', 'obama', 'male'), 42 : ('bob', 'bib', 'male'), # you can use 42 as index, like strings integers are not mutable True: ('', '', ''), # meaningless example just to show that any immutable object will fit as index } fname, ename, gender = phonebook['myBestBuddy'] fname, ename, gender = phonebook[42] Keys are unique among the dictionary. Jean-Michel khemeia at gmail.com wrote: > Hi. > As the subject says, I'm a newbie trying to learn python and now > dictionaries. I can create a dict, understand it and use it for simple > tasks. But the thing is that I don't really get the point on how to > use these in real life programing. > > For example I tryed to create a very simple phonebook > > code: > > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} > > I wonder if this is a correct usage and thinking about dictioaries in > python. > Everything in my example is based on a serval lists in a dictionary, > and person 1 is == ename[0] & fname[0] > and person 2 is == ename[1] & fname[1], it's based on position and > indexing. > > Is this correct if no, how would you do it? > if yes, how can I print the result out in a nice way? I need a for- > loop that prints: > all [0] in all lists > all [0] in all lists and so on. > > > thanks > /jonas > > From alan.isaac at gmail.com Fri Jun 12 08:32:57 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Fri, 12 Jun 2009 12:32:57 GMT Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: On 6/12/2009 7:51 AM khemeia at gmail.com apparently wrote: > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} Trying to stick close to your example, reverse the use of lists and dicts. worst_musicians = list() entry = dict(fname='ricky',lname='martin') worst_musicians.append(entry) entry = dict(fname='britney',lname='spears') worst_musicians.append(entry) for musician in worst_musicians: print "%(fname)s %(lname)s"%musician hth, Alan Isaac From marduk at letterboxes.org Fri Jun 12 08:34:57 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Fri, 12 Jun 2009 08:34:57 -0400 Subject: trying to understand dictionaries In-Reply-To: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> References: <6ba8e4cb-78df-479a-afd0-93d31ef88d75@y17g2000yqn.googlegroups.com> Message-ID: <1244810097.10675.7.camel@blackwidow.nbk> On Fri, 2009-06-12 at 04:51 -0700, khemeia at gmail.com wrote: > Hi. > As the subject says, I'm a newbie trying to learn python and now > dictionaries. I can create a dict, understand it and use it for simple > tasks. But the thing is that I don't really get the point on how to > use these in real life programing. > > For example I tryed to create a very simple phonebook > > code: > > d = {'fname': [], 'ename': []} > name1 = 'ricky' > name2 = 'martin' > d['fname'].append(name1) > d['ename'].append(name2) > > name1 = 'britney' > name2 = 'spears' > d['fname'].append(name1) > d['ename'].append(name2) > > > This gives me: > {'ename': ['martin', 'spears'], 'fname': ['ricky', 'britney']} > > I wonder if this is a correct usage and thinking about dictioaries in > python. > Everything in my example is based on a serval lists in a dictionary, > and person 1 is == ename[0] & fname[0] > and person 2 is == ename[1] & fname[1], it's based on position and > indexing. > > Is this correct if no, how would you do it? > if yes, how can I print the result out in a nice way? I need a for- > loop that prints: > all [0] in all lists > all [0] in all lists and so on. That's probably not the data model I'd use for a phone book. The following isn't either, but is better: d = dict() d[('martin', 'ricky')] = '555-1212' d[('spears', 'britney')] = '555-1213' for last, first in d: phone_number = d[(last, first)] print ... From mblume at socha.net Fri Jun 12 08:36:47 2009 From: mblume at socha.net (mblume) Date: 12 Jun 2009 12:36:47 GMT Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <4a324bdf$0$9117$5402220f@news.sunrise.ch> Am Thu, 11 Jun 2009 20:56:24 -0700 schrieb lucius: > I am trying to > print some values to a file (using c's printf like method). TypeError: > int argument required > # this works, i see value on screen > print w, h, absX, absY > Are you sure that w or h are not returned as strings? Hint: try this in an interpreter: w="100" print "%d" % (w) > > # this fails, I get "TypeError: int argument required" > print >> fo, " style=\"fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke- > opacity:0.9\"/> " % (absX, absY, w, h) > You could simplify such as an expression by writing: print 'x="%f"' % (x) HTH Martin From jeanmichel at sequans.com Fri Jun 12 08:39:04 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 14:39:04 +0200 Subject: EOF problem with ENTER In-Reply-To: References: <1b1ed3a9-03c4-4fb9-9771-9003d3ee3b14@w31g2000prd.googlegroups.com> <0e17eb53-3827-402d-b071-17aca2752bed@k17g2000prn.googlegroups.com> Message-ID: <4A324C68.1010905@sequans.com> Prasoon wrote: > I modified my code to > > #Euler Totient Function > import sys > from math import sqrt > def etf(n): > i,res =2,n > while(i*i<=n): > if(n%i==0): > res-=res/i > while(n%i==0): > n/=i > i+=1 > if(n>1): > res-=res/n > return res > > def main(): > while True: > t=raw_input() > if t!="":break > t=int(t) > while(t): > while True: > x=raw_input() > if x!="":break > x=int(x) > print str(etf(x)) > t-=1 > > if __name__ == "__main__": > main() > > Now it is working fine ....thanks!!! > Hello Prasoon, there's still a major issue with your code, check out http://tottinge.blogsome.com/meaningfulnames/ If your code is a private script targeted at your personal use, well I guess you can just ignore my comment. But I'm still impressed by how some of the python-list users have dived into your code with such ease. Regards, Jean-Michel From exarkun at divmod.com Fri Jun 12 08:50:21 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 12 Jun 2009 08:50:21 -0400 Subject: matplotlib installation In-Reply-To: Message-ID: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >> Vista platform? > > >Maintainers for some packages have run into a wall >compiling for 2.6. Matplotlib is one of these: >http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html > >Another package I care about is SimpleParse, which also >found compiling for 2.6 to be impossible. I do not know >if this was the same problem or not, but it means that >SimpleParse is *still* not available as an installer for 2.6. > >I assume this is of great concern to the Python community, >but I do not know where the discussion is taking place. Some discussion has occurred in the issue tracker: http://bugs.python.org/issue3308 http://bugs.python.org/issue6007 In general, the people responsible for how CPython builds on Windows don't seem to consider this an issue. Jean-Paul From lie.1296 at gmail.com Fri Jun 12 09:02:03 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 12 Jun 2009 13:02:03 GMT Subject: RE replace problem too In-Reply-To: References: Message-ID: oyster wrote: > in my case, I want to replace all the function name with '', that is > sin(1) -> (1) > sin(pi*(2+4)) -> (pi*(2+4)) > how can I use RE in this situation? thanx this works if there is no implicit multiplication: re.sub('\w+\(', '(', 'sin(pi*(2+4))') this one might be more robust: re.sub('[a-zA-Z]\w*\s*\(', '(', 'sin(pi*cos(2+4))') From gnewsg at gmail.com Fri Jun 12 09:03:53 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Fri, 12 Jun 2009 06:03:53 -0700 (PDT) Subject: command line of a process.exe on another host References: <86368584-af82-4591-9b0c-689295f1481a@w3g2000yqf.googlegroups.com> Message-ID: On 12 Giu, 13:02, Tim Golden wrote: > Giampaolo Rodola' wrote: > > On 12 Giu, 00:18, "Harry" wrote: > >> HI , > >> I have number of process run on different windows servers which run's with > >> different command line parameters. > > You can easily do this with psutil [1]: > > Since psutil uses the native Windows calls to retrieve such kind of > > info it's a lot faster than using any WMI-based solution. > > Looks great (and it's certainly fast). Can you pick up processes > on a different server? The docs don't seem to say so. Did I miss > something? (It's not clear that the OP actually wants that altho' > I read it that way). > > TJG Sorry, I didn't notice the OP meant to retrieve information from a remote machine. And no, psutil can't do anything like that. --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From simon212 at gmx.de Fri Jun 12 09:31:14 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 15:31:14 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: Message-ID: <4A3258A2.1040204@gmx.de> edexter wrote: > simon wrote: >> Hi everybody, >> >> The situation: >> I wrote a GUI, based on Python, TkInter and Pmw. >> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >> and various Linux Distributions. >> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >> in the installed blt package), also when I use setitems on >> Pmw.OptionMenu (I guess this is due to another package, associated with >> tcl/tk). >> >> The target: >> I have to get my GUI work under openSUSE 11.1 (x86_64). >> >> My plan: >> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >> I would like to know, how to install Python 2.4 along with TkInter and >> Pmw (and packages that are required by them), parallel to the existing >> Python 2.6. So that I do not break other software that depends on Python >> 2.6. >> >> If you can think of another plan, I would be also glad to discuss it. >> >> Cheers, >> Simon > > I suspect you want to install python 2.4 and then reinstall 2.6 I did > that in windows and I don't understand why it wouldn't work in linux I'm afraid, installation is quit different under UNIX based systems and Windows. I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within openSUSE 11.1 x86_64) via 'make altinstall'. First, I tried to configure with the following flags: --prefix=/opt/python-24 --enable-framework --with-pydebug This provoked an error during compilation via make (sorry, the list was so long, but I will post it, if it helps). Second, configured again without any flags. The installation by 'make altinstall' to /usr/local was a success. Python2.6 seams unaffected, too. So, I got my parallel installation. However, I cannot import modules like Tkinter or readline within python2.4. For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk sys.path says: ['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages'] sys.prefix and sys.exec_prefix say: '/usr/local' my bash's PATH variable says: /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin Which configuration step did I miss after my Python2.4 installation? What did I do wrong? Cheers, Simon From tim.wintle at teamrubber.com Fri Jun 12 09:32:03 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Jun 2009 14:32:03 +0100 Subject: command line of a process.exe on another host In-Reply-To: References: Message-ID: <1244813523.3718.153.camel@tim-laptop> On Thu, 2009-06-11 at 23:18 +0100, Harry wrote: > HI , > I have number of process run on different windows servers which run's with > different command line parameters. for example "process.exe -input > statusurl: http://sss.com "., These parameters can vary from host to host. > using Psexec I know the PID and process name which are running on these > machines, but how I can read the command line parameters of these process. > Is there a way to read these command line of the proess via python pls? I'm not sure how well this will work, but it might be worth looking at fabric - which lets you run through ssh onto lots of different machines (so I assume you'll need openssh on those machines) http://docs.fabfile.org/ Haven't used it myself, but I keep meaning to. > > any feedback appreciated.. > > thanks > Hari > From tim.wintle at teamrubber.com Fri Jun 12 09:40:52 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Jun 2009 14:40:52 +0100 Subject: install older Python version parallel In-Reply-To: References: Message-ID: <1244814052.3718.158.camel@tim-laptop> On Fri, 2009-06-12 at 00:30 -0700, edexter wrote: > I suspect you want to install python 2.4 and then reinstall 2.6 I did > that in windows and I don't understand why it wouldn't work in linux It won't normally work on linux these days because most distributions of gnu/linux need python to run the GUI. Put another way it means if something doesn't work how you want it, it's just some python somewhere to change :-) (Trust me, you don't want to remove the system version of python on most linux distributions or on macs) Tim From cournape at gmail.com Fri Jun 12 09:54:14 2009 From: cournape at gmail.com (David Cournapeau) Date: Fri, 12 Jun 2009 22:54:14 +0900 Subject: matplotlib installation In-Reply-To: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: <5b8d13220906120654t41e0f33alb80f690be3df12cb@mail.gmail.com> On Fri, Jun 12, 2009 at 9:50 PM, Jean-Paul Calderone wrote: > On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >> >> On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >>> >>> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >>> Vista platform? >> >> >> Maintainers for some packages have run into a wall >> compiling for 2.6. ?Matplotlib is one of these: >> >> http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html >> >> Another package I care about is SimpleParse, which also >> found compiling for 2.6 to be impossible. ?I do not know >> if this was the same problem or not, but it means that >> SimpleParse is *still* not available as an installer for 2.6. >> >> I assume this is of great concern to the Python community, >> but I do not know where the discussion is taking place. > > Some discussion has occurred in the issue tracker: > > ?http://bugs.python.org/issue3308 > ?http://bugs.python.org/issue6007 > > In general, the people responsible for how CPython builds on Windows > don't seem to consider this an issue. We got the same problem with numpy. The good news is it is solvable (at least partially). http://projects.scipy.org/numpy/browser/trunk/numpy/random/mtrand/randomkit.c Basically, there are some functions which are erroneously "declared" in the .lib, but they don't actually exist in the MS C runtime. We detect when the .C code is built under mingw, and add an hack to redirect the function to the "real" function, _ftime64 (see around line 75). cheers, David From aotto1968 at t-online.de Fri Jun 12 09:54:45 2009 From: aotto1968 at t-online.de (Andreas Otto) Date: Fri, 12 Jun 2009 15:54:45 +0200 Subject: ANNOUNCE: libmsgque 3.3 Message-ID: ANNOUNCE a majorfeature improvement of libmsgque ... What is LibMsgque ================= LibMsgque is an OS independent, Programming Language independent and Hardware independent solution to link applications together to act like a single application. Or with other words, LibMsgque is an Application-Server toolkit. Highlights of the current Release: ================================= This release introduce the C# port and the long waiting "managed" code interface to "libmsgque". This interface allow writing language-bindings to libmsgque without using an addition C library as "translator" between the native language and "libmsgque". The skip of this "translation" library introduce a new performance leader using C# together with the "mono" tools and outperform JAVA, TCL, PYTHON. On windows the "mono" tool and the "microsoft" native C# is supported. The performance-comparison between "c", "tcl", "python", "C#" and "java" was updated: -> results: http://libmsgque.sourceforge.net/performance.htm The Web-Site was updated: ========================= -> http://libmsgque.sourceforge.net For a fast introduction use the following URL: -> http://libmsgque.sourceforge.net/features.htm mfg Andreas Otto From paul.lafollette at gmail.com Fri Jun 12 10:05:29 2009 From: paul.lafollette at gmail.com (Paul LaFollette) Date: Fri, 12 Jun 2009 10:05:29 -0400 Subject: Question about None Message-ID: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Kind people, Using Python 3.0 on a Gatesware machine (XP). I am building a class in which I want to constrain the types that can be stored in various instance variables. For instance, I want to be certain that self.loc contains an int. This is straightforward (as long as I maintain the discipline of changing loc through a method rather than just twiddling it directly. def setLoc(lo): assert isinstance(lo, int), "loc must be an int" self.loc = lo does the trick nicely. However, I also want to constrain self.next to be either an instance of class Node, or None. I would think that the following should work but it doesn't. def setNext(nxt): assert isinstance(nxt, (Node, NoneType)), "next must be a Node" self.next = nxt since type(Node) responds with but the assertion above gives "name 'NoneType' is not defined" suggesting that NoneType is some sort of quasi-class. def setNext(nxt): assert nxt==None or isinstance(nxt, Node), "next must be a Node" self.next = nxt works ok, but it's uglier than it ought to be. So, I have three questions. 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? 2) is their a less ugly alternative that what I am using? 3) (this is purely philosophical but I am curious) Would it not be more intuitive if isinstance(None, ) returned true? Thank you for your kind attention. Paul From javier.collado at gmail.com Fri Jun 12 10:22:05 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Jun 2009 16:22:05 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Hello, This should work for you: In [1]: import types In [2]: isinstance(None, types.NoneType) Out[2]: True Best regards, Javier 2009/6/12 Paul LaFollette : > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. ?For instance, I want to be > certain that self.loc contains an int. ?This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > ?def setLoc(lo): > ? ?assert isinstance(lo, int), "loc must be an int" > ? ?self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. ?I would think that the following should work > but it doesn't. > > ?def setNext(nxt): > ? ?assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > ? ?self.next = nxt > > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. > > ?def setNext(nxt): > ? ?assert nxt==None or isinstance(nxt, Node), "next must be a Node" > ? ?self.next = nxt > > works ok, but it's uglier than it ought to be. > > So, I have three questions. > > 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? > 2) is their a less ugly alternative that what I am using? > 3) (this is purely philosophical but I am curious) ?Would it not be > more intuitive if > isinstance(None, ) returned true? > > Thank you for your kind attention. > Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From simon212 at gmx.de Fri Jun 12 10:24:49 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 16:24:49 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: <4A326531.50502@gmx.de> Simon wrote: > edexter wrote: >> simon wrote: >>> Hi everybody, >>> >>> The situation: >>> I wrote a GUI, based on Python, TkInter and Pmw. >>> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >>> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >>> and various Linux Distributions. >>> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >>> in the installed blt package), also when I use setitems on >>> Pmw.OptionMenu (I guess this is due to another package, associated with >>> tcl/tk). >>> >>> The target: >>> I have to get my GUI work under openSUSE 11.1 (x86_64). >>> >>> My plan: >>> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >>> I would like to know, how to install Python 2.4 along with TkInter and >>> Pmw (and packages that are required by them), parallel to the existing >>> Python 2.6. So that I do not break other software that depends on Python >>> 2.6. >>> >>> If you can think of another plan, I would be also glad to discuss it. >>> >>> Cheers, >>> Simon >> >> I suspect you want to install python 2.4 and then reinstall 2.6 I did >> that in windows and I don't understand why it wouldn't work in linux > > I'm afraid, installation is quit different under UNIX based systems and > Windows. > > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was > so long, but I will post it, if it helps). > > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, > too. So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', > '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > > Which configuration step did I miss after my Python2.4 installation? > What did I do wrong? > > Cheers, > Simon OK, I found an 'Ansatzpunkt' where I can start from: _tkinter.so is missing in /usr/local/lib/python2.4/lib-dynload so I guess my python is not configured for using Tcl? I found the following from http://mail.python.org/pipermail/python-list/2001-December/117984.html Install Tcl, Tk and Python as peers of each other ... 1. run configure in Python 2. make and make install Tcl (unless you're using binary dist)make and 3. make install Tk (unless you're using binary dist) 4. edit Setup 5. make and make install Python I guess, I will try that next. Maybe somebody knows a more detailed instruction. My problems: a) I don't know if I have to set special flags to make the three packages aware of each other during 'configure', 'make', and 'make altinstall'. b) Also, I don't know, which setup do I have to edit during step 4. c) Which Tcl and Tk versions do I need, don't I need tcl-devel in addition? Sorry for so many questions, but this stuff is new for me, Simon From lists at cheimes.de Fri Jun 12 10:32:27 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Jun 2009 16:32:27 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Paul LaFollette schrieb: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > def setLoc(lo): > assert isinstance(lo, int), "loc must be an int" > self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. I would think that the following should work > but it doesn't. > > def setNext(nxt): > assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > self.next = nxt How about the canonical way to check if an object is None? assert Node is None None is a singleton. Python guarantees that there is exactly one None object and on this account only one instance of NoneType. In Python 3.x you can't even overwrite the global variable None. User code shouldn't use NoneType at all. >>> type(None) >>> type(None)() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> None = 1 File "", line 1 SyntaxError: assignment to keyword The singletons True and False have a similar behavior. It's not possible to overwrite them as well. The bool type always returns either the singleton True or the singleton False. >>> True = False File "", line 1 SyntaxError: assignment to keyword >>> type(True) >>> type(True) is bool True >>> bool(42) True From exarkun at divmod.com Fri Jun 12 10:44:19 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 12 Jun 2009 10:44:19 -0400 Subject: matplotlib installation In-Reply-To: <5b8d13220906120654t41e0f33alb80f690be3df12cb@mail.gmail.com> Message-ID: <20090612144419.22176.1455202359.divmod.quotient.4784@henry.divmod.com> On Fri, 12 Jun 2009 22:54:14 +0900, David Cournapeau wrote: >On Fri, Jun 12, 2009 at 9:50 PM, Jean-Paul Calderone wrote: >> On Fri, 12 Jun 2009 11:33:36 GMT, Alan G Isaac wrote: >>> >>> On 6/12/2009 5:55 AM Virgil Stokes apparently wrote: >>>> >>>> Any suggestions on installing matplotlib for Python 2.6.2 on a Windows >>>> Vista platform? >>> >>> >>> Maintainers for some packages have run into a wall >>> compiling for 2.6. ?Matplotlib is one of these: >>> >>> http://www.nabble.com/binary-installers-for-python2.6--libpng-segfault%2C-MSVCR90.DLL-and-%09mingw-td23971661.html >>> >>> Another package I care about is SimpleParse, which also >>> found compiling for 2.6 to be impossible. ?I do not know >>> if this was the same problem or not, but it means that >>> SimpleParse is *still* not available as an installer for 2.6. >>> >>> I assume this is of great concern to the Python community, >>> but I do not know where the discussion is taking place. >> >> Some discussion has occurred in the issue tracker: >> >> ?http://bugs.python.org/issue3308 >> ?http://bugs.python.org/issue6007 >> >> In general, the people responsible for how CPython builds on Windows >> don't seem to consider this an issue. > >We got the same problem with numpy. The good news is it is solvable >(at least partially). > >http://projects.scipy.org/numpy/browser/trunk/numpy/random/mtrand/randomkit.c > >Basically, there are some functions which are erroneously "declared" >in the .lib, but they don't actually exist in the MS C runtime. We >detect when the .C code is built under mingw, and add an hack to >redirect the function to the "real" function, _ftime64 (see around >line 75). Thanks for pointing out one possible workaround. I don't think this is always applicable, though. For example, pyOpenSSL can't be built for Python 2.6 because OpenSSL uses localtime, another function with a similar problem as the one with ftime. To redirect its usage, OpenSSL itself needs to be changed and then distributed along with pyOpenSSL. Jean-Paul From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 12 10:45:28 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Jun 2009 16:45:28 +0200 Subject: Question about None In-Reply-To: References: Message-ID: <4a3269ef$0$23850$426a74cc@news.free.fr> Paul LaFollette a ?crit : > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. This somehow goes against the whole philosophy of dynamic typing Python is based upon... But there are indeed cases where it makes sense and I assume you know what you're doing !-) > For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > def setLoc(lo): > assert isinstance(lo, int), "loc must be an int" > self.loc = lo > > does the trick nicely. Did you considered using properties (or custom descriptors) instead ? (snip - others already answered) From lists at cheimes.de Fri Jun 12 10:49:04 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Jun 2009 16:49:04 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: Simon wrote: > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was > so long, but I will post it, if it helps). --enable-framework is for Mac OS X only. > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, > too. So, I got my parallel installation. You have chosen the correct and canonical way to install a parallel installation of Python. > However, I cannot import modules like Tkinter or readline within python2.4. You must install the development library of tk, readline, zlib and libbz2 prior to configure && make. Try this on your box: zypper install gcc make autoconf automake libtool zlib-devel readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel libopenssl-devel From jeff at jmcneil.net Fri Jun 12 10:55:41 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Fri, 12 Jun 2009 07:55:41 -0700 (PDT) Subject: Question about None References: Message-ID: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> On Jun 12, 10:05?am, Paul LaFollette wrote: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. ?For instance, I want to be > certain that self.loc contains an int. ?This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. > > ? def setLoc(lo): > ? ? assert isinstance(lo, int), "loc must be an int" > ? ? self.loc = lo > > does the trick nicely. > > However, I also want to constrain self.next to be either an instance > of class Node, or None. ?I would think that the following should work > but it doesn't. > > ? def setNext(nxt): > ? ? assert isinstance(nxt, (Node, NoneType)), "next must be a Node" > ? ? self.next = nxt > > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. > > ? def setNext(nxt): > ? ? assert nxt==None or isinstance(nxt, Node), "next must be a Node" > ? ? self.next = nxt > > works ok, but it's uglier than it ought to be. > > So, I have three questions. > > 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? > 2) is their a less ugly alternative that what I am using? > 3) (this is purely philosophical but I am curious) ?Would it not be > more intuitive if > isinstance(None, ) returned true? > > Thank you for your kind attention. > Paul 1. The problem is described clearly by that Exception. The 'NoneType' name isn't bound to any objects at that current scope. I know that with 2.6, you can import 'types.NoneType' but I don't believe the 3.0 types module includes NoneType. Someone else will have to clarify that as I don't have 3.0 installed. 2. A less ugly alternative? You could use the accepted method of testing against None: if var is None: do_stuff() The use of the 'is' operator checks whether objects are exactly the same (id(var) == id(None)) as opposed to 'isinstance' or '==.' You might also try defining descriptors in order to make your type checks slightly more transparent. That might be confusing to other users of your class, though. Not many people expect a TypeError from an attribute assignment. 3. None is an instance of NoneType. Why should isinstance return True when it's tested against other types? HTH, Jeff mcjeff.blogspot.com From benjamin.kaplan at case.edu Fri Jun 12 11:07:13 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 12 Jun 2009 11:07:13 -0400 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A3258A2.1040204@gmx.de> References: <4A3258A2.1040204@gmx.de> Message-ID: On Fri, Jun 12, 2009 at 9:31 AM, Simon wrote: > edexter wrote: > >> simon wrote: >> >>> Hi everybody, >>> >>> The situation: >>> I wrote a GUI, based on Python, TkInter and Pmw. >>> It runs perfectly fine with Python 2.4 (providing, TkInter and Pmw are >>> installed). But it crashes with Python 2.6. I tried this on MacOSX11.4 >>> and various Linux Distributions. >>> Crashes occurs when I activate a Pmw.Diaog (I guess this is due to a bug >>> in the installed blt package), also when I use setitems on >>> Pmw.OptionMenu (I guess this is due to another package, associated with >>> tcl/tk). >>> >>> The target: >>> I have to get my GUI work under openSUSE 11.1 (x86_64). >>> >>> My plan: >>> On my openSUSE 11.1 (x86_64), Python 2.6 is installed by default. >>> I would like to know, how to install Python 2.4 along with TkInter and >>> Pmw (and packages that are required by them), parallel to the existing >>> Python 2.6. So that I do not break other software that depends on Python >>> 2.6. >>> >>> If you can think of another plan, I would be also glad to discuss it. >>> >>> Cheers, >>> Simon >>> >> >> I suspect you want to install python 2.4 and then reinstall 2.6 I did >> that in windows and I don't understand why it wouldn't work in linux >> > > I'm afraid, installation is quit different under UNIX based systems and > Windows. > > I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within > openSUSE 11.1 x86_64) via 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list was so > long, but I will post it, if it helps). > The --enable-framework option is for creating Framework builds on OS X. It won't work on Linux. > > Second, configured again without any flags. The installation by 'make > altinstall' to /usr/local was a success. Python2.6 seams unaffected, too. > So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > Which configuration step did I miss after my Python2.4 installation? What > did I do wrong? > Again, give us the error message. We can't help if we don't know exactly what's going on. > > Cheers, > Simon > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bborcic at gmail.com Fri Jun 12 11:12:58 2009 From: bborcic at gmail.com (Boris Borcic) Date: Fri, 12 Jun 2009 17:12:58 +0200 Subject: Making the case for repeat In-Reply-To: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> Message-ID: <4a3270b8$1_7@news.bluewin.ch> Raymond Hettinger wrote: > There is a natural inclination to do the opposite. We factor code > to eliminate redundancy, but that is not always a good idea with > an API. The goal for code factoring is to minimize redundancy. > The goal for API design is having simple parts that are easily > learned and can be readily combined (i.e. the notion of an > iterator algebra). This reminds me of an early programming experience that left me with a fascination. At a time where code had to fit in a couple dozens kilobytes, I once had to make significant room in what was already very tight and terse code. Code factoring *did* provide the room in the end, but the fascinating part came before. There was strictly no redundancy apparent at first, and finding a usable one involved contemplating code execution paths for hours until some degree of similarity was apparent between two code path families. And then, the fascinating part, was to progressively mutate both *away* from minimality of code, in order to enhance the similarity until it could be factored out. I was impressed; in various ways. First; that the effort could be characterized quite mechanically and in a sense stupidly as finding a shortest equivalent program, while the subjective feeling was that the task exerted perceptive intelligence to the utmost. Second; by the notion that a global constraint of code minimization could map more locally to a constraint that drew code to expand. Third; that the process resulted in bottom-up construction of what's usually constructed top-down, mimicking the willful design of the latter case, eg. an API extension, as we might call it nowadays. Cheers, BB -- "hope achieves the square root of the impossible" From javier.collado at gmail.com Fri Jun 12 11:26:15 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Jun 2009 17:26:15 +0200 Subject: Question about None In-Reply-To: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> References: <1fa836f6-4903-47d6-987a-45152a6de133@z16g2000prd.googlegroups.com> Message-ID: Hello, You're right, types.NoneType is not available in python 3.0, I wasn't aware of that change. Thanks for pointing it out. Best regards, Javier 2009/6/12 Jeff McNeil : > On Jun 12, 10:05?am, Paul LaFollette > wrote: >> Kind people, >> >> Using Python 3.0 on a Gatesware machine (XP). >> I am building a class in which I want to constrain the types that can >> be stored in various instance variables. ?For instance, I want to be >> certain that self.loc contains an int. ?This is straightforward (as >> long as I maintain the discipline of changing loc through a method >> rather than just twiddling it directly. >> >> ? def setLoc(lo): >> ? ? assert isinstance(lo, int), "loc must be an int" >> ? ? self.loc = lo >> >> does the trick nicely. >> >> However, I also want to constrain self.next to be either an instance >> of class Node, or None. ?I would think that the following should work >> but it doesn't. >> >> ? def setNext(nxt): >> ? ? assert isinstance(nxt, (Node, NoneType)), "next must be a Node" >> ? ? self.next = nxt >> >> since type(Node) responds with but the assertion >> above gives "name 'NoneType' is not defined" suggesting that NoneType >> is some sort of quasi-class. >> >> ? def setNext(nxt): >> ? ? assert nxt==None or isinstance(nxt, Node), "next must be a Node" >> ? ? self.next = nxt >> >> works ok, but it's uglier than it ought to be. >> >> So, I have three questions. >> >> 1) Why doesn't isinstance(nxt, (Node, NoneType)) work? >> 2) is their a less ugly alternative that what I am using? >> 3) (this is purely philosophical but I am curious) ?Would it not be >> more intuitive if >> isinstance(None, ) returned true? >> >> Thank you for your kind attention. >> Paul > > 1. The problem is described clearly by that Exception. The 'NoneType' > name isn't bound to any objects at that current scope. ?I know that > with 2.6, you can import 'types.NoneType' but I don't believe the 3.0 > types module includes NoneType. ?Someone else will have to clarify > that as I don't have 3.0 installed. > > 2. A less ugly alternative? You could use the accepted method of > testing against None: > > if var is None: > ? ?do_stuff() > > The use of the 'is' operator checks whether objects are exactly the > same (id(var) == id(None)) as opposed to 'isinstance' or '==.' > > You might also try defining descriptors in order to make your type > checks slightly more transparent. That might be confusing to other > users of your class, though. Not many people expect a TypeError from > an attribute assignment. > > 3. None is an instance of NoneType. Why should isinstance return True > when it's tested against other types? > > HTH, > > Jeff > mcjeff.blogspot.com > -- > http://mail.python.org/mailman/listinfo/python-list > From jeanmichel at sequans.com Fri Jun 12 11:36:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Jun 2009 17:36:37 +0200 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: <4A327605.4020203@sequans.com> > def setNext(nxt): > assert nxt==None or isinstance(nxt, Node), "next must be a Node" > self.next = nxt > > works ok, but it's uglier than it ought to be. > > I don't find it that ugly. It's accurate, easy to read and understand. "What else ?" would say a famous coffee representative. If you like perfection, replace nxt==None by nxt is None. Jean-Michel From simon212 at gmx.de Fri Jun 12 11:49:54 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 17:49:54 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> Message-ID: <4A327922.9080202@gmx.de> Benjamin Kaplan wrote: > > > On Fri, Jun 12, 2009 at 9:31 AM, Simon > wrote: > > edexter wrote: > > simon wrote: > > Hi everybody, > > The situation: > I wrote a GUI, based on Python, TkInter and Pmw. > It runs perfectly fine with Python 2.4 (providing, TkInter > and Pmw are > installed). But it crashes with Python 2.6. I tried this on > MacOSX11.4 > and various Linux Distributions. > Crashes occurs when I activate a Pmw.Diaog (I guess this is > due to a bug > in the installed blt package), also when I use setitems on > Pmw.OptionMenu (I guess this is due to another package, > associated with > tcl/tk). > > The target: > I have to get my GUI work under openSUSE 11.1 (x86_64). > > My plan: > On my openSUSE 11.1 (x86_64), Python 2.6 is installed by > default. > I would like to know, how to install Python 2.4 along with > TkInter and > Pmw (and packages that are required by them), parallel to > the existing > Python 2.6. So that I do not break other software that > depends on Python > 2.6. > > If you can think of another plan, I would be also glad to > discuss it. > > Cheers, > Simon > > > I suspect you want to install python 2.4 and then reinstall 2.6 > I did > that in windows and I don't understand why it wouldn't work in linux > > > I'm afraid, installation is quit different under UNIX based systems > and Windows. > > I installed Python-2.4.4.tar.bz2 from python.org > , using gcc-4.3 (within openSUSE 11.1 x86_64) via > 'make altinstall'. > > First, I tried to configure with the following flags: > --prefix=/opt/python-24 --enable-framework --with-pydebug > This provoked an error during compilation via make (sorry, the list > was so long, but I will post it, if it helps). > > > The --enable-framework option is for creating Framework builds on OS X. > It won't work on Linux. > > > > Second, configured again without any flags. The installation by > 'make altinstall' to /usr/local was a success. Python2.6 seams > unaffected, too. So, I got my parallel installation. > > However, I cannot import modules like Tkinter or readline within > python2.4. > > For example, Tkinter.py is located in /usr/local/lib/python2.4/lib-tk > > sys.path says: ['', '/usr/local/lib/python24.zip', > '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', > '/usr/local/lib/python2.4/lib-tk', > '/usr/local/lib/python2.4/lib-dynload', > '/usr/local/lib/python2.4/site-packages'] > > sys.prefix and sys.exec_prefix say: '/usr/local' > > my bash's PATH variable says: > /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin > > Which configuration step did I miss after my Python2.4 installation? > What did I do wrong? > > > > Again, give us the error message. We can't help if we don't know exactly > what's going on. > > > Sorry, here it comes: Python 2.4.4 (#1, Jun 12 2009, 14:11:55) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "/etc/pythonstart", line 7, in ? import readline ImportError: No module named readline >>> import Tkinter Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter Right know, I'm following Christian's hint, to "install the development library of tk, readline, zlib and libbz2 prior to configure && make", because the following essential packages were not installed on my system: autoconf automake libbz2-devel libopenssl-devel libtool ncurses-devel readline-devel sqlite2-devel tack tcl-devel tk-devel zlib-devel I will let you know about the result, soon. Cheers, Simon From tjreedy at udel.edu Fri Jun 12 12:32:25 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Jun 2009 12:32:25 -0400 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: Paul LaFollette wrote: > since type(Node) responds with but the assertion > above gives "name 'NoneType' is not defined" suggesting that NoneType > is some sort of quasi-class. add NoneType = type(None) before using Nonetype From simon212 at gmx.de Fri Jun 12 13:05:53 2009 From: simon212 at gmx.de (Simon) Date: Fri, 12 Jun 2009 19:05:53 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> Message-ID: <4A328AF1.8090205@gmx.de> Christian Heimes wrote: > Simon wrote: >> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >> openSUSE 11.1 x86_64) via 'make altinstall'. >> >> First, I tried to configure with the following flags: >> --prefix=/opt/python-24 --enable-framework --with-pydebug >> This provoked an error during compilation via make (sorry, the list was >> so long, but I will post it, if it helps). > > --enable-framework is for Mac OS X only. > >> Second, configured again without any flags. The installation by 'make >> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >> too. So, I got my parallel installation. > > You have chosen the correct and canonical way to install a parallel > installation of Python. > >> However, I cannot import modules like Tkinter or readline within python2.4. > > You must install the development library of tk, readline, zlib and > libbz2 prior to configure && make. > > Try this on your box: > > zypper install gcc make autoconf automake libtool zlib-devel > readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel > libopenssl-devel > Unfortunately, I got the following errors, while compiling via make. Please, see attached text file for details about everything I did from installing the missing packages via zypper until make. [...] gcc -pthread -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -I. -I/home/simon/Python-2.4.4/./Include -I/usr/local/include -I/home/simon/Python-2.4.4/Include -I/home/simon/Python-2.4.4 -c /home/simon/Python-2.4.4/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.4/_curses_panel.o /home/simon/Python-2.4.4/Modules/_curses_panel.c:17:19: error: panel.h: No such file or directory [...] building '_tkinter' extension gcc -pthread -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11/include -I. -I/home/simon/Python-2.4.4/./Include -I/usr/local/include -I/home/simon/Python-2.4.4/Include -I/home/simon/Python-2.4.4 -c /home/simon/Python-2.4.4/Modules/_tkinter.c -o build/temp.linux-x86_64-2.4/_tkinter.o In file included from /home/simon/Python-2.4.4/Modules/_tkinter.c:67: /usr/include/tk.h:78:23: error: X11/Xlib.h: No such file or directory [...] X11 says: Program 'X11' is present in package 'xorg-x11', which is installed on your system. Absolute path to 'X11' is '/usr/bin/X11'. Please check your $PATH variable to see whether it contains the mentioned path. and it is on the path rpm -q xorg-x11 says: xorg-x11-7.4-8.18 Cheers, Simon -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: install.error.log URL: From rdmurray at bitdance.com Fri Jun 12 13:13:47 2009 From: rdmurray at bitdance.com (R. David Murray) Date: Fri, 12 Jun 2009 17:13:47 +0000 (UTC) Subject: zipfile doesn't compress very good, are there other solutions? References: <4A316C05.4080808@gmail.com> <50697b2c0906111358u400942f1yb2bcb1b33c1ecabe@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jun 11, 2009 at 1:41 PM, Stef Mientki wrote: > > Peter Otten wrote: > >> Stef Mientki wrote: > >>> Peter Otten wrote: > >>>> Stef Mientki wrote: > >>>>> I packed all sources with zipfile, > >>>>> but the compression doesn't seem to be very good. > >>>>> > >>>> > >>>> If you don't specify the compression, the files are not compressed at > >>>> all. Just in case you didn't know... > >>>> > >>> > >>> .. and would you be willing to tell me how I could set the compression ( > >>> at maximum) ? > >>> > >> > >> According to the documentation (hint, hint) there is only on and off. > >> > >> zipfile.ZipFile(filename, "w", compression=zipfile.ZIP_DEFLATED) > >> > >> > > > > sorry guys I made a mistake, > > I did read the doc, but as there was no default value metioned, > > Erm... > > class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]]) > > Open a ZIP file [...] compression is the ZIP compression method to > use when writing the archive, and should be ZIP_STORED or > ZIP_DEFLATED; [...] The default is ZIP_STORED. [...] > > Though I admit the docs could definitely do with having > "compression=ZIP_STORED" in the signature part of the doc. Georg's been fixing the method signatures bit by bit to use keyword style. Doc patches would be welcome to help speed up the conversion process. --David From sandra.bunn at thecarreraagency.com Fri Jun 12 13:22:36 2009 From: sandra.bunn at thecarreraagency.com (Sandra Bunn) Date: Fri, 12 Jun 2009 10:22:36 -0700 Subject: ANNOUNCE: TIB/Rendezvous module for python Message-ID: <007501c9eb82$61d2ca90$6601a8c0@SANDRALAPTOP> Hi Thomas, My name is Sandra with The Carrera Agency. I saw an online article by you regarding Tibco Rendezvous with Python. I am currently looking for a Python/Tibco developer for a remote position. Below is a description of what they are trying to do: Summary: Need the ability to connect to a TIBCO server natively using Python. The Python TICBO interface must be able to query for available servers and server clusters, create connections and sessions, and feed messages to queues and topics. The implementation must be fault tolerant and inform calling libraries of errors and / or throw consistent exceptions that can be caught and handled by higher level libraries. Functional Requirements The module must be able to: . connect to a TIBCO server using TIBCO's URL format . create a session to a named queue on the server. . create a message producer with a given session. . easily fill a TIBCO EMS Map Message with key value pairs. . send a filled Map Message to a TIBCO server. . shut down a connection. . work with TIBCO's built in failover and load balancing functionality. TIBCO C Native Equivalents The following are the native equivalents that need to successfully connect to a TIBCO server. These functions should only be used as guidelines for understanding which portions of TIBCO functionality are being used, and should not be considered requirements for 1:1 equivalency. Simplifications of TIBCO's C based functionality is expected. . Functions 1. tibemsConnectionFactory_Create 2. tibemsConnectionFactor_SetServerURL 3. tibemsConnectionFactory_CreateConnection 4. tibemsConnectionFactory_Destroy 5. tibemsQueue_Create 6. tibemsConnection_CreateSession 7. tibemsConnection_Stop 8. tibemsConnection_Close 9. tibemsSession_CreateProducer 10. tibemsMsgProducer_Close 11. tibemsMsgProducer_SendEx 12. tibemsDestination_Destroy 13. tibemsMsg_Destroy 14. tibemsMapMsg_Create 15. tibemsMapMsg_Set* Structures 1. tibemsMapMsg 2. tibemsConnectionFactory 3. tibemsConnection 4. tibemsDestination 5. tibemsSession 6. tibemsMsgProducer Basic assessment (not set in stone) of project level of effort to work against: . Phase One - 1 week o Discovery o Architectural documentation for to the C TIBCO level commands. Validation with internal engineering teams of architectural documentation and high level project plan. . Phase Two - 1.5 weeks o Coding - Wrapping C code with Boost or an equivalent wrapper system for python. . Phase Three - 1.5 weeks o Test and debug the implementation to assure the appropriate error conditions, performance, and other requirements set forth. . Phase Four - .5 week o Finalize documentation and cross train team on implementation If you or someone you know might be interested, please contact me. I look forward to hearing from you. Regards, Sandra Sandra Bunn The Carrera Agency 65 Enterprise Aliso Viejo, CA 92656 (310) 370-4778 - Ofc. (310) 499-5653 - Fax We've changed our look, not the quality of our service - www.thecarreraagency.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Fri Jun 12 14:20:16 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 12 Jun 2009 19:20:16 +0100 Subject: Need help in Python regular expression In-Reply-To: References: <2d4d8624-043b-4f5f-ae2d-bf73bca3d51b@p6g2000pre.googlegroups.com> Message-ID: On Fri, 12 Jun 2009 06:20:24 +0100, meryl wrote: > On Jun 11, 9:41?pm, "Mark Tolonen" wrote: >> "meryl" wrote in message >> >> > Hi, >> >> > I have this regular expression >> > blockRE = re.compile(".*RenderBlock {\w+}") >> >> > it works if my source is "RenderBlock {CENTER}". [snip] >> -----------------------code---------------------- >> import re >> pat = re.compile(r'Render(?:Block|Table) (?:\(\w+\)|{\w+})') >> >> testdata = '''\ >> RenderTable {TABLE} >> RenderBlock (CENTER) >> RenderBlock {CENTER} >> RenderTable {TABLE) ? ? ?#shouldn't match >> ''' >> >> print pat.findall(testdata) >> --------------------------------------------------- >> >> Result: >> >> ['RenderTable {TABLE}', 'RenderBlock (CENTER)', 'RenderBlock {CENTER}'] >> >> -Mark > > Thanks for both of your help. How can i modify the RegExp so that > both > RenderTable {TABLE} > and > RenderTable {TABLE} [text with a-zA-Z=SPACE0-9] > will match > > I try adding ".*" at the end , but it ends up just matching the second > one. Curious, it should work (and match rather more than you want, but that's another matter. Try adding this instead: '(?: \[[a-zA-Z= 0-9]*\])?' Personally I'd replace all those spaces with \s* or \s+, but I'm paranoid when it comes to whitespace. -- Rhodri James *-* Wildebeest Herder to the Masses From robert.kern at gmail.com Fri Jun 12 14:20:44 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Jun 2009 13:20:44 -0500 Subject: Question about None In-Reply-To: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: On 2009-06-12 09:05, Paul LaFollette wrote: > Kind people, > > Using Python 3.0 on a Gatesware machine (XP). > I am building a class in which I want to constrain the types that can > be stored in various instance variables. For instance, I want to be > certain that self.loc contains an int. This is straightforward (as > long as I maintain the discipline of changing loc through a method > rather than just twiddling it directly. You may want to consider using Enthought's Traits package (disclosure: I work for Enthought). http://pypi.python.org/pypi/Traits/ Type-checking attributes is not my favorite feature of Traits (I try to avoid using this feature if I can avoid it), but it is designed for precisely your use cases. In [2]: %cpaste Pasting code; enter '--' alone on the line to stop. :from enthought.traits.api import Float, HasTraits, Instance, Int, This : :class FancyClass(HasTraits): : """ An example traited class. : """ : x = Float(10.0) : y = Int(-20) : :class Node(HasTraits): : """ A node in a single-linked list. : """ : : # The location of this Node. : loc = Int(0) : : # The next Node. This() is a special trait that accepts instances of : # this class, or None. : next = This() : : # The data attached to the Node. It will accept instances of FancyClass : # or None. : data = Instance(FancyClass) : : :-- In [3]: n = Node() In [4]: n.next In [5]: n.data In [6]: n.loc Out[6]: 0 In [7]: fc = FancyClass(x=15.0) In [8]: fc.x Out[8]: 15.0 In [9]: fc.y Out[9]: -20 In [10]: fc.y = 'a string' --------------------------------------------------------------------------- TraitError Traceback (most recent call last) /Users/rkern/ in () /Users/rkern/svn/et/Traits/enthought/traits/trait_handlers.pyc in error(self, object, name, value) 173 """ 174 raise TraitError( object, name, self.full_info( object, name, value ), --> 175 value ) 176 177 def arg_error ( self, method, arg_num, object, name, value ): TraitError: The 'y' trait of a FancyClass instance must be an integer, but a value of 'a string' was specified. In [11]: n.data = fc In [12]: n.data = None In [13]: n.data = n --------------------------------------------------------------------------- TraitError Traceback (most recent call last) /Users/rkern/ in () /Users/rkern/svn/et/Traits/enthought/traits/trait_handlers.pyc in error(self, object, name, value) 173 """ 174 raise TraitError( object, name, self.full_info( object, name, value ), --> 175 value ) 176 177 def arg_error ( self, method, arg_num, object, name, value ): TraitError: The 'data' trait of a Node instance must be a FancyClass or None, but a value of <__main__.Node object at 0x17999c0> was specified. In [14]: n.next = Node(loc=1) In [15]: n.next Out[15]: <__main__.Node at 0x1892e70> -- 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 rhodri at wildebst.demon.co.uk Fri Jun 12 14:42:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 12 Jun 2009 19:42:17 +0100 Subject: TypeError: int argument required In-Reply-To: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Fri, 12 Jun 2009 04:56:24 +0100, lucius wrote: > I am trying to > print some values to a file (using c's printf like method). > TypeError: int argument required > # this works, i see value on screen > print w, h, absX, absY > > # where result is the return value of my regular expression. > > w, h, absX, absY = result.group(3), result.group(4), result.group > (5), result.group(6) > > w = 100 > h = 200 > > absX = 10.0 > absY = 20.0 > > # this fails, I get "TypeError: int argument required" > print >> fo, " style=\"fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke- > opacity:0.9\"/> " % (absX, absY, w, h) > > Thank you for any help. 1. This has to be the most incoherent help request that I've seen that included actual information. Figuring out what you were actually doing was quite a challenge. 2. That output string has severe "leaning toothpick" syndrome. Python accepts both single and double quotes to help avoid creating something so unreadable: use them. 3. matchobject.group(n) returns a string, not an int or float. -- Rhodri James *-* Wildebeest Herder to the Masses From aahz at pythoncraft.com Fri Jun 12 16:23:24 2009 From: aahz at pythoncraft.com (Aahz) Date: 12 Jun 2009 13:23:24 -0700 Subject: How to insert string in each match using RegEx iterator References: Message-ID: In article , 504crank at gmail.com <504crank at gmail.com> wrote: > >MRI scans would no doubt reveal that people who attain a mastery of >RegEx expressions must have highly developed areas of the brain. I >wonder where the RegEx part of the brain might be located. You want Friedl: http://www.powells.com/biblio/2-9780596528126-0 -- 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 piet at cs.uu.nl Fri Jun 12 16:24:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 12 Jun 2009 22:24:47 +0200 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <39379946-16f0-448c-a230-3da19449d40e@k19g2000prh.googlegroups.com> Message-ID: >>>>> higer (h) wrote: >h> On Jun 11, 11:44?am, Chris Rebert wrote: >>> On Wed, Jun 10, 2009 at 8:11 PM, higer wrote: >>> > I just want to compare two files,one from windows and the other from >>> > unix. But I do not want to compare them through reading them line by >>> > line. Then I found there is a filecmp module which is used as file and >>> > directory comparisons. However,when I use two same files (one from >>> > unix,one from windows,the content of them is the same) to test its cmp >>> > function, filecmp.cmp told me false. >>> >>> > Later, I found that windows use '\n\r' as new line flag but unix use >>> > '\n', so filecmp.cmp think that they are different,then return false. >>> > So, can anyone tell me that is there any method like IgnoreNewline >>> > which can ignore the difference of new line flag in diffrent >>> > platforms? If not,I think filecmp may be not a good file comparison >>> >>> Nope, there's no such flag. You could run the files through either >>> `dos2unix` or `unix2dos` beforehand though, which would solve the >>> problem. >>> Or you could write the trivial line comparison code yourself and just >>> make sure to open the files in Universal Newline mode (add 'U' to the >>> `mode` argument to `open()`). >>> You could also file a bug (a patch to add newline insensitivity would >>> probably be welcome). >>> >>> Cheers, >>> Chris >>> --http://blog.rebertia.com >h> Thank you very much. Adding 'U' argument can perfectly work, and I >h> think it is definitely to report this as a bug to Python.org as you >h> say. Filecmp does a binary compare, not a text compare. So it starts by comparing the sizes of the files and if they are different the files must be different. If equal it compares the bytes by reading large blocks. Comparing text files would be quite different especially when ignoring line separators. Maybe comparing text files should be added as a new feature. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From emile at fenx.com Fri Jun 12 16:51:24 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Jun 2009 13:51:24 -0700 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix In-Reply-To: References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: On 6/11/2009 12:09 AM higer said... > Tool can certainly be used to compare two files,but I just want to > compare them using Python code. > difflib? Emile From niels.egberts at gmail.com Fri Jun 12 16:58:42 2009 From: niels.egberts at gmail.com (Niels Egberts) Date: Fri, 12 Jun 2009 22:58:42 +0200 Subject: uncompress base64-gzipped string Message-ID: I'm creating a game in python and I want to a level editor called 'tiled'. It ouputs a .xml file with base64-gzipped information. Then every 4 bytes represents a number. See the following link: http://www.mapeditor.org/wiki/Examining_the_map_format To start I tried: code = base64.b64decode("H4sIAAAAAAAAAO3NoREAMAgEsLedAfafE4+s6l0jolNJiif18tt/Fj8AAMC9ARtYg28AEAAA") code = zlib.decompress(code) But I get: zlib.error: Error -3 while decompressing data: incorrect header check How can I solve this? Thanks, Niels. From aaron.watters at gmail.com Fri Jun 12 17:30:56 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Fri, 12 Jun 2009 14:30:56 -0700 (PDT) Subject: ANN: WHIFF += Flash chart widget support (Aaron Watters) References: Message-ID: <19839370-3b23-4efd-bbdf-75877639aceb@c19g2000prh.googlegroups.com> Regarding: http://aaron.oirt.rutgers.edu/myapp/amcharts/doc On Jun 12, 3:07 am, oyster wrote: > nice > the only pity is that amcharts is not a money-free product It is if you don't mind the little link in the corner. (which I think is only fair). I found a totally free one that looked pretty good too, which I may add sometime. http://teethgrinder.co.uk/open-flash-chart/ -- Aaron Watters === an apple every 8 hours will keep 3 doctors away. -- kliban From Nikolaus at rath.org Fri Jun 12 18:33:13 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Fri, 12 Jun 2009 18:33:13 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> Message-ID: <873aa5m6ae.fsf@vostro.rath.org> Nikolaus Rath writes: > Hi, > > Please consider this example: [....] I think I managed to narrow down the problem a bit. It seems that when a function returns normally, its local variables are immediately destroyed. However, if the function is left due to an exception, the local variables remain alive: ---------snip--------- #!/usr/bin/env python import gc class testclass(object): def __init__(self): print "Initializing" def __del__(self): print "Destructing" def dostuff(fail): obj = testclass() if fail: raise TypeError print "Calling dostuff" dostuff(fail=False) print "dostuff returned" try: print "Calling dostuff" dostuff(fail=True) except TypeError: pass gc.collect() print "dostuff returned" ---------snip--------- Prints out: ---------snip--------- Calling dostuff Initializing Destructing dostuff returned Calling dostuff Initializing dostuff returned Destructing ---------snip--------- Is there a way to have the obj variable (that is created in dostuff()) destroyed earlier than at the end of the program? As you can see, I already tried to explicitly call the garbage collector, but this does not help. Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From ben+python at benfinney.id.au Fri Jun 12 20:14:15 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Jun 2009 10:14:15 +1000 Subject: Exception inside loop wrongly failing doctest References: <02420d02$0$20639$c3e8da3@news.astraweb.com> <0242240f$0$21875$c3e8da3@news.astraweb.com> Message-ID: <87ws7h6ld4.fsf@benfinney.id.au> Steven D'Aprano writes: > Ah, that would be it. Not a bug then, a limitation of the doctest module. The doctest module is good for narrative tests (ensuring that examples in documentation actually work as written), but poor for unit testing. Both functions are useful, but each should use a different tool . Not entirely related to the limitation you've found, and I don't know from your explanation whether you're mixing the two purposes, but it's worth pointing out in case you are. -- \ ?I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.? ?Emo Philips | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Fri Jun 12 21:05:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 13 Jun 2009 13:05:31 +1200 Subject: OT: Periodic table gets a new element References: Message-ID: So, is this only accessible with Python 3.x, or will it be backported to 2.x as well? From lists at cheimes.de Fri Jun 12 21:06:38 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Jun 2009 03:06:38 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A328AF1.8090205@gmx.de> References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> Message-ID: Simon schrieb: > Christian Heimes wrote: >> Simon wrote: >>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >>> openSUSE 11.1 x86_64) via 'make altinstall'. >>> >>> First, I tried to configure with the following flags: >>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>> This provoked an error during compilation via make (sorry, the list was >>> so long, but I will post it, if it helps). >> >> --enable-framework is for Mac OS X only. >> >>> Second, configured again without any flags. The installation by 'make >>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>> too. So, I got my parallel installation. >> >> You have chosen the correct and canonical way to install a parallel >> installation of Python. >> >>> However, I cannot import modules like Tkinter or readline within >>> python2.4. >> >> You must install the development library of tk, readline, zlib and >> libbz2 prior to configure && make. >> >> Try this on your box: >> >> zypper install gcc make autoconf automake libtool zlib-devel >> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >> libopenssl-devel >> > > > Unfortunately, I got the following errors, while compiling via make. > Please, see attached text file for details about everything I did from > installing the missing packages via zypper until make. zypper should have installed all necessary dependencies, including a whole bunch of X11 headers. Something seems to be wrong on your system or SuSE's package dependencies. I know why I dislike SuSE. :) Although I started my Linux career 12 years ago with SuSE I prefer Debian based systems since Woody came out in 2002. :) > X11 says: > Program 'X11' is present in package 'xorg-x11', which is installed on > your system. zypper search X11 | grep devel ... zypper install xorg-x11-devel That should (hopefully) do the trick. On a Debian based systems it's much easier to install all Python dependencies with "apt-get build-dep python2.5" To quote SuSE: "Have a lot of fun ..." Und viel Gl?ck! Christian From python at mrabarnett.plus.com Fri Jun 12 21:26:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Jun 2009 02:26:50 +0100 Subject: Exceptions and Object Destruction In-Reply-To: <873aa5m6ae.fsf@vostro.rath.org> References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <4A33005A.9070208@mrabarnett.plus.com> Nikolaus Rath wrote: > Nikolaus Rath writes: >> Hi, >> >> Please consider this example: > [....] > > I think I managed to narrow down the problem a bit. It seems that when > a function returns normally, its local variables are immediately > destroyed. However, if the function is left due to an exception, the > local variables remain alive: > > ---------snip--------- > #!/usr/bin/env python > import gc > > class testclass(object): > def __init__(self): > print "Initializing" > > def __del__(self): > print "Destructing" > > def dostuff(fail): > obj = testclass() > > if fail: > raise TypeError > > print "Calling dostuff" > dostuff(fail=False) > print "dostuff returned" > > try: > print "Calling dostuff" > dostuff(fail=True) > except TypeError: > pass > > gc.collect() > print "dostuff returned" > ---------snip--------- > > > Prints out: > > > ---------snip--------- > Calling dostuff > Initializing > Destructing > dostuff returned > Calling dostuff > Initializing > dostuff returned > Destructing > ---------snip--------- > > > Is there a way to have the obj variable (that is created in dostuff()) > destroyed earlier than at the end of the program? As you can see, I > already tried to explicitly call the garbage collector, but this does > not help. > Are the objects retained because there's a reference to the stack frame(s) in the traceback? From sjmachin at lexicon.net Fri Jun 12 22:38:05 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 02:38:05 +0000 (UTC) Subject: uncompress base64-gzipped string References: Message-ID: Niels Egberts gmail.com> writes: > zlib.error: Error -3 while decompressing data: incorrect header check > > How can I solve this? The link you quoted says "you need to first base64 decode the string, then gunzip the resulting data" ... so gunzip it: | >>> s0 = "H4sIAAAAA......" | >>> import base64 | >>> s1 = base64.b64decode(s0) | >>> len(s0) | 72 | >>> len(s1) | 54 | >>> import StringIO # or cStringIO or io depending on what # Python versions you want to support | >>> sio = StringIO.StringIO(s1) | >>> import gzip | >>> gzf = gzip.GzipFile(fileobj=sio) | >>> guff = gzf.read() | >>> len(guff) | 4096 | >>> guff[:100] | '\x1b\x00\x00\x00\x1b\x00\x00\x00\x1b\x00\x00\x00 [snip] What a long journey: parse xml, base64 decode, gunzip, and you're still not home; next stop is struct.unpack ... HTH, John From higerinbeijing at gmail.com Fri Jun 12 23:29:41 2009 From: higerinbeijing at gmail.com (higer) Date: Fri, 12 Jun 2009 20:29:41 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP References: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Message-ID: <1c4c5f48-bcce-4d25-9517-f78a8a0c72eb@d25g2000prn.googlegroups.com> On Jun 12, 4:55?pm, higer wrote: > Maybe everyone know that decompyle(hosted on SourceForge.net) is a > tool to transfer a .pyc file to .py file and now it does only support > Python 2.3 or the below. I have found a project named unpyc which can > support Python version 2.5. Unpyc project is build on decompyle which > is hosted on google code and if you want you can download it. > > I build unpyc on Ubuntu successfully and can run it ok. But with some > purpose, I just want to use this tool on my WindowsXP, so I tried to > build it. I have tried many times and methods, with .net2003 or > MingGW, but I failed. So,I come here looking for sombody can help me.I > will give the showing error message with different method on the > following: > > 1 ? ? Using command : python setup.py install > F:\unpyc>python setup.py install > running install > running build > running build_py > creating build\lib.win32-2.5 > creating build\lib.win32-2.5\unpyc > copying unpyc\dis_15.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_16.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_20.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_21.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_22.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_23.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_24.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_25.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_26.py -> build\lib.win32-2.5\unpyc > copying unpyc\dis_files.py -> build\lib.win32-2.5\unpyc > copying unpyc\magics.py -> build\lib.win32-2.5\unpyc > copying unpyc\marshal_files.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_23.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_24.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_25.py -> build\lib.win32-2.5\unpyc > copying unpyc\opcode_26.py -> build\lib.win32-2.5\unpyc > copying unpyc\Parser.py -> build\lib.win32-2.5\unpyc > copying unpyc\Scanner.py -> build\lib.win32-2.5\unpyc > copying unpyc\spark.py -> build\lib.win32-2.5\unpyc > copying unpyc\verify.py -> build\lib.win32-2.5\unpyc > copying unpyc\Walker.py -> build\lib.win32-2.5\unpyc > copying unpyc\__init__.py -> build\lib.win32-2.5\unpyc > running build_ext > building 'unpyc/marshal_25' extension > creating build\temp.win32-2.5 > creating build\temp.win32-2.5\Release > creating build\temp.win32-2.5\Release\unpyc > f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / > nologo /Ox /MD /W3 /GX /DNDEBU > G -IF:\Python25\include -IF:\Python25\PC /Tcunpyc/marshal_25.c /Fobuild > \temp.win32-2.5\Release\unpyc > /marshal_25.obj > marshal_25.c > unpyc\marshal_25.c(401) : warning C4273: 'PyMarshal_WriteLongToFile' : > inconsistent dll linkage > unpyc\marshal_25.c(413) : warning C4273: > 'PyMarshal_WriteObjectToFile' : inconsistent dll linkage > unpyc\marshal_25.c(1004) : warning C4273: > 'PyMarshal_ReadShortFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1015) : warning C4273: > 'PyMarshal_ReadLongFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1044) : warning C4273: > 'PyMarshal_ReadLastObjectFromFile' : inconsistent dll link > age > unpyc\marshal_25.c(1087) : warning C4273: > 'PyMarshal_ReadObjectFromFile' : inconsistent dll linkage > unpyc\marshal_25.c(1101) : warning C4273: > 'PyMarshal_ReadObjectFromString' : inconsistent dll linkag > e > unpyc\marshal_25.c(1116) : warning C4273: > 'PyMarshal_WriteObjectToString' : inconsistent dll linkage > > f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe / > DLL /nologo /INCREMENTAL:NO /LI > BPATH:F:\Python25\libs /LIBPATH:F:\Python25\PCBuild /EXPORT:initunpyc/ > marshal_25 build\temp.win32-2. > 5\Release\unpyc/marshal_25.obj /OUT:build\lib.win32-2.5\unpyc/ > marshal_25.pyd /IMPLIB:build\temp.win3 > 2-2.5\Release\unpyc\marshal_25.lib > marshal_25.obj : error LNK2001: unresolved external symbol initunpyc/ > marshal_25 > build\temp.win32-2.5\Release\unpyc\marshal_25.lib : fatal error > LNK1120: 1 unresolved externals > LINK : fatal error LNK1141: failure during build of exports file > error: command '"f:\Program Files\Microsoft Visual Studio .NET > 2003\Vc7\bin\link.exe"' failed with e > xit status 1141 > > 2 ? ?Using command: ? python setup.py build -c mingw32 > > F:\unpyc>python setup.py build -c mingw32 > running build > running build_py > running build_ext > building 'unpyc/marshal_25' extension > F:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IF:\Python25\include - > IF:\Python25\PC -c unpyc/mars > hal_25.c -o build\temp.win32-2.5\Release\unpyc\marshal_25.o > unpyc/marshal_25.c:1087: warning: 'PyMarshal_ReadObjectFromFile' > defined locally after being referen > ced with dllimport linkage > unpyc/marshal_25.c:1101: warning: 'PyMarshal_ReadObjectFromString' > defined locally after being refer > enced with dllimport linkage > writing build\temp.win32-2.5\Release\unpyc\marshal_25.def > F:\mingw\bin\gcc.exe -mno-cygwin -shared -s build > \temp.win32-2.5\Release\unpyc\marshal_25.o build\te > mp.win32-2.5\Release\unpyc\marshal_25.def -LF:\Python25\libs -LF: > \Python25\PCBuild -lpython25 -lmsvc > r71 -o build\lib.win32-2.5\unpyc/marshal_25.pyd > F:\Python25\libs/libpython25.a(dcbbs00336.o):(.text+0x0): multiple > definition of `PyMarshal_ReadObje > ctFromString' > build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text > +0x2958): first defined here > F:\Python25\libs/libpython25.a(dcbbs00335.o):(.text+0x0): multiple > definition of `PyMarshal_ReadObje > ctFromFile' > build\temp.win32-2.5\Release\unpyc\marshal_25.o:marshal_25.c:(.text > +0x28fb): first defined here > Cannot export initunpyc/marshal_25: symbol not defined > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > PS: necessary files has been added in proper path: Python25.dll is in > windows/system32; python25.lib and libpython25.a is in Python25/libs; > > Appreciate that you can do me a favor.Thanks There is nobody can help me? From rylesny at gmail.com Sat Jun 13 00:55:14 2009 From: rylesny at gmail.com (ryles) Date: Fri, 12 Jun 2009 21:55:14 -0700 (PDT) Subject: Unhandled exception in thread References: Message-ID: <9bc92125-7e9b-448a-a501-a4c2ee93e849@k2g2000yql.googlegroups.com> On Jun 11, 3:52?pm, Mads Michelsen wrote: > Here's the deal. The script in question is a screen scraping thing > which downloads and parses the html in the background using a separate > thread (the 'thread' module), while the main program serves up the > data to the user, allowing some modicum of interaction. Sometimes, not > always (though I cannot see a pattern), when I quit the script, the > following error message is printed: > > ? ? Unhandled exception in thread started by > ? ? Error in sys.excepthook: > > ? ? Original exception was: Are you using daemon threads? There are some issues with CPython when exiting with daemon threads: http://bugs.python.org/issue1722344 http://bugs.python.org/issue1856 http://bugs.python.org/issue4106 It's possible you are encountering this kind of problem. I have had to deal with issue4106, the workaround being to explicitly join the thread of multiprocessing.Queue before exiting. I would follow Scott's advice and explicitly request and wait for your threads to exit before terminating the process. From ajsavige at yahoo.com.au Sat Jun 13 01:02:53 2009 From: ajsavige at yahoo.com.au (Andrew Savige) Date: Fri, 12 Jun 2009 22:02:53 -0700 (PDT) Subject: Lexical scope: converting Perl to Python Message-ID: <447038.54682.qm@web56406.mail.re3.yahoo.com> I'd like to convert the following Perl code to Python: ?use strict; ?{ ?? my %private_hash = ( A=>42, B=>69 ); ?? sub public_fn { ???? my $param = shift; ???? return $private_hash{$param}; ?? } ?} ?print public_fn("A");??????? # good:? prints 42 ?my $x = $private_hash{"A"};? # error: good, hash not in scope The real code is more complex; the above is a simplified example. Notice that this code uses Perl's lexical scope to hide the %private_hash variable, but not the public_fn() function. While I could convert this code to the following Python code: ?private_hash = dict( A=42, B=69 ) ?def public_fn(param): ?? return private_hash[param] ?print public_fn("A")???? # good:? prints 42 ?x = private_hash["A"]??? # works: oops, hash is in scope I'm not happy with that because I'd like to limit the scope of the private_hash variable so that it is known only inside public_fn. Of course, I could hide the hash like so: ?def public_fn(param): ?? private_hash = dict( A=42, B=69 ) ?? return private_hash[param] yet I'm not happy with that either because of the repeated initialization the hash each time the function is called. What is the Pythonic equivalent of Perl's lexical scope, as illustrated by the code snippet above? Thanks, /-\ Need a Holiday? Win a $10,000 Holiday of your choice. Enter now.http://us.lrd.yahoo.com/_ylc=X3oDMTJxN2x2ZmNpBF9zAzIwMjM2MTY2MTMEdG1fZG1lY2gDVGV4dCBMaW5rBHRtX2xuawNVMTEwMzk3NwR0bV9uZXQDWWFob28hBHRtX3BvcwN0YWdsaW5lBHRtX3BwdHkDYXVueg--/SIG=14600t3ni/**http%3A//au.rd.yahoo.com/mail/tagline/creativeholidays/*http%3A//au.docs.yahoo.com/homepageset/%3Fp1=other%26p2=au%26p3=mailtagline From mk.fraggod at gmail.com Sat Jun 13 01:25:45 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 11:25:45 +0600 Subject: [Tutor] Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: <20090613112545.2ce188af@coercion> On Thu, 11 Jun 2009 22:35:15 -0700 Dennis Lee Bieber wrote: > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > declaimed the following in > gmane.comp.python.general: > > > I sent this to the Tutor mailing list and did not receive a response. > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > remarks? > > > > Please reply off-list and thanks in advance. Code examples are below in > > plain text. > > > Sorry -- you post to a public forum, expect to get the response on a > public forum... > > > > My program runs interactively by allowing the user to directly > > > interact with the python prompt. This program has a runAll() method > > > that runs a series of subprocesses with a cap on how many instances > > > are running at a time. My intent is to allow the user to use Ctrl-C to > > > break these subprocesses. Note that while not reflected in the demo > > Are they subprocesses or threads? Your sample code seems to be using > threads. > > When using threads, there is no assurance that any thread other than > the main program will receive a keyboard interrupt. In fact, no thread other than the main will get interrupt. > > def runAll(): > > workers = [ Thread(target = runSingle, args = [i]) > > for i in xrange(MAX_SUBPROCS + 1) ] > > try: > > for w in workers: > > w.start() > > except KeyboardInterrupt: > > ## I want this to be shown on a KeyboardInterrupt > > print '********* stopped midway ********' > > You are unlikely to see that... After you start the defined worker > /threads/ (which doesn't take very long -- all threads will be started, > but some may immediately block on the semaphore) this block will exit > and you will be at... > > > for w in workers: > > w.join() > > ... a .join() call, which is the most likely position at which the > keyboard interrupt will be processed, killing the main program thread > and probably generating some errors as dangling active threads are > forceably killed. There was quite interesting explaination of what happens when you send ^C with threads, posted on concurrency-sig list recently: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf Can be quite shocking, but my experience w/ threads only confirms that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From apt.shansen at gmail.com Sat Jun 13 01:35:57 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 12 Jun 2009 22:35:57 -0700 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: <7a9c25c20906122235y44795758pb96abe547464f98@mail.gmail.com> > > private_hash = dict( A=42, B=69 ) > def public_fn(param): > return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"] # works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. > A common idiom to do that would be this: def public_fn(param, __private_hash=dict(A=42, B=69)): return __private_hash[param] People often squint when they see that but it is useful in several ways. Python initializes the default arguments -once-, at definition. If they are mutable-- a dictionary, list or such-- that same dict is used everytime the function is called. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Jun 13 01:43:29 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Jun 2009 01:43:29 -0400 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: Andrew Savige wrote: > I'd like to convert the following Perl code to Python: > > use strict; > { > my %private_hash = ( A=>42, B=>69 ); > sub public_fn { > my $param = shift; > return $private_hash{$param}; > } > } > print public_fn("A"); # good: prints 42 > my $x = $private_hash{"A"}; # error: good, hash not in scope > > The real code is more complex; the above is a simplified example. > > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. > > While I could convert this code to the following Python code: > > private_hash = dict( A=42, B=69 ) > def public_fn(param): > return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"] # works: oops, hash is in scope Why would you do that if you do not want to do that? > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. def public_fn(): private_hash = dict( A=42, B=69 ) def public_fn(param): return private_hash[param] return public_fn public_fn = public_fn() print (public_fn("A")) x = private_hash["A"] # outputs 42 Traceback (most recent call last): File "C:\Programs\Python31\misc\t1", line 8, in x = private_hash["A"] NameError: name 'private_hash' is not defined Terry Jan Reedy From mk.fraggod at gmail.com Sat Jun 13 01:44:31 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 11:44:31 +0600 Subject: Lexical scope: converting Perl to Python References: Message-ID: <20090613114431.6f4893c7@coercion> On Fri, 12 Jun 2009 22:02:53 -0700 (PDT) Andrew Savige wrote: > I'd like to convert the following Perl code to Python: > > ?use strict; > ?{ > ?? my %private_hash = ( A=>42, B=>69 ); > ?? sub public_fn { > ???? my $param = shift; > ???? return $private_hash{$param}; > ?? } > ?} > ?print public_fn("A");??????? # good:? prints 42 > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > ... > > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? If you're using scope for garbage-collecting purposes, there's "with" statement and contextlib: from contextlib import contextmanager @contextmanager def get_hash(): complex_hash = dict(A=42, B-69) try: yield complex_hash except Exception as ex: del complex_hash # complex destructor ;) raise ex with get_hash() as hash: # do stuff with hash Note that this only makes sense if you need to implement some complex operation on hash destruction, and do that whatever-happens-inside-with to close the object, obviously not the case with simple dict above. And if you want to obfuscate one part of your code from another, you'll probably have better luck with languages like java, since no one seem to care about such stuff with python, so it'd be a hack against the language, at best. Why would you want to hide the code from itself, anyway? It's not like you'd be able to accomplish it - code can easily grep it's process body in memory and harvest all the "private" values, so I'd suggest getting some fresh air when you start to feel like doing that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 02:29:34 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 16:29:34 +1000 Subject: Question about None References: Message-ID: <02433982$0$20629$c3e8da3@news.astraweb.com> Paul LaFollette wrote: > 3) (this is purely philosophical but I am curious) Would it not be > more intuitive if > isinstance(None, ) returned true? Good grief no!!! None is an object. It has a type, NoneType. It's *not* a string, or a float, or an int, or a list, so why would you want isinstance() to *lie* and say that it is? Python is good for testing these sorts of ideas: >>> _isinstance = isinstance >>> def isinstance(obj, type): ... if obj is None: return True ... return _isinstance(obj, type) ... >>> x = "parrot" >>> if isinstance(x, str): ... print x.upper() ... PARROT >>> x = None >>> if isinstance(x, str): print x.upper() ... Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'upper' -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 02:34:00 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 16:34:00 +1000 Subject: Question about None References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> Message-ID: <02433a8b$0$20629$c3e8da3@news.astraweb.com> Jean-Michel Pichavant wrote: > >> def setNext(nxt): >> assert nxt==None or isinstance(nxt, Node), "next must be a Node" >> self.next = nxt >> >> works ok, but it's uglier than it ought to be. >> >> > I don't find it that ugly. It's accurate, easy to read and understand. Actually, it's inaccurate. There are *three* bugs in that code, two in the same line. (Admittedly, one of the three is closer to a nitpick than a bug.) You already allude to one of them: > "What else ?" would say a famous coffee representative. > If you like perfection, replace nxt==None by nxt is None. Delete the "if you like perfection" part. Testing for equality against None in this case is simply *wrong*. Arbitrary objects can be made to test equal to None -- for instance, the Null object pattern. Unless you wish to allow such "null" objects as well as None, then "nxt == None" does not do what you want to do: it fails to reject some things that should be rejected. The second bug is that the line uses assert for runtime value/type testing. That's bad, because asserts are disabled when you run Python with the optimisation flag. That means that your program will stop performing the necessary test. assert is for testing program logic[1], not argument testing. If you're ever tempted to write an if...elif...else block that includes the comment, "this should never happen, but just in case" then you have a good candidate for an assert. A good use for assert is for checking that your program logic is correct, not for testing user-arguments: def process(text): for word in text.split(): word = somefunction(word) # say that it's important that word contains no newlines # you're sure that somefunction() *won't* introduce any, # but you want to be positive assert "\n" not in word do_something_with(word) In this case, assert is appropriate: the code *should* work if the assert is disabled, but it will give you some protection from bugs in your code. Whenever you're tempted to use assert, ask yourself "if I deleted this test from my code, would the program still run correctly?". If the answer is "possibly not", then don't use an assert. The third bug (the nitpick) is a bug in the API: you name the argument "nxt" with no e, but in the error message, you call it "next" with an e. The fact that any intelligent person should be able to guess what parameter the error is referring to doesn't make it less wrong. So, fixing the three issues: def setNext(next): if not (next is None or isinstance(next, Node)): raise ValueError("next must be a Node") self.next = next [1] Arguably, it's also good for poor-man's unit testing when you're too lazy to write proper tests. -- Steven From randall at tnr.cc Sat Jun 13 03:23:37 2009 From: randall at tnr.cc (Randall Smith) Date: Sat, 13 Jun 2009 02:23:37 -0500 Subject: moving Connection/PipeConnection between processes Message-ID: I've got a situation in which I'd like to hand one end of a pipe to another process. First, in case you ask why, a spawner process is created early before many modules are imported. That spawner process is responsible for creating new processes and giving a proxy to the parent process. (h1-1 <-- Pipe() --> h1-2) |------------------------> child1 |(s1 < Pipe() > s2) parent -> spawner -> |--> child2 |(h2-1) <-- Pipe() --> (h2-2) |----------------------| |------------------------> child3 (h3-1 <-- Pipe() --> h3-2) When I try to pass Connection h1-1 to the parent using Connection s1, I get an error: TypeError: Required argument 'handle' (pos 1) not found This error is from unpickling the Connection h1-1. You can duplicate the error like this: pickled_connection = pickle.dumps(h1-1, 2) pickle.loads(pickled_connection) # raises the same error Looking at the pickle docs, I wonder if this could be resolved by adding a __getnewargs__ method to _multiprocessing.Connection. But even if that would work I couldn't do it now since it's an extension module. I've thought about trying to recreate the Connection. Looks like it should be possible with Connection.fileno(). The Unix portion looks easy, but the win32 portion does not. So if it's possible, what's the best way to pass a Connection to another process? Randall From mk.fraggod at gmail.com Sat Jun 13 04:11:47 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 14:11:47 +0600 Subject: moving Connection/PipeConnection between processes References: Message-ID: <20090613141147.1ed3667d@coercion> On Sat, 13 Jun 2009 02:23:37 -0500 Randall Smith wrote: > I've got a situation in which I'd like to hand one end of a pipe to > another process. First, in case you ask why, a spawner process is > created early before many modules are imported. That spawner process is > responsible for creating new processes and giving a proxy to the parent > process. > ... > > Looking at the pickle docs, I wonder if this could be resolved by adding > a __getnewargs__ method to _multiprocessing.Connection. But even if > that would work I couldn't do it now since it's an extension module. > I've thought about trying to recreate the Connection. Looks like it > should be possible with Connection.fileno(). The Unix portion looks > easy, but the win32 portion does not. > > So if it's possible, what's the best way to pass a Connection to another > process? Pickle has nothing to do with the problem since it lay much deeper: in the OS. From kernel point of view, every process has it's own "descriptor table" and the integer id of the descriptor is all the process gets, so when you say "os.pipe()" kernel actually gives you a number which is completely meaningless for any other process - it either doesn't exists in it's descriptor table or points to something else. So, what you actually need is to tell the kernel to duplicate underlying object in another process' table (with it's own numbering), which is usually done via special flag for sendmsg(2) in C, so you should probably look out for py implementation of this call, which I haven't stumbled upon, but, admittely, never looked for. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jenigirly at gmail.com Sat Jun 13 04:39:27 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:39:27 -0700 (PDT) Subject: distutils extension configuration problem References: Message-ID: <41e1431c-d486-41d1-a5ac-7514f7df7743@d2g2000pra.googlegroups.com> On May 27, 2:10?am, Ron Garret wrote: > I'm trying to build PyObjC on an Intel Mac running OS X 10.5.7. ?The > build is breaking because distutils seems to want to build extension > modules as universal binaries, but some of the libraries it depends on > are built for intel-only, i.e.: > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ python2.6 > setup.py build > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils > /dist.py:266: UserWarning: Unknown distribution option: 'options' > ? warnings.warn(msg) > running build > running build_py > running build_ext > building 'ScreenSaver._inlines' extension > gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk-g > -bundle -undefined dynamic_lookup > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o -o > build/lib.macosx-10.3-i386-2.6/ScreenSaver/_inlines.so -framework > ScreenSaver > ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file > is not of required architecture for architecture ppc > collect2: ld returned 1 exit status > lipo: can't open input file: > /var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-//ccMFYRkt.out (No such > file or directory) > error: command 'gcc' failed with exit status 1 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o: Mach-O > universal binary with 2 architectures > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture ppc): Mach-O object ppc > build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for > architecture i386): ? Mach-O object i386 > > [ron at mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file > /usr/local/lib/libtiff.dylib > /usr/local/lib/libtiff.dylib: Mach-O dynamically linked shared library > i386 > > How do I get distutils to stop trying to build extensions as universal > binaries? > > Thanks, > rg Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:39:45 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:39:45 -0700 (PDT) Subject: Can't run PyQt apps with MacPython References: <25cdb69b-689c-4cfe-a378-3016b3d50e50@s21g2000vbb.googlegroups.com> Message-ID: <684fce61-7e9d-4f9d-a4dd-0fa6637f4d47@u9g2000prd.googlegroups.com> On May 13, 8:53?pm, Morad wrote: > I recently got a new MacBook Pro with Leopard, and would like to > develop using Python and PyQt. I installed the latest QtSDK, updated > MacPython to V 2.5.4 and then proceeded to install SIP and PyQt as > described in Mark Summerfield's book on PyQt Programming. Everything > went fine and none of the scripts complained. However when I want to > run a demo app, I get the error message "Fatal Python error: > Interpreter not initialized (version mismatch?) / Abort Trap". Anybody > can help? Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:40:00 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:40:00 -0700 (PDT) Subject: Help AIX 5.3 build on Python-3.1a2 References: Message-ID: <97dae51e-4020-448f-90db-d9fdccdfaf99@k19g2000prh.googlegroups.com> On Apr 26, 2:14?pm, Jeroen Ruigrok van der Werven wrote: > -On [20090425 19:17], Aahz (a... at pythoncraft.com) wrote: > > >In article , > > wrote: > >>"Include/token.h", line 42.9: 1506-213 (S) Macro name TILDE cannot be > >>redefined. > >>"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line > >>250 of /usr/include/sys/ioctl.h. > > >Can you try trimming down the compilation to a small reproducible case? > > I thought it was already clear from what was provided? > > Include/token.h has a #define for TILDE and apparently AIX has a #define for > TILDE in /usr/include/sys/ioctl.h as well. So you can a redefinition. > > One way around it, depending how AIX protects headers might be to change > Include/token.h to either: > > #if defined(_SYS_IOCTL_H_) > #undef TILDE > #define TILDE ? ? ? ? ? 32 > #endif > > or > > #if defined(aix) > #undef TILDE > #define TILDE ? ? ? ? ? 32 > #endif > > -- > Jeroen Ruigrok van der Werven / asmodai > ????? ?????? ??? ?? ??????http://www.in-nomine.org/|http://www.rangaku.org/| GPG: 2EAC625B > A rose is a rose is a rose is a rose... Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:42:22 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:42:22 -0700 (PDT) Subject: moving Connection/PipeConnection between processes References: <20090613141147.1ed3667d@coercion> Message-ID: On Jun 13, 1:11?pm, Mike Kazantsev wrote: > On Sat, 13 Jun 2009 02:23:37 -0500 > > > > > > Randall Smith wrote: > > I've got a situation in which I'd like to hand one end of a pipe to > > another process. ?First, in case you ask why, a spawner process is > > created early before many modules are imported. ?That spawner process is > > responsible for creating new processes and giving a proxy to the parent > > process. > > ... > > > Looking at the pickle docs, I wonder if this could be resolved by adding > > a __getnewargs__ method to _multiprocessing.Connection. ?But even if > > that would work I couldn't do it now since it's an extension module. > > I've thought about trying to recreate the Connection. ?Looks like it > > should be possible with Connection.fileno(). ?The Unix portion looks > > easy, but the win32 portion does not. > > > So if it's possible, what's the best way to pass a Connection to another > > process? > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Check http://www.voipsipsdk.com its a good one. From jenigirly at gmail.com Sat Jun 13 04:42:38 2009 From: jenigirly at gmail.com (jenifer adam) Date: Sat, 13 Jun 2009 01:42:38 -0700 (PDT) Subject: Lexical scope: converting Perl to Python References: <20090613114431.6f4893c7@coercion> Message-ID: On Jun 13, 10:44?am, Mike Kazantsev wrote: > On Fri, 12 Jun 2009 22:02:53 -0700 (PDT) > > > > > > Andrew Savige wrote: > > I'd like to convert the following Perl code to Python: > > > ?use strict; > > ?{ > > ?? my %private_hash = ( A=>42, B=>69 ); > > ?? sub public_fn { > > ???? my $param = shift; > > ???? return $private_hash{$param}; > > ?? } > > ?} > > ?print public_fn("A");??????? # good:? prints 42 > > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > > ... > > > What is the Pythonic equivalent of Perl's lexical scope, as > > illustrated by the code snippet above? > > If you're using scope for garbage-collecting purposes, there's "with" > statement and contextlib: > > ? from contextlib import contextmanager > > ? @contextmanager > ? def get_hash(): > ? ? complex_hash = dict(A=42, B-69) > ? ? try: yield complex_hash > ? ? except Exception as ex: > ? ? ? del complex_hash # complex destructor ;) > ? ? ? raise ex > > ? with get_hash() as hash: > ? ? # do stuff with hash > > Note that this only makes sense if you need to implement some complex > operation on hash destruction, and do that whatever-happens-inside-with > to close the object, obviously not the case with simple dict above. > > And if you want to obfuscate one part of your code from another, you'll > probably have better luck with languages like java, since no one seem > to care about such stuff with python, so it'd be a hack against the > language, at best. > Why would you want to hide the code from itself, anyway? It's not like > you'd be able to accomplish it - code can easily grep it's process body > in memory and harvest all the "private" values, so I'd suggest getting > some fresh air when you start to feel like doing that. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Check http://www.voipsipsdk.com its a good one. From piet at cs.uu.nl Sat Jun 13 04:46:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 13 Jun 2009 10:46:09 +0200 Subject: How should I compare two txt files separately coming from windows/dos and linux/unix References: <2ed92c9d-8de2-47fc-8584-ac78b69d274c@x1g2000prh.googlegroups.com> <50697b2c0906102044w32f26c4at2cf257f5cc4ac0e6@mail.gmail.com> Message-ID: >>>>> Emile van Sebille (EvS) wrote: >EvS> On 6/11/2009 12:09 AM higer said... >>> Tool can certainly be used to compare two files,but I just want to >>> compare them using Python code. >>> >EvS> difflib? If I understand correctly the OP just wanted to know whether two files were equal, not what the differences would be. In that case difflib is overkill. On the other hand `equal' has many meanings. Ignoring line endings is one option, ignoring trailing whitespace could be another one. Yet another one could be normalizing the character encoding, etc. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From niels.egberts at gmail.com Sat Jun 13 05:02:20 2009 From: niels.egberts at gmail.com (Niels Egberts) Date: Sat, 13 Jun 2009 11:02:20 +0200 Subject: uncompress base64-gzipped string In-Reply-To: References: Message-ID: On Sat, Jun 13, 2009 at 4:38 AM, John Machin wrote: > | >>> guff[:100] > | '\x1b\x00\x00\x00\x1b\x00\x00\x00\x1b\x00\x00\x00 [snip] > > What a long journey: parse xml, base64 decode, gunzip, > and you're still not home; next stop is struct.unpack ... > > HTH, > John Thanks for the help! I dont think I could have done that. And thanks for the tip on struct.unpack I managed to get a list of integers to work with. Niels From simon212 at gmx.de Sat Jun 13 05:12:02 2009 From: simon212 at gmx.de (Simon) Date: Sat, 13 Jun 2009 11:12:02 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> Message-ID: <4A336D62.6070302@gmx.de> Christian Heimes wrote: > Simon schrieb: >> Christian Heimes wrote: >>> Simon wrote: >>>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 (within >>>> openSUSE 11.1 x86_64) via 'make altinstall'. >>>> >>>> First, I tried to configure with the following flags: >>>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>>> This provoked an error during compilation via make (sorry, the list was >>>> so long, but I will post it, if it helps). >>> --enable-framework is for Mac OS X only. >>> >>>> Second, configured again without any flags. The installation by 'make >>>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>>> too. So, I got my parallel installation. >>> You have chosen the correct and canonical way to install a parallel >>> installation of Python. >>> >>>> However, I cannot import modules like Tkinter or readline within >>>> python2.4. >>> You must install the development library of tk, readline, zlib and >>> libbz2 prior to configure && make. >>> >>> Try this on your box: >>> >>> zypper install gcc make autoconf automake libtool zlib-devel >>> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >>> libopenssl-devel >>> >> >> Unfortunately, I got the following errors, while compiling via make. >> Please, see attached text file for details about everything I did from >> installing the missing packages via zypper until make. > > zypper should have installed all necessary dependencies, including a > whole bunch of X11 headers. Something seems to be wrong on your system > or SuSE's package dependencies. > I know why I dislike SuSE. :) Although I started my Linux career 12 > years ago with SuSE I prefer Debian based systems since Woody came out > in 2002. :) > >> X11 says: >> Program 'X11' is present in package 'xorg-x11', which is installed on >> your system. > > zypper search X11 | grep devel > ... > zypper install xorg-x11-devel > > That should (hopefully) do the trick. On a Debian based systems it's > much easier to install all Python dependencies with "apt-get build-dep > python2.5" > > To quote SuSE: "Have a lot of fun ..." > > Und viel Gl?ck! > > Christian > Danke :) On Monday, I will be able to tell if it worked out, or if I have to try a new strategy, e.g. to convince the admin about (K)ubuntu. From anthra.norell at bluewin.ch Sat Jun 13 05:30:37 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 13 Jun 2009 11:30:37 +0200 Subject: CAD file format specifications? In-Reply-To: <4A32AD8D.2010000@geniusdv.com> References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> Message-ID: <4A3371BD.70508@bluewin.ch> Andres Acosta wrote: > HI there Anthara have you checked out www.Blender.org, It is open > source and accepts a lot of your formats. for import and export. > Anrdres > Anthra Norell wrote: >> Hi, >> Anyone working with CAD who knows about numeric data entry? I have >> 3d coordinates of a construction site on a slope (borders, setbacks >> and isometric elevation lines). Someone made me aware of Google's >> Sketch Up. It looks very attractive for the purpose of architectural >> planning, especially suited to create visual impressions. Doodling >> seems easy. But I have to start with modeling the terrain and the >> envelope and the only way to do that seems to be in one of several >> CAD file formats (skp, dwg, dxf, 3ds, ddf and dem). So I need to cast >> my numbers into one of these formats. Any suggestions? >> >> Thanks >> >> Frederic >> > > Andres, Thanks for the tip. I wasn't aware of Blender. The web page looks promising. I downloaded it and am going to have a look at it. Frederic From koranthala at gmail.com Sat Jun 13 07:42:16 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 04:42:16 -0700 (PDT) Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> Message-ID: <5c4984a4-bd51-424b-8165-7b226eaddb96@o5g2000prh.googlegroups.com> On Jun 13, 10:25?am, Mike Kazantsev wrote: > On Thu, 11 Jun 2009 22:35:15 -0700 > Dennis Lee Bieber wrote: > > > > > On Thu, 11 Jun 2009 08:44:24 -0500, "Strax-Haber, Matthew (LARC-D320)" > > declaimed the following in > > gmane.comp.python.general: > > > > I sent this to the Tutor mailing list and did not receive a response. > > > Perhaps one of you might be able to offer some sagely wisdom or pointed > > > remarks? > > > > Please reply off-list and thanks in advance. Code examples are below in > > > plain text. > > > ? ?Sorry -- you post to a public forum, expect to get the response on a > > public forum... > > > > > My program runs interactively by allowing the user to directly > > > > interact with the python prompt. This program has a runAll() method > > > > that runs a series of subprocesses with a cap on how many instances > > > > are running at a time. My intent is to allow the user to use Ctrl-C to > > > > break these subprocesses. Note that while not reflected in the demo > > > ? ?Are they subprocesses or threads? Your sample code seems to be using > > threads. > > > ? ?When using threads, there is no assurance that any thread other than > > the main program will receive a keyboard interrupt. > > In fact, no thread other than the main will get interrupt. > > > > > > def runAll(): > > > ? ? workers = [ Thread(target = runSingle, args = [i]) > > > ? ? ? ? ? ? for i in xrange(MAX_SUBPROCS + 1) ] > > > ? ? try: > > > ? ? ? ? for w in workers: > > > ? ? ? ? ? ? w.start() > > > ? ? except KeyboardInterrupt: > > > ? ? ? ? ## I want this to be shown on a KeyboardInterrupt > > > ? ? ? ? print '********* stopped midway ********' > > > ? ?You are unlikely to see that... After you start the defined worker > > /threads/ (which doesn't take very long -- all threads will be started, > > but some may immediately block on the semaphore) this block will exit > > and you will be at... > > > > ? ? for w in workers: > > > ? ? ? ? w.join() > > > ? ?... a .join() call, which is the most likely position at which the > > keyboard interrupt will be processed, killing the main program thread > > and probably generating some errors as dangling active threads are > > forceably killed. > > There was quite interesting explaination of what happens when you send > ^C with threads, posted on concurrency-sig list recently: > > ?http://blip.tv/file/2232410 > ?http://www.dabeaz.com/python/GIL.pdf > > Can be quite shocking, but my experience w/ threads only confirms that. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Thank you very much for the link Mike. Are there other videos/audio like this? I am learning more from these videos than by experience alone. I did find one - http://www.awaretek.com/python/ - are there other links? From ivlenin at gmail.com Sat Jun 13 07:48:28 2009 From: ivlenin at gmail.com (I V) Date: 13 Jun 2009 13:48:28 +0200 Subject: Lexical scope: converting Perl to Python References: Message-ID: <4a33920c@news.x-privat.org> On Fri, 12 Jun 2009 22:02:53 -0700, Andrew Savige wrote: > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. You might try: def public_fn(param): private_hash = publicfn.private_hash return private_hash[param] public_fn.private_hash = {'A':42, 'B':69} (You don't have to assign public_fn.private_hash to a local variable, but you might want to, to avoid extra typing, if you refer to private_hash more than a couple of times in the function). From steve at REMOVETHIS.cybersource.com.au Sat Jun 13 08:15:21 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 13 Jun 2009 22:15:21 +1000 Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <4a3270b8$1_7@news.bluewin.ch> Message-ID: <02438a8b$0$20617$c3e8da3@news.astraweb.com> Boris Borcic wrote: > This reminds me of an early programming experience that left me with a > fascination. At a time where code had to fit in a couple dozens kilobytes, > I once had to make significant room in what was already very tight and > terse code. Code factoring *did* provide the room in the end, but the > fascinating part came before. > > There was strictly no redundancy apparent at first, and finding a usable > one involved contemplating code execution paths for hours until some > degree of similarity was apparent between two code path families. And > then, the fascinating part, was to progressively mutate both *away* from > minimality of code, in order to enhance the similarity until it could be > factored out. > > I was impressed; in various ways. First; that the effort could be > characterized quite mechanically and in a sense stupidly as finding a > shortest equivalent program, while the subjective feeling was that the > task exerted perceptive intelligence to the utmost. Second; by the notion > that a global constraint of code minimization could map more locally to a > constraint that drew code to expand. Third; that the process resulted in > bottom-up construction of what's usually constructed top-down, mimicking > the willful design of the latter case, eg. an API extension, as we might > call it nowadays. This is much the same that happens in maximisation problems: the value gets trapped in a local maximum, and the only way to reach a greater global maximum is to go downhill for a while. I believe that hill-climbing algorithms allow some downhill movement for just that reason. Genetic algorithms allow "mutations" -- and of course real evolution of actual genes also have mutation. -- Steven From nick at craig-wood.com Sat Jun 13 08:29:35 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 13 Jun 2009 07:29:35 -0500 Subject: Lexical scope: converting Perl to Python References: Message-ID: Andrew Savige wrote: > > I'd like to convert the following Perl code to Python: > > ?use strict; > ?{ > ?? my %private_hash = ( A=>42, B=>69 ); > ?? sub public_fn { > ???? my $param = shift; > ???? return $private_hash{$param}; > ?? } > ?} > ?print public_fn("A");??????? # good:? prints 42 > ?my $x = $private_hash{"A"};? # error: good, hash not in scope > > The real code is more complex; the above is a simplified example. > > Notice that this code uses Perl's lexical scope to hide the > %private_hash variable, but not the public_fn() function. > > While I could convert this code to the following Python code: > > ?private_hash = dict( A=42, B=69 ) > ?def public_fn(param): > ?? return private_hash[param] > ?print public_fn("A")???? # good:? prints 42 > ?x = private_hash["A"]??? # works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable so that it is known only inside public_fn. > > Of course, I could hide the hash like so: > > ?def public_fn(param): > ?? private_hash = dict( A=42, B=69 ) > ?? return private_hash[param] > > yet I'm not happy with that either because of the repeated > initialization the hash each time the function is called. > > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? Either _private_hash = dict( A=42, B=69) def public_fn(param): return _private_hash[param] Or def public_fn(param, _private_hash = dict( A=42, B=69)): return _private_hash[param] Is probably the pythonic equivalents. Note that private_hash starts with an underscore which means it won't be exported from a module by default and it is a convention that it is private and shouldn't be fiddled with. I'd probably go with the latter of the two examples. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mk.fraggod at gmail.com Sat Jun 13 08:35:48 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sat, 13 Jun 2009 18:35:48 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <5c4984a4-bd51-424b-8165-7b226eaddb96@o5g2000prh.googlegroups.com> Message-ID: <20090613183548.017849b5@coercion> On Sat, 13 Jun 2009 04:42:16 -0700 (PDT) koranthala wrote: > Are there other videos/audio like this? I am learning more from these > videos than by experience alone. Indeed, it is a very interesting presentation, but I'm afraid I've stumbled upon it just as you did, but on concurrency-sig mailing list. It's a relatively new list (now hosted on mail.python.org), not specifically dedicated to podcasts or, for that matter, any implementation details. I haven't seen any other material like this there. > I did find one - http://www.awaretek.com/python/ - are there other > links? Thanks for sharing this link, although I prefer such information in written form - it's easier/faster to work with and much more accessible. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From piet at cs.uu.nl Sat Jun 13 09:06:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 13 Jun 2009 15:06:09 +0200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: >>>>> Nikolaus Rath (NR) wrote: >NR> Is there a way to have the obj variable (that is created in dostuff()) >NR> destroyed earlier than at the end of the program? As you can see, I >NR> already tried to explicitly call the garbage collector, but this does >NR> not help. The exact time of the destruction of objects is an implementation detail and should not be relied upon. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From bborcic at gmail.com Sat Jun 13 09:48:54 2009 From: bborcic at gmail.com (K4NTICO) Date: Sat, 13 Jun 2009 06:48:54 -0700 (PDT) Subject: Making the case for repeat References: <5c11eb0a-0aba-4c34-95d4-a5c705e55838@k8g2000yqn.googlegroups.com> <4a3270b8$1_7@news.bluewin.ch> <02438a8b$0$20617$c3e8da3@news.astraweb.com> Message-ID: <6efc3531-dbf2-4b8c-a2f0-a756ef2411f5@c36g2000yqn.googlegroups.com> On 13 juin, 14:15, Steven D'Aprano wrote: > Boris Borcic wrote: > > This reminds me of an early programming experience that left me with a > > fascination. At a time where code had to fit in a couple dozens kilobytes, > > I once had to make significant room in what was already very tight and > > terse code. Code factoring *did* provide the room in the end, but the > > fascinating part came before. > > > There was strictly no redundancy apparent at first, and finding a usable > > one involved contemplating code execution paths for hours until some > > degree of similarity was apparent between two code path families. And > > then, the fascinating part, was to progressively mutate both *away* from > > minimality of code, in order to enhance the similarity until it could be > > factored out. > > > I was impressed; in various ways. First; that the effort could be > > characterized quite mechanically and in a sense stupidly as finding a > > shortest equivalent program, while the subjective feeling was that the > > task exerted perceptive intelligence to the utmost. Second; by the notion > > that a global constraint of code minimization could map more locally to a > > constraint that drew code to expand. Third; that the process resulted in > > bottom-up construction of what's usually constructed top-down, mimicking > > the willful design of the latter case, eg. an API extension, as we might > > call it nowadays. > > This is much the same that happens in maximisation problems: the value gets > trapped in a local maximum, and the only way to reach a greater global > maximum is to go downhill for a while. > > I believe that hill-climbing algorithms allow some downhill movement for > just that reason. Genetic algorithms allow "mutations" -- and of course > real evolution of actual genes also have mutation. > > -- > Steven Indeed exactly. But it wasn't quite the same to think through it first hand, as I said that the subjective feeling was "perceptive intelligence got exercized to the utmost". To illustrate, it is very much the memory of that experience - the perceptive training - that made me notice, for another high point, what I think to be a common factor worthy of capture between the sociology of Archimedes' Eureka and that of Einstein's E=mc^2, let's just describe Archimedes' case in the right manner: There is a trading port city, and thus citizens who are experts in both floating ships on the seas and of weighting goods on the scale in the markets. And then comes Archimedes who says : "hey, experts, I show you that these two aeras of your expertise that of course you think have nothing to do with each other except for what you know so well and clear - they are in fact two faces of a single coin that you ignore." And thus a codeful question : "What does F(Syracuse) hear if F(Eureka) is the = in E=mc^2 ?" And a more serious one : what happens to the potential for similar discoveries, when society specializes expertise to the point that there isn't any more any community of "simultaneous experts" ? Cheers, BB -- "Hope achieves the square root of the impossible" From benjamin at python.org Sat Jun 13 10:46:28 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 13 Jun 2009 09:46:28 -0500 Subject: [RELEASED] Python 3.1 Release Candidate 2 Message-ID: <1afaf6160906130746v2d951486v7a52d7b838070189@mail.gmail.com> On behalf of the Python development team, I'm happy to announce the second release candidate of Python 3.1. Python 3.1 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/dev/py3k/whatsnew/3.1.html or Misc/NEWS in the Python distribution. This is a release candidate, and as such, we do not recommend use in production environments. However, please take this opportunity to test the release with your libraries or applications. This will hopefully discover bugs before the final release and allow you to determine how changes in 3.1 might impact you. If you find things broken or incorrect, please submit a bug report at http://bugs.python.org For more information and downloadable distributions, see the Python 3.1 website: http://www.python.org/download/releases/3.1/ See PEP 375 for release schedule details: http://www.python.org/dev/peps/pep-0375/ Enjoy, -- Benjamin Benjamin Peterson benjamin at python.org Release Manager (on behalf of the entire python-dev team and 3.1's contributors) From mwilson at the-wire.com Sat Jun 13 11:25:27 2009 From: mwilson at the-wire.com (Mel) Date: Sat, 13 Jun 2009 11:25:27 -0400 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: Gunter Henriksen wrote: [ ... ] > I guess to me, fundamentally, the interpretation of > tuple as a sequence whose elements have semantic meaning > implicitly defined by position is a relatively abstract > intrepretation whose value is dubious relative to the > value of immutability, since it seems like a shortcut > which sacrifices explicitness for the sake of brevity. The immutability makes it easier to talk about the semantic meanings. After you do > event_timestamp = (2009, 06, 04, 05, 02, 03) there's nothing that can happen to the tuple to invalidate > (year, month, day, hour, minute, second) = event_timestamp even though, as you say, there's nothing in the tuple to inform anybody about the year, month, day, ... interpretation. And of course there's nothing in a C struct object that isn't in the equivalent Python tuple. The difference is that the C compiler has arranged all the outside code that uses the struct object to use it in the correct way. The only object I've found in Python that truly replaces a struct object in C is a dict with string keys -- or an object that uses such a dict as its __dict__. Mel. From emailkgnow at gmail.com Sat Jun 13 11:26:24 2009 From: emailkgnow at gmail.com (Khalid) Date: Sat, 13 Jun 2009 08:26:24 -0700 (PDT) Subject: Python 3.1 Release Candidate 2 References: Message-ID: <94c36f68-b537-4bb2-a139-a9397d25bf6e@k17g2000prn.googlegroups.com> On Jun 13, 5:46?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy to announce the second > release candidate of Python 3.1. > > Python 3.1 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/dev/py3k/whatsnew/3.1.htmlor Misc/NEWS in the Python > distribution. > > This is a release candidate, and as such, we do not recommend use in production > environments. ?However, please take this opportunity to test the release with > your libraries or applications. ?This will hopefully discover bugs before the > final release and allow you to determine how changes in 3.1 might impact you. > If you find things broken or incorrect, please submit a bug report at > > ? ? ?http://bugs.python.org > > For more information and downloadable distributions, see the Python 3.1 website: > > ? ? ?http://www.python.org/download/releases/3.1/ > > See PEP 375 for release schedule details: > > ? ? ?http://www.python.org/dev/peps/pep-0375/ > > Enjoy, > -- Benjamin > > Benjamin Peterson > benjamin at python.org > Release Manager > (on behalf of the entire python-dev team and 3.1's contributors) GOOD NEWS ... THANKS From koranthala at gmail.com Sat Jun 13 11:49:52 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 08:49:52 -0700 (PDT) Subject: Good books in computer science? Message-ID: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Hi all, I do understand that this is not a python question and I apologize for that straight up. But I am a full time follower of this group and I have seen very very brilliant programmers and solutions. I also want to be a good programmer - so this question. Which are the classic books in computer science which one should peruse? I have (a) Code Complete (b) GOF (c) Art of programming. Art of programming was too tough for me - and I couldnt understand much. The other two were good books - I understood and implemented quite a bit from both. What are the other books which I should peruse? Regards K From python at bdurham.com Sat Jun 13 12:27:22 2009 From: python at bdurham.com (python at bdurham.com) Date: Sat, 13 Jun 2009 12:27:22 -0400 Subject: Good books in computer science? In-Reply-To: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <1244910442.4624.1320224723@webmail.messagingengine.com> Timeless classics - highly recommended: Software Tools by Plaugher Mythical Man Month by Brooks Malcolm From tjreedy at udel.edu Sat Jun 13 12:27:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Jun 2009 12:27:45 -0400 Subject: Question about None In-Reply-To: <02433a8b$0$20629$c3e8da3@news.astraweb.com> References: <65d199b50906120705k153a66cbh3e726b5b6ae412cc@mail.gmail.com> <02433a8b$0$20629$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: [ snip excellent discussion of proper use of assert] > The third bug (the nitpick) is a bug in the API: you name the argument "nxt" > with no e, but in the error message, you call it "next" with an e. The fact > that any intelligent person should be able to guess what parameter the > error is referring to doesn't make it less wrong. > > So, fixing the three issues: > > def setNext(next): > if not (next is None or isinstance(next, Node)): > raise ValueError("next must be a Node") > self.next = next [counternit] Of course, next() is a builtin function and some consider reusing builtin names as bare names (versus attribute names) a bad habit. I think the OP had a good idea in using a variation, but should have been consistent. From Scott.Daniels at Acm.Org Sat Jun 13 12:29:02 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 13 Jun 2009 09:29:02 -0700 Subject: uncompress base64-gzipped string In-Reply-To: References: Message-ID: Niels Egberts wrote: > On Sat, Jun 13, 2009 at 4:38 AM, John Machin wrote: > ... > And thanks for the tip on struct.unpack I managed to get a list of > integers to work with. You might make do with array.fromstring (perhaps using .byteswap afterwards) to get your numbers if you are talking more than a handful. --Scott David Daniels Scott.Daniels at Acm.Org From http Sat Jun 13 12:56:18 2009 From: http (Paul Rubin) Date: 13 Jun 2009 09:56:18 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <7xocssvzrh.fsf@ruckus.brouhaha.com> koranthala writes: > Which are the classic books in computer science which one should > peruse? > I have (a) Code Complete (b) GOF (c) Art of programming. > > Art of programming was too tough for me - and I couldnt understand > much. The other two were good books - I understood and implemented > quite a bit from both. > What are the other books which I should peruse? Code Complete and GOF are software engineering books but not really CS books. TAOCP is a CS book but a bit old fashioned. Other classics: Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman (online at mitpress.mit.edu/sicp) From gallium.arsenide at gmail.com Sat Jun 13 13:23:38 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 10:23:38 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> Message-ID: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> On Jun 13, 2:29 am, Steven D'Aprano wrote: > Paul LaFollette wrote: > > 3) (this is purely philosophical but I am curious) > > Would it not be more intuitive if > > isinstance(None, ) returned true? > > Good grief no!!! > > None is an object. It has a type, NoneType. It's *not* a > string, or a float, or an int, or a list, so why would > you want isinstance() to *lie* and say that it is? Because you might want None to behave as though it were nothing at all. Paul LaFollette is probably thinking along the lines of formal logic or set theory. It's a little bit confused because programming isn't quite the same as math, and so it's a common question when designing and implementing programming languages how far to take certain abstractions. In some languages, nil, null, or none will try to behave as mathematically close to "nothing" (complete absence of anything) as possible, even though in reality they have to have some concrete implementation, such as perhaps being a singleton object. But mathematically speaking, it's intuitive that "nothing" would match any type. I find that it's somewhat like the confusion that often occurs regarding the all() function. Some people are surprised that all([]) returns True, but it's the same logic behind the truth of the statement "every element of the empty set is an integer". It's also true that every element of the empty set is a float. Or an elephant. John From koranthala at gmail.com Sat Jun 13 13:37:13 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 10:37:13 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: > Code Complete and GOF are software engineering books but not really > CS books. I understand and concur. Since I am a software engineer - coming in to software from a different background - what I am looking for is self- improvement books for a software engineer. This can include both CS and Software books - even though I found that CS books are much less understandable to me :-) From http Sat Jun 13 13:49:12 2009 From: http (Paul Rubin) Date: 13 Jun 2009 10:49:12 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <7xr5xovxbb.fsf@ruckus.brouhaha.com> John Yeung writes: > Because you might want None to behave as though it were nothing at all. Sure, you might also want strings to behave as if they were ints, but wishing doesn't make it so. > But mathematically speaking, it's intuitive that "nothing" would match > any type. Completely wrong. The concept you're thinking of in denotational semantics is called "bottom", but bottom is not a value that functions can compute and return. It is really the absence of a value. We would say that a function semantically returns bottom, if calling does something like loop forever (never return), or it makes the program crash, or something like that. None is a value which in Haskell has a particular type. In some other languages, there are None-like values in more than one type, like in Haskell, for any type there is a Nothing for the Maybe of that type, but they all are of differing types, just like Python has an integer 0 and a floating point 0 that are of differing types. > I find that it's somewhat like the confusion that often occurs > regarding the all() function. It's the other way though, all([])=True makes sense, isinstance(None,int) does not. From http Sat Jun 13 13:55:01 2009 From: http (Paul Rubin) Date: 13 Jun 2009 10:55:01 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xr5xovxbb.fsf@ruckus.brouhaha.com> Message-ID: <7xiqj0vx1m.fsf@ruckus.brouhaha.com> Paul Rubin writes: > crash, or something like that. None is a value which in Haskell has a I got ahead of myself, of course I meant Python (the *next* sentence was going to mention Haskell). The corresponding concept in Haskell is called Nothing, which lives in a type functor called Maybe. I don't have time to go into it right now but there is a notion among language weenies these days that the presence of something like None (in Python) or Null (in Java, SQL, etc) is a wart in a language and that it's preferable to have something like Maybe. From randall at tnr.cc Sat Jun 13 14:02:24 2009 From: randall at tnr.cc (Randall Smith) Date: Sat, 13 Jun 2009 13:02:24 -0500 Subject: moving Connection/PipeConnection between processes In-Reply-To: <20090613141147.1ed3667d@coercion> References: <20090613141147.1ed3667d@coercion> Message-ID: Mike Kazantsev wrote: > On Sat, 13 Jun 2009 02:23:37 -0500 > Randall Smith wrote: > >> I've got a situation in which I'd like to hand one end of a pipe to >> another process. First, in case you ask why, a spawner process is >> created early before many modules are imported. That spawner process is >> responsible for creating new processes and giving a proxy to the parent >> process. >> > ... >> Looking at the pickle docs, I wonder if this could be resolved by adding >> a __getnewargs__ method to _multiprocessing.Connection. But even if >> that would work I couldn't do it now since it's an extension module. >> I've thought about trying to recreate the Connection. Looks like it >> should be possible with Connection.fileno(). The Unix portion looks >> easy, but the win32 portion does not. >> >> So if it's possible, what's the best way to pass a Connection to another >> process? > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > As I was referring to earlier, Unix is easy. fd = mycon.fileno() new_con = _multiprocessing.Connection(os.dup(fd)) But Windows? The implementation of the pipe creation is on line 167 of connection.py. I don't know where to start. Randall From no.email at please.post Sat Jun 13 14:11:11 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 18:11:11 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? Message-ID: Switching from Perl here, and having a hard time letting go... Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, second, and last element in that array. In Perl I could write: my @wanted = @foo[3, 7, 1, -1]; I was a bit surprised when I got this in Python: >>> wanted = foo[3, 7, 1, -1] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers Granted, Perl's syntax is often obscure and hard-to-read, but in this particular case I find it quite transparent and unproblematic, and the fictional "pythonized" form above even more so. The best I've been able to come up with in Python are the somewhat Perl-like-in-its-obscurity: >>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) or the clearer but unaccountably sesquipedalian >>> wanted = [foo[i] for i in 3, 7, 1, -1] >>> wanted = [foo[3], foo[7], foo[7], foo[-1]] Are these the most idiomatically pythonic forms? Or am I missing something better? TIA! kynn From nate at nathanstoddard.com Sat Jun 13 14:13:15 2009 From: nate at nathanstoddard.com (Nathan Stoddard) Date: Sat, 13 Jun 2009 18:13:15 +0000 (UTC) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: On Sat, 13 Jun 2009 08:49:52 -0700, koranthala wrote: > Hi all, > I do understand that this is not a python question and I apologize > for that straight up. > But I am a full time follower of this group and I have seen very > very brilliant programmers and solutions. > I also want to be a good programmer The best way to become a good programmer is to program. Write a lot of code; work on some large projects. This will improve your skill more than anything else. It's also important to learn new languages regularly. I recommend to learn C, Python, and Lisp first. > Which are the classic books in computer science which one should > peruse? A list of some good books is at steve.yegge.googlepages.com/ten-great- books. Also read programming blogs. -- Nathan Stoddard, http://nathanstoddard.com From jackdied at gmail.com Sat Jun 13 15:17:56 2009 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Jun 2009 15:17:56 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: On Sat, Jun 13, 2009 at 2:11 PM, kj wrote: > > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. ?In Perl I could write: > > ?my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > >>>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > ?File "", line 1, in > TypeError: list indices must be integers > > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > >>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > >>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? ?Or am I missing > something better? > There is only so much room in the syntax for common cases before you end up with ... perl (no offense intended, I'm a perl monk[1]). The Python grammar isn't as context sensitive or irregular as the perl grammar so mylist[1,2,3] so the "1,2,3" tuple is always interpreted as a tuple and the square brackets always expect an int or a slice. Not including special cases everywhere means there isn't a short way to handle special cases but it also means human readers have to remember fewer special cases. Perl and Python make different tradeoffs in that respect. -Jack [1] http://www.perlmonks.org/?node_id=111952 From nick at craig-wood.com Sat Jun 13 15:29:34 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 13 Jun 2009 14:29:34 -0500 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: kj wrote: > > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > > >>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers You've just tried to index a list with a tuple... If foo was a dictionary then this might make sense. > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > > >>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > > >>> wanted = [foo[i] for i in 3, 7, 1, -1] > >>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? Or am I missing > something better? Firstly run "import this" at the python interactive interpreter to remind youself of the philosophical differences between perl and python. I think the philosophy of python is the major reason why it is such a good language. As I transitioned from perl to python it took me a while to let go of perlisms, and get used to writing a little bit more code (usually of the order of a few characters only) but which was much much clearer. Perl is full of cleverness which give you great pleasure to write as a programmer. However when you or someone else looks at that code later they don't get that same pleasure - horror is more likely the reaction! Python just isn't like that. I'd probably write wanted = foo[3], foo[7], foo[1], foo[-1] (assuming you didn't mind having a tuple rather than a list) or maybe this wanted = [ foo[i] for i in 3, 7, 1, -1 ] However I can't think of the last time I wanted to do this - array elements having individual purposes are usually a sign that you should be using a different data structure. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From brian at sweetapp.com Sat Jun 13 15:44:02 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 20:44:02 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <4A340182.5070609@sweetapp.com> kj wrote: > > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; Could you explain your use case? It could be that a list isn't the appropriate data structure. Cheers, Brian From arnodel at googlemail.com Sat Jun 13 15:59:49 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 13 Jun 2009 20:59:49 +0100 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: kj writes: > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; > > I was a bit surprised when I got this in Python: > >>>> wanted = foo[3, 7, 1, -1] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers > > Granted, Perl's syntax is often obscure and hard-to-read, but in > this particular case I find it quite transparent and unproblematic, > and the fictional "pythonized" form above even more so. > > The best I've been able to come up with in Python are the somewhat > Perl-like-in-its-obscurity: > >>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > > or the clearer but unaccountably sesquipedalian > >>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > > Are these the most idiomatically pythonic forms? Or am I missing > something better? You're missing operator.itemgetter: >>> from operator import itemgetter >>> foo = "spam & eggs" >>> itemgetter(3, 7, 1, -1)(foo) ('m', 'e', 'p', 's') >>> -- Arnaud From travisaltman at gmail.com Sat Jun 13 16:05:32 2009 From: travisaltman at gmail.com (Travis Altman) Date: Sat, 13 Jun 2009 16:05:32 -0400 Subject: https post request Message-ID: i'm trying to make a https post request, i'm following the example linked below. http://www.java2s.com/Tutorial/Python/0420__Network/SendinganHTTPPOSTRequestfromaPythonScript.htm i'm trying to make the https post request to netflix.com, below is my code 1 import httplib 2 3 # def statement used to parse response from web server 4 def printText(txt): 5 lines = txt.split('\n') 6 for lines in lines: 7 print line.strip() 8 9 # connect to web server 10 httpServ = httplib.HTTPSConnection("https://www.netflix.com", 443) 11 print httpServ 12 httpServ.connect() 13 14 # specifying the exact login URL 15 16 request = "test" 17 18 httpServ.request('POST', \ 19 '/Login', \ 20 'nextpage=http%3A%2F%2Fwww.netflix.com %2F&SubmitButton=Click+Here+to+Continue&movieid=&trkid=&email=email% 40gmail.com&password1=supersecret % request') 21 22 # response 23 24 response = httpServ.getresponse() 25 26 print response 27 if response.status == httplib.OK: 28 printText (response.read()) 29 30 httpServ.close() getting the following errors, any suggestions? Traceback (most recent call last): File "printerPythonScript.py", line 12, in httpServ.connect() File "/usr/lib/python2.5/httplib.py", line 1130, in connect sock.connect((self.host, self.port)) File "", line 1, in connect socket.gaierror: (-5, 'No address associated with hostname') -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstrickler at gmail.com Sat Jun 13 16:11:46 2009 From: jstrickler at gmail.com (John S) Date: Sat, 13 Jun 2009 13:11:46 -0700 (PDT) Subject: Lexical scope: converting Perl to Python References: Message-ID: On Jun 13, 8:29?am, Nick Craig-Wood wrote: > Andrew Savige wrote: > > > ?I'd like to convert the following Perl code to Python: > > > ??use strict; > > ??{ > > ??? my %private_hash = ( A=>42, B=>69 ); > > ??? sub public_fn { > > ????? my $param = shift; > > ????? return $private_hash{$param}; > > ??? } > > ??} > > ??print public_fn("A");??????? # good:? prints 42 > > ??my $x = $private_hash{"A"};? # error: good, hash not in scope > > > ?The real code is more complex; the above is a simplified example. > > > ?Notice that this code uses Perl's lexical scope to hide the > > ?%private_hash variable, but not the public_fn() function. > > > ?While I could convert this code to the following Python code: > > > ??private_hash = dict( A=42, B=69 ) > > ??def public_fn(param): > > ??? return private_hash[param] > > ??print public_fn("A")???? # good:? prints 42 > > ??x = private_hash["A"]??? # works: oops, hash is in scope > > > ?I'm not happy with that because I'd like to limit the scope of the > > ?private_hash variable so that it is known only inside public_fn. > > > ?Of course, I could hide the hash like so: > > > ??def public_fn(param): > > ??? private_hash = dict( A=42, B=69 ) > > ??? return private_hash[param] > > > ?yet I'm not happy with that either because of the repeated > > ?initialization the hash each time the function is called. > > > ?What is the Pythonic equivalent of Perl's lexical scope, as > > ?illustrated by the code snippet above? > > Either > > _private_hash = dict( A=42, B=69) > > def public_fn(param): > ? ? return _private_hash[param] > > Or > > def public_fn(param, _private_hash = dict( A=42, B=69)): > ? ? return _private_hash[param] > > Is probably the pythonic equivalents. ?Note that private_hash starts > with an underscore which means it won't be exported from a module by > default and it is a convention that it is private and shouldn't be > fiddled with. ?I'd probably go with the latter of the two examples. > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Another approach is to just use a class to hold the data, and a class method (AKA classmethod) to access the data: # class definition class my_util(object): _private_hash = { 'A':42,'B':69 } @classmethod def public_fn(cls,index): return cls._private_hash[index] # usage print my_util.public_fn('A') print my_util.public_fn('B') This keeps pretty close to the OP's intention. It does require you to use the class name, but that's.....OK, and better than an anonymous block IMHO. Note: I'm a recovering Perl hacker. From gallium.arsenide at gmail.com Sat Jun 13 16:25:28 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 13:25:28 -0700 (PDT) Subject: Question about None References: 7xr5xovxbb.fsf@ruckus.brouhaha.com Message-ID: On Jun 13, 1:49?pm, Paul Rubin wrote: > John Yeung writes: > > Because you might want None to behave as though it were > > nothing at all. > > Sure, you might also want strings to behave as if they > were ints, but wishing doesn't make it so. I'm not saying that the OP, as a programmer using Python, would wish that Python's None behaves like nothing. I'm saying that as a philosophical question, which is how he phrased it, one might want one's language (perhaps one is designing this language) to have something that behaves like "nothing", and then call this "None". I don't think he's saying that the wrong choice was made for Python; I'm certainly not saying that; it was just a musing. > > But mathematically speaking, it's intuitive that > > "nothing" would match any type. > > Completely wrong. ?The concept you're thinking of in > denotational semantics is called "bottom", but bottom > is not a value that functions can compute and return. >?It is really the absence of a value. I've never heard a mathematician use the term "bottom". It certainly could be that I just haven't talked to the right types of mathematicians. I'm not sure it's even relevant. "Denotational semantics" is specific to computer science. My point was simply that even an elementary understanding of mathematics (and I'll grant a naive understanding of computer science as well) might lead someone to think that it *might* make sense for None to be the name for nothing. > > I find that it's somewhat like the confusion that often > > occurs regarding the all() function. > > It's the other way though, all([])=True makes sense, > isinstance(None,int) does not. Look, even a lot of the people on this very list, who answer questions as if they are experts, have been tripped up by all(). I am not here to say they are stupid. I also do not mean to present myself as an expert, whether in math, computer science, or Python in particular. I'm just trying to present the reasoning someone (however naive) might have to even bring up the possibility that it might make sense for isinstance(None, foo) to be True for any foo. I probably would not have been prompted to respond in the first place if Steven D'Aprano hadn't deemed the notion to require three exclamation points to shoot down. I think it is enough to say that None is an object and it has a specific type, thus it shouldn't match any other type; which is what he then said, albeit excitedly. ;) John From rhodri at wildebst.demon.co.uk Sat Jun 13 16:52:09 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 21:52:09 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 13 Jun 2009 18:37:13 +0100, koranthala wrote: > >> Code Complete and GOF are software engineering books but not really >> CS books. > > I understand and concur. Since I am a software engineer - coming in to > software from a different background - what I am looking for is self- > improvement books for a software engineer. In that case The Mythical Man-Month (Brooks) is a must. -- Rhodri James *-* Wildebeest Herder to the Masses From no.email at please.post Sat Jun 13 16:56:54 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 20:56:54 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In Jack Diederich writes: >There is only so much room in the syntax for common cases before you >end up with ... perl (no offense intended, I'm a perl monk[1]). The >Python grammar isn't as context sensitive or irregular as the perl >grammar so mylist[1,2,3] so the "1,2,3" tuple is always interpreted >as a tuple and the square brackets always expect an int or a slice. >Not including special cases everywhere means there isn't a short way >to handle special cases but it also means human readers have to >remember fewer special cases. Perl and Python make different >tradeoffs in that respect. OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be ambiguous: does it mean the fourth element of foo, or the tuple consisting of this element alone? I suppose that's good enough reason to veto this idea... Thanks for all the responses. kynn From rhodri at wildebst.demon.co.uk Sat Jun 13 16:58:10 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 21:58:10 +0100 Subject: Lexical scope: converting Perl to Python In-Reply-To: <447038.54682.qm@web56406.mail.re3.yahoo.com> References: <447038.54682.qm@web56406.mail.re3.yahoo.com> Message-ID: On Sat, 13 Jun 2009 06:02:53 +0100, Andrew Savige wrote: > What is the Pythonic equivalent of Perl's lexical scope, as > illustrated by the code snippet above? The useful (to you) pythonic answer depends rather a lot on why you want to do something like that. While you've been given several possibilities, the "correct" answer might well be "don't do that at all" :-) -- Rhodri James *-* Wildebeest Herder to the Masses From no.email at please.post Sat Jun 13 17:00:34 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 21:00:34 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In Nick Craig-Wood writes: >However I can't think of the last time I wanted to do this - array >elements having individual purposes are usually a sign that you should >be using a different data structure. In the case I was working with, was a stand-in for the value returned by some_match.groups(). The match comes from a standard regexp defined elsewhere and that captures more groups than I need. (This regexp is applied to every line of a log file.) kj From jstrickler at gmail.com Sat Jun 13 17:08:27 2009 From: jstrickler at gmail.com (John S) Date: Sat, 13 Jun 2009 14:08:27 -0700 (PDT) Subject: How to insert string in each match using RegEx iterator References: Message-ID: On Jun 10, 12:13?am, "504cr... at gmail.com" <504cr... at gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > Here's the code I started with: > > >>> rePatt = re.compile('\d+\s') > >>> iterator = rePatt.finditer(string) > >>> count = 0 > >>> for match in iterator: > > ? ? ? ? if count < 1: > ? ? ? ? ? ? ? ? print string[0:match.start()] + ' INSERT ' + string[match.start > ():match.end()] > ? ? ? ? elif count >= 1: > ? ? ? ? ? ? ? ? print ' INSERT ' + string[match.start():match.end()] > ? ? ? ? count = count + 1 > > My code returns an empty string. > > I'm new to Python, but I'm finding it really enjoyable (with the > exception of this challenging puzzle). > > Thanks in advance. I like using a *callback* function instead of *plain text* with the re.sub() method. To do this, call the sub() function in the normal way, but instead of specifying a string as the replacement, specify a function. This function expects the same match object returned by re.search() or re.match(). The text matched by your RE is replaced by the return value of the function. This gives you a lot of flexibility; you can use the matched text to look up values in files or databases, or online, for instance, and you can do any sort of text manipulation desired. ----8<----------------------------------------------------------------------- import re # original string oldstring = '123 abc 456 def 789 ghi' # RE to match a sequence of 1 or more digits rx_digits = re.compile(r"\d+") # callback function -- expects a Match object, returns the replacement string def repl_func(m): return 'INSERT ' + m.group(0) # do the substitution newstring = rx_digits.sub(repl_func,oldstring) print "OLD:",oldstring print "NEW:",newstring --------------------------------------------------------------------------------- Output: OLD: 123 abc 456 def 789 ghi NEW: INSERT 123 abc INSERT 456 def INSERT 789 ghi You could also do it with a lambda function if you didn't want to write a separate function: newstring = rx_digits.sub(lambda m: 'INSERT ' + m.group(0),oldstring) I understand that for this simple case, ' 'INSERT ' + \1 is sufficient, and a callback is overkill; I wanted to show the OP a more generic approach to complex substitutions. From rhodri at wildebst.demon.co.uk Sat Jun 13 17:22:14 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 22:22:14 +0100 Subject: Question about None In-Reply-To: References: Message-ID: On Sat, 13 Jun 2009 21:25:28 +0100, John Yeung wrote: >> > But mathematically speaking, it's intuitive that >> > "nothing" would match any type. >> >> Completely wrong. ?The concept you're thinking of in >> denotational semantics is called "bottom", but bottom >> is not a value that functions can compute and return. >> ?It is really the absence of a value. > > I've never heard a mathematician use the term "bottom". It certainly > could be that I just haven't talked to the right types of > mathematicians. I'm not sure it's even relevant. "Denotational > semantics" is specific to computer science. My point was simply that > even an elementary understanding of mathematics (and I'll grant a > naive understanding of computer science as well) might lead someone to > think that it *might* make sense for None to be the name for nothing. Such an understanding would be clearly wrong in the context in which we were talking (and denotational semantics is a branch of category theory, which is not specific to computer science if you don't mind). If None is nothing, then it can't be a string, int, float or anything else, because they're all something. -- Rhodri James *-* Wildebeest Herder to the Masses From skip at pobox.com Sat Jun 13 17:22:51 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 13 Jun 2009 16:22:51 -0500 (CDT) Subject: Generating a unique filename in the face of unicode filename Message-ID: <20090613212251.A3F0D110830A@montanaro.dyndns.org> In my lockfile module I generate a unique name like so: self.path = path self.lock_file = os.path.abspath(path) + ".lock" self.hostname = socket.gethostname() self.pid = os.getpid() if threaded: name = threading.current_thread().get_name() tname = "%s-" % quote(name, safe="") else: tname = "" dirname = os.path.dirname(self.lock_file) self.unique_name = os.path.join(dirname, "%s.%s%s" % (self.hostname, tname, self.pid)) where path is the file which is to be locked. Frank Niessink uses lockfile in his Task Coach application and reported a problem to me one of his Windows users encountered: ... File "taskcoachlib\persistence\taskfile.pyo", line 266, in acquire_lock File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 537, in FileLock File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 296, in __init__ File "taskcoachlib\thirdparty\lockfile\lockfile.pyo", line 175, in __init__ File "ntpath.pyo", line 102, in join UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal not in range(128) where line 175 is the assignment to self.unique_name. After a little back-and-forth with his user it turns out that her computer's hostname contains non-ASCII data, so presumably self.hostname is a unicode object. I tried to replicate this on my Mac but can't: >>> dirname = "/tmp" >>> h = u"\xef" >>> tname = threading.currentThread().getName() >>> os.path.join(dirname, "%s.%s.%s" % (h, tname, os.getpid())) u'/tmp/\xef.MainThread.11004' It works for Frank on his Windows box as well. Any ideas how to properly Unicode-proof this code? Thanks, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From gallium.arsenide at gmail.com Sat Jun 13 17:27:37 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 14:27:37 -0700 (PDT) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: <9cce24bf-2f3b-438f-91da-7fbf202fbf1d@r31g2000prh.googlegroups.com> On Jun 13, 3:59?pm, Arnaud Delobelle wrote: > kj writes: > > Are these the most idiomatically pythonic forms? ?Or am > > I missing something better? > > You're missing operator.itemgetter: > > >>> from operator import itemgetter > >>> foo = "spam & eggs" > >>> itemgetter(3, 7, 1, -1)(foo) > > ('m', 'e', 'p', 's') That looks to me like the best solution to the OP's specific question. It's amazing how many cool things are tucked into the standard library. While it's easy to miss these things, I appreciate the effort to keep Python's core relatively small. (Not knowing about itemgetter, I would have gone with the list comprehension.) John From pdlemper at earthlink.net Sat Jun 13 17:48:43 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 16:48:43 -0500 Subject: frustrating failure of 'break' statement ( novice ) Message-ID: In my programs the 'break' fails to work. I've studied the docs for 3.0 and Programming in Python, neither of which are illuminating. Simplest example : while True : num = int(input()) print(num) if num == 0 : break print('done') SyntaxError : invalid syntax ( pointing to end of break ) This happens whether the 'break' is put on same line as the conditional, flush with while, flush with if, or appropriately indented 4 spaces. " I saw the number 4 in gold " -Guido with apologies to Wm Carlos Williams From gallium.arsenide at gmail.com Sat Jun 13 17:49:34 2009 From: gallium.arsenide at gmail.com (John Yeung) Date: Sat, 13 Jun 2009 14:49:34 -0700 (PDT) Subject: Question about None References: Message-ID: On Jun 13, 5:22?pm, "Rhodri James" wrote: > Such an understanding would be clearly wrong in the context > in which we were talking (and denotational semantics is a > branch of category theory, which is not specific to computer > science if you don't mind). ?If None is nothing, then it can't > be a string, int, float or anything else, because they're all > something. I appreciate your explanation, and your politeness. And I accept your answer, as well as Steven's and Paul's for that matter. I still think it is understandable (and people may choose to understand in a condescending way, if they wish) that someone might not get the difference between what you are saying and the statement that all elements of the empty set are floats. I mean, what's in the empty set? Nothing. But you've said that floats are something. How is it that nothing is something? Please, I do not wish to extend this thread. My last question was rhetorical. It's not a challenge. I accept your answer, as well as the others. To be clear, I find it very intuitive that None does not match the other types. But just as the devil seems to have plenty of advocates, I guess I am a naive person's advocate, of sorts. (I must stress I'm not the OP's advocate, nor do I consider him naive.) John From brian at sweetapp.com Sat Jun 13 17:59:18 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 22:59:18 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <4A342136.5010909@sweetapp.com> kj wrote: > In Nick Craig-Wood writes: > >> However I can't think of the last time I wanted to do this - array >> elements having individual purposes are usually a sign that you should >> be using a different data structure. > > In the case I was working with, was a stand-in for the value returned > by some_match.groups(). The match comes from a standard regexp > defined elsewhere and that captures more groups than I need. (This > regexp is applied to every line of a log file.) > > kj The common idiom for this sort of thing is: _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() Cheers, Brian From dickinsm at gmail.com Sat Jun 13 18:07:10 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 13 Jun 2009 15:07:10 -0700 (PDT) Subject: frustrating failure of 'break' statement ( novice ) References: Message-ID: On Jun 13, 10:48?pm, pdlem... at earthlink.net wrote: > In my programs the 'break' fails to work. ?I've studied the docs for > 3.0 and Programming in Python, neither of which are illuminating. > Simplest example : > > while True : > ? ? num = int(input()) > ? ? print(num) > ? ? if num == 0 : > ? ? ? ? break > > print('done') > > SyntaxError : invalid syntax ? ?( pointing to end of break ) > [...] Are you mixing tabs and spaces in your code at all? Check that the 'break' line is indented with 8 spaces rather than a tab character. Mark From python at mrabarnett.plus.com Sat Jun 13 18:15:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Jun 2009 23:15:17 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A342136.5010909@sweetapp.com> References: <4A342136.5010909@sweetapp.com> Message-ID: <4A3424F5.7010901@mrabarnett.plus.com> Brian Quinlan wrote: > kj wrote: >> In Nick Craig-Wood >> writes: >> >>> However I can't think of the last time I wanted to do this - array >>> elements having individual purposes are usually a sign that you should >>> be using a different data structure. >> >> In the case I was working with, was a stand-in for the value returned >> by some_match.groups(). The match comes from a standard regexp >> defined elsewhere and that captures more groups than I need. (This >> regexp is applied to every line of a log file.) >> >> kj > > The common idiom for this sort of thing is: > > _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() > Alternatively: val1, val2, val3 = some_match.group(4, 8, something) From rhodri at wildebst.demon.co.uk Sat Jun 13 18:15:47 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 13 Jun 2009 23:15:47 +0100 Subject: frustrating failure of 'break' statement ( novice ) In-Reply-To: References: Message-ID: On Sat, 13 Jun 2009 22:48:43 +0100, wrote: > In my programs the 'break' fails to work. I've studied the docs for > 3.0 and Programming in Python, neither of which are illuminating. > Simplest example : > > while True : > num = int(input()) > print(num) > if num == 0 : > break > > print('done') > > > SyntaxError : invalid syntax ( pointing to end of break ) > This happens whether the 'break' is put on same line as the > conditional, flush with while, flush with if, or appropriately > indented 4 spaces. It works for me, running it from file. It fails with "invalid syntax" (pointing to the end of *print*) if I cut and paste the program exactly into a Python shell, presumably because the shell gets unhappy about having more command input when it wants to be executing the while loop. Does this match what you see? -- Rhodri James *-* Wildebeest Herder to the Masses From brian at sweetapp.com Sat Jun 13 18:22:56 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 13 Jun 2009 23:22:56 +0100 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3424F5.7010901@mrabarnett.plus.com> References: <4A342136.5010909@sweetapp.com> <4A3424F5.7010901@mrabarnett.plus.com> Message-ID: <4A3426C0.2040509@sweetapp.com> MRAB wrote: > Brian Quinlan wrote: >> kj wrote: >>> In Nick Craig-Wood >>> writes: >>> >>>> However I can't think of the last time I wanted to do this - array >>>> elements having individual purposes are usually a sign that you should >>>> be using a different data structure. >>> >>> In the case I was working with, was a stand-in for the value returned >>> by some_match.groups(). The match comes from a standard regexp >>> defined elsewhere and that captures more groups than I need. (This >>> regexp is applied to every line of a log file.) >>> >>> kj >> >> The common idiom for this sort of thing is: >> >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() >> > Alternatively: > > val1, val2, val3 = some_match.group(4, 8, something) Actually, now that I think about it, naming the groups seems like it would make this code a lot less brittle. Cheers, Brian From piet at cs.uu.nl Sat Jun 13 18:38:30 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 00:38:30 +0200 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xr5xovxbb.fsf@ruckus.brouhaha.com> <7xiqj0vx1m.fsf@ruckus.brouhaha.com> Message-ID: >>>>> Paul Rubin (PR) wrote: >PR> Paul Rubin writes: >>> crash, or something like that. None is a value which in Haskell has a >PR> I got ahead of myself, of course I meant Python (the *next* sentence >PR> was going to mention Haskell). The corresponding concept in Haskell >PR> is called Nothing, which lives in a type functor called Maybe. I >PR> don't have time to go into it right now but there is a notion among >PR> language weenies these days that the presence of something like None >PR> (in Python) or Null (in Java, SQL, etc) is a wart in a language and >PR> that it's preferable to have something like Maybe. The reason is that in Haskell the type system doesn't have union types. Instead it has the disjoint sum, and Maybe is just one of them. Otherwise you could have used the union of Nothing and any other type. In Python there is no reason to use a disjoint sum as Python doesn't use static typing. You can use unions of types at your hearts desire. So I don't think there is not much difference between None and Nothing, except for the type system. Java, on the other hand does have static typing but does not have disjoint sums. So they have not much choice but to put null in every class-based type. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From no.email at please.post Sat Jun 13 19:01:04 2009 From: no.email at please.post (kj) Date: Sat, 13 Jun 2009 23:01:04 +0000 (UTC) Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: In kj writes: >OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be >ambiguous: does it mean the fourth element of foo, or the tuple >consisting of this element alone? I suppose that's good enough >reason to veto this idea... Hmmm, come to think of it, this argument is weaker than I thought at first. Python already has cases where it has to deal with this sort of ambiguity, and does so with a trailing comma. So the two cases could be disambiguated: foo[3] for the single element, and foo[3,] for the one-element tuple. Also, the association of this idiom with Perl is a bit unfair: tuple-index is very common in other languages, and in pure math as well. As I said in my original post, Perl code often has very obscure expressions, but I would never describe tuple indexing as one of them. By the same token, the desing of Python does not entirely disregard considerations of ease of writing. Who could argue that foo[:] is intrinsically clearer, or easier to read than foo[0:len(foo)] ? Please don't misunderstand me here. I don't want to critize, let alone change, Python. I'm sure there is a good reason for why Python doesn't support foo[3,7,1,-1], but I have not figured it out yet. I still find it unconvincing that it would be for the sake of keeping the code easy to read, because I don't see how foo[3,7,1,-1] is any more confusing than foo[:]. kj From piet at cs.uu.nl Sat Jun 13 19:02:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 01:02:16 +0200 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: >>>>> kj (k) wrote: >k> Switching from Perl here, and having a hard time letting go... >k> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >k> second, and last element in that array. In Perl I could write: >k> my @wanted = @foo[3, 7, 1, -1]; >k> I was a bit surprised when I got this in Python: >>>>> wanted = foo[3, 7, 1, -1] >k> Traceback (most recent call last): >k> File "", line 1, in >k> TypeError: list indices must be integers >k> Granted, Perl's syntax is often obscure and hard-to-read, but in >k> this particular case I find it quite transparent and unproblematic, >k> and the fictional "pythonized" form above even more so. >k> The best I've been able to come up with in Python are the somewhat >k> Perl-like-in-its-obscurity: >>>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) >k> or the clearer but unaccountably sesquipedalian >>>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] >k> Are these the most idiomatically pythonic forms? Or am I missing >k> something better? Do it yourself: class MyList(list): def __getitem__(self, indx): if isinstance (indx, tuple): return [self[i] for i in indx] else: return list.__getitem__(self, indx) l = MyList((range(10))) print l[3, 7, 1, -1] print l[3] print l[3:7] # and now for something completely different print l[3, (7, 1), -1] duck :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jeremy.cowles at gmail.com Sat Jun 13 19:07:41 2009 From: jeremy.cowles at gmail.com (Jeremy Cowles) Date: Sat, 13 Jun 2009 16:07:41 -0700 Subject: Distributed computing & sending the interpreter Message-ID: <373cf0740906131607k4cf6ac79ncc09e174fde13a22@mail.gmail.com> Hi all, I'm working on a distributed computing project (PyMW and BOINC) where we are sending Python scripts to client machines. Currently, we make two very unlikely assumptions: that Python 2.5 is installed and that the interpreter is available on the PATH. We are looking at our options to remove this assumption and the two most likely are redistributing the entire Python installation (for each supported platform) and embedding the interpreter in a custom executable and sending select parts of the standard library with it (to reduce size). It seems like we would have to pre-compile for each different platform, which is a pain and sending the entire installation could be tricky. I am looking for alternatives, comments and suggestions. Any help would be greatly appreciated. Also, please let me know if there is a better list to post this question to; would the python-dev list be appropriate? Thanks, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Jun 13 20:05:09 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Jun 2009 17:05:09 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In article <873aa5m6ae.fsf at vostro.rath.org>, Nikolaus Rath wrote: > >I think I managed to narrow down the problem a bit. It seems that when >a function returns normally, its local variables are immediately >destroyed. However, if the function is left due to an exception, the >local variables remain alive: Correct. You need to get rid of the stack trace somehow; the simplest way is to wrap things in layers of functions (i.e. return from the function with try/except and *don't* save the traceback). Note that if your goal is to ensure finalization rather than recovering memory, you need to do that explicitly rather than relying on garbage collection. -- 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 pdlemper at earthlink.net Sat Jun 13 20:20:17 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 19:20:17 -0500 Subject: Persistent failure of 'break' statement ( novice ) References: Message-ID: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Thanks Mark & Rhodri. Neither works. I'm using Notepad2 as editor. Don't use the tab. Each space counted with spacebar & recounted. Rewrote the block from scratch as new script and eliminated the print line in the loop. Now no error message, but it will go on forever despite repeatedly entering 0. Have to get out with ctrl-c . while True : num = int(input()) if num == 0 : break print('done') Frusting: I'm missing something fundamental. Dave WB3DWE From ben+python at benfinney.id.au Sat Jun 13 20:24:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 10:24:48 +1000 Subject: preferring [] or () in list of error codes? References: <87zlcicmvi.fsf@benfinney.id.au> <8763f5d0r2.fsf@benfinney.id.au> <87eitqa10z.fsf@benfinney.id.au> <878wjy8gv5.fsf@benfinney.id.au> Message-ID: <87d49764rz.fsf@benfinney.id.au> Mel writes: > The immutability makes it easier to talk about the semantic meanings. > After you do > > event_timestamp = (2009, 06, 04, 05, 02, 03) > there's nothing that can happen to the tuple to invalidate > > (year, month, day, hour, minute, second) = event_timestamp > even though, as you say, there's nothing in the tuple to inform anybody > about the year, month, day, ... interpretation. Also note that the stdlib ?collections.namedtuple? implementation essentially acknowledges this: the names are assigned in advance to index positions, tying a specific semantic meaning to each position. -- \ ?Prediction is very difficult, especially of the future.? | `\ ?Niels Bohr | _o__) | Ben Finney From contact at xavierho.com Sat Jun 13 21:15:03 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 14 Jun 2009 11:15:03 +1000 Subject: Persistent failure of 'break' statement ( novice ) In-Reply-To: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Message-ID: <2d56febf0906131815n30acb7a1i2b2629691698894c@mail.gmail.com> I don't see any error in that code except the fact HTML ate one space from the code you pasted. It worked fine and perfectly as expected, even with print(num) present. I think you have either a run-time environment problem, or an editor encoding problem. Try a different editor, and/or different ways of launching the program. And share with us what you did to run this to begin with, that might help as well. Best regards, 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 Sun, Jun 14, 2009 at 10:20 AM, wrote: > Thanks Mark & Rhodri. Neither works. > > I'm using Notepad2 as editor. Don't use the tab. Each space > counted with spacebar & recounted. Rewrote the block from > scratch as new script and eliminated the print line in the loop. > Now no error message, but it will go on forever despite repeatedly > entering 0. Have to get out with ctrl-c . > > while True : > num = int(input()) > if num == 0 : > break > > print('done') > > Frusting: I'm missing something fundamental. Dave WB3DWE > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Sat Jun 13 22:03:38 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 19:03:38 -0700 (PDT) Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> Message-ID: <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > Now no error message, but it will go on forever despite repeatedly > entering 0. ?Have to get out with ctrl-c . ? ? > ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE After you hit the zero key, do you hit the Enter key? If the answer is yes, then our crystal balls have proved useless. You'll have to supply some meaningful detail. If you are pasting your script into a Python interactive prompt, stop doing that, save your script as a file, and run it from the command line. Here's a script for you to use. It has some diagnostic print() calls in it so that we can see what is going wrong. 8<----- cut here import sys print(sys.version) assert sys.version.startswith('3.') while True : text = input('Enter a number -> ') print('You entered', ascii(text)) if text != "0": print('That is NOT the digit zero!') num = int(text) print('Value:', num) if num == 0: break print('done') 8<----- cut here And when you run it, copy the outout and paste it into your return message/posting, like I've done below: [I called my copy break_fail.py] C:\junk>\python30\python break_fail.py 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] Enter a number -> 9 You entered '9' That is NOT the digit zero! Value: 9 Enter a number -> 0 You entered '0' Value: 0 done C:\junk> Hoping this helps, John From roy at panix.com Sat Jun 13 22:21:07 2009 From: roy at panix.com (Roy Smith) Date: Sat, 13 Jun 2009 22:21:07 -0400 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In article , "Rhodri James" wrote: > The Mythical Man-Month (Brooks) is a must. What's amazing about this book is just how relevant it is today, 35 years after it was written. Some of the technical details have changed (how many of us still keep our project notes on microfiche?), but cross out "microfiche" and write in "wiki" and what he's saying is just as valid today. It's not about computer science. It's not really even about software engineering. It's more about general project management than anything else. In the same vein, Death March, by Ed Yourdon. From pdlemper at earthlink.net Sat Jun 13 22:27:51 2009 From: pdlemper at earthlink.net (pdlemper at earthlink.net) Date: Sat, 13 Jun 2009 21:27:51 -0500 Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> Message-ID: <3pn8355ojbd09nlb5bv2f0ucp2qkvttstj@4ax.com> On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin wrote: >On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > >> Now no error message, but it will go on forever despite repeatedly >> entering 0. ?Have to get out with ctrl-c . ? ? > >> ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE > >After you hit the zero key, do you hit the Enter key? > >If the answer is yes, then our crystal balls have proved useless. >You'll have to supply some meaningful detail. If you are pasting your >script into a Python interactive prompt, stop doing that, save your >script as a file, and run it from the command line. > >Here's a script for you to use. It has some diagnostic print() calls >in it so that we can see what is going wrong. > >8<----- cut here >import sys >print(sys.version) >assert sys.version.startswith('3.') >while True : > text = input('Enter a number -> ') > print('You entered', ascii(text)) > if text != "0": > print('That is NOT the digit zero!') > num = int(text) > print('Value:', num) > if num == 0: > break >print('done') >8<----- cut here > >And when you run it, copy the outout and paste it into your return >message/posting, like I've done below: > >[I called my copy break_fail.py] > >C:\junk>\python30\python break_fail.py >3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] >Enter a number -> 9 >You entered '9' >That is NOT the digit zero! >Value: 9 >Enter a number -> 0 >You entered '0' >Value: 0 >done > >C:\junk> > >Hoping this helps, >John John : Hitting Enter solved it. Thanks so much. I was treating input() as getch() or getche() . Dave WB3DWE From http Sat Jun 13 22:34:34 2009 From: http (Paul Rubin) Date: 13 Jun 2009 19:34:34 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Roy Smith writes: > In the same vein, Death March, by Ed Yourdon. I've been wanting to read "Antipatterns". From research at johnohagan.com Sat Jun 13 23:17:45 2009 From: research at johnohagan.com (John O'Hagan) Date: Sun, 14 Jun 2009 03:17:45 +0000 Subject: Question about None In-Reply-To: References: Message-ID: <200906140317.46479.research@johnohagan.com> On Sat, 13 Jun 2009, John Yeung wrote: > On Jun 13, 5:22 pm, "Rhodri James" > > wrote: > > Such an understanding would be clearly wrong in the context > > in which we were talking (and denotational semantics is a > > branch of category theory, which is not specific to computer > > science if you don't mind). If None is nothing, then it can't > > be a string, int, float or anything else, because they're all > > something. > > I appreciate your explanation, and your politeness. > > And I accept your answer, as well as Steven's and Paul's for that > matter. I still think it is understandable (and people may choose to > understand in a condescending way, if they wish) that someone might > not get the difference between what you are saying and the statement > that all elements of the empty set are floats. I mean, what's in the > empty set? Nothing. But you've said that floats are something. How > is it that nothing is something? [...] Also accepting that Python's implementation of None and all() are well-defined and practical, I would add that philosophically these matters of emptiness and nothingness are far from concluded. Bertrand Russell, for one, would have disputed the behaviour of all([]), although he may have appreciated its usefulness. Regards, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Jun 14 00:22:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 13 Jun 2009 21:22:58 -0700 Subject: Off-topic: Usenet archiving history (was Re: FW: [Tutor] Multi-Threading and KeyboardInterrupt) References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: In article , Dennis Lee Bieber wrote: > > As for the use of X-Noarchive headers... Back before Google, most >NNTP servers had automatic expiration of messages (on my ISP at the >time, the binary groups expired after 24 hours!, most messages expired >after one or two weeks). I never used X-Noarchive -- in truth, I didn't >even know about it. > > THEN... Google started doing Google Groups with no automatic >expiration. That is when the subject of X-Noarchive headers came up in >some of the groups I'd been following. I and a fair number of others >immediately took advantage of it. Actually, it's not really fair to blame Google for this, they were only following the design of DejaNews, which they purchased in 2001. Google did create some additional value by finding old Usenet archives that predated DejaNews. (Google Groups, which I normally refer to as Gooja in deference to the history, debuted the archive on Dec 10, 2001.) -- 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 koranthala at gmail.com Sun Jun 14 01:38:32 2009 From: koranthala at gmail.com (koranthala) Date: Sat, 13 Jun 2009 22:38:32 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On Jun 14, 1:52?am, "Rhodri James" wrote: > On Sat, 13 Jun 2009 18:37:13 +0100, koranthala ? > wrote: > > > > >> Code Complete and GOF are software engineering books but not really > >> CS books. > > > I understand and concur. Since I am a software engineer - coming in to > > software from a different background - what I am looking for is self- > > improvement books for a software engineer. > > In that case The Mythical Man-Month (Brooks) is a must. > > -- > Rhodri James *-* Wildebeest Herder to the Masses Thank you Rhodri. I do have Mythical Man-Month - a great book indeed. I was looking for more technical books - I have now got a good set - Putting it across so that others can also use maybe - Code Complete, GOF, Mythical Man-Month, SICP - Thank you Paul - I have downloaded it from Web Site, Introduction to algorithm - I have placed an order for the same, The Pragmatic Programmer - Planning to buy, Refactoring: Improving the Design of Existing Code - again planning to buy, The C Programming Language - I had this, lost it, now I will buy again, The Little Schemer - I am not sure about buying this - I dont know scheme Software Tools - Seems to be a classic - not sure whether I will buy. Regards K From mk.fraggod at gmail.com Sun Jun 14 01:55:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 11:55:09 +0600 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <20090614115509.437d46b2@coercion> On Fri, 12 Jun 2009 18:33:13 -0400 Nikolaus Rath wrote: > Nikolaus Rath writes: > > Hi, > > > > Please consider this example: > [....] > > I think I managed to narrow down the problem a bit. It seems that when > a function returns normally, its local variables are immediately > destroyed. However, if the function is left due to an exception, the > local variables remain alive: > ... > > Is there a way to have the obj variable (that is created in dostuff()) > destroyed earlier than at the end of the program? As you can see, I > already tried to explicitly call the garbage collector, but this does > not help. Strange thing is that no one suggested contextlib, which made _exactly_ for this purpose: #!/usr/bin/env python import gc class testclass(object): def __init__(self): self.alive = True # just for example print "Initializing" def __del__(self): if self.alive: # try..except wrapper would suffice here, # so destruction won't raise ex, if already done print "Destructing" self.alive = False def __enter__(self): pass def __exit__(self, ex_type, ex_val, ex_trace): self.__del__() if not ex_type is None: raise RuntimeError(ex_val) def dostuff(fail): with testclass() as obj: # some stuff if fail: raise TypeError # some more stuff print "success" print "Calling dostuff" dostuff(fail=False) print "dostuff returned" try: print "Calling dostuff" dostuff(fail=True) except TypeError: pass gc.collect() print "dostuff returned" And it doesn't matter where you use "with", it creates a volatile context, which destructs before anything else happens on higher level. Another simplified case, similar to yours is file objects: with open(tmp_path, 'w') as file: # write_ops os.rename(tmp_path, path) So whatever happens inside "with", file should end up closed, else os.rename might replace valid path with zero-length file. It should be easy to use cursor with contextlib, consider using contextmanager decorator: from contextlib import contextmanager @contextmanager def get_cursor(): try: cursor = conn.cursor() yield cursor except Exception as ex: raise ex finally: cursor.close() with get_cursor() as cursor: # whatever ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From rustompmody at gmail.com Sun Jun 14 02:37:38 2009 From: rustompmody at gmail.com (rustom) Date: Sat, 13 Jun 2009 23:37:38 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <49565374-8f7f-4703-8d5e-41190f0373b2@i28g2000prd.googlegroups.com> On Jun 14, 10:38?am, koranthala wrote: > Software Tools - Seems to be a classic - not sure whether I will buy. In that vein but more modern -- Art of Unix Programming by Eric Raymond (available online) Some of my old favorites: Intro to functional programming by Bird and Wadler TAOCP slightly more modernized more heady and less programmer oriented -- Concrete Mathematics by Knuth and... Science of Programming by David Gries; again more modernized to Logical Approach to Discrete Mathematics Bentley's Wriiting Efficient Programs and Programming pearls Dijkstra's writings -- http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html -- are not kind to software engineers [His defn of SE -- How to program if you cannot]. Seemingly irrelevant -- Good programmers are very good with their editors -- someone mentioned yegge. Read him for inspiration on emacs. Of course you can use something else but its important to get good at it. From sjmachin at lexicon.net Sun Jun 14 02:51:44 2009 From: sjmachin at lexicon.net (John Machin) Date: Sat, 13 Jun 2009 23:51:44 -0700 (PDT) Subject: Persistent failure of 'break' statement ( novice ) References: <7lf835dbptn754naipogni5uvj0heqpfd6@4ax.com> <0579b3d1-51cd-4848-9368-e4aac5034066@o21g2000prn.googlegroups.com> <3pn8355ojbd09nlb5bv2f0ucp2qkvttstj@4ax.com> Message-ID: On Jun 14, 12:27?pm, pdlem... at earthlink.net wrote: > On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin > > > > wrote: > >On Jun 14, 10:20?am, pdlem... at earthlink.net wrote: > > >> Now no error message, but it will go on forever despite repeatedly > >> entering 0. ?Have to get out with ctrl-c . ? ? > > >> ? ? ? ? ? ?Frusting: I'm missing something fundamental. Dave WB3DWE > > >After you hit the zero key, do you hit the Enter key? > [snip] > > John : Hitting Enter solved it. ?Thanks so much. ?I was treating > input() as getch() or getche() . ? ? ? ? ? ? ? Dave WB3DWE Here's a tip: when all else fails, read the manual. In this case: http://docs.python.org/3.0/library/functions.html#input """The function then reads a line from input, converts it to a string (stripping a trailing newline)""" If you are desperate for getch() and getche(), see here: http://docs.python.org/3.0/library/msvcrt.html?highlight=msvcrt#console-i-o HTH, John From zak.mc.kraken at libero.it Sun Jun 14 02:55:30 2009 From: zak.mc.kraken at libero.it (Vito De Tullio) Date: Sun, 14 Jun 2009 08:55:30 +0200 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: Jack Diederich wrote: > the square brackets always expect an int or a slice. true only for lists :) In [1]: mydict = {} In [2]: mydict[1,2,3] = 'hi' In [3]: print mydict[1,2,3] ------> print(mydict[1,2,3]) hi -- By ZeD From db3l.net at gmail.com Sun Jun 14 03:33:10 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 14 Jun 2009 03:33:10 -0400 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: Dennis Lee Bieber writes: > Either way -- it was still a change from "expiration at some > date"... Though since (Netcom/Mindspring)Earthlink seems to have > subcontracted NNTP service to Giganews (or some such) it wouldn't > surprise me to learn that service also keeps a mammoth archive... I'm not sure it's really a change, or if it is, it certainly isn't a change from how things were originally. "Expiration at some date" was never any sort of global policy for Usenet - just an aspect of a individual news server. Some servers held messages for long periods, particularly for the big seven groups - it's true that alt.* and in particular the binaries, might expire quickly. I know I certainly ran some servers that didn't bother expiring - or had expiration times in years - of the big seven. My experience post-dates the great renaming, so I can't speak to before that, but don't think behavior was very different. Individual messages could include an Expires: header if they wished, but even that was just a suggestion. Any actual expiration was due to local configuration on each news server, which while it could take Expires: headers into account, was just as often driven by local storage availability or the whims of the local news admin :-) I think Deja News was providing web access to their archive from the mid-90s on (so quite a while before Google even existed) so certainly by that point everyone had access to a rather complete archive even if messages had expired on their local server. I think Deja was also the first to introduce X-No-Archive. But other archives certainly existed pre-Deja, which I'm sure is, in large part, how Google was able to locate and incorporate the older messages into their system after their acquisition of the Deja archive. -- David From lie.1296 at gmail.com Sun Jun 14 03:34:12 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 14 Jun 2009 07:34:12 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: Piet van Oostrum wrote: >>>>>> kj (k) wrote: > >> k> Switching from Perl here, and having a hard time letting go... > >> k> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >> k> second, and last element in that array. In Perl I could write: > >> k> my @wanted = @foo[3, 7, 1, -1]; > >> k> I was a bit surprised when I got this in Python: > >>>>>> wanted = foo[3, 7, 1, -1] >> k> Traceback (most recent call last): >> k> File "", line 1, in >> k> TypeError: list indices must be integers > >> k> Granted, Perl's syntax is often obscure and hard-to-read, but in >> k> this particular case I find it quite transparent and unproblematic, >> k> and the fictional "pythonized" form above even more so. > >> k> The best I've been able to come up with in Python are the somewhat >> k> Perl-like-in-its-obscurity: > >>>>>> wanted = map(foo.__getitem__, (3, 7, 1, -1)) > >> k> or the clearer but unaccountably sesquipedalian > >>>>>> wanted = [foo[i] for i in 3, 7, 1, -1] >>>>>> wanted = [foo[3], foo[7], foo[7], foo[-1]] > >> k> Are these the most idiomatically pythonic forms? Or am I missing >> k> something better? > > Do it yourself: > > class MyList(list): > def __getitem__(self, indx): > if isinstance (indx, tuple): > return [self[i] for i in indx] > else: > return list.__getitem__(self, indx) > > l = MyList((range(10))) > > print l[3, 7, 1, -1] > print l[3] > print l[3:7] > > # and now for something completely different > > print l[3, (7, 1), -1] > even better: print l[3, 4:10:2, 7] From mk.fraggod at gmail.com Sun Jun 14 03:46:18 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 13:46:18 +0600 Subject: Make upof Computer References: <11c7c592-12cb-4d6c-b964-96782da39690@s38g2000prg.googlegroups.com> Message-ID: <20090614134618.19f03efd@coercion> On Sun, 14 Jun 2009 00:46:16 -0700 (PDT) "Mr . Waqar Akbar" wrote: ... Judging by the typo in the last subject, someone indeed types all this crap in manually! Oh my god... -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From ben+python at benfinney.id.au Sun Jun 14 03:46:26 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 17:46:26 +1000 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> Message-ID: <87r5xn45rh.fsf@benfinney.id.au> David Bolen writes: > Individual messages could include an Expires: header if they wished, Since we're already well off-topic: NNTP, HTTP, and email, and probably other protocols as well, all deal with messages. They are all consistent in defining a message [0] as having *exactly one* header. Every time you call a field from the header ?a header?, or refer to the plural ?headers of a message?, the IETF kills a kitten. You don't want to hurt a kitten, do you? [0] Okay, NNTP calls a message an ?article?, and the header is composed of ?lines? where other protocols call them ?fields? (since there can be multiple lines per field), but that's no excuse. -- \ ?If I held you any closer I would be on the other side of you.? | `\ ?Groucho Marx | _o__) | Ben Finney From lie.1296 at gmail.com Sun Jun 14 03:48:38 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 14 Jun 2009 07:48:38 GMT Subject: How to escape # hash character in regex match strings In-Reply-To: References: <9e1deb80-639e-405f-853d-9cd88a69a3d0@s21g2000vbb.googlegroups.com> <6d70e178-2f11-4b2c-85fe-336c43afc544@x6g2000vbg.googlegroups.com> Message-ID: Brian D wrote: > On Jun 11, 9:22 am, Brian D wrote: >> On Jun 11, 2:01 am, Lie Ryan wrote: >> >> >> >>> 504cr... at gmail.com wrote: >>>> I've encountered a problem with my RegEx learning curve -- how to >>>> escape hash characters # in strings being matched, e.g.: >>>>>>> string = re.escape('123#abc456') >>>>>>> match = re.match('\d+', string) >>>>>>> print match >>>> <_sre.SRE_Match object at 0x00A6A800> >>>>>>> print match.group() >>>> 123 >>>> The correct result should be: >>>> 123456 >>>> I've tried to escape the hash symbol in the match string without >>>> result. >>>> Any ideas? Is the answer something I overlooked in my lurching Python >>>> schooling? >>> As you're not being clear on what you wanted, I'm just guessing this is >>> what you wanted: >>>>>> s = '123#abc456' >>>>>> re.match('\d+', re.sub('#\D+', '', s)).group() >>> '123456' >>>>>> s = '123#this is a comment and is ignored456' >>>>>> re.match('\d+', re.sub('#\D+', '', s)).group() >>> '123456' >> Sorry I wasn't more clear. I positively appreciate your reply. It >> provides half of what I'm hoping to learn. The hash character is >> actually a desirable hook to identify a data entity in a scraping >> routine I'm developing, but not a character I want in the scrubbed >> data. >> >> In my application, the hash makes a string of alphanumeric characters >> unique from other alphanumeric strings. The strings I'm looking for >> are actually manually-entered identifiers, but a real machine-created >> identifier shouldn't contain that hash character. The correct pattern >> should be 'A1234509', but is instead often merely entered as '#12345' >> when the first character, representing an alphabet sequence for the >> month, and the last two characters, representing a two-digit year, can >> be assumed. Identifying the hash character in a RegEx match is a way >> of trapping the string and transforming it into its correct machine- >> generated form. >> >> I'm surprised it's been so difficult to find an example of the hash >> character in a RegEx string -- for exactly this type of situation, >> since it's so common in the real world that people want to put a pound >> symbol in front of a number. >> >> Thanks! > > By the way, other forms the strings can take in their manually created > forms: > > A#12345 > #1234509 > > Garbage in, garbage out -- I know. I wish I could tell the people > entering the data how challenging it is to work with what they > provide, but it is, after all, a screen-scraping routine. perhaps it's like this? >>> # you can use re.search if that suits better >>> a = re.match('([A-Z]?)#(\d{5})(\d\d)?', 'A#12345') >>> b = re.match('([A-Z]?)#(\d{5})(\d\d)?', '#1234509') >>> a.group(0) 'A#12345' >>> a.group(1) 'A' >>> a.group(2) '12345' >>> a.group(3) >>> b.group(0) '#1234509' >>> b.group(1) '' >>> b.group(2) '12345' >>> b.group(3) '09' From ben+python at benfinney.id.au Sun Jun 14 03:55:48 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 14 Jun 2009 17:55:48 +1000 Subject: Make-up of computer References: Message-ID: <87my8b45bv.fsf@benfinney.id.au> "Mr . Waqar Akbar" writes: > A computer is a collection of modular electronic components, i.e. > components that can be replaced by other components that may have > different characteristics that are capable of running computer > programs. And also storing and manipulating all sorts of other digital information, not just programs. > Thus, the term "hardware" refers to all the material elements of a > computer and "software" refers to the program parts. Rather, ?software? refers to *all* the streams of bits. Whether a bit stream is interpreted as a program, a graphic image, a document, or all three simultaneously ? or any of countless other potential interpretations for a bit stream ? is transitory, and doesn't affect its nature as ?software?. Or, as the aphorism goes: The hardware is the parts of the computer you can kick, and the software is everything else in the computer. -- \ ?I spilled spot remover on my dog. Now he's gone.? ?Steven | `\ Wright | _o__) | Ben Finney From kwatch at gmail.com Sun Jun 14 04:06:36 2009 From: kwatch at gmail.com (kwatch) Date: Sun, 14 Jun 2009 01:06:36 -0700 (PDT) Subject: ANN: pyTenjin 0.8.1 - much faster template engine than Django Message-ID: <58230bc0-97d5-476c-9a69-5bf60a21f304@c18g2000prh.googlegroups.com> I released pyTenjin 0.8.1. http://www.kuwata-lab.com/tenjin/ http://pypi.python.org/pypi/Tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) This is a bug fix release. See CHANGES for details. http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Bugfix from 0.8.1 ----------------- * Fix bugs on CacheStorage#unset(). (thanks Steve) * Fix tenjin.helpers.html.new_cycle() to work on Python 3.0. Changes from 0.8.1 ------------------ * Update 'doc/faq.html' and add new section. 'Is it possible to change indent restriction more flexible?' http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-flexibleindent Documents --------- * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * FAQ http://www.kuwata-lab.com/tenjin/pytenjin-faq.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Have fun! -- regards, makoto kuwata From ldo at geek-central.gen.new_zealand Sun Jun 14 04:18:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 20:18:12 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In message , koranthala wrote: > I do have Mythical Man-Month - a great book indeed. > I was looking for more technical books ... No-one has mentioned Andrew Tanenbaum's "Computer Networks". So much of programming seems to involve networking these days, I think the current (4th) edition is a great introduction to how to think in network terms, particularly about security issues. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:23:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:23:31 +1200 Subject: Measuring Fractal Dimension ? References: Message-ID: In message , Peter Billam wrote: > Are there any modules, packages, whatever, that will > measure the fractal dimensions of a dataset, e.g. a time-series ? I don't think any countable set, even a countably-infinite set, can have a fractal dimension. It's got to be uncountably infinite, and therefore uncomputable. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:32:46 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:32:46 +1200 Subject: random number including 1 - i.e. [0,1] References: Message-ID: In message , Jussi Piitulainen wrote: > Miles Kaufmann writes: > >> I'm curious what algorithm calls for random numbers on a closed >> interval. > > The Box-Muller transform, polar form. At least Wikipedia says so. Doesn't seem to be necessary, if I interpret the following correctly : Given u and v, independent and uniformly distributed in the closed interval [?1, +1], set s = R2 = u2 + v2. (Clearly \scriptstyle R = \sqrt{s}.) If s = 0 or s > 1, throw u and v away and try another pair (u, v). Continue until a pair with s in the open interval (0, 1) is found. Since s is supposed to be in an open interval, I don't see how it makes any difference if u and v are chosen from an open or semiopen interval. The probability of hitting the exact endpoints is 0, after all. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:36:39 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:36:39 +1200 Subject: random number including 1 - i.e. [0,1] References: <75CADB31-7A7B-4F83-9A19-6A34B96A24B5@umich.edu> Message-ID: In message , Esmail wrote: > I'm implementing a Particle Swarm Optimizer. Depending on what paper you > read you'll see mention of required random values "between 0 and 1" > which is somewhat ambiguous. I came across one paper that specified > the range [0,1], so inclusive 1, which was the reason for my question. Sounds like some of their descriptions are a bit sloppy. Maybe best to clear it up by trying to think what a value of exactly or exactly 1 for the random value might mean: are those boundaries meant to be inside the set, or outside? Is it meaningful to concatenate two adjacent intervals? In that case any point can only belong to one of the intervals, not both. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:38:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:38:59 +1200 Subject: random number including 1 - i.e. [0,1] References: Message-ID: In message , Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid ? xid ) + c2 * Rand( ) * (pgd ?xid ) (1a) > > xid = xid + vid (1b) Are the terms meant to be clamped to a particular range of values? Otherwise it probably doesn't matter. From ldo at geek-central.gen.new_zealand Sun Jun 14 05:43:30 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 14 Jun 2009 21:43:30 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > 2. That output string has severe "leaning toothpick" syndrome. Python > accepts both single and double quotes to help avoid creating something > so unreadable: use them. Backslashes are more scalable. From madigreece at yahoo.gr Sun Jun 14 06:31:43 2009 From: madigreece at yahoo.gr (jeni) Date: Sun, 14 Jun 2009 03:31:43 -0700 (PDT) Subject: error: an integer is required References: Message-ID: <0319e22c-6b6a-4165-91cd-2813dcfa1e58@y17g2000yqn.googlegroups.com> On 8 ????, 21:46, Terry Reedy wrote: > madigre... at yahoo.gr wrote: > > I execute my code in linux environment. > > My code is: > > > from os import * > > > def insert_text_file(self, strng): > > ? ? ?t=open("elements_file.txt", "a") > > ? ? ?t.write(strng) > > ? ? ?t.close() > > > I'm getting this error: > > > : an integer is required > > > Where is the mistake? > > Help me, please!! > > Tell us the Python version and give the *full* traceback message, not > just the last line. ?I am pretty sure you also left out an important > part of the code you executed to get that message. > > tjr- ???????? ???????? ?? ???????? - > > - ???????? ???????? ?? ???????? - With both import os and os.open there is the same error. I have developed in python a game for OPLC. When I run the game in Python 2.5.2 at Windows there is no problem. But after I play a game at OLPC I get the following message: Traceback (most recent call last) /home/olpc/Activities/Kremala.activity/Kremala.py in add_letter (self=, widget=, grama='i') --> self.find_w() self.find_w=> /home/Activities/Kremala.activity/Kremala.py in find_w (self=) self.show_gr() --> self.sosti_leksi() self.sosti_leksi==> /home/Activities/Kremala.activity/Kremala.py in sosti_leksi (self=) s=self.categ+":"+str(1)+" nikh me "+str(6-self.m)+"prospatheies \n" --> self.insert_text_file(s) self.insert_text_file===> /home/Activities/Kremala.activity/Kremala.py in insert_text_file (self=, strng='geografia:1 nikh me 2 prospatheies\n') --> t=open("elements_file.txt", "a") global open= t.write(strng) t.close() : an integer is required OLPC's software is important? From kindly at gmail.com Sun Jun 14 07:02:47 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 04:02:47 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. Message-ID: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> I am sure people have thought of this before, but I cant find where. I think that python should adapt a way of defining different types of mapping functions by proceeding a letter before the curly brackets. i.e ordered = o{}, multidict = m{} (like paste multidict). So you could define an ordered dict by newordered = o{"llvm" : "ptyhon", "parrot" : "perl"} . (they should also probably have there own comprehensions as well o{foo for bar in foobar}). People nowadays think in terms of hashes and lists (especially with jsons and javascript not going away} and most of my time seems to be spent in different ways to store bits of data in memory in this way. It also seems to be the way to think in python (an object or a class object are just mappings themselves) Most packages that I have seen re- implement these different container types at one point anyway. It seems a shame they are not brought up to the top level, with potentially new, cleverer ones that have not been thought of yet. There will be potential to add different letters to the start when it seems that a certain mapping pattern seems in popular use. Am I crazy to think this is a good idea? I have not looked deeply pythons grammer to see if it conflicts with anything, but on the surface it looks fine. From mk.fraggod at gmail.com Sun Jun 14 07:25:10 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 17:25:10 +0600 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <20090614172510.5299448e@coercion> On Sun, 14 Jun 2009 04:02:47 -0700 (PDT) kindly wrote: > Am I crazy to think this is a good idea? I have not looked deeply > pythons grammer to see if it conflicts with anything, but on the > surface it looks fine. I'd say "on the surface it looks like perl" ;) I'd prefer to use dict() to declare a dict, not some mix of letters and incomprehensible symbols, thank you. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From kindly at gmail.com Sun Jun 14 07:36:17 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 04:36:17 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <20090614172510.5299448e@coercion> Message-ID: On Jun 14, 12:25?pm, Mike Kazantsev wrote: > On Sun, 14 Jun 2009 04:02:47 -0700 (PDT) > > kindly wrote: > > Am I crazy to think this is a good idea? ?I have not looked deeply > > pythons grammer to see if it conflicts with anything, but on the > > surface it looks fine. > > I'd say "on the surface it looks like perl" ;) > I'd prefer to use dict() to declare a dict, not some mix of letters and > incomprehensible symbols, thank you. > > -- > Mike Kazantsev // fraggod.net > > ?signature.asc > < 1KViewDownload Python already has it for strings r"foo" or u"bar". So I do not think its going against the grain. From stefan_ml at behnel.de Sun Jun 14 07:45:48 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 14 Jun 2009 13:45:48 +0200 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Hi, this kind of stuff is commonly discussed on the python-ideas mailing list. You might want to search that list and/or repost this over there. Stefan kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ordered = o{}, multidict = m{} (like paste multidict). So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . (they should also probably have there own > comprehensions as well o{foo for bar in foobar}). > > People nowadays think in terms of hashes and lists (especially with > jsons and javascript not going away} and most of my time seems to be > spent in different ways to store bits of data in memory in this way. > It also seems to be the way to think in python (an object or a class > object are just mappings themselves) Most packages that I have seen re- > implement these different container types at one point anyway. It > seems a shame they are not brought up to the top level, with > potentially new, cleverer ones that have not been thought of yet. > There will be potential to add different letters to the start when it > seems that a certain mapping pattern seems in popular use. > > Am I crazy to think this is a good idea? I have not looked deeply > pythons grammer to see if it conflicts with anything, but on the > surface it looks fine. From roy at panix.com Sun Jun 14 07:59:32 2009 From: roy at panix.com (Roy Smith) Date: Sun, 14 Jun 2009 07:59:32 -0400 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: In article <7x4ouj7dc5.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Roy Smith writes: > > In the same vein, Death March, by Ed Yourdon. > > I've been wanting to read "Antipatterns". I didn't think that was so great. It had a lot of hype, which lead to be believe it would be something wonderful, but I wasn't so impressed. From db3l.net at gmail.com Sun Jun 14 07:59:58 2009 From: db3l.net at gmail.com (David Bolen) Date: Sun, 14 Jun 2009 07:59:58 -0400 Subject: Off-topic: Usenet archiving history References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <87r5xn45rh.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > David Bolen writes: > >> Individual messages could include an Expires: header if they wished, > > Since we're already well off-topic: NNTP, HTTP, and email, and probably > other protocols as well, all deal with messages. They are all consistent > in defining a message [0] as having *exactly one* header. Heh, I'm not sure it's quite as consistent as you may think, particularly with older RFCs, which are relevant in this discussion since we're talking about historical artifacts. For example, while more recent mail RFCs like 2822 may specifically talk about header fields as the "header" (singular) of the message, the older RFC 822 instead refers to a "headers" (plural) section. > Every time you call a field from the header ?a header?, or refer to > the plural ?headers of a message?, the IETF kills a kitten. You > don't want to hurt a kitten, do you? Heaven forbid - though I'd think I could hold my own with the IETF. My reference to "header" was in lieu of "header line", something that the Usenet RFCs (1036, and the older 850) do extensively themselves. But I'll be more careful in the future - need to ensure kitten safety! -- David From arnodel at googlemail.com Sun Jun 14 08:04:39 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 14 Jun 2009 13:04:39 +0100 Subject: Measuring Fractal Dimension ? References: Message-ID: Lawrence D'Oliveiro writes: > In message , Peter Billam wrote: > >> Are there any modules, packages, whatever, that will >> measure the fractal dimensions of a dataset, e.g. a time-series ? > > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. I think there are attempts to estimate the fractal dimension of a set using a finite sample from this set. But I can't remember where I got this thought from! -- Arnaud From http Sun Jun 14 08:27:33 2009 From: http (Paul Rubin) Date: 14 Jun 2009 05:27:33 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: <7xy6rvuhje.fsf@ruckus.brouhaha.com> Roy Smith writes: > > I've been wanting to read "Antipatterns". > > I didn't think that was so great. It had a lot of hype, which lead to be > believe it would be something wonderful, but I wasn't so impressed. Hmm, good to know. Thanks. From http Sun Jun 14 08:30:11 2009 From: http (Paul Rubin) Date: 14 Jun 2009 05:30:11 -0700 Subject: Measuring Fractal Dimension ? References: Message-ID: <7xtz2juhf0.fsf@ruckus.brouhaha.com> Arnaud Delobelle writes: > I think there are attempts to estimate the fractal dimension of a set > using a finite sample from this set. But I can't remember where I got > this thought from! There are image data compression schemes that work like that, trying to detect self-similarity in the data. It can go the reverse way too. There was a program called Genuine Fractals that tried to increase the apparent resolution of photographs by adding artificial detail constructed from detected self-similarity. Its results were mixed, as I remember. From mk.fraggod at gmail.com Sun Jun 14 08:30:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Sun, 14 Jun 2009 18:30:35 +0600 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <20090614172510.5299448e@coercion> Message-ID: <20090614183035.737adc84@coercion> On Sun, 14 Jun 2009 04:36:17 -0700 (PDT) kindly wrote: > Python already has it for strings r"foo" or u"bar". So I do not think > its going against the grain. Yes, and there's other syntactic sugar like ";" (barely used), mentioned string types, "(element,)", "%s"%var or curly braces themselves. Some of them might even seem as unnecessary and redundant, but they should there to support legacy code, at least, and I don't think it's a good idea to add any more. In fact, py3 will drop "%s"%var syntax in favor of "{0}".format(var) and I think it's a good call. There's only so much sugar to add before it'll transform into salt and you'll start seeing lines like these: s**'@z!~;()=~$x>;%x>l;$(,'*e;y*%z),$;@=!;h(l~;*punch jokers;halt;*;print; I'm happy to use python because it discourages such syntax, among other things. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 08:59:24 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 22:59:24 +1000 Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <0244e656$0$20638$c3e8da3@news.astraweb.com> Stefan Behnel wrote: > Hi, > > this kind of stuff is commonly discussed on the python-ideas mailing list. > You might want to search that list and/or repost this over there. Please don't top-post here. If the OP takes this idea to python-ideas, chances are he'll be told to take the concept here first, for feedback, before python-ideas. More comments below: > kindly wrote: >> I am sure people have thought of this before, but I cant find where. >> I think that python should adapt a way of defining different types of >> mapping functions by proceeding a letter before the curly brackets. >> i.e ordered = o{}, multidict = m{} (like paste multidict). So you >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", >> "parrot" : "perl"} . (they should also probably have there own >> comprehensions as well o{foo for bar in foobar}). You can do that more readably: data = OrderedDict() data = SortedDict() data = MultiDict() etc. The advantages are: * no new syntax is needed; * you can have as many different types of mappings as needed, without needing to change the compiler or worry about clashes between letters; * not all mapping types necessarily have the same initialiser signature; * the mapping type doesn't need to be a built-in type. The analogy with raw strings is faulty: r"" changes the way the compiler interprets the characters between the quotes, it doesn't create a different type of object. There's nothing explicitly *wrong* with the idea of o{} m{} etc for a *small* number of built-in mapping types. If ordered dicts (say) ever become built-ins, rather than a type that you have to import from a module, then maybe we'll be looking for syntax for them, in which case there's worse ideas than o{}. But even then, a disadvantage would be that it's awfully perlish. There's already two uses for {}, namely dicts and sets, and I don't know that adding a third or more is a good idea. -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:01:30 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:01:30 +1000 Subject: Perl's @foo[3,7,1,-1] ? References: Message-ID: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> kj wrote: > OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be > ambiguous: does it mean the fourth element of foo, or the tuple > consisting of this element alone? I suppose that's good enough > reason to veto this idea... There's nothing ambiguous about it. obj.__getitem__(x) already accepts two different sorts of objects for x: ints and slice-objects: >>> range(8)[3] 3 >>> range(8)[slice(3)] [0, 1, 2] >>> range(8)[slice(3, None)] [3, 4, 5, 6, 7] >>> range(8)[slice(3, 4)] [3] Allowing tuple arguments need not be ambiguous: range(8)[3] => 3 range(8)[(3,)] => [3] range(8)[(3,5,6)] => [3, 5, 6] I've rarely needed to grab arbitrary items from a list in this fashion. I think a more common case would be extracting fields from a tuple. In any case, there are a few alternatives: Grab them all, and ignore some of them (ugly for more than one or two ignorable items): _, x, _, _, y, _, _, _, z, _ = range(10) # x=1, y=4, z=9 Subclass list to allow tuple slices: >>> class MyList(list): ... def __getitem__(self, obj): ... if type(obj) is tuple: ... return [self[i] for i in obj] ... else: ... return list.__getitem__(self, obj) ... >>> L = MyList(range(10)) >>> L[(1, 4, 8)] [1, 4, 8] Write a helper function: def getitems(L, *indexes): if len(indexes) == 1: indexes = indexes[0] return [L[i] for i in indexes] But I think this is an obvious enough extension to the __getitem__ protocol that I for one would vote +1 on it being added to Python sequence objects (lists, tuples, strings). -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:04:02 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:04:02 +1000 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <0244e76b$0$20638$c3e8da3@news.astraweb.com> Nathan Stoddard wrote: > The best way to become a good programmer is to program. Write a lot of > code; work on some large projects. This will improve your skill more than > anything else. I think there are about 100 million VB code-monkeys who prove that theory wrong. Seriously, and without denigrating any specific language, you can program by (almost) mindlessly following a fixed number of recipes and patterns. This will get the job done, but it won't make you a good programmer. -- Steven From cjw at ncf.ca Sun Jun 14 09:05:49 2009 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 14 Jun 2009 09:05:49 -0400 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Stefan Behnel wrote: > Hi, > > this kind of stuff is commonly discussed on the python-ideas mailing list. > You might want to search that list and/or repost this over there. > > Stefan > > kindly wrote: >> I am sure people have thought of this before, but I cant find where. >> I think that python should adapt a way of defining different types of >> mapping functions by proceeding a letter before the curly brackets. >> i.e ordered = o{}, multidict = m{} (like paste multidict). So you >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", >> "parrot" : "perl"} . (they should also probably have there own >> comprehensions as well o{foo for bar in foobar}). >> >> People nowadays think in terms of hashes and lists (especially with >> jsons and javascript not going away} and most of my time seems to be >> spent in different ways to store bits of data in memory in this way. >> It also seems to be the way to think in python (an object or a class >> object are just mappings themselves) Most packages that I have seen re- >> implement these different container types at one point anyway. It >> seems a shame they are not brought up to the top level, with >> potentially new, cleverer ones that have not been thought of yet. >> There will be potential to add different letters to the start when it >> seems that a certain mapping pattern seems in popular use. >> >> Am I crazy to think this is a good idea? I have not looked deeply >> pythons grammer to see if it conflicts with anything, but on the >> surface it looks fine. This has some appeal in the light of Python 3.1's ordered dictionary. Colin W. From graham.ashton at gmail.com Sun Jun 14 09:13:54 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:13:54 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x4ouj7dc5.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-14 03:34:34 +0100, Paul Rubin said: > Roy Smith writes: >> In the same vein, Death March, by Ed Yourdon. > > I've been wanting to read "Antipatterns". I bought it but couldn't get into it. Light on meat, heavy on boredom (for me - these things are always somewhat subjective). From deets at nospam.web.de Sun Jun 14 09:14:49 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 14 Jun 2009 15:14:49 +0200 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <0244e656$0$20638$c3e8da3@news.astraweb.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> Message-ID: <79kbe9F1qt9u4U2@mid.uni-berlin.de> > The analogy with raw strings is faulty: r"" changes the way the compiler > interprets the characters between the quotes, it doesn't create a different > type of object. But u"" does, as does the new bytestring-literal in Python3. So there is precedent. Diez From graham.ashton at gmail.com Sun Jun 14 09:15:56 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:15:56 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-14 06:38:32 +0100, koranthala said: > > The Pragmatic Programmer - Planning to buy, > Refactoring: Improving the Design of Existing Code - again planning to > buy, These are my top two recommendations for people who can already code a bit, but who want to get really really good. The first few chapters of Refactoring hold the key insights, the rest is examples. > The Little Schemer - I am not sure about buying this - I dont know > scheme If you want to learn functional programming, that's excellent. From graham.ashton at gmail.com Sun Jun 14 09:19:13 2009 From: graham.ashton at gmail.com (Graham Ashton) Date: Sun, 14 Jun 2009 14:19:13 +0100 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On 2009-06-14 14:04:02 +0100, Steven D'Aprano said: > Nathan Stoddard wrote: > >> The best way to become a good programmer is to program. Write a lot of >> code; work on some large projects. This will improve your skill more than >> anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. Really? So you don't think that the best way to get good at something is to practice? I think I'm paraphrasing Richard Feynman here, but the only way to truly understand something is to do it. Obviously a bit of guided learning is a major boon, but you can't be practice. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 09:25:20 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 14 Jun 2009 23:25:20 +1000 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> John Yeung wrote: > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. I think you're wrong. Mathematically, you can't mix types like real numbers and sets: while 1+0 = 1, you can't expect to get a sensible result from 1+{} or {1}?0. (If that character between the set and zero ends up missing, it's meant to be INTERSECTION u'\u2229'.) Similarly, you can't add a scalar to a vector or matrix, even if one or the other is null. > I find that it's somewhat like the confusion that often occurs > regarding the all() function. Some people are surprised that all([]) > returns True, but it's the same logic behind the truth of the > statement "every element of the empty set is an integer". It's also > true that every element of the empty set is a float. Or an elephant. So-called "vacuous truth". It's often useful to have all([]) return true, but it's not *always* useful -- there are reasonable cases where the opposite behaviour would be useful: if all(the evidence points to the Defendant's guilt) then: the Defendant is guilty execute(the Defendant) sadly means that if there is no evidence that a crime has been committed, the person accused of committing the imaginary crime will be executed. -- Steven From cd at okunah.de Sun Jun 14 09:27:25 2009 From: cd at okunah.de (Christof Donat) Date: Sun, 14 Jun 2009 15:27:25 +0200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: Hi, > Which are the classic books in computer science which one should > peruse? >From having read this discussion up to now I'd recomend you to read code written by good programmers. Christof From castironpi at gmail.com Sun Jun 14 09:27:32 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 06:27:32 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: <09cf0ce3-0bfa-4300-89ba-1233fb90dd83@3g2000yqk.googlegroups.com> On Jun 14, 4:02?am, kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ? ordered = o{}, ?multidict = m{} ?(like paste multidict). ?So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . ?(they should also probably have there own > comprehensions as well o{foo for bar in foobar}). That kind of stuff is highly explosive, unfortunately. o{ }, m{ }, d [ ], and q[ ] are just a few. But 'collections' is kind of sparse. I expect you would also want users to be able to define their own prefixes, no? As is, the syntax is not atrocious: oA= OrderedDict( [ ( pair1 ), ( pair2 ) ] oA= o{ pair1, pair2 } At least you can still include literals, and are not restricted to per- line additions as in C. snip > Most packages that I have seen re- > implement these different container types at one point anyway. It > seems a shame they are not brought up to the top level, with > potentially new, cleverer ones that have not been thought of yet. snip Do you merely want to populate the 'collections' module, or are the prefixes essential to your idea? From kindly at gmail.com Sun Jun 14 09:30:59 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 06:30:59 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4f168d3e-1c4e-4157-9469-7ee9c3b14c01@k19g2000prh.googlegroups.com> On Jun 14, 1:59?pm, Steven D'Aprano wrote: > Stefan Behnel wrote: > > Hi, > > > this kind of stuff is commonly discussed on the python-ideas mailing list. > > You might want to search that list and/or repost this over there. > > Please don't top-post here. > > If the OP takes this idea to python-ideas, chances are he'll be told to take > the concept here first, for feedback, before python-ideas. > > More comments below: > > > kindly wrote: > >> I am sure people have thought of this before, but I cant find where. > >> I think that python should adapt a way of defining different types of > >> mapping functions by proceeding a letter before the curly brackets. > >> i.e ? ordered = o{}, ?multidict = m{} ?(like paste multidict). ?So you > >> could define an ordered dict by newordered = o{"llvm" : "ptyhon", > >> "parrot" : "perl"} . ?(they should also probably have there own > >> comprehensions as well o{foo for bar in foobar}). > > You can do that more readably: > > data = OrderedDict() > data = SortedDict() > data = MultiDict() etc. > > The advantages are: > > * no new syntax is needed; > > * you can have as many different types of mappings as needed, without > needing to change the compiler or worry about clashes between letters; > > * not all mapping types necessarily have the same initialiser signature; > > * the mapping type doesn't need to be a built-in type. > > The analogy with raw strings is faulty: r"" changes the way the compiler > interprets the characters between the quotes, it doesn't create a different > type of object. > > There's nothing explicitly *wrong* with the idea of o{} m{} etc for a > *small* number of built-in mapping types. If ordered dicts (say) ever > become built-ins, rather than a type that you have to import from a module, > then maybe we'll be looking for syntax for them, in which case there's > worse ideas than o{}. But even then, a disadvantage would be that it's > awfully perlish. There's already two uses for {}, namely dicts and sets, > and I don't know that adding a third or more is a good idea. > > -- > Steven Thank you all for your feedback. I have never actually used perl, but I imagine if I did, I imagine I would have more disgust at the suger. I think my point is more that I think python should consider having more useful top level data structures and less to do with how they are created. There has been a big shift in the way people pass around structures and this is mainly due to the dict(hash) type, that python uses so well. I am glad the ordered dict will be in 2.7 and 3.1. I was just imagining what would be the next step in definition of structures. New languages like clojure have adopted the dict as top level. I imagine immutable/thread safe/transactional dicts to be around soon in other languages to help with concurrency. It would be nice if python was ahead of the game in this. From castironpi at gmail.com Sun Jun 14 09:36:12 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 06:36:12 -0700 (PDT) Subject: Different types of dicts with letter before the curly braces. References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> <4a34e2ec$0$31344$9b4e6d93@newsspool4.arcor-online.net> <0244e656$0$20638$c3e8da3@news.astraweb.com> <4f168d3e-1c4e-4157-9469-7ee9c3b14c01@k19g2000prh.googlegroups.com> Message-ID: <73c4e8eb-b018-4f01-bcac-0c9af171d144@37g2000yqp.googlegroups.com> On Jun 14, 6:30?am, kindly wrote: > On Jun 14, 1:59?pm, Steven D'Aprano snip > I am glad the ordered dict will be in 2.7 and 3.1. I > was just imagining what would be the next step in definition of > structures. New languages like clojure have adopted the dict as top > level. ?I imagine immutable/thread safe/transactional dicts to be > around soon in other languages to help with concurrency. ?It would be > nice if python was ahead of the game in this. Just not ahead of its /time/. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 10:00:56 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 00:00:56 +1000 Subject: Measuring Fractal Dimension ? References: Message-ID: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Lawrence D'Oliveiro wrote: > In message , Peter Billam wrote: > >> Are there any modules, packages, whatever, that will >> measure the fractal dimensions of a dataset, e.g. a time-series ? > > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. Incorrect. Koch's snowflake, for example, has a fractal dimension of log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial triangle, and a perimeter given by lim n->inf (4/3)**n. Although the perimeter is infinite, it is countably infinite and computable. Strictly speaking, there's not one definition of "fractal dimension", there are a number of them. One of the more useful is the "Hausdorf dimension", which relates to the idea of how your measurement of the size of a thing increases as you decrease the size of your yard-stick. The Hausdorf dimension can be statistically estimated for finite objects, e.g. the fractal dimension of the coast of Great Britain is approximately 1.25 while that of Norway is 1.52; cauliflower has a fractal dimension of 2.33 and crumpled balls of paper of 2.5; the surface of the human brain and lungs have fractal dimensions of 2.79 and 2.97. -- Steven From Scott.Daniels at Acm.Org Sun Jun 14 10:10:11 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 14 Jun 2009 07:10:11 -0700 Subject: Question about None In-Reply-To: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > ... or {1}?0. (If that character between the set and zero ends up missing, > it's meant to be INTERSECTION u'\u2229'.) Note that you can write this in a quite readable way in ASCII: "it's meant to be the character u'\N{INTERSECTION}'." --Scott David Daniels Scott.Daniels at Acm.Org From mwilson at the-wire.com Sun Jun 14 10:21:22 2009 From: mwilson at the-wire.com (Mel) Date: Sun, 14 Jun 2009 10:21:22 -0400 Subject: Question about None References: Message-ID: John Yeung wrote: > And I accept your answer, as well as Steven's and Paul's for that > matter. I still think it is understandable (and people may choose to > understand in a condescending way, if they wish) that someone might > not get the difference between what you are saying and the statement > that all elements of the empty set are floats. I mean, what's in the > empty set? Nothing. But you've said that floats are something. How > is it that nothing is something? It's sort of a logic equivalent of divide-by-zero. All elements of the empty set are floats. All elements of the empty set are ints. Ints are not floats. Therefore all elements of the empty set are not floats. You elaborate your logic to talk around this problem, and you quit when you get tired. Mel. From castironpi at gmail.com Sun Jun 14 10:27:29 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 07:27:29 -0700 (PDT) Subject: persistent composites Message-ID: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Hi, please forgive the multi-posting on this general topic. Some time ago, I recommended a pursuit of keeping 'persistent composite' types on disk, to be read and updated at other times by other processes. Databases provide this functionality, with the exception that field types in any given table are required to be uniform. Python has no such restriction. I tried out an implementation of composite collections, specifically lists, sets, and dicts, using 'sqlite3' as a persistence back-end. It's significantly slower, but we might argue that attempting to do it by hand classifies as a premature optimization; it is easy to optimize debugged code. The essentials of the implementation are: - each 'object' gets its own table. = this includes immutable types - a reference count table = when an object's ref. count reaches zero, its table is dropped - a type-map table = maps object's table ID to a string of its type - a single 'entry point' table, with the table ID of the entry-point object = the entry point is the only data structure available to new connections. (I imagine it will usually be a list or dict.) I will be sure to kill any interest you might have by now, by "revealing" a snippet of code. The object creation procedure: def new_table( self, type ): ''' 'type' is a string, the name of the class the object is an instance of ''' cur= self.conn.cursor( ) recs= cur.execute( '''SELECT max( tableid ) FROM refcounts''' ) rec= cur.fetchone( ) if rec[ 0 ] is None: obid= 0 else: obid= rec[ 0 ]+ 1 cur.execute( '''INSERT INTO types VALUES( ?, ? )''', ( obid, type ) ) cur.execute( '''INSERT INTO refcounts VALUES( ?, ? )''', ( obid, 1 ) ) The increment ref. count procedure: def incref( self, obid ): cur= self.conn.cursor( ) recs= cur.execute( '''SELECT count FROM refcounts WHERE tableid = ?''', ( obid, ) ) rec= recs.fetchone( ) newct= rec[ 0 ]+ 1 cur.execute( '''UPDATE refcounts SET count = ? WHERE tableid = ?''', ( newct, obid ) ) The top-level structure contains these two procedures, as well as 'setentry', 'getentry', and 'revive' procedures. Most notably, user-defined types are possible. The dict is merely a persistent dict. 'revive' checks the global namespace by name for the original type, subject to the same restrictions that we all know and love that 'pickle' has. As usual, deadlocks and cyclic garbage pose the usual problems. The approach I used last time was to maintain a graph of acquired locks, and merely check for cycles to avert deadlocks, which would go in a separate table. For garbage, I can't find a better solution than Python already uses. >From the 3.0 docs: gc.garbage A list of objects which the collector found to be unreachable but could not be freed (uncollectable objects). ... Python doesn?t collect such [garbage] cycles automatically because, in general, it isn?t possible for Python to guess a safe order in which to run the __del__() methods. If you know a safe order, you can force the issue by examining the garbage list, and explicitly breaking cycles due to your objects within the list. Before I go and flesh out the entire interfaces for the provided types, does anyone have a use for it? From kindly at gmail.com Sun Jun 14 10:54:12 2009 From: kindly at gmail.com (kindly) Date: Sun, 14 Jun 2009 07:54:12 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Jun 14, 3:27?pm, Aaron Brady wrote: > Hi, please forgive the multi-posting on this general topic. > > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. ?Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. ?Python has no such restriction. > > I tried out an implementation of composite collections, specifically > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > It's significantly slower, but we might argue that attempting to do it > by hand classifies as a premature optimization; it is easy to optimize > debugged code. > > The essentials of the implementation are: > ? - each 'object' gets its own table. > ? ? = this includes immutable types > ? - a reference count table > ? ? = when an object's ref. count reaches zero, its table is dropped > ? - a type-map table > ? ? = maps object's table ID to a string of its type > ? - a single 'entry point' table, with the table ID of the entry-point > object > ? ? = the entry point is the only data structure available to new > connections. ?(I imagine it will usually be a list or dict.) > > I will be sure to kill any interest you might have by now, by > "revealing" a snippet of code. > > The object creation procedure: > > def new_table( self, type ): > ? ''' 'type' is a string, the name of the class the object is an > instance of ''' > ? cur= self.conn.cursor( ) > ? recs= cur.execute( '''SELECT max( tableid ) FROM refcounts''' ) > ? rec= cur.fetchone( ) > ? if rec[ 0 ] is None: > ? ? obid= 0 > ? else: > ? ? obid= rec[ 0 ]+ 1 > ? cur.execute( '''INSERT INTO types VALUES( ?, ? )''', ( obid, > type ) ) > ? cur.execute( '''INSERT INTO refcounts VALUES( ?, ? )''', ( obid, > 1 ) ) > > The increment ref. count procedure: > > def incref( self, obid ): > ? cur= self.conn.cursor( ) > ? recs= cur.execute( '''SELECT count FROM refcounts WHERE tableid > = ?''', ( obid, ) ) > ? rec= recs.fetchone( ) > ? newct= rec[ 0 ]+ 1 > ? cur.execute( '''UPDATE refcounts SET count = ? WHERE tableid = ?''', > ( newct, obid ) ) > > The top-level structure contains these two procedures, as well as > 'setentry', 'getentry', and 'revive' procedures. > > Most notably, user-defined types are possible. ?The dict is merely a > persistent dict. ?'revive' checks the global namespace by name for the > original type, subject to the same restrictions that we all know and > love that 'pickle' has. > > As usual, deadlocks and cyclic garbage pose the usual problems. ?The > approach I used last time was to maintain a graph of acquired locks, > and merely check for cycles to avert deadlocks, which would go in a > separate table. ?For garbage, I can't find a better solution than > Python already uses. > > From the 3.0 docs: > gc.garbage > > ? ? A list of objects which the collector found to be unreachable but > could not be freed (uncollectable objects). > ... > Python doesn?t collect such [garbage] cycles automatically because, in > general, it isn?t possible for Python to guess a safe order in which > to run the __del__() methods. If you know a safe order, you can force > the issue by examining the garbage list, and explicitly breaking > cycles due to your objects within the list. > > Before I go and flesh out the entire interfaces for the provided > types, does anyone have a use for it? I like it as a concept, have not got any use for it this minute, but I am sure it will be useful someday. From rustompmody at gmail.com Sun Jun 14 11:00:17 2009 From: rustompmody at gmail.com (rustom) Date: Sun, 14 Jun 2009 08:00:17 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Jun 14, 6:04?pm, Steven D'Aprano wrote: > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > > Seriously, and without denigrating any specific language, you can program by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. When Dijkstra was asked what next programming language to learn he would typically recommend Latin :-) > Really? So you don't think that the best way to get good at something > is to practice? I think I'm paraphrasing Richard Feynman here, but the > only way to truly understand something is to do it. > Obviously a bit of guided learning is a major boon, but you can't be practice. For every one Horowitz there are a thousand wannbes thumping on the piano trying to become Horowitz. The traction that practice gives is maximal only in the beginning. From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 11:07:56 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 01:07:56 +1000 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Graham Ashton wrote: > On 2009-06-14 14:04:02 +0100, Steven D'Aprano > said: > >> Nathan Stoddard wrote: >> >>> The best way to become a good programmer is to program. Write a lot of >>> code; work on some large projects. This will improve your skill more >>> than anything else. >> >> I think there are about 100 million VB code-monkeys who prove that theory >> wrong. > > Really? So you don't think that the best way to get good at something > is to practice? Shame on you for deliberately cutting out my more serious and nuanced answer while leaving a silly quip. As I went on to say: "... you can program by (almost) mindlessly following a fixed number of recipes and patterns. This will get the job done, but it won't make you a good programmer." There are huge numbers (millions?) of lousy programmers who program every single day and never become good programmers. "Practice makes perfect" only works for mechanical skills and rote learning, neither of which are especially applicable to good programming. (Although rote learning is helpful for reducing the time taken to look up syntax and library functions.) Without some level of understanding and creativity, as soon as you hit a problem that can't be efficiently solved by one of the patterns or recipes you've learned, you're in trouble. All the practice in the world won't give you the discipline to write appropriate comments, or to test your code thoroughly. Practice won't *necessarily* make you creative -- you can't be creative in a field you know nothing about, but having learned the language and the libraries doesn't necessarily mean you can apply the tools to solve novel problems. Many programmers know a few good tricks, and try to hammer every problem into a form that can be solved by one of the few tricks they know, no matter whether it is appropriate or not. Witness how many people try to write regexes to parse bracketed expressions, a problem which requires a proper parser. (This is not necessarily a bad thing, but it often is.) You could write a piece of code like: s = "" for word in some_data: s += " " + word a thousand times a day, and *never* learn that this is Bad Code, because you never profile it with more than a few thousand words and so never discover that it's O(n**2). Eventually when it gets released into the real world, somebody reports that it takes eight hours to process 100MB of words, and then *some other guy* re-writes your code to use s = " ".join(words), and you remain in blissful ignorance, happily writing your bad code every single time. > I think I'm paraphrasing Richard Feynman here, but the > only way to truly understand something is to do it. An amazingly inappropriate quote for a *theoretical* physicist to have said. Whether Feynman did or didn't say that, it's clearly untrue: many people do without understanding. Many people can cook, some people are expert cooks, but few people understand precisely what takes place when you cook food. People can catch and throw balls, and have little or no understanding of gravity, air-resistance, and the mechanics of their own bodies. In fact... just before you hit Delete on this post, how about you explain *how* you make your finger reach out and press the Delete key? You probably move bits of your body a million times a day, and the chances are very high that until now, you've never once noticed that you have no idea how you do it. I think that simple fact blows out of the water the concept that doing implies understanding. > Obviously a bit of guided learning is a major boon, but you can't be > practice. I didn't say that practice was useless. Arguably, it may even be necessary to be a good programmer. (Although less so for an unsurprising language like Python, where it is very common to write code which works correctly the first time.) But practice is clearly not *sufficient* to be a good programmer. -- Steven From steve at REMOVETHIS.cybersource.com.au Sun Jun 14 11:24:48 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 15 Jun 2009 01:24:48 +1000 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <02450869$0$20636$c3e8da3@news.astraweb.com> Aaron Brady wrote: > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. Python has no such restriction. ... > I will be sure to kill any interest you might have by now, by > "revealing" a snippet of code. How about telling us what problem you're trying to solve? Giving us your implementation isn't useful if we don't even know what it's for. Persistent data on disk, okay, I get that -- but how is it different from (say) XML, or INI files, or pickles, or similar? Is the idea to have *live* data stored on disk, updated by multiple processes simultaneously? Don't assume that people will remember your recommendation from "some time ago". -- Steven From piet at cs.uu.nl Sun Jun 14 11:37:04 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 14 Jun 2009 17:37:04 +0200 Subject: Question about None References: Message-ID: >>>>> John Yeung (JY) wrote: >JY> I've never heard a mathematician use the term "bottom". It certainly >JY> could be that I just haven't talked to the right types of >JY> mathematicians. "Bottom" is a term from lattice theory, which is a branch of mathematics. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From spam.helmut.hard at gmail.com Sun Jun 14 11:42:23 2009 From: spam.helmut.hard at gmail.com (Helmut Fritz) Date: Sun, 14 Jun 2009 17:42:23 +0200 Subject: shoehorn c-structured data into Numpy Message-ID: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Hello there everyone, I used to be on this a long time ago but then I got so much spam I gave up. But this strategy has come a little unstuck. I have binary output from a Fortran program that is in a big-endian C-structured binary file. The output can be very variable and many options create different orderings in the binary file. So I'd like to keep the header-reading in python. Anyhoo, I've so far been able to read the output with the struct module. But my question is how do I create numpy arrays from the bits of the file I want? So far I've been able to scan through to the relevant sections and I've tried all maner of idiotic combinations... The floats are 4 bytes for sinngle percision, and it's a unstructured grid from a finite difference scheme so I know the number of cells (ncells) for the property I am looking to extract. So I've tried: TC1 = np.frombuffer(struct.unpack(">%df" % ncells, data.read(4*ncells))[0], dtype=float) Only to get a very logical: >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 239, in spmapdat >>> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, data.read(4*ncells))[0], dtype=float) >>> AttributeError: 'float' object has no attribute '__buffer__' ok... so I'll feed frombuffer my data file... And then tried: TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 240, in spmapdat >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) >>> ValueError: buffer is smaller than requested size And THEN I tried: TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) >>> Traceback (most recent call last): >>> File "a2o.py", line 466, in >>> runme(me) >>> File "a2o.py", line 438, in runme >>> me.spmapdat(data) >>> File "a2o.py", line 240, in spmapdat >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) >>> ValueError: buffer is smaller than requested size But it's the right size - honest. (In general) I should be able to put these arrays into memory with no problems. Certainly given the rate at which I'm turning around this code... Memory may be in the terabytes once I'm done. Anyone got a Sesame Street answer for this? Many thanks! Helmut. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Sun Jun 14 11:49:42 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 17:49:42 +0200 Subject: Question about None In-Reply-To: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <6faf39c90906140849v37c0f5dfu251c4e678db9483@mail.gmail.com> On Sat, Jun 13, 2009 at 7:23 PM, John Yeung wrote: > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. ?It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. ?In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. I don't see why that would be the case. Something of the type "thingy" is ONE thingy. Nothing is ZERO thingies, so it is not something of the type "thingy". A car is a single car. Nothing is zero cars, which is not a car, just like two cars is not a car. -- Andr? Engels, andreengels at gmail.com From martin at v.loewis.de Sun Jun 14 11:52:32 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 14 Jun 2009 17:52:32 +0200 Subject: Generating a unique filename in the face of unicode filename In-Reply-To: References: Message-ID: <4a351cc1$0$20516$9b622d9e@news.freenet.de> > where line 175 is the assignment to self.unique_name. After a little > back-and-forth with his user it turns out that her computer's hostname > contains non-ASCII data, so presumably self.hostname is a unicode object. Most likely, it is not. It's rather the hostname encoded in the ANSI code page. > It works for Frank on his Windows box as well. Any ideas how to properly > Unicode-proof this code? You should first decode the gethostname result, using the locale's encoding; expect this decoding to fail possibly, so the "ignore" error handler might be your best choice. Regards, Martin From koranthala at gmail.com Sun Jun 14 12:01:26 2009 From: koranthala at gmail.com (koranthala) Date: Sun, 14 Jun 2009 09:01:26 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: <33972035-e5fd-4b5b-ac9b-128cb15ee2d0@d7g2000prl.googlegroups.com> > There are huge numbers (millions?) of lousy programmers who program every > single day and never become good programmers. I think I can attest to that. I was a programmer (in a low level language) in a huge MNC code monkey shop for > 7 years. I consider myself to be Ok - not great, but not very poor either. I had written a lot of code in those 7 years, but due to lack of exposure and laziness, never knew that I have to read books. As I mentioned before, I come in from a non-computing engineering degree, so I did not even know which books to read etc. I had seen many of the frameworks written by others, and was extremely impressed. I considered those people who wrote those frameworks to be geniuses - until I accidently came across one site where I read about GOF. I bought it and read it - and straight away understood that whatever I learned in the last 7 years, I could have learned most of them in 6 months, provided I had read the right books. All the frameworks were just amalgamation of these patterns. Now, I voraciously purchase and read books - both in the domain of my work and on computer science in general. Even though I am not going to be recruited by google any time soon :-), I think I have become a much better programmer over the last one year. I see my code before 1 year and I am horrified :-). Practice makes perfect only if you push yourself - and you need exposure to know that. From cjns1989 at gmail.com Sun Jun 14 12:15:59 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 14 Jun 2009 12:15:59 -0400 Subject: Good books in computer science? In-Reply-To: <0244e76b$0$20638$c3e8da3@news.astraweb.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <20090614161559.GB2558@turki.gavron.org> On Sun, Jun 14, 2009 at 09:04:02AM EDT, Steven D'Aprano wrote: > Nathan Stoddard wrote: > > > The best way to become a good programmer is to program. Write a lot of > > code; work on some large projects. This will improve your skill more than > > anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > > Seriously, and without denigrating any specific language, you can program by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. Vivaldi vs. Mozart And the latter especially had definitely mastered his editor. Just think of the sheer volume of the coding he managed during his short life. Not many bugs either? CJ From fsb at thefsb.org Sun Jun 14 12:35:24 2009 From: fsb at thefsb.org (tom) Date: Sun, 14 Jun 2009 09:35:24 -0700 (PDT) Subject: waling a directory with very many files Message-ID: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for example, in c, perl or php one can use opendir() and then repeatedly readdir() until getting to the end of the file list. it seems this could be more efficient in some applications. is there a way to do this in python? i'm relatively new to the language. i looked through the documentation and tried googling but came up empty. From castironpi at gmail.com Sun Jun 14 12:41:06 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 09:41:06 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <02450869$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Jun 14, 8:24?am, Steven D'Aprano wrote: > Aaron Brady wrote: > > Some time ago, I recommended a pursuit of keeping 'persistent > > composite' types on disk, to be read and updated at other times by > > other processes. ?Databases provide this functionality, with the > > exception that field types in any given table are required to be > > uniform. ?Python has no such restriction. > ... > > I will be sure to kill any interest you might have by now, by > > "revealing" a snippet of code. > > How about telling us what problem you're trying to solve? Giving us your > implementation isn't useful if we don't even know what it's for. Persistent > data on disk, okay, I get that -- but how is it different from (say) XML, > or INI files, or pickles, or similar? Is the idea to have *live* data > stored on disk, updated by multiple processes simultaneously? Don't assume > that people will remember your recommendation from "some time ago". > > -- > Steven It was no time at all in the Usenet world, I suppose. There are lots of strategies for storing data on a disk, and lots of strategies for storing data in memory. I was trying on disk what Python uses on memory. If you want to argue that Python isn't useful, you're in the wrong place. If you want to argue that Python's strategy is useful on disks, you're talking to the right person. I'll draw an analogy. static data structures : sql & co. :: Python data structures : this undertaking. It has all the advantages over SQL & XML structures that Python has over C structures: sort of a 'worst of neither' combination. I haven't written a textbook on DSs, though, so I don't quite know where to begin. In my eyes, you're practically asking, "What's your use case for Python?" Either that, or I don't know enough other languages. I have nothing to use it for, but someone might, and it might be just plumb interesting to fellow Pythoneers. If I did, I'd have somewhere to start. From paul.lafollette at gmail.com Sun Jun 14 12:49:56 2009 From: paul.lafollette at gmail.com (Paul LaFollette) Date: Sun, 14 Jun 2009 12:49:56 -0400 Subject: Question about None Message-ID: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Thank you all for your thoughtful and useful comments. Since this has largely morphed into a discussion of my 3rd question, perhaps it would interest you to hear my reason for asking it. John is just about spot on. Part of my research involves the enumeration and generation of various combinatorial objects using what are called "loopless" or "constant time" algorithms. (This means that the time required to move from one object to the next is bounded by a constant that is independent of the size of the object. It is related to following idea: If I generate all of the possible patterns expressible with N bits by simply counting in binary, as many as N bits may change from one pattern to the next. On the other hand if I use Gray code only one bit changes from each pattern to the next. If you are interested in this essentially useless (but fun) subject, the seminal paper by Gideon Ehrlich is here: http://portal.acm.org/citation.cfm?id=321781 ) Now, suppose that I want to generate, say, the set of all ordered trees with N nodes. I need to be able to represent the empty ordered tree, i.e. the tree with with zero nodes. There are a lot of ways I could do this. The problem is that I might tomorrow be looking instead at rooted trees, or free trees, or Young tableaux and in each case I will need to represent the empty rooted tree, or the empty free tree, or the empty Young tableau. In a very real sense, the empty Young tableau IS a Young tableau and the empty ordered tree IS an ordered tree. But in an equally real sense they are the same "ghost of a thing" looked at in different universes of discourse. So, what I would like is some sort of object that is a "kind of" everything but contains nothing, a unique minimal element of the partial ordering imposed on the set of classes by the inheritance heierarchy. Whilst I am not naive mathematically, I am relatively naive in the area of language design. In my naivete, it seemed to me that None could have been designed to be such a thing. Apparently that is incorrect. The matter is not urgent, there are oodles of workarounds. Indeed, having once found a particular loopless algorithm I don't necessarily publish an implementation of it, but rather a formal description and proof of correctness. Still, before I submit things for publication I generally prefer to implement them for myself just to convince myself that what I have proved correct in fact works at least for modest values of N. Paul ____________________________________ paul[dot]lafollette[at]gmail.com http://www.cis.temple.edu/~lafollet From arnodel at googlemail.com Sun Jun 14 13:02:54 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 14 Jun 2009 18:02:54 +0100 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > So-called "vacuous truth". It's often useful to have all([]) return true, > but it's not *always* useful -- there are reasonable cases where the > opposite behaviour would be useful: > > if all(the evidence points to the Defendant's guilt) then: > the Defendant is guilty > execute(the Defendant) > > sadly means that if there is no evidence that a crime has been committed, > the person accused of committing the imaginary crime will be executed. This is a bad example. Someone is not convicted of a crime just because all the available evidence points towards their guilt. There may be very little evidence altogether, or it might just be circumstancial, or unconvincing. Even though it may all point towards the defendent's guilt, it doesn't mean they will be convicted. There needs to be enough evidence to convince the jury. So it would be something like: if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: the defendant is guilty ... -- Arnaud From python at mrabarnett.plus.com Sun Jun 14 13:17:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 18:17:17 +0100 Subject: shoehorn c-structured data into Numpy In-Reply-To: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> References: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Message-ID: <4A35309D.5040005@mrabarnett.plus.com> Helmut Fritz wrote: > > Hello there everyone, I used to be on this a long time ago but then I > got so much spam I gave up. > > But this strategy has come a little unstuck. I have binary output from > a Fortran program that is in a big-endian C-structured binary file. The > output can be very variable and many options create different orderings > in the binary file. So I'd like to keep the header-reading in python. > > Anyhoo, I've so far been able to read the output with the struct > module. But my question is how do I create numpy arrays from the bits > of the file I want? > > So far I've been able to scan through to the relevant sections and I've > tried all maner of idiotic combinations... > > The floats are 4 bytes for sinngle percision, and it's a unstructured > grid from a finite difference scheme so I know the number of cells > (ncells) for the property I am looking to extract. > > So I've tried: > TC1 = np.frombuffer(struct.unpack(">%df" % ncells, > data.read(4*ncells))[0], dtype=float) > Only to get a very logical: > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 239, in spmapdat > >>> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, > data.read(4*ncells))[0], dtype=float) > >>> AttributeError: 'float' object has no attribute '__buffer__' > This: struct.unpack(">%df" % ncells, data.read(4*ncells)) unpacks to a tuple of floats, from which you get the first (actually the zeroth) float. You probably didn't want to do that! :-) Try: TC1 = np.array(struct.unpack(">%df" % ncells, data.read(4 * ncells)), dtype=float) > ok... so I'll feed frombuffer my data file... > > And then tried: > TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 240, in spmapdat > >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=ncells) > >>> ValueError: buffer is smaller than requested size > > And THEN I tried: > TC1 = np.frombuffer(data.read(4*ncells), dtype=float, count=4*ncells) > >>> Traceback (most recent call last): > >>> File "a2o.py", line 466, in > >>> runme(me) > >>> File "a2o.py", line 438, in runme > >>> me.spmapdat(data) > >>> File "a2o.py", line 240, in spmapdat > >>> TC1 = np.frombuffer(data.read(4*ncells), dtype=float, > count=4*ncells) > >>> ValueError: buffer is smaller than requested size > > But it's the right size - honest. > > (In general) I should be able to put these arrays into memory with no > problems. Certainly given the rate at which I'm turning around this > code... Memory may be in the terabytes once I'm done. > > Anyone got a Sesame Street answer for this? > > Many thanks! Helmut. > From jaime.frio at gmail.com Sun Jun 14 13:18:53 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Sun, 14 Jun 2009 19:18:53 +0200 Subject: persistent composites In-Reply-To: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <97a8f1a70906141018r6a2fd83es388262b764f9229b@mail.gmail.com> On Sun, Jun 14, 2009 at 4:27 PM, Aaron Brady wrote: > > Before I go and flesh out the entire interfaces for the provided > types, does anyone have a use for it? A real-world application of persistent data structures can be found here: http://stevekrenzel.com/persistent-list Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From andreengels at gmail.com Sun Jun 14 13:26:31 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 19:26:31 +0200 Subject: Question about None In-Reply-To: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Message-ID: <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> On Sun, Jun 14, 2009 at 6:49 PM, Paul LaFollette wrote: > Now, suppose that I want to generate, say, the set of all ordered > trees with N nodes. ? I need to be able to represent the empty ordered > tree, i.e. the tree with with zero nodes. ?There are a lot of ways I > could do this. ?The problem is that I might tomorrow be looking > instead at rooted trees, or free trees, or Young tableaux and in each > case I will need to represent the empty rooted tree, or the empty free > tree, or the empty Young tableau. > > In a very real sense, the empty Young tableau IS a Young tableau and > the empty ordered tree IS an ordered tree. ?But in an equally real > sense they are the same "ghost of a thing" looked at in different > universes of discourse. But do you also want the empty Young tableau to BE an ordered tree? A number? A diddlewoodaddy? It seems much more logical to me to define your Young tableaus such that the definition includes the empty one as well. -- Andr? Engels, andreengels at gmail.com From mail at timgolden.me.uk Sun Jun 14 13:35:23 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 14 Jun 2009 18:35:23 +0100 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A3534DB.5080604@timgolden.me.uk> tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). TJG From python at mrabarnett.plus.com Sun Jun 14 14:00:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 19:00:26 +0100 Subject: Question about None In-Reply-To: <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> <6faf39c90906141026m126b36b7g9c799dd0fe94c68f@mail.gmail.com> Message-ID: <4A353ABA.7030206@mrabarnett.plus.com> Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:49 PM, Paul > LaFollette wrote: >> Now, suppose that I want to generate, say, the set of all ordered >> trees with N nodes. I need to be able to represent the empty ordered >> tree, i.e. the tree with with zero nodes. There are a lot of ways I >> could do this. The problem is that I might tomorrow be looking >> instead at rooted trees, or free trees, or Young tableaux and in each >> case I will need to represent the empty rooted tree, or the empty free >> tree, or the empty Young tableau. >> >> In a very real sense, the empty Young tableau IS a Young tableau and >> the empty ordered tree IS an ordered tree. But in an equally real >> sense they are the same "ghost of a thing" looked at in different >> universes of discourse. > > But do you also want the empty Young tableau to BE an ordered tree? A > number? A diddlewoodaddy? It seems much more logical to me to define > your Young tableaus such that the definition includes the empty one as > well. > For strings there's the empty string with the same methods. It's not the same as None. For lists there's the empty list with the same methods. It's not the same as None. For dicts there's the empty dict with the same methods. It's not the same as None. For sets there's the empty set with the same methods. It's not the same as None. etc. From fsb at thefsb.org Sun Jun 14 14:32:12 2009 From: fsb at thefsb.org (tom) Date: Sun, 14 Jun 2009 11:32:12 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> On Jun 14, 1:35?pm, Tim Golden wrote: > > If you're on Windows, you can use the win32file.FindFilesIterator > function from the pywin32 package. (Which wraps the Win32 API > FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd and os x. From castironpi at gmail.com Sun Jun 14 14:32:35 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 11:32:35 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: <9638ebf3-a8df-4113-9dbc-d941eede562c@i28g2000prd.googlegroups.com> On Jun 14, 10:02?am, Arnaud Delobelle wrote: snip > guilt, it doesn't mean they will be convicted. ?There needs to be enough > evidence to convince the jury. ?So it would be something like: > > if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: > ? ?the defendant is guilty > ? ?... > > -- > Arnaud You all are only two months late. http://groups.google.com/group/comp.lang.python/msg/7b63d0d11246ecad Can't argue with results. From CGenie at gmail.com Sun Jun 14 14:43:17 2009 From: CGenie at gmail.com (CoolGenie) Date: Sun, 14 Jun 2009 11:43:17 -0700 (PDT) Subject: efficient undo/redo in pyqt Message-ID: Hello, I'm writing a small component for drawing, in PyQt4. Currently I'm implementing undo/redo through Qt's framework. I create a list which contains points, lines, etc. which appear as the user draws on the screen. On every paint event the list is read, processed and drawn. This way doing is just adding elements, and undoing is popping them from the list. My question: is this an efficient way or could this be done any better? The code is here http://sourceforge.net/svn/?group_id=252201 if anyone is interested. Best regards, Przemek From jeremy.r.fishman at gmail.com Sun Jun 14 15:00:33 2009 From: jeremy.r.fishman at gmail.com (Jeremy) Date: Sun, 14 Jun 2009 12:00:33 -0700 (PDT) Subject: weakrefs, threads,, and object ids Message-ID: <84397edd-4830-4c90-9fb6-f72c74028f6e@i28g2000prd.googlegroups.com> Hello, I'm using weakrefs in a small multi-threaded application. I have been using object IDs as dictionary keys with weakrefs to execute removal code, and was glad to find out that this is in fact recommended practice (http://docs.python.org/library/weakref.html) > This simple example shows how an application can use objects IDs to retrieve > objects that it has seen before. The IDs of the objects can then be used in other > data structures without forcing the objects to remain alive, but the objects can > still be retrieved by ID if they do. After reading this, I realized it made no explicit mention of thread safety in this section, whereas other sections made a note of correct practice with threads. The docs for the id() function specify > Return the identity of an object. This is guaranteed to be unique among > simultaneously existing objects. (Hint: it's the object's memory address.) While guaranteed unique for simultaneously existing objects, how often will an object assume an ID previously held by former object? Given that the ID is a memory address in Python's heap, I assume the answer is either not often, or very often. Specifically, I'm wondering if the case can occur that the callback for a weakref is executed after another object has been allocated with the same object identifier as a previous object. If such an object is inserted into a module-level dictionary, could it over-write a previous entry with the same identifier and then get deleted whenever the weakref callback happens to fire? On a related note, what is a recommended way to obtain a weak reference to a thread? From pataphor at gmail.com Sun Jun 14 15:14:55 2009 From: pataphor at gmail.com (pataphor) Date: Sun, 14 Jun 2009 21:14:55 +0200 Subject: left brain and right brain permutations Message-ID: left brain: Generate permutations by index, see previous newsgroup posts. Code not now available here. They are very pragmatic and practical, can start right away, and can be efficiently spread over many independent computing cores. right brain: from itertools import izip, chain from math import factorial def expand(i,n): for _ in xrange(i+1): yield i+1 for _ in xrange(n-i): yield i def firstrow(n): for i in xrange(n+1): for _ in xrange(factorial(n)): yield i def otherrow(x,n): return chain(*izip(*(expand(i,n) for i in x))) def nextperm(L,n): yield firstrow(n) for x in L: yield otherrow(x,n) def perm(n): L = [[0]] for i in xrange(1,n): L = nextperm(L,i) return izip(*L) They are very hard to understand but can yield deep insights, once one gets into them they hint at hidden regularities and symmetries, maybe even parallel worlds. Unfortunately they are very impractical because they generate their future out of previous results. Until someone invents a quantum computer. From that point on though they leave every left brain piece of code behind as if that old code would stand still on its spot. So, its not like I don't understand the functional mind, believe me, I would like nothing more than to go that way, but until quantum computing is there this stuff won't be able to compete. (Background, ignore this post, it is just for future reference, comments are still welcome though) P. From benjamin.kaplan at case.edu Sun Jun 14 15:16:04 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 14 Jun 2009 15:16:04 -0400 Subject: Good books in computer science? In-Reply-To: <0244e76b$0$20638$c3e8da3@news.astraweb.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Sun, Jun 14, 2009 at 9:04 AM, Steven D'Aprano < steve at removethis.cybersource.com.au> wrote: > Nathan Stoddard wrote: > > > The best way to become a good programmer is to program. Write a lot of > > code; work on some large projects. This will improve your skill more than > > anything else. > > I think there are about 100 million VB code-monkeys who prove that theory > wrong. > There aren't 100 million VB code-monkeys. There are 100 million VB drag-and-drop monkeys, but they never actually wrote any program by themselves- Daddy Microsoft wrote a lot of it for them. > > Seriously, and without denigrating any specific language, you can program > by > (almost) mindlessly following a fixed number of recipes and patterns. This > will get the job done, but it won't make you a good programmer. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Sun Jun 14 15:21:51 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 14 Jun 2009 20:21:51 +0100 Subject: waling a directory with very many files In-Reply-To: <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: <4A354DCF.8070105@timgolden.me.uk> tom wrote: > On Jun 14, 1:35 pm, Tim Golden wrote: >> If you're on Windows, you can use the win32file.FindFilesIterator >> function from the pywin32 package. (Which wraps the Win32 API >> FindFirstFile / FindNextFile pattern). > > thanks, tim. > > however, i'm not using windows. freebsd and os x. Presumably, if Perl etc. can do it then it should be simple enough to drop into ctypes and call the same library code, no? (I'm not a BSD / OS X person, I'm afraid, so perhaps this isn't so easy...) TJG From http Sun Jun 14 15:37:34 2009 From: http (Paul Rubin) Date: 14 Jun 2009 12:37:34 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Andre Engels writes: > I don't see why that would be the case. Something of the type "thingy" > is ONE thingy. Nothing is ZERO thingies, so it is not something of the > type "thingy". A car is a single car. Nothing is zero cars, which is > not a car, just like two cars is not a car. That seems to confuse values with collections of them. A car is not the same as a one-element list of cars. Nothing is not the same as a zero-element list of cars. From andreengels at gmail.com Sun Jun 14 16:11:18 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:11:18 +0200 Subject: Question about None In-Reply-To: <7xfxe2ehdt.fsf@ruckus.brouhaha.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: <6faf39c90906141311x779d459dhbe87a63b2b7b65a8@mail.gmail.com> On Sun, Jun 14, 2009 at 9:37 PM, Paul Rubin wrote: > Andre Engels writes: >> I don't see why that would be the case. Something of the type "thingy" >> is ONE thingy. Nothing is ZERO thingies, so it is not something of the >> type "thingy". A car is a single car. Nothing is zero cars, which is >> not a car, just like two cars is not a car. > > That seems to confuse values with collections of them. ?A car is not > the same as a one-element list of cars. ?Nothing is not the same as a > zero-element list of cars. So you are of the opinion that "nothing" _is_ a car? -- Andr? Engels, andreengels at gmail.com From http Sun Jun 14 16:21:14 2009 From: http (Paul Rubin) Date: 14 Jun 2009 13:21:14 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: <7xprd6o9c5.fsf@ruckus.brouhaha.com> Andre Engels writes: > > That seems to confuse values with collections of them. ??A car is not > > the same as a one-element list of cars. ??Nothing is not the same as a > > zero-element list of cars. > > So you are of the opinion that "nothing" _is_ a car? Eh? No of course not. a != b and b != c does not mean a==c. I don't understand what you're getting at. From andreengels at gmail.com Sun Jun 14 16:30:32 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:30:32 +0200 Subject: Question about None In-Reply-To: <7xprd6o9c5.fsf@ruckus.brouhaha.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> <7xprd6o9c5.fsf@ruckus.brouhaha.com> Message-ID: <6faf39c90906141330pc4cce2ai3dba204eefdb72d2@mail.gmail.com> On Sun, Jun 14, 2009 at 10:21 PM, Paul Rubin wrote: > Andre Engels writes: >> > That seems to confuse values with collections of them. ??A car is not >> > the same as a one-element list of cars. ??Nothing is not the same as a >> > zero-element list of cars. >> >> So you are of the opinion that "nothing" _is_ a car? > > Eh? ?No of course not. ?a != b and b != c does not mean a==c. > I don't understand what you're getting at. I was making a point that I don't agree that "nothing" would match any type. The reason was that anything of the type car is one car, not two cars or zero cars, but "nothing" is zero cars. You don't agree with me, so apparently you are of the opinion that "nothing" would be a car. -- Andr? Engels, andreengels at gmail.com From Scott.Daniels at Acm.Org Sun Jun 14 16:32:07 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 14 Jun 2009 13:32:07 -0700 Subject: shoehorn c-structured data into Numpy In-Reply-To: References: <8b0a63e80906140842o611a2371v75530b1cb9c7dc56@mail.gmail.com> Message-ID: MRAB wrote: > Helmut Fritz wrote: >> I have binary output >> from a Fortran program that is in a big-endian C-structured binary >> file. The output can be very variable and many options create >> different orderings in the binary file. So I'd like to keep the >> header-reading in python. >> >> Anyhoo, I've so far been able to read the output with the struct >> module. But my question is how do I create numpy arrays from the bits >> of the file I want? >> TC1 = np.frombuffer(struct.unpack(">%df" % ncells, >> data.read(4*ncells))[0], dtype=float) Note both struct and numpy.frombuffer unpack data from a buffer. Do it only once: If you are going to a numpy array: TC1 = np.frombuffer(data.read(4*ncells)), dtype=float) # and possibly: TC1.byteswap(True) # True to byteswap in place. Or (even better -- less copying): TC1 = np.fromfile(data, count=ncells, dtype=float) # and again, possibly: TC1.byteswap(True) # True to byteswap in place. --Scott David Daniels Scott.Daniels at Acm.Org From andreengels at gmail.com Sun Jun 14 16:35:50 2009 From: andreengels at gmail.com (Andre Engels) Date: Sun, 14 Jun 2009 22:35:50 +0200 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. What kind of directories are those that just a list of files would result in a "very large" object? I don't think I have ever seen directories with more than a few thousand files... -- Andr? Engels, andreengels at gmail.com From wayne.dads.bell at gmail.com Sun Jun 14 16:47:52 2009 From: wayne.dads.bell at gmail.com (dads) Date: Sun, 14 Jun 2009 13:47:52 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> I'm wanting to purchase some of the titles that have been raised in this thread. When I look they are very expensive books which is understandable. Do you think getting earlier editions that are cheaper is a daft thing or should I fork out the extra ?10-?30 to get the latest edition? From http Sun Jun 14 17:18:22 2009 From: http (Paul Rubin) Date: 14 Jun 2009 14:18:22 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> Message-ID: <7xljnu1plt.fsf@ruckus.brouhaha.com> dads writes: > I'm wanting to purchase some of the titles that have been raised in > this thread. When I look they are very expensive books which is > understandable. Do you think getting earlier editions that are cheaper > is a daft thing or should I fork out the extra ?10-?30 to get the > latest edition? It depends on the book. Also, keep in mind that quite a few good books these days are online where you can read them for free. SICP (mentioned in my earlier post) is one of them. From http Sun Jun 14 17:19:37 2009 From: http (Paul Rubin) Date: 14 Jun 2009 14:19:37 -0700 Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> <7xprd6o9c5.fsf@ruckus.brouhaha.com> Message-ID: <7xhbyi1pjq.fsf@ruckus.brouhaha.com> Andre Engels writes: > I was making a point that I don't agree that "nothing" would match any > type. The reason was that anything of the type car is one car, not two > cars or zero cars, but "nothing" is zero cars. You don't agree with > me, so apparently you are of the opinion that "nothing" would be a car. I don't agree that "nothing" is "zero cars". Just like I don't agree that the empty set, the empty list, and the empty string are the same thing. From kay at fiber-space.de Sun Jun 14 17:29:04 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sun, 14 Jun 2009 14:29:04 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Message-ID: <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> On 14 Jun., 16:00, Steven D'Aprano wrote: > Incorrect. Koch's snowflake, for example, has a fractal dimension of log > 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial triangle, > and a perimeter given by lim n->inf (4/3)**n. Although the perimeter is > infinite, it is countably infinite and computable. No, the Koch curve is continuous in R^2 and uncountable. Lawrence is right and one can trivially cover a countable infinite set with disks of the diameter 0, namely by itself. The sum of those diameters to an arbitrary power is also 0 and this yields that the Hausdorff dimension of any countable set is 0. From org.python.pythonlist at pooryorick.com Sun Jun 14 17:41:47 2009 From: org.python.pythonlist at pooryorick.com (Poor Yorick) Date: Sun, 14 Jun 2009 17:41:47 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored Message-ID: <4A356E9B.30806@pooryorick.com> The following code produces an error (python-2.6.2). Either of the following eliminates the error: . assign something besides mod1 (the newly-created module) to d1 . remove the call to shelve.open Why is there an error produced in the first place? What is the interaction between d1, mod1, and shelve about? This code runs without error in python-3.1 $ cat test1.py import test2 newmodule = test2.load() $ cat test2.py import imp import shelve def load(): text='import test2\n' text += '''print('hello from test3')\n''' code = compile(text,'', 'exec') mod1 = imp.new_module('newmodule') newdict = mod1.__dict__ #newdict = {} exec(code,newdict) mod1 mode = mod1 d1['unique'] = mod1 #d1['unique'] = '' return mod1 print('hello from test2') d1 = {} cache = shelve.open('persist') $ python2.6 test1.py hello from test2 hello from test3 Exception TypeError: "'NoneType' object is not callable" in ignored Exception TypeError: "'NoneType' object is not callable" in ignored -- Yorick From rhodri at wildebst.demon.co.uk Sun Jun 14 18:23:06 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:23:06 +0100 Subject: Different types of dicts with letter before the curly braces. In-Reply-To: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> References: <39c3f239-999e-460f-913f-5943eeba12a2@h11g2000yqb.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 12:02:47 +0100, kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of defining different types of > mapping functions by proceeding a letter before the curly brackets. > i.e ordered = o{}, multidict = m{} (like paste multidict). So you > could define an ordered dict by newordered = o{"llvm" : "ptyhon", > "parrot" : "perl"} . (they should also probably have there own > comprehensions as well o{foo for bar in foobar}). -1. And before you ask, that would have been my reaction to the 'u' and 'b' string prefixes as well. Python has perfectly good constructors for any class already, and it's perfectly obvious what they're doing because they involve the class name. Obfuscating this by using one character modifiers on existing literal syntax and expecting the result to be (a) obvious and (b) meaningful in the face of an ever-extending collection of basic types is optimistic in the extreme. Even Perl doesn't expect that much memory of you! -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Jun 14 18:28:44 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:28:44 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton wrote: > On 2009-06-14 14:04:02 +0100, Steven D'Aprano > said: > >> Nathan Stoddard wrote: >> >>> The best way to become a good programmer is to program. Write a lot of >>> code; work on some large projects. This will improve your skill more >>> than >>> anything else. >> I think there are about 100 million VB code-monkeys who prove that >> theory >> wrong. > > Really? So you don't think that the best way to get good at something is > to practice? Self-evidently. If what you practice is bad practice, it doesn't matter how much you practice it you'll still be no good at good practice in practice. Practically speaking, that is :-) -- Rhodri James *-* Wildebeest Herder to the Masses From ldo at geek-central.gen.new_zealand Sun Jun 14 18:39:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 10:39:50 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: In message <0050ecf7$0$9684$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > Graham Ashton wrote: > >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: >> >>> Nathan Stoddard wrote: >>> >>>> The best way to become a good programmer is to program. Write a lot of >>>> code; work on some large projects. This will improve your skill more >>>> than anything else. >>> >>> I think there are about 100 million VB code-monkeys who prove that >>> theory wrong. >> >> Really? So you don't think that the best way to get good at something >> is to practice? > > Shame on you for deliberately cutting out my more serious and nuanced > answer while leaving a silly quip. Can't have been very "serious and nuanced" if it could be summed up by such a "silly quip" though, could it? From ldo at geek-central.gen.new_zealand Sun Jun 14 18:42:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 10:42:50 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: In message , Chris Jones wrote: > Vivaldi vs. Mozart > > And the latter especially had definitely mastered his editor. Just think > of the sheer volume of the coding he managed during his short life. > > Not many bugs either? I thought Vivaldi did more. The style of music was such that they could virtually sketch it out in shorthand, and leave it to the copyists to expand to proper notation for the musicians to play. I imagine that it was also the job of copyists to fix the typos. In other words, high productivity was a direct consequence of adoption of a cookie-cutter style. From python at mrabarnett.plus.com Sun Jun 14 18:52:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Jun 2009 23:52:15 +0100 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4A357F1F.6060407@mrabarnett.plus.com> Rhodri James wrote: > On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton > wrote: > >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: >> >>> Nathan Stoddard wrote: >>> >>>> The best way to become a good programmer is to program. Write a lot of >>>> code; work on some large projects. This will improve your skill more >>>> than >>>> anything else. >>> I think there are about 100 million VB code-monkeys who prove that >>> theory >>> wrong. >> >> Really? So you don't think that the best way to get good at something >> is to practice? > > Self-evidently. If what you practice is bad practice, it doesn't matter > how much you practice it you'll still be no good at good practice in > practice. Practically speaking, that is :-) > True. And there's no point in practising if you don't understand what you're doing or why you're doing it that way. There are plenty of good tutorials for Python, for example, but if you can't follow any of them (assuming that it's not just a language problem), or can't be bothered to read any of them, then you probably shouldn't be a programmer. From rhodri at wildebst.demon.co.uk Sun Jun 14 18:52:19 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Jun 2009 23:52:19 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> 2. That output string has severe "leaning toothpick" syndrome. Python >> accepts both single and double quotes to help avoid creating something >> so unreadable: use them. > > Backslashes are more scalable. Yes, yes, you can print them at any size. That doesn't excuse sprinkling several million backslashes through literal constants when there's a more readable alternative. -- Rhodri James *-* Wildebeest Herder to the Masses From peter at www.pjb.com.au Sun Jun 14 19:06:49 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 14 Jun 2009 23:06:49 GMT Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> Message-ID: >> In message , Peter Billam wrote: >>> Are there any modules, packages, whatever, that will >>> measure the fractal dimensions of a dataset, e.g. a time-series ? > Lawrence D'Oliveiro wrote: >> I don't think any countable set, even a countably-infinite set, can >> have a fractal dimension. It's got to be uncountably infinite, and >> therefore uncomputable. You need a lot of data-points to get a trustworthy answer. Of course edge-effects step in as you come up against the spacing betwen the points; you'd have to weed those out. On 2009-06-14, Steven D'Aprano wrote: > Strictly speaking, there's not one definition of "fractal dimension", there > are a number of them. One of the more useful is the "Hausdorf dimension", They can be seen as special cases of Renyi's generalised entropy; the Hausdorf dimension (D0) is easy to compute because of the box-counting-algorithm: http://en.wikipedia.org/wiki/Box-counting_dimension Also easy to compute is the Correlation Dimension (D2): http://en.wikipedia.org/wiki/Correlation_dimension Between the two, but much slower, is the Information Dimension (D1) http://en.wikipedia.org/wiki/Information_dimension which most closely corresponds to physical entropy. Multifractals are very common in nature (like stock exchanges, if that counts as nature :-)) http://en.wikipedia.org/wiki/Multifractal_analysis but there you really need _huge_ datasets to get useful answers ... There have been lots of papers published (these are some refs I have: G. Meyer-Kress, "Application of dimension algorithms to experimental chaos," in "Directions in Chaos", Hao Bai-Lin ed., (World Scientific, Singapore, 1987) p. 122 S. Ellner, "Estmating attractor dimensions for limited data: a new method, with error estimates" Physi. Lettr. A 113,128 (1988) P. Grassberger, "Estimating the fractal dimensions and entropies of strange attractors", in "Chaos", A.V. Holden, ed. (Princeton University Press, 1986, Chap 14) G. Meyer-Kress, ed. "Dimensions and Entropies in Chaotic Systems - Quantification of Complex Behaviour", vol 32 of Springer series in Synergetics (Springer Verlag, Berlin, 1986) N.B. Abraham, J.P. Gollub and H.L. Swinney, "Testing nonlinear dynamics," Physica 11D, 252 (1984) ) but I haven't chased these up and I don't think they contain any working code. But the work has been done, so the code must be there still, on some computer somwhere... Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From tjreedy at udel.edu Sun Jun 14 19:14:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:14:10 -0400 Subject: Question about None In-Reply-To: <0050d4eb$0$9666$c3e8da3@news.astraweb.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > > So-called "vacuous truth". It's often useful to have all([]) return > true, but it's not *always* useful -- there are reasonable cases > where the opposite behaviour would be useful: > > if all(the evidence points to the Defendant's guilt) then: the > Defendant is guilty execute(the Defendant) > > sadly means that if there is no evidence that a crime has been > committed, the person accused of committing the imaginary crime will > be executed. It seems to me that the absurd conclusion implied by the theorem invalidates the theorem rather than supporting your point. No evidence is only the endpoint of a continuum. Suppose that 'all' is one teensy weensy bit of evidence. A drunked bystander gives a vague description that fits. Or twenty years before, the defendent argued with the deceased and said 'I wish you were dead'. Should the person be executed? I say not. You? Of course, a person would only be a defendant in the absence of evidence under a depraved regime that would not much care if there were. Try finding another 'reasonable case'. Terry Jan Reedy From tjreedy at udel.edu Sun Jun 14 19:27:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:27:46 -0400 Subject: Question about None In-Reply-To: References: Message-ID: Mel wrote: > John Yeung wrote: > >> And I accept your answer, as well as Steven's and Paul's for that >> matter. I still think it is understandable (and people may choose to >> understand in a condescending way, if they wish) that someone might >> not get the difference between what you are saying and the statement >> that all elements of the empty set are floats. I mean, what's in the >> empty set? Nothing. But you've said that floats are something. How >> is it that nothing is something? > > It's sort of a logic equivalent of divide-by-zero. > > All elements of the empty set are floats. > All elements of the empty set are ints. > Ints are not floats. > Therefore all elements of the empty set are not floats. If x in e => x in floats x in e => x in ints x in ints => x not in floats Then x in e => x not in floats, a contradition, So not(x in e), the definition of empty set. > You elaborate your logic to talk around this problem, and you quit when you > get tired. No problem. Colloquial English is not the same as careful logic. 2 minutes, tired? Nah. tjr From tjreedy at udel.edu Sun Jun 14 19:36:11 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:36:11 -0400 Subject: Question about None In-Reply-To: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> References: <65d199b50906140949tf9f2b6cq86eb70ec884abaaf@mail.gmail.com> Message-ID: Paul LaFollette wrote: > Thank you all for your thoughtful and useful comments. Since this has > largely morphed into a discussion of my 3rd question, perhaps it would > interest you to hear my reason for asking it. > > John is just about spot on. Part of my research involves the > enumeration and generation of various combinatorial objects using what > are called "loopless" or "constant time" algorithms. (This means that > the time required to move from one object to the next is bounded by a > constant that is independent of the size of the object. It is related > to following idea: If I generate all of the possible patterns > expressible with N bits by simply counting in binary, as many as N > bits may change from one pattern to the next. On the other hand if I > use Gray code only one bit changes from each pattern to the next. But the number of bits you must examine to determine which to change is bounded by N and increases with N. From lists at cheimes.de Sun Jun 14 19:47:03 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 01:47:03 +0200 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: tom schrieb: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. Some time ago we had a discussion about turning os.listdir() into a generator. No conclusion was agreed on. We also thought about exposing the functions opendir(), readdir(), closedir() and friends but as far as I know and as far as I've checked the C code in Modules/posixmodule.c none of the functions as been added. For now you are on your own to implement wrappers for the system calls. For the distant future you may see the appropriate functions in the os module. A mail to the python ideas list may increase your chances. ;) Christian From tjreedy at udel.edu Sun Jun 14 19:48:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:48:15 -0400 Subject: waling a directory with very many files In-Reply-To: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. tjr From sjmachin at lexicon.net Sun Jun 14 19:48:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 14 Jun 2009 23:48:21 +0000 (UTC) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not =?utf-8?b?Y2FsbGFibGUiCWlu?= ignored References: <4A356E9B.30806@pooryorick.com> Message-ID: Poor Yorick pooryorick.com> writes: > > The following code produces an error (python-2.6.2). Either of the following > eliminates the error: > > . assign something besides mod1 (the newly-created module) to d1 > > . remove the call to shelve.open [snip] > > $ python2.6 test1.py > hello from test2 > hello from test3 > Exception TypeError: "'NoneType' object is not callable" in ignored > Exception TypeError: "'NoneType' object is not callable" in ignored Take your error message, paste it into a search box in a browser, delete punctuation characters (especially "), and hit the search button. Limiting your search to this newsgroup is a good idea. From tjreedy at udel.edu Sun Jun 14 19:49:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2009 19:49:36 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <4A356E9B.30806@pooryorick.com> References: <4A356E9B.30806@pooryorick.com> Message-ID: Poor Yorick wrote: > The following code produces an error (python-2.6.2). You forgot to post the error traceback. From lists at cheimes.de Sun Jun 14 19:50:02 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 01:50:02 +0200 Subject: waling a directory with very many files In-Reply-To: <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <6faf39c90906141335i9f60cc7u3ae3cf52120c7016@mail.gmail.com> Message-ID: Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I've seen directories with several hundreds of thousand files. Depending on the file system and IO capacity it can take about one to several minute until 'ls' even starts to print out files names. It's no fun on directories on a CIFS storage or ext3 w/o a btree dir index. Christian From lists at cheimes.de Sun Jun 14 20:06:18 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 15 Jun 2009 02:06:18 +0200 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: Terry Reedy wrote: > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. ython 3.1rc1+ (py3k:73396, Jun 12 2009, 22:45:18) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> type(os.listdir(".")) Christian From python at mrabarnett.plus.com Sun Jun 14 20:06:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Jun 2009 01:06:20 +0100 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A35907C.5010400@mrabarnett.plus.com> Christian Heimes wrote: > tom schrieb: >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. for example, in c, perl or php one can >> use opendir() and then repeatedly readdir() until getting to the end >> of the file list. it seems this could be more efficient in some >> applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > Some time ago we had a discussion about turning os.listdir() into a > generator. No conclusion was agreed on. We also thought about exposing > the functions opendir(), readdir(), closedir() and friends but as far as > I know and as far as I've checked the C code in Modules/posixmodule.c > none of the functions as been added. > Perhaps if there's a generator it should be called iterdir(). Or would it be unPythonic to have listdir() and iterdir()? Probably. > For now you are on your own to implement wrappers for the system calls. > For the distant future you may see the appropriate functions in the os > module. A mail to the python ideas list may increase your chances. ;) > From ldo at geek-central.gen.new_zealand Sun Jun 14 20:33:50 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 12:33:50 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro > wrote: > >> In message , Rhodri >> James wrote: >> >>> 2. That output string has severe "leaning toothpick" syndrome. Python >>> accepts both single and double quotes to help avoid creating something >>> so unreadable: use them. >> >> Backslashes are more scalable. > > That doesn't excuse sprinkling several million backslashes through literal > constants when there's a more readable alternative. Perl allows just about any printable character as a quote. I tried alternative quotes for many years, and decided making that choice was a waste of brain cells. So no, using alternative quotes does not make things more readable. From ldo at geek-central.gen.new_zealand Sun Jun 14 20:45:43 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 12:45:43 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: In message , Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. I suppose it depends how well-liked it is. Nerdy lists may work better, but they tend not to be liked. > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I worked on an application system which, at one point, routinely dealt with directories containing hundreds of thousands of files. But even that kind of directory contents only adds up to a few megabytes. From castironpi at gmail.com Sun Jun 14 21:26:55 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sun, 14 Jun 2009 18:26:55 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <7xfxe2ehdt.fsf@ruckus.brouhaha.com> Message-ID: On Jun 14, 12:37?pm, Paul Rubin wrote: > Andre Engels writes: snip > > type "thingy". A car is a single car. Nothing is zero cars, which is > > not a car, just like two cars is not a car. > > That seems to confuse values with collections of them. ?A car is not > the same as a one-element list of cars. ?Nothing is not the same as a > zero-element list of cars. Collections are a mathematical (ideal, cognitive) construct. From davea at ieee.org Sun Jun 14 21:39:19 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Jun 2009 21:39:19 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <4A356E9B.30806@pooryorick.com> References: <4A356E9B.30806@pooryorick.com> Message-ID: <4A35A647.2020006@ieee.org> Poor Yorick wrote: >
The > following code produces an error (python-2.6.2). Either of the following > eliminates the error: > > . assign something besides mod1 (the newly-created module) to d1 > > . remove the call to shelve.open > > Why is there an error produced in the first place? What is the > interaction > between d1, mod1, and shelve about? This code runs without error in > python-3.1 > > $ cat test1.py > import test2 > newmodule = test2.load() > > $ cat test2.py > > import imp > import shelve > > def load(): > text='import test2\n' > text += '''print('hello from test3')\n''' > code = compile(text,'', 'exec') > mod1 = imp.new_module('newmodule') > > newdict = mod1.__dict__ > #newdict = {} > > exec(code,newdict) > mod1 > mode = mod1 > d1['unique'] = mod1 > #d1['unique'] = '' > return mod1 > > print('hello from test2') > d1 = {} > cache = shelve.open('persist') > > $ python2.6 test1.py > hello from test2 > hello from test3 > Exception TypeError: "'NoneType' object is not callable" in ignored > Exception TypeError: "'NoneType' object is not callable" in ignored > You don't need all those lines to trigger these exception messages. All you need in test1.py is the import statement. And in test2.py: import shelve cache = shelve.open('persist') To cure it, just close the cache: cache.close() I don't have any idea what the exception means, but this seems like a logical thing, to close it. From python.list at tim.thechases.com Sun Jun 14 22:07:25 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Jun 2009 21:07:25 -0500 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <4A35ACDD.1020803@tim.thechases.com> >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking >> a directory as a liked list. for example, in c, perl or php one can >> use opendir() and then repeatedly readdir() until getting to the end >> of the file list. it seems this could be more efficient in some >> applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. Since at least 2.4, os.walk has itself been a generator. However, the contents of the directory (the 3rd element of the yielded tuple) is a list produced by listdir() instead of a generator. Unless listdir() has been changed to a generator instead of a list (which other respondents seem to indicate has not been implemented), this doesn't address the OP's issue of "lots of files in a single directory". -tkc From org.python.pythonlist at pooryorick.com Sun Jun 14 22:19:28 2009 From: org.python.pythonlist at pooryorick.com (Poor Yorick) Date: Sun, 14 Jun 2009 22:19:28 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: References: <4A356E9B.30806@pooryorick.com> Message-ID: <4A35AFB0.10803@pooryorick.com> Terry Reedy wrote: > Poor Yorick wrote: >> The following code produces an error (python-2.6.2). > > You forgot to post the error traceback. > There was no traceback, but following John Machin's prodding, I read back through some older posts (including one of yours) which I hadn't guessed were relevant the first time around. It seems that the program itself was functioning properly, but when the interpreter exited, objects were being deleted in an order which did not permit orderly teardown of other objects. I hadn't thought to look, before, but despite the warnings, the exit status of the interpreter was 0. The solution to the errors was to register a teardown function in the module: import atexit def teardown(): del globals()['d1'] atexit.register(teardown) -- Yorick From ldo at geek-central.gen.new_zealand Sun Jun 14 22:26:13 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 14:26:13 +1200 Subject: uncompress base64-gzipped string References: Message-ID: In message , John Machin wrote: > What a long journey: parse xml, base64 decode, gunzip, > and you're still not home; next stop is struct.unpack ... Binary data in an XML file?? Were these the same folks who worked on OOXML, by any chance? From ldo at geek-central.gen.new_zealand Sun Jun 14 22:32:35 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 15 Jun 2009 14:32:35 +1200 Subject: matplotlib installation References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: In message , David Cournapeau wrote: > Basically, there are some functions which are erroneously "declared" > in the .lib, but they don't actually exist in the MS C runtime. Isn't this a MinGW bug? From asimsaeed.2006 at gmail.com Sun Jun 14 22:49:11 2009 From: asimsaeed.2006 at gmail.com (Asim Saeed) Date: Sun, 14 Jun 2009 19:49:11 -0700 (PDT) Subject: Cisco certification Message-ID: if you wnat to know about cisco certification it books and dump http://ciscocity.blogspot.com From philr at aspexconsulting.co.nz Sun Jun 14 23:38:20 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Mon, 15 Jun 2009 15:38:20 +1200 Subject: Good books in computer science? In-Reply-To: <4A357F1F.6060407@mrabarnett.plus.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: >Rhodri James wrote: >> On Sun, 14 Jun 2009 14:19:13 +0100, Graham Ashton >> wrote: >> >>> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >>> said: >>> >>>> Nathan Stoddard wrote: >>>> >>>>> The best way to become a good programmer is to program. Write a lot of >>>>> code; work on some large projects. This will improve your skill more >>>>> than >>>>> anything else. >>>> I think there are about 100 million VB code-monkeys who prove that >>>> theory >>>> wrong. >>> >>> Really? So you don't think that the best way to get good at something >>> is to practice? >> >> Self-evidently. If what you practice is bad practice, it doesn't matter >> how much you practice it you'll still be no good at good practice in >> practice. Practically speaking, that is :-) >> >True. And there's no point in practising if you don't understand what >you're doing or why you're doing it that way. There are plenty of good >tutorials for Python, for example, but if you can't follow any of them >(assuming that it's not just a language problem), or can't be bothered >to read any of them, then you probably shouldn't be a programmer. If you are given to depression then programming is possibly not for you. Keep tackling problems that are beyond your current capabilities. Think about what you are doing... this is more subtle that you might grasp at first. Know there is always a better way and seek it. Prime your thinking by reading Edsgar Dijkstra. Dijkstra's "Notes on Structured Programming" are a good read and are probably available on the 'Net by now. You will see that his concerns had practically nothing to do with "Goto Considered Harmful". That was a later observation made as a result of checking students programs. His notes were knocking around in the UK back in 1966 and earlier. His co-authored book on "Structure Programming" is good reading even now. (O-J Dahl, EW Dijkstra, and CAR Hoare). See http://www.cs.utexas.edu/users/EWD/transcriptions/transcriptions.html for his famous EWD series of notes. Gain access to one of the IEEE or ACM web sites and their resources. I used to sneak into my local university library before the 'Net to read this stuff. Beyond that I check up on the reading lists for CS students from time to time. This often throws up real gems and prevents me from being blind-sided. Beware any "programmer" who only knows one computer language and only one OS, especially if this is either windows or a version of UNIX. My 2c worth From steven at REMOVE.THIS.cybersource.com.au Sun Jun 14 23:48:16 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 03:48:16 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: >> Shame on you for deliberately cutting out my more serious and nuanced >> answer while leaving a silly quip. > > Can't have been very "serious and nuanced" if it could be summed up by > such a "silly quip" though, could it? But it can't be summed up by the silly quip, which is why I'm complaining that the silly quip on its own fails to include the more serious and nuanced elements of my post. -- Steven From drentha at gmail.com Sun Jun 14 23:53:39 2009 From: drentha at gmail.com (Oni) Date: Sun, 14 Jun 2009 20:53:39 -0700 (PDT) Subject: Specify the sorting direction for the various columns/ References: <018f4fa2-7203-4c98-a313-da5584976bd9@z20g2000prh.googlegroups.com> <20090612113434.47a84b00@coercion> Message-ID: <3fb7c945-744c-4f6e-82f6-0d895afba239@s38g2000prg.googlegroups.com> Thanks for the answers. My goal was to try to avoid hard coding and add a little shine to the code I have inherited. But its too far gone already and time is short. So have used Mike's answer. Mike answer with minor changes: import datetime import pprint import operator import time entries = [{'name': 'ZZ2', 'username': 'ZZ3', 'date': datetime.datetime (2007, 9, 30, 16, 43, 54)},{'name': 'ZZ2', 'username': 'ZZ5','date': datetime.datetime(2008, 9, 30, 16, 43, 54)},{'name': 'ZZ3', 'username': 'ZZ1', 'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] entries.sort(key = lambda x: (x['name'], -time.mktime(x ['date'].timetuple()) )) pp = pprint.PrettyPrinter(depth=2) pp.pprint(entries) From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:27:18 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:27:18 GMT Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 18:02:54 +0100, Arnaud Delobelle wrote: > Steven D'Aprano writes: >> So-called "vacuous truth". It's often useful to have all([]) return >> true, but it's not *always* useful -- there are reasonable cases where >> the opposite behaviour would be useful: >> >> if all(the evidence points to the Defendant's guilt) then: >> the Defendant is guilty >> execute(the Defendant) >> >> sadly means that if there is no evidence that a crime has been >> committed, the person accused of committing the imaginary crime will be >> executed. > > This is a bad example. Someone is not convicted of a crime just because > all the available evidence points towards their guilt. There may be > very little evidence altogether, or it might just be circumstancial, or > unconvincing. Even though it may all point towards the defendent's > guilt, it doesn't mean they will be convicted. There needs to be enough > evidence to convince the jury. So it would be something like: > > if sum(guilt_weight(e) for e in evidence) > GUILT_THRESHOLD: > the defendant is guilty > ... Not all trials are jury trials, and not all cultures have a presumption of innocence. There are, in fact, many places where the government and police think little of falsifying evidence to convict innocent people, including people that they know are innocent of any crime (an extreme case was Stalin's show trials). But as far as I know, nobody ever argues that people are guilty based on the principle of Vacuous Truth: everybody agrees that if there is no evidence of a crime, the person should be considered innocent rather than guilty. Even Stalin manufactured evidence of crimes. (In most cases, that evidence was to torture people into confessing to crimes that did not, in fact, take place.) To put it another way, logically: all(the evidence is true) not any(the evidence is false) should be considered identical, but in practice, we treat: evidence = [] # evidence of a crime all(evidence) as false instead of true, even in places with no presumption of innocence. While: not any(map(operator.not_, evidence)) is also treated as false. In any case, I'm not arguing against vacuous truth -- it's clearly the right way to deal with empty sets *nearly always*. But it isn't entirely straight-forward, and leads to some difficulties, such as a vacuous truth X implies both Y and not Y at the same time. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:50:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:50:27 GMT Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > Steven D'Aprano wrote: >> >> So-called "vacuous truth". It's often useful to have all([]) return >> true, but it's not *always* useful -- there are reasonable cases where >> the opposite behaviour would be useful: [...] > It seems to me that the absurd conclusion implied by the theorem > invalidates the theorem rather than supporting your point. I wouldn't go so far as to say the vacuous truth theorem ("empty statements are true") is invalidated. The Wikipedia article discusses various reasons why it's more correct (or at least more useful) to treat vacuous statements as true: http://en.wikipedia.org/wiki/Vacuous_truth But it's not without difficulties -- however those difficulties are smaller than those if you take vacuous statements as false in general. [...] > Try finding another 'reasonable case'. Any time you do something like: if not x and all(x): process(x) instead of just: if all(x): process(x) I can't think of a real world example off the top of my head, but here's a contrived example demonstrating that vacuous truths imply both a fact and it's opposite: def startswith(s, chars): """Return True if s starts with any of chars.""" for c in chars: if s.startswith(c): return True return False if all([startswith(w, "aeiou") for w in words]): print "All the words start with vowels." if all([startswith(w, "bcdfghjklmnpqrstvwxyz") for w in words]): print "All of the words start with consonants." If words is empty, this code claims that all of the words start with vowels as well as starting with consonants. There are, of course, ways to work around that other than rejecting vacuous truths. One is to simply use an "elif" for the second test. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:55:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:55:03 GMT Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > On 14 Jun., 16:00, Steven D'Aprano > wrote: > >> Incorrect. Koch's snowflake, for example, has a fractal dimension of >> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial >> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the >> perimeter is infinite, it is countably infinite and computable. > > No, the Koch curve is continuous in R^2 and uncountable. I think we're talking about different things. The *number of points* in the Koch curve is uncountably infinite, but that's nothing surprising, the number of points in the unit interval [0, 1] is uncountably infinite. But the *length* of the Koch curve is not, it's given by the above limit, which is countably infinite (it's a rational number for all n). > Lawrence is > right and one can trivially cover a countable infinite set with disks of > the diameter 0, namely by itself. The sum of those diameters to an > arbitrary power is also 0 and this yields that the Hausdorff dimension > of any countable set is 0. Nevertheless, the Hausdorff dimension (or a close approximation thereof) can be calculated from the scaling properties of even *finite* objects. To say that self-similar objects like broccoli or the inner surface of the human lungs fails to nest at all scales is pedantically correct but utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good enough for me. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Jun 15 00:56:06 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Jun 2009 04:56:06 GMT Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in other languages one can avoid generating such an object by walking a >> directory as a liked list. for example, in c, perl or php one can use >> opendir() and then repeatedly readdir() until getting to the end of the >> file list. it seems this could be more efficient in some applications. >> >> is there a way to do this in python? i'm relatively new to the >> language. i looked through the documentation and tried googling but >> came up empty. > > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... You haven't looked very hard :) $ pwd /home/steve/.thumbnails/normal $ ls | wc -l 33956 And I periodically delete thumbnails, to prevent the number of files growing to hundreds of thousands. -- Steven From deostroll at gmail.com Mon Jun 15 01:45:38 2009 From: deostroll at gmail.com (deostroll) Date: Sun, 14 Jun 2009 22:45:38 -0700 (PDT) Subject: parsing json using simplejson Message-ID: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> I need to be able to parse a json data object using the simplejson package. First of all I need to know all the task needed for this job. --deostroll From randall at tnr.cc Mon Jun 15 01:58:42 2009 From: randall at tnr.cc (Randall Smith) Date: Mon, 15 Jun 2009 00:58:42 -0500 Subject: moving Connection/PipeConnection between processes In-Reply-To: <20090613141147.1ed3667d@coercion> References: <20090613141147.1ed3667d@coercion> Message-ID: Now that I've done some homework, everything you said is clear. Mike Kazantsev wrote: > > Pickle has nothing to do with the problem since it lay much deeper: in > the OS. > > From kernel point of view, every process has it's own "descriptor > table" and the integer id of the descriptor is all the process gets, so > when you say "os.pipe()" kernel actually gives you a number which is > completely meaningless for any other process - it either doesn't exists > in it's descriptor table or points to something else. > > So, what you actually need is to tell the kernel to duplicate > underlying object in another process' table (with it's own numbering), > which is usually done via special flag for sendmsg(2) in C, so you > should probably look out for py implementation of this call, which I > haven't stumbled upon, but, admittely, never looked for. > sendmsg is a missing feature of the socket module. http://bugs.python.org/issue1194378 And this implements it: http://pypi.python.org/pypi/python-eunuchs/0.0.0 From bob.martin at excite.com Mon Jun 15 02:26:05 2009 From: bob.martin at excite.com (Bob Martin) Date: Mon, 15 Jun 2009 06:26:05 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <1QlZl.42661$OO7.9021@text.news.virginmedia.com> in 117455 20090615 044816 Steven D'Aprano wrote: >On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: > >>> Shame on you for deliberately cutting out my more serious and nuanced >>> answer while leaving a silly quip. >> >> Can't have been very "serious and nuanced" if it could be summed up by >> such a "silly quip" though, could it? > >But it can't be summed up by the silly quip, which is why I'm complaining >that the silly quip on its own fails to include the more serious and >nuanced elements of my post. Lots of references to "good programmer" but no attempt to define the term. Who is the better programmer - one who writes lousy code but produces good programs or one who obeys all the rules of coding but whose programs break all the time? (Yes, I know there are two other categories!) In almost 50 years programming I have met all types but I tended to judge them by the end results, not on their style. From lie.1296 at gmail.com Mon Jun 15 03:14:46 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 15 Jun 2009 07:14:46 GMT Subject: Good books in computer science? In-Reply-To: <1QlZl.42661$OO7.9021@text.news.virginmedia.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <1QlZl.42661$OO7.9021@text.news.virginmedia.com> Message-ID: Bob Martin wrote: > in 117455 20090615 044816 Steven D'Aprano wrote: >> On Mon, 15 Jun 2009 10:39:50 +1200, Lawrence D'Oliveiro wrote: >> >>>> Shame on you for deliberately cutting out my more serious and nuanced >>>> answer while leaving a silly quip. >>> Can't have been very "serious and nuanced" if it could be summed up by >>> such a "silly quip" though, could it? >> But it can't be summed up by the silly quip, which is why I'm complaining >> that the silly quip on its own fails to include the more serious and >> nuanced elements of my post. > > Lots of references to "good programmer" but no attempt to define the term. > > Who is the better programmer - one who writes lousy code but produces good programs > or one who obeys all the rules of coding but whose programs break all the time? > (Yes, I know there are two other categories!) > In almost 50 years programming I have met all types but I tended to judge them > by the end results, not on their style. A programmer that just follows the recipes for the so-called "rules of coding" is just, as Steven says, a bad programmers. Unless you write a program that works, you are not a programmer; once you've written one that works, we'll see whether you're a good or bad by your style. Points is taken when the so-called rules are followed mindlessly. Bonus Points if you can justify your breaking rules. No point for program that doesn't work. From python at rcn.com Mon Jun 15 03:45:13 2009 From: python at rcn.com (Raymond Hettinger) Date: Mon, 15 Jun 2009 00:45:13 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: [David Wilson] > The problem is simple: given one or more ordered sequences, return > only the objects that appear in each sequence, without reading the > whole set into memory. This is basically an SQL many-many join. FWIW, this is equivalent to the Welfare Crook problem in David Gries book, The Science of Programming, http://tinyurl.com/mzoqk4 . > I thought it could be accomplished through recursively embedded > generators, but that approach failed in the end. Translated into Python, David Gries' solution looks like this: def intersect(f, g, h): i = j = k = 0 try: while True: if f[i] < g[j]: i += 1 elif g[j] < h[k]: j += 1 elif h[k] < f[i]: k += 1 else: print(f[i]) i += 1 except IndexError: pass streams = [sorted(sample(range(50), 30)) for i in range(3)] for s in streams: print(s) intersect(*streams) Raymond From cassian at free.fr Mon Jun 15 03:57:49 2009 From: cassian at free.fr (Cassian Braconnier) Date: Mon, 15 Jun 2009 09:57:49 +0200 Subject: Impossible to reinstall python-opensync which made unusable my package installation tools Message-ID: <4A35FEFD.9050603@free.fr> Hi, Recently, I decided to install a package for python-opensync on my Ubuntu 9.04 (Jaunty). This package was here : http://www.progweb.com/modules/blackberry/opensync/ (I was said later that this package was for Debian SID) This was a very bad idea : it completely broke Synaptic, and made it impossible to install any (other, non python) package with apt-get or dpkg commands. Any attempt to remove or reinstall python-opensync with dpkg or apt-get commands, used with various 'force' options, gave no result, for instance : ============= root at tux-laptop# dpkg -P --force-remove-reinstreq python-opensync dpkg - avertissement, probl?me contourn? ? cause de --force : Le paquet est dans un ?tat incoh?rent - vous devriez le r?installer avant d'essayer de le supprimer. (Lecture de la base de donn?es... 236922 fichiers et r?pertoires d?j? install?s.) Suppression de python-opensync ... Usage: update-python-modules [-v] [-c] package_directory [...] update-python-modules [-v] [-c] package.dirs [...] update-python-modules [-v] [-a|-f|-p] update-python-modules: error: /usr/share/python-support/python-opensync.public is not a directory dpkg : erreur de traitement de python-opensync (--purge) : le sous-processus pre-removal script a retourn? une erreur de sortie d'?tat 2 Usage: update-python-modules [-v] [-c] package_directory [...] update-python-modules [-v] [-c] package.dirs [...] update-python-modules [-v] [-a|-f|-p] update-python-modules: error: /usr/share/python-support/python-opensync.public is not a directory dpkg : erreur lors du nettoyage : le sous-processus post-installation script a retourn? une erreur de sortie d'?tat 2 Des erreurs ont ?t? rencontr?es pendant l'ex?cution : python-opensync ==================== The pre and post removal scripts are respectively : /var/lib/dpkg/info/python-opensync.prerm : ================= #!/bin/sh set -e # Automatically added by dh_pysupport if which update-python-modules >/dev/null 2>&1; then update-python-modules -c python-opensync.public fi # End automatically added section ========================= /var/lib/dpkg/info/python-opensync.postinst : ================== #!/bin/sh set -e # Automatically added by dh_pysupport if which update-python-modules >/dev/null 2>&1; then update-python-modules python-opensync.public fi # End automatically added section ========================== For the time being I cannot install anything using dpkg or apt-get (nor synaptic) : I get an error message saying that "python-opensync should be reinstalled but that its archive is unavailable", and as I said, any attempt to reinstall python-opensync fails. So far I could not get any useful advice on the french ubuntu users forum, it is the reason why, though I am in no way a python-guy, I turned to this list. Thank you for any advice. Idoin From lie.1296 at gmail.com Mon Jun 15 04:00:11 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 15 Jun 2009 08:00:11 GMT Subject: Alter list items within loop In-Reply-To: References: <94009fbe-9466-4c51-a532-c53e47a8c086@b7g2000pre.googlegroups.com> <5ZcYl.33508$YU2.17397@nlpi066.nbdc.sbc.com> Message-ID: Tim Harig wrote: > On 2009-06-11, Duncan Booth wrote: >> Tim Harig wrote: >>>> number 3 never gets printed. Does Python make a copy of a list before >>>> it iterates through it?: >>> No, complex types are passed by reference unless explicity copied. >> *All* types are passed by reference unless explicitly copied. Python does >> make special cases for simple and complex types. > > That is technically true; but, you will not have this issue with simple > singlular data types. Technically the difference as to whether you will > have this problem depends on whether or not an object is mutable. > Simple objects (numbers and strings) are all immutable. Since this issue > revolves around changing objects in place, it cannot arise with immutable > objects. I am not always conscous of whether I am working with objects > that are mutable or immutable; but, I am generally concious of the general > complexity of the object. Whenever I am working with objects that are > complex, I am reminded to watch out for mutability issues. So, while it is not > totally correct to think of it this way, I find it an easier guideline to > follow. Everything is passed as an object[1], no matter how simple or complex, mutable or immutable. This can be seen: >>> def foo(a): ... print id(a) ... >>> b = 10 >>> id(b) 8578336 >>> foo(b) 8578336 [1] internally as PyObject pointer but that's implementation detail From sjmachin at lexicon.net Mon Jun 15 04:11:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Jun 2009 01:11:39 -0700 (PDT) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored References: <4A356E9B.30806@pooryorick.com> Message-ID: <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> On Jun 15, 9:49?am, Terry Reedy wrote: > Poor Yorick wrote: > > The following code produces an error (python-2.6.2). > > You forgot to post the error traceback. The exception was IGNORED ... so no traceback. From deets at nospam.web.de Mon Jun 15 04:21:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 10:21:09 +0200 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> Message-ID: <79medbF1qu45cU1@mid.uni-berlin.de> deostroll wrote: > I need to be able to parse a json data object using the simplejson > package. First of all I need to know all the task needed for this job. - install simplejson - read documentation of simplejson - use simplejson as documented - ??? - profit! Diez From nick at craig-wood.com Mon Jun 15 04:29:34 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 03:29:34 -0500 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: tom wrote: > On Jun 14, 1:35?pm, Tim Golden wrote: > > > > If you're on Windows, you can use the win32file.FindFilesIterator > > function from the pywin32 package. (Which wraps the Win32 API > > FindFirstFile / FindNextFile pattern). > > thanks, tim. > > however, i'm not using windows. freebsd and os x. Here is a ctypes generator listdir for unix-like OSes. I tested it under linux. #!/usr/bin/python """ An equivalent os.listdir but as a generator using ctypes """ from ctypes import CDLL, c_char_p, c_int, c_long, c_ushort, c_byte, c_char, Structure, POINTER from ctypes.util import find_library class c_dir(Structure): """Opaque type for directory entries, corresponds to struct DIR""" c_dir_p = POINTER(c_dir) class c_dirent(Structure): """Directory entry""" # FIXME not sure these are the exactly correct types! _fields_ = ( ('d_ino', c_long), # inode number ('d_off', c_long), # offset to the next dirent ('d_reclen', c_ushort), # length of this record ('d_type', c_byte), # type of file; not supported by all file system types ('d_name', c_char * 4096) # filename ) c_dirent_p = POINTER(c_dirent) c_lib = CDLL(find_library("c")) opendir = c_lib.opendir opendir.argtypes = [c_char_p] opendir.restype = c_dir_p # FIXME Should probably use readdir_r here readdir = c_lib.readdir readdir.argtypes = [c_dir_p] readdir.restype = c_dirent_p closedir = c_lib.closedir closedir.argtypes = [c_dir_p] closedir.restype = c_int def listdir(path): """ A generator to return the names of files in the directory passed in """ dir_p = opendir(".") while True: p = readdir(dir_p) if not p: break name = p.contents.d_name if name not in (".", ".."): yield name closedir(dir_p) if __name__ == "__main__": for name in listdir("."): print name -- Nick Craig-Wood -- http://www.craig-wood.com/nick From eckhardt at satorlaser.com Mon Jun 15 04:38:02 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Jun 2009 10:38:02 +0200 Subject: Impossible to reinstall python-opensync which made unusable my package installation tools References: Message-ID: Cassian Braconnier wrote: > [...] completely broke Synaptic, and made it impossible to install any > (other, non python) package with apt-get or dpkg commands. This is not a Python error and it doesn't actually belong here. > So far I could not get any useful advice on the french ubuntu users > forum, it is the reason why, though I am in no way a python-guy, > I turned to this list. Fire up an IRC client, connect to freenode and join the channel #ubuntu, #debian or #debian-fr, there you should be able to find people who can help you. Otherwise, it seems that the package is in a half-installed state and that it fails to configure. What you can do is remove the content of the failing post-installation script and then retry configuring it. Obviously it might cause the package itself to break, but it shouldn't affect the whole package management system. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From dfnsonfsduifb at gmx.de Mon Jun 15 05:14:56 2009 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Mon, 15 Jun 2009 11:14:56 +0200 Subject: Mysterious hang Message-ID: <79mhogF1rhob9U1@mid.dfncis.de> Hello group, I'm pretty despereate right now and apologize for my diffuse question in advance - but I do not know how to continue right now. I'm writing a GUI client (pygtk) which talks to a server (TCP/IP), fetches pictures (FITS format) and displays them. This works nicely. Now I have a plugin which is called from a menu. The plugin also talks to the server, then fetches a picture. However, when trying to fetch a picture this way, the Python program hangs - every time, always at the same position - and I have not the least clue why. File "./guiclient.py", line 368, in on_Focus self.__plugin_instances[0].run() File "plugins/Focus.py", line 57, in run img = result.fetch() File "/home/joe/client/imgproto/Connection.py", line 54, in fetch return self.__device.conn().getbindata() File "/home/joe/client/imgproto/TransportLayerConnection.py", line 100, in getbindata copied = self.__s.recv_into(result[pos:], remaining) The debug output of my program indicates that *always* the last 1023 bytes are waited for. Wireshark however tells me they are sent! Done, fetching '2009_06_15_11_12_12_picture' Fetching... Fetching remaining 659520 bytes 15360 bytes fetched Fetching remaining 644160 bytes 16384 bytes fetched Fetching remaining 627776 bytes 16384 bytes fetched Fetching remaining 611392 bytes 16384 bytes fetched Fetching remaining 595008 bytes 16384 bytes fetched Fetching remaining 578624 bytes 16384 bytes fetched Fetching remaining 562240 bytes 147456 bytes fetched Fetching remaining 414784 bytes 49152 bytes fetched Fetching remaining 365632 bytes 49152 bytes fetched Fetching remaining 316480 bytes 49152 bytes fetched Fetching remaining 267328 bytes 98304 bytes fetched Fetching remaining 169024 bytes 49152 bytes fetched Fetching remaining 119872 bytes 49152 bytes fetched Fetching remaining 70720 bytes 49152 bytes fetched Fetching remaining 21568 bytes 20545 bytes fetched Fetching remaining 1023 bytes I then tried to multithread that, which did not work either (showed even more confusing behaviour). What in the world could possibly cause such an error? How can I trace it? Kind regards, Johannes -- "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verl?sterung von Gott, Bibel und mir und bewusster Blasphemie." -- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik <48d8bf1d$0$7510$5402220f at news.sunrise.ch> From madigreece at yahoo.gr Mon Jun 15 06:37:27 2009 From: madigreece at yahoo.gr (jeni) Date: Mon, 15 Jun 2009 03:37:27 -0700 (PDT) Subject: : an integer is required Message-ID: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> I have developed in python a game for OPLC. When I run the game in Python 2.5.2 at Windows there is no problem. But after I play a game at OLPC I get the following message: Traceback (most recent call last) /home/olpc/Activities/Kremala.activity/Kremala.py in add_letter (self=, widget=, grama='i') --> self.find_w() self.find_w=> /home/Activities/Kremala.activity/Kremala.py in find_w (self=) self.show_gr() --> self.sosti_leksi() self.sosti_leksi==> /home/Activities/Kremala.activity/Kremala.py in sosti_leksi (self=) s=self.categ+":"+str(1)+" nikh me "+str(6-self.m)+"prospatheies \n" --> self.insert_text_file(s) self.insert_text_file===> /home/Activities/Kremala.activity/Kremala.py in insert_text_file (self=, strng='geografia:1 nikh me 2 prospatheies\n') --> t=open("elements_file.txt", "a") global open= t.write(strng) t.close() : an integer is required OLPC's software is important? From rhodri at wildebst.demon.co.uk Mon Jun 15 07:02:32 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 15 Jun 2009 12:02:32 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro >> wrote: >> >>> In message , >>> Rhodri >>> James wrote: >>> >>>> 2. That output string has severe "leaning toothpick" syndrome. >>>> Python >>>> accepts both single and double quotes to help avoid creating something >>>> so unreadable: use them. >>> >>> Backslashes are more scalable. >> >> That doesn't excuse sprinkling several million backslashes through >> literal >> constants when there's a more readable alternative. > > Perl allows just about any printable character as a quote. I tried > alternative quotes for many years, and decided making that choice was a > waste of brain cells. > > So no, using alternative quotes does not make things more readable. I find it odd that you consider qquoting less scalable than backslashes. I also find it odd that you dislike two visuals stutters (at the start and end of string) so much that you'll put up with a dozen visual stutters in the string to avoid them. Particular since my years of Perl-bashing lead me to the opposite conclusion. -- Rhodri James *-* Wildebeest Herder to the Masses From pdpinheiro at gmail.com Mon Jun 15 07:14:14 2009 From: pdpinheiro at gmail.com (pdpi) Date: Mon, 15 Jun 2009 04:14:14 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: <7e7a22a6-1aaa-4605-b254-60e08c39e141@j18g2000yql.googlegroups.com> On Jun 15, 5:55?am, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > > On 14 Jun., 16:00, Steven D'Aprano > > wrote: > > >> Incorrect. Koch's snowflake, for example, has a fractal dimension of > >> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial > >> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the > >> perimeter is infinite, it is countably infinite and computable. > > > No, the Koch curve is continuous in R^2 and uncountable. > > I think we're talking about different things. The *number of points* in > the Koch curve is uncountably infinite, but that's nothing surprising, > the number of points in the unit interval [0, 1] is uncountably infinite. > But the *length* of the Koch curve is not, it's given by the above limit, > which is countably infinite (it's a rational number for all n). > > > Lawrence is > > right and one can trivially cover a countable infinite set with disks of > > the diameter 0, namely by itself. The sum of those diameters to an > > arbitrary power is also 0 and this yields that the Hausdorff dimension > > of any countable set is 0. > > Nevertheless, the Hausdorff dimension (or a close approximation thereof) > can be calculated from the scaling properties of even *finite* objects. > To say that self-similar objects like broccoli or the inner surface of > the human lungs fails to nest at all scales is pedantically correct but > utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good > enough for me. > > -- > Steven You're mixing up the notion of countability. It only applies to set sizes. Unless you're saying that there an infinite series has a countable number of terms (a completely trivial statement), to say that the length is "countably finite" simply does not parse correctly (let alone being semantically correct or not). This said, I agree with you: I reckon that the Koch curve, while composed of uncountable cardinality, is completely described by the vertices, so a countable set of points. It follows that you must be able to correctly calculate the Hausdorff dimension of the curve from those control points alone, so you should also be able to estimate it from a finite sample (you can arguably infer self-similarity from a limited number of self- similar generations). From eckhardt at satorlaser.com Mon Jun 15 07:25:14 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Jun 2009 13:25:14 +0200 Subject: : an integer is required References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: jeni wrote: [ ..large backtrace.. ] For your own sake and that of your readers, try next time to reduce the code that causes the problems to a minimal example. This prevents people from guessing or simply ignoring your problems. > /home/Activities/Kremala.activity/Kremala.py in insert_text_file > (self=>, strng='geografia:1 nikh me 2 prospatheies\n') > --> t=open("elements_file.txt", "a") > global open= open() doesn't take a string as second parameter, see 'help(open)'. Instead, it takes one of the integers which are defined as symbols in the os module, see 'dir(os)'. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From newsgroup at silveraxe.de Mon Jun 15 07:45:03 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Mon, 15 Jun 2009 13:45:03 +0200 Subject: Error in Pango while using cairo/librsvg Message-ID: <4a363441$0$30238$9b4e6d93@newsspool1.arcor-online.net> Hi, I try using Python (on Windows) with Cairo and librsvg to convert a svg file to a png image. I got some help from the German python newsgroup to get this running but now I run into some problems with pango I don't know how to solve. Running the python script in the console it tells me: (python.exe:4908): Pango-CRITICAL **: pango_win32_font_map_get_font_cache: assertion `font_map != NULL' failed ** Pango:ERROR:pangowin32.c:838:pango_win32_font_finalize: assertion failed: (win32font->fontmap != NULL) This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. The script I run is: > #!/usr/bin/python > > from ctypes import * > import cairo > from rsvg_wrapper import rsvgClass > from sys import argv > from os.path import exists > import getopt > > if __name__ == "__main__": > opts, args = getopt.getopt (argv[1:], 'o:h', > ['width=', 'height=', 'output=', 'help']) > file = args[0] > > rsvg = rsvgClass() > > svg = rsvg.Handle (file = file) > svgDimensionData=svg.get_dimension_data() > > if file[-4:] == ".svg": > file = file[:-4] > output = "%s.png" % file > base = "%s%d.png" > i = 1 > while exists (output): > output = base % (file, i) > i += 1 > > width = svgDimensionData[0] > height = svgDimensionData[1] > > surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height) > cr = cairo.Context (surface) > > wscale = float (width) / svgDimensionData[0] > hscale = float (height) / svgDimensionData[1] > > cr.scale (wscale, hscale) > > svg.render_cairo (cr) > > surface.write_to_png (output) and the rsvg_wrapper.py is: > #some code to give rsvg.render_cairo(ctx) ability > #on windows. > import os > try: > import rsvg > WINDOWS=False > except ImportError: > print"Warning, could not import 'rsvg'" > if os.name == 'nt': > print "Detected windows, creating rsvg." > #some workarounds for windows > > from ctypes import * > > l=CDLL('librsvg-2-2.dll') > g=CDLL('libgobject-2.0-0.dll') > g.g_type_init() > > class rsvgHandle(): > class RsvgDimensionData(Structure): > _fields_ = [("width", c_int), > ("height", c_int), > ("em",c_double), > ("ex",c_double)] > > class PycairoContext(Structure): > _fields_ = [("PyObject_HEAD", c_byte * object.__basicsize__), > ("ctx", c_void_p), > ("base", c_void_p)] > > def __init__(self, path): > self.path = path > error = '' > self.handle = l.rsvg_handle_new_from_file(self.path,error) > > > def get_dimension_data(self): > svgDim = self.RsvgDimensionData() > l.rsvg_handle_get_dimensions(self.handle,byref(svgDim)) > return (svgDim.width,svgDim.height) > > def render_cairo(self, ctx): > ctx.save() > z = self.PycairoContext.from_address(id(ctx)) > l.rsvg_handle_render_cairo(self.handle, z.ctx) > ctx.restore() > > > > class rsvgClass(): > def Handle(self,file): > return rsvgHandle(file) > I have the GIMP 2.6 bin folder in my path so all DLLs are used from that folder. I have no idea why the error is raised. I also tried to "import pango" in the script but then it tells me: > Traceback (most recent call last): > File "svg2png2.py", line 41, in > svg.render_cairo (cr) > File "...\rsvg_wrapper.py", line 45, in render_cairo > l.rsvg_handle_render_cairo(self.handle, z.ctx) > WindowsError: exception: access violation reading 0x00000008 Can anybody help my with the svg2png conversion here? Thanks, Hilmar From hniksic at xemacs.org Mon Jun 15 07:47:08 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Jun 2009 13:47:08 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <87k53d4t37.fsf@busola.homelinux.net> Terry Reedy writes: > You did not specify version. In Python3, os.walk has become a > generater function. So, to answer your question, use 3.1. os.walk has been a generator function all along, but that doesn't help OP because it still uses os.listdir internally. This means that it both creates huge lists for huge directories, and holds on to those lists until the iteration over the directory (and all subdirectories) is finished. In fact, os.walk is not suited for this kind of memory optimization because yielding a *list* of files (and a separate list of subdirectories) is specified in its interface. This hasn't changed in Python 3.1: dirs, nondirs = [], [] for name in names: if isdir(join(top, name)): dirs.append(name) else: nondirs.append(name) if topdown: yield top, dirs, nondirs From hniksic at xemacs.org Mon Jun 15 08:00:02 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 15 Jun 2009 14:00:02 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> Message-ID: <87fxe14shp.fsf@busola.homelinux.net> Nick Craig-Wood writes: > Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or for hacks one needs right now, but can anyone seriously propose using this kind of code in a Python program? For example, this seems much more "Linux-only", or possibly even "32-bit-Linux-only", than "unix-like": > class c_dirent(Structure): > """Directory entry""" > # FIXME not sure these are the exactly correct types! > _fields_ = ( > ('d_ino', c_long), # inode number > ('d_off', c_long), # offset to the next dirent > ('d_reclen', c_ushort), # length of this record > ('d_type', c_byte), # type of file; not supported by all file system types > ('d_name', c_char * 4096) # filename > ) From deets at nospam.web.de Mon Jun 15 08:15:25 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 14:15:25 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <79ms4jF1r4ja4U1@mid.uni-berlin.de> tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. if we assume the number of files to be a million (which certainly qualifies as one of the larger directory sizes one encounters...), and the average filename length with 20, you'd end up with 20 megs of data. Is that really a problem on nowadays several gigabyte machines? And we are talking a rather freakish case here. Diez From Olivier.Darge at gmail.com Mon Jun 15 08:37:14 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 15 Jun 2009 05:37:14 -0700 (PDT) Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> Message-ID: <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> On 13 juin, 07:25, Mike Kazantsev wrote: > There was quite interesting explaination of what happens when you send > ^C with threads, posted on concurrency-sig list recently: > > ?http://blip.tv/file/2232410 > ?http://www.dabeaz.com/python/GIL.pdf > > Can be quite shocking, but my experience w/ threads only confirms that. Hi there, please read this package page (in 2.6), this is very interesting. http://docs.python.org/library/multiprocessing.html I tested it : it works. Multi-core cpu's are happy :-) me too, Olivier From vs at it.uu.se Mon Jun 15 08:43:46 2009 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 15 Jun 2009 14:43:46 +0200 Subject: On the property function Message-ID: <4A364202.2050700@it.uu.se> Does anyone have a good example (or examples) of when "property(...)" can be useful? Thank you, --V. Stokes From deets at nospam.web.de Mon Jun 15 08:45:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Jun 2009 14:45:37 +0200 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <79mtt7F1r4807U1@mid.uni-berlin.de> Aaron Brady wrote: > Hi, please forgive the multi-posting on this general topic. > > Some time ago, I recommended a pursuit of keeping 'persistent > composite' types on disk, to be read and updated at other times by > other processes. Databases provide this functionality, with the > exception that field types in any given table are required to be > uniform. Python has no such restriction. > > I tried out an implementation of composite collections, specifically > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > It's significantly slower, but we might argue that attempting to do it > by hand classifies as a premature optimization; it is easy to optimize > debugged code. Sounds like you are re-inventing the ZODB. Diez From willgun at live.cn Mon Jun 15 08:58:55 2009 From: willgun at live.cn (willgun) Date: Mon, 15 Jun 2009 20:58:55 +0800 Subject: How to get the total size of a local hard disk? Message-ID: Hi,everyone! How to get the total size of a local hard disk? I mean total size,not free space. Thanks in advance! From bearophileHUGS at lycos.com Mon Jun 15 09:23:47 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Mon, 15 Jun 2009 06:23:47 -0700 (PDT) Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: <8f84c845-396e-4ed9-a7ad-9f80070d9c1f@z9g2000yqi.googlegroups.com> Lawrence D'Oliveiro: >So no, using alternative quotes does not make things more readable.< You think that this: ' ' Isn't a bit more readable and simpler to write than: " " I think lot of doesn't agree with you. In such situation it can also be positive to split such string in two or more parts, for example (untested): style = ("fill:blue; stroke:pink; stroke-width:5; " "fill-opacity:0.1; stroke-opacity:0.9") print >> fo, ' ' % (abs_x, abs_y, w, h, style) Bye, bearophile From gh at ghaering.de Mon Jun 15 09:44:07 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 15 Jun 2009 15:44:07 +0200 Subject: Observer implementations In-Reply-To: References: Message-ID: Tobias Weber wrote: > Hi, > how to use the Observer pattern in Python? Implement it in your classes? > I found PubSub and PyDispatcher, both of which are abandoned. [...] I haven't searched for these, but googling for "python observer pattern" yields http://code.activestate.com/recipes/131499/ and this seems like a good inspiritation for owns own implementation. -- Gerhard From travisaltman at gmail.com Mon Jun 15 09:46:01 2009 From: travisaltman at gmail.com (Travis Altman) Date: Mon, 15 Jun 2009 09:46:01 -0400 Subject: unsuccessful post request hangs, what gives? Message-ID: i'm trying to use a post request to authenticate to a web application. let's say username = alice is valid but username = bob does not exits. making the request with alice works like a charm but when i try username = bob it hangs? any suggestions? -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.org.uk Mon Jun 15 09:48:17 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Mon, 15 Jun 2009 06:48:17 -0700 (PDT) Subject: How to get the total size of a local hard disk? References: Message-ID: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> On 15 Jun, 14:58, willgun wrote: > > How to get the total size of a local hard disk? > I mean total size,not free space. Which platform are you using? On a Linux-based system you might look at the contents of /proc/partitions and then, presumably with Python, parse the contents to yield a number of blocks for the hard disk in question. This quantity would then be converted into a more familiar measure. One might expect something like PSI to support this kind of activity... http://bitbucket.org/chrismiles/psi/ ...but I think it only really provides process-related information. Paul From willgun at live.cn Mon Jun 15 09:53:17 2009 From: willgun at live.cn (willgun) Date: Mon, 15 Jun 2009 21:53:17 +0800 Subject: How to get the total size of a local hard disk? In-Reply-To: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: Unfortunately,I'm on win32. Actually,I prefer a cross-platform method. Thanks. From mail at timgolden.me.uk Mon Jun 15 09:53:57 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Jun 2009 14:53:57 +0100 Subject: How to get the total size of a local hard disk? In-Reply-To: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <4A365275.3010706@timgolden.me.uk> Paul Boddie wrote: > On 15 Jun, 14:58, willgun wrote: >> How to get the total size of a local hard disk? >> I mean total size,not free space. > > Which platform are you using? On a Linux-based system you might look > at the contents of /proc/partitions and then, presumably with Python, > parse the contents to yield a number of blocks for the hard disk in > question. This quantity would then be converted into a more familiar > measure. > > One might expect something like PSI to support this kind of > activity... > > http://bitbucket.org/chrismiles/psi/ > > ...but I think it only really provides process-related information. On Windows, WMI is nearly always the answer to these kind of things (altho' since WMI is nearly always a shell around other APIs there's usually some other way). http://timgolden.me.uk/python/wmi_cookbook.html#percentage_free TJG From mail at timgolden.me.uk Mon Jun 15 10:04:08 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Jun 2009 15:04:08 +0100 Subject: How to get the total size of a local hard disk? In-Reply-To: References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <4A3654D8.2080804@timgolden.me.uk> willgun wrote: > Unfortunately,I'm on win32. > Actually,I prefer a cross-platform method. > Thanks. These kind of things tend to be fairly platform specific. Obviously, nothing's stopping anyone writing a module which does some platform-sniffing and conditional imports and provides a consistent interface. Far as I know, though, there's no such thing for Python at the mo. Think of it as a market opportunity! TJG From nick at craig-wood.com Mon Jun 15 10:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 09:29:33 -0500 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> <87fxe14shp.fsf@busola.homelinux.net> Message-ID: Hrvoje Niksic wrote: > Nick Craig-Wood writes: > > > Here is a ctypes generator listdir for unix-like OSes. > > ctypes code scares me with its duplication of the contents of system > headers. I understand its use as a proof of concept, or for hacks one > needs right now, but can anyone seriously propose using this kind of > code in a Python program? For example, this seems much more > "Linux-only", or possibly even "32-bit-Linux-only", than > "unix-like": It was a proof of concept certainly.. It can be done properly with gccxml though which converts structures into ctypes definitions. That said the dirent struct is specified by POSIX so if you get the correct types for all the individual members then it should be correct everywhere. Maybe ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From exarkun at divmod.com Mon Jun 15 10:38:44 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 10:38:44 -0400 Subject: waling a directory with very many files In-Reply-To: Message-ID: <20090615143844.22176.641726464.divmod.quotient.5585@henry.divmod.com> On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: >Hrvoje Niksic wrote: >> Nick Craig-Wood writes: >> >> > Here is a ctypes generator listdir for unix-like OSes. >> >> ctypes code scares me with its duplication of the contents of system >> headers. I understand its use as a proof of concept, or for hacks one >> needs right now, but can anyone seriously propose using this kind of >> code in a Python program? For example, this seems much more >> "Linux-only", or possibly even "32-bit-Linux-only", than >> "unix-like": > >It was a proof of concept certainly.. > >It can be done properly with gccxml though which converts structures >into ctypes definitions. > >That said the dirent struct is specified by POSIX so if you get the >correct types for all the individual members then it should be correct >everywhere. Maybe ;-) > The problem is that POSIX specifies the fields with types like off_t and ino_t. Since ctypes doesn't know anything about these types, application code has to specify their size and other attributes. As these vary from platform to platform, you can't get it correct without asking a real C compiler. In other words, POSIX talks about APIs and ctypes deals with ABIs. http://pypi.python.org/pypi/ctypes_configure/0.1 helps with the problem, and is a bit more accessible than gccxml. It is basically correct to say that using ctypes without using something like gccxml or ctypes_configure will give you non-portable code. Jean-Paul From andrew.henshaw at gtri.gatech.edu Mon Jun 15 10:40:24 2009 From: andrew.henshaw at gtri.gatech.edu (Andrew Henshaw) Date: Mon, 15 Jun 2009 10:40:24 -0400 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: "Raymond Hettinger" wrote in message news:fb1feeeb-c430-4ca7-9e76-fea02ea3ef6f at v23g2000pro.googlegroups.com... > [David Wilson] >> The problem is simple: given one or more ordered sequences, return >> only the objects that appear in each sequence, without reading the >> whole set into memory. This is basically an SQL many-many join. > > FWIW, this is equivalent to the Welfare Crook problem in David Gries > book, The Science of Programming, http://tinyurl.com/mzoqk4 . > > >> I thought it could be accomplished through recursively embedded >> generators, but that approach failed in the end. > > Translated into Python, David Gries' solution looks like this: > > def intersect(f, g, h): > i = j = k = 0 > try: > while True: > if f[i] < g[j]: > i += 1 > elif g[j] < h[k]: > j += 1 > elif h[k] < f[i]: > k += 1 > else: > print(f[i]) > i += 1 > except IndexError: > pass > > streams = [sorted(sample(range(50), 30)) for i in range(3)] > for s in streams: > print(s) > intersect(*streams) > > > Raymond Here's my translation of your code to support variable number of streams: def intersect(*s): num_streams = len(s) indices = [0]*num_streams try: while True: for i in range(num_streams): j = (i + 1) % num_streams if s[i][indices[i]] < s[j][indices[j]]: indices[i] += 1 break else: print(s[0][indices[0]]) indices[0] += 1 except IndexError: pass From ken at seehart.com Mon Jun 15 10:54:27 2009 From: ken at seehart.com (Ken Seehart) Date: Mon, 15 Jun 2009 07:54:27 -0700 Subject: unsuccessful post request hangs, what gives? In-Reply-To: References: Message-ID: <4A3660A3.4090001@seehart.com> Travis Altman wrote: > i'm trying to use a post request to authenticate to a web > application. let's say username = alice is valid but username = bob > does not exits. making the request with alice works like a charm but > when i try username = bob it hangs? any suggestions? Can you show us the relevant code? - Ken From jcd at sdf.lonestar.org Mon Jun 15 11:05:59 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 15 Jun 2009 11:05:59 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> References: <0244e6d3$0$20638$c3e8da3@news.astraweb.com> Message-ID: <1245078359.10076.13.camel@aalcdl07> On Sun, 2009-06-14 at 23:01 +1000, Steven D'Aprano wrote: > Write a helper function: > > def getitems(L, *indexes): > if len(indexes) == 1: > indexes = indexes[0] > return [L[i] for i in indexes] > Whoops! Your example is broken: >>> cars = ['Ford', 'Toyota', 'Edsel'] >>> getitems(cars, 1) Traceback (most recent call last): File "", line 1, in File "", line 4, in getitems TypeError: 'int' object is not iterable >>> I think you meant to apply that [0] to the created list instead. Something like: def getitems(L, *indexes): new_list = [L[i] for i in indexes] if len(indexes) == 1: new_list = new_list[0] return new_list But I'm not sure that would be the best idea anyway. Just let getitems always return a list. That way the caller doesn't have to test the length to figure out what to do with it. If you know you want a single item, you can use regular old .__getitem__ (or .get) methods, or direct indexing. Then getitems can just be: def getitems(L, *indexes): return [L[i] for i in indexes] > > But I think this is an obvious enough extension to the __getitem__ protocol > that I for one would vote +1 on it being added to Python sequence objects > (lists, tuples, strings). > I'd be +0. It won't change my life, but it seems like a decent idea. > > -- > Steven > Cheers, Cliff From roop at forwardbias.in Mon Jun 15 11:08:20 2009 From: roop at forwardbias.in (roop) Date: Mon, 15 Jun 2009 08:08:20 -0700 (PDT) Subject: ImageEnhance.Contrast - is this fishy or what? Message-ID: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> I was browsing ImageEnhace.py, and found something that I thought was odd in class Contrast: class Contrast(_Enhance): "Adjust image contrast" def __init__(self, image): self.image = image mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/ 256.0 self.degenerate = Image.new("L", image.size, mean).convert (image.mode) Isn't reduce(lambda a,b: a+b, image.convert("L").histogram()) the same as (image.size[0] * image.size[1]) - just count the number of pixels in the image? (Afaik, the histogram is a list of 256 elements where the ith element gives the number of pixels with i as the pixel value (0 <= i < 256)). Is this actually fishy or have I got it all muddled up? Thanks, roop From Juergen.Hermann at 1und1.de Mon Jun 15 11:33:58 2009 From: Juergen.Hermann at 1und1.de (jh) Date: Mon, 15 Jun 2009 15:33:58 +0000 (UTC) Subject: how to get the path of a module (myself) ? References: <4A2447F0.2050905@gmail.com> <662715f21fdf486785783086cec9cda3@preisshare.net> <4A24685D.5000500@gmail.com> Message-ID: Stef Mientki gmail.com> writes: > I don't seem to have pkg_utils, > only pkgutil, which doesn't have an apropiate function. > > But I found another way, don't know if that's reliable: > import inspect > print inspect.currentframe().f_code.co_filenameE Eeek. > head -999 foo/* ==> foo/__init__.py <== import pkg_resources print pkg_resources.resource_string(__name__, "bar") ==> foo/bar <== bar > python -c "import foo" bar Make a "def load_resource" from that print line and you're done. From aahz at pythoncraft.com Mon Jun 15 11:37:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Jun 2009 08:37:19 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: In article <79mtt7F1r4807U1 at mid.uni-berlin.de>, Diez B. Roggisch wrote: >Aaron Brady wrote: >> >> Some time ago, I recommended a pursuit of keeping 'persistent >> composite' types on disk, to be read and updated at other times by >> other processes. Databases provide this functionality, with the >> exception that field types in any given table are required to be >> uniform. Python has no such restriction. >> >> I tried out an implementation of composite collections, specifically >> lists, sets, and dicts, using 'sqlite3' as a persistence back-end. >> It's significantly slower, but we might argue that attempting to do it >> by hand classifies as a premature optimization; it is easy to optimize >> debugged code. > >Sounds like you are re-inventing the ZODB. ...or SQLAlchemy or pickles in a SQL BLOB or... -- 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 vadim.pestovnikov at gmail.com Mon Jun 15 11:37:32 2009 From: vadim.pestovnikov at gmail.com (VP) Date: Mon, 15 Jun 2009 08:37:32 -0700 (PDT) Subject: Please advise me for a right solution Message-ID: <15b1e25c-2bb4-425e-974f-be3d686b5931@p21g2000prn.googlegroups.com> Hi all, Please advise me for a right solution based on your experience. I need to create a web based inventory tool with specific requirements such as: * More then one group is going to use it. * Authentication and authorization system based on user and group privileges. For example based on a group privileges group can add/edit/delete their own stuff and having a read only access to other groups stuff. etc. What solution is better for that? * CGI implementation from the scratch. It seems to much work and I am not sure that this is right way. * WSGI based frameworks such as Werkzeug, Pylons, repoze.bg for HTTP requests and responds plus different components like AuthKit, repoze.who and repoze.what, SQLAlchemy or raw SQL I was trying to get those thing done by Django, but realized that every time I have to extend Django admin interface or to extend user profile etc.. I am not telling that Django is not good for this, just personal fillings. May be I am wrong. Well, what you recommend me? From usernet at ilthio.net Mon Jun 15 11:40:53 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 15 Jun 2009 15:40:53 GMT Subject: cross platform method Re: How to get the total size of a local hard disk? References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> On 2009-06-15, Tim Golden wrote: > These kind of things tend to be fairly platform specific. There is however a way to do it in a cross platform manner which will return an appoximation of the available space. 1. delete all of the files (and folders) on the partition that you want to test. 2. create a file as large as the drive will permit. 3. repeat two with as many files as the drive will allow to be written. This needs to be done on filesystems with file size limits (ie, FAT file systems will only allow files as large as 4G). 4. Once all the files have been written, calculate the total size of all of the files to get your answer. This method is a little descructive and slow; but, it should work on all platforms. This is a joke. Do not take it seriously. I do not actually suggest anybody use this method to measure the size of their drive. I do not take any responsibility for any damages incurred by using this method. I will laugh at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands. From aahz at pythoncraft.com Mon Jun 15 11:47:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 15 Jun 2009 08:47:45 -0700 Subject: weakrefs, threads,, and object ids References: <84397edd-4830-4c90-9fb6-f72c74028f6e@i28g2000prd.googlegroups.com> Message-ID: In article <84397edd-4830-4c90-9fb6-f72c74028f6e at i28g2000prd.googlegroups.com>, Jeremy wrote: > >While guaranteed unique for simultaneously existing objects, how often >will an object assume an ID previously held by former object? Given >that the ID is a memory address in Python's heap, I assume the answer >is either not often, or very often. Very often: Python 2.4 (#1, Jan 17 2005, 14:59:14) [GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2 Type "help", "copyright", "credits" or "license" for more information. >>> x = id(object()) >>> y = id(object()) >>> x == y True Sorry, can't help you with your other questions; I'm not familiar with weakrefs. -- 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 rridge at csclub.uwaterloo.ca Mon Jun 15 11:48:14 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Mon, 15 Jun 2009 11:48:14 -0400 Subject: matplotlib installation References: <20090612125021.22176.846257516.divmod.quotient.4771@henry.divmod.com> Message-ID: David Cournapeau wrote: > Basically, there are some functions which are erroneously "declared" > in the .lib, but they don't actually exist in the MS C runtime. Lawrence D'Oliveiro wrote: > Isn't this a MinGW bug? No, MinGW runtime library isn't supposed to be fully compatible with the Microsoft runtime library. While MinGW happens to use part of an older Microsoft runtime library (MSVCRT.DLL) the goal of the MinGW has never been to make a compiler that was 100% compatible with any version of the Microsoft C compiler. There also isn't anything wrong with the Microsoft runtime. A library that mixes both objects and import records is perfectly legitimate. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From dmitrey.kroshko at scipy.org Mon Jun 15 11:49:24 2009 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Mon, 15 Jun 2009 08:49:24 -0700 (PDT) Subject: ANN: openopt 0.24 - free numerical optimization framework Message-ID: Hi all, OpenOpt 0.24, a free Python-written numerical optimization framework with some own solvers and connections to tens of 3rd party ones, has been released. BSD license allows to use it in both free opensource and commercial closed-code software. Currently we have ~80 unique visitors daily, 15% of the ones visit installation webpage, and some more install it via PYPI, Debian and Alt Linux repository, mac.softpedia.com, darwinports.com, pythonxy.com, mloss.org. Our homepage: http://openopt.org Introduction to the framework: http://openopt.org/Foreword All release details are here: http://openopt.org/Changelog or http://forum.openopt.org/viewtopic.php?id=110 Regards, OpenOpt developers. From mk.fraggod at gmail.com Mon Jun 15 11:53:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Mon, 15 Jun 2009 21:53:35 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> Message-ID: <20090615215335.4cb26673@coercion> On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) OdarR wrote: > On 13 juin, 07:25, Mike Kazantsev wrote: > > There was quite interesting explaination of what happens when you send > > ^C with threads, posted on concurrency-sig list recently: > > > > ?http://blip.tv/file/2232410 > > ?http://www.dabeaz.com/python/GIL.pdf > > > > Can be quite shocking, but my experience w/ threads only confirms that. > > Hi there, > please read this package page (in 2.6), this is very interesting. > http://docs.python.org/library/multiprocessing.html > > I tested it : it works. Multi-core cpu's are happy :-) I'd certainly prefer using processes because they indeed work flawlessly in that respect, but threads are way simplier and much more integrated into the language, so I can avoid re-imlementing tons of shared stuff, IPC and locking by using threads which bassically run in the same context. That might mean 90% of code for trivial but parallel task. Alas, they don't work flawlessly in all cases, but there is still million and one use for them. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From s.dornseifer at gmx.net Mon Jun 15 11:55:00 2009 From: s.dornseifer at gmx.net (S. Dornseifer) Date: Mon, 15 Jun 2009 17:55:00 +0200 Subject: install Python-2.4.4 from source (parallel to existing Python-2.6) In-Reply-To: <4A336D62.6070302@gmx.de> References: <4A3258A2.1040204@gmx.de> <4A328AF1.8090205@gmx.de> <4A336D62.6070302@gmx.de> Message-ID: <4A366ED4.4030004@gmx.net> Simon wrote: > Christian Heimes wrote: >> Simon schrieb: >>> Christian Heimes wrote: >>>> Simon wrote: >>>>> I installed Python-2.4.4.tar.bz2 from python.org, using gcc-4.3 >>>>> (within >>>>> openSUSE 11.1 x86_64) via 'make altinstall'. >>>>> >>>>> First, I tried to configure with the following flags: >>>>> --prefix=/opt/python-24 --enable-framework --with-pydebug >>>>> This provoked an error during compilation via make (sorry, the list >>>>> was >>>>> so long, but I will post it, if it helps). >>>> --enable-framework is for Mac OS X only. >>>> >>>>> Second, configured again without any flags. The installation by 'make >>>>> altinstall' to /usr/local was a success. Python2.6 seams unaffected, >>>>> too. So, I got my parallel installation. >>>> You have chosen the correct and canonical way to install a parallel >>>> installation of Python. >>>> >>>>> However, I cannot import modules like Tkinter or readline within >>>>> python2.4. >>>> You must install the development library of tk, readline, zlib and >>>> libbz2 prior to configure && make. >>>> >>>> Try this on your box: >>>> >>>> zypper install gcc make autoconf automake libtool zlib-devel >>>> readline-devel tk-devel tcl-devel sqlite2-devel libbz2-devel >>>> libopenssl-devel >>>> >>> >>> Unfortunately, I got the following errors, while compiling via make. >>> Please, see attached text file for details about everything I did from >>> installing the missing packages via zypper until make. >> >> zypper should have installed all necessary dependencies, including a >> whole bunch of X11 headers. Something seems to be wrong on your system >> or SuSE's package dependencies. >> I know why I dislike SuSE. :) Although I started my Linux career 12 >> years ago with SuSE I prefer Debian based systems since Woody came out >> in 2002. :) >> >>> X11 says: >>> Program 'X11' is present in package 'xorg-x11', which is installed on >>> your system. >> >> zypper search X11 | grep devel >> ... >> zypper install xorg-x11-devel >> >> That should (hopefully) do the trick. On a Debian based systems it's >> much easier to install all Python dependencies with "apt-get build-dep >> python2.5" >> >> To quote SuSE: "Have a lot of fun ..." >> >> Und viel Gl?ck! >> >> Christian >> > > Danke :) > > On Monday, I will be able to tell if it worked out, or if I have to try > a new strategy, e.g. to convince the admin about (K)ubuntu. Problem is solved, thanks again :) From Juergen.Hermann at 1und1.de Mon Jun 15 11:56:14 2009 From: Juergen.Hermann at 1und1.de (Juergen Hermann) Date: Mon, 15 Jun 2009 15:56:14 +0000 (UTC) Subject: Programming language comparison examples? References: <20090605192040.C5A6310ED608@montanaro.dyndns.org> Message-ID: pobox.com> writes: > but that's not what I was thinking of. I thought there was a site with a > bunch of smaller examples. http://langref.org/ is another one. From castironpi at gmail.com Mon Jun 15 11:56:20 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 08:56:20 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: <8021c688-c2d0-44be-87a9-a4dcfba8909a@s1g2000prd.googlegroups.com> On Jun 15, 5:45?am, "Diez B. Roggisch" wrote: > Aaron Brady wrote: > > Hi, please forgive the multi-posting on this general topic. > > > Some time ago, I recommended a pursuit of keeping 'persistent > > composite' types on disk, to be read and updated at other times by > > other processes. ?Databases provide this functionality, with the > > exception that field types in any given table are required to be > > uniform. ?Python has no such restriction. > > > I tried out an implementation of composite collections, specifically > > lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > > It's significantly slower, but we might argue that attempting to do it > > by hand classifies as a premature optimization; it is easy to optimize > > debugged code. > > > > Sounds like you are re-inventing the ZODB. > > Diez Alright, Diez. Here is some private consulting for free. ''Section 2.6.1: The most common idiom that isn't caught by the ZODB is mutating a list or dictionary'' My approach performs this for free. The docs also don't mention interprocess communication, which is one of the two primary functions that I satisfy in my approach. The syntax is different, non-trivially so, and mine is more Pythonic. From castironpi at gmail.com Mon Jun 15 11:56:57 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 08:56:57 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> On Jun 14, 10:18?am, Jaime Fernandez del Rio wrote: > On Sun, Jun 14, 2009 at 4:27 PM, Aaron Brady wrote: > > > Before I go and flesh out the entire interfaces for the provided > > types, does anyone have a use for it? > > A real-world application of persistent data structures can be found here: > > http://stevekrenzel.com/persistent-list > > Jaime Jaime, thanks for the link. I contacted its author. From mk.fraggod at gmail.com Mon Jun 15 12:03:44 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Mon, 15 Jun 2009 22:03:44 +0600 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> Message-ID: <20090615220344.7585cb9b@coercion> On Sun, 14 Jun 2009 22:45:38 -0700 (PDT) deostroll wrote: > I need to be able to parse a json data object using the simplejson > package. First of all I need to know all the task needed for this job. Note that py2.6 has a bundled json module. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From castironpi at gmail.com Mon Jun 15 12:10:56 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 09:10:56 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: <9c0fd2d2-7a26-44bc-9e51-2a6126c2c312@v35g2000pro.googlegroups.com> On Jun 14, 9:50?pm, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > > Steven D'Aprano wrote: > > >> So-called "vacuous truth". It's often useful to have all([]) return > >> true, but it's not *always* useful -- there are reasonable cases where > >> the opposite behaviour would be useful: > [...] > > It seems to me that the absurd conclusion implied by the theorem > > invalidates the theorem rather than supporting your point. > > I wouldn't go so far as to say the vacuous truth theorem ("empty > statements are true") is invalidated. The Wikipedia article discusses > various reasons why it's more correct (or at least more useful) to treat > vacuous statements as true: > > http://en.wikipedia.org/wiki/Vacuous_truth > > But it's not without difficulties -- however those difficulties are > smaller than those if you take vacuous statements as false in general. snip Those difficulties are pretty gaping. I would start by dividing the natural language 'use cases' of 'if' statements into imperative and declarative. Declarative: If it's raining, it's cloudy. In this case, the assertion is meant to convey a general, non- concrete, observation trend across space and time. Its content is a claim of 100% correlation between two statuses of the real world. Imperative: If you're out of bread, go buy some. Here, the speaker is in a position of authority over the audience, who will be following his/er commands, and acting under the speaker's authority. The speaker is meaning to convey conditional instructions, for a possible circumstance. There is no component of observation or assertion. We see this distinction in programming too. Is the user merely asserting a relation, or defining a procedure? Implies( Raining( x ), Cloudy( x ) ) or if OutOfBread( x ): BuyBread( ) The 'if' statement is counterfactual in its native environment. As such, natural speakers never use it in vacuous cases, and it's not naturally defined. In a mathematical (ideal) environment, its semantics are artificially constructed like any other math predicate, and proofs involving it will define its vacuous case, or fail. From castironpi at gmail.com Mon Jun 15 12:18:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 09:18:48 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <79mtt7F1r4807U1@mid.uni-berlin.de> Message-ID: On Jun 15, 8:37?am, a... at pythoncraft.com (Aahz) wrote: > In article <79mtt7F1r480... at mid.uni-berlin.de>, > Diez B. Roggisch wrote: > > >Aaron Brady wrote: > > >> Some time ago, I recommended a pursuit of keeping 'persistent > >> composite' types on disk, to be read and updated at other times by > >> other processes. ?Databases provide this functionality, with the > >> exception that field types in any given table are required to be > >> uniform. ?Python has no such restriction. > > >> I tried out an implementation of composite collections, specifically > >> lists, sets, and dicts, using 'sqlite3' as a persistence back-end. > >> It's significantly slower, but we might argue that attempting to do it > >> by hand classifies as a premature optimization; it is easy to optimize > >> debugged code. > > >Sounds like you are re-inventing the ZODB. > > ...or SQLAlchemy or pickles in a SQL BLOB or... I recognize your aversion to my claim of making a new approach on something. I suppose an austere review of literature would compare with the existing alternatives. My approach does not define tables, so it is not SQL Alchemy; it is not mere sugar for SQL. It defines a 'set' class and a 'tuple' class, so some of the functionality may (and probably should be expected to) overlap. http://www.sqlalchemy.org/docs/05/ormtutorial.html#define-and-create-a-table My approach does not pickle objects, so it is not a mere BLOB pickle. If a user writes, listA[ 50 ].append( "abcde" ), one addition is made to an existing structure, and the remaining contents of 'listA' are unread and unchanged. From thephantom6969 at hotmail.com Mon Jun 15 13:02:54 2009 From: thephantom6969 at hotmail.com (Mikie) Date: Mon, 15 Jun 2009 10:02:54 -0700 (PDT) Subject: twisted server Message-ID: I am setting up a simple twisted server looks like this ___________________________________________________- It will respond on port 8007 of the local host With a predefined greeting. """ print greeting from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor class QOTD(Protocol): def connectionMade(self): self.transport.write(""" Twisted TCP Server Example

HELLO WORLD!

This is a TCP/IP Server written in Python using
the Twisted networking framework.

Further instruction can be found here:

	Twisted Documentation: Writing Servers


This server will respond on port 8007 of the local host
With a predefined greeting.
		
""") self.transport.loseConnection() # Then lines are Twisted magic: factory = Factory() factory.protocol = QOTD # Running under :8007 # Should be > :1024 reactor.listenTCP(8007, factory) reactor.run() ______________________________________________-- I would like to have an image loaded in the html page, but when I use the port is inserted and the image will not load. Is there a way to load the image? Thanx From http Mon Jun 15 14:10:22 2009 From: http (Paul Rubin) Date: 15 Jun 2009 11:10:22 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> Message-ID: <7xeitlv04x.fsf@ruckus.brouhaha.com> Aaron Brady writes: > > A real-world application of persistent data structures can be found here: > > http://stevekrenzel.com/persistent-list > > Jaime, thanks for the link. I contacted its author. You might also look at www.couchdb.org . From wayne.dads.bell at gmail.com Mon Jun 15 14:38:58 2009 From: wayne.dads.bell at gmail.com (dads) Date: Mon, 15 Jun 2009 11:38:58 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: I remember someone earlier in the thread mentioning reading source code from good coders. I've been wanting to give this a go as it makes perfect sense, I suppose the standard library would be a good start. What would your recommendations be, something not too too hard, so I don't understand. From chulusjo at franticfilms.com Mon Jun 15 14:58:59 2009 From: chulusjo at franticfilms.com (Christoffer Hulusjo) Date: Mon, 15 Jun 2009 11:58:59 -0700 Subject: catch/block assertion pop-up? Message-ID: <4A3699F3.8020709@franticfilms.com> Hi. I'm using a 32bit Python module to control a graphics application (Eyeon Fusion), that the developer of the application has released to allow python scripting. The module is known to have a bunch of bugs and the company that made it tells me that there is not a scheduled update anytime soon. I'm using simple commands that allows me to access the applications function, it looks something like this. .... fusionApp.Connect() settingsTable = fusionApp.GetSettings() .... The problem is that on some specific functions (which actually works and returns the requested data), it outputs assertion errors, which is a pop-up window like this... "Fusion Assert" (title) "File: FusionScript.cpp" "Line: 361" "Condition: false" "Debug, Disable, Skip" (buttons) So I'm getting all the data I need, but the popup error assertion makes my application useless as it could halt for user interaction at any time. By the looks of the error message it seems to be something actually happening in a c++ dll that the python module wraps to connect to the host application. I can't wait for the developer to update the library so my question is, Are there any way to suppress/block/catch dialogs that are poping up or assertions? it doesn't trigger any exception so I cant use try, catch. I'm using Python 2.5.2 32bit build on Windows XP 64bit OS. Best regards Christoffer From exarkun at divmod.com Mon Jun 15 15:01:24 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 15:01:24 -0400 Subject: twisted server In-Reply-To: Message-ID: <20090615190124.22176.1787062085.divmod.quotient.5697@henry.divmod.com> On Mon, 15 Jun 2009 10:02:54 -0700 (PDT), Mikie wrote: >I am setting up a simple twisted server looks like this > > [snip] > >I would like to have an image loaded in the html page, but when I use > the port is inserted and the image will not >load. Is there a way to load the image? This isn't a good way to make a web server with Twisted. Take a look at http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.html Jean-Paul From daniel.watrous at gmail.com Mon Jun 15 15:14:28 2009 From: daniel.watrous at gmail.com (Daniel) Date: Mon, 15 Jun 2009 12:14:28 -0700 (PDT) Subject: Limit (max) connections SimpleHTTPServer Message-ID: <310b1ad4-879e-4e4f-8244-9bfc6f4ebfc7@y10g2000prc.googlegroups.com> Hello, I would like to know if there is some way to limit the maximum number of connections to my SimpleHTTPServer. I have built a system that sends out work from one box to worker boxes and am using SimpleHTTPServer to send the work. The files are very large (sometimes as much as 20-30MB). When the system gets backed up, there can be as many as 500 requests coming in. After about 100 connections, the whole system starts to get sluggish. When they get over 250 or so some requests will begin to fail "error: (10054, 'Connection reset by peer')" or "error: (10053, 'Software caused connection abort')" Any help and suggestions appreciated. Thanks. From exarkun at divmod.com Mon Jun 15 15:30:55 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 15 Jun 2009 15:30:55 -0400 Subject: Limit (max) connections SimpleHTTPServer In-Reply-To: <310b1ad4-879e-4e4f-8244-9bfc6f4ebfc7@y10g2000prc.googlegroups.com> Message-ID: <20090615193055.22176.273946368.divmod.quotient.5708@henry.divmod.com> On Mon, 15 Jun 2009 12:14:28 -0700 (PDT), Daniel wrote: >Hello, > >I would like to know if there is some way to limit the maximum number >of connections to my SimpleHTTPServer. I have built a system that >sends out work from one box to worker boxes and am using >SimpleHTTPServer to send the work. The files are very large >(sometimes as much as 20-30MB). When the system gets backed up, there >can be as many as 500 requests coming in. After about 100 >connections, the whole system starts to get sluggish. When they get >over 250 or so some requests will begin to fail > >"error: (10054, 'Connection reset by peer')" > >or "error: (10053, 'Software caused connection abort')" > >Any help and suggestions appreciated. For a server that has to deal with this kind of load, you might want to look at Twisted instead of SimpleHTTPServer. You can certainly impose a limit on the number of connections SimpleHTTPServer handles at once, but you'll get better performance with Twisted, due to less thread overhead and because you probably won't have to impose such a limit, or if you do, it can be much higher. Check it out: http://twistedmatrix.com/trac/ http://twistedmatrix.com/projects/core/documentation/howto/servers.html Jean-Paul From tjreedy at udel.edu Mon Jun 15 15:35:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 15:35:04 -0400 Subject: waling a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: Christian Heimes wrote: > Terry Reedy wrote: >> You did not specify version. In Python3, os.walk has become a generater >> function. So, to answer your question, use 3.1. > > I'm sorry to inform you that Python 3.x still returns a list, not a > generator. >>> type(os.walk('.')) However, it is a generator of directory tuples that include a filename list produced by listdir, rather than a generator of filenames themselves, as I was thinking. I wish listdir had been changed in 3.0 along with map, filter, and range, but I made no effort and hence cannot complain. tjr From hellzfury at gmail.com Mon Jun 15 15:43:13 2009 From: hellzfury at gmail.com (Matt) Date: Mon, 15 Jun 2009 15:43:13 -0400 Subject: Multi-Threading and KeyboardInterrupt In-Reply-To: <20090615215335.4cb26673@coercion> References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> <20090615215335.4cb26673@coercion> Message-ID: <4C03B3DE-1DFC-4514-AC33-12BE334AC268@gmail.com> I'm going to use the multipocessing library from here forward so I can take advantage of multiple cores and clusters. Either one should work for my use, since in my non-demonstration code each thread spends most of it's time waiting for a separate non-Python subprocess (created with subprocess.Popen) to finish anyway. (I guess Python would see this as IO-blocking) Therefore, if you can fix my toy example with threading, that's fine. DB.py, followed by a KeyboardInterrupt yields the output in a.out. I want roughly the output in desired.out. What do I need to do to modify this code to get my desired output and corresponding functionality? It would be a shame if this wasn't possible in any pure-Python way. ~Matt On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote: > On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) > OdarR wrote: > >> On 13 juin, 07:25, Mike Kazantsev wrote: >>> There was quite interesting explaination of what happens when you >>> send >>> ^C with threads, posted on concurrency-sig list recently: >>> >>> http://blip.tv/file/2232410 >>> http://www.dabeaz.com/python/GIL.pdf >>> >>> Can be quite shocking, but my experience w/ threads only confirms >>> that. >> >> Hi there, >> please read this package page (in 2.6), this is very interesting. >> http://docs.python.org/library/multiprocessing.html >> >> I tested it : it works. Multi-core cpu's are happy :-) > > I'd certainly prefer using processes because they indeed work > flawlessly in that respect, but threads are way simplier and much more > integrated into the language, so I can avoid re-imlementing tons of > shared stuff, IPC and locking by using threads which bassically run in > the same context. > That might mean 90% of code for trivial but parallel task. > > Alas, they don't work flawlessly in all cases, but there is still > million and one use for them. > > -- > Mike Kazantsev // fraggod.net > -- > http://mail.python.org/mailman/listinfo/python-list I'm going to use the multipocessing library from here forward so I can take advantage of multiple cores and clusters. Either one should work for my use, since in my non-demonstration code each thread spends most of it's time waiting for a separate non-Python subprocess (created with subprocess.Popen) to finish anyway. (I guess Python would see this as IO-blocking) DB.py, followed by a KeyboardInterrupt yields the output in a.out. I want roughly the output in desired.out. What do I need to do to modify this code to get my desired output and corresponding functionality? It would be a shame if this wasn't possible in any pure-Python way. ~Matt On Jun 15, 2009, at 11:53 AM, Mike Kazantsev wrote: > On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) > OdarR wrote: > >> On 13 juin, 07:25, Mike Kazantsev wrote: >>> There was quite interesting explaination of what happens when you >>> send >>> ^C with threads, posted on concurrency-sig list recently: >>> >>> http://blip.tv/file/2232410 >>> http://www.dabeaz.com/python/GIL.pdf >>> >>> Can be quite shocking, but my experience w/ threads only confirms >>> that. >> >> Hi there, >> please read this package page (in 2.6), this is very interesting. >> http://docs.python.org/library/multiprocessing.html >> >> I tested it : it works. Multi-core cpu's are happy :-) > > I'd certainly prefer using processes because they indeed work > flawlessly in that respect, but threads are way simplier and much more > integrated into the language, so I can avoid re-imlementing tons of > shared stuff, IPC and locking by using threads which bassically run in > the same context. > That might mean 90% of code for trivial but parallel task. > > Alas, they don't work flawlessly in all cases, but there is still > million and one use for them. > > -- > Mike Kazantsev // fraggod.net > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: a.out Type: application/octet-stream Size: 2780 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: desired.out Type: application/octet-stream Size: 142 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Sub.py Type: text/x-python-script Size: 165 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: DB.py Type: text/x-python-script Size: 604 bytes Desc: not available URL: From tjreedy at udel.edu Mon Jun 15 16:00:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:00:42 -0400 Subject: Question about None In-Reply-To: References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <0050d4eb$0$9666$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 14 Jun 2009 19:14:10 -0400, Terry Reedy wrote: > >> Steven D'Aprano wrote: >>> So-called "vacuous truth". It's often useful to have all([]) return >>> true, but it's not *always* useful -- there are reasonable cases where >>> the opposite behaviour would be useful: > [...] >> It seems to me that the absurd conclusion implied by the theorem >> invalidates the theorem rather than supporting your point. > > I wouldn't go so far as to say the vacuous truth theorem ("empty > statements are true") is invalidated. The Wikipedia article discusses > various reasons why it's more correct (or at least more useful) to treat > vacuous statements as true: > > http://en.wikipedia.org/wiki/Vacuous_truth > > But it's not without difficulties -- however those difficulties are > smaller than those if you take vacuous statements as false in general. > > [...] >> Try finding another 'reasonable case'. > > Any time you do something like: > > if not x and all(x): > process(x) > > > instead of just: > > if all(x): > process(x) > > > I can't think of a real world example off the top of my head, but here's > a contrived example demonstrating that vacuous truths imply both a fact > and it's opposite: > > > def startswith(s, chars): > """Return True if s starts with any of chars.""" > for c in chars: > if s.startswith(c): return True > return False > > > if all([startswith(w, "aeiou") for w in words]): > print "All the words start with vowels." > > if all([startswith(w, "bcdfghjklmnpqrstvwxyz") for w in words]): > print "All of the words start with consonants." > If words is empty, this code claims that all of the words start with > vowels as well as starting with consonants. So? These are true and non-contradictory. They are NOT 'opposites'. Together they imply that there are are no words in words, which is true. To paraphrase my response to mel, I believe it was: [(x in words => x.startswith(vowel)) and (x in words => x.startswith(nonvowel)) and x.startswith(vowel) <=> not(x.startswith(nonvowel)] => not(x in words) which is the definition of 'words is the empty set' by the law of contradiction. The negation of 'all words starts with vowel' is 'there exists a word that starts with a non-vowel', which is different from 'all words start with consonants' since the latter is true when there are no words whereas the former is not. Terry Jan Reedy From tjreedy at udel.edu Mon Jun 15 16:06:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:06:36 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> Message-ID: John Machin wrote: > On Jun 15, 9:49 am, Terry Reedy wrote: >> Poor Yorick wrote: >>> The following code produces an error (python-2.6.2). >> You forgot to post the error traceback. > > The exception was IGNORED ... so no traceback. Yes, I forgot that Exception TypeError: "'NoneType' object is not callable" in ignored should be parsed as '''Exception TypeError: "'NoneType' object is not callable" in''' [was] ignored rather than read as Exception TypeError: "'NoneType' object is not callable" in ignored From arnodel at googlemail.com Mon Jun 15 16:10:04 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Jun 2009 21:10:04 +0100 Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: "Andrew Henshaw" writes: > "Raymond Hettinger" wrote in message > news:fb1feeeb-c430-4ca7-9e76-fea02ea3ef6f at v23g2000pro.googlegroups.com... >> [David Wilson] >>> The problem is simple: given one or more ordered sequences, return >>> only the objects that appear in each sequence, without reading the >>> whole set into memory. This is basically an SQL many-many join. >> >> FWIW, this is equivalent to the Welfare Crook problem in David Gries >> book, The Science of Programming, http://tinyurl.com/mzoqk4 . >> >> >>> I thought it could be accomplished through recursively embedded >>> generators, but that approach failed in the end. >> >> Translated into Python, David Gries' solution looks like this: >> >> def intersect(f, g, h): >> i = j = k = 0 >> try: >> while True: >> if f[i] < g[j]: >> i += 1 >> elif g[j] < h[k]: >> j += 1 >> elif h[k] < f[i]: >> k += 1 >> else: >> print(f[i]) >> i += 1 >> except IndexError: >> pass >> >> streams = [sorted(sample(range(50), 30)) for i in range(3)] >> for s in streams: >> print(s) >> intersect(*streams) >> >> >> Raymond > > Here's my translation of your code to support variable number of streams: > > def intersect(*s): > num_streams = len(s) > indices = [0]*num_streams > try: > while True: > for i in range(num_streams): > j = (i + 1) % num_streams > if s[i][indices[i]] < s[j][indices[j]]: > indices[i] += 1 > break > else: > print(s[0][indices[0]]) > indices[0] += 1 > except IndexError: > pass I posted this solution earlier on: def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(1, len(v)): while v[0] > v[i]: v[i] = nexts[i]() if v[0] < v[i]: break else: yield v[0] v[0] = nexts[0]() It's quite similar but not as clever as the solution proposed by R. Hettinger insofar as it doesn't exploit the fact that if a, b, c are members of a totally ordered set, then: if a >= b >= c >= a then a = b = c. However it can be easily modified to do so: def intersect(iterables): nexts = [iter(iterable).next for iterable in iterables] v = [next() for next in nexts] while True: for i in xrange(-1, len(v)-1): if v[i] < v[i+1]: v[i] = nexts[i]() break else: yield v[0] v[0] = nexts[0]() I haven't really thought about it too much, but there may be cases where the original version terminates faster (I guess when it is expected that the intersection is empty). -- Arnaud From tjreedy at udel.edu Mon Jun 15 16:14:33 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:14:33 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: Phil Runciman wrote: > > Gain access to one of the IEEE or ACM web sites and their resources. > I used to sneak into my local university library before the 'Net to > read this stuff. > > Beyond that I check up on the reading lists for CS students from time > to time. This often throws up real gems and prevents me from being > blind-sided. For those who are not rich, MIT has put a lot of courseware on the web, including in particular, CS, for free. And there is lots more put up by professors and departments elsewhere. There are free language manuals and interpreters/compilers for those who want to stretch their brain that way. From tjreedy at udel.edu Mon Jun 15 16:25:46 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 15 Jun 2009 16:25:46 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: A classic that I found valuable is Science of Programming David Gries, 1981 http://www.amazon.com/gp/product/0387964800 It is still in print as a paperback. Several ssed copies are $11 shipped to US - a bargain. Gries is a died-in-the-wool iterationist. His cursory discussion of recursion is not worth much, but he really knows iteration with while. From james at biosci.utexas.edu Mon Jun 15 16:51:46 2009 From: james at biosci.utexas.edu (james at biosci.utexas.edu) Date: Mon, 15 Jun 2009 15:51:46 -0500 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <20090615155146.4oifsimqdc08sg4k@webmail.utexas.edu> this mit course in the open courseware catalog is focused specifically on python: http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/Syllabus/index.htm Quoting Terry Reedy : > Phil Runciman wrote: >> >> Gain access to one of the IEEE or ACM web sites and their resources. >> I used to sneak into my local university library before the 'Net to >> read this stuff. >> >> Beyond that I check up on the reading lists for CS students from time >> to time. This often throws up real gems and prevents me from being >> blind-sided. > > For those who are not rich, MIT has put a lot of courseware on the web, > including in particular, CS, for free. And there is lots more put up > by professors and departments elsewhere. There are free language > manuals and interpreters/compilers for those who want to stretch their > brain that way. > > -- > http://mail.python.org/mailman/listinfo/python-list From Scott.Daniels at Acm.Org Mon Jun 15 17:05:05 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 15 Jun 2009 14:05:05 -0700 Subject: ImageEnhance.Contrast - is this fishy or what? In-Reply-To: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> Message-ID: roop wrote: > I was browsing ImageEnhace.py, and found something that I thought was > odd in class Contrast: > > class Contrast(_Enhance): > "Adjust image contrast" > def __init__(self, image): > self.image = image > mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/ > 256.0 > self.degenerate = Image.new("L", image.size, mean).convert > (image.mode) > > Isn't reduce(lambda a,b: a+b, image.convert("L").histogram()) the same > as (image.size[0] * image.size[1]) - just count the number of pixels > in the image? (Afaik, the histogram is a list of 256 elements where > the ith element gives the number of pixels with i as the pixel value > (0 <= i < 256)). Is this actually fishy or have I got it all muddled > up? > > Thanks, > roop Good catch [I'll send a copy to the imaging sig]. If you replace class Contrast like this: class Contrast(ImageEnhance._Enhance): "Adjust image contrast" def __init__(self, image): self.image = image w, h = image.size mean = sum(n * c for n, c in enumerate( image.convert("L").histogram()) ) / float(w * h) self.degenerate = Image.new("L", image.size, mean).convert(image.mode) You should get a working Contrast class. There _is_ another possibility: class Contrast(ImageEnhance._Enhance): "Adjust image contrast" def __init__(self, image): self.image = image clone = image.copy() clone.thumbnail((1, 1)) self.degenerate = clone.resize(image.size) The former goes to a grey point, while the latter goes to the picture's color center. I'm not quite sure which one is more properly called "contrast," as I can see wanting either one. --Scott David Daniels Scott.Daniels at Acm.Org From nick at craig-wood.com Mon Jun 15 17:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 15 Jun 2009 16:29:33 -0500 Subject: waling a directory with very many files References: Message-ID: Jean-Paul Calderone wrote: > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: > >Hrvoje Niksic wrote: > >> Nick Craig-Wood writes: > >> > >> > Here is a ctypes generator listdir for unix-like OSes. > >> > >> ctypes code scares me with its duplication of the contents of system > >> headers. I understand its use as a proof of concept, or for hacks one > >> needs right now, but can anyone seriously propose using this kind of > >> code in a Python program? For example, this seems much more > >> "Linux-only", or possibly even "32-bit-Linux-only", than > >> "unix-like": > > > >It was a proof of concept certainly.. > > > >It can be done properly with gccxml though which converts structures > >into ctypes definitions. > > > >That said the dirent struct is specified by POSIX so if you get the > >correct types for all the individual members then it should be correct > >everywhere. Maybe ;-) > > The problem is that POSIX specifies the fields with types like off_t and > ino_t. Since ctypes doesn't know anything about these types, application > code has to specify their size and other attributes. As these vary from > platform to platform, you can't get it correct without asking a real C > compiler. These types could be part of ctypes. After all ctypes knows how big a long is on all platforms, and it knows that a uint32_t is the same on all platforms, it could conceivably know how big an off_t or an ino_t is too. > In other words, POSIX talks about APIs and ctypes deals with ABIs. > > http://pypi.python.org/pypi/ctypes_configure/0.1 helps with the problem, > and is a bit more accessible than gccxml. I haven't seen that before - looks interesting. > It is basically correct to say that using ctypes without using something > like gccxml or ctypes_configure will give you non-portable code. Well it depends on if the API is specified in types that ctypes understands. Eg, short, int, long, int32_t, uint64_t etc. A lot of interfaces are specified exactly like that and work just fine with ctypes in a portable way. I agree with you that struct dirent probably isn't one of those though! I think it would be relatively easy to implent the code I demonstrated in a portable way though... I'd do it by defining dirent as a block of memory and then for the first run, find a known filename in the block, establishing the offset of the name field since that is all we are interested in for the OPs problem. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ISF (Computer Scientists without Frontiers, Mon Jun 15 18:05:17 2009 From: ISF (Computer Scientists without Frontiers, (ISF (Computer Scientists without Frontiers,) Date: Mon, 15 Jun 2009 15:05:17 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <6101ec18-168f-4449-81ee-6f6808e22367@v35g2000pro.googlegroups.com> Hello All, good readings can be found among free e-books too: I'd like to share with you feeds to following free directories http://feeds2.feedburner.com/E-booksDirectory http://www.freetechbooks.com/rss.php warmest regards, Aldo From rick.arnett at gmail.com Mon Jun 15 18:07:22 2009 From: rick.arnett at gmail.com (the_ricka) Date: Mon, 15 Jun 2009 15:07:22 -0700 (PDT) Subject: Why is os.stat so slow? Message-ID: <9b2b9630-9895-447a-a147-8098a9efdf21@w3g2000yqf.googlegroups.com> Hi all, Fairly new to python but have programmed in other languages (C, Java) before. I was experimenting with a python program that needed to take a directory tree and get the total disk usage of every file (and subfolder) underneath it. This solution also has to run on Windows Server 2003 for work and it is accessing a NAS shared via CIFS. A sample folder I'm using contains about 26,000 subfolders and 435,000 files. The original solution I came up with was elegant, but extremely slow (compared to doing a right click in Windowsexplorer on the folder tree and clicking properties). It looked something like this: import os folder = r'Z:\foldertree' folder_size = 0 for (path, dirs, files) in os.walk(folder): for file in files: folder_size += os.path.getsize(os.path.join(path,file)) I profiled the above code and os.stat was taking up roughly 90% of the time. After digging around, I found some code in another post to use win32api to use API calls to speed this up (if you are interested, search for supper fast walk, yes super is misspelled). To my surprise, the average time is now about 1/7th of what it used to be. I believe the problem is that my simple solution had to call os.stat twice (once in the os.walk and once by me calling os.path.getsize) for every file and folder in the tree. I understand that os.stat can work on any OS. However, the expense should not be that dramatic of a difference (in my opinion). Is there an OS agnostic way to get this functionality to work faster? Also, if I wanted to port this to Linux or some other OS, is os.stat as expensive? If so, are there other libraries (like win32api) to assist in doing these operations faster? From thudfoo at opensuse.us Mon Jun 15 18:23:09 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 15 Jun 2009 15:23:09 -0700 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <4A357F1F.6060407@mrabarnett.plus.com> Message-ID: <3d881a310906151523v12f07101l7192c083c9f5e3fc@mail.gmail.com> On 6/15/09, Terry Reedy wrote: > Phil Runciman wrote: > > > > > Gain access to one of the IEEE or ACM web sites and their resources. > > I used to sneak into my local university library before the 'Net to > > read this stuff. > > > > Beyond that I check up on the reading lists for CS students from time > > to time. This often throws up real gems and prevents me from being > > blind-sided. > > > > For those who are not rich, MIT has put a lot of courseware on the web, > including in particular, CS, for free. And there is lots more put up by > professors and departments elsewhere. There are free language manuals and > interpreters/compilers for those who want to stretch their brain that way. > > The MIT Online Course Ware starts here: http://ocw.mit.edu/OcwWeb/web/help/start/index.htm I downloaded the Mathematics for Computer Science course: ~9MB. Looks to be excellent! Do you have links to share for the other materials? From mk.fraggod at gmail.com Mon Jun 15 19:31:53 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 05:31:53 +0600 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <20090616053154.1379a057@coercion> On Mon, 15 Jun 2009 15:35:04 -0400 Terry Reedy wrote: > Christian Heimes wrote: > > Terry Reedy wrote: > >> You did not specify version. In Python3, os.walk has become a generater > >> function. So, to answer your question, use 3.1. > > > > I'm sorry to inform you that Python 3.x still returns a list, not a > > generator. > > >>> type(os.walk('.')) > > > However, it is a generator of directory tuples that include a filename > list produced by listdir, rather than a generator of filenames > themselves, as I was thinking. I wish listdir had been changed in 3.0 > along with map, filter, and range, but I made no effort and hence cannot > complain. Why? We have itertools.imap, itertools.ifilter and xrange already. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From songkai.sk at gmail.com Mon Jun 15 19:36:21 2009 From: songkai.sk at gmail.com (kai) Date: Mon, 15 Jun 2009 16:36:21 -0700 (PDT) Subject: Build problem on Solaris 9 Message-ID: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> Hi All, When I run make after successively running ./configure, I got the following Error message: ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl /usr/bin/env: No such file or directory make: *** [Python/Python-ast.c] Error 127 /usr/bin/env deos exist.... Can anyone help me with this? Kai From castironpi at gmail.com Mon Jun 15 19:56:58 2009 From: castironpi at gmail.com (Aaron Brady) Date: Mon, 15 Jun 2009 16:56:58 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> Message-ID: On Jun 15, 11:10?am, Paul Rubin wrote: > Aaron Brady writes: > > > A real-world application of persistent data structures can be found here: > > >http://stevekrenzel.com/persistent-list > > > Jaime, thanks for the link. ?I contacted its author. > > You might also look atwww.couchdb.org. I'm not much for the interface. But the back end might match what I'm doing. From ldo at geek-central.gen.new_zealand Mon Jun 15 20:57:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Jun 2009 12:57:31 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro > wrote: > >> Perl allows just about any printable character as a quote. I tried >> alternative quotes for many years, and decided making that choice was a >> waste of brain cells. >> >> So no, using alternative quotes does not make things more readable. > > I find it odd that you consider qquoting less scalable than backslashes. Backslashes are scalable because they can be nested to any depth, without having to decide beforehand which quotes to use at which level. And yes, I do write things like this: out.write \ ( "function JSString(Str)\n" # /* returns a JavaScript string literal that evaluates to Str. */ " {\n" " var Result = \"\\\"\"\n" " for (var i = 0; i < Str.length; ++i)\n" " {\n" " var ThisCh = Str.charAt(i)\n" " if (ThisCh == \"\\\\\")\n" " {\n" " ThisCh = \"\\\\\\\\\"\n" " }\n" " else if (ThisCh == \"\\\"\")\n" " {\n" " ThisCh = \"\\\\\\\"\"\n" " }\n" " else if (ThisCh == \"\\t\")\n" " {\n" " ThisCh = \"\\\\t\"\n" " }\n" " else if (ThisCh == \"\\n\")\n" " {\n" " ThisCh = \"\\\\n\"\n" " } /*if*/\n" " Result += ThisCh\n" " } /*for*/\n" " return Result + \"\\\"\"\n" "} /*JSString*/\n" ) > I also find it odd that you dislike two visuals stutters (at the start > and end of string) so much that you'll put up with a dozen visual > stutters in the string to avoid them. Particular since my years of > Perl-bashing lead me to the opposite conclusion. I find it odd you should think so. From pavlovevidence at gmail.com Mon Jun 15 21:49:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 18:49:16 -0700 (PDT) Subject: Observer implementations References: Message-ID: On Jun 15, 5:22?pm, Tobias Weber wrote: > In article , > ?Gerhard H?ring wrote: > > > Implement it in your classes? > > No time to reinvent the wheel Hmm, observer pattern seems to be one of those things simple enough that reimplementing the wheel might actually be less work than adapting a third-party implementation. But I'll leave that decision to you. > I'd still need to know how to weakref a classmethod I can't imagine why you would need to weak reference a class method, since they usually live forever along with the class. But again, you are doing it so you would know. I can't think of an easy way to do it without metaclass programming. Unless you are trying to create a weakref to a bound classmethod. I'd say that's still pretty useless: bound classmethods only keep alive classes and classmethods, which both live forever, and bound classmethods are lightweight and hardly worth the effort. Maybe show us what you need to weak reference classmethods for and we can help you better. Carl Banks From sjmachin at lexicon.net Mon Jun 15 22:50:02 2009 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Jun 2009 19:50:02 -0700 (PDT) Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> Message-ID: <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> On Jun 16, 6:06?am, Terry Reedy wrote: > John Machin wrote: > > On Jun 15, 9:49 am, Terry Reedy wrote: > >> Poor Yorick wrote: > >>> The following code produces an error (python-2.6.2). > >> You forgot to post the error traceback. > > > The exception was IGNORED ... so no traceback. > > Yes, I forgot that > Exception TypeError: "'NoneType' object is not callable" in ?ignored > > should be parsed as > > '''Exception TypeError: "'NoneType' object is not callable" in''' [was] > ? ?ignored > > rather than read as > > Exception TypeError: "'NoneType' object is not callable" in ignored Yep, it's not the clearest message I've ever seen, and it gives no clue as to who or what is doing the ignoring. Here's a suggestion for your enhancement request: Shutdown ignored this exception: TypeError: "'NoneType' object is not callable" From steve at nospam.au Mon Jun 15 22:56:19 2009 From: steve at nospam.au (steve) Date: Tue, 16 Jun 2009 12:56:19 +1000 Subject: python tutorial Message-ID: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> I was just looking at the python tutorial, and I noticed these lines: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files "Windows makes a distinction between text and binary files; "the end-of-line characters in text files are automatically altered "slightly when data is read or written. I don't see any obvious way to at docs.python.org to get that corrected: Is there some standard procedure? Steve From deostroll at gmail.com Mon Jun 15 23:01:58 2009 From: deostroll at gmail.com (deostroll) Date: Mon, 15 Jun 2009 20:01:58 -0700 (PDT) Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> Message-ID: <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> I want to be able to parse it into python objects. Any ideas? --deostroll From ivlenin at gmail.com Mon Jun 15 23:11:18 2009 From: ivlenin at gmail.com (I V) Date: 16 Jun 2009 05:11:18 +0200 Subject: Observer implementations References: Message-ID: <4a370d56$1@news.x-privat.org> On Mon, 15 Jun 2009 15:29:34 +0200, Tobias Weber wrote: > Despite the confusion all those are useable, but I ran into the problem > that I can't register a @classmethod because weakref doesn't like them. What do you mean by weakref not liking class methods? This seems to work OK on python 2.6 class C(object): @classmethod def cm(cls): return "Class method of " + str(cls) cm = C.cm print cm() # Outputs: # Class method of w = weakref.ref(cm) print w # Outputs: # print w() # Outputs: # > print w()() # Outputs: # Class method of del cm print w # Outputs: # From pavlovevidence at gmail.com Mon Jun 15 23:58:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 20:58:47 -0700 (PDT) Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> On Jun 15, 7:56?pm, "steve" wrote: > I was just looking at the python tutorial, and I noticed these lines: > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > "Windows makes a distinction between text and binary files; > "the end-of-line characters in text files are automatically altered > "slightly when data is read or written. > > I don't see any obvious way to at docs.python.org to get that corrected: Is > there some standard procedure? What's wrong with it? Carl Banks From pavlovevidence at gmail.com Tue Jun 16 00:04:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Jun 2009 21:04:08 -0700 (PDT) Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: <639fccd8-d5a1-4bee-a2db-ccf63d7786d2@a5g2000pre.googlegroups.com> On Jun 15, 8:01?pm, deostroll wrote: > I want to be able to parse it into python objects. Any ideas? 1. If applicable, pay better attention in class. 2. Install simplejson and try to use it, then, if you still need help, come back and post your question along with your honest attempt to do it. P.S. Someone will be by to post the "How to ask smart questions" essay shortly. Carl Banks From davea at ieee.org Tue Jun 16 00:06:13 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 00:06:13 -0400 Subject: : an integer is required In-Reply-To: References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: <4A371A35.7040809@ieee.org> Ulrich Eckhardt wrote: > open() doesn't take a string as second parameter, see 'help(open)'. Instead, > it takes one of the integers which are defined as symbols in the os module, > see 'dir(os)'. > > > Where'd you get that misinformation? The second parameter to the builtin function open() is a string, such as 'r', 'wb', etc. help(open) doesn't say much in 2.6, but in 3.1, it spells it out. For 2.6, look at the non-interactive documentation, such as the chm file in Windows. Now perhaps you're referring to open() in some other module, such as os.open(). If so, it behooves you to specify that, as an unqualified open() can only refer to the one in builltin. From msdark at archlinux.cl Tue Jun 16 00:11:12 2009 From: msdark at archlinux.cl (Matias Hernandez Arellano) Date: Tue, 16 Jun 2009 00:11:12 -0400 Subject: Label (or other widget) auto refresh? Message-ID: <4A371B60.7080505@archlinux.cl> Hi list... I have a question for you.. First... sorry for my english, but i speak spanish xD.. I have a little GUI made with Glade and GtkBuilder... in his gui when i click on a button i show a dialog window.. in this dialog i put a label.. this label show some value.. this value was reading from serial port. The PC is connected to a Basic Stamp (a microcontroller), the Basic Stamp write in the serial port a binary value every time when a some sensor change.. I need to show this value in the label in the dialog window at the same time when the basic stamp write to the serial port... How can i refresh the text in the label to show the change of the value every time... instantaniely? I think in a threads, but i can't get it... Thanks a lot!!!! -- Matias Hern?ndez (Msdark) www.msdark.archlinux.cl ArchLinux-CL - WikiAdmin MSN: matiasfh at gmail.com Twitter : www.twitter.com/msdark Plurk : www.plurk.com/msdark Linux User: #445065 http://keys.gnupg.net/pks/lookup?op=get&search=0xEA3EEC672189419C From clp2 at rebertia.com Tue Jun 16 00:19:59 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Jun 2009 21:19:59 -0700 Subject: On the property function In-Reply-To: <4A364202.2050700@it.uu.se> References: <4A364202.2050700@it.uu.se> Message-ID: <50697b2c0906152119x7d30e5a1xb88175d0295de442@mail.gmail.com> On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: > Does anyone have a good example (or examples) of when "property(...)" can be > useful? Erm, when you want to create a property (i.e. computed attribute). from __future__ import division class TimeDelta(object): def __init__(self, secs): self. seconds =secs @property def minutes(self): return self.seconds/60 @property def hours(self): return self.minutes/60 @property def days(self): return self.hours/24 td = TimeDelta(55555555555) print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" Cheers, Chris -- http://blog.rebertia.com From philr at aspexconsulting.co.nz Tue Jun 16 00:26:29 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 16 Jun 2009 16:26:29 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: FWIW I actually dislike this book! Gasp... Much of the material is excellent but IBM got into the huge mess with the 360. Brooks observed failure from the inside and IMHO did a great job of it. Project managers can never rescue stuffed concepts especially if a lot of money has been spent! Such projects have momentum and roll over anyone who gets in the way. Brilliant architects are worth their weight in gold. I believe that ICL's VME/B OS began as a skunk works project.* It had such an architect. The latter was the official OS and was pretty good too. I think Warboys took over later once VME/B became official... if anyone out there knows better then please let us know and correct Wikipedia too. The Wikipedia item on VME is too sanitised for my taste. The "truth" is generally far more interesting. If the software you are developing is going to be used by many people then remaining sharp and on top of your game is so important. Do not program if you are tired or you will spend your life debugging. ;-) I stop coding at 3pm for this reason. I come right again around 10pm! Yes, despite the above, do read the book, but remember that among the content is a cautionary tale! Ooops, the above is a bit away from Python. ;-) Phil *I was told this by the leader an ICL research team, no less than Alan Sutcliffe himself... many years ago now. (c. May/June 1970) -----Original Message----- From: Roy Smith [mailto:roy at panix.com] Sent: Sunday, 14 June 2009 2:21 p.m. Subject: Re: Good books in computer science? In article , "Rhodri James" wrote: > The Mythical Man-Month (Brooks) is a must. What's amazing about this book is just how relevant it is today, 35 years after it was written. Some of the technical details have changed (how many of us still keep our project notes on microfiche?), but cross out "microfiche" and write in "wiki" and what he's saying is just as valid today. It's not about computer science. It's not really even about software engineering. It's more about general project management than anything else. In the same vein, Death March, by Ed Yourdon. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 00:29:13 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Jun 2009 04:29:13 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: On Mon, 15 Jun 2009 20:58:47 -0700, Carl Banks wrote: > On Jun 15, 7:56?pm, "steve" wrote: >> I was just looking at the python tutorial, and I noticed these lines: >> >> http://docs.python.org/tutorial/inputoutput.html#reading-and- writing-... >> >> "Windows makes a distinction between text and binary files; "the >> end-of-line characters in text files are automatically altered >> "slightly when data is read or written. >> >> I don't see any obvious way to at docs.python.org to get that >> corrected: Is there some standard procedure? > > What's wrong with it? Perhaps because it's unclear whether it is Windows, or Python, or both, which is automatically altering the data. As for getting the docs changed, you can submit a bug request at the bug tracker: http://bugs.python.org/ -- Steven From mk.fraggod at gmail.com Tue Jun 16 00:31:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 10:31:09 +0600 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: <20090616103109.4b4ee4ff@coercion> On Mon, 15 Jun 2009 20:01:58 -0700 (PDT) deostroll wrote: > I want to be able to parse it into python objects. Any ideas? JSON objects behave like python dicts (key:val pairs), so why not just use them? Both simplejson and py2.6-json (which is quite similar to the former) do just that, but if you like JS attribute-like key access model you can use it by extending the builtin dict class: import types, collections class AttrDict(dict): '''AttrDict - dict with JS-like key=attr access''' def __init__(self, *argz, **kwz): if len(argz) == 1 and not kwz and isinstance(argz[0], types.StringTypes): super(AttrDict, self).__init__(open(argz[0])) else: super(AttrDict, self).__init__(*argz, **kwz) for k,v in self.iteritems(): setattr(self, k, v) # re-construct all values via factory def __val_factory(self, val): return AttrDict(val) if isinstance(val, collections.Mapping) else val def __getattr__(self, k): return super(AttrDict, self).__getitem__(k) __getitem__ = __getattr__ def __setattr__(self, k, v): return super(AttrDict, self).__setitem__(k, self.__val_factory(v)) __setitem__ = __setattr__ if __name__ == '__main__': import json data = AttrDict(json.loads('{"host": "docs.python.org",' ' "port": 80,' ' "references": [ "collections",' ' "json",' ' "types",' ' "data model" ],' ' "see_also": { "UserDict": "similar, although' ' less flexible dict implementation." } }')) print data.references # You can always use it as a regular dict print 'port' in data print data['see_also'] # Data model propagnates itself to any sub-mappings data.see_also.new_item = dict(x=1, y=2) print data.see_also.keys() data.see_also.new_item['z'] = 3 print data.see_also.new_item.z -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From philr at aspexconsulting.co.nz Tue Jun 16 00:33:31 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 16 Jun 2009 16:33:31 +1200 Subject: FW: Good books in computer science? Message-ID: Oh dear the "latter" referred to VME/K but got lost in my editing. Sorry about that. Phil > -----Original Message----- > From: Phil Runciman > Sent: Tuesday, 16 June 2009 4:26 p.m. > To: python-list at python.org > Subject: RE: Good books in computer science? > > FWIW I actually dislike this book! Gasp... > > Much of the material is excellent but IBM got into the huge mess with > the 360. Brooks observed failure from the inside and IMHO did a great > job of it. > > Project managers can never rescue stuffed concepts especially if a > lot of money has been spent! Such projects have momentum and roll > over anyone who gets in the way. > > Brilliant architects are worth their weight in gold. I believe that > ICL's VME/B OS began as a skunk works project.* It had such an > architect. The LATTER was the official OS and was pretty good too. I > think Warboys took over later once VME/B became official... if anyone > out there knows better then please let us know and correct Wikipedia > too. The Wikipedia item on VME is too sanitised for my taste. The > "truth" is generally far more interesting. > > If the software you are developing is going to be used by many people > then remaining sharp and on top of your game is so important. Do not > program if you are tired or you will spend your life debugging. ;-) I > stop coding at 3pm for this reason. I come right again around 10pm! > > Yes, despite the above, do read the book, but remember that among the > content is a cautionary tale! > > Ooops, the above is a bit away from Python. ;-) > > > Phil > > > *I was told this by the leader an ICL research team, no less than > Alan Sutcliffe himself... many years ago now. (c. May/June 1970) > > > -----Original Message----- > From: Roy Smith [mailto:roy at panix.com] > Sent: Sunday, 14 June 2009 2:21 p.m. > Subject: Re: Good books in computer science? > > In article , > "Rhodri James" wrote: > > > The Mythical Man-Month (Brooks) is a must. > > What's amazing about this book is just how relevant it is today, 35 > years > after it was written. Some of the technical details have changed > (how many > of us still keep our project notes on microfiche?), but cross out > "microfiche" and write in "wiki" and what he's saying is just as > valid > today. It's not about computer science. It's not really even about > software engineering. It's more about general project management > than > anything else. > > In the same vein, Death March, by Ed Yourdon. From ldo at geek-central.gen.new_zealand Tue Jun 16 00:45:43 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Jun 2009 16:45:43 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In message , Piet van Oostrum wrote: > The exact time of the destruction of objects is an implementation detail > and should not be relied upon. That may be true in Java and other corporate-herd-oriented languages, but we know that dynamic languages like Perl and Python make heavy use of reference-counting wherever they can. If it's easy to satisfy yourself that the lifetime of an object will be delimited in this way, I don't see why you can't rely upon it. From girish.cfc at gmail.com Tue Jun 16 01:09:57 2009 From: girish.cfc at gmail.com (Girish) Date: Mon, 15 Jun 2009 22:09:57 -0700 (PDT) Subject: Error in reg dll Message-ID: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Hello. I am not able to register DLL generated from py2exe I have written following code to generate the DLL: ################################################################################## from distutils.core import setup import py2exe import sys # If run without args, build executables, in quiet mode. if len(sys.argv) == 1: sys.argv.append("py2exe") sys.argv.append("-q") class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "2.8.9" self.name = "DSPACE API" # a COM server dll, modules is required # interp = Target( description = "COM server module", modules = ["Dspace"], create_exe = True, ) excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs", "pywin.dialogs.list"] options = { "bundle_files": 1, "ascii": 1, # to make a smaller executable, don't include the encodings "compressed": 1, # compress the library archive "excludes": excludes, # COM stuff we don't want } setup( options = {"py2exe": options}, zipfile = None, # append zip-archive to the executable. com_server = [interp], ) #######################################END######################################## When I try to register the dll using the commant: regsve32 dspace.dll, I am getting error saying :"DLLRegisterServer in dspace.dll failed. Return code was: 0xc0000005" Please help me to solve this issue. Thanks, Girish... From mk.fraggod at gmail.com Tue Jun 16 01:12:17 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 11:12:17 +0600 Subject: Multi-Threading and KeyboardInterrupt References: <6AC49076-B62B-4FEB-BD41-9A0D5BCA3798@neu.edu> <20090613112545.2ce188af@coercion> <49905947-72ba-4bff-886e-af4f6ab7cbac@p6g2000pre.googlegroups.com> <20090615215335.4cb26673@coercion> Message-ID: <20090616111217.321e2c50@coercion> On Mon, 15 Jun 2009 15:43:13 -0400 Matt wrote: > I'm going to use the multipocessing library from here forward so I can > take advantage of multiple cores and clusters. Either one should work > for my use, since in my non-demonstration code each thread spends most > of it's time waiting for a separate non-Python subprocess (created > with subprocess.Popen) to finish anyway. (I guess Python would see > this as IO-blocking) Therefore, if you can fix my toy example with > threading, that's fine. > > DB.py, followed by a KeyboardInterrupt yields the output in a.out. I > want roughly the output in desired.out. > > What do I need to do to modify this code to get my desired output and > corresponding functionality? It would be a shame if this wasn't > possible in any pure-Python way. I don't know how complex task you have, but solving trivial IO blocks with threads or subprocesses look either like ugly hack or an overkill to me. Why not just use I/O without blocking? It's not 80s or 90s anymore, where you had to create subprocess to handle every non-synchronous task, and since the main burden will be pushed into non-py subprocesses already, why not implement controller as a nice, clean and simple single-threaded event loop? Consider this recipe: http://code.activestate.com/recipes/576759/ And if the task before you is complex indeed, involving more than just two to five child processes with a simple "while True: ..." loop, consider using twisted framework - it'll allow you to do incredible stuff with any number of sockets with just few lines of code in a clean, abstracted way. Latter would also mean that you can always replace os pipes with network sockets just by changing transport name, distributing your app to any number of machines. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From davea at ieee.org Tue Jun 16 01:30:00 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 01:30:00 -0400 Subject: python tutorial In-Reply-To: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4A372DD8.5030102@ieee.org> steve wrote: > I was just looking at the python tutorial, and I noticed these lines: > > http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files > > "Windows makes a distinction between text and binary files; > "the end-of-line characters in text files are automatically altered > "slightly when data is read or written. > > I don't see any obvious way to at docs.python.org to get that corrected: Is > there some standard procedure? > > Steve > > It's not clear from your question what you want corrected. Are you saying that the tutorial leaves out some detail? Or are you upset that reading the data gets "automatically altered" data? If it's the former, just lookup the function in the reference documentation (eg. the chm file in a Windows installation). The way to control the behavior is with the 'mode' parameter to open(). If mode has a 'b' in it, the file is considered binary, which means no translation is done. If the mode has a 'u' in it, or neither 'b' nor 'u', then some translation is done. The purpose of the translation is to let the program always use \n to mean end of line, for code that'll be portable between the various operating system conventions. Windows typically does text files with \r\n at the end of each line. Some Macs do just a \r, and Unix and Linux use a \n. One reason a programmer has to be aware of it is that he/she may be reading or writing a file from a different operating environment, for example, a script that'll be uploaded to a web server running a different OS. From hniksic at xemacs.org Tue Jun 16 03:03:43 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 16 Jun 2009 09:03:43 +0200 Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <37100677-eb9a-465f-b3f1-f1e227b591ad@w9g2000pro.googlegroups.com> <87fxe14shp.fsf@busola.homelinux.net> Message-ID: <87fxe0fynk.fsf@busola.homelinux.net> Nick Craig-Wood writes: > It can be done properly with gccxml though which converts structures > into ctypes definitions. That sounds interesting. > That said the dirent struct is specified by POSIX so if you get the > correct types for all the individual members then it should be > correct everywhere. Maybe ;-) AFAIK POSIX specifies the names and types of the members, but not their order in the structure, nor alignment. From eckhardt at satorlaser.com Tue Jun 16 03:08:12 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 16 Jun 2009 09:08:12 +0200 Subject: : an integer is required References: <3e06a699-5f6b-4ecb-8185-ff99c02fec59@w40g2000yqd.googlegroups.com> Message-ID: Dave Angel wrote: > Ulrich Eckhardt wrote: >> open() doesn't take a string as second parameter, see 'help(open)'. >> Instead, it takes one of the integers which are defined as symbols in the >> os module, see 'dir(os)'. > > [...]The second parameter to the builtin function open() is a string[...] > Now perhaps you're referring to open() in some other module, such as > os.open(). True, mixed those up, as perhaps did the OP. > an unqualified open() can only refer to the one in builltin. ...unless you explicitly imported an 'open' from somewhere else. Thanks for the correction. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From Joachim at Strombergson.com Tue Jun 16 03:12:40 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Tue, 16 Jun 2009 09:12:40 +0200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <4A3745E8.3080600@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! dads wrote: > I remember someone earlier in the thread mentioning reading source > code from good coders. I've been wanting to give this a go as it makes > perfect sense, I suppose the standard library would be a good start. > What would your recommendations be, something not too too hard, so I > don't understand. When people wants to know what (good) Python code looks like, I usually point them to Trac: http://trac.edgewall.org/ Trac is not only a good tool for development written in Python. Trac also uses Trac to develop Trac (cudos for eating your own dogfood) and Trac allows easy browsing of the source code. I still consider myself a Python-n00b and my judgement might be all wrong. But I believe that the Trac developers follows Pythonic code rules and the result a prime example of what well written, well document Python code looks like. Check for yourself though at: http://trac.edgewall.org/browser/trunk/trac - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko3RegACgkQZoPr8HT30QEMVwCgrNkOYMGFmhMYunwZqlTFpAkt He8AoOEXIC/QXkRu+sHtzIz+1+JQZp2F =o+g8 -----END PGP SIGNATURE----- From martin at v.loewis.de Tue Jun 16 03:15:33 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 16 Jun 2009 09:15:33 +0200 Subject: Build problem on Solaris 9 In-Reply-To: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> References: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> Message-ID: <4a374695$0$11163$9b622d9e@news.freenet.de> > When I run make after successively running ./configure, I got the > following Error message: > ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl > /usr/bin/env: No such file or directory > make: *** [Python/Python-ast.c] Error 127 > > /usr/bin/env deos exist.... > > Can anyone help me with this? It's probably rather that "python" does not exist on the path, which asdl_c.py requires. touch Include/Python-ast.h Python/Python-ast.c should work around. Regards, Martin From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 03:34:35 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Jun 2009 07:34:35 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > In message , Piet van Oostrum wrote: > >> The exact time of the destruction of objects is an implementation >> detail and should not be relied upon. > > That may be true in Java and other corporate-herd-oriented languages, > but we know that dynamic languages like Perl and Python make heavy use > of reference-counting wherever they can. If it's easy to satisfy > yourself that the lifetime of an object will be delimited in this way, I > don't see why you can't rely upon it. Reference counting is an implementation detail used by CPython but not IronPython or Jython. I don't know about the dozen or so other minor/new implementations, like CLPython, PyPy, Unladen Swallow or CapPython. In other words, if you want to write *Python* code rather than CPython code, don't rely on ref-counting. -- Steven From zeal_goswami at yahoo.com Tue Jun 16 04:35:41 2009 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Tue, 16 Jun 2009 14:05:41 +0530 (IST) Subject: Regarding GUI Message-ID: <736213.33022.qm@web94916.mail.in2.yahoo.com> Hi, I have a very basic question about GUI programming as i am beginner into Python. You are providing many enviroment for GUI programming in python. But could you guide me which is better or frequently used Abhishek Goswami Chennai Phone No -0996227099 Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From banibrata.dutta at gmail.com Tue Jun 16 04:46:34 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 16 Jun 2009 14:16:34 +0530 Subject: Regarding GUI In-Reply-To: <736213.33022.qm@web94916.mail.in2.yahoo.com> References: <736213.33022.qm@web94916.mail.in2.yahoo.com> Message-ID: <3de8e1f70906160146k11ad35adu131de2fd0ed5b66e@mail.gmail.com> Kindly search the archives of this mailing list... this is a fairly FAQ, and you should find a relevant thread which isn't older than 2-3 months, IIRC. In brief, you have several options, as you've probably already found, most one of the most popular is wxPython but then there are several other alternatives, and best fit depends on your specific requirements, constraints and background. On Tue, Jun 16, 2009 at 2:05 PM, abhishek goswami wrote: > Hi, > I have a very basic question about GUI programming as i am beginner into > Python. > > You are providing many enviroment for GUI programming in python. But could > you guide me > > which is better or frequently used > > > Abhishek Goswami > Chennai > Phone No -0996227099 > ------------------------------ > Bollywood news, movie reviews, film trailers and more! Click here. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From starglider101 at gmail.com Tue Jun 16 04:48:46 2009 From: starglider101 at gmail.com (Jorge) Date: Tue, 16 Jun 2009 09:48:46 +0100 Subject: Need to know if a file as only ASCII charaters Message-ID: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Hi there, I'm making a application that reads 3 party generated ASCII files, but some times the files are corrupted totally or partiality and I need to know if it's a ASCII file with *nix line terminators. In linux I can run the file command but the applications should run in windows. Any help will be great. Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Tue Jun 16 05:16:54 2009 From: koranthala at gmail.com (koranthala) Date: Tue, 16 Jun 2009 02:16:54 -0700 (PDT) Subject: On the property function References: <4A364202.2050700@it.uu.se> Message-ID: On Jun 16, 9:19?am, Chris Rebert wrote: > On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: > > Does anyone have a good example (or examples) of when "property(...)" can be > > useful? > > Erm, when you want to create a property (i.e. computed attribute). > > from __future__ import division > class TimeDelta(object): > ? ? def __init__(self, secs): > ? ? ? ? self. seconds =secs > > ? ? @property > ? ? def minutes(self): > ? ? ? ? return self.seconds/60 > > ? ? @property > ? ? def hours(self): > ? ? ? ? return self.minutes/60 > > ? ? @property > ? ? def days(self): > ? ? ? ? return self.hours/24 > > td = TimeDelta(55555555555) > print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" > > Cheers, > Chris > --http://blog.rebertia.com To add a little more, this link _ http://dirtsimple.org/2004/12/python-is-not-java.html _ might help. - Search for 'Getters and setters' and you will reach the place where property is explained more. From prasoonthegreat at gmail.com Tue Jun 16 05:32:31 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 02:32:31 -0700 (PDT) Subject: Input problem Message-ID: I am new to python....and using python 2.6 I want to know when to use raw_input( ) and when to use input( )??? According to my interpretation one should use input( ) when entering numbers etc and raw_input( ) when a string is too be entered..... Correct me if I am wrong.... Also if I want to enter two numbers 'a' and b such that while entering them through the keyboard there is a space between the two... For example: >>>Enter two numbers: .....12 15 Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? I mean how to handle spaces???/ From mjohnson at cfi.co.ug Tue Jun 16 05:32:40 2009 From: mjohnson at cfi.co.ug (Johnson Mpeirwe) Date: Tue, 16 Jun 2009 12:32:40 +0300 Subject: PSP Text Editor Message-ID: <4A3766B8.7000507@cfi.co.ug> Hi all, Does anyone know of any good Python Server Pages text editor that can provide indentation, syntax highlighting, etc.. Thank you. Regards, Johnson From lie.1296 at gmail.com Tue Jun 16 06:14:13 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 10:14:13 GMT Subject: On the property function In-Reply-To: References: <4A364202.2050700@it.uu.se> Message-ID: Chris Rebert wrote: > On Mon, Jun 15, 2009 at 5:43 AM, Virgil Stokes wrote: >> Does anyone have a good example (or examples) of when "property(...)" can be >> useful? > > Erm, when you want to create a property (i.e. computed attribute). > > from __future__ import division > class TimeDelta(object): > def __init__(self, secs): > self. seconds =secs > > @property > def minutes(self): > return self.seconds/60 > > @property > def hours(self): > return self.minutes/60 > > @property > def days(self): > return self.hours/24 > > td = TimeDelta(55555555555) > print td.days, "days", "=", td.hours, "hours", "=", td.minutes, "minutes" > > Cheers, > Chris Python's property is better than just that... from __future__ import division class TimeDelta(object): def __init__(self, secs): self. seconds =secs @property def minutes(self): return self.seconds @minutes.setter def minutes(self, value self.seconds = 60 * value @property def hours(self): return self.minutes/60 @hours.setter def hours(self, value): self.minutes = 60 * value @property def days(self): return self.hours/24 @days.setter def days(self, value): self.hours = 24 * value From bearophileHUGS at lycos.com Tue Jun 16 06:16:15 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 16 Jun 2009 03:16:15 -0700 (PDT) Subject: Input problem References: Message-ID: <87eb235f-83a8-401d-845a-1237530ed959@h18g2000yqj.googlegroups.com> Prasoon: > I am new to python....and using python 2.6 > I want to know when to use raw_input( ) and when to use input( )??? I think it's better to always use raw_input(), and then convert the string to the data to work on. Once in a while you may want to use input() to input expressions (like formulas) in your program in a quick, simple and unsafe way... In Python3+ they have removed input() and they have renamed raw_input () as input(). You can have the functionality of 2.x input() with eval (input()). (I think Python3 developers have taken the right choices here). Bye, bearophile From bieffe62 at gmail.com Tue Jun 16 06:34:02 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 16 Jun 2009 03:34:02 -0700 (PDT) Subject: Input problem References: Message-ID: On 16 Giu, 11:32, Prasoon wrote: > I am new to python....and using python 2.6 > I want to know when to use raw_input( ) and when to use input( )??? > > According to my interpretation one should use input( ) when entering > numbers etc and > raw_input( ) when a string is too be entered..... > > Correct me if I am wrong.... > You should almost always use raw_input and write your own code to validate the input and convert it. input (wich is roughly equivalent of veval (raw:_input()) is officially considered a Bad Choice and as such has been changed in Python 3.x ( that is, python 3.x 'input' is equivalent to python 2.x raw_input ). P.S : if you are new to python and don't expect to use external libraries for the next months (one year?) you might consider to start directly with python 3.x. > Also if I want to enter two numbers 'a' and b such that while entering > them through the keyboard > there is a space between the two... > > For example:>>>Enter two numbers: > > ?.....12 15 > > Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? > > I mean how to handle spaces???/ For instance: map( int, raw_input.split() ) splits the input string using blanks as separator, then try to convert each piece in an integer and returns a list of integer. Of course if the input string is not a list of integer you get an exception. You could also do: a, b = map( int, raw_input.split() ) but in this case you get an exception also if the input strings cobntains less or more than two integers. Ciao ----- FB From sanal.vikram at gmail.com Tue Jun 16 07:30:02 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Tue, 16 Jun 2009 04:30:02 -0700 (PDT) Subject: how to stop a function execution like... Message-ID: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Is there any built-in function to stop execution of a function similar to stop the program execution by sys.exit? In the example below, I want to skip statement 2... if the 'if' condition is satisfied. Don't advice me to put statement 2 in 'else' block. That's not my intention. May be this a simple task. Sorry to say I'm novice in Python, gentlemen... def funct : if (.....) : statement 1 statement 2 From prasoonthegreat at gmail.com Tue Jun 16 07:36:07 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 04:36:07 -0700 (PDT) Subject: Input problem References: Message-ID: On Jun 16, 3:34?pm, Francesco Bochicchio wrote: > On 16 Giu, 11:32, Prasoon wrote:> I am new to python....and using python 2.6 > > I want to know when to use raw_input( ) and when to use input( )??? > > > According to my interpretation one should use input( ) when entering > > numbers etc and > > raw_input( ) when a string is too be entered..... > > > Correct me if I am wrong.... > > You should almost always use raw_input and write your own code to > validate the > input and convert it. input (wich is roughly equivalent of veval > (raw:_input()) > is officially considered a Bad Choice and as such has been changed in > Python 3.x > ( that is, python 3.x 'input' is equivalent to python 2.x raw_input ). > > P.S : if you are new to python and don't expect to use external > libraries for the next > months (one year?) you might consider to start directly with python > 3.x. > > > Also if I want to enter two numbers 'a' and b such that while entering > > them through the keyboard > > there is a space between the two... > > > For example:>>>Enter two numbers: > > > ?.....12 15 > > > Can I use input( ) such that 12 gets accepted in 'a' and 15 in 'b'???? > > > I mean how to handle spaces???/ > > For instance: map( int, raw_input.split() ) splits the > input string using blanks as separator, then try to convert each piece > in an integer > and returns a list of integer. Of course if the input string is not a > list of integer > you get an exception. > > You could also do: > > a, b = ?map( int, raw_input.split() ) > > but in this case you get an exception also if the input strings > cobntains less or more than two integers. > > Ciao > ----- > FB I think you meant a, b = map( int, raw_input().split() ) Prasoon From aaron.watters at gmail.com Tue Jun 16 07:44:32 2009 From: aaron.watters at gmail.com (Aaron Watters) Date: Tue, 16 Jun 2009 04:44:32 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> Message-ID: <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> On Jun 14, 4:47 pm, dads wrote: > I'm wanting to purchase some of the titles that have been raised in > this thread. When I look they are very expensive books which is > understandable. Do you think getting earlier editions that are cheaper > is a daft thing or should I fork out the extra ?10-?30 to get the > latest edition? This is the best book ever written on computer science and the first edition is free. http://www.math.upenn.edu/~wilf/AlgComp3.html -- Aaron Watters http://aaron.oirt.rutgers.edu/myapp/amcharts/doc === less is more. From deets at nospam.web.de Tue Jun 16 07:45:16 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Jun 2009 13:45:16 +0200 Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Message-ID: <79penvF1qrnigU1@mid.uni-berlin.de> Gaudha wrote: > Is there any built-in function to stop execution of a function similar > to stop the program execution by sys.exit? > In the example below, I want to skip statement 2... if the 'if' > condition is satisfied. > Don't advice me to put statement 2 in 'else' block. That's not my > intention. Why not? It's from all you tell us perfectly the right thing to do. > May be this a simple task. Sorry to say I'm novice in Python, > gentlemen... > > def funct : > if (.....) : statement 1 > statement 2 def funct(): if ...: statement 1 return statement 2 would also work. But it is not really "better" than using else. Diez From prasoonthegreat at gmail.com Tue Jun 16 07:49:32 2009 From: prasoonthegreat at gmail.com (Prasoon) Date: Tue, 16 Jun 2009 04:49:32 -0700 (PDT) Subject: Input problem References: Message-ID: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> What is the difference between z=int(raw_input()) and z=eval(raw_input())????(I thought them to be the same in case of integers) I mean when an integer is entered in that case are they same and when an integer in not entered,in that case how are they different????? From sanal.vikram at gmail.com Tue Jun 16 08:22:06 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Tue, 16 Jun 2009 05:22:06 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> Message-ID: <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> On Jun 16, 4:45?pm, "Diez B. Roggisch" wrote: > Gaudha wrote: > > Is there any built-in function to stop execution of a function similar > > to stop the program execution by sys.exit? > > In the example below, I want to skip statement 2... if the 'if' > > condition is satisfied. > > Don't advice me to put statement 2 in 'else' block. That's not my > > intention. > > Why not? It's from all you tell us perfectly the right thing to do. > > > May be this a simple task. Sorry to say I'm novice in Python, > > gentlemen... > > > def funct : > > ? ? if (.....) : statement 1 > > ? ? statement 2 > > def funct(): > ? ? if ...: > ? ? ? ?statement 1 > ? ? ? ?return > ? ? statement 2 > > would also work. But it is not really "better" than using else. > > Diez I considered 'return' as meant only for returning any value. Thank you sir... From phil at riverbankcomputing.com Tue Jun 16 08:28:53 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 16 Jun 2009 13:28:53 +0100 Subject: SIP v4.8.1 Released Message-ID: <25d841a7520e2a394970782902ef5892@localhost> SIP v4.8.1 has been released and can be downloaded from http://www.riverbankcomputing.com/software/sip/. SIP is a tool for generating Python modules that wrap C or C++ libraries. It is similar to SWIG. It is used to generate PyQt and PyKDE. SIP is licensed under the Python License and runs on Windows, UNIX, Linux and MacOS/X. SIP requires Python v2.3 or later. The main focus of this release is support for Python v3. Other features of SIP include: - extension modules are implemented as a single binary .pyd or .so file (no Python stubs) - support for Python new-style classes - the ability to specify the super-type and meta-type used to wrap instances - generated modules are quick to import, even for large libraries - thread support - the ability to re-implement C++ abstract and virtual methods in Python - the ability to define Python classes that derive from abstract C++ classes - the ability to spread a class hierarchy across multiple Python modules - support for C++ namespaces - support for C++ exceptions - support for C++ operators - an extensible build system written in Python that supports over 50 platform/compiler combinations - the generation of API files for IDEs that support autocompletion and call tips. From lukepadawan at gmail.com Tue Jun 16 08:48:41 2009 From: lukepadawan at gmail.com (Lucas P Melo) Date: Tue, 16 Jun 2009 09:48:41 -0300 Subject: Tool for browsing python code Message-ID: <4A3794A9.5080309@gmail.com> Is there any tool for browsing python code? (I'm having a hard time trying to figure this out) Anything like cscope with vim would be great. From stef.mientki at gmail.com Tue Jun 16 08:54:08 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 14:54:08 +0200 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: <4A3795F0.3020009@gmail.com> Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time > trying to figure this out) > Anything like cscope with vim would be great. maybe a good IDE like PyScripter would do ? cheers, Stef From banibrata.dutta at gmail.com Tue Jun 16 08:55:00 2009 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Tue, 16 Jun 2009 18:25:00 +0530 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> On Tue, Jun 16, 2009 at 6:18 PM, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time trying > to figure this out) > Anything like cscope with vim would be great. > -- > http://mail.python.org/mailman/listinfo/python-list > If you are not averse to GUI's, there are lot of options... IDLE, PyScripter, BOA, PyDev(Eclipse)... not sure if there are any "curses" base TUI's (!) for Python. -- regards, Banibrata http://www.linkedin.com/in/bdutta -------------- next part -------------- An HTML attachment was scrubbed... URL: From pdpinheiro at gmail.com Tue Jun 16 08:55:35 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 16 Jun 2009 05:55:35 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> Message-ID: On Jun 16, 12:45?pm, "Diez B. Roggisch" wrote: > Gaudha wrote: > > Is there any built-in function to stop execution of a function similar > > to stop the program execution by sys.exit? > > In the example below, I want to skip statement 2... if the 'if' > > condition is satisfied. > > Don't advice me to put statement 2 in 'else' block. That's not my > > intention. > > Why not? It's from all you tell us perfectly the right thing to do. > If I understood his post correctly, it's because he really wants to exit the function early. If that is the case, in his real situation rather than the tiny example he posted, using the else clause would translate into: def funct(params): if a: something else: rest of the function goes here and it goes on for a while so you just burnt through an indentation level needlessly Now we can have a nice philosophical discussion about how using the else version makes the execution outline more obvious :) From phil at riverbankcomputing.com Tue Jun 16 09:09:33 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 16 Jun 2009 14:09:33 +0100 Subject: PyQt v4.5.1 Released (Python bindings for Qt) Message-ID: PyQt v4.5.1 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/. PyQt is a comprehensive set of bindings for the Qt application and UI framework from Nokia. It supports the same platforms as Qt (Windows, Linux and MacOS/X). The highlights of this release include: - support for Python v3 - support for Qt v4.5 - a new Pythonic API for connecting signals and slots that doesn't require any knowledge of C++ data types - support for the GTK+ theme engine. Windows installers are provided for the GPL version of PyQt which contains everything needed for PyQt development (including Qt, Qt Designer and QScintilla) except Python itself. PyQt v4 is implemented as a set of 18 extension modules containing over 400 classes and over 6,000 functions and methods. QtCore The non-GUI infrastructure including event loops, threads, i18n, Unicode, signals and slots, user and application settings, mapped files and shared memory. QtDesigner A set of classes that allow the Qt Designer GUI design tool to be extended with PyQt. QtGui A rich collection of GUI widgets. QtHelp A set of classes for creating and viewing searchable documentation and being able to integrate online help with PyQt applications. It includes the C++ port of the Lucene text search engine. QtNetwork A set of classes to support TCP and UDP socket programming and higher level protocols (eg. HTTP, SSL). QtOpenGL A set of classes that allows PyOpenGL to render onto Qt widgets. QtScript A set of classes that implements a JavaScript interpreter. Python objects may be exposed in the interpreter as JavaScript objects. QtScriptTools A debugger for the JavaScript interpreter. QtSql A set of classes that implement SQL data models and interfaces to industry standard databases. The Windows installers include support for SQLite, MySQL, PostgreSQL and ODBC. QtSvg A set of classes to render SVG files onto Qt widgets. QtTest A set of classes to automate unit testing of PyQt applications and GUIs. QtWebKit This implements a web browser engine based on the WebKit engine used by Apple's Safari browser. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages. QtXML A set of classes that implement DOM and SAX parsers. QtXMLPatterns A set of classes that implement XQuery and XPath support for XML and custom data models. QtAssistant A set of classes that enables the Qt Assistant online help browser to be integrated with an application. QAxContainer A set of classes for Windows that allows the integration of ActiveX controls and COM objects. phonon A cross-platform multimedia framework that enables the use of audio and video content in PyQt applications. DirectX is used as the Windows backend, QuickTime as the MacOS/X backend, and GStreamer as the Linux backend. DBus PyQt includes dbus.mainloop.qt that allows the Qt event loop to be used with the standard DBus Python bindings. PyQt includes the pyuic4 utility which generates Python code to implement user interfaces created with Qt Designer in the same way that the uic utility generates C++ code. It is also able to load Designer XML files dynamically. PyQt is available under the GPL and a commercial license. Unlike Qt, PyQt is not available under the LGPL. The commercial PyQt license allows GPL applications to be relicensed at any time. From davea at ieee.org Tue Jun 16 09:17:42 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 09:17:42 -0400 Subject: Need to know if a file as only ASCII charaters In-Reply-To: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A379B76.9060801@ieee.org> Jorge wrote: > Hi there, > I'm making a application that reads 3 party generated ASCII files, but some > times > the files are corrupted totally or partiality and I need to know if it's a > ASCII file with *nix line terminators. > In linux I can run the file command but the applications should run in > windows. > > Any help will be great. > > Thank you in advance. > > So, which is the assignment: 1) determine if a file has non-ASCII characters 2) determine whether the line-endings are crlf or just lf In the former case, look at translating the file contents to Unicode, specifying ASCII as source. If it fails, you have non-ASCII In the latter case, investigate the 'u' attribute of the mode parameter in the open() function. You also need to ask yourself whether you're doing a validation of the file, or doing a "best guess" like the file command. From davea at ieee.org Tue Jun 16 09:29:28 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 09:29:28 -0400 Subject: how to stop a function execution like... In-Reply-To: <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> <79penvF1qrnigU1@mid.uni-berlin.de> <7346cdce-a248-41f8-b34a-127e66aaa6d5@j9g2000prh.googlegroups.com> Message-ID: <4A379E38.3080200@ieee.org> Gaudha wrote: > On Jun 16, 4:45 pm, "Diez B. Roggisch" wrote: > >> Gaudha wrote: >> >>> Is there any built-in function to stop execution of a function similar >>> to stop the program execution by sys.exit? >>> In the example below, I want to skip statement 2... if the 'if' >>> condition is satisfied. >>> Don't advice me to put statement 2 in 'else' block. That's not my >>> intention. >>> >> Why not? It's from all you tell us perfectly the right thing to do. >> >> >>> May be this a simple task. Sorry to say I'm novice in Python, >>> gentlemen... >>> >>> def funct : >>> if (.....) : statement 1 >>> statement 2 >>> >> def funct(): >> if ...: >> statement 1 >> return >> statement 2 >> >> would also work. But it is not really "better" than using else. >> >> Diez >> > > I considered 'return' as meant only for returning any value. Thank you > sir... > > return with no arguments will return a value of None, same as falling off the end of the function. That can be important to know, as the caller can therefore test for None. From jsanga at cox.net Tue Jun 16 09:43:55 2009 From: jsanga at cox.net (mzdude) Date: Tue, 16 Jun 2009 06:43:55 -0700 (PDT) Subject: how to stop a function execution like... References: <5270b46d-9f47-457f-ad96-5b794f42b583@r31g2000prh.googlegroups.com> Message-ID: <8c2b6de8-60a1-49b7-8a69-622b9849856a@g15g2000pra.googlegroups.com> On Jun 16, 7:30?am, Gaudha wrote: > Is there any built-in function to stop execution of a function similar > to stop the program execution by sys.exit? > In the example below, I want to skip statement 2... if the 'if' > condition is satisfied. > Don't advice me to put statement 2 in 'else' block. That's not my > intention. > May be this a simple task. Sorry to say I'm novice in Python, > gentlemen... > > def funct : > ? ? if (.....) : statement 1 > ? ? statement 2 sys.exit is a pretty harsh way to stop execution. It usually means unable to continue. There is nothing that stops you from putting that in a function. Another possiblity would be def funct : if( .... ) : statement 1 raise UserWarning, "precondition X in funct not met" statement 2 ... statement n Check out the try / except docs. From mcfletch at vrplumber.com Tue Jun 16 09:53:21 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 16 Jun 2009 09:53:21 -0400 Subject: Observer implementations In-Reply-To: References: Message-ID: <4A37A3D1.7050901@vrplumber.com> Tobias Weber wrote: ... > No time to reinvent the wheel > > I'd still need to know how to weakref a classmethod > See PyDispatcher for code to do this. PyDispatcher, at least, is not abandoned, it would be more accurate to say "finished". I use it in OpenGLContext (extensively), but I haven't had to change anything in a rather long time. It pretty much just works. Enjoy, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From castironpi at gmail.com Tue Jun 16 09:57:13 2009 From: castironpi at gmail.com (Aaron Brady) Date: Tue, 16 Jun 2009 06:57:13 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> Message-ID: <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> On Jun 15, 4:56?pm, Aaron Brady wrote: > On Jun 15, 11:10?am, Paul Rubin wrote: > > > Aaron Brady writes: > > > > A real-world application of persistent data structures can be found here: > > > >http://stevekrenzel.com/persistent-list > > > > Jaime, thanks for the link. ?I contacted its author. > > > You might also look atwww.couchdb.org. > > I'm not much for the interface. ?But the back end might match what I'm > doing. Making the charitable interpretation that this was the extent of c-l- py's support and enthusiasm for my idea, I will now go into mourning. Death occurred at oh-eight-hundred. Rest in peace, support & enthusiasm. From pdpinheiro at gmail.com Tue Jun 16 10:17:27 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 16 Jun 2009 07:17:27 -0700 (PDT) Subject: Need to know if a file as only ASCII charaters References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <639ae03a-3808-422e-acbf-97b0c4eb9bb7@e21g2000yqb.googlegroups.com> On Jun 16, 2:17?pm, Dave Angel wrote: > Jorge wrote: > > Hi there, > > I'm making ?a application that reads 3 party generated ASCII files, but some > > times > > the files are corrupted totally or partiality and I need to know if it's a > > ASCII file with *nix line terminators. > > In linux I can run the file command but the applications should run in > > windows. > > > Any help will be great. > > > Thank you in advance. > > So, which is the assignment: > ? ?1) determine if a file has non-ASCII characters > ? ?2) determine whether the line-endings are crlf or just lf > > In the former case, look at translating the file contents to Unicode, > specifying ASCII as source. ?If it fails, you have non-ASCII > In the latter case, investigate the 'u' attribute of the mode parameter > in the open() function. > > You also need to ask yourself whether you're doing a validation of the > file, or doing a "best guess" like the file command. >From your requisites, you're already assuming something that _should_ be ASCII, so it's easiest to check for ASCIIness at the binary level: Open the file as binary Loop at the bytes exit with error upon reading a byte outside the printable range (32-126 decimal) or any of a number of lower-range exceptions (\n, \t -- not \r since you want UNIX-style linefeeds) exit with success if the loop ended cleanly This supposes you're dealing strictly with ASCII, and not a full 8 bit codepage, of course. From shuantsu at gmail.com Tue Jun 16 10:20:00 2009 From: shuantsu at gmail.com (Filipe Teixeira) Date: Tue, 16 Jun 2009 07:20:00 -0700 (PDT) Subject: simple GUI for my application? Message-ID: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Hi, I'm really struggling to find the best GUI to make a simple application. I'm doing a program to load all the ini files in the current folder, or the folder that the user chooses and list the specifics entries in it. So, the program would be like this: Som tabs here like: ( Load | Edit | Options) In the [ Load ] tab: A folder tree in the left, and two labels or edit boxes showing some specific entries in the ini file. In the [ Edit ] tab: really straight-forward, Edit boxes of the entries so the user can edit in the [ options ] tab: More edits to specifie the default folder, etc. Basically I will use a lot of edit boxes and some tabs, and a folder tree, any tips so I can search in the right place? From usernet at ilthio.net Tue Jun 16 10:23:54 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 16 Jun 2009 14:23:54 GMT Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <_VNZl.32463$yr3.10126@nlpi068.nbdc.sbc.com> On 2009-06-16, Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. http://www.python.org/doc/faq/gui/ From HeinTest at web.de Tue Jun 16 10:41:09 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 16:41:09 +0200 Subject: Funny xmlrpc / linux problem Message-ID: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Hello, I found a timing problem while playing with the xmlrpx stuff. I created a very simple server, running on a network node on windows. The client runs on windows or linux. It runs a very simple test function on the server which just echos a passed string. The trip time is beeing measured. When I use a 1024 char test string I get a trip time in the 10-20ms range on windows and linux. But for small arguments the trip time explodes - why on earth ?! May be this problem is here off topic and tcp/ip stack related. Here is the very very simply test server: #!/usr/bin/python # -*- coding: cp1250 -*- # xmlrpc test server import SimpleXMLRPCServer import xmlrpclib import time # the test function - justs echos the argument def RunTest(buffer): return buffer print "Starting RPC Server..." # Create server server = SimpleXMLRPCServer.SimpleXMLRPCServer(("node01", 10000)) server.register_function(RunTest) # Run the server's main loop server.serve_forever() This is the test client: #!/usr/bin/python # -*- coding: cp1250 -*- # Test for Roundtrip Time xmlrpc calls import SimpleXMLRPCServer import xmlrpclib import datetime print "started..." s = xmlrpclib.ServerProxy('http://laptvm:10000') # place here your server address for scale in (100240, 10240, 1024, 512, 256, 128, 64, 32, 16, 10, 1): print "Checking with", scale buffer = "0123456789" * scale now = datetime.datetime.now() for i in range(10): res = s.RunTest(buffer) if buffer != res: print "data error" later = datetime.datetime.now() dt = later - now print "time for 10 loops: %f" % (dt.seconds + (0.000001 * dt.microseconds)) Some results from my tests here: started... Checking with 100240 time for 10 loops: 3.282000 Checking with 10240 time for 10 loops: 0.360000 Checking with 1024 time for 10 loops: 0.078000 Checking with 512 time for 10 loops: 0.047000 Checking with 256 time for 10 loops: 0.046000 Checking with 128 time for 10 loops: 0.047000 Checking with 64 time for 10 loops: 1.985000 ' Whats this ?! - smaler packets, more time ?! Checking with 32 time for 10 loops: 2.000000 Checking with 16 time for 10 loops: 2.000000 Checking with 10 time for 10 loops: 2.000000 Checking with 1 time for 10 loops: 2.000000 Tanks a lot, Hans From dcm6293 at rit.edu Tue Jun 16 10:42:08 2009 From: dcm6293 at rit.edu (Daniel Merboth (RIT Student)) Date: Tue, 16 Jun 2009 10:42:08 -0400 Subject: Getting a processes' name? Message-ID: <4CD74416FB9F204EA1258409610E5626AD127A@svits27.main.ad.rit.edu> Hello, My college uses a program called AccessGrid for video conferencing, and it runs through pythonw.exe. It comes with a python script to kill all processes and exit the program. The problem is, the script kills everything related to pythonw.exe, including my open scripts. I'm looking for a way to get the name of the window or the processname, or something, to differentiate between the running versions of pythonw.exe. This is critical to a script I'm writing that grabs a bunch of the computer's information, populates an HTML table with it, then uploads it to an internal webpage. The goal is to make my (and my co-worker's) job easier on AccessGrid node maintenance. We use VNC to remotely access and having a table that automatically updates when a DNS or IP changes would be an incredible asset to us. The script also includes some basic information about AccessGrid, so if a staffmember emails us a node isn't working, we can quickly diagnose and repair the problem. The scripts both overlap in getting the name of a running process. I'm also kind of teaching myself python to write this. I have coding experience in java though. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From HeinTest at web.de Tue Jun 16 10:51:57 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 16:51:57 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Small addition: While tracing the network data I found the server to be the problem, the answer to a request is beeing delayed by about 180ms - no idea why. From stef.mientki at gmail.com Tue Jun 16 10:58:05 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 16:58:05 +0200 Subject: simple GUI for my application? In-Reply-To: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <4A37B2FD.6010006@gmail.com> Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. > > I'm doing a program to load all the ini files in the current folder, > or the folder that the user chooses and list the specifics entries in > it. > > So, the program would be like this: > > Som tabs here like: > ( Load | Edit | Options) > > In the [ Load ] tab: > A folder tree in the left, and two labels or edit boxes showing some > specific entries in the ini file. > > In the [ Edit ] tab: > really straight-forward, Edit boxes of the entries so the user can > edit > > in the [ options ] tab: > More edits to specifie the default folder, etc. > > Basically I will use a lot of edit boxes and some tabs, and a folder > tree, any tips so I can search in the right place? > mayby this will do: http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html cheers, Stef From HeinTest at web.de Tue Jun 16 11:06:27 2009 From: HeinTest at web.de (=?ISO-8859-1?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 17:06:27 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37b4f3$0$3279$8e6e7893@newsreader.ewetel.de> Another addendum... while running again the server code on a linux host, the times are as expected. started... Checking with 100240 time for 10 loops: 2.844000 Checking with 10240 time for 10 loops: 0.390000 Checking with 1024 time for 10 loops: 0.078000 Checking with 512 time for 10 loops: 0.063000 Checking with 256 time for 10 loops: 0.063000 Checking with 128 time for 10 loops: 0.062000 Checking with 64 time for 10 loops: 0.063000 Checking with 32 time for 10 loops: 0.063000 Checking with 16 time for 10 loops: 0.062000 Checking with 10 time for 10 loops: 0.063000 Checking with 1 time for 10 loops: 0.063000 The problem seems to be on the windows side. Any ideas ? Thanks, greetings Hans From gnapalm at gmail.com Tue Jun 16 11:07:42 2009 From: gnapalm at gmail.com (gnapalm) Date: Tue, 16 Jun 2009 17:07:42 +0200 Subject: Python module problem under QNX Message-ID: Hello, I'm trying to solve an issue with custom Python module at QNX 6.4.0 and Python 2.5.2. I have simple Python module (A.so) written in c++ which is linked against some other c++ library (B.so) both build by autotools. On Linux all works fine with PYTHONPATH pointed to A.so directory when dynamic linker loads B.so afterwards. On QNX there is no inter-library dependency support in libtools and Python can not find symbols from B.so. I'm not using dlopen in Python module and I would like to keep it that way. What is the workaround for this issue? Thanks in advance. g. From mk.fraggod at gmail.com Tue Jun 16 11:09:09 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Tue, 16 Jun 2009 21:09:09 +0600 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> Message-ID: <20090616210909.10eb439c@coercion> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) Aaron Brady wrote: > Making the charitable interpretation that this was the extent of c-l- > py's support and enthusiasm for my idea, I will now go into mourning. > Death occurred at oh-eight-hundred. Rest in peace, support & > enthusiasm. I've read this thread from the beginning, being tempted to insert remarks about shelve module or ORMs like SQLAlchemy, but that'd be meaningless without the problem description, which I haven't seen anywhere. Is it some trick idea like "let's walk on our heads"? -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From gnapalm at gmail.com Tue Jun 16 11:19:29 2009 From: gnapalm at gmail.com (gnapalm) Date: Tue, 16 Jun 2009 17:19:29 +0200 Subject: Python so module dependency problem under QNX Message-ID: Hello, I'm trying to solve an issue with custom Python module at QNX 6.4.0 and Python 2.5.2. I have simple Python module (A.so) written in c++ which is linked against some other c++ library (B.so) both build by autotools. On Linux all works fine with PYTHONPATH pointed to A.so directory when dynamic linker loads B.so afterwards. On QNX there is no inter-library dependency support in libtools and Python can not find symbols from B.so. I'm not using dlopen in Python module and I would like to keep it that way. What is the workaround for this issue? Thanks in advance. g. From brian at sweetapp.com Tue Jun 16 11:19:36 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Tue, 16 Jun 2009 16:19:36 +0100 Subject: Funny xmlrpc / linux problem In-Reply-To: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4A37B808.1080202@sweetapp.com> Hey Hans, Try reversing the list of numbers and see if anything changes. Cheers, Brian Hans M?ller wrote: > Hello, > > I found a timing problem while playing with the xmlrpx stuff. > > I created a very simple server, running on a network node on windows. > The client runs on windows or linux. It runs a very simple test function > on the server > which just echos a passed string. The trip time is beeing measured. > When I use a 1024 char test string I get a trip time in the 10-20ms > range on windows and linux. > But for small arguments the trip time explodes - why on earth ?! > > May be this problem is here off topic and tcp/ip stack related. > > Here is the very very simply test server: > > #!/usr/bin/python > # -*- coding: cp1250 -*- > # xmlrpc test server > > import SimpleXMLRPCServer > import xmlrpclib > import time > > # the test function - justs echos the argument > def RunTest(buffer): > return buffer > > > print "Starting RPC Server..." > > # Create server > server = SimpleXMLRPCServer.SimpleXMLRPCServer(("node01", 10000)) > server.register_function(RunTest) > > # Run the server's main loop > server.serve_forever() > > > This is the test client: > > #!/usr/bin/python > # -*- coding: cp1250 -*- > # Test for Roundtrip Time xmlrpc calls > > import SimpleXMLRPCServer > import xmlrpclib > import datetime > > print "started..." > > > s = xmlrpclib.ServerProxy('http://laptvm:10000') # place here > your server address > > for scale in (100240, 10240, 1024, 512, 256, 128, 64, 32, 16, 10, 1): > print "Checking with", scale > buffer = "0123456789" * scale > now = datetime.datetime.now() > for i in range(10): > res = s.RunTest(buffer) > if buffer != res: > print "data error" > later = datetime.datetime.now() > dt = later - now > > print "time for 10 loops: %f" % (dt.seconds + (0.000001 * > dt.microseconds)) > > > > Some results from my tests here: > > started... > Checking with 100240 > time for 10 loops: 3.282000 > Checking with 10240 > time for 10 loops: 0.360000 > Checking with 1024 > time for 10 loops: 0.078000 > Checking with 512 > time for 10 loops: 0.047000 > Checking with 256 > time for 10 loops: 0.046000 > Checking with 128 > time for 10 loops: 0.047000 > Checking with 64 > time for 10 loops: 1.985000 ' Whats this ?! - smaler packets, more > time ?! > Checking with 32 > time for 10 loops: 2.000000 > Checking with 16 > time for 10 loops: 2.000000 > Checking with 10 > time for 10 loops: 2.000000 > Checking with 1 > time for 10 loops: 2.000000 > > > > Tanks a lot, > Hans From R.Brodie at rl.ac.uk Tue Jun 16 11:22:27 2009 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 16 Jun 2009 16:22:27 +0100 Subject: Funny xmlrpc / linux problem References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: "Hans M?ller" wrote in message news:4a37b18d$0$3283$8e6e7893 at newsreader.ewetel.de... > Small addition: > > While tracing the network data I found the server to be the problem, > the answer to a request is beeing delayed by about 180ms - no idea why. Nagle's algorithm: you've unintentionally produced a textbook demonstration. From darcy at druid.net Tue Jun 16 11:23:23 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 16 Jun 2009 11:23:23 -0400 Subject: Tool for browsing python code In-Reply-To: <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: <20090616112323.4dc759e2.darcy@druid.net> On Tue, 16 Jun 2009 18:25:00 +0530 Banibrata Dutta wrote: > not sure if there are any "curses" base TUI's (!) for Python. vi -- 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 gabriel.rossetti at arimaz.com Tue Jun 16 11:41:08 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Tue, 16 Jun 2009 17:41:08 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? Message-ID: <4A37BD14.5010807@arimaz.com> Hello everyone, I get an OperationalError with sqlite3 if I put the wrong column name, but shouldn't that be a ProgrammingError instead? I read PEP 249 and it says : " OperationalError Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. It must be a subclass of DatabaseError. ProgrammingError Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc. It must be a subclass of DatabaseError. " and to me it sounds more like a programming error than an operational error. Thank you, Gabriel From esnow at verio.net Tue Jun 16 11:59:40 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 08:59:40 -0700 (PDT) Subject: doctests and decorators Message-ID: Apparently there is a known issue with doctests, in which tests in functions using externally defined decorators are ignored. The recommended fix is to update the order of checks in the _from_module method of DocTestFinder in the doctest module. The bug and fix are discussed at the following URLs (and several places in this group): http://bugs.python.org/issue1108 http://mail.python.org/pipermail/python-list/2007-September/627866.html The fix implies that the inpect.getmodule function will find the module of the function object and not of the decorator. However, in 2.4 the inspect.getmodule function returns the module of the decorator. I have subsequently tested this in 2.5 and 2.6, and it also returns the module of the decorator. As such, the fix for doctests does not work in my tests. Below is the test code that I used: test1.py ++++++++++++++++++++++++++++ def decorator(function): def new_function(*args, **kwargs): return function(*args, **kwargs) return new_function test2.py ++++++++++++++++++++++++++++ import test1 import inspect class Test(object): @test1.decorator def test2(self): pass def run_tests(): test = Test() test.test2() print("Test is class, test is instance, test2 is method of Test (has decorator)") print("test's module: %s" % inspect.getmodule(test)) print("Test's module: %s" % inspect.getmodule(Test)) print("test.test2's module: %s" % inspect.getmodule (test.test2)) print("Test.test2's module: %s" % inspect.getmodule (Test.test2)) print("test.test2's func_name: %s" % test.test2.func_name) print("Test.test2's func_name: %s" % Test.test2.func_name) if __name__ == "__main__": run_tests() Here is the output that I got in 2.4, 2.5, and 2.6: Test is class, test is instance, test2 is method of Test (has decorator) test's module: Test's module: test.test2's module: Test.test2's module: test.test2's func_name: new_function Test.test2's func_name: new_function If things were working right, then the module for test.test2 would be the same as the module for test. I must be missing something, as the referenced discussion suggests a simple conclusion. Any ideas? -eric From shaibani at ymail.com Tue Jun 16 12:00:02 2009 From: shaibani at ymail.com (Ala) Date: Tue, 16 Jun 2009 17:00:02 +0100 Subject: ODE, GUI, plotter in Python Message-ID: <160620091700027246%shaibani@ymail.com> Hello everyone. I am starting on implementing a simulator using python, and since it's the first time I code in python would appreciate a few pointers: The simulator will use a coupled ODE for the most part of the simulation, I plan to use scipy. (Anything considered faster/better than scipy for solving coupled ODEs? ) I plan for a GUI program with network graph plotting. I am leaning towards using Qt for the GUI (internet forums seem to recommend it, anyone got other preferences? ) Since the GUI application will contain few buttons and a plot, I am planning to implement matplotlib into the GUI. But does anyone know if matplotlib allows for interaction with the graph plot? (say for a network simulation, allowing to right click on nodes and disable them for instance, or alter some other properties of nodes and/or links across them). I am just starting out, hence I'd rather get some advice and experiment a bit for my self as I go along. Thank you. From esnow at verio.net Tue Jun 16 12:19:03 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 09:19:03 -0700 (PDT) Subject: doctests and decorators References: Message-ID: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> On Jun 16, 9:59?am, Eric Snow wrote: > Apparently there is a known issue with doctests, in which tests in > functions using externally defined decorators are ignored. ?The > recommended fix is to update the order of checks in the _from_module > method of DocTestFinder in the doctest module. ?The bug and fix are > discussed at the following URLs (and several places in this group): > > http://bugs.python.org/issue1108http://mail.python.org/pipermail/python-list/2007-September/627866.html > > The fix implies that the inpect.getmodule function will find the > module of the function object and not of the decorator. ?However, in > 2.4 the inspect.getmodule function returns the module of the > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > also returns the module of the decorator. ?As such, the fix for > doctests does not work in my tests. ?Below is the test code that I > used: > > > > test1.py > ++++++++++++++++++++++++++++ > def decorator(function): > ? ? def new_function(*args, **kwargs): > ? ? ? ? return function(*args, **kwargs) > ? ? return new_function > > test2.py > ++++++++++++++++++++++++++++ > import test1 > import inspect > > class Test(object): > ? ? @test1.decorator > ? ? def test2(self): pass > > def run_tests(): > ? ? test = Test() > ? ? test.test2() > > ? ? print("Test is class, test is instance, test2 is method of Test > (has decorator)") > ? ? print("test's module: ? ? ? ? ?%s" % inspect.getmodule(test)) > ? ? print("Test's module: ? ? ? ? ?%s" % inspect.getmodule(Test)) > ? ? print("test.test2's module: ? ?%s" % inspect.getmodule > (test.test2)) > ? ? print("Test.test2's module: ? ?%s" % inspect.getmodule > (Test.test2)) > ? ? print("test.test2's func_name: %s" % test.test2.func_name) > ? ? print("Test.test2's func_name: %s" % Test.test2.func_name) > > if __name__ == "__main__": > ? ? run_tests() > > > > Here is the output that I got in 2.4, 2.5, and 2.6: > > Test is class, test is instance, test2 is method of Test (has > decorator) > test's module: ? ? ? ? ? > Test's module: ? ? ? ? ? > test.test2's module: ? ? > Test.test2's module: ? ? > test.test2's func_name: new_function > Test.test2's func_name: new_function > > If things were working right, then the module for test.test2 would be > the same as the module for test. ?I must be missing something, as the > referenced discussion suggests a simple conclusion. ?Any ideas? > > -eric One work-around I found is the following change in example: test1.py ++++++++++++++++++++++++++++ def decorator(function): def new_function(*args, **kwargs): return function(*args, **kwargs) new_function.__module__ = function.__module__ new_function.__doc__ = function.__doc__ new_function.__name__ = function.__name__ return new_function However, this seems pretty lame. The doctest module should be able to figure out that the docstring belongs is there in the module. -eric From lists at cheimes.de Tue Jun 16 12:31:21 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Jun 2009 18:31:21 +0200 Subject: doctests and decorators In-Reply-To: References: Message-ID: Eric Snow schrieb: > Apparently there is a known issue with doctests, in which tests in > functions using externally defined decorators are ignored. The > recommended fix is to update the order of checks in the _from_module > method of DocTestFinder in the doctest module. The bug and fix are > discussed at the following URLs (and several places in this group): > > http://bugs.python.org/issue1108 > http://mail.python.org/pipermail/python-list/2007-September/627866.html > > The fix implies that the inpect.getmodule function will find the > module of the function object and not of the decorator. However, in > 2.4 the inspect.getmodule function returns the module of the > decorator. I have subsequently tested this in 2.5 and 2.6, and it > also returns the module of the decorator. As such, the fix for > doctests does not work in my tests. Below is the test code that I > used: It's not an issue with the doctest module but with your code. You want to use functools.wraps(). http://docs.python.org/library/functools.html#functools.wraps Christian From esnow at verio.net Tue Jun 16 12:39:16 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 09:39:16 -0700 (PDT) Subject: doctests and decorators References: Message-ID: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> On Jun 16, 10:31?am, Christian Heimes wrote: > Eric Snow schrieb: > > > > > Apparently there is a known issue with doctests, in which tests in > > functions using externally defined decorators are ignored. ?The > > recommended fix is to update the order of checks in the _from_module > > method of DocTestFinder in the doctest module. ?The bug and fix are > > discussed at the following URLs (and several places in this group): > > >http://bugs.python.org/issue1108 > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > The fix implies that the inpect.getmodule function will find the > > module of the function object and not of the decorator. ?However, in > > 2.4 the inspect.getmodule function returns the module of the > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > also returns the module of the decorator. ?As such, the fix for > > doctests does not work in my tests. ?Below is the test code that I > > used: > > It's not an issue with the doctest module but with your code. You want > to use functools.wraps(). > > http://docs.python.org/library/functools.html#functools.wraps > > Christian Unfortunately, I am stuck on 2.4 for now, which does not have the functools. -eric From sjmachin at lexicon.net Tue Jun 16 12:41:03 2009 From: sjmachin at lexicon.net (John Machin) Date: Tue, 16 Jun 2009 09:41:03 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: Message-ID: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> On Jun 17, 1:41?am, Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > [snip] > and to me it sounds more like a programming error than an operational > error. How about showing us the code you used and the exact error message and traceback? From deets at nospam.web.de Tue Jun 16 12:48:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Jun 2009 18:48:47 +0200 Subject: ODE, GUI, plotter in Python References: <160620091700027246%shaibani@ymail.com> Message-ID: <79q0h0F1s3d9dU1@mid.uni-berlin.de> > you should take a look at > http://pyode.sourceforge.net/ I think he's talking about "ordinary differential equations". While these are part of physics-simulations (and the ODE-libraries' name might be a PUN), PyODE is not what the OP is after. Diez From Scott.Daniels at Acm.Org Tue Jun 16 12:49:40 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 09:49:40 -0700 Subject: Input problem In-Reply-To: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: <0rydnXBLEZ8DVqrXnZ2dnUVZ_gudnZ2d@pdx.net> Prasoon wrote: > What is the difference between > > z=int(raw_input()) and z=eval(raw_input())????(I thought them to be > the same in case of integers) Note that you can (and probably should) provide a prompt as an arg to input and raw_input. > I mean when an integer is entered in that case are they same and when > an integer in not entered,in that case how are they different????? In response to an input() call in Python 2.x, you can type sys.exit() Generally it gives your user enough rope to shoot himself in the foot. And here is the code running under 3.0 and 3.1rc2 (release candidate #2) a, b = (int(t) for t in input('Numbers: ').split()) --Scott David Daniels Scott.Daniels at Acm.Org From wiggly at wiggly.org Tue Jun 16 12:50:48 2009 From: wiggly at wiggly.org (Nigel Rantor) Date: Tue, 16 Jun 2009 17:50:48 +0100 Subject: cross platform method Re: How to get the total size of a local hard disk? In-Reply-To: <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> <9YtZl.13329$im1.1880@nlpi061.nbdc.sbc.com> Message-ID: <4A37CD68.90708@wiggly.org> Tim Harig wrote: > > This is a joke. Do not take it seriously. I do not actually suggest > anybody use this method to measure the size of their drive. I do not take any > responsibility for any damages incurred by using this method. I will laugh > at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands. > Like most jokes it's not really funny if you have to explain it. But I appreciate that you're worried that anyone who would actually follow the advice would also probably be rabidly litigious even if they were one of those rare-breed of living brain-donors. n From HeinTest at web.de Tue Jun 16 12:51:32 2009 From: HeinTest at web.de (=?ISO-8859-15?Q?Hans_M=FCller?=) Date: Tue, 16 Jun 2009 18:51:32 +0200 Subject: Funny xmlrpc / linux problem In-Reply-To: References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> Message-ID: <4a37cd94$0$3284$8e6e7893@newsreader.ewetel.de> Richard, thanks a lot for your hint, that was completely new for me. Nagle's optimisation is definitely a good idea in most cases. By the way, do you have an idea how to access the underlying socket to modify the behavier via the setsockopt function to disable Nagle's algorythm in my special case (i need speed for small packets) ? Thanks a lot Hans From lie.1296 at gmail.com Tue Jun 16 12:51:57 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 16:51:57 GMT Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Rhodri > James wrote: > >> On Mon, 15 Jun 2009 01:33:50 +0100, Lawrence D'Oliveiro >> wrote: >> >>> Perl allows just about any printable character as a quote. I tried >>> alternative quotes for many years, and decided making that choice was a >>> waste of brain cells. >>> >>> So no, using alternative quotes does not make things more readable. >> I find it odd that you consider qquoting less scalable than backslashes. > > Backslashes are scalable because they can be nested to any depth, without > having to decide beforehand which quotes to use at which level. And yes, I > do write things like this: Scalable for the computers, not the eye... >> I also find it odd that you dislike two visuals stutters (at the start >> and end of string) so much that you'll put up with a dozen visual >> stutters in the string to avoid them. Particular since my years of >> Perl-bashing lead me to the opposite conclusion. > > I find it odd you should think so. > If found it odd that you think that is more readable and scalable than this: out.write ( ''' function JSString(Str) { var Result = '\"' for (var i = 0; i < Str.length; ++i) { var ThisCh = Str.charAt(i) if (ThisCh == '\\') { ThisCh = '\\\\' } else if (ThisCh == '\"') { ThisCh = '\\\"' } else if (ThisCh == '\t') { ThisCh = '\\t' } else if (ThisCh == '\n') { ThisCh = '\\n' } /*if*/ Result += ThisCh } /*for*/ return Result + '\"' } /*JSString*/ ''' ) I might go even further: out.write ( ''' function JSString(Str) { const dq = '\"' const slash = '\\' var Result = dq for (var i = 0; i < Str.length; ++i) { var ThisCh = Str.charAt(i) if (ThisCh == slash) { ThisCh = slash + slash } else if (ThisCh == dq) { ThisCh = slash + dq } else if (ThisCh == '\t') { ThisCh = slash + 't' } else if (ThisCh == '\n') { ThisCh = slash + 'n' } /*if*/ Result += ThisCh } /*for*/ return Result + dq } /*JSString*/ ''' ) From jholloway7 at gmail.com Tue Jun 16 12:52:43 2009 From: jholloway7 at gmail.com (Joe Holloway) Date: Tue, 16 Jun 2009 11:52:43 -0500 Subject: strptime issue in multi-threaded application Message-ID: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> We recently uplifted our web application to run on Python 2.6.2. We've noticed on a couple occasions that calls into time.strptime have failed with this exception: ImportError: Failed to import _strptime because the import lockis [sic] held by another thread. I poked around the source code enough to realize that this is apparently due to time.strptime using PyImport_ImportModuleNoBlock which potentially raises an ImportError rather than waiting for the "import lock" to be released [1]. This appears to have been introduced as a workaround for other thread safety concerns [2]. Does this indicate that strptime and any other library function that uses the non-blocking import call in this fashion are not thread safe? Is there an idiomatic way of dealing with this error in multi-threaded applications? Like I mentioned, it's only happened on a couple occasions because the right conditions have to be in place, but something doesn't seem right about it. I thought I'd ask on the mailing list before going so far as to open a ticket, but feel free to direct me there if that's the appropriate place for this. Thanks, Joe [1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock [2] http://svn.python.org/view?view=rev&revision=59678 From joncle at googlemail.com Tue Jun 16 13:09:36 2009 From: joncle at googlemail.com (Jon Clements) Date: Tue, 16 Jun 2009 10:09:36 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: Message-ID: <36eb5d87-fad7-4966-a57b-305f879488d8@z9g2000yqi.googlegroups.com> On Jun 16, 4:41?pm, Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > > " ? ? ? ?OperationalError > > ? ? ? ? ? ? Exception raised for errors that are related to the > ? ? ? ? ? ? database's operation and not necessarily under the control > ? ? ? ? ? ? of the programmer, e.g. an unexpected disconnect occurs, > ? ? ? ? ? ? the data source name is not found, a transaction could not > ? ? ? ? ? ? be processed, a memory allocation error occurred during > ? ? ? ? ? ? processing, etc. ?It must be a subclass of DatabaseError. > > ? ? ? ? ProgrammingError > > ? ? ? ? ? ? Exception raised for programming errors, e.g. table not > ? ? ? ? ? ? found or already exists, syntax error in the SQL > ? ? ? ? ? ? statement, wrong number of parameters specified, etc. ?It > ? ? ? ? ? ? must be a subclass of DatabaseError. > " > > and to me it sounds more like a programming error than an operational > error. > > Thank you, > Gabriel I would agree. With v2.5.2 of Python, I'm getting OperationalError from sqlite3 and ProgrammingError from the psycopg2 (for postgres) library. (Trying to create a table that already exists, trying to 'create tabel' and trying to select from non-existant tables) I don't have time to go through code but looking at http://www.sqlite.org/c3ref/c_abort.html, it would appear that there's enough error results to distinguish between Operational and Programming exceptions. Perhaps result != SQLITE_OK raises OperationalError, or I'm looking at the wrong C spec for the version in various Python versions etc... Or perhaps there's some chosen rationale... or, perhaps, for an embedded engine, no one cares how it failed, it just did... Jon From wuerzner at gmail.com Tue Jun 16 13:11:52 2009 From: wuerzner at gmail.com (kmw) Date: Tue, 16 Jun 2009 10:11:52 -0700 (PDT) Subject: strange behavior with os.system Message-ID: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Hi, I wanted to write a simple script (in 5 minutes or so) which replaces the option '+1' given to the command 'sort' by '-k 2' and than runs 'sort' with the modified argument list. After two hours I am giving up and ask you for help. This is what I tried (please excuse the verbose code, it is due to my various efforts to understand the error): #!/usr/bin/python import sys, os, re arguments = sys.argv[0] for i in sys.argv[1:]: arguments += " " + i p = re.compile ( "(\+(\d+))" ) m = p.search ( arguments ) print type ( m ) m_list = list ( m.groups () ) print type ( m_list ) from1 = str ( m_list[0] ) to1 = "-k " + str ( int ( m_list[1] ) + 1 ) cmd1 = str ( arguments.replace ( from1, to1 ) ) print cmd1 os.system ( cmd1 ) Now, this is what I get (on three different machines with different versions of python): ./sort -F -k 2 -e Traceback (most recent call last): File "./sort", line 9, in m_list = list ( m.groups () ) AttributeError: 'NoneType' object has no attribute 'groups' Please note the unrequested output of ''. The strange thing about this all is the fact that the whole thing works as expected when typed into the interpreter. I would be glad if anyone could help. Best regards, Kay From python at mrabarnett.plus.com Tue Jun 16 13:18:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:18:49 +0100 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: <4A37D3F9.9090503@mrabarnett.plus.com> Joe Holloway wrote: > We recently uplifted our web application to run on Python 2.6.2. > We've noticed on a couple occasions that calls into time.strptime have > failed with this exception: > > ImportError: Failed to import _strptime because the import lockis > [sic] held by another thread. > > I poked around the source code enough to realize that this is > apparently due to time.strptime using PyImport_ImportModuleNoBlock > which potentially raises an ImportError rather than waiting for the > "import lock" to be released [1]. This appears to have been > introduced as a workaround for other thread safety concerns [2]. > > Does this indicate that strptime and any other library function that > uses the non-blocking import call in this fashion are not thread safe? > Is there an idiomatic way of dealing with this error in > multi-threaded applications? > > Like I mentioned, it's only happened on a couple occasions because the > right conditions have to be in place, but something doesn't seem right > about it. I thought I'd ask on the mailing list before going so far > as to open a ticket, but feel free to direct me there if that's the > appropriate place for this. > > Thanks, > Joe > > [1] http://www.python.org/doc/2.6/c-api/import.html#PyImport_ImportModuleNoBlock > [2] http://svn.python.org/view?view=rev&revision=59678 A simple workaround might be to sleep a short time and then retry. From michele.simionato at gmail.com Tue Jun 16 13:24:39 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 16 Jun 2009 10:24:39 -0700 (PDT) Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> Message-ID: <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> On Jun 16, 6:39?pm, Eric Snow wrote: > On Jun 16, 10:31?am, Christian Heimes wrote: > > > > > Eric Snow schrieb: > > > > Apparently there is a known issue with doctests, in which tests in > > > functions using externally defined decorators are ignored. ?The > > > recommended fix is to update the order of checks in the _from_module > > > method of DocTestFinder in the doctest module. ?The bug and fix are > > > discussed at the following URLs (and several places in this group): > > > >http://bugs.python.org/issue1108 > > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > > The fix implies that the inpect.getmodule function will find the > > > module of the function object and not of the decorator. ?However, in > > > 2.4 the inspect.getmodule function returns the module of the > > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > > also returns the module of the decorator. ?As such, the fix for > > > doctests does not work in my tests. ?Below is the test code that I > > > used: > > > It's not an issue with the doctest module but with your code. You want > > to use functools.wraps(). > > >http://docs.python.org/library/functools.html#functools.wraps > > > Christian > > Unfortunately, I am stuck on 2.4 for now, which does not have the > functools. > > -eric But you can always use the decorator module: http://pypi.python.org/pypi/decorator From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 13:25:19 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 10:25:19 -0700 (PDT) Subject: how to import a name from a module-path? Message-ID: I'm storing the path to functions in a database and now I'd like to get a reference so I can execute them. I looked briefly at the imp module and got very confused... Currently I'm doing this: def import_object(path): module, obj = path.rsplit('.', 1) exec "from rootpkg.%s import %s as fn" % (module, obj) return fn function = import_object('mypackage.mymodule.myfunction') this is happening in a trusted environment, so I'm not worried about malicious code. Are there more elegant ways of doing this (ie. without exec)? -- bjorn From hypertaos at gmail.com Tue Jun 16 13:27:47 2009 From: hypertaos at gmail.com (Humberto) Date: Tue, 16 Jun 2009 10:27:47 -0700 (PDT) Subject: mac text files & for line Message-ID: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Greetings. This is probably a v. basic question, but my apologies as I'm relatively new w/ this. But I am attempting to use for line to iterate through a text file, but I am working on a Mac and am getting a single block of text. I assume this is because of the Mac {CR} usage vs. line feed. Is there a programmatic way to use for line to interpret the carriage return character as a new line? Otherwise, what are the easiest ways to be able to force a replacement of the {CR} character w/ the line feed? I've attempted the method using tr, but receive an illegal byte sequence error when running the tr '\r' '\n' < file1.txt > file2.txt command on my Mac. Any help would be greatly appreciated and thanks! From python at mrabarnett.plus.com Tue Jun 16 13:29:17 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:29:17 +0100 Subject: strange behavior with os.system In-Reply-To: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: <4A37D66D.7070001@mrabarnett.plus.com> kmw wrote: > Hi, > > I wanted to write a simple script (in 5 minutes or so) which replaces > the option '+1' given to the command 'sort' by '-k 2' and than runs > 'sort' with the modified argument list. After two hours I am giving up > and ask you for help. This is what I tried (please excuse the verbose > code, it is due to my various efforts to understand the error): > > #!/usr/bin/python > import sys, os, re > arguments = sys.argv[0] > for i in sys.argv[1:]: > arguments += " " + i Shorter: arguments = " ".join(sys.argv) > p = re.compile ( "(\+(\d+))" ) This looks for a "+" followed by digits. > m = p.search ( arguments ) > print type ( m ) > m_list = list ( m.groups () ) > print type ( m_list ) > from1 = str ( m_list[0] ) > to1 = "-k " + str ( int ( m_list[1] ) + 1 ) > cmd1 = str ( arguments.replace ( from1, to1 ) ) > print cmd1 > os.system ( cmd1 ) > > Now, this is what I get (on three different machines with different > versions of python): > > > ./sort -F -k 2 -e No "+"s, so the p.search(arguments) returns None. > > Traceback (most recent call last): > File "./sort", line 9, in > m_list = list ( m.groups () ) > AttributeError: 'NoneType' object has no attribute 'groups' > > Please note the unrequested output of ''. The strange > thing about this all is the fact that the whole thing works as > expected when typed into the interpreter. I would be glad if anyone > could help. > From jeff at jmcneil.net Tue Jun 16 13:33:57 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 16 Jun 2009 10:33:57 -0700 (PDT) Subject: Funny xmlrpc / linux problem References: <4a37af05$0$3283$8e6e7893@newsreader.ewetel.de> <4a37b18d$0$3283$8e6e7893@newsreader.ewetel.de> <4a37cd94$0$3284$8e6e7893@newsreader.ewetel.de> Message-ID: <63b91f3f-c7c3-4e92-8ff1-a1c1caffae87@r33g2000yqn.googlegroups.com> On Jun 16, 12:51?pm, Hans M?ller wrote: > Richard, > > thanks a lot for your hint, that was completely new for me. > Nagle's optimisation is definitely a good idea in most cases. > > By the way, do you have an idea how to access the underlying socket to modify the behavier > via the setsockopt function to disable Nagle's algorythm in my special case (i need speed for small > packets) ? > > Thanks a lot > > Hans Something like this ought to work. SimpleXMLRPCServer uses SocketServer.TCPServer to handle all of the network-layer stuff. Also, ironically, see http://bugs.python.org/issue6192. import socket from SimpleXMLRPCServer import SimpleXMLRPCServer class MyXMLServer(SimpleXMLRPCServer): def server_bind(self): self.socket.setsockopt( socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) SimpleXMLRPCServer.server_bind(self) s = MyXMLServer(('127.0.0.1', 8080)) print s.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) HTH, Jeff From esnow at verio.net Tue Jun 16 13:36:00 2009 From: esnow at verio.net (Eric Snow) Date: Tue, 16 Jun 2009 10:36:00 -0700 (PDT) Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: On Jun 16, 11:24?am, Michele Simionato wrote: > On Jun 16, 6:39?pm, Eric Snow wrote: > > > > > On Jun 16, 10:31?am, Christian Heimes wrote: > > > > Eric Snow schrieb: > > > > > Apparently there is a known issue with doctests, in which tests in > > > > functions using externally defined decorators are ignored. ?The > > > > recommended fix is to update the order of checks in the _from_module > > > > method of DocTestFinder in the doctest module. ?The bug and fix are > > > > discussed at the following URLs (and several places in this group): > > > > >http://bugs.python.org/issue1108 > > > >http://mail.python.org/pipermail/python-list/2007-September/627866.html > > > > > The fix implies that the inpect.getmodule function will find the > > > > module of the function object and not of the decorator. ?However, in > > > > 2.4 the inspect.getmodule function returns the module of the > > > > decorator. ?I have subsequently tested this in 2.5 and 2.6, and it > > > > also returns the module of the decorator. ?As such, the fix for > > > > doctests does not work in my tests. ?Below is the test code that I > > > > used: > > > > It's not an issue with the doctest module but with your code. You want > > > to use functools.wraps(). > > > >http://docs.python.org/library/functools.html#functools.wraps > > > > Christian > > > Unfortunately, I am stuck on 2.4 for now, which does not have the > > functools. > > > -eric > > But you can always use the decorator module:http://pypi.python.org/pypi/decorator Thanks to both of you. Very helpful. So in general should decorators always hide themselves? I am guessing not, otherwise this would already be part of their behavior. Still, is it the common case to camouflage the decorator like this? If so, I would expect it to be the default behavior of decorators. -eric From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 13:39:44 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 10:39:44 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> On Jun 15, 6:56?am, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > >> i can traverse a directory using os.listdir() or os.walk(). but if a > >> directory has a very large number of files, these methods produce very > >> large objects talking a lot of memory. > > >> in other languages one can avoid generating such an object by walking a > >> directory as a liked list. for example, in c, perl or php one can use > >> opendir() and then repeatedly readdir() until getting to the end of the > >> file list. it seems this could be more efficient in some applications. > > >> is there a way to do this in python? i'm relatively new to the > >> language. i looked through the documentation and tried googling but > >> came up empty. > > > What kind of directories are those that just a list of files would > > result in a "very large" object? I don't think I have ever seen > > directories with more than a few thousand files... > > You haven't looked very hard :) > > $ pwd > /home/steve/.thumbnails/normal > $ ls | wc -l > 33956 > > And I periodically delete thumbnails, to prevent the number of files > growing to hundreds of thousands. > > Steven Not proud of this, but...: [django] www4:~/datakortet/media$ ls bfpbilder|wc -l 174197 all .jpg files between 40 and 250KB with the path stored in a database field... *sigh* Oddly enough, I'm a relieved that others have had similar folder sizes (I've been waiting for this burst to the top of my list for a while now). Bjorn From python at mrabarnett.plus.com Tue Jun 16 13:39:52 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 18:39:52 +0100 Subject: mac text files & for line In-Reply-To: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: <4A37D8E8.3050106@mrabarnett.plus.com> Humberto wrote: > Greetings. > > This is probably a v. basic question, but my apologies as I'm > relatively new w/ this. > > But I am attempting to use for line to iterate through a text > file, but I am working on a Mac and am getting a single block of text. > I assume this is because of the Mac {CR} usage vs. line feed. > > Is there a programmatic way to use for line to interpret the carriage > return character as a new line? Otherwise, what are the easiest ways > to be able to force a replacement of the {CR} character w/ the line > feed? I've attempted the method using tr, but receive an > illegal byte sequence error when running the tr '\r' '\n' < file1.txt >> file2.txt command on my Mac. > > Any help would be greatly appreciated and thanks! Open the file with mode 'U' for universal newline support ('\n', '\r' or '\r\n'). From Scott.Daniels at Acm.Org Tue Jun 16 13:42:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 10:42:58 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Dave Angel wrote: > Jorge wrote: >> Hi there, >> I'm making a application that reads 3 party generated ASCII files, >> but some >> times >> the files are corrupted totally or partiality and I need to know if >> it's a >> ASCII file with *nix line terminators. >> In linux I can run the file command but the applications should run in >> windows. >> >> Any help will be great. >> >> Thank you in advance. >> >> > So, which is the assignment: > 1) determine if a file has non-ASCII characters > 2) determine whether the line-endings are crlf or just lf > > In the former case, look at translating the file contents to Unicode, > specifying ASCII as source. If it fails, you have non-ASCII > In the latter case, investigate the 'u' attribute of the mode parameter > in the open() function. > > You also need to ask yourself whether you're doing a validation of the > file, or doing a "best guess" like the file command. > > Also, realize that ASCII is a 7-bit code, with printing characters all greater than space, and very few people use delete ('\x7F'), so you can define a function to determine if a file contains only printing ASCII and a few control characters. This one is False unless some ink would be printed. Python 3.X: def ascii_file(name, controls=b'\t\n'): ctrls = set(controls + b' ') with open(name, 'rb') as f: chars = set(f.read()) return min(chars) >= min(ctrls) ord('~') >= max(chars) ) and min(chars - ctrls) > ord(' ') Python 2.X: def ascii_file(name, controls='\t\n'): ctrls = set(controls + ' ') with open(name, 'rb') as f: chars = set(f.read()) return min(chars) >= min(ctrls) and '~' >= max(chars ) and min(chars - ctrls) > ' ' For potentially more performance (at least on 2.X), you could do min and max on the data read, and only do the set(data) if the min and max are OK. --Scott David Daniels Scott.Daniels at Acm.Org From gherron at islandtraining.com Tue Jun 16 13:43:33 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Jun 2009 10:43:33 -0700 Subject: how to import a name from a module-path? In-Reply-To: References: Message-ID: <4A37D9C5.5060800@islandtraining.com> thebjorn wrote: > I'm storing the path to functions in a database and now I'd like to > get a reference so I can execute them. > > I looked briefly at the imp module and got very confused... Currently > I'm doing this: > > def import_object(path): > module, obj = path.rsplit('.', 1) > exec "from rootpkg.%s import %s as fn" % (module, obj) > return fn > > function = import_object('mypackage.mymodule.myfunction') > > this is happening in a trusted environment, so I'm not worried about > malicious code. > > Are there more elegant ways of doing this (ie. without exec)? > Yes. Look at the __import__ builtin function, and if that's not enough functionality, look at the module names imp, which provides documentation starting with this bit: DESCRIPTION This module provides the components needed to build your own __import__ function. Both are available in Python2.x and Python3.x Gary Herron > -- bjorn > From kyosohma at gmail.com Tue Jun 16 13:58:12 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 16 Jun 2009 10:58:12 -0700 (PDT) Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> Message-ID: <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> On Jun 16, 9:20?am, Filipe Teixeira wrote: > Hi, I'm really struggling to find the best GUI to make a simple > application. > > I'm doing a program to load all the ini files in the current folder, > or the folder that the user chooses and list the specifics entries in > it. > > So, the program would be like this: > > Som tabs here like: > ( Load | Edit | Options) > > In the [ Load ] tab: > A folder tree in the left, and two labels or edit boxes showing some > specific entries in the ini file. > > In the [ Edit ] tab: > really straight-forward, Edit boxes of the entries so the user can > edit > > in the [ options ] tab: > More edits to specifie the default folder, etc. > > Basically I will use a lot of edit boxes and some tabs, and a folder > tree, any tips so I can search in the right place? wxPython has all the widgets you've described built into it. They also have a very helpful mailing list. However, you should try the various toolkits and see which one makes the most sense to you. When I was first looking at GUIs, I tried Tkinter first. But it just couldn't replicate the stupid UIs I needed to reimplement, so I went with wxPython. I've heard good things about pyQT. If you want the ultimate look-and-feel for Windows, you should go with IronPython. - Mike From Scott.Daniels at Acm.Org Tue Jun 16 14:09:35 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 11:09:35 -0700 Subject: doctests and decorators In-Reply-To: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> References: <7ff460ab-99f1-4290-b322-a464fd1bab66@j9g2000prh.googlegroups.com> Message-ID: Eric Snow wrote: > ... > One work-around I found is the following change in example: > test1.py > ++++++++++++++++++++++++++++ > def decorator(function): > def new_function(*args, **kwargs): > return function(*args, **kwargs) > new_function.__module__ = function.__module__ > new_function.__doc__ = function.__doc__ > new_function.__name__ = function.__name__ > return new_function > > However, this seems pretty lame. The doctest module should be able to > figure out that the docstring belongs is there in the module. would the following look better? import functools ... def decorator(function): @functools.wraps(function) def new_function(*args, **kwargs): return function(*args, **kwargs) return new_function --Scott David Daniels Scott.Daniels at Acm.Org From norseman at hughes.net Tue Jun 16 14:12:14 2009 From: norseman at hughes.net (norseman) Date: Tue, 16 Jun 2009 11:12:14 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A37E07E.60709@hughes.net> Scott David Daniels wrote: > Dave Angel wrote: >> Jorge wrote: >>> Hi there, >>> I'm making a application that reads 3 party generated ASCII files, >>> but some >>> times >>> the files are corrupted totally or partiality and I need to know if >>> it's a >>> ASCII file with *nix line terminators. >>> In linux I can run the file command but the applications should run in >>> windows. you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) combination. If present you have Microsoft compatibility. If not you don't. If you think High Bits might be part of the corruption, filter each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) then check for the \x0D \x0A combination. Run the test on a known text setup. Intel uses one order and the SUN and the internet another. The BIG/Little ending confuses many. Intel reverses the order of multibyte numerics. Thus - Small machine has big ego or largest byte value last. Big Ending. Big machine has small ego. Little Ending. Some coders get the 0D0A backwards, some don't. You might want to test both. (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending Intel stores them (2^8)(2^16)(2^24)(2^32) big ending SUN/Internet stores them in correct math order. Python will use \r\n (0D0A) and \n\r (0A0D) correctly. HTH Steve >>> >>> Any help will be great. >>> >>> Thank you in advance. >>> >>> >> So, which is the assignment: >> 1) determine if a file has non-ASCII characters >> 2) determine whether the line-endings are crlf or just lf >> >> In the former case, look at translating the file contents to Unicode, >> specifying ASCII as source. If it fails, you have non-ASCII >> In the latter case, investigate the 'u' attribute of the mode >> parameter in the open() function. >> >> You also need to ask yourself whether you're doing a validation of the >> file, or doing a "best guess" like the file command. >> >> > Also, realize that ASCII is a 7-bit code, with printing characters all > greater than space, and very few people use delete ('\x7F'), so you > can define a function to determine if a file contains only printing > ASCII and a few control characters. This one is False unless some ink > would be printed. > > Python 3.X: > def ascii_file(name, controls=b'\t\n'): > ctrls = set(controls + b' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) ord('~') >= max(chars) > ) and min(chars - ctrls) > ord(' ') > > Python 2.X: > def ascii_file(name, controls='\t\n'): > ctrls = set(controls + ' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) and '~' >= max(chars > ) and min(chars - ctrls) > ' ' > > For potentially more performance (at least on 2.X), you could do min > and max on the data read, and only do the set(data) if the min and > max are OK. > > --Scott David Daniels > Scott.Daniels at Acm.Org From BjornSteinarFjeldPettersen at gmail.com Tue Jun 16 14:19:26 2009 From: BjornSteinarFjeldPettersen at gmail.com (thebjorn) Date: Tue, 16 Jun 2009 11:19:26 -0700 (PDT) Subject: how to import a name from a module-path? References: Message-ID: <0a546aed-c1e8-41fa-be8b-336568ad89d3@m19g2000yqk.googlegroups.com> On Jun 16, 7:43?pm, Gary Herron wrote: > thebjorn wrote: > > I'm storing the path to functions in a database and now I'd like to > > get a reference so I can execute them. > > > I looked briefly at the imp module and got very confused... ?Currently > > I'm doing this: > > > ? def import_object(path): > > ? ? ? module, obj = path.rsplit('.', 1) > > ? ? ? exec "from rootpkg.%s import %s as fn" % (module, obj) > > ? ? ? return fn > > > ? function = import_object('mypackage.mymodule.myfunction') > > > this is happening in a trusted environment, so I'm not worried about > > malicious code. > > > Are there more elegant ways of doing this (ie. without exec)? > > Yes. ?Look at the __import__ builtin function, [...] Thanks, that is much better: def import_object(path): module, obj = path.rsplit('.', 1) m = __import__(module, fromlist=['rootpkg']) return getattr(m, obj) function = import_object('mypackage.mymodule.myfunction') > Gary Herron Bjorn From http Tue Jun 16 14:22:46 2009 From: http (Paul Rubin) Date: 16 Jun 2009 11:22:46 -0700 Subject: Measuring Fractal Dimension ? References: Message-ID: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > I don't think any countable set, even a countably-infinite set, can have a > fractal dimension. It's got to be uncountably infinite, and therefore > uncomputable. I think the idea is you assume uniform continuity of the set (as expressed by a parametrized curve). That should let you approximate the fractal dimension. As for countability, remember that the reals are a separable metric space, so the value of a continuous function any dense subset of the reals (e.g. on the rationals, which are countable) completely determines the function, iirc. From usernet at ilthio.net Tue Jun 16 14:24:21 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 16 Jun 2009 18:24:21 GMT Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: On 2009-06-16, Mike Driscoll wrote: > On Jun 16, 9:20?am, Filipe Teixeira wrote: >> Hi, I'm really struggling to find the best GUI to make a simple >> application. [SNIP] >> Basically I will use a lot of edit boxes and some tabs, and a folder >> tree, any tips so I can search in the right place? > When I was first looking at GUIs, I tried Tkinter first. But it just > ultimate look-and-feel for Windows, you should go with IronPython. IronPython is not a GUI toolkit per se. It is a python implementation build on top of .Net like Jython is built on top of Java. I therefore has access to the MFCs which can be used to create native Windows GUIs. This can also be done from Cpython using the pywin extensions. From chrisspen at gmail.com Tue Jun 16 14:24:51 2009 From: chrisspen at gmail.com (Chris) Date: Tue, 16 Jun 2009 11:24:51 -0700 (PDT) Subject: Python WSDL Support Message-ID: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Is there any modern support for WSDL? The only projects I could find are ZSI and SOAPpy, and both have been dead for several years. From stef.mientki at gmail.com Tue Jun 16 14:27:12 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 16 Jun 2009 20:27:12 +0200 Subject: [ANN] first full alpha release of PyLab_Works v0.3 Message-ID: <4A37E400.4080305@gmail.com> hello, I am pleased to announce the first full alpha release of PyLab_Works, v0.3. PyLab_Works is a modular Visual Development Environment, based on data-flow programming technics. PyLab_Works is specially aimed at Education, Engineering and Science. The ideas behind PyLab_Works are, that the final user should not be burdened with programming details and domain details, whereas the domain expert should be able to implement the specific domain knowledge without being a full educated programmer. You can always find my notes on PyLab_Works on http://pic.flappie.nl Most of these pages are also collected in a single pdf document, which can be found here: http://pylab-works.googlecode.com/files/pw_manual.pdf The source code and a one-button-Windows-Installer can be found on codegoogle: http://code.google.com/p/pylab-works/ The files are rather large, because they contain some data samples. The Windows-Installer contains everything you need to get started with PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. Although the PyLab_Works programs are compiled with Py2Exe, all the source files are explicitly included. have fun, Stef Mientki From python at mrabarnett.plus.com Tue Jun 16 14:35:49 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Jun 2009 19:35:49 +0100 Subject: Need to know if a file as only ASCII charaters In-Reply-To: <4A37E07E.60709@hughes.net> References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> <4A37E07E.60709@hughes.net> Message-ID: <4A37E605.3040405@mrabarnett.plus.com> norseman wrote: > Scott David Daniels wrote: >> Dave Angel wrote: >>> Jorge wrote: >>>> Hi there, >>>> I'm making a application that reads 3 party generated ASCII files, >>>> but some >>>> times >>>> the files are corrupted totally or partiality and I need to know if >>>> it's a >>>> ASCII file with *nix line terminators. >>>> In linux I can run the file command but the applications should run in >>>> windows. > > you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) > combination. If present you have Microsoft compatibility. If not you > don't. If you think High Bits might be part of the corruption, filter > each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) > then check for the \x0D \x0A combination. > Run the test on a known text setup. Intel uses one order and the SUN and > the internet another. The BIG/Little ending confuses many. Intel > reverses the order of multibyte numerics. Thus - Small machine has big > ego or largest byte value last. Big Ending. Big machine has small ego. > Little Ending. Some coders get the 0D0A backwards, some don't. You > might want to test both. > In an ASCII file endianness is irrelevant. From Scott.Daniels at Acm.Org Tue Jun 16 14:52:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 11:52:01 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: norseman wrote: > Scott David Daniels wrote: >> Dave Angel wrote: >>> Jorge wrote: ... >>>> I'm making a application that reads 3 party generated ASCII files, >>>> but some times the files are corrupted totally or partiality and >>>> I need to know if it's a ASCII file with *nix line terminators. >>>> In linux I can run the file command but the applications should run in >>>> windows. > you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) > combination. If present you have Microsoft compatibility. If not you > don't. If you think High Bits might be part of the corruption, filter > each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) > then check for the \x0D \x0A combination. Well ASCII defines a \x0D as the return code, and \x0A as line feed. It is unix that is wrong, not Microsoft (don't get me wrong, I know Microsoft has often redefined what it likes invalidly). If you open the file with 'U', Python will return lines w/o the \r character whether or not they started with it, equally well on both unix and Microsoft systems. Many moons ago the high order bit was used as a parity bit, but few communication systems do that these days, so anything with the high bit set is likely corruption. > .... Intel uses one order and the SUN and the internet another. The > BIG/Little ending confuses many. Intel reverses the order of multibyte > numerics. Thus- Small machine has big ego or largest byte value last. > Big Ending. Big machine has small ego. > Little Ending. Some coders get the 0D0A backwards, some don't. You > might want to test both. > (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending > Intel stores them (2^8)(2^16)(2^24)(2^32) big ending > SUN/Internet stores them in correct math order. > Python will use \r\n (0D0A) and \n\r (0A0D) correctly. This is the most confused summary of byte sex I've ever read. There is no such thing as "correct math order" (numbers are numbers). The '\n\r' vs. '\r\n' has _nothing_ to do with little-endian vs. big-endian. By the way, there are great arguments for each order, and no clear winner. Network order was defined for sending numbers across a wire, the idea was that you'd unpack them to native order as you pulled the data off the wire. The '\n\r' vs. '\r\n' differences harken back to the days when they were format effectors (carriage return moved the carriage to the extreme left, line feed advanced the paper). You needed both to properly position the print head. ASCII uses the pair, and defined the effect of each. As ASCII was being worked out, MIT even defined a "line starve" character to move up one line just as line feed went down one. The order of the format effectors most used was '\r\n' because the carriage return involved the most physical motion on many devices, and the vertical motion time of the line feed could happen while the carriage was moving. After that, you often added padding bytes (typically ASCII NUL ('\x00') or DEL ('\x7F')) to allow the hardware time to finish before you the did spacing and printing. --Scott David Daniels Scott.Daniels at Acm.Org From ullrich at math.okstate.edu Tue Jun 16 14:57:57 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Tue, 16 Jun 2009 13:57:57 -0500 Subject: Measuring Fractal Dimension ? References: <0244f4c2$0$14422$c3e8da3@news.astraweb.com> <46cee448-4ef5-46d1-85ef-001108f201d2@m19g2000yqk.googlegroups.com> Message-ID: On 15 Jun 2009 04:55:03 GMT, Steven D'Aprano wrote: >On Sun, 14 Jun 2009 14:29:04 -0700, Kay Schluehr wrote: > >> On 14 Jun., 16:00, Steven D'Aprano >> wrote: >> >>> Incorrect. Koch's snowflake, for example, has a fractal dimension of >>> log 4/log 3 ? 1.26, a finite area of 8/5 times that of the initial >>> triangle, and a perimeter given by lim n->inf (4/3)**n. Although the >>> perimeter is infinite, it is countably infinite and computable. >> >> No, the Koch curve is continuous in R^2 and uncountable. > >I think we're talking about different things. The *number of points* in >the Koch curve is uncountably infinite, but that's nothing surprising, >the number of points in the unit interval [0, 1] is uncountably infinite. >But the *length* of the Koch curve is not, it's given by the above limit, >which is countably infinite (it's a rational number for all n). No, the length of the perimeter is infinity, period. Calling it "countably infinite" makes no sense. You're confusing two different sorts of "infinity". A set has a cardinality - "countably infinite" is the smallest infinite cardinality. Limits, as in calculus, as in that limit above, are not cardinailities. > >> Lawrence is >> right and one can trivially cover a countable infinite set with disks of >> the diameter 0, namely by itself. The sum of those diameters to an >> arbitrary power is also 0 and this yields that the Hausdorff dimension >> of any countable set is 0. > >Nevertheless, the Hausdorff dimension (or a close approximation thereof) >can be calculated from the scaling properties of even *finite* objects. >To say that self-similar objects like broccoli or the inner surface of >the human lungs fails to nest at all scales is pedantically correct but >utterly pointless. If it's good enough for Beno?t Mandelbrot, it's good >enough for me. From Scott.Daniels at Acm.Org Tue Jun 16 15:04:32 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:04:32 -0700 Subject: doctests and decorators In-Reply-To: References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: Eric Snow wrote: > In general should decorators always hide themselves? I am guessing > not, otherwise this would already be part of their behavior. Still, > is it the common case to camouflage the decorator like this? If so, I > would expect it to be the default behavior of decorators. The Python goal is "no magic". So, if you want the stuff wrapped, you do it (as the default traceback shows where the code actually goes). It would be far more complicated to display the truth if decorators defaulted to modifying the builtins, and you had to do magic to remove that part of the decoration. A decorator has _very_ simple semantics, while anything that automatically copied attributes would have funny semantics indeed for use by funny decorators like: abi = [] def indexed(function): result = len(abi) abi.append(function) return result @indexed def first_function(...): ... @indexed def second_function(...): ... --Scott David Daniels Scott.Daniels at Acm.Org From kyosohma at gmail.com Tue Jun 16 15:05:05 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Tue, 16 Jun 2009 12:05:05 -0700 (PDT) Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: On Jun 16, 1:24?pm, Tim Harig wrote: > On 2009-06-16, Mike Driscoll wrote: > > > On Jun 16, 9:20?am, Filipe Teixeira wrote: > >> Hi, I'm really struggling to find the best GUI to make a simple > >> application. > [SNIP] > >> Basically I will use a lot of edit boxes and some tabs, and a folder > >> tree, any tips so I can search in the right place? > > When I was first looking at GUIs, I tried Tkinter first. But it just > > ultimate look-and-feel for Windows, you should go with IronPython. > > IronPython is not a GUI toolkit per se. ?It is a python implementation > build on top of .Net like Jython is built on top of Java. ?I therefore has > access to the MFCs which can be used to create native Windows GUIs. ?This > can also be done from Cpython using the pywin extensions. That is true...I was just referring to IronPython's ability to hook a GUI created using Visual Studio easily. Going about it through pywin and ctypes is probably above the OP's current needs...although I think Greg Ewing's pyGUI wraps that stuff. I suppose the OP might find that useful: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ - Mike From Scott.Daniels at Acm.Org Tue Jun 16 15:09:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:09:06 -0700 Subject: strptime issue in multi-threaded application In-Reply-To: References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: MRAB wrote: > Joe Holloway wrote: >> We recently uplifted our web application to run on Python 2.6.2. >> We've noticed on a couple occasions that calls into time.strptime have >> failed with this exception: >> [2] http://svn.python.org/view?view=rev&revision=59678 > > A simple workaround might be to sleep a short time and then retry. Can you just import and use time.strptime once before you start the threads? --Scott David Daniels Scott.Daniels at Acm.Org From rlnewman at ucsd.edu Tue Jun 16 15:13:58 2009 From: rlnewman at ucsd.edu (Rob Newman) Date: Tue, 16 Jun 2009 12:13:58 -0700 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes Message-ID: Hi All, I am new to Python, and have a very specific task to accomplish. I have a command line shell script that takes two arguments: create_graphs.sh -v --sta=STANAME where STANAME is a string 4 characters long. create_graphs creates a series of graphs using Matlab (among other 3rd party packages). Right now I can run this happily by hand, but I have to manually execute the command for each STANAME. What I want is to have a Python script that I pass a list of STANAMEs to, and it acts like a daemon and spawns as many child processes as there are processors on my server (64), until it goes through all the STANAMES (about 200). I posted a message on Stack Overflow (ref: http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro) and was recommended to use the multiprocessing and subprocess packages. In the Stack Overflow answers, it was suggested that I use the process pool class in multiprocessing. However, the server I have to use is a Sun Sparc (T5220, Sun OS 5.10) and there is a known issue with sem_open() (ref: http://bugs.python.org/issue3770), so it appears I cannot use the process pool class. So, below is my script (controller.py) that I have attempted to use as a test, that just calls the 'ls' command on a file I know exists rather than firing off my shell script (which takes ~ 10 mins to run per STANAME): #!/path/to/python import sys import os import json import multiprocessing import subprocess def work(verbose,staname): print 'function:',staname print 'parent process:', os.getppid() print 'process id:', os.getpid() print "ls /path/to/file/"+staname+"_info.pf" # cmd will eventually get replaced with the shell script with the verbose and staname options cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] return subprocess.call(cmd, shell=False) if __name__ == '__main__': report_sta_list = ['B10A','B11A','BNLO'] # Print out the complete station list for testing print report_sta_list # Get the number of processors available num_processes = multiprocessing.cpu_count() print 'Number of processes: %s' % (num_processes) print 'Now trying to assign all the processors' threads = [] len_stas = len(report_sta_list) print "+++ Number of stations to process: %s" % (len_stas) # run until all the threads are done, and there is no data left while len(threads) < len(report_sta_list): # if we aren't using all the processors AND there is still data left to # compute, then spawn another thread print "+++ Starting to set off all child processes" if( len(threads) < num_processes ): this_sta = report_sta_list.pop() print "+++ Station is %s" % (this_sta) p = multiprocessing.Process(target=work,args=['v',this_sta]) p.start() print p, p.is_alive() threads.append(p) else: for thread in threads: if not thread.is_alive(): threads.remove(thread) However, I seem to be running into a whole series of errors: myhost{rt}62% controller.py ['B10A', 'B11A', 'BNLO'] Number of processes: 64 Now trying to assign all the processors +++ Number of stations to process: 3 +++ Starting to set off all child processes +++ Station is BNLO True +++ Starting to set off all child processes +++ Station is B11A function: BNLO parent process: 22341 process id: 22354 ls /path/to/file/BNLO_info.pf True function: B11A parent process: 22341 process id: 22355 ls /path/to/file/B11A_info.pf Process Process-1: Traceback (most recent call last): File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in _bootstrap self.run() File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "controller.py", line 104, in work return subprocess.call(cmd, shell=False) File "/opt/csw/lib/python/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ errread, errwrite) File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory Process Process-2: Traceback (most recent call last): File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in _bootstrap self.run() File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "controller.py", line 104, in work return subprocess.call(cmd, shell=False) File "/opt/csw/lib/python/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ errread, errwrite) File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory The files are there: mhost{me}11% ls -la /path/to/files/BNLO_info.pf -rw-rw-r-- 1 me group 391 May 19 22:40 /path/to/files/ BNLO_info.pf myhost{me}12% ls -la /path/to/file/B11A_info.pf -rw-rw-r-- 1 me group 391 May 19 22:27 /path/to/files/ B11A_info.pf I might be doing this completely wrong, but I thought this would be the way to list the files dynamically. Admittedly this is just a stepping stone to running the actual shell script I want to run. Can anyone point me in the right direction or offer any advice for using these packages? Thanks in advance for any help or insight. - Rob From Scott.Daniels at Acm.Org Tue Jun 16 15:19:02 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:19:02 -0700 Subject: mac text files & for line In-Reply-To: References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: MRAB wrote: > Humberto wrote: >> But I am attempting to use for line to iterate through a text >> file, but I am working on a Mac and am getting a single block of text. >> I assume this is because of the Mac {CR} usage vs. line feed. >> >> Is there a programmatic way to use for line to interpret the carriage >> return character as a new line? Otherwise, what are the easiest ways >> to be able to force a replacement of the {CR} character w/ the line >> feed? I've attempted the method using tr, but receive an >> illegal byte sequence error when running the tr '\r' '\n' < file1.txt >>> file2.txt command on my Mac. Read http://www.catb.org/~esr/faqs/smart-questions.html Show code, inputs, and output and explain what you expected. This could be one of dozens of problems. > Open the file with mode 'U' for universal newline support ('\n', '\r' or > '\r\n'). A good guess of what might be going wrong. Another could be using read. --Scott David Daniels Scott.Daniels at Acm.Org From aahz at pythoncraft.com Tue Jun 16 15:33:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 16 Jun 2009 12:33:33 -0700 Subject: Please advise me for a right solution References: <15b1e25c-2bb4-425e-974f-be3d686b5931@p21g2000prn.googlegroups.com> Message-ID: In article <15b1e25c-2bb4-425e-974f-be3d686b5931 at p21g2000prn.googlegroups.com>, VP wrote: > >I need to create a web based inventory tool with specific requirements >such as: > >* More then one group is going to use it. >* Authentication and authorization system based on user and group >privileges. > >For example based on a group privileges group can add/edit/delete >their own stuff and having a read only access to other groups stuff. Maybe this would help? http://code.google.com/p/django-inventory/ I do think you should plan on using a framework of some kind, to handle the authentication system at least. -- 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 Scott.Daniels at Acm.Org Tue Jun 16 15:38:52 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 12:38:52 -0700 Subject: ImageEnhance.Contrast - is this fishy or what? In-Reply-To: References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> Message-ID: <-OadnW9hvbHbbqrXnZ2dnUVZ_s-dnZ2d@pdx.net> Scott David Daniels wrote: > roop wrote: >> I was browsing ImageEnhace.py, and found something that I thought was >> odd in class Contrast: >> >> class Contrast(_Enhance): >> "Adjust image contrast" >> >> > ... > Good catch [I'll send a copy to the imaging sig]. If you replace class > ... Over on image-sig, Fredrik Lundh responded: > And the award for finding the oldest bug in PIL goes to... (that code > was last touched in 1996). > > I've checked in a last-second fix for 1.1.7 (to be frozen any day soon > now, promise). > > Thanks /F Congrats, roop, on getting this discovered just in the nick of time. The code he uses is: class Contrast(_Enhance): "Adjust image contrast" def __init__(self, image): self.image = image mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5) self.degenerate = Image.new("L", image.size, mean).convert(image.mode) --Scott David Daniels Scott.Daniels at Acm.Org From aahz at pythoncraft.com Tue Jun 16 15:44:10 2009 From: aahz at pythoncraft.com (Aahz) Date: 16 Jun 2009 12:44:10 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> Message-ID: In article <8f093893-310a-4f0f-9e67-61393c234299 at f38g2000pra.googlegroups.com>, Aaron Watters wrote: > >This is the best book ever written on computer science >and the first edition is free. > >http://www.math.upenn.edu/~wilf/AlgComp3.html Thanks! -- 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 HellZFury+Python at gmail.com Tue Jun 16 15:47:37 2009 From: HellZFury+Python at gmail.com (Matt) Date: Tue, 16 Jun 2009 15:47:37 -0400 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes In-Reply-To: References: Message-ID: Try replacing: cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] with: cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] Basically, the first is the conceptual equivalent of executing the following in BASH: ?ls /path/to/file/FOO_info.pf? The second is this: ?ls? ?/path/to/file/FOO_info.pf? The first searches for a command in your PATH named ?ls /path...?. The second searches for a command names ?ls? and gives it the argument ?/path...? Also, I think this is cleaner (but it?s up to personal preference): cmd = [ "ls", "/path/to/file/%s_info.pf" % staname] ________________________ ~Matthew Strax-Haber Northeastern University, CCIS & CBA Co-op, NASA Langley Research Center Student Government Association, Special Interest Senator Resident Student Association, SGA Rep & General Councilor Chess Club, Treasurer E-mail: strax-haber.m=AT=neu.edu On Tue, Jun 16, 2009 at 3:13 PM, Rob Newman wrote: > Hi All, > > I am new to Python, and have a very specific task to accomplish. I have a > command line shell script that takes two arguments: > > create_graphs.sh -v --sta=STANAME > > where STANAME is a string 4 characters long. > > create_graphs creates a series of graphs using Matlab (among other 3rd party > packages). > > Right now I can run this happily by hand, but I have to manually execute the > command for each STANAME. What I want is to have a Python script that I pass > a list of STANAMEs to, and it acts like a daemon and spawns as many child > processes as there are processors on my server (64), until it goes through > all the STANAMES (about 200). > > I posted a message on Stack Overflow (ref: > http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro)?and > was recommended to use the multiprocessing and subprocess packages. In the > Stack Overflow answers, it was suggested that I use the process pool class > in multiprocessing. However, the server I have to use is a Sun Sparc (T5220, > Sun OS 5.10) and there is a known issue with sem_open() (ref: > http://bugs.python.org/issue3770), so it appears I cannot use the process > pool class. > > So, below is my script (controller.py) that I have attempted to use as a > test, that just calls the 'ls' command on a file I know exists rather than > firing off my shell script (which takes ~ 10 mins to run per STANAME): > > #!/path/to/python > > import sys > import os > import json > import multiprocessing > import subprocess > > def work(verbose,staname): > ?print 'function:',staname > ?print 'parent process:', os.getppid() > ?print 'process id:', os.getpid() > ?print "ls /path/to/file/"+staname+"_info.pf" > ?# cmd will eventually get replaced with the shell script with the verbose > and staname options > ?cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > ?return subprocess.call(cmd, shell=False) > > if __name__ == '__main__': > > ?report_sta_list = ['B10A','B11A','BNLO'] > > ?# Print out the complete station list for testing > ?print report_sta_list > > ?# Get the number of processors available > ?num_processes = multiprocessing.cpu_count() > > ?print 'Number of processes: %s' % (num_processes) > > ?print 'Now trying to assign all the processors' > > ?threads = [] > > ?len_stas = len(report_sta_list) > > ?print "+++ Number of stations to process: %s" % (len_stas) > > ?# run until all the threads are done, and there is no data left > ?while len(threads) < len(report_sta_list): > > ? ?# if we aren't using all the processors AND there is still data left to > ? ?# compute, then spawn another thread > > ? ?print "+++ Starting to set off all child processes" > > ? ?if( len(threads) < num_processes ): > > ? ? ?this_sta = report_sta_list.pop() > > ? ? ?print "+++ Station is %s" % (this_sta) > > ? ? ?p = multiprocessing.Process(target=work,args=['v',this_sta]) > > ? ? ?p.start() > > ? ? ?print p, p.is_alive() > > ? ? ?threads.append(p) > > ? ?else: > > ? ? ?for thread in threads: > > ? ? ? ?if not thread.is_alive(): > > ? ? ? ? ?threads.remove(thread) > > However, I seem to be running into a whole series of errors: > > myhost{rt}62% controller.py > ['B10A', 'B11A', 'BNLO'] > Number of processes: 64 > Now trying to assign all the processors > +++ Number of stations to process: 3 > +++ Starting to set off all child processes > +++ Station is BNLO > True > +++ Starting to set off all child processes > +++ Station is B11A > function: BNLO > parent process: 22341 > process id: 22354 > ls /path/to/file/BNLO_info.pf > True > function: B11A > parent process: 22341 > process id: 22355 > ls /path/to/file/B11A_info.pf > Process Process-1: > Traceback (most recent call last): > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in > _bootstrap > ? ?self.run() > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run > ? ?self._target(*self._args, **self._kwargs) > ?File "controller.py", line 104, in work > ? ?return subprocess.call(cmd, shell=False) > ?File "/opt/csw/lib/python/subprocess.py", line 444, in call > ? ?return Popen(*popenargs, **kwargs).wait() > ?File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ > ? ?errread, errwrite) > ?File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child > ? ?raise child_exception > OSError: [Errno 2] No such file or directory > Process Process-2: > Traceback (most recent call last): > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in > _bootstrap > ? ?self.run() > ?File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in run > ? ?self._target(*self._args, **self._kwargs) > ?File "controller.py", line 104, in work > ? ?return subprocess.call(cmd, shell=False) > ?File "/opt/csw/lib/python/subprocess.py", line 444, in call > ? ?return Popen(*popenargs, **kwargs).wait() > ?File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ > ? ?errread, errwrite) > ?File "/opt/csw/lib/python/subprocess.py", line 1092, in _execute_child > ? ?raise child_exception > OSError: [Errno 2] No such file or directory > > The files are there: > > mhost{me}11% ls -la /path/to/files/BNLO_info.pf > -rw-rw-r-- ? 1 me ? ? ? group ? ? 391 May 19 22:40 > /path/to/files/BNLO_info.pf > myhost{me}12% ls -la /path/to/file/B11A_info.pf > -rw-rw-r-- ? 1 me ? ? ? group ? ? 391 May 19 22:27 > /path/to/files/B11A_info.pf > > I might be doing this completely wrong, but I thought this would be the way > to list the files dynamically. Admittedly this is just a stepping stone to > running the actual shell script I want to run. Can anyone point me in the > right direction or offer any advice for using these packages? > > Thanks in advance for any help or insight. > - Rob > -- > http://mail.python.org/mailman/listinfo/python-list > From piet at cs.uu.nl Tue Jun 16 15:47:42 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 21:47:42 +0200 Subject: Input problem References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: >>>>> Prasoon (P) wrote: >P> What is the difference between >P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >P> the same in case of integers) >P> I mean when an integer is entered in that case are they same and when >P> an integer in not entered,in that case how are they different????? >>> z=eval(raw_input()) 3+4 >>> z 7 >>> z=int(raw_input()) 3+4 Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '3+4' -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 15:51:57 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 21:51:57 +0200 Subject: PSP Text Editor References: Message-ID: >>>>> Johnson Mpeirwe (JM) wrote: >JM> Hi all, >JM> Does anyone know of any good Python Server Pages text editor that can >JM> provide indentation, syntax highlighting, etc.. A text editor in a web context doesn't run on the server but in the browser. Therefore it should use client-side scripting (which probably means Javascript or flash (shudder!)) Including that in a PSP web page isn't so much different from its inclusion in any other framework. You must just choose one of the existing editors. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 16:07:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 22:07:17 +0200 Subject: PSP Text Editor References: Message-ID: Reading your question again I think I have probably misunderstood it. You want to an editor to edit Python Server Pages? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Tue Jun 16 16:16:56 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 22:16:56 +0200 Subject: strange behavior with os.system References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: >>>>> kmw (k) wrote: >k> Hi, >k> I wanted to write a simple script (in 5 minutes or so) which replaces >k> the option '+1' given to the command 'sort' by '-k 2' and than runs >k> 'sort' with the modified argument list. After two hours I am giving up >k> and ask you for help. This is what I tried (please excuse the verbose >k> code, it is due to my various efforts to understand the error): [snip] >k> Please note the unrequested output of ''. The strange >k> thing about this all is the fact that the whole thing works as >k> expected when typed into the interpreter. I would be glad if anyone >k> could help. MRAB has already given you some insight, I hope. But are you aware that you are calling your own program again? Or did you want to call the standard sort program? In that case you shouldn't call ./sort as it is in argv[0], but just sort (assuming '.' is not in your PATH) or the full path, like /usr/bin/sort. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From arnodel at googlemail.com Tue Jun 16 16:22:12 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Jun 2009 21:22:12 +0100 Subject: Tool for browsing python code References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: "D'Arcy J.M. Cain" writes: > On Tue, 16 Jun 2009 18:25:00 +0530 > Banibrata Dutta wrote: >> not sure if there are any "curses" base TUI's (!) for Python. > > vi emacs :) -- Arnaud From lie.1296 at gmail.com Tue Jun 16 16:27:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 20:27:06 GMT Subject: mac text files & for line In-Reply-To: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: Humberto wrote: > Greetings. > > This is probably a v. basic question, but my apologies as I'm > relatively new w/ this. > > But I am attempting to use for line to iterate through a text > file, but I am working on a Mac and am getting a single block of text. > I assume this is because of the Mac {CR} usage vs. line feed. > > Is there a programmatic way to use for line to interpret the carriage > return character as a new line? Otherwise, what are the easiest ways > to be able to force a replacement of the {CR} character w/ the line > feed? I've attempted the method using tr, but receive an > illegal byte sequence error when running the tr '\r' '\n' < file1.txt >> file2.txt command on my Mac. > > Any help would be greatly appreciated and thanks! I guess this is how you write your code: f = open('myfile.txt', 'r').read() for line in f: print line # stream of characters... if that's the case, change the code into: f = open('myfile.txt', 'r') for line in f: print line If you .read() the file yourself, you'll get a single string of the whole file content; '\n' (of whatever real type) inside a string is not used as delimiter for a for-loop. From nick at craig-wood.com Tue Jun 16 16:29:33 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 16 Jun 2009 15:29:33 -0500 Subject: waling a directory with very many files References: Message-ID: Nick Craig-Wood wrote: > Jean-Paul Calderone wrote: > > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: > > >Hrvoje Niksic wrote: > > >> Nick Craig-Wood writes: > > >> > > >> > Here is a ctypes generator listdir for unix-like OSes. > > >> > > >> ctypes code scares me with its duplication of the contents of system > > >> headers. I understand its use as a proof of concept, or for hacks one > > >> needs right now, but can anyone seriously propose using this kind of > > >> code in a Python program? For example, this seems much more > > >> "Linux-only", or possibly even "32-bit-Linux-only", than > > >> "unix-like": > > > > > >It was a proof of concept certainly.. Just in case anyone is interested here is an implementation using cython. Compile with python setup.py build_ext --inplace And run listdir.py This would have been much easier if cython supported yield, but unfortunately it doesn't (yet - I think it is in the works). This really should work on any platform! --setup.py---------------------------------------------------------- from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( cmdclass = {'build_ext': build_ext}, ext_modules = [Extension("directory", ["directory.pyx"])] ) --directory.pyx---------------------------------------------------------- # Cython interface for listdir # python setup.py build_ext --inplace import cython cdef extern from "dirent.h": struct dirent: char d_name[0] struct dir_handle: pass ctypedef dir_handle DIR "DIR" DIR *opendir(char *name) int closedir(DIR *dirp) dirent *readdir(DIR *dirp) cdef class Directory: """Represents an open directory""" cdef DIR *handle def __init__(self, path): self.handle = opendir(path) def readdir(self): cdef dirent *p p = readdir(self.handle) if p is NULL: return None return p.d_name def close(self): closedir(self.handle) --listdir.py---------------------------------------------------------- from directory import Directory def listdir(path): """ A generator to return the names of files in the directory passed in """ d = Directory(".") while True: name = d.readdir() if not name: break if name not in (".", ".."): yield name d.close() if __name__ == "__main__": for name in listdir("."): print name ------------------------------------------------------------ -- Nick Craig-Wood -- http://www.craig-wood.com/nick From hypertaos at gmail.com Tue Jun 16 16:31:56 2009 From: hypertaos at gmail.com (Humberto) Date: Tue, 16 Jun 2009 13:31:56 -0700 (PDT) Subject: mac text files & for line References: <84ca1c97-5f1e-46ef-9a76-86a60362f35d@g19g2000yql.googlegroups.com> Message-ID: On Jun 16, 1:39?pm, MRAB wrote: > Humberto wrote: > > Greetings. > > > This is probably a v. basic question, but my apologies as I'm > > relatively new w/ this. > > > But I am attempting to use for line to iterate through a text > > file, but I am working on a Mac and am getting a single block of text. > > I assume this is because of the Mac {CR} usage vs. line feed. > > > Is there a programmatic way to use for line to interpret the carriage > > return character as a new line? Otherwise, what are the easiest ways > > to be able to force a replacement of the {CR} character w/ the line > > feed? I've attempted the method using tr, but receive an > > illegal byte sequence error when running the tr '\r' '\n' < file1.txt > >> file2.txt command on my Mac. > > > Any help would be greatly appreciated and thanks! > > Open the file with mode 'U' for universal newline support ('\n', '\r' or > '\r\n'). Precisely my problem. Thanks so much. I'd overlooked the references to U in the entry for the open function. To the other fellow, I think the question was reasonably specific in the second paragraph...I sense the helpful response bore that out. I certainly acknowledge my mistake in having overlooked the reference in the documentation. So my apologies for any inconvenience and thanks again. From darcy at druid.net Tue Jun 16 16:38:21 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 16 Jun 2009 16:38:21 -0400 Subject: Tool for browsing python code In-Reply-To: References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> Message-ID: <20090616163821.c3c9d48d.darcy@druid.net> On Tue, 16 Jun 2009 21:22:12 +0100 Arnaud Delobelle wrote: > "D'Arcy J.M. Cain" writes: > >> not sure if there are any "curses" base TUI's (!) for Python. > > vi > > emacs :) Hey, it was all pretty civil up till now. ;) -- 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 lie.1296 at gmail.com Tue Jun 16 16:50:25 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 16 Jun 2009 20:50:25 GMT Subject: Input problem In-Reply-To: References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: Piet van Oostrum wrote: >>>>>> Prasoon (P) wrote: > >> P> What is the difference between >> P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >> P> the same in case of integers) > >> P> I mean when an integer is entered in that case are they same and when >> P> an integer in not entered,in that case how are they different????? >>> z=eval(raw_input()) # or z = input() in py-2 import subprocess; subprocess.Popen(['killuser', 'now', '-j20', '-O3']) eocaioewurf4fcrejcomefvweracv >>> _ From mrstevegross at gmail.com Tue Jun 16 16:54:01 2009 From: mrstevegross at gmail.com (mrstevegross) Date: Tue, 16 Jun 2009 13:54:01 -0700 (PDT) Subject: Guidance on initialization code in a module Message-ID: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Is there a common way to initialize various stuff in a module? That is, I have some code in my module that I want to run whenever the module is imported. Currently, my module looks like this: === foo.py === def something(): ... def somethingelse(): ... something() === EOF === Is the 'something()' line at the end in an ok location? I just put it at the end. Maybe there's some special __init__() mechanism for modules? Or should I use the 'if __name__ != '__main__'' trick? Thanks, --Steve From waldemar.osuch at gmail.com Tue Jun 16 16:57:53 2009 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Tue, 16 Jun 2009 13:57:53 -0700 (PDT) Subject: Python WSDL Support References: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Message-ID: <38dbd285-b55e-4577-8bb4-698253c100b0@l12g2000yqo.googlegroups.com> On Jun 16, 12:24?pm, Chris wrote: > Is there any modern support for WSDL? The only projects I could find > are ZSI and SOAPpy, and both have been dead for several years. https://fedorahosted.org/suds/ is actively maintained From piet at cs.uu.nl Tue Jun 16 17:02:23 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:02:23 +0200 Subject: Python WSDL Support References: <84cf9696-3d45-4dc8-8805-3cf06addd487@w3g2000yqf.googlegroups.com> Message-ID: >>>>> Chris (C) wrote: >C> Is there any modern support for WSDL? The only projects I could find >C> are ZSI and SOAPpy, and both have been dead for several years. That is not necessarily bad. But for the client side there is also suds (https://fedorahosted.org/suds/). And you may also look for soaplib (http://trac.optio.webfactional.com/) but it is probably also `dead'. There is a fork soaplib-lxml, however, that is being actively developed. SOAP is not very popular in the Python world, I think. SOAP is a mammoth and that fits better in the Java and Microsoft worlds :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From songkai.sk at gmail.com Tue Jun 16 17:02:40 2009 From: songkai.sk at gmail.com (kai) Date: Tue, 16 Jun 2009 14:02:40 -0700 (PDT) Subject: Build problem on Solaris 9 References: <4a0d468a-15ed-4a8b-8041-dbf9d48e7cd0@y6g2000prf.googlegroups.com> <4a374695$0$11163$9b622d9e@news.freenet.de> Message-ID: On Jun 16, 12:15?am, "Martin v. L?wis" wrote: > > When I run make after successively running ./configure, I got the > > following Error message: > > ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl > > /usr/bin/env: No such file or directory > > make: *** [Python/Python-ast.c] Error 127 Thank you so much!!! It compiles now. Kai > > > /usr/bin/env deos exist.... > > > Can anyone help me with this? > > It's probably rather that "python" does not exist on the path, > which asdl_c.py requires. > > touch Include/Python-ast.h Python/Python-ast.c > > should work around. > > Regards, > Martin From rlnewman at ucsd.edu Tue Jun 16 17:11:00 2009 From: rlnewman at ucsd.edu (Rob Newman) Date: Tue, 16 Jun 2009 14:11:00 -0700 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes In-Reply-To: References: Message-ID: Thanks Matt - that worked. Kind regards, - Rob On Jun 16, 2009, at 12:47 PM, Matt wrote: > Try replacing: > cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > with: > cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] > > Basically, the first is the conceptual equivalent of executing the > following in BASH: > ?ls /path/to/file/FOO_info.pf? > The second is this: > ?ls? ?/path/to/file/FOO_info.pf? > > The first searches for a command in your PATH named ?ls /path...?. The > second searches for a command names ?ls? and gives it the argument > ?/path...? > > Also, I think this is cleaner (but it?s up to personal preference): > cmd = [ "ls", "/path/to/file/%s_info.pf" % staname] > > ________________________ > ~Matthew Strax-Haber > Northeastern University, CCIS & CBA > Co-op, NASA Langley Research Center > Student Government Association, Special Interest Senator > Resident Student Association, SGA Rep & General Councilor > Chess Club, Treasurer > E-mail: strax-haber.m=AT=neu.edu > > On Tue, Jun 16, 2009 at 3:13 PM, Rob Newman wrote: >> Hi All, >> >> I am new to Python, and have a very specific task to accomplish. I >> have a >> command line shell script that takes two arguments: >> >> create_graphs.sh -v --sta=STANAME >> >> where STANAME is a string 4 characters long. >> >> create_graphs creates a series of graphs using Matlab (among other >> 3rd party >> packages). >> >> Right now I can run this happily by hand, but I have to manually >> execute the >> command for each STANAME. What I want is to have a Python script >> that I pass >> a list of STANAMEs to, and it acts like a daemon and spawns as many >> child >> processes as there are processors on my server (64), until it goes >> through >> all the STANAMES (about 200). >> >> I posted a message on Stack Overflow (ref: >> http://stackoverflow.com/questions/884650/python-spawn-parallel-child-processes-on-a-multi-processor-system-use-multipro) >> and >> was recommended to use the multiprocessing and subprocess packages. >> In the >> Stack Overflow answers, it was suggested that I use the process >> pool class >> in multiprocessing. However, the server I have to use is a Sun >> Sparc (T5220, >> Sun OS 5.10) and there is a known issue with sem_open() (ref: >> http://bugs.python.org/issue3770), so it appears I cannot use the >> process >> pool class. >> >> So, below is my script (controller.py) that I have attempted to use >> as a >> test, that just calls the 'ls' command on a file I know exists >> rather than >> firing off my shell script (which takes ~ 10 mins to run per >> STANAME): >> >> #!/path/to/python >> >> import sys >> import os >> import json >> import multiprocessing >> import subprocess >> >> def work(verbose,staname): >> print 'function:',staname >> print 'parent process:', os.getppid() >> print 'process id:', os.getpid() >> print "ls /path/to/file/"+staname+"_info.pf" >> # cmd will eventually get replaced with the shell script with the >> verbose >> and staname options >> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] >> return subprocess.call(cmd, shell=False) >> >> if __name__ == '__main__': >> >> report_sta_list = ['B10A','B11A','BNLO'] >> >> # Print out the complete station list for testing >> print report_sta_list >> >> # Get the number of processors available >> num_processes = multiprocessing.cpu_count() >> >> print 'Number of processes: %s' % (num_processes) >> >> print 'Now trying to assign all the processors' >> >> threads = [] >> >> len_stas = len(report_sta_list) >> >> print "+++ Number of stations to process: %s" % (len_stas) >> >> # run until all the threads are done, and there is no data left >> while len(threads) < len(report_sta_list): >> >> # if we aren't using all the processors AND there is still data >> left to >> # compute, then spawn another thread >> >> print "+++ Starting to set off all child processes" >> >> if( len(threads) < num_processes ): >> >> this_sta = report_sta_list.pop() >> >> print "+++ Station is %s" % (this_sta) >> >> p = multiprocessing.Process(target=work,args=['v',this_sta]) >> >> p.start() >> >> print p, p.is_alive() >> >> threads.append(p) >> >> else: >> >> for thread in threads: >> >> if not thread.is_alive(): >> >> threads.remove(thread) >> >> However, I seem to be running into a whole series of errors: >> >> myhost{rt}62% controller.py >> ['B10A', 'B11A', 'BNLO'] >> Number of processes: 64 >> Now trying to assign all the processors >> +++ Number of stations to process: 3 >> +++ Starting to set off all child processes >> +++ Station is BNLO >> True >> +++ Starting to set off all child processes >> +++ Station is B11A >> function: BNLO >> parent process: 22341 >> process id: 22354 >> ls /path/to/file/BNLO_info.pf >> True >> function: B11A >> parent process: 22341 >> process id: 22355 >> ls /path/to/file/B11A_info.pf >> Process Process-1: >> Traceback (most recent call last): >> File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in >> _bootstrap >> self.run() >> File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in >> run >> self._target(*self._args, **self._kwargs) >> File "controller.py", line 104, in work >> return subprocess.call(cmd, shell=False) >> File "/opt/csw/lib/python/subprocess.py", line 444, in call >> return Popen(*popenargs, **kwargs).wait() >> File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ >> errread, errwrite) >> File "/opt/csw/lib/python/subprocess.py", line 1092, in >> _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> Process Process-2: >> Traceback (most recent call last): >> File "/opt/csw/lib/python/multiprocessing/process.py", line 231, in >> _bootstrap >> self.run() >> File "/opt/csw/lib/python/multiprocessing/process.py", line 88, in >> run >> self._target(*self._args, **self._kwargs) >> File "controller.py", line 104, in work >> return subprocess.call(cmd, shell=False) >> File "/opt/csw/lib/python/subprocess.py", line 444, in call >> return Popen(*popenargs, **kwargs).wait() >> File "/opt/csw/lib/python/subprocess.py", line 595, in __init__ >> errread, errwrite) >> File "/opt/csw/lib/python/subprocess.py", line 1092, in >> _execute_child >> raise child_exception >> OSError: [Errno 2] No such file or directory >> >> The files are there: >> >> mhost{me}11% ls -la /path/to/files/BNLO_info.pf >> -rw-rw-r-- 1 me group 391 May 19 22:40 >> /path/to/files/BNLO_info.pf >> myhost{me}12% ls -la /path/to/file/B11A_info.pf >> -rw-rw-r-- 1 me group 391 May 19 22:27 >> /path/to/files/B11A_info.pf >> >> I might be doing this completely wrong, but I thought this would be >> the way >> to list the files dynamically. Admittedly this is just a stepping >> stone to >> running the actual shell script I want to run. Can anyone point me >> in the >> right direction or offer any advice for using these packages? >> >> Thanks in advance for any help or insight. >> - Rob From lenz at joinville.udesc.br Tue Jun 16 17:12:10 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 16 Jun 2009 14:12:10 -0700 Subject: ODE, GUI, plotter in Python In-Reply-To: <160620091700027246%shaibani@ymail.com> References: <160620091700027246%shaibani@ymail.com> Message-ID: <200906161412.11404.lenz@joinville.udesc.br> Em Ter 16 Jun 2009, ?s 09:00:02, Ala escreveu: > Hello everyone. > > I am starting on implementing a simulator using python, and since it's > the first time I code in python would appreciate a few pointers: > > The simulator will use a coupled ODE for the most part of the > simulation, I plan to use scipy. (Anything considered faster/better > than scipy for solving coupled ODEs? ) > > I plan for a GUI program with network graph plotting. I am leaning > towards using Qt for the GUI (internet forums seem to recommend it, > anyone got other preferences? ) > > Since the GUI application will contain few buttons and a plot, I am > planning to implement matplotlib into the GUI. But does anyone know if > matplotlib allows for interaction with the graph plot? (say for a > network simulation, allowing to right click on nodes and disable them > for instance, or alter some other properties of nodes and/or links > across them). > > I am just starting out, hence I'd rather get some advice and experiment > a bit for my self as I go along. > > Thank you. you should take a look at http://pyode.sourceforge.net/ and pygame. []'s Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From lists at cheimes.de Tue Jun 16 17:19:53 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Jun 2009 23:19:53 +0200 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> References: <8fe048f70906160952w4c730cd6nad3db178305a815b@mail.gmail.com> Message-ID: Joe Holloway schrieb: > We recently uplifted our web application to run on Python 2.6.2. > We've noticed on a couple occasions that calls into time.strptime have > failed with this exception: > > ImportError: Failed to import _strptime because the import lockis > [sic] held by another thread. The error message is my fault. The cause of the mistake is obvious: PyErr_Format(PyExc_ImportError, "Failed to import %.200s because the import lock" "is held by another thread.", name); > I poked around the source code enough to realize that this is > apparently due to time.strptime using PyImport_ImportModuleNoBlock > which potentially raises an ImportError rather than waiting for the > "import lock" to be released [1]. This appears to have been > introduced as a workaround for other thread safety concerns [2]. Without PyImport_ImportModuleNoBlock() your application would block forever. > Does this indicate that strptime and any other library function that > uses the non-blocking import call in this fashion are not thread safe? > Is there an idiomatic way of dealing with this error in > multi-threaded applications? It's not a matter of thread safety per se. I've added the function to work around a dead lock situation. Python allows you to import a module in a subthread but the entire import system is protected by a lock. > Like I mentioned, it's only happened on a couple occasions because the > right conditions have to be in place, but something doesn't seem right > about it. I thought I'd ask on the mailing list before going so far > as to open a ticket, but feel free to direct me there if that's the > appropriate place for this. I have an idea what might happen in your application. Is an import triggering the start of a thread? You can get around the issue by decoupling imports from thread startups. Your application should import all modules before it starts its threaded components. For now you can decrease the severity of your issue by placing "import _strptime" next to "import time" somewhere in your code. Once it a module is loaded PyImport_ImportModuleNoBlock() will not fail to import it a second time. Christian From piet at cs.uu.nl Tue Jun 16 17:20:05 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:20:05 +0200 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes References: Message-ID: >>>>> Matt (M) wrote: >M> Try replacing: >M> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] >M> with: >M> cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] In addition I would like to remark that -- if the only thing you want to do is to start up a new command with subprocess.Popen -- the use of the multiprocessing package is overkill. You could use threads as well. Moreover, if you don't expect any output from these processes and don't supply input to them through pipes there isn't even a need for these threads. You could just use os.wait() to wait for a child to finish and then start a new process if necessary. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From hobesh at gmail.com Tue Jun 16 17:36:05 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 14:36:05 -0700 Subject: Executing a python script while it is running Message-ID: Hi everybody, Here's my situation: I have a batch file that calls a python script. This batch file is triggered by an outside application when the application completes a task. The problem is that while the batch file (and pythons script) is running, the application will complete the next task, and try to call the batch file again (while it is already running) Hopefully that's not too confusing. I'm not sure what direction to go with this, any help or nudges in the RIGHT direction would be greatly appreciated. From piet at cs.uu.nl Tue Jun 16 17:39:03 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 16 Jun 2009 23:39:03 +0200 Subject: Input problem References: <090aea11-b7b6-4b6c-aa0d-eaa4ce96cfbc@k19g2000prh.googlegroups.com> Message-ID: >>>>> Lie Ryan (LR) wrote: >LR> Piet van Oostrum wrote: >>>>>>>> Prasoon (P) wrote: >>> >P> What is the difference between >P> z=int(raw_input()) and z=eval(raw_input())????(I thought them to be >P> the same in case of integers) >>> >P> I mean when an integer is entered in that case are they same and when >P> an integer in not entered,in that case how are they different????? >>>>> z=eval(raw_input()) # or z = input() in py-2 >LR> import subprocess; subprocess.Popen(['killuser', 'now', '-j20', '-O3']) >LR> eocaioewurf4fcrejcomefvweracv >>>>> _ SyntaxError: invalid syntax eval will not accept statements like import, only expressions. But as Scott David Daniels already had mentioned you can shoot yourself in the foot easily with input() or eval() if you can't trust the input. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From gherron at islandtraining.com Tue Jun 16 17:47:02 2009 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Jun 2009 14:47:02 -0700 Subject: Executing a python script while it is running In-Reply-To: References: Message-ID: <4A3812D6.7000507@islandtraining.com> Zach Hobesh wrote: > Hi everybody, > > Here's my situation: > > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. > > I'm not sure what direction to go with this, any help or nudges in the > RIGHT direction would be greatly appreciated. > You haven't defined a problem. It's perfectly fine for two (or more) processes to be running the same script at the same time. Unless, of course, the script is doing something which should not be run in duplicate. But then, you'll have to tell us what *that* is, and why it's a problem. Then we'll have some problem for which we can ponder a solution. From invalid at invalid Tue Jun 16 17:53:09 2009 From: invalid at invalid (Grant Edwards) Date: Tue, 16 Jun 2009 16:53:09 -0500 Subject: Executing a python script while it is running References: Message-ID: On 2009-06-16, Zach Hobesh wrote: > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. No, though you haven't explained why that's a problem. > I'm not sure what direction to go with this, any help or > nudges in the RIGHT direction would be greatly appreciated. First, you have to explain what your problem is. -- Grant Edwards grante Yow! It's a hole all the at way to downtown Burbank! visi.com From Scott.Daniels at Acm.Org Tue Jun 16 18:05:06 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 16 Jun 2009 15:05:06 -0700 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ... > > def somethingelse(): > ... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Seems fine there. I'd add a comment like: something() #initialize the frambus so the whatzies are set up. Perhaps I'd choose better names :-) --Scott David Daniels Scott.Daniels at Acm.Org From fetchinson at googlemail.com Tue Jun 16 18:15:06 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 16 Jun 2009 15:15:06 -0700 Subject: Tool for browsing python code In-Reply-To: <20090616163821.c3c9d48d.darcy@druid.net> References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> <20090616163821.c3c9d48d.darcy@druid.net> Message-ID: >> "D'Arcy J.M. Cain" writes: >> >> not sure if there are any "curses" base TUI's (!) for Python. >> > vi >> >> emacs :) > > Hey, it was all pretty civil up till now. ;) I've heard from my cousin that his former high school classmate's uncle did a research on a large statistical sample of programmers and found that emacs users' brains are about 12% smaller than vi users' :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From davea at ieee.org Tue Jun 16 18:31:44 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 18:31:44 -0400 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: <4A381D50.1010406@ieee.org> mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ... > > def somethingelse(): > ... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Maybe there's some special __init__() mechanism for > modules? Or should I use the 'if __name__ != '__main__'' trick? > > Thanks, > --Steve > > You're doing fine. Everything in the module is run when it's imported. Running a definition, of course, compiles it, and adds its name to the module's namespace. But anything outside of a definition or class, or other qualifier will just be run. If the module will never be used as a script, the if __name__ == logic isn't needed. If you want this initialization code to be run *only* if it's not being run as a script, then you'd do as you suggest, if __name__ != "__main__" But usually, the initialization code wants to be run whether it's being used as a script, or as a library module. So leave the conditional off, till you actually decide what behavior should be conditional. From dstanek at dstanek.com Tue Jun 16 18:40:44 2009 From: dstanek at dstanek.com (David Stanek) Date: Tue, 16 Jun 2009 18:40:44 -0400 Subject: Guidance on initialization code in a module In-Reply-To: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> References: <5298570c-84c0-4776-9b10-6693dd27a4de@21g2000vbk.googlegroups.com> Message-ID: On Tue, Jun 16, 2009 at 4:54 PM, mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ?... > > def somethingelse(): > ?... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Maybe there's some special __init__() mechanism for > modules? Or should I use the 'if __name__ != '__main__'' trick? > I think what you are doing is fine. The only thing that I would do differently is rename 'something' to 'initialize'. That way your intent is really obvious. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From davea at ieee.org Tue Jun 16 18:42:06 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 18:42:06 -0400 Subject: Executing a python script while it is running In-Reply-To: References: Message-ID: <4A381FBE.9040003@ieee.org> Zach Hobesh wrote: > Hi everybody, > > Here's my situation: > > I have a batch file that calls a python script. > > This batch file is triggered by an outside application when the > application completes a task. The problem is that while the batch > file (and pythons script) is running, the application will complete > the next task, and try to call the batch file again (while it is > already running) > > Hopefully that's not too confusing. > > I'm not sure what direction to go with this, any help or nudges in the > RIGHT direction would be greatly appreciated. > > A lot more information would be useful. What version of Python, and what operating system environment? Exactly what would you like to happen when the batch file is invoked a second time? Possibilities that occur to me: 1) ignore the second run 2) let them both run as separate processes 3) abort the first run, as the second one will replace it 4) queue something to be processed when the first run finishes What provisions does this existing application have for long-running batch files? Seems the synchronization ought to happen there. Do you have any constraints on how long your script might take, worst case? What if the application finishes its tasks at a faster average rate than your script can process them? From hobesh at gmail.com Tue Jun 16 18:48:56 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 15:48:56 -0700 Subject: Executing a python script while it is running In-Reply-To: <4A381FBE.9040003@ieee.org> References: <4A381FBE.9040003@ieee.org> Message-ID: > A lot more information would be useful. ?What version of Python, and what > operating system environment? ?Exactly what would you like to happen when > the batch file is invoked a second time? I'm running Python 2.6.2 on Windows. I'm passing filenames to the batch files and I need all filenames to be processed. I can't have any fails. I'm working on logging any fails I do have so that I can maybe batch process at the end of the day. > ?2) let them both run as separate processes This sounds like a good option, but I'm not totally sure on how to go about this? > ?4) queue something to be processed when the first run finishes I had the same idea, but I believe it would involve having another python script run all day long, which wouldn't necessarily be a bad thing, but I'd like to explore other options as well. > What provisions does this existing application have for long-running batch > files? ?Seems the synchronization ought to happen there. ?Do you have any > constraints on how long your script might take, worst case? ?What if the > application finishes its tasks at a faster average rate than your script can > process them? The batch file is moving large video files. Duration probably ranges from 10 sec to 45 mins. On average, the application takes longer to process the files than it does the batch file/python script takes to copy them, but I'm concerned about the occasional time that the application finishes a small file right after finishing a large file. Thanks for your response! -Zach From norseman at hughes.net Tue Jun 16 19:07:06 2009 From: norseman at hughes.net (norseman) Date: Tue, 16 Jun 2009 16:07:06 -0700 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <4A38259A.6010406@hughes.net> Scott David Daniels wrote: > norseman wrote: >> Scott David Daniels wrote: >>> Dave Angel wrote: >>>> Jorge wrote: ... >>>>> I'm making a application that reads 3 party generated ASCII files, >>>>> but some times the files are corrupted totally or partiality and I >>>>> need to know if it's a ASCII file with *nix line terminators. >>>>> In linux I can run the file command but the applications should run in >>>>> windows. >> you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) >> combination. If present you have Microsoft compatibility. If not you >> don't. If you think High Bits might be part of the corruption, filter >> each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) >> then check for the \x0D \x0A combination. > > Well ASCII defines a \x0D as the return code, and \x0A as line feed. > It is unix that is wrong, not Microsoft (don't get me wrong, I know > Microsoft has often redefined what it likes invalidly). If you > open the file with 'U', Python will return lines w/o the \r character > whether or not they started with it, equally well on both unix and > Microsoft systems. Yep - but if you are on Microsoft systems you will usually need the \r. Remove them and open the file in Notepad to see what I mean. Wordpad handles the lack of \r OK. Handles larger files too. > Many moons ago the high order bit was used as a > parity bit, but few communication systems do that these days, so > anything with the high bit set is likely corruption. > OH? How did one transfer binary files over the phone? I used PIP or Kermit and it got there just fine, high bits and all. Mail and other so called "text only" programs CAN (but not necessarily do) use 7bit transfer protocols. Can we say MIME? FTP transfers high bit just fine too. Set protocols to 8,1 and none. (8bit, 1 stop, no parity) As to how his 3rd party ASCII files are generated? He does not know, I do not know, we do not know (or care), so test before use. Filter out the high bits, remove all control characters except cr,lf and perhaps keep the ff too, then test what's left. ASCII cr - carriage return ^M x0D \r lf - line feed ^J x0A \n ff - form feed (new page) ^L x0C \f >> .... Intel uses one order and the SUN and the internet another. The > > BIG/Little ending confuses many. Intel reverses the order of multibyte > > numerics. Thus- Small machine has big ego or largest byte value last. > > Big Ending. Big machine has small ego. >> Little Ending. Some coders get the 0D0A backwards, some don't. You >> might want to test both. >> (2^32)(2^24)(2^16(2^8) 4 bytes correct math order little ending >> Intel stores them (2^8)(2^16)(2^24)(2^32) big ending >> SUN/Internet stores them in correct math order. >> Python will use \r\n (0D0A) and \n\r (0A0D) correctly. > > This is the most confused summary of byte sex I've ever read. > There is no such thing as "correct math order" (numbers are numbers). "...number are numbers..." Nope! Numbers represented as characters may be in ASCII but you should take a look at at IBM mainframes. They use EBCDIC and the 'numbers' are different bit patterns. Has anyone taken the time to read the IEEE floating point specs? To an electronic calculating machine, internally everything is a bit. Bytes are a group of bits and the CPU structure determines what a given bit pattern is. The computer has no notion of number, character or program instruction. It only knows what it is told. Try this - set the next instruction (jump) to a data value and watch the machine try to execute it as a program instruction. (I assume you can program in assembly. If not - don't tell because 'REAL programmers do assembly'. I think the last time I used it was 1980 or so. The program ran until the last of the hardware died and replacements could not be found. The client hired another to write for the new machines and closed shop shortly after. I think the owner was tired and found an excuse to retire. :) > The '\n\r' vs. '\r\n' has _nothing_ to do with little-endian vs. > big-endian. By the way, there are great arguments for each order, > and no clear winner. I don't care. Not the point. Point is some people get it fouled up and cause others problems. Test for both. You will save yourself a great deal of trouble in the long run. > Network order was defined for sending numbers > across a wire, the idea was that you'd unpack them to native order > as you pulled the data off the wire. "... sending BINARY FORMATTED numbers..." (verses character - type'able) Network order was defined to reduce machine time. Since the servers that worked day in and day out were SUN, SUN order won. I haven't used EBCDIC in so long I really don't remember for sure but it seems to me they used SUN order before SUN was around. Same for the VAX, I think. > > The '\n\r' vs. '\r\n' differences harken back to the days when they were > format effectors (carriage return moved the carriage to the extreme > left, line feed advanced the paper). You needed both to properly > position the print head. Yep. There wasn't enough intelligence in the old printers to 'cook" the stream. > ASCII uses the pair, and defined the effect > of each. Actually the Teletype people defined most of the \x00 - \x1f concepts. If I remember the trivia correctly - original teletype was 6 bit bytes. Bit pattern was neither ASCII nor EBCDIC. Both of those adopted the teletype control-character concept. > As ASCII was being worked out, MIT even defined a "line > starve" character to move up one line just as line feed went down one. > The order of the format effectors most used was '\r\n' because the > carriage return involved the most physical motion on many devices, and > the vertical motion time of the line feed could happen while the > carriage was moving. True. My experiment with reversing the two instructions would sometimes cause the printer to malfunction. One of my first 'black boxes' (filters) included instructions to see and correct the "wrong" pattern. Then I had to modify it to allow pure binary to get 'pictures' on the dot matrix types. > After that, you often added padding bytes > (typically ASCII NUL ('\x00') or DEL ('\x7F')) to allow the hardware > time to finish before you the did spacing and printing. > If I remember correctly: ASCII NULL x00 In my opinion, NULL should be none set :) IBM NULL x80 IBM card 80 Cols Sperry-Rand x90 S/R Card 90 Cols Trivia question: Why is a byte 8 bits? Ans: people have 10 fingers and the hardware to handle morse code (single wire - serial transfers) needed timers. 1-start, 8 data, 1-stop makes it a count by ten. Burroughs had 10 bits but counting by 12s just didn't come 'naturally'. That was the best answer I've heard to date. In reality - who knows? '...padding...' I never did. Never had to. Printers I used had enough buffer to void that practice. Thirty two character buffer seemed to be enough to disallow overflow. Of course we were using 300 to 1200 BAUD and DTR (pin 19 in most cases) -OR- the RTS and CTS pair of wires to control flow since ^S/^Q could be a valid dot matrix byte(s). Same for hardwired PIP or Kermit transfers. > --Scott David Daniels > Scott.Daniels at Acm.Org > From tjreedy at udel.edu Tue Jun 16 20:02:31 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Jun 2009 20:02:31 -0400 Subject: python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored In-Reply-To: <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> References: <4A356E9B.30806@pooryorick.com> <19e2fc30-0a17-4964-98e4-29576ae03f65@y10g2000prc.googlegroups.com> <27d4ce07-3802-4193-afd0-050cd2b4d1fb@z16g2000prd.googlegroups.com> Message-ID: John Machin wrote: >> Yes, I forgot that >> Exception TypeError: "'NoneType' object is not callable" in ignored >> >> should be parsed as >> >> '''Exception TypeError: "'NoneType' object is not callable" in''' [was] >> ignored >> >> rather than read as >> >> Exception TypeError: "'NoneType' object is not callable" in ignored > > Yep, it's not the clearest message I've ever seen, and it gives no > clue as to who or what is doing the ignoring. Here's a suggestion for > your enhancement request: > > Shutdown ignored this exception: TypeError: "'NoneType' object is not > callable" http://bugs.python.org/issue6294 From davea at ieee.org Tue Jun 16 20:06:30 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Jun 2009 20:06:30 -0400 Subject: Executing a python script while it is running In-Reply-To: References: <4A381FBE.9040003@ieee.org> Message-ID: <4A383386.10409@ieee.org> Zach Hobesh wrote: >> A lot more information would be useful. What version of Python, and what >> operating system environment? Exactly what would you like to happen when >> the batch file is invoked a second time? >> > > I'm running Python 2.6.2 on Windows. I'm passing filenames to the > batch files and I need all filenames to be processed. I can't have > any fails. I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > > >> 2) let them both run as separate processes >> > > This sounds like a good option, but I'm not totally sure on how to go > about this? > > >> 4) queue something to be processed when the first run finishes >> > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. > > >> What provisions does this existing application have for long-running batch >> files? Seems the synchronization ought to happen there. Do you have any >> constraints on how long your script might take, worst case? What if the >> application finishes its tasks at a faster average rate than your script can >> process them? >> > > The batch file is moving large video files. Duration probably ranges > from 10 sec to 45 mins. On average, the application takes longer to > process the files than it does the batch file/python script takes to > copy them, but I'm concerned about the occasional time that the > application finishes a small file right after finishing a large file. > > Thanks for your response! > > -Zach > > Option 2 is what you get by default. Naturally it depends on what the application is using to launch the batch file, but the most common cases will launch a separate process. That means most of python will work fine; the only likely conflict you'll have is if one script is trying to move or copy the same file the other one is doing. So I'd suggest you do a rename (which I believe is atomic on all the platforms) of the source file, then do the move. Notice that if the destination is on the same physical volume, you can just "rename" it directly to the final location, at least on Windows. Such a rename is essentially instantaneous, regardless of file size. For option 4, you could just have the batch file launch a script that moves the file locally into a standard place, then the all-day-long (background) script will actually do the slow move on any file it spots in the special directory. If you need more information, you could add also create a text file that identifies the other parameters to go with the file. In any case, the background script would poll the directory for work to do, do it, then check again. Any time the poll fails, just sleep for 30 seconds or so. From mdaglow at daglowconsulting.com Tue Jun 16 20:21:49 2009 From: mdaglow at daglowconsulting.com (Marta Daglow) Date: Tue, 16 Jun 2009 20:21:49 -0400 Subject: Looking for top web engineers In-Reply-To: References: Message-ID: Hi, One of my clients is looking for three top web developers (engineers) to build a new video platform from scratch. Wouldn't it be nice to build this system without having to work with legacy code or systems? They are part of a major organization and have deep funding. We're looking for someone who is team player and who loves to work with other very smart engineers. Top pay, benefits and cool SF Bay Area location. Are you interested or know of someone who would be? If you would like to know more, please email me and we can set up a time to talk. Kind Regards, Marta Daglow | Managing Partner - HR Consulting Daglow Consulting Group | 415.461.5845 mdaglow at daglowconsulting.com Recruit - Retain - Inspire From Eric_Dexter at msn.com Tue Jun 16 20:56:34 2009 From: Eric_Dexter at msn.com (edexter) Date: Tue, 16 Jun 2009 17:56:34 -0700 (PDT) Subject: first full alpha release of PyLab_Works v0.3 References: Message-ID: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> On Jun 16, 12:27?pm, Stef Mientki wrote: > hello, > > I am pleased to announce the first full alpha release of PyLab_Works, v0.3. > > PyLab_Works is a modular Visual Development Environment, based on > data-flow programming technics. PyLab_Works is specially aimed at > Education, Engineering and Science. The ideas behind PyLab_Works are, > that the final user should not be burdened with programming details and > domain details, whereas the domain expert should be able to implement > the specific ?domain knowledge without being a full educated programmer. > > You can always find my notes on PyLab_Works on > ? ?http://pic.flappie.nl > Most of these pages are also collected in a single pdf document, which > can be found here: > ?http://pylab-works.googlecode.com/files/pw_manual.pdf > > The source code and a one-button-Windows-Installer can be found on > codegoogle: > ?http://code.google.com/p/pylab-works/ > The files are rather large, because they contain some data samples. > The Windows-Installer contains everything you need to get started with > PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, ? > Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, > Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. > Although the PyLab_Works programs are compiled with Py2Exe, all the > source files are explicitly included. > > have fun, > Stef Mientki program didn't start because .dll is missing (sorry I don't have the name)... I don't know if that is just an issue with the installer with vista or not (missing msv something 71. dll) From hobesh at gmail.com Tue Jun 16 21:21:56 2009 From: hobesh at gmail.com (hobesh at gmail.com) Date: Wed, 17 Jun 2009 01:21:56 +0000 Subject: Executing a python script while it is running In-Reply-To: <4A383386.10409@ieee.org> Message-ID: <001636456fe6019056046c811e8c@google.com> Hey Dave, Thanks for the helpful responses. > Option 2 is what you get by default. Naturally it depends on what the > application is using to launch the batch file, but the most common cases > will launch a separate process. The app ended up delaying starting the second batch file until it finished the first. I had the app trigger an infinite loop on completion, and sent two files through at the same time. The second file finished seconds after the first, but the batch file didn't trigger until I closed the first one. > For option 4, you could just have the batch file launch a script that > moves the file locally into a standard place, then the all-day-long > (background) script will actually do the slow move on any file it spots > in the special directory. If you need more information, you could add > also create a text file that identifies the other parameters to go with > the file. In any case, the background script would poll the directory for > work to do, do it, then check again. Any time the poll fails, just sleep > for 30 seconds or so. I just tried a simple test with this basic outline, and it seemed to work fine. I had the app write a batch file and throw that batch file into the special directory. The background script grabbed the batch files and ran them in order of time created. Still not sure what the best option is. I'm not sure what will happen if I just let the app regulate itself, so I may go with option 4. Thanks again! -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Jun 16 21:37:53 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Jun 2009 18:37:53 -0700 Subject: Executing a python script while it is running In-Reply-To: <001636456fe6019056046c811e8c@google.com> References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> Message-ID: <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> On Tue, Jun 16, 2009 at 6:21 PM, wrote: > Hey Dave, > > Thanks for the helpful responses. > >> Option 2 is what you get by default. ?Naturally it depends on what the >> application ?is using to launch the batch file, but the most common cases >> will launch a separate process. > > The app ended up delaying starting the second batch file until it finished > the first. I had the app trigger an infinite loop on completion, and sent > two files through at the same time. The second file finished seconds after > the first, but the batch file didn't trigger until I closed the first one. Are you sure you aren't unknowingly having the app wait on the first batch file process until it terminates? How exactly are you launching the batch files? Cheers, Chris -- http://blog.rebertia.com From alan.isaac at gmail.com Tue Jun 16 21:50:55 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 01:50:55 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: Message-ID: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> On 6/13/2009 2:11 PM kj apparently wrote: > Switching from Perl here, and having a hard time letting go... > > Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, > second, and last element in that array. In Perl I could write: > > my @wanted = @foo[3, 7, 1, -1]; >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a[[3,7,1,-1]] array([3, 7, 1, 9]) hth, Alan Isaac From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:14:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:14:34 GMT Subject: Perl's @foo[3,7,1,-1] ? References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> Message-ID: On Wed, 17 Jun 2009 01:50:55 +0000, Alan G Isaac wrote: > On 6/13/2009 2:11 PM kj apparently wrote: >> Switching from Perl here, and having a hard time letting go... >> >> Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, >> second, and last element in that array. In Perl I could write: >> >> my @wanted = @foo[3, 7, 1, -1]; > >>>> a = np.arange(10) >>>> a > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>>> a[[3,7,1,-1]] > array([3, 7, 1, 9]) > > hth, > Alan Isaac What's np.arange? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:20:27 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:20:27 GMT Subject: doctests and decorators References: <7e9b5828-85c9-4850-9f09-f6f1e995462f@j9g2000prh.googlegroups.com> <967d5ac0-5cba-49ea-b118-375752e99188@j18g2000yql.googlegroups.com> Message-ID: On Tue, 16 Jun 2009 12:04:32 -0700, Scott David Daniels wrote: > Eric Snow wrote: >> In general should decorators always hide themselves? I am guessing >> not, otherwise this would already be part of their behavior. Still, is >> it the common case to camouflage the decorator like this? If so, I >> would expect it to be the default behavior of decorators. > > The Python goal is "no magic". So, if you want the stuff wrapped, you > do it (as the default traceback shows where the code actually goes). It > would be far more complicated to display the truth if decorators > defaulted to modifying the builtins, and you had to do magic to remove > that part of the decoration. I'm afraid I can't understand what you're saying. What do you consider "magic"? What's a "default traceback"? What do you mean, "display the truth"? > A decorator has _very_ simple semantics, > while anything that automatically copied attributes would have funny > semantics indeed for use by funny decorators like: [...] functools.wraps() automatically copies attributes: >>> import functools >>> def dec(func): ... @functools.wraps(func) ... def inner(*args): ... return func(args) + 1 ... return inner ... >>> def f(x): ... return 1 ... >>> f.attr = "Attribute" >>> f = dec(f) >>> f(3) 2 >>> f.attr 'Attribute' -- Steven From Nikolaus at rath.org Tue Jun 16 22:22:31 2009 From: Nikolaus at rath.org (Nikolaus Rath) Date: Tue, 16 Jun 2009 22:22:31 -0400 Subject: Logging multiple lines Message-ID: <87tz2fa9aw.fsf@vostro.rath.org> Hi, Are there any best practices for handling multi-line log messages? For example, the program, main = logging.getLogger() handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) main.addHandler(handler) main.setLevel(logging.DEBUG) main.info("Starting") try: bla = 42/0 except: main.exception("Oops...") generates the log messages 2009-06-16 22:19:57,515 INFO Starting 2009-06-16 22:19:57,518 ERROR Oops... Traceback (most recent call last): File "/home/nikratio/lib/EclipseWorkspace/playground/src/mytests.py", line 27, in bla = 42/0 ZeroDivisionError: integer division or modulo by zero which are a mess in any logfile because they make it really difficult to parse. How do you usually handle multi-line messages? Do you avoid them completely (and therefore also the exception logging facilities provided by logging)? Or is it possible to tweak the formatter so that it inserts the prefix at the beginning of every line? Best, -Nikolaus -- ?Time flies like an arrow, fruit flies like a Banana.? PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C From mk.fraggod at gmail.com Tue Jun 16 22:33:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 08:33:55 +0600 Subject: Newbie help for using multiprocessing and subprocess packages for creating child processes References: Message-ID: <20090617083355.37db565a@malediction> On Tue, 16 Jun 2009 23:20:05 +0200 Piet van Oostrum wrote: > >>>>> Matt (M) wrote: > > >M> Try replacing: > >M> cmd = [ "ls /path/to/file/"+staname+"_info.pf" ] > >M> with: > >M> cmd = [ ?ls?, ?/path/to/file/"+staname+"_info.pf" ] > > In addition I would like to remark that -- if the only thing you want > to do is to start up a new command with subprocess.Popen -- the use > of the multiprocessing package is overkill. You could use threads as > well. > > Moreover, if you don't expect any output from these processes and > don't supply input to them through pipes there isn't even a need for > these threads. You could just use os.wait() to wait for a child to > finish and then start a new process if necessary. And even if there is need to read/write data from/to the pipes more than once (aka communicate), using threads or any more python subprocesses seem like hammering a nail with sledgehammer - just _read_ or _write_ to pipes asynchronously. -- Mike Kazantsev // fraggod.net From lie.1296 at gmail.com Tue Jun 16 22:49:06 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 02:49:06 GMT Subject: Executing a python script while it is running In-Reply-To: References: <4A381FBE.9040003@ieee.org> Message-ID: Zach Hobesh wrote: >> A lot more information would be useful. What version of Python, and what >> operating system environment? Exactly what would you like to happen when >> the batch file is invoked a second time? > > I'm running Python 2.6.2 on Windows. I'm passing filenames to the > batch files and I need all filenames to be processed. I can't have > any fails. I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > >> 2) let them both run as separate processes > > This sounds like a good option, but I'm not totally sure on how to go > about this? For that one, you don't really have to do anything special as long as both program doesn't try to modify the same file at the same time. If the two program need to modify the same file, you need to arrange some coordination, the specifics of which highly depends on what you're trying to do. >> 4) queue something to be processed when the first run finishes > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. You don't necessarily have to have daemon process, cron/scheduled task can do it as well. 5) detect for another process; if there is, sleep until the it terminates, then do the job. If there is a good possibility of 3 or more process, it might be necessary to use a lock file, if the lock file exists, sleep, else create a lock file and do the job. >> What provisions does this existing application have for long-running batch >> files? Seems the synchronization ought to happen there. Do you have any >> constraints on how long your script might take, worst case? What if the >> application finishes its tasks at a faster average rate than your script can >> process them? > > The batch file is moving large video files. Duration probably ranges > from 10 sec to 45 mins. On average, the application takes longer to > process the files than it does the batch file/python script takes to > copy them, but I'm concerned about the occasional time that the > application finishes a small file right after finishing a large file. > > Thanks for your response! > > -Zach From ldo at geek-central.gen.new_zealand Tue Jun 16 22:50:28 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 14:50:28 +1200 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > Lawrence D'Oliveiro writes: > >> I don't think any countable set, even a countably-infinite set, can have >> a fractal dimension. It's got to be uncountably infinite, and therefore >> uncomputable. > > I think the idea is you assume uniform continuity of the set (as > expressed by a parametrized curve). That should let you approximate > the fractal dimension. Fractals are, by definition, not uniform in that sense. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 16 22:51:23 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 02:51:23 GMT Subject: Need to know if a file as only ASCII charaters References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: On Tue, 16 Jun 2009 10:42:58 -0700, Scott David Daniels wrote: > Dave Angel wrote: >> Jorge wrote: >>> Hi there, >>> I'm making a application that reads 3 party generated ASCII files, >>> but some >>> times >>> the files are corrupted totally or partiality and I need to know if >>> it's a >>> ASCII file with *nix line terminators. In linux I can run the file >>> command but the applications should run in windows. >>> >>> Any help will be great. >>> >>> Thank you in advance. >>> >>> >> So, which is the assignment: >> 1) determine if a file has non-ASCII characters 2) determine whether >> the line-endings are crlf or just lf >> >> In the former case, look at translating the file contents to Unicode, >> specifying ASCII as source. If it fails, you have non-ASCII In the >> latter case, investigate the 'u' attribute of the mode parameter in the >> open() function. >> >> You also need to ask yourself whether you're doing a validation of the >> file, or doing a "best guess" like the file command. >> >> > Also, realize that ASCII is a 7-bit code, with printing characters all > greater than space, and very few people use delete ('\x7F'), so you can > define a function to determine if a file contains only printing ASCII > and a few control characters. This one is False unless some ink would > be printed. > > Python 3.X: > def ascii_file(name, controls=b'\t\n'): > ctrls = set(controls + b' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) ord('~') >= max(chars) > ) and min(chars - ctrls) > ord(' ') > > Python 2.X: > def ascii_file(name, controls='\t\n'): > ctrls = set(controls + ' ') > with open(name, 'rb') as f: > chars = set(f.read()) > return min(chars) >= min(ctrls) and '~' >= max(chars > ) and min(chars - ctrls) > ' ' > > For potentially more performance (at least on 2.X), you could do min and > max on the data read, and only do the set(data) if the min and max are > OK. You're suggesting that running through the entire data three times instead of once is an optimization? Boy, I'd hate to see what you consider a pessimation! *wink* I think the best solution will probably be a lazy function which stops processing as soon as it hits a character that isn't ASCII. # Python 2.5, and untested def ascii_file(name): from string import printable with open(name, 'rb') as f: for c in f.read(1): if c not in printable: return False return True This only reads the entire file if it needs to, and only walks the data once if it is ASCII. In practice, you may actually get better performance by reading in a block at a time, rather than a byte at a time: # Python 2.5, and still untested def ascii_file(name, bs=65536): # 64K default blocksize from string import printable with open(name, 'rb') as f: text = f.read(bs) while text: for c in text: if c not in printable: return False text = f.read(bs) return True -- Steven From ldo at geek-central.gen.new_zealand Tue Jun 16 22:52:28 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 14:52:28 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> Message-ID: In message <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, thebjorn wrote: > Not proud of this, but...: > > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l > 174197 > > all .jpg files between 40 and 250KB with the path stored in a database > field... *sigh* Why not put the images themselves into database fields? > Oddly enough, I'm a relieved that others have had similar folder sizes ... One of my past projects had 400000-odd files in a single folder. They were movie frames, to allow assembly of movie sequences on demand. From wolfgang at rohdewald.de Tue Jun 16 23:13:11 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Jun 2009 05:13:11 +0200 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <200906170513.11804.wolfgang@rohdewald.de> On Wednesday, 17. June 2009, Steven D'Aprano wrote: > while text: > for c in text: > if c not in printable: return False that is one loop per character. wouldn't it be faster to apply a regex to text? something like while text: if re.search(r'\W',text): return False -- Wolfgang From mk.fraggod at gmail.com Tue Jun 16 23:18:58 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 09:18:58 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> Message-ID: <20090617091858.432f89ca@malediction> On Wed, 17 Jun 2009 14:52:28 +1200 Lawrence D'Oliveiro wrote: > In message > <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, > thebjorn wrote: > > > Not proud of this, but...: > > > > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l > > 174197 > > > > all .jpg files between 40 and 250KB with the path stored in a > > database field... *sigh* > > Why not put the images themselves into database fields? > > > Oddly enough, I'm a relieved that others have had similar folder > > sizes ... > > One of my past projects had 400000-odd files in a single folder. They > were movie frames, to allow assembly of movie sequences on demand. For both scenarios: Why not use hex representation of md5/sha1-hashed id as a path, arranging them like /path/f/9/e/95ea4926a4 ? That way, you won't have to deal with many-files-in-path problem, and, since there's thousands of them anyway, name readability shouldn't matter. In fact, on modern filesystems it doesn't matter whether you accessing /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea with only hundred of them in each path. Former case (all-in-one-path) would even outperform the latter with ext3 or reiserfs by a small margin. Sadly, that's not the case with filesystems like FreeBSD ufs2 (at least in sixth branch), so it's better to play safe and create subdirs if the app might be run on different machines than keeping everything in one path. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From mk.fraggod at gmail.com Tue Jun 16 23:24:13 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 09:24:13 +0600 Subject: Logging multiple lines References: <87tz2fa9aw.fsf@vostro.rath.org> Message-ID: <20090617092413.7da4f164@malediction> On Tue, 16 Jun 2009 22:22:31 -0400 Nikolaus Rath wrote: > How do you usually handle multi-line messages? Do you avoid them > completely (and therefore also the exception logging facilities > provided by logging)? Or is it possible to tweak the formatter so > that it inserts the prefix at the beginning of every line? I'd log exception name and timestamp (or id) only, pushing the full message with the same id to another log or facility (like mail it to some dedicated bug-report box). -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From lie.1296 at gmail.com Tue Jun 16 23:30:29 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:30:29 GMT Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Scott David Daniels wrote: > norseman wrote: >> Scott David Daniels wrote: >>> Dave Angel wrote: >>>> Jorge wrote: ... >>>>> I'm making a application that reads 3 party generated ASCII files, >>>>> but some times the files are corrupted totally or partiality and I >>>>> need to know if it's a ASCII file with *nix line terminators. >>>>> In linux I can run the file command but the applications should run in >>>>> windows. >> you are looking for a \x0D (the Carriage Return) \x0A (the Line feed) >> combination. If present you have Microsoft compatibility. If not you >> don't. If you think High Bits might be part of the corruption, filter >> each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10) >> then check for the \x0D \x0A combination. > > Well ASCII defines a \x0D as the return code, and \x0A as line feed. > It is unix that is wrong, not Microsoft (don't get me wrong, I know > Microsoft has often redefined what it likes invalidly). The \r\n was originally a hack because teletype machines can only do one thing at a time (i.e. do a line feed NAND carriage return) and trying to do both at the same time or the wrong order would trigger a bug that sends a HCF instruction on many ancient teletypes. Unix decided that in virtual terminal, \r\n is unnecessary and redundant since VTs can do both in a single instruction. We can argue that Microsoft is "foolish consistency" here or Unix is changing standards just for saving a few bytes, but objectively neither side is right or wrong since the problem was a hack in the first place. If anyone is wrong, it is Mac that decided to use \r when Unix have already decided which characters to abandon (or maybe it's their usual reason: "different just because we want to be different") From lie.1296 at gmail.com Tue Jun 16 23:34:51 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:34:51 GMT Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: Wolfgang Rohdewald wrote: > On Wednesday, 17. June 2009, Steven D'Aprano wrote: >> while text: >> for c in text: >> if c not in printable: return False > > that is one loop per character. unless printable is a set > wouldn't it be faster to apply a regex to text? > something like > > while text: > if re.search(r'\W',text): return False > regex? Don't even start... Anyway, only cProfile and profile would know who is the fastest... And, is speed really that important for this case? Seems like premature optimization to me. From higerinbeijing at gmail.com Tue Jun 16 23:40:00 2009 From: higerinbeijing at gmail.com (higer) Date: Tue, 16 Jun 2009 20:40:00 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? Message-ID: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> My Python version is 2.5.2; When I reading the bytecode of some pyc file, I always found that there are many jump command from different position,but to the same position. You can see this situation in following code(this bytecode is just from one .pyc file and I don't have its source .py file): ..... 526 POP_TOP '' 527 LOAD_FAST 'imeHandle' 530 LOAD_ATTR 'isCnInput' 533 CALL_FUNCTION_0 '' 536 JUMP_IF_FALSE '574' 539 POP_TOP '' 540 LOAD_FAST 'GUIDefine' 543 LOAD_ATTR 'CandidateIsOpen' 546 JUMP_IF_TRUE '574' 549 POP_TOP '' 550 LOAD_FAST 'GUIDefine' 553 LOAD_ATTR 'CompositionWndIsOpen' 556 JUMP_IF_TRUE '574' 559 POP_TOP '' 560 LOAD_FAST 'isWanNengWB' 563 JUMP_IF_FALSE '574' 566 POP_TOP '' 567 LOAD_FAST 'state' 570 LOAD_CONST 1 573 BINARY_AND '' 574_0 COME_FROM '' 574_1 COME_FROM '' 574_2 COME_FROM '' 574_3 COME_FROM '' ... >From the above bytecode,we know that line 574 is the point that many position jumps to.So,it just looks like the 'goto' function in C, but we know that there is none such function in Python. One 'JUMP**' command is companied with a 'COME_FROM' command,so more than one 'COME_FROM' OPs are listed on line 574... But ,the question is, I have tried a lot of ways(e.g.for loop,while loop and mixed) to re-present 'goto' style bytecodes like this, but the result depressed me. So,I think maybe it is just a compiler optimization in Python2.5? I'm not sure,so I'm appreciated that if anyone can help me. From lie.1296 at gmail.com Tue Jun 16 23:42:02 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:42:02 GMT Subject: walking a directory with very many files In-Reply-To: <20090617091858.432f89ca@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >>> Not proud of this, but...: >>> >>> [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >>> 174197 >>> >>> all .jpg files between 40 and 250KB with the path stored in a >>> database field... *sigh* >> Why not put the images themselves into database fields? >> >>> Oddly enough, I'm a relieved that others have had similar folder >>> sizes ... >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > > That way, you won't have to deal with many-files-in-path problem, and, > since there's thousands of them anyway, name readability shouldn't > matter. > > In fact, on modern filesystems it doesn't matter whether you accessing > /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea > with only hundred of them in each path. Former case (all-in-one-path) > would even outperform the latter with ext3 or reiserfs by a small > margin. > Sadly, that's not the case with filesystems like FreeBSD ufs2 (at least > in sixth branch), so it's better to play safe and create subdirs if the > app might be run on different machines than keeping everything in one > path. > It might not matter for the filesystem, but the file explorer (and ls) would still suffer. Subfolder structure would be much better, and much easier to navigate manually when you need to. From lie.1296 at gmail.com Tue Jun 16 23:47:00 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 03:47:00 GMT Subject: Logging multiple lines In-Reply-To: <87tz2fa9aw.fsf@vostro.rath.org> References: <87tz2fa9aw.fsf@vostro.rath.org> Message-ID: Nikolaus Rath wrote: > Hi, > > Are there any best practices for handling multi-line log messages? > > For example, the program, > > main = logging.getLogger() > handler = logging.StreamHandler() > handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) > main.addHandler(handler) > main.setLevel(logging.DEBUG) > main.info("Starting") > try: > bla = 42/0 > except: > main.exception("Oops...") > > generates the log messages > > 2009-06-16 22:19:57,515 INFO Starting > 2009-06-16 22:19:57,518 ERROR Oops... > Traceback (most recent call last): > File "/home/nikratio/lib/EclipseWorkspace/playground/src/mytests.py", line 27, in > bla = 42/0 > ZeroDivisionError: integer division or modulo by zero > > > which are a mess in any logfile because they make it really difficult to > parse. > > > How do you usually handle multi-line messages? Do you avoid them > completely (and therefore also the exception logging facilities provided > by logging)? Or is it possible to tweak the formatter so that it inserts > the prefix at the beginning of every line? > > The next line that starts with a timestamp is part of the next log. If you added timestamp on every line, that would be much more difficult to parse. You could do something like: import re timestamp_re = '...' messages = [] for line in open('log.log'): if timestamp_re.match(line): messages.append([line]) else: messages[-1].append(line) From delroth at gmail.com Tue Jun 16 23:47:47 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Wed, 17 Jun 2009 05:47:47 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> Message-ID: <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > What's np.arange? import numpy as np -- Pierre "delroth" Bourdon ?tudiant ? l'EPITA / Student at EPITA From warhammer1805 at gmail.com Wed Jun 17 00:05:43 2009 From: warhammer1805 at gmail.com (python-newbie113) Date: Tue, 16 Jun 2009 21:05:43 -0700 (PDT) Subject: Newbie question about method options Message-ID: I am new to python and have a question about using methods. Here is the link i am looking at: http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm If i use, create_arc(bbox, options) => id what is id? and how do i find the parameter list representing options? Thanks for help in advance Andrew From usernet at ilthio.net Wed Jun 17 00:32:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Wed, 17 Jun 2009 04:32:16 GMT Subject: Newbie question about method options References: Message-ID: On 2009-06-17, python-newbie113 wrote: > If i use, create_arc(bbox, options) => id > what is id? and how do i find the parameter list representing options? I am not familiar with tkinker; but, the expression is just showing a function prototype. The function part should be self-explanitory. Judging from statements below like: canvasx(screenx) => float, canvasy(screeny) => float and bbox(items) => tuple, bbox() => tuple and the fact that "id" is mentioned for all of the functions that return a handle, I suspect that the "=>" and what comes after it is just a typographical notation to tell the reader what kind of datatype they can expect the function to return. From mk.fraggod at gmail.com Wed Jun 17 01:07:05 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 11:07:05 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: <20090617110705.7e7c423f@malediction> On Wed, 17 Jun 2009 03:42:02 GMT Lie Ryan wrote: > Mike Kazantsev wrote: > > In fact, on modern filesystems it doesn't matter whether you > > accessing /path/f9e95ea4926a4 with million files in /path > > or /path/f/9/e/95ea with only hundred of them in each path. Former > > case (all-in-one-path) would even outperform the latter with ext3 > > or reiserfs by a small margin. > > Sadly, that's not the case with filesystems like FreeBSD ufs2 (at > > least in sixth branch), so it's better to play safe and create > > subdirs if the app might be run on different machines than keeping > > everything in one path. > > It might not matter for the filesystem, but the file explorer (and ls) > would still suffer. Subfolder structure would be much better, and much > easier to navigate manually when you need to. It's an insane idea to navigate any structure with hash-based names and hundreds of thousands files *manually*: "What do we have here? Hashies?" ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jaime.frio at gmail.com Wed Jun 17 01:35:35 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Wed, 17 Jun 2009 07:35:35 +0200 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <97a8f1a70906162235g6a31eb2fia9683ef9e2c19075@mail.gmail.com> On Wed, Jun 17, 2009 at 4:50 AM, Lawrence D'Oliveiro wrote: > In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, ?wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). ?That should let you approximate >> the fractal dimension. > > Fractals are, by definition, not uniform in that sense. I had my doubts on this statement being true, so I've gone to my copy of Gerald Edgar's "Measure, Topology and Fractal Geometry" and Proposition 2.4.10 on page 69 states: "The sequence (gk), in the dragon construction of the Koch curve converges uniformly." And uniform continuity is a very well defined concept, so there really shouldn't be an interpretation issue here either. Would not stick my head out for it, but I am pretty sure that a continuous sequence of curves that converges to a continuous curve, will do so uniformly. Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From hobesh at gmail.com Wed Jun 17 01:42:44 2009 From: hobesh at gmail.com (Zach Hobesh) Date: Tue, 16 Jun 2009 22:42:44 -0700 Subject: Executing a python script while it is running In-Reply-To: <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> Message-ID: On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > On Tue, Jun 16, 2009 at 6:21 PM, wrote: >> Hey Dave, >> >> Thanks for the helpful responses. >> >>> Option 2 is what you get by default. ?Naturally it depends on what the >>> application ?is using to launch the batch file, but the most common cases >>> will launch a separate process. >> >> The app ended up delaying starting the second batch file until it finished >> the first. I had the app trigger an infinite loop on completion, and sent >> two files through at the same time. The second file finished seconds after >> the first, but the batch file didn't trigger until I closed the first one. > > Are you sure you aren't unknowingly having the app wait on the first > batch file process until it terminates? How exactly are you launching > the batch files? > > Cheers, > Chris > -- > http://blog.rebertia.com Hey Chris, I actually think that's what's happening, which is fine in my case (for now anyway) as I just need them all to complete, we don't need them running at the same time. I'm using a job management system, and they have the option of triggering a command line after completing a job. A better/safer solution might be spawning another job and re-inserting to the jms queue. Thanks again, Zach From tkjthingone at gmail.com Wed Jun 17 01:43:08 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Tue, 16 Jun 2009 22:43:08 -0700 Subject: Tool for browsing python code In-Reply-To: References: <4A3794A9.5080309@gmail.com> <3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com> <20090616163821.c3c9d48d.darcy@druid.net> Message-ID: On Tue, Jun 16, 2009 at 3:15 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > >> "D'Arcy J.M. Cain" writes: > >> >> not sure if there are any "curses" base TUI's (!) for Python. > >> > vi > >> > >> emacs :) > > > > Hey, it was all pretty civil up till now. ;) > > I've heard from my cousin that his former high school classmate's > uncle did a research on a large statistical sample of programmers and > found that emacs users' brains are about 12% smaller than vi users' :) > > Cheers, > Daniel > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > I'm afraid it's the other way around, really. You see, emacs contains 5 characters, thus requiring MORE brainpower to understand, where as vi is only 2 characters, requiring LESS brainpower. It's like that old joke. Why do blondes move to L.A? Because it's easy to spell. I guess what I'm saying is vi users are blondes. :) *crosses fingers and hopes he posted to the list this time* -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Wed Jun 17 01:45:23 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:45:23 +1200 Subject: walking a directory with very many files References: Message-ID: In message , Jean-Paul Calderone wrote: > The problem is that POSIX specifies the fields with types like off_t and > ino_t. Since ctypes doesn't know anything about these types, application > code has to specify their size and other attributes. As these vary from > platform to platform, you can't get it correct without asking a real C > compiler. Just to add to the complications, on 32-bit platforms, off_t can be either 64 bits or 32 bits, depending on whether a C program is compiled with -D_FILE_OFFSET_BITS=64 or not. This causes all kinds of aliasing of POSIX routines to the appropriate variants of the underlying libc routine names. With ctypes, you have to directly access the underlying routine names, unless you implement some kind of equivalent aliasing scheme on top. From mr.william.clifford at gmail.com Wed Jun 17 01:46:14 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Tue, 16 Jun 2009 22:46:14 -0700 (PDT) Subject: Exotic Logics Message-ID: I was staring at a logic table the other day, and I asked myself, "what if one wanted to play with exotic logics; how might one do it?" I did some searching but not being too sure of what to look for and carried away with my own enthusiasm for the idea, I didn't find much. What I've come up with is, no doubt, inefficient, naive, poor python style, and probably wrong in fundamental ways too subtle for me, but here it is: import itertools import operator class Logic(): """class of generic logic operators""" @staticmethod def lsd(rdx, n): """yield up base rdx digits of n in least significant order""" while n > 0: q, r = divmod(n, rdx) n = q yield r @staticmethod def rdxn(rdx, seq): """reduce a sequence of numbers by powers of rdx""" return reduce(operator.add, map(operator.mul, seq, (pow(rdx, i) for i in range(len(seq))))) @staticmethod def pute(rdx, opr, arg): """a logical primitive which returns 0 or 1.""" if arg < 0: return 0 o = tuple(lsd(rdx, opr)) try: return o[arg] except IndexError: return 0 @staticmethod def make_puter(rdx, opr): """return a function based on pute.""" o = tuple(Logic.lsd(rdx, opr)) def puter(arg): if arg < 0: return 0 try: return o[arg] except IndexError: return 0 return puter @staticmethod def make_inputs(rdx, *args): """yield a stripe of rdxn digits from args.""" largs = [Logic.lsd(rdx, a) for a in args] for i in itertools.izip_longest(*largs, fillvalue=0): yield Logic.rdxn(rdx, i) @staticmethod def compute(rdx, opr, *args): """return a number computed from opr of rdx.""" puter = Logic.make_puter(rdx, opr) inputs = Logic.make_inputs(rdx, *args) outputs = [puter(i) for i in inputs] return Logic.rdxn(rdx, outputs) @staticmethod def make_computer(rdx, opr): """return a computer of opr, rdx.""" def computer(*args): puter = Logic.make_puter(rdx, opr) inputs = Logic.make_inputs(rdx, *args) outputs = [puter(i) for i in inputs] return Logic.rdxn(rdx, outputs) return computer def __init__(self, rdx, opr): self._computer = Logic.make_computer(rdx, opr) def __call__(self, *args): return self._computer(*args) This seemed to be working for the limited tests I did on it, while I was doing them. The following checked out last time I tried: >>> and_ = Logic(2, 8) >>> or_ = Logic(2, 14) >>> xor = Logic(2, 6) I have no idea how to validate the results of the trinary and beyond logics. Thanks for reading and trying this out. Corrections? Criticism? Comments? -- William Clifford From ldo at geek-central.gen.new_zealand Wed Jun 17 01:49:59 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:49:59 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In message , Phil Runciman wrote: > FWIW I actually dislike this book! Why? From ldo at geek-central.gen.new_zealand Wed Jun 17 01:51:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:51:12 +1200 Subject: SIP v4.8.1 Released References: Message-ID: In message , Phil Thompson wrote: > SIP is a tool for generating Python modules that wrap C or C++ libraries. > It is similar to SWIG. It is used to generate PyQt and PyKDE. I find the name confusing. Every time I hear it I think "Session Initiation Protocol". OK, so I've been spending too much time with Asterisk. So sue me. :) From ldo at geek-central.gen.new_zealand Wed Jun 17 01:52:30 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:52:30 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: In message , Steven D'Aprano wrote: > On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: > >> In message , Piet van Oostrum wrote: >> >>> The exact time of the destruction of objects is an implementation >>> detail and should not be relied upon. >> >> That may be true in Java and other corporate-herd-oriented languages, >> but we know that dynamic languages like Perl and Python make heavy use >> of reference-counting wherever they can. If it's easy to satisfy >> yourself that the lifetime of an object will be delimited in this way, I >> don't see why you can't rely upon it. > > Reference counting is an implementation detail used by CPython but not > [implementations built on runtimes designed for corporate-herd-oriented > languages, like] IronPython or Jython. I rest my case. From ldo at geek-central.gen.new_zealand Wed Jun 17 01:53:33 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 17:53:33 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: In message <20090617091858.432f89ca at malediction>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >> > Not proud of this, but...: >> > >> > [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >> > 174197 >> > >> > all .jpg files between 40 and 250KB with the path stored in a >> > database field... *sigh* >> >> Why not put the images themselves into database fields? >> >> > Oddly enough, I'm a relieved that others have had similar folder >> > sizes ... >> >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > > That way, you won't have to deal with many-files-in-path problem ... Why is that a problem? From http Wed Jun 17 02:04:11 2009 From: http (Paul Rubin) Date: 16 Jun 2009 23:04:11 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <7xd493v1k4.fsf@ruckus.brouhaha.com> Jaime Fernandez del Rio writes: > I am pretty sure that a continuous sequence of > curves that converges to a continuous curve, will do so uniformly. I think a typical example of a curve that's continuous but not uniformly continuous is f(t) = sin(1/t), defined when t > 0 It is continuous at every t>0 but wiggles violently as you get closer to t=0. You wouldn't be able to approximate it by sampling a finite number of points. A sequence like g_n(t) = sin((1+1/n)/ t) for n=1,2,... obviously converges to f, but not uniformly. On a closed interval, any continuous function is uniformly continuous. From http Wed Jun 17 02:13:41 2009 From: http (Paul Rubin) Date: 16 Jun 2009 23:13:41 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: <7x7hzbv14a.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > > Reference counting is an implementation detail used by CPython but not > > [implementations built on runtimes designed for corporate-herd-oriented > > languages, like] IronPython or Jython. > > I rest my case. You're really being pretty ignorant. I don't know of any serious Lisp system that uses reference counting, both for performance reasons and to make sure cyclic structures are reclaimed properly. Lisp is certainly not a corporate herd language. Even CPython doesn't rely completely on reference counting (it has a fallback gc for cyclic garbage). Python introduced the "with" statement to get away from the kludgy CPython programmer practice of opening files and relying on the file being closed when the last reference went out of scope. From timr at probo.com Wed Jun 17 02:16:43 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:16:43 -0700 Subject: parsing json using simplejson References: <8b8aa836-1493-46a6-ace6-b2581fe77e30@z20g2000prh.googlegroups.com> <20090615220344.7585cb9b@coercion> <05bbda9b-864d-4654-88e2-6148bb23723a@z20g2000prh.googlegroups.com> Message-ID: deostroll wrote: > >I want to be able to parse it into python objects. Any ideas? What did you not like about the very useful replies you have already received? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 02:16:54 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 06:16:54 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> Message-ID: On Wed, 17 Jun 2009 17:52:30 +1200, Lawrence D'Oliveiro wrote: > In message , > Steven D'Aprano wrote: > >> On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote: >> >>> In message , Piet van Oostrum wrote: >>> >>>> The exact time of the destruction of objects is an implementation >>>> detail and should not be relied upon. >>> >>> That may be true in Java and other corporate-herd-oriented languages, >>> but we know that dynamic languages like Perl and Python make heavy use >>> of reference-counting wherever they can. If it's easy to satisfy >>> yourself that the lifetime of an object will be delimited in this way, >>> I don't see why you can't rely upon it. >> >> Reference counting is an implementation detail used by CPython but not >> [implementations built on runtimes designed for corporate-herd-oriented >> languages, like] IronPython or Jython. > > I rest my case. CLPython and Unladen Swallow do not use reference counting. I suppose you might successfully argue that Lisp is a corporate-herd-oriented language, and that Google (the company behind Unladen Swallow) is a corporate-herd. But PyPy doesn't use reference counting either. Perhaps you think that Python is a language designed for corporate-herds too? -- Steven From timr at probo.com Wed Jun 17 02:18:29 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:18:29 -0700 Subject: How to get the total size of a local hard disk? References: <1246fb94-1917-4899-bfba-8733a8bc1c22@37g2000yqp.googlegroups.com> Message-ID: willgun wrote: > >Unfortunately,I'm on win32. >Actually,I prefer a cross-platform method. Why do you need this? This kind of information is not very useful in a cross-platform application. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From deets at nospam.web.de Wed Jun 17 02:21:40 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Jun 2009 08:21:40 +0200 Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? In-Reply-To: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: <79rgbkF1rcncsU1@mid.uni-berlin.de> higer schrieb: > My Python version is 2.5.2; When I reading the bytecode of some pyc > file, I always found that there are many jump command from different > position,but to the same position. You can see this situation in > following code(this bytecode is just from one .pyc file and I don't > have its source .py file): > > ..... > 526 POP_TOP '' > 527 LOAD_FAST 'imeHandle' > 530 LOAD_ATTR 'isCnInput' > 533 CALL_FUNCTION_0 '' > 536 JUMP_IF_FALSE '574' > 539 POP_TOP '' > 540 LOAD_FAST 'GUIDefine' > 543 LOAD_ATTR 'CandidateIsOpen' > 546 JUMP_IF_TRUE '574' > 549 POP_TOP '' > 550 LOAD_FAST 'GUIDefine' > 553 LOAD_ATTR 'CompositionWndIsOpen' > 556 JUMP_IF_TRUE '574' > 559 POP_TOP '' > 560 LOAD_FAST 'isWanNengWB' > 563 JUMP_IF_FALSE '574' > 566 POP_TOP '' > 567 LOAD_FAST 'state' > 570 LOAD_CONST 1 > 573 BINARY_AND '' > 574_0 COME_FROM '' > 574_1 COME_FROM '' > 574_2 COME_FROM '' > 574_3 COME_FROM '' > ... > > From the above bytecode,we know that line 574 is the point that many > position jumps to.So,it just looks like the 'goto' function in C, but > we know that there is none such function in Python. > One 'JUMP**' command is companied with a 'COME_FROM' command,so more > than one 'COME_FROM' OPs are listed on line 574... > > But ,the question is, I have tried a lot of ways(e.g.for loop,while > loop and mixed) to re-present 'goto' style bytecodes like this, but > the result depressed me. > So,I think maybe it is just a compiler optimization in Python2.5? I'm > not sure,so I'm appreciated that if anyone can help me. Getting a depression because of a compiler is a bit strong... However, yes, bytecode is similar to assembler, and in that respect higher-level control-structures are created using (conditional) jumps. The same is true for other bytecode-languages, see here for the JVM: http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493 Diez From darwin at nowhere.com Wed Jun 17 02:23:53 2009 From: darwin at nowhere.com (Paul Hemans) Date: Wed, 17 Jun 2009 16:23:53 +1000 Subject: Managing a multiple threaded service Message-ID: Hi, New to Python .... I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site for data. I want to run the program as a windows service. My questions are: Should both of them run as threads and then just have an infinite loop with a sleep in the main thread in order to stop the main program from just terminating? Or should I choose one of the threads to run as the main program and spawn the other off? That was my original intention, but I am concerned that if I use SimpleHTTPRequestHandler in the main thread, will it block any attempt to terminate the service. Just looking for pointers to the best practice approach. This is where I am at: if __name__=="__main__": import SocketServer import threading import monitor ## Monitor changes on the server (separate thread) monitor = monitor.monitor(fnLog=self.logStatus) monitor.start() ## Service interface port = 8081 server=SocketServer.TCPServer(('',port),ScriptRequestHandler) server.serve_forever() ## To run the web server on a different thread... ## t = threading.Thread(target=server.serve_forever) ## t.setDaemon(True) # don't hang on exit ## t.start() server.socket.close() From timr at probo.com Wed Jun 17 02:24:20 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:24:20 -0700 Subject: simple GUI for my application? References: <226f89b7-41a3-4308-a1ff-4b96c443aaf9@x31g2000prc.googlegroups.com> <803b7da3-f858-4608-b461-de3d85f8a41b@g1g2000yqh.googlegroups.com> Message-ID: Tim Harig wrote: > >IronPython is not a GUI toolkit per se. It is a python implementation >build on top of .Net like Jython is built on top of Java. I therefore has >access to the MFCs which can be used to create native Windows GUIs. That's not correct. MFC is strictly a native C++ concept. IronPython, being a .NET language, has access to the .NET GUIs, which means either Windows Forms or the incredibly powerful Windows Presentation Framework. However, if I may be allowed to express an opinion, if you're going to play in that world, you are swimming upstream unless you write in C#. Otherwise, you end up spending most of your time translating C# concepts into Python. >This can also be done from Cpython using the pywin extensions. Here, you are correct. Pywin32 does include a Python implementation of MFC. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From martin.hellwig at dcuktec.org Wed Jun 17 02:29:07 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 07:29:07 +0100 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: edexter wrote: > On Jun 16, 12:27 pm, Stef Mientki wrote: >> hello, >> >> I am pleased to announce the first full alpha release of PyLab_Works, v0.3. >> >> PyLab_Works is a modular Visual Development Environment, based on >> data-flow programming technics. PyLab_Works is specially aimed at >> Education, Engineering and Science. The ideas behind PyLab_Works are, >> that the final user should not be burdened with programming details and >> domain details, whereas the domain expert should be able to implement >> the specific domain knowledge without being a full educated programmer. >> >> You can always find my notes on PyLab_Works on >> http://pic.flappie.nl >> Most of these pages are also collected in a single pdf document, which >> can be found here: >> http://pylab-works.googlecode.com/files/pw_manual.pdf >> >> The source code and a one-button-Windows-Installer can be found on >> codegoogle: >> http://code.google.com/p/pylab-works/ >> The files are rather large, because they contain some data samples. >> The Windows-Installer contains everything you need to get started with >> PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, >> Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, >> Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. >> Although the PyLab_Works programs are compiled with Py2Exe, all the >> source files are explicitly included. >> >> have fun, >> Stef Mientki > > program didn't start because .dll is missing (sorry I don't have the > name)... I don't know if that is just an issue with the installer > with vista or not (missing msv something 71. dll) You probably mean the microsoft visual C++ runtime (msvcr71.dll), windows vista has a brand new way (via manifest files) to make it more difficult to install compiled binaries. Search for 'Microsoft Visual C++ 2005 Redistributable Package' and install it. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From timr at probo.com Wed Jun 17 02:30:18 2009 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Jun 2009 23:30:18 -0700 Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: higer wrote: > >My Python version is 2.5.2; When I reading the bytecode of some pyc >file, I always found that there are many jump command from different >position,but to the same position. You can see this situation in >following code(this bytecode is just from one .pyc file and I don't >have its source .py file): >... >From the above bytecode,we know that line 574 is the point that many >position jumps to.So,it just looks like the 'goto' function in C, but >we know that there is none such function in Python. >... >But ,the question is, I have tried a lot of ways(e.g.for loop,while >loop and mixed) to re-present 'goto' style bytecodes like this, but >the result depressed me. >So,I think maybe it is just a compiler optimization in Python2.5? I'm >not sure,so I'm appreciated that if anyone can help me. I can't figure out what you're asking here. Are you annoyed that the byte code contains GOTOs? This is a silly thing to worry about. The whole purpose of a compiler is to translate a program express in high-level constructs into a lower-level and more primitive format. The simplest form of an "if" statement or a "while" statement always includes unconditional branches. This exact same thing happens with every compiler. Assembly languages, for example, do not have "if/then/else" instructions, nor "while" instructions, nor "switch" instructions. If you write a C program with an "if" statement, the resulting assembly program will contain a "goto" (usually called "jump" or "branch"). Don't worry about it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Wed Jun 17 02:45:24 2009 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 17 Jun 2009 16:45:24 +1000 Subject: Managing a multiple threaded service In-Reply-To: References: Message-ID: <4A389104.1030308@gmail.com> On 17/06/2009 4:23 PM, Paul Hemans wrote: > Hi, > New to Python .... > I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site > for data. I want to run the program as a windows service. > My questions are: > Should both of them run as threads and then just have an infinite loop with > a sleep in the main thread in order to stop the main program from just > terminating? No need for a loop - just have the main thread wait forever for the stop request. The main problem I forsee is asking the socketserver thread to terminate as it is likely to be inside 'accept' or some other blocking function. HTH, Mark From gabriel.rossetti at arimaz.com Wed Jun 17 03:15:04 2009 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Wed, 17 Jun 2009 09:15:04 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> References: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> Message-ID: <4A3897F8.7070602@arimaz.com> John Machin wrote: > On Jun 17, 1:41 am, Gabriel Rossetti > wrote: > >> Hello everyone, >> >> I get an OperationalError with sqlite3 if I put the wrong column name, >> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it >> says : >> >> > [snip] > >> and to me it sounds more like a programming error than an operational >> error. >> > > How about showing us the code you used and the exact error message and > traceback? > > > Well, the code isn't really relevant to the problem, but here is is : import sqlite3 conn = sqlite3.connect("/tmp/test.db") conn.execute("SELECT name, value FROM local_param") for row in conn: print row And I get : Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: no such table: local_param Which I think should be a ProgrammingError If I fix the table name I but use a wrong column name I also get an OperationalError import sqlite3 conn = sqlite3.connect("/tmp/test.db") conn.execute("SELECT name, valueeeeeeee FROM local_parameters") for row in conn: print row Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: no such column: valueeeeeeee Which should also be a ProgrammingError as I see it and as my interpretation of the documention. Gabriel From wuerzner at gmail.com Wed Jun 17 03:30:22 2009 From: wuerzner at gmail.com (kmw) Date: Wed, 17 Jun 2009 00:30:22 -0700 (PDT) Subject: strange behavior with os.system References: <00830236-4e68-480b-b097-e092a5d99000@l12g2000yqo.googlegroups.com> Message-ID: That's it. I am calling my own program and not coreutils' sort, what explains the unrequested output. Many thanks. Cheers, Kay On 16 Jun., 22:16, Piet van Oostrum wrote: > >>>>> kmw (k) wrote: > >k> Hi, > >k> I wanted to write a simple script (in 5 minutes or so) which replaces > >k> the option '+1' given to the command 'sort' by '-k 2' and than runs > >k> 'sort' with the modified argument list. After two hours I am giving up > >k> and ask you for help. This is what I tried (please excuse the verbose > >k> code, it is due to my various efforts to understand the error): > > [snip] > > >k> Please note the unrequested output of ''. The strange > >k> thing about this all is the fact that ?the whole thing works as > >k> expected when typed ?into the interpreter. I would be glad if anyone > >k> could help. > > MRAB has already given you some insight, I hope. > But are you aware that you are calling your own program again? > Or did you want to call the standard sort program? In that case you > shouldn't call ./sort as it is in argv[0], but just sort (assuming '.' > is not in your PATH) or the full path, like /usr/bin/sort. > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org From mail at microcorp.co.za Wed Jun 17 03:41:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 17 Jun 2009 09:41:18 +0200 Subject: Tool for browsing python code References: <4A3794A9.5080309@gmail.com><3de8e1f70906160555s445cfdefv8499162654183132@mail.gmail.com><20090616163821.c3c9d48d.darcy@druid.net> Message-ID: <00d801c9ef21$daff6660$0d00a8c0@Hendrik> Horace Blegg wrote: >I've heard from my cousin that his former high school classmate's >uncle did a research on a large statistical sample of programmers and >found that emacs users' brains are about 12% smaller than vi users' :) >I'm afraid it's the other way around, really. You see, emacs contains 5 characters, thus requiring MORE >brainpower to understand, where as vi is only 2 characters, requiring LESS brainpower. It's like that old joke. >Why do blondes move to L.A? Because it's easy to spell. I guess what I'm saying is vi users are blondes. :) All this stuff is nonsense. It is a well known fact that the size of your brain is not governed by what editor you use, but by what you drink. The conjecture that some editors might drive you to drink is at the moment only a theory. I am not aware of any hard evidence that correlates hard tack drinking patterns with editor usage. So any research on brain size vs editor usage that does not also include drinking pattern data is essentially invalid. - Hendrik From davea at ieee.org Wed Jun 17 03:43:46 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Jun 2009 03:43:46 -0400 Subject: Newbie question about method options In-Reply-To: References: Message-ID: <4A389EB2.8040409@ieee.org> python-newbie113 wrote: > I am new to python and have a question about using methods. > > Here is the link i am looking at: > http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm > > If i use, create_arc(bbox, options) => id > what is id? and how do i find the parameter list representing options? > > Thanks for help in advance > > Andrew > > This is a tkinter question, not a python one, and it's really all about how the docs for tkinter are organized. I don't use tkinter, so I had to spelunk a little bit (try search). You're looking at a summary page. You want to see the details for a given one of those methods. Search for create_arc, and you'll find http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm as one of the links. The link "Back" will get you to: http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm which is the beginning of Chapter 14, "The Canvas Arc Item" As for 'id' I have no idea, but if you read further, you'll probably find out. The fact that all of these methods return one indicates it's some sort of object reference for those widgets. From mail at microcorp.co.za Wed Jun 17 04:01:24 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 17 Jun 2009 10:01:24 +0200 Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <00d901c9ef21$db289940$0d00a8c0@Hendrik> "Diez B. Roggisch" wrote: > Getting a depression because of a compiler is a bit strong... > > However, yes, bytecode is similar to assembler, and in that respect > higher-level control-structures are created using (conditional) jumps. > > The same is true for other bytecode-languages, see here for the JVM: > > http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493 This is right. It is my opinion that it is not possible to make a useful machine, virtual or real, which executes instructions sequentially, if the instruction set does not contain a conditional jump of some sort. I have tried doing it using conditional calls, and it fails on the equivalent of the first if ..., elif ... you try to write. - Hendrik From mk.fraggod at gmail.com Wed Jun 17 04:24:31 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 14:24:31 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: <20090617142431.2b25faf5@malediction> On Wed, 17 Jun 2009 17:53:33 +1200 Lawrence D'Oliveiro wrote: > > Why not use hex representation of md5/sha1-hashed id as a path, > > arranging them like /path/f/9/e/95ea4926a4 ? > > > > That way, you won't have to deal with many-files-in-path problem ... > > Why is that a problem? So you can os.listdir them? Don't ask me what for, however, since that's the original question. Also not every fs still in use handles this situation effectively, see my original post. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 04:28:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 08:28:20 GMT Subject: Exotic Logics References: Message-ID: On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > I was staring at a logic table the other day, and I asked myself, "what > if one wanted to play with exotic logics; how might one do it?" First question: what's an exotic logics? Do you mean things like three-value logic, fuzzy logic, probabilistic reasoning, etc? Or do you mean logical operators others than and, or, xor, nand, nor, etc? Or both? Something else? > I did > some searching but not being too sure of what to look for and carried > away with my own enthusiasm for the idea, I didn't find much. What I've > come up with is, no doubt, inefficient, naive, poor python style, and > probably wrong in fundamental ways too subtle for me, but here it is: > > import itertools > import operator > > class Logic(): > """class of generic logic operators""" [...] If (nearly) all your methods are static methods, chances are a class is the wrong solution. Why not just define the static methods as top-level functions? > This seemed to be working for the limited tests I did on it, while I was > doing them. The following checked out last time I tried: > >>>> and_ = Logic(2, 8) >>>> or_ = Logic(2, 14) >>>> xor = Logic(2, 6) > > I have no idea how to validate the results of the trinary and beyond > logics. The same way you would validate and_, or_ and xor: to validate something, you need to know what the correct answer is, then compare the answer you get with the answer you should get. For a binary operator and binary operands, you can exhaustively check every valid input: flag1 op flag2 there are four combinations of input flags: 0 op 0 0 op 1 1 op 0 1 op 1 For three-valued logic, there are 9 combinations. For four-valued, 16. So exhaustively testing all the possible inputs is quite simple. As far as getting the correct answers, you have to decide which three- valued logic(s) you want to use, then go look them up. Or just make them up yourself! E.g. given trinary flags 0, 1, 2, (say), you might want the operators to give the same results with 0, 1 as they would if you were applying it to binary flags 0, 1. E.g.: # binary operands 0 and 0 => 0 0 and 1 => 0 1 and 0 => 0 1 and 1 => 1 # trinary operands 0 and 0 => 0 0 and 1 => 0 0 and 2 => ? # probably 0 1 and 0 => 0 1 and 1 => 1 1 and 2 => ? # could be 0, or maybe 1 2 and 0 => ? # probably 0 2 and 1 => ? # 0 or 1 2 and 2 => ? # probably 2 Different choices lead to different versions of ternary logic. > Thanks for reading and trying this out. Corrections? Criticism? > Comments? You're implementation seems rather confusing. I think that's partly because you use lots of abbreviated jargon terms that mean little or nothing to me: rdx, opr (operator?), lsd, pute. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 04:44:19 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Jun 2009 08:44:19 GMT Subject: Exotic Logics References: Message-ID: On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > I was staring at a logic table the other day, and I asked myself, "what > if one wanted to play with exotic logics; how might one do it?" This might be useful for you, and if not useful, at least it might blow your mind like it did mine. (This is not original to me -- I didn't create it. However, I can't find the original source.) Imagine for a moment that there are no boolean values. There are no numbers. They were never invented. There are no classes. There are no objects. There are only functions. Could you define functions that act like boolean values? And could you define other functions to operate on them? def true(x, y): return x def false(x, y): return y def print_bool(b): print b("true", "false") print_bool(true) print_bool(false) def Not(b): def not_b(x, y): return b(y, x) return not_b print_bool(Not(true)) print_bool(Not(false)) print_bool(Not(Not(true))) def And(a, b): return a(b, a) def Or(a, b): return a(a, b) print_bool(And(true, true)) print_bool(And(true, false)) print_bool(Or(false, true)) print_bool(Or(false, false)) -- Steven From higerinbeijing at gmail.com Wed Jun 17 05:14:26 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 17 Jun 2009 02:14:26 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <64179b1f-6cec-4708-ae94-3ed5c5fb373e@g1g2000yqh.googlegroups.com> Hi,all: I'm sorry that I did not make my question clear. What I mean is that what the souce code would look like that will be compiled to such bytecodes. Regards, higer From command.bbs at alexbbs.twbbs.org Wed Jun 17 05:27:50 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 17 Jun 2009 09:27:50 GMT Subject: UDP queue size Message-ID: <4gRWbd$vn0@alexbbs.twbbs.org> I got a problem about UDP. How do I get the UDP buffer size? When the server had some delay in handling incoming UDP, it will lost some package. I wonder it's because the system buffer size, is there any ways to find the exactly size of the buffer? ex: client.py ---------------- import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in xrange(1000): s.sendto('xxx', ('192.168.1.135',10000)) server.py: in ip (192.168.1.135) ---------------- import socket import time s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(('',10000)) time.sleep(10) # here will only recv 255 package, others are lost... for i in xrange(1000): msg, addr = s.recvfrom(500) print i -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From wolfgang at rohdewald.de Wed Jun 17 05:40:31 2009 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Wed, 17 Jun 2009 11:40:31 +0200 Subject: Need to know if a file as only ASCII charaters In-Reply-To: References: <6e5b31840906160148o4ba6e295x747ec249f0814c1a@mail.gmail.com> Message-ID: <200906171140.31320.wolfgang@rohdewald.de> On Wednesday 17 June 2009, Lie Ryan wrote: > Wolfgang Rohdewald wrote: > > On Wednesday, 17. June 2009, Steven D'Aprano wrote: > >> while text: > >> for c in text: > >> if c not in printable: return False > > > > that is one loop per character. > > unless printable is a set that would still execute the line "if c not in..." once for every single character, against just one regex call. With bigger block sizes, the advantage of regex should increase. > > wouldn't it be faster to apply a regex to text? > > something like > > > > while text: > > if re.search(r'\W',text): return False > > > > regex? Don't even start... Here comes a cProfile test. Note that the first variant of Steven would always have stopped after the first char. After fixing that making it look like variant 2 with block size=1, I now have 3 variants: Variant 1 Blocksize 1 Variant 2 Blocksize 65536 Variant 3 Regex on Blocksize 65536 testing for a file with 400k bytes shows regex as a clear winner. Doing the same for an 8k file: variant 2 takes 3ms, Regex takes 5ms. Variants 2 and 3 take about the same time for a file with 20k. python ascii.py | grep CPU 398202 function calls in 1.597 CPU seconds 13 function calls in 0.104 CPU seconds 1181 function calls in 0.012 CPU seconds import re import cProfile from string import printable def ascii_file1(name): with open(name, 'rb') as f: c = f.read(1) while c: if c not in printable: return False c = f.read(1) return True def ascii_file2(name): bs = 65536 with open(name, 'rb') as f: text = f.read(bs) while text: for c in text: if c not in printable: return False text = f.read(bs) return True def ascii_file3(name): bs = 65536 search = r'[^%s]' % re.escape(printable) reco = re.compile(search) with open(name, 'rb') as f: text = f.read(bs) while text: if reco.search(text): return False text = f.read(bs) return True def test(fun): if fun('/tmp/x'): print 'is ascii' else: print 'is not ascii' cProfile.run("test(ascii_file1)") cProfile.run("test(ascii_file2)") cProfile.run("test(ascii_file3)") -- Wolfgang From deets at nospam.web.de Wed Jun 17 05:59:15 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Jun 2009 11:59:15 +0200 Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> <64179b1f-6cec-4708-ae94-3ed5c5fb373e@g1g2000yqh.googlegroups.com> Message-ID: <79rst2F1pqvecU1@mid.uni-berlin.de> higer wrote: > Hi,all: > > I'm sorry that I did not make my question clear. What I mean is that > what the souce code would look like that will be compiled to such > bytecodes. >>> import dis >>> def foo(): ... for i in xrange(10): ... if i == 5: ... break ... if i == 4: ... continue ... i *= 100 ... >>> dis.disassemble(foo.func_code) 2 0 SETUP_LOOP 68 (to 71) 3 LOAD_GLOBAL 0 (xrange) 6 LOAD_CONST 1 (10) 9 CALL_FUNCTION 1 12 GET_ITER >> 13 FOR_ITER 54 (to 70) 16 STORE_FAST 0 (i) 3 19 LOAD_FAST 0 (i) 22 LOAD_CONST 2 (5) 25 COMPARE_OP 2 (==) 28 JUMP_IF_FALSE 5 (to 36) 31 POP_TOP 4 32 BREAK_LOOP 33 JUMP_FORWARD 1 (to 37) >> 36 POP_TOP 5 >> 37 LOAD_FAST 0 (i) 40 LOAD_CONST 3 (4) 43 COMPARE_OP 2 (==) 46 JUMP_IF_FALSE 7 (to 56) 49 POP_TOP 6 50 JUMP_ABSOLUTE 13 53 JUMP_FORWARD 1 (to 57) >> 56 POP_TOP 7 >> 57 LOAD_FAST 0 (i) 60 LOAD_CONST 4 (100) 63 INPLACE_MULTIPLY 64 STORE_FAST 0 (i) 67 JUMP_ABSOLUTE 13 >> 70 POP_BLOCK >> 71 LOAD_CONST 0 (None) 74 RETURN_VALUE >>> Pretty much everything with control-structures. Diez From sjmachin at lexicon.net Wed Jun 17 06:06:26 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Jun 2009 20:06:26 +1000 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <4A3897F8.7070602@arimaz.com> References: <2b156468-02fc-469c-896e-29a5bf19aa10@w35g2000prg.googlegroups.com> <4A3897F8.7070602@arimaz.com> Message-ID: <4A38C022.7090609@lexicon.net> On 17/06/2009 5:15 PM, Gabriel Rossetti wrote: > John Machin wrote: >> On Jun 17, 1:41 am, Gabriel Rossetti >> wrote: >> >>> Hello everyone, >>> >>> I get an OperationalError with sqlite3 if I put the wrong column name, >>> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it >>> says : >>> >>> >> [snip] >> >>> and to me it sounds more like a programming error than an operational >>> error. >>> >> >> How about showing us the code you used and the exact error message and >> traceback? >> >> >> > Well, the code isn't really relevant to the problem, but here is is : > > import sqlite3 > > conn = sqlite3.connect("/tmp/test.db") > conn.execute("SELECT name, value FROM local_param") > > for row in conn: > print row > > And I get : > > Traceback (most recent call last): > File "", line 1, in > sqlite3.OperationalError: no such table: local_param > > > Which I think should be a ProgrammingError > > If I fix the table name I but use a wrong column name I also get an > OperationalError OK OK alright already ... I agree with you ... report a bug. Cheers, John From paul.paj at gmail.com Wed Jun 17 06:09:34 2009 From: paul.paj at gmail.com (Paul Johnston) Date: Wed, 17 Jun 2009 03:09:34 -0700 (PDT) Subject: class or instance method Message-ID: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Hi, I would like to have a method that is both a classmethod and an instancemethod. So: class MyClass(object): @class_or_instance def myfunc(cls_or_self): pass The semantics I'd like are: When you call MyClass.myfunc, it gets passed a class When you call MyClass().myfunc, it gets passed an instance I'm sure I've seen some code to do this somewhere, but I can't find it now. Any help appreciated. Paul From pdpinheiro at gmail.com Wed Jun 17 06:18:27 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 03:18:27 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: <4afb1842-e7e5-43f9-8320-ebf14b851d97@g19g2000yql.googlegroups.com> On Jun 17, 9:01?am, "Hendrik van Rooyen" wrote: > ?"Diez B. Roggisch" wrote: > > > Getting a depression because of a compiler is a bit strong... > > > However, yes, bytecode is similar to assembler, and in that respect > > higher-level control-structures are created using (conditional) jumps. > > > The same is true for other bytecode-languages, see here for the JVM: > > >http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.... > > This is right. > > It is my opinion that it is not possible to make a useful machine, > virtual or real, which executes instructions sequentially, if the > instruction set does not contain a conditional jump of some sort. > > I have tried doing it using conditional calls, and it fails on > the equivalent of the first if ..., elif ... ?you try to write. > > - Hendrik Not a matter of opinion. One of the requisite elements of a Turing Machine is conditional jumping. From 42flicks at gmail.com Wed Jun 17 06:22:08 2009 From: 42flicks at gmail.com (Mike) Date: Wed, 17 Jun 2009 22:22:08 +1200 Subject: GAEUnit testing Message-ID: <2b54d4370906170322h2e2aaa0ctea3701be8b5aa169@mail.gmail.com> Hello I'm using GAEUnit to develop an app for google appengine and am having a little trouble. I'm trying to make a test as follows: I have a file (say model.py) which contains Model.db model classes and some methods for accessing them. The methods are not part of the class. In my test I can call model.save_person(person) which will call Person(name=person) and Person.put(). I can confirm this is being saved to the db (app engine db stub) by logging the result of Person.all() under the call to put. What I want to do is create a method in model.py called get_people which will return Person.all(). If I do this the second test returns an empty result set. I think this is because the second test is not getting the same reference. In my set up I'd like to set up a Person with details such as address, phone, preferences and have each test get the data for this person and test the result of some transformations. I'd like to do this using the methods in my model.py class, and avoid importing the database to the test unit and using references to self. Am I approaching this correctly? How would I implement this? Thanks for any assistance, I'm new to python and especially unittesting. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Jun 17 06:39:47 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Jun 2009 12:39:47 +0200 Subject: class or instance method In-Reply-To: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Message-ID: <4a38c7e8$0$11904$426a74cc@news.free.fr> Paul Johnston a ?crit : > Hi, > > I would like to have a method that is both a classmethod and an > instancemethod. So: > > class MyClass(object): > @class_or_instance > def myfunc(cls_or_self): > pass > > The semantics I'd like are: > When you call MyClass.myfunc, it gets passed a class > When you call MyClass().myfunc, it gets passed an instance > > I'm sure I've seen some code to do this somewhere, but I can't find it > now. Any help appreciated. IIRC, there's something quite similar in formencode. From bruno.42.desthuilliers at websiteburo.invalid Wed Jun 17 06:47:24 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Jun 2009 12:47:24 +0200 Subject: Question about None In-Reply-To: <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> Message-ID: <4a38c9b1$0$11904$426a74cc@news.free.fr> John Yeung a ?crit : > On Jun 13, 2:29 am, Steven D'Aprano > wrote: >> Paul LaFollette wrote: >>> 3) (this is purely philosophical but I am curious) >>> Would it not be more intuitive if >>> isinstance(None, ) returned true? >> Good grief no!!! >> >> None is an object. It has a type, NoneType. It's *not* a >> string, or a float, or an int, or a list, so why would >> you want isinstance() to *lie* and say that it is? > > Because you might want None to behave as though it were nothing at > all. > > Paul LaFollette is probably thinking along the lines of formal logic > or set theory. It's a little bit confused because programming isn't > quite the same as math, and so it's a common question when designing > and implementing programming languages how far to take certain > abstractions. In some languages, nil, null, or none will try to > behave as mathematically close to "nothing" (complete absence of > anything) as possible, even though in reality they have to have some > concrete implementation, such as perhaps being a singleton object. > But mathematically speaking, it's intuitive that "nothing" would match > any type. IOW, what's the OP is after is not the None type, but some yet unexisting "Anything" type !-) From ldo at geek-central.gen.new_zealand Wed Jun 17 07:04:37 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:04:37 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> Message-ID: In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 17:53:33 +1200 > Lawrence D'Oliveiro wrote: > >> > Why not use hex representation of md5/sha1-hashed id as a path, >> > arranging them like /path/f/9/e/95ea4926a4 ? >> > >> > That way, you won't have to deal with many-files-in-path problem ... >> >> Why is that a problem? > > So you can os.listdir them? Why should you have a problem os.listdir'ing lots of files? From ldo at geek-central.gen.new_zealand Wed Jun 17 07:07:15 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:07:15 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Lie Ryan wrote: > out.write ( > ''' > function JSString(Str) > { > var Result = '\"' > for (var i = 0; i < Str.length; ++i) > { > var ThisCh = Str.charAt(i) > if (ThisCh == '\\') > { > ThisCh = '\\\\' > } > else if (ThisCh == '\"') > { > ThisCh = '\\\"' > } > else if (ThisCh == '\t') > { > ThisCh = '\\t' > } > else if (ThisCh == '\n') > { > ThisCh = '\\n' > } /*if*/ > Result += ThisCh > } /*for*/ > return Result + '\"' > } /*JSString*/ > ''' > ) You haven't managed to get rid of the backslashes. > I might go even further: > > out.write ( > ''' > function JSString(Str) > { > const dq = '\"' > const slash = '\\' > > var Result = dq > for (var i = 0; i < Str.length; ++i) > { > var ThisCh = Str.charAt(i) > if (ThisCh == slash) > { > ThisCh = slash + slash > } > else if (ThisCh == dq) > { > ThisCh = slash + dq > } > else if (ThisCh == '\t') > { > ThisCh = slash + 't' > } > else if (ThisCh == '\n') > { > ThisCh = slash + 'n' > } /*if*/ > Result += ThisCh > } /*for*/ > return Result + dq > } /*JSString*/ > ''' > ) Now you've lost track of the original point of the discussion, which is about using alternate quotes to avoid backslashes. From ldo at geek-central.gen.new_zealand Wed Jun 17 07:29:48 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Jun 2009 23:29:48 +1200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: In message <7x7hzbv14a.fsf at ruckus.brouhaha.com>, wrote: > Lawrence D'Oliveiro writes: > >> > Reference counting is an implementation detail used by CPython but not >> > [implementations built on runtimes designed for corporate-herd-oriented >> > languages, like] IronPython or Jython. >> >> I rest my case. > > You're really being pretty ignorant. I don't know of any serious Lisp > system that uses reference counting, both for performance reasons and > to make sure cyclic structures are reclaimed properly. Both of which, oddly enough, more modern dynamic languages like Python manage perfectly well. From zeal_goswami at yahoo.com Wed Jun 17 07:32:21 2009 From: zeal_goswami at yahoo.com (abhishek goswami) Date: Wed, 17 Jun 2009 17:02:21 +0530 (IST) Subject: Regarding Python is scripting language or not Message-ID: <501798.29841.qm@web94916.mail.in2.yahoo.com> Hi, I have very basic question about Python that do we consider pyhton as script language. I searched in google but it becomes more confusion for me. After some analysis I came to know that Python support oops . Can anyone Guide me that Python is Oject oriented programming language or Script language Abhishek Goswami Chennai Phone No -0996227099 ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From charles at declareSub.com Wed Jun 17 07:37:32 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 07:37:32 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <7xd493v1k4.fsf@ruckus.brouhaha.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <4F141360-C2AF-4DC1-891D-6AB222960ABD@declareSub.com> On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: > Jaime Fernandez del Rio writes: >> I am pretty sure that a continuous sequence of >> curves that converges to a continuous curve, will do so uniformly. > > I think a typical example of a curve that's continuous but not > uniformly continuous is > > f(t) = sin(1/t), defined when t > 0 > > It is continuous at every t>0 but wiggles violently as you get closer > to t=0. You wouldn't be able to approximate it by sampling a finite > number of points. A sequence like > > g_n(t) = sin((1+1/n)/ t) for n=1,2,... > > obviously converges to f, but not uniformly. On a closed interval, > any continuous function is uniformly continuous. Isn't (-?, ?) closed? Charles Yeomans From charles at declareSub.com Wed Jun 17 07:49:52 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 07:49:52 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) In-Reply-To: <7x7hzbv14a.fsf@ruckus.brouhaha.com> References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 2009, at 2:13 AM, Paul Rubin wrote: > Lawrence D'Oliveiro writes: >>> Reference counting is an implementation detail used by CPython but >>> not >>> [implementations built on runtimes designed for corporate-herd- >>> oriented >>> languages, like] IronPython or Jython. >> >> I rest my case. > > You're really being pretty ignorant. I don't know of any serious Lisp > system that uses reference counting, both for performance reasons and > to make sure cyclic structures are reclaimed properly. Lisp is > certainly not a corporate herd language. > > Even CPython doesn't rely completely on reference counting (it has a > fallback gc for cyclic garbage). Python introduced the "with" > statement to get away from the kludgy CPython programmer practice of > opening files and relying on the file being closed when the last > reference went out of scope. I'm curious as you why you consider this practice to be kludgy; my experience with RAII is pretty good. Charles Yeomans From dickinsm at gmail.com Wed Jun 17 07:52:29 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 04:52:29 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> On Jun 17, 7:04?am, Paul Rubin wrote: > I think a typical example of a curve that's continuous but not > uniformly continuous is > > ? ?f(t) = sin(1/t), defined when t > 0 > > It is continuous at every t>0 but wiggles violently as you get closer > to t=0. ?You wouldn't be able to approximate it by sampling a finite > number of points. ?A sequence like > > ? ?g_n(t) = sin((1+1/n)/ t) ? ?for n=1,2,... > > obviously converges to f, but not uniformly. ?On a closed interval, > any continuous function is uniformly continuous. Right, but pointwise convergence doesn't imply uniform convergence even with continuous functions on a closed bounded interval. For an example, take the sequence g_n (n >= 0), of continuous real-valued functions on [0, 1] defined by: g_n(t) = nt if 0 <= t <= 1/n else 1 Then for any 0 <= t <= 1, g_n(t) -> 0 as n -> infinity. But the convergence isn't uniform: max_t(g_n(t)-0) = 1 for all n. Maybe James is thinking of the standard theorem that says that if a sequence of continuous functions on an interval converges uniformly then its limit is continuous? Mark From dickinsm at gmail.com Wed Jun 17 07:56:20 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 04:56:20 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <6e1d0b33-254c-445d-96c3-5d5023c29fd5@k2g2000yql.googlegroups.com> On Jun 17, 12:52?pm, Mark Dickinson wrote: > g_n(t) = nt if 0 <= t <= 1/n else 1 Whoops. Wrong definition. That should be: g_n(t) = nt if 0 <= t <= 1/n else n(2/n-t) if 1/n <= t <= 2/n else 0 Then my claim that g_n(t) -> 0 for all t might actually make sense... From jeanmichel at sequans.com Wed Jun 17 08:13:15 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 14:13:15 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> Message-ID: <4A38DDDB.5070309@sequans.com> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >> What's np.arange? >> > > import numpy as np > > -- > Pierre "delroth" Bourdon > ?tudiant ? l'EPITA / Student at EPITA > Perfect example of why renaming namespaces should be done only when absolutely required, that is, almost never. Jean-Michel From contact at xavierho.com Wed Jun 17 08:24:16 2009 From: contact at xavierho.com (Xavier Ho) Date: Wed, 17 Jun 2009 22:24:16 +1000 Subject: class or instance method In-Reply-To: <4a38c7e8$0$11904$426a74cc@news.free.fr> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <4a38c7e8$0$11904$426a74cc@news.free.fr> Message-ID: <2d56febf0906170524l408dc07ev432b8d56db1c66c8@mail.gmail.com> I'm quite curious as to why you would like it, because: >>> MyClass (returns the MyClass class representation) >>> MyClass() (returns a instance of the MyClass class) So, are you just looking for a method that does exactly the above? Best regards, 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 Wed, Jun 17, 2009 at 8:39 PM, Bruno Desthuilliers wrote: > Paul Johnston a ?crit : > >> Hi, >> >> I would like to have a method that is both a classmethod and an >> instancemethod. So: >> >> class MyClass(object): >> @class_or_instance >> def myfunc(cls_or_self): >> pass >> >> The semantics I'd like are: >> When you call MyClass.myfunc, it gets passed a class >> When you call MyClass().myfunc, it gets passed an instance >> >> I'm sure I've seen some code to do this somewhere, but I can't find it >> now. Any help appreciated. >> > > IIRC, there's something quite similar in formencode. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jaime.frio at gmail.com Wed Jun 17 08:26:27 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Wed, 17 Jun 2009 14:26:27 +0200 Subject: Measuring Fractal Dimension ? In-Reply-To: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <97a8f1a70906170526m313948arcbe6ca22cbe601c8@mail.gmail.com> On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: > Maybe James is thinking of the standard theorem > that says that if a sequence of continuous functions > on an interval converges uniformly then its limit > is continuous? Jaime was simply plain wrong... The example that always comes to mind when figuring out uniform convergence (or lack of it), is the step function , i.e. f(x)= 0 if x in [0,1), x(x)=1 if x >= 1, being approximated by the sequence f_n(x) = x**n if x in [0,1), f_n(x) = 1 if x>=1, where uniform convergence is broken mostly due to the limiting function not being continuous. I simply was too quick with my extrapolations, and have realized I have a looooot of work to do for my "real and functional analysis" exam coming in three weeks... Jaime P.S. The snowflake curve, on the other hand, is uniformly continuous, right? -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From sjmachin at lexicon.net Wed Jun 17 08:29:19 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 17 Jun 2009 05:29:19 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: On Jun 17, 1:40?pm, higer wrote: > My Python version is 2.5.2; When I reading the bytecode of some pyc > file, I always found that there are many jump command from different > position,but to the same position. You can see this situation in > following code(this bytecode is just from one .pyc file and I don't > have its source .py file): > Why don't you (a) read the answers you got on stackoverflow to the identical question (b) WRITE some code instead of inspecting the entrails of the code of others? From ml at well-adjusted.de Wed Jun 17 08:35:40 2009 From: ml at well-adjusted.de (Jochen Schulz) Date: Wed, 17 Jun 2009 14:35:40 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <20090617123540.GA19607@wasteland.homelinux.net> abhishek goswami: > > Can anyone Guide me that Python is Oject oriented programming language > or Script language In my opinion, Python is both. But an "objective" answer would require you to define what you means by these terms. If, by "object-oriented" you mean "everything has to be put into classes", then Python is not object-oriented. If, by "scripting language" you mean Python is an error-prone toy language, unsuitable for large, serious projects, then Python is not a scripting language either. J. -- My clothes aren't just fashion. They're a lifestyle. [Agree] [Disagree] -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From jeanmichel at sequans.com Wed Jun 17 08:38:55 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 14:38:55 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <4A38E3DF.2010408@sequans.com> abhishek goswami wrote: > Hi, > I have very basic question about Python that do we consider pyhton as > script language. > I searched in google but it becomes more confusion for me. After some > analysis I came to know that Python support oops . > > Can anyone Guide me that Python is Oject oriented programming language > or Script language > > Abhishek Goswami > Chennai > Phone No -0996227099 > > > ------------------------------------------------------------------------ > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > Depends on what you are calling a scripting language. Refering to wikipedia, "A *scripting language*, *script language* or *extension language* is a programming language that allows some control of a single or many software application(s) ." Python is definitely OOP oriented and I don't think it fits in the script definition above. Python is interpreted and platform independent, but you can still build standalone platform dependent binaries if required. Regarding your last question, I'm not sure scripting and OOP language are not compatible, I'm pretty sure you'll be able to find OOP scripting language. Jean-Michel From hniksic at xemacs.org Wed Jun 17 08:40:45 2009 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 17 Jun 2009 14:40:45 +0200 Subject: class or instance method References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> Message-ID: <87ljnr3ueq.fsf@busola.homelinux.net> Paul Johnston writes: > I would like to have a method that is both a classmethod and an > instancemethod. So: > > class MyClass(object): > @class_or_instance > def myfunc(cls_or_self): > pass > > The semantics I'd like are: > When you call MyClass.myfunc, it gets passed a class > When you call MyClass().myfunc, it gets passed an instance class class_or_instance(object): def __init__(self, fn): self.fn = fn def __get__(self, obj, cls): if obj is not None: return lambda *args, **kwds: self.fn(obj, *args, **kwds) else: return lambda *args, **kwds: self.fn(cls, *args, **kwds) >>> class MyClass(object): ... @class_or_instance ... def myfunc(cls_or_self): ... return cls_or_self ... >>> MyClass.myfunc() >>> MyClass().myfunc() <__main__.MyClass object at 0xb7a248cc> You might want to use functools.wrap to return named functions rather than unnamed lambdas, but you get the idea. From dickinsm at gmail.com Wed Jun 17 08:46:22 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 05:46:22 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> On Jun 17, 1:26?pm, Jaime Fernandez del Rio wrote: > On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: > > Maybe James is thinking of the standard theorem > > that says that if a sequence of continuous functions > > on an interval converges uniformly then its limit > > is continuous? s/James/Jaime. Apologies. > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? Yes, at least in the sense that it can be parametrized by a uniformly continuous function from [0, 1] to the Euclidean plane. I'm not sure that it makes a priori sense to describe the curve itself (thought of simply as a subset of the plane) as uniformly continuous. Mark From higerinbeijing at gmail.com Wed Jun 17 08:47:09 2009 From: higerinbeijing at gmail.com (higer) Date: Wed, 17 Jun 2009 05:47:09 -0700 (PDT) Subject: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> Message-ID: <7734a932-31e9-4eb8-bc60-84a05f471e46@h18g2000yqj.googlegroups.com> On Jun 17, 8:29?pm, John Machin wrote: > On Jun 17, 1:40?pm, higer wrote: > > > My Python version is 2.5.2; When I reading the bytecode of some pyc > > file, I always found that there are many jump command from different > > position,but to the same position. You can see this situation in > > following code(this bytecode is just from one .pyc file and I don't > > have its source .py file): > > Why don't you (a) read the answers you got on stackoverflow to the > identical question (b) WRITE some code instead of inspecting the > entrails of the code of others? Thanks, I read the answer just now. And thank everbody for your suggestion! From Scott.Daniels at Acm.Org Wed Jun 17 09:05:12 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:05:12 -0700 Subject: walking a directory with very many files In-Reply-To: <20090617091858.432f89ca@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> Message-ID: Mike Kazantsev wrote: > On Wed, 17 Jun 2009 14:52:28 +1200 > Lawrence D'Oliveiro wrote: > >> In message >> <234b19ac-7baf-4356-9fe5-37d00146d982 at z9g2000yqi.googlegroups.com>, >> thebjorn wrote: >> >>> Not proud of this, but...: >>> >>> [django] www4:~/datakortet/media$ ls bfpbilder|wc -l >>> 174197 >>> >>> all .jpg files between 40 and 250KB with the path stored in a >>> database field... *sigh* >> Why not put the images themselves into database fields? >> >>> Oddly enough, I'm a relieved that others have had similar folder >>> sizes ... >> One of my past projects had 400000-odd files in a single folder. They >> were movie frames, to allow assembly of movie sequences on demand. > > For both scenarios: > Why not use hex representation of md5/sha1-hashed id as a path, > arranging them like /path/f/9/e/95ea4926a4 ? > ... > In fact, on modern filesystems it doesn't matter whether you accessing > /path/f9e95ea4926a4 with million files in /path or /path/f/9/e/95ea > with only hundred of them in each path. Probably better to use: /path/f9/e9/5ea4926a4 If you want to talk hundreds per layer. Branching 16 ways seems silly. --Scott David Daniels Scott.Daniels at Acm.Org From pdpinheiro at gmail.com Wed Jun 17 09:18:17 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 06:18:17 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> Message-ID: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> On Jun 17, 1:26?pm, Jaime Fernandez del Rio wrote: > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? The definition of uniform continuity is that, for any epsilon > 0, there is a delta > 0 such that, for any x and y, if x-y < delta, f(x)-f (y) < epsilon. Given that Koch's curve is shaped as recursion over the transformation from ___ to _/\_, it's immediately obvious that, for a delta of at most the length of ____, epsilon will be at most the height of /. It follows that, inversely, for any arbitrary epsilon, you find the smallest / that's still taller than epsilon, and delta is bound by the respective ____. (hooray for ascii demonstrations) Curiously enough, it's the recursive/self-similar nature of the Koch curve so easy to prove as uniformly continuous. From Scott.Daniels at Acm.Org Wed Jun 17 09:26:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:26:31 -0700 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> Message-ID: Jean-Michel Pichavant wrote: > On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >>> What's np.arange? >> >> import numpy as np > > Perfect example of why renaming namespaces should be done only when > absolutely required, that is, almost never. > > Jean-Michel Actually, "np." is quite commonly used in the numpy community, so it is a bit of a "term of art". Since you can often use several numpy elements in an expression, brevity is appreciated, and at least they've stopped assuming "from numpy import *" in their documents. Unfortunately, if you work in a numpy world long enough, you'll forget that not everyone uses numpy. --Scott David Daniels Scott.Daniels at Acm.Org From martin.hellwig at dcuktec.org Wed Jun 17 09:29:07 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 14:29:07 +0100 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: Jochen Schulz wrote: > abhishek goswami: >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language > > In my opinion, Python is both. But an "objective" answer would require > you to define what you means by these terms. > > If, by "object-oriented" you mean "everything has to be put into > classes", then Python is not object-oriented. If, by "scripting > language" you mean Python is an error-prone toy language, unsuitable for > large, serious projects, then Python is not a scripting language either. > > J. IMHO Python is an programming environment where you can chose the right approach for your particular problem. Because it seems to favour clarity over classification purity, it can not be so easily defined. This approach should be fine for everybody unless you are the type that insist on using one approach because in theory it should be suitable for everything. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From Scott.Daniels at Acm.Org Wed Jun 17 09:41:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:41:58 -0700 Subject: Newbie question about method options In-Reply-To: References: Message-ID: Dave Angel wrote: > python-newbie113 wrote: >> I am new to python and have a question about using methods. >> >> Here is the link i am looking at: >> http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm >> >> If i use, create_arc(bbox, options) => id >> what is id? and how do i find the parameter list representing options? > > Search for create_arc, and you'll find > http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm > as one of the links. The link "Back" will get you to: > http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm > > which is the beginning of Chapter 14, "The Canvas Arc Item" > > As for 'id' I have no idea, but if you read further, you'll probably > find out. The fact that all of these methods return one indicates it's > some sort of object reference for those widgets. Everything drawn on a canvas has an 'id' which just happens to be an integer (treat it as a magic cookie). You specify that id to the canvas to talk about that particular element, but you often group canvas elements together via "tags", and use the same canvas operations on a tag so that you can do your operation to everything with that tag. operations include such things as color manipulation, delete, clone, and move. --Scott David Daniels Scott.Daniels at Acm.Org From kshama.nagaraj at gmail.com Wed Jun 17 09:48:21 2009 From: kshama.nagaraj at gmail.com (kshama nagaraj) Date: Wed, 17 Jun 2009 15:48:21 +0200 Subject: os.read in non blocking mode of os.open : resource busy error Message-ID: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> Dear all, I am using os.open to open a tun/tap device and then read data from it. I also need to do some other tasks apart from reading from this device. So i wish to have the read non blocking. I am opening the device in non-block mode using os.O_NONBLOCK . But, if i do this, i get an error when i call the os.read a follows: File "./tunnel_more1.py", line 305, in main_loop payload = os.read(self.tun_fd,64) OSError: [Errno 11] Resource temporarily unavailable I am running my application with GNU Radio on Ubuntu. Can some one tell me, what is the error? What are the ways to use non blocking read? thanks all for your time and attention. -- Thanks & Regards Kshama -------------- next part -------------- An HTML attachment was scrubbed... URL: From Scott.Daniels at Acm.Org Wed Jun 17 09:50:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 17 Jun 2009 06:50:37 -0700 Subject: UDP queue size In-Reply-To: <4gRWbd$vn0@alexbbs.twbbs.org> References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: ???????? wrote: > I got a problem about UDP. > > How do I get the UDP buffer size? > > When the server had some delay in handling incoming UDP, it will lost > some package. I wonder it's because the system buffer size, is there any > ways to find the exactly size of the buffer? UDP is defined as "best effort then give up," so _everything_ that handles a UDP packet is allowed to drop it; that means switchers, routers, ..., anything along the path to the target application. So, you cannot expect to do any better than a conservative guess, perhaps augmented by dynamic scaling. --Scott David Daniels Scott.Daniels at Acm.Org From jure.erznoznik at gmail.com Wed Jun 17 10:00:02 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Wed, 17 Jun 2009 07:00:02 -0700 (PDT) Subject: Newbie queue question Message-ID: Hi, I'm pretty new to Python (2.6) and I've run into a problem I just can't seem to solve. I'm using dbfpy to access DBF tables as part of a little test project. I've programmed two separate functions, one that reads the DBF in main thread and the other which reads the DBF asynchronously in a separate thread. Here's the code: def demo_01(): '''DBF read speed only''' dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): rec = dbf1[i1] dbf1.close() def demo_03(): '''DBF read speed into a FIFO queue''' class mt(threading.Thread): q = Queue.Queue(64) def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) dbf1.close() del dbf1 self.q.join() t = mt() t.start() while t.isAlive(): try: rec = t.q.get(False, 0.2) t.q.task_done(); except: pass del t However I'm having serious issues with the second method. It seems that as soon as I start accessing the queue from both threads, the reading speed effectively halves. I have tried the following: 1. using deque instead of queue (same speed) 2. reading 10 records at a time and inserting them in a separate loop (hoped the congestion would help) 3. Increasing queue size to infinite and waiting 10 seconds in main thread before I started reading - this one yielded full reading speed, but the waiting took away all the threading benefits I'm sure I'm doing something very wrong here, I just can't figure out what. Can anyone help me with this? Thanks, Jure From Eric_Dexter at msn.com Wed Jun 17 10:12:14 2009 From: Eric_Dexter at msn.com (edexter) Date: Wed, 17 Jun 2009 07:12:14 -0700 (PDT) Subject: first full alpha release of PyLab_Works v0.3 References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: On Jun 17, 12:29?am, "Martin P. Hellwig" wrote: > edexter wrote: > > On Jun 16, 12:27 pm, Stef Mientki wrote: > >> hello, > > >> I am pleased to announce the first full alpha release of PyLab_Works, v0.3. > > >> PyLab_Works is a modular Visual Development Environment, based on > >> data-flow programming technics. PyLab_Works is specially aimed at > >> Education, Engineering and Science. The ideas behind PyLab_Works are, > >> that the final user should not be burdened with programming details and > >> domain details, whereas the domain expert should be able to implement > >> the specific ?domain knowledge without being a full educated programmer. > > >> You can always find my notes on PyLab_Works on > >> ? ?http://pic.flappie.nl > >> Most of these pages are also collected in a single pdf document, which > >> can be found here: > >> ?http://pylab-works.googlecode.com/files/pw_manual.pdf > > >> The source code and a one-button-Windows-Installer can be found on > >> codegoogle: > >> ?http://code.google.com/p/pylab-works/ > >> The files are rather large, because they contain some data samples. > >> The Windows-Installer contains everything you need to get started with > >> PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle, ? > >> Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, > >> Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. > >> Although the PyLab_Works programs are compiled with Py2Exe, all the > >> source files are explicitly included. > > >> have fun, > >> Stef Mientki > > > program didn't start because .dll is missing (sorry I don't have the > > name)... ?I don't know if that is just an issue with the installer > > with vista or not (missing msv something 71. dll) > > You probably mean the microsoft visual C++ runtime (msvcr71.dll), > windows vista has a brand new way (via manifest files) to make it more > difficult to install compiled binaries. > > Search for 'Microsoft Visual C++ 2005 Redistributable Package' and > install it. > > -- > MPHhttp://blog.dcuktec.comm > 'If consumed, best digested with added seasoning to own preference.' it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 Redistributable Package did not help.. I had simular problems with alot of installers I had saved (from installing on xp) but when I grabbed newer installers they all worked, could be the manifast.... I was looking forward to trying it out.. From dickinsm at gmail.com Wed Jun 17 10:23:33 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 07:23:33 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> Message-ID: On Jun 17, 2:18?pm, pdpi wrote: > On Jun 17, 1:26?pm, Jaime Fernandez del Rio > wrote: > > > P.S. The snowflake curve, on the other hand, is uniformly continuous, right? > > The definition of uniform continuity is that, for any epsilon > 0, > there is a delta > 0 such that, for any x and y, if x-y < delta, f(x)-f > (y) < epsilon. Given that Koch's curve is shaped as recursion over the > transformation from ___ to _/\_, it's immediately obvious that, for a > delta of at most the length of ____, epsilon will be at most the > height of /. It follows that, inversely, for any arbitrary epsilon, > you find the smallest / that's still taller than epsilon, and delta is > bound by the respective ____. (hooray for ascii demonstrations) I think I'm too stupid to follow this. It looks as though you're treating (a portion of?) the Koch curve as the graph of a function f from R -> R and claiming that f is uniformly continuous. But the Koch curve isn't such a graph (it fails the 'vertical line test', in the language of precalculus 101), so I'm confused. Here's an alternative proof: Let K_0, K_1, K_2, ... be the successive generations of the Koch curve, so that K_0 is the closed line segment from (0, 0) to (1, 0), K_1 looks like _/\_, etc. Parameterize each Kn by arc length, scaled so that the domain of the parametrization is always [0, 1] and oriented so that the parametrizing function fn has fn(0) = (0,0) and fn(1) = (1, 0). Let d = ||f1 - f0||, a positive real constant whose exact value I can't be bothered to calculate[*] (where ||f1 - f0|| means the maximum over all x in [0, 1] of the distance from f0(x) to f1(x)). Then from the self-similarity we get ||f2 - f1|| = d/3, ||f3 - f2|| = d/9, ||f4 - f3|| = d/27, etc. Hence, since sum_{i >= 0} d/(3^i) converges absolutely, the sequence f0, f1, f2, ... converges *uniformly* to a limiting function f : [0, 1] -> R^2 that parametrizes the Koch curve. And since a uniform limit of uniformly continuous function is uniformly continuous, it follows that f is uniformly continuous. Mark [*] I'm guessing 1/sqrt(12). From paul at boddie.org.uk Wed Jun 17 10:25:38 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Wed, 17 Jun 2009 07:25:38 -0700 (PDT) Subject: Tool for browsing python code References: Message-ID: <791f647b-4514-4273-a9c8-83e140b1040f@t21g2000yqi.googlegroups.com> On 16 Jun, 14:48, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time > trying to figure this out) > Anything like cscope with vim would be great. Are you limiting your inquiry to text editors or IDEs, or are Web- based solutions also interesting? Often, convenient browsing tools index the code and try and provide reasonable links from the place where a particular name or symbol may be used to the definition of that name or symbol elsewhere in a system. Initially, for a Web-based code browser, I looked at LXR [1], but it seemed that OpenGrok [2] was probably a better solution except for the fact that it uses the usual Java parallel universe of Web and application servers. Meanwhile, there are pages on the python.org Wiki about IDEs, editors and documentation tools, all of which might be relevant here: http://wiki.python.org/moin/DevelopmentTools Paul [1] http://lxr.linux.no/ [2] http://opensolaris.org/os/project/opengrok/ From kwmsmith at gmail.com Wed Jun 17 10:38:42 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 17 Jun 2009 09:38:42 -0500 Subject: Tool for browsing python code In-Reply-To: <4A3794A9.5080309@gmail.com> References: <4A3794A9.5080309@gmail.com> Message-ID: On Tue, Jun 16, 2009 at 7:48 AM, Lucas P Melo wrote: > Is there any tool for browsing python code? (I'm having a hard time trying > to figure this out) > Anything like cscope with vim would be great. Check out pycscope: http://pypi.python.org/pypi/pycscope/0.3 I use it myself, and it works fine. Better than ctags/etags for python. Kurt From http Wed Jun 17 10:46:12 2009 From: http (Paul Rubin) Date: 17 Jun 2009 07:46:12 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> Message-ID: <7xfxdyrk97.fsf@ruckus.brouhaha.com> Mark Dickinson writes: > It looks as though you're treating (a portion of?) the Koch curve as > the graph of a function f from R -> R and claiming that f is > uniformly continuous. But the Koch curve isn't such a graph (it > fails the 'vertical line test', I think you treat it as a function f: R -> R**2 with the usual distance metric on R**2. From descentspb at gmail.com Wed Jun 17 10:57:05 2009 From: descentspb at gmail.com (Igor Katson) Date: Wed, 17 Jun 2009 18:57:05 +0400 Subject: ANN: pyTenjin 0.8.0 - much faster template engine than Django In-Reply-To: References: Message-ID: <4A390441.3070905@gmail.com> kwatch wrote: > I have released pyTenjin 0.8.0 > Thanks for your project. I have used it a little, and there is a question to you. import tenjin from tenjin.helpers import * shared_cache = tenjin.GaeMemcacheCacheStorage() engine = tenjin.Engine(cache=shared_cache) 1. Why should I import tenjin.helpers if I don't use the helpers in my code? 2. Why does the code not work if I don't import the helpers? I think you should manage this issue inside the library. From castironpi at gmail.com Wed Jun 17 11:06:22 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 08:06:22 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Jun 16, 10:09?am, Mike Kazantsev wrote: > On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) > > Aaron Brady wrote: > > Making the charitable interpretation that this was the extent of c-l- > > py's support and enthusiasm for my idea, I will now go into mourning. > > Death occurred at oh-eight-hundred. ?Rest in peace, support & > > enthusiasm. > > I've read this thread from the beginning, being tempted to insert > remarks about shelve module or ORMs like SQLAlchemy, but that'd be > meaningless without the problem description, which I haven't seen > anywhere. Is it some trick idea like "let's walk on our heads"? More like bronze them, or hang them on a tackboard. You haven't convinced me that it's not a problem, or that it's an easy one. From castironpi at gmail.com Wed Jun 17 11:10:48 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 08:10:48 -0700 (PDT) Subject: Question about None References: <02433982$0$20629$c3e8da3@news.astraweb.com> <6c0bc07a-92e6-42eb-a63d-43e79674861a@y34g2000prb.googlegroups.com> <4a38c9b1$0$11904$426a74cc@news.free.fr> Message-ID: On Jun 17, 5:47?am, Bruno Desthuilliers wrote: > John Yeung a ?crit : > > But mathematically speaking, it's intuitive that "nothing" would match > > any type. > > IOW, what's the OP is after is not the None type, but some yet > unexisting "Anything" type !-) The behaviors of the 'anything' object are a subset of those of any other object. I don't believe that 'subset' is a proper characterization of the relationship between the methods of a subclass and the methods of its superclass. But 'superset' may be. Should 'object' inherit from None? From dickinsm at gmail.com Wed Jun 17 11:18:52 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 17 Jun 2009 08:18:52 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 3:46?pm, Paul Rubin wrote: > Mark Dickinson writes: > > It looks as though you're treating (a portion of?) the Koch curve as > > the graph of a function f from R -> R and claiming that f is > > uniformly continuous. ?But the Koch curve isn't such a graph (it > > fails the 'vertical line test', > > I think you treat it as a function f: R -> R**2 with the usual > distance metric on R**2. Right. Or rather, you treat it as the image of such a function, if you're being careful to distinguish the curve (a subset of R^2) from its parametrization (a continuous function R -> R**2). It's the parametrization that's uniformly continuous, not the curve, and since any curve can be parametrized in many different ways any proof of uniform continuity should specify exactly which parametrization is in use. Mark From nick at craig-wood.com Wed Jun 17 11:29:31 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 17 Jun 2009 10:29:31 -0500 Subject: UDP queue size References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: ???M???v???@???? wrote: > I got a problem about UDP. > > How do I get the UDP buffer size? > > When the server had some delay in handling incoming UDP, it will lost > some package. I wonder it's because the system buffer size, is there any > ways to find the exactly size of the buffer? > > ex: > > client.py > import socket > > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > for i in xrange(1000): > s.sendto('xxx', ('192.168.1.135',10000)) > > > > server.py: in ip (192.168.1.135) > import socket > import time > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > s.bind(('',10000)) > time.sleep(10) > > # here will only recv 255 package, others are lost... > for i in xrange(1000): > msg, addr = s.recvfrom(500) > print i I think you want setsockopt... >>> import socket >>> import time >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >>> s.bind(('',10000)) >>> s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF) 112640 >>> s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1048576) >>> s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF) 262142 >>> I ran the above on linux and I expect the limit 262144 is settable in /proc/sys/net somewhere. No idea whether the above works on windows! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mk.fraggod at gmail.com Wed Jun 17 11:45:35 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Wed, 17 Jun 2009 21:45:35 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> Message-ID: <20090617214535.108667ca@coercion> On Wed, 17 Jun 2009 23:04:37 +1200 Lawrence D'Oliveiro wrote: > In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 17:53:33 +1200 > > Lawrence D'Oliveiro wrote: > > > >> > Why not use hex representation of md5/sha1-hashed id as a path, > >> > arranging them like /path/f/9/e/95ea4926a4 ? > >> > > >> > That way, you won't have to deal with many-files-in-path problem ... > >> > >> Why is that a problem? > > > > So you can os.listdir them? > > Why should you have a problem os.listdir'ing lots of files? I shouldn't, and I don't ;) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From martin.hellwig at dcuktec.org Wed Jun 17 11:58:41 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 16:58:41 +0100 Subject: UDP queue size In-Reply-To: References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: Scott David Daniels wrote: > ???????? wrote: >> I got a problem about UDP. >> >> How do I get the UDP buffer size? >> >> When the server had some delay in handling incoming UDP, it will lost >> some package. I wonder it's because the system buffer size, is there any >> ways to find the exactly size of the buffer? > > UDP is defined as "best effort then give up," so _everything_ that > handles a UDP packet is allowed to drop it; that means switchers, > routers, ..., anything along the path to the target application. > So, you cannot expect to do any better than a conservative guess, > perhaps augmented by dynamic scaling. > > --Scott David Daniels > Scott.Daniels at Acm.Org I would like to add, that you are most likely to lose packages because they are to big, I can not remember for sure if UDP had a fixed limit above what the MTU does, but you might want to look at that direction too. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From pdpinheiro at gmail.com Wed Jun 17 11:58:48 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 08:58:48 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 17, 4:18?pm, Mark Dickinson wrote: > On Jun 17, 3:46?pm, Paul Rubin wrote: > > > Mark Dickinson writes: > > > It looks as though you're treating (a portion of?) the Koch curve as > > > the graph of a function f from R -> R and claiming that f is > > > uniformly continuous. ?But the Koch curve isn't such a graph (it > > > fails the 'vertical line test', > > > I think you treat it as a function f: R -> R**2 with the usual > > distance metric on R**2. > > Right. ?Or rather, you treat it as the image of such a function, > if you're being careful to distinguish the curve (a subset > of R^2) from its parametrization (a continuous function > R -> R**2). ?It's the parametrization that's uniformly > continuous, not the curve, and since any curve can be > parametrized in many different ways any proof of uniform > continuity should specify exactly which parametrization is > in use. > > Mark I was being incredibly lazy and using loads of handwaving, seeing as I posted that (and this!) while procrastinating at work. an even lazier argument: given the _/\_ construct, you prove that its vertical growth is bound: the height of / is less than 1/3 (given a length of 1 for ___), so, even if you were to build _-_ with the middle segment at height = 1/3, the maximum vertical growth would be sum 1/3^n from 1 to infinity, so 0.5. Sideways growth has a similar upper bound. 0.5 < 1, so the chebyshev distance between any two points on the curve is <= 1. Ergo, for any x,y, f(x) is at most at chebyshev distance 1 of (y). Induce the argument for "smaller values of one". From icanbob at gmail.com Wed Jun 17 12:10:54 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 17 Jun 2009 09:10:54 -0700 (PDT) Subject: Executing a python script while it is running References: <4A383386.10409@ieee.org> <001636456fe6019056046c811e8c@google.com> <50697b2c0906161837h1bb8e7a2ocff38a259d7e1317@mail.gmail.com> Message-ID: On Jun 17, 1:42 am, Zach Hobesh wrote: > On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > > On Tue, Jun 16, 2009 at 6:21 PM, wrote: > >> Hey Dave, > > >> Thanks for the helpful responses. > > >>> Option 2 is what you get by default. Naturally it depends on what the > >>> application is using to launch the batch file, but the most common cases > >>> will launch a separate process. > > >> The app ended up delaying starting the second batch file until it finished > >> the first. I had the app trigger an infinite loop on completion, and sent > >> two files through at the same time. The second file finished seconds after > >> the first, but the batch file didn't trigger until I closed the first one. > > > Are you sure you aren't unknowingly having the app wait on the first > > batch file process until it terminates? How exactly are you launching > > the batch files? > > > Cheers, > > Chris > > -- > >http://blog.rebertia.com > > Hey Chris, > > I actually think that's what's happening, which is fine in my case > (for now anyway) as I just need them all to complete, we don't need > them running at the same time. I'm using a job management system, and > they have the option of triggering a command line after completing a > job. > > A better/safer solution might be spawning another job and re-inserting > to the jms queue. > > Thanks again, > > Zach You might want to take a look at the Python-SIMPL toolkit (http:// www.icanprogram.com/06py/main.html). SIMPL uses a Send/Receive/Reply interprocess messaging scheme which will naturally queue requests for you. Without too much effort you may be able to reorient your scheme to eliminate the batch file entirely. bob From brendandetracey at yahoo.com Wed Jun 17 12:15:17 2009 From: brendandetracey at yahoo.com (Brendan) Date: Wed, 17 Jun 2009 09:15:17 -0700 (PDT) Subject: exit() or sys.exit() Message-ID: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> What is the difference on exit() and sys.exit() when called in the main body of a script? From the command line they seem to have the same effect. Aside: Just used a python dictionary in which the keys were compiled regular expressions. Provided a very elegant solution. Have to love it. From python.list at tim.thechases.com Wed Jun 17 12:33:44 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 17 Jun 2009 11:33:44 -0500 Subject: exit() or sys.exit() In-Reply-To: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: <4A391AE8.8040605@tim.thechases.com> Brendan wrote: > What is the difference on exit() and sys.exit() when called in the > main body of a script? From the command line they seem to have the > same effect. In Python <=2.4 you had to use sys.exit() because __builtins__.exit() griped: tchase at asgix:~$ python2.4 Python 2.4.4 (#2, Apr 15 2008, 23:43:20) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> type(exit) >>> exit() Traceback (most recent call last): File "", line 1, in ? TypeError: 'str' object is not callable In 2.5, it's an instance of site.Quitter which is callable, allowing it to behave like sys.exit() (from my observations, __builtins__.exit() and sys.exit() behave the same). I tend to use sys.exit() because I've still got code running on machines mired at 2.4 -tkc From castironpi at gmail.com Wed Jun 17 12:34:47 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 09:34:47 -0700 (PDT) Subject: Executing a python script while it is running References: <4A381FBE.9040003@ieee.org> Message-ID: <16ed8850-33c9-4778-a263-15401d366f34@h28g2000yqd.googlegroups.com> On Jun 16, 3:48?pm, Zach Hobesh wrote: > > A lot more information would be useful. ?What version of Python, and what > > operating system environment? ?Exactly what would you like to happen when > > the batch file is invoked a second time? > > I'm running Python 2.6.2 on Windows. ?I'm passing filenames to the > batch files and I need all filenames to be processed. ?I can't have > any fails. ?I'm working on logging any fails I do have so that I can > maybe batch process at the end of the day. > > > ?2) let them both run as separate processes > > This sounds like a good option, but I'm not totally sure on how to go > about this? > > > ?4) queue something to be processed when the first run finishes > > I had the same idea, but I believe it would involve having another > python script run all day long, which wouldn't necessarily be a bad > thing, but I'd like to explore other options as well. This sort of falls under both categories, 2 & 4, and it will probably be judged 'poor practice' by history. We're all historians now, I guess. Windows has what's called a 'named mutex' for interprocess synchro'tion. Start your new process, acquire their shared mutex by name, and block on it. You will have one process for each file, but only one will run at once. You won't even need to build a shared library; 'ctypes' will suffice. From lie.1296 at gmail.com Wed Jun 17 12:37:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 16:37:04 GMT Subject: Exotic Logics In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > >> I was staring at a logic table the other day, and I asked myself, "what >> if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > your mind like it did mine. > > (This is not original to me -- I didn't create it. However, I can't find > the original source.) > > Imagine for a moment that there are no boolean values. > There are no numbers. They were never invented. > There are no classes. > There are no objects. > There are only functions. > > Could you define functions that act like boolean values? And could you > define other functions to operate on them? > > > def true(x, y): > return x > > def false(x, y): > return y > > def print_bool(b): > print b("true", "false") > String isn't considered object? Also, b/true()/false() is a function object, isn't it? Unless function is first-class, you can't pass them around like that, since you need a function pointer (a.k.a number); but if function is first-class then there it is an object. From castironpi at gmail.com Wed Jun 17 12:59:03 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 09:59:03 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> On Jun 17, 1:44?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > This might be useful for you, and if not useful, at least it might blow > your mind like it did mine. > > (This is not original to me -- I didn't create it. However, I can't find > the original source.) > > Imagine for a moment that there are no boolean values. > There are no numbers. ?They were never invented. > There are no classes. > There are no objects. > There are only functions. > > Could you define functions that act like boolean values? And could you > define other functions to operate on them? snip I think high and low /voltages/, though continuous and approximate, might satisfy this. There are no such things as electrons, only variations in density of the luminiferous ether. From rob.clewley at gmail.com Wed Jun 17 13:01:15 2009 From: rob.clewley at gmail.com (Rob Clewley) Date: Wed, 17 Jun 2009 13:01:15 -0400 Subject: ODE, GUI, plotter in Python In-Reply-To: <160620091700027246%shaibani@ymail.com> References: <160620091700027246%shaibani@ymail.com> Message-ID: There was just an announcement on this list and the scipy list for PyLab_Works, which sounds exactly like what you're looking for. I would not recommend starting over with a new simulator at this point. -Rob On Tue, Jun 16, 2009 at 12:00 PM, Ala wrote: > Hello everyone. > > I am starting on implementing a simulator using python, and since it's > the first time I code in python would appreciate a few pointers: > > The simulator will use a coupled ODE for the most part of the > simulation, I plan to use scipy. (Anything considered faster/better > than scipy for solving coupled ODEs? ) > > I plan for a GUI program with network graph plotting. I am leaning > towards using Qt for the GUI (internet forums seem to recommend it, > anyone got other preferences? ) > > Since the GUI application will contain few buttons and a plot, I am > planning to implement matplotlib into the GUI. But does anyone know if > matplotlib allows for interaction with the graph plot? (say for a > network simulation, allowing to right click on nodes and disable them > for instance, or alter some other properties of nodes and/or links > across them). > > I am just starting out, hence I'd rather get some advice and experiment > a bit for my self as I go along. > > Thank you. From castironpi at gmail.com Wed Jun 17 13:04:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:04:36 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <140d5517-f5a1-4027-9b52-c19964bdcf7e@i6g2000yqj.googlegroups.com> On Jun 17, 1:28?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > First question: what's an exotic logics? > > Do you mean things like three-value logic, fuzzy logic, probabilistic > reasoning, etc? You (OP) may be interested in the definitions of the fuzzy operators: and( x, y ) := min( x, y ) or( x, y ) := max( x, y ) not( x ) := 1 (one)- x nand( x, y ) := not( and( x, y ) ) = 1- min( x, y ) Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have: xor( x, y ) := min( max( x, y ), 1- min( x, y ) ) However, defining 'xor' as '( x and not y ) or ( y and not x )', we don't have: xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) ) Good question. From pdpinheiro at gmail.com Wed Jun 17 13:05:24 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 17 Jun 2009 10:05:24 -0700 (PDT) Subject: Exotic Logics References: Message-ID: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> On Jun 17, 5:37?pm, Lie Ryan wrote: > Steven D'Aprano wrote: > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > >> I was staring at a logic table the other day, and I asked myself, "what > >> if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > > your mind like it did mine. > > > (This is not original to me -- I didn't create it. However, I can't find > > the original source.) > > > Imagine for a moment that there are no boolean values. > > There are no numbers. ?They were never invented. > > There are no classes. > > There are no objects. > > There are only functions. > > > Could you define functions that act like boolean values? And could you > > define other functions to operate on them? > > > def true(x, y): > > ? ? return x > > > def false(x, y): > > ? ? return y > > > def print_bool(b): > > ? ? print b("true", "false") > > String isn't considered object? > > Also, b/true()/false() is a function object, isn't it? Unless function > is first-class, you can't pass them around like that, since you need a > function pointer (a.k.a number); but if function is first-class then > there it is an object. What Steven was doing was implementing some of the more basic stuff from Lambda calculus in python. If you're implementing a different system in an existing language, you'll need to use _some_ facilities of the original language to interface with the outside world. Anyway, here's a sample interactive session I just tried: >>> def a(stuff): ... print stuff ... >>> def b(stuff): ... stuff("abc") ... >>> b(a) abc functions are first-class citizens in python. From brendandetracey at yahoo.com Wed Jun 17 13:06:20 2009 From: brendandetracey at yahoo.com (Brendan) Date: Wed, 17 Jun 2009 10:06:20 -0700 (PDT) Subject: exit() or sys.exit() References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: <005747ad-7f29-41b7-afed-3b592d7bc2b5@l12g2000yqo.googlegroups.com> On Jun 17, 1:33?pm, Tim Chase wrote: > Brendan wrote: > > What is the difference on exit() and sys.exit() when called in the > > main body of a script? From the command line they seem to have the > > same effect. > > In Python <=2.4 you had to use sys.exit() because > __builtins__.exit() griped: > > ? ?tchase at asgix:~$ python2.4 > ? ?Python 2.4.4 (#2, Apr 15 2008, 23:43:20) > ? ?[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 > Type "help", "copyright", "credits" or "license" for more > information. > ? ?>>> type(exit) > ? ? > ? ?>>> exit() > ? ?Traceback (most recent call last): > ? ? ?File "", line 1, in ? > ? ?TypeError: 'str' object is not callable > > In 2.5, it's an instance of site.Quitter which is callable, > allowing it to behave like sys.exit() ?(from my observations, > __builtins__.exit() and sys.exit() behave the same). > > I tend to use sys.exit() because I've still got code running on > machines mired at 2.4 > > -tkc Okay. Thanks. From castironpi at gmail.com Wed Jun 17 13:20:51 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:20:51 -0700 (PDT) Subject: Exotic Logics References: <140d5517-f5a1-4027-9b52-c19964bdcf7e@i6g2000yqj.googlegroups.com> Message-ID: On Jun 17, 10:04?am, Aaron Brady wrote: snip > You (OP) may be interested in the definitions of the fuzzy operators: > > and( x, y ) := min( x, y ) > or( x, y ) := max( x, y ) > not( x ) := 1 (one)- x > nand( x, y ) := not( and( x, y ) ) = 1- min( x, y ) > > Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have: > > xor( x, y ) := min( max( x, y ), 1- min( x, y ) ) > > However, defining 'xor' as '( x and not y ) or ( y and not x )', we > don't have: > > xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) ) Corollary: xor1( x, y ) === xor2( x, y ). Non-exhaustive demonstration, excerpt: >>> def xor1( x, y ): ... return min( max( x, y ), 1- min( x, y ) ) ... >>> def xor2( x, y ): ... return max( min( x, 1- y ), min( y, 1- x ) ) ... >>> for i in range( 0, 11, 2 ): ... for j in range( 0, 11, 2 ): ... print i, j, xor2( x, y )*10, ' ', ... print 0 0 0.0 0 2 2.0 0 4 4.0 0 6 6.0 0 8 8.0 2 0 2.0 2 2 2.0 2 4 4.0 2 6 6.0 2 8 8.0 4 0 4.0 4 2 4.0 4 4 4.0 4 6 6.0 4 8 6.0 6 0 6.0 6 2 6.0 6 4 6.0 6 6 4.0 6 8 4.0 8 0 8.0 8 2 8.0 8 4 6.0 8 6 4.0 8 8 2.0 10 0 10.0 10 2 8.0 10 4 6.0 10 6 4.0 10 8 2.0 They appear to be equal. I forgot to mention, fuzzy values take on values from the continuous open or closed range 0 to 1. From mensanator at aol.com Wed Jun 17 13:23:59 2009 From: mensanator at aol.com (Mensanator) Date: Wed, 17 Jun 2009 10:23:59 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> Message-ID: <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> On Jun 17, 11:59?am, Aaron Brady wrote: > On Jun 17, 1:44?am, Steven D'Aprano > > > > wrote: > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > I was staring at a logic table the other day, and I asked myself, "what > > > if one wanted to play with exotic logics; how might one do it?" > > > This might be useful for you, and if not useful, at least it might blow > > your mind like it did mine. > > > (This is not original to me -- I didn't create it. However, I can't find > > the original source.) > > > Imagine for a moment that there are no boolean values. > > There are no numbers. ?They were never invented. > > There are no classes. > > There are no objects. > > There are only functions. > > > Could you define functions that act like boolean values? And could you > > define other functions to operate on them? > > snip > > I think high and low /voltages/, though continuous and approximate, > might satisfy this. > > There are no such things as electrons, I've got a Tesla coil if you'd like to meet some electrons personally. > only variations in density of > the luminiferous ether. From castironpi at gmail.com Wed Jun 17 13:30:39 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:30:39 -0700 (PDT) Subject: Exotic Logics References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: On Jun 17, 10:05?am, pdpi wrote: > On Jun 17, 5:37?pm, Lie Ryan wrote: > > > > > Steven D'Aprano wrote: > > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > >> I was staring at a logic table the other day, and I asked myself, "what > > >> if one wanted to play with exotic logics; how might one do it?" > > > > This might be useful for you, and if not useful, at least it might blow > > > your mind like it did mine. > > > > (This is not original to me -- I didn't create it. However, I can't find > > > the original source.) > > > > Imagine for a moment that there are no boolean values. > > > There are no numbers. ?They were never invented. > > > There are no classes. > > > There are no objects. > > > There are only functions. > > > > Could you define functions that act like boolean values? And could you > > > define other functions to operate on them? > > > > def true(x, y): > > > ? ? return x > > > > def false(x, y): > > > ? ? return y > > > > def print_bool(b): > > > ? ? print b("true", "false") > > > String isn't considered object? > > > Also, b/true()/false() is a function object, isn't it? Unless function > > is first-class, you can't pass them around like that, since you need a > > function pointer (a.k.a number); but if function is first-class then > > there it is an object. > > What Steven was doing was implementing some of the more basic stuff > from Lambda calculus in python. If you're implementing a different > system in an existing language, you'll need to use _some_ facilities > of the original language to interface with the outside world. Sir! Entropy levels are approaching dangerously low levels. We don't even have enough entropy to fi From castironpi at gmail.com Wed Jun 17 13:32:02 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:32:02 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> Message-ID: <1a554d09-a6c5-4cfa-99de-8252eb0a0195@r33g2000yqn.googlegroups.com> On Jun 17, 10:23?am, Mensanator wrote: > On Jun 17, 11:59?am, Aaron Brady wrote: > > > > > On Jun 17, 1:44?am, Steven D'Aprano > > > wrote: > > > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > > > I was staring at a logic table the other day, and I asked myself, "what > > > > if one wanted to play with exotic logics; how might one do it?" > > > > This might be useful for you, and if not useful, at least it might blow > > > your mind like it did mine. > > > > (This is not original to me -- I didn't create it. However, I can't find > > > the original source.) > > > > Imagine for a moment that there are no boolean values. > > > There are no numbers. ?They were never invented. > > > There are no classes. > > > There are no objects. > > > There are only functions. > > > > Could you define functions that act like boolean values? And could you > > > define other functions to operate on them? > > > snip > > > I think high and low /voltages/, though continuous and approximate, > > might satisfy this. > > > There are no such things as electrons, > > I've got a Tesla coil if you'd like to meet some electrons personally. The Wall Street Journal ran an article about Asian pleasure markets; they provide a-- quote-- "perfectly reasonable professional option". From castironpi at gmail.com Wed Jun 17 13:37:19 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 10:37:19 -0700 (PDT) Subject: Exotic Logics References: <1202bdf0-dcb4-4e15-9b72-da5245d6e9d7@k8g2000yqn.googlegroups.com> <8b7829c7-039f-4591-ada6-88d2a858f1e6@i6g2000yqj.googlegroups.com> <1a554d09-a6c5-4cfa-99de-8252eb0a0195@r33g2000yqn.googlegroups.com> Message-ID: On Jun 17, 10:32?am, Aaron Brady wrote: > On Jun 17, 10:23?am, Mensanator wrote: snip > > > I think high and low /voltages/, though continuous and approximate, > > > might satisfy this. > > > > There are no such things as electrons, > > > I've got a Tesla coil if you'd like to meet some electrons personally. > > The Wall Street Journal ran an article about Asian pleasure markets; > they provide a-- quote-- "perfectly reasonable professional option". For shame, Lieutenant. Always cite your source. http://online.wsj.com/article/SB124416693109987685.html Last paragraph, second to last sentence. It was a book review of _The East, the West, and Sex_ by Richard Bernstein . From cameron.pulsford at gmail.com Wed Jun 17 13:41:07 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 13:41:07 -0400 Subject: Pythonic way to overwrite a file Message-ID: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Hey all, hopefully a simple question. I'm writing a simple python tool that opens a file, and does something like for line in file.readlines(): temp.write(line.doStuff()) However, I want to provide the option do this "in place", as in have the destination file be the same as the source file. Currently, I am writing to a temp file and then using "os.system('mv %s %s' % (dstfile, srcfile))" to copy the destination file onto the soruce file. This is extremely ugly though, and will only work on unix based systems (I'm guessing, unless windows has mv too). Is there a more pythonic way to do this? Ideally I'd like to change the file as I go through it and not deal with a second file at all. That wouldn't have any atomicity though... What would be the most pythonic+safest way to do this? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip.groeger at googlemail.com Wed Jun 17 13:58:14 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Wed, 17 Jun 2009 19:58:14 +0200 Subject: Create 3D Surface / Contour (with vpython?) Message-ID: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Hi! How can I create a 3D surface (or something like the picture on the FAQ page http://www.vpython.org/contents/FAQ.html ) with python [or vpython]. Didnt find anything in the Documentation under "graph" Basically like a contourf diagram in 3D ( http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think you know what I mean. Reason: I want to simulate waves in a square basin. Hope I dont need to use hundrets of little spheres (in case of vpython) for the surface ;) Thanks alot - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcharrow at csail.mit.edu Wed Jun 17 14:06:12 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Wed, 17 Jun 2009 14:06:12 -0400 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Message-ID: <4A393094.9090701@csail.mit.edu> Cameron Pulsford wrote: > Hey all, hopefully a simple question. > > I'm writing a simple python tool that opens a file, and does something like > > for line in file.readlines(): > temp.write(line.doStuff()) > > However, I want to provide the option do this "in place", as in have the > destination file be the same as the source file. > Is loading the whole file into memory an option? If so, this should work: filename = "spam.txt" lines = open(filename).readlines() # Read new = [somefunction(line) for line in lines] # Change open(filename, 'w').writelines(new) # Write If you want to stick with your original approach, but want it to work cross platform, then I think this is what you want: http://docs.python.org/library/shutil#shutil.move HTH, Ben From jeanmichel at sequans.com Wed Jun 17 14:09:04 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Jun 2009 20:09:04 +0200 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> Message-ID: <4A393140.2060003@sequans.com> Cameron Pulsford wrote: > Hey all, hopefully a simple question. > > I'm writing a simple python tool that opens a file, and does something > like > > for line in file.readlines(): > temp.write(line.doStuff()) > > However, I want to provide the option do this "in place", as in have > the destination file be the same as the source file. Currently, I am > writing to a temp file and then using "os.system('mv %s %s' % > (dstfile, srcfile))" to copy the destination file onto the soruce > file. This is extremely ugly though, and will only work on unix based > systems (I'm guessing, unless windows has mv too). Is there a more > pythonic way to do this? Ideally I'd like to change the file as I go > through it and not deal with a second file at all. That wouldn't have > any atomicity though... What would be the most pythonic+safest way to > do this? > > Thanks in advance > Altering directly the file is dangerous, what if something goes wrong during the process ? Create a temp file and copying it if successful is your best bet. I guess using python modules like tempfile and shutil are a pythonic way to do it : import tempfile import shutil In [14]: tempfile.NamedTemporaryFile? Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, suffix='', prefix='tmp', dir=None) Docstring: Create and return a temporary file. Arguments: 'prefix', 'suffix', 'dir' -- as for mkstemp. 'mode' -- the mode argument to os.fdopen (default "w+b"). 'bufsize' -- the buffer size argument to os.fdopen (default -1). The file is created as mkstemp() would do it. Returns an object with a file-like interface; the name of the file is accessible as file.name. The file will be automatically deleted when it is closed. In [7]: shutil.copy? Definition: shutil.copy(src, dst) Docstring: Copy data and mode bits ("cp src dst"). The destination may be a directory. From cameron.pulsford at gmail.com Wed Jun 17 14:26:07 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 14:26:07 -0400 Subject: Pythonic way to overwrite a file In-Reply-To: <4A393140.2060003@sequans.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> Message-ID: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Essentially it just cleans up a source file of erroneous spaces and tabs and can also convert tabs to spaces so loading the whole file into memory is possibly an option. I am making this utility for personal use, and that would definitely be fine, but if it turned out well I'd open source it and then I wouldn't be so sure. This is only supposed to handle text files, so when would reading it all into memory become too much for most computers? I'm guessing there aren't many source files of too great a size. On Wed, Jun 17, 2009 at 2:09 PM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > Cameron Pulsford wrote: > >> Hey all, hopefully a simple question. >> >> I'm writing a simple python tool that opens a file, and does something >> like >> >> for line in file.readlines(): >> temp.write(line.doStuff()) >> >> However, I want to provide the option do this "in place", as in have the >> destination file be the same as the source file. Currently, I am writing to >> a temp file and then using "os.system('mv %s %s' % (dstfile, srcfile))" to >> copy the destination file onto the soruce file. This is extremely ugly >> though, and will only work on unix based systems (I'm guessing, unless >> windows has mv too). Is there a more pythonic way to do this? Ideally I'd >> like to change the file as I go through it and not deal with a second file >> at all. That wouldn't have any atomicity though... What would be the most >> pythonic+safest way to do this? >> Thanks in advance >> >> > Altering directly the file is dangerous, what if something goes wrong > during the process ? > Create a temp file and copying it if successful is your best bet. > > I guess using python modules like tempfile and shutil are a pythonic way > to do it : > > import tempfile > import shutil > > In [14]: tempfile.NamedTemporaryFile? > Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, > suffix='', prefix='tmp', dir=None) > Docstring: > Create and return a temporary file. > Arguments: > 'prefix', 'suffix', 'dir' -- as for mkstemp. > 'mode' -- the mode argument to os.fdopen (default "w+b"). > 'bufsize' -- the buffer size argument to os.fdopen (default -1). > The file is created as mkstemp() would do it. > > Returns an object with a file-like interface; the name of the file > is accessible as file.name. The file will be automatically deleted > when it is closed. > > > In [7]: shutil.copy? > Definition: shutil.copy(src, dst) > Docstring: > Copy data and mode bits ("cp src dst"). > > The destination may be a directory. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcfletch at vrplumber.com Wed Jun 17 14:44:42 2009 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Wed, 17 Jun 2009 14:44:42 -0400 Subject: Observer implementations In-Reply-To: References: Message-ID: <4A39399A.1030106@vrplumber.com> Tobias Weber wrote: > In article , > "Mike C. Fletcher" wrote: > > >> See PyDispatcher for code to do this. >> > > That was the original problem. Got it now: if used inside the class > definition dispatcher.connect will raise "cannot create weak reference > to 'classmethod' object". Outside (using Class.method) it works fine. > Ah, I think you've got a logic problem there. The classmethod during class creation has no reference to the class being created, so if you were to call *that* thing it would blow up: class x( object ): @classmethod def y( cls, text ): print text y( 'No you do not!' ) if you were to create a reference to *that* thing (the decorated un-bound class method) it would never have the binding for cls, so it wouldn't do anything. The correct way IMO to bind after-class-creation (e.g. by a class decorator or metaclass) where you reference a bound class method. If you *really* want to do it this way, you can do something like this: class x( object ): @classmethod def y( cls, value ): pass dispatcher.connect( lambda *args: x.y( *args ), signal='hello' ) but ick. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From ken at seehart.com Wed Jun 17 14:56:33 2009 From: ken at seehart.com (Ken Seehart) Date: Wed, 17 Jun 2009 11:56:33 -0700 Subject: Regarding Python is scripting language or not In-Reply-To: <501798.29841.qm@web94916.mail.in2.yahoo.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <4A393C61.3060504@seehart.com> abhishek goswami wrote: > Hi, > I have very basic question about Python that do we consider pyhton as > script language. > I searched in google but it becomes more confusion for me. After some > analysis I came to know that Python support oops . > > Can anyone Guide me that Python is Oject oriented programming language > or Script language > > Abhishek Goswami > Chennai > Phone No -0996227099 > ------------------------------------------------------------------------ > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > Both. Especially if you define the terms "object oriented" and "scripting" in terms of positive space (attributes that are present) instead of negative space (attributes that are not present). Python has all of the important features of OOP, but lacks some of the imposed constraints that some consider to be part of the definition of OOP (I personally do not consider the constraints to be central to a useful definition of OOP) Python has all of the important features that one would want in a scripting language (although it has a larger memory footprint than some scripting languages), but lacks many of limitations associated with "toy languages". Python is somewhat unique in it's ability to fill both of these areas so well without being unnatural. In my opinion, it is extremely useful to have one language that serves as both a highly scalable full-featured OOP language and as an extremely simple scripting language, because it allows one to build a large complex system within which one can easily do scripting tasks. Proof that python is a scripting language: print "Hello world" Proof that python is an OOP language benefiting from scripting capabilities: Django comes to mind. There are hundreds of others out there, but instead of listing them, I think I will get back to programming. Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jun 17 15:03:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Jun 2009 15:03:12 -0400 Subject: Regarding Python is scripting language or not In-Reply-To: <20090617123540.GA19607@wasteland.homelinux.net> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Jochen Schulz wrote: > abhishek goswami: >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language > > In my opinion, Python is both. But an "objective" answer would require > you to define what you means by these terms. > > If, by "object-oriented" you mean "everything has to be put into > classes", then Python is not object-oriented. That depends on what you mean by 'put into classes' (and 'everything'). If you mean 'be an instance of a class', which I think is the most natural reading, then Python *is* object-oriented and, if I understand what I have read correctly (so that ints are just (unboxed) ints and not members of an int class), Java *is not*! If you mean 'be an attribute of a class' (which to me is not 'in') or textually located within a class statement, then I doubt an language qualifies. It is impossible for every class statement to lie within a class statement and I wonder whether any language requires all classes to be attributes of some class (as opposed to subclasses or instances). However, if 'everything' means 'everything but classes', then, as I understand, Java and some others qualify. If fact, if one views modules as classes that cannot be instanced or as classes with one instance, themselves, then Python also qualifies. Python also qualifies if you mean 'be in some attribute of a class' and view modules as classes. *All* modules are values of sys.modules, including builtins, __main__, and sys itself. > If, by "scripting > language" you mean Python is an error-prone toy language, unsuitable for > large, serious projects, then Python is not a scripting language either. On the other hand, CPython is designed to be extended by and thereby script code written in C and C-wrapped Fortran. This is a big part of why it uses reference-counting for garbage collection. It also has functions for running other processes and interacting with other processes. Terry Jan Reedy From mr.william.clifford at gmail.com Wed Jun 17 15:05:00 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Wed, 17 Jun 2009 12:05:00 -0700 (PDT) Subject: Exotic Logics References: Message-ID: On Jun 17, 1:28?am, Steven D'Aprano wrote: > On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > > I was staring at a logic table the other day, and I asked myself, "what > > if one wanted to play with exotic logics; how might one do it?" > > First question: what's an exotic logics? > > Do you mean things like three-value logic, fuzzy logic, probabilistic > reasoning, etc? > > Or do you mean logical operators others than and, or, xor, nand, nor, etc? > > Or both? Something else? The short answer is 'yes'. Obviously, I don't know much about this stuff. I was looking a table of different operators and their truth values and saw that these were just different ways of reading and comparing numbers. I wrote this code to explore this idea in a general sense and see where it leads and learn something about computers. > [...] > > If (nearly) all your methods are static methods, chances are a class is > the wrong solution. Why not just define the static methods as top-level > functions? That is exactly how they started. I wrapped them up in an class because I thought I might want to create a bunch of them for testing and experimentation. I'm curious to see how combinations of functions give the same (or different) results. I've read one can do all of the 16 binary operations with clever uses of NAND or NOR. [SNIP] > You're implementation seems rather confusing. I think that's partly > because you use lots of abbreviated jargon terms that mean little or > nothing to me: rdx, opr (operator?), lsd, pute. Sorry about the confusion. It's because I'm confused. I should check out a book on the subject. Thanks for your help. -- William Clifford From jholloway7 at gmail.com Wed Jun 17 15:08:08 2009 From: jholloway7 at gmail.com (Joe Holloway) Date: Wed, 17 Jun 2009 14:08:08 -0500 Subject: strptime issue in multi-threaded application In-Reply-To: <8fe048f70906171057s2f183a06re7779afaf2f529a6@mail.gmail.com> References: <8fe048f70906171057s2f183a06re7779afaf2f529a6@mail.gmail.com> Message-ID: <8fe048f70906171208m7b652c5dj30011788fb025a2a@mail.gmail.com> Christian wrote: > > Joe Holloway schrieb: > > ImportError: Failed to import _strptime because the import lockis > > [sic] held by another thread. > > The error message is my fault. The cause of the mistake is obvious: No worries. The error message is clear even with the minor typo, I just wanted to recreate it here in case someone is searching for it down the road. > > Like I mentioned, it's only happened on a couple occasions because the > > right conditions have to be in place, but something doesn't seem right > > about it. ?I thought I'd ask on the mailing list before going so far > > as to open a ticket, but feel free to direct me there if that's the > > appropriate place for this. > > I have an idea what might happen in your application. Is an import > triggering the start of a thread? Not that I'm aware of. When the error is triggered, my module is simply calling into a library that's then calling into time.striptime(). The import that fails seems to be just a side effect of this. > You can get around the issue by decoupling imports from thread > startups. Your application should import all modules before it > starts its threaded components. To give you a better idea of the scenario, this is a Django web application deployed inside a WSGI container (mod_wsgi+Apache2). Ultimately, I'm not sure I have any control over when the imports occur since the WSGI container is what's managing the threads and my application is just being plugged into that container, if that makes sense. Consider that two URL handlers are likely be implemented in separate modules and hence both require a different set of imports. If both are served concurrently and one of them is making the first call to strptime while the other one has acquired the import lock, this can fail. Failing is obviously better than deadlocking, but it seems like pushing the workaround higher up in the call stack would cause some serious abstraction leaks. I don't fully understand what was causing the original deadlock, but my module should be able to call into time.strptime without incurring an ImportError or a deadlock under any circumstance? > For now you can decrease the severity of your issue by placing "import > _strptime" next to "import time" somewhere in your code. Once it a > module is loaded PyImport_ImportModuleNoBlock() will not fail to import > it a second time. Thanks for the workaround. I'm not all that concerned about the functional impact this has on my application since it has only happened a couple of times over the course of 6 weeks or so. My intent was more to make it visible in case there's a deeper design issue that can be addressed. Take care, Joe From vinay_sajip at yahoo.co.uk Wed Jun 17 15:15:34 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 17 Jun 2009 12:15:34 -0700 (PDT) Subject: A simpler logging configuration file format? References: <30db8a0b-5b19-47e4-9364-54cbd7a7cacf@h23g2000vbc.googlegroups.com> Message-ID: On Jun 5, 9:07?pm, geoff.ba... at gmail.com wrote: > Hi all, Some discussion about this has already taken place on the issue tracker: http://bugs.python.org/issue6136 and I thought I would summarise my comments there on this thread, for people who have no need to look at that issue. > At the moment, if I want to add a new logger "foo" writing to its own > file "foo" to my config file, I have to repeat the name 7(!) times, > editing 3 different sections in the process: Strictly speaking, you don't need to repeat the name "foo" 7 times. > 1) Add "foo" to [loggers] and [handlers]. (These seem completely > pointless and were apparently added in anticipation of new > functionality that never happened). You don't have to call the logger "foo" and the handler "foo". The names in the [loggers] and [handlers] section are just to allow the system to cross-refer different entities (loggers, handlers, formatters) declared in the config file. You could give the logger a name of "L1" and the handler a name of "H1", for example. > 2) Create the section > [logger_foo] > handler:foo > qualname:foo > level:INFO Here, if you named your logger L1, the section would be [logger_L1], not [logger_foo]. If you called your handler H1, then the handler line would be handlers=H1. The qualname is "foo" because you choose to log events to the logger named "foo". It could be more specific, e.g. "myapp.mymodule.myfunctionalarea". > 3) Create the section > [handler_foo] > class: FileHandler > args:("foo", "a") Here, if you named your handler H1, the section would be [handler_H1], not [handler_foo]. You've also called the log file "foo", which more conventionally you might name "foo.log". In your simple example where everything is named foo, and you've chosen to call cross-referencing handles within the file "foo", then naturally you repeat "foo" a lot of times. In an equivalent file [loggers] keys=root,L1 [handlers] keys=H1 [logger_L1] level=INFO handlers=H1 qualname=foo [handler_H1] class=FileHandler args=('foo.log', 'w') "foo" only occurs twice. > Wondering how it got like this, I found this blog from soon after it > was released in 2004: > > http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Pytho... > > Some of the verdicts are "full of dead chickens and error prone", > "horribly complicated" , "over-engineered". So along comes the > "basicConfig" method in 2005 which is supposed to address thes > concerns. But this can only be applied globally, not even to > individual loggers, so is only helpful for extremely basic usage > (everything to one target) as far as I can see. The config file is > still much as it was then. Some of this is just a consequence of using ConfigParser. The existing file format is not perfect or even complete (for example - no support for filters), and was proposed on python-dev for review before the logging package went into Python. The general consensus was that it was OK for basic use, and IIRC several people considered it as +0 or -0 because they envisaged doing their own thing (e.g. having the logging configuration as just part of an application's overall configuration). This is the reason configuration was put in a separate sub-module - if it's not needed, it needn't be loaded. AFAICT since basicConfig was introduced and later refined, there has not been much feedback about the configuration file format being a problem - and while that could be because no-one is using it, that's not borne out by the evidence. There have been numerous instances on c.l.py where questions have been raised about how to specify custom handlers in the configuration file, so at least some people are using it or have used it (the configuration functionality, I mean). > I'd really like to see the concept extended to encompass multiple > loggers and the config file. Allowing Logger.basicConfig should be > trivial. Writing a configuration format which took a section and > passed all the options in it to basicConfig would in my view lead to a > much friendlier syntax for normal usage. Well, basicConfig is for basic configuration of the logging package as a whole, not for configuring individual loggers or handlers. It's best not to conflate loggers and handlers - basicConfig might appear to do this because its arguments are partly specifying handler configuration and partly logger configuration. This is because it's the simplest case - one logger (the root logger) and one handler (according to the relevant arguments passed in). The handler-related arguments are used to create a default handler and/or formatter, the logging level is specified by the level argument, and it's applied to the root logger. It doesn't make sense to use the same approach if you are going to configure multiple loggers and handlers; if the existing format is not palatable, it's relatively easy to create your own format and write code to parse it and load it, and then call the programmatic API to configure logging appropriately. You mentioned on the bug tracker that you are coming from a background of using log4py - in which I believe loggers provide the functionality which is found in handlers in Python's logging. If you believe you have an idea for a much simpler configuration format (perhaps for simpler use cases, or perhaps for general use) I would encouraging writing an implementation and putting it up on PyPI so that people can play around with it and give feedback. ISTM that there is a general feeling that any sizeable new or changed functionality intended for the stdlib should be proven in the community through wide use before being seriously considered for inclusion. For example, I wrote a hierarchical configuration module, just one of several configuration-related modules on PyPI: http://pypi.python.org/pypi?%3Aaction=search&term=config&submit=search However, I am not proposing it for inclusion in the stdlib, as I don't believe it has had enough feedback yet from the community to be able to accurately gauge its quality or utility. From tjreedy at udel.edu Wed Jun 17 15:23:37 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Jun 2009 15:23:37 -0400 Subject: Exotic Logics In-Reply-To: References: Message-ID: William Clifford wrote: > same (or different) results. I've read one can do all of the 16 > binary > operations with clever uses of NAND or NOR. The book Laws of Form, by Spencer-Brown' is based on that observation, with nand/nor expanded to n-ary 'bag' functions (like sum() is). I recommend it, especially if you can find it in a library. tjr From lists at cheimes.de Wed Jun 17 15:25:08 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Jun 2009 21:25:08 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Terry Reedy wrote: > If you mean 'be an instance of a class', which I think is the most > natural reading, then Python *is* object-oriented and, if I understand > what I have read correctly (so that ints are just (unboxed) ints and not > members of an int class), Java *is not*! A friend of mine calls Java and C++ class centric programming languanges. ;) Christian From gokhansever at gmail.com Wed Jun 17 15:43:43 2009 From: gokhansever at gmail.com (=?UTF-8?Q?G=C3=B6khan_SEVER?=) Date: Wed, 17 Jun 2009 14:43:43 -0500 Subject: Create 3D Surface / Contour (with vpython?) In-Reply-To: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> References: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Message-ID: <49d6b3500906171243g1a3df390pa4f95b7fad103efe@mail.gmail.com> On Wed, Jun 17, 2009 at 12:58 PM, Philip Gr?ger < philip.groeger at googlemail.com> wrote: > Hi! > How can I create a 3D surface (or something like the picture on the FAQ > page http://www.vpython.org/contents/FAQ.html ) with python [or vpython]. > Didnt find anything in the Documentation under "graph" > Basically like a contourf diagram in 3D ( > http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think > you know what I mean. > > Reason: I want to simulate waves in a square basin. Hope I dont need to use > hundrets of little spheres (in case of vpython) for the surface ;) > > Thanks alot > > - Philip > -- > http://mail.python.org/mailman/listinfo/python-list > > I suggest two alternatives, second one being the fancier: http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo.html http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#enthought.mayavi.mlab.surf -------------- next part -------------- An HTML attachment was scrubbed... URL: From Samnsparky at gmail.com Wed Jun 17 15:56:11 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 17 Jun 2009 12:56:11 -0700 (PDT) Subject: SHM and Touchpad Message-ID: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Hello! I am writing an application that requires access to the state of a synaptics touch pad on a laptop running Ubuntu Linux (for the number of fingers, pressure, x location, y location, etc). A different program using C++ accesses the information through SHM and I was hoping to do the same with Python. I looked in PyPi and I noticed that there was a module for SHM but I can not figure out where to download it from (http://pypi.python.org/pypi/shm). Does anyone have any suggestions? Thanks, Sam From jcd at sdf.lonestar.org Wed Jun 17 16:03:21 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 17 Jun 2009 16:03:21 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A38DDDB.5070309@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> Message-ID: <1245269001.27277.28.camel@aalcdl07> On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> What's np.arange? > >> > > > > import numpy as np > > > > -- > > Pierre "delroth" Bourdon > > ?tudiant ? l'EPITA / Student at EPITA > > > > Perfect example of why renaming namespaces should be done only when > absolutely required, that is, almost never. > > Jean-Michel I disagree. Renaming namespaces should always be done if it will help stop people from doing a 'from package import *'. However, example code should always include relevant imports. Cheers, Cliff From martin.hellwig at dcuktec.org Wed Jun 17 16:05:09 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Jun 2009 21:05:09 +0100 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: edexter wrote: > > it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 > Redistributable Package > did not help.. I had simular problems > with alot of installers I had saved (from installing on xp) but when > I grabbed newer installers > they all worked, could be the manifast.... I was looking forward to > trying it out.. > > Did you tried this one? http://www.microsoft.com/downloads/details.aspx?FamilyID=200b2fd9-ae1a-4a14-984d-389c36f85647&displaylang=en Found via: http://lmgtfy.com/?q=Microsoft+Visual+C%2B%2B+2005+SP1+Redistributable+Package+(x86)&l=1 -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From mani at tungle.com Wed Jun 17 16:05:48 2009 From: mani at tungle.com (Mani Ghasemlou) Date: Wed, 17 Jun 2009 16:05:48 -0400 Subject: logging.fileConfig limitations? Message-ID: Hi all, I have an application that writes out its logs in a subfolder of the user's local data directory. Let's say our user's name is "?????2". On my Windows XP machine, this logging path turns out to be: C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.log My application has a "bootstrap" kind of application that sets up the application's subfolder and writes out the log config file. Notice that the user's name contains non-ASCII characters. So, I encode the path in UTF8 format before writing the log config file. My resulting log config is (the last line is the most important): ----- BEGIN [formatters] keys: normal [handlers] keys: rotatingfile [loggers] keys: root [formatter_normal] format: %(asctime)s %(levelname)s %(module)s: %(message)s [logger_root] level: DEBUG handlers: rotatingfile [handler_rotatingfile] class: handlers.RotatingFileHandler formatter: normal args: ["C:/Documents and Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log", "a", 2*1024*1024, 5, None] ----- END Now it turns out that the logging module can't find "C:/Documents and Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log" specified in the "args" section, and rightfully so because this is an encoded string. *There does not seem to be a way for me to specify the encoding of the string so that the logging module resolves the proper unicode path.* This is my key problem! Is there some way to accomplish what I want? One interesting observation: I did some poking around in the logging module shipped with Python 2.5. I put in some code in the Python logging module to force UTF8 decoding of the "filename" argument, the result of which was interesting: it would end up logging in "C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.txt" (not MyApp.log !). I've done a little debugging and can't immediately figure out why this is happening. Any help would be greatly appreciated! Regards, Mani From philip at semanchuk.com Wed Jun 17 16:09:18 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Jun 2009 16:09:18 -0400 Subject: SHM and Touchpad In-Reply-To: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: On Jun 17, 2009, at 3:56 PM, Sparky wrote: > Hello! I am writing an application that requires access to the state > of a synaptics touch pad on a laptop running Ubuntu Linux (for the > number of fingers, pressure, x location, y location, etc). A different > program using C++ accesses the information through SHM and I was > hoping to do the same with Python. I looked in PyPi and I noticed that > there was a module for SHM but I can not figure out where to download > it from (http://pypi.python.org/pypi/shm). Does anyone have any > suggestions? Hi Sam, I'm not familiar with that shm, however there was (and still is) a old Python IPC module called shm. It uses Sys V semaphores, not POSIX semaphores like the shm in pypi. The old shm module has been replaced by two newer ones. For Sys V IPC: http://semanchuk.com/philip/sysv_ipc/ For POSIX IPC: http://semanchuk.com/philip/posix_ipc/ The old shm module is still around on semanchuk.com but I'm not updating it anymore (the author is AWOL and I'm just the maintainer) and I don't recommend using it. HTH Philip From Samnsparky at gmail.com Wed Jun 17 16:13:39 2009 From: Samnsparky at gmail.com (Sparky) Date: Wed, 17 Jun 2009 13:13:39 -0700 (PDT) Subject: SHM and Touchpad References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: On Jun 17, 2:09?pm, Philip Semanchuk wrote: > On Jun 17, 2009, at 3:56 PM, Sparky wrote: > > > Hello! I am writing an application that requires access to the state > > of a synaptics touch pad on a laptop running Ubuntu Linux (for the > > number of fingers, pressure, x location, y location, etc). A different > > program using C++ accesses the information through SHM and I was > > hoping to do the same with Python. I looked in PyPi and I noticed that > > there was a module for SHM but I can not figure out where to download > > it from (http://pypi.python.org/pypi/shm). Does anyone have any > > suggestions? > > Hi Sam, > I'm not familiar with that shm, however there was (and still is) a old ? > Python IPC module called shm. It uses Sys V semaphores, not POSIX ? > semaphores like the shm in pypi. > > The old shm module has been replaced by two newer ones. For Sys V IPC:http://semanchuk.com/philip/sysv_ipc/ > > For POSIX IPC:http://semanchuk.com/philip/posix_ipc/ > > The old shm module is still around on semanchuk.com but I'm not ? > updating it anymore (the author is AWOL and I'm just the maintainer) ? > and I don't recommend using it. > > HTH > Philip Dear Philip, Thank you for your quick response, I will take a look at the link you provided. From manu3d at gmail.com Wed Jun 17 16:17:13 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 17 Jun 2009 13:17:13 -0700 (PDT) Subject: etree, lxml unexpected behaviour Message-ID: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> Hi everybody, I just tried the following: >>> import xml.etree.ElementTree as etree >>> e = etree.fromstring('') >>> e.getchildren()[0].attrib {'anAttr': '1', '{anotherNamespace}anotherAttr': '2'} Notice the lack of namespace before the attribute "anAttr". I find this unexpected because as you can see I did set the default namespace with xmlns="aNamespace" and the elements (rather than the attributes) are correctly associated with it, i.e.: >>> e Is there a way to change this behaviour so that attributes without namespace are correctly associated with the default namespace, just like the elements? lxml exhibit the exact same behaviour. Manu From lie.1296 at gmail.com Wed Jun 17 16:22:03 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 20:22:03 GMT Subject: SHM and Touchpad In-Reply-To: References: <02038faa-91a3-4326-87ab-c237c26121de@g19g2000yql.googlegroups.com> Message-ID: Sparky wrote: > > Thank you for your quick response, I will take a look at the link you > provided. Depending on what you're trying to do, you may be able to use `synclient` with subprocess. From cameron.pulsford at gmail.com Wed Jun 17 16:35:58 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Wed, 17 Jun 2009 16:35:58 -0400 Subject: Reading and setting file permissions programmatically Message-ID: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Sorry to flood the list but my google fu isn't up to par today I guess. Basically, is it possible to read the permissions on one file and then set the permissions of another file to the ones we just read? os.dup2 seemed like it would work but I might not be using it correctly. I know there is os.chmod, but I haven't found the equivalent to read permissions. Preferably this would work on unix and windows too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Wed Jun 17 16:36:31 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 20:36:31 GMT Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: Jean-Michel Pichavant wrote: > abhishek goswami wrote: >> Hi, >> I have very basic question about Python that do we consider pyhton as >> script language. >> I searched in google but it becomes more confusion for me. After some >> analysis I came to know that Python support oops . >> >> Can anyone Guide me that Python is Oject oriented programming language >> or Script language >> >> Abhishek Goswami >> Chennai >> Phone No -0996227099 >> >> >> ------------------------------------------------------------------------ >> ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET >> > Depends on what you are calling a scripting language. > Refering to wikipedia, > "A *scripting language*, *script language* or *extension language* is a > programming language > that allows some control of a single or many software application(s) > ." > > Python is definitely OOP oriented and I don't think it fits in the > script definition above. Python is multiparadigm. It is a mix of OOP language and functional language. It does not force you to use certain paradigm and allows you to mix paradigms in a single piece of code. Python is a programming language when referring to the stand-alone virtual machine. Python is a scripting language when used inside OpenOffice.org or Inkscape or GIMP or Blender or other software that uses python as scripting language. You may also argue that python is a scripting language for the OS. IMHO, whether a language is scripting language or programming language is independent of the language (Python, Java, Basic, C, etc) nor the implementation (CPython, Sun's JVM, VB, GCC, etc) of the language, but instead tied to the usage of the language (Stand-alone Python vs. python on OpenOffice/Blender/GIMP/Inkscape, Standalone Java vs. browser-based Java, VB vs. VBA/VBScript, etc). > Python is interpreted and platform independent, but you can still build > standalone platform dependent binaries if required. > > Regarding your last question, I'm not sure scripting and OOP language > are not compatible, I'm pretty sure you'll be able to find OOP scripting > language. > > Jean-Michel From stefan_ml at behnel.de Wed Jun 17 16:58:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Jun 2009 22:58:06 +0200 Subject: etree, lxml unexpected behaviour In-Reply-To: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> References: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> Message-ID: <4a3958de$0$30230$9b4e6d93@newsspool1.arcor-online.net> Emanuele D'Arrigo wrote: > Hi everybody, I just tried the following: > >>>> import xml.etree.ElementTree as etree >>>> e = etree.fromstring('') >>>> e.getchildren()[0].attrib > {'anAttr': '1', '{anotherNamespace}anotherAttr': '2'} > > Notice the lack of namespace before the attribute "anAttr". I find > this unexpected because as you can see I did set the default namespace > with xmlns="aNamespace" and the elements (rather than the attributes) > are correctly associated with it, i.e.: > >>>> e > > > Is there a way to change this behaviour so that attributes without > namespace are correctly associated with the default namespace, just > like the elements? There isn't, because this is the correct behaviour according to the spec. http://www.w3.org/TR/REC-xml-names/#defaulting """ A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. """ Stefan From python at mrabarnett.plus.com Wed Jun 17 17:09:41 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Jun 2009 22:09:41 +0100 Subject: Reading and setting file permissions programmatically In-Reply-To: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> References: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Message-ID: <4A395B95.3070801@mrabarnett.plus.com> Cameron Pulsford wrote: > Sorry to flood the list but my google fu isn't up to par today I guess. > > Basically, is it possible to read the permissions on one file and then > set the permissions of another file to the ones we just read? os.dup2 > seemed like it would work but I might not be using it correctly. > > I know there is os.chmod, but I haven't found the equivalent to read > permissions. Preferably this would work on unix and windows too. > os.stat(path).st_mode From manu3d at gmail.com Wed Jun 17 17:15:52 2009 From: manu3d at gmail.com (Emanuele D'Arrigo) Date: Wed, 17 Jun 2009 14:15:52 -0700 (PDT) Subject: etree, lxml unexpected behaviour References: <80c0ae14-11be-4891-99cb-e5de5604ba4c@h18g2000yqj.googlegroups.com> <4a3958de$0$30230$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <3083d542-26ab-4b57-87b9-a848181e7bcc@w40g2000yqd.googlegroups.com> Thank you for the clarification Stefan, I understand. From philr at aspexconsulting.co.nz Wed Jun 17 17:18:04 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Thu, 18 Jun 2009 09:18:04 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: Because it reminds me of when things went badly wrong. IBM360, Von Neumann architecture, no hardware stacks ... IMHO Burroughs and ICL had better approaches to OS design back then but had less resources to develop their ideas. However, mainly this period marked a transition from the excitement and discovery phase of computing to commercial power plays and take-overs. The best ideas in a field tend to get lost in the melee of competition. Early computers were rooted in academia and there was a lot of cross fertilisation of ideas and approaches. IMHO commerce affected layers of the stack where it had no useful contribution to make. Vertical integration warred against sound architecture. The book has an important message and I recommend that people read it. The book is to me, and possibly only me, an icon representing when things went wrong. -----Original Message----- From: Lawrence D'Oliveiro [mailto:ldo at geek-central.gen.new_zealand] Sent: Wednesday, 17 June 2009 5:50 p.m. To: python-list at python.org Subject: RE: Good books in computer science? In message , Phil Runciman wrote: > FWIW I actually dislike this book! Why? From lie.1296 at gmail.com Wed Jun 17 17:21:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Jun 2009 21:21:27 GMT Subject: Exotic Logics In-Reply-To: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: pdpi wrote: > On Jun 17, 5:37 pm, Lie Ryan wrote: >> Steven D'Aprano wrote: >>> On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: >>>> I was staring at a logic table the other day, and I asked myself, "what >>>> if one wanted to play with exotic logics; how might one do it?" >>> This might be useful for you, and if not useful, at least it might blow >>> your mind like it did mine. >>> (This is not original to me -- I didn't create it. However, I can't find >>> the original source.) >>> Imagine for a moment that there are no boolean values. >>> There are no numbers. They were never invented. >>> There are no classes. >>> There are no objects. >>> There are only functions. >>> Could you define functions that act like boolean values? And could you >>> define other functions to operate on them? >>> def true(x, y): >>> return x >>> def false(x, y): >>> return y >>> def print_bool(b): >>> print b("true", "false") >> String isn't considered object? >> >> Also, b/true()/false() is a function object, isn't it? Unless function >> is first-class, you can't pass them around like that, since you need a >> function pointer (a.k.a number); but if function is first-class then >> there it is an object. > > What Steven was doing was implementing some of the more basic stuff > from Lambda calculus in python. If you're implementing a different > system in an existing language, you'll need to use _some_ facilities > of the original language to interface with the outside world. Anyway, > here's a sample interactive session I just tried: > >>>> def a(stuff): > .... print stuff > .... >>>> def b(stuff): > .... stuff("abc") > .... >>>> b(a) > abc > > functions are first-class citizens in python. I've just reread my sentence, and even I wouldn't have understood (or would misunderstood) what I was talking about if it was worded like that. What I meant was: if you can pass a function as an argument to another function, that means either: 1) you must use function pointer (numbers) or 2) function is a first-class object. Both violates the restriction (no number and no object respectively). Even after abandoning the semantics of functions in python, going to function as in purely mathematical sense, I still am not convinced (warning: I don't know lambda calculus, although I program in heavily functional style). PS: the string comment was meant to be a joke... From basti.wiesner at gmx.net Wed Jun 17 17:41:53 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Wed, 17 Jun 2009 23:41:53 +0200 Subject: exit() or sys.exit() References: <5f1506fa-ad99-4b1c-8c36-9a71e2375e9d@y7g2000yqa.googlegroups.com> Message-ID: > What is the difference on exit() and sys.exit() when called in the > main body of a script? From the command line they seem to have the > same effect. As of Python 2.5 there is no difference, however documentation [1] says about exit() and quit(): > They are useful for the interactive interpreter shell and should not be > used in programs. [1] http://docs.python.org/library/constants.html#constants-added-by-the- site-module -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From alan.isaac at gmail.com Wed Jun 17 18:00:38 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 22:00:38 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> Message-ID: On 6/17/2009 4:03 PM J. Cliff Dyer apparently wrote: > example code > should always include relevant imports. Agreed. It was a cut and paste failure. Apologies. Alan Isaac From kyrie at uh.cu Wed Jun 17 18:03:08 2009 From: kyrie at uh.cu (Luis Alberto Zarrabeitia Gomez) Date: Wed, 17 Jun 2009 18:03:08 -0400 Subject: Exotic Logics In-Reply-To: References: <98790d3e-4389-46b5-8b5a-ceb27ede60fe@x3g2000yqa.googlegroups.com> Message-ID: <1245276188.4a39681ca6b3b@mail.uh.cu> Quoting Lie Ryan : > pdpi wrote: > > On Jun 17, 5:37 pm, Lie Ryan wrote: > >> Steven D'Aprano wrote: > >>> On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > >>>> I was staring at a logic table the other day, and I asked myself, "what > >>>> if one wanted to play with exotic logics; how might one do it?" > >>> This might be useful for you, and if not useful, at least it might blow > >>> your mind like it did mine. > >>> (This is not original to me -- I didn't create it. However, I can't find > >>> the original source.) > >>> Imagine for a moment that there are no boolean values. > >>> There are no numbers. They were never invented. > >>> There are no classes. > >>> There are no objects. > >>> There are only functions. > >>> Could you define functions that act like boolean values? And could you > >>> define other functions to operate on them? > >>> [basic lambda calculus definitions] [...] > What I meant was: if you can pass a function as an argument to another > function, that means either: 1) you must use function pointer (numbers) > or 2) function is a first-class object. Both violates the restriction > (no number and no object respectively). > > Even after abandoning the semantics of functions in python, going to > function as in purely mathematical sense, I still am not convinced > (warning: I don't know lambda calculus, although I program in heavily > functional style). You are confusing semantics with implementation. At some point, of course one would need to use real object (at the lowest level, the computer I'm typing this in is a physical object). But the interesting part is that you can define the whole logic system using nothing but functions. You may need to implement it using objects, or maybe you could devise a machine that will behave like that using only sticks on the floor, but that doesn't matter. From the user's perspective, there would be only functions: no strings, no objects, no numbers. That reminds me of my last class (disclaimer: I teach discrete math). I told my students "well, let's assume that numbers exist", and I wasn't making fun of them... I found that topic easier to understand (computability, primitive recursion) if one ignores the numbers, even if one obviously has to write them somewhere at some point. -- Luis Zarrabeitia Facultad de Matem?tica y Computaci?n, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu From alan.isaac at gmail.com Wed Jun 17 18:07:28 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Wed, 17 Jun 2009 22:07:28 GMT Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: On 6/17/2009 8:38 AM Jean-Michel Pichavant apparently wrote: > I'm pretty sure you'll be able to find OOP scripting > language. fwiw, Alan Isaac From steven.samuel.cole at gmail.com Wed Jun 17 18:19:38 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Wed, 17 Jun 2009 15:19:38 -0700 (PDT) Subject: generator expression works in shell, NameError in script Message-ID: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Hello, I am trying to generate this list of tuples: [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] My code works fine in the Python shell: >>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>> title_choices [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] The same code run in a script fails with NameError: global name 'titles' is not defined Does anybody know why ? How can I fix the error ? Thank you very much :-) Steve From bearophileHUGS at lycos.com Wed Jun 17 18:22:41 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Wed, 17 Jun 2009 15:22:41 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <37cc0e5b-6ecd-42b9-8f81-74feb51240ec@j18g2000yql.googlegroups.com> Nathan Stoddard: > The best way to become a good programmer is to program. Write a lot of > code; work on some large projects. This will improve your skill more than > anything else. It's also important to learn new languages regularly. I > recommend to learn C, Python, and Lisp first. To become very good in a practical activity (like programming or writing stories or playing piano) you have to do many things for a lot of time. You have to practice it a lot, but that's not enough. You also must keep pushing forward the limit of your skills, doing things hard for you. Reading smart books and learning from the experts in the field is usually necessary. Quite often it's useful to read good books not much related with the activity you are doing too, because the human mind works better this way. Another thing you have to do is to keep your eyes open, for example to be able to understand when your learning is struck in some slow corner: now and then you will have to meta-learn, that is to change the way you learn and train yourself. This is a hard and often painful thing to do, but it's probably necessary if you want to become very good, because very often you learn in the wrong way, or in a not much efficient way. Howard Gardner too has written about such topic. Bye, bearophile From emile at fenx.com Wed Jun 17 18:27:32 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 15:27:32 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: On 6/17/2009 3:19 PM ssc said... > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > >>>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>>> title_choices > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined You get this because titles doesn't exist in the builtin, local or global namespaces. Post the code that fails. It's hard to debug working code. :) Emile > > Does anybody know why ? How can I fix the error ? > > Thank you very much :-) > > Steve From ldo at geek-central.gen.new_zealand Wed Jun 17 18:33:49 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 10:33:49 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > On Wed, 17 Jun 2009 23:04:37 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >> >>> On Wed, 17 Jun 2009 17:53:33 +1200 >>> Lawrence D'Oliveiro wrote: >>> >>>>> Why not use hex representation of md5/sha1-hashed id as a path, >>>>> arranging them like /path/f/9/e/95ea4926a4 ? >>>>> >>>>> That way, you won't have to deal with many-files-in-path problem ... >>>> >>>> Why is that a problem? >>> >>> So you can os.listdir them? >> >> Why should you have a problem os.listdir'ing lots of files? > > I shouldn't, and I don't ;) Then why did you suggest that there was a problem being able to os.listdir them? From clp2 at rebertia.com Wed Jun 17 18:38:47 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Jun 2009 15:38:47 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> On Wed, Jun 17, 2009 at 3:19 PM, ssc wrote: > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > >>>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) >>>> title_choices > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined > > Does anybody know why ? How can I fix the error ? See what Emile said, but here's a nicer way to code it, IMHO: titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms'] title_choices = zip(range(len(titles)+1), ['']+titles) zip() to the rescue! Cheers, Chris -- http://blog.rebertia.com From tack at urandom.ca Wed Jun 17 18:41:44 2009 From: tack at urandom.ca (Jason Tackaberry) Date: Wed, 17 Jun 2009 18:41:44 -0400 Subject: generator expression works in shell, NameError in script In-Reply-To: <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> Message-ID: <1245278504.6577.120.camel@arrakis> On Wed, 2009-06-17 at 15:38 -0700, Chris Rebert wrote: > See what Emile said, but here's a nicer way to code it, IMHO: > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms'] > title_choices = zip(range(len(titles)+1), ['']+titles) > > zip() to the rescue! How about: enumerate([''] + titles) From emile at fenx.com Wed Jun 17 18:46:50 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 15:46:50 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <1245278504.6577.120.camel@arrakis> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <1245278504.6577.120.camel@arrakis> Message-ID: On 6/17/2009 3:41 PM Jason Tackaberry said... > How about: > > enumerate([''] + titles) > or perhaps, depending on usage... list(enumerate(titles)) Emile From joncle at googlemail.com Wed Jun 17 18:49:03 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 17 Jun 2009 15:49:03 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> Message-ID: <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> On Jun 17, 11:19?pm, ssc wrote: > Hello, > > I am trying to generate this list of tuples: > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > My code works fine in the Python shell: > > >>> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > >>> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) > >>> title_choices > > [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] > > The same code run in a script fails with > NameError: global name 'titles' is not defined > > Does anybody know why ? How can I fix the error ? > > Thank you very much :-) > > Steve Why are you doing this? I'm assuming a code to title look up is required (don't forget military, royal and honorable titles etc... :) ) Why not just: >>> titles = ['', 'Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >>> lookup = dict(enumerate(titles)) >>> print lookup {0: '', 1: 'Dr', 2: 'Miss', 3: 'Mr', 4: 'Mrs', 5: 'Ms'} or if you don't want a dict, then just: >>> print list(enumerate(titles)) [(0, ''), (1, 'Dr'), (2, 'Miss'), (3, 'Mr'), (4, 'Mrs'), (5, 'Ms')] From rhodri at wildebst.demon.co.uk Wed Jun 17 18:53:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Jun 2009 23:53:28 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Wed, 17 Jun 2009 16:06:22 +0100, Aaron Brady wrote: > On Jun 16, 10:09?am, Mike Kazantsev wrote: >> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) >> >> Aaron Brady wrote: >> > Making the charitable interpretation that this was the extent of c-l- >> > py's support and enthusiasm for my idea, I will now go into mourning. >> > Death occurred at oh-eight-hundred. ?Rest in peace, support & >> > enthusiasm. >> >> I've read this thread from the beginning, being tempted to insert >> remarks about shelve module or ORMs like SQLAlchemy, but that'd be >> meaningless without the problem description, which I haven't seen >> anywhere. Is it some trick idea like "let's walk on our heads"? > > More like bronze them, or hang them on a tackboard. You haven't > convinced me that it's not a problem, or that it's an easy one. Unfortunately it's up to you to demonstrate that it is a problem, whichever of the many possible 'it's you're talking about. So far, the question "Why would I want to use this? What's the use case?" has gone unanswered, and I'm sure I'm not the only baffled by it. -- Rhodri James *-* Wildebeest Herder to the Masses From tim.wintle at teamrubber.com Wed Jun 17 18:54:23 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 17 Jun 2009 23:54:23 +0100 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Message-ID: <1245279263.9195.27.camel@tim-laptop> On Wed, 2009-06-17 at 14:26 -0400, Cameron Pulsford wrote: > This is only supposed to handle text files, so when would reading it > all into memory become too much for most computers? I'm guessing there > aren't many source files of too great a size. I often use python with server log files - 1Tb of plain-text wouldn't seem too much to me, but it wouldn't fit into ram on many computers ;-) For source files I wouldn't think it would be a problem - but I agree with Jean-Michel, I can imagine running an app like yours over hundreds of source files at once. It wouldn't be nice if I decided to kill the program half way through and found it had died half way through processing a file and lost my code! Tim Wintle From steven.samuel.cole at gmail.com Wed Jun 17 18:54:28 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Wed, 17 Jun 2009 15:54:28 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> Message-ID: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Wow! Didn't expect that kind of instant support. Thank you very much, I'll give both zip and enumerate a try. The code I've shown is actually copied pretty straight from a Django form class, but I didn't want to mention that as not to dilute the conversation. Don't think it matters, anyway. This is the relevant excerpt: from django.forms import Form class SignupForm(Form): titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in titles) Now that I look at it again, it seems odd to me to not have the code e.g. in __init__(...), but just 'class-global'. Still, that does not seem a reason for titles not to be not defined, as I do define it just in the line above. Does the generator expression have its own little namespace or so ? From rhodri at wildebst.demon.co.uk Wed Jun 17 18:58:25 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Jun 2009 23:58:25 +0100 Subject: Pythonic way to overwrite a file In-Reply-To: <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> References: <5700df6b0906171041s520a79an830e3d31e92b8d25@mail.gmail.com> <4A393140.2060003@sequans.com> <5700df6b0906171126r2685b6c8qcd8259579199d5bd@mail.gmail.com> Message-ID: Top-posting, tsk, tsk. On Wed, 17 Jun 2009 19:26:07 +0100, Cameron Pulsford wrote: > Essentially it just cleans up a source file of erroneous spaces and tabs > and > can also convert tabs to spaces so loading the whole file into memory is > possibly an option. I am making this utility for personal use, and that > would definitely be fine, [snip] You won't say that the first time it screws up and destroys one of your files. Making in-place changes is something that should set big red lights flashing in software engineering terms. You don't want to get into the habit of doing that, especially for personal use. -- Rhodri James *-* Wildebeest Herder to the Masses From stef.mientki at gmail.com Wed Jun 17 18:59:25 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 18 Jun 2009 00:59:25 +0200 Subject: first full alpha release of PyLab_Works v0.3 In-Reply-To: References: <9d0b9ac5-3ae2-449c-b929-73960519b68a@l12g2000yqo.googlegroups.com> Message-ID: <4A39754D.5020604@gmail.com> >>> program didn't start because .dll is missing (sorry I don't have the >>> name)... I don't know if that is just an issue with the installer >>> with vista or not (missing msv something 71. dll) >>> >> You probably mean the microsoft visual C++ runtime (msvcr71.dll), >> windows vista has a brand new way (via manifest files) to make it more >> difficult to install compiled binaries. >> >> Search for 'Microsoft Visual C++ 2005 Redistributable Package' and >> install it. >> >> -- >> MPHhttp://blog.dcuktec.comm >> 'If consumed, best digested with added seasoning to own preference.' >> > > it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005 > Redistributable Package > did not help.. I had simular problems > with alot of installers I had saved (from installing on xp) but when > I grabbed newer installers > they all worked, could be the manifast.... I was looking forward to > trying it out.. > > I rebuild the package with all windows system files included, suggested by Py2Exe, see the installation instructions: http://mientki.ruhosting.nl/data_www/pylab_works/pw_installation.html these system files will be unpacked in the root of the installation. I'm not familiar with Windows Vista, but this would be the trick in Windows XP. cheers, Stef From clp2 at rebertia.com Wed Jun 17 19:11:19 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Jun 2009 16:11:19 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> On Wed, Jun 17, 2009 at 3:54 PM, ssc wrote: > Wow! Didn't expect that kind of instant support. Thank you very much, > I'll give both zip and enumerate a try. > > The code I've shown is actually copied pretty straight from a Django > form class, but I didn't want to mention that as not to dilute the > conversation. Don't think it matters, anyway. This is the relevant > excerpt: > > from django.forms import Form > > class SignupForm(Form): > > ? ?titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > ? ?title_choices ? = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Now that I look at it again, it seems odd to me to not have the code > e.g. in __init__(...), but just 'class-global'. > Still, that does not seem a reason for titles not to be not defined, > as I do define it just in the line above. > > Does the generator expression have its own little namespace or so ? No, which leads to the common "WTF?" reaction upon seeing stuff like: >>> funcs = ((lambda: x) for x in range(7)) >>> list_of = list(funcs) >>> list_of[0]() 6 Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Wed Jun 17 19:13:03 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 16:13:03 -0700 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: On 6/17/2009 3:54 PM ssc said... > Wow! Didn't expect that kind of instant support. Thank you very much, > I'll give both zip and enumerate a try. > > The code I've shown is actually copied pretty straight from a Django > form class, but I didn't want to mention that as not to dilute the > conversation. Don't think it matters, anyway. This is the relevant > excerpt: > > from django.forms import Form > > class SignupForm(Form): > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Now that I look at it again, it seems odd to me to not have the code > e.g. in __init__(...), but just 'class-global'. And as class is an executable statement, I imagine titles exists in a namespace that hasn't yet been completely defined. > Still, that does not seem a reason for titles not to be not defined, > as I do define it just in the line above. Well, again, titles will exists in the SignupForm namespace once it exists, which it doesn't yet when you get to title_choices and want to access it. Define titles above the class and you should be OK. > > Does the generator expression have its own little namespace or so ? Sometimes -- in some python versions generator expressions leak... Emile From rhodri at wildebst.demon.co.uk Wed Jun 17 19:26:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 00:26:17 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro wrote: [snip example code] > You haven't managed to get rid of the backslashes. [snip other example code] > Now you've lost track of the original point of the discussion, which is > about using alternate quotes to avoid backslashes. Ah, selective amnesia, how useful you are. The original point of the discussion was in fact about using alternative quotes to avoid alternate backslashes (or at least excessive ones). The first example showed this nicely, actually, within the confines of a language which doesn't give you much more help. Yes, I know from past conversations that you have a superhuman ability to recognise the code in apparent line noise. That still doesn't make it legible to anyone else. -- Rhodri James *-* Wildebeest Herder to the Masses From steven.samuel.cole at gmail.com Wed Jun 17 19:38:39 2009 From: steven.samuel.cole at gmail.com (Steven Samuel Cole) Date: Thu, 18 Jun 2009 11:38:39 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> Message-ID: Both zip and enumerate do the trick. Thanks for the pointers, that's 2 more built-ins under my belt :-) Still don't really understand why my initial code didn't work, though... Thanks everyone! :-) From ethan at stoneleaf.us Wed Jun 17 19:56:03 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 17 Jun 2009 16:56:03 -0700 Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: <4A398293.9080308@stoneleaf.us> Lawrence D'Oliveiro wrote: > In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > > >>On Wed, 17 Jun 2009 23:04:37 +1200 >>Lawrence D'Oliveiro wrote: >> >> >>>In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >>> >>> >>>>On Wed, 17 Jun 2009 17:53:33 +1200 >>>>Lawrence D'Oliveiro wrote: >>>> >>>> >>>>>>Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>arranging them like /path/f/9/e/95ea4926a4 ? >>>>>> >>>>>>That way, you won't have to deal with many-files-in-path problem ... >>>>> >>>>>Why is that a problem? >>>> >>>>So you can os.listdir them? >>> >>>Why should you have a problem os.listdir'ing lots of files? >> >>I shouldn't, and I don't ;) > > > Then why did you suggest that there was a problem being able to os.listdir > them? > He didn't, the OP did. From norseman at hughes.net Wed Jun 17 20:26:13 2009 From: norseman at hughes.net (norseman) Date: Wed, 17 Jun 2009 17:26:13 -0700 Subject: Create 3D Surface / Contour (with vpython?) In-Reply-To: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> References: <386f361c0906171058q3608dbc5teed699f685c9b929@mail.gmail.com> Message-ID: <4A3989A5.6040807@hughes.net> Philip Gr?ger wrote: > Hi! > How can I create a 3D surface (or something like the picture on the FAQ > page http://www.vpython.org/contents/FAQ.html ) with python [or > vpython]. Didnt find anything in the Documentation under "graph" > Basically like a contourf diagram in 3D > (http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I > think you know what I mean. > > Reason: I want to simulate waves in a square basin. Hope I dont need to > use hundrets of little spheres (in case of vpython) for the surface ;) > > Thanks alot > > - Philip > ========================= First of all, those are not quite contours, at least not as the mapping industry uses the term. They are function generated cross sections, perhaps rotated or translated, closely spaced, that have been rendered. Rendered makes them pictures (rasters) and as such the base values are no longer vectors. If you are looking to create pictures you need to plot the points in 3D space, rotate (in 3D space) to a viewpoint of choice and either render the points if they are close enough or create a series of triangular planes from the interior of the points. Do a Google on Triangulated Irregular Networks (TIN). Also try http://wikipedia.org/ The TIN was originally created to aid in computer generated surfaces for use in Aerial Mapping (Photogrammetry). The OG (original ground) could be generated and then the Engineer or Designer could use that to base his/her earth redistributions to a minimum in things like highways, subdivisions and such. Later when GIS came along it borrowed the equations and selected the raster format as it's base. Unfortunately rasters are equally spaced points of same size along the X or Y axis (can be same along both) thus forming a grid. TIN points are NOT on a grid. They occur where needed to dot outline the surface. Coupled with break lines (polylines, sometimes called line strings) to trace an edge (like edge of mountain road) the TIN can depict very accurately a surface. Mother Nature uses quite a number of math functions in just your front yard. The proper dotting of the area reduces the overall number of points required to 'shape' the surface. Contours, in mapping, are connected lines of equal elevation. Contours do not touch each other. Look up Topographic Maps, Lines of Equal Elevation, Contours, 2D representations of 3D objects, Photogrammetry, Land Surveying - subsection volumes. For a single function you can look at the choices you named. I think Rasterman has (had?) a good rendering program which could be used to render any formula output you may want to generate. Re-run your graphs with small increments and combine outputs and render. Should work. Waves are just cyclic output. (Crest and trough) Direction gets changed in small increments radiating out from point of creation and bounce (off wall) is part of path. Time determines total length. How complicated is that? The combined 360 degree outputs for a given time slice (time from creation) provides 'surface' at that point. Add 'vigor' factors to control frequency and strength (amplitude) of waves. I'm assuming you can do the math. That being the case, it should be a nice programming exercise. Good Luck; Steve From steve at nospam.au Wed Jun 17 20:36:01 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 10:36:01 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> >"Carl Banks" wrote in message >news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >On Jun 15, 7:56 pm, "steve" wrote: >> I was just looking at the python tutorial, and I noticed these lines: >> >> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >> >> "Windows makes a distinction between text and binary files; >> "the end-of-line characters in text files are automatically altered >> "slightly when data is read or written. >> >> I don't see any obvious way to at docs.python.org to get that corrected: >> Is >> there some standard procedure? > >What's wrong with it? > > >Carl Banks 1) Windows does not make a distinction between text and binary files. 2) end-of-line characters in text files are not automatically altered by Windows. (david) From steve at nospam.au Wed Jun 17 21:18:36 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 11:18:36 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> Message-ID: <4a3995ed$0$32369$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.16.04.29.14 at REMOVE.THIS.cybersource.com.au... > On Mon, 15 Jun 2009 20:58:47 -0700, Carl Banks wrote: > >> On Jun 15, 7:56 pm, "steve" wrote: >>> I was just looking at the python tutorial, and I noticed these lines: >>> >>> http://docs.python.org/tutorial/inputoutput.html#reading-and- > writing-... >>> >>> "Windows makes a distinction between text and binary files; "the >>> end-of-line characters in text files are automatically altered >>> "slightly when data is read or written. >>> >>> I don't see any obvious way to at docs.python.org to get that >>> corrected: Is there some standard procedure? >> >> What's wrong with it? > > Perhaps because it's unclear whether it is Windows, or Python, or both, > which is automatically altering the data. > > As for getting the docs changed, you can submit a bug request at the bug > tracker: > > http://bugs.python.org/ > > > > > -- > Steven Thanks, we've submitted a bug request, http://bugs.python.org/issue6301 Steve From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:34:25 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:34:25 GMT Subject: Exotic Logics References: Message-ID: On Wed, 17 Jun 2009 16:37:04 +0000, Lie Ryan wrote: >> Imagine for a moment that there are no boolean values. There are no >> numbers. They were never invented. There are no classes. >> There are no objects. >> There are only functions. >> >> Could you define functions that act like boolean values? And could you >> define other functions to operate on them? ... > String isn't considered object? Given that the strings only exist inside one function specifically for printing, I think we can ignore that. If you prefer, print_bool() could look at the function names, that would work just as well. One way or the other, we have to get human-readable names into the system *somehow*. > Also, b/true()/false() is a function object, isn't it? Unless function > is first-class, you can't pass them around like that, since you need a > function pointer (a.k.a number); but if function is first-class then > there it is an object. That's an implementation detail. So long as you can pass around functions, and return them, then it doesn't matter whether they are implemented as objects or not. -- Steven From robert.kern at gmail.com Wed Jun 17 21:37:52 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Jun 2009 20:37:52 -0500 Subject: python tutorial In-Reply-To: <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On 2009-06-17 19:36, steve wrote: >> "Carl Banks" wrote in message >> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >> On Jun 15, 7:56 pm, "steve" wrote: >>> I was just looking at the python tutorial, and I noticed these lines: >>> >>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>> >>> "Windows makes a distinction between text and binary files; >>> "the end-of-line characters in text files are automatically altered >>> "slightly when data is read or written. >>> >>> I don't see any obvious way to at docs.python.org to get that corrected: >>> Is >>> there some standard procedure? >> What's wrong with it? >> >> >> Carl Banks > > 1) Windows does not make a distinction between text and binary files. > > 2) end-of-line characters in text files are not automatically altered by > Windows. The Windows implementation of the C standard makes the distinction. E.g. using stdio to write out "foo\nbar\n" in a file opened in text mode will result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode will result in "foo\nbar\n" in memory. Reading such a file in binary mode will result in "foo\r\nbar\r\n". In your bug report, you point out several proprietary APIs that do not make such a distinction, but that does not remove the implementations of the standard APIs that do make such a distinction. http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx Perhaps it's a bit dodgy to blame "Windows" per se rather than its C runtime, but I think it's a reasonable statement on the whole. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:42:51 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:42:51 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: > 1) Windows does not make a distinction between text and binary files. Of course it does. Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> f = open("test", "wb") >>> f.write("abc\x1Adef") >>> f.close() >>> f = open("test", "r") # read as text >>> f.read() 'abc' >>> f.close() >>> f = open("test", "rb") # read as binary >>> f.read() 'abc\x1adef' >>> f.close() >>> -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:43:37 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:43:37 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> Even CPython doesn't rely completely on reference counting (it has a >> fallback gc for cyclic garbage). Python introduced the "with" >> statement to get away from the kludgy CPython programmer practice of >> opening files and relying on the file being closed when the last >> reference went out of scope. > > I'm curious as you why you consider this practice to be kludgy; my > experience with RAII is pretty good. Because it encourages harmful laziness. Laziness is only a virtue when it leads to good code for little effort, but in this case, it leads to non- portable code. Worse, if your data structures include cycles, it also leads to resource leaks. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 21:44:03 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 01:44:03 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 23:29:48 +1200, Lawrence D'Oliveiro wrote: > In message <7x7hzbv14a.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> > Reference counting is an implementation detail used by CPython but >>> > not [implementations built on runtimes designed for >>> > corporate-herd-oriented languages, like] IronPython or Jython. >>> >>> I rest my case. >> >> You're really being pretty ignorant. I don't know of any serious Lisp >> system that uses reference counting, both for performance reasons and >> to make sure cyclic structures are reclaimed properly. > > Both of which, oddly enough, more modern dynamic languages like Python > manage perfectly well. *Python* doesn't have a ref counter. That's an implementation detail of *CPython*. There is nothing in the specifications for the language Python which requires a ref counter. CPython's ref counter is incapable of dealing with cyclic structures, and so it has a second garbage collector specifically for that purpose. The only reason Python manages perfectly well is by NOT relying on a ref counter: some implementations don't have one at all, and the one which does, uses a second gc. Additionally, while I'm a fan of the simplicity of CPython's ref counter, one serious side effect of it is that it requires the GIL, which essentially means CPython is crippled on multi-core CPUs compared to non- ref counting implementations. -- Steven From mk.fraggod at gmail.com Wed Jun 17 22:14:23 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Thu, 18 Jun 2009 08:14:23 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: <20090618081423.2e0356b9@coercion> On Thu, 18 Jun 2009 10:33:49 +1200 Lawrence D'Oliveiro wrote: > In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 23:04:37 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: > >> > >>> On Wed, 17 Jun 2009 17:53:33 +1200 > >>> Lawrence D'Oliveiro wrote: > >>> > >>>>> Why not use hex representation of md5/sha1-hashed id as a path, > >>>>> arranging them like /path/f/9/e/95ea4926a4 ? > >>>>> > >>>>> That way, you won't have to deal with many-files-in-path problem ... > >>>> > >>>> Why is that a problem? > >>> > >>> So you can os.listdir them? > >> > >> Why should you have a problem os.listdir'ing lots of files? > > > > I shouldn't, and I don't ;) > > Then why did you suggest that there was a problem being able to os.listdir > them? I didn't, OP did, and that's what the topic "walking directory with many files" is about. I wonder whether you're unable to read past the first line, trying to make some point or just some kind of alternatively-gifted (i.e. brain-handicapped) person to keep interpreting posts w/o context like that. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From jason.heeris at gmail.com Wed Jun 17 22:40:25 2009 From: jason.heeris at gmail.com (Jason) Date: Wed, 17 Jun 2009 19:40:25 -0700 (PDT) Subject: How can I enumerate (list) serial ports? Message-ID: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Hi, I'm developing an application to talk to a device over a serial port. I'm trying my hardest to keep it cross platform, so I was using pySerial for the serial communications. But I can't see a pythonic, cross-platform way to enumerate serial ports on a machine. Ideally I could show the user a list of "COM1","COM2", etc, or ttyS0, ttyS1, etc. At the moment I think they'll just have to type it into a box. Is there a known way to do this? Is there anyone who has a hack they're willing to share? Thanks, Jason From wistoch at gmail.com Wed Jun 17 22:45:36 2009 From: wistoch at gmail.com (Wei, James) Date: Wed, 17 Jun 2009 19:45:36 -0700 (PDT) Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux Message-ID: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> When I am editing python program with SPE, I found that SPE will freeze when it is doing auto-completion. The behavior is very strange that I can not edit the file again. If I switch to another file and then switch back, I can edit it again. So I switch to eclipse+pydev, but I found the same thing happen. So I think it is not the problem of SPE or eclipse or pydev. If I disable auto-completion function in SPE or Eclipse+PyDev, it will not freeze any longer. Anybody can give me some hints? I am using Ubuntu 8.10 and updated to latest. All packages is installed through package manager. From wistoch at gmail.com Wed Jun 17 22:47:37 2009 From: wistoch at gmail.com (Wei, James) Date: Wed, 17 Jun 2009 19:47:37 -0700 (PDT) Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> Message-ID: <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> On Jun 18, 10:45?am, "Wei, James" wrote: > When I am editing python program with SPE, I found that SPE will > freeze when it is doing auto-completion. The behavior is very strange > that I can not edit the file again. If I switch to another file and > then switch back, I can edit it again. > > So I switch to eclipse+pydev, but I found the same thing happen. So I > think it is not the problem of SPE or eclipse or pydev. > > If I disable auto-completion function in SPE or Eclipse+PyDev, it will > not freeze any longer. > > Anybody can give me some hints? > > I am using Ubuntu 8.10 and updated to latest. All packages is > installed through package manager. the only thing I googled related with it is http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html but I think they are different. From trinioler at gmail.com Wed Jun 17 22:57:12 2009 From: trinioler at gmail.com (Tyler Laing) Date: Wed, 17 Jun 2009 19:57:12 -0700 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> Message-ID: <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> Do you experience the same problem even on an empty program file or is it limited to just one file? -Tyler On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > On Jun 18, 10:45 am, "Wei, James" wrote: > > When I am editing python program with SPE, I found that SPE will > > freeze when it is doing auto-completion. The behavior is very strange > > that I can not edit the file again. If I switch to another file and > > then switch back, I can edit it again. > > > > So I switch to eclipse+pydev, but I found the same thing happen. So I > > think it is not the problem of SPE or eclipse or pydev. > > > > If I disable auto-completion function in SPE or Eclipse+PyDev, it will > > not freeze any longer. > > > > Anybody can give me some hints? > > > > I am using Ubuntu 8.10 and updated to latest. All packages is > > installed through package manager. > > the only thing I googled related with it is > > > http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html > > but I think they are different. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From charles at declareSub.com Wed Jun 17 22:58:27 2009 From: charles at declareSub.com (Charles Yeomans) Date: Wed, 17 Jun 2009 22:58:27 -0400 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) In-Reply-To: References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: <596CA436-AF47-4164-AEBB-3B011B09C2E4@declareSub.com> On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: > On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: > >>> Even CPython doesn't rely completely on reference counting (it has a >>> fallback gc for cyclic garbage). Python introduced the "with" >>> statement to get away from the kludgy CPython programmer practice of >>> opening files and relying on the file being closed when the last >>> reference went out of scope. >> >> I'm curious as you why you consider this practice to be kludgy; my >> experience with RAII is pretty good. > > Because it encourages harmful laziness. Laziness is only a virtue > when it > leads to good code for little effort, but in this case, it leads to > non- > portable code. Worse, if your data structures include cycles, it also > leads to resource leaks. > Memory management may be an "implementation detail", but it is unfortunately one that illustrates the so-called law of leaky abstractions. So I think that one has to write code that follows the memory management scheme of whatever language one uses. For code written for CPython only, as mine is, RAII is an appropriate idiom and not kludgy at all. Under your assumptions, its use would be wrong, of course. Charles Yeomans From perfreem at gmail.com Wed Jun 17 23:28:43 2009 From: perfreem at gmail.com (per) Date: Wed, 17 Jun 2009 20:28:43 -0700 (PDT) Subject: fastest native python database? Message-ID: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> hi all, i'm looking for a native python package to run a very simple data base. i was originally using cpickle with dictionaries for my problem, but i was making dictionaries out of very large text files (around 1000MB in size) and pickling was simply too slow. i am not looking for fancy SQL operations, just very simple data base operations (doesn't have to be SQL style) and my preference is for a module that just needs python and doesn't require me to run a separate data base like Sybase or MySQL. does anyone have any recommendations? the only candidates i've seen are snaklesql and buzhug... any thoughts/benchmarks on these? any info on this would be greatly appreciated. thank you From wistoch at gmail.com Wed Jun 17 23:32:19 2009 From: wistoch at gmail.com (Wei, Xiaohai) Date: Thu, 18 Jun 2009 11:32:19 +0800 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> Message-ID: <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> yes, the same problem even on an empty program. every file has the same problem. for example, if I new a file and input the following: import os os. after I input '.', it will pop up the window, and i can select the function of os module or continue input. but after that, no action can be taken for this file unless I switch to other files and then switch back. On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing wrote: > Do you experience the same problem even on an empty program file or is it > limited to just one file? > > -Tyler > > On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > >> On Jun 18, 10:45 am, "Wei, James" wrote: >> > When I am editing python program with SPE, I found that SPE will >> > freeze when it is doing auto-completion. The behavior is very strange >> > that I can not edit the file again. If I switch to another file and >> > then switch back, I can edit it again. >> > >> > So I switch to eclipse+pydev, but I found the same thing happen. So I >> > think it is not the problem of SPE or eclipse or pydev. >> > >> > If I disable auto-completion function in SPE or Eclipse+PyDev, it will >> > not freeze any longer. >> > >> > Anybody can give me some hints? >> > >> > I am using Ubuntu 8.10 and updated to latest. All packages is >> > installed through package manager. >> >> the only thing I googled related with it is >> >> >> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >> >> but I think they are different. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Best wishes to you. Yours sincerely Xiaohai Wei wistoch at ustc.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Wed Jun 17 23:38:05 2009 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Jun 2009 20:38:05 -0700 Subject: fastest native python database? In-Reply-To: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: On 6/17/2009 8:28 PM per said... > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. You might like gadfly... http://gadfly.sourceforge.net/gadfly.html Emile > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you From jussij at zeusedit.com Wed Jun 17 23:41:27 2009 From: jussij at zeusedit.com (JussiJ) Date: Wed, 17 Jun 2009 20:41:27 -0700 (PDT) Subject: What text editor is everyone using for Python References: <85hbz9f56i.fsf@agentultra.com> <35e44e77-fdd1-470a-b5ad-f5ffd187f1af@g22g2000pra.googlegroups.com> <9a346808-6e06-44de-b6b3-f3720286ff13@l12g2000yqo.googlegroups.com> <4a211274-f190-47e3-8166-5b3536d678e7@i28g2000prd.googlegroups.com> <802b4bfa-40b8-4459-b0c5-d5df5b61c181@n21g2000vba.googlegroups.com> Message-ID: On May 31, 12:42 am, edexter wrote: On the Windows platform the Zeus editor has Python language support: http://www.zeusedit.com > I will sometimes use word pad but i perfer syntax > highlighting.. The syntax highlighter is fully configurable. > I would be after is to be able to define my syntax file, the > ability to use code snippits, It has a code template feature. > the ability to add tools and compilers... and it also has these features. If also does Python code folding and is scriptable in Python. Jussi Jumppanen Author: Zeus for Windows From steven at REMOVE.THIS.cybersource.com.au Wed Jun 17 23:41:55 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 03:41:55 GMT Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 22:58:27 -0400, Charles Yeomans wrote: > On Jun 17, 2009, at 9:43 PM, Steven D'Aprano wrote: > >> On Wed, 17 Jun 2009 07:49:52 -0400, Charles Yeomans wrote: >> >>>> Even CPython doesn't rely completely on reference counting (it has a >>>> fallback gc for cyclic garbage). Python introduced the "with" >>>> statement to get away from the kludgy CPython programmer practice of >>>> opening files and relying on the file being closed when the last >>>> reference went out of scope. >>> >>> I'm curious as you why you consider this practice to be kludgy; my >>> experience with RAII is pretty good. >> >> Because it encourages harmful laziness. Laziness is only a virtue when >> it >> leads to good code for little effort, but in this case, it leads to >> non- >> portable code. Worse, if your data structures include cycles, it also >> leads to resource leaks. >> >> > > Memory management may be an "implementation detail", but it is > unfortunately one that illustrates the so-called law of leaky > abstractions. So I think that one has to write code that follows the > memory management scheme of whatever language one uses. For code > written for CPython only, as mine is, RAII is an appropriate idiom and > not kludgy at all. Under your assumptions, its use would be wrong, of > course. CPython isn't a language, it's an implementation. I'm unable to find anything in the Python Reference which explicitly states that files will be closed when garbage collected, except for one brief mention in tempfile.TemporaryFile: "Return a file-like object that can be used as a temporary storage area. The file is created using mkstemp(). It will be destroyed as soon as it is closed (including an implicit close when the object is garbage collected)." http://docs.python.org/library/tempfile.html In practical terms, it's reasonably safe to assume Python will close files when garbage collected (it would be crazy not to!) but that's not explicitly guaranteed anywhere I can see. In any case, there is no guarantee *when* files will be closed -- for long-lasting processes that open and close a lot of files, or for data structures with cycles, you might easily run out of file descriptors. The docs for file give two recipes for recommended ways of dealing with files: http://docs.python.org/library/stdtypes.html#file.close Both of them close the file, one explicitly, the other implicitly. In both cases, they promise to close the file as soon as you are done with it. Python the language does not. The tutorials explicitly recommends closing the file when you're done: "When you?re done with a file, call f.close() to close it and free up any system resources taken up by the open file." http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files In summary: relying on immediate closure of files is implementation specific behaviour. By all means do so, with your eyes open and with full understanding that you're relying on platform-specific behaviour with no guarantee of when, or even if, files will be closed. -- Steven From perfreem at gmail.com Wed Jun 17 23:47:57 2009 From: perfreem at gmail.com (per) Date: Wed, 17 Jun 2009 20:47:57 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <5a77a35e-7c7a-46a3-a1de-5ec5a6d4e6ca@t10g2000vbg.googlegroups.com> i would like to add to my previous post that if an option like SQLite with a python interface (pysqlite) would be orders of magnitude faster than naive python options, i'd prefer that. but if that's not the case, a pure python solution without dependencies on other things would be the best option. thanks for the suggestion, will look into gadfly in the meantime. On Jun 17, 11:38?pm, Emile van Sebille wrote: > On 6/17/2009 8:28 PM per said... > > > hi all, > > > i'm looking for a native python package to run a very simple data > > base. i was originally using cpickle with dictionaries for my problem, > > but i was making dictionaries out of very large text files (around > > 1000MB in size) and pickling was simply too slow. > > > i am not looking for fancy SQL operations, just very simple data base > > operations (doesn't have to be SQL style) and my preference is for a > > module that just needs python and doesn't require me to run a separate > > data base like Sybase or MySQL. > > You might like gadfly... > > http://gadfly.sourceforge.net/gadfly.html > > Emile > > > > > does anyone have any recommendations? the only candidates i've seen > > are snaklesql and buzhug... any thoughts/benchmarks on these? > > > any info on this would be greatly appreciated. thank you > > From jussij at zeusedit.com Wed Jun 17 23:52:36 2009 From: jussij at zeusedit.com (JussiJ) Date: Wed, 17 Jun 2009 20:52:36 -0700 (PDT) Subject: What text editor is everyone using for Python References: Message-ID: <354ebc10-a3a1-49ef-bacb-9e1d69ed7ef6@y34g2000prb.googlegroups.com> On May 26, 3:35 am, LittleGrasshopper wrote: > With so many choices, I was wondering what editor is the one you > prefer when coding Python, The Zeus for Windows IDE is Python aware: http://www.zeusedit.com/python.html > and why. It does syntax highlighting, smart indenting, code folding etc etc You can write Zeus scripts in Python. Zeus also creates Python tag informatuion (via ctags.exe) and this information is used to populate the class/code browser. It is also possible to hook in the Python documentation so the help can be searched and accessed from within the editor: http://www.zeusedit.com/forum/viewtopic.php?t=8 Jussi Jumppanen Author: Zeus for Windows IDE NOTE: Zeus is shareware From mr.william.clifford at gmail.com Thu Jun 18 00:03:45 2009 From: mr.william.clifford at gmail.com (William Clifford) Date: Wed, 17 Jun 2009 21:03:45 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <3bf78076-688d-4ec8-9ea6-9fe070d94f4f@c20g2000prh.googlegroups.com> On Jun 17, 8:28?pm, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you I don't know how they stack up but what about: Python CDB http://pilcrow.madison.wi.us/#pycdb or Dee (for ideological reasons) http://www.quicksort.co.uk/ -- William Clifford From kushal.kumaran+python at gmail.com Thu Jun 18 00:19:49 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 18 Jun 2009 09:49:49 +0530 Subject: Reading and setting file permissions programmatically In-Reply-To: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> References: <5700df6b0906171335o6a8456acic9dfb3f75a025ee7@mail.gmail.com> Message-ID: <1e364c4e0906172119g4ebb3631tb02f335c18e3e19a@mail.gmail.com> On Thu, Jun 18, 2009 at 2:05 AM, Cameron Pulsford wrote: > Sorry to flood the list but my google fu isn't up to par today I guess. > Basically, is it possible to read the permissions on one file and then set > the permissions of another file to the ones we just read? os.dup2 seemed > like it would work but I might not be using it correctly. > I know there is os.chmod, but I haven't found the equivalent to read > permissions. Preferably this would work on unix and windows too. shutil.copymode -- kushal From afriere at yahoo.co.uk Thu Jun 18 01:17:04 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 22:17:04 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> On Jun 18, 5:03?am, Terry Reedy wrote: > That depends on what you mean by 'put into classes' (and 'everything'). > > If you mean 'be an instance of a class', which I think is the most > natural reading, then Python *is* object-oriented and, if I understand > what I have read correctly (so that ints are just (unboxed) ints and not > members of an int class), Java *is not*! +1 This needs to be said to those who imagine, because you have to code the class explicitly in Java whereas Python objects can be manipulated in ignorance of the idea of class, that Java is somehow OO in the way Python is not. OTOH the whole notion of defining OO by the use of classes automatically excludes from consideration prototype-based OO languages (eg. Self) which arguably offer a purer approach to OO than class centric languages. From delroth at gmail.com Thu Jun 18 01:41:13 2009 From: delroth at gmail.com (Pierre Bourdon) Date: Thu, 18 Jun 2009 07:41:13 +0200 Subject: fastest native python database? In-Reply-To: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <1ba9eaed0906172241s2b22a191l1bfd9177d7f180d5@mail.gmail.com> On Thu, Jun 18, 2009 at 05:28, per wrote: > hi all, Hi, > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. If you just need something which does not depend on any external libraries (that's what I understand in "just needs python"), you should also consider sqlite3 as it is a built-in module in Python 2.5 and newer. You do not need modules like pysqlite to use it. -- Pierre "delroth" Bourdon ?tudiant ? l'EPITA / Student at EPITA From afriere at yahoo.co.uk Thu Jun 18 01:42:40 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 22:42:40 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: On Jun 15, 6:35?am, Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... (asun at lucrezia:~/pit/lsa/act:5)$ ls -1 | wc -l 142607 There, you've seen one with 142 thousand now! :P From steve at nospam.au Thu Jun 18 01:57:16 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 15:57:16 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Robert Kern" wrote in message news:mailman.1728.1245289092.8015.python-list at python.org... > On 2009-06-17 19:36, steve wrote: >>> "Carl Banks" wrote in message >>> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>> On Jun 15, 7:56 pm, "steve" wrote: >>>> I was just looking at the python tutorial, and I noticed these lines: >>>> >>>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>> >>>> "Windows makes a distinction between text and binary files; >>>> "the end-of-line characters in text files are automatically altered >>>> "slightly when data is read or written. >>>> >>>> I don't see any obvious way to at docs.python.org to get that >>>> corrected: >>>> Is >>>> there some standard procedure? >>> What's wrong with it? >>> >>> >>> Carl Banks >> >> 1) Windows does not make a distinction between text and binary files. >> >> 2) end-of-line characters in text files are not automatically altered by >> Windows. > > The Windows implementation of the C standard makes the distinction. E.g. > using stdio to write out "foo\nbar\n" in a file opened in text mode will > result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode > will result in "foo\nbar\n" in memory. Reading such a file in binary mode > will result in "foo\r\nbar\r\n". In your bug report, you point out several > proprietary APIs that do not make such a distinction, but that does not > remove the implementations of the standard APIs that do make such a > distinction. > > http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx > > Perhaps it's a bit dodgy to blame "Windows" per se rather than its C > runtime, but I think it's a reasonable statement on the whole. > > -- > 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 > Which is where I came in: I was looking for simple file IO in the tutorial. The tutorial tells me something false about Windows, rather than something true about Python. I'm looking at a statement that is clearly false (for anyone who knows anything about Windows file systems and Windows file io), which leaves the Python behaviour completely undefined (for anyone who knows nothing about Python). I understand that many of you don't really have any understanding of Windows, much less any background with Windows, and I'm here to help. That part was simple. The next part is where I can't help: What is the behaviour of Python? I'm sure you don't think that tutorial is only for readers who can guess that they have to extrapolate from the behaviour of the Visual C library in order to work out what Python does. Steve From steve at nospam.au Thu Jun 18 01:58:37 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 15:58:37 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... > On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: > >> 1) Windows does not make a distinction between text and binary files. > > Of course it does. > > > Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> f = open("test", "wb") >>>> f.write("abc\x1Adef") >>>> f.close() >>>> f = open("test", "r") # read as text >>>> f.read() > 'abc' >>>> f.close() >>>> f = open("test", "rb") # read as binary >>>> f.read() > 'abc\x1adef' >>>> f.close() >>>> > > > -- > Steven Ok, Python makes a distinction between text and binary files. Steve. From bob.martin at excite.com Thu Jun 18 02:07:26 2009 From: bob.martin at excite.com (Bob Martin) Date: Thu, 18 Jun 2009 06:07:26 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: in 117815 20090617 221804 Phil Runciman wrote: >Because it reminds me of when things went badly wrong. IBM360, Von Neumann = >architecture, no hardware stacks ... > >IMHO Burroughs and ICL had better approaches to OS design back then but had= >less resources to develop their ideas.=20 > >However, mainly this period marked a transition from the excitement and dis= >covery phase of computing to commercial power plays and take-overs. The bes= >t ideas in a field tend to get lost in the melee of competition. Early comp= >uters were rooted in academia and there was a lot of cross fertilisation of= >ideas and approaches. IMHO commerce affected layers of the stack where it = >had no useful contribution to make. Vertical integration warred against sou= >nd architecture. > >The book has an important message and I recommend that people read it. The = >book is to me, and possibly only me, an icon representing when things went = >wrong. Well, it's an opinion, but certainly not one I would agree with! AFAIAC the IBM 360 got everything right, which is why the instruction set is still going strong 45 years later (I've used it for every one of those 45 years). From mail at timgolden.me.uk Thu Jun 18 02:20:42 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Jun 2009 07:20:42 +0100 Subject: How can I enumerate (list) serial ports? In-Reply-To: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> References: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Message-ID: <4A39DCBA.3070303@timgolden.me.uk> Jason wrote: > Hi, > > I'm developing an application to talk to a device over a serial port. > I'm trying my hardest to keep it cross platform, so I was using > pySerial for the serial communications. But I can't see a pythonic, > cross-platform way to enumerate serial ports on a machine. As with many other such issues, instant cross-platformability is likely to be rare. I admin I haven't looked at pySerial but I imagine that, behind the scenes, it's doing some sort of conditional imports according to platform. I imagine you'd have to do something similar to get a list of port names. On Windows, WMI can give you what you want. Look at the Win32_SerialPort class. Hopefully, someone else can help for other platforms. TJG From afriere at yahoo.co.uk Thu Jun 18 02:21:06 2009 From: afriere at yahoo.co.uk (Asun Friere) Date: Wed, 17 Jun 2009 23:21:06 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: On Jun 15, 1:00?am, rustom wrote: > > For every one Horowitz there are a thousand wannbes thumping on the > piano trying to become Horowitz. > The traction that practice gives is maximal only in the beginning. Funny but I was watching an interview/conversation between and older composer and a young up and coming WFCP (World Famous Concert Pianist) the other day. The composer had been teaching the pianist to understand the works he was playing ... anyway, the old guy remarked that when he was younger he wanted to be a WFCP too, but that he lacked a crucial ability that the young star had. What was it? "I lack the ability to make myself practise as well and for as long as you do." From gervich at sbcglobal.net Thu Jun 18 02:23:56 2009 From: gervich at sbcglobal.net (Jason Gervich) Date: Wed, 17 Jun 2009 23:23:56 -0700 Subject: IDLE comments Message-ID: <1245306236.3326.3.camel@jason-desktop> Why does IDLE use two hash marks for comments (##)? Most other editors (Geany, SPE) use a single hash mark (#) to designate comments. How does one change IDLE to use just a single (#) hash mark for comments? Thanks, Jason Gervich Santa Cruz, CA -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Thu Jun 18 02:44:36 2009 From: castironpi at gmail.com (Aaron Brady) Date: Wed, 17 Jun 2009 23:44:36 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> Message-ID: <687da532-5d62-47a3-a229-5ff4b66ca2bf@p4g2000vba.googlegroups.com> On Jun 17, 7:38?am, Jean-Michel Pichavant wrote: > abhishek goswami wrote: > > Hi, > > I have very basic question about Python that do we consider pyhton as > > script language. > > I searched in google but it becomes more confusion for me. After some > > analysis I came to know that Python support oops . > > > Can anyone Guide me that Python is Oject oriented programming language > > or Script language > > > Abhishek Goswami > > Chennai > > Phone No -0996227099 > > > ------------------------------------------------------------------------ > > ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET > > > > Depends on what you are calling a scripting language. > Refering to wikipedia, > "A *scripting language*, *script language* or *extension language* is a > programming language > that allows some control of a single or many software application(s) > ." > > Python is definitely OOP oriented and I don't think it fits in the > script definition above. > Python is interpreted and platform independent, but you can still build > standalone platform dependent binaries if required. > > Regarding your last question, I'm not sure scripting and OOP language > are not compatible, I'm pretty sure you'll be able to find OOP scripting > language. > > Jean-Michel I'm not the only one that thinks that Java is a joke, though I provoke flaming, and do not know it fluently. It's all big words and handcuffs. To quote my favorite t.v. show, 'You imply disparity where none exists.' You're trying to 'pigeon-hole', where the subjects are fairly complex, even though not ultimately continuous, but still not binary. You might as well be asking whether it's rainy or sunny out. Even day and night only account for 22-23 hours out of our day. Speaking of big words, programming languages vary in a number of dimensions. Regardless of what surface you use to divide the space, you'll have data points which aren't quite intuitively aligned with the rest of their category; not to shirk the burden of proof. The high complexity of Python blurs the partition. You might give it a center, and some membership density function that decreases with the distance from it, like the volume of a loudspeaker. I'm not sure whether you would define these from use data, or something more a priori. The former doesn't require as much contortion. Some have proposed the same tactic for culture division and nation borders, incidentally, as one 'compromization' tactic; that is, to 'fuzzily' classify regions, and languages likewise. It would make Python, say 10% appropriate for scripting, and 90% object-oriented, just as 10% of 'our' police comes from, and 10% of our taxes goes to Sweden. However, you've never heard of a 70% Catholic, and further, the logistics on that formulation don't align quite rightly: it would be more like, 'we' pay takes to Sweden at 10% of the tax rate at its capital and anywhere else that only Sweden influences. Some places of commerce even accept the kroner too. That still might not make you be 70% Catholic, but definitely ten people definitely definitely can. Come to think of it, the percentages don't have to add up to 1, it's more like Python is 50% appropriate for scripting, and object-oriented in the high nineties. I guess I was just trying to be politically correct, impartial, or otherwise unbiased, though consequently rigid in the meantime. Sadly so. Linguists define distinctions between natural languages by measure of mutual interpretability. The two most similar languages out there may be practically the same; the two most different may not have even any syntax in common; and the one most different from the one closest to it may well be Python. Fancy that! In this participant's humble opinion, no. There are better scripting languages out there. In his arrogant opinion, no. It 'sets the curve'. From citronelu at yahoo.com Thu Jun 18 02:54:07 2009 From: citronelu at yahoo.com (CiTro) Date: Wed, 17 Jun 2009 23:54:07 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix Message-ID: I'm looking for a way to convert a string to it's unicode "brother". This means: stringOne = "\u0026" stringTwo = u"\u0026" print unicode(stringOne) == stringTwo The result is false. What function should I use, to duplicate the effect of the "u" prefix ? From steven at REMOVE.THIS.cybersource.com.au Thu Jun 18 03:05:20 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Jun 2009 07:05:20 GMT Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote: > "Steven D'Aprano" wrote in > message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... >> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: >> >>> 1) Windows does not make a distinction between text and binary files. >> >> Of course it does. ... > Ok, Python makes a distinction between text and binary files. Microsoft have reported a bug where cmd.exe fails to recognise EOF in a text file: http://support.microsoft.com/kb/156258 The behaviour of reading past the \0x1A character is considered a bug, which says that cmd.exe at least (and by extension Windows apps in general) are expected to stop reading at \0x1A for text files. Technically, the Windows file systems record the length of text files and so an explicit EOF character is redundant, nevertheless, the behaviour of stopping the read at \0x1A is expected. Whether you want to claim it is "Windows" or "the Windows shell" or something else is a fine distinction that makes little difference in practice. Anyway, here's Raymond Chen of Microsoft explaining more: http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx -- Steven From __peter__ at web.de Thu Jun 18 03:08:33 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Jun 2009 09:08:33 +0200 Subject: String to unicode - duplicating by function the effect of u prefix References: Message-ID: CiTro wrote: > I'm looking for a way to convert a string to it's unicode "brother". > > This means: > > stringOne = "\u0026" > stringTwo = u"\u0026" > > print unicode(stringOne) == stringTwo > > The result is false. What function should I use, to duplicate the > effect of the "u" prefix ? "\u..." has a special meaning only in unicode, not string literals: >>> s = "\u0026" >>> len(s) 6 >>> s.decode("unicode-escape") u'&' >>> _ == u"\u0026" True Peter From quentel.pierre at wanadoo.fr Thu Jun 18 03:09:41 2009 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Thu, 18 Jun 2009 00:09:41 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> On 18 juin, 05:28, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you Hi, buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : from buzhug import Base db = Base('foo').create(('name',str),('age',int)) db.insert('john',33) # simple queries print db(name='john') # complex queries print [ rec.name for rec in db if age > 30 ] # update rec.update(age=34) I made a few speed comparisons with Gadfly, KirbyBase (another pure- Python DB, not maintained anymore) and SQLite. You can find the results on the buzhug home page : http://buzhug.sourceforge.net The conclusion is that buzhug is much faster than the other pure- Python db engines, and (only) 3 times slower than SQLite - Pierre From citronelu at yahoo.com Thu Jun 18 03:23:31 2009 From: citronelu at yahoo.com (CiTro) Date: Thu, 18 Jun 2009 00:23:31 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix References: Message-ID: <060b9f4a-8ca5-4459-b302-66311f5c39e1@u10g2000vbd.googlegroups.com> Thank you, Peter. That solved my problem. From ldo at geek-central.gen.new_zealand Thu Jun 18 03:29:53 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 19:29:53 +1200 Subject: TypeError: int argument required References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: In message , Rhodri James wrote: > On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro > wrote: > > [snip example code] > >> You haven't managed to get rid of the backslashes. > > [snip other example code] > >> Now you've lost track of the original point of the discussion, which is >> about using alternate quotes to avoid backslashes. > > Ah, selective amnesia, how useful you are. The original point of the > discussion was in fact about using alternative quotes to avoid alternate > backslashes (or at least excessive ones). No mention of avoiding "alternate backslashes (or at least excessive ones)". Here's what I said, in message : > In message , Rhodri > James wrote: > >> On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro >> wrote: >> >>> In message , Rhodri >>> James wrote: >>> >>>> 2. That output string has severe "leaning toothpick" syndrome. Python >>>> accepts both single and double quotes to help avoid creating something >>>> so unreadable: use them. >>> >>> Backslashes are more scalable. >> >> That doesn't excuse sprinkling several million backslashes through >> literal constants when there's a more readable alternative. > > Perl allows just about any printable character as a quote. I tried > alternative quotes for many years, and decided making that choice was a > waste of brain cells. > > So no, using alternative quotes does not make things more readable. Now compare that with Lie Ryan's examples which, instead of using backslashes, instead used alternative quotes plus backslashes in one example, and in the other example, alternative quotes, alternatives to literal quotes, and backslashes. As opposed to my original routine, which managed three levels of quoting using just backslashes. Do you begin to understand what I mean by "scalable"? From ldo at geek-central.gen.new_zealand Thu Jun 18 03:34:47 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Jun 2009 19:34:47 +1200 Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: In message <07ac7d7a-48e1-45e5-a21c- f2c259c7528a at j12g2000vbl.googlegroups.com>, per wrote: > i'm looking for a native python package to run a very simple data > base. Use Python mapping objects. Most real-world databases will fit in memory anyway. From arnodel at googlemail.com Thu Jun 18 03:39:40 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Jun 2009 08:39:40 +0100 Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: Christian Heimes writes: > Terry Reedy wrote: >> If you mean 'be an instance of a class', which I think is the most >> natural reading, then Python *is* object-oriented and, if I understand >> what I have read correctly (so that ints are just (unboxed) ints and not >> members of an int class), Java *is not*! > > A friend of mine calls Java and C++ class centric programming languanges. ;) It's unfair on C++ given that one can write perfectly good C++ programs without classes, just as in Python. -- Arnaud From phostu at gmail.com Thu Jun 18 03:49:17 2009 From: phostu at gmail.com (Vincent) Date: Thu, 18 Jun 2009 00:49:17 -0700 (PDT) Subject: String to unicode - duplicating by function the effect of u prefix References: <060b9f4a-8ca5-4459-b302-66311f5c39e1@u10g2000vbd.googlegroups.com> Message-ID: <8d2464e6-5059-43db-af0b-c72c6819b89c@p21g2000prn.googlegroups.com> On Jun 18, 3:23?pm, CiTro wrote: > Thank you, Peter. That solved my problem. the another way is, codecs.raw_unicode_escape_decode(stringOne) == stringTwo From steve at nospam.au Thu Jun 18 04:06:38 2009 From: steve at nospam.au (steve) Date: Thu, 18 Jun 2009 18:06:38 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au><4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> "Steven D'Aprano" wrote in message news:pan.2009.06.18.07.05.20 at REMOVE.THIS.cybersource.com.au... > On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote: > >> "Steven D'Aprano" wrote in >> message news:pan.2009.06.18.01.42.51 at REMOVE.THIS.cybersource.com.au... >>> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote: >>> >>>> 1) Windows does not make a distinction between text and binary files. >>> >>> Of course it does. > ... >> Ok, Python makes a distinction between text and binary files. > > Microsoft have reported a bug where cmd.exe fails to recognise EOF in a > text file: > > http://support.microsoft.com/kb/156258 > > The behaviour of reading past the \0x1A character is considered a bug, > which says that cmd.exe at least (and by extension Windows apps in > general) are expected to stop reading at \0x1A for text files. > > > Technically, the Windows file systems record the length of text files and > so an explicit EOF character is redundant, nevertheless, the behaviour of > stopping the read at \0x1A is expected. Whether you want to claim it is > "Windows" or "the Windows shell" or something else is a fine distinction > that makes little difference in practice. > > Anyway, here's Raymond Chen of Microsoft explaining more: > > http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx > > > > -- > Steven If you're pleased to be learning something about Windows, then I'm pleased for you. The reason that I didn't give a full discussion about the history of DOS and Microsoft C was that I didn't think it was relevant to a Python newsgroup. My Bad. I didn't think anyone would care about the behaviour of copy vs xcopy in DOS 6-. I'd like to see the Tutorial corrected so that it gives some useful information about the behaviour of Python. As part of that, I'd like to see it corrected so that it doesn't include patently false information, but only because the patently false information about Windows obscures the message about Python. Believe me, I really don't care what myths you believe about Windows, or why you believe them. I've got a full and interesting life of my own. I'm only interested in getting the Python tutorial corrected so that it gives some sensible information to someone who hasn't already had the advantage of learning what the popular myths represent to the Python community. So far I've been pointed to a discussion of C, a discussion of DOS, and a discussion of Windows NT 4. Great. Glad to see that you know how to use the Internet. I'll give you that if you already have a meaning to assign to those meaningless words, you know more Python than I do. And I'll give you that if you already have a meaning to assign to those meaningless words, you know more Visual C than I do. Is that all there is? You're going to leave the tutorial because you can mount an obscure justification and it makes sense to someone who already knows what it means? Tell me it isn't so :~( From jason.heeris at gmail.com Thu Jun 18 04:10:29 2009 From: jason.heeris at gmail.com (Jason) Date: Thu, 18 Jun 2009 01:10:29 -0700 (PDT) Subject: How can I enumerate (list) serial ports? References: <2304b844-89cf-4a2b-9351-0d2856ae0b50@d38g2000prn.googlegroups.com> Message-ID: <9a91f171-e223-44a1-8b26-f09650a4e823@g15g2000pra.googlegroups.com> On Jun 18, 2:20?pm, Tim Golden wrote: > but I imagine that, behind the scenes, it's doing some sort > of conditional imports according to platform. I have, and yes indeed it does. > I imagine you'd > have to do something similar to get a list of port names. That's what I thought, although I might just defer to the user knowing what to type in (since they would have to identify the port allocated to the device in the first place). > On Windows, WMI can give you what you want. Look at the > Win32_SerialPort class. Hopefully, someone else can help > for other platforms. Thanks for this pointer :) Cheers, Jason From ben+python at benfinney.id.au Thu Jun 18 04:55:04 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Jun 2009 18:55:04 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <87r5xh2a6v.fsf@benfinney.id.au> "steve" writes: > So far I've been pointed to a discussion of C, a discussion of DOS, > and a discussion of Windows NT 4. Great. Glad to see that you know how > to use the Internet. Says the person who doesn't want to attach an identity to his messages. (Yes, that's ad hominem if used to dismiss your argument; but it's *you* that is raising ?know how to use the internet?, so at that point you become fair game, IMO.) > Is that all there is? You're going to leave the tutorial because you > can mount an obscure justification and it makes sense to someone who > already knows what it means? Tell me it isn't so :~( Who is ?you?? Someone who knows how to use the internet surely can tell that comp.lang.python isn't the place to come expecting *changes* in the Python tutorial. You started out asking how to *interpret* it, which is fine for this forum; but discussing it here isn't going to lead automatically to any *midification* to a document developed within the core of Python. -- \ ?Whatever you do will be insignificant, but it is very | `\ important that you do it.? ?Mahatma Gandhi | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Jun 18 05:09:38 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Jun 2009 11:09:38 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> <40bbc78c-863b-4adc-8079-e2825651ddfc@z8g2000prd.googlegroups.com> Message-ID: <4a3a0442$0$9848$426a74cc@news.free.fr> Asun Friere a ?crit : (snip) > OTOH the whole notion of defining OO by the use of classes > automatically excludes from consideration prototype-based OO languages > (eg. Self) which arguably offer a purer approach to OO than class > centric languages. FWIW, there's no notion of "class" in the minimal (and only commonly agreed AFAIK) definitions of OO: 1/ an object id defined by an id, a state and a behaviour 2/ objects communicate by sending messages to each others From conra2004 at yahoo.com Thu Jun 18 05:24:39 2009 From: conra2004 at yahoo.com (yadin) Date: Thu, 18 Jun 2009 02:24:39 -0700 (PDT) Subject: please help...writing set to a file Message-ID: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Good day every one! I got this python program that returns me a set like this.. Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] I was reading this from a file?. How can I transform this to something that looks like this Column1 Column 2 100 A 200 B 300 C 400 D E F G And then write this to a file??? thank you for taking your time!!! From pdpinheiro at gmail.com Thu Jun 18 05:28:55 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 18 Jun 2009 02:28:55 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> Message-ID: <9c21ab4a-21f8-45e6-a3cb-54559eb900f1@t10g2000vbg.googlegroups.com> On Jun 18, 8:09?am, Pierre Quentel wrote: > On 18 juin, 05:28, per wrote: > > > > > > > hi all, > > > i'm looking for a native python package to run a very simple data > > base. i was originally using cpickle with dictionaries for my problem, > > but i was making dictionaries out of very large text files (around > > 1000MB in size) and pickling was simply too slow. > > > i am not looking for fancy SQL operations, just very simple data base > > operations (doesn't have to be SQL style) and my preference is for a > > module that just needs python and doesn't require me to run a separate > > data base like Sybase or MySQL. > > > does anyone have any recommendations? the only candidates i've seen > > are snaklesql and buzhug... any thoughts/benchmarks on these? > > > any info on this would be greatly appreciated. thank you > > Hi, > > buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : > > from buzhug import Base > db = Base('foo').create(('name',str),('age',int)) > db.insert('john',33) > # simple queries > print db(name='john') > # complex queries > print [ rec.name for rec in db if age > 30 ] > # update > rec.update(age=34) > > I made a few speed comparisons with Gadfly, KirbyBase (another pure- > Python DB, not maintained anymore) and SQLite. You can find the > results on the buzhug home page :http://buzhug.sourceforge.net > > The conclusion is that buzhug is much faster than the other pure- > Python db engines, and (only) 3 times slower than SQLite > > - Pierre Which means that, at this point in time, since both gadfly and sqlite use approximately the same API, sqlite takes the lead as a core package (post-2.5 anyway) From benjamin.kaplan at case.edu Thu Jun 18 06:30:18 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Jun 2009 06:30:18 -0400 Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: On Thu, Jun 18, 2009 at 5:24 AM, yadin wrote: > Good day every one! > > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? > thank you for taking your time!!! > I don't think you can. A set doesn't maintain order so you couldn't count on it being returned in a particular order. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From karthik301176 at gmail.com Thu Jun 18 06:30:35 2009 From: karthik301176 at gmail.com (Karthik) Date: Thu, 18 Jun 2009 03:30:35 -0700 (PDT) Subject: Packing a ctypes struct containing bitfields. Message-ID: Hello Everybody, I'm trying to create a packed structure in ctypes (with one 64-bit element that is bitfielded to 48 bits), unsuccessfully: =================================== from ctypes import * class foo (Structure): _pack_ = 1 _fields_ = [ ("bar", c_ulonglong, 48), ] print("sizeof(foo) = %d" % sizeof(foo)) =================================== I'm expecting that this should print 6 - however, on my box, it prints 8. The following piece of C code, when compiled and run, prints 6, which is correct. =================================== struct foo { unsigned long long bar: 48; }; printf("sizeof(foo) = %d", sizeof(foo)); =================================== So... what am I doing wrong? Thanks, Karthik. From davea at ieee.org Thu Jun 18 06:34:05 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Jun 2009 06:34:05 -0400 Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: <4A3A181D.6020608@ieee.org> yadin wrote: > Good day every one! > > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp =?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? > thank you for taking your time!!! > > > Since a set has no order, it cannot be done. There's no association between 100 and A that can be independently determined from just the set and the list. Just how was the original assignment worded, anyway? And what version of Python are you using for it? After you solve that problem (perhaps by returning a list in both cases), then the real question might be one of formatting. Since the columns in your example don't line up in any meaningful way, perhaps you just want to slap a few spaces before and between the elements. You'll need to do a strip() on the pp items, to get rid of the newline. Then something like: line = " " + ppitem.strip() + " " + otheritem Loop through the lists and send the lines to the file. Don't forget to close it at the end. From georges at racinet.fr Thu Jun 18 07:21:56 2009 From: georges at racinet.fr (Racinet Georges) Date: Thu, 18 Jun 2009 13:21:56 +0200 Subject: Default namespace and attributes with ElementTree 1.3 Message-ID: <9405D110-5080-4BDB-BA80-187472C6DEF4@racinet.fr> Hi there, I've got a problem with the way ElementTree 1.3a3-20070912 handles attributes with the default namespace feature (please feel free to redirect me if this isn't the proper place to discuss such matters). >>> from elementtree import ElementTree as ET >>> e = ET.fromstring('') >>> ET.tostring(e) '' Notice that the 'id' attribute does not belong to the "foo" namespace. If I got the XML 1.0 specification right, this is perfectly normal (Quoting http://www.w3.org/TR/REC-xml-names/#defaulting) : "Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. (...) The namespace name for an unprefixed attribute name always has no value." Now, trying to serialize this back with the default_namespace feature of ET 1.3, I get an error, as predicted by the online documentation >>> t = ET.ElementTree(e) >>> t.write(sys.stdout, default_namespace='foo') Traceback (...) ValueError: cannot use non-qualified names with default_namespace option Since this is a parse/serialize round-trip, I think that this behaviour isn't right, and that unprefixed attributes should go through. Actually, shouldn't attributes even be outside of the scope of the default namespace feature ? Is there hope for future improvements about this ? I saw some FIXME comment in the source. The svn head version (rev 528) seems to be identical in that respect, by the way. Removing in ElementTree.py the part where the ValueError is been raised seems to solve the issue at first sight : >>> t.write(sys.stdout, default_namespace='foo') but this lets also unprefixed elements go through, which is unwanted: >>> e = ET.fromstring('') >>> t = ET.ElementTree(e) >>> t.write(sys.stdout, default_namespace='foo') I wouldn't care in my application, whose output is xhtml, though. Regards, -- Georges Racinet, http://www.racinet.fr Zope/CPS/Plone expertise, assistance & development GPG: 0x4862FFF7 -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 489 bytes Desc: This is a digitally signed message part URL: From x.piter at gmail.com Thu Jun 18 07:24:42 2009 From: x.piter at gmail.com (Piter_) Date: Thu, 18 Jun 2009 14:24:42 +0300 Subject: pyserial question Message-ID: <6f4f96030906180424w367d4d11r2f1d37ec264a4bf@mail.gmail.com> Hi all. I try to control some equipment from python trough comport. I have not succeeded in pyserial. But if I use this terminal: http://hw-server.com/files/priloha/termv19b.zip http://hw-server.com/software/termv19b.html It works with following settings. Boud rate: 9600 Data bids: 8 Parity: none stop bids: 1 Handshaking: RST on TX I cant find out how to set "Handshaking RST on TX" in pyserial. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at craig-wood.com Thu Jun 18 07:29:31 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 18 Jun 2009 06:29:31 -0500 Subject: UDP queue size References: <4gRWbd$vn0@alexbbs.twbbs.org> Message-ID: Martin P. Hellwig wrote: > Scott David Daniels wrote: > > ???????? wrote: > >> I got a problem about UDP. > >> > >> How do I get the UDP buffer size? > >> > >> When the server had some delay in handling incoming UDP, it will lost > >> some package. I wonder it's because the system buffer size, is there any > >> ways to find the exactly size of the buffer? > > > > UDP is defined as "best effort then give up," so _everything_ that > > handles a UDP packet is allowed to drop it; that means switchers, > > routers, ..., anything along the path to the target application. > > So, you cannot expect to do any better than a conservative guess, > > perhaps augmented by dynamic scaling. > > I would like to add, that you are most likely to lose packages because > they are to big, I can not remember for sure if UDP had a fixed limit > above what the MTU does, but you might want to look at that > direction too. UDP messages can be up to 64k. However they will be fragmented to the MTU which is 1500 bytes for most ethernet traffic. The means that the chance of losing a bigger UDP message is much higher because you only need to lose one of the fragments to lose the message. Most people who use UDP try to keep the total message size below 1500 bytes (1480 data without the header IIRC) for that reason. wireshark/tcpdump will quickly show you whether you are fragmenting your UDP messages. Another thing to bear in mind with UDP is that you can easily exceed the packets / second that switches / routers can bear if you send lots of small messages. Switches / routers will start dumping packets if you do that since. Some switches just crash in my experience too ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From anthra.norell at bluewin.ch Thu Jun 18 07:39:28 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Thu, 18 Jun 2009 13:39:28 +0200 Subject: CAD file format specifications? In-Reply-To: <4A37D79D.4070604@hughes.net> References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> Message-ID: <4A3A2770.2030802@bluewin.ch> norseman wrote: > Anthra Norell wrote: >> Andres Acosta wrote: >>> HI there Anthara have you checked out www.Blender.org, It is open >>> source and accepts a lot of your formats. for import and export. >>> Anrdres >>> Anthra Norell wrote: >>>> Hi, >>>> Anyone working with CAD who knows about numeric data entry? I >>>> have 3d coordinates of a construction site on a slope (borders, >>>> setbacks and isometric elevation lines). Someone made me aware of >>>> Google's Sketch Up. It looks very attractive for the purpose of >>>> architectural planning, especially suited to create visual >>>> impressions. Doodling seems easy. But I have to start with modeling >>>> the terrain and the envelope and the only way to do that seems to >>>> be in one of several CAD file formats (skp, dwg, dxf, 3ds, ddf and >>>> dem). So I need to cast my numbers into one of these formats. Any >>>> suggestions? >>>> >>>> Thanks >>>> >>>> Frederic >>>> >>> >>> >> Andres, >> >> Thanks for the tip. I wasn't aware of Blender. The web page looks >> promising. I downloaded it and am going to have a look at it. >> >> Frederic >> > =================== > Frederic; > Could you be a little more specific about your data's current > format and the format that seems to best suit your needs? > > Tabular source data and dxf output files for use in CAD are quite > simple to write. But this assumes dxf suits your display program's > needs. > > I think, for display purposes, Microsoft Word still accepts dxf files. > I run unix mostly and I don't keep up with Window$. ;( > > > I suggest you Google for CAD (Computer Aided Drafting) programs. There > are free ones out there. Most will take the DXF format. If the > contours are pre-traced you can polyline them to make the contours > look correct. If the 3D points are X-section or random you will need a > contour generating program.... and so it goes. > > Let's start here - what is your area of expertise, how much math in > your background, why are you attempting this exercise? > > In order to communicate properly I need to know. I can tailor my > comments to suit. > > > > > > Steve Turner > Licensed Land Surveyor CA 5197 (inactive) > 1st order Photogrammetric Compiler (2D depctions from 3D photo sets) > in short Map Maker, Master Grade > norseman at hughes.net Steve, Thank you for your support. In a nutshell: I have a patch of constructible land and have the coordinates of its borders and a few other parameters. The patch is on a slope, so I had a surveyor do the isometric elevation lines. That's a lot more coordinates. The coordinates are plain text. Plain text is a breeze to convert into Python sequences. So I made a bitmap of the ground plan with the elevation lines as a template to play around doing architecture. A ground plan is 2d and as such is rather ill-suited to conceptualize the vertical dimension. Then someone made me aware of Google Sketch Up. It looks sort of like MS Paint in three dimensions: intuitive for doodling. Before I waste time doodling a flying or a subterranean house I want to make a three-dimensional template of the terrain and the constructible volume. The way to import numeric data, for what I see, is as one of the following CAD-file formats: skp, dwg, dxf, 3ds, ddf or dem. So I need to convert my coordinates into one of them, preferably the conversion-friendliest, but I don't have the specifications of any one. I had a look at Blender. It looks impressive too. It might be an alternative to Sketch Up. I'll worry about that later. My immediate need is a file conversion utility. A cursory inspection of Blender's menu tabs and the various help options didn't turn up a file-conversion utility. So, my question is: How do I convert a bunch of three-dimensional coordinates defining lines into a file format Sketch Up can read (skp, dwg, dxf, 3ds, ddf or dem)? Frederic From darcy at druid.net Thu Jun 18 08:06:28 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Jun 2009 08:06:28 -0400 Subject: python tutorial In-Reply-To: References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <20090618080628.2adb7662.darcy@druid.net> On 18 Jun 2009 07:05:20 GMT Steven D'Aprano wrote: > Technically, the Windows file systems record the length of text files and > so an explicit EOF character is redundant, nevertheless, the behaviour of > stopping the read at \0x1A is expected. Whether you want to claim it is I really loved CP/M in its day but isn't it time we let go? -- 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 piet at cs.uu.nl Thu Jun 18 08:08:23 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 14:08:23 +0200 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <873aa5m6ae.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: >>>>> Charles Yeomans (CY) wrote: >CY> Memory management may be an "implementation detail", but it is >CY> unfortunately one that illustrates the so-called law of leaky >CY> abstractions. So I think that one has to write code that follows the >CY> memory management scheme of whatever language one uses. For code written >CY> for CPython only, as mine is, RAII is an appropriate idiom and not kludgy >CY> at all. Under your assumptions, its use would be wrong, of course. I dare to say that, even in CPython it is doomed to disappear, but we don't know yet on what timescale. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From peter.bell at com.au Thu Jun 18 08:27:02 2009 From: peter.bell at com.au (Peter Bell) Date: Thu, 18 Jun 2009 22:27:02 +1000 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au><2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au><4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4a3a329e$1_4@news.peopletelecom.com.au> > "Steven D'Aprano" writes >http://support.microsoft.com/kb/156258 That says that Windows NT 3.5 and NT 4 couldn't make a distinction between text and binary files. I don't think that advances your case. If they had changed the Windows behaviour, yes, but Windows 7 seems to be compatible with NT 3.5 rather than with DOS. Peter Bell. From grguthrie at gmail.com Thu Jun 18 08:38:15 2009 From: grguthrie at gmail.com (guthrie) Date: Thu, 18 Jun 2009 05:38:15 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> Message-ID: <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> On Jun 17, 6:38?pm, Steven Samuel Cole wrote: > Still don't really understand why my initial code didn't work, though... Your code certainly looks reasonable, and looks to me like it "should" work. The comment of partial namespace is interesting, but unconvincing (to me) - but I am not a Python expert! It would certainly seem that within that code block it is in the local namespace, not removed from that scope to be in another. Seems that it should either be a bug, or else is a design error in the language! Just as in the above noted "WTF" - non-intuitive language constructs that surprise users are poor design. From ml at well-adjusted.de Thu Jun 18 09:07:59 2009 From: ml at well-adjusted.de (Jochen Schulz) Date: Thu, 18 Jun 2009 15:07:59 +0200 Subject: Regarding Python is scripting language or not In-Reply-To: References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: <20090618130759.GC19607@wasteland.homelinux.net> Terry Reedy: > Jochen Schulz wrote: >> >> If, by "object-oriented" you mean "everything has to be put into >> classes", then Python is not object-oriented. > > That depends on what you mean by 'put into classes' (and 'everything'). :) What I meant was that in Python you can write code without defining your own classes at all. I had Java in mind where you cannot write a program without using the keyword 'class'. But I think we agree here. J. -- In idle moments I remember former lovers with sentimental tenderness. [Agree] [Disagree] -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: Digital signature URL: From alan.isaac at gmail.com Thu Jun 18 09:22:56 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Thu, 18 Jun 2009 13:22:56 GMT Subject: please help...writing set to a file In-Reply-To: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> References: <4374052f-1118-423d-accc-4348cc9bb4ae@k20g2000vbp.googlegroups.com> Message-ID: On 6/18/2009 5:24 AM yadin apparently wrote: > I got this python program that returns me a set like this.. > Set ([?A\n?, B\n?, ?C\n?, ?D\n?, ?E\n?, ?F\n?, ?G\n? ]) > And a list pp = [?100\n? ?200\n? ?300\n? ?400\n?] > I was reading this from a file?. > How can I transform this to something that looks like this > Column1 Column 2 > > 100 A > 200 B > 300 C > 400 D > E > F > G > And then write this to a file??? http://docs.python.org/library/functions.html#sorted http://docs.python.org/library/itertools.html#itertools.izip_longest http://docs.python.org/library/stdtypes.html#str.format http://docs.python.org/library/functions.html#open hth, Alan Isaac From rhodri at wildebst.demon.co.uk Thu Jun 18 09:28:32 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 14:28:32 +0100 Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro wrote: > Now compare that with Lie Ryan's examples which, instead of using > backslashes, instead used alternative quotes plus backslashes in one > example, and in the other example, alternative quotes, alternatives to > literal quotes, and backslashes. As opposed to my original routine, which > managed three levels of quoting using just backslashes. Do you begin to > understand what I mean by "scalable"? I do, and I still disagree. More importantly, Lie Ryan's examples were much more readable, which is what I was complaining about. -- Rhodri James *-* Wildebeest Herder to the Masses From nick at craig-wood.com Thu Jun 18 09:29:32 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 18 Jun 2009 08:29:32 -0500 Subject: Packing a ctypes struct containing bitfields. References: Message-ID: Karthik wrote: > Hello Everybody, > > I'm trying to create a packed structure in ctypes (with one 64-bit > element that is bitfielded to 48 bits), > unsuccessfully: > > =================================== > from ctypes import * > > class foo (Structure): > _pack_ = 1 > _fields_ = [ > ("bar", c_ulonglong, 48), > ] > > print("sizeof(foo) = %d" % sizeof(foo)) > =================================== > I'm expecting that this should print 6 - however, on my box, it prints > 8. > > The following piece of C code, when compiled and run, prints 6, which > is correct. > =================================== > struct foo { > unsigned long long bar: 48; > }; > > printf("sizeof(foo) = %d", sizeof(foo)); > =================================== > > So... what am I doing wrong? I compiled and ran the above with gcc on my linux box - it prints 8 unless I add __attribute__((__packed__)) to the struct. I'm not sure that using bitfields like that is a portable at all between compilers let alone architectures. I'd probably do from ctypes import * class foo (Structure): _pack_ = 1 _fields_ = [ ("bar0", c_uint32), ("bar1", c_uint16), ] def set_bar(self, bar): self.bar0 = bar & 0xFFFFFFFF self.bar1 = (bar >> 32) & 0xFFFF def get_bar(self): return (self.bar1 << 32) + self.bar0 bar = property(get_bar, set_bar) print "sizeof(foo) = %d" % sizeof(foo) f = foo() print f.bar f.bar = 123456789012345 print f.bar Which prints sizeof(foo) = 6 0 123456789012345 -- Nick Craig-Wood -- http://www.craig-wood.com/nick From HeinTest at web.de Thu Jun 18 09:35:38 2009 From: HeinTest at web.de (=?windows-1252?Q?Hans_M=FCller?=) Date: Thu, 18 Jun 2009 15:35:38 +0200 Subject: Once again, comparison wxpython with PyQt Message-ID: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Here we have to select between wxPython and PyQt for a medium size project. In this project several hundred dialogs are to be created. This work will be done by a program generator which has to re-written. The question now is which framework should we use. As far as I could found is PyQt with the Qt Framework the superior choice. Most articles I found (not all) results to PyQt. But Qt is expensive ~ 3400? per Developer and OS. Since these articles are more or less old, it would be nice to hear your current opinions. Condensed, I found this pros / cons: Pros for Qt: - best framwork, well designed - nice GUI builders - faster execution Cons: - epensive Pros for wxPython: - cheap - big community Cons: - more layers on top of OS - more bugs (still valid ?) - slower Can someone tell me about his experiences with one or both frameworks ? Thanks a lot, Greetings Hans From no.email at please.post Thu Jun 18 09:36:34 2009 From: no.email at please.post (kj) Date: Thu, 18 Jun 2009 13:36:34 +0000 (UTC) Subject: command-line one-liners a la Perl? Message-ID: I'm a recovering Perl addict, and I'm jonesin' badly for command-line one-liners, like % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt How can I get my fix with Python? kynn From pruebauno at latinmail.com Thu Jun 18 09:56:00 2009 From: pruebauno at latinmail.com (nn) Date: Thu, 18 Jun 2009 06:56:00 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> Message-ID: <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> On Jun 18, 8:38?am, guthrie wrote: > On Jun 17, 6:38?pm, Steven Samuel Cole > wrote: > > > Still don't really understand why my initial code didn't work, though... > > Your code certainly looks reasonable, and looks to me like it "should" > work. The comment of partial namespace is interesting, but > unconvincing (to me) - but I am not a Python expert! It would > certainly seem that within that code block it is in the local > namespace, not removed from that scope to be in another. > > Seems that it should either be a bug, or else is a design error in the > language! > > Just as in the above noted "WTF" - non-intuitive language constructs > that surprise users are poor design. This is certainly an odd one. This code works fine under 2.6 but fails in Python 3.1. >>> class x: ... lst=[2] ... gen=[lst.index(e) for e in lst] ... Traceback (most recent call last): File "", line 1, in File "", line 3, in x File "", line 3, in NameError: global name 'lst' is not defined >>> From python at mrabarnett.plus.com Thu Jun 18 10:05:12 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Jun 2009 15:05:12 +0100 Subject: command-line one-liners a la Perl? In-Reply-To: References: Message-ID: <4A3A4998.1090007@mrabarnett.plus.com> kj wrote: > > > I'm a recovering Perl addict, and I'm jonesin' badly for command-line > one-liners, like > > % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt > > How can I get my fix with Python? > python -c "print 'Hello world!'" Although you need to remember that Python makes much more use of whitespace, which limits the usefulness of the command line. From x.piter at gmail.com Thu Jun 18 10:18:10 2009 From: x.piter at gmail.com (Piter_) Date: Thu, 18 Jun 2009 07:18:10 -0700 (PDT) Subject: pyserial. How to set Handshaking to "RST on TX". Message-ID: <80890a0d-5645-4f56-a373-1e80bae5dbde@q37g2000vbi.googlegroups.com> Hi all I try to drive some equipment trough serial port. So far I could do it with some windows com port terminal if handhaking set to "RTS on TX". http://hw-server.com/software/termv19b.html But I cant find out how to set it in pyserial. Thanks in advance for any hint. From unayok at gmail.com Thu Jun 18 10:32:28 2009 From: unayok at gmail.com (unayok) Date: Thu, 18 Jun 2009 07:32:28 -0700 (PDT) Subject: command-line one-liners a la Perl? References: Message-ID: <8e29f8d7-edd1-493a-aa9a-f15565bd9353@r13g2000vbr.googlegroups.com> On Jun 18, 9:36?am, kj wrote: > I'm a recovering Perl addict, and I'm jonesin' badly for command-line > one-liners, like > > ? % perl -lne '@f=split "\t";print join "\t", at f[3,1] if $f[2]=~/frobozz/i' in.txt > > How can I get my fix with Python? > > kynn I'd encourage you to learn the ways of Python which ordinarily don't encourage cramming lots of code into a single line. However... if you are insistent on seeing how much rope Python can give you to hang yourself... ;) $ python -c 'print "\n".join( "\t".join( ( data[3], data[1] ) ) for data in ( lambda fn : ( line.strip().split("\t") for line in file( fn, "r" ) ) )( "in.txt" ) if data[2].lower().find( "frobozz" ) > -1 )' (untested) should do something similar to your perl statement (display the fourth and second fields from tab-delimited lines containing "frobozz" in any case-mixture in the third field for lines read from the "in.txt" file). Note that the frobozz search is not a regex search in this example. Requiring regex would make things more complicated. Probably could be cleaned up a bit. u. From castironpi at gmail.com Thu Jun 18 10:44:42 2009 From: castironpi at gmail.com (Aaron Brady) Date: Thu, 18 Jun 2009 07:44:42 -0700 (PDT) Subject: Regarding Python is scripting language or not References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> Message-ID: On Jun 18, 6:07?am, Jochen Schulz wrote: > Terry Reedy: > > > Jochen Schulz wrote: > > >> If, by "object-oriented" you mean "everything has to be put into > >> classes", then Python is not object-oriented. > > > That depends on what you mean by 'put into classes' (and 'everything'). > > :) What I meant was that in Python you can write code without defining > your own classes at all. I had Java in mind where you cannot write a > program without using the keyword 'class'. But I think we agree here. Numbers have infinite precision. From deets at nospam.web.de Thu Jun 18 10:49:21 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 18 Jun 2009 16:49:21 +0200 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <79v28tF1srnv7U1@mid.uni-berlin.de> Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size > project. In this project several hundred dialogs are to be created. This > work will be done by a program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. No, it's not. It is LGPL by now. You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's about 500?. However, it is much less than Qt used to be. Diez From chris at simplistix.co.uk Thu Jun 18 10:55:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 15:55:51 +0100 Subject: Announcing www.python-excel.org Message-ID: <4A3A5577.2060704@simplistix.co.uk> Hi All, Google unfortunately has a knack of presenting prospective Python users who need to work with Excel files with information that is now really rather out of date. To try and help with this, I've setup a small website at: http://www.python-excel.org ...to try and list the latest recommended ways of working with Excel files in Python. If you work with excel files in Python, then please take a look and let me know what you think. cheers, Chris PS: If anyone reading this has a python-related blog, it might help Google if you could post a short entry about this new site. -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From piet at cs.uu.nl Thu Jun 18 11:02:27 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 17:02:27 +0200 Subject: Newbie queue question References: Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Hi, >JE> I'm pretty new to Python (2.6) and I've run into a problem I just >JE> can't seem to solve. >JE> I'm using dbfpy to access DBF tables as part of a little test project. >JE> I've programmed two separate functions, one that reads the DBF in main >JE> thread and the other which reads the DBF asynchronously in a separate >JE> thread. >JE> Here's the code: >JE> def demo_01(): >JE> '''DBF read speed only''' >JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) >JE> for i1 in xrange(len(dbf1)): >JE> rec = dbf1[i1] >JE> dbf1.close() >JE> def demo_03(): >JE> '''DBF read speed into a FIFO queue''' >JE> class mt(threading.Thread): >JE> q = Queue.Queue(64) >JE> def run(self): >JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) >JE> for i1 in xrange(len(dbf1)): >JE> self.q.put(dbf1[i1]) >JE> dbf1.close() >JE> del dbf1 >JE> self.q.join() >JE> t = mt() >JE> t.start() >JE> while t.isAlive(): >JE> try: >JE> rec = t.q.get(False, 0.2) >JE> t.q.task_done(); >JE> except: >JE> pass >JE> del t >JE> However I'm having serious issues with the second method. It seems >JE> that as soon as I start accessing the queue from both threads, the >JE> reading speed effectively halves. >JE> I have tried the following: >JE> 1. using deque instead of queue (same speed) >JE> 2. reading 10 records at a time and inserting them in a separate loop >JE> (hoped the congestion would help) >JE> 3. Increasing queue size to infinite and waiting 10 seconds in main >JE> thread before I started reading - this one yielded full reading speed, >JE> but the waiting took away all the threading benefits >JE> I'm sure I'm doing something very wrong here, I just can't figure out >JE> what. For a start the thread switching and the queue administration just take time, that you can avoid if you do everything sequentially. Threading can have an advantage if there is the possiblilty of overlap. But there is none in your example, so it's just overhead. If your processing would do something substantially and if the reading of the file would be I/O bound for example. You don't say how big the file is, and it also may be in your O.S. cache so then reading it would essentially be CPU bound. And then there is this code: while t.isAlive(): try: rec = t.q.get(False, 0.2) t.q.task_done(); except: pass t.q.get(False, 0.2) means do a non-blocking get, so that when there is nothing in the queue it returns immediately and then takes the exception path which also is substantial overhead. Whether this will happen or not depends on the timing which depends on the scheduling of the O.S. For example when the O.S. schedules the main task first it will be busy wait looping quite a lot before the first item arrives in the queue. If the file is small it will probably put then all the items in the queue and there will be no more busy wait looping. But busy wait looping just consumes CPU time. By the way, the second parameter (0.2) which is supposed to be the timeout period is just ignored if the first parameter is false. You might be better off giving True as the first parameter to get. I dislike any form of busy wait loop. It would be better to just use a normal get(), but that conflicts with your end detection. while t.isAlive() is not a particularly good way to detect that the processing is finished I think because of timing issues. After the last t.q.task_done() [which doesn't need a semicolon, by the way] it takes some time before the self.q.join() will be processed and the thread finishes. In the mean time while t.isAlive() is constantly being tested, also wasting CPU time. IMHO a better way is to put a sentinel object in the queue: def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) self.q.put(None) dbf1.close() del dbf1 self.q.join() while True: rec = t.q.get() t.q.task_done() if rec is None: break And then you probably can also get rid of the self.q.join() and t.q.task_done() -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From pdpinheiro at gmail.com Thu Jun 18 11:22:59 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 18 Jun 2009 08:22:59 -0700 (PDT) Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> Message-ID: <5995aa64-ca3c-4e82-a8ca-8138af59ac2e@e20g2000vbc.googlegroups.com> On Jun 18, 3:49?pm, "Diez B. Roggisch" wrote: > Hans M?ller wrote: > > Here we have to select between wxPython and PyQt for a medium size > > project. In this project several hundred dialogs are to be created. This > > work will be done by a program generator which has to re-written. > > > The question now is which framework should we use. > > As far as I could found is PyQt with the Qt Framework the superior choice. > > Most articles I found (not all) results to PyQt. > > But Qt is expensive ~ 3400? per Developer and OS. > > No, it's not. It is LGPL by now. > > You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's > about 500?. However, it is much less than Qt used to be. > > Diez Not quite. You only have to pay for the commercial license -- you can use PyQT as GPL as well. This may or may not be acceptable for Hans's purposes, but nowhere near "have to pay licensing". From newsgroup at silveraxe.de Thu Jun 18 11:31:04 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Thu, 18 Jun 2009 17:31:04 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <79v28tF1srnv7U1@mid.uni-berlin.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> Message-ID: <4a3a5dc2$0$32676$9b4e6d93@newsspool2.arcor-online.net> Diez B. Roggisch schrieb: >> Here we have to select between wxPython and PyQt for a medium size >> project. In this project several hundred dialogs are to be created. This >> work will be done by a program generator which has to re-written. >> >> The question now is which framework should we use. >> As far as I could found is PyQt with the Qt Framework the superior choice. >> Most articles I found (not all) results to PyQt. >> But Qt is expensive ~ 3400? per Developer and OS. > > No, it's not. It is LGPL by now. > > You will have to pay licensing for *PyQT*. I'm not sure, but I *think* it's > about 500?. However, it is much less than Qt used to be. You are pretty close, it's ?350.00 + 15% VAT (UK) See here: http://www.riverbankcomputing.co.uk/commercial/buy Best, Hilmar From chris at simplistix.co.uk Thu Jun 18 11:38:14 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 16:38:14 +0100 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 Message-ID: <4A3A5F66.2030701@simplistix.co.uk> Hi All, Too many people in the Python community *still* think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's EuroPython conference in Birmingham, UK on Monday, 29th June that will cover working with Excel files in Python using the pure-python libraries xlrd, xlwt and xlutils. I'll be looking to cover: - Reading Excel Files Including extracting all the data types, formatting and working with large files. - Writing Excel Files Including formatting, many of the useful frilly extras and writing large excel files. - Modifying and Filtering Excel Files A run through of taking existing Excel files and modifying them in various ways. - Workshop for your problems I'm hoping anyone who attends will get a lot out of this! If you're planning on attending and have a particular problem you'd like to work on in this part of the tutorial, please drop me an email and I'll try and make sure I come prepared! All you need for the tutorial is a working knowledge of Excel and Python, with a laptop as an added benefit, and to be at EuroPython this year: http://www.europython.eu/ I look forward to seeing you all there! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From james at agentultra.com Thu Jun 18 11:45:45 2009 From: james at agentultra.com (J Kenneth King) Date: Thu, 18 Jun 2009 11:45:45 -0400 Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: <85iqita6l2.fsf@agentultra.com> per writes: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you berkeley db is pretty fast. locking and such nice features are included. the module you'd be looking at is bsddb i believe. From aahz at pythoncraft.com Thu Jun 18 12:09:24 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Jun 2009 09:09:24 -0700 Subject: Exceptions and Object Destruction (was: Problem with apsw and garbage collection) References: <87tz2mb2yy.fsf@vostro.rath.org> <7x7hzbv14a.fsf@ruckus.brouhaha.com> Message-ID: In article , Steven D'Aprano wrote: > >Additionally, while I'm a fan of the simplicity of CPython's ref counter, >one serious side effect of it is that it requires the GIL, which >essentially means CPython is crippled on multi-core CPUs compared to non- >ref counting implementations. Your bare "crippled" is an unfair overstatement. What you meant to write was that computational multi-threaded applications that don't use NumPy are crippled. Otherwise you're simply spreading FUD. -- 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 vinay_sajip at yahoo.co.uk Thu Jun 18 12:15:12 2009 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 18 Jun 2009 09:15:12 -0700 (PDT) Subject: logging.fileConfig limitations? References: Message-ID: <6478bb0e-69aa-490f-8d4b-109f1e09617d@r3g2000vbp.googlegroups.com> On Jun 17, 9:05?pm, Mani Ghasemlou wrote: > Hi all, > > C:\Documents and Settings\?????2\Local Settings\Application Data\MyApp\MyApp.log > > Now it turns out that the logging module can't find "C:/Documents and > Settings/??????????2/Local Settings/Application Data/MyApp/MyApp.log" > specified in the "args" section, and rightfully so because this is an > encoded string. *There does not seem to be a way for me to specify the > encoding of the string so that the logging module resolves the proper > unicode path.* This is my key problem! > > Is there some way to accomplish what I want? > No need to poke about in the source. Here's my script: #-- log_ufn.py -- import logging.config logging.config.fileConfig("log_ufn.ini") logging.error("Holy Cow, Batman!") and here's my configuration file, adapted from yours: #-- log_ufn.ini -- [formatters] keys: normal [handlers] keys: rotatingfile [loggers] keys: root [formatter_normal] format: %(asctime)s %(levelname)s %(module)s: %(message)s [logger_root] level: DEBUG handlers: rotatingfile [handler_rotatingfile] class: handlers.RotatingFileHandler formatter: normal args: (u"C:/Temp/\u00DF\u00E9\u00E4\u00F6\u00DC2/MyApp.log", "a", 2*1024*1024, 5, None) Note that I specified a Unicode filename, with Unicode escapes for ?????2. After I run the script (using ActivePython 2.5.2.2), I get the following output: # -- Contents of C:\temp\?????2\MyApp.log -- 2009-06-18 17:07:30,493 ERROR log_ufn: Holy Cow, Batman! Which seems to be what one would expect. From ethan at stoneleaf.us Thu Jun 18 12:30:28 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Jun 2009 09:30:28 -0700 Subject: python tutorial In-Reply-To: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <4A3A6BA4.1050909@stoneleaf.us> steve wrote: > "Robert Kern" wrote in message > news:mailman.1728.1245289092.8015.python-list at python.org... > >>On 2009-06-17 19:36, steve wrote: >> >>>>"Carl Banks" wrote in message >>>>news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>>>On Jun 15, 7:56 pm, "steve" wrote: >>>> >>>>>I was just looking at the python tutorial, and I noticed these lines: >>>>> >>>>>http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>>> >>>>>"Windows makes a distinction between text and binary files; >>>>>"the end-of-line characters in text files are automatically altered >>>>>"slightly when data is read or written. >>>>> >>>>>I don't see any obvious way to at docs.python.org to get that >>>>>corrected: >>>>>Is >>>>>there some standard procedure? >>>> >>>>What's wrong with it? >>>> >>>> >>>>Carl Banks >>> >>>1) Windows does not make a distinction between text and binary files. >>> >>>2) end-of-line characters in text files are not automatically altered by >>>Windows. >> >>The Windows implementation of the C standard makes the distinction. E.g. >>using stdio to write out "foo\nbar\n" in a file opened in text mode will >>result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode >>will result in "foo\nbar\n" in memory. Reading such a file in binary mode >>will result in "foo\r\nbar\r\n". In your bug report, you point out several >>proprietary APIs that do not make such a distinction, but that does not >>remove the implementations of the standard APIs that do make such a >>distinction. >> >> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >> >>Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >>runtime, but I think it's a reasonable statement on the whole. >> >>-- >>Robert Kern > > > > Which is where I came in: I was looking for simple file IO in the tutorial. > The tutorial tells me something false about Windows, rather than something > true about Python. > > I'm looking at a statement that is clearly false (for anyone who knows > anything about Windows file systems and Windows file io), which leaves the > Python behaviour completely undefined (for anyone who knows nothing about > Python). > > I understand that many of you don't really have any understanding of > Windows, much less any background with Windows, and I'm here to help. That > part was simple. I will freely admit to having no idea of just how many pythonastis have good Windows experience/background, but how about you give us the benefit of the doubt and tell us exactly which languages/routines you play with *in windows* that fail to make a distinction between text and binary? > The next part is where I can't help: What is the behaviour of Python? > > I'm sure you don't think that tutorial is only for readers who can guess > that they have to extrapolate from the behaviour of the Visual C library in > order to work out what Python does. > > > Steve From torriem at gmail.com Thu Jun 18 12:32:27 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 18 Jun 2009 10:32:27 -0600 Subject: Exotic Logics In-Reply-To: References: Message-ID: <4A3A6C1B.70208@gmail.com> William Clifford wrote: > I've read one can do all of the 16 binary operations with clever uses > of NAND or NOR. That is correct. In fact semiconductor logic is done using these two principle gates. See http://en.wikipedia.org/wiki/NAND_logic . Quite interesting really. From wells at submute.net Thu Jun 18 12:54:58 2009 From: wells at submute.net (Wells Oliver) Date: Thu, 18 Jun 2009 11:54:58 -0500 Subject: A question on scope... Message-ID: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> In writing out python classes, it seems the 'self' is optional, meaning that inside a class method, "self.foo = bar" has the same effect as "foo = bar". Is this right? If so, it seems a little odd- what's the rationale? Or am I mistaken? -- Wells Oliver wells at submute.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jun 18 13:05:53 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Jun 2009 18:05:53 +0100 Subject: A question on scope... In-Reply-To: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> Message-ID: <4A3A73F1.7090107@mrabarnett.plus.com> Wells Oliver wrote: > In writing out python classes, it seems the 'self' is optional, meaning > that inside a class method, "self.foo = bar" has the same effect as "foo > = bar". Is this right? If so, it seems a little odd- what's the rationale? > > Or am I mistaken? > Inside a function or method "foo = bar" would make "foo" local by default. In an instance method an attribute "foo" of the instance needs a reference to the instance itself, by convention "self", therefore "self.foo". In a class method a reference to the class itself is by convention "cls", therefore "cls.foo". From lie.1296 at gmail.com Thu Jun 18 13:54:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 17:54:17 GMT Subject: TypeError: int argument required In-Reply-To: References: <1e9e5f99-593a-4740-bf2a-52b597be1064@x1g2000prh.googlegroups.com> Message-ID: Rhodri James wrote: > On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro > wrote: > >> Now compare that with Lie Ryan's examples which, instead of using >> backslashes, instead used alternative quotes plus backslashes in one >> example, and in the other example, alternative quotes, alternatives to >> literal quotes, and backslashes. As opposed to my original routine, which >> managed three levels of quoting using just backslashes. Do you begin to >> understand what I mean by "scalable"? > > I do, and I still disagree. More importantly, Lie Ryan's examples were > much more readable, which is what I was complaining about. I still remember when I started programming, I wrote in QBASIC without indentations. I honestly saw no reason to indent because I still can see the program flow as clearly as the bottom of a bucket of crystalline water. No decisions to be made, everything is consistently justified left. I still remember asking a friend, "Why is your code jagged like that?" and him looking at me a bit confused at the question. From kyosohma at gmail.com Thu Jun 18 14:00:25 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 18 Jun 2009 11:00:25 -0700 (PDT) Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: Message-ID: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> On Jun 18, 10:38?am, Chris Withers wrote: > Hi All, > > Too many people in the Python community *still* think the only way to > work with Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's EuroPython > conference in Birmingham, UK on Monday, 29th June that will cover > working with Excel files in Python using the pure-python libraries xlrd, > xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > ? ?Including extracting all the data types, formatting and working with > ? ?large files. > > - Writing Excel Files > > ? ?Including formatting, many of the useful frilly extras and writing > ? ?large excel files. > > - Modifying and Filtering Excel Files > > ? ?A run through of taking existing Excel files and modifying them in > ? ?various ways. > > - Workshop for your problems > > ? ?I'm hoping anyone who attends will get a lot out of this! If you're > ? ?planning on attending and have a particular problem you'd like to work > ? ?on in this part of the tutorial, please drop me an email and I'll try > ? ?and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at EuroPython this > year: > > http://www.europython.eu/ > > I look forward to seeing you all there! > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > ? ? ? ? ? ? -http://www.simplistix.co.uk As I recall, these utilities don't allow the programmer to access Excel's formulas. Is that still an issue? Mike From ullrich at math.okstate.edu Thu Jun 18 14:13:42 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:13:42 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. I won't ask where I can find this definition. That Koch thing is a closed curve in R^2. That means _by definition_ that it is a continuous function from [0,1] to R^2 (with the same value at the endpoints). And any continuous fu From ullrich at math.okstate.edu Thu Jun 18 14:14:20 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:14:20 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. From ullrich at math.okstate.edu Thu Jun 18 14:16:06 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:16:06 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <201l35pbl234ousllfthb5vsl1advoj9cv@4ax.com> On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro wrote: >In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, wrote: > >> Lawrence D'Oliveiro writes: >> >>> I don't think any countable set, even a countably-infinite set, can have >>> a fractal dimension. It's got to be uncountably infinite, and therefore >>> uncomputable. >> >> I think the idea is you assume uniform continuity of the set (as >> expressed by a parametrized curve). That should let you approximate >> the fractal dimension. > >Fractals are, by definition, not uniform in that sense. Sorry if I've already posted half of this - having troubles hitting the toushpad on this little machine by accident. The fractal in question is a curve in R^2. By definition that means it is a continuous function from [a,b] to R^2 (with the same value at the two endpoints). Hence it's uniformly continuous. From ullrich at math.okstate.edu Thu Jun 18 14:17:44 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:17:44 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> Message-ID: <141l35pi79g53kfjji7t9ms8ooahqrmomv@4ax.com> On Wed, 17 Jun 2009 07:35:35 +0200, Jaime Fernandez del Rio wrote: >On Wed, Jun 17, 2009 at 4:50 AM, Lawrence >D'Oliveiro wrote: >> In message <7x63ew3uo9.fsf at ruckus.brouhaha.com>, ?wrote: >> >>> Lawrence D'Oliveiro writes: >>> >>>> I don't think any countable set, even a countably-infinite set, can have >>>> a fractal dimension. It's got to be uncountably infinite, and therefore >>>> uncomputable. >>> >>> I think the idea is you assume uniform continuity of the set (as >>> expressed by a parametrized curve). ?That should let you approximate >>> the fractal dimension. >> >> Fractals are, by definition, not uniform in that sense. > >I had my doubts on this statement being true, so I've gone to my copy >of Gerald Edgar's "Measure, Topology and Fractal Geometry" and >Proposition 2.4.10 on page 69 states: "The sequence (gk), in the >dragon construction of the Koch curve converges uniformly." And >uniform continuity is a very well defined concept, so there really >shouldn't be an interpretation issue here either. Would not stick my >head out for it, but I am pretty sure that a continuous sequence of >curves that converges to a continuous curve, will do so uniformly. Nope. Not that I see the relvance here - the g_k _do_ converge uniformly. >Jaime From ullrich at math.okstate.edu Thu Jun 18 14:19:23 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:19:23 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans wrote: > >On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: > >> Jaime Fernandez del Rio writes: >>> I am pretty sure that a continuous sequence of >>> curves that converges to a continuous curve, will do so uniformly. >> >> I think a typical example of a curve that's continuous but not >> uniformly continuous is >> >> f(t) = sin(1/t), defined when t > 0 >> >> It is continuous at every t>0 but wiggles violently as you get closer >> to t=0. You wouldn't be able to approximate it by sampling a finite >> number of points. A sequence like >> >> g_n(t) = sin((1+1/n)/ t) for n=1,2,... >> >> obviously converges to f, but not uniformly. On a closed interval, >> any continuous function is uniformly continuous. > >Isn't (-?, ?) closed? What is your version of the definition of "closed"? >Charles Yeomans From ullrich at math.okstate.edu Thu Jun 18 14:21:50 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:21:50 -0500 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> Message-ID: <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> On Wed, 17 Jun 2009 05:46:22 -0700 (PDT), Mark Dickinson wrote: >On Jun 17, 1:26?pm, Jaime Fernandez del Rio >wrote: >> On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinson wrote: >> > Maybe James is thinking of the standard theorem >> > that says that if a sequence of continuous functions >> > on an interval converges uniformly then its limit >> > is continuous? > >s/James/Jaime. Apologies. > >> P.S. The snowflake curve, on the other hand, is uniformly continuous, right? > >Yes, at least in the sense that it can be parametrized >by a uniformly continuous function from [0, 1] to the >Euclidean plane. I'm not sure that it makes a priori >sense to describe the curve itself (thought of simply >as a subset of the plane) as uniformly continuous. As long as people are throwing around all this math stuff: Officially, by definition a curve _is_ a parametrization. Ie, a curve in the plane _is_ a continuous function from an interval to the plane, and a subset of the plane is not a curve. Officially, anyway. >Mark From ullrich at math.okstate.edu Thu Jun 18 14:26:56 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Jun 2009 13:26:56 -0500 Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson wrote: >On Jun 17, 3:46?pm, Paul Rubin wrote: >> Mark Dickinson writes: >> > It looks as though you're treating (a portion of?) the Koch curve as >> > the graph of a function f from R -> R and claiming that f is >> > uniformly continuous. ?But the Koch curve isn't such a graph (it >> > fails the 'vertical line test', >> >> I think you treat it as a function f: R -> R**2 with the usual >> distance metric on R**2. > >Right. Or rather, you treat it as the image of such a function, >if you're being careful to distinguish the curve (a subset >of R^2) from its parametrization (a continuous function >R -> R**2). It's the parametrization that's uniformly >continuous, not the curve, Again, it doesn't really matter, but since you use the phrase "if you're being careful": In fact what you say is exactly backwards - if you're being careful that subset of the plane is _not_ a curve (it's sometimes called the "trace" of the curve". >and since any curve can be >parametrized in many different ways any proof of uniform >continuity should specify exactly which parametrization is >in use. Any _closed_ curve must have [a,b] as its parameter interval, and hence is uniformly continuous since any continuous function on [a,b] is uniformly continuous. >Mark From charles at declareSub.com Thu Jun 18 14:32:13 2009 From: charles at declareSub.com (Charles Yeomans) Date: Thu, 18 Jun 2009 14:32:13 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <814BF6DE-E201-4FCB-ACC4-328AEC689180@declareSub.com> On Jun 18, 2009, at 2:19 PM, David C. Ullrich wrote: > On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans > wrote: > >> >> On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote: >> >>> Jaime Fernandez del Rio writes: >>>> I am pretty sure that a continuous sequence of >>>> curves that converges to a continuous curve, will do so uniformly. >>> >>> I think a typical example of a curve that's continuous but not >>> uniformly continuous is >>> >>> f(t) = sin(1/t), defined when t > 0 >>> >>> It is continuous at every t>0 but wiggles violently as you get >>> closer >>> to t=0. You wouldn't be able to approximate it by sampling a finite >>> number of points. A sequence like >>> >>> g_n(t) = sin((1+1/n)/ t) for n=1,2,... >>> >>> obviously converges to f, but not uniformly. On a closed interval, >>> any continuous function is uniformly continuous. >> >> Isn't (-?, ?) closed? > > What is your version of the definition of "closed"? >> My version of a closed interval is one that contains its limit points. Charles Yeomans From lie.1296 at gmail.com Thu Jun 18 14:48:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 18:48:27 GMT Subject: walking a directory with very many files In-Reply-To: <20090617110705.7e7c423f@malediction> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> Message-ID: <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Mike Kazantsev wrote: > On Wed, 17 Jun 2009 03:42:02 GMT > Lie Ryan wrote: > >> Mike Kazantsev wrote: >>> In fact, on modern filesystems it doesn't matter whether you >>> accessing /path/f9e95ea4926a4 with million files in /path >>> or /path/f/9/e/95ea with only hundred of them in each path. Former >>> case (all-in-one-path) would even outperform the latter with ext3 >>> or reiserfs by a small margin. >>> Sadly, that's not the case with filesystems like FreeBSD ufs2 (at >>> least in sixth branch), so it's better to play safe and create >>> subdirs if the app might be run on different machines than keeping >>> everything in one path. >> It might not matter for the filesystem, but the file explorer (and ls) >> would still suffer. Subfolder structure would be much better, and much >> easier to navigate manually when you need to. > > It's an insane idea to navigate any structure with hash-based names > and hundreds of thousands files *manually*: "What do we have here? > Hashies?" ;) > Like... when you're trying to debug a code that generates an error with a specific file... Yeah, it might be possible to just mv the file from outside, but not being able to enter a directory just because you've got too many files in it is kind of silly. From robert.kern at gmail.com Thu Jun 18 14:55:07 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Jun 2009 13:55:07 -0500 Subject: python tutorial In-Reply-To: <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: On 2009-06-18 00:57, steve wrote: > "Robert Kern" wrote in message > news:mailman.1728.1245289092.8015.python-list at python.org... >> On 2009-06-17 19:36, steve wrote: >>>> "Carl Banks" wrote in message >>>> news:2f6271b1-5ffa-4cec-81f8->>0276ad647026 at p5g2000pre.googlegroups.com... >>>> On Jun 15, 7:56 pm, "steve" wrote: >>>>> I was just looking at the python tutorial, and I noticed these lines: >>>>> >>>>> http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... >>>>> >>>>> "Windows makes a distinction between text and binary files; >>>>> "the end-of-line characters in text files are automatically altered >>>>> "slightly when data is read or written. >>>>> >>>>> I don't see any obvious way to at docs.python.org to get that >>>>> corrected: >>>>> Is >>>>> there some standard procedure? >>>> What's wrong with it? >>>> >>>> >>>> Carl Banks >>> 1) Windows does not make a distinction between text and binary files. >>> >>> 2) end-of-line characters in text files are not automatically altered by >>> Windows. >> The Windows implementation of the C standard makes the distinction. E.g. >> using stdio to write out "foo\nbar\n" in a file opened in text mode will >> result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode >> will result in "foo\nbar\n" in memory. Reading such a file in binary mode >> will result in "foo\r\nbar\r\n". In your bug report, you point out several >> proprietary APIs that do not make such a distinction, but that does not >> remove the implementations of the standard APIs that do make such a >> distinction. >> >> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >> >> Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >> runtime, but I think it's a reasonable statement on the whole. >> >> -- >> 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 >> > > > Which is where I came in: I was looking for simple file IO in the tutorial. > The tutorial tells me something false about Windows, rather than something > true about Python. I don't think it's false. I think it's a fair statement given the Windows implementation of the C standard library. Such things are frequently considered to be part of the OS. This isn't just some random API; it's the implementation of the C standard. > I'm looking at a statement that is clearly false (for anyone who knows > anything about Windows file systems and Windows file io), which leaves the > Python behaviour completely undefined (for anyone who knows nothing about > Python). > > I understand that many of you don't really have any understanding of > Windows, much less any background with Windows, and I'm here to help. That > part was simple. > > The next part is where I can't help: What is the behaviour of Python? The full technical description is where it belongs, in the reference manual rather than a tutorial: http://docs.python.org/library/functions.html#open > I'm sure you don't think that tutorial is only for readers who can guess > that they have to extrapolate from the behaviour of the Visual C library in > order to work out what Python does. All a tutorial level documentation needs to know is what is described: when a file is opened in text mode, the actual bytes written to a file for a newline may be different depending on the platform. The reason that it does not explain the precise behavior on each and every platform is because it *is* undefined. Python 2.x does whatever the C standard library implementation for stdio does. It mentions Windows as a particularly common example of a difference between text mode and binary mode. -- 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 tamuzija at yahoo.es Thu Jun 18 14:57:46 2009 From: tamuzija at yahoo.es (Moni GV) Date: Thu, 18 Jun 2009 18:57:46 +0000 (GMT) Subject: ERROR: how to use a text file in a module? Message-ID: <645298.22108.qm@web24404.mail.ird.yahoo.com> Hi, Help with a "No such file ..." error. I have the next folder structure: ---Network contains: ??? --packets.py ??? --Temp contains: ?????? -test.py Well, within packets.py I do this: from Temp.test import * Within test.py I do this: f = open ("topo.txt", "r") The error is: No such file "topo.txt" However, when I execute test.py, without using neither packets.py nor the folder structure, there is no error, because topo.txt exists. I'm sure I'm doing something wrong with the "import" staff or "path" maybe, but have no idea...please help!!! Thanks in advance! ** M?nica Guerrero M.Sc. Student Rey Juan Carlos University Madrid -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Thu Jun 18 15:08:14 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Jun 2009 19:08:14 GMT Subject: python tutorial In-Reply-To: <87r5xh2a6v.fsf@benfinney.id.au> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39f58f$0$32385$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <87r5xh2a6v.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > You started out asking how to *interpret* it, which is fine for this > forum; but discussing it here isn't going to lead automatically to any > *midification* to a document developed within the core of Python. > I definitely want to see how python doc be midified, last time I checked MIDI cannot play spoken words, don't know whether there is text-to-speech sound font though ;) From tjreedy at udel.edu Thu Jun 18 15:17:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 15:17:05 -0400 Subject: Regarding Python is scripting language or not In-Reply-To: <20090618130759.GC19607@wasteland.homelinux.net> References: <501798.29841.qm@web94916.mail.in2.yahoo.com> <20090617123540.GA19607@wasteland.homelinux.net> <20090618130759.GC19607@wasteland.homelinux.net> Message-ID: Jochen Schulz wrote: > Terry Reedy: >> Jochen Schulz wrote: >>> If, by "object-oriented" you mean "everything has to be put into >>> classes", then Python is not object-oriented. >> That depends on what you mean by 'put into classes' (and 'everything'). > > :) What I meant was that in Python you can write code without defining > your own classes at all. I had Java in mind where you cannot write a > program without using the keyword 'class'. But I think we agree here. Yes, I amplified your basic point ;-) From vishal_shetye at persistent.co.in Thu Jun 18 15:27:09 2009 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Fri, 19 Jun 2009 00:57:09 +0530 Subject: Help: Group based synchronize decorator Message-ID: I want to synchronize calls using rw locks per 'group' and my implementation is similar to http://code.activestate.com/recipes/465057/ except that I have my own Lock implementation. All my synchronized functions take 'whatGroup' as param. My lock considers 'group' while deciding on granting locks through acquire. What I could come up with is: - decorator knows(assumes) first param to decorated functions is always 'whatGroup' - decorator passes this 'whatGroup' argument to my lock which is used in acquire logic. Is it ok to make such assumptions in decorator? Any suggestions/alternatives? thanks vishal DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. From piet at cs.uu.nl Thu Jun 18 15:43:24 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 18 Jun 2009 21:43:24 +0200 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a3a329e$1_4@news.peopletelecom.com.au> Message-ID: >>>>> "Peter Bell" (PB) wrote: >>> "Steven D'Aprano" >PB> writes >>> http://support.microsoft.com/kb/156258 >PB> That says that Windows NT 3.5 and NT 4 couldn't make >PB> a distinction between text and binary files. I don't think >PB> that advances your case. And that was a bug apparently (euphemistically called a `problem'). >PB> If they had changed the Windows behaviour, yes, but >PB> Windows 7 seems to be compatible with NT 3.5 rather >PB> than with DOS. If that is true then they may still be `researching this problem'. :=( -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Thu Jun 18 15:50:47 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 15:50:47 -0400 Subject: python tutorial In-Reply-To: <4A3A6BA4.1050909@stoneleaf.us> References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com><4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d73d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4A3A6BA4.1050909@stoneleaf.us> Message-ID: >>>> >>>> 1) Windows does not make a distinction between text and binary files. 'Windows', in its broad sense of Windoes system, includes the standards and protocols mandated by its maker, Microsoft Corporation, and implemented in its C compiler, which it uses to compile the software that other interact with. I am pretty sure that WixXP Notepad *still* requires \r\n in text files, even though Wordpad does not. Don't know about Haste (la Vista) and the upcoming Win7. It is a common metaphor in English to ascribe agency to products and blame them for the sins (or virtues) of their maker. 'Unix' and 'Linux' are also used in the double meaning of OS core and OS system that includes core, languages tools, and standard utilities. >>>> 2) end-of-line characters in text files are not automatically >>>> altered by >>>> Windows. >>> >>> The Windows implementation of the C standard makes the distinction. >>> E.g. using stdio to write out "foo\nbar\n" in a file opened in text >>> mode will result in "foo\r\nbar\r\n" in the file. Reading such a file >>> in text mode will result in "foo\nbar\n" in memory. Reading such a >>> file in binary mode will result in "foo\r\nbar\r\n". In your bug >>> report, you point out several proprietary APIs that do not make such >>> a distinction, but that does not remove the implementations of the >>> standard APIs that do make such a distinction. >>> >>> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx >>> >>> Perhaps it's a bit dodgy to blame "Windows" per se rather than its C >>> runtime, but I think it's a reasonable statement on the whole. I agree. There are much worse sins in the docs to be fixed. Hmmm. "Bill Gates, his successors, and minions, still require, after 28 years, that we jump through artificial hoops, confuse ourselves, and waste effort, by differentiating text and binary files and fiddling with line endings." More accurate, perhaps, but probably less wise than the current text. Terry Jan Reedy From basti.wiesner at gmx.net Thu Jun 18 16:02:35 2009 From: basti.wiesner at gmx.net (Sebastian Wiesner) Date: Thu, 18 Jun 2009 22:02:35 +0200 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <79v28tF1srnv7U1@mid.uni-berlin.de> <5995aa64-ca3c-4e82-a8ca-8138af59ac2e@e20g2000vbc.googlegroups.com> Message-ID: > On Jun 18, 3:49 pm, "Diez B. Roggisch" wrote: >> Hans M?ller wrote: >> > Here we have to select between wxPython and PyQt for a medium size >> > project. In this project several hundred dialogs are to be created. >> > This work will be done by a program generator which has to re-written. >> >> > The question now is which framework should we use. >> > As far as I could found is PyQt with the Qt Framework the superior >> > choice. Most articles I found (not all) results to PyQt. >> > But Qt is expensive ~ 3400? per Developer and OS. >> >> No, it's not. It is LGPL by now. >> >> You will have to pay licensing for *PyQT*. I'm not sure, but I *think* >> it's about 500?. However, it is much less than Qt used to be. >> >> Diez > > Not quite. You only have to pay for the commercial license -- you can > use PyQT as GPL as well. FWIW, PyQt4 license conditions do not enforce GPL 2 for derived work, but also permit a bunch of other free software licenses (e.g. MIT/X11, BSD, Apache, etc.) -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From kyosohma at gmail.com Thu Jun 18 16:25:05 2009 From: kyosohma at gmail.com (Mike Driscoll) Date: Thu, 18 Jun 2009 13:25:05 -0700 (PDT) Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <68d794fc-b036-4e9c-984d-0b2739acb2ff@o30g2000vbc.googlegroups.com> On Jun 18, 8:35?am, Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size project. > In this project several hundred dialogs are to be created. This work will be done by a > program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. > Since these articles are more or less old, it would be nice to hear your current opinions. > > Condensed, I found this pros / cons: > > Pros for Qt: > ? ? ? ? - best framwork, well designed "Best" in who's opinion? > ? ? ? ? - nice GUI builders > ? ? ? ? - faster execution How was the execution speed measured? > Cons: > ? ? ? ? - epensive The others have answered this... > > Pros for wxPython: > ? ? ? ? - cheap > ? ? ? ? - big community > Cons: > ? ? ? ? - more layers on top of OS > ? ? ? ? - more bugs (still valid ?) > ? ? ? ? - slower > Again, how was the slowness measured? > Can someone tell me about his experiences with one or both frameworks ? > > Thanks a lot, > > Greetings > Hans I've been using wxPython for almost three years. I can attest to there being a good solid community behind wx that is very friendly. The wxPython framework is built on top of C++ wxWidgets code, but as far as I know, pyQT is built on top of the QT framework. So I'm not sure where this idea of "more layers" for wx comes from. I haven't messed with QT to know if it is faster or not. Hopefully someone else can weigh in on that. I also don't know which has more bugs. For what I've done though, I've never had a bug to deal with. I've created a fairly involved timesheet for my company that's a little unwieldy at the moment. I also have quite a few smaller applications in wxPython. I like it quite a bit. All the widgets I've ever needed are already implemented and when they aren't there, it always seems that one of the other developers releases one. I would recommend trying to create something small in each toolkit (like a minimal calculator) and see which one makes the most sense to you. Mike From hyugaricdeau at gmail.com Thu Jun 18 16:55:45 2009 From: hyugaricdeau at gmail.com (Hyuga) Date: Thu, 18 Jun 2009 13:55:45 -0700 (PDT) Subject: Perl's @foo[3,7,1,-1] ? References: <4A342136.5010909@sweetapp.com> <4A3424F5.7010901@mrabarnett.plus.com> Message-ID: <897e4f4c-9d44-41e2-add8-fc7105625d6d@f10g2000vbf.googlegroups.com> On Jun 13, 6:22?pm, Brian Quinlan wrote: > MRAB wrote: > > Brian Quinlan wrote: > >> kj wrote: > >>> In Nick Craig-Wood > >>> writes: > > >>>> However I can't think of the last time I wanted to do this - array > >>>> elements having individual purposes are usually a sign that you should > >>>> be using a different data structure. > > >>> In the case I was working with, was a stand-in for the value returned > >>> by some_match.groups(). ?The match comes from a standard regexp > >>> defined elsewhere and that captures more groups than I need. ?(This > >>> regexp is applied to every line of a log file.) > > >>> kj > > >> The common idiom for this sort of thing is: > > >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups() > > > Alternatively: > > > ? ? val1, val2, val3 = some_match.group(4, 8, something) > > Actually, now that I think about it, naming the groups seems like it > would make this code a lot less brittle. I was about to suggest that too, but it sounds like the OP has little or no control, in this case, over the RE itself. Another thing I would suggest is using the (?:) syntax--it allows creating a syntactic group that isn't returned in the list of match groups. From arnodel at googlemail.com Thu Jun 18 16:56:57 2009 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Jun 2009 21:56:57 +0100 Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: David C. Ullrich writes: > On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > wrote: > >>On Jun 17, 3:46?pm, Paul Rubin wrote: >>> Mark Dickinson writes: >>> > It looks as though you're treating (a portion of?) the Koch curve as >>> > the graph of a function f from R -> R and claiming that f is >>> > uniformly continuous. ?But the Koch curve isn't such a graph (it >>> > fails the 'vertical line test', >>> >>> I think you treat it as a function f: R -> R**2 with the usual >>> distance metric on R**2. >> >>Right. Or rather, you treat it as the image of such a function, >>if you're being careful to distinguish the curve (a subset >>of R^2) from its parametrization (a continuous function >>R -> R**2). It's the parametrization that's uniformly >>continuous, not the curve, > > Again, it doesn't really matter, but since you use the phrase > "if you're being careful": In fact what you say is exactly > backwards - if you're being careful that subset of the plane > is _not_ a curve (it's sometimes called the "trace" of the curve". I think it is quite common to refer to call 'curve' the image of its parametrization. Anyway there is a representation theorem somewhere that I believe says for subsets of R^2 something like: A subset of R^2 is the image of a continuous function [0,1] -> R^2 iff it is compact, connected and locally connected. (I might be a bit -or a lot- wrong here, I'm not a practising mathematician) Which means that there is no need to find a parametrization of a plane curve to know that it is a curve. To add to this, the usual definition of the Koch curve is not as a function [0,1] -> R^2, and I wonder how hard it is to find such a function for it. It doesn't seem that easy at all to me - but I've never looked into fractals. -- Arnaud From jure.erznoznik at gmail.com Thu Jun 18 17:25:26 2009 From: jure.erznoznik at gmail.com (=?ISO-8859-15?Q?Jure_Erzno=B8nik?=) Date: Thu, 18 Jun 2009 14:25:26 -0700 (PDT) Subject: Newbie queue question References: Message-ID: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Thanks for the suggestions. I've been looking at the source code of threading support objects and I saw that non-blocking requests in queues use events, while blocking requests just use InterlockedExchange. So plain old put/get is much faster and I've managed to confirm this today with further testing. Sorry about the semicolon, just can't seem to shake it with my pascal & C++ background :) Currently, I've managed to get the code to this stage: class mt(threading.Thread): q = Queue.Queue() def run(self): dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1) for i1 in xrange(len(dbf1)): self.q.put(dbf1[i1]) dbf1.close() del dbf1 self.q.put(None) t = mt() t.start() time.sleep(22) rec = 1 while rec <> None: rec = t.q.get() del t Note the time.sleep(22). It takes about 22 seconds to read the DBF with the 200K records (71MB). It's entirely in cache, yes. So, If I put this sleep in there, the whole procedure finishes in 22 seconds with 100% CPU (core) usage. Almost as fast as the single threaded procedure. There is very little overhead. When I remove the sleep, the procedure finishes in 30 seconds with ~80% CPU (core) usage. So the threading overhead only happens when I actually cause thread interaction. This never happened to me before. Usually (C, Pascal) there was some threading overhead, but I could always measure it in tenths of a percent. In this case it's 50% and I'm pretty sure InterlockedExchange is the fastest thing there can be. My example currently really is a dummy one. It doesn't do much, only the reading thread is implemented, but that will change with time. Reading the data source is one task, I will proceed with calculations and with a rendering engine, both of which will be pretty CPU intensive as well. I'd like to at least make the reading part behave like I want it to before I proceed. It's clear to me I don't understand Python's threading concepts yet. I'd still appreciate further advice on what to do to make this sample work with less overhead. From tjreedy at udel.edu Thu Jun 18 17:51:01 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2009 17:51:01 -0400 Subject: Generator functions subclass generator? Message-ID: An iterator class is a class with an __iter__ method that returns self and a __next__ method that on each call returns one not-yet-returned item of the actual or virtual collection it represents and raises StopIteration when there are no more items to return. 'Generator' (3.1 name) is one of several built-in iterator classes. A generator function is a function with keyword 'yield' in its body. Its presence results in four special behaviors. 1. When the generator function is called, it returns a generator instance inst instead of executing its body code. 2. When inst.__next__ is called, the body *is* executed. 3. When any yield is reached, an object is returned (yielded), but execution of the body code is only suspended, not terminated. 4. The next call resume execution at the point of suspension. I believe any non-recursive generator functions can be written as an actual iterator class, though perhaps with more difficulty. (I suspect the same is true of recursive generators but I have never tried one.) The greater ease of writing gfs is one reason we have them. I find the first two bits of magic easier with the following simile: a generator function is like a virtual subclass of generator. In other words, def gf(params): body acts somewhat like the following hypothetical code class gf(generator): # inherited __new__ method stores the args # __iter__ is also inherited def __next__(): params = # added body 'yield' in the body of __next__ would still have special effects 3 and 4. I am planning to use this in my book. Does anyone else, particularly Python beginners, find it helpful? Terry Jan Reedy From rhodri at wildebst.demon.co.uk Thu Jun 18 18:42:55 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Jun 2009 23:42:55 +0100 Subject: ERROR: how to use a text file in a module? In-Reply-To: <645298.22108.qm@web24404.mail.ird.yahoo.com> References: <645298.22108.qm@web24404.mail.ird.yahoo.com> Message-ID: On Thu, 18 Jun 2009 19:57:46 +0100, Moni GV wrote: > Help with a "No such file ..." error. I have the next folder structure: > ---Network contains: > ??? --packets.py > ??? --Temp contains: > ?????? -test.py > > Well, within packets.py I do this: > from Temp.test import * Wildcarded imports like this aren't often a good idea. It has nothing to do with your problem, I just thought I'd mention it. > Within test.py I do this: > f = open ("topo.txt", "r") > > The error is: > No such file "topo.txt" > > However, when I execute test.py, without using neither packets.py nor > the folder structure, there is no error, because topo.txt exists. Where does topo.txt exist? In the Temp directory? I'll take a wild stab in the dark, and suggest that the way you ran your program the first time (to get the error) was approximately like this (depending on your operating system): cd Network python packets.py Am I right? And for the second time (when it worked) was: cd Network/Temp python test.py roughly what you did? Assuming that I'm right, notice that you are in different directories each time. Python will look for a file called "topo.txt" in the *current* directory (i.e. where you "cd"ed to) each time, *not* in the same directory as test.py. (If you double-clicked on the files, I think that's equivalent to the situations I outlined above. I certainly wouldn't want to trust where the current directory was in that case!) To fix this, you either need to be consistent about how you run your program and change the filename appropriately (i.e. writing 'open("Temp/topo.txt", "r")' instead), or you need to fix where 'topo.txt' is supposed to be relative to your home directory or the filesystem root and change the filename to match it (as in 'open("/usr/local/lalala/topo.txt", "r")' or 'open("~/Network/Test/topo.txt", "r")', or the equivalent on Windows). -- Rhodri James *-* Wildebeest Herder to the Masses From chris at simplistix.co.uk Thu Jun 18 18:43:09 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 23:43:09 +0100 Subject: xlutils 1.3.2 released! Message-ID: <4A3AC2FD.9090102@simplistix.co.uk> Hi All, I'm pleased to announce a new release of xlutils. This is a small collection of utilities that make use of both xlrd and xlwt to process Microsoft Excel files. The list of utilities included in this release are: xlutils.copy Tools for copying xlrd.Book objects to xlwt.Workbook objects. xlutils.display Utility functions for displaying information about xlrd-related objects in a user-friendly and safe fashion. xlutils.filter A mini framework for splitting and filtering Excel files into new Excel files. xlutils.margins Tools for finding how much of an Excel file contains useful data. xlutils.save Tools for serializing xlrd.Book objects back to Excel files. xlutils.styles Tools for working with formatting information expressed in styles. A full list of changes since the last release can be found here: http://www.simplistix.co.uk/software/python/xlutils/changes To find out more, please read here: http://www.simplistix.co.uk/software/python/xlutils In case you're not aware, xlrd and xlwt are two excellent pure-python libraries for reading and writing Excel files. They run on any platform and, likely, any implementation of Python without the need for horrific things like binding to Excel via COM and so needing a Windows machine. If you use any of xlrd, xlwt or xlutils, the following google group will be of use: http://groups.google.com.au/group/python-excel Hope some of this is of interest, I'd love to hear from anyone who ends up using it! cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From aahz at pythoncraft.com Thu Jun 18 18:43:53 2009 From: aahz at pythoncraft.com (Aahz) Date: 18 Jun 2009 15:43:53 -0700 Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <4a39d78d$0$32395$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: In article , D'Arcy J.M. Cain wrote: > >I really loved CP/M in its day but isn't it time we let go? +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From chris at simplistix.co.uk Thu Jun 18 18:51:43 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Jun 2009 23:51:43 +0100 Subject: TestFixtures 1.6.0 released! Message-ID: <4A3AC4FF.5060200@simplistix.co.uk> Hi All, I'm pleased to announce the first advertised release of TestFixtures. This is a collection of helpers and mock objects that are useful when writing unit tests or doc tests. The modules currently included are: *Comparison* This class lets you instantiate placeholders that can be used to compared expected results with actual results where objects in the actual results do not support useful comparison. The comparision can be based just on the type of the object or on a partial set of the object's attributes, both of which are particularly handy when comparing sequences returned from tested code. *compare* A replacement for assertEquals and the failUnless(x() is True) pattern. Gives more useful differences when the arguments aren't the same, particularly for sequences and long strings. *diff* This function will compare two strings and give a unified diff of their comparison. Handy as a third parameter to unittest.TestCase.assertEquals. *generator* This function will return a generator that yields the arguments it was called with when the generator is iterated over. *LogCapture* This helper allows you to capture log messages for specified loggers in doctests. *log_capture* This decorator allows you to capture log messages for specified loggers for the duration of unittest methods. *replace* This decorator enables you to replace objects such as classes and functions for the duration of a unittest method. The replacements are removed regardless of what happens during the test. *Replacer* This helper enables you to replace objects such as classes and functions from within doctests and then restore the originals once testing is completed. *should_raise* This is a better version of assertRaises that lets you check the exception raised is not only of the correct type but also has the correct parameters. *TempDirectory* This helper will create a temporary directory for you using mkdtemp and provides a handy class method for cleaning all of these up. *tempdir* This decorator will create a temporary directory for the duration of the unit test and clear it up no matter the outcome of the test. *test_date* This is a handy class factory that returns datetime.date replacements that have a today method that gives repeatable, specifiable, testable dates. *test_datetime* This is a handy class factory that returns datetime.datetime replacements that have a now method that gives repeatable, specifiable, testable datetimes. *test_time* This is a handy replacement for time.time that gives repeatable, specifiable, testable times. *wrap* This is a generic decorator for wrapping method and function calls with a try-finally and having code executed before the try and as part of the finally. To find out more, please read here: http://pypi.python.org/pypi/testfixtures cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From scott.pigman at gmail.com Thu Jun 18 19:19:27 2009 From: scott.pigman at gmail.com (Scott) Date: Thu, 18 Jun 2009 16:19:27 -0700 (PDT) Subject: Allocating memory to pass back via ctypes callback function Message-ID: Hi, I'm using python ctypes to interact with the C API of a commercial-off- the-shelf application. I need to implement callback functions which will be called by the application. The callbacks take as a parameter a char** parameter for which the callback function will allocate memory and set the value of the underlying char*. The hitch is that I need to allocate the memory with the vendor's own memory allocation function because the caller will free the memory with the corresponding vendor free function. The problem is that I can't quite work out how to set the address of the incoming POINTER(c_char_p) parameter to the location provided by the memory allocation function. def my_callback(pointer_c_char_p): py_string = get_string_to_pass_back() address = VENDOR_malloc( len(py_string)*sizeof(c_char) ) # ???? how to set pointer_c_char_p.contents to memory location address? # ???? would this be the correct next thing to do? pointer_c_char_p.contents = c_char_p(py_string) # ???? return 0 Thanks, Scott From notontheweb at noisp.com Thu Jun 18 19:39:59 2009 From: notontheweb at noisp.com (Jive Dadson) Date: Thu, 18 Jun 2009 16:39:59 -0700 Subject: AT&T Usenet Netnews Service Shutting Down In-Reply-To: <1245249220_11395@newsgroups.bellsouth.net> References: <1245249220_11395@newsgroups.bellsouth.net> Message-ID: newsmaster at bellsouth.net wrote: > Please note that on or around July 15, 2009, AT&T will no longer be > offering access to the Usenet Netnews service. If you wish to continue > reading Usenet newsgroups, access is available through third-party vendors. > > http://support.att.net/usenet > > > Distribution: AT&T SouthEast Newsgroups Servers Ah ha. I think I may have figured out how to work around it. I need to use my EasyNews server to post the message, (with "SSL"), rather than the ATT server. I think. Maybe. Does anyone know if it's possible to have Thunderbird use different outgoing servers for different accounts? I know this is not a Python question. Please forgive me. The main reason I'm sending these messages is just to see if they go through. From dickinsm at gmail.com Thu Jun 18 20:01:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 18 Jun 2009 17:01:12 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 18, 7:26?pm, David C. Ullrich wrote: > On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > >Right. ?Or rather, you treat it as the image of such a function, > >if you're being careful to distinguish the curve (a subset > >of R^2) from its parametrization (a continuous function > >R -> R**2). ?It's the parametrization that's uniformly > >continuous, not the curve, > > Again, it doesn't really matter, but since you use the phrase > "if you're being careful": In fact what you say is exactly > backwards - if you're being careful that subset of the plane > is _not_ a curve (it's sometimes called the "trace" of the curve". Darn. So I've been getting it wrong all this time. Oh well, at least I'm not alone: "De?nition 1. A simple closed curve J, also called a Jordan curve, is the image of a continuous one-to-one function from R/Z to R2. [...]" - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. "We say that Gamma is a curve if it is the image in the plane or in space of an interval [a, b] of real numbers of a continuous function gamma." - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). Perhaps your definition of curve isn't as universal or 'official' as you seem to think it is? Mark From davea at ieee.org Thu Jun 18 20:11:33 2009 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Jun 2009 20:11:33 -0400 Subject: Exotic Logics In-Reply-To: <4A3A6C1B.70208@gmail.com> References: <4A3A6C1B.70208@gmail.com> Message-ID: <4A3AD7B5.6010202@ieee.org> Michael Torrie wrote: > William Clifford wrote: > >> I've read one can do all of the 16 binary operations with clever uses >> of NAND or NOR. >> > > That is correct. In fact semiconductor logic is done using these two > principle gates. See http://en.wikipedia.org/wiki/NAND_logic . Quite > interesting really. > > Not "is done" but "could be" done. As your reference correctly points out, "However, contrary to popular belief, modern integrated circuits are not constructed exclusively from a single type of gate" From usenet at janc.invalid Thu Jun 18 20:11:55 2009 From: usenet at janc.invalid (JanC) Date: Fri, 19 Jun 2009 00:11:55 +0000 (UTC) Subject: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization? References: <6fa3e727-8881-4acd-ac52-9b1f55af1cbc@h11g2000yqb.googlegroups.com> <79rgbkF1rcncsU1@mid.uni-berlin.de> Message-ID: Hendrik van Rooyen wrote: > It is my opinion that it is not possible to make a useful machine, > virtual or real, which executes instructions sequentially, if the > instruction set does not contain a conditional jump of some sort. > > I have tried doing it using conditional calls, and it fails on > the equivalent of the first if ..., elif ... you try to write. I'm 99.99% sure you can implement that by using a decision subroutine that returns subroutine pointers (and maybe parameter pointers), but it certainly won't be efficient on current CPU designs... -- JanC From pavlovevidence at gmail.com Thu Jun 18 20:26:43 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 18 Jun 2009 17:26:43 -0700 (PDT) Subject: python tutorial References: <4a3709d3$0$32336$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2f6271b1-5ffa-4cec-81f8-0276ad647026@p5g2000pre.googlegroups.com> <4a398bf2$0$32342$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <37219ea2-b5ce-4e43-9f0a-0e1c1b7fe1d6@t11g2000vbc.googlegroups.com> On Jun 17, 5:36?pm, "steve" wrote: > >"Carl Banks" wrote in message > >news:2f6271b1-5ffa-4cec-81f8->>0276ad647__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__ at p5g2000pre.googlegroups.com... > >On Jun 15, 7:56 pm, "steve" wrote: > >> I was just looking at the python tutorial, and I noticed these lines: > > >>http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-... > > >> "Windows makes a distinction between text and binary files; > >> "the end-of-line characters in text files are automatically altered > >> "slightly when data is read or written. > > >> I don't see any obvious way to at docs.python.org to get that corrected: > >> Is > >> there some standard procedure? > > >What's wrong with it? > > >Carl Banks > > 1) Windows does not make a distinction between text and binary files. > > 2) end-of-line characters in text files are not automatically altered by > Windows. I agree with Robert Kern, it isn't necessary to distinguish between Windows OS and a particular Windows runtime library for the purposes of a tutorial. Carl Banks From http Thu Jun 18 20:40:55 2009 From: http (Paul Rubin) Date: 18 Jun 2009 17:40:55 -0700 Subject: Measuring Fractal Dimension ? References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> Message-ID: <7xmy85ys14.fsf@ruckus.brouhaha.com> David C. Ullrich writes: > >> obviously converges to f, but not uniformly. On a closed interval, > >> any continuous function is uniformly continuous. > > > >Isn't (-?, ?) closed? > > What is your version of the definition of "closed"? I think the whole line is closed, but I hadn't realized anyone considered the whole line to be an "interval". Apparently they do. So that the proper statement specifies compactness (= closed and bounded) rather than just "closed". From matt at tplus1.com Thu Jun 18 20:56:18 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 00:56:18 GMT Subject: Is this pylint error message valid or silly? Message-ID: Here's the code that I'm feeding to pylint: $ cat f.py from datetime import datetime def f(c="today"): if c == "today": c = datetime.today() return c.date() And here's what pylint says: $ pylint -e f.py No config file found, using default configuration ************* Module f E: 10:f: Instance of 'str' has no 'date' member (but some types could not be inferred) Is this a valid error message? Is the code above bad? If so, what is the right way? I changed from using a string as the default to None, and then pylint didn't mind: $ cat f.py from datetime import datetime def f(c=None): if c is None: c = datetime.today() return c.date() $ pylint -e f.py No config file found, using default configuration I don't see any difference between using a string vs None. Both are immutable. I find the string much more informative, since I can write out what I want. Looking for comments. Matt From karthik301176 at gmail.com Thu Jun 18 21:06:25 2009 From: karthik301176 at gmail.com (Karthik) Date: Thu, 18 Jun 2009 18:06:25 -0700 (PDT) Subject: Packing a ctypes struct containing bitfields. References: Message-ID: On Jun 18, 6:29?pm, Nick Craig-Wood wrote: > Karthik wrote: > > ?Hello Everybody, > > > ?I'm trying to create a packed structure in ctypes (with one 64-bit > > ?element that is bitfielded to 48 bits), > > ?unsuccessfully: > > > =================================== > > ?from ctypes import * > > > ?class foo (Structure): > > ? ? ?_pack_ = 1 > > ? ? ?_fields_ = [ > > ? ? ? ? ?("bar", ? ?c_ulonglong, 48), > > ? ? ?] > > > ?print("sizeof(foo) = %d" % sizeof(foo)) > > =================================== > > ?I'm expecting that this should print 6 - however, on my box, it prints > > ?8. > > > ?The following piece of C code, when compiled and run, prints 6, which > > ?is correct. > > =================================== > > ?struct foo { > > ? ? ?unsigned long long bar: 48; > > ?}; > > > ?printf("sizeof(foo) = %d", sizeof(foo)); > > =================================== > > > ?So... what am I doing wrong? > > I compiled and ran the above with gcc on my linux box - it prints 8 > unless I add __attribute__((__packed__)) to the struct. > > I'm not sure that using bitfields like that is a portable at all > between compilers let alone architectures. > > I'd probably do > > from ctypes import * > > class foo (Structure): > ? ? _pack_ = 1 > ? ? _fields_ = [ > ? ? ? ? ("bar0", ? ?c_uint32), > ? ? ? ? ("bar1", ? ?c_uint16), > ? ? ] > ? ? def set_bar(self, bar): > ? ? ? ? self.bar0 = bar & 0xFFFFFFFF > ? ? ? ? self.bar1 = (bar >> 32) & 0xFFFF > ? ? def get_bar(self): > ? ? ? ? return (self.bar1 << 32) + self.bar0 > ? ? bar = property(get_bar, set_bar) > > print "sizeof(foo) = %d" % sizeof(foo) > f = foo() > print f.bar > f.bar = 123456789012345 > print f.bar > > Which prints > > sizeof(foo) = 6 > 0 > 123456789012345 > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick Oops, sorry about the missing __attribute__((packed)) - that was an error of omission. Thank you, Nick :) I'm looking at some C code that's using bitfields in structs, and I'm writing python code that "imports" these structs and messes around with them - unfortunately, I'm not at liberty to change the C code to not use bitfields. Your solution works fine, so that's what I'm going to use. Thanks, Karthik. From fabiofz at gmail.com Thu Jun 18 21:32:55 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 18 Jun 2009 22:32:55 -0300 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> Message-ID: > yes, the same problem even on an empty program. every file has the same > problem. > > for example, if I new a file and input the following: > import os > os. > after I input '.', it will pop up the window, and i can select the function > of os module or continue input. but after that, no action can be taken for > this file unless I switch to other files and then switch back. If it's in pydev, there's probably some problem in your interpreter configuration (when you do os. it'll spawn a shell to gather the completions -- but that should be pretty quick unless you have some firewall that's preventing the communication or the spawn didn't go well -- check your error log to see if you have any errors... In linux I've seen some problems when connecting to 127.0.0.1 while having ipv6 enabled or in a network card misconfiguration that could cause problems too). Cheers, Fabio > > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing wrote: >> >> Do you experience the same problem even on an empty program file or is it >> limited to just one file? >> >> -Tyler >> >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: >>> >>> On Jun 18, 10:45?am, "Wei, James" wrote: >>> > When I am editing python program with SPE, I found that SPE will >>> > freeze when it is doing auto-completion. The behavior is very strange >>> > that I can not edit the file again. If I switch to another file and >>> > then switch back, I can edit it again. >>> > >>> > So I switch to eclipse+pydev, but I found the same thing happen. So I >>> > think it is not the problem of SPE or eclipse or pydev. >>> > >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it will >>> > not freeze any longer. >>> > >>> > Anybody can give me some hints? >>> > >>> > I am using Ubuntu 8.10 and updated to latest. All packages is >>> > installed through package manager. >>> >>> the only thing I googled related with it is >>> >>> >>> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >>> >>> but I think they are different. >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > -- > Best wishes to you. > > Yours sincerely > > Xiaohai Wei > wistoch at ustc.edu > > -- > http://mail.python.org/mailman/listinfo/python-list > > From sjmachin at lexicon.net Thu Jun 18 22:08:57 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Jun 2009 02:08:57 +0000 (UTC) Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: Mike Driscoll gmail.com> writes: > On Jun 18, 10:38?am, Chris Withers wrote: > > working with Excel files in Python using the pure-python libraries xlrd, > > xlwt and xlutils. > As I recall, these utilities don't allow the programmer to access > Excel's formulas. Is that still an issue? xlwt supports creating XLS files with a large chunk of the Excel formula functionality. Support in xlrd for decompiling formulas exists only in a crude form sufficient to support debugging of xlwt formula enhancements. Whether this is an issue or not and for whom is difficult to detect -- certainly there have been no demands for refund of purchase price :-). Some recent enhancements have been initiated as patches supplied by programmers personally. Patches (preferably pre-discussed) are welcome, as would be any advice on how to get the big end of town to send patent lawyers[1], gun coders and money. [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ From notontheweb at noisp.com Thu Jun 18 22:23:52 2009 From: notontheweb at noisp.com (Jive Dadson) Date: Thu, 18 Jun 2009 19:23:52 -0700 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <_EC_l.156072$fo6.2168@en-nntp-09.dc1.easynews.com> Qt has far better documentation, and it has Qt Designer. The documentation is a big deal. I wrote a little project in wxPython, and I spent 90% of my time just trying to find the names of member functions and then to figure out what they do. Why not use Qt C++? I like Python a lot. Heck, I even embedded it in a robot controller that might have wrangled some of the wafers that went into your computer chips. But I think I would go with C++ for a medium size GUI project. Hans M?ller wrote: > Here we have to select between wxPython and PyQt for a medium size project. > In this project several hundred dialogs are to be created. This work > will be done by a > program generator which has to re-written. > > The question now is which framework should we use. > As far as I could found is PyQt with the Qt Framework the superior choice. > Most articles I found (not all) results to PyQt. > But Qt is expensive ~ 3400? per Developer and OS. > Since these articles are more or less old, it would be nice to hear your > current opinions. > > Condensed, I found this pros / cons: > > Pros for Qt: > - best framwork, well designed > - nice GUI builders > - faster execution > Cons: > - epensive > > Pros for wxPython: > - cheap > - big community > Cons: > - more layers on top of OS > - more bugs (still valid ?) > - slower > > > > > Can someone tell me about his experiences with one or both frameworks ? > > Thanks a lot, > > Greetings > Hans From ethan at stoneleaf.us Thu Jun 18 22:37:36 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Jun 2009 19:37:36 -0700 Subject: fastest native python database? In-Reply-To: <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> Message-ID: <4A3AF9F0.7000009@stoneleaf.us> Pierre Quentel wrote: > On 18 juin, 05:28, per wrote: > >>hi all, >> >>i'm looking for a native python package to run a very simple data >>base. i was originally using cpickle with dictionaries for my problem, >>but i was making dictionaries out of very large text files (around >>1000MB in size) and pickling was simply too slow. > > buzhug syntax doesn't use SQL statements, but a more Pythonic syntax : > > from buzhug import Base > db = Base('foo').create(('name',str),('age',int)) > db.insert('john',33) > # simple queries > print db(name='john') > # complex queries > print [ rec.name for rec in db if age > 30 ] > # update > rec.update(age=34) > > I made a few speed comparisons with Gadfly, KirbyBase (another pure- > Python DB, not maintained anymore) and SQLite. You can find the > results on the buzhug home page : http://buzhug.sourceforge.net > > The conclusion is that buzhug is much faster than the other pure- > Python db engines, and (only) 3 times slower than SQLite > > - Pierre Howdy, Pierre! I have also written a pure Python implementation of a database, one that uses dBase III or VFP 6 .dbf files. Any chance you could throw it into the mix to see how quickly (or slowly!) it runs? The code to run the same steps are (after an import dbf): #insert test table = dbf.Table('/tmp/tmptable', 'a N(6.0), b N(6.0), c C(100)') # if recs is list of tuples for rec in recs: table.append(rec) # elif recs is list of lists #for a, b, c in recs: # current = table.append() # current.a = a # current.b = b # current.c = c #select1 test for i in range(100): nb = len(table) if nb: avg = sum([r.b for r in table])/nb #select2 test for num_string in num_strings: recs = table.find({'c':'%s'%num_string}, contained=True) nb = len(recs) if nb: avg = sum([r.b for r in recs])/nb #delete1 test for rec in table: if 'fifty' in rec.c: rec.delete_record() # to purge the records would then require a table.pack() #delete2 test for rec in table: if 10 < rec.a < 20000: rec.delete_record() # again, permanent deletion requires a table.pack() #update1 test table.order('a') for i in range(100): # update description says 1000, update code is 100 records = table.query(python='10*%d <= a < 10*%d' %(10*i,10*(i+1))) for rec in records: rec.b *= 2 #update2 test records = table.query(python="0 <= a < 1000") for rec in records: rec.c = new_c[rec.a] Thanks, I hope! :) ~Ethan~ http://groups.google.com/group/python-dbase -------------- next part -------------- A non-text attachment was scrubbed... Name: python-dbf.zip Type: application/x-zip-compressed Size: 23032 bytes Desc: not available URL: From trinioler at gmail.com Thu Jun 18 22:40:22 2009 From: trinioler at gmail.com (Tyler Laing) Date: Thu, 18 Jun 2009 19:40:22 -0700 Subject: Calling subprocess with arguments Message-ID: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> I've been trying any variation I can think of to do this properly, but here's my problem: I want to execute this command string: vlc -I rc This allows vlc to be controlled via a remote interface instead of the normal gui interface. Now, say, I try this from subprocess: >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) But I don't get the remote interface. I get the normal gui interface. So how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', 'rc'] with executable set to 'vlc'. I've had shell=True, I've had shell=False. I've tried all these combinations. What am I doing wrong? -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From rylesny at gmail.com Thu Jun 18 23:02:43 2009 From: rylesny at gmail.com (ryles) Date: Thu, 18 Jun 2009 20:02:43 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <400a9a27-89df-4caa-826c-fb23e2b68435@f16g2000vbf.googlegroups.com> > Does the generator expression have its own little namespace or so ? Yes, generators create a new scope: http://docs.python.org/reference/expressions.html#grammar-token-generator_expression From rylesny at gmail.com Thu Jun 18 23:09:25 2009 From: rylesny at gmail.com (ryles) Date: Thu, 18 Jun 2009 20:09:25 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: On Jun 18, 9:56?am, nn wrote: > On Jun 18, 8:38?am, guthrie wrote: > > > > > On Jun 17, 6:38?pm, Steven Samuel Cole > > wrote: > > > > Still don't really understand why my initial code didn't work, though... > > > Your code certainly looks reasonable, and looks to me like it "should" > > work. The comment of partial namespace is interesting, but > > unconvincing (to me) - but I am not a Python expert! It would > > certainly seem that within that code block it is in the local > > namespace, not removed from that scope to be in another. > > > Seems that it should either be a bug, or else is a design error in the > > language! > > > Just as in the above noted "WTF" - non-intuitive language constructs > > that surprise users are poor design. > > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > > >>> class x: > > ... ? ? lst=[2] > ... ? ? gen=[lst.index(e) for e in lst] > ... > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 3, in x > ? File "", line 3, in > NameError: global name 'lst' is not defined > > > > I believe it works in 2.x because unlike generator expressions, list comprehensions do not create a new scope. However, in 3.0 list comprehensions are actually treated as list(). http://docs.python.org/reference/expressions.html http://www.python.org/dev/peps/pep-0289 From philip at semanchuk.com Thu Jun 18 23:19:09 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Jun 2009 23:19:09 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught Message-ID: Hi all, I need help understanding how Python deals with Ctrl-C. A user has reported a bug in my posix_ipc module. When a Python app is waiting to acquire an IPC semaphore and the user hits Ctrl-C, my code should return a custom error indicating that the semaphore wait was interrupted by a signal. However, the caller never sees the error I set. Instead they get a KeyboardInterrupt that refuses to be caught by try/except. Here's a sample program that demonstrates the problem when run from the command line: # ----------------------------------- import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) try: sem.acquire() # User hits Ctrl + C while this is waiting except: print "********* I caught it!" sem.close() sem.unlink() # ----------------------------------- I expected that code to raise a posix_ipc.Error with the text, "The wait was interrupted by a signal" which would then be trapped by the except statement which would print the "I caught it!" message. Instead a KeyboardInterrupt error is propagated up to the interpreter and the process is killed as if the try/except wasn't there at all. I have verified that the C function sem_wait() returns -1 (failure), that errno is set to EINTR and that my detects that properly. So far, so good. PyErr_Occurred() returns NULL at that point. So my code calls PyErr_SetString() to set a custom error for the caller and returns NULL. It's apparently at some point after that that the KeyboardInterrupt error is being set. If I substitute my sysv_ipc module for posix_ipc (very similar to posix_ipc but uses Sys V semaphores instead of POSIX), I get the same behavior. I see this w/Python 2.5 under OS X and also w/Python 2.5 under Ubuntu 8.0.4. If anyone wants to look at my C code, the relevant case statement is on line 555 of posix_ipc_module.c. http://semanchuk.com/philip/posix_ipc/ http://semanchuk.com/philip/sysv_ipc/ Any suggestions would be appreciated. Thanks Philip From wistoch at gmail.com Thu Jun 18 23:22:36 2009 From: wistoch at gmail.com (Wei, Xiaohai) Date: Fri, 19 Jun 2009 11:22:36 +0800 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> Message-ID: <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> Thanks for your reply. where is the error log? I can not find it at /var/log I have a virtual network card to bridge kvm virtual machine. will it cause problem? as you said configuration of interpretor, how should I configure the interpretor? Thanks James On Fri, Jun 19, 2009 at 9:32 AM, Fabio Zadrozny wrote: > > yes, the same problem even on an empty program. every file has the same > > problem. > > > > for example, if I new a file and input the following: > > import os > > os. > > after I input '.', it will pop up the window, and i can select the > function > > of os module or continue input. but after that, no action can be taken > for > > this file unless I switch to other files and then switch back. > > If it's in pydev, there's probably some problem in your interpreter > configuration (when you do os. it'll spawn a shell to gather the > completions -- but that should be pretty quick unless you have some > firewall that's preventing the communication or the spawn didn't go > well -- check your error log to see if you have any errors... In linux > I've seen some problems when connecting to 127.0.0.1 while having ipv6 > enabled or in a network card misconfiguration that could cause > problems too). > > Cheers, > > Fabio > > > > > > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing > wrote: > >> > >> Do you experience the same problem even on an empty program file or is > it > >> limited to just one file? > >> > >> -Tyler > >> > >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: > >>> > >>> On Jun 18, 10:45 am, "Wei, James" wrote: > >>> > When I am editing python program with SPE, I found that SPE will > >>> > freeze when it is doing auto-completion. The behavior is very strange > >>> > that I can not edit the file again. If I switch to another file and > >>> > then switch back, I can edit it again. > >>> > > >>> > So I switch to eclipse+pydev, but I found the same thing happen. So I > >>> > think it is not the problem of SPE or eclipse or pydev. > >>> > > >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it > will > >>> > not freeze any longer. > >>> > > >>> > Anybody can give me some hints? > >>> > > >>> > I am using Ubuntu 8.10 and updated to latest. All packages is > >>> > installed through package manager. > >>> > >>> the only thing I googled related with it is > >>> > >>> > >>> > http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html > >>> > >>> but I think they are different. > >>> > >>> -- > >>> http://mail.python.org/mailman/listinfo/python-list > >> > >> > >> > >> -- > >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > > > > > -- > > Best wishes to you. > > > > Yours sincerely > > > > Xiaohai Wei > > wistoch at ustc.edu > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- Best wishes to you. Yours sincerely Xiaohai Wei wistoch at ustc.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Fri Jun 19 00:20:55 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 19 Jun 2009 16:20:55 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <7a0hv6F1sm9rbU1@mid.individual.net> ssc wrote: > class SignupForm(Form): > > titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] > title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in > titles) > > Does the generator expression have its own little namespace or so ? Yes. The generator expression is a function, with its own local namespace. Since the class scope is not visible from inside functions declared within it, the behaviour you're seeing results. -- Greg From greg at cosc.canterbury.ac.nz Fri Jun 19 00:28:10 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 19 Jun 2009 16:28:10 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: <7a0icpF1smf41U1@mid.individual.net> nn wrote: > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > >>>>class x: > > ... lst=[2] > ... gen=[lst.index(e) for e in lst] In 3.x it was decided that the loop variables in a list comprehension should be local, and not leak into the surrounding scope. This was implemented by making the list comprehension into a nested function. Unfortunately this leads to the same unintuitive behaviour as a genexp when used in a class scope. -- Greg From ben+python at benfinney.id.au Fri Jun 19 00:33:25 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Jun 2009 14:33:25 +1000 Subject: Is this pylint error message valid or silly? References: Message-ID: <87eitg267e.fsf@benfinney.id.au> Matthew Wilson writes: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): > > if c == "today": > c = datetime.today() > > return c.date() > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration > ************* Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types could > not be inferred) > > Is this a valid error message? Yes. Mentally run through your code and ask ?what happens if the condition for the ?if? statement is false?? > Is the code above bad? If so, what is the right way? Yes, it's bad: * The function name ?f? is completely unhelpful. Consider a reader of the function who has no access to the inside of your head: Your function should be named, preferably, as a verb phrase, to say what the function *does* when it is called. * The parameter name ?c? is completely undescriptive. Again, consider a reader ignorant of your thinking: You should name parameters so they help the reader know what the parameter is supposed to be and how it will be interpreted. * You're re-binding the parameter name ?c? to something different within the function: it starts out bound to the input string, but by the time the function ends you're expecting it to be bound to a datetime object. Instead, you should be binding a *different* name to the datetime object you create inside the function, and using that for the return statement. -- \ ?Read not to contradict and confute, nor to believe and take | `\ for granted ? but to weigh and consider.? ?Francis Bacon | _o__) | Ben Finney From ldo at geek-central.gen.new_zealand Fri Jun 19 01:51:52 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:51:52 +1200 Subject: Packing a ctypes struct containing bitfields. References: Message-ID: In message , Karthik wrote: > from ctypes import * Don't do that. From ldo at geek-central.gen.new_zealand Fri Jun 19 01:53:40 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:53:40 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> Message-ID: In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: > On Thu, 18 Jun 2009 10:33:49 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: >> >>> On Wed, 17 Jun 2009 23:04:37 +1200 >>> Lawrence D'Oliveiro wrote: >>> >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev >>>> wrote: >>>> >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 >>>>> Lawrence D'Oliveiro wrote: >>>>> >>>>>>> Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>> arranging them like /path/f/9/e/95ea4926a4 ? >>>>>>> >>>>>>> That way, you won't have to deal with many-files-in-path problem >>>>>>> ... >>>>>> >>>>>> Why is that a problem? >>>>> >>>>> So you can os.listdir them? >>>> >>>> Why should you have a problem os.listdir'ing lots of files? >>> >>> I shouldn't, and I don't ;) >> >> Then why did you suggest that there was a problem being able to >> os.listdir them? > > I didn't, OP did ... Then why did you reply to my question "Why is that a problem?" with "So that you can os.listdir them?", if you didn't think there was a problem (see above)? From ldo at geek-central.gen.new_zealand Fri Jun 19 01:54:31 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:54:31 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> Message-ID: In message , Ethan Furman wrote: > Lawrence D'Oliveiro wrote: >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev wrote: >> >> >>>On Wed, 17 Jun 2009 23:04:37 +1200 >>>Lawrence D'Oliveiro wrote: >>> >>> >>>>In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev wrote: >>>> >>>> >>>>>On Wed, 17 Jun 2009 17:53:33 +1200 >>>>>Lawrence D'Oliveiro wrote: >>>>> >>>>> >>>>>>>Why not use hex representation of md5/sha1-hashed id as a path, >>>>>>>arranging them like /path/f/9/e/95ea4926a4 ? >>>>>>> >>>>>>>That way, you won't have to deal with many-files-in-path problem ... >>>>>> >>>>>>Why is that a problem? >>>>> >>>>>So you can os.listdir them? >>>> >>>>Why should you have a problem os.listdir'ing lots of files? >>> >>>I shouldn't, and I don't ;) >> >> Then why did you suggest that there was a problem being able to >> os.listdir them? > > He didn't ... He replied to my question "Why is that a problem?" with "So you can os.listdir them?". Why reply with an explanation of why it's a problem if you don't think it's a problem? From ldo at geek-central.gen.new_zealand Fri Jun 19 01:55:18 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 19 Jun 2009 17:55:18 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan wrote: > Yeah, it might be possible to just mv the file from outside, but not > being able to enter a directory just because you've got too many files > in it is kind of silly. Sounds like a problem with your file/directory-manipulation tools. From rajat.dudeja at aeroflex.com Fri Jun 19 02:42:16 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Fri, 19 Jun 2009 02:42:16 -0400 Subject: How to check if file is open on Windows XP? Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> Hi, I'm looking for a fascility that can check if the file is open on Windows XP and if the file is open (say a notepad file is open), I want to close that file (i.e the notepad application) I found that there are no such methods available in OS modules. Is using Win32 API is the only solution? Pleae suggest. Thanks, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jun 19 02:46:14 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 02:46:14 -0400 Subject: AT&T Usenet Netnews Service Shutting Down In-Reply-To: References: <1245249220_11395@newsgroups.bellsouth.net> Message-ID: Jive Dadson wrote: > newsmaster at bellsouth.net wrote: >> Please note that on or around July 15, 2009, AT&T will no longer be >> offering access to the Usenet Netnews service. If you wish to continue >> reading Usenet newsgroups, access is available through third-party >> vendors. news.gmane.org (free) mirrors python-list as gmane.comp.python.general I prefer it to c.l.p because python-list filters out most spam. > Ah ha. I think I may have figured out how to work around it. I need to > use my EasyNews server to post the message, (with "SSL"), rather than > the ATT server. I think. Maybe. Does anyone know if it's possible to > have Thunderbird use different outgoing servers for different accounts? Tbird recommends not doing so (no idea why), so it *must* be possible ;-). Looks pretty simple. From tjreedy at udel.edu Fri Jun 19 02:55:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 02:55:52 -0400 Subject: Is this pylint error message valid or silly? In-Reply-To: References: Message-ID: Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): pylint infers that you intend users to pass a string. Human would guess the same at this point. > if c == "today": > c = datetime.today() Now I guess that you actually intend c to be passed as a datetime object. You only used the string as a type annotation, not as a real default value. Something like 'record_date = None' is better. > return c.date() and here you ask for the input's date, which strings do not have. > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration > ************* Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types could > not be inferred) > > Is this a valid error message? Is the code above bad? If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > > $ cat f.py > from datetime import datetime > > def f(c=None): > > if c is None: > c = datetime.today() > > return c.date() > > $ pylint -e f.py > No config file found, using default configuration > > I don't see any difference between using a string vs None. Both are > immutable. I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt From mail at anjanesh.net Fri Jun 19 03:22:16 2009 From: mail at anjanesh.net (Anjanesh Lekshminarayanan) Date: Fri, 19 Jun 2009 12:52:16 +0530 Subject: Integer Division Message-ID: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> >>> a = 1 >>> b = 25 >>> a / b 0 >>> float(a) / b 0.040000000000000001 >>> >>> from __future__ import division >>> a = 1 >>> b = 25 >>> a / b 0.040000000000000001 >>> In what simple way can I get just 0.04 ? -- Anjanesh Lekshmnarayanan From clp2 at rebertia.com Fri Jun 19 03:27:00 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 00:27:00 -0700 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: <50697b2c0906190027p5eea1343r5d9619948514b3fd@mail.gmail.com> On Fri, Jun 19, 2009 at 12:22 AM, Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 >>>> > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 >>>> > > In what simple way can I get just 0.04 ? Note that what you are shown is the repr() of the float rather than the str() of the float. The repr() value is what the number truly is in binary, but str() applies more sensible rounding. Example (remember that print() does an implicit str()): >>> from __future__ import division >>> print(1/25) 0.04 >>> repr(1/25) 0.040000000000000001 >>> Alternatively, you can use the decimal arithmetic library: >>> from decimal import Decimal >>> Decimal(1)/Decimal(25) Decimal('0.04') >>> Cheers, Chris -- http://blog.rebertia.com From jure.erznoznik at gmail.com Fri Jun 19 03:29:11 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 00:29:11 -0700 (PDT) Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Message-ID: I've done some further testing on the subject: I also added some calculations in the main loop to see what effect they would have on speed. Of course, I also added the same calculations to the single threaded functions. They were simple summary functions, like average, sum, etc. Almost no interaction with the buffers was added, just retrieval of a single field's value. Single threaded, the calculations added another 4.3 seconds to the processing time (~18%) MultiThreaded, they added 1.8 seconds. CPU usage remained below 100% of one core at all times. Made me check the process affinity. I know the main thread uses way less CPU than DBF reading thread (4 secs vs 22 secs). So I think adding these calculations should have but a minimal impact on threaded execution time. Instead, the execution time increases!!! I'm beginning to think that Python's memory management / functions introduce quite a significant overhead for threading. I think I'll just write this program in one of the compilers today to verify just how stupid I've become. From mk.fraggod at gmail.com Fri Jun 19 03:40:15 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 13:40:15 +0600 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> Message-ID: <20090619134015.349ba199@malediction> On Fri, 19 Jun 2009 17:53:40 +1200 Lawrence D'Oliveiro wrote: > In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: > > > On Thu, 18 Jun 2009 10:33:49 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev > >> wrote: > >> > >>> On Wed, 17 Jun 2009 23:04:37 +1200 > >>> Lawrence D'Oliveiro wrote: > >>> > >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev > >>>> wrote: > >>>> > >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 > >>>>> Lawrence D'Oliveiro wrote: > >>>>> > >>>>>>> Why not use hex representation of md5/sha1-hashed id as a > >>>>>>> path, arranging them like /path/f/9/e/95ea4926a4 ? > >>>>>>> > >>>>>>> That way, you won't have to deal with many-files-in-path > >>>>>>> problem ... > >>>>>> > >>>>>> Why is that a problem? > >>>>> > >>>>> So you can os.listdir them? > >>>> > >>>> Why should you have a problem os.listdir'ing lots of files? > >>> > >>> I shouldn't, and I don't ;) > >> > >> Then why did you suggest that there was a problem being able to > >> os.listdir them? > > > > I didn't, OP did ... > > Then why did you reply to my question "Why is that a problem?" with > "So that you can os.listdir them?", if you didn't think there was a > problem (see above)? Why do you think that if I didn't suggest there is a problem, I think there is no problem? I do think there might be such a problem and even I may have to face it someday. So, out of sheer curiosity how more rediculous this topic can be I'll try to rephrase and extend what I wrote in the first place: Why would you want to listdir them? I can imagine at least one simple scenario: you had some nasty crash and you want to check that every file has corresponding, valid db record. What's the problem with listdir if there's 10^x of them? Well, imagine that db record also holds file modification time (say, the files are some kind of cache), so not only you need to compare listdir results with db, but also do os.stat on every file and some filesystems will do it very slowly with so many of them in one place. Now, I think I made this point in the first answer, no? Of course you can make it more rediculous by your I-can-talk-away-any-problem-I-can't-see-or-solve approach by asking "why would you want to use such filesystems?", "why do you have to use FreeBSD?", "why do you have to work for such employer?", "why do you have to eat?" etc, but you know, sometimes it's easier and better for the project/work just to solve it, than talk everyone else away from it just because you don't like otherwise acceptable solution. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From chris at simplistix.co.uk Fri Jun 19 03:56:02 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 08:56:02 +0100 Subject: MailingLogger 3.3.0 Released! Message-ID: <4A3B4492.9030003@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with an X-Mailer header for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested In addition, extra support is provided for configuring the handlers when using ZConfig, Zope 2 or Zope 3. The latest releases of ZConfig, in particular, provide a great way to configure the python logging framework without having to resort to the appalling .ini-based configuration stuff: >>> from ZConfig import configureLoggers >>> configureLoggers(''' ... ... level INFO ... ... PATH STDOUT ... format %(levelname)s %(name)s %(message)s ... ... ... ''') This release of MailingLogger adds the ability to use %(levelname)s in subject-line formatting for SummarisingLoggers to include the highest level logged. For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From dickinsm at gmail.com Fri Jun 19 04:12:26 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 01:12:26 -0700 (PDT) Subject: Integer Division References: Message-ID: On Jun 19, 8:22?am, Anjanesh Lekshminarayanan wrote: > >>> a = 1 > >>> b = 25 > >>> a / b > 0 > >>> float(a) / b > > 0.040000000000000001 Python typically stores floats in binary, not decimal. The value 0.04 isn't exactly representable in binary, so the division float(1)/25 can't produce 0.04: what you get instead is a very good approximation to 0.04. That's why you're seeing what you're seeing above. Note that 0.0400...001 is *also* just an approximation to the actual value stored, but it's a better approximation than 0.04. The exact value stored is (probably, assuming your machine is typical): 0.040000000000000000832667268468867405317723751068115234375 or, if you prefer, it's: 5764607523034235/144115188075855872 > In what simple way can I get just 0.04 ? The answer to that depends on what you want and why you want it. Do you want a string or a number? And if you want a number, does it have to be *exactly* 0.04, or can your application cope with a tiny error? If you're trying to get a string and just want things to look nice, use str() instead of repr(), or display the value using print. If you want more control over the number of digits displayed, use Python's string formatting: e.g., in Python 2.6: >>> format(0.04, '.3f') # format with 3 places after the point '0.040' See the following for more information on format: http://docs.python.org/library/string.html#formatstrings If you're after the number and you *really* need to be able to manipulate the *exact* value 0.04 in Python (e.g., because you're doing financial work), you're probably better off using the Decimal module: http://docs.python.org/library/decimal.html See also: http://docs.python.org/tutorial/floatingpoint.html Mark From martin.schoon at gmail.com Fri Jun 19 04:16:39 2009 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Fri, 19 Jun 2009 10:16:39 +0200 Subject: Slow wxPyhon on Vista? Message-ID: <87y6ro3afs.fsf@crunchbang.Belkin> Hello there, this might be my first post here and it is slightly off topic since it is not about something I am developing. At work use a nifty little program called Task Coach. It helps me keep track of what I spend time on. Here is my problem. When I use it on a Vista box its user interface is very, very slow when it comes to some but not all operations. On any other Windows version it reacts instantaneously. I have not tried Task Coach on Linux or Solaris (yet). Is this how wxPython or Python works on Vista in general or is this the result of some local oddity on my employer's Vista configuration? TIA, /Martin From jure.erznoznik at gmail.com Fri Jun 19 04:27:48 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 01:27:48 -0700 (PDT) Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> Message-ID: <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Digging further, I found this: http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html Looking up on this info, I found this: http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock If this is correct, no amount of threading would ever help in Python since only one core / CPU could *by design* ever be utilized. Except for the code that accesses *no* functions / memory at all. This does seem to be a bit harsh though. I'm now writing a simple test program to verify this. Multiple data- independed threads just so I can see if more than one core can at all be utilized. :( From usernet at ilthio.net Fri Jun 19 04:35:18 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Jun 2009 08:35:18 GMT Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: On 2009-06-19, =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > If this is correct, no amount of threading would ever help in Python > since only one core / CPU could *by design* ever be utilized. Except > for the code that accesses *no* functions / memory at all. Don't multithread...multiprocess. By running multiple python instances, the operating system handles the processor scheduling for each so that you can use all available CPUs/cores. It also tends to make debugging easier. It does create more overhead -- significantly more on some OSs. From lepto.python at gmail.com Fri Jun 19 04:42:06 2009 From: lepto.python at gmail.com (oyster) Date: Fri, 19 Jun 2009 16:42:06 +0800 Subject: lib to do advanced geometry calculation? Message-ID: <6a4f17690906190142q518d2291k20df19f624b738fd@mail.gmail.com> My problem is some complex, because some condition is not supplied as a given value please have a look at http://www.lusiya.com/bbs/attachment/thumb/Mon_0906/80_3201_d2fa7bd75d28675.jpg because I have to do futher calculation based on previous steps as http://www.lusiya.com/bbs/attachment/thumb/Mon_0906/80_3201_d342e52235049e0.jpgshows, I want to get a precise value if possible, that is to say, (sqrt(2), 0), but not (1.414.0) [description] (clear condition) A=point(0,1) B=point(1,1) C=point(0,0) D=point(1,0) AC=segment(A, C) BD=segment(B, D) CD=segment(C, D) AB=segment(A, B) I=midpoint(B, D) (vague condition) E=pointOn(AC) F=pointOn(BD) EF=segment(E, F) G=mirror(A, EF) G=pointOn(CD) H=mirror(I, EF) H=pointOn(AB) (solve) E F [/description] Above is the description of my question, but I also hope I can write a problem like that to solve it. The only lib I know is sympy, but it seems that I must write different and long code accroding to different problem So is there any advanced (and lazy of cause) lib to handle my question? thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From heintest at web.de Fri Jun 19 04:42:33 2009 From: heintest at web.de (=?windows-1252?Q?Hans_M=FCller?=) Date: Fri, 19 Jun 2009 10:42:33 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> Message-ID: <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Thanks for all your informative replies. If I understand you right, for a commercial, closed source program I only need a commercial PyQt license for ~ 500? ? As far as I know I also need a Qt Licenses which is ~3500? per OS. What is right ? Thanks a lot, Hans From piet at cs.uu.nl Fri Jun 19 04:53:27 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 10:53:27 +0200 Subject: Help: Group based synchronize decorator References: Message-ID: >>>>> Vishal Shetye (VS) wrote: >VS> I want to synchronize calls using rw locks per 'group' and my implementation is similar to >VS> http://code.activestate.com/recipes/465057/ >VS> except that I have my own Lock implementation. >VS> All my synchronized functions take 'whatGroup' as param. My lock considers 'group' while deciding on granting locks through acquire. >VS> What I could come up with is: >VS> - decorator knows(assumes) first param to decorated functions is always 'whatGroup' >VS> - decorator passes this 'whatGroup' argument to my lock which is used in acquire logic. >VS> Is it ok to make such assumptions in decorator? As long as you make sure that all decorated functions indeed adhere to that assumption there is nothing wrong with it. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From newsgroup at silveraxe.de Fri Jun 19 04:58:46 2009 From: newsgroup at silveraxe.de (Hilmar Bunjes) Date: Fri, 19 Jun 2009 10:58:46 +0200 Subject: Once again, comparison wxpython with PyQt In-Reply-To: <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4a3b5347$0$30232$9b4e6d93@newsspool1.arcor-online.net> Hans M?ller schrieb: > Thanks for all your informative replies. > > If I understand you right, for a commercial, closed source program I > only need a commercial PyQt license for ~ 500? ? > > As far as I know I also need a Qt Licenses which is ~3500? per OS. > > What is right ? Qt is under the LGPL license to you can use it for free in your commercial program. Best, Hilmar From jeremy+complangpython at jeremysanders.net Fri Jun 19 05:00:16 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Fri, 19 Jun 2009 10:00:16 +0100 Subject: Once again, comparison wxpython with PyQt References: <4a3a42aa$0$3286$8e6e7893@newsreader.ewetel.de> <4a3b4f3c$0$32668$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Hans M?ller wrote: > Thanks for all your informative replies. > > If I understand you right, for a commercial, closed source program I > only need a commercial PyQt license for ~ 500? ? Why not ask the guys at riverbankcomputing? http://www.riverbankcomputing.co.uk/commercial/pyqt This page http://www.riverbankcomputing.co.uk/software/pyqt/license Says "The commercial version of PyQt can be used with both the commercial and LGPL versions of Qt." > As far as I know I also need a Qt Licenses which is ~3500? per OS. Not true, now Qt is licensed under the LGPL. You have to abide by the LGPL, however, which means that the user has to be able to relink a modified form of the library, Qt, with your application should they wish. You should check whether the LGPL is appropriate for the way you want to ship your program. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ From piet at cs.uu.nl Fri Jun 19 05:14:28 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 11:14:28 +0200 Subject: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009 References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: >>>>> John Machin (JM) wrote: >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ Apart from these patents probably being silly, why don't they just write the code in Python? :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From chris at simplistix.co.uk Fri Jun 19 05:21:11 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 10:21:11 +0100 Subject: ErrorHandler 1.0.0 Released! Message-ID: <4A3B5887.6000509@simplistix.co.uk> I'm pleased to finally get around to announcing the release of ErrorHandler. This is a handler for the python standard logging framework that can be used to tell whether messages have been logged at or above a certain level. This can be useful when wanting to ensure that no errors have been logged before committing data back to a database. Here's an example: First, you set up the error handler: >>> from logging import getLogger >>> from errorhandler import ErrorHandler >>> logger = getLogger() >>> e = ErrorHandler() The handler started off being un-fired: >>> e.fired False Then you do whatever else you need to do, which may involve logging: >>> logger.info('some information') >>> e.fired False However, if any logging occurs at an error level or above: >>> logger.error('an error') Then the error handler becomes fired: >>> e.fired True You use this as a condition to only do certain actions when no errors have been logged: >>> if e.fired: ... print "Not updating files as errors have occurred" Not updating files as errors have occurred If your code does work in batches, you may wish to reset the error handler at the start of each batch: >>> e.reset() >>> e.fired False For more information, please see: http://www.simplistix.co.uk/software/python/errorhandler or http://pypi.python.org/pypi/errorhandler cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Fri Jun 19 05:22:51 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 19 Jun 2009 10:22:51 +0100 Subject: Excel Formulae in Python ;-) In-Reply-To: References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: <4A3B58EB.6070306@simplistix.co.uk> Piet van Oostrum wrote: >>>>>> John Machin (JM) wrote: > >> JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ > > Apart from these patents probably being silly, why don't they just write > the code in Python? :=) Would be cool, but there are things like Resolver One (http://www.resolversystems.com/product/) and DiscoveryScript (http://www.xefion.com/en/discoveryscript.html) ...that help. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From pod at internode.on.net Fri Jun 19 05:35:10 2009 From: pod at internode.on.net (PoD) Date: 19 Jun 2009 09:35:10 GMT Subject: CAD file format specifications? References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> Message-ID: <024b4dd3$0$20662$c3e8da3@news.astraweb.com> On Thu, 18 Jun 2009 13:39:28 +0200, Anthra Norell wrote: > I had a look at Blender. It looks impressive too. It might be an > alternative to Sketch Up. I'll worry about that later. My immediate need > is a file conversion utility. A cursory inspection of Blender's menu > tabs and the various help options didn't turn up a file-conversion > utility. So, my question is: How do I convert a bunch of > three-dimensional coordinates defining lines into a file format Sketch > Up can read (skp, dwg, dxf, 3ds, ddf or dem)? > > Frederic If you look in the File/Import menu in Blender, you will see all the file types which it can load. The importing is done with python scripts, so if you are going to write a converter you might just as well write an import script for Blender. The raw import script shows how simple it can be. From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 05:43:54 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 11:43:54 +0200 Subject: A question on scope... In-Reply-To: References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> Message-ID: <4a3b5dc3$0$2985$426a74cc@news.free.fr> MRAB a ?crit : > Wells Oliver wrote: NB : answering the OP (original post didn't show up on c.l.py ???) >> In writing out python classes, it seems the 'self' is optional, You mean, inside a method ? >> meaning that inside a class method, In Python, a "class method" is a method that operates on the class object itself instead of operating on an instance of the class. >> "self.foo = bar" has the same >> effect as "foo = bar". Is this right? It's obviously false, cf MRAB's answer. From jure.erznoznik at gmail.com Fri Jun 19 05:52:55 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 02:52:55 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? Message-ID: See here for introduction: http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 Digging through my problem, I discovered Python isn't exactly thread safe and to solve the issue, there's this Global Interpreter Lock (GIL) in place. Effectively, this causes the interpreter to utilize one core when threading is not used and .95 of a core when threading is utilized. Is there any work in progess on core Python modules that will permanently resolve this issue? Is there any other way to work around the issue aside from forking new processes or using something else? From gh at ghaering.de Fri Jun 19 06:20:16 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 19 Jun 2009 12:20:16 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: <4A37BD14.5010807@arimaz.com> References: <4A37BD14.5010807@arimaz.com> Message-ID: Gabriel Rossetti wrote: > Hello everyone, > > I get an OperationalError with sqlite3 if I put the wrong column name, > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > says : > > " OperationalError > Exception raised for errors that are related to the > database's operation and not necessarily under the control > of the programmer, e.g. an unexpected disconnect occurs, > the data source name is not found, a transaction could not > be processed, a memory allocation error occurred during > processing, etc. It must be a subclass of DatabaseError. > ProgrammingError > Exception raised for programming errors, e.g. table not > found or already exists, syntax error in the SQL > statement, wrong number of parameters specified, etc. It > must be a subclass of DatabaseError. > " > > and to me it sounds more like a programming error than an operational > error. I agree. But I can't help you there. See _pysqlite_seterror() at http://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c What I do is map SQLite error codes to DB-API exceptions. And SQLite reports your error as generic SQLITE_ERROR, which is mapped to OperationalError. -- Gerhard From albert at spenarnc.xs4all.nl Fri Jun 19 06:49:00 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 19 Jun 2009 10:49:00 GMT Subject: preferring [] or () in list of error codes? References: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: In article , > > >But practicality beats purity -- there are many scenarios where we make >compromises in our meaning in order to get correct, efficient code. E.g. >we use floats, despite them being a poor substitute for the abstract Real >numbers we mean. > >In addition, using a tuple or a list in this context: > > if e.message.code in (25401,25402,25408): > >is so idiomatic, that using a set in it's place would be distracting. >Rather that efficiently communicating the programmer's intention, it >would raise in my mind the question "that's strange, why are they using a >set there instead of a tuple?". As a newby I'm really expecting a set here. The only reason my mind goes in the direction of 3 items is that it makes no sense in combination with ``in''. That makes this idiom one that should be killed. " point1 = (0,1,0) point2 = (1,0,0) point3 = (0,0,1) for i in (point1,point2, point3): .... " ??? I don't think so. At least I would do " for i in [point1,point2,point3]: statements " But I greatly prefer a set " for i in {point1,point2,point3}: statements " Because a set is unorderded, this would convey to the the compiler that it may evaluate the three statements concurrently. For a list I expect the guarantee that the statements are evaluated in order. For a tuple I don't know what to expect. That alone is sufficient reason not to use it here. [Yes I know { } doesn't denote a set. I tried it. I don't know how to denote a set ... ] >-- >Steven 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 scott.pigman at gmail.com Fri Jun 19 07:14:19 2009 From: scott.pigman at gmail.com (Scott) Date: Fri, 19 Jun 2009 04:14:19 -0700 (PDT) Subject: Allocating memory to pass back via ctypes callback function References: Message-ID: <0b8e092f-2353-4a6b-8ff0-62e1e7b4d427@r3g2000vbp.googlegroups.com> I think I found the answer to my own question. Can anyone spot any issues with the following solution? The application I'm writing will be hitting these callbacks pretty heavily so I'm nervous about mucking up the memory management and creating one of those bugs that passes undetected through testing but nails you in production. def my_callback(p_cstring): answer = 'foobar' address = VENDOR_malloc(len(answer)+1) cstring = c_char_p.from_address( address ) cstring.value = answer p_cstring.contents = cstring return From david.lyon at preisshare.net Fri Jun 19 07:16:33 2009 From: david.lyon at preisshare.net (David Lyon) Date: Fri, 19 Jun 2009 07:16:33 -0400 Subject: Slow wxPyhon on =?UTF-8?Q?Vista=3F?= In-Reply-To: <87y6ro3afs.fsf@crunchbang.Belkin> References: <87y6ro3afs.fsf@crunchbang.Belkin> Message-ID: <5bc3ad79f831b20568c6893831335c2a@preisshare.net> On Fri, 19 Jun 2009 10:16:39 +0200, martin.schoon at gmail.com (Martin Sch??n) wrote: > Here is my problem. When I use it on a Vista box its > user interface is very, very slow when it comes to > some but not all operations. On any other Windows > version it reacts instantaneously. I have not tried > Task Coach on Linux or Solaris (yet). > > Is this how wxPython or Python works on Vista in > general or is this the result of some local oddity on my > employer's Vista configuration? I have encountered the same thing on XP in one instance on a development box. For some reason, wxpython just grinds to a halt. I couldn't solve it and reimaged the O/S... that fixed it... David From piet at cs.uu.nl Fri Jun 19 07:23:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:23:16 +0200 Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Digging further, I found this: >JE> http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html >JE> Looking up on this info, I found this: >JE> http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock >JE> If this is correct, no amount of threading would ever help in Python >JE> since only one core / CPU could *by design* ever be utilized. Except >JE> for the code that accesses *no* functions / memory at all. It is not the design of the Python language, but of the Python implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:29:21 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:29:21 +0200 Subject: Integer Division References: Message-ID: >>>>> Anjanesh Lekshminarayanan (AL) escribi?: >>>>> a = 1 >>>>> b = 25 >>>>> a / b >AL> 0 >>>>> float(a) / b >AL> 0.040000000000000001 >>>>> >>>>> from __future__ import division >>>>> a = 1 >>>>> b = 25 >>>>> a / b >AL> 0.040000000000000001 >>>>> >AL> In what simple way can I get just 0.04 ? In addition to the answers others have given: >>> 0.04 0.040000000000000001 >>> IIRC, Python 3.1 will give 0.04. But this doesn't mean the answer will be mathematically equal to 0.04, just that it tries to make it less painful. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:32:10 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:32:10 +0200 Subject: Excel Formulae in Python ;-) References: <17c27230-a9f9-44f0-bea8-b4c22c0cf972@e24g2000vbe.googlegroups.com> Message-ID: >>>>> Chris Withers (CW) wrote: >CW> Piet van Oostrum wrote: >>>>>>>> John Machin (JM) wrote: >>> >JM> [1] No kidding: http://www.google.com/patents/about?id=QMwnAAAAEBAJ >>> >>> Apart from these patents probably being silly, why don't they just write >>> the code in Python? :=) >CW> Would be cool, but there are things like >CW> Resolver One (http://www.resolversystems.com/product/) >CW> and >CW> DiscoveryScript (http://www.xefion.com/en/discoveryscript.html) >CW> ...that help. Actually, I meant writing the patent application in Python :=) instead of this pseudo-exact legalese with goto instructions for the control flow. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Fri Jun 19 07:39:20 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 13:39:20 +0200 Subject: Newbie queue question References: <6079ea97-b26a-4c8d-9d19-8b35a5db7dbd@f10g2000vbf.googlegroups.com> <2d897ba1-c36c-4b71-b6ff-9b7366a4c8bf@l28g2000vba.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Digging further, I found this: >JE> http://www.oreillynet.com/onlamp/blog/2005/10/does_python_have_a_concurrency.html >JE> Looking up on this info, I found this: >JE> http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock >JE> If this is correct, no amount of threading would ever help in Python >JE> since only one core / CPU could *by design* ever be utilized. Except >JE> for the code that accesses *no* functions / memory at all. It is not the design of the Python language, but of the *CPython* implementation. And yes, it will not benefit from more than one core. You should watch/read this: http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From davea at ieee.org Fri Jun 19 08:06:51 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 08:06:51 -0400 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: <4A3B7F5B.1030302@ieee.org> Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b >>>> > 0 > >>>> float(a) / b >>>> > 0.040000000000000001 > > > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b >>>> > 0.040000000000000001 > > > In what simple way can I get just 0.04 ? > > Your subject line says "Integer Division" but you're dealing with floats. IEEE standard float cannot exactly represent 0.04 In fact, no binary floating point value of finite precision can get that exact value. So if you really want 0.04, you need to use the decimal package. It's the only way you'll be sure of exactly representing any decimal fraction you need. Let's call val = float(1)/25 If you're using future division (or Python 3.x), 1/25 will be exactly the same as val. In either case, the division cannot come out exactly, since there is no such exact float. On the other hand, some *string* representation of val may not come out "exact." Technically, to represent val in decimal digits may take up to 59 or so characters. But the two standard conversions from float to string ( float.__str__ and float.__val__ ) do a little rounding themselves. So you can try them, and see that one of them "works." (print calls the __str__ method, while the interpreter uses __repr__) The problem with this is that what "works" for one such val might fail for the next. And these __str__ and __val__ have been implemented multiple times, so testing on one Python version will not assure consistency on the next. The issue is that you're counting on two approximations canceling each other out. That'll work in some circumstances, but knowing what they are isn't reasonable. So what do people do? Simplest is to use a decimal package. I tried back in the early 80's to convince the IEEE committee to include decimal float in the standard, but was rejected. I had implemented (microcoded) arithmetic and transcendentals on a machine which offered only decimal floating point; no binary floating point. Next choice? Stick to integers, or implied fractions. For example, if dealing with dollars and cents, always calculate and store the value in pennies, and only insert the decimal when displaying. Finally, it's not hard (if you know something about the numbers) to get a "pretty" display version for yourself, rounding it as you're converting to string. Note that this affects other aspects of your program, such as comparisons between two floats. If you sum up 100 copies of .01, will you get exactly 1.0 ? I don't know, but in many cases, clearly not. This is not a new problem. I read about it in McCracken's Fortran book in 1967, where he said to use something on the order of: if abs(a-b) < .0000000001 ... when comparing reals. From ben+python at benfinney.id.au Fri Jun 19 08:13:36 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Jun 2009 22:13:36 +1000 Subject: preferring [] or () in list of error codes? References: <13b716c0-fb58-4952-813b-0b3791fae8a6@f10g2000vbf.googlegroups.com> <87my8icj7l.fsf@benfinney.id.au> Message-ID: <87ab441kwf.fsf@benfinney.id.au> Albert van der Horst writes: > But I greatly prefer a set > > " > for i in {point1,point2,point3}: > statements > " Agreed, for the reasons you cite. I think this idiom can be expected to become more common and hopefully displace using a tuple literal or list literal, as the set literal syntax becomes more reliably available on arbitrary installed Python versions. > [Yes I know { } doesn't denote a set. I tried it. I don't know how to > denote a set ... ] Try it in Python 3 and be prepared to be pleased . -- \ ?Too many Indians spoil the golden egg.? ?Sir Joh | `\ Bjelke-Petersen | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 08:45:43 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 14:45:43 +0200 Subject: generator expression works in shell, NameError in script In-Reply-To: References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> Message-ID: <4a3b8860$0$19616$426a74cc@news.free.fr> Emile van Sebille a ?crit : > On 6/17/2009 3:54 PM ssc said... >> Wow! Didn't expect that kind of instant support. Thank you very much, >> I'll give both zip and enumerate a try. >> >> The code I've shown is actually copied pretty straight from a Django >> form class, but I didn't want to mention that as not to dilute the >> conversation. Don't think it matters, anyway. This is the relevant >> excerpt: >> >> from django.forms import Form >> >> class SignupForm(Form): >> >> titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',] >> title_choices = [(0, '')] + list((titles.index(t)+1, t) for t in >> titles) >> >> Now that I look at it again, it seems odd to me to not have the code >> e.g. in __init__(...), but just 'class-global'. > > And as class is an executable statement, I imagine titles exists in a > namespace that hasn't yet been completely defined. >> Still, that does not seem a reason for titles not to be not defined, >> as I do define it just in the line above. > > Well, again, titles will exists in the SignupForm namespace once it > exists, which it doesn't yet when you get to title_choices and want to > access it. The namespace itself is as defined at any point of the class statement's body as the local namespace of a function at any given point of the function's body. Else decorators (or their alternate pre '@' syntactic-sugar version) wouldn't work. FWIW, the following code works JustFine(tm): bruno at bruno:~$ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list(enumerate(bar)) as well as this one: >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = [(bar.index(t)+1, t) for t in bar] and this one: >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list((b, b) for b in bar) but it indeed looks like using bar.index *in a generator expression* fails (at least in 2.5.2) : >>> class Foo(object): ... bar = ['a', 'b', 'c'] ... baaz = list((bar.index(b), b) for b in bar) ... Traceback (most recent call last): File "", line 1, in File "", line 3, in Foo File "", line 3, in NameError: global name 'bar' is not defined Looks like a bug to me :-/ From martin.hellwig at dcuktec.org Fri Jun 19 09:04:12 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 19 Jun 2009 14:04:12 +0100 Subject: Decorator question (how to test if decorated function is in a class) Message-ID: Hi all, I have been trying out to wrap my mind around the advantages of decorators and thought I found a use in one of my experiments. (see code after my sig). Although it works, I think it should be able to do it better. My particular problem is that I want to remove an argument (say always the first one) when the decorated function is called. However if the function is defined in a class the first argument is self and thus the second argument should be removed. Since I like to have a more general DRY approach I want to test if the decorated function is defined in a class or not thus knowing that the first argument is self and must be preserved. I tried different approaches but all didn't work and looked very unpythonic (looking at the attributes, descriptors namespaces, id() of the function, the first argument and the decorator itself). So is there a way to find out if the first argument is 'self' without making a false positive if the first argument is a class instance passed to a function? -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' code: class Decorator(object): "When used as Decorator(argument) returns a decorator" def __init__(self, key): self.key = key def __call__(self, function): "Return a decorator" def decorator(*arg_tuple, **arg_dict): "The decorator test if the arguments contain a valid key" if arg_tuple[0] == self.key: # This means it is a simple function, so check and strip it arg_list = arg_tuple[1::] return(function(*arg_list, **arg_dict)) elif arg_tuple[1] == self.key: # This means it is a class method, check it, # strip (but retain self) arg_list = arg_tuple arg_list = arg_list[0:1] + arg_list[2::] return(function(*arg_list, **arg_dict)) else: # The key was invalid return('invalid') return(decorator) class Test(object): @Decorator('key') def test(self, data): return(data) @Decorator('key') def function_2(self, data): return(data) @Decorator('key') def function_3(self, data): return(data) @Decorator('key') def test_f(data): return(data) # Test starts here test_c = Test() print(test_c.test('key', 'data')) print(test_f('key', 'data')) print(test_c.test('invalid', 'data')) print(test_f('invalid', 'data')) From dickinsm at gmail.com Fri Jun 19 09:08:18 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 06:08:18 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <4a3b8860$0$19616$426a74cc@news.free.fr> Message-ID: <2c34275d-f112-44ed-b99e-201c1ee3a823@v4g2000vba.googlegroups.com> On Jun 19, 1:45?pm, Bruno Desthuilliers wrote: > [...] > but it indeed looks like using bar.index *in a generator expression* > fails (at least in 2.5.2) : > > ? >>> class Foo(object): > ... ? ? bar = ['a', 'b', 'c'] > ... ? ? baaz = list((bar.index(b), b) for b in bar) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 3, in Foo > ? ?File "", line 3, in > NameError: global name 'bar' is not defined > > Looks like a bug to me :-/ I think it's working as intended: name resolution for nested scopes skips intermediate class scopes. The 'Discussion' section of PEP 227 (Statically Nested Scopes) is illuminating; here's a snippet: """Names in class scope are not accessible. Names are resolved in the innermost enclosing function scope. If a class definition occurs in a chain of nested scopes, the resolution process skips class definitions. This rule prevents odd interactions between class attributes and local variable access.""" Mark From castironpi at gmail.com Fri Jun 19 09:24:34 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 06:24:34 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Jun 17, 3:53?pm, "Rhodri James" wrote: > On Wed, 17 Jun 2009 16:06:22 +0100, Aaron Brady ? > wrote: > > > > > On Jun 16, 10:09?am, Mike Kazantsev wrote: > >> On Tue, 16 Jun 2009 06:57:13 -0700 (PDT) > > >> Aaron Brady wrote: > >> > Making the charitable interpretation that this was the extent of c-l- > >> > py's support and enthusiasm for my idea, I will now go into mourning. > >> > Death occurred at oh-eight-hundred. ?Rest in peace, support & > >> > enthusiasm. > > >> I've read this thread from the beginning, being tempted to insert > >> remarks about shelve module or ORMs like SQLAlchemy, but that'd be > >> meaningless without the problem description, which I haven't seen > >> anywhere. Is it some trick idea like "let's walk on our heads"? > > > More like bronze them, or hang them on a tackboard. ?You haven't > > convinced me that it's not a problem, or that it's an easy one. > > Unfortunately it's up to you to demonstrate that it is a problem, > whichever of the many possible 'it's you're talking about. ?So far, > the question "Why would I want to use this? ?What's the use case?" > has gone unanswered, and I'm sure I'm not the only baffled by it. I can demonstrate it's a problem; many things are. The subject line says it all. SQL will persist (and share for IPC, after a fashion) sets of statically typed tuples. But we have need for sets of dynamically typed tuples, in volatile storage at the very least, or no one would like Python. Whether we have need for them in persistent storage remains to be seen. POSH Python Object SHaring has been at least one student's graduate thesis. It couldn't hurt to pursue it if one has time, as with many things. It's pretty likely my estimates of end user usefulness of 'KeepDB', say, derive sturdily and steadily from our estimated popularity of Python. So much for my motives, though not for my opportunities. My implementation has followed two separate paths: one using SQL for a back-end host; the other using hand-coded bytes on disk, complete with large file support using views, and on-disk (or in-buffer) memory management, which incidentally I spoke up about about a year ago. It was the topic of an honors lecture in the Data Structures course in my undergrad. For the record, I still can't beat a log-N balanced tree for finding free nodes, but I am operating on the assumption that the smallest sufficient region is the best to return from 'alloc'. You are not being any help, Rhodri, in your question. Its chief virtue is fidelity of programming, that is, what you write is most true to what you mean. If you have an object on disk, and want the third element of its 'coords' list attribute, it's a waste to do anything other than find its disk address, then the disk address of its 'coords' attribute, then the disk address of the third element of that, such as say, loading or worse, processing, the entire structure; even if, and in light of parallel considerations about economic market transparency and efficiency, that is to say, economy, maybe / especially/ if, you are having a lowly machine make do. You don't want to open every box in your basement to find your tennis racket; you want to open one box, find the racket in the index, then open all and only the boxes that 'nestedly' contain the racket. (Yes, that's / all/ and /only/, or 'if and only if'-- not to be confused with 'one and only'.) It's more economic. From matt at tplus1.com Fri Jun 19 09:36:01 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 13:36:01 GMT Subject: Is this pylint error message valid or silly? References: Message-ID: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> On Fri 19 Jun 2009 02:55:52 AM EDT, Terry Reedy wrote: >> if c == "today": >> c = datetime.today() > > Now I guess that you actually intend c to be passed as a datetime > object. You only used the string as a type annotation, not as a real > default value. Something like 'record_date = None' is better. Thanks for the feedback. I think I should have used a more obvious string in my original example and a more descriptive parameter name. So, pretend that instead of c="today" I wrote record_date="defaults to today's date". I know my way is unorthodox, but I think it is a little bit more obvious to the reader than record_date=None The None is a signal to use a default value, but that is only apparent after reading the code. Thanks again for the comments. Matt From trinioler at gmail.com Fri Jun 19 09:47:38 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 06:47:38 -0700 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3618a6e10906190647h4726fc7tc919d00e2910fbc7@mail.gmail.com> This is a very long-running issue, that has been discussed many times. Here are the two sides to keeping the gil or removing it: Remove the GIL: - True multi-threaded programming - Scalable performance across a multi-core machine - Unfortunately, this causes a slow-down in single core/thread performance - Most of the slow down comes from Python's Reference counting, as every function is supposed to increase and decrease the references... which leads to a lot of synchronization and checking of locks. - It makes the core interpreter much more complex Keeping the GIL: - Processes should be used instead of threads. Look at Erlang, THE model of concurrency. It uses a process model for concurrency and message passing, rather than threads. This means you avoid deadlocks, livelocks, race conditions(not entirely, but they are reduced) - C extensions can still gain really impressive multi-threaded performance. My C extension, a wrapper around ffmpeg, releases the GIL for 90% or so of its processing time, so all other threads are still extremely responsive. - It allows python to stay simple, understandable, and offer good performance, if you know how to use it properly. Basically the two sides are that you it ends up slowing things down, it makes the interpreter more complex vs you should use processes instead, and be smart about how you use the GIL. -Tyler On Fri, Jun 19, 2009 at 2:52 AM, Jure Erzno?nik wrote: > See here for introduction: > > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From bcharrow at csail.mit.edu Fri Jun 19 09:53:08 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Fri, 19 Jun 2009 09:53:08 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4A3B9844.2030201@csail.mit.edu> Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? There is a group of people working on an alternative implementation to Python that, among other things, will not have a GIL: http://code.google.com/p/unladen-swallow/ There was even a successful attempt to remove the GIL from CPython, but it caused single threaded python code to be much slower. See more here: http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock Cheers, Ben From rhodri at wildebst.demon.co.uk Fri Jun 19 09:53:57 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Jun 2009 14:53:57 +0100 Subject: Is this pylint error message valid or silly? In-Reply-To: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> References: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> Message-ID: On Fri, 19 Jun 2009 14:36:01 +0100, Matthew Wilson wrote: > On Fri 19 Jun 2009 02:55:52 AM EDT, Terry Reedy wrote: >>> if c == "today": >>> c = datetime.today() >> >> Now I guess that you actually intend c to be passed as a datetime >> object. You only used the string as a type annotation, not as a real >> default value. Something like 'record_date = None' is better. > > Thanks for the feedback. I think I should have used a more obvious > string in my original example and a more descriptive parameter name. > > So, pretend that instead of > > c="today" > > I wrote > > record_date="defaults to today's date". > > I know my way is unorthodox, but I think it is a little bit more obvious > to the reader than > > record_date=None > > The None is a signal to use a default value, but that is only apparent > after reading the code. It's a very common idiom, however, and in addition record_data is None is a cheap test, while record_data == "defaults to today's date" is an expensive test as well as easy to mistype. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Fri Jun 19 10:00:52 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Jun 2009 15:00:52 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: On Fri, 19 Jun 2009 14:24:34 +0100, Aaron Brady wrote: > You are not being any help, Rhodri, in your question. To you, perhaps not. To me, it has at least had the effect of making what you're trying to do (write a pythonic object database) clearer. -- Rhodri James *-* Wildebeest Herder to the Masses From martin.vonloewis at hpi.uni-potsdam.de Fri Jun 19 10:16:18 2009 From: martin.vonloewis at hpi.uni-potsdam.de (Martin von Loewis) Date: Fri, 19 Jun 2009 16:16:18 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4A3B9DB2.4070909@hpi.uni-potsdam.de> > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. > Is there any other way to work around the issue aside from forking new > processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin From martin.vonloewis at hpi.uni-potsdam.de Fri Jun 19 10:16:31 2009 From: martin.vonloewis at hpi.uni-potsdam.de (Martin von Loewis) Date: Fri, 19 Jun 2009 16:16:31 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. > Is there any other way to work around the issue aside from forking new > processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin From mblume at socha.net Fri Jun 19 10:38:42 2009 From: mblume at socha.net (mblume) Date: 19 Jun 2009 14:38:42 GMT Subject: Is this pylint error message valid or silly? References: Message-ID: <4a3ba2f2$0$9117$5402220f@news.sunrise.ch> Am Fri, 19 Jun 2009 00:56:18 +0000 schrieb Matthew Wilson: > Here's the code that I'm feeding to pylint: > > $ cat f.py > from datetime import datetime > > def f(c="today"): > > if c == "today": > c = datetime.today() > > return c.date() > > > And here's what pylint says: > > $ pylint -e f.py > No config file found, using default configuration ************* > Module f > E: 10:f: Instance of 'str' has no 'date' member (but some types > could not be inferred) > > Is this a valid error message? Is the code above bad? If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > > $ cat f.py > from datetime import datetime > > def f(c=None): > > if c is None: > c = datetime.today() > > return c.date() > > $ pylint -e f.py > No config file found, using default configuration > > I don't see any difference between using a string vs None. Both are > immutable. I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt Think of what happens if somebody calls some_result = f("yesterday") HTH Martin From Olivier.Darge at gmail.com Fri Jun 19 10:40:05 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 07:40:05 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <7a0e7314-e07f-4e1f-b9c6-6f9c336818be@g20g2000vba.googlegroups.com> On 19 juin, 11:52, Jure Erzno?nik wrote: > See here for introduction:http://groups.google.si/group/comp.lang.python/browse_thread/thread/3... > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. > > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? hi, please read this carefully, there is a solution for Python on multi-core : multiprocessing api. Really nice. Keep real threads for common tasks like network stuff for example. I recently complained too :-) Olivier From thomas.robitaille at gmail.com Fri Jun 19 10:40:11 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Fri, 19 Jun 2009 07:40:11 -0700 (PDT) Subject: multiprocessing and process run time Message-ID: <24112854.post@talk.nabble.com> Hi, I'm making use of the multiprocessing module, and I was wondering if there is an easy way to find out how long a given process has been running for. For example, if I do import multiprocessing as mp import time def time_waster(): time.sleep(1000) p = mp.Process(target=time_waster) p.start() Is there a way that I can then find how long p has been running for? I figured I can use p.pid to get the PID of the process, but I'm not sure where to go from there. Is there an easy way to do this? Thanks, Thomas -- View this message in context: http://www.nabble.com/multiprocessing-and-process-run-time-tp24112854p24112854.html Sent from the Python - python-list mailing list archive at Nabble.com. From invalid at invalid Fri Jun 19 10:41:53 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 09:41:53 -0500 Subject: pyserial question References: <6f4f96030906180424w367d4d11r2f1d37ec264a4bf@mail.gmail.com> Message-ID: On 2009-06-19, Dennis Lee Bieber wrote: > On Thu, 18 Jun 2009 14:24:42 +0300, Piter_ declaimed >> I cant find out how to set "Handshaking RST on TX" in pyserial. > > Never encountered "RST" mode... "RTS" mode is common. > >>From the source -- a port can be initialized with: [nothing relevent] > If RTS/CTS is not doing what you need... You may have to go > very low-level -- programmatically setting and clearing the > control lines. [...] That's not what wants. He wants RTS to be automatically asserted while data is being transmitted, and de-asserted while data is being received. That feature is called "RTS toggle" in MS-Window-speak. The rest of us usually call it half-duplex RTS control or auto-line-direction or something like that. Trying to do it manually from user-space is generally futile. If you're very lucky, you'll be able to get it to work some of the time on some platforms. [ example of manually setting/clearing RTS] > Again, both of those clips are readily viewable by just > looking at the .py files in the serial package. AFAIK, pyserial doesn't support RTS toggle -- it's a feature not supportted my some platforms and/or serial drivers. However, it is supported by the standard Win32 drivers, so you can enable it by setting the appropriate values in the DCB passed SetCommState(). I'm not a windows guy, so you're going to have to go search the Win32 API docs for details. You might be able to use pyserial to open the port, then get the file handle to do whatever low-level configuration tweaks you want, and then use pyserial to read/write data. NB: RTS toggle in Windows drivers isn't generally very reliable, since it's implemented in software by polling the UART status register. Not all UARTS set the tx shift register empty bit at the correct point in time. -- Grant Edwards grante Yow! Like I always say at -- nothing can beat visi.com the BRATWURST here in DUSSELDORF!! From invalid at invalid Fri Jun 19 10:44:17 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 09:44:17 -0500 Subject: Integer Division References: Message-ID: On 2009-06-19, Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 >>>> > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 >>>> > > In what simple way can I get just 0.04 ? You can't. There _is_no_ 0.04 when using binary IEEE floating point (which is what's used for floats on any computer you're likely to run across). You could use some other data type (rationals, BCD floats, etc.). -- Grant Edwards grante Yow! Hello. I know at the divorce rate among visi.com unmarried Catholic Alaskan females!! From aahz at pythoncraft.com Fri Jun 19 10:45:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 07:45:13 -0700 Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: In article , Aaron Brady wrote: > >You are not being any help, Rhodri, in your question. Maybe not, but honestly, you're getting pretty close to going back in my killfile. Although you're no longer trolling this group, I find your writing difficult to read at best; answering questions from people like Rhodri is about your only chance to reach people like me. Even without the killfile, I'm skipping about 60-80% of your posts. It's a free Usenet, of course, so you're under no obligation to pay any attention to me, but I think you ought to consider the merits of changing your opinion of Rhodri's questions. Side note: the rhetorical trick of inserting a person's name in a statement is often intended and received as a mildly patronizing insult. It's not at all clear to me whether that was your intent; if not, you might want to change your writing style a bit. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jjkk73 at gmail.com Fri Jun 19 10:46:46 2009 From: jjkk73 at gmail.com (jorma kala) Date: Fri, 19 Jun 2009 15:46:46 +0100 Subject: Retrieving column values by column name with MySQLdb Message-ID: Hi, Is there a way of retrieving the value of columns in the rows returned by fetchall, by column name instead of index on the row? Code Snippet: query="select * from employees" db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) cursor = db.cursor () cursor.execute (query) rows = cursor.fetchall () for row in rows: print row[0] Instead of specifying the index of the row to retrieve the first column (row[0]), I'd like to retrieve the value of the first column by column name. Something like row.get('employee_id') Is something of the sort possible with Mysqdb? Thanks very much. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mk.fraggod at gmail.com Fri Jun 19 10:52:01 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 20:52:01 +0600 Subject: multiprocessing and process run time References: <24112854.post@talk.nabble.com> Message-ID: <20090619205201.51171713@coercion> On Fri, 19 Jun 2009 07:40:11 -0700 (PDT) Thomas Robitaille wrote: > I'm making use of the multiprocessing module, and I was wondering if there > is an easy way to find out how long a given process has been running for. > For example, if I do > > import multiprocessing as mp > import time > > def time_waster(): > time.sleep(1000) > > p = mp.Process(target=time_waster) > > p.start() > > Is there a way that I can then find how long p has been running for? I > figured I can use p.pid to get the PID of the process, but I'm not sure > where to go from there. Is there an easy way to do this? If you use unix-like platform (e.g. linux) you can just use 'ps -e -o pid,start_time | grep '. I'd used procpy to do ps-like stuff in python since it's a wrapper around the same procps library, prehaps it can get the same results as well, w/o having to invoke shell commands: http://code.google.com/p/procpy/ -- Mike Kazantsev // fraggod.net From trinioler at gmail.com Fri Jun 19 10:55:19 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 07:55:19 -0700 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> Message-ID: <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> So no one has an answer for why passing flags and the values the flags need through subprocess does not work? I would like an answer. I've examined all the examples I could find online, which were all toy examples, and not helpful to my problem. On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: > I've been trying any variation I can think of to do this properly, but > here's my problem: > > I want to execute this command string: vlc -I rc > > This allows vlc to be controlled via a remote interface instead of the > normal gui interface. > > Now, say, I try this from subprocess: > > >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, > stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > But I don't get the remote interface. I get the normal gui interface. So > how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', > 'rc'] with executable set to 'vlc'. I've had shell=True, I've had > shell=False. I've tried all these combinations. > > What am I doing wrong? > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From castironpi at gmail.com Fri Jun 19 10:56:04 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 07:56:04 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Jun 19, 7:45?am, a... at pythoncraft.com (Aahz) wrote: > In article , > Aaron Brady ? wrote: > > > > >You are not being any help, Rhodri, in your question. ? > > Maybe not, but honestly, you're getting pretty close to going back in my > killfile. ?Although you're no longer trolling this group, I find your > writing difficult to read at best; answering questions from people like > Rhodri is about your only chance to reach people like me. ?Even without > the killfile, I'm skipping about 60-80% of your posts. ?It's a free > Usenet, of course, so you're under no obligation to pay any attention to > me, but I think you ought to consider the merits of changing your > opinion of Rhodri's questions. > > Side note: the rhetorical trick of inserting a person's name in a > statement is often intended and received as a mildly patronizing insult. > It's not at all clear to me whether that was your intent; if not, you > might want to change your writing style a bit. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha > Side note: the rhetorical trick of inserting a person's name in a This is a welcome digression for me. I wasn't sure that my idea was being taken seriously. On a temperature scale from freezing to boiling, I took Rhodri's message to be somewhere in the single digits-- quite chilly. Maybe if it hadn't made me feel so defensive, I could've just said so. But, judging from his reply, he got the message. > I find your > writing difficult to read at best; ... > I'm skipping about 60-80% of your posts. My loss. From javier.collado at gmail.com Fri Jun 19 11:05:24 2009 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 19 Jun 2009 17:05:24 +0200 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: Hello, The problem might be that, aside from creating the Popen object, to get the command run you need to call 'communicate' (other options, not used with the Popen object directly, are 'call' or 'waitpid' as explained in the documentation). Did you do that? Best regards, Javier 2009/6/19 Tyler Laing : > So no one has an answer for why passing flags and the values the flags need > through subprocess does not work? I would like an answer. I've examined all > the examples I could find online, which were all toy examples, and not > helpful to my problem. > > On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: >> >> I've been trying any variation I can think of to do this properly, but >> here's my problem: >> >> I want to execute this command string: vlc -I rc >> >> This allows vlc to be controlled via? a remote interface instead of the >> normal gui interface. >> >> Now, say, I try this from subprocess: >> >> >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, >> >>> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >> But I don't get the remote interface. I get the normal gui interface. So >> how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', >> 'rc'] with executable set to 'vlc'. I've had shell=True, I've had >> shell=False. I've tried all these combinations. >> >> What am I doing wrong? >> >> -- >> Visit my blog at http://oddco.ca/zeroth/zblog > > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > > -- > http://mail.python.org/mailman/listinfo/python-list > > From fabiofz at gmail.com Fri Jun 19 11:05:34 2009 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 19 Jun 2009 12:05:34 -0300 Subject: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux In-Reply-To: <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> References: <2f542842-b283-4661-8fb4-6377dca31f09@j9g2000prh.googlegroups.com> <31f16604-d8f5-48b1-9744-770ef87f6ae1@x29g2000prf.googlegroups.com> <3618a6e10906171957pd472f7fle6b1008a18eb749a@mail.gmail.com> <547c5c320906172032q291f52bdlfbc8f6c4006dde7f@mail.gmail.com> <547c5c320906182022x57b42439xbd73c7c5c3cf8bb1@mail.gmail.com> Message-ID: On Fri, Jun 19, 2009 at 12:22 AM, Wei, Xiaohai wrote: > Thanks for your reply. > > where is the error log? I can not find it at /var/log Take a look at http://pydev.sourceforge.net/faq.html#how_do_i_report_a_bug (it gives the details on how to find the needed info). > I have a virtual network card to bridge kvm virtual machine. will it cause > problem? Not sure... What I know is that pydev creates a shell and connects to it through 127.0.0.1, so, if that fails, that could be a problem. > as you said configuration of interpretor, how should I configure the > interpretor? Please follow the getting started tutorial for that: http://fabioz.com/pydev/manual_101_root.html Cheers, Fabio > > Thanks > > James > > On Fri, Jun 19, 2009 at 9:32 AM, Fabio Zadrozny wrote: >> >> > yes, the same problem even on an empty program. every file has the same >> > problem. >> > >> > for example, if I new a file and input the following: >> > import os >> > os. >> > after I input '.', it will pop up the window, and i can select the >> > function >> > of os module or continue input. but after that, no action can be taken >> > for >> > this file unless I switch to other files and then switch back. >> >> If it's in pydev, there's probably some problem in your interpreter >> configuration (when you do os. it'll spawn a shell to gather the >> completions -- but that should be pretty quick unless you have some >> firewall that's preventing the communication or the spawn didn't go >> well -- check your error log to see if you have any errors... In linux >> I've seen some problems when connecting to 127.0.0.1 while having ipv6 >> enabled or in a network card misconfiguration that could cause >> problems too). >> >> Cheers, >> >> Fabio >> >> >> > >> > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing >> > wrote: >> >> >> >> Do you experience the same problem even on an empty program file or is >> >> it >> >> limited to just one file? >> >> >> >> -Tyler >> >> >> >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James wrote: >> >>> >> >>> On Jun 18, 10:45?am, "Wei, James" wrote: >> >>> > When I am editing python program with SPE, I found that SPE will >> >>> > freeze when it is doing auto-completion. The behavior is very >> >>> > strange >> >>> > that I can not edit the file again. If I switch to another file and >> >>> > then switch back, I can edit it again. >> >>> > >> >>> > So I switch to eclipse+pydev, but I found the same thing happen. So >> >>> > I >> >>> > think it is not the problem of SPE or eclipse or pydev. >> >>> > >> >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it >> >>> > will >> >>> > not freeze any longer. >> >>> > >> >>> > Anybody can give me some hints? >> >>> > >> >>> > I am using Ubuntu 8.10 and updated to latest. All packages is >> >>> > installed through package manager. >> >>> >> >>> the only thing I googled related with it is >> >>> >> >>> >> >>> >> >>> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html >> >>> >> >>> but I think they are different. >> >>> >> >>> -- >> >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> >> >> >> -- >> >> Visit my blog at http://oddco.ca/zeroth/zblog >> > >> > >> > >> > -- >> > Best wishes to you. >> > >> > Yours sincerely >> > >> > Xiaohai Wei >> > wistoch at ustc.edu >> > >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> > > > > > -- > Best wishes to you. > > Yours sincerely > > Xiaohai Wei > wistoch at ustc.edu > From mk.fraggod at gmail.com Fri Jun 19 11:07:11 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:07:11 +0600 Subject: Retrieving column values by column name with MySQLdb References: Message-ID: <20090619210711.6a88ce7a@coercion> On Fri, 19 Jun 2009 15:46:46 +0100 jorma kala wrote: > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? Try this: db = MySQLdb.Connection(host=host,user=user,passwd=passwd,db=database) db.query(query) result = db.store_result() data = result.fetch_row(maxrows=0, how=1) -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From trinioler at gmail.com Fri Jun 19 11:07:29 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 08:07:29 -0700 Subject: Calling subprocess with arguments In-Reply-To: References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> I can't use communicate, as it waits for the child process to terminate. Basically it blocks. I'm trying to have dynamic communication between the python program, and vlc. On Fri, Jun 19, 2009 at 8:05 AM, Charles Yeomans wrote: > > On Jun 19, 2009, at 10:55 AM, Tyler Laing wrote: > > So no one has an answer for why passing flags and the values the flags need > through subprocess does not work? I would like an answer. I've examined all > the examples I could find online, which were all toy examples, and not > helpful to my problem. > > On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing wrote: > >> I've been trying any variation I can think of to do this properly, but >> here's my problem: >> >> I want to execute this command string: vlc -I rc >> >> This allows vlc to be controlled via a remote interface instead of the >> normal gui interface. >> >> Now, say, I try this from subprocess: >> >> >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, >> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >> But I don't get the remote interface. I get the normal gui interface. So >> how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', >> 'rc'] with executable set to 'vlc'. I've had shell=True, I've had >> shell=False. I've tried all these combinations. >> >> What am I doing wrong? >> > > You might try > > p = subprocess.Popen('vlc -I rc test.avi', ... > > Charles Yeomans > > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From mk.fraggod at gmail.com Fri Jun 19 11:13:55 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:13:55 +0600 Subject: Calling subprocess with arguments References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> Message-ID: <20090619211355.4491c5e8@coercion> On Fri, 19 Jun 2009 07:55:19 -0700 Tyler Laing wrote: > I want to execute this command string: vlc -I rc > > This allows vlc to be controlled via a remote interface instead of the > normal gui interface. > > Now, say, I try this from subprocess: > > >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False, > stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > But I don't get the remote interface. I get the normal gui interface. So > how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', > 'rc'] with executable set to 'vlc'. I've had shell=True, I've had > shell=False. I've tried all these combinations. > > What am I doing wrong? Write a simple script: #!/usr/bin/env python import sys open('/tmp/argv', 'w').write(repr(sys.argv)) And replace 'vlc' with a path to this script, then invoke it from a shell, compare the results. If it gets the right stuff, try the same with os.environ (prehaps vlc keeps socket location there, just like ssh/gpg-agents?). -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From mk.fraggod at gmail.com Fri Jun 19 11:21:42 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:21:42 +0600 Subject: Calling subprocess with arguments References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> Message-ID: <20090619212142.0cfd88db@coercion> On Fri, 19 Jun 2009 08:07:29 -0700 Tyler Laing wrote: > I can't use communicate, as it waits for the child process to terminate. > Basically it blocks. I'm trying to have dynamic communication between the > python program, and vlc. Unfortunately, subprocess module doesn't allow it out-of-the-box, but you can use fnctl calls to perform non-blocking reads/writes on it's pipes, like this: flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) After that, you can grab all the available data from the pipe at any given time w/o blocking. Try this recipe: http://code.activestate.com/recipes/576759/ -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From ethan at stoneleaf.us Fri Jun 19 11:24:05 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 19 Jun 2009 08:24:05 -0700 Subject: fastest native python database? In-Reply-To: <4A3AF9F0.7000009@stoneleaf.us> References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> <47ae2f90-9561-42f5-be6f-0d85c9765b85@h23g2000vbc.googlegroups.com> <4A3AF9F0.7000009@stoneleaf.us> Message-ID: <4A3BAD95.1020805@stoneleaf.us> Ethan Furman wrote: > This body part will be downloaded on demand. > Not sure what happened there... here's the text... Howdy, Pierre! I have also written a pure Python implementation of a database, one that uses dBase III or VFP 6 .dbf files. Any chance you could throw it into the mix to see how quickly (or slowly!) it runs? The code to run the same steps are (after an import dbf): #insert test table = dbf.Table('/tmp/tmptable', 'a N(6.0), b N(6.0), c C(100)') # if recs is list of tuples for rec in recs: table.append(rec) # elif recs is list of lists #for a, b, c in recs: # current = table.append() # current.a = a # current.b = b # current.c = c #select1 test for i in range(100): nb = len(table) if nb: avg = sum([record.b for record in table])/nb #select2 test for num_string in num_strings: records = table.find({'c':'%s'%num_string}, contained=True) nb = len(records) if nb: avg = sum([record.b for record in records])/nb #delete1 test for record in table: if 'fifty' in record.c: record.delete_record() # to purge the records would then require a table.pack() #delete2 test for rec in table: if 10 < rec.a < 20000: rec.delete_record() # again, permanent deletion requires a table.pack() #update1 test table.order('a') for i in range(100): # update description says 1000, update code is 100 records = table.query(python='10*%d <= a < 10*%d' %(10*i,10*(i+1))) for rec in records: rec.b *= 2 #update2 test records = table.query(python="0 <= a < 1000") for rec in records: rec.c = new_c[rec.a] Thanks, I hope! :) ~Ethan~ http://groups.google.com/group/python-dbase From Olivier.Darge at gmail.com Fri Jun 19 11:24:39 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 08:24:39 -0700 (PDT) Subject: multiprocessing and process run time References: Message-ID: On 19 juin, 16:40, Thomas Robitaille wrote: > Hi, > > I'm making use of the multiprocessing module, and I was wondering if there > is an easy way to find out how long a given process has been running for. > For example, if I do > > import multiprocessing as mp > import time > > def time_waster(): > ? ? time.sleep(1000) > > p = mp.Process(target=time_waster) > > p.start() > > Is there a way that I can then find how long p has been running for? I > figured I can use p.pid to get the PID of the process, but I'm not sure > where to go from there. Is there an easy way to do this? Something like : import multiprocessing as mp import time q_out = mp.Queue() def time_waster(qo): time.sleep(5) qo.put('stopped at ' + time.ctime(time.time())) def main(): p = mp.Process(target=time_waster, args=(q_out,)) print "start at: " + time.ctime(time.time()) p.start() p.join() print q_out.get() if __name__ == "__main__": main() The Queue (the one from multiprocessing ! don't mix with the Queue module) is used as a safe exchange object between the parent and all the child. Olivier From kushal.kumaran+python at gmail.com Fri Jun 19 11:25:51 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 19 Jun 2009 20:55:51 +0530 Subject: Retrieving column values by column name with MySQLdb In-Reply-To: References: Message-ID: <1e364c4e0906190825xf3e711ficca5efd715b7d789@mail.gmail.com> On Fri, Jun 19, 2009 at 8:16 PM, jorma kala wrote: > Hi, > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? > Code Snippet: > > ???? query="select * from employees" > ???? db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) > ???? cursor = db.cursor () > ???? cursor.execute (query) > ???? rows = cursor.fetchall () > > ??????for row in rows: > ?????????????? print row[0] > > > Instead of specifying the index of the row to retrieve the first column > (row[0]), I'd like to retrieve the value of the first column by column name. > Something like row.get('employee_id') > Is something of the sort possible with Mysqdb? > Thanks very much. > Use a DictCursor: import MySQLdb.cursors . . . cursor = db.cursor (MySQLdb.cursors.DictCursor) cursor.execute (query) rows = cursor.fetchall () for row in rows: print row['employee_id'] -- kushal From trinioler at gmail.com Fri Jun 19 11:28:17 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 08:28:17 -0700 Subject: Calling subprocess with arguments In-Reply-To: <20090619212142.0cfd88db@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> Message-ID: <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> Thanks mike, the idea that maybe some of the info isn't being passed is certainly interesting. Here's the output of os.environ and sys.argv: tyler at Surak:~$ cat environ {'XAUTHORITY': '/home/tyler/.Xauthority', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'ORBIT_SOCKETDIR': '/tmp/orbit-tyler', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'tyler', 'USER': 'tyler', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games', 'HOME': '/home/tyler', 'WINDOWPATH': '7', 'SSH_AGENT_PID': '3235', 'LANG': 'en_CA.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': 'c40b96e13a53e01daf91b3c24a37cc3f-1245418411.623618-1455422513', 'SESSION_MANAGER': 'local/Surak:/tmp/.ICE-unix/3078', 'SHLVL': '1', 'DISPLAY': ':0.0', 'WINDOWID': '62914615', 'COLUMNS': '80', 'GPG_AGENT_INFO': '/tmp/seahorse-WkObD8/S.gpg-agent:3260:1', 'USERNAME': 'tyler', 'GDM_XSERVER_LOCATION': 'local', 'GTK_RC_FILES': '/etc/gtk/gtkrc:/home/tyler/.gtkrc-1.2-gnome2', 'LINES': '24', 'SSH_AUTH_SOCK': '/tmp/keyring-glzV2L/socket.ssh', 'DESKTOP_SESSION': 'default', 'GDMSESSION': 'default', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-HXzG5Pt75p,guid=9fc00f8a914d6f800340ca634a3b93ac', '_': '/usr/bin/python', 'GTK_MODULES': 'canberra-gtk-module', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-glzV2L/socket', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GNOME_KEYRING_PID': '3065', '__GL_YIELD': 'NOTHING', 'GDM_LANG': 'en_CA.UTF-8', 'HISTCONTROL': 'ignoreboth', 'XDG_DATA_DIRS': '/usr/local/share/:/usr/share/:/usr/share/gdm/', 'PWD': '/home/tyler', 'COLORTERM': 'gnome-terminal', 'FROM_WRAPPER': 'yes', 'LS_COLORS': 'no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'} tyler at Surak:~$ cat argv ['./testsub.py', '-I', 'rc'] On Fri, Jun 19, 2009 at 8:21 AM, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 08:07:29 -0700 > Tyler Laing wrote: > > > I can't use communicate, as it waits for the child process to terminate. > > Basically it blocks. I'm trying to have dynamic communication between the > > python program, and vlc. > > Unfortunately, subprocess module doesn't allow it out-of-the-box, but > you can use fnctl calls to perform non-blocking reads/writes on it's > pipes, like this: > > flags = fcntl.fcntl(fd, fcntl.F_GETFL) > fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) > > After that, you can grab all the available data from the pipe at any > given time w/o blocking. > > Try this recipe: > > http://code.activestate.com/recipes/576759/ > > -- > Mike Kazantsev // fraggod.net > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Fri Jun 19 11:30:31 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 19 Jun 2009 08:30:31 -0700 (PDT) Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? References: <4A37BD14.5010807@arimaz.com> Message-ID: On Jun 19, 8:20?pm, Gerhard H?ring wrote: > Gabriel Rossetti wrote: > > Hello everyone, > > > I get an OperationalError with sqlite3 if I put the wrong column name, > > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it > > says : > > > " ? ? ? ?OperationalError > > ? ? ? ? ? ? ? ? ? ?Exception raised for errors that are related to the > > ? ? ? ? ? ?database's operation and not necessarily under the control > > ? ? ? ? ? ?of the programmer, e.g. an unexpected disconnect occurs, > > ? ? ? ? ? ?the data source name is not found, a transaction could not > > ? ? ? ? ? ?be processed, a memory allocation error occurred during > > ? ? ? ? ? ?processing, etc. ?It must be a subclass of DatabaseError. > > ? ? ? ? ? ? ? ? ?ProgrammingError > > ? ? ? ? ? ? ? ? ? ?Exception raised for programming errors, e.g. table not > > ? ? ? ? ? ?found or already exists, syntax error in the SQL > > ? ? ? ? ? ?statement, wrong number of parameters specified, etc. ?It > > ? ? ? ? ? ?must be a subclass of DatabaseError. > > " > > > and to me it sounds more like a programming error than an operational > > error. > > I agree. But I can't help you there. > > See _pysqlite_seterror() athttp://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c > > What I do is map SQLite error codes to DB-API exceptions. And SQLite > reports your error as generic SQLITE_ERROR, which is mapped to > OperationalError. Hi Gerhard, In http://www.sqlite.org/c3ref/prepare.html it says """When an error occurs, sqlite3_step() will return one of the detailed error codes or extended error codes. The legacy behavior was that sqlite3_step() would only return a generic SQLITE_ERROR result code and you would have to make a second call to sqlite3_reset() in order to find the underlying cause of the problem. With the "v2" prepare interfaces, the underlying reason for the error is returned immediately.""" Are you using sqlite3_prepare() or sqlite3_prepare_v2()? sqlite3_errcode() or sqlite3_extended_errcode()? Cheers, John From python.list at tim.thechases.com Fri Jun 19 11:32:32 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 19 Jun 2009 10:32:32 -0500 Subject: Retrieving column values by column name with MySQLdb In-Reply-To: References: Message-ID: <4A3BAF90.7020909@tim.thechases.com> jorma kala wrote: > Hi, > Is there a way of retrieving the value of columns in the rows returned by > fetchall, by column name instead of index on the row? > Code Snippet: > > query="select * from employees" > db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database) > cursor = db.cursor () > cursor.execute (query) > rows = cursor.fetchall () > > for row in rows: > print row[0] > > > Instead of specifying the index of the row to retrieve the first column > (row[0]), I'd like to retrieve the value of the first column by column name. > Something like row.get('employee_id') > Is something of the sort possible with Mysqdb? Mike gave you a good answer, though I think it's MySQL specific. For a more generic solution: cursor.execute(query) name_to_index = dict( (d[0], i) for i, d in enumerate(cursor.description) ) rows = cursor.fetchall() for row in rows: print row[name_to_index['employee_id']] Or in case you have lots of column-names, a simple lambda can ease the typing required: for row in rows: item = lambda col_name: row[name_to_index[col_name]] print item('employee_id') The built-in sqlite3 module also has a way to tell results to come back as a dict[1] Note in each case the column-name indexing is case-sensitive. Hope this helps, -tim [1] http://docs.python.org/library/sqlite3.html#sqlite3.Connection.row_factory From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 19 11:38:46 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Jun 2009 17:38:46 +0200 Subject: Decorator question (how to test if decorated function is in a class) In-Reply-To: References: Message-ID: <4a3bb0ee$0$3613$426a74cc@news.free.fr> Martin P. Hellwig a ?crit : > Hi all, > > I have been trying out to wrap my mind around the advantages of > decorators and thought I found a use in one of my experiments. (see code > after my sig). > > Although it works, I think it should be able to do it better. > My particular problem is that I want to remove an argument (say always > the first one) when the decorated function is called. > > However if the function is defined in a class the first argument is self > and thus the second argument should be removed. You'll have the same problem with a function defined outside a class then "attached" to the class, ie: def func(...): pass class Foo(object): pass Foo.meth = func > Since I like to have a more general DRY approach I want to test if the > decorated function is defined in a class or not thus knowing that the > first argument is self and must be preserved. Short answer: this makes no sense. > I tried different approaches but all didn't work and looked very > unpythonic (looking at the attributes, descriptors namespaces, id() of > the function, the first argument and the decorator itself). > > So is there a way to find out if the first argument is 'self' without > making a false positive if the first argument is a class instance passed > to a function? The solution to your problem is elsewhere... Read the doc about the descriptor protocol, and how it's implemented by the function type to "turn" functions into methods when they are looked up as attribute of a class... From mk.fraggod at gmail.com Fri Jun 19 11:47:52 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 21:47:52 +0600 Subject: Retrieving column values by column name with MySQLdb References: <4A3BAF90.7020909@tim.thechases.com> Message-ID: <20090619214752.2e84e737@coercion> On Fri, 19 Jun 2009 10:32:32 -0500 Tim Chase wrote: > Mike gave you a good answer, though I think it's MySQL specific. I don't have to deal with MySQL frequently but I've remembered that I used got the fields out somehow, and now, looking at the code, I wonder myself, why "how" is 1 and wtf is this "how", anyway!? ;) I can't seem to find any mention of such methods in documentation and even python source, guess they are implemented directly in underlying C lib. Hope I learned to abstract from such syntax since then, I sure do... -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From stefan_ml at behnel.de Fri Jun 19 11:54:32 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Jun 2009 17:54:32 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. You might want to read about "The Problem with Threads": http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf and then decide to switch to an appropriate concurrency model for your use case. Stefan From tjreedy at udel.edu Fri Jun 19 11:58:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 11:58:15 -0400 Subject: Is this pylint error message valid or silly? In-Reply-To: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> References: <5vM_l.1152$Rb6.195@flpi147.ffdc.sbc.com> Message-ID: Matthew Wilson wrote: > Thanks for the feedback. I think I should have used a more obvious > string in my original example and a more descriptive parameter name. > > So, pretend that instead of > > c="today" > > I wrote > > record_date="defaults to today's date". > > I know my way is unorthodox, Which is fine. Just do not by surprised when a fake default fakes out pylint, which by its nature, must embody the orthodoxy of its author ;-) To win general acceptance, that in turn must match the orthodoxy of the general audience. but I think it is a little bit more obvious > to the reader than > > record_date=None > > The None is a signal to use a default value, but that is only apparent > after reading the code. > > Thanks again for the comments. > > Matt From mk.fraggod at gmail.com Fri Jun 19 12:00:28 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:00:28 +0600 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> Message-ID: <20090619220028.201b1484@coercion> On Fri, 19 Jun 2009 08:28:17 -0700 Tyler Laing wrote: > Thanks mike, the idea that maybe some of the info isn't being passed is > certainly interesting. > > Here's the output of os.environ and sys.argv: > ... I'm afraid these doesn't make much sense without the output from the second results, from py itself. My suggestion was just to compare them - pop the py shell, eval the outputs into two sets, do the diff and you'll see it at once. If there's an empty set then I guess it's pretty safe to assume that python creates subprocess in the same way the shell does. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From tjreedy at udel.edu Fri Jun 19 12:01:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 12:01:52 -0400 Subject: Integer Division In-Reply-To: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> References: <1a7951080906190022g3bf6ccfbjaa4c2ab640132c17@mail.gmail.com> Message-ID: Anjanesh Lekshminarayanan wrote: >>>> a = 1 >>>> b = 25 >>>> a / b > 0 >>>> float(a) / b > 0.040000000000000001 > >>>> from __future__ import division >>>> a = 1 >>>> b = 25 >>>> a / b > 0.040000000000000001 > > In what simple way can I get just 0.04 ? Short answer: use 3.1: >>> 1//25 0 >>> 1/25 0.04 ;-) But you should really try to understand the answers others gave. tjr From mk.fraggod at gmail.com Fri Jun 19 12:09:20 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:09:20 +0600 Subject: Calling subprocess with arguments In-Reply-To: <20090619220028.201b1484@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> Message-ID: <20090619220920.3aa68630@coercion> On Fri, 19 Jun 2009 22:00:28 +0600 Mike Kazantsev wrote: > On Fri, 19 Jun 2009 08:28:17 -0700 > Tyler Laing wrote: > > > Thanks mike, the idea that maybe some of the info isn't being passed is > > certainly interesting. > > > > Here's the output of os.environ and sys.argv: > > > ... > > I'm afraid these doesn't make much sense without the output from the > second results, from py itself. My suggestion was just to compare them > - pop the py shell, eval the outputs into two sets, do the diff and > you'll see it at once. > If there's an empty set then I guess it's pretty safe to assume that > python creates subprocess in the same way the shell does. Just thought of one more really simple thing I've missed: vlc might expect it's remote to work with tty, so when py shoves it a pipe instead, it automatically switches to non-interactive mode. You can remedy that a bit by superclassing subprocess.Popen, replacing pipes with pty, but they are quite hard to work with, prehaps pexpect module would be of some use there: http://pypi.python.org/pypi/pexpect/ -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From tjreedy at udel.edu Fri Jun 19 12:15:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2009 12:15:02 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: Jure Erzno?nik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. > Effectively, this causes the interpreter to utilize one core when > threading is not used and .95 of a core when threading is utilized. Python does not have (or not have) GIL. It is an implementation issue. CPython uses it, to good effect. > Is there any work in progess on core Python modules that will > permanently resolve this issue? > Is there any other way to work around the issue aside from forking new > processes or using something else? Use one of the other implementations. Jython, IronPython, Pypy, ??? From wells at submute.net Fri Jun 19 12:16:38 2009 From: wells at submute.net (Wells Oliver) Date: Fri, 19 Jun 2009 11:16:38 -0500 Subject: n00b confusion re: local variable referenced before assignment error Message-ID: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Writing a class which essentially spiders a site and saves the files locally. On a URLError exception, it sleeps for a second and tries again (on 404 it just moves on). The relevant bit of code, including the offending method: class Handler(threading.Thread): def __init__(self, url): threading.Thread.__init__(self) self.url = url def save(self, uri, location): try: handler = urllib2.urlopen(uri) except urllib2.HTTPError, e: if e.code == 404: return else: print "retrying %s (HTTPError)" % uri time.sleep(1) self.save(uri, location) except urllib2.URLError, e: print "retrying %s" % uri time.sleep(1) self.save(uri, location) if not os.path.exists(os.path.dirname(location)): os.makedirs(os.path.dirname(location)) file = open(location, "w") file.write(handler.read()) file.close() ... But what I am seeing is that after a retry (on catching a URLError exception), I see bunches of "UnboundLocalError: local variable 'handler' referenced before assignment" errors on line 38, which is the "file.write(handler.read())" line.. What gives? -- Wells Oliver wells at submute.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From garrickp at gmail.com Fri Jun 19 12:30:09 2009 From: garrickp at gmail.com (Falcolas) Date: Fri, 19 Jun 2009 09:30:09 -0700 (PDT) Subject: n00b confusion re: local variable referenced before assignment error References: Message-ID: <3d6cac13-48c9-4592-86c3-c4019386e460@j12g2000vbl.googlegroups.com> On Jun 19, 10:16?am, Wells Oliver wrote: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again (on > 404 it just moves on). The relevant bit of code, including the offending > method: > > [snip] > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? 'Handler' is only assigned in the try statement, so if you error into your exception clause, nothing will have been bound to the name 'handler', causing the exception you're seeing. From trinioler at gmail.com Fri Jun 19 12:30:48 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 09:30:48 -0700 Subject: Calling subprocess with arguments In-Reply-To: <20090619220920.3aa68630@coercion> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> <20090619220920.3aa68630@coercion> Message-ID: <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> Sorry, XD. I'll ask the VLC people if they happen to know why VLC won't open up the remote interface. -Tyler On Fri, Jun 19, 2009 at 9:09 AM, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 22:00:28 +0600 > Mike Kazantsev wrote: > > > On Fri, 19 Jun 2009 08:28:17 -0700 > > Tyler Laing wrote: > > > > > Thanks mike, the idea that maybe some of the info isn't being passed is > > > certainly interesting. > > > > > > Here's the output of os.environ and sys.argv: > > > > > ... > > > > I'm afraid these doesn't make much sense without the output from the > > second results, from py itself. My suggestion was just to compare them > > - pop the py shell, eval the outputs into two sets, do the diff and > > you'll see it at once. > > If there's an empty set then I guess it's pretty safe to assume that > > python creates subprocess in the same way the shell does. > > Just thought of one more really simple thing I've missed: vlc might > expect it's remote to work with tty, so when py shoves it a pipe > instead, it automatically switches to non-interactive mode. > > You can remedy that a bit by superclassing subprocess.Popen, replacing > pipes with pty, but they are quite hard to work with, prehaps pexpect > module would be of some use there: > > http://pypi.python.org/pypi/pexpect/ > > -- > Mike Kazantsev // fraggod.net > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Jun 19 12:30:48 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 19 Jun 2009 18:30:48 +0200 Subject: n00b confusion re: local variable referenced before assignment error In-Reply-To: References: Message-ID: <7a1spoF1t7fovU1@mid.uni-berlin.de> Wells Oliver schrieb: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again > (on 404 it just moves on). The relevant bit of code, including the > offending method: > > class Handler(threading.Thread): > def __init__(self, url): > threading.Thread.__init__(self) > self.url = url > > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > > ... > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable > 'handler' referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. Your code defines the name handler only if the urllib2.urlopen is successful. But you try later to access it uncoditionally, and of course that fails. You need to put the file-stuff after the urlopen, inside the try-except. Also note that python has no tail-recursion-optimization, so your method will recurse and at some point exhaust the stack if there are many errors. You should consider writing it rather as while-loop, with breaking out of it when the page could be fetched. Diez From mk.fraggod at gmail.com Fri Jun 19 12:36:38 2009 From: mk.fraggod at gmail.com (Mike Kazantsev) Date: Fri, 19 Jun 2009 22:36:38 +0600 Subject: n00b confusion re: local variable referenced before assignment error References: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Message-ID: <20090619223638.331fea20@coercion> On Fri, 19 Jun 2009 11:16:38 -0500 Wells Oliver wrote: > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? Why not? Try fails, except calls retry and after the retry code execution continues to the undefined "handler", since the try has failed here. You might want to insert return or avoid (possibly endless) recursion altogether - just wrap it into while loop with some counter (aka max_tries). Also, you can get rid of code duplication by catching some basic urllib2 exception, then checking if it's urllib2.HTTPError and it's code is 404, retrying ("continue" for the loop case) otherwise. -- Mike Kazantsev // fraggod.net -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 205 bytes Desc: not available URL: From trinioler at gmail.com Fri Jun 19 12:37:50 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 09:37:50 -0700 Subject: Calling subprocess with arguments In-Reply-To: <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> References: <3618a6e10906181940u44c6e753r1f86946eabffb68c@mail.gmail.com> <3618a6e10906190755n214fcf05y1d71a67064146a57@mail.gmail.com> <3618a6e10906190807h5f2c7fd9q81df0f1a26ef9bf4@mail.gmail.com> <20090619212142.0cfd88db@coercion> <3618a6e10906190828v5af2df6atdbd32ab142df2d82@mail.gmail.com> <20090619220028.201b1484@coercion> <20090619220920.3aa68630@coercion> <3618a6e10906190930u5ec539e8p73bd189b3dfc68c2@mail.gmail.com> Message-ID: <3618a6e10906190937wb89ed9es93f0cad4ab1d9a3d@mail.gmail.com> It appears to be an issue specifically with VLC, not subprocess. Thank you guys. The remote interface works through sockets, which is perfectly fine... if I create a local socket, I can have it connect to the socket with command line arguments. On Fri, Jun 19, 2009 at 9:30 AM, Tyler Laing wrote: > Sorry, XD. I'll ask the VLC people if they happen to know why VLC won't > open up the remote interface. > > -Tyler > > On Fri, Jun 19, 2009 at 9:09 AM, Mike Kazantsev wrote: > >> On Fri, 19 Jun 2009 22:00:28 +0600 >> Mike Kazantsev wrote: >> >> > On Fri, 19 Jun 2009 08:28:17 -0700 >> > Tyler Laing wrote: >> > >> > > Thanks mike, the idea that maybe some of the info isn't being passed >> is >> > > certainly interesting. >> > > >> > > Here's the output of os.environ and sys.argv: >> > > >> > ... >> > >> > I'm afraid these doesn't make much sense without the output from the >> > second results, from py itself. My suggestion was just to compare them >> > - pop the py shell, eval the outputs into two sets, do the diff and >> > you'll see it at once. >> > If there's an empty set then I guess it's pretty safe to assume that >> > python creates subprocess in the same way the shell does. >> >> Just thought of one more really simple thing I've missed: vlc might >> expect it's remote to work with tty, so when py shoves it a pipe >> instead, it automatically switches to non-interactive mode. >> >> You can remedy that a bit by superclassing subprocess.Popen, replacing >> pipes with pty, but they are quite hard to work with, prehaps pexpect >> module would be of some use there: >> >> http://pypi.python.org/pypi/pexpect/ >> >> -- >> Mike Kazantsev // fraggod.net >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From Olivier.Darge at gmail.com Fri Jun 19 12:50:43 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 09:50:43 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 16:16, Martin von Loewis If you know that your (C) code is thread safe on its own, you can > release the GIL around long-running algorithms, thus using as many > CPUs as you have available, in a single process. what do you mean ? Cpython can't benefit from multi-core without multiple processes. Olivier From trinioler at gmail.com Fri Jun 19 13:05:10 2009 From: trinioler at gmail.com (Tyler Laing) Date: Fri, 19 Jun 2009 10:05:10 -0700 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3618a6e10906191005i580eec03sd7be3a7a1ab6ba96@mail.gmail.com> CPython itself can't... but the c extension can. Mine did. On Fri, Jun 19, 2009 at 9:50 AM, OdarR wrote: > On 19 juin, 16:16, Martin von Loewis > If you know that your (C) code is thread safe on its own, you can > > release the GIL around long-running algorithms, thus using as many > > CPUs as you have available, in a single process. > > what do you mean ? > > Cpython can't benefit from multi-core without multiple processes. > > Olivier > -- > http://mail.python.org/mailman/listinfo/python-list > -- Visit my blog at http://oddco.ca/zeroth/zblog -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Fri Jun 19 13:13:12 2009 From: skip at pobox.com (skip at pobox.com) Date: Fri, 19 Jun 2009 12:13:12 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <19003.50984.827956.602333@montanaro.dyndns.org> >> If you know that your (C) code is thread safe on its own, you can >> release the GIL around long-running algorithms, thus using as many >> CPUs as you have available, in a single process. Olivier> what do you mean ? Olivier> Cpython can't benefit from multi-core without multiple Olivier> processes. It can, precisely as Martin indicated. Only one thread at a time can hold the GIL. That doesn't mean that multiple threads can't execute. Suppose you have two threads, one of which winds up executing some bit of C code which doesn't mess with the Python run-time at all (say, a matrix multiply). Before launching into the matrix multiply, the extension module releases the GIL then performs the multiply. With the GIL released another thread can acquire it. Once the multiply finishes the first thread needs to reacquire the GIL before executing any calls into the Python runtime or returning. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From Olivier.Darge at gmail.com Fri Jun 19 14:08:31 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 11:08:31 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 19:13, s... at pobox.com wrote: > ? ? Olivier> what do you mean ? > > ? ? Olivier> Cpython can't benefit from multi-core without multiple > ? ? Olivier> processes. > > It can, precisely as Martin indicated. ?Only one thread at a time can hold > the GIL. ?That doesn't mean that multiple threads can't execute. ?Suppose I don't say multiple threads can't execute....(?). I say that with the Python library, I don't see (yet) benefit with multiple threads *on* multiple CPU/core. Ever seen this recent video/presentation ? : http://blip.tv/file/2232410 http://www.dabeaz.com/python/GIL.pdf > you have two threads, one of which winds up executing some bit of C code > which doesn't mess with the Python run-time at all (say, a matrix multiply). I don't know how to do that with common Python operations... Only one thread will be really running at a time in memory (meanwhile other thread are waiting). Are you refering to a specialized code ? > Before launching into the matrix multiply, the extension module releases the > GIL then performs the multiply. ?With the GIL released another thread can > acquire it. ?Once the multiply finishes the first thread needs to reacquire > the GIL before executing any calls into the Python runtime or returning. I don't see such improvement in the Python library, or maybe you can indicate us some meaningfull example...? I currently only use CPython, with PIL, Reportlab...etc. I don't see improvement on a Core2duo CPU and Python. How to proceed (following what you wrote) ? A contrario, I saw *real* improvement on parallel computing with the Py 2.6 multiprocessing module. Olivier From amita.ekbote at gmail.com Fri Jun 19 14:17:24 2009 From: amita.ekbote at gmail.com (Amita Ekbote) Date: Fri, 19 Jun 2009 13:17:24 -0500 Subject: Convert hash to struct Message-ID: Hello, I am retrieving values from a database in the form of a dictionary so I can access the values as d['column'] and I was wondering if there is a way to convert the hash to a struct like format so i can just say d.column. Makes it easier to read and understand. Thanks Amita -- Amita Ekbote From lie.1296 at gmail.com Fri Jun 19 14:42:49 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 18:42:49 GMT Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: Lawrence D'Oliveiro wrote: > In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan > wrote: > >> Yeah, it might be possible to just mv the file from outside, but not >> being able to enter a directory just because you've got too many files >> in it is kind of silly. > > Sounds like a problem with your file/directory-manipulation tools. > try an `ls` on a folder with 10000+ files. See how long is needed to print all the files. Ok, now pipe ls to less, take three days to browse through all the filenames to locate the file you want to see. The file manipulation tool may not have problems with it; it's the user that would have a hard time sorting through the huge amount of files. Even with glob and grep, some types of queries are just too difficult or is plain silly to write a full fledged one-time use program just to locate a few files. From ullrich at math.okstate.edu Fri Jun 19 14:43:11 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Fri, 19 Jun 2009 13:43:11 -0500 Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: Evidently my posts are appearing, since I see replies. I guess the question of why I don't see the posts themselves \is ot here... On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson wrote: >On Jun 18, 7:26?pm, David C. Ullrich wrote: >> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >> >Right. ?Or rather, you treat it as the image of such a function, >> >if you're being careful to distinguish the curve (a subset >> >of R^2) from its parametrization (a continuous function >> >R -> R**2). ?It's the parametrization that's uniformly >> >continuous, not the curve, >> >> Again, it doesn't really matter, but since you use the phrase >> "if you're being careful": In fact what you say is exactly >> backwards - if you're being careful that subset of the plane >> is _not_ a curve (it's sometimes called the "trace" of the curve". > >Darn. So I've been getting it wrong all this time. Oh well, >at least I'm not alone: > >"De?nition 1. A simple closed curve J, also called a >Jordan curve, is the image of a continuous one-to-one >function from R/Z to R2. [...]" > >- Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. > >"We say that Gamma is a curve if it is the image in >the plane or in space of an interval [a, b] of real >numbers of a continuous function gamma." > >- Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). > >Perhaps your definition of curve isn't as universal or >'official' as you seem to think it is? Perhaps not. I'm very surprised to see those definitions; I've been a mathematician for 25 years and I've never seen a curve defined a subset of the plane. Hmm. You left out a bit in the first definition you cite: "A simple closed curve J, also called a Jordan curve, is the image of a continuous one-to-one function from R/Z to R2. We assume that each curve comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z the time parameter. By abuse of notation, we write J(t) in R2 instead of phi_j (t), using the same notation for the function phi_J and its image J." Close to sounding like he can't decide whether J is a set or a function... Then later in the same paper "Definition 2. A polygon is a Jordan curve that is a subset of a finite union of lines. A polygonal path is a continuous function P : [0, 1] ->? R2 that is a subset of a finite union of lines. It is a polygonal arc, if it is 1 . 1." By that definition a polygonal path is not a curve. Worse: A polygonal path is a function from [0,1] to R^2 _that is a subset of a finite union of lines_. There's no such thing - the _image_ of such a function can be a subset of a finite union of lines. Not that it matters, but his defintion of "polygonal path" is, _if_ we're being very careful, self-contradictory. So I don't think we can count that paper as a suitable reference for what the _standard_ definitions are; the standard definitions are not self-contradictory this way. Then the second definition you cite: Amazon says the prerequisites are two years of calculus. The stanard meaning of log is log base e, even though it means log base 10 in calculus. >Mark From darcy at druid.net Fri Jun 19 14:49:09 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Jun 2009 14:49:09 -0400 Subject: Convert hash to struct In-Reply-To: References: Message-ID: <20090619144909.94a9a127.darcy@druid.net> On Fri, 19 Jun 2009 13:17:24 -0500 Amita Ekbote wrote: > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. Are there enough clues here? class MyDict(dict): def __getattribute__(self, name): return dict.__getattribute__(self, name) def __getattr__(self, name): return self.get(name, 42) x = MyDict({'a': 1, 'b': 2, 'values': 3}) print x.a print x.z print x.values Big question - what should the last line display? If you expect "3" and not "" then you need to reconsider the above implementation. Thinking about the question may change your opinion about this being a good idea after all. -- 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 lie.1296 at gmail.com Fri Jun 19 14:52:34 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 18:52:34 GMT Subject: Convert hash to struct In-Reply-To: References: Message-ID: Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > You may be able to update the class' dict: >>> class MyDB(object): ... def __init__(self, di): ... self.__dict__.update(di) ... >>> di = {'a':10, 'b': 20} >>> d = MyDB(di) >>> d <__main__.MyDB object at 0x7f756b0d0b90> >>> d.a 10 >>> d.b 20 but this might be a security risk, if you cannot trust the database or its content. It is much preferrable to use something like: >>> class MyDB(object): ... def __init__(self, di): ... self.a = di['a'] ... self.b = di['b'] since you now have full control of what collumns can go in and whatnot. From me at gustavonarea.net Fri Jun 19 15:02:44 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Fri, 19 Jun 2009 12:02:44 -0700 (PDT) Subject: Rich comparison methods don't work in sets? Message-ID: Hello, everyone. I've noticed that if I have a class with so-called "rich comparison" methods (__eq__, __ne__, etc.), when its instances are included in a set, set.__contains__/__eq__ won't call the .__eq__ method of the elements and thus the code below: """ obj1 = RichComparisonClass() obj2 = RichComparisonClass() set1 = set([obj1]) set2 = set([obj2]) if obj1 == obj2: print "Objects 1 and 2 are equivalent" else: print "Objects 1 and 2 aren't equivalent" if set1 == set2: print "Sets 1 and 2 are equivalent" else: print "Sets 1 and 2 aren't equivalent" """ Would output: """ Objects 1 and 2 are equivalent Sets 1 and 2 aren't equivalent """ instead of: """ Objects 1 and 2 are equivalent Sets 1 and 2 are equivalent """ How can I work around this? The only solution that comes to my mind is to write a function like this: """ def same_sets(set1, set2): if len(set1) != len(set2): return False for element1 in set1: found = False for element2 in set2: if element1 == element2: found = True break; if not found: return False return True """ But I see it pretty ugly; also I'd also have to roll out my own "contains" (e.g., `element in set`) function. I expect and hope there's a pythonic way to do this. Does it exist? Thanks in advance! From lists at cheimes.de Fri Jun 19 15:05:51 2009 From: lists at cheimes.de (Christian Heimes) Date: Fri, 19 Jun 2009 21:05:51 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: OdarR wrote: > I don't see such improvement in the Python library, or maybe you can > indicate us some meaningfull example...? > > I currently only use CPython, with PIL, Reportlab...etc. > I don't see improvement on a Core2duo CPU and Python. How to proceed > (following what you wrote) ? I've seen a single Python process using the full capacity of up to 8 CPUs. The application is making heavy use of lxml for large XSL transformations, a database adapter and my own image processing library based upon FreeImage. Of course both lxml and my library are written with the GIL in mind. They release the GIL around every call to C libraries that don't touch Python objects. PIL releases the lock around ops as well (although it took me a while to figure it out because PIL uses its own API instead of the standard macros). reportlab has some optional C libraries that increase the speed, too. Are you using them? By the way threads are evil (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and not *the* answer to concurrency. Christian From pavlovevidence at gmail.com Fri Jun 19 15:08:55 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Jun 2009 12:08:55 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <6f90a341-c1a5-4fa7-9642-e48b3bf4f604@j12g2000vbl.googlegroups.com> On Jun 19, 6:53?am, Ben Charrow wrote: > Jure Erzno?nik wrote: > > See here for introduction: > >http://groups.google.si/group/comp.lang.python/browse_thread/thread/3... > > > Digging through my problem, I discovered Python isn't exactly thread > > safe and to solve the issue, there's this Global Interpreter Lock > > (GIL) in place. > > Effectively, this causes the interpreter to utilize one core when > > threading is not used and .95 of a core when threading is utilized. > > > Is there any work in progess on core Python modules that will > > permanently resolve this issue? > > Is there any other way to work around the issue aside from forking new > > processes or using something else? > > There is a group of people working on an alternative implementation to Python > that, among other things, will not have a GIL:http://code.google.com/p/unladen-swallow/ That's not a foregone conclusion. Well it's not a foregone conclusion that unladen-swallow will succeed at all, but even if it does they only say they intend to remove the GIL, not that they necessarily will. The GIL actually "solves" two problems: the overhead of synchronizing reference counts, and the difficulty of writing threaded extensions. The unladen-swallow team only address the first problem in their plans. So, even if they do remove the GIL, I doubt GvR will allow it to be merged back into CPython unless makes extensions are just as easy to write. That is something I have serious doubts they can pull off. Which means a GIL-less unladen-swallow is likely to end being another fork like IronPython and Jython. Those projects already have no GIL. Carl Banks From charles at declareSub.com Fri Jun 19 15:13:08 2009 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 19 Jun 2009 15:13:08 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: > Evidently my posts are appearing, since I see replies. > I guess the question of why I don't see the posts themselves > \is ot here... > > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson > wrote: > >> On Jun 18, 7:26 pm, David C. Ullrich >> wrote: >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >>>> Right. Or rather, you treat it as the image of such a function, >>>> if you're being careful to distinguish the curve (a subset >>>> of R^2) from its parametrization (a continuous function >>>> R -> R**2). It's the parametrization that's uniformly >>>> continuous, not the curve, >>> >>> Again, it doesn't really matter, but since you use the phrase >>> "if you're being careful": In fact what you say is exactly >>> backwards - if you're being careful that subset of the plane >>> is _not_ a curve (it's sometimes called the "trace" of the curve". >> >> Darn. So I've been getting it wrong all this time. Oh well, >> at least I'm not alone: >> >> "De?nition 1. A simple closed curve J, also called a >> Jordan curve, is the image of a continuous one-to-one >> function from R/Z to R2. [...]" >> >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. >> >> "We say that Gamma is a curve if it is the image in >> the plane or in space of an interval [a, b] of real >> numbers of a continuous function gamma." >> >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). >> >> Perhaps your definition of curve isn't as universal or >> 'official' as you seem to think it is? > > Perhaps not. I'm very surprised to see those definitions; I've > been a mathematician for 25 years and I've never seen a > curve defined a subset of the plane. I have. > > > Hmm. You left out a bit in the first definition you cite: > > "A simple closed curve J, also called a Jordan curve, is the image > of a continuous one-to-one function from R/Z to R2. We assume that > each curve > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z > the time > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j > (t), using the > same notation for the function phi_J and its image J." > > > Close to sounding like he can't decide whether J is a set or a > function... On the contrary, I find this definition to be written with some care. > Then later in the same paper > > "Definition 2. A polygon is a Jordan curve that is a subset of a > finite union of > lines. A polygonal path is a continuous function P : [0, 1] ->? R2 > that is a subset of > a finite union of lines. It is a polygonal arc, if it is 1 . 1." > These are a bit too casual for me as well... > > By that definition a polygonal path is not a curve. > > Worse: A polygonal path is a function from [0,1] to R^2 > _that is a subset of a finite union of lines_. There's no > such thing - the _image_ of such a function can be a > subset of a finite union of lines. > > Not that it matters, but his defintion of "polygonal path" > is, _if_ we're being very careful, self-contradictory. > So I don't think we can count that paper as a suitable > reference for what the _standard_ definitions are; > the standard definitions are not self-contradictory this way. Charles Yeomans From quarl at 8166.clguba.z.quarl.org Fri Jun 19 15:21:53 2009 From: quarl at 8166.clguba.z.quarl.org (Karl Chen) Date: Fri, 19 Jun 2009 15:21:53 -0400 Subject: timeit and __future__ Message-ID: I wanted to time something that uses with_statement, in python2.5. Importing __future__ in the statement or the setup doesn't work since it's not the beginning of the code being compiled. Other than using a separate module, I could only come up with this: timeit.template = 'from __future__ import with_statement\n' + timeit.template timeit should directly support importing __future__ stuff... From matt at tplus1.com Fri Jun 19 15:26:03 2009 From: matt at tplus1.com (Matthew Wilson) Date: Fri, 19 Jun 2009 19:26:03 GMT Subject: Rich comparison methods don't work in sets? References: Message-ID: On Fri 19 Jun 2009 03:02:44 PM EDT, Gustavo Narea wrote: > Hello, everyone. > > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() > obj2 = RichComparisonClass() What does >>> obj1 is obj2 return? I don't know anything about set internals. Matt From sakradevanamindra at gmail.com Fri Jun 19 15:26:36 2009 From: sakradevanamindra at gmail.com (Leo Brugud) Date: Fri, 19 Jun 2009 12:26:36 -0700 (PDT) Subject: dynamically associate radio buttons with droplists Message-ID: Hi Folks, Not being very familiar with python, nor with cgi/http, I intend to have 3 of buttons in a webpage, each of them is associate with a file (so I have 3 files, too) What I would like to have is, when users choose a button, the droplist update automatically to load the contents of the associated file. Can someone educate me the approach of this? Thanks From davea at ieee.org Fri Jun 19 15:34:23 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 15:34:23 -0400 Subject: n00b confusion re: local variable referenced before assignment error In-Reply-To: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> References: <3f1a902d0906190916w6e471deav8858df9d024642a1@mail.gmail.com> Message-ID: <4A3BE83F.8070004@ieee.org> Wells Oliver wrote: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again (on > 404 it just moves on). The relevant bit of code, including the offending > method: > > class Handler(threading.Thread): > def __init__(self, url): > threading.Thread.__init__(self) > self.url = url > > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: > return > else: > print "retrying %s (HTTPError)" % uri > time.sleep(1) > self.save(uri, location) > except urllib2.URLError, e: > print "retrying %s" % uri > time.sleep(1) > self.save(uri, location) > > if not os.path.exists(os.path.dirname(location)): > os.makedirs(os.path.dirname(location)) > > file = open(location, "w") > file.write(handler.read()) > file.close() > > ... > > But what I am seeing is that after a retry (on catching a URLError > exception), I see bunches of "UnboundLocalError: local variable 'handler' > referenced before assignment" errors on line 38, which is the > "file.write(handler.read())" line.. > > What gives? > > Your save() method is recursive in the case of that error, which is a poor excuse for what should have been a loop. You should have some retry depth check, just in case you get hundreds of such errors on the same site. But ignoring that issue, the specific symptom is caused when returning from the recursive call. You still fall through to the end of your outer method call, and try to write stuff from that handler (also wiping out the file "location" in the process). Without a handler, that causes an exception. So you should follow those calls to self.save() with return's. Much better would be to write a loop in the first place, and break out of the loop when you succeed. Then the flow is much easier to follow, and you can easily avoid the risk of looping forever, nor of running out of stack space. Something like (untested): def save(self, uri, location): for tries in xrange(10): #try up to 10 times try: handler = urllib2.urlopen(uri) except urllib2.HTTPError, e: if e.code == 404: break else: print "retrying %s (HTTPError)" % uri time.sleep(1) continue except urllib2.URLError, e: print "retrying %s" % uri time.sleep(1) continue if not os.path.exists(os.path.dirname(location)): os.makedirs(os.path.dirname(location)) file = open(location, "w") file.write(handler.read()) file.close() break Other refinements are possible, of course. For example, if you have any cleanup code at the end you may need an additional flag variable to tell whether you've succeeded or not. From __peter__ at web.de Fri Jun 19 15:37:17 2009 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Jun 2009 21:37:17 +0200 Subject: Rich comparison methods don't work in sets? References: Message-ID: Gustavo Narea wrote: > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() How is RichComparisonClass implemented? Did you provide a __hash__() method such that obj1 == obj2 implies hash(obj1) == hash(obj2)? This is necessary for instances of the class to work properly with sets and dicts. Peter From pruebauno at latinmail.com Fri Jun 19 15:38:42 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:38:42 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt >>> def midnight_next_day(initial_time=None): if initial_time == "use today's date": initial_time = datetime.now() return initial_time.date() + timedelta(days=1) >>> midnight_next_day() Traceback (most recent call last): File "", line 1, in midnight_next_day() File "", line 6, in midnight_next_day return initial_time.date() + timedelta(days=1) AttributeError: 'NoneType' object has no attribute 'date' >>> From dickinsm at gmail.com Fri Jun 19 15:40:36 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 19 Jun 2009 12:40:36 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> On Jun 19, 7:43?pm, David C. Ullrich wrote: > Evidently my posts are appearing, since I see replies. > I guess the question of why I don't see the posts themselves > \is ot here... Judging by this thread, I'm not sure that much is off-topic here. :-) > Perhaps not. I'm very surprised to see those definitions; I've > been a mathematician for 25 years and I've never seen a > curve defined a subset of the plane. That in turn surprises me. I've taught multivariable calculus courses from at least three different texts in three different US universities, and as far as I recall a 'curve' was always thought of as a subset of R^2 or R^3 in those courses (though not always with explicit definitions, since that would be too much to hope for with that sort of text). Here's Stewart's 'Calculus', p658: "Examples 2 and 3 show that different sets of parametric equations can represent the same curve. Thus we distinguish between a *curve*, which is a set of points, and a *parametric curve*, in which the points are traced in a particular way." Again as far as I remember, the rest of the language in those courses (e.g., 'level curve', 'curve as the intersection of two surfaces') involves thinking of curves as subsets of R^2 or R^3. Certainly I'll agree that it's then necessary to parameterize the curve before being able to do anything useful with it. [Standard question when teaching multivariable calculus: "Okay, so we've got a curve. What's the first thing we do with it?" Answer, shouted out from all the (awake) students: "PARAMETERIZE IT!" (And then calculate its length/integrate the given vector field along it/etc.) Those were the days...] A Google Books search even turned up some complex analysis texts where the word 'curve' is used to mean a subset of the plane; check out the book by Ian Stewart and David Orme Tall, 'Complex Analysis: a Hitchhiker's Guide to the Plane': they distinguish 'curves' (subset of the complex plane) from 'paths' (functions from a closed bounded interval to the complex plane). > "Definition 2. A polygon is a Jordan curve that is a subset of a > finite union of > lines. A polygonal path is a continuous function P : [0, 1] ->? R2 > that is a subset of > a finite union of lines. It is a polygonal arc, if it is 1 . 1." > > By that definition a polygonal path is not a curve. Right. I'm much more willing to accept 'path' as standard terminology for a function [a, b] -> (insert_favourite_space_here). > Not that it matters, but his defintion of "polygonal path" > is, _if_ we're being very careful, self-contradictory. Agreed. Surprising, coming from Hales; he must surely rank amongst the more careful mathematicians out there. > So I don't think we can count that paper as a suitable > reference for what the _standard_ definitions are; > the standard definitions are not self-contradictory this way. I just don't believe there's any such thing as 'the standard definition' of a curve. I'm happy to believe that in complex analysis and differential geometry it's common to define a curve to be a function. But in general I'd suggest that it's one of those terms that largely depends on context, and should be defined clearly when it's not totally obvious from the context which definition is intended. For example, for me, more often than not, a curve is a 1-dimensional scheme over a field k (usually *not* algebraically closed), that's at least some of {geometrically reduced, geometrically irreducible, proper, smooth}. That's a far cry either from a subset of an affine space or from a parametrization by an interval. > Then the second definition you cite: Amazon says the > prerequisites are two years of calculus. The stanard > meaning of log is log base e, even though means > log base 10 in calculus. Sorry, I've lost context for this comment. Why are logs relevant? (I'm very well aware of the debates over the meaning of log, having frequently had to help students 'unlearn' their "log=log10" mindset when starting a first post-calculus course). Mark From pruebauno at latinmail.com Fri Jun 19 15:41:18 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:41:18 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt >>> def midnight_next_day(initial_time="use today's date"): if initial_time == "use today's date": initial_time = datetime.now() return initial_time.date() + timedelta(days=1) >>> midnight_next_day() Traceback (most recent call last): File "", line 1, in midnight_next_day() File "", line 6, in midnight_next_day return initial_time.date() + timedelta(days=1) AttributeError: 'str' object has no attribute 'date' From pavlovevidence at gmail.com Fri Jun 19 15:41:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Jun 2009 12:41:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> On Jun 19, 11:08?am, OdarR wrote: > On 19 juin, 19:13, s... at pobox.com wrote: > > > ? ? Olivier> what do you mean ? > > > ? ? Olivier> Cpython can't benefit from multi-core without multiple > > ? ? Olivier> processes. > > > It can, precisely as Martin indicated. ?Only one thread at a time can hold > > the GIL. ?That doesn't mean that multiple threads can't execute. ?Suppose > > I don't say multiple threads can't execute....(?). > I say that with the Python library, I don't see (yet) benefit with > multiple threads *on* multiple CPU/core. He's saying that if your code involves extensions written in C that release the GIL, the C thread can run on a different core than the Python-thread at the same time. The GIL is only required for Python code, and C code that uses the Python API. C code that spends a big hunk of time not using any Python API (like, as Skip pointed out, a matrix multiply) can release the GIL and the thread can run on a different core at the same time. I always found to be a *terribly* weak rationalization. The fact is, few Python developers can take much advantage of this. (Note: I'm not talking about releasing the GIL for I/O operations, it's not the same thing. I'm talking about the ability to run computations on multiple cores at the same time, not to block in 50 threads at the same time. Multiple cores aren't going to help that much in the latter case.) I wish Pythonistas would be more willing to acknowledge the (few) drawbacks of the language (or implementation, in this case) instead of all this rationalization. It's like people here in Los Angeles who complain about overcast days. What, 330 days of sunshine not enough? Jesus. I wish people would just say, "This is a limitation of CPython. There are reasons why it's there, and it helps some people, but unfortunately it has drawbacks for others", instead of the typical "all u hav 2 do is rite it in C LOL". Carl Banks From clp2 at rebertia.com Fri Jun 19 15:42:49 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 12:42:49 -0700 Subject: Rich comparison methods don't work in sets? In-Reply-To: References: Message-ID: <50697b2c0906191242t1b92a7b6ne349ae34b29c57b1@mail.gmail.com> On Fri, Jun 19, 2009 at 12:02 PM, Gustavo Narea wrote: > Hello, everyone. > > I've noticed that if I have a class with so-called "rich comparison" > methods > (__eq__, __ne__, etc.), when its instances are included in a set, > set.__contains__/__eq__ won't call the .__eq__ method of the elements > and thus > the code below: > """ > obj1 = RichComparisonClass() > obj2 = RichComparisonClass() > > set1 = set([obj1]) > set2 = set([obj2]) > > if obj1 == obj2: > ? ?print "Objects 1 and 2 are equivalent" > else: > ? ?print "Objects 1 and 2 aren't equivalent" > > if set1 == set2: > ? ?print "Sets 1 and 2 are equivalent" > else: > ? ?print "Sets 1 and 2 aren't equivalent" > """ > > Would output: > """ > Objects 1 and 2 are equivalent > Sets 1 and 2 aren't equivalent > """ > > instead of: > """ > Objects 1 and 2 are equivalent > Sets 1 and 2 are equivalent > """ > > How can I work around this? The only solution that comes to my mind is Note that sets are dict-based and thus use hash tables internally. Thus, you must implement a sensible __hash__ method. The default __hash__ provided by class `object` uses the object ID for the hash. Since id(x) == id(y) iff x is y, and hash(x) != hash(y) implies x != y, If you don't implement __hash__, object's implementation causes every distinct object of your type to be considered unequal a priori, so it doesn't bother to check any further by calling the comparison methods. Cheers, Chris -- http://blog.rebertia.com From castironpi at gmail.com Fri Jun 19 15:50:53 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 12:50:53 -0700 (PDT) Subject: fastest native python database? References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: On Jun 17, 8:28?pm, per wrote: > hi all, > > i'm looking for a native python package to run a very simple data > base. i was originally using cpickle with dictionaries for my problem, > but i was making dictionaries out of very large text files (around > 1000MB in size) and pickling was simply too slow. > > i am not looking for fancy SQL operations, just very simple data base > operations (doesn't have to be SQL style) and my preference is for a > module that just needs python and doesn't require me to run a separate > data base like Sybase or MySQL. > > does anyone have any recommendations? the only candidates i've seen > are snaklesql and buzhug... any thoughts/benchmarks on these? > > any info on this would be greatly appreciated. thank you I have one or two. If the objects you're pickling are all dictionaries, you could store file names in a master 'shelve' object, and nested data in the corresponding files. Otherwise, it may be pretty cheap to write the operations by hand using ctypes if you only need a few, though that can get precarious quickly. Just like life, huh? Lastly, the 'sqlite3' module's bark is worse than its byte. From pruebauno at latinmail.com Fri Jun 19 15:52:37 2009 From: pruebauno at latinmail.com (nn) Date: Fri, 19 Jun 2009 12:52:37 -0700 (PDT) Subject: Is this pylint error message valid or silly? References: Message-ID: <440006b0-1fcd-41a6-920c-d0167a2e54ac@n4g2000vba.googlegroups.com> On Jun 18, 8:56?pm, Matthew Wilson wrote: > Here's the code that I'm feeding to pylint: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c="today"): > > ? ? ? ? if c == "today": > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > And here's what pylint says: > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > ? ? ************* Module f > ? ? E: 10:f: Instance of 'str' has no 'date' member (but some types could > ? ? not be inferred) > > Is this a valid error message? ?Is the code above bad? ?If so, what is > the right way? > > I changed from using a string as the default to None, and then pylint > didn't mind: > > ? ? $ cat f.py > ? ? from datetime import datetime > > ? ? def f(c=None): > > ? ? ? ? if c is None: > ? ? ? ? ? ? ? ? ? ? c = datetime.today() > > ? ? ? ? return c.date() > > ? ? $ pylint -e f.py > ? ? No config file found, using default configuration > > I don't see any difference between using a string vs None. ?Both are > immutable. ?I find the string much more informative, since I can write > out what I want. > > Looking for comments. > > Matt This is a limitation of static type checking and Pylint is a (limited) static type checker for Python. A language with static type checking would not have even allowed you to compile this. A static type checkers sees this: def midnight_next_day(initial_time [string or in python whatever gets passed(T)]): if initial_time [string (or T)]== [(some constant) string]: initial_time [datetime] = datetime.now() {implied else: initial_time [string or (T)] } return initial_time[could be either datetime or string (oops string does not have date()) pylint doesn?t check for T].date() + timedelta(days=1) or this: def midnight_next_day(initial_time [None object or (T)]): if initial_time [None object or (T)]== [None object]: initial_time [type datetime] = datetime.now() {implied else: initial_time [T] } return initial_time[datetime (pylint doesn?t check for T)].date() + timedelta(days=1) From jeremiah.jester at panasonic.aero Fri Jun 19 15:55:43 2009 From: jeremiah.jester at panasonic.aero (Jeremiah Jester) Date: Fri, 19 Jun 2009 12:55:43 -0700 Subject: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009 In-Reply-To: <4A3A5F66.2030701@simplistix.co.uk> References: <4A3A5F66.2030701@simplistix.co.uk> Message-ID: <1245441343.32055.2.camel@jesterj-laptop> Chris, Do you have any online tutorial for this topic? Thanks, JJ On Thu, 2009-06-18 at 08:38 -0700, Chris Withers wrote: > Hi All, > > Too many people in the Python community *still* think the only way to > work with Excel files in Python is using COM on Windows. > > To try and correct this, I'm giving a tutorial at this year's > EuroPython > conference in Birmingham, UK on Monday, 29th June that will cover > working with Excel files in Python using the pure-python libraries > xlrd, > xlwt and xlutils. > > I'll be looking to cover: > > - Reading Excel Files > > Including extracting all the data types, formatting and working > with > large files. > > - Writing Excel Files > > Including formatting, many of the useful frilly extras and writing > large excel files. > > - Modifying and Filtering Excel Files > > A run through of taking existing Excel files and modifying them in > various ways. > > - Workshop for your problems > > I'm hoping anyone who attends will get a lot out of this! If you're > planning on attending and have a particular problem you'd like to > work > on in this part of the tutorial, please drop me an email and I'll > try > and make sure I come prepared! > > All you need for the tutorial is a working knowledge of Excel and > Python, with a laptop as an added benefit, and to be at EuroPython > this > year: > > http://www.europython.eu/ > > I look forward to seeing you all there! > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > - http://www.simplistix.co.uk > > > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations.html > > > Disclaimer: The information contained in this transmission, including any attachments, may contain confidential information of Panasonic Avionics Corporation. This transmission is intended only for the use of the addressee(s) listed above. Unauthorized review, dissemination or other use of the information contained in this transmission is strictly prohibited. If you have received this transmission in error or have reason to believe you are not authorized to receive it, please notify the sender by return email and promptly delete the transmission. From anthra.norell at bluewin.ch Fri Jun 19 16:00:45 2009 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 19 Jun 2009 22:00:45 +0200 Subject: CAD file format specifications? In-Reply-To: References: <4A324276.80804@bluewin.ch> <4A32AD8D.2010000@geniusdv.com> <4A3371BD.70508@bluewin.ch> <4A37D79D.4070604@hughes.net> <4A3A2770.2030802@bluewin.ch> Message-ID: <4A3BEE6D.4070702@bluewin.ch> Dennis Lee Bieber wrote: > On Thu, 18 Jun 2009 13:39:28 +0200, Anthra Norell > declaimed the following in > gmane.comp.python.general: > > > >> utility. So, my question is: How do I convert a bunch of >> three-dimensional coordinates defining lines into a file format Sketch >> Up can read (skp, dwg, dxf, 3ds, ddf or dem)? >> >> > Most CAD type data files are highly structured -- and the formats > may be under company control... > > http://en.wikipedia.org/wiki/USGS_DEM > http://rockyweb.cr.usgs.gov/nmpstds/acrodocs/dem/2DEM0198.PDF > > http://www.martinreddy.net/gfx/3d/3DS.spec > Dennis, norseman, Thanks for your suggestions. First thing I'm trying to write a DXF converter using norseman's excellent documentation. It seems I only need a simple subset of the DXF format (Entities). When I'm done I shall take a close look at the links above. So, thanks again. Frederic From piet at cs.uu.nl Fri Jun 19 16:03:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 19 Jun 2009 22:03:16 +0200 Subject: multiprocessing and process run time References: Message-ID: >>>>> Thomas Robitaille (TR) wrote: >TR> Hi, >TR> I'm making use of the multiprocessing module, and I was wondering if there >TR> is an easy way to find out how long a given process has been running for. >TR> For example, if I do >TR> import multiprocessing as mp >TR> import time >TR> def time_waster(): >TR> time.sleep(1000) >TR> p = mp.Process(target=time_waster) >TR> p.start() >TR> Is there a way that I can then find how long p has been running for? I >TR> figured I can use p.pid to get the PID of the process, but I'm not sure >TR> where to go from there. Is there an easy way to do this? You could look at the psutil module: http://code.google.com/p/psutil/ -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From mitko at qlogic.com Fri Jun 19 16:18:58 2009 From: mitko at qlogic.com (Mitko Haralanov) Date: Fri, 19 Jun 2009 13:18:58 -0700 Subject: Checking for binary data in a string Message-ID: <20090619131858.1b4ade03@hematite.mv.qlogic.com> I have a question about finding out whether a string contains binary data? In my application, I am reading from a file which could contain binary data. After I have read the data, I transfer it using xmlrpclib. However, xmlrpclib has trouble unpacking XML which contains binary data and my application throws an exception. The solution to this problem is to use base64 encoding of the data but I don't know how to check whether the encoding will be needed? If I read in a string containing some binary data from the file, the type of that string is which is not different from any other string, so I can't use that as a check. The only other check that I can think of is to check every character in the read-in string against string.printable but that will take a long time. Can anyone suggest a better way to handle the check? Thank you in advance. -- Mitko Haralanov From lie.1296 at gmail.com Fri Jun 19 16:55:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 20:55:08 GMT Subject: Convert hash to struct In-Reply-To: References: Message-ID: Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > I just remembered something... If you used python > 2.6, you may also look at namedtuple From castironpi at gmail.com Fri Jun 19 17:00:49 2009 From: castironpi at gmail.com (Aaron Brady) Date: Fri, 19 Jun 2009 14:00:49 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: Message-ID: <81d1e7ba-9718-4b67-becb-753ee3f99725@e20g2000vbc.googlegroups.com> On Jun 19, 12:42?pm, Chris Rebert wrote: > On Fri, Jun 19, 2009 at 12:02 PM, Gustavo Narea wrote: > > Hello, everyone. > > > I've noticed that if I have a class with so-called "rich comparison" > > methods > > (__eq__, __ne__, etc.), when its instances are included in a set, > > set.__contains__/__eq__ won't call the .__eq__ method of the elements > > and thus > > the code below: snip > > """ > > obj1 = RichComparisonClass() > > obj2 = RichComparisonClass() > > > set1 = set([obj1]) > > set2 = set([obj2]) > > > if obj1 == obj2: > > ? ?print "Objects 1 and 2 are equivalent" > > else: > > ? ?print "Objects 1 and 2 aren't equivalent" > > > if set1 == set2: > > ? ?print "Sets 1 and 2 are equivalent" > > else: > > ? ?print "Sets 1 and 2 aren't equivalent" > > """ > > > Would output: > > """ > > Objects 1 and 2 are equivalent > > Sets 1 and 2 aren't equivalent > > """ > > > instead of: > > """ > > Objects 1 and 2 are equivalent > > Sets 1 and 2 are equivalent > > """ > > > How can I work around this? The only solution that comes to my mind is > > Note that sets are dict-based and thus use hash tables internally. > Thus, you must implement a sensible __hash__ method. > The default __hash__ provided by class `object` uses the object ID for the hash. > > Since id(x) == id(y) ?iff ?x is y, and > hash(x) != hash(y) implies x != y, > If you don't implement __hash__, object's implementation causes every > distinct object of your type to be considered unequal a priori, so it > doesn't bother to check any further by calling the comparison methods. > > Cheers, > Chris > --http://blog.rebertia.com You're using sets for uniqueness and faster lookups than a list or other collection. Uniqueness is determined by hash key first, then by identity (due to an idiosyncrasy of 'RichCompareBool'), then by rich equality. If you want to compare to every element, you can't use sets, because they take short-cuts by omitting many of the comparisons. From amita.ekbote at gmail.com Fri Jun 19 17:03:58 2009 From: amita.ekbote at gmail.com (Amita Ekbote) Date: Fri, 19 Jun 2009 16:03:58 -0500 Subject: Convert hash to struct In-Reply-To: References: Message-ID: I wanted to make a more generic way of doing this so that even if the columns are modified or new ones are added it should be simple. Anyway I will reconsider this sort of am implementation. Just out of curiosity is there any other way of achieving this? Thanks Amita On Fri, Jun 19, 2009 at 1:52 PM, Lie Ryan wrote: > Amita Ekbote wrote: >> Hello, >> >> I am retrieving values from a database in the form of a dictionary so >> I can access the values as d['column'] and I was wondering if there is >> a way to convert the hash to a struct like format so i can just say >> d.column. Makes it easier to read and understand. >> >> Thanks >> Amita >> > > You may be able to update the class' dict: > >>>> class MyDB(object): > ... def __init__(self, di): > ... self.__dict__.update(di) > ... >>>> di = {'a':10, 'b': 20} >>>> d = MyDB(di) >>>> d > <__main__.MyDB object at 0x7f756b0d0b90> >>>> d.a > 10 >>>> d.b > 20 > > but this might be a security risk, if you cannot trust the database or > its content. > > It is much preferrable to use something like: > >>>> class MyDB(object): > ... def __init__(self, di): > ... self.a = di['a'] > ... self.b = di['b'] > > > since you now have full control of what collumns can go in and whatnot. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Amita Ekbote From invalid at invalid Fri Jun 19 17:12:10 2009 From: invalid at invalid (Grant Edwards) Date: Fri, 19 Jun 2009 16:12:10 -0500 Subject: Checking for binary data in a string References: Message-ID: On 2009-06-19, Mitko Haralanov wrote: > I have a question about finding out whether a string contains > binary data? All strings contain binary data. Unless you've invented ternary logic and built a computer with it. ;) > If I read in a string containing some binary data from the file, the > type of that string is which is not different from any > other string, so I can't use that as a check. Correct. > The only other check that I can think of is to check every > character in the read-in string against string.printable but > that will take a long time. There's no such thing as a free lunch. If you want to know if some condition is true for every octet in a string, then you have to check whether it's true for every character in the string -- until you find it to be false. IOW, you can stop when you find the first non-printable octect. -- Grant Edwards grante Yow! Eisenhower!! Your at mimeograph machine upsets visi.com my stomach!! From jure.erznoznik at gmail.com Fri Jun 19 17:13:50 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 14:13:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Thanks guys, for all the replies. They were some very interesting reading / watching. Seems to me, the Unladen-Swallow might in time produce code which will have this problem lessened a bit. Their roadmap suggests at least modifying the GIL principles if not fully removing it. On top of this, they seem to have a pretty aggressive schedule with good results expected by Q3 this year. I'm hoping that their patches will be accepted to cPython codebase in a timely manner. I definitely liket the speed improvements they showed for Q1 modifications. Though those improvements don't help my case yet... The presentation from mr. Beasley was hilarious :D I find it curious to learn that just simple replacement from events to actual mutexes already lessens the problem a lot. This should already be implemented in the cPython codebase IMHO. As for multiprocessing alternatives, I'll have to look into them. I haven't yet done multiprocessing code and don't really know what will happen when I try. I believe that threads would be much more appropriate for my project, but it's definitely worth a shot. Since my project is supposed to be cross platform, I'm not really looking forward to learning cross platform for C++. All my C++ experience is DOS + Windows derivatives till now :( From davea at ieee.org Fri Jun 19 17:35:16 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 17:35:16 -0400 Subject: Checking for binary data in a string In-Reply-To: <20090619131858.1b4ade03@hematite.mv.qlogic.com> References: <20090619131858.1b4ade03@hematite.mv.qlogic.com> Message-ID: <4A3C0494.7090902@ieee.org> Mitko Haralanov wrote: > I have a question about finding out whether a string contains binary > data? > > In my application, I am reading from a file which could contain > binary data. After I have read the data, I transfer it using xmlrpclib. > > However, xmlrpclib has trouble unpacking XML which contains binary data > and my application throws an exception. The solution to this problem is > to use base64 encoding of the data but I don't know how to check > whether the encoding will be needed? > > If I read in a string containing some binary data from the file, the > type of that string is which is not different from any > other string, so I can't use that as a check. > > The only other check that I can think of is to check every character in > the read-in string against string.printable but that will take a long > time. > > Can anyone suggest a better way to handle the check? Thank you in > advance. > > All the data is binary. But perhaps you mean ASCII (7 bits), or you mean between 20-7f. or something. The way I'd tackle it is to build a translation table for your definition of "binary." Then simply do something like: if data != data.translate(table): ..... Convert to bin64 or whatever... The translation table would be defined such that table[ch] == ch for all ch that are "nonbinary" and table[ch] != ch for all ch that are "binary." And naturally you only build the table once, and reuse it on each buffer. This should be quicker than any for loop you could write, though there may be other builltin functions that are even quicker. It's a start, though. Note that you will probably also be escaping the xml special characters, such as &, <, and >. So you might get clever about letting a single translate pass tell you whether the data can be stored unmodified, then do a second translate to decide which way to modify it. Whether this is worthwhile depends in part on how often the buffer fits into which category. From Olivier.Darge at gmail.com Fri Jun 19 17:45:02 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 14:45:02 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On 19 juin, 21:05, Christian Heimes wrote: > I've seen a single Python process using the full capacity of up to 8 > CPUs. The application is making heavy use of lxml for large XSL > transformations, a database adapter and my own image processing library > based upon FreeImage. interesting... > Of course both lxml and my library are written with the GIL in mind. > They release the GIL around every call to C libraries that don't touch > Python objects. PIL releases the lock around ops as well (although it > took me a while to figure it out because PIL uses its own API instead of > the standard macros). reportlab has some optional C libraries that > increase the speed, too. Are you using them? I don't. Or maybe I did, but I have no clue what to test. Do you have a real example, some code snippet to can prove/show activity on multiple core ? I accept your explanation, but I also like experiencing :) > By the way threads are evil > (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and > not *the* answer to concurrency. I don't see threads as evil from my little experience on the subject, but we need them. I'm reading what's happening in the java world too, it can be interesting. Olivier From jure.erznoznik at gmail.com Fri Jun 19 17:49:27 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 14:49:27 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Message-ID: Sorry, just a few more thoughts: Does anybody know why GIL can't be made more atomic? I mean, use different locks for different parts of code? This way there would be way less blocking and the plugin interface could remain the same (the interpreter would know what lock it used for the plugin, so the actual function for releasing / reacquiring the lock could remain the same) On second thought, forget this. This is probably exactly the cause of free-threading reduced performance. Fine-graining the locks increased the lock count and their implementation is rather slow per se. Strange that *nix variants don't have InterlockedExchange, probably because they aren't x86 specific. I find it strange that other architectures wouldn't have these instructions though... Also, an OS should still be able to support such a function even if underlying architecture doesn't have it. After all, a kernel knows what it's currently running and they are typically not preempted themselves. Also, a beside question: why does python so like to use events instead of "true" synchronization objects? Almost every library I looked at used that. IMHO that's quite irrational. Using objects that are intended for something else for the job while there are plenty of "true" options supported in every OS out there. Still, the free-threading mod could still work just fine if there was just one more global variable added: current python thread count. A simple check for value greater than 1 would trigger the synchronization code, while having just one thread would introduce no locking at all. Still, I didn't like the performance figures of the mod (0.6 execution speed, pretty bad core / processor scaling) I don't know why it's so hard to do simple locking just for writes to globals. I used to do it massively and it always worked almost with no penalty at all. It's true that those were all Windows programs, using critical sections. From Olivier.Darge at gmail.com Fri Jun 19 17:51:04 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Fri, 19 Jun 2009 14:51:04 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: On 19 juin, 21:41, Carl Banks wrote: > He's saying that if your code involves extensions written in C that > release the GIL, the C thread can run on a different core than the > Python-thread at the same time. ?The GIL is only required for Python > code, and C code that uses the Python API. ?C code that spends a big > hunk of time not using any Python API (like, as Skip pointed out, a > matrix multiply) can release the GIL and the thread can run on a > different core at the same time. I understand the idea, even if I don't see any examples in the standard library. any examples ? > (Note: I'm not talking about releasing the GIL for I/O operations, > it's not the same thing. ?I'm talking about the ability to run > computations on multiple cores at the same time, not to block in 50 > threads at the same time. ?Multiple cores aren't going to help that > much in the latter case.) yes, I also speak about hard computation that could benefit with multiple cores. > I wish Pythonistas would be more willing to acknowledge the (few) > drawbacks of the language (or implementation, in this case) instead of > all this rationalization. ?It's like people here in Los Angeles who > complain about overcast days. ?What, 330 days of sunshine not enough? > Jesus. ?I wish people would just say, "This is a limitation of > CPython. ?There are reasons why it's there, and it helps some people, > but unfortunately it has drawbacks for others", instead of the typical > "all u hav 2 do is rite it in C LOL". "LOL" I would like to say such thing about my weather...I live in Europe in a rainy country. Olivier From davea at ieee.org Fri Jun 19 17:52:11 2009 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Jun 2009 17:52:11 -0400 Subject: Convert hash to struct In-Reply-To: References: Message-ID: <4A3C088B.4030101@ieee.org> Amita Ekbote wrote: > I wanted to make a more generic way of doing this so that even if the > columns are modified or new ones are added it should be simple. Anyway > I will reconsider this sort of am implementation. Just out of > curiosity is there any other way of achieving this? > > Thanks > Amita > > On Fri, Jun 19, 2009 at 1:52 PM, Lie Ryan wrote: > >> Amita Ekbote wrote: >> >>> Hello, >>> >>> I am retrieving values from a database in the form of a dictionary so >>> I can access the values as d['column'] and I was wondering if there is >>> a way to convert the hash to a struct like format so i can just say >>> d.column. Makes it easier to read and understand. >>> >>> Thanks >>> Amita >>> >>> >> You may be able to update the class' dict: >> >> >>>>> class MyDB(object): >>>>> >> ... def __init__(self, di): >> ... self.__dict__.update(di) >> ... >> >>>>> di = {'a':10, 'b': 20} >>>>> d = MyDB(di) >>>>> d >>>>> >> <__main__.MyDB object at 0x7f756b0d0b90> >> >>>>> d.a >>>>> >> 10 >> >>>>> d.b >>>>> >> 20 >> >> but this might be a security risk, if you cannot trust the database or >> its content. >> >> It is much preferrable to use something like: >> >> >>>>> class MyDB(object): >>>>> >> ... def __init__(self, di): >> ... self.a = di['a'] >> ... self.b = di['b'] >> >> >> since you now have full control of what collumns can go in and whatnot. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> You really shouldn't top-post here; it makes the sequence of message and response very hard to follow. Put your comments at the end, unless it's a simple "thanks for the response" one-liner. Someone else pointed out that you can derive from dict, and showed you why that can be dangerous if one of the attributes you're trying to use happens to be already a method in the list class. But you could write a class that *contains* a dict, and gives you access to it by attribute. Look at this for starters: class undict(object): def __init__(self): self.data = {"key1":44, "key2":90} def __getattr__(self, name): try: return self.data[name] except KeyError: raise AttributeError(name) From jasondrew72 at gmail.com Fri Jun 19 17:58:27 2009 From: jasondrew72 at gmail.com (Jason) Date: Fri, 19 Jun 2009 14:58:27 -0700 (PDT) Subject: Convert hash to struct References: Message-ID: Here's my general-purpose solution for doing this: class Dict2Class(object): """ Update like a dictionary, but expose the keys as class properties. Sweet! You can instantiate and update this practically any way you choose, and the values are available as class properties. >>> c = Dict2Class((('fred', 11), ('joe', 88)), bob=9) >>> c.bob 9 >>> c.joe 88 >>> c = Dict2Class({'bob': 88, 'fred': 9}) >>> c.fred 9 >>> c = Dict2Class() >>> c.bob = 88 >>> c.bob 88 This subclasses plain old object. It could also subclass dict to provide even more functionality, but at the risk of naming collisions between the dict methods and property names. """ def __init__(self, *e, **f): self.__dict__ = dict(*e, **f) def update(self, *e, **f): self.__dict__.update(*e, **f) # Looks a little complex, but it rocks. On Jun 19, 2:17?pm, Amita Ekbote wrote: > ?Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand. > > Thanks > Amita > > -- > Amita Ekbote From jnoller at gmail.com Fri Jun 19 17:59:26 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 19 Jun 2009 17:59:26 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4222a8490906191459x1eaf912bt18b7db5e9f8dd5ea@mail.gmail.com> On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: > On 19 juin, 16:16, Martin von Loewis > If you know that your (C) code is thread safe on its own, you can >> release the GIL around long-running algorithms, thus using as many >> CPUs as you have available, in a single process. > > what do you mean ? > > Cpython can't benefit from multi-core without multiple processes. > > Olivier Sorry, you're incorrect. I/O Bound threads do in fact, take advantage of multiple cores. From wayne.dads.bell at gmail.com Fri Jun 19 17:59:33 2009 From: wayne.dads.bell at gmail.com (dads) Date: Fri, 19 Jun 2009 14:59:33 -0700 (PDT) Subject: File Syncing Message-ID: I've created a small application that when you click one of the buttons it randomly picks a paragraphs from a list that it generates from a text file and then copies them to the clipboard. It also has make new/edit/delete/print/ etc functionality. It's for work so I get some brownie points and every know and then I could work on it and learn python while getting paid (heaven) instead of my normal customer service job (mind I've done 95% of it at home). I've been allowed to install it on one of the blade servers so one of the team can use if they connect to that server. Great stuff. When we normally connect through one of the thin clients we connect randomly to one of three blade servers. I've just thought that when I add the app to the other servers they will be completely separate. So if the the paragraphs which are stored in text files are amended/ deleted/created will only happen on one server and not them all. I've a couple of questions: What would happen if more than one person used my application at the same time? I haven't added any I/O exception code so I think that would be an issue but would python crash? (it's only got simple functions and controls in it, no threading or process code or anything like that, i'd post it but it's 2500lines long) What would I have to learn to be able to sync the text files on each server? python network programming? Or something else? Sorry for my naivety =p From jure.erznoznik at gmail.com Fri Jun 19 18:06:07 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 15:06:07 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 19, 11:45?pm, OdarR wrote: > On 19 juin, 21:05, Christian Heimes wrote: > > > I've seen a single Python process using the full capacity of up to 8 > > CPUs. The application is making heavy use of lxml for large XSL > > transformations, a database adapter and my own image processing library > > based upon FreeImage. > > interesting... > > > Of course both lxml and my library are written with the GIL in mind. > > They release the GIL around every call to C libraries that don't touch > > Python objects. PIL releases the lock around ops as well (although it > > took me a while to figure it out because PIL uses its own API instead of > > the standard macros). reportlab has some optional C libraries that > > increase the speed, too. Are you using them? > > I don't. Or maybe I did, but I have no clue what to test. > Do you have a real example, some code snippet to can prove/show > activity on multiple core ? > I accept your explanation, but I also like experiencing :) > > > By the way threads are evil > > (http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf) and > > not *the* answer to concurrency. > > I don't see threads as evil from my little experience on the subject, > but we need them. > I'm reading what's happening in the java world too, it can be > interesting. > > Olivier Olivier, What Christian is saying is that you can write a C/C++ Python plugin, release the GIL inside it and then process stuff in threads inside the plugin. All this is possible if the progammer doesn't use any Python objects and it's fairly easy to write such a plugin. Any counting example will do just fine. The problem with this solution is that you have to write the code in C which quite defeats the purpose of using an interpreter in the first place... Of course, no pure python code will currently utilize multiple cores (because of GIL). I do aggree though that threading is important. Regardless of any studies showing that threads suck, they are here and they offer relatively simple concurrency. IMHO they should never have been crippled like this. Even though GIL solves access violations, it's not the right approach. It simply kills all threading benefits except for the situation where you work with multiple I/O blocking threads. That's just about the only situation where this problem is not apparent. We're way past single processor single core computers now. An important product like Python should support these architectures properly even if only 1% of applications written in it use threading. But as Guido himself said; I should not complain but instead try to contribute to solution. That's the hard part, especially since there's lots of code that actually need the locking. From jure.erznoznik at gmail.com Fri Jun 19 18:10:17 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 15:10:17 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 19, 11:59?pm, Jesse Noller wrote: > On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: > > On 19 juin, 16:16, Martin von Loewis >> If you know that your (C) code is thread safe on its own, you can > >> release the GIL around long-running algorithms, thus using as many > >> CPUs as you have available, in a single process. > > > what do you mean ? > > > Cpython can't benefit from multi-core without multiple processes. > > > Olivier > > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. Incorrect. They take advantage of OS threading support where another thread can run while one is blocked for I/O. That is not equal to running on multiple cores (though it actually does do that, just that cores are all not well utilized - sum(x) < 100% of one core). You wil get better performance running on single core because of the way GIL is implemented in all cases. From paul at boddie.org.uk Fri Jun 19 18:18:06 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Fri, 19 Jun 2009 15:18:06 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: On 19 Jun, 21:41, Carl Banks wrote: > > (Note: I'm not talking about releasing the GIL for I/O operations, > it's not the same thing. ?I'm talking about the ability to run > computations on multiple cores at the same time, not to block in 50 > threads at the same time. ?Multiple cores aren't going to help that > much in the latter case.) There seems to be a mixing together of these two things when people talk about "concurrency". Indeed, on the concurrency-sig mailing list [1] there's already been discussion about whether a particular example [2] is really a good showcase of concurrency. According to Wikipedia, concurrency is about "computations [...] executing simultaneously" [3], not about whether one can handle hundreds of communications channels sequentially, although this topic is obviously relevant when dealing with communications between processing contexts. I agree with the over-rationalisation assessment: it's not convenient (let alone an advantage) for people to have to switch to C so that they can release the GIL, nor is it any comfort that CPython's limitations are "acceptable" for the socket multiplexing server style of solution when that isn't the kind of solution being developed. However, there are some reasonable tools out there (and viable alternative implementations), and I'm optimistic that the situation will only improve. Paul [1] http://mail.python.org/mailman/listinfo/concurrency-sig [2] http://wiki.python.org/moin/Concurrency/99Bottles [3] http://en.wikipedia.org/wiki/Concurrency_(computer_science) From lie.1296 at gmail.com Fri Jun 19 18:31:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 19 Jun 2009 22:31:08 GMT Subject: Checking for binary data in a string In-Reply-To: References: Message-ID: Grant Edwards wrote: > On 2009-06-19, Mitko Haralanov wrote: > >> I have a question about finding out whether a string contains >> binary data? > > All strings contain binary data. Not quite, (python 2.x's) strings are binary data. It just happens that it behaves like text when you appropriately encode/decode it. In python 3.x, the default string have evolved to unicode string, which is a true text and the old string which contains arbitrary binary data evolved into bytestring. From jnoller at gmail.com Fri Jun 19 18:43:39 2009 From: jnoller at gmail.com (Jesse Noller) Date: Fri, 19 Jun 2009 18:43:39 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4222a8490906191543o74049391p7f86449f3d0b2319@mail.gmail.com> On Fri, Jun 19, 2009 at 6:10 PM, Jure Erzno?nik wrote: > On Jun 19, 11:59?pm, Jesse Noller wrote: >> On Fri, Jun 19, 2009 at 12:50 PM, OdarR wrote: >> > On 19 juin, 16:16, Martin von Loewis > >> If you know that your (C) code is thread safe on its own, you can >> >> release the GIL around long-running algorithms, thus using as many >> >> CPUs as you have available, in a single process. >> >> > what do you mean ? >> >> > Cpython can't benefit from multi-core without multiple processes. >> >> > Olivier >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > > Incorrect. They take advantage of OS threading support where another > thread can run while one is blocked for I/O. > That is not equal to running on multiple cores (though it actually > does do that, just that cores are all not well utilized - sum(x) < > 100% of one core). > You wil get better performance running on single core because of the > way GIL is implemented in all cases. No. That's simply incorrect. I (and others) have seen significant increases in threaded, I/O bound code using multiple cores. It's not perfect, but it is faster. From gh at ghaering.de Fri Jun 19 19:09:24 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Sat, 20 Jun 2009 01:09:24 +0200 Subject: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError? In-Reply-To: References: <4A37BD14.5010807@arimaz.com> Message-ID: John Machin wrote: > Hi Gerhard, > [...] > In http://www.sqlite.org/c3ref/prepare.html it says """When an error > occurs, sqlite3_step() will return one of the detailed error codes or > extended error codes. The legacy behavior was that sqlite3_step() > would only return a generic SQLITE_ERROR result code and you would > have to make a second call to sqlite3_reset() in order to find the > underlying cause of the problem. With the "v2" prepare interfaces, the > underlying reason for the error is returned immediately.""" > > Are you using sqlite3_prepare() or sqlite3_prepare_v2()? > sqlite3_errcode() or sqlite3_extended_errcode()? Because of compatibility with older SQLite versions, I'm using the old API only. I'll change this one day and then I'll be able to throw a lot of compatibility code out of the window, too. But I certainly won't go #ifdef hell and implement both. -- Gerhard From arlie.c at gmail.com Fri Jun 19 19:16:05 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 16:16:05 -0700 (PDT) Subject: Play MP3s from Windows Message-ID: Hi, Newbie here. I copied and pasted the code below. But when I ran it I got this error: D:\>python mp3.py Duree du fichier : 298919 millisecondes Traceback (most recent call last): File "mp3.py", line 37, in time.sleep(int(buf)/1000) ValueError: invalid literal for int() with base 10: '' The code: # -*- coding: utf-8 -*- import time from ctypes import windll, c_buffer class mci: def __init__(self): self.w32mci = windll.winmm.mciSendStringA self.w32mcierror = windll.winmm.mciGetErrorStringA def send(self,commande): buffer = c_buffer(255) errorcode = self.w32mci(str(commande),buffer,254,0) if errorcode: return errorcode, self.get_error(errorcode) else: return errorcode,buffer.value def get_error(self,error): error = int(error) buffer = c_buffer(255) self.w32mcierror(error,buffer,254) return buffer.value def directsend(self, txt): (err,buf)=self.send(txt) if err != 0: print'Erreur',str(err),'sur',txt,':',buf return (err,buf) mci=mci() mci.directsend('open "d:\\Linger.mp3" alias toto') mci.directsend('set toto time format milliseconds') err,buf=mci.directsend('status toto length ') print 'Duree du fichier : ',buf,' millisecondes' err,buf=mci.directsend('play toto from 0 to '+str(buf)) time.sleep(int(buf)/1000) mci.directsend('close toto') #@-salutations #-- #Michel Claveau Please help. I'm in the middle of a project and I wanted to use this. From arlie.c at gmail.com Fri Jun 19 19:20:09 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 16:20:09 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: On Jun 20, 7:16?am, Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : ?298919 ?millisecondes > Traceback (most recent call last): > ? File "mp3.py", line 37, in > ? ? time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' > > The code: > > # -*- coding: utf-8 -*- > > import time > from ctypes import windll, c_buffer > > class mci: > ? ? def __init__(self): > ? ? ? ? self.w32mci = windll.winmm.mciSendStringA > ? ? ? ? self.w32mcierror = windll.winmm.mciGetErrorStringA > > ? ? def send(self,commande): > ? ? ? ? buffer = c_buffer(255) > ? ? ? ? errorcode = self.w32mci(str(commande),buffer,254,0) > ? ? ? ? if errorcode: > ? ? ? ? ? ? return errorcode, self.get_error(errorcode) > ? ? ? ? else: > ? ? ? ? ? ? return errorcode,buffer.value > > ? ? def get_error(self,error): > ? ? ? ? error = int(error) > ? ? ? ? buffer = c_buffer(255) > ? ? ? ? self.w32mcierror(error,buffer,254) > ? ? ? ? return buffer.value > > ? ? def directsend(self, txt): > ? ? ? ? (err,buf)=self.send(txt) > ? ? ? ? if err != 0: > ? ? ? ? ? ? print'Erreur',str(err),'sur',txt,':',buf > ? ? ? ? return (err,buf) > > mci=mci() > mci.directsend('open "d:\\Linger.mp3" alias toto') > mci.directsend('set toto time format milliseconds') > err,buf=mci.directsend('status toto length ') > print 'Duree du fichier : ',buf,' millisecondes' > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > time.sleep(int(buf)/1000) > mci.directsend('close toto') > > #@-salutations > #-- > #Michel Claveau > > Please help. I'm in the middle of a project and I wanted to use this. By the way I using Python 2.6.2. From usernet at ilthio.net Fri Jun 19 19:27:10 2009 From: usernet at ilthio.net (Tim Harig) Date: Fri, 19 Jun 2009 23:27:10 GMT Subject: Play MP3s from Windows References: Message-ID: On 2009-06-19, Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : 298919 millisecondes > Traceback (most recent call last): > File "mp3.py", line 37, in > time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' Did you mean time.sleep(int(buf/1000)) which will guarantee that the value sent to sleep is an integer rather then a float if buf is not evenly divisible by 1000 (even after it has been rounded to an integer)? From aahz at pythoncraft.com Fri Jun 19 19:31:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:31:59 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > >I do aggree though that threading is important. Regardless of any >studies showing that threads suck, they are here and they offer >relatively simple concurrency. IMHO they should never have been >crippled like this. Even though GIL solves access violations, it's not >the right approach. It simply kills all threading benefits except for >the situation where you work with multiple I/O blocking threads. >That's just about the only situation where this problem is not >apparent. NumPy? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Fri Jun 19 19:35:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:35:18 -0700 Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: In article <157e0345-74e0-4144-a2e6-2b4cc854ce37 at z7g2000vbh.googlegroups.com>, Carl Banks wrote: > >I wish Pythonistas would be more willing to acknowledge the (few) >drawbacks of the language (or implementation, in this case) instead of >all this rationalization. Please provide more evidence that Pythonistas are unwilling to acknowledge the drawbacks of the GIL. I think you're just spreading FUD. The problem is that discussions about the GIL almost invariably include false statements about the GIL, and I'm certainly not going to hamper my writing to always include the caveats about GIL drawbacks while correcting the wrong information. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Fri Jun 19 19:36:32 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 16:36:32 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: >On Jun 19, 11:59=A0pm, Jesse Noller wrote: >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > >Incorrect. They take advantage of OS threading support where another >thread can run while one is blocked for I/O. That is not equal to >running on multiple cores (though it actually does do that, just that >cores are all not well utilized - sum(x) < 100% of one core). You wil >get better performance running on single core because of the way GIL is >implemented in all cases. You should put up or shut up -- I've certainly seen multi-core speedup with threaded software, so show us your benchmarks! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From lists at cheimes.de Fri Jun 19 19:42:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 20 Jun 2009 01:42:20 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: OdarR schrieb: > On 19 juin, 21:41, Carl Banks wrote: >> He's saying that if your code involves extensions written in C that >> release the GIL, the C thread can run on a different core than the >> Python-thread at the same time. The GIL is only required for Python >> code, and C code that uses the Python API. C code that spends a big >> hunk of time not using any Python API (like, as Skip pointed out, a >> matrix multiply) can release the GIL and the thread can run on a >> different core at the same time. > > I understand the idea, even if I don't see any examples in the > standard library. > any examples ? http://svn.python.org/view/python/trunk/Modules/posixmodule.c?revision=72882&view=markup Search for Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS > yes, I also speak about hard computation that could benefit with > multiple cores. Hard computations gain more speed from carefully crafted C or Fortran code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or parallelized algorithms. If you start sharing values between multiple cores you have a serious problem. Oh, and use NumPy for the job ;) >> I wish people would just say, "This is a limitation of >> CPython. There are reasons why it's there, and it helps some people, >> but unfortunately it has drawbacks for others", instead of the typical >> "all u hav 2 do is rite it in C LOL". > > "LOL" > I would like to say such thing about my weather...I live in Europe in > a rainy country. It *is* a well known limitation of Python. All the nice 'n shiny syntax and features are coming with a cost. Python is a powerful language and good tool for lots of stuff. But Python is and will never become the ?bertool that solves every problem perfectly. At some point you need a different tool to get the raw power of your machine. C (and perhaps Fortran) are the weapons of choice for number crunching. Christian From rridge at csclub.uwaterloo.ca Fri Jun 19 19:46:31 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Fri, 19 Jun 2009 19:46:31 -0400 Subject: Status of Python threading support (GIL removal)? References: Message-ID: Jesse Noller wrote: > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. wrote: >Incorrect. They take advantage of OS threading support where another >thread can run while one is blocked for I/O. That is not equal to >running on multiple cores (though it actually does do that, just that >cores are all not well utilized - sum(x) < 100% of one core). You wil >get better performance running on single core because of the way GIL is >implemented in all cases. Aahz wrote: >You should put up or shut up -- I've certainly seen multi-core speedup >with threaded software, so show us your benchmarks! By definition an I/O bound thread isn't CPU bound so won't benefit from improved CPU resources. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From jure.erznoznik at gmail.com Fri Jun 19 19:49:39 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Fri, 19 Jun 2009 16:49:39 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: Message-ID: On Jun 20, 1:36?am, a... at pythoncraft.com (Aahz) wrote: > > You should put up or shut up -- I've certainly seen multi-core speedup > with threaded software, so show us your benchmarks! > -- Sorry, no intent to offend anyone here. Flame wars are not my thing. I have shown my benchmarks. See first post and click on the link. That's the reason I started this discussion. All I'm saying is that you can get threading benefit, but only if the threading in question is implemented in C plugin. I have yet to see pure Python code which does take advantage of multiple cores. From what I read about GIL, this is simply impossible by design. But I'm not disputing the fact that cPython as a whole can take advantage of multiple cores. There certainly are built-in objects that work as they should. From lists at cheimes.de Fri Jun 19 19:52:50 2009 From: lists at cheimes.de (Christian Heimes) Date: Sat, 20 Jun 2009 01:52:50 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: Aahz wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854ce37 at z7g2000vbh.googlegroups.com>, > Carl Banks wrote: >> I wish Pythonistas would be more willing to acknowledge the (few) >> drawbacks of the language (or implementation, in this case) instead of >> all this rationalization. > > Please provide more evidence that Pythonistas are unwilling to > acknowledge the drawbacks of the GIL. I think you're just spreading FUD. > The problem is that discussions about the GIL almost invariably include > false statements about the GIL, and I'm certainly not going to hamper my > writing to always include the caveats about GIL drawbacks while > correcting the wrong information. Aahz, my magic pixie dust bag is empty. Do you have some spare dust to remove the cursed GIL all alone? :p Christian From emile at fenx.com Fri Jun 19 19:56:57 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 19 Jun 2009 16:56:57 -0700 Subject: Checking for binary data in a string In-Reply-To: <20090619131858.1b4ade03@hematite.mv.qlogic.com> References: <20090619131858.1b4ade03@hematite.mv.qlogic.com> Message-ID: On 6/19/2009 1:18 PM Mitko Haralanov said... > I have a question about finding out whether a string contains binary > data? > The only other check that I can think of is to check every character in > the read-in string against string.printable but that will take a long > time. Well, probably not really. Consider that CPU speeds dramatically outperform network transport speeds such that by the time your local performance becomes an issue, you've got a _huge_ xmlrpc argument to pass over the wire... Emile From lie.1296 at gmail.com Fri Jun 19 20:07:27 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Jun 2009 00:07:27 GMT Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <3LV_l.19708$y61.13502@news-server.bigpond.net.au> Jure Erzno?nik wrote: > On Jun 20, 1:36 am, a... at pythoncraft.com (Aahz) wrote: >> You should put up or shut up -- I've certainly seen multi-core speedup >> with threaded software, so show us your benchmarks! >> -- > > Sorry, no intent to offend anyone here. Flame wars are not my thing. > > I have shown my benchmarks. See first post and click on the link. > That's the reason I started this discussion. > > All I'm saying is that you can get threading benefit, but only if the > threading in question is implemented in C plugin. > I have yet to see pure Python code which does take advantage of > multiple cores. From what I read about GIL, this is simply impossible > by design. > > But I'm not disputing the fact that cPython as a whole can take > advantage of multiple cores. There certainly are built-in objects that > work as they should. I never used threading together with I/O intensively before, but I heard that I/O operations releases the GIL, and such they're similar to GIL-releasing C extensions which makes it possible to benefit from multicore in I/O bound pure python code. Perhaps we should have more built-in/stdlib operations that can release GIL safely to release GIL by default? And perhaps some builtin/stdlib should receive an optional argument that instruct them to release GIL and by passing this argument, you're making a contract that you wouldn't do certain things that would disturb the builtin/stdlib's operations; the specifics of what operations are prohibited would be noted on their docs. From usernet at ilthio.net Fri Jun 19 20:07:41 2009 From: usernet at ilthio.net (Tim Harig) Date: Sat, 20 Jun 2009 00:07:41 GMT Subject: Play MP3s from Windows References: Message-ID: On 2009-06-19, Arlie wrote: > print 'Duree du fichier : ',buf,' millisecondes' You can obviously make sure that 'buf' can be accessed as a string. > time.sleep(int(buf)/1000) The error seems to be having issues converting buf to an int. Could you possibly convert it to a string before converting it to an int? time.sleep(int(str(buf))/1000) From python at mrabarnett.plus.com Fri Jun 19 20:48:25 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 01:48:25 +0100 Subject: Play MP3s from Windows In-Reply-To: References: Message-ID: <4A3C31D9.8070100@mrabarnett.plus.com> Arlie wrote: > Hi, > > Newbie here. I copied and pasted the code below. But when I ran it I > got this error: > > D:\>python mp3.py > Duree du fichier : 298919 millisecondes > Traceback (most recent call last): > File "mp3.py", line 37, in > time.sleep(int(buf)/1000) > ValueError: invalid literal for int() with base 10: '' > > The code: > > # -*- coding: utf-8 -*- > > import time > from ctypes import windll, c_buffer > > class mci: > def __init__(self): > self.w32mci = windll.winmm.mciSendStringA > self.w32mcierror = windll.winmm.mciGetErrorStringA > > def send(self,commande): > buffer = c_buffer(255) > errorcode = self.w32mci(str(commande),buffer,254,0) > if errorcode: > return errorcode, self.get_error(errorcode) > else: > return errorcode,buffer.value > > def get_error(self,error): > error = int(error) > buffer = c_buffer(255) > self.w32mcierror(error,buffer,254) > return buffer.value > > def directsend(self, txt): > (err,buf)=self.send(txt) > if err != 0: > print'Erreur',str(err),'sur',txt,':',buf > return (err,buf) > > mci=mci() > mci.directsend('open "d:\\Linger.mp3" alias toto') > mci.directsend('set toto time format milliseconds') > err,buf=mci.directsend('status toto length ') > print 'Duree du fichier : ',buf,' millisecondes' From the output it's clear that 'buf' contains '298919'. > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > time.sleep(int(buf)/1000) From the output it's clear that 'buf' contains ''. Are you expecting it to contain the length, like it did for the previous call? Perhaps you should just use the length returned by the previous call. > mci.directsend('close toto') > From manidevarajan at gmail.com Fri Jun 19 20:52:05 2009 From: manidevarajan at gmail.com (Terminator) Date: Fri, 19 Jun 2009 17:52:05 -0700 (PDT) Subject: What is the best method to match a pattern in set of lines Message-ID: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Hello, My requierment is to get the "Stick Tag" value from the below o/p and based on tag take different actions. What is the best way to implement it. I am new to Python, so appreciate any input. Command o/p: =================================================================== File: Packet.tcl Status: Needs Merge Working revision: 1.2.98 Result of merge Repository revision: 1.2.99 /auto/quality/CVS/tools/ext/ Packet.tcl,v Sticky Tag: rel-ip-branch (branch: 1.584.2) Sticky Date: (none) Sticky Options: (none) Requirement: If "Sticky Tag" is rel-ip-brach do A else "Sticky Tag" is rel-ipv6-branch do B Thanks in advance. From arlie.c at gmail.com Fri Jun 19 20:57:01 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 17:57:01 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: <1030835b-efca-4219-85e1-0afd31fbba13@x31g2000prc.googlegroups.com> On Jun 20, 8:07?am, Tim Harig wrote: > On 2009-06-19, Arlie wrote: > > > print 'Duree du fichier : ',buf,' millisecondes' > > You can obviously make sure that 'buf' can be accessed as a string. > > > time.sleep(int(buf)/1000) > > The error seems to be having issues converting buf to an int. ?Could you > possibly convert it to a string before converting it to an int? > > time.sleep(int(str(buf))/1000) I'm still getting same error. So I just did this: ... mci=mci() mci.directsend('open "d:\\Linger.mp3" alias toto') mci.directsend('set toto time format milliseconds') err,buf=mci.directsend('status toto length ') print 'Duree du fichier : ',buf,' millisecondes' soundlength = int(buf) / 1000 err,buf=mci.directsend('play toto from 0 to '+str(buf)) #time.sleep(int(buf)/1000) time.sleep(soundlength) mci.directsend('close toto') From arlie.c at gmail.com Fri Jun 19 21:05:03 2009 From: arlie.c at gmail.com (Arlie) Date: Fri, 19 Jun 2009 18:05:03 -0700 (PDT) Subject: Play MP3s from Windows References: Message-ID: On Jun 20, 8:48?am, MRAB wrote: > Arlie wrote: > > Hi, > > > Newbie here. I copied and pasted the code below. But when I ran it I > > got this error: > > > D:\>python mp3.py > > Duree du fichier : ?298919 ?millisecondes > > Traceback (most recent call last): > > ? File "mp3.py", line 37, in > > ? ? time.sleep(int(buf)/1000) > > ValueError: invalid literal for int() with base 10: '' > > > The code: > > > # -*- coding: utf-8 -*- > > > import time > > from ctypes import windll, c_buffer > > > class mci: > > ? ? def __init__(self): > > ? ? ? ? self.w32mci = windll.winmm.mciSendStringA > > ? ? ? ? self.w32mcierror = windll.winmm.mciGetErrorStringA > > > ? ? def send(self,commande): > > ? ? ? ? buffer = c_buffer(255) > > ? ? ? ? errorcode = self.w32mci(str(commande),buffer,254,0) > > ? ? ? ? if errorcode: > > ? ? ? ? ? ? return errorcode, self.get_error(errorcode) > > ? ? ? ? else: > > ? ? ? ? ? ? return errorcode,buffer.value > > > ? ? def get_error(self,error): > > ? ? ? ? error = int(error) > > ? ? ? ? buffer = c_buffer(255) > > ? ? ? ? self.w32mcierror(error,buffer,254) > > ? ? ? ? return buffer.value > > > ? ? def directsend(self, txt): > > ? ? ? ? (err,buf)=self.send(txt) > > ? ? ? ? if err != 0: > > ? ? ? ? ? ? print'Erreur',str(err),'sur',txt,':',buf > > ? ? ? ? return (err,buf) > > > mci=mci() > > mci.directsend('open "d:\\Linger.mp3" alias toto') > > mci.directsend('set toto time format milliseconds') > > err,buf=mci.directsend('status toto length ') > > print 'Duree du fichier : ',buf,' millisecondes' > > ?From the output it's clear that 'buf' contains '298919'. > > > err,buf=mci.directsend('play toto from 0 to '+str(buf)) > > time.sleep(int(buf)/1000) > > ?From the output it's clear that 'buf' contains ''. Are you expecting it > to contain the length, like it did for the previous call? Perhaps you > should just use the length returned by the previous call. I actually did that and it's working fine now. Thanks. > > > mci.directsend('close toto') > > I just got the program from the web. I have never program in python but I'm taking the risk of replacing an existing perl program for a more readable code. As of now everything seems like a haze to me. I have read python tutorial just yesterday. I'm due to deliver this project in 36 hours or less. This is suppose to download mp3 file to client then connect to mysql get the person info and play appropriate mp3 for that person calling his full name. From gagsl-py2 at yahoo.com.ar Fri Jun 19 22:16:20 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Jun 2009 23:16:20 -0300 Subject: Blogger Widget web app References: <7b3f931c-7750-440d-8f91-315c4c04dc72@d2g2000pra.googlegroups.com> Message-ID: En Thu, 11 Jun 2009 16:44:03 -0300, steven.oldner escribi?: > Please give me directions on where to start researching for answers. > I probably can do the javascript, but I don't know where to start on > the Python. > > 1. Wife has a blogger blog and wants a widget to embed in the posts. > 2. Widget will have a form that readers can enter their name and url. > 3. Widget also lists in numeric order the name and url of all the > readers who signed up in that post. > 4. Son has an old PC he turned into a server, and installed Windows > IIS on it. I'd look in the Python Package Index http://pypi.python.org/ for existing solutions. -- Gabriel Genellina From exarkun at divmod.com Fri Jun 19 22:42:57 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 19 Jun 2009 22:42:57 -0400 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <3LV_l.19708$y61.13502@news-server.bigpond.net.au> Message-ID: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> On Sat, 20 Jun 2009 00:07:27 GMT, Lie Ryan wrote: > [snip] > >Perhaps we should have more built-in/stdlib operations that can release >GIL safely to release GIL by default? And perhaps some builtin/stdlib >should receive an optional argument that instruct them to release GIL >and by passing this argument, you're making a contract that you wouldn't >do certain things that would disturb the builtin/stdlib's operations; >the specifics of what operations are prohibited would be noted on their >docs. There would be a lot less useless discussion if people would do a minimal amount of checking to see if the ideas they're suggesting are at all feasible. Why don't you take a look at the CPython source and see if this is actually possible? If you're not comfortable diving into a C program, then maybe you could try to become so first, or refrain from making suggestions that rely on technical details you know nothing about? Jean-Paul From gagsl-py2 at yahoo.com.ar Fri Jun 19 23:15:55 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 00:15:55 -0300 Subject: Error in reg dll References: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Message-ID: En Tue, 16 Jun 2009 02:09:57 -0300, Girish escribi?: > I am not able to register DLL generated from py2exe > When I try to register the dll using the commant: regsve32 dspace.dll, > I am getting error saying :"DLLRegisterServer in dspace.dll failed. > Return code was: 0xc0000005" I don't think the problem is in your setup.py, but on Dspace.py or any module it uses. 0xc0000005 is an Access Violation - an attempt to read/write memory at an illegal address. Try removing pieces from Dspace.py until you find the culprit. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Jun 19 23:50:14 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 00:50:14 -0300 Subject: Getting a processes' name? References: <4CD74416FB9F204EA1258409610E5626AD127A@svits27.main.ad.rit.edu> Message-ID: En Tue, 16 Jun 2009 11:42:08 -0300, Daniel Merboth (RIT Student) escribi?: > My college uses a program called AccessGrid for video conferencing, and > it runs through pythonw.exe. It comes with a python script to kill all > processes and exit the program. The problem is, the script kills > everything related to pythonw.exe, including my open scripts. I'm > looking for a way to get the name of the window or the processname, or > something, to differentiate between the running versions of pythonw.exe. The lazy answer is to make a copy of pythonw.exe under another name, and use that to launch the other scripts... Another way would be to use ExeMaker [1] so the process name is not pythonw.exe but another one. http://effbot.org/zone/exemaker.htm -- Gabriel Genellina From clp2 at rebertia.com Fri Jun 19 23:51:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Jun 2009 20:51:39 -0700 Subject: IDLE comments In-Reply-To: <1245306236.3326.3.camel@jason-desktop> References: <1245306236.3326.3.camel@jason-desktop> Message-ID: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: > Why does IDLE use two hash marks for comments (##)? Most other editors > (Geany, SPE) use a single hash mark (#) to designate comments. I would guess to distinguish its (usually block) comments from manually-added (usually explanatory) comments, but this is just conjecture. > How does one change IDLE to use just a single (#) hash mark for comments? Edit its source code? The GUI doesn't appear to expose any option for it. Cheers, Chris -- http://blog.rebertia.com From greg at cosc.canterbury.ac.nz Fri Jun 19 23:58:56 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 20 Jun 2009 15:58:56 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: <7a351vF1tjnsaU1@mid.individual.net> ryles wrote: > However, in 3.0 list > comprehensions are actually treated as list(). That's not quite true -- it would be rather inefficient if it was. The code generated for the LC is much the same as it was in 2.x. But the whole LC is put into a nested function so that the loop variables are local to it. -- Greg From greg at cosc.canterbury.ac.nz Sat Jun 20 00:09:08 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 20 Jun 2009 16:09:08 +1200 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: Message-ID: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Philip Semanchuk wrote: > try: > sem.acquire() # User hits Ctrl + C while this is waiting > except: > print "********* I caught it!" > Instead a KeyboardInterrupt error is propagated up to the interpreter > and the process is killed as if the try/except wasn't there at all. Not sure exactly what's happening, but I think I can guess. Python installs a signal handler for Ctrl-C that sets a flag in the interpreter. Every so many bytecodes executed, the flag is checked and KeyboardInterrupt raised if it's set. So there can be a short delay between the Ctrl-C signal being received and KeyboardInterrupt being raised, and it seems that this delay results in it happening after the try-except has exited. You could try using signal.signal() to install a handler for Ctrl-C that does nothing in a section around the sem.acquire call(). That should prevent the KeyboardInterrupt flag from being set, but the signal will still be occurring at the Unix level, so the system call will get interrupted. -- Greg From aahz at pythoncraft.com Sat Jun 20 00:17:50 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 21:17:50 -0700 Subject: Is this pylint error message valid or silly? References: <87eitg267e.fsf@benfinney.id.au> Message-ID: In article <87eitg267e.fsf at benfinney.id.au>, Ben Finney wrote: >Matthew Wilson writes: >> >> from datetime import datetime >> def f(c="today"): >> if c == "today": >> c = datetime.today() >> return c.date() > >* You're re-binding the parameter name ???c??? to something different within > the function: it starts out bound to the input string, but by the time > the function ends you're expecting it to be bound to a datetime > object. Instead, you should be binding a *different* name to the > datetime object you create inside the function, and using that for the > return statement. Actually, I disagree that this is necessarily bad, although it's often a yellow flag. The context in which it is possibly appropriate is when you want your function to handle multiple types for one parameter and you always cast the data to one single type. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sat Jun 20 00:27:51 2009 From: aahz at pythoncraft.com (Aahz) Date: 19 Jun 2009 21:27:51 -0700 Subject: Missing c.l.py posts (was Re: A question on scope...) References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> Message-ID: In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > >NB : answering the OP (original post didn't show up on c.l.py ???) Correct. There's a problem with the mail->news gateway, I think that MIME messages are failing. I "fixed" the problem for c.l.py.announce by making the list reject non-ASCII messages, but I don't think that's an option for python-list. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From vincent at vincentdavis.net Sat Jun 20 01:20:22 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Jun 2009 23:20:22 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) Message-ID: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> I currently have something like this. class applicant(): def __int__(self, x, y): self.randomnum = normalvariate(x, y) then other stuff x, y are only used to calculate self.randomnum and this seems to work. But I want self.randomnum to be 0 <= randomnum <= 100. The only way I can thing of to do this is is with a while statement and that seems more complicated than necessary. I would really like to keep it on one line. How would I do that? Thanks Vincent Davis From gervich at sbcglobal.net Sat Jun 20 02:55:04 2009 From: gervich at sbcglobal.net (Jason Gervich) Date: Fri, 19 Jun 2009 23:55:04 -0700 Subject: IDLE comments In-Reply-To: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> References: <1245306236.3326.3.camel@jason-desktop> <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> Message-ID: <1245480904.3326.21.camel@jason-desktop> Thanks, Chris. The best (and only) explanation I've heard so far. AS for as editing the source code, that's beyond my gnubyness. I thought there might be an easily accessible configuration file, but for the time I'll use it as is. I do wonder why in all these forum discussions about which Python editor to use, IDLE is seldom mentioned. Perhaps the Curse of the Gnuby lies upon it! Thanks for the quick response. Jason Gervich Santa Cruz, CA On Fri, 2009-06-19 at 20:51 -0700, Chris Rebert wrote: > On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: > > Why does IDLE use two hash marks for comments (##)? Most other editors > > (Geany, SPE) use a single hash mark (#) to designate comments. > > I would guess to distinguish its (usually block) comments from > manually-added (usually explanatory) comments, but this is just > conjecture. > > > How does one change IDLE to use just a single (#) hash mark for comments? > > Edit its source code? The GUI doesn't appear to expose any option for it. > > Cheers, > Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_re at fastmail.us Sat Jun 20 03:38:14 2009 From: john_re at fastmail.us (john_re) Date: Sat, 20 Jun 2009 00:38:14 -0700 Subject: Join Python Global Meeting Sunday June 21 using VOIP - BerkeleyTIP Message-ID: <1245483494.28252.1321307207@webmail.messagingengine.com> Join the friendly Python Global [& ALL FREE SW HW & CULTURE] community Meeting: this Sunday, June 21, using VOIP, 10A - 6P Pacific USA time [GMT - 8? 7? hours] = 1P - 9P Eastern USA = 6P - 2A??? GMT - Daylight savings correction? +7 hours? at the BerkeleyTIP Global Free SW HW & Culture meeting http://sites.google.com/site/berkeleytip/ CONNECT VIA VOIP (& IRC): Join IRC channel #berkeleytip on freenode.net, & we'll help get you connected on VOIP. Have a VOIP headset. http://sites.google.com/site/berkeleytip/remote-attendance LOCAL MEETING NEW LOCATION: Free speech cafe closed Sundays in summer. Watch the BTIP local list for final in person UCB meeting location details: http://groups.google.com/group/BerkTIP GENERIC HOURLY SCHEDULE, & MARK YOUR CALENDAR - NEXT 3 MEETINGS: Sun June 21, Sat July 4, Sun July 19 http://sites.google.com/site/berkeleytip/schedule Join the mailing list, introduce yourself, tell us what projects you are interested in, invite others to join your project: BTIP-Global http://groups.google.com/group/BerkTIPGlobal ===== HOT TOPICs: Oracle owns OpenOffice & MySQL - What help is needed? KDE 4 aps need work - especially Calendar?! Open Hardware - Robotics? POLL: ** How about 2x per month Weekday Evening BTIP-Global Meetings? ** 1) The Wednesday & Thursday _after_ the BTIP weekend meetings? 2) The Monday & Tuesday _before_ the BTIP weekend meetings? 3) Other? Your suggestions? - Join the mailing list & send in your opinions/thoughts/suggestions. GROUP PROJECT - Asterisk VOIP conference server: We've now got our own Asterisk VOIP conference server. [Thanks, Windsor & Jack! :) ] Help: - get a user channel members status page working - get SIP & Skype ability? http://sites.google.com/site/berkeleytip/remote-attendance YOUR PROJECT - LET US KNOW, GET SOME VOLUNTEER HELP: http://groups.google.com/group/BerkTIPGlobal VIDEOS - OPPORTUNITY - FINDER VOLUNTEER NEEDED No videos this month, cause David & I are too busy. Do you want to find some for us all to watch? Check out this link, email the list & let us know you'd like to volunteer. :) http://sites.google.com/site/berkeleytip/talk-videos See the mailing lists for the latest info/changes: http://sites.google.com/site/berkeleytip/mailing-lists JOIN THE ANNOUNCEMENT LIST - 1 or 2 announcements per month: http://groups.google.com/group/BerkTIPAnc FOR FORWARDING: You are invited to forward this message to anywhere appropriate. From piet at cs.uu.nl Sat Jun 20 04:19:28 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:19:28 +0200 Subject: KeyboardInterrupt eats my error and then won't be caught References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: >>>>> greg (g) wrote: >g> Philip Semanchuk wrote: >>> try: >>> sem.acquire() # User hits Ctrl + C while this is waiting >>> except: >>> print "********* I caught it!" >>> Instead a KeyboardInterrupt error is propagated up to the interpreter >>> and the process is killed as if the try/except wasn't there at all. >g> Not sure exactly what's happening, but I think I can guess. >g> Python installs a signal handler for Ctrl-C that sets a >g> flag in the interpreter. Every so many bytecodes executed, >g> the flag is checked and KeyboardInterrupt raised if it's >g> set. >g> So there can be a short delay between the Ctrl-C signal >g> being received and KeyboardInterrupt being raised, and it >g> seems that this delay results in it happening after the >g> try-except has exited. I think you are approaching the cause of the problem. Your answer triggered the following thought in my head: There are actually two exceptions occurring: One is the Ctrl-C, which as you correctly say, will probably delayed until there is a `check' in the interpreter (see also David Beazley's wonderful presentation on the GIL). The other one is the exception that is generated in the IPC code by returning a NULL. This one should caught by the except clause. As the call to sem.acquire releases and reacquires the GIL, I think signal processing will be done immediately. This causes the KeyboardInterrupt exception to occur immediately i.e. to interrupt the handling of the other exception. >g> You could try using signal.signal() to install a handler >g> for Ctrl-C that does nothing in a section around the >g> sem.acquire call(). That should prevent the KeyboardInterrupt >g> flag from being set, but the signal will still be occurring >g> at the Unix level, so the system call will get interrupted. Your suggestion seems to work: import posix_ipc import signal sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) signal.signal(signal.SIGINT, lambda sig, frame: None) status = [] try: status.append("Trying") sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except: status.append("I caught it!") print status sem.close() sem.unlink() prints: ['Trying', 'I caught it!'] I also tried some other variants, catching the KeyboardInterrupt at various places: This one prints: ['Trying', 'Keyboard Interrupt'] This suggests to me that the first exception handling is aborted by the Ctrl-C handling. import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) status = [] try: try: status.append("Trying") sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except: status.append("I caught it!") except KeyboardInterrupt: status.append("Keyboard Interrupt") print status sem.close() sem.unlink() And this one prints: ['Trying', 'I caught it!'] import posix_ipc sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX) status = [] try: status.append("Trying") try: sem.acquire() # User hits Ctrl + C while this is waiting status.append("Acquired") except KeyboardInterrupt: status.append("Interrupt") except: status.append("I caught it!") print status sem.close() sem.unlink() I was actually a bit surprised that the addition of the try/except KeyboardInterrupt helps solve the problem but that apparently the exception handler is not executed. Folding the two try's into one with two except clauses will not help as there are indeed two exceptions to be handled. I also added traceback printout in the outer exception handler and it points to the sem.acquire line. My conclusion is that if there are two exceptions at the same time, the inner exception handler is interrupted by the other exception even before the except clause can be entered. And only the outer one is really executed. This explains the behaviour that the OP described. I think you can only have two exceptions at the same time if at least one of them is a signal. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Sat Jun 20 04:34:58 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:34:58 +0200 Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <39741266-9f4e-4d6c-ba22-021413ff4bc4@n8g2000vbb.googlegroups.com> Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> Sorry, just a few more thoughts: >JE> Does anybody know why GIL can't be made more atomic? I mean, use >JE> different locks for different parts of code? >JE> This way there would be way less blocking and the plugin interface >JE> could remain the same (the interpreter would know what lock it used >JE> for the plugin, so the actual function for releasing / reacquiring the >JE> lock could remain the same) >JE> On second thought, forget this. This is probably exactly the cause of >JE> free-threading reduced performance. Fine-graining the locks increased >JE> the lock count and their implementation is rather slow per se. The major obstacles are the refcounts. It would mean that each refcounted object would need a separate lock including constants like 0, 1, True, None. You would have much more locking and unlocking then with the GIL. So to get rid of it first the refcounting has to go. But that is not sufficient. When the GIL will be removed I suspect that many concurrent programs will start to fail subtly because they make assumptions about the atomicity of the operations. In CPython each bytecode is atomic, but when there is no GIL this is no longer true. Java has defined this quite rigorously in its memory model (although there first memory model had subtle bugs): Read and write operations on 32-bit quantities are atomic, others not. This means that on a 64-bit system, where pointers are 64-bit even assignments on variables of object types are not atomic and have to be protected with synchronized. (My info is a few years old, so in the meantime it may have changed.) In a GIL-less python the same would be true. Of course the hardware that your program is running on could have atomic read/writes on 64-bit quantities but if you rely upon that your program may no longer be portable. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From mail at timgolden.me.uk Sat Jun 20 04:39:10 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 20 Jun 2009 09:39:10 +0100 Subject: How to check if file is open on Windows XP? In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F1@EVS1.aeroflex.corp> Message-ID: <4A3CA02E.7080209@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I'm looking for a fascility that can check if the file is open on Windows XP > and if the file is open (say a notepad file is open), I want to close that file > (i.e the notepad application) In short, this is far trickier than you might imagine. It's come up a number of times on the Python / Python-win32 lists. A recent thread is here: http://mail.python.org/pipermail/python-list/2009-May/713077.html But if you simply Google for things like: site:mail.python.org sysinternals handle You'll get a bunch of hits asking / answering the same thing. TJG From piet at cs.uu.nl Sat Jun 20 04:45:08 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:45:08 +0200 Subject: Status of Python threading support (GIL removal)? References: Message-ID: >>>>> Jure Erzno?nik (JE) wrote: >JE> I have shown my benchmarks. See first post and click on the link. >JE> That's the reason I started this discussion. >JE> All I'm saying is that you can get threading benefit, but only if the >JE> threading in question is implemented in C plugin. >JE> I have yet to see pure Python code which does take advantage of >JE> multiple cores. From what I read about GIL, this is simply impossible >JE> by design. In fact, at least theoretically, your original application could benefit from multiple cores. Take this scenario: You have one thread that reads from a file. On each read the GIL is released until the read has completed. In the meantime the other thread could do some CPU-intensive work. Now if the read comes entirely from the O.S. cache it is also CPU-bound. So there a second core comes in handy. Now usually these reads will not consume so much CPU so it will probably be hardly noticeable. But if you would have some kind of CPU-intensive User-space File System, for example with compression and/or encryption and the data is in memory you might notice it. In this example all your application code is written in Python. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From piet at cs.uu.nl Sat Jun 20 04:49:00 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 10:49:00 +0200 Subject: Status of Python threading support (GIL removal)? References: Message-ID: >>>>> Ross Ridge (RR) wrote: >RR> By definition an I/O bound thread isn't CPU bound so won't benefit from >RR> improved CPU resources. But doing I/O is not the same as being I/O bound. And Python allows multithreading when a thread does I/O even if that thread is not I/O bound but CPU bound. See my other posting for an example. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From ldo at geek-central.gen.new_zealand Sat Jun 20 04:51:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 20:51:07 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617142431.2b25faf5@malediction> <20090617214535.108667ca@coercion> <20090618081423.2e0356b9@coercion> <20090619134015.349ba199@malediction> Message-ID: In message <20090619134015.349ba199 at malediction>, Mike Kazantsev wrote: > On Fri, 19 Jun 2009 17:53:40 +1200 > Lawrence D'Oliveiro wrote: > >> In message <20090618081423.2e0356b9 at coercion>, Mike Kazantsev wrote: >> >> > On Thu, 18 Jun 2009 10:33:49 +1200 >> > Lawrence D'Oliveiro wrote: >> > >> >> In message <20090617214535.108667ca at coercion>, Mike Kazantsev >> >> wrote: >> >> >> >>> On Wed, 17 Jun 2009 23:04:37 +1200 >> >>> Lawrence D'Oliveiro wrote: >> >>> >> >>>> In message <20090617142431.2b25faf5 at malediction>, Mike Kazantsev >> >>>> wrote: >> >>>> >> >>>>> On Wed, 17 Jun 2009 17:53:33 +1200 >> >>>>> Lawrence D'Oliveiro wrote: >> >>>>> >> >>>>>>> Why not use hex representation of md5/sha1-hashed id as a >> >>>>>>> path, arranging them like /path/f/9/e/95ea4926a4 ? >> >>>>>>> >> >>>>>>> That way, you won't have to deal with many-files-in-path >> >>>>>>> problem ... >> >>>>>> >> >>>>>> Why is that a problem? >> >>>>> >> >>>>> So you can os.listdir them? >> >>>> >> >>>> Why should you have a problem os.listdir'ing lots of files? >> >>> >> >>> I shouldn't, and I don't ;) >> >> >> >> Then why did you suggest that there was a problem being able to >> >> os.listdir them? >> > >> > I didn't, OP did ... >> >> Then why did you reply to my question "Why is that a problem?" with >> "So that you can os.listdir them?", if you didn't think there was a >> problem (see above)? > > Why do you think that if I didn't suggest there is a problem, I think > there is no problem? It wasn't that you didn't suggest there was a problem, but that you suggested a "solution" as though there was a problem. > Why would you want to listdir them? It's a common need, to find out what's in a directory. > I can imagine at least one simple scenario: you had some nasty crash > and you want to check that every file has corresponding, valid db > record. But why would that be relevant to this case? From ldo at geek-central.gen.new_zealand Sat Jun 20 04:54:03 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 20:54:03 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: In message , Lie Ryan wrote: > Lawrence D'Oliveiro wrote: > >> In message <%Zv_l.19493$y61.5958 at news-server.bigpond.net.au>, Lie Ryan >> wrote: >> >>> Yeah, it might be possible to just mv the file from outside, but not >>> being able to enter a directory just because you've got too many files >>> in it is kind of silly. >> >> Sounds like a problem with your file/directory-manipulation tools. > > try an `ls` on a folder with 10000+ files. > > See how long is needed to print all the files. As I've mentioned elsewhere, I had scripts routinely dealing with directories containing around 400,000 files. > Ok, now pipe ls to less, take three days to browse through all the > filenames to locate the file you want to see. Sounds like you're approaching the issue with a GUI-centric mentality, which is completely hopeless at dealing with this sort of situation. From pavlovevidence at gmail.com Sat Jun 20 05:02:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 02:02:34 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> On Jun 19, 4:42?pm, Christian Heimes wrote: > OdarR schrieb: > > > On 19 juin, 21:41, Carl Banks wrote: > >> He's saying that if your code involves extensions written in C that > >> release the GIL, the C thread can run on a different core than the > >> Python-thread at the same time. ?The GIL is only required for Python > >> code, and C code that uses the Python API. ?C code that spends a big > >> hunk of time not using any Python API (like, as Skip pointed out, a > >> matrix multiply) can release the GIL and the thread can run on a > >> different core at the same time. > > > I understand the idea, even if I don't see any examples in the > > standard library. > > any examples ? > > http://svn.python.org/view/python/trunk/Modules/posixmodule.c?revisio... > > Search for Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS > > > yes, I also speak about hard computation that could benefit with > > multiple cores. > > Hard computations gain more speed from carefully crafted C or Fortran > code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or > parallelized algorithms. If you start sharing values between multiple > cores you have a serious problem. > > Oh, and use NumPy for the job ;) > > >> I wish people would just say, "This is a limitation of > >> CPython. ?There are reasons why it's there, and it helps some people, > >> but unfortunately it has drawbacks for others", instead of the typical > >> "all u hav 2 do is rite it in C LOL". > > > "LOL" > > I would like to say such thing about my weather...I live in Europe in > > a rainy country. > > It *is* a well known limitation of Python. All the nice 'n shiny syntax > and features are coming with a cost. Python is a powerful language and > good tool for lots of stuff. But Python is and will never become the > ?bertool that solves every problem perfectly. At some point you need a > different tool to get the raw power of your machine. C (and perhaps > Fortran) are the weapons of choice for number crunching. This is the narrowminded attitude that irritates me. Here's the thing: not everyone complaining about the GIL is trying to get the "raw power of their machines." They just want to take advantage of multiple cores so that their Python program runs faster. It would be rude and presumptuous to tell such a person, "Well, GIL isn't that big of a deal because if you want speed you can always rewrite it in C to take advantage of multiple cores". Carl Banks From pavlovevidence at gmail.com Sat Jun 20 05:16:17 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 02:16:17 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <14f2ed75-20cd-4850-bc2e-6ea17a21ba51@r31g2000prh.googlegroups.com> On Jun 19, 4:35?pm, a... at pythoncraft.com (Aahz) wrote: > In article <157e0345-74e0-4144-a2e6-2b4cc854c... at z7g2000vbh.googlegroups.com>, > Carl Banks ? wrote: > >I wish Pythonistas would be more willing to acknowledge the (few) > >drawbacks of the language (or implementation, in this case) instead of > >all this rationalization. ? > > Please provide more evidence that Pythonistas are unwilling to > acknowledge the drawbacks of the GIL. I will not, since I was not making an assertion, but an observation that some Pythonistas ignore (and even outright dismiss) claims that Python has a drawback by countering with a suggestion that they should be doing it some other, often more obtuse, way anyway--and expressing a wish that I could observe this less often. Carl Banks From kay at fiber-space.de Sat Jun 20 05:36:22 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 20 Jun 2009 02:36:22 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Message-ID: > You might want to read about "The Problem with Threads": > > http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf > > and then decide to switch to an appropriate concurrency model for your use > case. and to a programming language that supports it. From contact at xavierho.com Sat Jun 20 05:37:20 2009 From: contact at xavierho.com (Xavier Ho) Date: Sat, 20 Jun 2009 19:37:20 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> While there are a lot of valid ways to do it, anything you do will change the outcome of the probability anyway. I'm assuming you are just looking to clamp the values. Try this: http://codepad.org/NzlmSMN9 (it runs the code, too) ========================================== # Clamp a normal distribution outcome import random class applicant(): def __init__(self, x, y): self.randomnum = clamp(random.normalvariate(x, y), 0, 100) def clamp(input, min=0, max=100): """Clamps the input between min and max. if input < min, returns min min < input < max, returns input input > max, returns max Default: min = 0, max = 100.""" if input < min: return min elif input > max: return max else: return input if __name__ == "__main__": for num in range(10): print applicant(random.randint(0,100), random.randint(0,100)).randomnum ====================================================== Or you could just use randint() if you only wanted a linear distribution. PS: Thanks, btw, new to python myself also, and looking into this was cool. :] Best regards, 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 Sat, Jun 20, 2009 at 3:20 PM, Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. I would really like to keep it > on one line. How would I do that? > > Thanks > Vincent Davis > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sat Jun 20 05:38:00 2009 From: http (Paul Rubin) Date: 20 Jun 2009 02:38:00 -0700 Subject: Question about None References: Message-ID: <7xzlc3gs93.fsf@ruckus.brouhaha.com> Paul LaFollette writes: > So, what I would like is some sort of object that is a "kind of" > everything but contains nothing, a unique minimal element of the > partial ordering imposed on the set of classes by the inheritance > heierarchy. Whilst I am not naive mathematically, I am relatively > naive in the area of language design. In my naivete, it seemed to me > that None could have been designed to be such a thing. Apparently > that is incorrect. I don't remember if I linked to this article: http://en.wikibooks.org/wiki/Haskell/Denotational_semantics You might like it. If you want to learn some contemporary programming language theory at a mathematical level, start with Harper's "Practical Foundations for Programming Languages": http://www.cs.cmu.edu/~rwh/plbook/book.pdf From ldo at geek-central.gen.new_zealand Sat Jun 20 06:21:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Jun 2009 22:21:12 +1200 Subject: File Syncing References: Message-ID: In message , dads wrote: > What would I have to learn to be able to sync the text files on each > server? How big is the text file? If it's small, why not have your script read it directly from a master server every time it runs, instead of having a local copy. From Olivier.Darge at gmail.com Sat Jun 20 06:24:37 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 20 Jun 2009 03:24:37 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <9ec761b0-3782-4153-a0d8-9b5f4fb171fd@t11g2000vbc.googlegroups.com> On 20 juin, 11:02, Carl Banks wrote: > Here's the thing: not everyone complaining about the GIL is trying to > get the "raw power of their machines." ?They just want to take > advantage of multiple cores so that their Python program runs > faster. > > It would be rude and presumptuous to tell such a person, "Well, GIL > isn't that big of a deal because if you want speed you can always > rewrite it in C to take advantage of multiple cores". merci Carl, you expressed what I would like to tell. Olivier From sumerc at gmail.com Sat Jun 20 06:58:02 2009 From: sumerc at gmail.com (k3xji) Date: Sat, 20 Jun 2009 03:58:02 -0700 (PDT) Subject: YASS (Yet Another Success Story) Message-ID: <534f19f6-181c-42ee-803c-9bd867b6d053@n4g2000vba.googlegroups.com> Hi all, Started a project year ago with hard goals in mind : Developing a game server which can handle thousands of clients simultaneously.System must be stable, scalable, efficient, and if the client need to migrate the server to another OS, this will be a matter of time, if possible without changing any code. Also, the system should be controlled via database operations, meaning some specific DB changes should be determined by the system on-the-fly and necassary processing should be done at runtime(Client timeout values, adding new game lobbies..etc..) And all of this should be a one-man project dues to the fact that the project is a volunteer work, thus is separate from our ordinary jobs, there is no budget:). This was 8 months ago, and I still remember we are talking with my colleguae to decide which programming language is better for our requirements. We wrote the tradeoffs of different languages on board and compare our objectives against them by giving numbers. I remember, the last three standing programming languages are: C++, Java, and Python. We decided that code maintability and stability is cheaper than native code efficiency and also easy porting is important. C++ is only successfull on efficiency but maintaining the code, even if we use 3rd party libraries is a nightmare, especially in a massive multithreaded project like a game server. Also, we decided a game server's bottleneck is on network I/O other than the actual processing which means there should be not so much performance degradation between C++ and an interpreted language. So the final is between Java and Python. I know Java has been adding very good optimizations for interpreter efficiency over the years(JIT compiling..etc.) And I remember somewhere reading that Java is 10 times faster than Python. But Python, on the other hand is a perfect language and very simple which means the project may be completed sooner and efficiency again will be not a so much problem as the bottleneck should be on network I/O if the server is coded correctly. Although we have made this decision, we still had some doubts but we move on with Python. I don't know Python at the time and only coded few simple projects with it. I started with reading python socket/threading tutorials, then I downloaded and read actual Python code to get deeper and deeper. This was 10 months ago. Now we have been able to implement the game server with Python using MySQL as a backend DB and currently 5000 players (increasing) are playing multiplayer games with it with a system load of 0.4-0.8(see Unix getloadavg output) on a 1.8 Ghz Dual Xeon processor. Let me give some benchmarks, please note that one thing I learn through this journey is that testing/benchmarking a server software is really difficult and maybe in some conditions impossible thing to do correctly as inactive client connections may cause indeterministic behavior and also WAN latencies are very different than LAN latencies..etc. Anyway, we had to do a benchmark before going with this server on live. We installed a UnrealIRCd server which is also using select() as an I/O paradigm just as we are and supporting many of the features we have. This server is a IRC server written in C and being written since nearly 10 years. We connect thousands of clients and do simple messaging between them. I don't have an official test/benchmark result or a nice graph for this, however the system running UnrealIRCD is locked up when processing 4 Mb/sec of data, where our 6 month old Python server is locking up the system resources after 3.5 Mb/sec. We have done other tests including stressing server accept(), adding inactive connections but I am really not %100 confident about the test environments and do not want to give you false impression. But we decided that this 0.5 Mb factor is still not enough for us and we move on to inspect what is really causing the bottlenecks and how to optimize them. Here, to be honest, I cannot see very uch help from Python. Profiling/Optimization is the only place I am upset with Python. Here is the requirements for the profiler: I want to be able to enable/disable profiler tool on the fly without requiring any kind of restart and the profiler should be multithreaded (thus thread-safe). I decided that cProfiler and other profiler tools are in need of some updates to fulfill my req?rements, which makes me write my own profiler. It took me 3 days to come up with a profiler that satisfies my requirements, this profiler will profile only my code, meaning the server code to avoid performance degradation and timings will need not be nested-aware and timing precision is not very important (other than secs). I have implemented the profiler with the help of decorators and started profiling my code on-live. Here comes the another part of Python that is some kind of shady: optimization. After profiling the code, it turns out most of the time is spent on the following: 1) Selecting/Deselecting interest sets for select() 2) Unnecessary function calls. (for integrating some OOP concepts, I think we have overlooked the performance factor and there really are some functions which can be inlined but declared as a function) 3) Redundant try-except's in all over place(Again our fault to make the system stable, we have put some debug purposed-assert like try- excepts in the main server flow.) After, looking on these subjects for 2 weeks, we came up with solutions for all of them, and we see that it is working approximately 5 times faster. This test is done in live, we run two server processes which are all running on a predefined CPU(means CPU affinity of the process is set before hand to avoid mis-interpreting system diagnose tools like top(1)). When same client number is connected to both servers, the second one is giving 5 times better values in top and ps tools. Also, the processing time (meaning the server loop except the select() call) is also 10 times faster than before. Just one note about optimizing Python code: do not optimize Python code based on your assumptions, just go and test if it really runs faster. I don't want to go to details of this hint, but believe me making Python code optimized may be very very tricky. It is then I decided to write up here this as a success story, as I am very newcomer to Python but come up with a nearly commercial product in a very short period of time and I don't think this is about my personal characteristics and intelligence or so:), as I am old enough to know/meet that there are much much more brilliant people than I am and they also have similar experiences with Python. So, one last note: every software project goes same tasks as above often much much more officially and carefully, I would suggest managers to see that just do not listen to the ordinary brain-washes. Python is a great choice for easy developing, easy debugging, easy maintaining and most importantly very very time-friendly. Of course there will be tasks .n which Python is suitable, but hey, if it Python is in the list, take it seriously. Thanks, Special thanks to people in this group who had answered my silly Python questions along the way. S?mer Cip From Yell123 at aol.com Sat Jun 20 07:12:48 2009 From: Yell123 at aol.com (Yell123 at aol.com) Date: Sat, 20 Jun 2009 07:12:48 EDT Subject: Python in Nashville Message-ID: I maintain a math hobby - magic square web page _http://www.knechtmagicsquare.paulscomputing.com/_ (http://www.knechtmagicsquare.paulscomputing.com/) A very bright fellow in England sent me a algorithm written in python to solve a problem I was working on. I can't seem to get it to work ... syntax problems.... The segment below gives the explanation and the code: If you are interested in the problem this solves ... see section 1 on my website "Topographical Model For the Magic Square" Sorry about the delay in replying; I've been having email problems.] > I read a article by your wife on magic squares. I have been fooling > around with magic square models. I read your bio and see you did some work > with random walk stuff. I have been wanting a algorithm ... ( perhaps a > Greedy algorithm) that would calculate the amount of retained water for any > order of magic square. ( see topographical model setion I on web link > below) Hm, interesting problem. Let's see. (Please forgive me if some or all of what I'm about to say is totally familiar and/or obvious to you.) If I've understood you right, your problem is as follows. Call the number written in each cell its "height". Define the "water height" of a cell to be the smallest N such that there's a path from that cell to the outside of the square using only cells of height <= N. So, when you pour an infinite amount of water over the square and let it settle, each cell ends up with water up to its water height, if that's bigger than its height. Then the "capacity" of the square is the sum of (water height - height) over cells for which that's positive, and you want to calculate the capacity of a given square. So, the following seems like a pretty good algorithm. It's a bit like Dijkstra's shortest-path algorithm. It needs a data structure called a "priority queue", which means a container that stores objects along with numbers called their "priorities", and has efficient ways of doing (1) add an object to the queue and (2) pull out the object with highest priority. We'll keep track of an upper bound on the water height for each cell, and use the queue to store cells for which we might be able to reduce the upper bound. No, actually we'll use it to store cells that might enable us to reduce their neighbours' upper bounds. 1. For each cell, set bound(cell) = n^2. (This is a very boring upper bound on the water height of the cell.) 2. For each cell on the edge of the square: 2a. Set bound(cell) = height(cell). 2b. Put that cell into the queue with priority -bound(cell). (So lower cells have higher priority. Actually, many priority queue implementations already use the "smaller number = higher priority" convention.) 3. While the queue isn't empty: 3a. Pull out the highest-priority cell from the queue. 3b. For each neighbour of that cell: 3b1. Let b = max(bound(cell),height(neighbour)). 3b2. If if bound(neighbour) > b: 3b2a. Set bound(neighbour) = b. 3b2b. Add the neighbour to the queue with priority -b. When this is finished, for every cell bound(cell) should equal (not just be an upper bound for) the cell's water height, because: 1. bound(cell) is always an upper bound on the cell's water height, because the only way it gets decreased is when we find that the cell has a neighbour whose water height is known to be <= its new value. (So there's a path from the cell to the edge, using nothing higher than that value, beginning with that neighbour.) 2. For cells along the edge, bound(cell) equals the cell's water height, because for these cells height = water height, and right at the start we set bound = height. 3. Suppose that when the algorithm finishes bound(cell) is actually bigger than cell's water height w. Then there is a path from the cell to the edge using nothing of height > w. Follow that path until you find a cell for which bound <= w. (There must always be one, since bound = height for edge cells and the last cell on our path is an edge cell and has height <= w.) Then we've found two adjacent cells of height <= w, one of which has bound <= w and one of which as bound > w. But at some point the former must have been put into the queue with bound <= w; when it came out, its neighbour would have been examined and had its bound decreased to <= w. Contradiction. >From 1 and 3, we find that at the end of the algorithm the bounds equal the water heights. Now we can just sum max(bound-height,0) over all cells, and get the total capacity of the square. Here's some Python code that does it (rather inefficiently): def process(square): n = len(square) # square is a list of lists bounds = [n*[n*n] for i in range(n)] queue = [] # lousy implementation, just for algorithm testing # head of queue is last element # big numbers for high priority for i in range(n-1): bounds[i][0] = square[i][0] queue.append((-bounds[i][0],i,0)) bounds[n-1][i] = square[n-1][i] queue.append((-bounds[n-1][i],n-1,i)) bounds[i+1][n-1] = square[i+1][n-1] queue.append((-bounds[i+1][n-1],i+1,n-1)) bounds[0][i+1] = square[0][i+1] queue.append((-bounds[0][i+1],0,i+1)) while queue: queue.sort() (b,i,j) = queue.pop() for (di,dj) in [(-1,0),(1,0),(0,-1),(0,1)]: u=i+di; v=j+dj if 0<=u0: s += delta return s Testing on one of your examples: >>> capacity([[6,26,49,34,35,13,12],[5,48,1,28,30,36,27], [47,2,19,20,21,29,37],[46,17,10,25,7,32,38],[45,24,22,3,33,9,39], [11,44,31,23,8,40,18],[15,14,43,42,41,16,4]]) 320 (Your page says 321, but I think 320 is correct. The sum of the heights in the submerged region is 394, not 393.) How efficient is this? Well, it's not quite obvious to me that a cell can't be put into the queue more than once, but I think that should be rare. So let's suppose that typically each cell goes in once. The queue should never be bigger than the number of cells aside from complications that arise when a cell is inserted more than once; it certainly shouldn't be bigger than, say, 4 times the number of cells. And each priority queue operation should take no worse than some modest multiple of log(queue_size) basic operations. So the total time to process the whole square shouldn't be worse than some small multiple of n^2 log n. That seems like about the best you could reasonably expect. (I have another approach in mind that might reduce that to n^2 f(n) where f grows even more slowly when n is very large, but at the cost of greater complexity when n is not very large. I bet you'll only be doing this for n not very large.) Note: the idiotic "sort the list every time" priority queue implementation in the Python code above is emphatically *not* suitable for production use. Find a proper priority queue implementation in your language of choice. -- g If some one could help me get this working ... I would be grateful. I have loaded Python Ver 2.6 ... but when I paste this code in it keeps giving me errors. Thanks Craig Knecht **************A Good Credit Score is 700 or Above. See yours in just 2 easy steps! (http://pr.atwola.com/promoclk/100126575x1222585064x1201462784/aol?redir=http://www.freecreditreport.com/pm/default.aspx?sc=668072&hmpgID=62&bcd= JunestepsfooterNO62) -------------- next part -------------- An HTML attachment was scrubbed... URL: From piet at cs.uu.nl Sat Jun 20 07:41:36 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 13:41:36 +0200 Subject: KeyboardInterrupt eats my error and then won't be caught References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: After my previous experiment I was curious how this works with input(). I replaced the sem.acquire() with raw_input() and ran the same tests. Now the inner exception is really taken so it works like the OP expected. The exception, however is KeyboardInterrupt, not the special exception from the IPC module. So I looked in the source code how they did it: The code is in Parser/myreadline.c. This code for input in function calls PyErr_CheckSignals() and PyOS_InterruptOccurred() for a proper handling of the interrupt. So it seems the OP should do something similar. Onl;y to deliver the custom error you will have to do some other stuff. I don't know what but maybe calling PyErr_SetString is sufficient as it might overwrite the KeyboardInterrupt stuff. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From castironpi at gmail.com Sat Jun 20 07:41:46 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 20 Jun 2009 04:41:46 -0700 (PDT) Subject: persistent composites References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> <043cefaf-80b3-474b-a54f-8cff47d454d0@d38g2000prn.googlegroups.com> <7xeitlv04x.fsf@ruckus.brouhaha.com> <013d6415-80b0-4984-84ed-b23c02fd6014@x29g2000prf.googlegroups.com> <20090616210909.10eb439c@coercion> Message-ID: <01a81c22-6da3-4bb9-a359-8ff6fc1270c3@l34g2000vbi.googlegroups.com> On Jun 19, 7:00?am, "Rhodri James" wrote: > On Fri, 19 Jun 2009 14:24:34 +0100, Aaron Brady ? > wrote: > > > You are not being any help, Rhodri, in your question. > > To you, perhaps not. ?To me, it has at least had the effect of making > what you're trying to do (write a pythonic object database) clearer. I stand corrected. Some help you were. I have nothing further to say about it. From python at mrabarnett.plus.com Sat Jun 20 08:34:00 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 13:34:00 +0100 Subject: IDLE comments In-Reply-To: <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> References: <1245306236.3326.3.camel@jason-desktop> <50697b2c0906192051t675a9c0ft5bd5841cead7806e@mail.gmail.com> Message-ID: <4A3CD738.8030807@mrabarnett.plus.com> Chris Rebert wrote: > On Wed, Jun 17, 2009 at 11:23 PM, Jason Gervich wrote: >> Why does IDLE use two hash marks for comments (##)? Most other editors >> (Geany, SPE) use a single hash mark (#) to designate comments. > > I would guess to distinguish its (usually block) comments from > manually-added (usually explanatory) comments, but this is just > conjecture. > The menu has the entries "Comment Out Region" and "Uncomment Region" so that you can disable lines of code by turning them into comments and then uncomment them again. By using "##" it can distinguish between comments that it has created from those that you might have added later, which start with one "#". >> How does one change IDLE to use just a single (#) hash mark for comments? > > Edit its source code? The GUI doesn't appear to expose any option for it. > From vincent at vincentdavis.net Sat Jun 20 08:54:23 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 06:54:23 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> Message-ID: <77e831100906200554h6068ac6k1b7ad97cc3e560dd@mail.gmail.com> > # Clamp a normal distribution outcome > > import random > > class applicant(): > ??? def __init__(self, x, y): > ??????? self.randomnum = clamp(random.normalvariate(x, y), 0, 100) > > def clamp(input, min=0, max=100): > ??? """Clamps the input between min and max. > > ??? if? input < min, returns min > ??????? min < input < max, returns input > ??????? input > max, returns max > > ??? Default: min = 0, max = 100.""" > ??? if input < min: > ??????? return min > ??? elif input > max: > ??????? return max > ??? else: > ??????? return input > > if __name__ == "__main__": > ??? for num in range(10): > ??????? print applicant(random.randint(0,100), > random.randint(0,100)).randomnum Why not have the def clamp inside the class? I would prefer to keep everything I need for the class together. I am new to classes but I have to say things like if __name__ == "__main__": have no intuitive meaning to me. It is true I don't know what __name__ and __main__ do and I can look it up but I don't even have a guess based on the names and usage. I am Now not sure if that is what I want or If I want to redraw from the distribution. I am wanting to simulate test scores. My option see to be to draw from a normal (I don't want linear) distribution and scale it to 0-100 or clamp it as you (Xavier) suggested or draw from the distribution again (this is what I was thinking) I think this is still what I want but I should look up the implications of each. The problem I have with the clamp is that the tails in the sample could be large. Thanks Vincent From contact at xavierho.com Sat Jun 20 09:01:58 2009 From: contact at xavierho.com (Xavier Ho) Date: Sat, 20 Jun 2009 23:01:58 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <2d56febf0906200600y36dd20d8ica7d08bfc5391e60@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <77e831100906200554h6068ac6k1b7ad97cc3e560dd@mail.gmail.com> <2d56febf0906200600y36dd20d8ica7d08bfc5391e60@mail.gmail.com> Message-ID: <2d56febf0906200601i634f1f49g6253db8eb91f0176@mail.gmail.com> (sorry Vincent, I sent it to you but not the mailing list.) Good luck, here are my answers: Why not have clamp in the class? Because Clamp itself is a reusable function. I was rather surprised it's not in the standard math module. if __name__ == "__main__" is only meaningful when the .py file itself is run as the main file (like typing in python name.py that has this code in the console). Otherwise if this file was imported and run in any other python run-time, including the standard console, the "__main__" part won't execute at all. The only purpose of that was to print out 10 random samples. If you're not sure if this is what you want, then um.. not much I can do there. What is this class originally for? If you feel the clamp is too huge, well, I'm always interested in improvements/alternatives! Best regards, 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 Sat, Jun 20, 2009 at 10:54 PM, Vincent Davis wrote: > > # Clamp a normal distribution outcome > > > > import random > > > > class applicant(): > > def __init__(self, x, y): > > self.randomnum = clamp(random.normalvariate(x, y), 0, 100) > > > > def clamp(input, min=0, max=100): > > """Clamps the input between min and max. > > > > if input < min, returns min > > min < input < max, returns input > > input > max, returns max > > > > Default: min = 0, max = 100.""" > > if input < min: > > return min > > elif input > max: > > return max > > else: > > return input > > > > if __name__ == "__main__": > > for num in range(10): > > print applicant(random.randint(0,100), > > random.randint(0,100)).randomnum > > Why not have the def clamp inside the class? I would prefer to keep > everything I need for the class together. > I am new to classes but I have to say things like if __name__ == > "__main__": have no intuitive meaning to me. It is true I don't know > what __name__ and __main__ do and I can look it up but I don't even > have a guess based on the names and usage. > > I am Now not sure if that is what I want or If I want to redraw from > the distribution. I am wanting to simulate test scores. My option see > to be to draw from a normal (I don't want linear) distribution and > scale it to 0-100 or clamp it as you (Xavier) suggested or draw from > the distribution again (this is what I was thinking) I think this is > still what I want but I should look up the implications of each. The > problem I have with the clamp is that the tails in the sample could be > large. > > Thanks > Vincent > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Jun 20 09:12:18 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 14:12:18 +0100 Subject: Python in Nashville In-Reply-To: References: Message-ID: <4A3CE032.6030701@mrabarnett.plus.com> Yell123 at aol.com wrote: > > I maintain a math hobby - magic square web page > > http://www.knechtmagicsquare.paulscomputing.com/ > > > A very bright fellow in England sent me a algorithm written in python to > solve a problem I was working on. I can't seem to get it to work ... > syntax problems.... > > [snip] > > *If some one could help me get this working ... I would be grateful.* > > ** > > *I have loaded Python Ver 2.6 ... but when I paste this code in it keeps > giving me errors.* > Are you trying to paste it in IDLE's interactive prompt? That can be difficult! :-) If I paste it all at once I get a syntax error, but if I paste one function at a time then it's OK. From skip at pobox.com Sat Jun 20 09:36:52 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 20 Jun 2009 08:36:52 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <19004.58868.719487.153677@montanaro.dyndns.org> Carl> Here's the thing: not everyone complaining about the GIL is trying Carl> to get the "raw power of their machines." They just want to take Carl> advantage of multiple cores so that their Python program runs Carl> faster. If their code is CPU-bound it's likely that rewriting critical parts in C or using packages like numpy would improve there performance with or without multi-threading. For people who aren't used to C there are tools like Pyrex and Cython which provide a middle road. Skip From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 09:39:51 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 20 Jun 2009 23:39:51 +1000 Subject: timeit and __future__ References: Message-ID: <0058c162$0$9746$c3e8da3@news.astraweb.com> Karl Chen wrote: > > I wanted to time something that uses with_statement, in python2.5. > Importing __future__ in the statement or the setup doesn't work > since it's not the beginning of the code being compiled. Other > than using a separate module, I could only come up with this: > > timeit.template = 'from __future__ import with_statement\n' + > timeit.template > > timeit should directly support importing __future__ stuff... Yes, it probably should. Please make a bug report/feature request at the Python bug tracker. If you have a patch, that would be even better. http://bugs.python.org/ -- Steven From davea at ieee.org Sat Jun 20 09:57:53 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 09:57:53 -0400 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <4A3CEAE1.4030509@ieee.org> Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. I would really like to keep it > on one line. How would I do that? > > Thanks > Vincent Davis > > There are at least two interpretations to your requirement, both of which change the distribution. So you have to specify what the real distribution is that you want. 1) clamp - see Xavier's response. This will give you more values at exactly 100 and/or exactly 0 than normalvariate would specify, 2) discard - this will throw away any values outside the range, and try again. And in this case, a loop is essential, plus some mechanism to handle the case where the loop would never terminate. For example, suppose x is 10000. From lucafbb at gmail.com Sat Jun 20 10:17:01 2009 From: lucafbb at gmail.com (Luca) Date: Sat, 20 Jun 2009 16:17:01 +0200 Subject: raw_input with a pre-compiled data Message-ID: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. -- -- luca From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:26:20 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:26:20 +1000 Subject: Convert hash to struct References: Message-ID: <0058cc47$0$9712$c3e8da3@news.astraweb.com> Jason wrote: > Here's my general-purpose solution for doing this: > > class Dict2Class(object): > """ > Update like a dictionary, but expose the keys as class properties. I'm afraid that's wrong. It's wrong twice: * Properties are computed attributes. These are not, they are regular attributes. * Class attributes are shared between all instances. These are not, so they are instance attributes (or just regular "attributes" without qualification), not class attributes. > def __init__(self, *e, **f): > self.__dict__ = dict(*e, **f) You're updating the instance __dict__, not the class __dict__. Hence they are instance attributes. This is the correct thing to do, but if you wanted to share keys and values between all instances, you would use class attributes: def __init__(self, *e, **f): self.__class__.__dict__ = dict(*e, **f) As far as properties, in this case there's no sensible reason for making them properties. (Properties have their uses, but this isn't one of them.) However, since I'm not sensible *grin*, here's a quick-and-dirty version that works, for some definition of "works": class Dict2PropertyClass(object): # Like Dict2Class except using properties. def __init__(self, *e, **f): for key, value in dict(*e, **f).items(): private = '_' + key setattr(self, private, value) getter = lambda self, private=private: getattr(self, private) setter = ( lambda self, value, private=private: setattr(self, private, value) ) setattr(self.__class__, key, property(getter, setter) ) Getting update() working with this version is left as an exercise for the masochistic *wink* -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:35:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:35:19 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) References: Message-ID: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> Vincent Davis wrote: > I currently have something like this. > > class applicant(): > def __int__(self, x, y): > self.randomnum = normalvariate(x, y) > then other stuff > > x, y are only used to calculate self.randomnum and this seems to > work. But I want self.randomnum to be 0 <= randomnum <= 100. Then it isn't a normal variate. > The only > way I can thing of to do this is is with a while statement and that > seems more complicated than necessary. Why? It's a perfectly simple procedure: def __int__(self, x, y): x = -1 while not 0 <= x <= 100: x = normalvariate(x, y) # do other stuff That is the correct way to truncate a normal distribution. Alternatively, truncate values past the end-points, but this will distort the random distribution significantly: x = max(0, min(100, normalvariate(x, y))) You probably don't want that, as it will cause far more 0 and 100 values than you would otherwise expect. > I would really like to keep it > on one line. How would I do that? Why? Is the enter key on your keyboard broken? -- Steven From grante at visi.com Sat Jun 20 10:44:38 2009 From: grante at visi.com (Grant Edwards) Date: Sat, 20 Jun 2009 09:44:38 -0500 Subject: Checking for binary data in a string References: Message-ID: On 2009-06-19, Lie Ryan wrote: > Grant Edwards wrote: >> On 2009-06-19, Mitko Haralanov wrote: >> >>> I have a question about finding out whether a string contains >>> binary data? >> >> All strings contain binary data. > > Not quite, (python 2.x's) strings are binary data. > > It just happens that it behaves like text when you appropriately > encode/decode it. > > In python 3.x, the default string have evolved to unicode > string, which is a true text and the old string which contains > arbitrary binary data evolved into bytestring. You've got a computer that stores unicode strings as something other than binary data? ;) -- Grant From contact at xavierho.com Sat Jun 20 10:49:55 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 21 Jun 2009 00:49:55 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> References: <024ce5a3$0$31512$c3e8da3@news.astraweb.com> Message-ID: <2d56febf0906200749l49208681q1875a1feee0f10c4@mail.gmail.com> > > def __int__(self, x, y): > x = -1 > while not 0 <= x <= 100: > x = normalvariate(x, y) > # do other stuff > > That is the correct way to truncate a normal distribution. > > Thanks for the response. But why would you set the mean to -1 to begin? > > x = max(0, min(100, normalvariate(x, y))) > > That is an awesome way of shorthanding clamp. Best regards, 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 steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:54:22 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:54:22 +1000 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> Message-ID: <0058d2da$0$9759$c3e8da3@news.astraweb.com> Vincent Davis wrote: >> # Clamp a normal distribution outcome I don't know who you are quoting -- you should give attribution to them. >> def clamp(input, min=0, max=100): ... >> if input < min: >> return min >> elif input > max: >> return max >> else: >> return input An easier way to do this: return min(100, max(0, input)) but again, I stress that this will strongly distort the random distribution. It's probably not what you want. > Why not have the def clamp inside the class? Why bother? > I would prefer to keep > everything I need for the class together. But you don't. You have the random.normalvariate in a completely different module. I'm sure you have other operations like +, - etc as built-in functions. Not everything is inside the class. > I am new to classes but I have to say things like if __name__ == > "__main__": have no intuitive meaning to me. It is true I don't know > what __name__ and __main__ do and I can look it up but I don't even > have a guess based on the names and usage. When you import a module with the line: import mymodule Python automatically creates a variable mymodule.__name__ and sets it to the string "__mymodule__". When you run a module as a script, by calling it from the shell, using (for example): $ python mymodule.py Python automatically creates the variable mymodule.__name__ as before, but this time sets its value to the string "__main__". So the construction: if __name__ == "__main__": do_stuff_here() is a way to include code that will only be executed when running the module as a script, not when it is imported as a module. > I am Now not sure if that is what I want or If I want to redraw from > the distribution. I am wanting to simulate test scores. My option see > to be to draw from a normal (I don't want linear) distribution and > scale it to 0-100 or clamp it as you (Xavier) suggested or draw from > the distribution again (this is what I was thinking) I think this is > still what I want but I should look up the implications of each. The > problem I have with the clamp is that the tails in the sample could be > large. Strictly speaking, you want a different distribution, not normal. Possibly the F-distribution? Anyway, whatever it is, unless you need very accurate results, a truncated normal distribution shouldn't be *too* far off: close enough for government work. Clamping will not be very good: it will result in an excess of 0 and 100 scores. Imagine a graph that looks vaguely like this: 000: ********** 010: * 020: ** 030: **** 040: ******* 050: ********* 060: ********** 070: ******** 080: ***** 090: ** 100: ************* That's what you'll get by clamping (possibly exaggerated for effect). Truncating with a while loop will result in something closer to this: 000: * 010: * 020: ** 030: **** 040: ******* 050: ********* 060: ********** 070: ******** 080: ***** 090: ** 100: * which is far less distorted. -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 10:56:47 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 00:56:47 +1000 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> Message-ID: <0058d36a$0$9759$c3e8da3@news.astraweb.com> Lawrence D'Oliveiro wrote: >> Ok, now pipe ls to less, take three days to browse through all the >> filenames to locate the file you want to see. > > Sounds like you're approaching the issue with a GUI-centric mentality, > which is completely hopeless at dealing with this sort of situation. Piping the output of ls to less is a GUI-centric mentality? -- Steven From stefan_ml at behnel.de Sat Jun 20 11:28:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Jun 2009 17:28:23 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Kay Schluehr wrote: >> You might want to read about "The Problem with Threads": >> >> http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf >> >> and then decide to switch to an appropriate concurrency model for your use >> case. > > and to a programming language that supports it. Maybe, yes. But many different concurrency models are supported by a larger number of programming languages in one way or another, so the choice of an appropriate library is often sufficient - and usually a lot easier than using the 'most appropriate' programming language. Matter of available skills, mostly. There's usually a lot less code to be written that deals with concurrency than code that implements what the person paying you makes money with, so learning a new library may be worth it, while learning a new language may not. Stefan From lorenzo.digregorio at gmail.com Sat Jun 20 11:40:57 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sat, 20 Jun 2009 08:40:57 -0700 (PDT) Subject: Inheritance and forward references (prototypes) Message-ID: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --------------------------------------- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here I would have a prototype of class A which is the same as class BaseA class B(object): def __init__(self): self.obj = A() return if __name__ == "__main__": # class A(BaseA): # Uncomment this for using BaseA objects # pass class A(DebugA): # Uncomment this for using DebugA objects pass --------------------------------------- I can figure out some ways to fix this but none seems satisfying. Either they are too specific or too cumbersome. A runtime redefinition of class A does not seem to work either. What would be the most "pythonesque" solution other than sorting out the class order? Best Regards, Lorenzo From me at gustavonarea.net Sat Jun 20 11:50:41 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Sat, 20 Jun 2009 08:50:41 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: Message-ID: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Hello again, everybody. Thank you very much for your responses. You guessed right, I didn't use the __hash__ method (and I forgot to mention that, sorry). And unfortunately, I think I can't make them hashable, because the objects are compared based on their attributes, which are in turn other kind of objects compared based on other attributes. All these class instances are compared with __eq__/__ne__ and they wrap relatively complex data which would be hard to attempt to represent them unambiguously using a 32-bit integer. That's why I'm afraid I cannot use hashables. I guess I'll have to use something like the function of my first post. :( Thanks, - Gustavo. From wayne.dads.bell at gmail.com Sat Jun 20 11:58:16 2009 From: wayne.dads.bell at gmail.com (dads) Date: Sat, 20 Jun 2009 08:58:16 -0700 (PDT) Subject: File Syncing References: Message-ID: On Jun 20, 11:21?am, Lawrence D'Oliveiro wrote: > In message > b0d7-586b1b332... at t10g2000vbg.googlegroups.com>, dads wrote: > > What would I have to learn to be able to sync the text files on each > > server? > > How big is the text file? If it's small, why not have your script read it > directly from a master server every time it runs, instead of having a local > copy. Yeah the text files will never get bigger than a 100k. I don't think they have a master server but i'll check. Thanks From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 12:13:04 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 02:13:04 +1000 Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <024cfc8b$0$25987$c3e8da3@news.astraweb.com> Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. There is no need for hash to represent the data unambiguously. >>> hash(-1) -2 >>> hash(-2) -2 >>> hash(2.0**32 - 1) -2 >>> hash(1) 1 >>> hash(2.0**64 - 1) 1 >>> hash(2.0**64 + 1) 1 >>> hash(2) 2 >>> hash(1+2**32) 2 >>> hash(1+2**64) 2 >>> hash(1+2**128) 2 >>> hash(2.0) 2 The rule is, if x and y are equal, then hash(x) should equal hash(y). This does NOT imply that if hash(x) == hash(y), then x must equal y, nor is there any requirement for every unique piece of data to have a unique hash. -- Steven From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 12:21:18 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 02:21:18 +1000 Subject: Inheritance and forward references (prototypes) References: Message-ID: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: You don't actually explain what is the problem. Fortunately, I'm good at guessing, and I think I can guess what your problem is (see below): > --------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > # here I would have a prototype of class A which is the same as class > BaseA > > class B(object): > def __init__(self): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > --------------------------------------- Class A only gets defined if you run the module as a script. What you need is to unconditionally define class A, outside of the if __name__ block: class A(BaseA): pass # A.__base__ = DebugA ## Uncomment this line for debugging. -- Steven From python at mrabarnett.plus.com Sat Jun 20 12:27:45 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Jun 2009 17:27:45 +0100 Subject: Rich comparison methods don't work in sets? In-Reply-To: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <4A3D0E01.60907@mrabarnett.plus.com> Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. > > I guess I'll have to use something like the function of my first > post. :( > A hash doesn't have to be unambiguous. It's just a way to reduce the number of equality checks that have to be made. Could you create a hash from a tuple of attributes? If all else fails you could define a hash function that returns a constant. You would, however, lose the speed advantage that a hash gives in narrowing down the possible matches. From gagsl-py2 at yahoo.com.ar Sat Jun 20 12:28:28 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 13:28:28 -0300 Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: En Sat, 20 Jun 2009 12:50:41 -0300, Gustavo Narea escribi?: > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. Combine the hash values of whatever objects are involved in __eq__ but make sure they cannot change (in that case the hash value would be invalid). No need for hash to be unambiguous - objects that compare equal must have the same hash value, but objects with the same hash value may be different. -- Gabriel Genellina From clp2 at rebertia.com Sat Jun 20 12:38:57 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Jun 2009 09:38:57 -0700 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: > Hi all. > > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working path. What does "pre-compile" mean in this context? It's not clear at all, so I can't even understand your question. Cheers, Chris -- http://blog.rebertia.com From gagsl-py2 at yahoo.com.ar Sat Jun 20 12:42:37 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Jun 2009 13:42:37 -0300 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: En Sat, 20 Jun 2009 11:17:01 -0300, Luca escribi?: > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working > path. What do you mean "pre-compile the raw_input input line"? Maybe you're looking for this: import os defpath = os.getcwd() path = raw_input("Enter path [%s]: " % defpath) if not path: path = defpath print "Using path=%s" % path -- Gabriel Genellina From vincent at vincentdavis.net Sat Jun 20 13:48:21 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 11:48:21 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> Message-ID: <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Quoting Steven, >Truncating with a while loop will result in something closer to this: > 000: * > 010: * > 020: ** > 030: **** > 040: ******* > 050: ********* > 060: ********** > 070: ******** > 080: ***** > 090: ** > 100: * > > which is far less distorted." That is why I was thinking of a while loop. > Strictly speaking, you want a different distribution, not normal. Possibly > the F-distribution?" Why do you suggest a F dist, I have to admit I am not really sure how "most" test score are distributed. I was thinking it would be a truncated skewed normal. i.e. scores range from 0-100, mean is 80. For my I realize this is venturing more into statistics. Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Jun 20 13:52:55 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 03:52:55 +1000 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> References: <20090620024257.22176.1441349844.divmod.quotient.7705@henry.divmod.com> Message-ID: <4A3D21F7.9010608@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Paul Calderone wrote: > On Sat, 20 Jun 2009 00:07:27 GMT, Lie Ryan wrote: >> [snip] >> >> Perhaps we should have more built-in/stdlib operations that can release >> GIL safely to release GIL by default? And perhaps some builtin/stdlib >> should receive an optional argument that instruct them to release GIL >> and by passing this argument, you're making a contract that you wouldn't >> do certain things that would disturb the builtin/stdlib's operations; >> the specifics of what operations are prohibited would be noted on their >> docs. > > There would be a lot less useless discussion if people would do a minimal > amount of checking to see if the ideas they're suggesting are at all > feasible. > > Why don't you take a look at the CPython source and see if this is actually > possible? If you're not comfortable diving into a C program, then maybe > you > could try to become so first, or refrain from making suggestions that rely > on technical details you know nothing about? > > Jean-Paul There are 4 types of people's attitude towards discussion on GIL: Two useless ones: 1. seasoned developers who have run out of ideas and moved to other more important issues, leaving GIL problems to be solved by the future generation; 2. newbies who spurts out random ideas, often half-baked, impossible, unfeasible, or just plain stupid; and two helpful ones: 3. people who are too tired discussing GIL and just shut their mouth up; 4. people who preached resistance against GIL is futile and converted people of type 2 into type 3. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAko9IfcACgkQqC3FTmXeMUa11wCdFMmvLM6Y3fx8DPcty27XhuVS eJkAnAup/G/cQkDML0k49a+SlM1ymvCS =1cRN -----END PGP SIGNATURE----- From davea at ieee.org Sat Jun 20 14:43:32 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 14:43:32 -0400 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: Message-ID: <4A3D2DD4.1010406@ieee.org> Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: > > --------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > # here I would have a prototype of class A which is the same as class > BaseA > > class B(object): > def __init__(self): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > --------------------------------------- > > I can figure out some ways to fix this but none seems satisfying. > Either they are too specific or too cumbersome. > A runtime redefinition of class A does not seem to work either. > What would be the most "pythonesque" solution other than sorting out > the class order? > > Best Regards, > Lorenzo > > You haven't shown us any problem. class B works fine with a forward reference to A. Now if you were trying to subclass A before defining it, that'd be a problem. Or if you were trying to make an instance of B before defining A. Better put some code together with enough meat to actually show a symptom. And tell us what sys.version says. I'm testing with 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running on Win XP. From davea at ieee.org Sat Jun 20 15:01:34 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 15:01:34 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> Message-ID: <4A3D320E.1080303@ieee.org> Luca wrote: > Hi all. > > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working path. > > You'll have to define several terms for us: 1) "pre-compile" - Are you coding in Python, or in C, or some other compiled language? Microsoft C has (had?) something called pre-compiled headers, but they never worked very well, so I kept them disabled. 2) "the choice" - what choice would that be? 3) "this" - what's this? 4) "current working path" - what does this mean? Do you perhaps mean "current directory" aka "current working directory" ? Or do you mean the path to the __main__ file? The only thing I can understand clearly is "read data from user command line". You get that from sys.argv usually, or you can parse it with optparse. Or if you need the line unmodified, AND if you're on Windows, you can use the win32 module to call something like GetCommandLine(). I'd have to check that last one, though. From davea at ieee.org Sat Jun 20 15:27:50 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 15:27:50 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: <699f51260906201216r30cd5986xa816e7dbf7224630@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <4A3D320E.1080303@ieee.org> <699f51260906201216r30cd5986xa816e7dbf7224630@mail.gmail.com> Message-ID: <4A3D3836.2070401@ieee.org> patx wrote: > Could you use if elif statements? Don't understand what you mean really? > > On Sat, Jun 20, 2009 at 3:01 PM, Dave Angel wrote: > > >> Luca wrote: >> >> >>> Hi all. >>> >>> I need to use a function like the raw_input to read data from user >>> command line, but I really like to pre-compile the choice and I'm not >>> able to do this. There is some other function/module I can use? >>> I wanna to pre-compile the raw_input input line with the current working >>> path. >>> >>> >>> >>> >> You'll have to define several terms for us: >> >> 1) "pre-compile" - Are you coding in Python, or in C, or some other >> compiled language? Microsoft C has (had?) something called pre-compiled >> headers, but they never worked very well, so I kept them disabled. >> 2) "the choice" - what choice would that be? >> 3) "this" - what's this? >> 4) "current working path" - what does this mean? Do you perhaps mean >> "current directory" aka "current working directory" ? Or do you mean the >> path to the __main__ file? >> >> The only thing I can understand clearly is "read data from user command >> line". You get that from sys.argv usually, or you can parse it with >> optparse. Or if you need the line unmodified, AND if you're on Windows, you >> can use the win32 module to call something like GetCommandLine(). I'd have >> to check that last one, though. >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> This was sent off-list. And it was top-posted, so I'll have to copy his two questions here... > Could you use if elif statements? Yes. Whenever they're needed. But I don't see the relevance to this thread. > Don't understand what you mean really? This "question" doesn't parse. From lie.1296 at gmail.com Sat Jun 20 15:58:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Jun 2009 19:58:59 GMT Subject: What is the best method to match a pattern in set of lines In-Reply-To: References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Message-ID: <7cb%l.19863$y61.15772@news-server.bigpond.net.au> Dennis Lee Bieber wrote: > On Fri, 19 Jun 2009 17:52:05 -0700 (PDT), Terminator > declaimed the following in > gmane.comp.python.general: > >> Hello, >> My requierment is to get the "Stick Tag" value from the below o/p and >> based on tag take different actions. What is the best way to implement >> it. I am new to Python, so appreciate any input. >> >> Command o/p: >> =================================================================== >> File: Packet.tcl Status: Needs Merge >> >> Working revision: 1.2.98 Result of merge >> Repository revision: 1.2.99 /auto/quality/CVS/tools/ext/ >> Packet.tcl,v >> Sticky Tag: rel-ip-branch (branch: 1.584.2) >> Sticky Date: (none) >> Sticky Options: (none) >> >> Requirement: >> If "Sticky Tag" is rel-ip-brach >> do A >> else "Sticky Tag" is rel-ipv6-branch >> do B >> >> Thanks in advance. > > Sounds like homework -- but rather advanced if the homework is to > extract/parse stuff from a CVS repository... > > > Step one: find the line with "Sticky Tag:" > I presume you can code an I/O loop reading lines from a file... in > that case, look at: > if "Sticky Tag:" in line: > > Step two: once the line is found; extract the word after the field > identifier... > > Step three: > if word == "rel-ip-branch": # I'm presuming brach is typo Regular expression? From piet at cs.uu.nl Sat Jun 20 16:16:21 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 20 Jun 2009 22:16:21 +0200 Subject: Inheritance and forward references (prototypes) References: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Message-ID: >>>>> Steven D'Aprano (SD) wrote: >SD> Lorenzo Di Gregorio wrote: >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >SD> You don't actually explain what is the problem. Fortunately, I'm good at >SD> guessing, and I think I can guess what your problem is (see below): >>> --------------------------------------- >>> class BaseA(object): >>> def __init__(self): >>> return >>> >>> class DebugA(BaseA): >>> def __init__(self): >>> return >>> >>> # here I would have a prototype of class A which is the same as class >>> BaseA >>> >>> class B(object): >>> def __init__(self): >>> self.obj = A() >>> return >>> >>> if __name__ == "__main__": >>> # class A(BaseA): # Uncomment this for using BaseA objects >>> # pass >>> class A(DebugA): # Uncomment this for using DebugA objects >>> pass >>> --------------------------------------- >SD> Class A only gets defined if you run the module as a script. What you need >SD> is to unconditionally define class A, outside of the if __name__ block: >SD> class A(BaseA): >SD> pass >SD> # A.__base__ = DebugA ## Uncomment this line for debugging. >>>A.__base__ = DebugA TypeError: readonly attribute Make that: A.__bases__ = DebugA, >SD> -- >SD> Steven -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From lorenzo.digregorio at gmail.com Sat Jun 20 16:26:56 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sat, 20 Jun 2009 13:26:56 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: Message-ID: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> On Jun 20, 8:43?pm, Dave Angel wrote: > Lorenzo Di Gregorio wrote: > > Hi, > > > I'm wondering what would be the preferred way to solve the following > > forward reference problem: > > > --------------------------------------- > > class BaseA(object): > > ? ? def __init__(self): > > ? ? ? ? return > > > class DebugA(BaseA): > > ? ? def __init__(self): > > ? ? ? ? return > > > # here I would have a prototype of class A which is the same as class > > BaseA > > > class B(object): > > ? ? def __init__(self): > > ? ? ? ? self.obj = A() > > ? ? ? ? return > > > if __name__ == "__main__": > > # ? ?class A(BaseA): # Uncomment this for using BaseA objects > > # ? ? ? pass > > ? ? class A(DebugA): # Uncomment this for using DebugA objects > > ? ? ? ? pass > > --------------------------------------- > > > I can figure out some ways to fix this but none seems satisfying. > > Either they are too specific or too cumbersome. > > A runtime redefinition of class A does not seem to work either. > > What would be the most "pythonesque" solution other than sorting out > > the class order? > > > Best Regards, > > Lorenzo > > You haven't shown us any problem. ?class B works fine with a forward > reference to A. ?Now if you were trying to subclass A before defining > it, that'd be a problem. ?Or if you were trying to make an instance of B > before defining A. > > Better put some code together with enough meat to actually show a > symptom. ?And tell us what sys.version says. ?I'm testing with ? 2.6.2 > (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > on Win XP.- Hide quoted text - > > - Show quoted text - Thank you for your help: I'm working on a rather large source, but I think I have isolated the problem now. This listing generates an error: ----------------------------------------------- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return class B(object): def __init__(self,test=A()): self.obj = A() return if __name__ == "__main__": # class A(BaseA): # Uncomment this for using BaseA objects # pass class A(DebugA): # Uncomment this for using DebugA objects pass ----------------------------------------------- The error happens because Python apparently evaluates the named arguments before running the script. I think I have read something about this some (long) time ago but I can't find it anymore. Suggestions? BTW, my Python version is 2.6.1 (with latest PyDev). Thx! Lorenzo From philip at semanchuk.com Sat Jun 20 16:30:58 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 20 Jun 2009 16:30:58 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: <4D686E7E-0128-416F-AEDC-E39E8B4DAD0C@semanchuk.com> On Jun 20, 2009, at 7:41 AM, Piet van Oostrum wrote: > After my previous experiment I was curious how this works with > input(). I replaced the sem.acquire() with raw_input() and ran the > same > tests. Now the inner exception is really taken so it works like the OP > expected. The exception, however is KeyboardInterrupt, not the special > exception from the IPC module. > > So I looked in the source code how they did it: > The code is in Parser/myreadline.c. > > This code for input in function calls PyErr_CheckSignals() and > PyOS_InterruptOccurred() for a proper handling of the interrupt. So it > seems the OP should do something similar. Onl;y to deliver the custom > error you will have to do some other stuff. I don't know what but > maybe > calling PyErr_SetString is sufficient as it might overwrite the > KeyboardInterrupt stuff. Thank you Greg and especially Piet for going to the trouble of installing posix_ipc and experimenting with it. Piet, your research into raw_input() gave me a solution. In my C code, I added a call to PyErr_CheckSignals() as the first line inside the "case EINTR". Apparently calling PyErr_CheckSignals() sets the Python error indicator -- PyErr_Occurred() returns true and the error is PyExc_KeyboardInterrupt. I'm able to clear that error and return my own. Prior to adding the call to PyErr_CheckSignals(), PyErr_Occurred() returned false, so my code had no error to clear. Best of all, PyErr_CheckSignals() doesn't interfere with a Python- level signal handler if one is set. This worked under OS X and Linux. I'll have to think some more about exactly how I want my module to report the Ctrl-C, but at least now I have the tools to control the situation. Thanks again for your invaluable assistance. If I'm ever in NL or NZ I'll buy you a beer. =) Cheers Philip From bearophileHUGS at lycos.com Sat Jun 20 16:47:24 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 20 Jun 2009 13:47:24 -0700 (PDT) Subject: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> Message-ID: <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> This is a small OT post, sorry. Dennis Lee Bieber, may I ask why most or all your posts are set to "No- Archive"? > HTTP://www.bestiaria.com/ I think there are other furries beside you around here. Bye, bearophile From robert.kern at gmail.com Sat Jun 20 16:54:14 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 20 Jun 2009 15:54:14 -0500 Subject: Rich comparison methods don't work in sets? In-Reply-To: <4A3D0E01.60907@mrabarnett.plus.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> <4A3D0E01.60907@mrabarnett.plus.com> Message-ID: On 2009-06-20 11:27, MRAB wrote: > Gustavo Narea wrote: >> Hello again, everybody. >> >> Thank you very much for your responses. You guessed right, I didn't >> use the __hash__ method (and I forgot to mention that, sorry). >> >> And unfortunately, I think I can't make them hashable, because the >> objects are compared based on their attributes, which are in turn >> other kind of objects compared based on other attributes. All these >> class instances are compared with __eq__/__ne__ and they wrap >> relatively complex data which would be hard to attempt to represent >> them unambiguously using a 32-bit integer. That's why I'm afraid I >> cannot use hashables. >> >> I guess I'll have to use something like the function of my first >> post. :( >> > A hash doesn't have to be unambiguous. It's just a way to reduce the > number of equality checks that have to be made. > > Could you create a hash from a tuple of attributes? A typical way to implement this is to make a method that returns a tuple of attributes to use in both the __eq__ and __hash__ methods. class Foo(object): def key(self): return (self.x, self.y, self.bar) def __eq__(self, other): return self.key() == other.key() def __ne__(self, other): return not (self == other) def __hash__(self): return hash(self.key()) As long as those attributes are also hashable, this usually works well. -- 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-url at phaseit.net Sat Jun 20 17:41:07 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Sat, 20 Jun 2009 21:41:07 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 20) Message-ID: QOTW: "... open recursion with abstraction is supported in OOP but it requires elaborate and rather tedious boilerplate in FP ..." - Martin Odersky http://www.nabble.com/Re%3A--scala--usefulness-of-OOP-p23273389.html How to write a method that may act both as an instance method and as a class method: http://groups.google.com/group/comp.lang.python/browse_thread/thread/41e3606af55598e8/ How to check the Python version? http://groups.google.com/group/comp.lang.python/browse_thread/thread/105dd4686e7985e1/ Exceptions alter the normal lifetime of some objects: http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f9056711e3e313c Are exit() and sys.exit() the same thing? http://groups.google.com/group/comp.lang.python/browse_thread/thread/72b318b07030a048/ "Exotic" logics http://groups.google.com/group/comp.lang.python/browse_thread/thread/75d688efdac05526/ A compilation of good books in Computer Science/Software Engineering: http://groups.google.com/group/comp.lang.python/browse_thread/thread/952facdd398772/ itertools.intersect is missing? http://groups.google.com/group/comp.lang.python/browse_thread/thread/4772d9ff82a90a6c/ From Perl to Python: Lexical (private) scope: http://groups.google.com/group/comp.lang.python/browse_thread/thread/2b2536c28cd32888/ Multiple sequence subscripts: http://groups.google.com/group/comp.lang.python/browse_thread/thread/61c1d89d988a2cac/ None, vacuous truth, denotational semantics, and other philosophical aspects of emptyness: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c5397f9b6726b7a/ Walking a directory containing many many files: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ff3905b80de43588/ How to get the total size of a local hard disk in a cross-platform way :) http://groups.google.com/group/comp.lang.python/msg/c6c09fa6b3b62f84 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From castironpi at gmail.com Sat Jun 20 18:39:00 2009 From: castironpi at gmail.com (Aaron Brady) Date: Sat, 20 Jun 2009 15:39:00 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: On Jun 20, 9:27?am, MRAB wrote: > Gustavo Narea wrote: > > Hello again, everybody. > > > Thank you very much for your responses. You guessed right, I didn't > > use the __hash__ method (and I forgot to mention that, sorry). > > > And unfortunately, I think I can't make them hashable, because the > > objects are compared based on their attributes, which are in turn > > other kind of objects compared based on other attributes. All these > > class instances are compared with __eq__/__ne__ and they wrap > > relatively complex data which would be hard to attempt to represent > > them unambiguously using a 32-bit integer. That's why I'm afraid I > > cannot use hashables. > > > I guess I'll have to use something like the function of my first > > post. :( > > A hash doesn't have to be unambiguous. It's just a way to reduce the > number of equality checks that have to be made. > > Could you create a hash from a tuple of attributes? > > If all else fails you could define a hash function that returns a > constant. Ooo sneaky. +1 fancy. > You would, however, lose the speed advantage that a hash > gives in narrowing down the possible matches. Are there /any/ immutable members of the objects? From contact at xavierho.com Sat Jun 20 19:05:47 2009 From: contact at xavierho.com (Xavier Ho) Date: Sun, 21 Jun 2009 09:05:47 +1000 Subject: Inheritance and forward references (prototypes) In-Reply-To: <2d56febf0906201604i582153a9yf822686f2103602f@mail.gmail.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <2d56febf0906201604i582153a9yf822686f2103602f@mail.gmail.com> Message-ID: <2d56febf0906201605j5d6706b9w230d3c2aebf068ea@mail.gmail.com> Arg, forgot to post to the mailing list again. -_- On a smaller issue, don't you need to do: class DebugA(BaseA): def __init__(self): BaseA.__init__(self) return As in, explicitly call the __init__ function when you initalise DebugA, since DebugA extends BaseA? I'm just getting this "necessary" step because my books say so. If anyone has a good explanation, please do tell. Best regards, 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 Sun, Jun 21, 2009 at 6:26 AM, Lorenzo Di Gregorio < lorenzo.digregorio at gmail.com> wrote: > On Jun 20, 8:43 pm, Dave Angel wrote: > > Lorenzo Di Gregorio wrote: > > > Hi, > > > > > I'm wondering what would be the preferred way to solve the following > > > forward reference problem: > > > > > --------------------------------------- > > > class BaseA(object): > > > def __init__(self): > > > return > > > > > class DebugA(BaseA): > > > def __init__(self): > > > return > > > > > # here I would have a prototype of class A which is the same as class > > > BaseA > > > > > class B(object): > > > def __init__(self): > > > self.obj = A() > > > return > > > > > if __name__ == "__main__": > > > # class A(BaseA): # Uncomment this for using BaseA objects > > > # pass > > > class A(DebugA): # Uncomment this for using DebugA objects > > > pass > > > --------------------------------------- > > > > > I can figure out some ways to fix this but none seems satisfying. > > > Either they are too specific or too cumbersome. > > > A runtime redefinition of class A does not seem to work either. > > > What would be the most "pythonesque" solution other than sorting out > > > the class order? > > > > > Best Regards, > > > Lorenzo > > > > You haven't shown us any problem. class B works fine with a forward > > reference to A. Now if you were trying to subclass A before defining > > it, that'd be a problem. Or if you were trying to make an instance of B > > before defining A. > > > > Better put some code together with enough meat to actually show a > > symptom. And tell us what sys.version says. I'm testing with 2.6.2 > > (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > > on Win XP.- Hide quoted text - > > > > - Show quoted text - > > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. > > Suggestions? > > BTW, my Python version is 2.6.1 (with latest PyDev). > > Thx! > Lorenzo > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Sat Jun 20 19:18:31 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 21 Jun 2009 00:18:31 +0100 Subject: Inheritance and forward references (prototypes) In-Reply-To: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: On Sat, 20 Jun 2009 21:26:56 +0100, Lorenzo Di Gregorio wrote: > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj = A() > return > > if __name__ == "__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. I could have sworn this was in the FAQ, but apparently not. You're right, Python evaluates the default arguments when it executes the `def` instruction. (Yes, `def` is an executable instruction. It's got to create the function/method object after all!) The usual fix is not to make the default an instance of A (which will have all sorts of other side effects as well, since the same instance of A will be shared by all the Bs that don't supply a `test` parameter), but to use `None` as a marker. class B(object): def __init__(self, test=None): if test is None: test = A() self.obj = A() and so on. -- Rhodri James *-* Wildebeest Herder to the Masses From tjreedy at udel.edu Sat Jun 20 19:22:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Jun 2009 19:22:59 -0400 Subject: Rich comparison methods don't work in sets? In-Reply-To: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: Gustavo Narea wrote: > Hello again, everybody. > > Thank you very much for your responses. You guessed right, I didn't > use the __hash__ method (and I forgot to mention that, sorry). > > And unfortunately, I think I can't make them hashable, because the > objects are compared based on their attributes, which are in turn > other kind of objects compared based on other attributes. All these > class instances are compared with __eq__/__ne__ and they wrap > relatively complex data which would be hard to attempt to represent > them unambiguously using a 32-bit integer. That's why I'm afraid I > cannot use hashables. If the result of 'o1 == o2' changes over time, then the objects are not very suitable as set members. > I guess I'll have to use something like the function of my first > post. :( > > Thanks, > > - Gustavo. From robert.kern at gmail.com Sat Jun 20 19:32:50 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 20 Jun 2009 18:32:50 -0500 Subject: Rich comparison methods don't work in sets? In-Reply-To: References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: On 2009-06-20 18:22, Terry Reedy wrote: > Gustavo Narea wrote: >> Hello again, everybody. >> >> Thank you very much for your responses. You guessed right, I didn't >> use the __hash__ method (and I forgot to mention that, sorry). >> >> And unfortunately, I think I can't make them hashable, because the >> objects are compared based on their attributes, which are in turn >> other kind of objects compared based on other attributes. All these >> class instances are compared with __eq__/__ne__ and they wrap >> relatively complex data which would be hard to attempt to represent >> them unambiguously using a 32-bit integer. That's why I'm afraid I >> cannot use hashables. > > If the result of 'o1 == o2' changes over time, then the objects are not > very suitable as set members. Sometimes, I think it would be nice if sets and the other containers could be modified to accept a user-supplied hash and comparison functions on construction. A key function like list.sort() would probably also work. Even when you have objects that aren't hashable in general, there are many times when you know you will not be modifying them in a given context. Being able to do set operations on them in that context would be really useful. -- 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 charles at declareSub.com Sat Jun 20 19:36:01 2009 From: charles at declareSub.com (Charles Yeomans) Date: Sat, 20 Jun 2009 19:36:01 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> References: <7x63ew3uo9.fsf@ruckus.brouhaha.com> <7xd493v1k4.fsf@ruckus.brouhaha.com> <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <1e78af8c-b5f1-4e95-bcee-aeff3422f1d4@y9g2000yqg.googlegroups.com> <2b1l359tnal4eqnm0apjkhu8kgao97af21@4ax.com> Message-ID: On Jun 18, 2009, at 2:21 PM, David C. Ullrich wrote: > On Wed, 17 Jun 2009 05:46:22 -0700 (PDT), Mark Dickinson > wrote: > >> On Jun 17, 1:26 pm, Jaime Fernandez del Rio >> wrote: >>> On Wed, Jun 17, 2009 at 1:52 PM, Mark >>> Dickinson wrote: >>>> Maybe James is thinking of the standard theorem >>>> that says that if a sequence of continuous functions >>>> on an interval converges uniformly then its limit >>>> is continuous? >> >> s/James/Jaime. Apologies. >> >>> P.S. The snowflake curve, on the other hand, is uniformly >>> continuous, right? >> >> Yes, at least in the sense that it can be parametrized >> by a uniformly continuous function from [0, 1] to the >> Euclidean plane. I'm not sure that it makes a priori >> sense to describe the curve itself (thought of simply >> as a subset of the plane) as uniformly continuous. > > As long as people are throwing around all this math stuff: > Officially, by definition a curve _is_ a parametrization. > Ie, a curve in the plane _is_ a continuous function from > an interval to the plane, and a subset of the plane is > not a curve. > > Officially, anyway. This simply isn't true. Charles Yeomans From rhodri at wildebst.demon.co.uk Sat Jun 20 19:36:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 21 Jun 2009 00:36:33 +0100 Subject: persistent composites In-Reply-To: References: <421d4336-450e-480b-81fd-a574e6fbe1ba@r10g2000yqa.googlegroups.com> Message-ID: On Fri, 19 Jun 2009 15:56:04 +0100, Aaron Brady wrote: > This is a welcome digression for me. I wasn't sure that my idea was > being taken seriously. On a temperature scale from freezing to > boiling, I took Rhodri's message to be somewhere in the single > digits-- quite chilly. Correctly, though apparently for the wrong reason. I know get what you're trying to do, despite you consistently refusing to present a use case. > Maybe if it hadn't made me feel so defensive, > I could've just said so. But, judging from his reply, he got the > message. I'm wondering whether you did, though. Aahz's later point that you need to work on your presentation skills is not something you should dismiss out of hand as you appear to. Your original post read very much like "here's some code, please tell me I'm brilliant and should carry on." Whether or not you are brilliant, that doesn't go down well. When you're trying to generate interest in something, actively generating disinterest like that isn't going to help. -- Rhodri James *-* Wildebeest Herder to the Masses From pavlovevidence at gmail.com Sat Jun 20 19:42:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 16:42:51 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> Message-ID: <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> On Jun 20, 6:36?am, s... at pobox.com wrote: > ? ? Carl> Here's the thing: not everyone complaining about the GIL is trying > ? ? Carl> to get the "raw power of their machines." ?They just want to take > ? ? Carl> advantage of multiple cores so that their Python program runs > ? ? Carl> faster. > > If their code is CPU-bound it's likely that rewriting critical parts in C or > using packages like numpy would improve there performance with or without > multi-threading. ?For people who aren't used to C there are tools like Pyrex > and Cython which provide a middle road. Once again you miss the point. I'm sure you think you're trying to be helpful, but you're coming off as really presumptuous with this casual dismissal of their concerns. There are many, many valid reasons why people don't want to stray from Pure Python. Converting to C, Fortran, Pyrex, etc. has a significant cost (in both implementation and maintenance): much more than the cost of parallelizing pure Python code. I guess what really bothers me about this is how easily people throw out "shut up and use C" for some things, especially things that quite reasonably appear to be a silly limitation. Maybe you don't intend to sound like you're saying "shut up and use C", but to me, that's how you come off. If you're going to advise someone to use C, at least try to show some understanding for their concerns--it would go a long way. Carl Banks From davea at ieee.org Sat Jun 20 19:54:46 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Jun 2009 19:54:46 -0400 Subject: Inheritance and forward references (prototypes) In-Reply-To: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <4A3D76C6.4030400@ieee.org> Lorenzo Di Gregorio wrote: > On Jun 20, 8:43 pm, Dave Angel wrote: > >> Lorenzo Di Gregorio wrote: >> >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >>> >>> --------------------------------------- >>> class BaseA(object): >>> def __init__(self): >>> return >>> >>> class DebugA(BaseA): >>> def __init__(self): >>> return >>> >>> # here I would have a prototype of class A which is the same as class >>> BaseA >>> >>> class B(object): >>> def __init__(self): >>> self.obj =() >>> return >>> >>> if __name__ ="__main__": >>> # class A(BaseA): # Uncomment this for using BaseA objects >>> # pass >>> class A(DebugA): # Uncomment this for using DebugA objects >>> pass >>> --------------------------------------- >>> >>> I can figure out some ways to fix this but none seems satisfying. >>> Either they are too specific or too cumbersome. >>> A runtime redefinition of class A does not seem to work either. >>> What would be the most "pythonesque" solution other than sorting out >>> the class order? >>> >>> Best Regards, >>> Lorenzo >>> >> You haven't shown us any problem. class B works fine with a forward >> reference to A. Now if you were trying to subclass A before defining >> it, that'd be a problem. Or if you were trying to make an instance of B >> before defining A. >> >> Better put some code together with enough meat to actually show a >> symptom. And tell us what sys.version says. I'm testing with 2.6.2 >> (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running >> on Win XP.- Hide quoted text - >> >> - Show quoted text - >> > > Thank you for your help: I'm working on a rather large source, but I > think I have isolated the problem now. > This listing generates an error: > > ----------------------------------------------- > class BaseA(object): > def __init__(self): > return > > class DebugA(BaseA): > def __init__(self): > return > > class B(object): > def __init__(self,test=A()): > self.obj =() > return > > if __name__ ="__main__": > # class A(BaseA): # Uncomment this for using BaseA objects > # pass > class A(DebugA): # Uncomment this for using DebugA objects > pass > ----------------------------------------------- > > The error happens because Python apparently evaluates the named > arguments before running the script. > I think I have read something about this some (long) time ago but I > can't find it anymore. > > Suggestions? > > BTW, my Python version is 2.6.1 (with latest PyDev). > > Thx! > Lorenzo > > This error is caused because a default argument uses class A. Default arguments of class methods are evaluated during the definition of the class, and not later when the class is instantiated. Thus the problem. To work around that specific problem, you may want to use the following: class B(object): def __init__(self,test=None): if test==None: test = A() self.obj =() return This is actually different than what you had, since what you had would have used the same A() object for all instances of B that didn't supply their own test() parameter. Maybe that's what you wanted, and maybe not, but default arguments set to mutable values are frequently a bug. But I'm wondering if you're just looking for problems. Why not put the commented switch early in the file, and test for it wherever you need to use it? import x, y, z _debug = False #_debug = True then as soon as BaseA and DebugA are defined, do the following: if _debug: class A(DebugA): pass else: class A(BaseA) pass From martin.hellwig at dcuktec.org Sat Jun 20 20:02:48 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 21 Jun 2009 01:02:48 +0100 Subject: Decorator question (how to test if decorated function is in a class) In-Reply-To: <4a3bb0ee$0$3613$426a74cc@news.free.fr> References: <4a3bb0ee$0$3613$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Short answer: this makes no sense. Absolutely right, took me a while to figure that out though :-) Lesson learned (again): If it really seems impossible to do something in Python, it is likely the proposed solution is flawed. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From xahlee at gmail.com Sat Jun 20 20:26:13 2009 From: xahlee at gmail.com (Xah Lee) Date: Sat, 20 Jun 2009 17:26:13 -0700 (PDT) Subject: a evaluation of Google-code-prettify Message-ID: For those of you interested in the Google tech of syntax coloring source code in html on the fly using javascript, i've spent few hours for a evaluation. See: ? Google-code-prettify Examples http://xahlee.org/js/google-code-prettify/index.html Xah ? http://xahlee.org/ ? From steve at REMOVETHIS.cybersource.com.au Sat Jun 20 21:09:19 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 21 Jun 2009 11:09:19 +1000 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> Message-ID: <024d7a38$0$20654$c3e8da3@news.astraweb.com> Dennis Lee Bieber wrote: > On Sat, 20 Jun 2009 13:47:24 -0700 (PDT), Bearophile > declaimed the following in > gmane.comp.python.general: > >> This is a small OT post, sorry. >> >> Dennis Lee Bieber, may I ask why most or all your posts are set to "No- >> Archive"? >> > Taking into account some corrections from the last time I had to > explain... > > I'm from the days when the majority of NNTP servers were configured > to expire posts after some number of days (Netcom used to expire binary > groups after 24 hours! and most others were something like 14 days). > > Then came the precursor to GoogleGroups -- DejaNews -- threatening > to archive posts through eternity. This resulted in a fair amount of > protesting by some, and the creation of the x-no-archive header > convention (Agent even has configuration options such that, if one were > to not normally use x-no-archive such that one's own posts could be > archived, one could still honor it in replies to posts that did contain > it -- so those replies with quoted contents would also not be archived). > > It was at that time that I added the x-no-archive header to my posts > from Agent; as, while not as vocal as others, did object to DejaNews > plans. But your replies often contain useful information. It's a shame that they disappear from record, making them invisible for anyone searching the archives. A good rule of thumb when judging behaviour is to ask, "What if everyone did this?". If everyone set x-no-archive, then discussions on Usenet would be ephemeral, we couldn't point people to past discussions for information, and we would lose a lot of useful information. (Also a lot of garbage.) I can't tell you how often I find useful information in the archives of comp.lang.python thanks to those who archive the gname news-to-email gateway, and Google groups. If everyone did what you use, the entire community, including myself, would be far worse off. As far as I'm concerned, setting x-no-archive is harmful, anti-social behaviour on a technical newsgroup like this. You (almost) might as well just email the poster you're replying to directly. -- Steven From jure.erznoznik at gmail.com Sat Jun 20 21:23:50 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sat, 20 Jun 2009 18:23:50 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Look, guys, here's the thing: In the company I work at we decided to rewrite our MRP system in Python. I was one of the main proponents of it since it's nicely cross platform and allows for quite rapid application development. The language and it's built in functions are simply great. The opposition was quite strong, especially since the owner cheered for it - .net. So, recently I started writing a part of this new system in Python. A report generator to be exact. Let's not go into existing offerings, they are insufficient for our needs. First I started on a few tests. I wanted to know how the reporting engine will behave if I do this or that. One of the first tests was, naturally, threading. The reporting engine itself will have separate, semi-independent parts that can be threaded well, so I wanted to test that. The rest you know if you read the two threads I started on this group. Now, the core of the new application is designed so that it can be clustered so it's no problem if we just start multiple instances on one server, say one for each available core. The other day, a coworker of mine said something like: what?!? you've been using Python for two days "already" and you already say it's got a major fault? I kinda aggreed with him, especially since this particular coworker programmed strictly in Python for the last 6 months (and I haven't due to other current affairs). There was no way my puny testing could reveal such a major drawback. As it turns out, I was right. I have programmed enough threading to have tried enough variations which all reveal the GIL. Which I later confirmed through searching on the web. My purpose with developing the reporting engine in Python was twofold: learn Python as I go and create a native solution which will work out- of-the-box for all systems we decide to support. Making the thing open source while I'm at it was a side-bonus. However: Since the testing revealed this, shall we say "problem", I am tempted to just use plain old C++ again. Furthermore, I was also not quite content with the speed of arithmetic processing of the python engine. I created some simple aggregating objects that only performed two additions per pass. Calling them 200K times took 4 seconds. This is another reason why I'm beginning to think C++ might be a better alternative. I must admit, had the GIL issue not popped up, I'd just take the threading benefits and forget about it. But both things together, I'm thinking I need to rethink my strategy again. I may at some point decide that learning cross platform programming is worth a shot and just write a Python plugin for the code I write. The final effect will be pretty much the same, only faster. Perhaps I will even manage to get close to Crystal Reports speed, though I highly doubt that. But in the end, my Python skill will suffer. I still have an entire application (production support) to develop in it. Thanks for all the information and please don't flame each other. I already get the picture that GIL is a hot subject. From jure.erznoznik at gmail.com Sat Jun 20 21:27:16 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sat, 20 Jun 2009 18:27:16 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: Add: Carl, Olivier & co. - You guys know exactly what I wanted. Others: Going back to C++ isn't what I had in mind when I started initial testing for my project. From grant_ito at shaw.ca Sat Jun 20 21:37:27 2009 From: grant_ito at shaw.ca (Grant Ito) Date: Sat, 20 Jun 2009 18:37:27 -0700 Subject: Developing GUI applications Message-ID: Hi everyone. I'm looking to find out what people are using for an open source wysiwyg GUI developer. I'm running both Linux and Windows but prefer to do my development in Linux. I've got the most experience with Tkinter but am willing to look at wxPython and Tix as well. Thus far I've looked into PAGE and SpecTcl. The version of PAGE I've downloaded doesn't quite look like the online manual so I'm wondering about that. SpecTcl seems cool but I can't locate SpecPython by either Erik Brunel or Richard Colley, and the SpecTix page is down as well, as is the GUIBuilder page. All the sites I've looked at seem to date back to somewhere between 2002 and 2006. Any help would be much appreciated. ~Grant. From greg at cosc.canterbury.ac.nz Sat Jun 20 22:21:23 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 21 Jun 2009 14:21:23 +1200 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> Message-ID: <7a5jn2F1u1773U1@mid.individual.net> Philip Semanchuk wrote: > Best of all, PyErr_CheckSignals() doesn't interfere with a Python- level > signal handler if one is set. Ah, I hadn't realised that you were doing this in C code, and I was trying to think of a Python-level solution. For C code, the solution you give sounds like a good one. My only misgiving is that the user might expect to get a KeyboardInterrupt in response to Ctrl-C, so it might be better to just let it propagate instead of turning it into a different exception. -- Greg From vincent at vincentdavis.net Sat Jun 20 22:42:18 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Jun 2009 20:42:18 -0600 Subject: calculating a self.value, self.randomnum = normalvariate(x, y) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <77e831100906201942y7cb312ccxb87a823f0eb52b54@mail.gmail.com> Quoting Dennis Lee Bieber limitedNormal ( 75, 20 ) computed statistics: mu = 75.5121294828 sigma = 8.16374859991 Note how computing the input sigma such that 3*sigma does not exceed boundaries results in a narrow bell curve (hmm, and for this set, no one scored 95-100) retryNormal ( 75, 20 ) computed statistics: mu = 73.283826412 sigma = 16.9151951316 The retry model produces a skew, but perhaps somewhat unnatural; a real skew should still have relatively few entries in the 95-100 bin, whereas this is still rather symmetrical about the mean. Compare the 45, 65, and 80 bins between these two, those show most of the retried values that otherwise clipped to 100 below. clippedNormal ( 75, 20 ) computed statistics: mu = 75.3240108464 sigma = 18.1008966385 Note the unnatural peak of grades in the 95-100 range resulting from clipping out of range values into the range. * See, the full results below* Wow thanks for this Dennis, I am actually trying to simulate the scores on the step 1 medical boards exam. The actual distribution is not readily available. I like your limitedNormal approach. I think this is the way for me to go. I can come up with some reasonable mean and sd numbers from actual results then I this approach seems the best to simulate those results. I should actualy know more about this as I do a lot of stats but mostly regressions. I need to look up ome more about the F dist, but I think your limited approuch is the way to go. Trying to combine learning python and simulating the medical residency application process has been interesting. Here is a graph of past test results, I relize they are not on a 0 - 100 score but they is easy to address [image: step1_score_distribution_custom.GIF] Thanks Vincent Davis 720-301-3003 On Sat, Jun 20, 2009 at 7:43 PM, Dennis Lee Bieber wrote: > > I must be bored today... > > Expanded variation: > > -=-=-=-=-=- > """ > Random Scores > """ > > import random > import numpy > > def limitedNormal(mu, sigma=None): > """ > returns a random score from a normal (bell) distribution in > which > the mean, mu, is supplied by the caller, and in which the > standard deviation, sigma, is computed such that 3-sigma does > not drop below 0 [for mu < 50] or rise above 100 [for mu > 50] > sigma is shown as a parameter but is not used -- it permits > using the same arguments for all three *Normal() methods > """ > if mu < 50.0: > sigma = mu / 3.0 > else: > sigma = (100.0 - mu) / 3.0 > return random.normalvariate(mu, sigma) > > def clippedNormal(mu, sigma): > """ > returns a random score from a normal distribution in which > the mean, mu, and standard deviation, sigma, are supplied > by the caller. > the result is clipped to the range 0..100 > """ > return max(0.0, > min(100.0, > random.normalvariate(mu, sigma))) > > def retryNormal(mu, sigma): > """ > returns a random score from a normal distribution in which > the mean, mu, and the standard deviation, sigma, are supplied > by the caller. > if the result falls outside the range 0..100 a new score > is generated. > extremely large sigma, or mu close to the range end points > will cause slowness, as many results are thrown out and retried > """ > score = -1 > while not (0.0 <= score <= 100.0): > score = random.normalvariate(mu, sigma) > return score > > > def clippedGamma(mu, B): > """ > returns a random score from a gamma distribution in which the > "shape", a, is computed as the mean, mu, as from a normal > distribution divided by the B, "rate". Both mu and B are > supplied by the caller. > as the gamma distribution has a long tail to the right, for mu > > 50 > the result is computed as 100 - gamma(100-mu) to reflect the > desired skewness > results are clipped to the boundaries 0..100 as there is no easy > way to compute B to limit results, as is done for sigma in > limitedNormal() > NOTE: while the mean of the results will approach mu, the peak > of > the curve will be to the right (for mu>50) or left (for mu<50) > relative to a normal curve > """ > if mu < 50.0: > return max(0.0, > min(100.0, > random.gammavariate(mu / B, B))) > else: > return 100.0 - max(0.0, > min(100.0, > random.gammavariate((100.0 - mu) / B, > B))) > > def retryGamma(mu, B): > """ > returns a random score from a gamma distribution in which the > "shape", a, is computed as the mean, mu, as from a normal > distribution divided by the B, "rate". Both mu and B are > supplied by the caller. > as the gamma distribution has a long tail to the right, for mu > > 50 > the result is computed as 100 - gamma(100-mu) to reflect the > desired skewness > results outside the boundaries 0..100 will be retried > NOTE: while the mean of the results will approach mu, the peak > of > the curve will be to the right (for mu>50) or left (for mu<50) > relative to a normal curve > """ > score = -1 > while not (0.0 <= score <= 100.0): > if mu < 50.0: > score = random.gammavariate(mu / B, B) > else: > score = 100.0 - random.gammavariate((100.0 - mu) / B, > B) > return score > > if __name__ == "__main__": > tries = [ ("limitedNormal", limitedNormal, (75, 20)), > ("retryNormal", retryNormal, (75, 20)), > ("clippedNormal", clippedNormal, (75, 20)), > ("clippedGamma", clippedGamma, (75, 10)), > ("retryGamma", retryGamma, (75, 10)) ] > > state = random.getstate() > > for (name, func, args) in tries: > random.setstate(state) #reset random number generator so > #each run has the same sequence > scores = [func(*args) for i in range(100)] > scores.sort() #so listing is easier to scan visually > mu = numpy.mean(scores) > sigma = numpy.std(scores) > print "\n\n%s ( %s, %s )" % tuple([name] + list(args)) > print "\tcomputed statistics: mu = %s\tsigma = %s" % (mu, sigma) > (histv, histb) = numpy.histogram(scores, > bins=20, > range=(0.0, 100.0)) > print "\t\thistogram" > for i, v in enumerate(histv): > print "%4d\t%s" % (histb[i+1], "*" * v) > print "" > ## print "\t\tsorted scores" > ## print scores > print "" > > -=-=-=-=-=-=-=- > > limitedNormal ( 75, 20 ) > computed statistics: mu = 75.5121294828 sigma = 8.16374859991 > histogram > 5 > 10 > 15 > 20 > 25 > 30 > 35 > 40 > 45 > 50 > 55 * > 60 *** > 65 ****** > 70 ***************** > 75 ******************* > 80 ************************ > 85 ***************** > 90 ********** > 95 *** > 100 > > > Note how computing the input sigma such that 3*sigma does not exceed > boundaries results in a narrow bell curve (hmm, and for this set, no one > scored 95-100) > > > > > retryNormal ( 75, 20 ) > computed statistics: mu = 73.283826412 sigma = 16.9151951316 > histogram > 5 > 10 > 15 > 20 > 25 > 30 * > 35 * > 40 ** > 45 **** > 50 ** > 55 **** > 60 ****** > 65 ********** > 70 ********* > 75 ********* > 80 ************* > 85 ************* > 90 ******** > 95 ********* > 100 ********* > > The retry model produces a skew, but perhaps somewhat unnatural; a > real skew should still have relatively few entries in the 95-100 bin, > whereas this is still rather symmetrical about the mean. Compare the > 45, 65, and 80 bins between these two, those show most of the retried > values that otherwise clipped to 100 below. > > > clippedNormal ( 75, 20 ) > computed statistics: mu = 75.3240108464 sigma = 18.1008966385 > histogram > 5 > 10 > 15 > 20 > 25 > 30 * > 35 * > 40 ** > 45 *** > 50 ** > 55 **** > 60 ****** > 65 ********** > 70 ********* > 75 ******** > 80 ********* > 85 ************ > 90 ******** > 95 ******* > 100 ****************** > > Note the unnatural peak of grades in the 95-100 range resulting from > clipping out of range values into the range. > > > clippedGamma ( 75, 20 ) > computed statistics: mu = 75.2343345947 sigma = 21.1537553145 > histogram > 5 * > 10 > 15 > 20 > 25 * > 30 * > 35 *** > 40 * > 45 ***** > 50 **** > 55 ** > 60 ** > 65 ******** > 70 ***** > 75 ******* > 80 ********* > 85 ****** > 90 *********** > 95 ****************** > 100 **************** > > One entry was clipped to 0.0 as it doesn't show up below > > > > retryGamma ( 75, 20 ) > computed statistics: mu = 75.7551006676 sigma = 19.8990180392 > histogram > 5 > 10 > 15 > 20 > 25 * > 30 * > 35 *** > 40 * > 45 ***** > 50 **** > 55 *** > 60 ** > 65 ******** > 70 ***** > 75 ******* > 80 ********* > 85 ****** > 90 *********** > 95 ****************** > 100 **************** > > > > > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfraed at ix.netcom.com wulfraed at bestiaria.com > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: web-asst at bestiaria.com) > HTTP://www.bestiaria.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Sat Jun 20 23:18:53 2009 From: skip at pobox.com (skip at pobox.com) Date: Sat, 20 Jun 2009 22:18:53 -0500 Subject: Status of Python threading support (GIL removal)? In-Reply-To: <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <19005.42653.594623.203120@montanaro.dyndns.org> Carl> I'm sure you think you're trying to be helpful, but you're coming Carl> off as really presumptuous with this casual dismissal of their Carl> concerns. My apologies, but in most cases there is more than one way to skin a cat. Trust me, if removing the global interpreter lock was easy, or probably even it was simply hard, it almost certainly would have been done by now. Continuing to harp on this particular aspect of the CPython implementation doesn't help. Carl> I guess what really bothers me about this is how easily people Carl> throw out "shut up and use C" for some things, especially things Carl> that quite reasonably appear to be a silly limitation. You completely misunderstand I think. People don't throw out "shut up and use C" out of ignorance. In fact, I don't believe I've ever read a response which took that tone. The practical matter is that there has so far been no acceptable patch to CPython which gets rid of the global interpreter lock. Extremely smart people have tried. More than once. If Guido knew then (20 years ago) what he knows now: * that the chip manufacturers would have run out of clock speed improvements for a few years and resorted to multi-core CPUs as a way to make their computers "faster" * that garbage collection algorithms would have improved as much as they have in the past twenty years I suspect he might well have considered garbage collection instead of reference counting as a way to reclaim unreferenced memory and we might have a GIL-less CPython implementation today. Carl> Maybe you don't intend to sound like you're saying "shut up and Carl> use C", but to me, that's how you come off. If you're going to Carl> advise someone to use C, at least try to show some understanding Carl> for their concerns--it would go a long way. Then you haven't been listening. This topic comes up over and over and over again. It's a well-known limitation of the implementation. Poking people in the eye with it over and over doesn't help. The reasons for the limitation are explained every time the topic is raised. In the absence of a GIL-less CPython interpreter you are simply going to have to look elsewhere for performance improvements I'm afraid. Yes, I'll drag out the same old saws: * code hot spots in C or C++ * use tools like Pyrex, Cython, Psyco or Shed Skin * for array procesing, use numpy, preferably on top of a recent enough version of Atlas which does transparent multi-threading under the covers * use multiple processes * rewrite your code to use more efficient algorithms I don't write those out of ignorance for your plight. It's just that if you want a faster Python program today you're going to have to look elsewhere for your speedups. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From kay at fiber-space.de Sun Jun 21 00:22:18 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 20 Jun 2009 21:22:18 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On 20 Jun., 17:28, Stefan Behnel wrote: > Kay Schluehr wrote: > >> You might want to read about "The Problem with Threads": > > >>http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf > > >> and then decide to switch to an appropriate concurrency model for your use > >> case. > > > and to a programming language that supports it. > > Maybe, yes. But many different concurrency models are supported by a larger > number of programming languages in one way or another, so the choice of an > appropriate library is often sufficient - and usually a lot easier than > using the 'most appropriate' programming language. Matter of available > skills, mostly. There's usually a lot less code to be written that deals > with concurrency than code that implements what the person paying you makes > money with, so learning a new library may be worth it, while learning a new > language may not. > > Stefan This implies that people stay defensive concerning concurrency ( like me right now ) and do not embrace it like e.g. Erlang does. Sometimes there is a radical change in the way we design applications and a language is the appropriate medium to express it succinctly. Concurrency is one example, writing GUIs and event driven programs in a declarative style ( Flex, WPF, JavaFX ) is another one. In particular the latter group shows that new skills are adopted rather quickly. I don't see that a concurrency oriented language has really peaked though yet. From pavlovevidence at gmail.com Sun Jun 21 00:38:16 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 21:38:16 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> Message-ID: <062b4b9d-f27b-48ec-b760-057a9c818716@d2g2000pra.googlegroups.com> On Jun 20, 8:18?pm, s... at pobox.com wrote: > ? ? Carl> Maybe you don't intend to sound like you're saying "shut up and > ? ? Carl> use C", but to me, that's how you come off. ?If you're going to > ? ? Carl> advise someone to use C, at least try to show some understanding > ? ? Carl> for their concerns--it would go a long way. > > Then you haven't been listening. ?This topic comes up over and over and over > again. ?It's a well-known limitation of the implementation. ?Poking people > in the eye with it over and over doesn't help. ?The reasons for the > limitation are explained every time the topic is raised. ?In the absence of > a GIL-less CPython interpreter you are simply going to have to look > elsewhere for performance improvements I'm afraid. ?Yes, I'll drag out the > same old saws: > > ? ? * code hot spots in C or C++ > > ? ? * use tools like Pyrex, Cython, Psyco or Shed Skin > > ? ? * for array procesing, use numpy, preferably on top of a recent enough > ? ? ? version of Atlas which does transparent multi-threading under the > ? ? ? covers > > ? ? * use multiple processes > > ? ? * rewrite your code to use more efficient algorithms > > I don't write those out of ignorance for your plight. ?It's just that if you > want a faster Python program today you're going to have to look elsewhere > for your speedups. Just for the record, I am not taking issue with the advice itself (except that you forgot "use Jython/IronPython which have no GIL"). I'm not even saying that Python was wrong for having the GIL. All I'm saying is that [this is not aimed specifically at you] this advice can be delivered with more respect for the complainer's problem, and less fanboy-like knee-jerk defensiveness of Python. Carl Banks From clp2 at rebertia.com Sun Jun 21 01:09:23 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Jun 2009 22:09:23 -0700 Subject: Developing GUI applications In-Reply-To: References: Message-ID: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> On Sat, Jun 20, 2009 at 6:37 PM, Grant Ito wrote: > Hi everyone. > > I'm looking to find out what people are using for an open source wysiwyg GUI > developer. I'm running both Linux and Windows but prefer to do my > development in Linux. I've got the most experience with Tkinter but am > willing to look at wxPython and Tix as well. GTK: Glade - http://glade.gnome.org/ WxPython: Boa Constructor - http://boa-constructor.sourceforge.net/ Cheers, Chris -- http://blog.rebertia.com From paddy3118 at googlemail.com Sun Jun 21 01:32:05 2009 From: paddy3118 at googlemail.com (Paddy) Date: Sat, 20 Jun 2009 22:32:05 -0700 (PDT) Subject: Rosetta Code: request for help Message-ID: Hi, If you like programming problems and reading about/creating solutions to tasks in many languages not just Python, then take a look at Rosetta Code: http://www.rosettacode.org . If you 'lurk' for a while and read the submissions of others to get a feal for the site, then their is a list of tasks that still have no Python solution posted here: http://www.rosettacode.org/wiki/Tasks_not_implemented_in_Python that you might help out with. Some problems might need the use of specific but well known libraries such as PIL for the graphics, or specific knowledge. Others might be straight forward; or could do with an example translated to Python 3.x if it would change a lot from 2.x etc. Please take a look, I know I know I enjoy being involved. - Paddy. From jpablo.romero at gmail.com Sun Jun 21 01:33:22 2009 From: jpablo.romero at gmail.com (=?ISO-8859-1?Q?Juan_Pablo_Romero_M=E9ndez?=) Date: Sun, 21 Jun 2009 00:33:22 -0500 Subject: Developing GUI applications In-Reply-To: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> References: <50697b2c0906202209uc0e21b0o700299898476f2ec@mail.gmail.com> Message-ID: PyQt: http://www.riverbankcomputing.co.uk/software/pyqt/intro All the benefits of Qt: multiplataform, excellent documentation, great API, visual widget designer, etc, etc. For the coding itself, I use netbeans + python plugin. Regards, Juan Pablo 2009/6/21 Chris Rebert : > On Sat, Jun 20, 2009 at 6:37 PM, Grant Ito wrote: >> Hi everyone. >> >> I'm looking to find out what people are using for an open source wysiwyg GUI >> developer. I'm running both Linux and Windows but prefer to do my >> development in Linux. I've got the most experience with Tkinter but am >> willing to look at wxPython and Tix as well. > > GTK: Glade - http://glade.gnome.org/ > WxPython: Boa Constructor - http://boa-constructor.sourceforge.net/ > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > From billy.chasen at gmail.com Sun Jun 21 02:32:04 2009 From: billy.chasen at gmail.com (billy) Date: Sat, 20 Jun 2009 23:32:04 -0700 (PDT) Subject: Python class gotcha with scope? Message-ID: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> I don't quite understand why this happens. Why doesn't b have its own version of r? If r was just an int instead of a dict, then it would. >>> class foo: ... r = {} ... def setn(self, n): ... self.r["f"] = n ... >>> a = foo() >>> a.setn(4) >>> >>> b = foo() >>> b.r {'f': 4} thanks, billy From phostu at gmail.com Sun Jun 21 02:38:28 2009 From: phostu at gmail.com (Vincent) Date: Sat, 20 Jun 2009 23:38:28 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: <79d578a6-3cce-40e3-950e-ece3a452ce7d@c18g2000prh.googlegroups.com> On Jun 21, 2:32?pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ... ? ? r = {} > ... ? ? def setn(self, n): > ... ? ? ? ? ? ? self.r["f"] = n > ...>>> a = foo() > >>> a.setn(4) > > >>> b = foo() > >>> b.r > > {'f': 4} > > thanks, > > billy class Foo: def __init__(self): self.r = {} def setn(self,n): self.r['f'] = n a = Foo() a.setn(3) a.r {'f': 3} b = Foo() b.r {} From phostu at gmail.com Sun Jun 21 02:40:04 2009 From: phostu at gmail.com (Vincent) Date: Sat, 20 Jun 2009 23:40:04 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> <79d578a6-3cce-40e3-950e-ece3a452ce7d@c18g2000prh.googlegroups.com> Message-ID: <0ea4eceb-9291-49ee-8896-d13c88f6cd93@k17g2000prn.googlegroups.com> On Jun 21, 2:38?pm, Vincent wrote: > On Jun 21, 2:32?pm, billy wrote: > > > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ... ? ? r = {} > > ... ? ? def setn(self, n): > > ... ? ? ? ? ? ? self.r["f"] = n > > ...>>> a = foo() > > >>> a.setn(4) > > > >>> b = foo() > > >>> b.r > > > {'f': 4} > > > thanks, > > > billy > > class Foo: > ? ? def __init__(self): > ? ? ? ? self.r = {} > ? ? def setn(self,n): > ? ? ? ? self.r['f'] = n > > a = Foo() > a.setn(3) > a.r > {'f': 3} > b = Foo() > b.r > {} you defined r as class-level variable. and i defined r as instance-level variable. From pavlovevidence at gmail.com Sun Jun 21 02:41:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Jun 2009 23:41:03 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: On Jun 20, 11:32?pm, billy wrote: > I don't quite understand why this happens. Why doesn't b have its own > version of r? If r was just an int instead of a dict, then it would. > > >>> class foo: > > ... ? ? r = {} > ... ? ? def setn(self, n): > ... ? ? ? ? ? ? self.r["f"] = n > ...>>> a = foo() > >>> a.setn(4) > > >>> b = foo() > >>> b.r > > {'f': 4} r is a class attribute, that is, it is attacted to the class itself. Look at what happens when you enter foo.r at the interactive prompt: >>> foo.r {'f': 4} You want an instance attribute, a value attached to the instance of the class. You create those in the __init__ method: class foo: def __init__(self): self.r = {} def setn(self,n): self.r["n"] = n Carl Banks From billy.chasen at gmail.com Sun Jun 21 02:53:05 2009 From: billy.chasen at gmail.com (billy) Date: Sat, 20 Jun 2009 23:53:05 -0700 (PDT) Subject: Python class gotcha with scope? References: <6e83ba84-3184-4494-ad65-f46a3585b579@l2g2000vba.googlegroups.com> Message-ID: great, thanks for the quick responses :) On Jun 21, 2:41?am, Carl Banks wrote: > On Jun 20, 11:32?pm, billy wrote: > > > I don't quite understand why this happens. Why doesn't b have its own > > version of r? If r was just an int instead of a dict, then it would. > > > >>> class foo: > > > ... ? ? r = {} > > ... ? ? def setn(self, n): > > ... ? ? ? ? ? ? self.r["f"] = n > > ...>>> a = foo() > > >>> a.setn(4) > > > >>> b = foo() > > >>> b.r > > > {'f': 4} > > r is a class attribute, that is, it is attacted to the class itself. > Look at what happens when you enter foo.r at the interactive prompt: > > >>> foo.r > > {'f': 4} > > You want an instance attribute, a value attached to the instance of > the class. ?You create those in the __init__ method: > > class foo: > ? ? def __init__(self): > ? ? ? ? self.r = {} > ? ? def setn(self,n): > ? ? ? ? self.r["n"] = n > > Carl Banks From Olivier.Darge at gmail.com Sun Jun 21 03:32:31 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sun, 21 Jun 2009 00:32:31 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: <08830f2a-efd9-4e19-bf7b-e46c7e92a0ef@j20g2000vbp.googlegroups.com> On 21 juin, 03:27, Jure Erzno?nik wrote: > Add: > Carl, Olivier & co. - You guys know exactly what I wanted. > Others: Going back to C++ isn't what I had in mind when I started > initial testing for my project. Do you think multiprocessing can help you seriously ? Can you benefit from multiple cpu ? did you try to enhance your code with numpy ? Olivier (installed a backported multiprocessing on his 2.5.1 Python, but need installation of Xcode first) From p.elagin at gmail.com Sun Jun 21 03:43:22 2009 From: p.elagin at gmail.com (=?KOI8-R?B?/sXbydLTy8nKIOvP1A==?=) Date: Sun, 21 Jun 2009 00:43:22 -0700 (PDT) Subject: Newbie queue question References: Message-ID: <344816e6-2cbf-45d5-bea4-9cb90b18a1c0@o14g2000vbo.googlegroups.com> 1. say me dbf files count? 2. why dbf ? From jure.erznoznik at gmail.com Sun Jun 21 04:20:03 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sun, 21 Jun 2009 01:20:03 -0700 (PDT) Subject: Newbie queue question References: <344816e6-2cbf-45d5-bea4-9cb90b18a1c0@o14g2000vbo.googlegroups.com> Message-ID: <012d8040-b72b-48d1-84cf-471b82ff94d9@x6g2000vbg.googlegroups.com> On Jun 21, 9:43?am, ????????? ??? wrote: > 1. say me dbf files count? > 2. why dbf ? It was just a test. It was the most compatible format I could get between Python and the business application I work with without using SQL servers and such. Otherwise it's of no consequence. The final application will have a separate input engine that will support multiple databases as input. Jure From jure.erznoznik at gmail.com Sun Jun 21 04:39:38 2009 From: jure.erznoznik at gmail.com (=?windows-1252?Q?Jure_Erzno=9Enik?=) Date: Sun, 21 Jun 2009 01:39:38 -0700 (PDT) Subject: Status of Python threading support (GIL removal)? References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> <627e1793-aeeb-43ec-9e09-697e0089d33c@o21g2000prn.googlegroups.com> <58a32cba-0737-4a46-921b-70fffc254e36@x31g2000prc.googlegroups.com> <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> <08830f2a-efd9-4e19-bf7b-e46c7e92a0ef@j20g2000vbp.googlegroups.com> Message-ID: On Jun 21, 9:32?am, OdarR wrote: > > Do you think multiprocessing can help you seriously ? > Can you benefit from multiple cpu ? > > did you try to enhance your code with numpy ? > > Olivier > (installed a backported multiprocessing on his 2.5.1 Python, but need > installation of Xcode first) Multithreading / multiprocessing can help me with my problem. As you know, database reading is typically I/O bound so it helps to put it in a separate thread. I might not even notice the GIL if I used SQL access in the first place. As it is, DBFPY is pretty CPU intensive since it's a pure Python DBF implementation. To continue: the second major stage (summary calculations) is completely CPU bound. Using numpy might or might not help with it. Those are simple calculations, mostly additions. I try not to put the entire database in arrays to save memory and so I mostly just add counters where I can. Soe functions simply require arrays, but they are more rare, so I guess I'm safe with that. You wouldn't believe how complex some reports can be. Threading + memory saving is a must and even so, I'll probably have to implement some sort of serialization later on, so that the stuff can run on more memory constrained devices. The third major stage, rendering engine, is again mostly CPU bound, but at the same time it's I/O bound as well when outputting the result. All three major parts are more or less independent from each other and can run simultaneously, just with a bit of a delay. I can perform calculations while waiting for the next record and I can also start rendering immediately after I have all the data for the first group available. I may use multiprocessing, but I believe it introduces more communication overhead than threads and am so reluctant to go there. Threads were perfect, other stuff wasn't. To make things worse, no particular extension / fork / branch helps me here. So if I wanted to just do the stuff in Python, I'd have to move to Jthon or IronPython and hope cPython eventually improves in this area. I do actually need cPython since the other two aren't supported on all platforms my company intends to support. The main issue I currently have with GIL is that execution time is worse when I use threading. Had it been the same, I wouldn't worry too much about it. Waiting for a permenent solution would be much easier then... From lucafbb at gmail.com Sun Jun 21 05:28:19 2009 From: lucafbb at gmail.com (Luca) Date: Sun, 21 Jun 2009 11:28:19 +0200 Subject: raw_input with a pre-compiled data In-Reply-To: <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <27308d500906210228t2b62ab6dyb6b12e821dd7cad5@mail.gmail.com> On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: > On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >> Hi all. >> >> I need to use a function like the raw_input to read data from user >> command line, but I really like to pre-compile the choice and I'm not >> able to do this. There is some other function/module I can use? >> I wanna to pre-compile the raw_input input line with the current working path. > > What does "pre-compile" mean in this context? It's not clear at all, > so I can't even understand your question. I'm really sorry to all that replied... In fact I literally traduced a concept from italian and the term precompiled was not so clear... What I mean is this: I wanna that raw_input (or other modules) ask to the user the data, but some data inserted is already present, to the user can cancel it with the BACKSPACE key. Examples below (the "_" is the initial cursor position). >>> raw_input("Insert the directory to work: ") Insert the directory to work: _ What I need is: >>> XXX_raw_input("Insert the directory to work: ", default="/home/john/") Insert the directory to work: /home/john_ In the second example a user can cancel the text "/home/john". I hope this time is more clear, sorry again. -- -- luca From mail at microcorp.co.za Sun Jun 21 05:38:18 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 21 Jun 2009 11:38:18 +0200 Subject: Developing GUI applications References: Message-ID: <007a01c9f254$026c5ac0$0d00a8c0@Hendrik> "Grant Ito" wrote: > Hi everyone. > > I'm looking to find out what people are using for an open source wysiwyg GUI > developer. I'm running both Linux and Windows but prefer to do my > development in Linux. I've got the most experience with Tkinter but am > willing to look at wxPython and Tix as well. > > Thus far I've looked into PAGE and SpecTcl. The version of PAGE I've > downloaded doesn't quite look like the online manual so I'm wondering about > that. SpecTcl seems cool but I can't locate SpecPython by either Erik Brunel > or Richard Colley, and the SpecTix page is down as well, as is the > GUIBuilder page. > > All the sites I've looked at seem to date back to somewhere between 2002 and > 2006. Any help would be much appreciated. Have a long, hard look at Boa Constructor. It is a RAD based on wx. It actually works as advertised. - Hendrik From kushal.kumaran+python at gmail.com Sun Jun 21 05:47:45 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Sun, 21 Jun 2009 15:17:45 +0530 Subject: os.read in non blocking mode of os.open : resource busy error In-Reply-To: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> References: <530a33a60906170648t3f376fe1y5fd76db84bc1977d@mail.gmail.com> Message-ID: <1e364c4e0906210247r6dbcfbe6kdb963ff86ebd3c5a@mail.gmail.com> On Wed, Jun 17, 2009 at 7:18 PM, kshama nagaraj wrote: > Dear all, > > I am using os.open to open a tun/tap device and then read data from it. > I also need to do some other tasks apart from reading from this device. So i > wish to have the read non blocking. > I am opening the device in non-block mode using os.O_NONBLOCK . > But, if i do this, i get an error when i call the os.read a follows: > > ?File "./tunnel_more1.py", line 305, in main_loop > ??? payload = os.read(self.tun_fd,64) > OSError: [Errno 11] Resource temporarily unavailable > >From the glibc documentation of read: `EAGAIN' Normally, when no input is immediately available, `read' waits for some input. But if the `O_NONBLOCK' flag is set for the file (*note File Status Flags::), `read' returns immediately without reading any data, and reports this error. And from ipython: In [1]: import errno In [2]: print errno.EAGAIN 11 That's your error 11. > I am running my application with GNU Radio on Ubuntu. > > Can some one tell me, what is the error? What are the ways to use non > blocking read? > > thanks all for your time and attention. > > From mail at microcorp.co.za Sun Jun 21 05:47:49 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 21 Jun 2009 11:47:49 +0200 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net><4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <009601c9f255$5708b460$0d00a8c0@Hendrik> "Kay Schluehr" wrote: > This implies that people stay defensive concerning concurrency ( like > me right now ) and do not embrace it like e.g. Erlang does. Sometimes > there is a radical change in the way we design applications and a > language is the appropriate medium to express it succinctly. > Concurrency is one example, writing GUIs and event driven programs in > a declarative style ( Flex, WPF, JavaFX ) is another one. In > particular the latter group shows that new skills are adopted rather > quickly. > > I don't see that a concurrency oriented language has really peaked > though yet. I think that this is because (like your link has shown) the problem is really not trivial, and also because the model that can bring sanity to the party (independent threads/processes that communicate with queued messages) is seen as inefficient at small scale. - Hendrik From rklein at tpg.com.au Sun Jun 21 05:57:33 2009 From: rklein at tpg.com.au (rkl) Date: Sun, 21 Jun 2009 02:57:33 -0700 (PDT) Subject: waling a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> Message-ID: <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> On Jun 15, 2:35?am, tom wrote: > i can traverse adirectoryusing os.listdir() or os.walk(). but if adirectoryhas a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > adirectoryas a liked list. for example, in c, perl or php one can > use opendir() and then repeatedly readdir() until getting to the end > of the file list. it seems this could be more efficient in some > applications. > > is there a way to do this in python? i'm relatively new to the > language. i looked through the documentation and tried googling but > came up empty. I might be a little late with my comment here. David Beazley in his PyCon'2008 presentation "Generator Tricks For Systems Programmers" had this very elegant example of handling an unlimited numbers of files: import os, fnmatch def gen_find(filepat,top): """gen_find(filepat,top) - find matching files in directory tree, start searching from top expects: a file pattern as string, and a directory path as string yields: a sequence of filenames (including paths) """ for path, dirlist, filelist in os.walk(top): for name in fnmatch.filter(filelist,filepat): yield os.path.join(path,name) for file in gen_find('*.py', '/'): print file From mail at timgolden.me.uk Sun Jun 21 06:06:23 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 21 Jun 2009 11:06:23 +0100 Subject: waling a directory with very many files In-Reply-To: <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <284cd479-6431-454c-9fdf-7c9f2bc3f5ac@p5g2000pre.googlegroups.com> Message-ID: <4A3E061F.50108@timgolden.me.uk> rkl wrote: > I might be a little late with my comment here. > > David Beazley in his PyCon'2008 presentation "Generator Tricks > For Systems Programmers" had this very elegant example of handling an > unlimited numbers of files: David Beazley's generator stuff is definitely worth recommending on. I think the issue here is that: anything which ultimately uses os.listdir (and os.walk does) is bound by the fact that it will create a long list of every file before handing it back. Certainly there are techniques (someone posted a ctypes wrapper for opendir; I recommended FindFirst/NextFile on Windows) which could be applied, but those are all outside the stdlib. TJG From __peter__ at web.de Sun Jun 21 06:51:20 2009 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Jun 2009 12:51:20 +0200 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: Luca wrote: > On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: >> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >>> Hi all. >>> >>> I need to use a function like the raw_input to read data from user >>> command line, but I really like to pre-compile the choice and I'm not >>> able to do this. There is some other function/module I can use? >>> I wanna to pre-compile the raw_input input line with the current working >>> path. >> >> What does "pre-compile" mean in this context? It's not clear at all, >> so I can't even understand your question. > > I'm really sorry to all that replied... In fact I literally traduced a With "traduced" you stumbled upon another false friend ;) http://it.wikipedia.org/wiki/Falso_amico > concept from italian and the term precompiled was not so clear... > > What I mean is this: I wanna that raw_input (or other modules) ask to > the user the data, but some data inserted is already present, to the > user can cancel it with the BACKSPACE key. > > Examples below (the "_" is the initial cursor position). > > >>> raw_input("Insert the directory to work: ") > Insert the directory to work: _ > > What I need is: > >>> XXX_raw_input("Insert the directory to work: ", > >>> default="/home/john/") > Insert the directory to work: /home/john_ > > In the second example a user can cancel the text "/home/john". > > I hope this time is more clear, sorry again. import readline def input_default(prompt, default): def startup_hook(): readline.insert_text(default) readline.set_startup_hook(startup_hook) try: return raw_input(prompt) finally: readline.set_startup_hook(None) print input_default("directory? ", default="/home/john") The cmd module may also be worth having a look. Peter From stefan_ml at behnel.de Sun Jun 21 06:55:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 21 Jun 2009 12:55:00 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: <157e0345-74e0-4144-a2e6-2b4cc854ce37@z7g2000vbh.googlegroups.com> Message-ID: <4a3e1184$0$31878$9b4e6d93@newsspool3.arcor-online.net> Christian Heimes wrote: > Hard computations gain more speed from carefully crafted C or Fortran > code that utilizes features like the L1 and L2 CPU cache, SIMD etc. or > parallelized algorithms. If you start sharing values between multiple > cores you have a serious problem. > > Oh, and use NumPy for the job ;) [...] > It *is* a well known limitation of Python. All the nice 'n shiny syntax > and features are coming with a cost. Python is a powerful language and > good tool for lots of stuff. But Python is and will never become the > ?bertool that solves every problem perfectly. At some point you need a > different tool to get the raw power of your machine. C (and perhaps > Fortran) are the weapons of choice for number crunching. Well, and there's always Cython to the rescue when you need it. Stefan From stefan_ml at behnel.de Sun Jun 21 07:20:11 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 21 Jun 2009 13:20:11 +0200 Subject: Status of Python threading support (GIL removal)? In-Reply-To: References: Message-ID: <4a3e176c$0$31861$9b4e6d93@newsspool3.arcor-online.net> Jure Erzno?nik wrote: > On Jun 20, 1:36 am, a... at pythoncraft.com (Aahz) wrote: >> You should put up or shut up -- I've certainly seen multi-core speedup >> with threaded software, so show us your benchmarks! >> -- > > Sorry, no intent to offend anyone here. Flame wars are not my thing. > > I have shown my benchmarks. See first post and click on the link. > That's the reason I started this discussion. > > All I'm saying is that you can get threading benefit, but only if the > threading in question is implemented in C plugin. > I have yet to see pure Python code which does take advantage of > multiple cores. From what I read about GIL, this is simply impossible > by design. Well, CPython is written in C. So running Python code in CPython will necessarily run C code (whatever "plugin" means in your post above). If that C code frees the GIL or not depends on the parts of CPython or external packages that you use. And there are many parts that free the GIL and will thus benefit (sometimes heavily) from threading and multiple-cores, and there are also many parts that do not free the GIL and will therefore not (or likely not) benefit from multiple-cores. Claiming that "pure Python code does not free the GIL" in the context of CPython when you define "pure Python code" as code that does not depend on C code is plain flawed. Stefan From jeremy+complangpython at jeremysanders.net Sun Jun 21 07:48:19 2009 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Sun, 21 Jun 2009 12:48:19 +0100 Subject: Status of Python threading support (GIL removal)? References: Message-ID: Jesse Noller wrote: > Sorry, you're incorrect. I/O Bound threads do in fact, take advantage > of multiple cores. I don't know whether anyone else brought this up, but it looks like Python has problems with even this form of threading http://www.dabeaz.com/python/GIL.pdf It's certainly a very interesting read if you're interested in this subject. -- Jeremy Sanders http://www.jeremysanders.net/ From luislupeXXX at gmailXXX.com Sun Jun 21 07:51:16 2009 From: luislupeXXX at gmailXXX.com (Luis P. Mendes) Date: 21 Jun 2009 11:51:16 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) Message-ID: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> Hi, I have a program that uses a lot of resources: memory and cpu but it never returned this error before with other loads: """ MemoryError c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the error above Aborted """ The last time I checked physical RAM while the script was running, it was used in about 75% and there is no reason (based in other runs of the program) for it to surpass 80% (maximum). $ python -V Python 2.5.2 Pyscopg2 is version 2.0.8 I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ 1.66GHz and 3GB of RAM I could not find this error. What does this mean? Is this a bug of Python? of Psycopg2? Luis From lorenzo.digregorio at gmail.com Sun Jun 21 07:55:45 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Sun, 21 Jun 2009 04:55:45 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> On 21 Jun., 01:54, Dave Angel wrote: > LorenzoDiGregoriowrote: > > On Jun 20, 8:43 pm, Dave Angel wrote: > > >>LorenzoDiGregoriowrote: > > >>> Hi, > > >>> I'm wondering what would be the preferred way to solve the following > >>> forward reference problem: > > >>> --------------------------------------- > >>> class BaseA(object): > >>> ? ? def __init__(self): > >>> ? ? ? ? return > > >>> class DebugA(BaseA): > >>> ? ? def __init__(self): > >>> ? ? ? ? return > > >>> # here I would have a prototype of class A which is the same as class > >>> BaseA > > >>> class B(object): > >>> ? ? def __init__(self): > >>> ? ? ? ? self.obj =() > >>> ? ? ? ? return > > >>> if __name__ ="__main__": > >>> # ? ?class A(BaseA): # Uncomment this for using BaseA objects > >>> # ? ? ? pass > >>> ? ? class A(DebugA): # Uncomment this for using DebugA objects > >>> ? ? ? ? pass > >>> --------------------------------------- > > >>> I can figure out some ways to fix this but none seems satisfying. > >>> Either they are too specific or too cumbersome. > >>> A runtime redefinition of class A does not seem to work either. > >>> What would be the most "pythonesque" solution other than sorting out > >>> the class order? > > >>> Best Regards, > >>>Lorenzo > > >> You haven't shown us any problem. ?class B works fine with a forward > >> reference to A. ?Now if you were trying to subclass A before defining > >> it, that'd be a problem. ?Or if you were trying to make an instance of B > >> before defining A. > > >> Better put some code together with enough meat to actually show a > >> symptom. ?And tell us what sys.version says. ?I'm testing with ? 2.6.2 > >> (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)], running > >> on Win XP.- Hide quoted text - > > >> - Show quoted text - > > > Thank you for your help: I'm working on a rather large source, but I > > think I have isolated the problem now. > > This listing generates an error: > > > ----------------------------------------------- > > class BaseA(object): > > ? ? def __init__(self): > > ? ? ? ? return > > > class DebugA(BaseA): > > ? ? def __init__(self): > > ? ? ? ? return > > > class B(object): > > ? ? def __init__(self,test=A()): > > ? ? ? ? self.obj =() > > ? ? ? ? return > > > if __name__ ="__main__": > > # ? ?class A(BaseA): # Uncomment this for using BaseA objects > > # ? ? ? ?pass > > ? ? ?class A(DebugA): # Uncomment this for using DebugA objects > > ? ? ? ? ?pass > > ----------------------------------------------- > > > The error happens because Python apparently evaluates the named > > arguments before running the script. > > I think I have read something about this some (long) time ago but I > > can't find it anymore. > > > Suggestions? > > > BTW, my Python version is 2.6.1 (with latest PyDev). > > > Thx! > >Lorenzo > > This error is caused because a default argument uses class A. ?Default > arguments of class methods are evaluated during the definition of the > class, and not later when the class is instantiated. ?Thus the problem. > > To work around that specific problem, you may want to use the following: > > class B(object): > ? ? def __init__(self,test=None): > ? ? ? ? if test==None: > ? ? ? ? ? ? test = A() > ? ? ? ? self.obj =() > ? ? ? ? return > > This is actually different than what you had, since what you had would > have used the same A() object for all instances of B that didn't supply > their own test() parameter. ?Maybe that's what you wanted, and maybe > not, but default arguments set to mutable values are frequently a bug. > > But I'm wondering if you're just looking for problems. ?Why not put the > commented switch early in the file, and test for it wherever you need to > use it? > > import ?x, y, z > _debug = False > #_debug = True > > then as soon as ?BaseA and DebugA are defined, do the following: > > if _debug: > ? ? class A(DebugA): > ? ? ? ? pass > else: > ? ? class A(BaseA) > ? ? ? ? pass- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - I had also thought of using "None" (or whatever else) as a marker but I was curious to find out whether there are better ways to supply an object with standard values as a default argument. In this sense, I was looking for problems ;-) Of course the observation that "def" is an instruction and no declaration changes the situation: I would not have a new object being constructed for every instantiation with no optional argument, because __init__ gets executed on the instantiation but test=A() gets executed on reading 'def'. At this point I think there is no other way than using a marker as suggested above multiple times, if I want to supply a new object with default values for non-passed arguments. Anybody with a better idea? From piet at cs.uu.nl Sun Jun 21 08:25:13 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 21 Jun 2009 14:25:13 +0200 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: I notice that I see several postings on news:comp.lang.python that are replies to other postings that I don't see. Examples are the postings by Dennis Lee Bieber that I am replying to (but I break the thread on purpose). For example the posting with Message-ID: references: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c at mail.gmail.com> which is not present on my news server. I have been wondering why these disappear, and I noticed the following in the Dennis Lee Bieber posting: On Sat, 20 Jun 2009 11:48:21 -0600, Vincent Davis declaimed the following in gmane.comp.python.general: So apparently some of these come through gmane.comp.python.general. So my question is: would this be the cause of these disappearing postings? Are postings on gmane.comp.python.general not relayed to comp.lang.python? Are they relayed to the python mailing list? I find it quite disturbing that sometimes only half of a discussion is visible. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From me at gustavonarea.net Sun Jun 21 08:27:32 2009 From: me at gustavonarea.net (Gustavo Narea) Date: Sun, 21 Jun 2009 05:27:32 -0700 (PDT) Subject: Rich comparison methods don't work in sets? References: <930742af-64fa-4aff-be9e-b8d753cc6d5f@n8g2000vbb.googlegroups.com> Message-ID: <73497769-1271-401b-9ee2-5e9e7ebb6274@g20g2000vba.googlegroups.com> Hi, everyone. OK, I got it now! The value of the hash is not decisive, as __eq__ will still be called when the hashes match. It's like a filter, for performance reasons. It's really nice, I just tried it and it worked. Thank you very, very much!! Cheers, - Gustavo. From lie.1296 at gmail.com Sun Jun 21 09:04:59 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:04:59 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) In-Reply-To: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> Message-ID: <%dq%l.20091$y61.11699@news-server.bigpond.net.au> Luis P. Mendes wrote: > Hi, > > I have a program that uses a lot of resources: memory and cpu but it > never returned this error before with other loads: > > """ > MemoryError > c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the > error above > Aborted > """ > The last time I checked physical RAM while the script was running, it was > used in about 75% and there is no reason (based in other runs of the > program) for it to surpass 80% (maximum). > > $ python -V > Python 2.5.2 > > Pyscopg2 is version 2.0.8 > > I use Linux, Kernel 2.6.24.5-smp #2 SMP > with a Core2 CPU T5500 @ 1.66GHz and 3GB of RAM > > I could not find this error. What does this mean? > > Is this a bug of Python? of Psycopg2? > > Luis Have you tried running without psyco? Psyco increases memory usage quite significantly. If it runs well without psyco, you can try looking at your code and selectively psyco parts that need the speed boost the most. From lie.1296 at gmail.com Sun Jun 21 09:13:09 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:13:09 GMT Subject: Inheritance and forward references (prototypes) In-Reply-To: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: Lorenzo Di Gregorio wrote: > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observation that "def" is an instruction and no > declaration changes the situation: I would not have a new object being > constructed for every instantiation with no optional argument, because > __init__ gets executed on the instantiation but test=A() gets executed > on reading 'def'. > > At this point I think there is no other way than using a marker as > suggested above multiple times, if I want to supply a new object with > default values for non-passed arguments. Using None as default for mutable default argument is the common idiom for the problem you're having. From luislupeXXX at gmailXXX.com Sun Jun 21 09:23:43 2009 From: luislupeXXX at gmailXXX.com (Luis P. Mendes) Date: 21 Jun 2009 13:23:43 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> <%dq%l.20091$y61.11699@news-server.bigpond.net.au> Message-ID: <4a3e345e$0$90270$14726298@news.sunsite.dk> Sun, 21 Jun 2009 13:04:59 +0000, Lie Ryan escreveu: > Luis P. Mendes wrote: >> Hi, >> >> I have a program that uses a lot of resources: memory and cpu but it >> never returned this error before with other loads: >> >> """ >> MemoryError >> c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the >> error above >> Aborted >> """ >> The last time I checked physical RAM while the script was running, it >> was used in about 75% and there is no reason (based in other runs of >> the program) for it to surpass 80% (maximum). >> >> $ python -V >> Python 2.5.2 >> >> Pyscopg2 is version 2.0.8 >> >> I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ >> 1.66GHz and 3GB of RAM >> >> I could not find this error. What does this mean? >> >> Is this a bug of Python? of Psycopg2? >> >> Luis > > Have you tried running without psyco? Psyco increases memory usage quite > significantly. > > If it runs well without psyco, you can try looking at your code and > selectively psyco parts that need the speed boost the most. I really need Psyco (use version 1.6 - forgot to mention earlier) to speed up the code. The part that consumes more memory is the one that needs Psyco the most. Luis From paul.paj at gmail.com Sun Jun 21 09:31:58 2009 From: paul.paj at gmail.com (Paul Johnston) Date: Sun, 21 Jun 2009 06:31:58 -0700 (PDT) Subject: class or instance method References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> Message-ID: <76a06a1d-3536-4bf1-ad39-cbb1c1d71ea5@a5g2000pre.googlegroups.com> Hi, > class class_or_instance(object): > ? ? def __init__(self, fn): ... This works a treat, thank-you. Paul From lie.1296 at gmail.com Sun Jun 21 09:50:08 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Jun 2009 13:50:08 GMT Subject: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2) In-Reply-To: <4a3e345e$0$90270$14726298@news.sunsite.dk> References: <4a3e1eb4$0$90270$14726298@news.sunsite.dk> <%dq%l.20091$y61.11699@news-server.bigpond.net.au> <4a3e345e$0$90270$14726298@news.sunsite.dk> Message-ID: Luis P. Mendes wrote: > Sun, 21 Jun 2009 13:04:59 +0000, Lie Ryan escreveu: >> Have you tried running without psyco? Psyco increases memory usage quite >> significantly. >> >> If it runs well without psyco, you can try looking at your code and >> selectively psyco parts that need the speed boost the most. > > I really need Psyco (use version 1.6 - forgot to mention earlier) to > speed up the code. > The part that consumes more memory is the one that needs Psyco the most. Yeah, but try running without psyco first and see if the problem is really caused by psyco. If it still produces an error, then we can rule out psyco as the root cause of the problem. Selective psyco-ing can reduce the amount of memory psyco uses and may just be slightly slower than full boosting (and sometimes it may actually become faster in memory constrained situation as less swapping is needed). From deets at nospam.web.de Sun Jun 21 10:15:54 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 16:15:54 +0200 Subject: question about c++ and python In-Reply-To: References: Message-ID: <7a6tkqF1teatrU2@mid.uni-berlin.de> Issa Kamar schrieb: > Dear Sirs; > > I'm a PhD student,i have a question i wish if you can help me really.I'm working in Linux ubuntu 8.10,i have a c++ file which i need to connect this file to a python file and run it,i wish really if u can send me the method that can help me to do this and really I'm very thankful. If you send me money, I will send you the code. Otherwise, I suggest you start googling a bit and find out how to map C++-classes to Python. There is an abundance of information on that topic out there. Popular options include SWIG, Boost::Python and SIP, the latter I can only recommend from personal experience. Diez From issa.kamar at aul.edu.lb Sun Jun 21 10:17:11 2009 From: issa.kamar at aul.edu.lb (Issa Kamar) Date: Sun, 21 Jun 2009 16:17:11 +0200 Subject: question about c++ and python Message-ID: <9F3CEFC83E7BF24993F24EC234527543168B13CC4A@srv100002.aul.local> Dear Sirs; I'm a PhD student,i have a question i wish if you can help me really.I'm working in Linux ubuntu 8.10,i have a c++ file which i need to connect this file to a python file and run it,i wish really if u can send me the method that can help me to do this and really I'm very thankful. best regards From philip at semanchuk.com Sun Jun 21 10:49:42 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Jun 2009 10:49:42 -0400 Subject: KeyboardInterrupt eats my error and then won't be caught In-Reply-To: <7a5jn2F1u1773U1@mid.individual.net> References: <4A3C60E4.8020301@cosc.canterbury.ac.nz> <7a5jn2F1u1773U1@mid.individual.net> Message-ID: <756639A4-CE03-4E84-8EBE-BF3D9B88F375@semanchuk.com> On Jun 20, 2009, at 10:21 PM, greg wrote: > Philip Semanchuk wrote: > >> Best of all, PyErr_CheckSignals() doesn't interfere with a Python- >> level signal handler if one is set. > > Ah, I hadn't realised that you were doing this in C > code, and I was trying to think of a Python-level > solution. > > For C code, the solution you give sounds like a > good one. > > My only misgiving is that the user might expect to > get a KeyboardInterrupt in response to Ctrl-C, so > it might be better to just let it propagate instead > of turning it into a different exception. I completely agree. The simple solution (for me) is to handle all return codes of EINTR the same way which is to raise posix_ipc.Error with the message "The wait was interrupted by a signal". But that loses information. KeyboardInterrupt is very specific while posix_ipc.Error is generic and even parsing the message doesn't tell much more. When my C code sees EINTR, I will probably raise KeyboardError when I see that and add a specific posix_ipc.SignalError to raise in other EINTR circumstances. Thanks, Philip From vincent at vincentdavis.net Sun Jun 21 11:34:23 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 21 Jun 2009 09:34:23 -0600 Subject: python needs a tutorial for install and setup on a Mac Message-ID: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> I am running python on a mac and when I was getting going it was difficult to setup information. Specifically how modify bash_profile, how pythonpath works and how to set it up. how to switch between python versions. How/where to install modules if you have multiple installed versions. I am thinking about this from perspective of a new pythoner (is there a word for a person who programs in python). I think many new pythoners may be like me and don't mess with the underling UNIX on a mac. My question/suggestion is that there be a nice tutorial for this. I am wiling to contribute much but I am still somewhat new to python and may need help with some details. Also where should this be posted, how do I post it. Do other think there is a need? Any willing to help? But of course I may have missed a great tutorial out there if so I think It needs to be easier to findor I need to learn how to look. Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Sun Jun 21 11:54:47 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 17:54:47 +0200 Subject: docs error for PyBuffer_FillInfo? Message-ID: <7a73e8F1totcrU1@mid.uni-berlin.de> I'm trying to wrap a C++-lib with SIP & need to return a buffer-object from one method. I'm on python2.6 (OS X, but that doesn't matter I guess), and http://docs.python.org/c-api/buffer.html#Py_buffer gives a signature like this: int PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len, int readonly, int infoflags)? However, the abstract.h of the Python-installation has this: PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, Py_ssize_t len, int readonly, int flags); And obviously enough, compiling my wrapper fails because there is an argument missing. So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - all I've got is a void* and a total size of the buffer. Diez From aahz at pythoncraft.com Sun Jun 21 11:57:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 08:57:13 -0700 Subject: Status of Python threading support (GIL removal)? References: <627e1793-aeeb-43ec-9e09 <90303b55-8686-4d56-b89c-01e31d0a6080@l8g2000vbp.googlegroups.com> Message-ID: In article <90303b55-8686-4d56-b89c-01e31d0a6080 at l8g2000vbp.googlegroups.com>, =?windows-1252?Q?Jure_Erzno=9Enik?= wrote: > >So, recently I started writing a part of this new system in Python. A >report generator to be exact. Let's not go into existing offerings, >they are insufficient for our needs. > >First I started on a few tests. I wanted to know how the reporting >engine will behave if I do this or that. One of the first tests was, >naturally, threading. The reporting engine itself will have separate, >semi-independent parts that can be threaded well, so I wanted to test >that. This is not something that I would expect Python threads to provide a performance boost for. I would expect that if it were a GUI app, it would improve responsiveness, properly designed. If performance were a goal, I would start by profiling it under a single-threaded design and see where the hotspots were, then either choose one of several options for improving performance or go multi-process. Note that I'm generally one of the Python thread boosters (unlike some people who claim that Python threads are worthless), but I also never claim that Python threads are good for CPU-intensive operations (which report generation is), *except* for making GUI applications more responsive. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sun Jun 21 11:59:37 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 08:59:37 -0700 Subject: Status of Python threading support (GIL removal)? References: Message-ID: In article , Jeremy Sanders wrote: >Jesse Noller wrote: >> >> Sorry, you're incorrect. I/O Bound threads do in fact, take advantage >> of multiple cores. > >I don't know whether anyone else brought this up, but it looks >like Python has problems with even this form of threading > >http://www.dabeaz.com/python/GIL.pdf Most of us have already seen this. It's a good point, but IME writing multi-threaded apps for multi-core machines, I think one should be careful to avoid reading too much into it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From gruszczy at gmail.com Sun Jun 21 12:00:31 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Sun, 21 Jun 2009 18:00:31 +0200 Subject: urllib2 urlopen takes too much time Message-ID: <1be78d220906210900n66b606ffy496a6030d488fd5d@mail.gmail.com> I have encountered a performance problem using suds, which was traced down to _socket.recv. I am calling some web services and each of them uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, while the rest of the call is finished in milliseconds. Because of this, my web app works really slow, especially when it must do many ws calls. I could of course decrease the number of calls and do a lot of caching (which would be quite perilous and I wouldn't like to delve into this), but it seems as treating symptoms, rather than the illness itself. The machine I am connecting to through ws is in the same building, the connection should be really fast and mostly it is - except for using suds. Is it possible, that I could done something wrong and it hangs on this socket for too long? Have anyone encountered similar problems? Oh, and we did some profiling using also other tool written in C#, that also uses those web services and it worked much faster, so it doesn't seem to be connection problem. -- Filip Gruszczy?ski From grguthrie at gmail.com Sun Jun 21 12:00:52 2009 From: grguthrie at gmail.com (guthrie) Date: Sun, 21 Jun 2009 09:00:52 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> <7a0icpF1smf41U1@mid.individual.net> Message-ID: <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> On Jun 18, 11:28?pm, greg wrote: > nn wrote: > > This is certainly an odd one. This code works fine under 2.6 but fails > > in Python 3.1. > > >>>>class x: > > > ... ? ? lst=[2] > > ... ? ? gen=[lst.index(e) for e in lst] > > In 3.x it was decided that the loop variables in a list > comprehension should be local, and not leak into the > surrounding scope. This was implemented by making the > list comprehension into a nested function. > > Unfortunately this leads to the same unintuitive > behaviour as a genexp when used in a class scope. > -- I don't get this - the only local loop variable is "e", not lst. And lst is used twice in the generator expression, which is being complained about? It would generally be the case that a nested function would have access to its enclosing scope. In any case, even if/when the current behavior is explained or rationalized, it certainly appears un-intuitive, and that is another level of "error"! :-) From a.harrowell at gmail.com Sun Jun 21 12:01:53 2009 From: a.harrowell at gmail.com (TYR) Date: Sun, 21 Jun 2009 09:01:53 -0700 (PDT) Subject: urllib2 content-type headers Message-ID: I have a little application that wants to send data to a Google API. This API requires an HTTP header to be set as follows: Authorization: GoogleLogin auth=[value of auth token goes here] Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect this is due to an unfeature of urllib2. Notably, although you can use urllib2.Request's add_header method to append a header, the documentation (http://docs.python.org/library/urllib2.html) says that: remember that a few standard headers (Content-Length, Content-Type and Host) are added when the Request is passed to urlopen() (or OpenerDirector.open()). And: Note that there cannot be more than one header with the same name, and later calls will overwrite previous calls in case the key collides. To put it another way, you cannot rely on Content-Type being correct because whatever you set it to explicitly, urllib2 will silently change it to something else which may be wrong, and there is no way to stop it. What happened to "explicit is better than implicit"? From lists at cheimes.de Sun Jun 21 13:03:36 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Jun 2009 19:03:36 +0200 Subject: docs error for PyBuffer_FillInfo? In-Reply-To: <7a73e8F1totcrU1@mid.uni-berlin.de> References: <7a73e8F1totcrU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > > And obviously enough, compiling my wrapper fails because there is an > argument missing. > > So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - > all I've got is a void* and a total size of the buffer. The second argument points to the (optional) object for that you are creating the view. The code in Object/stringobject.c is a good example: static int string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags) { return PyBuffer_FillInfo(view, (PyObject*)self, (void *)self->ob_sval, Py_SIZE(self), 1, flags); } Christian From philip at semanchuk.com Sun Jun 21 13:08:46 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Jun 2009 13:08:46 -0400 Subject: urllib2 content-type headers In-Reply-To: References: Message-ID: <6CD5BD99-24AB-4CE8-B952-72D56D27BD16@semanchuk.com> On Jun 21, 2009, at 12:01 PM, TYR wrote: > I have a little application that wants to send data to a Google API. > This API requires an HTTP header to be set as follows: > > Authorization: GoogleLogin auth=[value of auth token goes here] > > Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect > this is due to an unfeature of urllib2. Notably, although you can use > urllib2.Request's add_header method to append a header, the > documentation (http://docs.python.org/library/urllib2.html) says that: > > remember that a few standard headers (Content-Length, Content-Type and > Host) are added when the Request is passed to urlopen() (or > OpenerDirector.open()). > > And: > > Note that there cannot be more than one header with the same name, and > later calls will overwrite previous calls in case the key collides. > > To put it another way, you cannot rely on Content-Type being correct > because whatever you set it to explicitly, urllib2 will silently > change it to something else which may be wrong, and there is no way to > stop it. What happened to "explicit is better than implicit"? Hi TYR, I'm confused, are you having a problem with the Content-Type or Authorization headers? Some suggestions -- - Try sending the request to a server you control so you can see what it is actually receiving. Maybe urllib2 isn't overwriting your header at all, but you're sending (e.g.) a misconfigured auth token. - Use a protocol sniffer like Wireshark to see what's going out over the wire - Urrlib2 automates some things for you (like building headers), but as with all automated magic sometimes it's not what you want. The httplib module offers finer control over HTTP conversations. You might want to use httplib to debug this problem even if you find you don't need it in your final solution. good luck Philip From walton.nathaniel at gmail.com Sun Jun 21 13:12:03 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 10:12:03 -0700 (PDT) Subject: os.system vs subprocess Message-ID: I get different behavior with os.system and subprocess (no surprise there I guess), but I was hoping for some clarification, namely why. If I type this directly into the command window: java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > mapoutput.txt mapoutput.txt stores the output: Command line mode: input file=censettings.xml 1358 files will be created in C:\Documents and Settings\Nate\Desktop \freqanalysis\tilefiles\CENSUS1-tiles 1358 tiles created out of 1358 in 16 seconds If I execute said command with subprocess, the output is not written to mapoutput.txt - the output just appears in the command window. If I execute said command with os.system, the output is written to mapoutput.txt like I expected. In reality all I want to do is access the first two lines of the above output before the process finishes, something which I haven't been able to manage with subprocess so far. I saw that somehow I might be able to use os.read(), but this is my first attempt at working with pipes/processes, so I'm a little overwhelmed. Thanks! From http Sun Jun 21 13:12:40 2009 From: http (Paul Rubin) Date: 21 Jun 2009 10:12:40 -0700 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net> <4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <7x7hz5jyt3.fsf@ruckus.brouhaha.com> "Hendrik van Rooyen" writes: > I think that this is because (like your link has shown) the problem > is really not trivial, and also because the model that can bring > sanity to the party (independent threads/processes that communicate > with queued messages) is seen as inefficient at small scale. That style works pretty well in Python and other languages. The main gripe about it for Python is the subject of this thread, i.e. the GIL. From clp2 at rebertia.com Sun Jun 21 14:12:29 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Jun 2009 11:12:29 -0700 Subject: os.system vs subprocess In-Reply-To: References: Message-ID: <50697b2c0906211112m731ca0ddk1849e4f27cfbe53c@mail.gmail.com> On Sun, Jun 21, 2009 at 10:12 AM, Nate wrote: > I get different behavior with os.system and subprocess (no surprise > there I guess), but I was hoping for some clarification, namely why. > > If I type this directly into the command window: > > java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > > mapoutput.txt > > mapoutput.txt stores the output: > Command line mode: input file=censettings.xml > 1358 files will be created in C:\Documents and Settings\Nate\Desktop > \freqanalysis\tilefiles\CENSUS1-tiles > 1358 tiles created out of 1358 in 16 seconds > > If I execute said command with subprocess, the output is not written > to mapoutput.txt - the output just appears in the command window. Show us the subprocess version of you code. People tend to not get the parameters quite right if they're not familiar with the library. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Sun Jun 21 14:22:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Jun 2009 11:22:39 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <50697b2c0906211122x412bbb2ahb0cb27f67b4d8b66@mail.gmail.com> On Sun, Jun 21, 2009 at 5:25 AM, Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. Examples are the postings by > Dennis Lee Bieber that I am replying to (but I As addressed in an earlier thread, Mr. Bieber chooses to set a Usenet header (X-Noarchive) in his postings that suppresses their permanent archiving (and often the archiving of replies to his posts). I would direct you to the thread, but it looks like it wasn't archived. :P Cheers, Chris -- http://blog.rebertia.com From davea at dejaviewphoto.com Sun Jun 21 14:53:28 2009 From: davea at dejaviewphoto.com (Dave Angel) Date: Sun, 21 Jun 2009 14:53:28 -0400 Subject: raw_input with a pre-compiled data In-Reply-To: References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <4A3E81A8.3050301@dejaviewphoto.com> Peter Otten wrote: > Luca wrote: > > >> On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: >> >>> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >>> >>>> Hi all. >>>> >>>> I need to use a function like the raw_input to read data from user >>>> command line, but I really like to pre-compile the choice and I'm not >>>> able to do this. There is some other function/module I can use? >>>> I wanna to pre-compile the raw_input input line with the current working >>>> path. >>>> >>> What does "pre-compile" mean in this context? It's not clear at all, >>> so I can't even understand your question. >>> >> I'm really sorry to all that replied... In fact I literally traduced a >> > > With "traduced" you stumbled upon another false friend ;) > > http://it.wikipedia.org/wiki/Falso_amico > > >> concept from italian and the term precompiled was not so clear... >> >> What I mean is this: I wanna that raw_input (or other modules) ask to >> the user the data, but some data inserted is already present, to the >> user can cancel it with the BACKSPACE key. >> >> Examples below (the "_" is the initial cursor position). >> >> >>> raw_input("Insert the directory to work: ") >> Insert the directory to work: _ >> >> What I need is: >> >>> XXX_raw_input("Insert the directory to work: ", >> >>> default="/home/john/") >> Insert the directory to work: /home/john_ >> >> In the second example a user can cancel the text "/home/john". >> >> I hope this time is more clear, sorry again. >> > > > import readline > > def input_default(prompt, default): > def startup_hook(): > readline.insert_text(default) > readline.set_startup_hook(startup_hook) > try: > return raw_input(prompt) > finally: > readline.set_startup_hook(None) > > print input_default("directory? ", default="/home/john") > > The cmd module may also be worth having a look. > > Peter > > > The readline module is specific to Unix implementations. I don't know what OS the OP was using. From piet at cs.uu.nl Sun Jun 21 15:03:54 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 21 Jun 2009 21:03:54 +0200 Subject: Meta question: disappearing posts References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: >>>>> Chris Rebert (CR) wrote: >CR> On Sun, Jun 21, 2009 at 5:25 AM, Piet van Oostrum wrote: >>> I notice that I see several postings on news:comp.lang.python that are >>> replies to other postings that I don't see. Examples are the postings by >>> Dennis Lee Bieber that I am replying to (but I >CR> As addressed in an earlier thread, Mr. Bieber chooses to set a Usenet >CR> header (X-Noarchive) in his postings that suppresses their permanent >CR> archiving (and often the archiving of replies to his posts). >CR> I would direct you to the thread, but it looks like it wasn't archived. :P Actually, I do see Mr. Bieber's posts, but not the ones he replies to. And I am not talking about the archives but about the regular NNTP server, although the retention period somewhere along the path could be so low that posts disappear before they reach us. Anyway, as I saw gmane mentioned in the replies I wondered if that would have something to do with the problem. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From walton.nathaniel at gmail.com Sun Jun 21 15:12:07 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 12:12:07 -0700 (PDT) Subject: os.system vs subprocess References: Message-ID: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> On Jun 21, 2:12?pm, Chris Rebert wrote: > On Sun, Jun 21, 2009 at 10:12 AM, Nate wrote: > > I get different behavior with os.system and subprocess (no surprise > > there I guess), but I was hoping for some clarification, namely why. > > > If I type this directly into the command window: > > > java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml > > > mapoutput.txt > > > mapoutput.txt stores the output: > > Command line mode: input file=censettings.xml > > 1358 files will be created in C:\Documents and Settings\Nate\Desktop > > \freqanalysis\tilefiles\CENSUS1-tiles > > 1358 tiles created out of 1358 in 16 seconds > > > If I execute said command with subprocess, the output is not written > > to mapoutput.txt - the output just appears in the command window. > > Show us the subprocess version of you code. People tend to not get the > parameters quite right if they're not familiar with the library. > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Here it is: gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) From milesck at umich.edu Sun Jun 21 15:20:38 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 15:20:38 -0400 Subject: urllib2 content-type headers In-Reply-To: References: Message-ID: On Jun 21, 2009, at 12:01 PM, TYR wrote: > Unfortunately, I'm getting nothing but 400 Bad Requests. I suspect > this is due to an unfeature of urllib2. Notably, although you can use > urllib2.Request's add_header method to append a header, the > documentation (http://docs.python.org/library/urllib2.html) says that: > > remember that a few standard headers (Content-Length, Content-Type and > Host) are added when the Request is passed to urlopen() (or > OpenerDirector.open()). > > And: > > Note that there cannot be more than one header with the same name, and > later calls will overwrite previous calls in case the key collides. > > To put it another way, you cannot rely on Content-Type being correct > because whatever you set it to explicitly, urllib2 will silently > change it to something else which may be wrong, and there is no way to > stop it. What happened to "explicit is better than implicit"? Those headers are added (by AbstractHTTPHandler.do_request_) only if they are missing. -Miles From milesck at umich.edu Sun Jun 21 15:47:32 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 15:47:32 -0400 Subject: generator expression works in shell, NameError in script In-Reply-To: <4a3b8860$0$19616$426a74cc@news.free.fr> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <4a3b8860$0$19616$426a74cc@news.free.fr> Message-ID: <62C32142-89B7-4181-A515-2C7F3B37E344@umich.edu> On Jun 19, 2009, at 8:45 AM, Bruno Desthuilliers wrote: > >>> class Foo(object): > ... bar = ['a', 'b', 'c'] > ... baaz = list((b, b) for b in bar) > > but it indeed looks like using bar.index *in a generator expression* > fails (at least in 2.5.2) : > > >>> class Foo(object): > ... bar = ['a', 'b', 'c'] > ... baaz = list((bar.index(b), b) for b in bar) > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in Foo > File "", line 3, in > NameError: global name 'bar' is not defined The reason that the first one works but the second fails is clearer if you translate each generator expression to the approximately equivalent generator function: class Foo(object): bar = ['a', 'b', 'c'] def _gen(_0): for b in _0: yield (b, b) baaz = list(_gen(iter(bar)) # PEP 227: "the name bindings that occur in the class block # are not visible to enclosed functions" class Foo(object): bar = ['a', 'b', 'c'] def _gen(_0): for b in _0: yield (bar.index(b), b) baaz = list(_gen(iter(bar)) -Miles From lists at cheimes.de Sun Jun 21 15:49:35 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Jun 2009 21:49:35 +0200 Subject: os.system vs subprocess In-Reply-To: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: Nate wrote: > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) Try this: gmapcreator = subprocess.Popen( ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar", "-dfile=censettings.xml"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = gmapcreator.communicate("stdin input") The subprocess doesn't use the shell so you have to apply the command as a list of strings. Do you really need stdin, stdout and stderr as pipes? If you aren't carefully with the API your program can block. Christian From paul.hermeneutic at gmail.com Sun Jun 21 15:57:34 2009 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 21 Jun 2009 14:57:34 -0500 Subject: Can I replace this for loop with a join? In-Reply-To: <74h2hnF135f35U1@mid.individual.net> References: <74h2hnF135f35U1@mid.individual.net> Message-ID: <1245614253.3797.1.camel@linux-3eb6.site> On Mon, 2009-04-13 at 17:03 +0200, WP wrote: > Hello, I have dictionary {1:"astring", 2:"anotherstring", etc} > > I now want to print: > "Press 1 for astring" > "Press 2 for anotherstring" etc > > I could do it like this: > dict = {1:'astring', 2:'anotherstring'} > for key in dict.keys(): > print 'Press %i for %s' % (key, dict[key]) > > Press 1 for astring > Press 2 for anotherstring > > but can I use a join instead? > > Thanks for any replies! > > - WP In addition to the comments already made, this code will be quite broken if there is ever a need to localize your package in another language. From deets at nospam.web.de Sun Jun 21 16:08:50 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 22:08:50 +0200 Subject: docs error for PyBuffer_FillInfo? In-Reply-To: References: <7a73e8F1totcrU1@mid.uni-berlin.de> Message-ID: <7a7ib8F1sd7uqU1@mid.uni-berlin.de> Christian Heimes schrieb: > Diez B. Roggisch wrote: >> And obviously enough, compiling my wrapper fails because there is an >> argument missing. >> >> So, I'm in need for a guide on how to use PyBuffer_FillInfo properly - >> all I've got is a void* and a total size of the buffer. > > The second argument points to the (optional) object for that you are > creating the view. The code in Object/stringobject.c is a good example: > > static int > string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags) > { > return PyBuffer_FillInfo(view, (PyObject*)self, > (void *)self->ob_sval, Py_SIZE(self), > 1, flags); > } But doesn't this mean the docs are faulty? Shall I report a bug? And I have to say that the docs are anything but clear to me. As I said, I've got a method void *lock(readonly=True) as part of a C++-library. So, all I've got is a void-pointer and a length (through another method). But I'm unsure about how to allocate the view - just with malloc? What about reference-counting, do I have to increment it? A self-contained example in the docs would be great. Any pointers? Thanks, Diez From tjreedy at udel.edu Sun Jun 21 16:16:10 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Jun 2009 16:16:10 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. Examples are the postings by > Dennis Lee Bieber that I am replying to (but I > break the thread on purpose). For example the posting with Message-ID: > references: > <77e831100906192220y5536d9d2oe5ca2dcc59084c0c at mail.gmail.com> which is > not present on my news server. I have been wondering why these > disappear, and I noticed the following in the Dennis Lee Bieber posting: > On Sat, 20 Jun 2009 11:48:21 -0600, Vincent Davis > declaimed the following in > gmane.comp.python.general: > > So apparently some of these come through gmane.comp.python.general. I am posting and reading thru gmane and generally see no problem. Sometimes I do see replies before the posting being replied. Sometimes certain posts get 'echoed' about week after the original posting date. If a reply gets echoed, but not the original, and one missed both originally, that can look weird. tjr > > So my question is: would this be the cause of these disappearing > postings? Are postings on gmane.comp.python.general not relayed to > comp.lang.python? Are they relayed to the python mailing list? I find it > quite disturbing that sometimes only half of a discussion is visible. From paul.hermeneutic at gmail.com Sun Jun 21 16:28:27 2009 From: paul.hermeneutic at gmail.com (Paul Watson) Date: Sun, 21 Jun 2009 15:28:27 -0500 Subject: GNUstep and Python Message-ID: <1245616107.3797.3.camel@linux-3eb6.site> Has anyone used GNUstep? In addition to Objective-C, there are Java and Ruby bindings. Has anyone created a Python binding to GNUstep? From philr at aspexconsulting.co.nz Sun Jun 21 16:40:08 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Mon, 22 Jun 2009 08:40:08 +1200 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: ->From: Bob Martin [mailto:bob.martin at excite.com] -.Sent: Thursday, 18 June 2009 6:07 p.m. -Subject: Re: RE: Good books in computer science? -in 117815 20090617 221804 Phil Runciman wrote: ->Because it reminds me of when things went badly wrong. IBM360, Von Neumann = ->architecture, no hardware stacks ... -> ->IMHO Burroughs and ICL had better approaches to OS design back then but had= ->less resources to develop their ideas.=20 -> ->However, mainly this period marked a transition from the excitement and dis= ->covery phase of computing to commercial power plays and take-overs. The bes= ->t ideas in a field tend to get lost in the melee of competition. Early comp= ->uters were rooted in academia and there was a lot of cross fertilisation of= ->ideas and approaches. IMHO commerce affected layers of the stack where it = ->had no useful contribution to make. Vertical integration warred against sou= ->nd architecture. -> ->The book has an important message and I recommend that people read it. The = ->book is to me, and possibly only me, an icon representing when things went = ->wrong. -Well, it's an opinion, but certainly not one I would agree with! -AFAIAC the IBM 360 got everything right, which is why the instruction set is still -going strong 45 years later (I've used it for every one of those 45 years). Yes, I was afraid someone would use that sort of argument. Sadly, having the best instruction set does not lead to commercial success. If it did then Interdata would still be with us. They used IBM360 instructions. How many instruction sets have you used? I have used at least 9.(I nearly missed the DG Nova). KDF9 had the best set for general computing that I had the privilege of using but that is not to say it was the best. The Burroughs B series or PDP11 may have been better... and doubtless there are many more candidates. What I can say is that for scientific/engineering calculations the RPN of KDF9 was Great because assembler was no harder than using algol60 for the calculations part of the problems I worked on. Oh yes, I even used assembler on the IBM360 series. It was a 360/50. The experience Did impact on the force of my observations! FWIW I learned it using the training material For the ICL System 4 which was superior to IBM's. The ICL System 4 was not a success... despite its instruction set. ;-) -AFAIAC the IBM 360 got everything right How many known bugs did the OS end up with? I know it hit 50,000+ and counting. LOL Suffice to say we are on a journey and Python is part of the scenery. Phil From Scott.Daniels at Acm.Org Sun Jun 21 16:51:58 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 21 Jun 2009 13:51:58 -0700 Subject: Inheritance and forward references (prototypes) In-Reply-To: <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: Lorenzo Di Gregorio wrote: > On 21 Jun., 01:54, Dave Angel wrote: >> ... >> class B(object): >> def __init__(self,test=None): >> if test==None: >> test = A() >> self.obj =() >> return > ... > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observation that "def" is an instruction and no > declaration changes the situation: I would not have a new object being > constructed for every instantiation with no optional argument, because > __init__ gets executed on the instantiation but test=A() gets executed > on reading 'def'.... If what you are worrying about is having a single default object, you could do something like this: class B(object): _default = None def __init__(self, test=None): if test is None: test = self._default if test is None: B._default = test = A() ... --Scott David Daniels Scott.Daniels at Acm.Org From deets at nospam.web.de Sun Jun 21 16:59:32 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 21 Jun 2009 22:59:32 +0200 Subject: GNUstep and Python In-Reply-To: <1245616107.3797.3.camel@linux-3eb6.site> References: <1245616107.3797.3.camel@linux-3eb6.site> Message-ID: <7a7l9kF1tv7viU1@mid.uni-berlin.de> Paul Watson schrieb: > Has anyone used GNUstep? > > In addition to Objective-C, there are Java and Ruby bindings. > > Has anyone created a Python binding to GNUstep? There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. Diez From Scott.Daniels at Acm.Org Sun Jun 21 17:23:41 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 21 Jun 2009 14:23:41 -0700 Subject: class or instance method In-Reply-To: <87ljnr3ueq.fsf@busola.homelinux.net> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> Message-ID: <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> Hrvoje Niksic wrote: > ... > class class_or_instance(object): > def __init__(self, fn): > self.fn = fn > def __get__(self, obj, cls): > if obj is not None: > return lambda *args, **kwds: self.fn(obj, *args, **kwds) > else: > return lambda *args, **kwds: self.fn(cls, *args, **kwds) > ... Just to polish a bit: import functools class ClassOrInstance(object): def __init__(self, fn): self._function = fn self._wrapper = functools.wraps(fn) def __get__(self, obj, cls): return self._wrapper(functools.partial(self._function, cls if obj is None else obj)) --Scott David Daniels Scott.Daniels at Acm.Org From milesck at umich.edu Sun Jun 21 17:56:01 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sun, 21 Jun 2009 17:56:01 -0400 Subject: class or instance method In-Reply-To: <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> References: <269bb501-2f5b-4487-9dd0-36f1b188fa59@3g2000yqk.googlegroups.com> <87ljnr3ueq.fsf@busola.homelinux.net> <6ridnTjog6rRPqPXnZ2dnUVZ_tidnZ2d@pdx.net> Message-ID: <50CD264B-A191-4F3D-9FAF-712656D2798E@umich.edu> On Jun 21, 2009, at 5:23 PM, Scott David Daniels wrote: > Hrvoje Niksic wrote: >> ... >> class class_or_instance(object): >> def __init__(self, fn): >> self.fn = fn >> def __get__(self, obj, cls): >> if obj is not None: >> return lambda *args, **kwds: self.fn(obj, *args, **kwds) >> else: >> return lambda *args, **kwds: self.fn(cls, *args, **kwds) >> ... > > Just to polish a bit: > > import functools > > class ClassOrInstance(object): > def __init__(self, fn): > self._function = fn > self._wrapper = functools.wraps(fn) > > def __get__(self, obj, cls): > return self._wrapper(functools.partial(self._function, > cls if obj is None else obj)) from types import MethodType class ClassOrInstance(object): def __init__(self, func): self._func = func def __get__(self, obj, cls): return MethodType(self._func, cls if obj is None else obj, cls) -Miles From ben+python at benfinney.id.au Sun Jun 21 18:09:45 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Jun 2009 08:09:45 +1000 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> <1245614253.3797.1.camel@linux-3eb6.site> Message-ID: <87skhtxmqe.fsf@benfinney.id.au> Paul Watson writes: > On Mon, 2009-04-13 at 17:03 +0200, WP wrote: > > dict = {1:'astring', 2:'anotherstring'} > > for key in dict.keys(): > > print 'Press %i for %s' % (key, dict[key]) > > In addition to the comments already made, this code will be quite > broken if there is ever a need to localize your package in another > language. How is this code especially broken? AFAICT, it merely needs the strings marked for translation, which is the best i18n situation any regular program can hope for anyway. -- \ ?Crime is contagious? if the government becomes a lawbreaker, | `\ it breeds contempt for the law.? ?Justice Louis Brandeis | _o__) | Ben Finney From walton.nathaniel at gmail.com Sun Jun 21 18:42:51 2009 From: walton.nathaniel at gmail.com (Nate) Date: Sun, 21 Jun 2009 15:42:51 -0700 (PDT) Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: On Jun 21, 3:49?pm, Christian Heimes wrote: > Nate wrote: > > gmapcreator = subprocess.Popen("java -Xms128M -Xmx512M -jar > > gmapcreator.jar -dfile=censettings.xml", stdin=subprocess.PIPE, > > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > Try this: > > gmapcreator = subprocess.Popen( > ? ? ["java", "-Xms128M", "-Xmx512M", "-jar", "gmapcreator.jar", > ? ? "-dfile=censettings.xml"], stdin=subprocess.PIPE, > ? ? stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > out, err = gmapcreator.communicate("stdin input") > > The subprocess doesn't use the shell so you have to apply the command as > a list of strings. > > Do you really need stdin, stdout and stderr as pipes? If you aren't > carefully with the API your program can block. > > Christian Christian, Thanks for your response. Related to this talk about shells, maybe you could point me towards a resource where I could read about how windows commands are processed w/w/o shells? I guess I assumed all subprocess commands were intepreted by the same thing, cmd.exe., or perhaps the shell. I guess this also ties in with me wondering what the whole subprocess Popen instantiation encompassed (the __init__ of the subprocess.Popen class?). I don't think I need stdin, stdout, stderr as pipes, I just was faced with several options for how to capture these things and I chose subprocess.PIPE. I could also os.pipe my own pipes, or create a file descriptor in one of a couple of ways, right? I'm just unclear on which method is preferable for me. All I want to do is pull the first 2 lines from the output before gmapcreator.jar finishes. The first 2 lines of output are always the same except a few numbers. From steve at REMOVETHIS.cybersource.com.au Sun Jun 21 19:24:28 2009 From: steve at REMOVETHIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 22 Jun 2009 09:24:28 +1000 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: <024eb31e$0$23675$c3e8da3@news.astraweb.com> Piet van Oostrum wrote: > I notice that I see several postings on news:comp.lang.python that are > replies to other postings that I don't see. I see the same problem. I suspect it's because of over-vigorous spam filtering from Usenet providers. Some even block everything from anyone using Google Groups. It's quite frustrating, to have perfectly valid Python-related posts go missing while dozens of posts offering to sell well-known brands of shoes and watches are delivered. -- Steven From lists at cheimes.de Sun Jun 21 19:40:58 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 22 Jun 2009 01:40:58 +0200 Subject: os.system vs subprocess In-Reply-To: References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: Nate wrote: > Thanks for your response. Related to this talk about shells, maybe you > could point me towards a resource where I could read about how windows > commands are processed w/w/o shells? I guess I assumed all subprocess > commands were intepreted by the same thing, cmd.exe., or perhaps the > shell. The subprocess module never uses the shell unless you tell it so. On Unix the modules uses fork() the exec*() familiy to create a new process. On Windows it's the CreateProcess() api. If you want to read about the Windows stuff then have fun at http://msdn.microsoft.com/ ;) > I guess this also ties in with me wondering what the whole subprocess > Popen instantiation encompassed (the __init__ of the subprocess.Popen > class?). It does *a lot* of stuff. The subprocess module tries very hard to create an easy to use interface that abstracts all OS specific traps very well. Most of the subprocess module is written in Python but that doesn't mean it's easy to understand. Have fun again! > I don't think I need stdin, stdout, stderr as pipes, I just was faced > with several options for how to capture these things and I chose > subprocess.PIPE. I could also os.pipe my own pipes, or create a file > descriptor in one of a couple of ways, right? I'm just unclear on > which method is preferable for me. All I want to do is pull the first > 2 lines from the output before gmapcreator.jar finishes. The first 2 > lines of output are always the same except a few numbers. os.pipe() are suffering from the same issue as subprocess.PIPE. In fact the PIPE constant tells subprocess to use OS specific pipes. If you don't read from all pipes simultaneously one pipe may get filled up to its buffer limit and both programs block. As long as you use just one PIPE or the communicate() method then nothing can get wrong. Christian From aahz at pythoncraft.com Sun Jun 21 19:43:49 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 16:43:49 -0700 Subject: dynamically associate radio buttons with droplists References: Message-ID: In article , Leo Brugud wrote: > >Not being very familiar with python, nor with cgi/http, I intend to >have 3 of buttons in a webpage, each of them is associate with a file >(so I have 3 files, too) > >What I would like to have is, when users choose a button, the droplist >update automatically to load the contents of the associated file. > >Can someone educate me the approach of this? Are you trying to do this without requiring the user to click the submit button? If yes, you need to learn JavaScript (although I think there are web frameworks that will auto-generate the JavaScript, you need to know JavaScript in order to do debugging). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From greg at cosc.canterbury.ac.nz Sun Jun 21 20:44:47 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 22 Jun 2009 12:44:47 +1200 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) In-Reply-To: References: <2d56febf0906200237v698e88c9q4389ee5435a2bdd6@mail.gmail.com> <0058d2da$0$9759$c3e8da3@news.astraweb.com> <77e831100906201047l58c59adcr5818fad21db482ac@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> <50697b2c0906211122x412bbb2ahb0cb27f67b4d8b66@mail.gmail.com> Message-ID: <7a82dsF1tthgsU1@mid.individual.net> Dennis Lee Bieber wrote: > unless one is reading from a server > that interprets X-no-archive to mean "delete before reading". Can't be too careful with security. Destroy it, memorize it and then read it! -- Greg From arlie.c at gmail.com Sun Jun 21 20:48:29 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 17:48:29 -0700 (PDT) Subject: pyinstaller Message-ID: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Newbie here using Python 2.6.2 on MS WinXP Pro SP3. I'm trying create an frozen exec and was able to generate and exe file. python D:\pyinstaller-1.3\Makespec.py -F myprog.py python D:\pyinstaller-1.3\Build.py myprog.spec --paths=D: \pyinstaller-1.3;D:\PROJECTS\pyproject but when I ran "myprog.exe" i get this: Traceback (most recent call last): File "", line 2, in File "D:\pyinstaller-1.3\iu.py", line 312, in importHook mod = _self_doimport(nm, ctx, fqname) File "D:\pyinstaller-1.3\iu.py", line 398, in doimport exec co in mod.__dict__ File "D:\PROJECTS\python.paging.system.client \buildpaging_system_client\out1.p yz/MySQLdb", line 19, in File "D:\pyinstaller-1.3\iu.py", line 312, in importHook mod = _self_doimport(nm, ctx, fqname) File "D:\pyinstaller-1.3\iu.py", line 382, in doimport mod = director.getmod(nm) File "D:\pyinstaller-1.3\iu.py", line 215, in getmod mod = owner.getmod(nm) File "D:\pyinstaller-1.3\iu.py", line 77, in getmod mod = imp.load_module(nm, fp, attempt, (ext, mode, typ)) ImportError: _mysql: init failed ~~~ I have to source files namely: myprog.py mp3.py This is the content of spec file: a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'myprog.py'], pathex=['D:\\PROJECTS\\pyproject']) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, a.binaries, name='myprog.exe', debug=False, strip=False, upx=False, console=True ) Please help. From arlie.c at gmail.com Sun Jun 21 20:59:10 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 17:59:10 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: Renamed the project directory. from ... File "D:\PROJECTS\python.paging.system.client \buildpaging_system_client\out1.p ... to ... File "D:\PROJECTS\pyproject \buildpyproject\out1.p ... From arlie.c at gmail.com Sun Jun 21 21:07:47 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 18:07:47 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: <065679db-ade1-44f0-8c85-9d5efa806568@p6g2000pre.googlegroups.com> Imported files in myprog.py: import MySQLdb import os # works on Windows or Linux, also Vista import os.path import time import mp3 ~~~~~~~ Content of mp3.py: # -*- coding: utf-8 -*- #Michel Claveau import time from ctypes import windll, c_buffer class mci: def __init__(self): self.w32mci = windll.winmm.mciSendStringA self.w32mcierror = windll.winmm.mciGetErrorStringA def send(self,commande): buffer = c_buffer(255) errorcode = self.w32mci(str(commande),buffer,254,0) if errorcode: return errorcode, self.get_error(errorcode) else: return errorcode,buffer.value def get_error(self,error): error = int(error) buffer = c_buffer(255) self.w32mcierror(error,buffer,254) return buffer.value def directsend(self, txt): (err,buf)=self.send(txt) if err != 0: print'Error',str(err),'sur',txt,':',buf return (err,buf) ################################################################### def play(mp3file): xmci=mci() xmci.directsend('open "' + mp3file + '" alias toto') xmci.directsend('set toto time format milliseconds') err,buf=xmci.directsend('status toto length ') #print 'Duree du fichier : ',buf,' millisecondes' soundlength = int(buf) / 1000 err,buf=xmci.directsend('play toto from 0 to '+str(buf)) #time.sleep(int(buf)/1000) time.sleep(soundlength + 1) xmci.directsend('close toto') From greg at cosc.canterbury.ac.nz Sun Jun 21 21:08:41 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 22 Jun 2009 13:08:41 +1200 Subject: generator expression works in shell, NameError in script In-Reply-To: <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> <7a0icpF1smf41U1@mid.individual.net> <9197b9a2-9196-4a92-af3f-2f3735e956a7@h23g2000vbc.googlegroups.com> Message-ID: <7a83qpF1u3ivuU1@mid.individual.net> guthrie wrote: > -- I don't get this - the only local loop variable is "e", not lst. Yes, but the whole list comprehension gets put into a nested function, including the part that evaluates lst. (It's not strictly *necessary* to do that, but that's the way it happens to be implemented at the moment.) > It would generally be the case that a nested function would have > access to its enclosing scope. Usually, but class namespaces are a special case -- they're not considered to be enclosing scopes, even though textually they're written that way. > it certainly appears un-intuitive It is, but it's hard to see what could be done to improve the situation without introducing worse problems. -- Greg From arlie.c at gmail.com Sun Jun 21 21:16:24 2009 From: arlie.c at gmail.com (Arlie) Date: Sun, 21 Jun 2009 18:16:24 -0700 (PDT) Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> <065679db-ade1-44f0-8c85-9d5efa806568@p6g2000pre.googlegroups.com> Message-ID: <759f6b39-e42f-46a1-80b4-32e953a4753a@x29g2000prf.googlegroups.com> Content of warnmyprog.txt: W: no module named posix (conditional import by os) W: no module named optik.__all__ (top-level import by optparse) W: no module named readline (delayed, conditional import by cmd) W: no module named readline (delayed import by pdb) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named ctypes.windll (top-level import by mp3) W: no module named ctypes.c_buffer (top-level import by mp3) W: no module named posix (delayed, conditional import by iu) W: no module named fcntl (conditional import by subprocess) W: no module named org (top-level import by copy) W: no module named _emx_link (conditional import by os) W: no module named optik.__version__ (top-level import by optparse) W: no module named fcntl (top-level import by tempfile) W: __all__ is built strangely at line 0 - collections (C:\Python26\lib \collections.pyc) W: delayed exec statement detected at line 0 - collections (C: \Python26\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C: \Python26\lib\doctest.pyc) W: delayed __import__ hack detected at line 0 - encodings (C: \Python26\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - optparse (D: \pyinstaller-1.3\optparse.pyc) W: delayed __import__ hack detected at line 0 - ctypes (C: \Python26\lib\ctypes\__init__.pyc) W: delayed __import__ hack detected at line 0 - ctypes (C: \Python26\lib\ctypes\__init__.pyc) W: __all__ is built strangely at line 0 - dis (C:\Python26\lib \dis.pyc) W: delayed eval hack detected at line 0 - os (C:\Python26\lib\os.pyc) W: __all__ is built strangely at line 0 - __future__ (C:\Python26\lib \__future__.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\lib\unittest.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\lib\unittest.pyc) W: __all__ is built strangely at line 0 - tokenize (C:\Python26\lib \tokenize.pyc) W: delayed exec statement detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\lib \bdb.pyc) W: delayed __import__ hack detected at line 0 - pickle (C: \Python26\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (C: \Python26\lib\pickle.pyc) W: delayed conditional exec statement detected at line 0 - iu (D: \pyinstaller-1.3\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (D: \pyinstaller-1.3\iu.pyc) W: delayed eval hack detected at line 0 - gettext (C:\Python26\lib \gettext.pyc) W: delayed __import__ hack detected at line 0 - optik.option_parser (D:\pyinstaller-1.3\optik\option_parser.pyc) W: delayed conditional eval hack detected at line 0 - warnings (C: \Python26\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (C:\Python26\lib\warnings.pyc) W: __all__ is built strangely at line 0 - optik (D: \pyinstaller-1.3\optik\__init__.pyc) W: delayed exec statement detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C: \Python26\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C: \Python26\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\lib \pdb.pyc) From ldo at geek-central.gen.new_zealand Sun Jun 21 21:50:10 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 13:50:10 +1200 Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: In message , Christian Heimes wrote: > The subprocess doesn't use the shell ... It can if you tell it to. From ldo at geek-central.gen.new_zealand Sun Jun 21 21:52:55 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 13:52:55 +1200 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: In message , Phil Runciman wrote: > What I can say is that for scientific/engineering calculations the RPN of > KDF9 was Great because assembler was no harder than using algol60 for the > calculations part of the problems I worked on. Unfortunately, we had to learn the hard way that machine instruction sets must be designed for efficiency of execution, not ease of use by humans. Stack-based architectures, for all their charm, cannot match register-based ones in this regard. From aahz at pythoncraft.com Sun Jun 21 23:28:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 21 Jun 2009 20:28:40 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> <77e831100906201048s3a169449i852e1120a214b3dc@mail.gmail.com> Message-ID: In article , Piet van Oostrum wrote: > >I notice that I see several postings on news:comp.lang.python that are >replies to other postings that I don't see. As stated previously, my suspicion is that at least some is caused by a problem with MIME messages and the mail->news gateway on python.org. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From timr at probo.com Sun Jun 21 23:50:14 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 21 Jun 2009 20:50:14 -0700 Subject: File Syncing References: Message-ID: <5rvt35donevj7k3e3rf6bg7d51e676uujo@4ax.com> dads wrote: >On Jun 20, 11:21?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message > >> b0d7-586b1b332... at t10g2000vbg.googlegroups.com>, dads wrote: >> > What would I have to learn to be able to sync the text files on each >> > server? >> >> How big is the text file? If it's small, why not have your script read it >> directly from a master server every time it runs, instead of having a local >> copy. > >Yeah the text files will never get bigger than a 100k. I don't think >they have a master server but i'll check. Thanks He's suggesting that you just PICK one and make that the master server. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bcharrow at csail.mit.edu Mon Jun 22 00:14:50 2009 From: bcharrow at csail.mit.edu (Ben Charrow) Date: Mon, 22 Jun 2009 00:14:50 -0400 Subject: Idioms and Anti-Idioms Question Message-ID: <4A3F053A.10208@csail.mit.edu> I have a question about the "Using Backslash to Continue Statements" in the howto "Idioms and Anti-Idioms in Python" (http://docs.python.org/howto/doanddont.html#using-backslash-to-continue-statements) It says: "...if the code was: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) then it would just be subtly wrong." What is subtly wrong about this piece of code? I can't see any bugs and can't think of subtle gotchas (e.g. the '\' is removed or the lines become separated, because in both cases an IndentationError would be raised). Cheers, Ben From cjns1989 at gmail.com Mon Jun 22 01:30:20 2009 From: cjns1989 at gmail.com (Chris Jones) Date: Mon, 22 Jun 2009 01:30:20 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <20090622053020.GA2769@turki.gavron.org> On Sun, Jun 14, 2009 at 06:42:50PM EDT, Lawrence D'Oliveiro wrote: > In message , Chris > Jones wrote: > > Vivaldi vs. Mozart > > > > And the latter especially had definitely mastered his editor. Just > > think of the sheer volume of the coding he managed during his short > > life. > > > > Not many bugs either? > > I thought Vivaldi did more. The style of music was such that they > could virtually sketch it out in shorthand, and leave it to the > copyists to expand to proper notation for the musicians to play. I > imagine that it was also the job of copyists to fix the typos. 100 years before Frederick W. Taylor was born..? Vivaldi ran a school for musically-minded young women, I heard, so his alumni may have pitched in. Mozart on the other hand, pretty much must have spent his days coding. It has been estimated that the fastest copyist would need years to manually reproduce the sum total of his manuscripts. Mind you, that's only stuff I read years ago, and even though I looked around a bit, I have no evidence to corroborate. > In other words, high productivity was a direct consequence of adoption > of a cookie-cutter style. It looks like we pretty much agree. You make it sound like it was Vivaldi who invented Pacbase. :-) Maybe I'm nitpicking, but the one thing I don't understand is how you practice programming. The term makes obvious sense when you're talking about your golf swing, acquiring competitive driving skills, playing tetris.. But programming..?? CJ From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 01:51:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Jun 2009 05:51:11 GMT Subject: Idioms and Anti-Idioms Question References: Message-ID: On Mon, 22 Jun 2009 00:14:50 -0400, Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in > the howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to- continue-statements) > > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > + calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? I can't see any bugs and > can't think of subtle gotchas (e.g. the '\' is removed or the lines > become separated, because in both cases an IndentationError would be > raised). As examples go, it's pretty lousy because you can't just copy and paste it into an interpreter session and see for yourself. However, with some helper objects: def forbulate(*args): return [1] def calculate_number(*args): return 2 class K: pass foo = K() foo.bar = lambda: {'first': [1, 2, 3]} baz = K() baz.quux = lambda *args: [3]*10 value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) I can run the example. I confirm that it works without a space after the line continuation character. Using Python 2.5, if I put a space after the backslash I get SyntaxError: unexpected character after line continuation character followed by IndentationError: unexpected indent So I don't understand the claim that the code is "subtly wrong" either. It looks to me like it's obviously wrong. -- Steven From lie.1296 at gmail.com Mon Jun 22 01:54:47 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 05:54:47 GMT Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in > the howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to-continue-statements) > > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > + calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? I can't see any bugs and > can't think of subtle gotchas (e.g. the '\' is removed or the lines > become separated, because in both cases an IndentationError would be > raised). The preferred style is to put the binary operators before the line-break (i.e. the line break is after the operators): value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ calculate_number(10, 20)*forbulate(500, 360) and even more preferrable is NOT to use explicit line break at all; relying on implicit breaking with parentheses since then you won't need to worry about empty lines: value = (foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + calculate_number(10, 20)*forbulate(500, 360) ) although, in a formula that is so complex, the most preferable way is to separate them so they won't need to take more than a single line: a = foo.bar()['first'][0] b = baz.quux(1, 2)[5:9] c = calculate_number(10, 20) d = forbulate(500, 360) value = a*b + c*d of course, a, b, c, d should be substituted with a more helpful names. The following is an extract from PEP 8: """ The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is *after* the operator, not before it. """ From vishal_shetye at persistent.co.in Mon Jun 22 02:27:35 2009 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Mon, 22 Jun 2009 11:57:35 +0530 Subject: Help: Group based synchronize decorator In-Reply-To: References: Message-ID: Thanks. - vishal > -----Original Message----- > Sent: Friday, June 19, 2009 3:15 PM > To: python-list at python.org > Subject: Python-list Digest, Vol 69, Issue 214 > > Message: 6 > Date: Fri, 19 Jun 2009 10:53:27 +0200 > From: Piet van Oostrum > To: python-list at python.org > Subject: Re: Help: Group based synchronize decorator > Message-ID: > Content-Type: text/plain; charset=us-ascii > > >>>>> Vishal Shetye (VS) wrote: > > >VS> I want to synchronize calls using rw locks per 'group' and my > implementation is similar to > >VS> http://code.activestate.com/recipes/465057/ > >VS> except that I have my own Lock implementation. > > >VS> All my synchronized functions take 'whatGroup' as param. My lock > considers 'group' while deciding on granting locks through acquire. > > >VS> What I could come up with is: > >VS> - decorator knows(assumes) first param to decorated functions is > always 'whatGroup' > >VS> - decorator passes this 'whatGroup' argument to my lock which is used > in acquire logic. > > >VS> Is it ok to make such assumptions in decorator? > > As long as you make sure that all decorated functions indeed adhere to > that assumption there is nothing wrong with it. > -- > Piet van Oostrum > URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] > Private email: piet at vanoostrum.org DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. From bob.martin at excite.com Mon Jun 22 02:36:02 2009 From: bob.martin at excite.com (Bob Martin) Date: Mon, 22 Jun 2009 06:36:02 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: in 118305 20090621 214008 Phil Runciman wrote: >How many instruction sets have you used? I have used at least 9. IBM 1401 IBM 1410 IBM 7090/7094 IBM 1620 IBM 360 IBM System/7 IBM 1130 IBM 1800 IBM Series/1 Intel 8080 etc Motorola 6800 etc Texas 9900 (my second favourite) plus a bunch of IBM microprocessor cards (eg Woodstock). From artem.bz at gmail.com Mon Jun 22 02:59:41 2009 From: artem.bz at gmail.com (=?KOI8-R?B?4dLUxc0g7snLz8zBxdfJ3g==?=) Date: Sun, 21 Jun 2009 23:59:41 -0700 (PDT) Subject: failed to build decompyle/unpyc project on WindowsXP References: <22c2aec7-1707-4696-8e15-a7c9a26027e0@a5g2000pre.googlegroups.com> Message-ID: <4ebdb4bb-2c5b-4f91-ab2d-13e552a0b180@k20g2000vbp.googlegroups.com> Hello! Project: http://unpyc.googlecode.com/svn/trunk/ For resolve problem You must: 1. modify file setup.py replace ext_modules = [Extension('unpyc/marshal_20', ['unpyc/'], define_macros=[]), Extension('unpyc/marshal_21', ['unpyc/marshal_21.c'], define_macros=[]), Extension('unpyc/marshal_22', ['unpyc/marshal_22.c'], define_macros=[]), Extension('unpyc/marshal_23', ['unpyc/marshal_23.c'], define_macros=[]), Extension('unpyc/marshal_24', ['unpyc/marshal_24.c'], define_macros=[]), Extension('unpyc/marshal_25', ['unpyc/marshal_25.c'], define_macros=[]), Extension('unpyc/marshal_26', ['unpyc/marshal_26.c'], define_macros=[]), ] on ext_modules = [Extension('marshal_20', ['marshal_20.c'], define_macros=[]), Extension('marshal_21', ['marshal_21.c'], define_macros=[]), Extension('marshal_22', ['marshal_22.c'], define_macros=[]), Extension('marshal_23', ['marshal_23.c'], define_macros=[]), Extension('marshal_24', ['marshal_24.c'], define_macros=[]), Extension('marshal_25', ['marshal_25.c'], define_macros=[]), Extension('marshal_26', ['marshal_26.c'], define_macros=[]), ] 2. ?opy files marshal_20.c marshal_21.c marshal_22.c marshal_23.c marshal_24.c marshal_25.c marshal_26.c from "unpyc" directory to "..\unpyc" near "setup.py" file. 3. Run python.exe setup.py install From eckhardt at satorlaser.com Mon Jun 22 03:07:03 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 22 Jun 2009 09:07:03 +0200 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> <1245614253.3797.1.camel@linux-3eb6.site> <87skhtxmqe.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Paul Watson writes: >> On Mon, 2009-04-13 at 17:03 +0200, WP wrote: >> > dict = {1:'astring', 2:'anotherstring'} >> > for key in dict.keys(): >> > print 'Press %i for %s' % (key, dict[key]) >> >> In addition to the comments already made, this code will be quite >> broken if there is ever a need to localize your package in another >> language. > > How is this code especially broken? AFAICT, it merely needs the strings > marked for translation, which is the best i18n situation any regular > program can hope for anyway. > The problem is that some language might require you to write "For X press Y", which is impossible to achieve here. I think percent-formatting supports using keys, like "Press %{key} for %{action}" % {'key': key, 'action':dict[key]} However, I would also like to hear what Paul really meant and also the alternatives he proposes. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From http Mon Jun 22 03:26:51 2009 From: http (Paul Rubin) Date: 22 Jun 2009 00:26:51 -0700 Subject: Can I replace this for loop with a join? References: <74h2hnF135f35U1@mid.individual.net> Message-ID: <7xbpog3f0k.fsf@ruckus.brouhaha.com> WP writes: > I could do it like this: > dict = {1:'astring', 2:'anotherstring'} > for key in dict.keys(): > print 'Press %i for %s' % (key, dict[key]) > Press 1 for astring > Press 2 for anotherstring Note that dict.keys() will return the keys in random order. > but can I use a join instead? print '\n'.join('Press %s for %s' for (k,v) in sorted(dict.iteritems())) (untested) should print them in order. Yes it is ok to use %s to format integers. Note: normally you should not call your dictionary 'dict', since 'dict' is a built-in value and overriding it could confuse people and/or code. From lucaberto at libero.it Mon Jun 22 03:29:06 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 00:29:06 -0700 (PDT) Subject: ctypes list library Message-ID: There is a command for ctypes that help me to know the entry points inside a library. Thanks Luca From sunruijia at gmail.com Mon Jun 22 03:33:11 2009 From: sunruijia at gmail.com (=?GB2312?B?wu2yu82jzOO1xNbt?=) Date: Mon, 22 Jun 2009 00:33:11 -0700 (PDT) Subject: error when use libgmail with proxy Message-ID: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Hi all, Does anybody use libgmail with proxy? I met error here. Below is code snip: libgmail.PROXY_URL = G_PROXY # the proxy url self.ga = libgmail.GmailAccount(account,pwd) self.ga.login() Error information: ga.login () File "C:\Python25\Lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage (req) File "C:\Python25\Lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open (req) File "build\bdist.win32\egg\mechanize\_opener.py", line 191, in open File "C:\Python25\lib\urllib2.py", line 399, in _open '_open', req) File "C:\Python25\lib\urllib2.py", line 360, in _call_chain result = func (*args) File "build\bdist.win32\egg\mechanize\_http.py", line 751, in https_open AttributeError: 'int' object has no attribute 'find_key_cert' Is it possible the issue of mechanize? From mail at timgolden.me.uk Mon Jun 22 03:57:40 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Jun 2009 08:57:40 +0100 Subject: os.system vs subprocess In-Reply-To: References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: <4A3F3974.70704@timgolden.me.uk> Nate wrote: > Thanks for your response. Related to this talk about shells, maybe you > could point me towards a resource where I could read about how windows > commands are processed w/w/o shells? I guess I assumed all subprocess > commands were intepreted by the same thing, cmd.exe., or perhaps the > shell. Just a comment here: on Windows, you almost *never* need to specify shell=True. Certainly, far less than most people seem to think you need to. The only things which certainly need shell to be set True are those which don't really exist as programs in their own right: dir, copy etc. You don't need to set it for batch files (altho' this does seem to vary slightly between versions) and you certainly don't need to set it for console programs in general, such as Python. import subprocess subprocess.call (["dir"], shell=False) subprocess.call (["dir"], shell=True) with open ("test.bat", "w") as f: f.write ("echo hello") subprocess.call (["test.bat"], shell=False) subprocess.call (["python", "-c", "import sys; print sys.executable"], shell=False) This all works as expected using Python 2.6.1 on WinXP SP3 TJG From ldo at geek-central.gen.new_zealand Mon Jun 22 04:01:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Jun 2009 20:01:07 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Lie Ryan wrote: > The preferred style is to put the binary operators before the line-break > ... Not by me. I prefer using a two-dimensional layout to make the expression structure more obvious: value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) In this case it's not necessary, but if the factors were really long, this could become value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) From mail at microcorp.co.za Mon Jun 22 04:03:13 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 22 Jun 2009 10:03:13 +0200 Subject: Status of Python threading support (GIL removal)? References: <4a3bb4b8$0$31342$9b4e6d93@newsspool4.arcor-online.net><4a3d0017$0$31332$9b4e6d93@newsspool4.arcor-online.net> <7x7hz5jyt3.fsf@ruckus.brouhaha.com> Message-ID: <002d01c9f30f$e4b07b80$0d00a8c0@Hendrik> "Paul Rubin" wrote: > "Hendrik van Rooyen" writes: > > I think that this is because (like your link has shown) the problem > > is really not trivial, and also because the model that can bring > > sanity to the party (independent threads/processes that communicate > > with queued messages) is seen as inefficient at small scale. > > That style works pretty well in Python and other languages. The main > gripe about it for Python is the subject of this thread, i.e. the GIL. I have found that if you accept it, and sprinkle a few judicious time.sleep(short_time)'s around, things work well. Sort of choosing yourself when the thread gives up its turn. - Hendrik From lucafbb at gmail.com Mon Jun 22 04:19:48 2009 From: lucafbb at gmail.com (Luca) Date: Mon, 22 Jun 2009 10:19:48 +0200 Subject: raw_input with a pre-compiled data In-Reply-To: References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: > With "traduced" you stumbled upon another false friend ;) > > http://it.wikipedia.org/wiki/Falso_amico D'oh!!! x-) > import readline > > def input_default(prompt, default): > ? ?def startup_hook(): > ? ? ? ?readline.insert_text(default) > ? ?readline.set_startup_hook(startup_hook) > ? ?try: > ? ? ? ?return raw_input(prompt) > ? ?finally: > ? ? ? ?readline.set_startup_hook(None) > > print input_default("directory? ", default="/home/john") > Thanks! It works! This is working on Linux and MacOS too. > The readline module is specific to Unix implementations. > I don't know what OS the OP was using. Any one knows is this working also on Windows? I've no Win system right no to test this... -- -- luca From clp2 at rebertia.com Mon Jun 22 04:36:05 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 01:36:05 -0700 Subject: raw_input with a pre-compiled data In-Reply-To: <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> <27308d500906220119k6df3e56ase96b444d2ef521f2@mail.gmail.com> Message-ID: <50697b2c0906220136h3a3b8e32l4c2a8624c0b0f806@mail.gmail.com> On Mon, Jun 22, 2009 at 1:19 AM, Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: >> With "traduced" you stumbled upon another false friend ;) >> >> http://it.wikipedia.org/wiki/Falso_amico > > D'oh!!! ? x-) > >> import readline >> >> def input_default(prompt, default): >> ? ?def startup_hook(): >> ? ? ? ?readline.insert_text(default) >> ? ?readline.set_startup_hook(startup_hook) >> ? ?try: >> ? ? ? ?return raw_input(prompt) >> ? ?finally: >> ? ? ? ?readline.set_startup_hook(None) >> >> print input_default("directory? ", default="/home/john") >> > > Thanks! It works! This is working on Linux and MacOS too. > >> The readline module is specific to Unix implementations. >> I don't know what OS the OP was using. > > Any one knows is this working also on Windows? I've no Win system > right no to test this... No, it won't. "specific to Unix" == Unix-only Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Mon Jun 22 04:49:18 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 10:49:18 +0200 Subject: ctypes list library In-Reply-To: References: Message-ID: <7a8usgF1mj0ccU1@mid.uni-berlin.de> luca72 schrieb: > There is a command for ctypes that help me to know the entry points > inside a library. dir() on a loaded library? But it won't do you any good, without having the header-file you can't possibly know what the functions take for parameters. Diez From __peter__ at web.de Mon Jun 22 04:52:12 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Jun 2009 10:52:12 +0200 Subject: raw_input with a pre-compiled data References: <27308d500906200717n5cba6a47v126dce105b02bb3@mail.gmail.com> <50697b2c0906200938j73e1913cj9926957fd1900c67@mail.gmail.com> Message-ID: Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__peter__ at web.de> wrote: >> import readline > Any one knows is this working also on Windows? I've no Win system > right no to test this... I do not have Windows available, either, but you might try http://ipython.scipy.org/moin/PyReadline/Intro Peter From lucaberto at libero.it Mon Jun 22 04:56:52 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 01:56:52 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> Thanks for your reply. I have another question i can load a list of library? Thanks Luca From deets at nospam.web.de Mon Jun 22 05:04:00 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 11:04:00 +0200 Subject: ctypes list library In-Reply-To: <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> Message-ID: <7a8vo1F1sas0bU1@mid.uni-berlin.de> luca72 schrieb: > Thanks for your reply. > I have another question i can load a list of library? Yes. Diez From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:13:42 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:13:42 +0200 Subject: Missing c.l.py posts (was Re: A question on scope...) In-Reply-To: References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> Message-ID: <4a3f4b46$0$11882$426a74cc@news.free.fr> Aahz a ?crit : > In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, > Bruno Desthuilliers wrote: >> NB : answering the OP (original post didn't show up on c.l.py ???) > > Correct. There's a problem with the mail->news gateway, I think that > MIME messages are failing. I "fixed" the problem for c.l.py.announce by > making the list reject non-ASCII messages, but I don't think that's an > option for python-list. Hu, I see. FWIW, it's not the first time I observe this (posts not showing up, only answers...), but at least I now know why. Well, I guess it might be possible to have the gateway "extract" the text part from MIME messages, but I'm not sure I'd volunteer to work on this... Just out of curiousity, where can I find more infos on this gateway ? From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:21:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:21:23 +0200 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: <024cfe79$0$23675$c3e8da3@news.astraweb.com> Message-ID: <4a3f4d13$0$11882$426a74cc@news.free.fr> Piet van Oostrum a ?crit : >>>>>> Steven D'Aprano (SD) wrote: (snip) >> SD> # A.__base__ = DebugA ## Uncomment this line for debugging. > >>>> A.__base__ = DebugA > TypeError: readonly attribute > > Make that: A.__bases__ = DebugA, or even better (readability-wise): A.__bases__ = (DebugA,) Just the same thing, but at least you wont neither miss the ',' no wonder wether it's a typo or the author really wanted a tuple. From bruno.42.desthuilliers at websiteburo.invalid Mon Jun 22 05:28:01 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Jun 2009 11:28:01 +0200 Subject: Inheritance and forward references (prototypes) In-Reply-To: References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> Message-ID: <4a3f4ea1$0$9730$426a74cc@news.free.fr> Dave Angel a ?crit : (snip > Default > arguments of class methods are evaluated during the definition of the > class Default arguments of functions are eval'd during the execution of the def statement. The fact that you use a def statement within a class statement's body is totally orthogonal - a def statement produces a function object, period. It's only when resolved as a class attribute that a function "becomes" a method object (thanks to the descriptor protocol). From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: ctypes list library References: Message-ID: luca72 wrote: > There is a command for ctypes that help me to know the entry points > inside a library. I don't know.. However nm on the library works quite well on the command line $ nm --defined-only -D /usr/lib/libdl.so 00000000 A GLIBC_2.0 00000000 A GLIBC_2.1 00000000 A GLIBC_2.3.3 00000000 A GLIBC_2.3.4 00000000 A GLIBC_PRIVATE 0000304c B _dlfcn_hook 000013b0 T dladdr 00001400 T dladdr1 00000ca0 T dlclose 00001170 T dlerror 00001490 T dlinfo 00001760 T dlmopen 00000ae0 T dlopen 000018d0 T dlopen 00000cf0 T dlsym 00000dd0 W dlvsym nm from the mingw distribution works on Windows too IIRC. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: Allocating memory to pass back via ctypes callback function References: <0b8e092f-2353-4a6b-8ff0-62e1e7b4d427@r3g2000vbp.googlegroups.com> Message-ID: Scott wrote: > I think I found the answer to my own question. Can anyone spot any > issues with the following solution? The application I'm writing will > be hitting these callbacks pretty heavily so I'm nervous about mucking > up the memory management and creating one of those bugs that passes > undetected through testing but nails you in production. > > def my_callback(p_cstring): > answer = 'foobar' > > address = VENDOR_malloc(len(answer)+1) > > cstring = c_char_p.from_address( address ) I think this allocates the pointer (the c_char_p) in the malloced block, not the actual data... > cstring.value = answer And this overwrites the pointer > p_cstring.contents = cstring > return If you try this, it gives all sorts of rubbish data / segfaults memmove(address, address+1, 1) Here is how I'd do it from ctypes import * from ctypes.util import find_library c_lib = CDLL(find_library("c")) malloc = c_lib.malloc malloc.argtypes = [c_long] malloc.restype = c_void_p answer = 'foobar\0' address = malloc(len(answer)) print address cstring = c_char_p() print addressof(cstring) cstring.value = address memmove(address, answer, len(answer)) print cstring.value memmove(address, address+1, 1) print cstring.value Which prints 159611736 3084544552 foobar ooobar -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Mon Jun 22 05:29:28 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 22 Jun 2009 04:29:28 -0500 Subject: Convert hash to struct References: Message-ID: D'Arcy J.M. Cain wrote: > On Fri, 19 Jun 2009 13:17:24 -0500 > Amita Ekbote wrote: > > I am retrieving values from a database in the form of a dictionary so > > I can access the values as d['column'] and I was wondering if there is > > a way to convert the hash to a struct like format so i can just say > > d.column. Makes it easier to read and understand. > > Are there enough clues here? > > class MyDict(dict): > def __getattribute__(self, name): > return dict.__getattribute__(self, name) > > def __getattr__(self, name): > return self.get(name, 42) > > x = MyDict({'a': 1, 'b': 2, 'values': 3}) That is my preferred solution - subclass dict rather than make a new type... I use this a lot for returning results from databases. Here is a more fleshed out version. Changing KeyError to AttributeError is necessary if you want the object to pickle. class MyDict(dict): """ A dictionary with attribute access also. If a builtin dictionary method collides with a member of the dictionary, the member function will win. """ def __getattr__(self, name): try: return super(db_dict, self).__getitem__(name) except KeyError: raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name)) def __setattr__(self, name, value): return super(db_dict, self).__setitem__(name, value) def __delattr__(self, name): try: return super(db_dict, self).__delitem__(name) except KeyError: raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name)) def copy(self): return MyDict(self) > print x.a > print x.z > print x.values > > Big question - what should the last line display? If you expect "3" > and not "" then > you need to reconsider the above implementation. Thinking about the > question may change your opinion about this being a good idea after > all. Indeed! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From csali at tiscali.it Mon Jun 22 05:53:18 2009 From: csali at tiscali.it (Carlo Salinari) Date: Mon, 22 Jun 2009 11:53:18 +0200 Subject: ctypes list library In-Reply-To: <7a8usgF1mj0ccU1@mid.uni-berlin.de> References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <4A3F548E.3010808@tiscali.it> Diez B. Roggisch wrote: > luca72 schrieb: >> There is a command for ctypes that help me to know the entry points >> inside a library. > > dir() on a loaded library? > > But it won't do you any good, without having the header-file you can't > possibly know what the functions take for parameters. I was trying this right now, but I can't even get the exported function names: >>> from ctypes import * >>> l = cdll.msvcrt >>> type(l) >>> dir(l) ['_FuncPtr', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_func_flags_', '_func_restype_', '_handle', '_name'] shouldn't the C functions names be there? From deets at nospam.web.de Mon Jun 22 05:59:09 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 11:59:09 +0200 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> Message-ID: <7a92ocF1uhgjcU1@mid.uni-berlin.de> Carlo Salinari wrote: > Diez B. Roggisch wrote: >> luca72 schrieb: >>> There is a command for ctypes that help me to know the entry points >>> inside a library. >> >> dir() on a loaded library? >> >> But it won't do you any good, without having the header-file you can't >> possibly know what the functions take for parameters. > > I was trying this right now, but I can't even get the exported function > names: To be honest, I wasn't 100% sure about this. That was the reason for the "?", but I admit that I should have phrased it more explicitly. But again, it is pretty useless anyway. Diez From jonas.esp at googlemail.com Mon Jun 22 06:06:53 2009 From: jonas.esp at googlemail.com (Kless) Date: Mon, 22 Jun 2009 03:06:53 -0700 (PDT) Subject: Check module without import it Message-ID: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> Is there any way to check that it's installed a module without import it directly? I'm using the nex code but it's possible that it not been necessary to import a module ----------------- try: import module except ImportError: pass else: print 'make anything' ----------------- From phostu at gmail.com Mon Jun 22 06:22:32 2009 From: phostu at gmail.com (Vincent) Date: Mon, 22 Jun 2009 03:22:32 -0700 (PDT) Subject: error when use libgmail with proxy References: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Message-ID: <61667eb5-4b7f-40ba-ad1a-f096e0544fc2@v35g2000pro.googlegroups.com> On Jun 22, 3:33 pm, ?????? wrote: > Hi all, > Does anybody use libgmail with proxy? I met error here. > > Below is code snip: > > libgmail.PROXY_URL = G_PROXY # the proxy url > self.ga = libgmail.GmailAccount(account,pwd) > self.ga.login() > > Error information: > ga.login > () > File "C:\Python25\Lib\site-packages\libgmail.py", line 305, in > login > pageData = self._retrievePage > (req) > File "C:\Python25\Lib\site-packages\libgmail.py", line 348, in > _retrievePage > resp = self.opener.open > (req) > File "build\bdist.win32\egg\mechanize\_opener.py", line 191, in > open > File "C:\Python25\lib\urllib2.py", line 399, in > _open > '_open', > req) > File "C:\Python25\lib\urllib2.py", line 360, in > _call_chain > result = func > (*args) > File "build\bdist.win32\egg\mechanize\_http.py", line 751, in > https_open > AttributeError: 'int' object has no attribute > 'find_key_cert' > > Is it possible the issue of mechanize? I do not know why you need proxy. i have used gdata do the same work like you. then i descript it in my blog: vincent-w.blogspot.com From eglyph at gmail.com Mon Jun 22 06:43:46 2009 From: eglyph at gmail.com (eGlyph) Date: Mon, 22 Jun 2009 03:43:46 -0700 (PDT) Subject: error when use libgmail with proxy References: <00b140f7-3275-4ddd-abf5-cea279fdde3b@e20g2000vbc.googlegroups.com> Message-ID: <6c61f034-c1dc-4341-ae7e-79a7fd80e989@r3g2000vbp.googlegroups.com> On 22 ???, 10:33, ?????? wrote: > Hi all, > Does anybody use libgmail with proxy? I met error here. I wouldn't recommend to use this module at all. It was writtent at the time when no IMAP was available at Google. Now there are POP and IMAP, so it's better to use them. From kushal.kumaran+python at gmail.com Mon Jun 22 06:44:16 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 22 Jun 2009 16:14:16 +0530 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: > I am running python on a mac and when I was getting going it was difficult > to setup information. Specifically how modify bash_profile, how pythonpath > works and how to set it up. how to switch between python versions. How/where > to install modules if you have multiple installed versions. I am thinking > about this from perspective? of a new pythoner (is there a word for a person > who programs in python). I think many new pythoners may be like me and don't > mess with the underling UNIX on a mac. > My question/suggestion is that there be a nice tutorial for this. I am > wiling to contribute much but I am still somewhat new to python and may need > help with some details. Also where should this be posted, how do I post it. > Do other think there is a need? Any willing to help? > But of course I may have missed a great tutorial out there if so I think It > needs to be easier to findor I need to learn how to look. > Have you seen the page at http://www.python.org/download/mac/ and the pages linked from it? -- kushal From wbsoft at xs4all.nl Mon Jun 22 06:57:35 2009 From: wbsoft at xs4all.nl (Wilbert Berendsen) Date: Mon, 22 Jun 2009 12:57:35 +0200 Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: <200906221257.35618.wbsoft@xs4all.nl> Op maandag 22 juni 2009, schreef Lawrence D'Oliveiro: > value = \ > ( > foo.bar()['first'][0] * baz.quux(1, 2)[5:9] > + > calculate_number(10, 20) * forbulate(500, 360) > ) I' prefer: value = (foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360)) w best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi From Olivier.Darge at gmail.com Mon Jun 22 07:22:15 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 22 Jun 2009 04:22:15 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: On 22 juin, 12:44, Kushal Kumaran wrote: > On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: > > I am running python on a mac and when I was getting going it was difficult > > to setup information. Specifically how modify bash_profile, how pythonpath > > works and how to set it up. how to switch between python versions. How/where > > to install modules if you have multiple installed versions. I am thinking > > about this from perspective? of a new pythoner (is there a word for a person > > who programs in python). I think many new pythoners may be like me and don't > > mess with the underling UNIX on a mac. > > My question/suggestion is that there be a nice tutorial for this. I am > > wiling to contribute much but I am still somewhat new to python and may need > > help with some details. Also where should this be posted, how do I post it. > > Do other think there is a need? Any willing to help? > > But of course I may have missed a great tutorial out there if so I think It > > needs to be easier to findor I need to learn how to look. > > Have you seen the page athttp://www.python.org/download/mac/and the > pages linked from it? do you think a pythonista can go further than the given example ? " >>> 2 + 2 4 " ;-) Olivier From Olivier.Darge at gmail.com Mon Jun 22 07:30:35 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 22 Jun 2009 04:30:35 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <63c6a696-540c-4eee-903a-d22bfb7a216a@l34g2000vbi.googlegroups.com> On 22 juin, 12:44, Kushal Kumaran > Have you seen the page athttp://www.python.org/download/mac/and the > pages linked from it? > As a (usefull) add-on : iPython (a must), I found this page a good help : http://www.brianberliner.com/2008/04/ipython-on-mac-os-x-105-leopard/ Olivier From lorenzo.digregorio at gmail.com Mon Jun 22 07:33:43 2009 From: lorenzo.digregorio at gmail.com (Lorenzo Di Gregorio) Date: Mon, 22 Jun 2009 04:33:43 -0700 (PDT) Subject: Inheritance and forward references (prototypes) References: <607f2ced-2907-4cd4-ab0a-5e2491301c17@l32g2000vba.googlegroups.com> <1d4a4119-cf2d-498c-83f5-694b994fe585@l8g2000vbp.googlegroups.com> Message-ID: <8bcd8622-d2a1-4ab1-9270-1334d0ac48a9@n21g2000vba.googlegroups.com> On 21 Jun., 22:51, Scott David Daniels wrote: > LorenzoDiGregoriowrote: > > On 21 Jun., 01:54, Dave Angel wrote: > >> ... > >> class B(object): > >> ? ? def __init__(self,test=None): > >> ? ? ? ? if test==None: > >> ? ? ? ? ? ? test = A() > >> ? ? ? ? self.obj =() > >> ? ? ? ? return > > ... > > I had also thought of using "None" (or whatever else) as a marker but > > I was curious to find out whether there are better ways to supply an > > object with standard values as a default argument. > > In this sense, I was looking for problems ;-) > > > Of course the observation that "def" is an instruction and no > > declaration changes the situation: I would not have a new object being > > constructed for every instantiation with no optional argument, because > > __init__ gets executed on the instantiation but test=A() gets executed > > on reading 'def'.... > > If what you are worrying about is having a single default object, you > could do something like this: > > ? ? ?class B(object): > ? ? ? ? ?_default = None > > ? ? ? ? ?def __init__(self, test=None): > ? ? ? ? ? ? ?if test is None: > ? ? ? ? ? ? ? ? ?test = self._default > ? ? ? ? ? ? ? ? ?if test is None: > ? ? ? ? ? ? ? ? ? ? ?B._default = test = A() > ? ? ? ? ? ? ?... > > --Scott David Daniels > Scott.Dani... at Acm.Org- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - Well, I could also declare (ups, define ;-)) __init__(self,**kwargs) and within the __init__, if kwargs['test'] exists, do test = kwargs ['test'], if it does not exist, do test = A(). The point is that it would have been cleaner to place it straight in the __init__, but due to the semantic of 'def' this does not seem possible. From ldo at geek-central.gen.new_zealand Mon Jun 22 08:03:36 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 00:03:36 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Wilbert Berendsen wrote: > I' prefer: > > value = (foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + > calculate_number(10, 20) * forbulate(500, 360)) I prefer using a two-dimensional layout to make the expression structure more obvious: value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) In this case it's not necessary, but if the factors were really long, this could become value = \ ( foo.bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360) ) From lucaberto at libero.it Mon Jun 22 08:19:43 2009 From: lucaberto at libero.it (luca72) Date: Mon, 22 Jun 2009 05:19:43 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> Message-ID: Can you tell me how load a list of library Thanks From aberry at aol.in Mon Jun 22 08:20:02 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 05:20:02 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <24146279.post@talk.nabble.com> Switching between python version Lets assume you have python 2.4.x and now you installed 2.5.x.By default python path will point to 2.4.x. To switch to python 2.5.x, use following commands... cd /usr/bin sudo rm pythonw sudo ln -s "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" pythonw sudo rm python sudo ln -s pythonw python2.5 sudo ln -s python2.5 python this worked for me... do let me know if any1 has other way of doing... Rgds, aberry Vincent Davis wrote: > > I am running python on a mac and when I was getting going it was difficult > to setup information. Specifically how modify bash_profile, how pythonpath > works and how to set it up. how to switch between python versions. > How/where > to install modules if you have multiple installed versions. I am thinking > about this from perspective of a new pythoner (is there a word for a > person > who programs in python). I think many new pythoners may be like me and > don't > mess with the underling UNIX on a mac. > My question/suggestion is that there be a nice tutorial for this. I am > wiling to contribute much but I am still somewhat new to python and may > need > help with some details. Also where should this be posted, how do I post > it. > Do other think there is a need? Any willing to help? > But of course I may have missed a great tutorial out there if so I think > It > needs to be easier to findor I need to learn how to look. > > Thanks > Vincent > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146279.html Sent from the Python - python-list mailing list archive at Nabble.com. From deets at nospam.web.de Mon Jun 22 08:29:58 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 14:29:58 +0200 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> Message-ID: <7a9bj5F1uhor1U1@mid.uni-berlin.de> luca72 wrote: > Can you tell me how load a list of library from ctypes.util import find_library from ctypes import CDLL for name in list_of_libraries: lib = CDLL(find_library(name)) Do you actually read the documentation of ctypes? Or python, for that matter? Diez From deets at nospam.web.de Mon Jun 22 08:31:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 14:31:17 +0200 Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <7a9blkF1uhor1U2@mid.uni-berlin.de> aberry wrote: > > Switching between python version > Lets assume you have python 2.4.x and now you installed 2.5.x.By default > python path will point to 2.4.x. To switch to python 2.5.x, use following > commands... > > cd /usr/bin > sudo rm pythonw > sudo ln -s "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" > pythonw > sudo rm python > sudo ln -s pythonw python2.5 > sudo ln -s python2.5 python > > this worked for me... do let me know if any1 has other way of doing... Bad idea. It might break tools that need the /usr/bin/python to be the system's python. a simple export PATH=/Library/.../bin:$PATH inside .bashrc should be all you need. Diez From tkpmep at hotmail.com Mon Jun 22 08:42:40 2009 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Mon, 22 Jun 2009 05:42:40 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> Message-ID: <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> I think a setup guide for the Mac would prove very useful. Earlier this year, I tried installing Python 2.6 on my iMac, and ran into all sorts of problems, largely as a result of the fact that I knew very little about Unix. I finally downloaded and installed the Enthought Python distribution for the Mac and it worked like a charm. From pdpinheiro at gmail.com Mon Jun 22 08:46:55 2009 From: pdpinheiro at gmail.com (pdpi) Date: Mon, 22 Jun 2009 05:46:55 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> Message-ID: <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> On Jun 19, 8:13?pm, Charles Yeomans wrote: > On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: > > > > > > > Evidently my posts are appearing, since I see replies. > > I guess the question of why I don't see the posts themselves > > \is ot here... > > > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson > > wrote: > > >> On Jun 18, 7:26 pm, David C. Ullrich ? > >> wrote: > >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson > >>>> Right. ?Or rather, you treat it as the image of such a function, > >>>> if you're being careful to distinguish the curve (a subset > >>>> of R^2) from its parametrization (a continuous function > >>>> R -> R**2). ?It's the parametrization that's uniformly > >>>> continuous, not the curve, > > >>> Again, it doesn't really matter, but since you use the phrase > >>> "if you're being careful": In fact what you say is exactly > >>> backwards - if you're being careful that subset of the plane > >>> is _not_ a curve (it's sometimes called the "trace" of the curve". > > >> Darn. ?So I've been getting it wrong all this time. ?Oh well, > >> at least I'm not alone: > > >> "De?nition 1. A simple closed curve J, also called a > >> Jordan curve, is the image of a continuous one-to-one > >> function from R/Z to R2. [...]" > > >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. > > >> "We say that Gamma is a curve if it is the image in > >> the plane or in space of an interval [a, b] of real > >> numbers of a continuous function gamma." > > >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). > > >> Perhaps your definition of curve isn't as universal or > >> 'official' as you seem to think it is? > > > Perhaps not. I'm very surprised to see those definitions; I've > > been a mathematician for 25 years and I've never seen a > > curve defined a subset of the plane. > > I have. > > > > > > > > > Hmm. You left out a bit in the first definition you cite: > > > "A simple closed curve J, also called a Jordan curve, is the image > > of a continuous one-to-one function from R/Z to R2. We assume that > > each curve > > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z > > the time > > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j > > (t), using the > > same notation for the function phi_J and its image J." > > > Close to sounding like he can't decide whether J is a set or a > > function... > > On the contrary, I find this definition to be written with some care. I find the usage of image slightly ambiguous (as it suggests the image set defines the curve), but that's my only qualm with it as well. Thinking pragmatically, you can't have non-simple curves unless you use multisets, and you also completely lose the notion of curve orientation and even continuity without making it a poset. At this point in time, parsimony says that you want to ditch your multiposet thingie (and God knows what else you want to tack in there to preserve other interesting curve properties) and really just want to define the curve as a freaking function and be done with it. From steve.ferg.bitbucket at gmail.com Mon Jun 22 08:50:34 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 22 Jun 2009 05:50:34 -0700 (PDT) Subject: easiest way to check python version? References: <82b698bc-b40f-4d03-aeae-2330a5d768e3@r3g2000vbp.googlegroups.com> Message-ID: Here is what I use in easygui:
#--------------------------------------------------
# check python version and take appropriate action
#--------------------------------------------------
"""
>From the python documentation:

sys.hexversion contains the version number encoded as a single
integer. This is
guaranteed to increase with each version, including proper support for
non-
production releases. For example, to test that the Python interpreter
is at
least version 1.5.2, use:

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
"""
if sys.hexversion >= 0x020600F0: runningPython26 = True
else: runningPython26 = False

if sys.hexversion >= 0x030000F0: runningPython3 = True
else: runningPython3 = False

if runningPython3:
    from tkinter import *
    import tkinter.filedialog as tk_FileDialog
    from io import StringIO
else:
    from Tkinter import *
    import tkFileDialog as tk_FileDialog
    from StringIO import StringIO

-- Steve Ferg From aberry at aol.in Mon Jun 22 08:56:12 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 05:56:12 -0700 (PDT) Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <7a9blkF1uhor1U2@mid.uni-berlin.de> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> Message-ID: <24146713.post@talk.nabble.com> thanks for suggestion... what should I put in 'bashrc ' so that I can switch between different version. as python command will always point to one Python framework (lets either 2.4.x or 2.5.x). regards, aberry Diez B. Roggisch-2 wrote: > > aberry wrote: > >> >> Switching between python version >> Lets assume you have python 2.4.x and now you installed 2.5.x.By default >> python path will point to 2.4.x. To switch to python 2.5.x, use following >> commands... >> >> cd /usr/bin >> sudo rm pythonw >> sudo ln -s >> "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" >> pythonw >> sudo rm python >> sudo ln -s pythonw python2.5 >> sudo ln -s python2.5 python >> >> this worked for me... do let me know if any1 has other way of doing... > > Bad idea. It might break tools that need the /usr/bin/python to be the > system's python. > > a simple > > export PATH=/Library/.../bin:$PATH > > inside .bashrc should be all you need. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146713.html Sent from the Python - python-list mailing list archive at Nabble.com. From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 08:56:24 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 14:56:24 +0200 Subject: Graphical library - charts Message-ID: Hello, I have thousends of files with logs from monitoring system. Each file has some important data (numbers). I'd like to create charts using those numbers. Could you please suggest library which will allow creating such charts ? The preferred chart is line chart. Besides is there any library which allow me to zoom in/out of such chart ? Sometimes I need to create chart using long-term data (a few months) but then observe a minutes - it would be good to not create another short-term chart but just zoom-in. Those files are on one unix server and the charts will be displayed on another unix server so the X-Window protocol is going to be used. Any suggestions ? Best regards przemol From jeanmichel at sequans.com Mon Jun 22 08:57:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 14:57:37 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1245269001.27277.28.camel@aalcdl07> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> Message-ID: <4A3F7FC1.1000200@sequans.com> J. Cliff Dyer wrote: > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >> >>>> What's np.arange? >>>> >>>> >>> import numpy as np >>> >>> -- >>> Pierre "delroth" Bourdon >>> ?tudiant ? l'EPITA / Student at EPITA >>> >>> >> Perfect example of why renaming namespaces should be done only when >> absolutely required, that is, almost never. >> >> Jean-Michel >> > > I disagree. Renaming namespaces should always be done if it will help > stop people from doing a 'from package import *'. However, example code > should always include relevant imports. > > Cheers, > Cliff > > > The import * should not used if possible, I totally agree on that point, but there's no need to rename namespaces for that. br Jean-Michel From aberry at aol.in Mon Jun 22 09:00:07 2009 From: aberry at aol.in (aberry) Date: Mon, 22 Jun 2009 06:00:07 -0700 (PDT) Subject: UnicodeDecodeError: problem when path contain folder start with character 'u Message-ID: <24146775.post@talk.nabble.com> I am facing an error on Unicode decoding of path if it contain a folder/file name starting with character 'u' . Here is what I did in IDLE 1. >>> fp = "C:\\ab\\anil" 2. >>> unicode(fp, "unicode_escape") 3. u'C:\x07b\x07nil' 4. >>> fp = "C:\\ab\\unil" 5. >>> unicode(fp, "unicode_escape") 6. 7. Traceback (most recent call last): 8. File "", line 1, in 9. unicode(fp, "unicode_escape") 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 5-9: end of string in escape sequence 11. >>> Not sure whether I am doing something wrong or this is as designed behavior . any help appreciated Rgds, aberry -- View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24146775.html Sent from the Python - python-list mailing list archive at Nabble.com. From bluefisher80 at gmail.com Mon Jun 22 09:17:20 2009 From: bluefisher80 at gmail.com (Jim Qiu) Date: Mon, 22 Jun 2009 21:17:20 +0800 Subject: How to output a complex List object to a file. Message-ID: Hi all, I have a object list list this: from bots.botsconfig import * from D96Arecords import recorddefs from edifactsyntax3 import syntax structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] I need to output this "structure" object into a file, how to do that ? Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Mon Jun 22 09:17:43 2009 From: aahz at pythoncraft.com (Aahz) Date: 22 Jun 2009 06:17:43 -0700 Subject: Missing c.l.py posts (was Re: A question on scope...) References: <3f1a902d0906180954o11d4aba9p9e3bb612ed403b22@mail.gmail.com> <4a3b5dc3$0$2985$426a74cc@news.free.fr> <4a3f4b46$0$11882$426a74cc@news.free.fr> Message-ID: In article <4a3f4b46$0$11882$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: >Aahz a ?crit : >> In article <4a3b5dc3$0$2985$426a74cc at news.free.fr>, >> Bruno Desthuilliers wrote: >>> >>> NB : answering the OP (original post didn't show up on c.l.py ???) >> >> Correct. There's a problem with the mail->news gateway, I think that >> MIME messages are failing. I "fixed" the problem for c.l.py.announce by >> making the list reject non-ASCII messages, but I don't think that's an >> option for python-list. > >Hu, I see. FWIW, it's not the first time I observe this (posts not >showing up, only answers...), but at least I now know why. Well, I guess >it might be possible to have the gateway "extract" the text part from >MIME messages, but I'm not sure I'd volunteer to work on this... Just >out of curiousity, where can I find more infos on this gateway ? It's part of Mailman, so that's where you should start. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From davea at ieee.org Mon Jun 22 09:17:47 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 09:17:47 -0400 Subject: ctypes list library In-Reply-To: References: Message-ID: <4A3F847B.4060608@ieee.org> Nick Craig-Wood wrote: > luca72 wrote: > >> There is a command for ctypes that help me to know the entry points >> inside a library. >> > > I don't know.. > > However nm on the library works quite well on the command line > > $ nm --defined-only -D /usr/lib/libdl.so > 00000000 A GLIBC_2.0 > 00000000 A GLIBC_2.1 > 00000000 A GLIBC_2.3.3 > 00000000 A GLIBC_2.3.4 > 00000000 A GLIBC_PRIVATE > 0000304c B _dlfcn_hook > 000013b0 T dladdr > 00001400 T dladdr1 > 00000ca0 T dlclose > 00001170 T dlerror > 00001490 T dlinfo > 00001760 T dlmopen > 00000ae0 T dlopen > 000018d0 T dlopen > 00000cf0 T dlsym > 00000dd0 W dlvsym > > nm from the mingw distribution works on Windows too IIRC. > > For Windows, you can use the Microsoft tool DUMPBIN to display entry points (and other stuff) for a DLL. Notice that a DLL may have almost any extension, including EXE, SYS, DRV, ... From bjourne at gmail.com Mon Jun 22 09:20:26 2009 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 22 Jun 2009 15:20:26 +0200 Subject: Graphical library - charts In-Reply-To: References: Message-ID: <740c3aec0906220620p4e43a326g5893bb15cbc43042@mail.gmail.com> 2009/6/22 : > Hello, > > I have thousends of files with logs from monitoring system. Each file > has some important data (numbers). I'd like to create charts using those > numbers. Could you please suggest library which will allow creating > such charts ? The preferred chart is line chart. > > Besides is there any library which allow me to zoom in/out of such chart ? > Sometimes I need to create chart using long-term data (a few months) but > then observe a minutes - it would be good to not create another short-term > chart but just zoom-in. > > Those files are on one unix server and the charts will be displayed on > another unix server so the X-Window protocol is going to be used. Try Google Charts. It is quite excellent for easily creating simple charts. There is also Gnuplot which is more advanced and complicated. Both tools have python bindings. -- mvh Bj?rn From philip at semanchuk.com Mon Jun 22 09:23:04 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 22 Jun 2009 09:23:04 -0400 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <6172D09B-ABB4-4E89-8F4D-619F05531F9A@semanchuk.com> On Jun 22, 2009, at 9:17 AM, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, ...snip... > > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? Have you looked at the pickle module? From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 09:27:03 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 15:27:03 +0200 Subject: Graphical library - charts References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart >> ? Sometimes I need to create chart using long-term data (a few months) >> but then observe a minutes - it would be good to not create another >> short-term chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. Which option is better: pygooglechart http://pygooglechart.slowchop.com/ google-chartwrapper http://code.google.com/p/google-chartwrapper/ Regards Przemek From steve.ferg.bitbucket at gmail.com Mon Jun 22 09:29:56 2009 From: steve.ferg.bitbucket at gmail.com (Steve Ferg) Date: Mon, 22 Jun 2009 06:29:56 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: If you are looking for *classics*, then you can't beat Michael Jackson's "Principles of Program Design" and "System Development". They are pre-ObjectOriented, but if you really want to understand what application programming is all about, this is where you should start. I also recommend Eric S. Roberts "Thinking Recursively". I don't know if it can be considered a classic, but a good programmer needs to be able to understand and do recursion, and I found this book a very readable introduction. It may also help if you bring a tighter focus to your search. The domain of programming can be divided up into large subdomains, each with its own specialized types of problems, techniques and classics. Here are some subdomains that I can think of off the top of my head: system programming -- dealing with interacting with the computer at the bits and bytes level scientific programming -- dealing with algorithms business programming -- dealing with data structures and the events that change them embedded & real-time programming -- dealing with controlling machines ... and there are probably others, such as writing compilers/ interpreters, and robotics programming. From przemolicc at poczta.fm-n-o-s-p-a-m Mon Jun 22 09:35:14 2009 From: przemolicc at poczta.fm-n-o-s-p-a-m (przemolicc at poczta.fm-n-o-s-p-a-m) Date: Mon, 22 Jun 2009 15:35:14 +0200 Subject: Graphical library - charts References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart >> ? Sometimes I need to create chart using long-term data (a few months) >> but then observe a minutes - it would be good to not create another >> short-term chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. By the way: do I need any access to internet while using this library ? Regards przemol From rridge at csclub.uwaterloo.ca Mon Jun 22 09:36:52 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Mon, 22 Jun 2009 09:36:52 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: Piet van Oostrum wrote: >I notice that I see several postings on news:comp.lang.python that are >replies to other postings that I don't see. Aahz wrote: >As stated previously, my suspicion is that at least some is caused by a >problem with MIME messages and the mail->news gateway on python.org. I'm not sure what MIME would have to do with it, but Piet van Oostrum's problem is almost certainly as result of the python.org mail to news gateway mangling the References header. The missing postings he's looking for don't actually exist. Just go up the thread one more posting and you'll find the message that was being replied to. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From deets at nospam.web.de Mon Jun 22 09:36:56 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Jun 2009 15:36:56 +0200 Subject: python needs a tutorial for install and setup on a Mac References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> Message-ID: <7a9fgnF1uclajU1@mid.uni-berlin.de> aberry wrote: > > thanks for suggestion... > what should I put in 'bashrc ' so that I can switch between different > version. > as python command will always point to one Python framework (lets either > 2.4.x or 2.5.x). if you want to switch, put in there three different lines, and comment that in that you need. Or write short bash-functions that replace the path. Not scripts!! They won't work. But I think if you want to switch, you are better off using fully qualified names, such as python2.5 and link these to your desired versions. Or start using virtualenvs for everything (as I do), and don't bother as you simply activate the one you want before using python. Diez From philip at semanchuk.com Mon Jun 22 09:59:02 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 22 Jun 2009 09:59:02 -0400 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <24146713.post@talk.nabble.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <7a9blkF1uhor1U2@mid.uni-berlin.de> <24146713.post@talk.nabble.com> Message-ID: On Jun 22, 2009, at 8:56 AM, aberry wrote: > > thanks for suggestion... > what should I put in 'bashrc ' so that I can switch between different > version. > as python command will always point to one Python framework (lets > either > 2.4.x or 2.5.x). Something like this would work: alias py25='/Library/Frameworks/Python.framework/Versions/2.5/bin/ pythonw' > Diez B. Roggisch-2 wrote: >> >> aberry wrote: >> >>> >>> Switching between python version >>> Lets assume you have python 2.4.x and now you installed 2.5.x.By >>> default >>> python path will point to 2.4.x. To switch to python 2.5.x, use >>> following >>> commands... >>> >>> cd /usr/bin >>> sudo rm pythonw >>> sudo ln -s >>> "/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw" >>> pythonw >>> sudo rm python >>> sudo ln -s pythonw python2.5 >>> sudo ln -s python2.5 python >>> >>> this worked for me... do let me know if any1 has other way of >>> doing... >> >> Bad idea. It might break tools that need the /usr/bin/python to be >> the >> system's python. >> >> a simple >> >> export PATH=/Library/.../bin:$PATH >> >> inside .bashrc should be all you need. >> >> Diez >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -- > View this message in context: http://www.nabble.com/python-needs-a-tutorial-for-install-and-setup-on-a-Mac-tp24135580p24146713.html > Sent from the Python - python-list mailing list archive at Nabble.com. > > -- > http://mail.python.org/mailman/listinfo/python-list From jcd at sdf.lonestar.org Mon Jun 22 10:12:08 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 10:12:08 -0400 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3F7FC1.1000200@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> Message-ID: <1245679928.22057.24.camel@aalcdl07> On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > J. Cliff Dyer wrote: > > On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: > > > >> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: > >> > >>>> What's np.arange? > >>>> > >>>> > >>> import numpy as np > >>> > >>> -- > >>> Pierre "delroth" Bourdon > >>> ?tudiant ? l'EPITA / Student at EPITA > >>> > >>> > >> Perfect example of why renaming namespaces should be done only when > >> absolutely required, that is, almost never. > >> > >> Jean-Michel > >> > > > > I disagree. Renaming namespaces should always be done if it will help > > stop people from doing a 'from package import *'. However, example code > > should always include relevant imports. > > > > Cheers, > > Cliff > > > > > > > The import * should not used if possible, I totally agree on that point, > but there's no need to rename namespaces for that. > > br > > Jean-Michel > Technically, no. But we're dealing with people, who are notoriously *un*technical in their behavior. A person is much more likely to develop bad habits if the alternative means more work for them. The reason people do `from foo import *` is that they don't want to type more than they have to. If they can write a one or two letter namespace, they're likely to be happy with that trade-off. If the alternative is to write out long module names every time you use a variable, they'll tend to develop bad habits. To paraphrase Peter Maurin, coding guidelines should have the aim of helping to "bring about a world in which it is easy to be good." I don't really see much problem with renaming namespaces: For people reading the code, everything is explicit, as you can just look at the top of the module to find out what module a namespace variable represent; the local namespace doesn't get polluted with God knows what from God knows where; and code remains succinct. I've found in my own code that using, for example, the name `sqlalchemy` in my code means that I have to go through painful contortions to get your code down to the PEP-8 recommended 80 characters per line. The resulting mess of multi-line statements is significantly less readable than the same code using the abbreviation `sa`. Do you have an argument for avoiding renaming namespaces? So far the only example you provided is a code fragment that doesn't run. I don't disagree with you on that example; referring to numpy as np without telling anyone what np refers to is a bad idea, but no functioning piece of code could reasonably do that. Cheers, Cliff From jcd at sdf.lonestar.org Mon Jun 22 10:17:19 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 10:17:19 -0400 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <1245680239.22057.25.camel@aalcdl07> Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, > {ID:'NAD',MIN:1,MAX:5,LEVEL:[ > {ID:'CTA',MIN:0,MAX:5,LEVEL:[ > {ID:'COM',MIN:0,MAX:5}, > ]}, > ]}, > {ID:'RFF',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'CUX',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ > {ID:'PIA',MIN:0,MAX:5}, > {ID:'IMD',MIN:0,MAX:5}, > {ID:'RFF',MIN:0,MAX:5}, > {ID:'ALI',MIN:0,MAX:5}, > {ID:'MOA',MIN:0,MAX:5}, > {ID:'PRI',MIN:0,MAX:5}, > {ID:'QTY',MIN:0,MAX:999,LEVEL:[ > {ID:'NAD',MIN:0,MAX:1}, > ]}, > ]}, > ]}, > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? > > Jim > From charles at declareSub.com Mon Jun 22 10:31:26 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 22 Jun 2009 10:31:26 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> References: <877fbba5-f13a-4fe2-bdcb-c28e59914c93@x5g2000yqk.googlegroups.com> <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: On Jun 22, 2009, at 8:46 AM, pdpi wrote: > On Jun 19, 8:13 pm, Charles Yeomans wrote: >> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >> >> >> >> >> >> >>> Hmm. You left out a bit in the first definition you cite: >> >>> "A simple closed curve J, also called a Jordan curve, is the image >>> of a continuous one-to-one function from R/Z to R2. We assume that >>> each curve >>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>> R/Z >>> the time >>> parameter. By abuse of notation, we write J(t) in R2 instead of >>> phi_j >>> (t), using the >>> same notation for the function phi_J and its image J." >> >>> Close to sounding like he can't decide whether J is a set or a >>> function... >> >> On the contrary, I find this definition to be written with some care. > > I find the usage of image slightly ambiguous (as it suggests the image > set defines the curve), but that's my only qualm with it as well. > > Thinking pragmatically, you can't have non-simple curves unless you > use multisets, and you also completely lose the notion of curve > orientation and even continuity without making it a poset. At this > point in time, parsimony says that you want to ditch your multiposet > thingie (and God knows what else you want to tack in there to preserve > other interesting curve properties) and really just want to define the > curve as a freaking function and be done with it. > -- But certainly the image set does define the curve, if you want to view it that way -- all parameterizations of a curve should satisfy the same equation f(x, y) = 0. Charles Yeomans From vlastimil.brom at gmail.com Mon Jun 22 10:41:10 2009 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 22 Jun 2009 16:41:10 +0200 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u In-Reply-To: <24146775.post@talk.nabble.com> References: <24146775.post@talk.nabble.com> Message-ID: <9fdb569a0906220741w5a43a574nef3e47f5dc07e996@mail.gmail.com> 2009/6/22 aberry : > > I am facing an error on Unicode decoding of path if it contain a folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" > 2. >>> unicode(fp, "unicode_escape") > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" > 5. >>> unicode(fp, "unicode_escape") > 6. > 7. Traceback (most recent call last): > 8. ? File "", line 1, in > 9. ? ? unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position > 5-9: end of string in escape sequence > 11. >>> > > Not sure whether I am doing something wrong or this is as designed behavior > . > any help appreciated > > Rgds, > aberry > > > -- > View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24146775.html > Sent from the Python - python-list mailing list archive at Nabble.com. > > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, It seems, that using unicode_escape codec is not appropriate here, are you sure, you are dealing with unicode encoded strings? The examples seem like usual strings with backslashes escaped. If these should be paths, you probably can use them directly without conversion (the "bel" hex 0x07 character is maybe not expected here, is it?) vbr From thudfoo at opensuse.us Mon Jun 22 11:05:26 2009 From: thudfoo at opensuse.us (member thudfoo) Date: Mon, 22 Jun 2009 08:05:26 -0700 Subject: Check module without import it In-Reply-To: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> References: <62706e41-b745-413f-8e97-dac3281303a1@g20g2000vba.googlegroups.com> Message-ID: <3d881a310906220805o2ff91ba4hf989d34747c2d8b7@mail.gmail.com> On Mon, Jun 22, 2009 at 3:06 AM, Kless wrote: > Is there any way to check that it's installed a module without import > it directly? > > I'm using the nex code but it's possible that it not been necessary to > import a module > > ----------------- > try: > ? import module > except ImportError: > ? pass > else: > ? print 'make anything' > ----------------- Have a look at find_module in the imp module of the standard library. From vincent at vincentdavis.net Mon Jun 22 11:19:42 2009 From: vincent at vincentdavis.net (Vincent Davis) Date: Mon, 22 Jun 2009 09:19:42 -0600 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <5ba21633-275d-4ca4-b6f0-8465743b94be@v4g2000vba.googlegroups.com> Message-ID: <77e831100906220819t25c93219k5f564bf01ba888dc@mail.gmail.com> tkpmep at hotmail.com wrote: > I think a setup guide for the Mac would prove very useful. Earlier > this year, I tried installing Python 2.6 on my iMac, and ran into all > sorts of problems, largely as a result of the fact that I knew very > little about Unix. I finally downloaded and installed the Enthought > Python distribution for the Mac and it worked like a charm. > Exactly why I think this is needed. I did the same thing, installed Enthought. Then I wanted to use 2.6 and now 3.0.1 . I have all versions installed. They work and I know how to switch between but not so sure what s going on when I things a package. I should not require lots of googling for the answers. The mailing lists are great and everyone is helpful but do you really want to answer the same questions again and agian. Kushal Kumaran "Have you seen the page at http://www.python.org/download/mac/ and the pages linked from it? Yes I have as I am sure tkpmep at hotmail.com and did not find it usefull, or I should say only a little. So I still have no answer, There seems to be a need but, no one has said "post it hear" or volunteered to help. Am I going about this wrong? Thanks Vincent -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jun 22 11:34:15 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 11:34:15 -0400 Subject: python needs a tutorial for install and setup on a Mac In-Reply-To: <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> References: <77e831100906210834j513820eana8cd77da2c02469e@mail.gmail.com> <1e364c4e0906220344k11426934w190264c22bb59607@mail.gmail.com> Message-ID: Kushal Kumaran wrote: > On Sun, Jun 21, 2009 at 9:04 PM, Vincent Davis wrote: >> I am running python on a mac and when I was getting going it was difficult >> to setup information. Specifically how modify bash_profile, how pythonpath >> works and how to set it up. how to switch between python versions. How/where >> to install modules if you have multiple installed versions. I am thinking >> about this from perspective of a new pythoner (is there a word for a person >> who programs in python). I think many new pythoners may be like me and don't >> mess with the underling UNIX on a mac. >> My question/suggestion is that there be a nice tutorial for this. I am >> wiling to contribute much but I am still somewhat new to python and may need >> help with some details. Also where should this be posted, how do I post it. >> Do other think there is a need? Any willing to help? >> But of course I may have missed a great tutorial out there if so I think It >> needs to be easier to findor I need to learn how to look. The Python doc set includes Using Python. Chapter 4 is ... on a Macintosh. If you think that is inadequate, start a new issue on the tracker (after searching for existing Mac doc issues). Python is a volunteer enterprise, and Python-Mac is a relatively small subset of volunteers, so feel free to help. > Have you seen the page at http://www.python.org/download/mac/ and the > pages linked from it? It is possible that the chapter should include material from or link to material in other pages. tjr From tjreedy at udel.edu Mon Jun 22 11:45:21 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 11:45:21 -0400 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u In-Reply-To: <24146775.post@talk.nabble.com> References: <24146775.post@talk.nabble.com> Message-ID: aberry wrote: > I am facing an error on Unicode decoding of path if it contain a folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" The results in two single \s in the string. Use / for paths, even on Windows, and you will have less trouble. > 2. >>> unicode(fp, "unicode_escape") why? Not for interacting with file system. It tries to interpret \s. Not what you want. > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" This has \u followed by three chars. \u followed by FOUR chars is a unicode escape for ONE unicode char. > 5. >>> unicode(fp, "unicode_escape") This tries to interpret \uxxxx as 1 char, but it only fines \uxxx and the string ends. > 6. > 7. Traceback (most recent call last): > 8. File "", line 1, in > 9. unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position > 5-9: end of string in escape sequence Read the doc for string literals and unicode function. From piet at cs.uu.nl Mon Jun 22 11:54:16 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 22 Jun 2009 17:54:16 +0200 Subject: UnicodeDecodeError: problem when path contain folder start with character 'u References: Message-ID: >>>>> aberry (a) a ?crit: >a> I am facing an error on Unicode decoding of path if it contain a folder/file >a> name starting with character 'u' . >a> Here is what I did in IDLE >a> 1. >>> fp = "C:\\ab\\anil" >a> 2. >>> unicode(fp, "unicode_escape") >a> 3. u'C:\x07b\x07nil' >a> 4. >>> fp = "C:\\ab\\unil" >a> 5. >>> unicode(fp, "unicode_escape") >a> 6. >a> 7. Traceback (most recent call last): >a> 8. File "", line 1, in >a> 9. unicode(fp, "unicode_escape") >a> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position >a> 5-9: end of string in escape sequence >a> 11. >>> >a> Not sure whether I am doing something wrong or this is as designed behavior >a> . >a> any help appreciated Calling unicode(fp, "unicode_escape") with these filenames is nonsense. unicode_escape is for transforming a string like \u20ac to a ?-sign or vice versa: >>> fp="\\u20ac" >>> print unicode(fp,"unicode_escape") ? So what are you trying to achieve? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Mon Jun 22 12:02:06 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 22 Jun 2009 12:02:06 -0400 Subject: Graphical library - charts In-Reply-To: References: Message-ID: przemolicc at poczta.fm-n-o-s-p-a-m wrote: >> Try Google Charts. It is quite excellent for easily creating simple >> charts. There is also Gnuplot which is more advanced and complicated. >> Both tools have python bindings. > > By the way: do I need any access to internet while using this library ? http://code.google.com/apis/chart/basics.html GoogleCharts are generated by Google in response to a url call to Google. They are intended for embedding in a web page with the url being part of an image element. While interesting for that, they may not be what you want for your app The largest size is well less than full screen. From jeanmichel at sequans.com Mon Jun 22 12:14:14 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 18:14:14 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <1245679928.22057.24.camel@aalcdl07> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4A3FADD6.3010608@sequans.com> J. Cliff Dyer wrote: > On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: > >> J. Cliff Dyer wrote: >> >>> On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: >>> >>> >>>> On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: >>>> >>>> >>>>>> What's np.arange? >>>>>> >>>>>> >>>>>> >>>>> import numpy as np >>>>> >>>>> -- >>>>> Pierre "delroth" Bourdon >>>>> ?tudiant ? l'EPITA / Student at EPITA >>>>> >>>>> >>>>> >>>> Perfect example of why renaming namespaces should be done only when >>>> absolutely required, that is, almost never. >>>> >>>> Jean-Michel >>>> >>>> >>> I disagree. Renaming namespaces should always be done if it will help >>> stop people from doing a 'from package import *'. However, example code >>> should always include relevant imports. >>> >>> Cheers, >>> Cliff >>> >>> >>> >>> >> The import * should not used if possible, I totally agree on that point, >> but there's no need to rename namespaces for that. >> >> br >> >> Jean-Michel >> >> > > Technically, no. But we're dealing with people, who are notoriously > *un*technical in their behavior. A person is much more likely to > develop bad habits if the alternative means more work for them. The > reason people do `from foo import *` is that they don't want to type > more than they have to. If they can write a one or two letter > namespace, they're likely to be happy with that trade-off. If the > alternative is to write out long module names every time you use a > variable, they'll tend to develop bad habits. To paraphrase Peter > Maurin, coding guidelines should have the aim of helping to "bring about > a world in which it is easy to be good." > > I don't really see much problem with renaming namespaces: For people > reading the code, everything is explicit, as you can just look at the > top of the module to find out what module a namespace variable > represent; the local namespace doesn't get polluted with God knows what > from God knows where; and code remains succinct. > > I've found in my own code that using, for example, the name `sqlalchemy` > in my code means that I have to go through painful contortions to get > your code down to the PEP-8 recommended 80 characters per line. The > resulting mess of multi-line statements is significantly less readable > than the same code using the abbreviation `sa`. > > Do you have an argument for avoiding renaming namespaces? So far the > only example you provided is a code fragment that doesn't run. I don't > disagree with you on that example; referring to numpy as np without > telling anyone what np refers to is a bad idea, but no functioning piece > of code could reasonably do that. > > Cheers, > Cliff > > Maybe I've been a little bit too dictatorial when I was saying that renaming namespaces should be avoided. Sure your way of doing make sense. In fact they're 2 main purposes of having strong coding rules: 1/ ease the coder's life 2/ ease the reader's life The perfect rule satisfies both of them, but when I have to choose, I prefer number 2. Renaming packages, especially those who are world wide used, may confuse the reader and force him to browse into more code. From the OP example, I was just pointing the fact that **he alone** gains 3 characters when **all** the readers need to ask what means "np". Renaming namespaces with a well chosen name (meaningful) is harmless. br Jean-Michel From edreamleo at charter.net Mon Jun 22 12:23:03 2009 From: edreamleo at charter.net (Edward K Ream) Date: Mon, 22 Jun 2009 11:23:03 -0500 Subject: ANN: Leo 4.6 beta 2 released Message-ID: Leo 4.6 b2 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.6: -------------------------- - Cached external files *greatly* reduces the time to load .leo files. - Leo now features a modern Qt interface by default. Leo's legacy Tk interface can also be used. - New --config, --file and --gui command-line options. - Leo tests syntax of .py files when saving them. - Leo can now open any kind of file into @edit nodes. - @auto-rst nodes support "round-tripping" of reStructuredText files. - Properties of commanders, positions and nodes simplify programming. - Improved Leo's unit testing framework. - Leo now requires Python 2.4 or later. - Dozens of small improvements and bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html -------------------------------------------------------------------- Edward K. Ream email: edreamleo at yahoo.com Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From tanner989 at hotmail.com Mon Jun 22 12:37:20 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Mon, 22 Jun 2009 11:37:20 -0500 Subject: Help Message-ID: Hi i was wondering how i should go about this problem: ok so i am writing a program for my school's football team and to keep the stats for each player there is a notebook with 3 tabs that has a txtctrl and a + and - button. i need to find a way to when you click the + or - button it updates that stat for that individual player. _________________________________________________________________ Hotmail? has ever-growing storage! Don?t worry about storage limits. http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009 -------------- next part -------------- An HTML attachment was scrubbed... URL: From zelegolas at gmail.com Mon Jun 22 12:58:19 2009 From: zelegolas at gmail.com (zelegolas) Date: Mon, 22 Jun 2009 09:58:19 -0700 (PDT) Subject: wikipedia with python Message-ID: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Let me know if it's the right place to ask. I'm looking for wiki writen with python where I can import all wikipedia site. If you have any links please let me know. Thanks From psimon at sonic.net Mon Jun 22 13:01:35 2009 From: psimon at sonic.net (Paul Simon) Date: Mon, 22 Jun 2009 10:01:35 -0700 Subject: Graphical library - charts References: Message-ID: <4a3fb8f7$0$95510$742ec2ed@news.sonic.net> I suggest you look at matplotlib. It's a bit of a learning curve but will do whatever you need. I have a similar requirement and found that gnuplot did not work for me. The plots are impressive. Paul Simon wrote in message news:h1nv4q$5k2$1 at news.dialog.net.pl... > Hello, > > I have thousends of files with logs from monitoring system. Each file > has some important data (numbers). I'd like to create charts using those > numbers. Could you please suggest library which will allow creating > such charts ? The preferred chart is line chart. > > Besides is there any library which allow me to zoom in/out of such chart ? > Sometimes I need to create chart using long-term data (a few months) but > then observe a minutes - it would be good to not create another short-term > chart but just zoom-in. > > Those files are on one unix server and the charts will be displayed on > another unix server so the X-Window protocol is going to be used. > > Any suggestions ? > > Best regards > przemol > From martin at marcher.name Mon Jun 22 13:16:08 2009 From: martin at marcher.name (Martin) Date: Mon, 22 Jun 2009 19:16:08 +0200 Subject: wikipedia with python In-Reply-To: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: <5fa6c12e0906221016x146a44ccr66528c73667caac9@mail.gmail.com> Does this help: http://www.mediawiki.org/wiki/MoinMoin On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: > Let me know if it's the right place to ask. > > I'm looking for wiki writen with python where I can import all > wikipedia site. > If you have any links please let me know. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.xing.com/profile/Martin_Marcher http://www.linkedin.com/in/martinmarcher You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html From lie.1296 at gmail.com Mon Jun 22 13:18:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 17:18:24 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: Jean-Michel Pichavant wrote: > Maybe I've been a little bit too dictatorial when I was saying that > renaming namespaces should be avoided. > Sure your way of doing make sense. In fact they're 2 main purposes of > having strong coding rules: > 1/ ease the coder's life > 2/ ease the reader's life > > The perfect rule satisfies both of them, but when I have to choose, I > prefer number 2. Renaming packages, especially those who are world wide > used, may confuse the reader and force him to browse into more code. > > From the OP example, I was just pointing the fact that **he alone** > gains 3 characters when **all** the readers need to ask what means "np". > Renaming namespaces with a well chosen name (meaningful) is harmless. As long as you keep all import statements at the head of the file, there is no readability problems with renaming namespace. Glance at the header file, see: import numpy as np and it's not hard to mentally switch np as numpy... well, as long as your header doesn't look like this: import numpy as np import itertools as it import Tkinter as Tk from time import time as t From andreengels at gmail.com Mon Jun 22 13:23:59 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 22 Jun 2009 19:23:59 +0200 Subject: wikipedia with python In-Reply-To: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: > Let me know if it's the right place to ask. > > I'm looking for wiki writen with python where I can import all > wikipedia site. > If you have any links please let me know. I don't think that's possible. If you wnat to import Wikipedia in a wiki, it will probably have to be MediaWiki - and that's written in PHP. What do you want to use the material for? -- Andr? Engels, andreengels at gmail.com From lie.1296 at gmail.com Mon Jun 22 13:36:07 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 22 Jun 2009 17:36:07 GMT Subject: Graphical library - charts In-Reply-To: References: Message-ID: BJ?rn Lindqvist wrote: > 2009/6/22 : >> Hello, >> >> I have thousends of files with logs from monitoring system. Each file >> has some important data (numbers). I'd like to create charts using those >> numbers. Could you please suggest library which will allow creating >> such charts ? The preferred chart is line chart. >> >> Besides is there any library which allow me to zoom in/out of such chart ? >> Sometimes I need to create chart using long-term data (a few months) but >> then observe a minutes - it would be good to not create another short-term >> chart but just zoom-in. >> >> Those files are on one unix server and the charts will be displayed on >> another unix server so the X-Window protocol is going to be used. > > Try Google Charts. It is quite excellent for easily creating simple > charts. There is also Gnuplot which is more advanced and complicated. > Both tools have python bindings. > I've used Quickplot (http://quickplot.sourceforge.net/) for similar purpose. It's not the most elegant solution since the chart viewer is external, not embedded to your program, but it works, zooming and all. You simply need to create a program that convert the log file into list of points and pipe it to quickplot or save it into a file and point quickplot to it (look at the command line options). The chart navigation is a bit unusual, but is efficient to work with once you get used to it. From ullrich at math.okstate.edu Mon Jun 22 14:11:02 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:11:02 -0500 Subject: Measuring Fractal Dimension ? References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: <59iv35d8rat0rvm45d3u14trhen69efrfe@4ax.com> On Mon, 22 Jun 2009 05:46:55 -0700 (PDT), pdpi wrote: >On Jun 19, 8:13?pm, Charles Yeomans wrote: >> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >> >> >> >> >> >> > Evidently my posts are appearing, since I see replies. >> > I guess the question of why I don't see the posts themselves >> > \is ot here... >> >> > On Thu, 18 Jun 2009 17:01:12 -0700 (PDT), Mark Dickinson >> > wrote: >> >> >> On Jun 18, 7:26 pm, David C. Ullrich ? >> >> wrote: >> >>> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson >> >>>> Right. ?Or rather, you treat it as the image of such a function, >> >>>> if you're being careful to distinguish the curve (a subset >> >>>> of R^2) from its parametrization (a continuous function >> >>>> R -> R**2). ?It's the parametrization that's uniformly >> >>>> continuous, not the curve, >> >> >>> Again, it doesn't really matter, but since you use the phrase >> >>> "if you're being careful": In fact what you say is exactly >> >>> backwards - if you're being careful that subset of the plane >> >>> is _not_ a curve (it's sometimes called the "trace" of the curve". >> >> >> Darn. ?So I've been getting it wrong all this time. ?Oh well, >> >> at least I'm not alone: >> >> >> "De?nition 1. A simple closed curve J, also called a >> >> Jordan curve, is the image of a continuous one-to-one >> >> function from R/Z to R2. [...]" >> >> >> - Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'. >> >> >> "We say that Gamma is a curve if it is the image in >> >> the plane or in space of an interval [a, b] of real >> >> numbers of a continuous function gamma." >> >> >> - Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995). >> >> >> Perhaps your definition of curve isn't as universal or >> >> 'official' as you seem to think it is? >> >> > Perhaps not. I'm very surprised to see those definitions; I've >> > been a mathematician for 25 years and I've never seen a >> > curve defined a subset of the plane. >> >> I have. >> >> >> >> >> >> >> >> > Hmm. You left out a bit in the first definition you cite: >> >> > "A simple closed curve J, also called a Jordan curve, is the image >> > of a continuous one-to-one function from R/Z to R2. We assume that >> > each curve >> > comes with a fixed parametrization phi_J : R/Z ->? J. We call t in R/Z >> > the time >> > parameter. By abuse of notation, we write J(t) in R2 instead of phi_j >> > (t), using the >> > same notation for the function phi_J and its image J." >> >> > Close to sounding like he can't decide whether J is a set or a >> > function... >> >> On the contrary, I find this definition to be written with some care. > >I find the usage of image slightly ambiguous (as it suggests the image >set defines the curve), but that's my only qualm with it as well. > >Thinking pragmatically, you can't have non-simple curves unless you >use multisets, and you also completely lose the notion of curve >orientation and even continuity without making it a poset. At this >point in time, parsimony says that you want to ditch your multiposet >thingie (and God knows what else you want to tack in there to preserve >other interesting curve properties) and really just want to define the >curve as a freaking function and be done with it. Precisely. From ullrich at math.okstate.edu Mon Jun 22 14:16:56 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:16:56 -0500 Subject: Measuring Fractal Dimension ? References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: On Mon, 22 Jun 2009 10:31:26 -0400, Charles Yeomans wrote: > >On Jun 22, 2009, at 8:46 AM, pdpi wrote: > >> On Jun 19, 8:13 pm, Charles Yeomans wrote: >>> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >>> >>> >>> >>> >>> >>> >>>> Hmm. You left out a bit in the first definition you cite: >>> >>>> "A simple closed curve J, also called a Jordan curve, is the image >>>> of a continuous one-to-one function from R/Z to R2. We assume that >>>> each curve >>>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>>> R/Z >>>> the time >>>> parameter. By abuse of notation, we write J(t) in R2 instead of >>>> phi_j >>>> (t), using the >>>> same notation for the function phi_J and its image J." >>> >>>> Close to sounding like he can't decide whether J is a set or a >>>> function... >>> >>> On the contrary, I find this definition to be written with some care. >> >> I find the usage of image slightly ambiguous (as it suggests the image >> set defines the curve), but that's my only qualm with it as well. >> >> Thinking pragmatically, you can't have non-simple curves unless you >> use multisets, and you also completely lose the notion of curve >> orientation and even continuity without making it a poset. At this >> point in time, parsimony says that you want to ditch your multiposet >> thingie (and God knows what else you want to tack in there to preserve >> other interesting curve properties) and really just want to define the >> curve as a freaking function and be done with it. >> -- > > >But certainly the image set does define the curve, if you want to view >it that way -- all parameterizations of a curve should satisfy the >same equation f(x, y) = 0. This sounds like you didn't read his post, or totally missed the point. Say S is the set of (x,y) in the plane such that x^2 + y^2 = 1. What's the "index", or "winding number", of that curve about the origin? (Hint: The curve c defined by c(t) = (cos(t), sin(t)) for 0 <= t <= 2pi has index 1 about the origin. The curve d(t) = (cos(-t), sin(-t)) (0 <= t <= 2pi) has index -1. The curve (cos(2t), sin(2t)) (same t) has index 2.) >Charles Yeomans From zelegolas at gmail.com Mon Jun 22 14:24:20 2009 From: zelegolas at gmail.com (ZeLegolas) Date: Mon, 22 Jun 2009 14:24:20 -0400 Subject: wikipedia with python In-Reply-To: <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels wrote: > On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >> Let me know if it's the right place to ask. >> >> I'm looking for wiki writen with python where I can import all >> wikipedia site. >> If you have any links please let me know. > > I don't think that's possible. If you wnat to import Wikipedia in a > wiki, it will probably have to be MediaWiki - and that's written in > PHP. > > What do you want to use the material for? Well sorry I was not clear. I have a wiki running with mediawiki and I want to import in a wiki written with python. From jeanmichel at sequans.com Mon Jun 22 14:31:13 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Jun 2009 20:31:13 +0200 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4A3FCDF1.4020203@sequans.com> Lie Ryan wrote: > Jean-Michel Pichavant wrote: > > > > >> Maybe I've been a little bit too dictatorial when I was saying that >> renaming namespaces should be avoided. >> Sure your way of doing make sense. In fact they're 2 main purposes of >> having strong coding rules: >> 1/ ease the coder's life >> 2/ ease the reader's life >> >> The perfect rule satisfies both of them, but when I have to choose, I >> prefer number 2. Renaming packages, especially those who are world wide >> used, may confuse the reader and force him to browse into more code. >> >> From the OP example, I was just pointing the fact that **he alone** >> gains 3 characters when **all** the readers need to ask what means "np". >> Renaming namespaces with a well chosen name (meaningful) is harmless. >> > > As long as you keep all import statements at the head of the file, there > is no readability problems with renaming namespace. > > Glance at the header file, see: > import numpy as np > > and it's not hard to mentally switch np as numpy... > > well, as long as your header doesn't look like this: > import numpy as np > import itertools as it > import Tkinter as Tk > from time import time as t > yep, your example is good, no namespace renaming ... :o) I would gladly accept the following renaming: import theMostEfficientPythonPackageInTheWorld as meppw Hopefully, package names are often usable as provided. Moreover, writing numpy instead of np is not harder for the coder than switching mentally from np to numpy for the reader. It's just about who you want to make the life easier, the coder or the reader ? br Jean-Michel From ullrich at math.okstate.edu Mon Jun 22 14:43:19 2009 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 22 Jun 2009 13:43:19 -0500 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> Message-ID: <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> On Fri, 19 Jun 2009 12:40:36 -0700 (PDT), Mark Dickinson wrote: >On Jun 19, 7:43?pm, David C. Ullrich wrote: >> Evidently my posts are appearing, since I see replies. >> I guess the question of why I don't see the posts themselves >> \is ot here... > >Judging by this thread, I'm not sure that much is off-topic >here. :-) > >> Perhaps not. I'm very surprised to see those definitions; I've >> been a mathematician for 25 years and I've never seen a >> curve defined a subset of the plane. > >That in turn surprises me. I've taught multivariable >calculus courses from at least three different texts >in three different US universities, and as far as I >recall a 'curve' was always thought of as a subset of >R^2 or R^3 in those courses (though not always with >explicit definitions, since that would be too much >to hope for with that sort of text). Here's Stewart's >'Calculus', p658: > >"Examples 2 and 3 show that different sets of parametric >equations can represent the same curve. Thus we >distinguish between a *curve*, which is a set of points, >and a *parametric curve*, in which the points are >traced in a particular way." > >Again as far as I remember, the rest of the language >in those courses (e.g., 'level curve', 'curve as the >intersection of two surfaces') involves thinking >of curves as subsets of R^2 or R^3. Certainly >I'll agree that it's then necessary to parameterize >the curve before being able to do anything useful >with it. > >[Standard question when teaching multivariable >calculus: "Okay, so we've got a curve. What's >the first thing we do with it?" Answer, shouted >out from all the (awake) students: "PARAMETERIZE IT!" >(And then calculate its length/integrate the >given vector field along it/etc.) >Those were the days...] Surely you don't say a curve is a subset of the plane and also talk about the integrals of verctor fields over _curves_? This is getting close to the point someone else made, before I had a chance to: We need a parametriztion of that subset of the plane before we can do most interesting things with it. The parametrization determines the set, but the set does not determine the parametrization (not even "up to" some sort of isomorphism; the set does not determine multiplicity, orientation, etc.) So if the definition of "curve" is not as I claim then in some sense it _should_ be. Hales defines a curve to be a set C and then says he assumes that there is a parametrization phi_C. Does he ever talk about things like the orientation of a curve a about a point? Seems likely. If so then his use of the word "curve" is simply not consistent with his definition. >A Google Books search even turned up some complex >analysis texts where the word 'curve' is used to >mean a subset of the plane; check out >the book by Ian Stewart and David Orme Tall, >'Complex Analysis: a Hitchhiker's Guide to the >Plane': they distinguish 'curves' (subset of the >complex plane) from 'paths' (functions from a >closed bounded interval to the complex plane). Hmm. I of all people am in no position to judge a book on complex analysis by the silliness if its title... >> "Definition 2. A polygon is a Jordan curve that is a subset of a >> finite union of >> lines. A polygonal path is a continuous function P : [0, 1] ->? R2 >> that is a subset of >> a finite union of lines. It is a polygonal arc, if it is 1 . 1." >> >> By that definition a polygonal path is not a curve. > >Right. I'm much more willing to accept 'path' as standard >terminology for a function [a, b] -> (insert_favourite_space_here). > >> Not that it matters, but his defintion of "polygonal path" >> is, _if_ we're being very careful, self-contradictory. > >Agreed. Surprising, coming from Hales; he must surely rank >amongst the more careful mathematicians out there. > >> So I don't think we can count that paper as a suitable >> reference for what the _standard_ definitions are; >> the standard definitions are not self-contradictory this way. > >I just don't believe there's any such thing as >'the standard definition' of a curve. I'm happy >to believe that in complex analysis and differential >geometry it's common to define a curve to be a >function. But in general I'd suggest that it's one >of those terms that largely depends on context, and >should be defined clearly when it's not totally >obvious from the context which definition is >intended. For example, for me, more often than not, >a curve is a 1-dimensional scheme over a field k >(usually *not* algebraically closed), that's at >least some of {geometrically reduced, geometrically >irreducible, proper, smooth}. That's a far cry either >from a subset of an affine space or from a >parametrization by an interval. Ok. >> Then the second definition you cite: Amazon says the >> prerequisites are two years of calculus. The stanard >> meaning of log is log base e, even though means >> log base 10 in calculus. > >Sorry, I've lost context for this comment. Why >are logs relevant? (I'm very well aware of the >debates over the meaning of log, having frequently >had to help students 'unlearn' their "log=log10" >mindset when starting a first post-calculus course). The point is that a calculus class is not mathematics. In my universe the standard definition of "log" is different froim what log means in a calculus class, and my point was that a definition of "curve" in a book that specifies it's supposed to be accessible to calculus students doesn't seem to me like much evidence regarding the standard definition in mathematics. >Mark From cgoldberg at gmail.com Mon Jun 22 14:50:19 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Mon, 22 Jun 2009 11:50:19 -0700 (PDT) Subject: Graphical library - charts References: <4a3fb8f7$0$95510$742ec2ed@news.sonic.net> Message-ID: <90cbb6a6-e814-478e-b1e2-c1252b8bfbe7@r3g2000vbp.googlegroups.com> > I suggest you look at matplotlib. +1 Another vote Matplotlib. It has impressive graphing/plotting capabilities and is used as a Python module/library. Description from site: "matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala matlab or mathematica), web application servers, and six graphical user interface toolkits." http://matplotlib.sourceforge.net/ -Corey Goldberg From chris at simplistix.co.uk Mon Jun 22 14:55:12 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 22 Jun 2009 19:55:12 +0100 Subject: Help In-Reply-To: References: Message-ID: <4A3FD390.3060409@simplistix.co.uk> tanner barnes wrote: > Hi i was wondering how i should go about this problem: ok so i am > writing a program for my school's football team and to keep the stats > for each player there is a notebook with 3 tabs that has a txtctrl and a > + and - button. i need to find a way to when you click the + or - button > it updates that stat for that individual player. We are not mind readers ;-) What version of Python are you using? What GUI framework are you using? Is there anywhere we can see your existing code? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From andreengels at gmail.com Mon Jun 22 15:01:16 2009 From: andreengels at gmail.com (Andre Engels) Date: Mon, 22 Jun 2009 21:01:16 +0200 Subject: wikipedia with python In-Reply-To: <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> Message-ID: <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> On Mon, Jun 22, 2009 at 8:24 PM, ZeLegolas wrote: > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. I don't think it will work, but you could try using the Special:Export page. -- Andr? Engels, andreengels at gmail.com From zelegolas at gmail.com Mon Jun 22 15:07:47 2009 From: zelegolas at gmail.com (ZeLegolas) Date: Mon, 22 Jun 2009 15:07:47 -0400 Subject: wikipedia with python In-Reply-To: <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> <778e5b9e4d0f2997114764844b56dcea@consultationscottware.com> <6faf39c90906221201q674dcaffwaa6ed769c828b1a9@mail.gmail.com> Message-ID: On Mon, 22 Jun 2009 21:01:16 +0200, Andre Engels wrote: > On Mon, Jun 22, 2009 at 8:24 PM, ZeLegolas wrote: > >> Well sorry I was not clear. I have a wiki running with mediawiki and I >> want >> to import in a wiki written with python. > > I don't think it will work, but you could try using the Special:Export > page. Thanks I will try. :) I don't choose the wiki base on python yet. Do you know one similar to mediawiki or what is the best wiki that you know? From robert.kern at gmail.com Mon Jun 22 15:11:49 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 22 Jun 2009 14:11:49 -0500 Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: <4A3FCDF1.4020203@sequans.com> References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> <4A3FCDF1.4020203@sequans.com> Message-ID: On 2009-06-22 13:31, Jean-Michel Pichavant wrote: > Moreover, writing numpy instead of np is not harder for the coder than > switching mentally from np to numpy for the reader. It's just about who > you want to make the life easier, the coder or the reader ? It depends on the audience. For those familiar with numpy and the np convention, it's easier to read code that uses np because there are many lines with several numpy functions called in each. -- 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 greyna at socal.rr.com Mon Jun 22 15:13:10 2009 From: greyna at socal.rr.com (Greg Reyna) Date: Mon, 22 Jun 2009 12:13:10 -0700 Subject: Procedures Message-ID: Learning Python (on a Mac), with the massive help of Mark Lutz's excellent book, "Learning Python". What I want to do is this: I've got a Class Object that begins with a def. It's designed to be fed a string that looks like this: "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," I'm parsing the string by finding the commas, and pulling out the data between them. No problem so far (I think...) The trouble is, there is a place where code is repeated: 1. Resetting the start & end position and finding the next comma in the string. In my previous experience (with a non-OOP language), I could create a 'procedure', which was a separate function. With a call like: var=CallProcedure(arg1,arg2) the flow control would go to the procedure, run, then Return back to the main function. In Python, when I create a second def in the same file as the first it receives a "undefined" error. I can't figure out how to deal with this. How do I set it up to have my function #1 call my function #2, and return? The only programming experience I've had where I pretty much knew what I was doing was with ARexx on the Amiga, a language much like Python without the OOP part. ARexx had a single-step debugger as part of the language installation. I've always depended on a debugger to help me understand what I'm doing (eg Script Debugger for Apple Script--not that I understand Apple Script) Python's debug system is largely confusing to me, but of course I'll keep at it. I would love to see a step-by-step debugging tutorial designed for someone like me who usually wants to single-step through an entire script. Thanks for any help, Greg Reyna From Scott.Daniels at Acm.Org Mon Jun 22 15:14:10 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Jun 2009 12:14:10 -0700 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> Chris Jones wrote: > .... Maybe I'm nitpicking, but the one thing I don't understand is how you > practice programming. > > The term makes obvious sense when you're talking about your golf swing, > acquiring competitive driving skills, playing tetris.. > > But programming..?? It is practice in the same way as learning to write well requires practice. Writing good code is a writing skill, as well as a precision of thought exercise. The basics of Computer Science are well-covered in TAOCP Volumes 1-5 (not all yet available in stores :-). You _must know data structures and fundamental algorithms, but after that what you write is a way of expressing clearly what you learn in a field. The field may be as narrow as "the field of Ink-Jet Printer automated testing for models XXX through XYZ of manufacturer Z," but in some sense the programs should clearly expr4ess that knowledge. If you read books on learning to write clearly, even if they are oriented to (non-fiction) writing in English, none of them advocate intensive study of a theory with little practice. You can follow the advice in those books (with a "loose" interpretation of the instructions) and improve your code. What the best teach you is be succinct, clear, unambiguous, and try new things regularly. It is only this variation that can help you get better. Read what others write about how to write code, but remember you will have your own style. Take what others write about how to code as a cook does a recipe: you should be understand what is being attempted, try it the authors way to see what new might surprise you, and carry away only what you find you can incorporate into your own process. How we pull stuff from our brains is as varied as the brains themselves. We bring a host of experiences to our writing, and we should similarly bring that to the programs we write. --Scott David Daniels Scott.Daniels at Acm.Org From dickinsm at gmail.com Mon Jun 22 15:38:51 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 22 Jun 2009 12:38:51 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 22, 7:43?pm, David C. Ullrich wrote: > Surely you don't say a curve is a subset of the plane and > also talk about the integrals of verctor fields over _curves_? > [snip rest of long response that needs a decent reply, but > possibly not here... ] I wonder whether we can find a better place to have this discussion; I think there are still plenty of interesting things to say, but I fear we're rather abusing the hospitality of comp.lang.python at the moment. I'd suggest moving it to sci.math, except that I've seen the noise/signal ratio over there... Mark From saurabh at saurabh.org Mon Jun 22 15:40:03 2009 From: saurabh at saurabh.org (saurabh) Date: 22 Jun 2009 19:40:03 GMT Subject: Open source python projects Message-ID: <4a3fde13$0$48239$14726298@news.sunsite.dk> Hi There, I am an experienced C programmer and recently dived into python, I have developed an instant love for it. I have been doing some routine scripting for day to day admin tasks,also have done some Tkinter and socket programming using python. I am looking for some open source python project preferably in one of the above areas (not strictly, am open to others too) to contribute. Please give me any pointers to some python project which needs a contributor. Thanks Saurabh From Scott.Daniels at Acm.Org Mon Jun 22 16:02:45 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 22 Jun 2009 13:02:45 -0700 Subject: fastest native python database? In-Reply-To: References: <07ac7d7a-48e1-45e5-a21c-f2c259c7528a@j12g2000vbl.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > ... Use Python mapping objects. > Most real-world databases will fit in memory anyway. Interesting theory. Certainly true for some definitions of "most" and "real-world" (and "databases" for that matter). --Scott David Daniels Scott.Daniels at Acm.Org From jcd at sdf.lonestar.org Mon Jun 22 16:03:31 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 22 Jun 2009 16:03:31 -0400 Subject: Procedures In-Reply-To: References: Message-ID: <1245701011.2066.20.camel@aalcdl07> On Mon, 2009-06-22 at 12:13 -0700, Greg Reyna wrote: > Learning Python (on a Mac), with the massive help of Mark Lutz's > excellent book, "Learning Python". > > What I want to do is this: > I've got a Class Object that begins with a def. It's designed to be > fed a string that looks like this: > > "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > > I'm parsing the string by finding the commas, and pulling out the > data between them. > No problem so far (I think...) The trouble is, there is a place > where code is repeated: > > 1. Resetting the start & end position and finding the next comma in the string. > Have you looked at the split() method on string objects. It works kind of like this: >>> s = "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," >>> s.split(",") ['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl 4', ' 2+4', ''] >>> elements = s.split(",") >>> elements ['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl 4', ' 2+4', ''] >>> elements[2] ' 3+8' > In my previous experience (with a non-OOP language), I could create a > 'procedure', which was a separate function. With a call like: > var=CallProcedure(arg1,arg2) the flow control would go to the > procedure, run, then Return back to the main function. > Python doesn't have procedures quite like this. It has functions (the things starting with "def"), which generally speaking take arguments and return values. For the most part, you do not want your functions to operate on variables that aren't either defined in the function or passed in as arguments. That leads to difficult-to-debug code. > In Python, when I create a second def in the same file as the first > it receives a "undefined" error. I can't figure out how to deal with > this. How do I set it up to have my function #1 call my function #2, > and return? Your problem description is confusing. First of all, no class starts with 'def'. They all start with 'class'. Perhaps you are talking about a module (a python file)? Also, telling us that you get an undefined error is not particularly helpful. Every Exception that python raises is accompanied by an extensive stack trace which will help you (or us) debug the problem. If you don't show us this information, we can't tell you what's going wrong. It will tell you (in ways that are crystal clear once you have a bit of practice reading them) exactly what went wrong. Can you show your code, as well as the complete error message you are receiving? My suggestions here, are essentially a paraphrasing of Eric Raymond's essay, "How to Ask Smart Questions." It is freely available on the web, and easily found via google. I recommend reading that, in order to get the most mileage out this news group. Cheers, Cliff From coldtortuga at gmail.com Mon Jun 22 16:08:16 2009 From: coldtortuga at gmail.com (Francis Carr) Date: Mon, 22 Jun 2009 13:08:16 -0700 (PDT) Subject: itertools.intersect? References: <331bb132-c813-4a67-982a-b2226575c86e@j20g2000vbp.googlegroups.com> Message-ID: On Jun 11, 6:23?pm, Mensanator wrote: > Removing the duplicates could be a big problem. It is fairly easy to ignore duplicates in a sorted list:
from itertools import groupby
def unique(ordered):
    """Yield the unique elements from a sorted iterable.
    """
    for key,_ in groupby(ordered):
        yield key
Combining this with some ideas of others, we have a simple, complete solution:
def intersect(*ascendingSeqs):
    """Yield the intersection of zero or more ascending iterables.
    """
    N=len(ascendingSeqs)
    if N==0:
        return

    unq = [unique(s) for s in ascendingSeqs]
    val = [u.next() for u in unq]
    while True:
        for i in range(N):
            while val[i-1] > val[i]:
                val[i] = unq[i].next()
        if val[0]==val[-1]:
            yield val[0]
            val[-1] = unq[-1].next()
This works with empty arg-lists; combinations of empty, infinite and finite iterators; iterators with duplicate elements; etc. The only requirement is that all iterators are sorted ascending. -- FC From gnewsg at gmail.com Mon Jun 22 16:49:17 2009 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 22 Jun 2009 13:49:17 -0700 (PDT) Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: On 22 Giu, 21:40, saurabh wrote: > Hi There, > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. > > Please give me any pointers to some python project which needs a > contributor. > > Thanks > Saurabh If you have experience in C system programming then you could help us with psutil: http://code.google.com/p/psutil You might want to take a look at our Milestone wiki which lists some features we would like to implement: http://code.google.com/p/psutil/wiki/Milestones The platforms we aim to support are: Linux, OS X, Windows and FreeBSD. If you're interested feel free to contact me at [g.rodola -AT- gmail - DOT- com] or use the psutil mailing list: http://groups.google.com/group/psutil --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil From philr at aspexconsulting.co.nz Mon Jun 22 16:53:20 2009 From: philr at aspexconsulting.co.nz (Phil Runciman) Date: Tue, 23 Jun 2009 08:53:20 +1200 Subject: Good books in computer science? In-Reply-To: <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <6padndYP063tS6LXnZ2dnUVZ_i2dnZ2d@pdx.net> Message-ID: A big yes to Scott's remarks. The first law of programming is: "Write as you would be written unto". Apologies to Kingsley. Phil -----Original Message----- From: Scott David Daniels [mailto:Scott.Daniels at Acm.Org] Sent: Tuesday, 23 June 2009 7:14 a.m. To: python-list at python.org Subject: Re: Good books in computer science? Chris Jones wrote: > .... Maybe I'm nitpicking, but the one thing I don't understand is how you > practice programming. > > The term makes obvious sense when you're talking about your golf swing, > acquiring competitive driving skills, playing tetris.. > > But programming..?? It is practice in the same way as learning to write well requires practice. Writing good code is a writing skill, as well as a precision of thought exercise. The basics of Computer Science are well-covered in TAOCP Volumes 1-5 (not all yet available in stores :-). You _must know data structures and fundamental algorithms, but after that what you write is a way of expressing clearly what you learn in a field. The field may be as narrow as "the field of Ink-Jet Printer automated testing for models XXX through XYZ of manufacturer Z," but in some sense the programs should clearly expr4ess that knowledge. If you read books on learning to write clearly, even if they are oriented to (non-fiction) writing in English, none of them advocate intensive study of a theory with little practice. You can follow the advice in those books (with a "loose" interpretation of the instructions) and improve your code. What the best teach you is be succinct, clear, unambiguous, and try new things regularly. It is only this variation that can help you get better. Read what others write about how to write code, but remember you will have your own style. Take what others write about how to code as a cook does a recipe: you should be understand what is being attempted, try it the authors way to see what new might surprise you, and carry away only what you find you can incorporate into your own process. How we pull stuff from our brains is as varied as the brains themselves. We bring a host of experiences to our writing, and we should similarly bring that to the programs we write. --Scott David Daniels Scott.Daniels at Acm.Org From charles at declareSub.com Mon Jun 22 17:03:14 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 22 Jun 2009 17:03:14 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <7xfxdyrk97.fsf@ruckus.brouhaha.com> <26aca241-c773-4488-91a8-e0ab6d0436a6@r34g2000vba.googlegroups.com> Message-ID: <2060624A-FC8E-4709-81E3-A1B6D346434D@declareSub.com> On Jun 22, 2009, at 2:16 PM, David C. Ullrich wrote: > On Mon, 22 Jun 2009 10:31:26 -0400, Charles Yeomans > wrote: > >> >> On Jun 22, 2009, at 8:46 AM, pdpi wrote: >> >>> On Jun 19, 8:13 pm, Charles Yeomans wrote: >>>> On Jun 19, 2009, at 2:43 PM, David C. Ullrich wrote: >>>> >>>> >>>> >>>> >>>> >>>> >>>>> Hmm. You left out a bit in the first definition you cite: >>>> >>>>> "A simple closed curve J, also called a Jordan curve, is the image >>>>> of a continuous one-to-one function from R/Z to R2. We assume that >>>>> each curve >>>>> comes with a fixed parametrization phi_J : R/Z ->? J. We call t in >>>>> R/Z >>>>> the time >>>>> parameter. By abuse of notation, we write J(t) in R2 instead of >>>>> phi_j >>>>> (t), using the >>>>> same notation for the function phi_J and its image J." >>>> >>>>> Close to sounding like he can't decide whether J is a set or a >>>>> function... >>>> >>>> On the contrary, I find this definition to be written with some >>>> care. >>> >>> I find the usage of image slightly ambiguous (as it suggests the >>> image >>> set defines the curve), but that's my only qualm with it as well. >>> >>> Thinking pragmatically, you can't have non-simple curves unless you >>> use multisets, and you also completely lose the notion of curve >>> orientation and even continuity without making it a poset. At this >>> point in time, parsimony says that you want to ditch your multiposet >>> thingie (and God knows what else you want to tack in there to >>> preserve >>> other interesting curve properties) and really just want to define >>> the >>> curve as a freaking function and be done with it. >>> -- >> >> >> But certainly the image set does define the curve, if you want to >> view >> it that way -- all parameterizations of a curve should satisfy the >> same equation f(x, y) = 0. > > This sounds like you didn't read his post, or totally missed the > point. > > Say S is the set of (x,y) in the plane such that x^2 + y^2 = 1. > What's the "index", or "winding number", of that curve about the > origin? > > (Hint: The curve c defined by c(t) = (cos(t), sin(t)) for > 0 <= t <= 2pi has index 1 about the origin. The curve > d(t) = (cos(-t), sin(-t)) (0 <= t <= 2pi) has index -1. > The curve (cos(2t), sin(2t)) (same t) has index 2.) That is to say, the "winding number" is a property of both the curve and a parameterization of it. Or, in other words, the winding number is a property of a function from S1 to C. Charles Yeomans From garabik-news-2005-05 at kassiopeia.juls.savba.sk Mon Jun 22 17:11:26 2009 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Mon, 22 Jun 2009 21:11:26 +0000 (UTC) Subject: wikipedia with python References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> Message-ID: Andre Engels wrote: > On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >> Let me know if it's the right place to ask. >> >> I'm looking for wiki writen with python where I can import all >> wikipedia site. >> If you have any links please let me know. > > I don't think that's possible. If you wnat to import Wikipedia in a > wiki, it will probably have to be MediaWiki - and that's written in > PHP. > MoinMoin has a MediaWiki format parser (or two). Not 100% compatible, but good enough for some purposes. Templates will be a problem, though. -- ----------------------------------------------------------- | 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 cmpython at gmail.com Mon Jun 22 18:25:06 2009 From: cmpython at gmail.com (CM) Date: Mon, 22 Jun 2009 15:25:06 -0700 (PDT) Subject: launch a .py file from a batch file Message-ID: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> I'd like to launch a number of programs, one of which is a Python GUI app, from a batch file launcher. I'd like to click the .bat file and have it open all the stuff and then not show the "DOS" console. I can launch an Excel and Word file fine using, e.g.: Start "" "path/mydocument.doc" But if I try that with a Python file, like: Start "" "path/myPythonApp.py" It does nothing. The others open fine and no Python app. However, if I do this instead (where path = full pathname to Python file), cd path myPythonApp.py it will launch the Python app fine, but it will show the "DOS" console. How can I get it to launch a .py file and yet not show the console? Thanks, Che From 1x7y2z9 at gmail.com Mon Jun 22 18:35:28 2009 From: 1x7y2z9 at gmail.com (1x7y2z9) Date: Mon, 22 Jun 2009 15:35:28 -0700 (PDT) Subject: re.NONE Message-ID: I am currently using python v2.5.2. Not sure if this is defined in a later version, but it would be nice to define re.NONE = 0 in the re module. This would be useful in cases such as: flags = re.DOTALL if dotall else re.NONE Also useful for "building up" flags by ORing with other flags. Thanks. From clp2 at rebertia.com Mon Jun 22 18:51:13 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 15:51:13 -0700 Subject: How to output a complex List object to a file. In-Reply-To: References: Message-ID: <50697b2c0906221551y637aee15g7ae563360c9ce18@mail.gmail.com> On Mon, Jun 22, 2009 at 6:17 AM, Jim Qiu wrote: > Hi all, > > I have a object list list this: > I need to output this "structure" object into a file, how to do that ? Links for the modules mentioned: http://docs.python.org/library/pickle.html http://docs.python.org/library/json.html Cheers, Chris -- http://blog.rebertia.com From peter at www.pjb.com.au Mon Jun 22 18:52:29 2009 From: peter at www.pjb.com.au (Peter Billam) Date: 22 Jun 2009 22:52:29 GMT Subject: Idioms and Anti-Idioms Question References: Message-ID: On 2009-06-22, Lie Ryan wrote: > Ben Charrow wrote: >> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ >> + calculate_number(10, 20)*forbulate(500, 360) >> What is subtly wrong about this piece of code? I can't see any bugs and >> can't think of subtle gotchas (e.g. the '\' is removed or the lines >> become separated, because in both cases an IndentationError would be >> raised). > > The preferred style is to put the binary operators before the line-break > (i.e. the line break is after the operators): > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ > calculate_number(10, 20)*forbulate(500, 360) > ... > The following is an extract from PEP 8: > The preferred way of wrapping long lines is by using Python's > implied line continuation inside parentheses, brackets and braces. > If necessary, you can add an extra pair of parentheses around an > expression, but sometimes using a backslash looks better. Make sure to > indent the continued line appropriately. The preferred place to break > around a binary operator is *after* the operator, not before it. Damian Conway, in Perl Best Practices, puts forward a clear argument for breaking *before* the operator: Using an expression at the end of a statement gets too long, it's common practice to break that expression after an operator and then continue the expression on the following line ... The rationale is that the operator that remains at the end of the line acts like a continutation marker, indicating that the expression continues on the following line. Using the operator as a continutation marker seems like an excellent idea, but there's a serious problem with it: people rarely look at the right edge of code. Most of the semantic hints in a program - such as keywords - appear on the left side of that code. More importantly, the structural cues for understanding code - for example, indenting, - are predominantly on the left as well ... This means that indenting the continued lines of the expression actually gives a false impression of the underlying structure, a misperception that the eye must travel all the way to the right margin to correct. which seems to me well-argued. I wonder on what grounds PEP8 says "The preferred place to break around a binary operator is *after* the operator" ? Perhaps it's just the "continutation marker" rationale? Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From skip at pobox.com Mon Jun 22 19:09:06 2009 From: skip at pobox.com (skip at pobox.com) Date: Mon, 22 Jun 2009 18:09:06 -0500 Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: <19008.3858.487195.120433@montanaro.dyndns.org> Saurabh> I am looking for some open source python project preferably in Saurabh> one of the above areas (not strictly, am open to others too) to Saurabh> contribute. If you have some Windows programming experience the SpamBayes project (http://www.spambayes.org/) could use some assistance. We have been held up because our existing Windows experts have been too busy to contribute much for a couple years. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From python at bdurham.com Mon Jun 22 19:18:38 2009 From: python at bdurham.com (python at bdurham.com) Date: Mon, 22 Jun 2009 19:18:38 -0400 Subject: Open source python projects In-Reply-To: <19008.3858.487195.120433@montanaro.dyndns.org> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> <19008.3858.487195.120433@montanaro.dyndns.org> Message-ID: <1245712718.25211.1321657737@webmail.messagingengine.com> Saurabh, 1. The Dabo crew is doing some exciting thing. Might be worth checking out. http://dabodev.com 2. The Py2exe project is also looking for help (and some C experience would be beneficial to this project). http://py2exe.org 3. There's a bunch of encryption code floating around in native Python that would benefit from being recoded as native C modules. Welcome! Malcolm From davea at ieee.org Mon Jun 22 19:22:51 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 19:22:51 -0400 Subject: Procedures In-Reply-To: References: Message-ID: <4A40124B.70400@ieee.org> Greg Reyna wrote: >
Learning > Python (on a Mac), with the massive help of Mark Lutz's excellent > book, "Learning Python". > > What I want to do is this: > I've got a Class Object that begins with a def. It's designed to be > fed a string that looks like this: > > "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > > I'm parsing the string by finding the commas, and pulling out the data > between them. > No problem so far (I think...) The trouble is, there is a place where > code is repeated: > > 1. Resetting the start & end position and finding the next comma in > the string. > > In my previous experience (with a non-OOP language), I could create a > 'procedure', which was a separate function. With a call like: > var=CallProcedure(arg1,arg2) the flow control would go to the > procedure, run, then Return back to the main function. > > In Python, when I create a second def in the same file as the first it > receives a "undefined" error. I can't figure out how to deal with > this. How do I set it up to have my function #1 call my function #2, > and return? > > The only programming experience I've had where I pretty much knew what > I was doing was with ARexx on the Amiga, a language much like Python > without the OOP part. ARexx had a single-step debugger as part of the > language installation. I've always depended on a debugger to help me > understand what I'm doing (eg Script Debugger for Apple Script--not > that I understand Apple Script) Python's debug system is largely > confusing to me, but of course I'll keep at it. I would love to see a > step-by-step debugging tutorial designed for someone like me who > usually wants to single-step through an entire script. > > Thanks for any help, > Greg Reyna > > You should post an example. Otherwise we can just make wild guesses. So for a wild guess, perhaps your question is how an instance method calls another instance method. But to put it briefly, a def inside a class definition does not create a name at global scope, but instead defines a method of that class. Normally, you have to use an object of that class as a prefix to call such a function (with the exception of __init__() for one example). class A(object): def func1(self, parm1, parm2): do some work self.func2(arg1) do some more work def func2(self, parm1): do some common work q = A() q.func1("data1", "data2") Here we use q.func1() to call the func1 method on the q instance of the class. We could also call q.func2() similarly. But I think you may have been asking about func1 calling func2. Notice the use of self.func2(). Self refers to the object of the method we're already in. From noname at nowhere.com Mon Jun 22 19:29:24 2009 From: noname at nowhere.com (Pegasus) Date: Tue, 23 Jun 2009 01:29:24 +0200 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: <4a40141d$0$47541$4fafbaef@reader1.news.tin.it> ndPython for Nanodesktop http://www.psp-ita.com/forum/viewtopic.php?t=28323 It shall be the most advanced, professional, reliable Python interpreter for Playstation Portable but there is actually a lack of performance and we are working to identify the origin of the problem. We need help. From noname at nowhere.com Mon Jun 22 19:32:54 2009 From: noname at nowhere.com (Pegasus) Date: Tue, 23 Jun 2009 01:32:54 +0200 Subject: Performance problem in ndPython 2.5.2. Why ? Message-ID: <4a4014d5$0$47539$4fafbaef@reader1.news.tin.it> Hi, I'm working on a version of Stackless Python (2.5.2) for Nanodesktop PSP. The interpreter works, but it is slow. So, I want to ask this: is there any option/#define that I can pass to pyconfig.h that makes faster the interpreter ? Which are the #define that affect the performance of Stackless Python ? Perhaps there is some library that I must include in the interpreter to obtain a boost of performance ? From milesck at umich.edu Mon Jun 22 19:34:40 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Mon, 22 Jun 2009 19:34:40 -0400 Subject: Idioms and Anti-Idioms Question In-Reply-To: <4A3F053A.10208@csail.mit.edu> References: <4A3F053A.10208@csail.mit.edu> Message-ID: On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote: > What is subtly wrong about this piece of code? I can't see any bugs > and can't think of subtle gotchas (e.g. the '\' is removed or the > lines become separated, because in both cases an IndentationError > would be raised). Perhaps, along with one of those gotchas, a mix of tabs and spaces are used such that the second line only _appears_ to have a different level of indentation? ;) -Miles From alan.isaac at gmail.com Mon Jun 22 19:35:20 2009 From: alan.isaac at gmail.com (Alan G Isaac) Date: Mon, 22 Jun 2009 23:35:20 GMT Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: On 6/22/2009 3:40 PM saurabh apparently wrote: > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. A one off project ... If you can help figure out how to produce a Windows installer of SimpleParse for Python 2.6 and post your experience here, I believe quite a few projects would profit, not to mention the SimpleParse users themselves. Cheers, Alan Isaac From python at mrabarnett.plus.com Mon Jun 22 19:43:06 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2009 00:43:06 +0100 Subject: re.NONE In-Reply-To: References: Message-ID: <4A40170A.9030101@mrabarnett.plus.com> 1x7y2z9 wrote: > I am currently using python v2.5.2. > > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. This would be useful in cases > such as: > flags = re.DOTALL if dotall else re.NONE > > Also useful for "building up" flags by ORing with other flags. > > Thanks. Just use 0. If you want it added then try requesting it at: http://bugs.python.org/ although it might be best to first gauge how much support you have for the suggestion. From contact at xavierho.com Mon Jun 22 19:47:49 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 23 Jun 2009 09:47:49 +1000 Subject: re.NONE In-Reply-To: <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> Message-ID: <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> (arg, MRAB, sorry, wrong address!) Defining None to 0 is a bad idea. You'll have trouble debugging later on. 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, Jun 23, 2009 at 9:43 AM, MRAB wrote: > 1x7y2z9 wrote: > >> I am currently using python v2.5.2. >> >> Not sure if this is defined in a later version, but it would be nice >> to define re.NONE = 0 in the re module. This would be useful in cases >> such as: >> flags = re.DOTALL if dotall else re.NONE >> >> Also useful for "building up" flags by ORing with other flags. >> >> Thanks. >> > > Just use 0. > > If you want it added then try requesting it at: > > http://bugs.python.org/ > > although it might be best to first gauge how much support you have for > the suggestion. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Mon Jun 22 19:55:28 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 23 Jun 2009 00:55:28 +0100 Subject: re.NONE In-Reply-To: <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> Message-ID: Re-ordered to eliminate the top-posting. On Tue, 23 Jun 2009 00:47:49 +0100, Xavier Ho wrote: > On Tue, Jun 23, 2009 at 9:43 AM, MRAB wrote: > >> 1x7y2z9 wrote: >> >>> I am currently using python v2.5.2. >>> >>> Not sure if this is defined in a later version, but it would be nice >>> to define re.NONE = 0 in the re module. This would be useful in cases >>> such as: >>> flags = re.DOTALL if dotall else re.NONE >>> >>> Also useful for "building up" flags by ORing with other flags. >>> >>> Thanks. >>> >> >> Just use 0. >> >> If you want it added then try requesting it at: >> >> http://bugs.python.org/ >> >> although it might be best to first gauge how much support you have for >> the suggestion. >> > (arg, MRAB, sorry, wrong address!) > > Defining None to 0 is a bad idea. You'll have trouble debugging later on. They aren't talking about None, they're talking about a hypothetical re.NONE to use as a flag to re.match() and the like. There's no issue with defining that to be 0, since it is the correct value! -- Rhodri James *-* Wildebeest Herder to the Masses From contact at xavierho.com Mon Jun 22 20:01:30 2009 From: contact at xavierho.com (Xavier Ho) Date: Tue, 23 Jun 2009 10:01:30 +1000 Subject: re.NONE In-Reply-To: <2d56febf0906221700p7f8936d7u3c273534b0352772@mail.gmail.com> References: <4A40170A.9030101@mrabarnett.plus.com> <2d56febf0906221647x19b46886u641cc1504b9ff6aa@mail.gmail.com> <2d56febf0906221647u20cf90dbga663602558fe5097@mail.gmail.com> <2d56febf0906221700p7f8936d7u3c273534b0352772@mail.gmail.com> Message-ID: <2d56febf0906221701g77d9d8dbh3d110131d13b1888@mail.gmail.com> Rhodri wrote: They aren't talking about None, they're talking about a hypothetical re.NONE to use as a flag to re.match() and the like. There's no issue with defining that to be 0, since it is the correct value! Ah, I see. That makes more sense. Thanks. :] (... I fail at sending to mailing list for some reason. What happend to the reply-to request? =/) 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 davea at ieee.org Mon Jun 22 20:04:39 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 22 Jun 2009 20:04:39 -0400 Subject: launch a .py file from a batch file In-Reply-To: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> Message-ID: <4A401C17.4050903@ieee.org> CM wrote: > I'd like to launch a number of programs, one of which is a Python GUI > app, from a batch file launcher. I'd like to click the .bat file and > have it open all the stuff and then not show the "DOS" console. > > I can launch an Excel and Word file fine using, e.g.: > Start "" "path/mydocument.doc" > > But if I try that with a Python file, like: > Start "" "path/myPythonApp.py" > > It does nothing. The others open fine and no Python app. > > However, if I do this instead (where path = full pathname to Python > file), > cd path > myPythonApp.py > > it will launch the Python app fine, but it will show the "DOS" > console. > > How can I get it to launch a .py file and yet not show the console? > > Thanks, > Che > > Assuming you're running on Windows XP, try the following line in your batch file: @start path\MyPythonApp.pyw That's of course after you rename your script to a pyw extension. That's associated with pythonw, which doesn't need a command window. Your batch file itself will still display a cmd window while it's running, but it'll finish quickly. This is the same as when using one to start a spreadsheet or whatever. If you cannot change the extension to the correct pyw extension, then try specifying the interpreter explicitly in the start line: @start c:\python26\pythonw.exe path\MyPythonApp.py You may need quotes in either of these cases, if you managed to include spaces in your pathnames. From ldo at geek-central.gen.new_zealand Mon Jun 22 20:56:11 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 12:56:11 +1200 Subject: re.NONE References: Message-ID: In message , 1x7y2z9 wrote: > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. Do so: re.NONE = 0 Problem solved. From bluefisher80 at gmail.com Mon Jun 22 21:38:51 2009 From: bluefisher80 at gmail.com (=?utf-8?B?Ymx1ZWZpc2hlcjgw?=) Date: Tue, 23 Jun 2009 09:38:51 +0800 Subject: =?utf-8?B?UmU6IFJlOiBIb3cgdG8gb3V0cHV0IGEgY29tcGxleCBMaXN0IG9iamVjdCB0byBhIGZpbGUu?= References: , <50697b2c0906221551y637aee15g7ae563360c9ce18@mail.gmail.com> Message-ID: <200906230938498438339@gmail.com> Let me get my question more clear, I want like the "structure" object printed into another python source file, which i will use in other program. The pickled format or even JSONed format does not fullfil my requirement, does it? Do i make it clear, I still need your guides. Jim Detail step: # #this object is constructed in A.py structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] ## #Then I need some code to output the exactly same structure= [ {ID:'UNH',MIN:1,MAX:1,LEVEL:[ {ID:'BGM',MIN:1,MAX:1}, {ID:'DTM',MIN:1,MAX:5}, {ID:'NAD',MIN:1,MAX:5,LEVEL:[ {ID:'CTA',MIN:0,MAX:5,LEVEL:[ {ID:'COM',MIN:0,MAX:5}, ]}, ]}, {ID:'RFF',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'CUX',MIN:0,MAX:5,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, ]}, {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ {ID:'DTM',MIN:0,MAX:5}, {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ {ID:'PIA',MIN:0,MAX:5}, {ID:'IMD',MIN:0,MAX:5}, {ID:'RFF',MIN:0,MAX:5}, {ID:'ALI',MIN:0,MAX:5}, {ID:'MOA',MIN:0,MAX:5}, {ID:'PRI',MIN:0,MAX:5}, {ID:'QTY',MIN:0,MAX:999,LEVEL:[ {ID:'NAD',MIN:0,MAX:1}, ]}, ]}, ]}, {ID:'UNT',MIN:1,MAX:1}, ] } ] # Into second file B.py B.py will be a file of another application. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluefisher80 at gmail.com Mon Jun 22 21:51:54 2009 From: bluefisher80 at gmail.com (bluefisher80) Date: Tue, 23 Jun 2009 09:51:54 +0800 Subject: How to output a complex List object to a file. References: , <1245680239.22057.25.camel@aalcdl07> Message-ID: <200906230951525317160@gmail.com> Actually I think i am just looking for print >> myFile.py, myListObj 2009-06-23 bluefisher80 ???? J. Cliff Dyer ????? 2009-06-22 22:17:12 ???? Jim Qiu ??? python-list ??? Re: How to output a complex List object to a file. Have you looked at the JSON module? On Mon, 2009-06-22 at 21:17 +0800, Jim Qiu wrote: > Hi all, > > I have a object list list this: > > from bots.botsconfig import * > from D96Arecords import recorddefs > from edifactsyntax3 import syntax > > structure= [ > {ID:'UNH',MIN:1,MAX:1,LEVEL:[ > {ID:'BGM',MIN:1,MAX:1}, > {ID:'DTM',MIN:1,MAX:5}, > {ID:'NAD',MIN:1,MAX:5,LEVEL:[ > {ID:'CTA',MIN:0,MAX:5,LEVEL:[ > {ID:'COM',MIN:0,MAX:5}, > ]}, > ]}, > {ID:'RFF',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'CUX',MIN:0,MAX:5,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > ]}, > {ID:'LOC',MIN:1,MAX:200000,LEVEL:[ > {ID:'DTM',MIN:0,MAX:5}, > {ID:'LIN',MIN:0,MAX:200000,LEVEL:[ > {ID:'PIA',MIN:0,MAX:5}, > {ID:'IMD',MIN:0,MAX:5}, > {ID:'RFF',MIN:0,MAX:5}, > {ID:'ALI',MIN:0,MAX:5}, > {ID:'MOA',MIN:0,MAX:5}, > {ID:'PRI',MIN:0,MAX:5}, > {ID:'QTY',MIN:0,MAX:999,LEVEL:[ > {ID:'NAD',MIN:0,MAX:1}, > ]}, > ]}, > ]}, > {ID:'UNT',MIN:1,MAX:1}, > ] > } > ] > > I need to output this "structure" object into a file, how to do that ? > > Jim > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jun 22 21:55:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 18:55:41 -0700 Subject: How to output a complex List object to a file. In-Reply-To: <200906230951525317160@gmail.com> References: <1245680239.22057.25.camel@aalcdl07> <200906230951525317160@gmail.com> Message-ID: <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> 2009/6/22 bluefisher80 : > > Actually I think i am just looking for > > print >> myFile.py, myListObj Well, that syntax is deprecated. And you'd have to create the actual file object. And put it in a variable. So it's more like: f = file("myFile.py", "w") f.write(str(myListObj)) f.close() However, the fact that you want to do this suggests a code smell. Why do you need to do this in the first place? Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Mon Jun 22 22:11:49 2009 From: cmpython at gmail.com (C M) Date: Mon, 22 Jun 2009 22:11:49 -0400 Subject: launch a .py file from a batch file In-Reply-To: <4A401C17.4050903@ieee.org> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: On Mon, Jun 22, 2009 at 8:04 PM, Dave Angel wrote: > CM wrote: > >> I'd like to launch a number of programs, one of which is a Python GUI >> app, from a batch file launcher. I'd like to click the .bat file and >> have it open all the stuff and then not show the "DOS" console. >> >> I can launch an Excel and Word file fine using, e.g.: >> Start "" "path/mydocument.doc" >> >> But if I try that with a Python file, like: >> Start "" "path/myPythonApp.py" >> >> It does nothing. The others open fine and no Python app. >> >> However, if I do this instead (where path = full pathname to Python >> file), >> cd path >> myPythonApp.py >> >> it will launch the Python app fine, but it will show the "DOS" >> console. >> >> How can I get it to launch a .py file and yet not show the console? >> >> Thanks, >> Che >> >> >> > Assuming you're running on Windows XP, try the following line in your batch > file: > @start path\MyPythonApp.pyw > > That's of course after you rename your script to a pyw extension. That's > associated with pythonw, which doesn't need a command window. > Well, I renamed my script to have a .pyw extension, and then ran the line above. Without quotes, it doesn't find it (because I have spaces in the path). With quotes it just opens a console and does nothing (does not launch the app). Any ideas? Thanks. Che > > Your batch file itself will still display a cmd window while it's running, > but it'll finish quickly. This is the same as when using one to start a > spreadsheet or whatever. > > If you cannot change the extension to the correct pyw extension, then try > specifying the interpreter explicitly in the start line: > > @start c:\python26\pythonw.exe path\MyPythonApp.py > > You may need quotes in either of these cases, if you managed to include > spaces in your pathnames. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluefisher80 at gmail.com Mon Jun 22 22:31:45 2009 From: bluefisher80 at gmail.com (=?utf-8?B?Ymx1ZWZpc2hlcjgw?=) Date: Tue, 23 Jun 2009 10:31:45 +0800 Subject: =?utf-8?B?UmU6IFJlOiBSZTogSG93IHRvIG91dHB1dCBhIGNvbXBsZXggTGlzdCBvYmplY3QgdG8gYSBmaWxlLg==?= References: , <1245680239.22057.25.camel@aalcdl07>, <200906230951525317160@gmail.com>, <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> Message-ID: <200906231031415155616@gmail.com> Hi Thanks for you tip, I am generating some code for another python application, so is there a better way for code generating? Actually i just need to generate some list objects to define EDI syntax using python. 2009-06-23 bluefisher80 ???? Chris Rebert ????? 2009-06-23 09:55:41 ???? bluefisher80 ??? J. Cliff Dyer; python-list ??? Re: Re: How to output a complex List object to a file. 2009/6/22 bluefisher80 : > > Actually I think i am just looking for > > print >> myFile.py, myListObj Well, that syntax is deprecated. And you'd have to create the actual file object. And put it in a variable. So it's more like: f = file("myFile.py", "w") f.write(str(myListObj)) f.close() However, the fact that you want to do this suggests a code smell. Why do you need to do this in the first place? Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From Andras.Pikler at students.olin.edu Mon Jun 22 22:49:48 2009 From: Andras.Pikler at students.olin.edu (Andras Pikler) Date: Mon, 22 Jun 2009 22:49:48 -0400 Subject: Converting Python code to C/C++ Message-ID: Hi! Short: I need to turn a Python program that I (mostly) wrote into C code, and I am at a loss. Long: I'm doing research/programming for a professor, and we are working with MIDI files (a type of simple music file). The research deals with generating variations from a musical melody; currently, my Python code uses a Python midi package I found online to read the notes in question from a midi file, about 350 lines of my own code to generate a variation based on these notes and the professor's algorithms, and finally the package again to write the new melody to another midi file. Now, my professor would like to have this exact code in C/C++, as she believes C is more compatible with MATLAB, and wants the code to be available in multiple languages in case a programmer works for her in the future who knows C but not Python. While I know a tiny bit of C (emphasis on the tiny), I would much prefer if there were some sort of automatic compiler I could use to turn my Python code into C than taking a week or two or three to learn the minimum I need about C, find a way to access MIDI files in it, and rewrite all of my code. After some googling, I found and tried Shedskin, but it doesn't work, as the Python midi package I'm using uses modules which Shedskin does not support. Otherwise, I haven't found much. Is there anything out there to help me do this? If not, from anyone who has experience in this regard, how daunting should I expect this to be? Any help is appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 22:52:59 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Jun 2009 02:52:59 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > In my universe the standard definition of "log" is different froim what > log means in a calculus class Now I'm curious what the difference is. -- Steven From jfabiani at yolo.com Mon Jun 22 22:56:54 2009 From: jfabiani at yolo.com (John Fabiani) Date: Mon, 22 Jun 2009 19:56:54 -0700 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> <19008.3858.487195.120433@montanaro.dyndns.org> Message-ID: python at bdurham.com wrote: > Saurabh, > > 1. The Dabo crew is doing some exciting thing. Might be worth checking > out. > http://dabodev.com yes Dabo is doing a lot these days. Using wxPython for the GUI, a fast interface for data supporting SQLite, MySQL,Postgres, Firebird, MsSQL and Now a web like program that supports the code from Dabo projects over the web. The report writer has had many improvements recently. People from everywhere are joining in - very cool. From magawake at gmail.com Mon Jun 22 23:17:22 2009 From: magawake at gmail.com (Mag Gam) Date: Mon, 22 Jun 2009 23:17:22 -0400 Subject: Reading a large csv file Message-ID: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Hello All, I have a very large csv file 14G and I am planning to move all of my data to hdf5. I am using h5py to load the data. The biggest problem I am having is, I am putting the entire file into memory and then creating a dataset from it. This is very inefficient and it takes over 4 hours to create the hdf5 file. The csv file has various types: int4, int4, str, str, str, str, str I was wondering if anyone knows of any techniques to load this file faster? TIA From steven at REMOVE.THIS.cybersource.com.au Mon Jun 22 23:42:29 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Jun 2009 03:42:29 GMT Subject: Reading a large csv file References: Message-ID: On Mon, 22 Jun 2009 23:17:22 -0400, Mag Gam wrote: > Hello All, > > I have a very large csv file 14G and I am planning to move all of my > data to hdf5. [...] > I was wondering if anyone knows of any techniques to load this file > faster? Faster than what? What are you using to load the file? -- Steven From clp2 at rebertia.com Tue Jun 23 00:17:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Jun 2009 21:17:37 -0700 Subject: How to output a complex List object to a file. In-Reply-To: <200906231031415155616@gmail.com> References: <1245680239.22057.25.camel@aalcdl07> <200906230951525317160@gmail.com> <50697b2c0906221855p1dee85a2sc844b385b034eacd@mail.gmail.com> <200906231031415155616@gmail.com> Message-ID: <50697b2c0906222117u1cc4ab31g42c17f629f6840ee@mail.gmail.com> On Mon, Jun 22, 2009 at 7:31 PM, bluefisher80 wrote: > Hi > > Thanks for you tip, > > I am generating some code for another python?application, > > so is there a better way for code generating? Actually i just need to > generate some list objects to define EDI syntax using python. Well, I would say avoid having to generate code in the first place, but if it's unavoidable, then that's essentially how you'd do it. Cheers, Chris -- http://blog.rebertia.com From metolone+gmane at gmail.com Tue Jun 23 00:21:24 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Mon, 22 Jun 2009 21:21:24 -0700 Subject: UnicodeDecodeError: problem when path contain folder start withcharacter 'u References: <24146775.post@talk.nabble.com> Message-ID: "aberry" wrote in message news:24146775.post at talk.nabble.com... > > I am facing an error on Unicode decoding of path if it contain a > folder/file > name starting with character 'u' . > > Here is what I did in IDLE > 1. >>> fp = "C:\\ab\\anil" > 2. >>> unicode(fp, "unicode_escape") > 3. u'C:\x07b\x07nil' > 4. >>> fp = "C:\\ab\\unil" > 5. >>> unicode(fp, "unicode_escape") > 6. > 7. Traceback (most recent call last): > 8. File "", line 1, in > 9. unicode(fp, "unicode_escape") > 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in > position > 5-9: end of string in escape sequence > 11. >>> > > Not sure whether I am doing something wrong or this is as designed > behavior > . > any help appreciated What is your intent? Below gives a unicode strings with backslashes. No need for unicode_escape here. >>> fp = "C:\\ab\\unil" >>> fp 'C:\\ab\\unil' >>> print fp C:\ab\unil >>> unicode(fp) u'C:\\ab\\unil' >>> print unicode(fp) C:\ab\unil >>> u'C:\\ab\\unil' u'C:\\ab\\unil' >>> print u'C:\\ab\\unil' C:\ab\unil From tkjthingone at gmail.com Tue Jun 23 00:28:05 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Mon, 22 Jun 2009 21:28:05 -0700 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: Do you even HAVE 14 gigs of memory? I can imagine that if the OS needs to start writing to the page file, things are going to slow down. -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at al.com.au Tue Jun 23 01:16:41 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 23 Jun 2009 15:16:41 +1000 Subject: square box graph (?) API in python Message-ID: <4A406539.1060904@al.com.au> Hi, I'm trying to graph something that looks like the bottom half of this http://windirstat.info/images/windirstat.jpg I was wondering if there is any API in python or wxPython specifically to do this? I know it is possible to do calculation manually and use floatcanvas or something similar but I was wondering if something like this has already been done. Cheers Astan From astan.chee at al.com.au Tue Jun 23 01:19:12 2009 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 23 Jun 2009 15:19:12 +1000 Subject: square box graph (?) API in python In-Reply-To: <4A406539.1060904@al.com.au> References: <4A406539.1060904@al.com.au> Message-ID: <4A4065D0.2040406@al.com.au> Hi, I'm trying to graph something that looks like the bottom half of this http://windirstat.info/images/windirstat.jpg I was wondering if there is any API in python or wxPython specifically to do this? I know it is possible to do calculation manually and use floatcanvas or something similar but I was wondering if something like this has already been done. Cheers Astan From magawake at gmail.com Tue Jun 23 01:27:03 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 23 Jun 2009 01:27:03 -0400 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Yes, the system has 64Gig of physical memory. What I meant was, is it possible to load to a hdf5 dataformat (basically NumPy array) without reading the entire file at first? I would like to splay to disk beforehand so it would be a bit faster instead of having 2 copies in memory. On Tue, Jun 23, 2009 at 12:28 AM, Horace Blegg wrote: > Do you even HAVE 14 gigs of memory? I can imagine that if the OS needs to > start writing to the page file, things are going to slow down. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From __peter__ at web.de Tue Jun 23 02:47:43 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Jun 2009 08:47:43 +0200 Subject: Reading a large csv file References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: Mag Gam wrote: > Yes, the system has 64Gig of physical memory. > > > What I meant was, is it possible to load to a hdf5 dataformat > (basically NumPy array) without reading the entire file at first? I > would like to splay to disk beforehand so it would be a bit faster > instead of having 2 copies in memory. It is certainly possible to read a csv file one line at a time. What exactly are you doing to convert it into hdf5? Showing some of your code might help. Peter From tjreedy at udel.edu Tue Jun 23 03:09:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Jun 2009 03:09:58 -0400 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Message-ID: Mag Gam wrote: > Yes, the system has 64Gig of physical memory. drool ;-). > What I meant was, is it possible to load to a hdf5 dataformat > (basically NumPy array) without reading the entire file at first? I > would like to splay to disk beforehand so it would be a bit faster > instead of having 2 copies in memory. If you can write hdf5 a line at a time, you should be able to something like for line in cvs: process line write hdf5 line this assumes 1-1 lines. From dickinsm at gmail.com Tue Jun 23 03:19:50 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 23 Jun 2009 00:19:50 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 23, 3:52?am, Steven D'Aprano wrote: > On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > > In my universe the standard definition of "log" is different froim what > > log means in a calculus class > > Now I'm curious what the difference is. It's just the usual argument about whether 'log' means log base 10 or log base e (natural log). At least in the US, most[*] calculus texts (and also most calculators), for reasons best known to themselves, use 'ln' to mean natural log and 'log' to mean log base 10. But most mathematicians use 'log' to mean natural log: pick up a random pure mathematics research paper that has the word 'log' in it, and unless it's otherwise qualified, it's safe to assume that it means log base e. (Except in the context of algorithmic complexity, where it might well mean log base 2 instead...) Python also suffers a bit from this confusion: the Decimal class defines methods 'ln' and 'log10', while the math module and cmath modules define 'log' and 'log10'. (But the Decimal module has other problems, like claiming that 0**0 is undefined while infinity**0 is 1.) [*] A notable exception is Michael Spivak's 'Calculus', which also happens to be the book I learnt calculus from many years ago. Mark From eric.brunel at nospam-pragmadev.com Tue Jun 23 03:50:07 2009 From: eric.brunel at nospam-pragmadev.com (Eric Brunel) Date: 23 Jun 2009 07:50:07 GMT Subject: GNUstep and Python References: <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <7a7l9kF1tv7viU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Paul Watson schrieb: >> Has anyone used GNUstep? >> >> In addition to Objective-C, there are Java and Ruby bindings. >> >> Has anyone created a Python binding to GNUstep? > > There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. Apparently, it's not: There was some compatibility in earlier versions, but it's been officially removed in version 2.0. See http://pyobjc.sourceforge.net/NEWS-2.0.html : "GNUstep support has been removed because this has never worked properly, nobody seems interested in fixing that and the internal APIs of PyObjC have changed greatly." I'd love to see that happen, but GNUStep seems to be disappearing little by little. Too bad... From michael at stroeder.com Tue Jun 23 04:59:55 2009 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Tue, 23 Jun 2009 10:59:55 +0200 Subject: Open source python projects In-Reply-To: <4a3fde13$0$48239$14726298@news.sunsite.dk> References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: saurabh wrote: > I am an experienced C programmer and recently dived into python, > I have developed an instant love for it. > I have been doing some routine scripting for day to day admin tasks,also > have done some Tkinter and socket programming using python. > > I am looking for some open source python project preferably in one of > the above areas (not strictly, am open to others too) to contribute. > > Please give me any pointers to some python project which needs a > contributor. I'm sure there are many projects which could need a helping hand. But instead of pointing you to a specific project I'd rather recommend that you contribute to projects you're using for your own daily work. Why? Because you simply know what's really needed if you deploy a software yourself. Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com From p.f.moore at gmail.com Tue Jun 23 05:30:25 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 23 Jun 2009 10:30:25 +0100 Subject: launch a .py file from a batch file In-Reply-To: References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> 2009/6/23 C M : >> Assuming you're running on Windows XP, try the following line in your >> batch file: >> @start path\MyPythonApp.pyw >> >> That's of course after you rename your script to a pyw extension. ?That's >> associated with pythonw, which doesn't need a command window. > > Well, I renamed my script to have a .pyw extension, and then ran the line > above.? Without quotes, it doesn't find it (because I have spaces in the > path). > With quotes it just opens a console and does nothing (does not launch the > app). > > Any ideas? Use @start "" "path\MyPythonApp.pyw" The first item in quotes is the window title. If you only include the path (in quotes) it's taken as a title, which is why you need the second set of quotes. Paul. From girish.cfc at gmail.com Tue Jun 23 06:45:59 2009 From: girish.cfc at gmail.com (Girish) Date: Tue, 23 Jun 2009 03:45:59 -0700 (PDT) Subject: Error in reg dll References: <3026f219-4ecf-4db0-978c-f90094725903@y6g2000prf.googlegroups.com> Message-ID: <3b719cd0-5487-4711-b3ee-a148900f2683@d25g2000prn.googlegroups.com> Hi, somehow I fixed the issue related to error code 0xc0000005. Now I am getting a different error code while registering DLL.. it says: "DllRegisrerServer in Dspacvce.dll Failed. Reyurn Code was: 0x80040201" On Jun 20, 8:15?am, "Gabriel Genellina" wrote: > En Tue, 16 Jun 2009 02:09:57 -0300,Girish escribi?: > > > I am not able to registerDLLgenerated from py2exe > > When I try to register thedllusing the commant: regsve32 dspace.dll, > > I am getting error saying :"DLLRegisterServer in dspace.dllfailed. > > Return code was: 0xc0000005" > > I don't think the problem is in your setup.py, but on Dspace.py or any ? > module it uses. 0xc0000005 is an Access Violation - an attempt to ? > read/write memory at an illegal address. > Try removing pieces from Dspace.py until you find the culprit. > > -- > Gabriel Genellina From bieffe62 at gmail.com Tue Jun 23 06:59:32 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 03:59:32 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? Message-ID: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Hi all, is there any site that reports the current porting (to Python 3.x) status of the main non-standard extension modules (such as pygtk, pywin32, wxpython, ...) ? I think such information would be very useful for people - like me - which are tryiing to decide how/when/if to port existing scripts/ applications to the new python, or also which python to use to start a new program. I searched and googled for this information but without finding anything. It looks to me that also the single extension module sites are quite shy at announcing plans for the porting (I understand that in part this is for the "is ready when is ready" philosophy of many non-large open software projects). Ciao ----- FB From ldo at geek-central.gen.new_zealand Tue Jun 23 07:16:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Jun 2009 23:16:42 +1200 Subject: Idioms and Anti-Idioms Question References: Message-ID: In message , Peter Billam wrote: > Damian Conway, in Perl Best Practices, puts forward a clear argument > for breaking *before* the operator: Except in JavaScript, where you have no choice. From aberry at aol.in Tue Jun 23 07:32:08 2009 From: aberry at aol.in (aberry) Date: Tue, 23 Jun 2009 04:32:08 -0700 (PDT) Subject: UnicodeDecodeError: problem when path contain folder start withcharacter 'u In-Reply-To: References: <24146775.post@talk.nabble.com> Message-ID: <24164207.post@talk.nabble.com> thanks all for help... actually this was in old code having 'unicode_escape' . i hope it was there to handle path which may contain localized chars... but removing unicode_escape' it worked fine... :) rgds, aberry Mark Tolonen-3 wrote: > > > "aberry" wrote in message > news:24146775.post at talk.nabble.com... >> >> I am facing an error on Unicode decoding of path if it contain a >> folder/file >> name starting with character 'u' . >> >> Here is what I did in IDLE >> 1. >>> fp = "C:\\ab\\anil" >> 2. >>> unicode(fp, "unicode_escape") >> 3. u'C:\x07b\x07nil' >> 4. >>> fp = "C:\\ab\\unil" >> 5. >>> unicode(fp, "unicode_escape") >> 6. >> 7. Traceback (most recent call last): >> 8. File "", line 1, in >> 9. unicode(fp, "unicode_escape") >> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in >> position >> 5-9: end of string in escape sequence >> 11. >>> >> >> Not sure whether I am doing something wrong or this is as designed >> behavior >> . >> any help appreciated > > What is your intent? Below gives a unicode strings with backslashes. No > need for unicode_escape here. > >>>> fp = "C:\\ab\\unil" >>>> fp > 'C:\\ab\\unil' >>>> print fp > C:\ab\unil >>>> unicode(fp) > u'C:\\ab\\unil' >>>> print unicode(fp) > C:\ab\unil >>>> u'C:\\ab\\unil' > u'C:\\ab\\unil' >>>> print u'C:\\ab\\unil' > C:\ab\unil > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24164207.html Sent from the Python - python-list mailing list archive at Nabble.com. From stephane at harobed.org Tue Jun 23 07:47:42 2009 From: stephane at harobed.org (Klein =?iso-8859-1?q?St=E9phane?=) Date: Tue, 23 Jun 2009 11:47:42 +0000 (UTC) Subject: I look for private Python Index server on my local network... What do you use ? Message-ID: Hi, I wonder what Python Index server (like as pypi.python.org) do you use in your corporation for handle your private python eggs ? I found three solutions : * http://pypi.python.org/pypi/basketweaver/0.1.2-r6 * http://pypi.python.org/pypi/pypi/2005-08-01 * http://pypi.python.org/pypi/EggBasket/0.6.1b Do you know another software ? What do you use ? Thanks for your help, Stephane From jakecjacobson at gmail.com Tue Jun 23 09:17:41 2009 From: jakecjacobson at gmail.com (jakecjacobson) Date: Tue, 23 Jun 2009 06:17:41 -0700 (PDT) Subject: Authenticating to web service using https and client certificate Message-ID: <8ba5a3e5-a77f-43c5-ae9e-8e8c043bf804@n21g2000vba.googlegroups.com> Hi, I need to post some XML files to a web client that requires a client certificate to authenticate. I have some code that works on posting a multipart form over http but I need to modify it to pass the proper certificate and post the XML file. Is there any example code that will point me in the correct direction? Thanks for your help. From davea at ieee.org Tue Jun 23 09:21:01 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 23 Jun 2009 09:21:01 -0400 Subject: launch a .py file from a batch file In-Reply-To: <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> <79990c6b0906230230i29df175bne742ff29148cf8fe@mail.gmail.com> Message-ID: <4A40D6BD.1070002@ieee.org> Paul Moore wrote: > 2009/6/23 C M : > >>> Assuming you're running on Windows XP, try the following line in your >>> batch file: >>> @start path\MyPythonApp.pyw >>> >>> That's of course after you rename your script to a pyw extension. That's >>> associated with pythonw, which doesn't need a command window. >>> >> Well, I renamed my script to have a .pyw extension, and then ran the line >> above. Without quotes, it doesn't find it (because I have spaces in the >> path). >> With quotes it just opens a console and does nothing (does not launch the >> app). >> >> Any ideas? >> > > Use > > @start "" "path\MyPythonApp.pyw" > > The first item in quotes is the window title. If you only include the > path (in quotes) it's taken as a title, which is why you need the > second set of quotes. > > Paul. > > CM - Paul is right. If you have to use quotes, then you also need the extra argument to hold the "title" for the command window that won't be created. Stupid syntax on "Start.exe". I seldom hit that because I try not to put anything in a directory with spaces in it, like "Program Files" or "Documents and Settings" I have uncovered dozens of bugs in other people's programs over the years that were triggered by spaces in the pathname. It's not so bad now, but still can bite you. From rolf.wester at ilt.fraunhofer.de Tue Jun 23 09:51:48 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Tue, 23 Jun 2009 15:51:48 +0200 Subject: C-extension 2 times slower than exe Message-ID: <4a40ddee$1@news.fhg.de> Hi, I have a C++ program that I would like to steer using Python. I made the wrapper using swig and linked the code (without the main function) into a shared object. My Python script loads the extension and calls a function of the C-extension, the rest runs entirely within the C-extension. For comparison I compiled the code including the main function with the same compilation options and linked all into an exe. The main function of the exe calls the same function as my Python script does. Surprisingly the code in the Python C-extension runs twice as long as the same code in the exe. Does anyone know what could be the reason for this behaviour? Thank you in advance Rolf From philip at semanchuk.com Tue Jun 23 10:06:53 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 10:06:53 -0400 Subject: C-extension 2 times slower than exe In-Reply-To: <4a40ddee$1@news.fhg.de> References: <4a40ddee$1@news.fhg.de> Message-ID: On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > Hi, > > I have a C++ program that I would like to steer using Python. I made > the > wrapper using swig and linked the code (without the main function) > into > a shared object. My Python script loads the extension and calls a > function of the C-extension, the rest runs entirely within the > C-extension. For comparison I compiled the code including the main > function with the same compilation options and linked all into an exe. > The main function of the exe calls the same function as my Python > script > does. Surprisingly the code in the Python C-extension runs twice as > long > as the same code in the exe. Does anyone know what could be the reason > for this behaviour? If the runtime of the C/C++ code is short, the time spent initializing the Python interpreter might have a big impact on the runtime of the Python version. From rolf.wester at ilt.fraunhofer.de Tue Jun 23 10:20:44 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Tue, 23 Jun 2009 16:20:44 +0200 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> Message-ID: <4a40e4b6$1@news.fhg.de> Philip Semanchuk wrote: > > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > >> Hi, >> >> I have a C++ program that I would like to steer using Python. I made the >> wrapper using swig and linked the code (without the main function) into >> a shared object. My Python script loads the extension and calls a >> function of the C-extension, the rest runs entirely within the >> C-extension. For comparison I compiled the code including the main >> function with the same compilation options and linked all into an exe. >> The main function of the exe calls the same function as my Python script >> does. Surprisingly the code in the Python C-extension runs twice as long >> as the same code in the exe. Does anyone know what could be the reason >> for this behaviour? > > If the runtime of the C/C++ code is short, the time spent initializing > the Python interpreter might have a big impact on the runtime of the > Python version. > > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use the time command to measure the time consumed but I also measure the time within the C-code using clock() and get similar result. So the Python startup time is not the reason for the runtime difference I found. Thank you anyway. Rolf From metolone+gmane at gmail.com Tue Jun 23 10:27:41 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 23 Jun 2009 07:27:41 -0700 Subject: UnicodeDecodeError: problem when path contain folder startwithcharacter 'u References: <24146775.post@talk.nabble.com> <24164207.post@talk.nabble.com> Message-ID: "aberry" wrote in message news:24164207.post at talk.nabble.com... > Mark Tolonen-3 wrote: >> "aberry" wrote in message >> news:24146775.post at talk.nabble.com... >>> >>> I am facing an error on Unicode decoding of path if it contain a >>> folder/file >>> name starting with character 'u' . >>> >>> Here is what I did in IDLE >>> 1. >>> fp = "C:\\ab\\anil" >>> 2. >>> unicode(fp, "unicode_escape") >>> 3. u'C:\x07b\x07nil' >>> 4. >>> fp = "C:\\ab\\unil" >>> 5. >>> unicode(fp, "unicode_escape") >>> 6. >>> 7. Traceback (most recent call last): >>> 8. File "", line 1, in >>> 9. unicode(fp, "unicode_escape") >>> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in >>> position >>> 5-9: end of string in escape sequence >>> 11. >>> >>> >>> Not sure whether I am doing something wrong or this is as designed >>> behavior >>> . >>> any help appreciated >> >> What is your intent? Below gives a unicode strings with backslashes. No >> need for unicode_escape here. >> >>>>> fp = "C:\\ab\\unil" >>>>> fp >> 'C:\\ab\\unil' >>>>> print fp >> C:\ab\unil >>>>> unicode(fp) >> u'C:\\ab\\unil' >>>>> print unicode(fp) >> C:\ab\unil >>>>> u'C:\\ab\\unil' >> u'C:\\ab\\unil' >>>>> print u'C:\\ab\\unil' >> C:\ab\unil > > thanks all for help... > actually this was in old code having 'unicode_escape' . > i hope it was there to handle path which may contain localized chars... > > but removing unicode_escape' it worked fine... :) If that was the case, then here's a few other options: >>> print 'c:\\\\abc\\\\unil\\xe4'.decode('unicode_escape') c:\abc\unil? >>> print r'c:\\abc\\unil\xe4'.decode('unicode_escape') c:\abc\unil? >>> print u'c:\\abc\u005cunil\u00e4' c:\abc\unil? >>> print ur'c:\abc\u005cunil\u00e4' c:\abc\unil? You can also use forward slashes as another poster mentioned. If you want to display the filenames with the backslashes, os.path.normpath can be used: >>> print os.path.normpath('c:/abc/unil\u00e4'.decode('unicode_escape')) c:\abc\unil? Note you only have to jump through these hoops to generate hard-coded filenames with special characters. If they are already on disk, just read them in with something like os.listdir(u'.'), which generates a list of unicode filenames. -Mark From mwilson at the-wire.com Tue Jun 23 10:29:21 2009 From: mwilson at the-wire.com (Mel) Date: Tue, 23 Jun 2009 10:29:21 -0400 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Lawrence D'Oliveiro wrote: > >>> Ok, now pipe ls to less, take three days to browse through all the >>> filenames to locate the file you want to see. >> >> Sounds like you're approaching the issue with a GUI-centric mentality, >> which is completely hopeless at dealing with this sort of situation. > > Piping the output of ls to less is a GUI-centric mentality? Yeah. The "dump it on the user" idea, or more politely "can't decide anything until the user has seen everything" is evident in the most "characteristic" GUIs. Mel. From jeff at jmcneil.net Tue Jun 23 10:35:18 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 23 Jun 2009 07:35:18 -0700 (PDT) Subject: I look for private Python Index server on my local network... What do you use ? References: Message-ID: On Jun 23, 7:47?am, Klein St?phane wrote: > Hi, > > I wonder what Python Index server (like as pypi.python.org) do you use in > your corporation for handle your private python eggs ? > > I found three solutions : > > *http://pypi.python.org/pypi/basketweaver/0.1.2-r6 > *http://pypi.python.org/pypi/pypi/2005-08-01 > *http://pypi.python.org/pypi/EggBasket/0.6.1b > > Do you know another software ? What do you use ? > > Thanks for your help, > Stephane I've always just created a directory structure laid out by egg name and enabled directory indexing. I've never really had a need for anything more complex and this has always worked well for me. For example: [root at buildslave01 eggs]# pwd /var/www/html/eggs [root at buildslave01 eggs]# [root at buildslave01 eggs]# ls Beaker hostapi.logmgmt Paste SQLAlchemy zope.component [root at buildslave01 eggs]# [root at buildslave01 eggs]# ls Beaker/ Beaker-1.1.2-py2.4.egg Beaker-1.2.1-py2.4.egg [root at buildslave01 eggs]# On this particular system, buildbot drops successfully built eggs into the correct location automatically for testing purposes. HTH, Jeff From cameron.pulsford at gmail.com Tue Jun 23 10:45:33 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Tue, 23 Jun 2009 10:45:33 -0400 Subject: Help with dictionaries and multidimensial lists Message-ID: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Hey all, I have a dictionary that looks like this (small example version) {(1, 2): 0} named a so I can do a[1,2] which returns 0. What I also have is a list of coordinates into a 2 dimensional array that might look like this b = [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Tue Jun 23 10:47:54 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 07:47:54 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: <0f4625ea-5100-4772-8bbc-c28ef9f67565@k8g2000yqn.googlegroups.com> On 23 Giu, 12:59, Francesco Bochicchio wrote: > Hi all, > > is there any site that reports the current porting (to Python 3.x) > status of the main non-standard extension modules (such as pygtk, > pywin32, wxpython, ...) ? > I think such information would be very useful for people - like me - > which are tryiing to decide how/when/if to port existing scripts/ > applications to the new python, or also ?which python to use to start > a new program. > > I searched and googled for this information ?but without finding > anything. It looks to me that also the single extension module sites > are quite shy at announcing plans for the porting (I understand that > in part this is for the "is ready when is ready" philosophy of many > non-large open software projects). > > Ciao > ----- > FB Well, I kept searching and found this at least : http://www.daniweb.com/forums/thread165340.html It lists Qt , BeautfulSoup (with problems) and pywin32 (which I use a lot :-) Another (less famous) module that I use, ply, also supports python3.x Maybe in the near future I can start porting some of my scripts ... Still believe that a central point to keep track of most of extension porting effort would be very useful ... Ciao ---- FB From deets at nospam.web.de Tue Jun 23 10:54:28 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Jun 2009 16:54:28 +0200 Subject: [Mac] file copy References: Message-ID: <7ac8e0F1tludjU1@mid.uni-berlin.de> Tobias Weber wrote: > Hi, > which is the best way to copy files on OS X? I want to preserve resource > forks and extended attributes. Are these still relevant on OSX? I've always only copied files directly, and never had any troubles. Diez From jcd at sdf.lonestar.org Tue Jun 23 10:59:50 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 23 Jun 2009 10:59:50 -0400 Subject: Procedures In-Reply-To: References: <1245701011.2066.20.camel@aalcdl07> Message-ID: <1245769190.5086.28.camel@aalcdl07> Please keep the discussion on-list. (Reply-all, rather than just replying to me.) On Mon, 2009-06-22 at 15:36 -0700, Greg Reyna wrote: > It's not the error that concerned me. The fact that there is an > error of this type makes clear that there's something wrong with the > way the scripts are structured. I was trying to communicate that I > recognized this fact. Clearly, I was not successful. Thought I'd > try to save bandwidth, too. > ... > I had tried running this previously with only one Class header: > "LineReader", the others were just defs. I changed the short defs > into sub-classes out of desperation, since I don't understand why the > main script is not recognizing functions that are in the same file. > > First is the shell input/output, then "ParseWork.py", the entire text > file that contains the scripts. > > Thanks for your interest, Cliff, > Greg > --- > >>> import ParseWork > >>> avar = ParseWork.LineReader() > >>> xstring = 'scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4,' > >>> avar.parseLine(xstring) > Traceback (most recent call last): > File "", line 1, in > File "ParseWork.py", line 13, in parseLine > xreturn = advanceSearch(xstring) #shorten the part of string to > be searched > NameError: global name 'advanceSearch' is not defined > >>> > --- > class LineReader: > def parseLine(self, xstring): > global sc_info,scnum,pnlnum,prev_pos,cur_pos > sc_info = { 'sc':{0:0}} #dict to store scene num; pnl num(s), ftge > prev_pos = 0 > cur_pos = xstring.find(',') #defaults to length of string > while xstring.find(',',(prev_pos+1)) != -1: > temp = xstring[prev_pos:cur_pos] #pull out the part btwn commas > section = temp.strip() > if section[0:1] == 's': > scnum = int(section[5:]) #get the number(s) off the > end of scene block > sc_info['sc',scnum] = scnum #store scnum-which is > both key and value > xreturn = advanceSearch(xstring) #shorten the part > of string to be searched > continue > if section[0:1] == 'p': > pnlnum = int(section[3:]) > sc_info['sc',scnum,pnlnum] = pnlnum #store pnlnum & > temp value for pnlnum > xreturn = advanceSearch(xstring) #the return value > is to move flow back here > continue > if section[0:1] != 's' or 'p': > xnum = section[0:] #section must contain the footage > if section.find('+'): #the + exists > ftge = parseFtge(section) > sc_info['sc',scnum,pnlnum] = ftge #store ftge in pnlnum > xreturn = advanceSearch(xstring) > continue > else: > ftge = (section/16.0) #section is frames-convert > to decimal > sc_info['sc',scnum,pnlnum] = ftge #store ftge in pnlnum > xreturn = advanceSearch(xstring) > continue > else: > print sc_info > > class ContRead(LineReader): > def advanceSearch(xstring): > prev_pos = (cur_pos +1) > cur_pos = xstring.find(',',prev_pos) #find the next comma > return > > class Footage(LineReader): > def parseFtge(section): > xplus = section.find('+') #find position of '+' > xfeet = int(section[0:xplus]) > xframes = int(section[(xplus + 1):-1]) > xframes_d = (xframes/16.0) > return (xfeet + xframes_d) > > >From what I can see you have no need for classes in your code. This is probably what is causing you trouble at the moment, so I would say just remove them. def parse_line(line): """splits a line on commas""" return line.split(',') def parse_footer(line): """Strips off leading four characters (maybe 'Ftr:'), and then parses the rest as above""" return parse_line([4:]) That should solve your problem. Below I illustrate some of how classes work, in case you are dead set on using them. Learning Python should address all of this as well. I haven't read it, so I can't be more specific. To call a method from another method within a class, you need to prefix it with self. That looks like this: class Spam(object): ## {1} def parse_line(self, line): ## {2} return line.split(',') def parse_footer(self, line): return self.parse_line(line[4:]) ## {3} # {1} always subclass 'object' to use newstyle classes # {2} Note that method declarations have an extra first argument, # usually called "self", which refers to your instance of the class. # {3} "self" finds parse_line within the current class # or superclasses of the current class. Note that self has # moved from inside the parentheses to before the method name. To call a method from another class you need to instantiate that class first. class Spam(object): def parse_line(self, line): return line.split(',') class Eggs(object): def parse_footer(self, line): parser = Spam() parser.parse_line(line[4:]) ## {4} # {4} The Spam instance "parser" is fed to the method "parse_line" as # its first argument (as "self"). If a class subclasses another class (by, e.g., replacing 'object' with 'Spam' in the class declaration of 'Eggs'), then methods in Eggs can reference methods in Spam using 'self'. class Spam(object): def parse_line(self, line): return line.split(',') class Eggs(Spam): ## {5} def parse_footer(self, line): return self.parse_line(line[4:]) ## {6} # {5} Now Eggs is a subclass of Spam # {6} "self" looks for a method called parse_line in Eggs, and # when it fails to find it, looks in Eggs' superclass, Spam # and finds it there. Hope that helps Cheers, Cliff > >On Mon, 2009-06-22 at 12:13 -0700, Greg Reyna wrote: > >> Learning Python (on a Mac), with the massive help of Mark Lutz's > >> excellent book, "Learning Python". > >> > >> What I want to do is this: > >> I've got a Class Object that begins with a def. It's designed to be > >> fed a string that looks like this: > >> > >> "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > >> > >> I'm parsing the string by finding the commas, and pulling out the > >> data between them. > >> No problem so far (I think...) The trouble is, there is a place > >> where code is repeated: > >> > >> 1. Resetting the start & end position and finding the next comma > >>in the string. > > > > > > >Have you looked at the split() method on string objects. It works kind > >of like this: > > > >>>> s = "scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4," > >>>> s.split(",") > >['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl > >4', ' 2+4', ''] > >>>> elements = s.split(",") > >>>> elements > >['scene 1', ' pnl 1', ' 3+8', ' pnl 2', ' 1+12', ' pnl 3', ' 12', ' pnl > >4', ' 2+4', ''] > >>>> elements[2] > >' 3+8' > > > > > > > >> In my previous experience (with a non-OOP language), I could create a > >> 'procedure', which was a separate function. With a call like: > >> var=CallProcedure(arg1,arg2) the flow control would go to the > >> procedure, run, then Return back to the main function. > >> > > > >Python doesn't have procedures quite like this. It has functions (the > >things starting with "def"), which generally speaking take arguments and > >return values. For the most part, you do not want your functions to > >operate on variables that aren't either defined in the function or > >passed in as arguments. That leads to difficult-to-debug code. > > > > > >> In Python, when I create a second def in the same file as the first > >> it receives a "undefined" error. I can't figure out how to deal with > >> this. How do I set it up to have my function #1 call my function #2, > >> and return? > > > >Your problem description is confusing. First of all, no class starts > >with 'def'. They all start with 'class'. Perhaps you are talking about > >a module (a python file)? > > > >Also, telling us that you get an undefined error is not particularly > >helpful. Every Exception that python raises is accompanied by an > >extensive stack trace which will help you (or us) debug the problem. If > >you don't show us this information, we can't tell you what's going > >wrong. It will tell you (in ways that are crystal clear once you have a > >bit of practice reading them) exactly what went wrong. > > > >Can you show your code, as well as the complete error message you are > >receiving? > > > >My suggestions here, are essentially a paraphrasing of Eric Raymond's > >essay, "How to Ask Smart Questions." It is freely available on the web, > >and easily found via google. I recommend reading that, in order to get > >the most mileage out this news group. > > > >Cheers, > >Cliff > From jeff at jmcneil.net Tue Jun 23 11:12:15 2009 From: jeff at jmcneil.net (Jeff McNeil) Date: Tue, 23 Jun 2009 08:12:15 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: <8b675cdf-026e-4e70-b6b0-d466411eaa2d@l5g2000vbp.googlegroups.com> On Jun 23, 6:59?am, Francesco Bochicchio wrote: > Hi all, > > is there any site that reports the current porting (to Python 3.x) > status of the main non-standard extension modules (such as pygtk, > pywin32, wxpython, ...) ? > I think such information would be very useful for people - like me - > which are tryiing to decide how/when/if to port existing scripts/ > applications to the new python, or also ?which python to use to start > a new program. > > I searched and googled for this information ?but without finding > anything. It looks to me that also the single extension module sites > are quite shy at announcing plans for the porting (I understand that > in part this is for the "is ready when is ready" philosophy of many > non-large open software projects). > > Ciao > ----- > FB You can pull a list of what works with 3.0 via PyPi, there's a link which points you to http://pypi.python.org/pypi?:action=browse&c=533&show=all. If the package isn't listed on PyPi, I believe you'll have to check out the vendor/distribution site. I posted something like this on my blog a few months back. Finding what's available isn't too terribly difficult. I thought it would be nice to have a port status page that lets the community know where certain package stand so volunteers can step in and help. I guess it would be rather difficult to keep such a page updated, though. From philip at semanchuk.com Tue Jun 23 11:13:38 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 11:13:38 -0400 Subject: [Mac] file copy In-Reply-To: <7ac8e0F1tludjU1@mid.uni-berlin.de> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <31BEEB5D-11A4-469C-A340-6A21E8A0D9CB@semanchuk.com> On Jun 23, 2009, at 10:54 AM, Diez B. Roggisch wrote: > Tobias Weber wrote: > >> Hi, >> which is the best way to copy files on OS X? I want to preserve >> resource >> forks and extended attributes. > > Are these still relevant on OSX? I've always only copied files > directly, and > never had any troubles. I think resource forks are now stored as extended attributes, and Apple's version of cp is aware of extended attributes. Try this -- create a text file via terminal using `touch foo.txt`. In Finder, click "get info" on the file and change it to open with anything other than TextEdit (e.g. Firefox). Now go back to terminal and look at the file. It's still zero bytes long, but try the command `xattr foo.txt` -- $ xattr foo.txt com.apple.FinderInfo com.apple.ResourceFork Also -- $ cp foo.txt bar.txt $ xattr bar.txt com.apple.FinderInfo com.apple.ResourceFork xattr -h gives options for this command. To the OP -- I remember reading somewhere that xattr is written in Python. You might find it useful or even be able to import it directly. HTH Philip From sn at sncs.se Tue Jun 23 11:20:39 2009 From: sn at sncs.se (Sverker Nilsson) Date: Tue, 23 Jun 2009 08:20:39 -0700 (PDT) Subject: Guppy-PE/Heapy 0.1.9 released Message-ID: I am happy to announce Guppy-PE 0.1.9 Guppy-PE is a library and programming environment for Python, currently providing in particular the Heapy subsystem, which supports object and heap memory sizing, profiling and debugging. It also includes a prototypical specification language, the Guppy Specification Language (GSL), which can be used to formally specify aspects of Python programs and generate tests and documentation from a common source. The main news in this release: o A patch by Chad Austin to compile with Visual Studio 2003 and Python 2.5 C compilers. I think this may fix similar problems with other Microsoft compilers. o Interactive help system, providing a .doc attribute that can be used to get info on available attributes in text form and also by invoking a browser. o New documentation file, heapy_tutorial.html. It contains for now an example of how to get started and use the interactive help. o Bug fix wrt pop for mutable bitset. (Not used in heapy, only in sets/test.py) o guppy.hpy().test() now includes the set-specific tests. o Remote monitor does not longer require readline library being installed. License: MIT Guppy-PE 0.1.9 is available in source tarball format on the Python Package Index (a.k.a. Cheeseshop): http://pypi.python.org/pypi/guppy/0.1.9 The project homepage is on Sourceforge: http://guppy-pe.sourceforge.net Enjoy, Sverker Nilsson Expertise in Linux, embedded systems, image processing, C, Python... http://sncs.se From gagsl-py2 at yahoo.com.ar Tue Jun 23 11:24:03 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Jun 2009 12:24:03 -0300 Subject: Idioms and Anti-Idioms Question References: <4A3F053A.10208@csail.mit.edu> Message-ID: En Mon, 22 Jun 2009 20:34:40 -0300, Miles Kaufmann escribi?: > On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote: > >> What is subtly wrong about this piece of code? I can't see any bugs >> and can't think of subtle gotchas (e.g. the '\' is removed or the lines >> become separated, because in both cases an IndentationError would be >> raised). > > Perhaps, along with one of those gotchas, a mix of tabs and spaces are > used such that the second line only _appears_ to have a different level > of indentation? ;) Neither. As back in time as I can go (Python 1.5), having any character after the backslash has always been a syntax error no matter what. Only the error message has changed: C:\TEMP>python15 syntaxerror.py File "syntaxerror.py", line 18 value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ ^ SyntaxError: invalid token So the "it might be subtly wrong" argument is strongly wrong. -- Gabriel Genellina From jaime.frio at gmail.com Tue Jun 23 11:29:39 2009 From: jaime.frio at gmail.com (Jaime Fernandez del Rio) Date: Tue, 23 Jun 2009 17:29:39 +0200 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Message-ID: <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> On Tue, Jun 23, 2009 at 4:45 PM, Cameron Pulsford wrote: > Hey all, I have a dictionary that looks like this (small example version) > {(1, 2): 0} named a > > so I can do a[1,2] which returns 0. What I also have is a list of > coordinates into a 2 dimensional array that might look like this b = > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? a[tuple(b[0])] should do it... Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus planes de dominaci?n mundial. From pavlovevidence at gmail.com Tue Jun 23 11:32:43 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 23 Jun 2009 08:32:43 -0700 (PDT) Subject: Idioms and Anti-Idioms Question References: Message-ID: <43e3d938-bfc0-43f1-924f-29c00ea1ab6d@g19g2000yql.googlegroups.com> On Jun 21, 9:14?pm, Ben Charrow wrote: > I have a question about the "Using Backslash to Continue Statements" in the > howto "Idioms and Anti-Idioms in Python" > (http://docs.python.org/howto/doanddont.html#using-backslash-to-contin...) > > It says: > > "...if the code was: > > value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ > ? ? ? ? ?+ calculate_number(10, 20)*forbulate(500, 360) > > then it would just be subtly wrong." > > What is subtly wrong about this piece of code? ?I can't see any bugs and can't > think of subtle gotchas (e.g. the '\' is removed or the lines become separated, > because in both cases an IndentationError would be raised). Perhaps it was originally was like this: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ + calculate_number(10, 20)*forbulate(500, 360) Carl Banks From cameron.pulsford at gmail.com Tue Jun 23 11:35:16 2009 From: cameron.pulsford at gmail.com (Cameron Pulsford) Date: Tue, 23 Jun 2009 11:35:16 -0400 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> <97a8f1a70906230829s7d847f50lc8a86e225a58a981@mail.gmail.com> Message-ID: <5700df6b0906230835r78c18b2csb630b7f134dac391@mail.gmail.com> Thanks! On Tue, Jun 23, 2009 at 11:29 AM, Jaime Fernandez del Rio < jaime.frio at gmail.com> wrote: > On Tue, Jun 23, 2009 at 4:45 PM, Cameron > Pulsford wrote: > > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > > > > so I can do a[1,2] which returns 0. What I also have is a list of > > coordinates into a 2 dimensional array that might look like this b = > > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? > > a[tuple(b[0])] should do it... > > Jaime > > -- > (\__/) > ( O.o) > ( > <) Este es Conejo. Copia a Conejo en tu firma y ay?dale en sus > planes de dominaci?n mundial. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwmsmith at gmail.com Tue Jun 23 11:49:53 2009 From: kwmsmith at gmail.com (Kurt Smith) Date: Tue, 23 Jun 2009 10:49:53 -0500 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: On Mon, Jun 22, 2009 at 9:49 PM, Andras Pikler wrote: > Hi! > > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > and I am at a loss. > > > > Long: I?m doing research/programming for a professor, and we are working > with MIDI files (a type of simple music file). The research deals with > generating variations from a musical melody; currently, my Python code uses > a Python midi package I found online to read the notes in question from a > midi file, about 350 lines of my own code to generate a variation based on > these notes and the professor?s algorithms, and finally the package again to > write the new melody to another midi file. > > > > Now, my professor would like to have this exact code in C/C++, as she > believes C is more compatible with MATLAB, and wants the code to be > available in multiple languages in case a programmer works for her in the > future who knows C but not Python. While I know a tiny bit of C (emphasis on > the tiny), I would much prefer if there were some sort of automatic compiler > I could use to turn my Python code into C than taking a week or two or three > to learn the minimum I need about C, find a way to access MIDI files in it, > and rewrite all of my code. > > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > Python midi package I?m using uses modules which Shedskin does not support. > Otherwise, I haven?t found much. Is there anything out there to help me do > this? If not, from anyone who has experience in this regard, how daunting > should I expect this to be? Taking on C from a cold start and being able to handle the ins and outs of interfacing with Python isn't something that's feasible in 'two or three weeks'. Here are a couple of options -- take 'em or leave 'em: 1) Put the code in Cython: http://www.cython.org/ (full disclosure: I'm doing a GSoC project with Cython). It will convert pretty much any python code into C code (even closures are supported in the most recent version, I think), and the C code can then be compiled into an extension module. The only problem with the above is the C code isn't, at first blush, easy to read. Nor is it supposed to be changed by the user. So that leads us to option... 2) Write the core functionality in C yourself, and then wrap those C functions in Cython. You'll want to take a look at the documentation: http://docs.cython.org/ and, more specifically on wrapping C code: http://docs.cython.org/docs/external_C_code.html I don't think you'll be able to avoid learning C, though. Kurt From jcd at sdf.lonestar.org Tue Jun 23 11:50:06 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 23 Jun 2009 11:50:06 -0400 Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: <1245772206.8812.1.camel@aalcdl07> On Mon, 2009-06-22 at 22:52 +0000, Peter Billam wrote: > I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > > -- > Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html If the lines got separated, a leading + could disappear into its line without any errors showing up. A trailing + would raise a syntax error. >>> spam = 6 >>> spam + File "", line 1 spam + ^ SyntaxError: invalid syntax >>> + spam 6 >>> From tanner989 at hotmail.com Tue Jun 23 12:19:06 2009 From: tanner989 at hotmail.com (tanner barnes) Date: Tue, 23 Jun 2009 11:19:06 -0500 Subject: help! Message-ID: Python Version: 2.6 GUI toolkit: WxPython Ok so i am writing a program for my school's football team. In one part there is a notebook with 4 tabs for that stats. In each tab there are 4 txtctrl's with a + and - for each. The problem im having is that i need when you click the + or - button that it updates that stat for the player. _________________________________________________________________ Microsoft brings you a new way to search the web. Try Bing? now http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try_bing_1x1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Tue Jun 23 12:20:38 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 23 Jun 2009 09:20:38 -0700 (PDT) Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> <8b675cdf-026e-4e70-b6b0-d466411eaa2d@l5g2000vbp.googlegroups.com> Message-ID: <40a2c409-256a-46c9-9769-1a3c0b4d4590@g1g2000yqh.googlegroups.com> On 23 Giu, 17:12, Jeff McNeil wrote: > On Jun 23, 6:59?am, Francesco Bochicchio wrote: > > > > > > > Hi all, > > > is there any site that reports the current porting (to Python 3.x) > > status of the main non-standard extension modules (such as pygtk, > > pywin32, wxpython, ...) ? > > You can pull a list of what works with 3.0 via PyPi, there's a link > which points you tohttp://pypi.python.org/pypi?:action=browse&c=533&show=all. > If the package isn't listed on PyPi, I believe you'll have to check > out the vendor/distribution site. > > I posted something like this on my blog a few months back. ?Finding > what's available isn't too terribly difficult. I thought it would be > nice to have a port status page that lets the community know where > certain package stand so volunteers can step in and help. I guess it > would be rather difficult to keep such a page updated, though > > - Mostra testo citato - Thanks. I thought of pypy, and even tried to search for Python 3 using its search button, but somehow missed the handy "python 3" link on the sidebar :-0 I agree that keeping a complete list would be very difficult, although useful ... Ciao ---- FB From philip at semanchuk.com Tue Jun 23 12:35:31 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 23 Jun 2009 12:35:31 -0400 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: On Jun 23, 2009, at 12:20 PM, Tobias Weber wrote: > In article , > Philip Semanchuk wrote: > >> I think resource forks are now stored as extended attributes, and > > No I'll take your word for it because I was just guessing, but then why do the xattrs in the example I gave show a resource fork? > >> Apple's version of cp is aware of extended attributes. > > Yes, but the manual doesn't say to what extent, nor anything about > ACLs Your original question didn't say anything about ACLs either. >> To the OP -- I remember reading somewhere that xattr is written in >> Python. You might find it useful or even be able to import it >> directly. > > It uses a C extension, but I could import it if I wanted to re-invent > the wheel ;) Isn't importing a module that's already written the exact opposite of re-inventing the wheel? From aahz at pythoncraft.com Tue Jun 23 12:51:03 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 09:51:03 -0700 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: In article <024d7a38$0$20654$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >Dennis Lee Bieber wrote: >> On Sat, 20 Jun 2009 13:47:24 -0700 (PDT), Bearophile >> declaimed the following in >> gmane.comp.python.general: >>> >>> Dennis Lee Bieber, may I ask why most or all your posts are set to "No- >>> Archive"? >> >> I'm from the days when the majority of NNTP servers were configured >> to expire posts after some number of days (Netcom used to expire binary >> groups after 24 hours! and most others were something like 14 days). >> >> Then came the precursor to GoogleGroups -- DejaNews -- threatening >> to archive posts through eternity. This resulted in a fair amount of >> protesting by some, and the creation of the x-no-archive header >> convention (Agent even has configuration options such that, if one were >> to not normally use x-no-archive such that one's own posts could be >> archived, one could still honor it in replies to posts that did contain >> it -- so those replies with quoted contents would also not be archived). >> >> It was at that time that I added the x-no-archive header to my posts >> from Agent; as, while not as vocal as others, did object to DejaNews >> plans. > >But your replies often contain useful information. It's a shame that they >disappear from record, making them invisible for anyone searching the >archives. > >A good rule of thumb when judging behaviour is to ask, "What if everyone did >this?". If everyone set x-no-archive, then discussions on Usenet would be >ephemeral, we couldn't point people to past discussions for information, >and we would lose a lot of useful information. (Also a lot of garbage.) I >can't tell you how often I find useful information in the archives of >comp.lang.python thanks to those who archive the gname news-to-email >gateway, and Google groups. If everyone did what you use, the entire >community, including myself, would be far worse off. > >As far as I'm concerned, setting x-no-archive is harmful, anti-social >behaviour on a technical newsgroup like this. You (almost) might as well >just email the poster you're replying to directly. Your response to Dennis seems at least a little over-the-top. So far as I'm concerned, anyone who joined Usenet after DejaNews is a latecomer; trying to change the cultural beliefs of those who were here first is asserting your superiority. I happen to disagree with people who post with X-no-archive, but I think it's certainly their right. Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, and it all worked. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 12:53:14 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 09:53:14 -0700 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: In article <4a3fde13$0$48239$14726298 at news.sunsite.dk>, saurabh wrote: > >I am an experienced C programmer and recently dived into python, >I have developed an instant love for it. >I have been doing some routine scripting for day to day admin tasks,also >have done some Tkinter and socket programming using python. > >I am looking for some open source python project preferably in one of >the above areas (not strictly, am open to others too) to contribute. http://wiki.python.org/moin/VolunteerOpportunities -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From anishaapte at gmail.com Tue Jun 23 12:54:02 2009 From: anishaapte at gmail.com (jythonuser) Date: Tue, 23 Jun 2009 09:54:02 -0700 (PDT) Subject: Dynamic method invocation Message-ID: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> Hi I am new to jythong and was wondering if/how I can do the following - a) register a java object with a given name with jython interpreter using set method b) call methods on the java object - but the methods may not exist on the object, so I would like to call from jython a generic method that I have defined on the object as opposed to using java reflection. Thus the java class is more like a proxy for invocation. As an example, I register an instance of java class Bar with name foo. I want to be able to call from jython - foo.method1 (args) I don't want to define all the methods that I can call from jython on class foo but have a generic method that the above jython code will invoke. I want to use a model where the methods that can be called on foo are discovered dynamically once they are invoked on java class. Clearly Java won't let me do this during method invocation so I am wondering if I can register some sort of proxy object with jython that will let me then delegate right call down to the java object. Thanks a bunch From python at mrabarnett.plus.com Tue Jun 23 13:08:57 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2009 18:08:57 +0100 Subject: reply to OT diversion In-Reply-To: References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <716a13f1-95ed-4f4a-8a30-5f79d1a2b04e@f16g2000vbf.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: <4A410C29.8050305@mrabarnett.plus.com> Aahz wrote: [snip] > Your response to Dennis seems at least a little over-the-top. So far as > I'm concerned, anyone who joined Usenet after DejaNews is a latecomer; > trying to change the cultural beliefs of those who were here first is > asserting your superiority. I happen to disagree with people who post > with X-no-archive, but I think it's certainly their right. > > Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, > and it all worked. Difficult to prove, though, because the evidence no longer exists! :-) From lie.1296 at gmail.com Tue Jun 23 13:49:07 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 17:49:07 GMT Subject: Measuring Fractal Dimension ? In-Reply-To: References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: Mark Dickinson wrote: > On Jun 23, 3:52 am, Steven D'Aprano > wrote: >> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: >>> In my universe the standard definition of "log" is different froim what >>> log means in a calculus class >> Now I'm curious what the difference is. > > It's just the usual argument about whether 'log' means > log base 10 or log base e (natural log). At least in the > US, most[*] calculus texts (and also most calculators), > for reasons best known to themselves, use 'ln' to mean > natural log and 'log' to mean log base 10. But most > mathematicians use 'log' to mean natural log: pick up a > random pure mathematics research paper that has the word > 'log' in it, and unless it's otherwise qualified, it's > safe to assume that it means log base e. (Except in the > context of algorithmic complexity, where it might well > mean log base 2 instead...) I usually use log without explicit base only when the base isn't relevant in the context (i.e. when whatever sane base you put in it wouldn't really affect the operations). In algorithmic complexity, a logarithm's base doesn't affect the growth shape and, like constant multiplier, is considered irrelevant to the complexity. > Python also suffers a bit from this confusion: the > Decimal class defines methods 'ln' and 'log10', while > the math module and cmath modules define 'log' and > 'log10'. In fact, in the Decimal class there is no log to an arbitrary base. > (But the Decimal module has other problems, > like claiming that 0**0 is undefined while > infinity**0 is 1.) Well, in math inf**0 is undefined. Since python is programming language, and in language standards it is well accepted that undefined behavior means implementations can do anything they like including returning 0, 1, 42, or even spitting errors, that doesn't make python non-conforming implementation. A more serious argument: in IEEE 745 float, inf**0 is 1. Mathematic operation in python is mostly a wrapper for the underlying C library's sense of math. > [*] A notable exception is Michael Spivak's 'Calculus', which also > happens to be the book I learnt calculus from many years ago. From python at bdurham.com Tue Jun 23 14:05:34 2009 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Jun 2009 14:05:34 -0400 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> Message-ID: <1245780334.11467.1321801415@webmail.messagingengine.com> Mag, If your source data is clean, it may also be faster for you to parse your input files directly vs. use the CSV module which may(?) add some overhead. Check out the struct module and/or use the split() method of strings. We do a lot of ETL processing with flat files and on a slow single core processing workstation, we can typically process 2 Gb of data in ~5 minutes. I would think a worst case processing time would be less than an hour for 14 Gb of data. Malcolm From lie.1296 at gmail.com Tue Jun 23 14:07:04 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 18:07:04 GMT Subject: Idioms and Anti-Idioms Question In-Reply-To: References: Message-ID: Peter Billam wrote: > On 2009-06-22, Lie Ryan wrote: >> Ben Charrow wrote: >>> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \ >>> + calculate_number(10, 20)*forbulate(500, 360) >>> What is subtly wrong about this piece of code? I can't see any bugs and >>> can't think of subtle gotchas (e.g. the '\' is removed or the lines >>> become separated, because in both cases an IndentationError would be >>> raised). >> The preferred style is to put the binary operators before the line-break >> (i.e. the line break is after the operators): >> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \ >> calculate_number(10, 20)*forbulate(500, 360) >> ... >> The following is an extract from PEP 8: >> The preferred way of wrapping long lines is by using Python's >> implied line continuation inside parentheses, brackets and braces. >> If necessary, you can add an extra pair of parentheses around an >> expression, but sometimes using a backslash looks better. Make sure to >> indent the continued line appropriately. The preferred place to break >> around a binary operator is *after* the operator, not before it. > > Damian Conway, in Perl Best Practices, puts forward a clear argument > for breaking *before* the operator: > Using an expression at the end of a statement gets too long, > it's common practice to break that expression after an operator > and then continue the expression on the following line ... > The rationale is that the operator that remains at the end > of the line acts like a continutation marker, indicating that > the expression continues on the following line. > Using the operator as a continutation marker seems like > an excellent idea, but there's a serious problem with it: > people rarely look at the right edge of code. > Most of the semantic hints in a program - such as keywords - > appear on the left side of that code. More importantly, the > structural cues for understanding code - for example, indenting, - > are predominantly on the left as well ... This means that indenting > the continued lines of the expression actually gives a false > impression of the underlying structure, a misperception that > the eye must travel all the way to the right margin to correct. > > which seems to me well-argued. I wonder on what grounds PEP8 > says "The preferred place to break around a binary operator is > *after* the operator" ? > Perhaps it's just the "continutation marker" rationale? > > Regards, Peter > When you're *scanning* the code, breaking the line before the operator might be better since you can easily see that that a line is a continuation from the previous line. However, when it comes to *reading* the code, it's easy to miss that the code continues to the next line, especially when you rely on parentheses' implicit line continuation and don't use an explicit line-continuation character (i.e. \). So... IMHO when it comes to break before or after the operator, it depends on whether you rely on parentheses or explicit line continuation. If you use implicit continuation with parentheses, it's better to break after operators; else if you use explicit continuation with \, it's better to break before operators. Since python prefers using parentheses' implicit line cont., it follows that breaking after operator is the natural choice. From lie.1296 at gmail.com Tue Jun 23 14:13:20 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Jun 2009 18:13:20 GMT Subject: Perl's @foo[3,7,1,-1] ? In-Reply-To: References: <3_XZl.1449$P5.716@nwrddc02.gnilink.net> <1ba9eaed0906162047p7b750d5auae69a05bc6547193@mail.gmail.com> <4A38DDDB.5070309@sequans.com> <1245269001.27277.28.camel@aalcdl07> <4A3F7FC1.1000200@sequans.com> <1245679928.22057.24.camel@aalcdl07> Message-ID: <4X80m.250$ze1.226@news-server.bigpond.net.au> Jean-Michel Pichavant wrote: > Lie Ryan wrote: >> Jean-Michel Pichavant wrote: >> >> >> >> >>> Maybe I've been a little bit too dictatorial when I was saying that >>> renaming namespaces should be avoided. >>> Sure your way of doing make sense. In fact they're 2 main purposes of >>> having strong coding rules: >>> 1/ ease the coder's life >>> 2/ ease the reader's life >>> >>> The perfect rule satisfies both of them, but when I have to choose, I >>> prefer number 2. Renaming packages, especially those who are world wide >>> used, may confuse the reader and force him to browse into more code. >>> >>> From the OP example, I was just pointing the fact that **he alone** >>> gains 3 characters when **all** the readers need to ask what means "np". >>> Renaming namespaces with a well chosen name (meaningful) is harmless. >>> >> >> As long as you keep all import statements at the head of the file, there >> is no readability problems with renaming namespace. >> >> Glance at the header file, see: >> import numpy as np >> >> and it's not hard to mentally switch np as numpy... >> >> well, as long as your header doesn't look like this: >> import numpy as np >> import itertools as it >> import Tkinter as Tk >> from time import time as t >> > > yep, your example is good, no namespace renaming ... :o) > I would gladly accept the following renaming: > import theMostEfficientPythonPackageInTheWorld as meppw > Hopefully, package names are often usable as provided. > > Moreover, writing numpy instead of np is not harder for the coder than > switching mentally from np to numpy for the reader. It's just about who > you want to make the life easier, the coder or the reader ? My point was, use namespace renaming whenever that improves readability; however like all tools, don't overuse it Another usecase might be when you have two similarly named package which might bring confusion on which is which if left as is. From cmpython at gmail.com Tue Jun 23 14:14:08 2009 From: cmpython at gmail.com (Che M) Date: Tue, 23 Jun 2009 11:14:08 -0700 (PDT) Subject: launch a .py file from a batch file References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> Message-ID: <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> On Jun 23, 5:30?am, Paul Moore wrote: > 2009/6/23 C M : > > >> Assuming you're running on Windows XP, try the following line in your > >> batch file: > >> @start path\MyPythonApp.pyw > > >> That's of course after you rename your script to a pyw extension. ?That's > >> associated with pythonw, which doesn't need a command window. > > > Well, I renamed my script to have a .pyw extension, and then ran the line > > above.? Without quotes, it doesn't find it (because I have spaces in the > > path). > > With quotes it just opens a console and does nothing (does not launch the > > app). > > > Any ideas? > > Use > > @start "" "path\MyPythonApp.pyw" > > The first item in quotes is the window title. If you only include the > path (in quotes) it's taken as a title, which is why you need the > second set of quotes. > > Paul. Unfortunately, when I try that it says "Windows cannot find [that file]", etc. And yet I am copying the filename right from the file manager and it IS there. What's also odd is that if I open the file using cd and then just putting the filename on the next line, that file (which I gave a .pyw extension) doesn't open, but a file that has a .py extension does. Any ideas? Thanks. Che From torriem at gmail.com Tue Jun 23 14:28:51 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 12:28:51 -0600 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <4A411EE3.4090101@gmail.com> Tobias Weber wrote: >> Apple's version of cp is aware of extended attributes. > > Yes, but the manual doesn't say to what extent, nor anything about ACLs mv, cp, etc (but not rsync) are completely aware of resource forks from Tiger on. This is well documented and known on the Mac forums. So shutils should work just fine for copying, moving, etc. From torriem at gmail.com Tue Jun 23 14:30:42 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 12:30:42 -0600 Subject: C-extension 2 times slower than exe In-Reply-To: <4a40e4b6$1@news.fhg.de> References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: <4A411F52.3080109@gmail.com> Rolf Wester wrote: > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use > the time command to measure the time consumed but I also measure the > time within the C-code using clock() and get similar result. So the > Python startup time is not the reason for the runtime difference I > found. Thank you anyway. Without a profiler it's hard to say where the time is being consumed. You might want to use ctypes and open your c++ code as a DLL without the python extension wrapper. From tjreedy at udel.edu Tue Jun 23 14:37:59 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Jun 2009 14:37:59 -0400 Subject: Help with dictionaries and multidimensial lists In-Reply-To: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> References: <5700df6b0906230745n5e1de361kdbb7aff7e0daf771@mail.gmail.com> Message-ID: Cameron Pulsford wrote: > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > > so I can do a[1,2] which returns 0. What I also have is a list of > coordinates into a 2 dimensional array that might look like this b = > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? Unless you are mutating your coordinate pairs in place, which you very seldom would *have to* do, I would make them tuples. b = [ (1,2), (3,5), ...] This would even save a bit of memory. I prefer this to converting list pairs to tuple pairs on access. tjr From malaclypse2 at gmail.com Tue Jun 23 14:45:21 2009 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Jun 2009 14:45:21 -0400 Subject: [Mac] file copy In-Reply-To: <4A411EE3.4090101@gmail.com> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> <4A411EE3.4090101@gmail.com> Message-ID: <16651e80906231145r23a45dc1n5841e6d0b7747128@mail.gmail.com> On Tue, Jun 23, 2009 at 2:28 PM, Michael Torrie wrote: > mv, cp, etc (but not rsync) are completely aware of resource forks from > Tiger on. ?This is well documented and known on the Mac forums. > > So shutils should work just fine for copying, moving, etc. I don't think that's true. The shutil docs (http://docs.python.org/library/shutil.html) has a big red box at the top that says: """ Warning Even the higher-level file copying functions (copy(), copy2()) can?t copy all file metadata. On POSIX platforms, this means that file owner and group are lost as well as ACLs. On Mac OS, the resource fork and other metadata are not used. This means that resources will be lost and file type and creator codes will not be correct. On Windows, file owners, ACLs and alternate data streams are not copied. """ If I understand the OP's question from the first email in this thread, that should pretty strongly warn you that shutil.copy2 is not going to do what you want. Not being a mac user myself, I don't know what the right way to accomplish what you want is, though. -- Jerry From deets at nospam.web.de Tue Jun 23 15:51:53 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Jun 2009 21:51:53 +0200 Subject: Dynamic method invocation In-Reply-To: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> Message-ID: <7acq2qF1u879sU1@mid.uni-berlin.de> jythonuser schrieb: > Hi > I am new to jythong and was wondering if/how I can do the following - > > a) register a java object with a given name with jython interpreter > using set method > b) call methods on the java object - but the methods may not exist on > the object, so I would like to call from jython a generic method that > I have defined on the object as opposed to using java reflection. > Thus the java class is more like a proxy for invocation. > > As an example, I register an instance of java class Bar with name > foo. I want to be able to call from jython - > foo.method1 (args) > I don't want to define all the methods that I can call from jython on > class foo but have a generic method that the above jython code will > invoke. I want to use a model where the methods that can be called on > foo are discovered dynamically once they are invoked on java class. > Clearly Java won't let me do this during method invocation so I am > wondering if I can register some sort of proxy object with jython that > will let me then delegate right call down to the java object. It's very unclear to me what you want, but to me, it looks as if you have some misconceptions about jython. There is no "registration" of java-objects. If you have a java-object, you can assign it to a name, and simply invoke any method on it (internally, that will mean using reflection, but that's below the covers for you) foo = SomeJavaClass() foo.some_method() As long as some_method is defined on SomeJavaClass, this will work. And there is also no type-information needed, so this will work in Jython, but not in java: ---- java ---- class A { public void foo() {}; } class B { // NOT A SUBCLASS OF A!! public void foo() {}; } ---- jython ---- if some_condition: bar = A() else: bar = B() bar.foo() Regarding the "generic method thing", I guess this will work: foo = SomeJavaObject() m = getattr(foo, "method_name_that_might_not_be_defined", None) if m: m(argument) Diez From milesck at umich.edu Tue Jun 23 16:42:48 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 23 Jun 2009 16:42:48 -0400 Subject: [Mac] file copy In-Reply-To: References: Message-ID: <7CBEBC9B-0DC2-417B-8003-F6D6B7EC998D@umich.edu> On Jun 23, 2009, at 9:52 AM, Tobias Weber wrote: > Hi, > which is the best way to copy files on OS X? I want to preserve > resource > forks and extended attributes. > > ... > > bin/cp -p This. cp -p, mv, rsync -E, tar, and other utilities will use the copyfile(3) API to preserve extended attributes, resource forks, and ACLs. cp -Rp should be just as safe as a Finder copy--moreso if you run it as root--with the exception of preserving creation dates. Or if you're worried about hard links, check out ditto(1). You presumably already know this, but avoid shutil at all costs. BackupBouncer (http://www.n8gray.org/code/backup-bouncer/) makes testing what gets preserved by various methods of copying quick and easy. The results for a Finder copy: Verifying: basic-permissions ... FAIL (Critical) Verifying: timestamps ... ok (Critical) Verifying: symlinks ... ok (Critical) Verifying: symlink-ownership ... FAIL Verifying: hardlinks ... FAIL (Important) Verifying: resource-forks ... Sub-test: on files ... ok (Critical) Sub-test: on hardlinked files ... FAIL (Important) Verifying: finder-flags ... ok (Critical) Verifying: finder-locks ... ok Verifying: creation-date ... ok Verifying: bsd-flags ... ok Verifying: extended-attrs ... Sub-test: on files ... ok (Important) Sub-test: on directories ... ok (Important) Sub-test: on symlinks ... ok Verifying: access-control-lists ... Sub-test: on files ... ok (Important) Sub-test: on dirs ... ok (Important) Verifying: fifo ... FAIL Verifying: devices ... FAIL Verifying: combo-tests ... Sub-test: xattrs + rsrc forks ... ok Sub-test: lots of metadata ... FAIL sudo cp -Rp: Verifying: basic-permissions ... ok (Critical) Verifying: timestamps ... ok (Critical) Verifying: symlinks ... ok (Critical) Verifying: symlink-ownership ... ok Verifying: hardlinks ... FAIL (Important) Verifying: resource-forks ... Sub-test: on files ... ok (Critical) Sub-test: on hardlinked files ... FAIL (Important) Verifying: finder-flags ... ok (Critical) Verifying: finder-locks ... ok Verifying: creation-date ... FAIL Verifying: bsd-flags ... ok Verifying: extended-attrs ... Sub-test: on files ... ok (Important) Sub-test: on directories ... ok (Important) Sub-test: on symlinks ... ok Verifying: access-control-lists ... Sub-test: on files ... ok (Important) Sub-test: on dirs ... ok (Important) Verifying: fifo ... ok Verifying: devices ... ok Verifying: combo-tests ... Sub-test: xattrs + rsrc forks ... ok Sub-test: lots of metadata ... ok -Miles From benjamin.kaplan at case.edu Tue Jun 23 17:07:22 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 23 Jun 2009 17:07:22 -0400 Subject: help! In-Reply-To: References: Message-ID: On Tue, Jun 23, 2009 at 12:19 PM, tanner barnes wrote: > Python Version: 2.6 > GUI toolkit: WxPython > > Ok so i am writing a program for my school's football team. In one part > there is a notebook with 4 tabs for that stats. In each > tab there are 4 txtctrl's with a + and - for each. The problem im having is > that i need when you click the + or - button that it updates that stat for > the player. > And what would you like us to tell you? Without specific details, the only advice I can give is to bind an event to the plus and minus buttons that updates the data. Or do you not know how to do that? What do you mean by update? Update the text in the GUI, save to a text file, or commit to a database? Please be as specific as possible. > ________________________________ > Microsoft brings you a new way to search the web. Try Bing? now > -- > http://mail.python.org/mailman/listinfo/python-list > > From egrefen at gmail.com Tue Jun 23 17:29:31 2009 From: egrefen at gmail.com (Edward Grefenstette) Date: Tue, 23 Jun 2009 14:29:31 -0700 (PDT) Subject: Trouble with running java using Popen Message-ID: I have a java prog I need to run at some point during the execution of a python module. The path to the folder containing the all the relevant java stuff (which runs fine from the command line) is stored in pkgpath. The relevant code is this: >>> os.chdir(pkgpath) >>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>> SemVectPackage.wait() Here indexpath is the path to a particular index file (usually indexpath = "./indexfolder/fileindex"), so that effectively Popen should be running the equivalent of the shell command: - java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex - which, again, runs fine in the terminal. However running the program returns the following error (echoed from shell, doesn't interrupt prog): - Exception in thread "main" java.lang.NoClassDefFoundError: SemanticVectorsEvaluator - I have no idea why this isn't working. Anyone have any suggestions as to how I might troubleshoot this? Best, Edward From 1x7y2z9 at gmail.com Tue Jun 23 17:32:27 2009 From: 1x7y2z9 at gmail.com (1x7y2z9) Date: Tue, 23 Jun 2009 14:32:27 -0700 (PDT) Subject: re.NONE References: Message-ID: <6778a308-609c-4218-ab32-e56cb97a1af1@y28g2000prd.googlegroups.com> On Jun 22, 5:56?pm, Lawrence D'Oliveiro wrote: > In message > c77d-4a47-8cb4-7dd916d69... at s1g2000prd.googlegroups.com>, 1x7y2z9 wrote: > > Not sure if this is defined in a later version, but it would be nice > > to define re.NONE = 0 in the re module. > > Do so: > > ? ? re.NONE = 0 > > Problem solved. It would be nice to have such a constant defined in the re module (make it standard). From davea at ieee.org Tue Jun 23 17:52:34 2009 From: davea at ieee.org (Dave Angel) Date: Tue, 23 Jun 2009 17:52:34 -0400 Subject: launch a .py file from a batch file In-Reply-To: <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> References: <44faf7a6-cc00-4473-aaad-9ad1bacb50cb@h28g2000yqd.googlegroups.com> <4A401C17.4050903@ieee.org> <4810f2f7-9d4b-444f-a049-47f9f00d0fd8@37g2000yqp.googlegroups.com> Message-ID: <4A414EA2.30004@ieee.org> Che M wrote: > On Jun 23, 5:30 am, Paul Moore wrote: > >> 2009/6/23 C M : >> >> >>>> Assuming you're running on Windows XP, try the following line in your >>>> batch file: >>>> @start path\MyPythonApp.pyw >>>> >>>> That's of course after you rename your script to a pyw extension. That's >>>> associated with pythonw, which doesn't need a command window. >>>> >>> Well, I renamed my script to have a .pyw extension, and then ran the line >>> above. Without quotes, it doesn't find it (because I have spaces in the >>> path). >>> With quotes it just opens a console and does nothing (does not launch the >>> app). >>> >>> Any ideas? >>> >> Use >> >> @start "" "path\MyPythonApp.pyw" >> >> The first item in quotes is the window title. If you only include the >> path (in quotes) it's taken as a title, which is why you need the >> second set of quotes. >> >> Paul. >> > > Unfortunately, when I try that it says "Windows cannot find [that > file]", etc. > And yet I am copying the filename right from the file manager and it > IS > there. > > What's also odd is that if I open the file using cd and then just > putting > the filename on the next line, that file (which I gave a .pyw > extension) > doesn't open, but a file that has a .py extension does. > > Any ideas? > Thanks. > Che > > > If you run the xx.pyw file interactively, does it work? If not, perhaps the pyw file association is broken. It, along with the py association, should have been set up by the Python install. You can check it (and fix it) with assoc and ftype. Here's what mine look like: M:\>assoc .pyw .pyw=Python.NoConFile M:\>ftype Python.NoConFile Python.NoConFile="C:\ProgFiles\Python26\pythonw.exe" "%1" %* Or, as I said in an earlier message, you could explicitly specify the interpreter to be run on the start line. Something like: @start "notitle" "c:\ProgFiles\Python26\pythonw.exe" "path\script.pyw" From norseman at hughes.net Tue Jun 23 18:11:17 2009 From: norseman at hughes.net (norseman) Date: Tue, 23 Jun 2009 15:11:17 -0700 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <4A415305.6020105@hughes.net> Edward Grefenstette wrote: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? > > Best, > Edward ================= First glance shows you using ./ in code and ../in terminal. Might check that first. Second glance shows you using Popen vs popen (OK) but is that the correct stdout? It is the CHILD's stdout that is being requested here. (Probably what you had in mind, but ... is it?) Third item - running from the terminal usually loads the terminal environment. Running under program control may NOT load the environment. This is a particular problem in Window$. Is the difference going to effect your efforts? As for Java specific problems (if any) I don't know. Another might. Steve From clp2 at rebertia.com Tue Jun 23 18:13:14 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Jun 2009 15:13:14 -0700 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <50697b2c0906231513l48cc067fg5e85bc104fa104de@mail.gmail.com> On Tue, Jun 23, 2009 at 2:29 PM, Edward Grefenstette wrote: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? Have you tried?: arglist = ["java", "-Xmx1024m", "SemanticVectorsEvaluator", "." + indexpath] SemVectPackage = Popen(arglist, stdout=PIPE) SemVectPackage.wait() Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Tue Jun 23 18:29:17 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 00:29:17 +0200 Subject: Trouble with running java using Popen In-Reply-To: References: Message-ID: <7ad39tF1uued4U1@mid.uni-berlin.de> Edward Grefenstette schrieb: > I have a java prog I need to run at some point during the execution of > a python module. > > The path to the folder containing the all the relevant java stuff > (which runs fine from the command line) is stored in pkgpath. The > relevant code is this: > >>>> os.chdir(pkgpath) >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) >>>> SemVectPackage.wait() > > Here indexpath is the path to a particular index file (usually > indexpath = "./indexfolder/fileindex"), so that effectively Popen > should be running the equivalent of the shell command: > - > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > - > which, again, runs fine in the terminal. > > However running the program returns the following error (echoed from > shell, doesn't interrupt prog): > - > Exception in thread "main" java.lang.NoClassDefFoundError: > SemanticVectorsEvaluator > - > > I have no idea why this isn't working. Anyone have any suggestions as > to how I might troubleshoot this? I'd say you got an CLASSPATH-issue here. You can add that explicitly via env as argument to Popen, or pass it via commandline-args. Diez From v.richomme at gmail.com Tue Jun 23 18:59:23 2009 From: v.richomme at gmail.com (smartmobili) Date: Tue, 23 Jun 2009 15:59:23 -0700 (PDT) Subject: Python 3.0.1 and mingw Message-ID: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> I wanted to know if you have some patch to compile python 3.x on mingw platform because I found some but doesn't work very well : make gcc -o python.exe \ Modules/python.o \ libpython3.0.a -lm Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Fatal Python error: Py_Initialize: can't initialize sys standard streams ImportError: No module named encodings.utf_8 I have some questions about posixmodule.c, config.c and makesetup, I can see in posixmodule that you define a INITFUNC like this : #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined (__BORLANDC__)) && !defined(__QNX__) #define INITFUNC PyInit_nt #define MODNAME "nt" #elif defined(PYOS_OS2) #define INITFUNC PyInit_os2 #define MODNAME "os2" #else #define INITFUNC PyInit_posix #define MODNAME "posix" #endif So first I tried to add || defined(____MINGW32____) to declare a PyInit_nt but after config.c was still using PyInit_posix. How does makesetup choose to include one function or another ? So finally python is using PyInit_posix... and after any idea why I got the compilation error ? From buzzard at urubu.freeserve.co.uk Tue Jun 23 19:55:14 2009 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Wed, 24 Jun 2009 00:55:14 +0100 Subject: IDLE / Python 2.5 under Jaunty Message-ID: A little off-topic perhaps, but I can't think of anywhere more likely to contain people with answers. I've just upgraded to Jaunty Jackalope where Python 2.6 is the default Python version. I'm still developing under 2.5, but IDLE now refuses to respond to left click events (for code editing, menus etc. respond as expected). If I right click, then left click I can move the cursor, but that's not ideal. I've tried SPE which is great, but I can't find a way of configuring the Python version, so I'm stuck with a 2.6 shell. I've had limited success with Boa Constructor (which defaulted to Python 2.6 and wxPython 2.6). By renaming a symlink (/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode.pth) I managed to get the wx version for Python 2.5 to default to 2.8.9.1. I've pointed Boa at 2.5 using the interpreter chooser, but the Boa frame designer still appears to expect wxPython 2.6 (it finds "errors" in my code and refuses to fire up). So, has anybody else had the left click issue with IDLE (and solved it)? Does anyone know how I can configure Boa to use wxPython 2.8.9.1? Does anyone know if it's possible to configure the Python version under SPE? Cheers. Duncan From pavlovevidence at gmail.com Tue Jun 23 19:57:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 23 Jun 2009 16:57:20 -0700 (PDT) Subject: C-extension 2 times slower than exe References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: On Jun 23, 7:20?am, Rolf Wester wrote: > Philip Semanchuk wrote: > > > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: > > >> Hi, > > >> I have a C++ program that I would like to steer using Python. I made the > >> wrapper using swig and linked the code (without the main function) into > >> a shared object. My Python script loads the extension and calls a > >> function of the C-extension, the rest runs entirely within the > >> C-extension. For comparison I compiled the code including the main > >> function with the same compilation options and linked all into an exe. > >> The main function of the exe calls the same function as my Python script > >> does. Surprisingly the code in the Python C-extension runs twice as long > >> as the same code in the exe. Does anyone know what could be the reason > >> for this behaviour? > > > If the runtime of the C/C++ code is short, the time spent initializing > > the Python interpreter might have a big impact on the runtime of the > > Python version. > > The runtime is about 2.5 sec and 5.0 sec respectively. I not only use > the time command to measure the time consumed but I also measure the > time within the C-code using clock() and get similar result. So the > Python startup time is not the reason for the runtime difference I > found. Thank you anyway. We can't really help you much unless you give us more details about what you did (how did you built it, how did you time it, and how are you calling the C extension from Python). All we can do is throw out possible ideas, and I will toss out a few, but if that's not it you'll have to post details. Are you building the extension with the same optimization flags as the compiler? Are you calling the C code repeatedly from inside a Python loop? From rcdailey at gmail.com Tue Jun 23 19:57:36 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Tue, 23 Jun 2009 16:57:36 -0700 (PDT) Subject: Forwarding keyword arguments Message-ID: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Suppose I have 2 functions like so: def Function2( **extra ): # do stuff def Function1( **extra ): Function2( extra ) As you can see, I would like to forward the additional keyword arguments in variable 'extra' to Function2 from Function1. How can I do this? I'm using Python 3.0.1 From david.lyon at preisshare.net Tue Jun 23 20:09:25 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 23 Jun 2009 20:09:25 -0400 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: <56c405e7af4de7e14ae05ebd9e5f4a4b@preisshare.net> On Wed, 24 Jun 2009 00:55:14 +0100, duncan smith wrote: > Does anyone know how I can configure Boa to use wxPython 2.8.9.1? Does > anyone know if it's possible to configure the Python version under SPE? It definitely is possible. In fact you need to use wxpython 2.8 with Boa. I had a similar problem under some ubuntu version. You can install 2.6 and 2.8 wxpython. But from memory there is a wxversion ubuntu package also. I had to do some "force"ing as there seemed to be circular dependencies. In the end I got it to work just fine... David From apt.shansen at gmail.com Tue Jun 23 20:25:47 2009 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 23 Jun 2009 17:25:47 -0700 Subject: Forwarding keyword arguments In-Reply-To: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <7a9c25c20906231725s2e987849pc1928500f28e6ae5@mail.gmail.com> > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 def Function1(**extra): Function2(**extra) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Jun 23 20:34:23 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Jun 2009 21:34:23 -0300 Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey escribi?: > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 Function2(**extra) See http://docs.python.org/3.0/reference/expressions.html#calls -- Gabriel Genellina From rcdailey at gmail.com Tue Jun 23 20:45:00 2009 From: rcdailey at gmail.com (Robert Dailey) Date: Tue, 23 Jun 2009 17:45:00 -0700 (PDT) Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <46c60603-f026-4061-a616-b12adfca7d3d@w40g2000yqd.googlegroups.com> On Jun 23, 7:34?pm, "Gabriel Genellina" wrote: > En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey ? > escribi?: > > > Suppose I have 2 functions like so: > > > def Function2( **extra ): > > ? ?# do stuff > > > def Function1( **extra ): > > ? ?Function2( extra ) > > > As you can see, I would like to forward the additional keyword > > arguments in variable 'extra' to Function2 from Function1. How can I > > do this? I'm using Python 3.0.1 > > Function2(**extra) > Seehttp://docs.python.org/3.0/reference/expressions.html#calls > > -- > Gabriel Genellina Thanks for the answer. I did look through the docs but I missed it I guess. From ben+python at benfinney.id.au Tue Jun 23 20:57:18 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Jun 2009 10:57:18 +1000 Subject: Forwarding keyword arguments References: <8819f648-105c-4c12-b5aa-08439dd38677@y7g2000yqa.googlegroups.com> Message-ID: <87zlbywis1.fsf@benfinney.id.au> Robert Dailey writes: > Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) (Style note: The Python style guide, PEP 8, would have the above code written as:: def function2(**extra): # do stuff def function1(**extra): function2(extra) See for a sensible style guide for Python code.) > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Python 3.0.1 The syntax for ?collect remaining positional arguments into a sequence? in a function definition versus ?unpack the values from this sequence into positional arguments? in a function call are intentionally similar:: def bar(spam, eggs, beans): pass def foo(*args): bar(*args) Likewise for the syntax for ?collect remaining keyword arguments into a mapping? in a function definition versus ?unpack the items from this mapping into keyword arguments? in a function call:: def function2(spam, eggs, beans): pass def function1(**kwargs): function2(**kwargs) For more detail, see the language reference section explaining calls . -- \ ?A society that will trade a little liberty for a little order | `\ will lose both, and deserve neither.? ?Thomas Jefferson, in a | _o__) letter to Madison | Ben Finney From torriem at gmail.com Tue Jun 23 21:24:16 2009 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Jun 2009 19:24:16 -0600 Subject: [Mac] file copy In-Reply-To: References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: <4A418040.1070503@gmail.com> Tobias Weber wrote: > Why "so"? shutil does not use bin/cp! That's good to know. I had always thought that that was what shutils did, but you're right; it does not. That said, since cp indeed *can* copy resource forks on Tiger and up, you could use subprocess to call it. Just as an aside, your response to a couple of the suggestions in this thread has been a bit brusque, even given the normal limits of e-mail communications. While it's true that nothing so far has been quite what you wanted, I'm sure that everyone has certainly tried to help you find a solution by throwing out different ideas! It is also true that for many people resources forks are not at all necessary, which is probably why someone mentioned that before, perhaps hoping to save you work. Anyways, I certainly hope you do get something working. From steven at REMOVE.THIS.cybersource.com.au Tue Jun 23 22:20:11 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Jun 2009 02:20:11 GMT Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: > Steven D'Aprano wrote: > >> Lawrence D'Oliveiro wrote: >> >>>> Ok, now pipe ls to less, take three days to browse through all the >>>> filenames to locate the file you want to see. >>> >>> Sounds like you're approaching the issue with a GUI-centric mentality, >>> which is completely hopeless at dealing with this sort of situation. >> >> Piping the output of ls to less is a GUI-centric mentality? > > Yeah. The "dump it on the user" idea, or more politely "can't decide > anything until the user has seen everything" is evident in the most > "characteristic" GUIs. Perhaps you're using different GUIs to me. In my experience, most GUIs tend to *hide* data from the user rather than give them everything under the sun. The classic example is Windows, which hides certain files in the GUI file manager even if you tell it to show all files. -- Steven From egrefen at gmail.com Tue Jun 23 22:54:10 2009 From: egrefen at gmail.com (Edward Grefenstette) Date: Tue, 23 Jun 2009 19:54:10 -0700 (PDT) Subject: Trouble with running java using Popen References: <7ad39tF1uued4U1@mid.uni-berlin.de> Message-ID: Bingo. I was running the python script in GNU script, and it wasn't loading my bash config file properly. Have fixed it by altering .screenrc and now the code runs fine. Would have never guessed to look if you hadn't mentioned it, cheers! Best, Ed On Jun 23, 11:29?pm, "Diez B. Roggisch" wrote: > Edward Grefenstette schrieb: > > > > > I have a java prog I need to run at some point during the execution of > > a python module. > > > The path to the folder containing the all the relevant java stuff > > (which runs fine from the command line) is stored in pkgpath. The > > relevant code is this: > > >>>> os.chdir(pkgpath) > >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath > >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True) > >>>> SemVectPackage.wait() > > > Here indexpath is the path to a particular index file (usually > > indexpath = "./indexfolder/fileindex"), so that effectively Popen > > should be running the equivalent of the shell command: > > - > > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex > > - > > which, again, runs fine in the terminal. > > > However running the program returns the following error (echoed from > > shell, doesn't interrupt prog): > > - > > Exception in thread "main" java.lang.NoClassDefFoundError: > > SemanticVectorsEvaluator > > - > > > I have no idea why this isn't working. Anyone have any suggestions as > > to how I might troubleshoot this? > > I'd say you got an CLASSPATH-issue here. You can add that explicitly via > env as argument to Popen, or pass it via commandline-args. > > Diez From aahz at pythoncraft.com Tue Jun 23 23:02:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:02:11 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: In article , Mark Dickinson wrote: >On Jun 22, 7:43=A0pm, David C. Ullrich wrote: >> >> Surely you don't say a curve is a subset of the plane and >> also talk about the integrals of verctor fields over _curves_? >> [snip rest of long response that needs a decent reply, but >> possibly not here... ] > >I wonder whether we can find a better place to have this discussion; I >think there are still plenty of interesting things to say, but I fear >we're rather abusing the hospitality of comp.lang.python at the moment. As long as it's confined to this thread, I certainly have no objection; right now, this thread is occupying only a small fractin of c.l.py bandwidth. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From kay at fiber-space.de Tue Jun 23 23:06:16 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Tue, 23 Jun 2009 20:06:16 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: On 24 Jun., 00:59, smartmobili wrote: > I wanted to know if you have some patch to compile python 3.x on mingw > platform because I found some > but doesn't work very well : > > make > > gcc -o python.exe \ > Modules/python.o \ > libpython3.0.a -lm > Could not find platform independent libraries > Could not find platform dependent libraries > Consider setting $PYTHONHOME to [:] > Fatal Python error: Py_Initialize: can't initialize sys standard > streams > ImportError: No module named encodings.utf_8 > > I have some questions about posixmodule.c, config.c and makesetup, > I can see in posixmodule that you define a INITFUNC like this : > > #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined > (__BORLANDC__)) && > !defined(__QNX__) > #define INITFUNC PyInit_nt > #define MODNAME "nt" > > #elif defined(PYOS_OS2) > #define INITFUNC PyInit_os2 > #define MODNAME "os2" > > #else > #define INITFUNC PyInit_posix > #define MODNAME "posix" > #endif > > So first I tried to add || defined(____MINGW32____) to declare a > PyInit_nt > but after config.c > was still using PyInit_posix. How does makesetup choose to include one > function or another ? > So finally python is using PyInit_posix... > > and after any idea why I got the compilation error ? Why on earth do you want to compile Python 3.0.1? From aahz at pythoncraft.com Tue Jun 23 23:08:18 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:08:18 -0700 Subject: Beauty and Fitness References: <7a73lrF1totcrU2@mid.uni-berlin.de> Message-ID: In article <7a73lrF1totcrU2 at mid.uni-berlin.de>, Diez B. Roggisch wrote: > >My god, these days they allow just anybody to spam, even f***tards that >are to stupid to include the actual URL of the spam they want to divulge. Thank you for reposting the spam in its entirety, with special thanks for munging your address so I can't even chide you privately. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 23:09:30 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:09:30 -0700 Subject: urllib2 urlopen takes too much time References: Message-ID: In article , =?UTF-8?Q?Filip_Gruszczy=C5=84ski?= wrote: > >I have encountered a performance problem using suds, which was traced >down to _socket.recv. I am calling some web services and each of them >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen, >while the rest of the call is finished in milliseconds. What happens if you use urlopen() by itself? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Tue Jun 23 23:13:37 2009 From: aahz at pythoncraft.com (Aahz) Date: 23 Jun 2009 20:13:37 -0700 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: In article , Ross Ridge wrote: >Aahz wrote: >>Piet van Oostrum wrote: >>> >>>>I notice that I see several postings on news:comp.lang.python that are >>>replies to other postings that I don't see. >> >>As stated previously, my suspicion is that at least some is caused by a >>problem with MIME messages and the mail->news gateway on python.org. > >I'm not sure what MIME would have to do with it, but Piet van Oostrum's >problem is almost certainly as result of the python.org mail to news >gateway mangling the References header. The missing postings he's looking >for don't actually exist. Just go up the thread one more posting and >you'll find the message that was being replied to. While that's also a bug in Mailman (I have a long-standing to-do item to fix that), there are also plenty of posts that simply aren't showing up in c.l.py. As I said, I'm pretty sure (based on what was happening with c.l.py.announce) that it's some kind of weird problem with the mail->news gateway with MIME posts. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From lie.1296 at gmail.com Tue Jun 23 23:30:54 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 03:30:54 GMT Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: duncan smith wrote: > I've just upgraded to Jaunty Jackalope where Python 2.6 is the default > Python version. I'm still developing under 2.5, but IDLE now refuses to > respond to left click events (for code editing, menus etc. respond as > expected). If I right click, then left click I can move the cursor, but > that's not ideal. For the meantime, you should search/file a bug report on Launchpad (Ubuntu's bugtracker) on: https://launchpad.net/ubuntu/ if you haven't already done so. I just tried idle 2.6 (python 2.6, Tk 8.4) on Gentoo, and left-clicking seems to run fine (although I'm a bit unclear on what kinds of left-clicking IDLE refuses to respond to). On the reports to Launchpad, don't forget to include the versions of python, idle, and Tk as reported on Help > About. From steven.samuel.cole at gmail.com Wed Jun 24 00:48:18 2009 From: steven.samuel.cole at gmail.com (ssc) Date: Tue, 23 Jun 2009 21:48:18 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> Message-ID: <13e776b0-6ca8-479e-ba82-eb5b7eb8f445@a5g2000pre.googlegroups.com> On Jun 18, 10:49?am, Jon Clements wrote: > Why are you doing this? I'm assuming a code to title look up is > required (don't forget military, royal and honorable titles > etc... :) ) I'm in New Zealand. Hardly any need for military titles, rarely any for royal and damn sure none for honorable :-D (scnr) From gdamjan at gmail.com Wed Jun 24 01:02:33 2009 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Wed, 24 Jun 2009 07:02:33 +0200 Subject: Best way to enumerate classes in a module Message-ID: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> I need to programmaticaly enumerate all the classes in a given module. Currently I'm using dir(module) but the Notice on the documentation page [1] says "dir() is supplied primarily as a convenience for use at an interactive prompt" so that kind of scares me. Is there a better approach? If there is, how do I get all the classes of the current module? [1] http://docs.python.org/library/functions.html#dir -- ?????? ( http://softver.org.mk/damjan/ ) Q: What's tiny and yellow and very, very, dangerous? A: A canary with the super-user password. From ldo at geek-central.gen.new_zealand Wed Jun 24 01:08:57 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Jun 2009 17:08:57 +1200 Subject: walking a directory with very many files References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: In message , Steven D'Aprano wrote: > On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: > >> Steven D'Aprano wrote: >> >>> Lawrence D'Oliveiro wrote: >>> >>>>> Ok, now pipe ls to less, take three days to browse through all the >>>>> filenames to locate the file you want to see. >>>> >>>> Sounds like you're approaching the issue with a GUI-centric mentality, >>>> which is completely hopeless at dealing with this sort of situation. >>> >>> Piping the output of ls to less is a GUI-centric mentality? >> >> Yeah. The "dump it on the user" idea, or more politely "can't decide >> anything until the user has seen everything" is evident in the most >> "characteristic" GUIs. > > Perhaps you're using different GUIs to me. In my experience, most GUIs > tend to *hide* data from the user rather than give them everything under > the sun. Which is getting a bit away from what we're discussing here, but certainly it is characteristic of GUIs to show you all 400,000 files in a directory, or at least try to do so, and either hang for half an hour or run out of memory and crash, rather than give you some intelligent way of prefiltering the file display up front. From chris at simplistix.co.uk Wed Jun 24 02:30:56 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 07:30:56 +0100 Subject: I look for private Python Index server on my local network... What do you use ? In-Reply-To: References: Message-ID: <4A41C820.9030303@simplistix.co.uk> Klein St?phane wrote: > I wonder what Python Index server (like as pypi.python.org) do you use in > your corporation for handle your private python eggs ? > > I found three solutions : > > * http://pypi.python.org/pypi/basketweaver/0.1.2-r6 > * http://pypi.python.org/pypi/pypi/2005-08-01 > * http://pypi.python.org/pypi/EggBasket/0.6.1b > > Do you know another software ? http://pypi.python.org/pypi/haufe.eggserver/0.2.5 > What do you use ? I actually just store the private eggs directly in a subversion repository and that the url of the folder the eggs live in to find-links. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Wed Jun 24 02:37:23 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 07:37:23 +0100 Subject: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009 In-Reply-To: <1245441343.32055.2.camel@jesterj-laptop> References: <4A3A5F66.2030701@simplistix.co.uk> <1245441343.32055.2.camel@jesterj-laptop> Message-ID: <4A41C9A3.5050602@simplistix.co.uk> Jeremiah Jester wrote: > Chris, > Do you have any online tutorial for this topic? I'm afraid not currently... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Wed Jun 24 02:37:54 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 08:37:54 +0200 Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. > > Is there a better approach? > > If there is, how do I get all the classes of the current module? inspect.getmembers(module, inspect.isclass), but this uses dir() internally. You may have to remove imported classes: >>> def getclasses(module): ... def accept(obj): ... return inspect.isclass(obj) and module.__name__ == obj.__module__ ... return [class_ for name, class_ in inspect.getmembers(module, accept)] ... >>> getclasses(inspect) [, , ...] Peter From chris at simplistix.co.uk Wed Jun 24 03:13:01 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 08:13:01 +0100 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> Message-ID: <4A41D1FD.7080004@simplistix.co.uk> Terry Reedy wrote: > Mag Gam wrote: >> Yes, the system has 64Gig of physical memory. > > drool ;-). Well, except that, dependent on what OS he's using, the size of one process may well still be limited to 2GB... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From Tim.Couper at standardbank.com Wed Jun 24 03:15:06 2009 From: Tim.Couper at standardbank.com (Couper, Tim T) Date: Wed, 24 Jun 2009 08:15:06 +0100 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Your prof. may find this thread of interest http://mail.python.org/pipermail/python-list/2000-June/039779.html My experience is that developers who know C and C++ can be productive in less than 1 week in python, and find it liberating, and educational, to do so. And at the same time they will have added a second language to their toolbox. As Kurt points out, learning C/C++ takes considerably longer (weeks/months to attain a level of competence). Python is now used in a number of universities as the language in which to teach comp sci undergraduate courses (I know of Leeds, & MIT), biomathematics, and my daughter just finished her PhD in speech and language processing at Edinburgh .. using python and Matplotlib .. as the extensive C/C++ libraries in that infomatics world are wrapped in python - and the MSc Comp Sci course has replaced Java as the language for teaching with Python. Dr Tim Couper -----Original Message----- From: python-list-bounces+tim.couper=standardbank.com at python.org [mailto:python-list-bounces+tim.couper=standardbank.com at python.org] On Behalf Of Kurt Smith Sent: 23 June 2009 16:50 Cc: python-list at python.org Subject: Re: Converting Python code to C/C++ On Mon, Jun 22, 2009 at 9:49 PM, Andras Pikler wrote: > Hi! > > > > Short: I need to turn a Python program that I (mostly) wrote into C > code, and I am at a loss. > > > > Long: I'm doing research/programming for a professor, and we are > working with MIDI files (a type of simple music file). The research > deals with generating variations from a musical melody; currently, my > Python code uses a Python midi package I found online to read the > notes in question from a midi file, about 350 lines of my own code to > generate a variation based on these notes and the professor's > algorithms, and finally the package again to write the new melody to another midi file. > > > > Now, my professor would like to have this exact code in C/C++, as she > believes C is more compatible with MATLAB, and wants the code to be > available in multiple languages in case a programmer works for her in > the future who knows C but not Python. While I know a tiny bit of C > (emphasis on the tiny), I would much prefer if there were some sort of > automatic compiler I could use to turn my Python code into C than > taking a week or two or three to learn the minimum I need about C, > find a way to access MIDI files in it, and rewrite all of my code. > > > > After some googling, I found and tried Shedskin, but it doesn't work, > as the Python midi package I'm using uses modules which Shedskin does not support. > Otherwise, I haven't found much. Is there anything out there to help > me do this? If not, from anyone who has experience in this regard, how > daunting should I expect this to be? Taking on C from a cold start and being able to handle the ins and outs of interfacing with Python isn't something that's feasible in 'two or three weeks'. Here are a couple of options -- take 'em or leave 'em: 1) Put the code in Cython: http://www.cython.org/ (full disclosure: I'm doing a GSoC project with Cython). It will convert pretty much any python code into C code (even closures are supported in the most recent version, I think), and the C code can then be compiled into an extension module. The only problem with the above is the C code isn't, at first blush, easy to read. Nor is it supposed to be changed by the user. So that leads us to option... 2) Write the core functionality in C yourself, and then wrap those C functions in Cython. You'll want to take a look at the documentation: http://docs.cython.org/ and, more specifically on wrapping C code: http://docs.cython.org/docs/external_C_code.html I don't think you'll be able to avoid learning C, though. Kurt -- http://mail.python.org/mailman/listinfo/python-list ***************************************************************************** This communication is sent by the Standard Bank Plc or one of its affiliates The registered details of Standard Bank Plc are: Registered in England No. 2130447, Registered Office 25 Dowgate Hill London EC4R 2SB Authorised and Regulated by the Financial Services Authority. More information on Standard Bank is available at www.standardbank.com Everything in this email and any attachments relating to the official business of Standard Bank Group Limited and any or all subsidiaries, the Company, is proprietary to the Company. It is confidential, legally privileged and protected by relevant laws. The Company does not own and endorse any other content. Views and opinions are those of the sender unless clearly stated as being that of the Company. The person or persons addressed in this email are the sole authorised recipient. Please notify the sender immediately if it has unintentionally, or inadvertently reached you and do not read, disclose or use the content in any way and delete this e-mail from your system. The Company cannot ensure that the integrity of this email has beenmaintained nor that it is free of errors, virus, interception or interference. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. ***************************************************************************** From usernet at ilthio.net Wed Jun 24 03:17:33 2009 From: usernet at ilthio.net (Tim Harig) Date: Wed, 24 Jun 2009 07:17:33 GMT Subject: wikipedia with python References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: On 2009-06-22, ZeLegolas wrote: > On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels > wrote: >> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >>> I'm looking for wiki writen with python where I can import all >>> wikipedia site. >> PHP. >> What do you want to use the material for? > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. To clarify, check one: [ ] A. You already have mediawiki wiki running on a web server; but, you would prefer to have your wiki power by Python. [ ] B. You already have mediawiki running on a web server and you have another wiki powered by Python; and, you would like to take the information from the python powered wiki and copy it to the mediawiki. [ ] C. You already have mediawiki running on a web server and you would also like to use the functionality of a wiki which is written in Python. Somehow, you would like to somehow access some of the Python's functionality and use it from inside of mediawiki. Perhaps making them work side by side. [ ] D. You already have mediawiki running on a webserver; but, you would like to get data from another mediawiki server that you don't have direct database access to; so, you would like to write a script in Python to scrape the data off of the other mediawiki's website. [ ] E. You already have a wiki running in python on a webserver and you would like to import data from another wiki that is powered by mediawiki. You might or might not have direct access to the database used by the wikimedia server. You would like a Python script to convert/scrap the data. [ ] F. Other From sjmachin at lexicon.net Wed Jun 24 03:18:47 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 00:18:47 -0700 (PDT) Subject: re.NONE References: Message-ID: <40123fe2-e0a8-4f24-95f2-225171f08fd0@o21g2000prn.googlegroups.com> On Jun 23, 8:35?am, 1x7y2z9 <1x7y... at gmail.com> wrote: > I am currently using python v2.5.2. > > Not sure if this is defined in a later version, but it would be nice > to define re.NONE = 0 in the re module. ?This would be useful in cases > such as: > flags = re.DOTALL if dotall else re.NONE > > Also useful for "building up" flags by ORing with other flags. -1 0 is even more useful. YAGNI. BTW everybody try typing NONE a few times fast ... if your fingers don't fight your brain and produce None anyway, you haven't been using Python long enough :-) From lie.1296 at gmail.com Wed Jun 24 03:30:24 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 07:30:24 GMT Subject: walking a directory with very many files In-Reply-To: References: <5f51bc62-16fb-4e24-ac6c-1e5ea3ee596c@d38g2000prn.googlegroups.com> <234b19ac-7baf-4356-9fe5-37d00146d982@z9g2000yqi.googlegroups.com> <20090617091858.432f89ca@malediction> <20090617110705.7e7c423f@malediction> <%Zv_l.19493$y61.5958@news-server.bigpond.net.au> <0058d36a$0$9759$c3e8da3@news.astraweb.com> Message-ID: Lawrence D'Oliveiro wrote: > In message , Steven > D'Aprano wrote: > >> On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote: >> >>> Steven D'Aprano wrote: >>> >>>> Lawrence D'Oliveiro wrote: >>>> >>>>>> Ok, now pipe ls to less, take three days to browse through all the >>>>>> filenames to locate the file you want to see. >>>>> Sounds like you're approaching the issue with a GUI-centric mentality, >>>>> which is completely hopeless at dealing with this sort of situation. >>>> Piping the output of ls to less is a GUI-centric mentality? >>> Yeah. The "dump it on the user" idea, or more politely "can't decide >>> anything until the user has seen everything" is evident in the most >>> "characteristic" GUIs. >> Perhaps you're using different GUIs to me. In my experience, most GUIs >> tend to *hide* data from the user rather than give them everything under >> the sun. > > Which is getting a bit away from what we're discussing here, but certainly > it is characteristic of GUIs to show you all 400,000 files in a directory, > or at least try to do so, and either hang for half an hour or run out of > memory and crash, rather than give you some intelligent way of prefiltering > the file display up front. In many debugging cases, you don't even know what to filter, which is what I was referring to when I said "Even with glob and grep ..." For example, when the problem mysteriously disappears when the file is isolated From andreengels at gmail.com Wed Jun 24 03:34:25 2009 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Jun 2009 09:34:25 +0200 Subject: wikipedia with python In-Reply-To: References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: <6faf39c90906240034w4694b166ud006a02d53ed9722@mail.gmail.com> On Wed, Jun 24, 2009 at 9:17 AM, Tim Harig wrote: > [ ] D. You already have mediawiki running on a webserver; but, you would > ? ? ? ?like to get data from another mediawiki server that you don't have > ? ? ? ?direct database access to; so, you would like to write a script in > ? ? ? ?Python to scrape the data off of the other mediawiki's website. In case D (and more general, to anyone who wants to do something to a Mediawiki wiki using Python), you can use the Python Wikipediabot Framework, http://pywikipediabot.sourceforge.net/ -- Andr? Engels, andreengels at gmail.com From lie.1296 at gmail.com Wed Jun 24 03:38:17 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 07:38:17 GMT Subject: wikipedia with python In-Reply-To: References: <9be383cc-6ae4-4fa4-9029-a6b48826b343@e21g2000yqb.googlegroups.com> <6faf39c90906221023h3383be3fy783d6276eb1b4470@mail.gmail.com> Message-ID: ZeLegolas wrote: > On Mon, 22 Jun 2009 19:23:59 +0200, Andre Engels > wrote: >> On Mon, Jun 22, 2009 at 6:58 PM, zelegolas wrote: >>> Let me know if it's the right place to ask. >>> >>> I'm looking for wiki writen with python where I can import all >>> wikipedia site. >>> If you have any links please let me know. >> I don't think that's possible. If you wnat to import Wikipedia in a >> wiki, it will probably have to be MediaWiki - and that's written in >> PHP. >> >> What do you want to use the material for? > > Well sorry I was not clear. I have a wiki running with mediawiki and I want > to import in a wiki written with python. > Is there anything insufficient in mediawiki, that you think could be satisfied with a python-based wiki? MediaWiki is one of the best wiki software around, so any features not found in MediaWiki or its plugins isn't likely to be available in another wiki (unless "written in a language I know" is considered a feature). From lele at metapensiero.it Wed Jun 24 03:41:05 2009 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 24 Jun 2009 09:41:05 +0200 Subject: GNUstep and Python References: <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <1245616107.3797.3.camel@linux-3eb6.site> <7a7l9kF1tv7viU1@mid.uni-berlin.de> Message-ID: <87iqimaxke.fsf@nautilus.homeip.net> Eric Brunel writes: > Diez B. Roggisch wrote: >> Paul Watson schrieb: >> There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep. > > Apparently, it's not: There was some compatibility in earlier versions, but > it's been officially removed in version 2.0. See > http://pyobjc.sourceforge.net/NEWS-2.0.html : > "GNUstep support has been removed because this has never worked properly, > nobody seems interested in fixing that and the internal APIs of PyObjC have > changed greatly." It's been a lot of time ago, but that is wrong: when I initially implemented PyObjC I put a lot of effort in understanding the differences between the NeXT and the GNU ObjC runtimes, and PyObjC used to work ok on both, with a slight bias toward the GNU runtime (having the source at hands helps, as you know :-) Version 2.0 brought major changes to the internals, mainly to support the new MacOS frameworks, with tools to automatically create the needed glue interfaces between the two worlds. Too bad I wasn't involved/motivated enough to keep the GNU runtime support up-to-date, and it was finally declared obsolete and removed. Just a few cents of clarity, ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at nautilus.homeip.net | -- Fortunato Depero, 1929. From sjmachin at lexicon.net Wed Jun 24 03:48:41 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 00:48:41 -0700 (PDT) Subject: re.NONE References: <40123fe2-e0a8-4f24-95f2-225171f08fd0@o21g2000prn.googlegroups.com> Message-ID: <31f9e5bd-ee8f-471f-809c-18af74726833@v23g2000pro.googlegroups.com> On Jun 24, 5:18?pm, John Machin wrote: > On Jun 23, 8:35?am, 1x7y2z9 <1x7y... at gmail.com> wrote: > > > I am currently using python v2.5.2. > > > Not sure if this is defined in a later version, but it would be nice > > to define re.NONE = 0 in the re module. ?This would be useful in cases > > such as: > > flags = re.DOTALL if dotall else re.NONE > > > Also useful for "building up" flags by ORing with other flags. > > -1 > > 0 is even more useful. YAGNI. > > BTW everybody try typing NONE a few times fast ... if your fingers > don't fight your brain and produce None anyway, you haven't been using > Python long enough :-) Oh and I forgot to mention that if this proposal goes ahead it will need a one-letter version -- perhaps re.Z -- and maybe even a PEP. It could end up rivalling the legendary IEFBR14 in the ratio-of-overhead- to-functionality stakes. From pavlovevidence at gmail.com Wed Jun 24 03:49:34 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 00:49:34 -0700 (PDT) Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: On Jun 23, 10:02?pm, ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] ?says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. > > Is there a better approach? > > If there is, how do I get all the classes of the current module? You can use module.__dict__.values() (or .itervalues()) to retrieve the contents of the module (and of course .keys() if you want names). If you want to check the same module that the code appears in, use globals() instead of module.__dict__. Something makes me think that module.__dict__ was only added to Python fairly recently, but I'm not sure. A word of warning (although I would guess you are already aware of these issues, but for other readers): this method can't tell the difference between a class defined in the module and a class imported into it. Finally, despite the warning, I think you are ok to use dir() for that purpose. It's not likely to change. Carl Banks From mail at microcorp.co.za Wed Jun 24 04:08:36 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 24 Jun 2009 10:08:36 +0200 Subject: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: <008301c9f4a3$2fcd4c80$0d00a8c0@Hendrik> "Aahz" wrote: > While that's also a bug in Mailman (I have a long-standing to-do item to > fix that), there are also plenty of posts that simply aren't showing up > in c.l.py. As I said, I'm pretty sure (based on what was happening with > c.l.py.announce) that it's some kind of weird problem with the mail->news > gateway with MIME posts. I have lately had some posts returned with a "seems to be forged" message. Two reasons for that: - first is if I use the smtp server from our local telco - saix - then there is no apparent relationship between where the message comes from and where it comes from, if you follow my Irish... - Second is if the same telco assigns me an IP that has been put on a list of bad boy IPs. So it is kind of pot luck if you see this message or not. - Hendrik From pdpinheiro at gmail.com Wed Jun 24 05:12:05 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 02:12:05 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> On Jun 23, 6:49?pm, Lie Ryan wrote: > Mark Dickinson wrote: > > On Jun 23, 3:52 am, Steven D'Aprano > > wrote: > >> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > >>> In my universe the standard definition of "log" is different froim what > >>> log means in a calculus class > >> Now I'm curious what the difference is. > > > It's just the usual argument about whether 'log' means > > log base 10 or log base e (natural log). ?At least in the > > US, most[*] calculus texts (and also most calculators), > > for reasons best known to themselves, use 'ln' to mean > > natural log and 'log' to mean log base 10. ?But most > > mathematicians use 'log' to mean natural log: ?pick up a > > random pure mathematics research paper that has the word > > 'log' in it, and unless it's otherwise qualified, it's > > safe to assume that it means log base e. ?(Except in the > > context of algorithmic complexity, where it might well > > mean log base 2 instead...) > > I usually use log without explicit base only when the base isn't > relevant in the context (i.e. when whatever sane base you put in it > wouldn't really affect the operations). In algorithmic complexity, a > logarithm's base doesn't affect the growth shape and, like constant > multiplier, is considered irrelevant to the complexity. > > > Python also suffers a bit from this confusion: ?the > > Decimal class defines methods 'ln' and 'log10', while > > the math module and cmath modules define 'log' and > > 'log10'. ? > > In fact, in the Decimal class there is no log to an arbitrary base. > > > (But the Decimal module has other problems, > > like claiming that 0**0 is undefined while > > infinity**0 is 1.) > > Well, in math inf**0 is undefined. Since python is programming language, > and in language standards it is well accepted that undefined behavior > means implementations can do anything they like including returning 0, > 1, 42, or even spitting errors, that doesn't make python non-conforming > implementation. > > A more serious argument: in IEEE 745 float, inf**0 is 1. Mathematic > operation in python is mostly a wrapper for the underlying C library's > sense of math. > > > > > [*] A notable exception is Michael Spivak's 'Calculus', which also > > happens to be the book I learnt calculus from many years ago. Well, AFAIK Python defines CPython as the standard. So whatever CPython does is the defined behaviour. Regarding inf ** 0, why does IEEE745 define it as 1, when there is a perfectly fine NaN value? From shelika.void at gmail.com Wed Jun 24 05:39:32 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 02:39:32 -0700 (PDT) Subject: Dictionary self lookup Message-ID: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Hi all. Assuming that python dictionaries already provide a bit of "shoot yourself in the foot", I think what I have in mind would not be so bad. What do you think of dictionaries having a self lookup in their declaration? Be able to do this: a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax instead of: a = { "foo" : "foo1" } a["bar"] = a["foo"] Maybe I'm murdering python syntax/philosophy right here so let me know if that's the case. I was thinking this could probably be done in python abstract tree but as I never looked into it I may be wrong. I'm willing to make the effort, provided I get some directions and that this idea is worth it. Any feedback is welcome. Cheers, Norberto From NoEmail at NoDomain.com Wed Jun 24 05:42:59 2009 From: NoEmail at NoDomain.com (saurabh) Date: Wed, 24 Jun 2009 14:42:59 +0500 Subject: Open source python projects References: <4a3fde13$0$48239$14726298@news.sunsite.dk> Message-ID: Thanks a lot everyone for your prompt replies. I am really glad to see so many options for me. I am sure joining any of the above projects will enrich my understanding of python and programming.I will just have to find out , to which project I will be most useful.I will definitely join one of them. -Saurabh From v.richomme at gmail.com Wed Jun 24 05:55:47 2009 From: v.richomme at gmail.com (smartmobili) Date: Wed, 24 Jun 2009 02:55:47 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: <82ca7daf-b6e9-4601-87db-a1b94c8eb7c2@f10g2000vbf.googlegroups.com> On 24 juin, 05:06, Kay Schluehr wrote: > On 24 Jun., 00:59, smartmobili wrote: > > > > > > > > > I wanted to know if you have some patch to compile python 3.x on mingw > > platform because I found some > > but doesn't work very well : > > > ? ? make > > > gcc ? -o python.exe \ > > Modules/python.o \ > > libpython3.0.a ? ?-lm > > Could not find platform independent libraries > > Could not find platform dependent libraries > > Consider setting $PYTHONHOME to [:] > > Fatal Python error: Py_Initialize: can't initialize sys standard > > streams > > ImportError: No module named encodings.utf_8 > > > I have some questions about posixmodule.c, config.c and makesetup, > > I can see in posixmodule that you define a INITFUNC like this : > > > #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined > > (__BORLANDC__)) && > > !defined(__QNX__) > > #define INITFUNC PyInit_nt > > #define MODNAME "nt" > > > #elif defined(PYOS_OS2) > > #define INITFUNC PyInit_os2 > > #define MODNAME "os2" > > > #else > > #define INITFUNC PyInit_posix > > #define MODNAME "posix" > > #endif > > > So first I tried to add || defined(____MINGW32____) to declare a > > PyInit_nt > > but after config.c > > was still using PyInit_posix. How does makesetup choose to include one > > function or another ? > > So finally python is using PyInit_posix... > > > and after any idea why I got the compilation error ? > > Why on earth do you want to compile Python 3.0.1? Because I need python to be able to compile other libraries on mingw (subcersion, ....). From deets at nospam.web.de Wed Jun 24 05:59:13 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 11:59:13 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <7aebgaF1up16pU1@mid.uni-berlin.de> Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. What kind of foot-shooting do you have in mind? > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. Obviously the proposed syntax can't work, as at the time of the dictionary construction the name the dict is bound to is either not known, or even bound to *another* dict. Additionally, the code would be by no means more efficient than the above "long" version, as whatever notation you chose, it won't help to deal with the fact that the dict-object itself, and also a potentially reference key, aren't already available. So behind the curtain, the exact same logic would apply, with all runtime-costs. Which leaves us with the question: why the heck do you want this? Diez From clp2 at rebertia.com Wed Jun 24 06:05:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 03:05:40 -0700 Subject: Dictionary self lookup In-Reply-To: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <50697b2c0906240305h6ce621c1k677202e94d3c2664@mail.gmail.com> On Wed, Jun 24, 2009 at 2:39 AM, Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. The idea sounds quite confusing and seems unnecessary. Specifically, your proposal appears to contravene the following points of the holy Zen of Python: - Explicit is better than implicit. - Readability counts. - Special cases aren't special enough to break the rules. - In the face of ambiguity, refuse the temptation to guess. - If the implementation is hard to explain, it's a bad idea. Cheers, Chris -- http://blog.rebertia.com From deets at nospam.web.de Wed Jun 24 06:06:37 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 12:06:37 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <7aebu7F1uahjuU1@mid.uni-berlin.de> Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. I doubt this will ever be accepted, but out of curiosity: *why* do you want this? And if you are willing to put some constraints on you keys, it would be easy enough to do this: def wicked_dict(**kwargs): mappings = [(name, source) for name, source in kwargs.iteritems() if name.startswith("_") res = dict((key, value) for key, value in kwarges.iteritems() if not name.startswith("_")) for name, source in mappings: res[name] = res[source] return res Diez From shelika.void at gmail.com Wed Jun 24 06:21:48 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 03:21:48 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> Message-ID: <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: > Norberto Lopes wrote: > > Hi all. > > Assuming that python dictionaries already provide a bit of "shoot > > yourself in the foot", I think what I have in mind would not be so > > bad. > > What kind of foot-shooting do you have in mind? > a = { "foo" : { "bar" : "moo" }} a["bar"] = a["foo"] print a {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} a["foo"]["bar"] = a["foo"] print a {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} (I know it's not a C shoot in the foot or something but still...) > > > > > > > > What do you think of dictionaries having a self lookup in their > > declaration? > > > Be able to do this: > > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > > instead of: > > > a = { "foo" : "foo1" } > > a["bar"] = a["foo"] > > > Maybe I'm murdering python syntax/philosophy right here so let me know > > if that's the case. > > I was thinking this could probably be done in python abstract tree but > > as I never looked into it I may be wrong. I'm willing to make the > > effort, provided I get some directions and that this idea is worth it. > > > Any feedback is welcome. > > Obviously the proposed syntax can't work, as at the time of the dictionary > construction the name the dict is bound to is either not known With just more thatn syntactic sugar this could be done >, or even bound to *another* dict. > doh! Didn't thought about that one. Nice catch. > Additionally, the code would be by no means more efficient than the > above "long" version, as whatever notation you chose, it won't help to deal > with the fact that the dict-object itself, and also a potentially reference > key, aren't already available. > > So behind the curtain, the exact same logic would apply, with all > runtime-costs. > > Which leaves us with the question: why the heck do you want this? > Syntactic sugar basically. I'm not ranting about performance, just easier write up. config = {"home" : "/home/test", "user1": config["home"] + "/user1", "user2" : config["home"] + "/user2", "python-dev" : config["user1"] + "/Projects/py-dev" } config = {"home" : "/home/test"} config["user1"] = config["home"] + "/user1" config["user2"] = config["home"] + "/user2" config["python-dev"] = config["user1"] + "/py-dev" Now, if you change config["home"] you'd have to redo all of the other entries. With the first one (assuming pointers to the entries) everything would get updated. Although python does not handles dict keys/values this way. Now that I think of this there would be a lot more than just syntactic sugar for this. (ignore the path concatenation without os.path) From shelika.void at gmail.com Wed Jun 24 06:22:48 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 03:22:48 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <2256855f-9e11-4650-83b6-04dc60934869@n21g2000vba.googlegroups.com> On Jun 24, 12:05?pm, Chris Rebert wrote: > On Wed, Jun 24, 2009 at 2:39 AM, Norberto Lopes wrote: > > Hi all. > > Assuming that python dictionaries already provide a bit of "shoot > > yourself in the foot", I think what I have in mind would not be so > > bad. > > > What do you think of dictionaries having a self lookup in their > > declaration? > > > Be able to do this: > > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > > instead of: > > > a = { "foo" : "foo1" } > > a["bar"] = a["foo"] > > > Maybe I'm murdering python syntax/philosophy right here so let me know > > if that's the case. > > The idea sounds quite confusing and seems unnecessary. > > Specifically, your proposal appears to contravene the following points > of the holy Zen of Python: > > - Explicit is better than implicit. > - Readability counts. > - Special cases aren't special enough to break the rules. > - In the face of ambiguity, refuse the temptation to guess. > - If the implementation is hard to explain, it's a bad idea. > > Cheers, > Chris > --http://blog.rebertia.com Ok, no arguments against this one :( /agree From mail131 at gmail.com Wed Jun 24 06:23:30 2009 From: mail131 at gmail.com (Przemyslaw Bak) Date: Wed, 24 Jun 2009 03:23:30 -0700 (PDT) Subject: fileinput.input, readlines and ... Message-ID: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Hello, I many files with log data. The structure of the file is quite inconvenience and similar to the following example: Data1 ValueA Data2 ValueB Data3 ValueC ... To get the values I need to find Data* and then get to the next line. I tried to use fileinput.input : ... for line in fileinput.input(filename): if line.find("Data2") >= 0: (now what ?) So I can find the requested line (Data2) but how to get value from the next line ? Is the fileinput.input the most convenient for this type of task ? Maybe readline or readlines would be better ? What can you recommend ? Regards From nospam at invalid.invalid Wed Jun 24 06:34:24 2009 From: nospam at invalid.invalid (robert) Date: Wed, 24 Jun 2009 12:34:24 +0200 Subject: Windows: open() -> "[Errno 38] Filename too long" Message-ID: When doing open/os.stat/...(dirpath+filename) and total path > 250 chars then OSError: "[Errno 38] Filename too long" is there a way to access the file without changing to that directory (its in a thread and a fast iteration of many file too) ? From mail at timgolden.me.uk Wed Jun 24 06:43:34 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Jun 2009 11:43:34 +0100 Subject: Windows: open() -> "[Errno 38] Filename too long" In-Reply-To: References: Message-ID: <4A420356.2060701@timgolden.me.uk> robert wrote: > When doing open/os.stat/...(dirpath+filename) > and total path > 250 chars then > > OSError: "[Errno 38] Filename too long" > > is there a way to access the file without changing to that directory > (its in a thread and a fast iteration of many file too) ? Change filename r"c:\temp\long.txt" to ur"\\?\c:\temp\long.txt" TJG From dickinsm at gmail.com Wed Jun 24 07:02:33 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 24 Jun 2009 04:02:33 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> Message-ID: <298b6e65-9caf-4c5d-bb3b-b0627054fc28@j19g2000vbp.googlegroups.com> On Jun 24, 10:12?am, pdpi wrote: > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > perfectly fine NaN value? Have a look at: http://www.eecs.berkeley.edu/~wkahan/ieee754status/ieee754.ps (see particularly page 9). Mark From deets at nospam.web.de Wed Jun 24 07:21:30 2009 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Jun 2009 13:21:30 +0200 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> Message-ID: <7aegajF1uqhasU1@mid.uni-berlin.de> Norberto Lopes wrote: > On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: >> Norberto Lopes wrote: >> > Hi all. >> > Assuming that python dictionaries already provide a bit of "shoot >> > yourself in the foot", I think what I have in mind would not be so >> > bad. >> >> What kind of foot-shooting do you have in mind? >> > > a = { "foo" : { "bar" : "moo" }} > a["bar"] = a["foo"] > print a > {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} > a["foo"]["bar"] = a["foo"] > print a > {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} > > (I know it's not a C shoot in the foot or something but still...) And something working alike for lists and objects. Cyclic references are a fact of (programming)-life unless you go fully functional - and then you'd certainly miss it sometimes.. > config = {"home" : "/home/test"} > config["user1"] = config["home"] + "/user1" > config["user2"] = config["home"] + "/user2" > config["python-dev"] = config["user1"] + "/py-dev" > > > Now, if you change config["home"] you'd have to redo all of the other > entries. With the first one (assuming pointers to the entries) > everything would get updated. Although python does not handles dict > keys/values this way. Now that I think of this there would be a lot > more than just syntactic sugar for this. Things that are re-done usually are useful being put into a function. Then redoing becomes easier :) Diez From shelika.void at gmail.com Wed Jun 24 07:21:35 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 04:21:35 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: On Jun 24, 1:21?pm, "Diez B. Roggisch" wrote: > Norberto Lopes wrote: > > On Jun 24, 11:59?am, "Diez B. Roggisch" wrote: > >> Norberto Lopes wrote: > >> > Hi all. > >> > Assuming that python dictionaries already provide a bit of "shoot > >> > yourself in the foot", I think what I have in mind would not be so > >> > bad. > > >> What kind of foot-shooting do you have in mind? > > > a = { "foo" : { "bar" : "moo" }} > > a["bar"] = a["foo"] > > print a > > {'foo': {'bar': 'moo'}, 'bar': {'bar': 'moo'}} > > a["foo"]["bar"] = a["foo"] > > print a > > {'foo': {'bar': {...}}, 'bar': {'bar': {...}}} > > > (I know it's not a C shoot in the foot or something but still...) > > And something working alike for lists and objects. Cyclic references are a > fact of (programming)-life unless you go fully functional - and then you'd > certainly miss it sometimes.. > Yes. (and sometimes you miss functional :D) > > config = {"home" : "/home/test"} > > config["user1"] = config["home"] + "/user1" > > config["user2"] = config["home"] + "/user2" > > config["python-dev"] = config["user1"] + "/py-dev" > > > Now, if you change config["home"] you'd have to redo all of the other > > entries. With the first one (assuming pointers to the entries) > > everything would get updated. Although python does not handles dict > > keys/values this way. Now that I think of this there would be a lot > > more than just syntactic sugar for this. > > Things that are re-done usually are useful being put into a function. Then > redoing becomes easier :) > > Diez True. In any case, reading from your pov, it seems that the solution would cause more problems than solving one. Thanks for the feedback though. Much appreciated :) From __peter__ at web.de Wed Jun 24 07:32:32 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 13:32:32 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Przemyslaw Bak wrote: > Hello, > > I many files with log data. The structure of the file is quite > inconvenience and similar to the following example: > Data1 > ValueA > Data2 > ValueB > Data3 > ValueC > ... > To get the values I need to find Data* and then get to the next line. > I tried to use fileinput.input : > ... > for line in fileinput.input(filename): > if line.find("Data2") >= 0: > (now what ?) > > So I can find the requested line (Data2) but how to get value from the > next line ? lines = fileinput.input(filename) for line in lines: if "Data2" in line: print line.strip(), "-->", next(lines).strip() > Is the fileinput.input the most convenient for this type of task ? > Maybe > readline or readlines would be better ? > What can you recommend ? If you need more than a few name value pairs it pays to put the data in a dictionary first: # assuming that values always consist of a single line with open(filename) as instream: lines = (line.strip() for line in lines) lookup = dict(zip(lines, lines)) print lookup["Data2"] print lookup["Data3"] Peter From magawake at gmail.com Wed Jun 24 07:38:11 2009 From: magawake at gmail.com (Mag Gam) Date: Wed, 24 Jun 2009 04:38:11 -0700 Subject: Reading a large csv file In-Reply-To: <4A41D1FD.7080004@simplistix.co.uk> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> Sorry for the delayed response. I was trying to figure this problem out. The OS is Linux, BTW Here is some code I have: import numpy as np from numpy import * import gzip import h5py import re import sys, string, time, getopt import os src=sys.argv[1] fs = gzip.open(src) x=src.split("/") filename=x[len(x)-1] #Get YYYY/MM/DD format YYYY=(filename.rsplit(".",2)[0])[0:4] MM=(filename.rsplit(".",2)[0])[4:6] DD=(filename.rsplit(".",2)[0])[6:8] f=h5py.File('/tmp/test_foo/FE.hdf5','w') grp="/"+YYYY try: f.create_group(grp) except ValueError: print "Year group already exists" grp=grp+"/"+MM try: f.create_group(grp) except ValueError: print "Month group already exists" grp=grp+"/"+DD try: group=f.create_group(grp) except ValueError: print "Day group already exists" str_type=h5py.new_vlen(str) mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', 'f4', 'f4')} print "Filename is: ",src fs = gzip.open(src) dset = f.create_dataset ('Foo',data=arr,compression='gzip') s=0 #Takes the longest here for y in fs: continue a=y.split(',') s=s+1 dset.resize(s,axis=0) fs.close() f.close() This works but just takes a VERY long time. Any way to optimize this? TIA On Wed, Jun 24, 2009 at 12:13 AM, Chris Withers wrote: > Terry Reedy wrote: >> >> Mag Gam wrote: >>> >>> Yes, the system has 64Gig of physical memory. >> >> drool ;-). > > Well, except that, dependent on what OS he's using, the size of one process > may well still be limited to 2GB... > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > ? ? ? ? ? - http://www.simplistix.co.uk > -- > http://mail.python.org/mailman/listinfo/python-list > From luke.leighton at googlemail.com Wed Jun 24 07:55:07 2009 From: luke.leighton at googlemail.com (lkcl) Date: Wed, 24 Jun 2009 04:55:07 -0700 (PDT) Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> Message-ID: <1f3c975f-9910-4139-8a45-589673ea920a@s6g2000vbp.googlegroups.com> On Jun 23, 10:59 pm, smartmobili wrote: > I wanted to know if you have some patch to compile python 3.x on mingw > platform because I found some > but doesn't work very well : you should compile a 2.N version. despite efforts and proof that the efforts passed all but about 8-12 regression tests, the python development core team deemed the 2.5 and the 2.7 mingw port efforts to be a waste of time. if you or anyone else disagrees with this, please do say so, on the python-dev mailing list and also in the bugtracker. at least one person has already done so: http://bugs.python.org/issue4954#msg85994 http://bugs.python.org/issue5046 states that i am not allowed to post "work in progress", despite it being significantly complete, and despite it being worthwhile to have added in as-is into the standard python repository. http://bugs.python.org/issue4954 is where a python2.5 mingw native _and_ cross-compile was successfully built. http://bugs.python.org/issue3871 is where roumen continues to provide the benefits of the continuous work that he is doing. when i last checked, he wasn't able to do native mingw32 builds but only cross- compiles, but that may have changed. the most significant difference between 4954 and 3871 at the time when my efforts were terminated due to python developer hostility is that i spent considerable time reducing the size of configure. firing up a new /bin/sh under MSYS, native, takes 0.7 seconds (and < 0.01 on a gnu/linux box). firing up a new /bin/sh under MSYS, running under Wine, took _well_ over two seconds. consequently, running an "unmodified" version of configure would take well over half an hour. by cutting most of configure out and going with a pre-prepared Config.h i was able to reduce that time down to (only) about 10 minutes. which is just about tolerable. like all free software projects, there is considerable additional work to be done: everything is "work in progress", but thanks to the python developers applying one standard to themselves on what constitutes "work in progress" and another for contributors, you will not get the benefit of my input and expertise until you (python users) can get the python developers to treat my efforts to help users with a little more respect. l. From dickinsm at gmail.com Wed Jun 24 08:32:13 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 24 Jun 2009 05:32:13 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <5e1ecda8-59b6-421a-b9d7-10861620aa45@l2g2000vba.googlegroups.com> Message-ID: <9db988bc-2bc1-4505-95c9-76be34555372@z26g2000vbl.googlegroups.com> On Jun 24, 10:12?am, pdpi wrote: > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > perfectly fine NaN value? Other links: the IEEE 754 revision working group mailing list archives are public; there was extensive discussion about special values of pow and similar functions. Here's a relevant Google search: http://www.google.com/search?q=site:grouper.ieee.org++pow+annex+D The C99 rationale document has some explanations for the choices for special values in Annex F. Look at pages 179--182 in: http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf Note that the original IEEE 754-1985 didn't give specifications for pow and other transcendental functions; so a complete specification for pow appeared in the C99 standard before it appeared in the current IEEE standard, IEEE 754-2008. Thus C99 Annex F probably had at least some small influence on the choices made for IEEE 754-2008 (and in turn, IEEE 754-1985 heavily influenced C99 Annex F). My own take on all this, briefly: - floating-point numbers are not real numbers, so mathematics can only take you so far in deciding what the 'right' values are for special cases; pragmatics has to play a role too. - there's general consensus in the numerical and mathematical community that it's useful to define pow(0.0, 0.0) to be 1. - once you've decided to define pow(0.0, 0.0) to be 1.0, it's easy to justify taking pow(inf, 0.0) to be 1.0: the same limiting arguments can be used as justification; or one can use reflection formulae like pow(1/x, y) = 1/pow(x, y), or... - one piece of general philosophy used for C99 and IEEE 754 seems to have been that NaN results should be avoided when it's possible to give a meaningful non-nan value instead. - part of the reason that pow is particularly controversial is that it's really trying to be two different functions at once: it's trying to be both a generalization of the `analytic' power function x**y = exp(y*log(x)), for real y and positive real x, and in this context one can make a good argument that 0**0 should be undefined; but at the same time it's also used in contexts where y is naturally thought of as an integer; and in the latter context bad things happen if you don't define pow(0, 0) to be 1. I really should get back to work now. Mark From stephane at openerp.com Wed Jun 24 09:06:51 2009 From: stephane at openerp.com (Stephane Wirtel) Date: Wed, 24 Jun 2009 15:06:51 +0200 Subject: Decode a barcode ? Message-ID: <4A4224EB.1070309@openerp.com> Hi all, I would like to know if there is a way to decode a barcode with a library ? Thank you so much, Stephane -- Stephane Wirtel - "As OpenERP is OpenSource, please feel free to contribute." Developper - Technical Lecturer OpenERP OpenERP - Tiny SPRL Chaussee de Namur, 40 B-1367 Gerompont Tel: +32.81.81.37.00 Web: http://www.tiny.be Web: http://www.openerp.com Planet: http://www.openerp.com/planet/ Blog: http://stephane-wirtel-at-tiny.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: stephane.vcf Type: text/x-vcard Size: 443 bytes Desc: not available URL: From sakradevanamindra at gmail.com Wed Jun 24 09:09:37 2009 From: sakradevanamindra at gmail.com (Shoryuken) Date: Wed, 24 Jun 2009 06:09:37 -0700 (PDT) Subject: dynamically associate radio buttons with droplists References: Message-ID: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> On Jun 21, 8:43?pm, a... at pythoncraft.com (Aahz) wrote: > In article ,LeoBrugud? wrote: > > > > >Not being very familiar with python, nor with cgi/http, ?I intend to > >have 3 of buttons in a webpage, each of them is associate with a file > >(so I have 3 files, too) > > >What I would like to have is, when users choose a button, the droplist > >update automatically to load the contents of the associated file. > > >Can someone educate me the approach of this? > > Are you trying to do this without requiring the user to click the submit > button? ?If yes, you need to learn JavaScript (although I think there are > web frameworks that will auto-generate the JavaScript, you need to know > JavaScript in order to do debugging). > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha Thanks, and yes I want to do it without the submit button So python alone cannot do this? From chris at simplistix.co.uk Wed Jun 24 09:18:09 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 24 Jun 2009 14:18:09 +0100 Subject: Decode a barcode ? In-Reply-To: <4A4224EB.1070309@openerp.com> References: <4A4224EB.1070309@openerp.com> Message-ID: <4A422791.3010501@simplistix.co.uk> Stephane Wirtel wrote: > I would like to know if there is a way to decode a barcode with a library ? What do you mean by decode? Do you mean starting with a .gif or something containing a barcode? Most barcode readers just act as keyboards, so you don't often need to do this ;-) If you mean something else, please elaborate! Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From noname at nowhere.com Wed Jun 24 09:22:06 2009 From: noname at nowhere.com (Pegasus) Date: Wed, 24 Jun 2009 15:22:06 +0200 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS Message-ID: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> I need help with an implementation of your interpreter under PSPE/PSP. I need to know something about the C functions that are recalled by the interpreter when it executes a .pyc file. Our version of ndPython is very slow in execution respect to Carlos's StackLess Python (another product for PSP). We believe that the trouble is in a routine of our Nanodesktop libc that can be a bottleneck. But we don't know which can be the interested routine (string ? memory allocation ?) Please, help us. The product is complete, but we cannot release cause this problem. Thank you in advance. Filippo Battaglia From marco.bizzarri at gmail.com Wed Jun 24 09:23:04 2009 From: marco.bizzarri at gmail.com (Marco Bizzarri) Date: Wed, 24 Jun 2009 15:23:04 +0200 Subject: Decode a barcode ? In-Reply-To: <4A4224EB.1070309@openerp.com> References: <4A4224EB.1070309@openerp.com> Message-ID: <3f0d61c40906240623n22f44ea5xd1bb1061bfc1f46d@mail.gmail.com> If you're looking for a library in python to find barcodes inside an image, and then decoding it, I'm afraid you're out of luck; as far as I can tell, there is no such a library available. In case you're looking for the theory on how to do that, I think this group is not the best suited to post such a question :) (( Despite the fact that many people could know the answer )) regards Marco On Wed, Jun 24, 2009 at 3:06 PM, Stephane Wirtel wrote: > Hi all, > > I would like to know if there is a way to decode a barcode with a library ? > > Thank you so much, > > Stephane > -- > Stephane Wirtel - "As OpenERP is OpenSource, please feel free to > contribute." > Developper - Technical Lecturer OpenERP > OpenERP - Tiny SPRL > Chaussee de Namur, 40 > B-1367 Gerompont > Tel: +32.81.81.37.00 > Web: http://www.tiny.be > Web: http://www.openerp.com > Planet: http://www.openerp.com/planet/ > Blog: http://stephane-wirtel-at-tiny.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Jun 24 09:33:48 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 24 Jun 2009 09:33:48 -0400 Subject: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: Ross Ridge wrote: >I'm not sure what MIME would have to do with it, but Piet van Oostrum's >problem is almost certainly as result of the python.org mail to news >gateway mangling the References header. The missing postings he's looking >for don't actually exist. Just go up the thread one more posting and >you'll find the message that was being replied to. In article , Aahz wrote: >While that's also a bug in Mailman (I have a long-standing to-do item to >fix that), there are also plenty of posts that simply aren't showing up >in c.l.py. Well, the message IDs that Piet van Oostrum gave are symptomatic of the References header bug and and just like he described, my newsreader also shows Dennis Lee Bieber always replying to posts that don't exist. Other messages might be getting eaten by the gateway, but the missing posts that Piet is complaining about almost certainly never existed. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From motoom at xs4all.nl Wed Jun 24 09:35:15 2009 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 24 Jun 2009 15:35:15 +0200 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: <4A422B93.2090305@xs4all.nl> Duncan Smith wrote: > IDLE now refuses to > respond to left click events (for code editing, menus etc. respond as > expected). If I right click, then left click I can move the cursor, but > that's not ideal. > > So, has anybody else had the left click issue with IDLE (and solved it)? Irritating problem, isn't it? I experience the same on FreeBSD with Tk8.5. I had to downgrade to Tk8.4, which has ugly fonts. See http://bugs.python.org/issue2995 "Moving the mouse over the text widget changes the cursor to the I-beam as expected, but click on text doesn't position the beam at the mouse position. It is also impossible to select text with the mouse. Selecting text with shift-arrow keys works, however." It's closed because it doesn't seem related to Python. 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 mail at microcorp.co.za Wed Jun 24 09:58:03 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 24 Jun 2009 15:58:03 +0200 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <007b01c9f4d4$287b8ec0$0d00a8c0@Hendrik> "Steven D'Aprano" wrote: >On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > >> In my universe the standard definition of "log" is different froim what >> log means in a calculus class > >Now I'm curious what the difference is. > Maybe he is a lumberjack, and quite all right... - Hendrik From rolf.wester at ilt.fraunhofer.de Wed Jun 24 10:10:35 2009 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Wed, 24 Jun 2009 16:10:35 +0200 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> Message-ID: <4a4233d0$1@news.fhg.de> Hello, thank you all very much for your replies. I tried to simplify things and make the two versions as comparable as possible. I put the C++ part of the program into a shared object libff.so. For the exe the main function is linked against this shared object. For the python stuff I made an interface consiting of only one function call_solver with the same code that has the main function used for the exe. Then I created a wrapper for this interface using swig and linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code just imports _ff and calls call_solver wich creates an object of the class Solver and calls its member solve (the main function of the exe does the same). I included some code for timing into the C++-code. #include //beginning of solve clock_t t0 = clock(); ... clock_t t1 = clock(); //end of solve cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The sources are compiled using the flags -fPIC -O3. Timing: 1) time python ff.py time used = 3.74 real 0m3.234s user 0m3.712s sys 0m0.192s 2) time ff time used = 2.19 real 0m3.170s user 0m2.088s sys 0m0.168s I tried some other optimizations: -O0: 1) time used = 21.91 real 0m21.568s user 0m22.001s sys 0m0.160s 2) time used = 20.87 real 0m22.206s user 0m20.989s sys 0m0.148s -O1 1) time used = 4.04 real 0m3.660s user 0m4.000s sys 0m0.160s 2) time used = 2.72 real 0m3.454s user 0m2.648s sys 0m0.164s It seems that there is an overhead of about 2 secs within the C++-code. I'm going to try this out with a problem that takes much more time than the present one. Regards Rolf Carl Banks wrote: > On Jun 23, 7:20 am, Rolf Wester wrote: >> Philip Semanchuk wrote: >> >>> On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote: >>>> Hi, >>>> I have a C++ program that I would like to steer using Python. I made the >>>> wrapper using swig and linked the code (without the main function) into >>>> a shared object. My Python script loads the extension and calls a >>>> function of the C-extension, the rest runs entirely within the >>>> C-extension. For comparison I compiled the code including the main >>>> function with the same compilation options and linked all into an exe. >>>> The main function of the exe calls the same function as my Python script >>>> does. Surprisingly the code in the Python C-extension runs twice as long >>>> as the same code in the exe. Does anyone know what could be the reason >>>> for this behaviour? >>> If the runtime of the C/C++ code is short, the time spent initializing >>> the Python interpreter might have a big impact on the runtime of the >>> Python version. >> The runtime is about 2.5 sec and 5.0 sec respectively. I not only use >> the time command to measure the time consumed but I also measure the >> time within the C-code using clock() and get similar result. So the >> Python startup time is not the reason for the runtime difference I >> found. Thank you anyway. > > We can't really help you much unless you give us more details about > what you did (how did you built it, how did you time it, and how are > you calling the C extension from Python). All we can do is throw out > possible ideas, and I will toss out a few, but if that's not it you'll > have to post details. > > Are you building the extension with the same optimization flags as the > compiler? > > Are you calling the C code repeatedly from inside a Python loop? > From invalid at invalid Wed Jun 24 10:10:43 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 24 Jun 2009 09:10:43 -0500 Subject: Converting Python code to C/C++ References: Message-ID: On 2009-06-24, Couper, Tim T wrote: > Your prof. may find this thread of interest > > http://mail.python.org/pipermail/python-list/2000-June/039779.html > > My experience is that developers who know C and C++ can be productive in > less than 1 week in python, and find it liberating, and educational, to > do so. And at the same time they will have added a second language to > their toolbox. As Kurt points out, learning C/C++ takes considerably > longer (weeks/months to attain a level of competence). I agree. Your professor is deluded and knows nothing about software development [not that either is particularly unusual in an academic setting]. Converting a Python program to C or C++ is a complete waste of time (both now _and_ later) unless there are severe, insurmountable performance problems with the Python version. Python is a far, far better language for both real-world production application development and for algorithm R&D. With Python, you spend your time working on algorithms and solving real-world problems. In C or C++, you spend your time fighting with the bugs in your code that are preventing the program from running. An algorithm that takes a few hours to implement and test in Python will take weeks in C or C++. That said, you'll be niether the first nor last person to be forced by a professor or manager to waste weeks or months of time doing something that's obviously stupid and futile from a technical point of view. -- Grant Edwards grante Yow! What's the MATTER at Sid? ... Is your BEVERAGE visi.com unsatisfactory? From donnyf at gmail.com Wed Jun 24 10:23:35 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 07:23:35 -0700 (PDT) Subject: Reading then sending new parts of a log file Message-ID: Hey guys. I'm trying to work up a little program that will send any new lines written to a file (log file from my home automation software) to me via instant message. I've gotten the instant message sending part figured out using xmpppy. I've done a few things with Python in the past but I am in no means more than a beginner/hacker. Can someone tell me what commands/ modules/etc exist for monitoring and parsing a file for new information that I can then send to my IM sending function? I am not asking for anyone to write the code but merely a push in the right direction. Thanks! From pdpinheiro at gmail.com Wed Jun 24 10:35:17 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 07:35:17 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: On Jun 24, 2:58?pm, "Hendrik van Rooyen" wrote: > "Steven D'Aprano" wrote: > >On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote: > > >> In my universe the standard definition of "log" is different froim what > >> log means in a calculus class > > >Now I'm curious what the difference is. > > Maybe he is a lumberjack, and quite all right... > > - Hendrik Or perhaps he works in a sewage facility. But yeah, Log2 and LogE are the only two bases that make "natural" sense except in specialized contexts. Base 10 (and, therefore, Log10) is an artifact of having that 10 fingers (in fact, whatever base you use, you always refer to it as base 10). From aahz at pythoncraft.com Wed Jun 24 10:37:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 07:37:23 -0700 Subject: dynamically associate radio buttons with droplists References: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> Message-ID: In article <16b382ee-a3ae-46ee-88fd-d87fc40d208d at g20g2000vba.googlegroups.com>, Shoryuken wrote: >On Jun 21, 8:43=A0pm, a... at pythoncraft.com (Aahz) wrote: >> In article .com>,LeoBrugud=A0 wrote: >>> >>>Not being very familiar with python, nor with cgi/http, =A0I intend to >>>have 3 of buttons in a webpage, each of them is associate with a file >>>(so I have 3 files, too) >>> >>>What I would like to have is, when users choose a button, the droplist >>>update automatically to load the contents of the associated file. >> >> Are you trying to do this without requiring the user to click the submit >> button? =A0If yes, you need to learn JavaScript (although I think there a= >re >> web frameworks that will auto-generate the JavaScript, you need to know >> JavaScript in order to do debugging). > >Thanks, and yes I want to do it without the submit button > >So python alone cannot do this? Correct; you need to have code run in the browser, and few browsers support Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From gagsl-py2 at yahoo.com.ar Wed Jun 24 10:48:50 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Jun 2009 11:48:50 -0300 Subject: Python 3.0.1 and mingw References: <87ecaa03-e83c-44d2-ac16-169d803194a0@f19g2000yqo.googlegroups.com> <1f3c975f-9910-4139-8a45-589673ea920a@s6g2000vbp.googlegroups.com> Message-ID: En Wed, 24 Jun 2009 08:55:07 -0300, lkcl escribi?: > On Jun 23, 10:59 pm, smartmobili wrote: >> I wanted to know if you have some patch to compile python 3.x on mingw >> platform because I found some >> but doesn't work very well : > > you should compile a 2.N version. > [...] > http://bugs.python.org/issue5046 states that i am not allowed to > post "work in progress", despite it being significantly complete, and > despite it being worthwhile to have added in as-is into the standard > python repository. What you've been told is not to use the Python bug tracker as a blog. You could write about your progresses in *another* place, and maybe from time to time post a link here so interested people is aware of it. > by cutting most of configure out and going with a pre-prepared > Config.h i was able to reduce that time down to (only) about 10 > minutes. That's fine, the "official" Windows build uses a hand written config.h too. > like all free software projects, there is considerable additional > work to be done: everything is "work in progress", but thanks to the > python developers applying one standard to themselves on what > constitutes "work in progress" and another for contributors, you will > not get the benefit of my input and expertise until you (python users) > can get the python developers to treat my efforts to help users with a > little more respect. If you expect your work to be taken seriously, work seriously. Randomly changing code until some symptom disappears isn't a very good practice, I'd say. Try to polish the patches a little until you are happy with them, and only then submit them. -- Gabriel Genellina From grenander at gmail.com Wed Jun 24 10:57:23 2009 From: grenander at gmail.com (Art) Date: Wed, 24 Jun 2009 07:57:23 -0700 (PDT) Subject: isinstance(obj, type(obj)) == True? Message-ID: I have the following problem: ipdb> p type(self) ipdb> isinstance(self, component.BiasComponent) False I thought that isinstance(obj, type(obj)) == True. The specific problem is when I try to call the super of a class and it only occurs after 'reload'ing the file in the interpreter. What am I messing up by reloading? It doesn't occur if I using for the first time in a fresh interpreter session. ---> 32 class BiasComponent(ModelComponent): 33 def __init__(self, g, model): 34 super(BiasComponent, self).__init__(g, model) TypeError: super(type, obj): obj must be an instance or subtype of type Seems like the self passed to __init__ is messed up in some way. Thanks! From philip.groeger at googlemail.com Wed Jun 24 10:59:09 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Wed, 24 Jun 2009 16:59:09 +0200 Subject: Animate Surface / Clear Scene (vpython) Message-ID: <386f361c0906240759i653539f7pc0408e239d147ae4@mail.gmail.com> Hi there! I just found a nice vpython example program on how to create surfaces (its one of the standard examples if you download vpython ... called "faces_heightfield" - just search for that). Is there a way to animate this surface? All my attempts resulted in creating just another surface without deleting the old one. Or is there a "clear scene from all objects" command? If animating such a surface in vpython is too complicated / slow / etc ... I have to try mayavi. But I already know vpython ;) thanks alot -Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From schwehr at gmail.com Wed Jun 24 11:22:19 2009 From: schwehr at gmail.com (Kurt Schwehr) Date: Wed, 24 Jun 2009 08:22:19 -0700 (PDT) Subject: A superclass using a child classes' methods Message-ID: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> I'm trying to build an OO system for encoding and decoding datapackets. I'd like the parent class to have an encode function that uses each of the child classes' packing methods. It appears that this works for attributes of children accessed by the parent, but not for methods. Is that right? For attributes I found this example, where the alphabet attribute is set in the child, but used in the parent. http://www.pasteur.fr/formation/infobio/python/ch19s04.html Should I just set an attribute in the child class and then call the super's functionality making is pull the data from the attribute? Thanks, -kurt From torriem at gmail.com Wed Jun 24 11:49:07 2009 From: torriem at gmail.com (Michael Torrie) Date: Wed, 24 Jun 2009 09:49:07 -0600 Subject: A superclass using a child classes' methods In-Reply-To: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <4A424AF3.5020103@gmail.com> Kurt Schwehr wrote: > I'm trying to build an OO system for encoding and decoding > datapackets. I'd like the parent class to have an encode function > that uses each of the child classes' packing methods. It appears that > this works for attributes of children accessed by the parent, but not > for methods. Is that right? For attributes I found this example, > where the alphabet attribute is set in the child, but used in the > parent. There is no difference between an attribute and a method. They are both attributes. One happens to be callable and is a method call. I just tried it and it seemed to work fine. In my old C++ days, I believe you would call this scenario virtual classes. In python, since everything is dynamic and computed at runtime, I think you can just refer to any attribute in the instance and as long as someone down the road provides it, it would work. For example: class parent(object): def test(self): print self.child_attribute self.child_method() class child(parent): def __init__(self): self.child_attribute = 'child' def child_method(self): print 'child method is called' c=child() c.test() This should display "child" and "child method is called" From buzzard at urubu.freeserve.co.uk Wed Jun 24 11:54:26 2009 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Wed, 24 Jun 2009 16:54:26 +0100 Subject: IDLE / Python 2.5 under Jaunty In-Reply-To: References: Message-ID: Michiel Overtoom wrote: > > Duncan Smith wrote: > >> IDLE now refuses to >> respond to left click events (for code editing, menus etc. respond as >> expected). If I right click, then left click I can move the cursor, but >> that's not ideal. >> >> So, has anybody else had the left click issue with IDLE (and solved it)? > > Irritating problem, isn't it? I experience the same on FreeBSD with Tk8.5. > I had to downgrade to Tk8.4, which has ugly fonts. > > See http://bugs.python.org/issue2995 > > "Moving the mouse over the text widget changes the cursor to the I-beam > as expected, but click on text doesn't position the beam at the mouse > position. It is also impossible to select text with the mouse. > Selecting text with shift-arrow keys works, however." > > It's closed because it doesn't seem related to Python. > > Greetings, > Thanks for the responses. I searched far and wide, and couldn't find anyone else having the same problem. I have Tk 8.4.19-2 and 8.5.6-3 on this machine. I remember changing the font a while back (before upgrading to Jaunty) because it was barely readable. I guess the issue is with Tk 8.5.6-3. Just found I can move the cursor (by left clicking) if I hold the control key down. Shift arrow keys works for selection. Still not so good. Cheers. Duncan From brian at sweetapp.com Wed Jun 24 11:56:42 2009 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 24 Jun 2009 16:56:42 +0100 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <4A424CBA.9040103@sweetapp.com> You could start by reading this: http://catb.org/~esr/faqs/smart-questions.html Cheers, Brian Pegasus wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. > > I need to know something about the C > functions that are recalled by the interpreter > when it executes a .pyc file. > > Our version of ndPython is very slow in > execution respect to Carlos's StackLess > Python (another product for PSP). > > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) > > > Please, help us. The product is complete, > but we cannot release cause this problem. > > Thank you in advance. > Filippo Battaglia > > From icanbob at gmail.com Wed Jun 24 12:01:13 2009 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 24 Jun 2009 09:01:13 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: On Jun 23, 11:49 am, Kurt Smith wrote: > On Mon, Jun 22, 2009 at 9:49 PM, Andras > > > > Pikler wrote: > > Hi! > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > > and I am at a loss. > > > Long: I?m doing research/programming for a professor, and we are working > > with MIDI files (a type of simple music file). The research deals with > > generating variations from a musical melody; currently, my Python code uses > > a Python midi package I found online to read the notes in question from a > > midi file, about 350 lines of my own code to generate a variation based on > > these notes and the professor?s algorithms, and finally the package again to > > write the new melody to another midi file. > > > Now, my professor would like to have this exact code in C/C++, as she > > believes C is more compatible with MATLAB, and wants the code to be > > available in multiple languages in case a programmer works for her in the > > future who knows C but not Python. While I know a tiny bit of C (emphasis on > > the tiny), I would much prefer if there were some sort of automatic compiler > > I could use to turn my Python code into C than taking a week or two or three > > to learn the minimum I need about C, find a way to access MIDI files in it, > > and rewrite all of my code. > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > > Python midi package I?m using uses modules which Shedskin does not support. > > Otherwise, I haven?t found much. Is there anything out there to help me do > > this? If not, from anyone who has experience in this regard, how daunting > > should I expect this to be? > > Taking on C from a cold start and being able to handle the ins and > outs of interfacing with Python isn't something that's feasible in > 'two or three weeks'. Here are a couple of options -- take 'em or > leave 'em: > > 1) Put the code in Cython:http://www.cython.org/ (full disclosure: > I'm doing a GSoC project with Cython). It will convert pretty much > any python code into C code (even closures are supported in the most > recent version, I think), and the C code can then be compiled into an > extension module. > > The only problem with the above is the C code isn't, at first blush, > easy to read. Nor is it supposed to be changed by the user. So that > leads us to option... > > 2) Write the core functionality in C yourself, and then wrap those C > functions in Cython. You'll want to take a look at the documentation: > > http://docs.cython.org/ > > and, more specifically on wrapping C code: > > http://docs.cython.org/docs/external_C_code.html > > I don't think you'll be able to avoid learning C, though. > > Kurt 3) use Python-SIMPL to connect your C module to your Python module using a 5 function API without any need for wrappers. ie. have your cake and eat it too http://www.icanprogram.com/06py/main.html bob From Scott.Daniels at Acm.Org Wed Jun 24 12:10:50 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:10:50 -0700 Subject: Converting Python code to C/C++ In-Reply-To: References: Message-ID: Couper, Tim T wrote: > ... My experience is that developers who know C and C++ can be productive > in less than 1 week in python, and find it liberating, and educational, to > do so. And at the same time they will have added a second language to > their toolbox. As Kurt points out, learning C/C++ takes considerably > longer (weeks/months to attain a level of competence). Yup. Remember that "be productive" is not quite the same as "master." The nice thing is that the mastery comes on a gentle slope, adding to your productivity without requiring drastic rethinking of all you understood (as is done to physics students, for example). > Python is now used in a number of universities as the language in which > to teach comp sci undergraduate courses (I know of Leeds, & MIT), > biomathematics, and my daughter just finished her PhD in speech and > language processing at Edinburgh .. using python and Matplotlib .. as > the extensive C/C++ libraries in that infomatics world are wrapped in > python - and the MSc Comp Sci course has replaced Java as the language > for teaching with Python. As a data point, Georgia Tech (I believe) had a two-semester Computer Science intro course in C++. In introducing a Python intro course, they provided for a few years both the Python and the C++ first semester, and kept the C++ second semester. They found no measurable difference in the performance on the second course (still in C++) even though the Python course people had to learn a new language in addition to learning the rest of the coursework. The first course is now in Python, since at the end of the two-semester sequence they know two languages and apparently suffer no compensating loss. --Scott David Daniels Scott.Daniels at Acm.Org From xelothath13 at gmail.com Wed Jun 24 12:11:22 2009 From: xelothath13 at gmail.com (humn) Date: Wed, 24 Jun 2009 09:11:22 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? Message-ID: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> I'm writing a script to convert Latex commands to bbcode by using the str.replace function and I'm confused as to why this works: if '\chapter' in line: line = line.replace('\chapter{', '[b][u]') line = line.replace('}', '[/b][/u]') but this doesn't: if '\title' in line: line = line.replace('\title{', '[size=150][b]') line = line.replace('}', '[/b][/size]') Here is the short version of the script: infile = open('test.tex') outfilename = infile.name.partition('.')[0] + '.bbcode' outfile = open(outfilename, 'w') for line in infile: if '\title' in line: line = line.replace('\title{', '[size=150][b]') line = line.replace('}', '[/b][/size]\n') if '\chapter' in line: line = line.replace('\chapter{', '[b][u]') line = line.replace('}', '[/u][/b]') outfile.write(line) infile.close() outfile.close() From bryanvick at gmail.com Wed Jun 24 12:17:31 2009 From: bryanvick at gmail.com (Bryan) Date: Wed, 24 Jun 2009 09:17:31 -0700 (PDT) Subject: Get name of class without instance Message-ID: Given a class: class Foo(object): pass How can I get the name "Foo" without having an instance of the class? str(Foo) gives me more than just the name Foo. "__main__.Account" Foo.__class__.__name__ gives me "type" I don't want to do: Foo().__class__.__name__ if possible. I would rather avoid the constructor. I just want to get a string "Foo" From skip at pobox.com Wed Jun 24 12:21:57 2009 From: skip at pobox.com (skip at pobox.com) Date: Wed, 24 Jun 2009 11:21:57 -0500 Subject: Reading a large csv file In-Reply-To: <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> <1cbd6f830906240438x61fb76f3o93f3d56138ca3fbf@mail.gmail.com> Message-ID: <19010.21157.212566.880066@montanaro.dyndns.org> Mag> s=0 Mag> #Takes the longest here Mag> for y in fs: Mag> continue Mag> a=y.split(',') Mag> s=s+1 Mag> dset.resize(s,axis=0) Mag> fs.close() Mag> f.close() Mag> This works but just takes a VERY long time. Mag> Any way to optimize this? I sort of suspect you're missing something there. Is there nothing between the for loop and the overly indented continue statement? At any rate, try using the csv module to read in your records: import csv reader = csv.reader(fs) ... for s, row in enumerate(reader): dset.resize(s, axis=0) -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From elwinter at verizon.net Wed Jun 24 12:22:10 2009 From: elwinter at verizon.net (Eric Winter) Date: Wed, 24 Jun 2009 09:22:10 -0700 (PDT) Subject: Unable to get Tkinter menubar to appear under OS X Message-ID: <3737fd18-4973-4cc3-914d-fbdefdbbb8a7@t10g2000vbg.googlegroups.com> Hi all. I've googled this issue several times and come up dry. Here's the situation: I have a X-windows build of Tkinter for Python built on an OS X machine (10.4 or 10.5, same issue). This is not the Aqua version of Tk, but Tk built from source using X-Window support. I also use a from- source build of Python, not the system Python. I don't like this arrangement, but project requirements (allegedly) dictate this approach. When I run any application using that copy of Tkinter and that copy of Python, everything seems to work fine except menus - the code which creates the menus runs, but no menus appear, either in the window or at the top of the screen. Am I required to use the Aqua version of Tk on OS X? If not, do I need to do something special on OS X when I built Tk and/or Python? Any hints here would be greatly appreciated. Thanks, Eric Winter Fermi Science Support Center NASA Goddard Space Flight Center From jeanmichel at sequans.com Wed Jun 24 12:23:28 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Jun 2009 18:23:28 +0200 Subject: A superclass using a child classes' methods In-Reply-To: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <4A425300.4060508@sequans.com> Kurt Schwehr wrote: > I'm trying to build an OO system for encoding and decoding > datapackets. I'd like the parent class to have an encode function > that uses each of the child classes' packing methods. It appears that > this works for attributes of children accessed by the parent, but not > for methods. hell no, this works for methods as well. > Is that right? For attributes I found this example, > where the alphabet attribute is set in the child, but used in the > parent. > > http://www.pasteur.fr/formation/infobio/python/ch19s04.html > > Should I just set an attribute in the child class and then call the > super's functionality making is pull the data from the attribute? > > Thanks, > -kurt > class Parent: def foo(self): raise NotImplementedError() # virtual method, it has to be overriden by childs def bar(self): self.foo() class Son(Parent): def foo(self): print "I'm your son" class Daughter(Parent): def foo(self): print "I'm your daughter" Son().bar() "I'm your son" Declaring the foo method at the Parent level is not required. But it's a good practice: explicit > implicit and it helps to write proper documentation. Jean-Michel From jeanmichel at sequans.com Wed Jun 24 12:24:37 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Jun 2009 18:24:37 +0200 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <4A425345.4070703@sequans.com> Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > > >>> Foo.__name__ 'Foo' 8-) JM From mail at timgolden.me.uk Wed Jun 24 12:25:21 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Jun 2009 17:25:21 +0100 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <4A425371.3050903@timgolden.me.uk> Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > You are going to kick yourself: class Foo (object): pass print Foo.__name__ TJG From Scott.Daniels at Acm.Org Wed Jun 24 12:26:30 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:26:30 -0700 Subject: Dictionary self lookup In-Reply-To: References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: Norberto Lopes wrote: > On Jun 24, 1:21 pm, "Diez B. Roggisch" wrote: >> Norberto Lopes wrote: ... >>> config = {"home" : "/home/test"} >>> config["user1"] = config["home"] + "/user1" >>> config["user2"] = config["home"] + "/user2" >>> config["python-dev"] = config["user1"] + "/py-dev" I'd write this as: home = "/home/test" config = {"home" : home, "user1" : home + "/user1", "user2" : home + "/user2", "python-dev" : home + "/py-dev"} or even (if the list gets much longer): home = "/home/test" config = {"home" : "", "user1" : "/user1", "user2" : "/user2", "python-dev" : "/py-dev"} for key, entry in config.iteritems(): config[key] = home + entry --Scott David Daniels Scott.Daniels at Acm.Org From unayok at gmail.com Wed Jun 24 12:28:34 2009 From: unayok at gmail.com (unayok) Date: Wed, 24 Jun 2009 09:28:34 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: On Jun 24, 12:11?pm, humn wrote: > but this doesn't: > > if '\title' in line: > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > ? ? ? ? line = line.replace('}', '[/b][/size]') \t is an escaped character. so, '\title' will look for 'itle' Two ways to fix this: 1. use r'\title' 2. use '\\title' \c does not represent a known escape sequence so it remains two characters. From bryanvick at gmail.com Wed Jun 24 12:28:56 2009 From: bryanvick at gmail.com (Bryan) Date: Wed, 24 Jun 2009 09:28:56 -0700 (PDT) Subject: Get name of class without instance References: Message-ID: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> On Jun 24, 9:25?am, Tim Golden wrote: > Bryan wrote: > > Given a class: > > > class Foo(object): > > ? ? pass > > > How can I get the name "Foo" without having an instance of the class? > > > str(Foo) gives me more than just the name Foo. ? "__main__.Account" > > Foo.__class__.__name__ gives me "type" > > > I don't want to do: > > Foo().__class__.__name__ if possible. ?I would rather avoid the > > constructor. ?I just want to get a string "Foo" > > You are going to kick yourself: > > class Foo (object): pass > > print Foo.__name__ > > TJG Whoops. How come dir(Foo) does not show __name__? That is how I was investigating the possibilities. From jcd at sdf.lonestar.org Wed Jun 24 12:36:19 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 24 Jun 2009 12:36:19 -0400 Subject: Get name of class without instance In-Reply-To: References: Message-ID: <1245861379.13858.0.camel@aalcdl07> On Wed, 2009-06-24 at 09:17 -0700, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > I'll give you a hint: >>> Foo().__class__ is Foo True From schwehr at gmail.com Wed Jun 24 12:37:11 2009 From: schwehr at gmail.com (Kurt Schwehr) Date: Wed, 24 Jun 2009 09:37:11 -0700 (PDT) Subject: A superclass using a child classes' methods References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> Message-ID: <87ccaa96-6462-45d3-8108-f09a94ae6797@l28g2000vba.googlegroups.com> Jean-Michel, Thanks for the excellent response setting me straight. Now to figure out what dumb thing I did to make my code not work... -kurt On Jun 24, 12:23?pm, Jean-Michel Pichavant wrote: > Kurt Schwehr wrote: > > I'm trying to build an OO system for encoding and decoding > > datapackets. ?I'd like the parent class to have an encode function > > that uses each of the child classes' packing methods. ?It appears that > > this works for attributes of children accessed by the parent, but not > > for methods. > [clear example of it working] > > Declaring the foo method at the Parent level is not required. But it's a > good practice: explicit > implicit and it helps to write proper > documentation. > > Jean-Michel From Scott.Daniels at Acm.Org Wed Jun 24 12:37:57 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:37:57 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Peter Otten wrote: > ... > If you need more than a few name value pairs it pays to put the data in a > dictionary first: > > # assuming that values always consist of a single line > with open(filename) as instream: > lines = (line.strip() for line in lines) > lookup = dict(zip(lines, lines)) > print lookup["Data2"] > print lookup["Data3"] Little bit of a fluff-up here. Perhaps something like: with open(filename) as instream: lines = (line.strip() for line in instream) lookup = dict(zip(lines[::2], lines[1::2])) The other way to do it is: lookup = {} with open(filename) as instream: gen = (line.strip() for line in instream) for key in gen: lookup[key] = next(gen) --Scott David Daniels Scott.Daniels at Acm.Org From kd at kendyck.com Wed Jun 24 12:38:20 2009 From: kd at kendyck.com (Ken Dyck) Date: Wed, 24 Jun 2009 09:38:20 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: On Jun 24, 12:11?pm, humn wrote: > I'm confused as to why this works: > > if '\chapter' in line: > ? ? ? ? line = line.replace('\chapter{', '[b][u]') > ? ? ? ? line = line.replace('}', '[/b][/u]') > > but this doesn't: > > if '\title' in line: > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > ? ? ? ? line = line.replace('}', '[/b][/size]') In string literals---whether they use single or double quotes--- backslashes are used as escape characters to denote special characters. The '\t' in '\title' is interpreted as the tab character so the string that your code is trying to find and replace is actually 'itle'. There isn't any special meaning for '\c', so python interprets that to mean a backslash followed by the character 'c', which is why the first case works. There are two ways to solve the problem: 1. Prefix the string literal with an 'r', indicating that backslashes should not be treated as escape characters (eg. r'\title'), or 2. Use a double backslash in the string literal to indicate that you mean a literal backslash, not an escape character (eg. '\\title') The official documentation, including a list of the special escape sequences, is here: http://docs.python.org/reference/lexical_analysis.html#string-literals -Ken From xelothath13 at gmail.com Wed Jun 24 12:39:05 2009 From: xelothath13 at gmail.com (humn) Date: Wed, 24 Jun 2009 09:39:05 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> Message-ID: <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> On Jun 24, 12:28?pm, unayok wrote: > On Jun 24, 12:11?pm, humn wrote: > > > but this doesn't: > > > if '\title' in line: > > ? ? ? ? line = line.replace('\title{', '[size=150][b]') > > ? ? ? ? line = line.replace('}', '[/b][/size]') > > \t is an escaped character. so, '\title' will look for > 'itle' > > Two ways to fix this: > > 1. use r'\title' > > 2. use '\\title' > > \c does not represent a known escape sequence so it remains two > characters. Thank you! Didn't know that it would escape characters with single quotes. I thought it only did that with double quotes. From dstanek at dstanek.com Wed Jun 24 12:47:59 2009 From: dstanek at dstanek.com (David Stanek) Date: Wed, 24 Jun 2009 12:47:59 -0400 Subject: Get name of class without instance In-Reply-To: References: Message-ID: Try Foo.__name__ if Foo is a class object. On 6/24/09, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from my mobile device David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From Scott.Daniels at Acm.Org Wed Jun 24 12:57:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 09:57:31 -0700 Subject: Reading then sending new parts of a log file In-Reply-To: References: Message-ID: Chuck Connors wrote: > Hey guys. I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? I am not > asking for anyone to write the code but merely a push in the right > direction. > > Thanks! What OS and version, what Python and version. --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Wed Jun 24 12:58:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 17:58:48 +0100 Subject: Why is it that str.replace doesn't work sometimes? In-Reply-To: <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: <4A425B48.4020509@mrabarnett.plus.com> humn wrote: > On Jun 24, 12:28 pm, unayok wrote: >> On Jun 24, 12:11 pm, humn wrote: >> >>> but this doesn't: >>> if '\title' in line: >>> line = line.replace('\title{', '[size=150][b]') >>> line = line.replace('}', '[/b][/size]') >> \t is an escaped character. so, '\title' will look for >> 'itle' >> >> Two ways to fix this: >> >> 1. use r'\title' >> >> 2. use '\\title' >> >> \c does not represent a known escape sequence so it remains two >> characters. > > Thank you! Didn't know that it would escape characters with single > quotes. I thought it only did that with double quotes. There's no difference between the two types of quote character. Python itself prefers to show ' when printing, unless " would be clearer: >>> # The empty string. >>> '' '' >>> "" '' >>> # Quoting the other type. >>> '"' '"' >>> "'" "'" >>> # Quoting the same type. >>> '\'' "'" >>> "\"" '"' From pdpinheiro at gmail.com Wed Jun 24 13:06:05 2009 From: pdpinheiro at gmail.com (pdpi) Date: Wed, 24 Jun 2009 10:06:05 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: 9db988bc-2bc1-4505-95c9-76be34555372@z26g2000vbl.googlegroups.com Message-ID: <3a1eff07-8f85-4f85-bff8-58d70c3eaf6c@p23g2000vbl.googlegroups.com> On Jun 24, 1:32?pm, Mark Dickinson wrote: > On Jun 24, 10:12?am, pdpi wrote: > > > Regarding inf ** 0, why does IEEE745 define it as 1, when there is a > > perfectly fine NaN value? > > Other links: ?the IEEE 754 revision working group mailing list > archives are public; ?there was extensive discussion about > special values of pow and similar functions. ?Here's a relevant > Google search: > > http://www.google.com/search?q=site:grouper.ieee.org++pow+annex+D > > The C99 rationale document has some explanations for the > choices for special values in Annex F. ?Look at pages 179--182 > in: > > http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf > > Note that the original IEEE 754-1985 didn't give specifications > for pow and other transcendental functions; ?so a complete > specification for pow appeared in the C99 standard before it > appeared in the current IEEE standard, IEEE 754-2008. ?Thus > C99 Annex F probably had at least some small influence on the > choices made for IEEE 754-2008 (and in turn, IEEE 754-1985 > heavily influenced C99 Annex F). > > My own take on all this, briefly: > > ?- floating-point numbers are not real numbers, so mathematics > ? ?can only take you so far in deciding what the 'right' values > ? ?are for special cases; ?pragmatics has to play a role too. > > ?- there's general consensus in the numerical and mathematical > ? ?community that it's useful to define pow(0.0, 0.0) to be 1. > > ?- once you've decided to define pow(0.0, 0.0) to be 1.0, it's > ? ?easy to justify taking pow(inf, 0.0) to be 1.0: ?the same > ? ?limiting arguments can be used as justification; ?or one can > ? ?use reflection formulae like pow(1/x, y) = 1/pow(x, y), or... > > ?- one piece of general philosophy used for C99 and IEEE 754 > ? ?seems to have been that NaN results should be avoided > ? ?when it's possible to give a meaningful non-nan value instead. > > ?- part of the reason that pow is particularly controversial > ? ?is that it's really trying to be two different functions > ? ?at once: ?it's trying to be both a generalization of the > ? ?`analytic' power function x**y = exp(y*log(x)), for > ? ?real y and positive real x, and in this context one can > ? ?make a good argument that 0**0 should be undefined; but > ? ?at the same time it's also used in contexts where y is > ? ?naturally thought of as an integer; and in the latter > ? ?context bad things happen if you don't define pow(0, 0) > ? ?to be 1. > > I really should get back to work now. > > Mark Thanks for the engrossing read (and damn you for making me waste valuable work hours). After perusing both C99 and the previous presentation on IEEE754, I find myself unconvinced regarding the special cases. It just stinks of bug-proneness, and I fail to see how assuming common values for exceptional cases relieves you from testing for those special cases and getting them behaving right (in an application-specific way) just the same. From tjreedy at udel.edu Wed Jun 24 13:07:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 13:07:36 -0400 Subject: Best way to enumerate classes in a module In-Reply-To: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: > I need to programmaticaly enumerate all the classes in a given module. > Currently I'm using dir(module) but the Notice on the documentation page > [1] says "dir() is supplied primarily as a convenience for use at an > interactive prompt" so that kind of scares me. That notice primarily refers to the fact that the special names (of __xxx__ form) returned are implementation and version dependent, and may not be complete in the sense that dir(ob) may not return __xyz__ even though ob.__xyz__ exists and can be retrieved. If you are only interested in regular-name attribute of ob, let your fear fly away. From rridge at csclub.uwaterloo.ca Wed Jun 24 13:17:53 2009 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 24 Jun 2009 13:17:53 -0400 Subject: reply to OT diversion (was: What is the best method to match a pattern in set of lines References: <028f3283-233d-442c-a67c-43b519aba938@s1g2000prd.googlegroups.com> <024d7a38$0$20654$c3e8da3@news.astraweb.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > Guess what? Prior to DejaNews, discussions on Usenet *were* ephemeral, > and it all worked. Not really, Usenet was archived before DejaNews arrived on the scene. I can find plenty of my posts from before then. Regardless, Usenet works better now that searchable archives are available on the WWW. Dennis Lee Bieber wrote: > If there were an "X-no-google" option I'd switch... I have no real >concerns about archives /accessed via NNTP through some paid-traceable >account/... But look at how much effort Google has to go through in the >attempt of obliterating email addresses in the attempt at minimizing >collection of such by spammers... Uh... this makes no sense. X-No-Archive does nothing to prevent spammers from harvesting your e-mail address. Your current posts are available to spammers for free on NNTP and WWW servers all over the 'net with or without the header. At least Google does try to hide your e-mail address, other WWW sites don't bother: http://www.rhinocerus.net/forum/lang-python/571842-re-pyserial-question.html You'd be more protected from spammers with an X-Google-Only option. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From clp2 at rebertia.com Wed Jun 24 13:22:39 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 10:22:39 -0700 Subject: isinstance(obj, type(obj)) == True? In-Reply-To: References: Message-ID: <50697b2c0906241022v1b290e34m75d5f58ab173b140@mail.gmail.com> On Wed, Jun 24, 2009 at 7:57 AM, Art wrote: > I have the following problem: > > ipdb> p type(self) > > > ipdb> isinstance(self, component.BiasComponent) > False > > I thought that isinstance(obj, type(obj)) == True. > > The specific problem is when I try to call the super of a class and it > only occurs after 'reload'ing the file in the interpreter. What am I > messing up by reloading? It doesn't occur if I using for the first > time in a fresh interpreter session. > > ---> 32 class BiasComponent(ModelComponent): > ? ? ?33 ? ? def __init__(self, g, model): > ? ? ?34 ? ? ? ? super(BiasComponent, self).__init__(g, model) > > TypeError: super(type, obj): obj must be an instance or subtype of > type > > Seems like the self passed to __init__ is messed up in some way. I would guess you're running into one of the caveats of using reload(); see http://docs.python.org/library/functions.html#reload Printing out id(BiasComponent) and id(type(obj)) both before and after the reload() call should be instructive. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Jun 24 13:25:12 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 13:25:12 -0400 Subject: Converting Python code to C/C++ In-Reply-To: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> References: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Message-ID: >> Short: I need to turn a Python program that I (mostly) wrote into C >> code, and I am at a loss. >> >> Now, my professor would like to have this exact code in C/C++, as she >> believes C is more compatible with MATLAB, and wants the code to be >> available in multiple languages in case a programmer works for her in >> the future who knows C but not Python. While I know a tiny bit of C >> (emphasis on the tiny), Your professor should wait until your Python version is complete and in final form and until a C version is needed. Then hire someone competent in both languages to do the translation. From __peter__ at web.de Wed Jun 24 13:29:19 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 19:29:19 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Scott David Daniels wrote: > Peter Otten wrote: >> with open(filename) as instream: >> lines = (line.strip() for line in lines) >> lookup = dict(zip(lines, lines)) > Little bit of a fluff-up here. Sorry, it should have been with open(filename) as instream: lines = (line.strip() for line in instream) lookup = dict(zip(lines, lines)) > Perhaps something like: > > with open(filename) as instream: > lines = (line.strip() for line in instream) > lookup = dict(zip(lines[::2], lines[1::2])) Tu quoque ;) Peter From clp2 at rebertia.com Wed Jun 24 13:31:02 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 10:31:02 -0700 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <50697b2c0906241031i4178b67bx1045d0cf684a15b0@mail.gmail.com> On Wed, Jun 24, 2009 at 6:22 AM, Pegasus wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. > > I need to know something about the C > functions that are recalled by the interpreter > when it executes a .pyc file. > > Our version of ndPython is very slow in > execution respect to Carlos's StackLess > Python (another product for PSP). > > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) > > > Please, help us. The product is complete, > but we cannot release cause this problem. > > Thank you in advance. > Filippo Battaglia In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. Cheers, Chris -- http://blog.rebertia.com From Wwy58 at yahoo.com Wed Jun 24 13:50:50 2009 From: Wwy58 at yahoo.com (David) Date: Wed, 24 Jun 2009 10:50:50 -0700 (PDT) Subject: urllib2.urlopen issue Message-ID: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> hello, I have a url that is "http://query.directrdr.com/ptrack? pid=225&v_url=http:// www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". If I open it on a browser, I can get its contents without any problem. However, if I use following code, import urllib2 url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' xml = urllib2.urlopen(url).read() then I get an exception of File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open raise URLError(err) urllib2.URLError: I think this is caused by the embedded "v_url=..." in the url. Anybody knows how to fix this? By the way, this code works well if I change the value of url to something like "www.yahoo.com" or "www.google.com". Thanks so much. From shelika.void at gmail.com Wed Jun 24 14:07:00 2009 From: shelika.void at gmail.com (Norberto Lopes) Date: Wed, 24 Jun 2009 11:07:00 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> <7aebgaF1up16pU1@mid.uni-berlin.de> <5361a395-eb40-4480-bc5f-fd78e483d024@j20g2000vbp.googlegroups.com> <7aegajF1uqhasU1@mid.uni-berlin.de> Message-ID: <2f093ae3-4393-4b36-a6fe-037b6acf4a5e@s6g2000vbp.googlegroups.com> On Jun 24, 6:26?pm, Scott David Daniels wrote: > Norberto Lopes wrote: > > On Jun 24, 1:21 pm, "Diez B. Roggisch" wrote: > >> Norberto Lopes wrote: ... > >>> config = {"home" : "/home/test"} > >>> config["user1"] = config["home"] + "/user1" > >>> config["user2"] = config["home"] + "/user2" > >>> config["python-dev"] = config["user1"] + "/py-dev" > > I'd write this as: > ? ? home = "/home/test" > ? ? config = {"home" : home, "user1" : home + "/user1", > ? ? ? ? ? ? ? "user2" : home + "/user2", "python-dev" : home + "/py-dev"} > > or even (if the list gets much longer): > > ? ? home = "/home/test" > ? ? config = {"home" : "", "user1" : "/user1", "user2" : "/user2", > ? ? ? ? ? ? ? "python-dev" : "/py-dev"} > ? ? for key, entry in config.iteritems(): > ? ? ? ? config[key] = home + entry > > --Scott David Daniels > Scott.Dani... at Acm.Org Yeah, there are a lot of options. That was just an example. Btw, I had "python-dev" depending on "user1" and "user1" depending on "home" precisely so that the way you suggested would get complicated. Yours examples fail in the python-dev key-value. You'd need an "extra" step ;) From xahlee at gmail.com Wed Jun 24 14:09:40 2009 From: xahlee at gmail.com (Xah Lee) Date: Wed, 24 Jun 2009 11:09:40 -0700 (PDT) Subject: talk of concurrency by Anders Hejlsberg and Guy Steele Message-ID: <5846735f-74aa-4c6a-933a-83ded986390c@u9g2000prd.googlegroups.com> of recent talks about concurrency, this video interview would be of interest: http://channel9.msdn.com/posts/Charles/Anders-Hejlsberg-and-Guy-Steele-Concurrency-and-Language-Design/ Anders Hejlsberg and Guy Steele: Concurrency and Language Design Posted By: Charles | Oct 6th, 2008 @ 6:27 AM | 75,079 Views | 19 Comments Xah ? http://xahlee.org/ ? From aahz at pythoncraft.com Wed Jun 24 14:11:27 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 11:11:27 -0700 Subject: urllib2.urlopen issue References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: In article <854313cf-6323-4ca9-b883-65ca8f414d96 at v23g2000pro.googlegroups.com>, David wrote: > >import urllib2 >url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' >xml = urllib2.urlopen(url).read() > >then I get an exception of > > File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > raise URLError(err) >urllib2.URLError: > >I think this is caused by the embedded "v_url=..." in the url. urllib.quote_plus() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From clp2 at rebertia.com Wed Jun 24 14:27:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 11:27:12 -0700 Subject: urllib2.urlopen issue In-Reply-To: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: <50697b2c0906241127h26562e9fsac42ecc1f32f13da@mail.gmail.com> On Wed, Jun 24, 2009 at 10:50 AM, David wrote: > hello, > > I have a url that is "http://query.directrdr.com/ptrack? > pid=225&v_url=http:// > www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". > If I open it on a browser, I can get its contents without any > problem. > However, if I use following code, > > > import urllib2 > > > url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// > www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' > > > xml = urllib2.urlopen(url).read() > > > then I get an exception of > > > ?File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > ? ?raise URLError(err) > urllib2.URLError: Unable to reproduce with either urllib or urllib2's urlopen(). I get some XML back without error both ways. Using Python 2.6.2 on Mac OS X. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Wed Jun 24 14:31:44 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 14:31:44 -0400 Subject: isinstance(obj, type(obj)) == True? In-Reply-To: References: Message-ID: Art wrote: > I have the following problem: > > ipdb> p type(self) > > > ipdb> isinstance(self, component.BiasComponent) > False > > I thought that isinstance(obj, type(obj)) == True. Yes, but that is not what you entered ;-). The name 'component.BiasComponent' is not bound to type(self), but to another object, probably with the same .__name__ attribute. > The specific problem is when I try to call the super of a class and it > only occurs after 'reload'ing the file in the interpreter. What am I > messing up by reloading? The relationship between namespace names and definition names. My guess is that you have two class objects with the same definition name. This happens when you reload the code for a class and have instances that keep the original class object alive. This sort of problem is why reload was *removed* from Py3. It did not work the way people wanted it to and expected it to. I recommend not to use it. > It doesn't occur if I using for the first > time in a fresh interpreter session. Starting fresh is the right thing to do. IDLE has a 'Restart Shell' command for this reason. It automatically restarts when you run a file. You have already wasted more time with reload than most people would ever save in a lifetime of using reload, even if it worked as expected. Terry Jan Reedy From invalid at invalid Wed Jun 24 14:35:34 2009 From: invalid at invalid (Grant Edwards) Date: Wed, 24 Jun 2009 13:35:34 -0500 Subject: Converting Python code to C/C++ References: <3E182F9C8D02B04894703F7716283BB60A3A2F3F@SIHLDNVSMSG01.Sbintldirectory.com> Message-ID: On 2009-06-24, Terry Reedy wrote: > Your professor should wait until your Python version is complete and in > final form and until a C version is needed. Then hire someone competent > in both languages to do the translation. Professor... hire... Good one! :) -- Grant Edwards grante Yow! BARRY ... That was at the most HEART-WARMING visi.com rendition of "I DID IT MY WAY" I've ever heard!! From koranthala at gmail.com Wed Jun 24 14:38:02 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 24 Jun 2009 11:38:02 -0700 (PDT) Subject: Matplotlib - an odd problem Message-ID: <2717e804-3ec0-4bbc-b850-17dbefa5d45b@g15g2000pra.googlegroups.com> Hi, I am using Matplotlib with Django to display charts on the web page. I am facing an odd problem in that, everytime I do a refresh on the web page, the image darkens - and the text becomes little unreadable. 5/6 refreshes later, the text becomes completely unreadable. Since I am using Django test server, the same process is being used. i.e. every refresh does not create a new process. When I tried killing the process, the image again cleared. So I think it is sort of memory leak or a saved value which is messing up something. But I cannot seem to find the issue at all. The code is as follows - import pylab from cStringIO import StringIO def print_pie_chart(request): labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' data = [15,30,45, 10] pylab.figure(1, figsize=(2,2)) ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', shadow=True) out = StringIO() pylab.savefig(out, format="PNG") out.seek(0) response = HttpResponse() response['Content-Type'] = 'image/png' response.write(out.read()) return response Can anyone help me out here? From tjreedy at udel.edu Wed Jun 24 14:40:36 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Jun 2009 14:40:36 -0400 Subject: Get name of class without instance In-Reply-To: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> References: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> Message-ID: Bryan wrote: > How come dir(Foo) does not show __name__? That is how I was > investigating the possibilities. Interesting question. Seems like an oversight. dir(some_module) and dir(some_function) include '__name__'. I suggest you search the tracker for existing issues on this subject and add a feature request if there is none. From donnyf at gmail.com Wed Jun 24 14:42:56 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 11:42:56 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 11:57?am, Scott David Daniels wrote: > What OS and version, what Python and version. Win XP, Python 2.6.2 From saurabh.gupta.7 at gmail.com Wed Jun 24 14:46:55 2009 From: saurabh.gupta.7 at gmail.com (Saurabh) Date: Wed, 24 Jun 2009 11:46:55 -0700 (PDT) Subject: Tutorials on Jinja Message-ID: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Hi All, I am trying to move my application on a MVC architecture and plan to use Jinja for the same. Can anyone provide me with few quick links that might help me to get started with Jinja? Thanks, Saby From Wwy58 at yahoo.com Wed Jun 24 14:59:29 2009 From: Wwy58 at yahoo.com (David) Date: Wed, 24 Jun 2009 11:59:29 -0700 (PDT) Subject: urllib2.urlopen issue References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> Message-ID: <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> On Jun 24, 11:27?am, Chris Rebert wrote: > On Wed, Jun 24, 2009 at 10:50 AM, David wrote: > > hello, > > > I have a url that is "http://query.directrdr.com/ptrack? > > pid=225&v_url=http:// > >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". > > If I open it on a browser, I can get its contents without any > > problem. > > However, if I use following code, > > > import urllib2 > > > url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// > >www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' > > > xml = urllib2.urlopen(url).read() > > > then I get an exception of > > > ?File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open > > ? ?raise URLError(err) > > urllib2.URLError: > > Unable to reproduce with either urllib or urllib2's urlopen(). I get > some XML back without error both ways. Using Python 2.6.2 on Mac OS X. > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Thanks Aahz. And thanks Chris. The XML content is what I am looking for. I use Python 2.5. Maybe I should update to 2.6.2? Python version problem? From unayok at gmail.com Wed Jun 24 15:48:44 2009 From: unayok at gmail.com (unayok) Date: Wed, 24 Jun 2009 12:48:44 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 10:23?am, Chuck Connors wrote: > Hey guys. ?I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. ?I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. ?Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? ?I am not > asking for anyone to write the code but merely a push in the right > direction. Here's a little nudge: http://code.activestate.com/recipes/157035/ In place of its "print" line, you'd make your call into your existing code to send the message. Some of the comments offer some improvements on it (always read the comments on the recipes), but this is likely the direction you will want to head. From twirlip at bigfoot.com Wed Jun 24 15:53:49 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 20:53:49 +0100 Subject: It's ... Message-ID: ... my first Python program! So please be gentle (no fifty ton weights on the head!), but tell me if it's properly "Pythonic", or if it's a dead parrot (and if the latter, how to revive it). I'm working from Beazley's /Python: Essential Reference/ (2nd ed. 2001), so my first newbie question is how best to find out what's changed from version 2.1 to version 2.5. (I've recently installed 2.5.4 on my creaky old Win98SE system.) I expect to be buying the 4th edition when it comes out, which will be soon, but before then, is there a quick online way to find this out? Having only got up to page 84 - where we can actually start to read stuff from the hard disk - I'm emboldened to try to learn to do something useful, such as removing all those annoying hard tab characters from my many old text files (before I cottoned on to using soft tabs in my text editor). This sort of thing seems to work, in the interpreter (for an ASCII text file, named 'h071.txt', in the current directory): stop = 3 # Tab stops every 3 characters from types import StringType # Is this awkwardness necessary? detab = lambda s : StringType.expandtabs(s, stop) # Or use def f = open('h071.txt') # Do some stuff to f, perhaps, and then: f.seek(0) print ''.join(map(detab, f.xreadlines())) f.close() Obviously, to turn this into a generally useful program, I need to learn to write to a new file, and how to parcel up the Python code, and write a script to apply the "detab" function to all the files found by searching a Windows directory, and replace the old files with the new ones; but, for the guts of the program, is this a reasonable way to write the code to strip tabs from a text file? For writing the output file, this seems to work in the interpreter: g = open('temp.txt', 'w') g.writelines(map(detab, f.xreadlines())) g.close() In practice, does this avoid creating the whole string in memory at one time, as is done by using ''.join()? (I'll have to read up on "opaque sequence objects", which have only been mentioned once or twice in passing - another instance perhaps being an xrange()?) Not that that matters much in practice (in this simple case), but it seems elegant to avoid creating the whole output file at once. OK, I'm just getting my feet wet, and I'll try not to ask too many silly questions! First impressions are: (1) Python seems both elegant and practical; and (2) Beazley seems a pleasantly unfussy introduction for someone with at least a little programming experience in other languages. -- Angus Rodgers From lie.1296 at gmail.com Wed Jun 24 15:57:09 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 19:57:09 GMT Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: Mag Gam wrote: > Sorry for the delayed response. I was trying to figure this problem > out. The OS is Linux, BTW Maybe I'm just being pedantic, but saying your OS is Linux means little as there are hundreds of variants (distros) of Linux. (Not to mention that Linux is a kernel, not a full blown OS, and people in GNU will insist to call Linux-based OS GNU/Linux) > Here is some code I have: > import numpy as np > from numpy import * Why are you importing numpy twice as np and as *? > import gzip > import h5py > import re > import sys, string, time, getopt > import os > > src=sys.argv[1] > fs = gzip.open(src) > x=src.split("/") > filename=x[len(x)-1] > > #Get YYYY/MM/DD format > YYYY=(filename.rsplit(".",2)[0])[0:4] > MM=(filename.rsplit(".",2)[0])[4:6] > DD=(filename.rsplit(".",2)[0])[6:8] > > f=h5py.File('/tmp/test_foo/FE.hdf5','w') this particular line would make it impossible to have more than one instance of the program open. May not be your concern... > > grp="/"+YYYY > try: > f.create_group(grp) > except ValueError: > print "Year group already exists" > > grp=grp+"/"+MM > try: > f.create_group(grp) > except ValueError: > print "Month group already exists" > > grp=grp+"/"+DD > try: > group=f.create_group(grp) > except ValueError: > print "Day group already exists" > > str_type=h5py.new_vlen(str) > mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', > 'f4', 'f4')} > print "Filename is: ",src > fs = gzip.open(src) > dset = f.create_dataset ('Foo',data=arr,compression='gzip') What is `arr`? > s=0 > > #Takes the longest here > for y in fs: > continue > a=y.split(',') > s=s+1 > dset.resize(s,axis=0) You increment s by 1 for each iteration, would this copy the dataset? (I never worked with h5py, so I don't know how it works) From mail131 at gmail.com Wed Jun 24 16:17:35 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 13:17:35 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: On Jun 24, 1:32?pm, Peter Otten <__pete... at web.de> wrote: > Przemyslaw Bak wrote: > > Hello, > > > I many files with log data. The structure of the file is quite > > inconvenience and similar to the following example: > > Data1 > > ? ValueA > > Data2 > > ? ValueB > > Data3 > > ? ValueC > > ... > > To get the values I need to find Data* and then get to the next line. > > I tried to use fileinput.input : > > ... > > for line in fileinput.input(filename): > > ? ? if line.find("Data2") >= 0: > > ? ? ? ? (now what ?) > > > So I can find the requested line (Data2) but how to get value from the > > next line ? > > lines = fileinput.input(filename) > for line in lines: > ? ? if "Data2" in line: > ? ? ? ? print line.strip(), "-->", next(lines).strip() I get an error: ... print line.strip(), "-->", next(lines).strip() NameError: global name 'next' is not defined From Scott.Daniels at Acm.Org Wed Jun 24 16:34:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 13:34:33 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <08qdneYKoJrfEd_XnZ2dnUVZ_q-dnZ2d@pdx.net> Peter Otten wrote: > Scott David Daniels wrote: >> Peter Otten wrote: >>> with open(filename) as instream: >>> lines = (line.strip() for line in lines) >>> lookup = dict(zip(lines, lines)) > >> Little bit of a fluff-up here. > > Sorry, it should have been > > with open(filename) as instream: > lines = (line.strip() for line in instream) > lookup = dict(zip(lines, lines)) > >> Perhaps something like: >> >> with open(filename) as instream: >> lines = (line.strip() for line in instream) >> lookup = dict(zip(lines[::2], lines[1::2])) > > Tu quoque ;) You are exactly right (and my vocabulary expands a bit); I must go wipe the egg off of my face now. I still am thinking lists even though I am writing generators. I should have written: with open(filename) as instream: lines = [line.strip() for line in instream] lookup = dict(zip(lines[::2], lines[1::2])) But, your example does in fact work as written. --Scott David Daniels Scott.Daniels at Acm.Org From twirlip at bigfoot.com Wed Jun 24 16:34:59 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 21:34:59 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 20:53:49 +0100, I wrote: >[...] my first newbie question is how best to find out >what's changed from version 2.1 to version 2.5. >[...] is there a quick online way to find this out? One way seems to be: ... although there doesn't seem to be any ... ah! ... "What's New in Python 2.2" -- Angus Rodgers From aahz at pythoncraft.com Wed Jun 24 16:38:52 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 13:38:52 -0700 Subject: How to find info about python 3.x extension module availability? References: <2838671f-d582-4af1-b850-ccc18ff9dd76@a36g2000yqc.googlegroups.com> Message-ID: In article <2838671f-d582-4af1-b850-ccc18ff9dd76 at a36g2000yqc.googlegroups.com>, Francesco Bochicchio wrote: > >is there any site that reports the current porting (to Python 3.x) >status of the main non-standard extension modules (such as pygtk, >pywin32, wxpython, ...) ? Feel free to create a wiki page on python.org... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jcd at sdf.lonestar.org Wed Jun 24 16:40:29 2009 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 24 Jun 2009 16:40:29 -0400 Subject: It's ... In-Reply-To: References: Message-ID: <1245876029.20649.21.camel@aalcdl07> On Wed, 2009-06-24 at 20:53 +0100, Angus Rodgers wrote: > ... my first Python program! So please be gentle (no fifty ton > weights on the head!), but tell me if it's properly "Pythonic", > or if it's a dead parrot (and if the latter, how to revive it). > Yay. Welcome to Python. > I'm working from Beazley's /Python: Essential Reference/ (2nd > ed. 2001), so my first newbie question is how best to find out > what's changed from version 2.1 to version 2.5. (I've recently > installed 2.5.4 on my creaky old Win98SE system.) I expect to > be buying the 4th edition when it comes out, which will be soon, > but before then, is there a quick online way to find this out? > Check here: http://docs.python.org/whatsnew/index.html It's not designed to be newbie friendly, but it's in there. > Having only got up to page 84 - where we can actually start to > read stuff from the hard disk - I'm emboldened to try to learn > to do something useful, such as removing all those annoying hard > tab characters from my many old text files (before I cottoned on > to using soft tabs in my text editor). > > This sort of thing seems to work, in the interpreter (for an > ASCII text file, named 'h071.txt', in the current directory): > > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? Not anymore. You can just use str for this. > detab = lambda s : StringType.expandtabs(s, stop) # Or use def First, use def. lambda is a rarity for use when you'd rather not assign your function to a variable. Second, expandtabs is a method on string objects. s is a string object, so you can just use s.expandtabs(stop) Third, I'd recommend passing your tabstops into detab with a default argument, rather than defining it irrevocably in a global variable (which is brittle and ugly) def detab(s, stop=3): #do stuff Then you can do three_space_version = detab(s) eight_space_version = detab(s, 8) > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) f is not opened for writing, so if you do stuff to the contents of f, you'll have to put the new version in a different variable, so f.seek(0) doesn't help. If you don't do stuff to it, then you're at the beginning of the file anyway, so either way, you shouldn't need to f.seek(0). > print ''.join(map(detab, f.xreadlines())) Sometime in the history of python, files became iterable, which means you can do the following: for line in f: print detab(line) Much prettier than running through join/map shenanigans. This is also the place to modify the output before passing it to detab: for line in f: # do stuff to line print detab(line) Also note that you can iterate over a file several times: f = open('foo.txt') for line in f: print line[0] # prints the first character of every line for line in f: print line[1] #prints the second character of every line > f.close() > > Obviously, to turn this into a generally useful program, I need > to learn to write to a new file, and how to parcel up the Python > code, and write a script to apply the "detab" function to all the > files found by searching a Windows directory, and replace the old > files with the new ones; but, for the guts of the program, is this > a reasonable way to write the code to strip tabs from a text file? > > For writing the output file, this seems to work in the interpreter: > > g = open('temp.txt', 'w') > g.writelines(map(detab, f.xreadlines())) > g.close() > Doesn't help, as map returns a list. You can use itertools.imap, or you can use a for loop, as above. > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? (I'll have to read up > on "opaque sequence objects", which have only been mentioned once > or twice in passing - another instance perhaps being an xrange()?) > Not that that matters much in practice (in this simple case), but > it seems elegant to avoid creating the whole output file at once. The terms to look for, rather than opaque sequence objects are "iterators" and "generators". > > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. > Glad you're enjoying Beazley. I would look for something more up-to-date. Python's come a long way since 2.1. I'd hate for you to miss out on all the iterators, booleans, codecs, subprocess, yield, unified int/longs, decorators, decimals, sets, context managers and new-style classes that have come since then. > -- > Angus Rodgers Cheers, Cliff From python at mrabarnett.plus.com Wed Jun 24 16:44:27 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 21:44:27 +0100 Subject: [SPAM] It's ... In-Reply-To: References: Message-ID: <4A42902B.6060701@mrabarnett.plus.com> Angus Rodgers wrote: [snip] > This sort of thing seems to work, in the interpreter (for an > ASCII text file, named 'h071.txt', in the current directory): > > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? > detab = lambda s : StringType.expandtabs(s, stop) # Or use def > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) > f.close() > stop = 3 # Tab stops every 3 characters detab = lambda s: s.expandtabs(stop) f = open('h071.txt') # Do some stuff to f, perhaps, and then: # f.seek(0) # Not necessary print ''.join(map(detab, f.xreadlines())) f.close() > Obviously, to turn this into a generally useful program, I need > to learn to write to a new file, and how to parcel up the Python > code, and write a script to apply the "detab" function to all the > files found by searching a Windows directory, and replace the old > files with the new ones; but, for the guts of the program, is this > a reasonable way to write the code to strip tabs from a text file? > > For writing the output file, this seems to work in the interpreter: > > g = open('temp.txt', 'w') > g.writelines(map(detab, f.xreadlines())) > g.close() > > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? (I'll have to read up > on "opaque sequence objects", which have only been mentioned once > or twice in passing - another instance perhaps being an xrange()?) > Not that that matters much in practice (in this simple case), but > it seems elegant to avoid creating the whole output file at once. > > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. > STOP = 3 # Tab stops every 3 characters in_file = open('h071.txt') out_file = open('temp.txt', 'w') for line in in_file: # Iterates one line at a time out_file.write(line.expandtabs(STOP)) in_file.close() out_file.close() From janssonks at gmail.com Wed Jun 24 16:48:15 2009 From: janssonks at gmail.com (Karl Jansson) Date: Wed, 24 Jun 2009 15:48:15 -0500 Subject: installation in mac os x In-Reply-To: <79c05cF1q46qkU1@mid.uni-berlin.de> References: <79c05cF1q46qkU1@mid.uni-berlin.de> Message-ID: <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> > > What happens if you work on the commandline (Terminal)? > > Python2.6 should be available from (out of my head) > > /Library/Frameworks/Python.framework/Versions/2.6/bin/python > > If that's working, it is successfully installed. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list If I work on the commandline, I have version 2.3, which works. But some of the commands in the tutorial don't work with that version, so I had to upgrade in order to do the tutorial. But I still can't do it, obviously. Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Jun 24 17:00:27 2009 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Jun 2009 23:00:27 +0200 Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Private Private wrote: > > lines = fileinput.input(filename) > > for line in lines: > > if "Data2" in line: > > print line.strip(), "-->", next(lines).strip() > > I get an error: > > ... > print line.strip(), "-->", next(lines).strip() > NameError: global name 'next' is not defined In Python versions prior to 2.6 instead of next(lines) you can use lines.next() Peter From frank.ruiz at gmail.com Wed Jun 24 17:01:02 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 14:01:02 -0700 Subject: Paramiko Help Message-ID: Apologies.. Python newb here.. switching from perl to python.. so please forgive if this is a dumb question. I am using the paramiko module and have some global variables defined. i.e. hostname = ' 10.10.10.10' sshport = '22' I am then trying to pass this variable into the client connect method - client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, root) I also have public key setup between source and destination host, so not sure if this will work, but trying to jump one hurtle at at time. So it seems like the values past to the connect method are taken at face value based on the error message I am seeing: TypeError: an integer is required Any help is much appreciated. Thanks! From joncle at googlemail.com Wed Jun 24 17:04:51 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Jun 2009 14:04:51 -0700 (PDT) Subject: Paramiko Help References: Message-ID: <99d20f8c-8106-4c70-8e60-8a8f2ebeb736@o36g2000vbi.googlegroups.com> On Jun 24, 10:01?pm, Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' > > I am then trying to pass this variable into the client connect method - > > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, root) > > I also have public key setup between source and destination host, so > not sure if this will work, but trying to jump one hurtle at at time. > > So it seems like the values past to the connect method are taken at > face value based on the error message I am seeing: > > TypeError: an integer is required > > Any help is much appreciated. > > Thanks! wild guess: should sshport = 22 (instead of '22') From clp2 at rebertia.com Wed Jun 24 17:05:37 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Jun 2009 14:05:37 -0700 Subject: Paramiko Help In-Reply-To: References: Message-ID: <50697b2c0906241405y62cf236al5a138a2813968bb@mail.gmail.com> On Wed, Jun 24, 2009 at 2:01 PM, Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' I'm haven't used Paramiko, but I would guess that this should instead be: sshport = 22 Note that Python does not autoconvert between strings and numbers like Perl does. Also, in the future, please give the full error traceback, not just the final error message, as it's much harder to debug code without it. Cheers, Chris -- http://blog.rebertia.com From jeff_barish at earthlink.net Wed Jun 24 17:06:27 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Wed, 24 Jun 2009 15:06:27 -0600 Subject: Problem with multithreading Message-ID: I have a program that uses multithreading to monitor two loops. When something happens in loop1, it sends a message to loop2 to have it execute a command. loop2 might have to return a result. If it does, it puts the result in a queue. loop1, meanwhile, would have blocked waiting for something to appear in the queue. The program works for a while, but eventually freezes. I know that freezing is a sign of deadlock. However, I put in print statements to localize the problem and discovered something weird. The freeze always occurs at a point in the code with the following statements: print "about to try" try: print "in try" I get "about to try", but not "in try". Is this observation consistent with the deadlock theory? If not, what could be making the program freeze at the try statement? I wrote a test program using the same techniques to illustrate the problem, but the test program works perfectly. I could post it, though, if it would help to understand what I am doing -- and what might be wrong in the real program. -- Jeffrey Barish From Scott.Daniels at Acm.Org Wed Jun 24 17:10:54 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 14:10:54 -0700 Subject: It's ... In-Reply-To: References: Message-ID: Angus Rodgers wrote: > ... my first ... question is how best to find out what's changed from version 2.1 > to version 2.5. (I've recently installed 2.5.4) Consecutively read: http://docs.python.org/whatsnew/2.2.html http://docs.python.org/whatsnew/2.3.html http://docs.python.org/whatsnew/2.4.html http://docs.python.org/whatsnew/2.5.html > stop = 3 # Tab stops every 3 characters Typically program constants should be full caps. See PEP 8 > from types import StringType # Is this awkwardness necessary? Nope > detab = lambda s : StringType.expandtabs(s, stop) # Or use def Really use def unless you have a solid reason not to. At the moment, I'd suggest you simply presume you have no such reason. Also, expandtabs is an instance method, so the roundabout is not needed. def detab(s): return s.expandtabs(stop) > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) Too much, even though that is how you thought the problem out. First, text files are now iterable (producing a line at a time much like xreadlines). Second the map above creates a list of all detabbed lines, then (while that list still exists), it also creates a string constant which is the "new" contents of the file. I'd simply use: for line in f: print detab(line.rstrip()) or even: for line in f: print line.rstrip().expandtabs(stop) > ... > g.writelines(map(detab, f.xreadlines())) > > In practice, does this avoid creating the whole string in memory > at one time, as is done by using ''.join()? Nope. But you could use a generator expression if you wanted: g.writelines(detab(line) for line in f) > OK, I'm just getting my feet wet, and I'll try not to ask too many > silly questions! > > First impressions are: (1) Python seems both elegant and practical; > and (2) Beazley seems a pleasantly unfussy introduction for someone > with at least a little programming experience in other languages. Both 1 and 2 are true in spades. --Scott David Daniels Scott.Daniels at Acm.Org From donnyf at gmail.com Wed Jun 24 17:12:22 2009 From: donnyf at gmail.com (Chuck Connors) Date: Wed, 24 Jun 2009 14:12:22 -0700 (PDT) Subject: Reading then sending new parts of a log file References: Message-ID: On Jun 24, 2:48?pm, unayok wrote: > Here's a little nudge:http://code.activestate.com/recipes/157035/ > > In place of its "print" line, you'd make your call into your existing > code to send the message. Wow! Thanks for the _shove_ in the right direction. Looks perfect. From twirlip at bigfoot.com Wed Jun 24 17:12:33 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:12:33 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 16:40:29 -0400, "J. Cliff Dyer" wrote: >On Wed, 2009-06-24 at 20:53 +0100, Angus Rodgers wrote: >> [...] >> from types import StringType # Is this awkwardness necessary? > >Not anymore. You can just use str for this. > >> detab = lambda s : StringType.expandtabs(s, stop) # Or use def > >First, use def. lambda is a rarity for use when you'd rather not assign >your function to a variable. > >Second, expandtabs is a method on string objects. s is a string object, >so you can just use s.expandtabs(stop) How exactly do I get detab, as a function from strings to strings (for a fixed tab size)? (This is aside from the point, which you make below, that the whole map/join idea is a bit of a no-no - in some other context, I might want to isolate a method like this.) >Third, I'd recommend passing your tabstops into detab with a default >argument, rather than defining it irrevocably in a global variable >(which is brittle and ugly) No argument there - I was just messing about in the interpreter, to see if the main idea worked. >> f = open('h071.txt') # Do some stuff to f, perhaps, and then: >> f.seek(0) > >f is not opened for writing, so if you do stuff to the contents of f, >you'll have to put the new version in a different variable, so f.seek(0) >doesn't help. If you don't do stuff to it, then you're at the beginning >of the file anyway, so either way, you shouldn't need to f.seek(0). I seemed to find that if I executed f.xreadlines() or f.readlines() once, I was somehow positioned at the end of the file or something, and had to do the f.seek(0) - but maybe I did something else silly. >> print ''.join(map(detab, f.xreadlines())) > >Sometime in the history of python, files became iterable, which means >you can do the following: > >for line in f: > print detab(line) > >Much prettier than running through join/map shenanigans. This is also >the place to modify the output before passing it to detab: > >for line in f: > # do stuff to line > print detab(line) > >Also note that you can iterate over a file several times: > >f = open('foo.txt') >for line in f: > print line[0] # prints the first character of every line >for line in f: > print line[1] #prints the second character of every line >> f.close() This all looks very nice. >> For writing the output file, this seems to work in the interpreter: >> >> g = open('temp.txt', 'w') >> g.writelines(map(detab, f.xreadlines())) >> g.close() >> > >Doesn't help, as map returns a list. Pity. Oh, well. >You can use itertools.imap, or you >can use a for loop, as above. This is whetting my appetite! >The terms to look for, rather than opaque sequence objects are >"iterators" and "generators". OK, will do. >Glad you're enjoying Beazley. I would look for something more >up-to-date. Python's come a long way since 2.1. I'd hate for you to >miss out on all the iterators, booleans, codecs, subprocess, yield, >unified int/longs, decorators, decimals, sets, context managers and >new-style classes that have come since then. I'll get either Beazley's 4th ed. (due next month, IIRC), or Chun, /Core Python Programming/ (2nd ed.), or both, unless someone has a better suggestion. (Eventually I'll migrate from Windows 98SE(!), and will need info on Python later than 2.5, but that's all I need for now.) -- Angus Rodgers From philip at semanchuk.com Wed Jun 24 17:13:10 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 24 Jun 2009 17:13:10 -0400 Subject: installation in mac os x In-Reply-To: <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> References: <79c05cF1q46qkU1@mid.uni-berlin.de> <6E5BC1AF-8A08-4C73-845F-22C92935DA5E@gmail.com> Message-ID: <95F13F9F-7E39-4376-8530-09EE1D358D67@semanchuk.com> On Jun 24, 2009, at 4:48 PM, Karl Jansson wrote: >> >> What happens if you work on the commandline (Terminal)? >> >> Python2.6 should be available from (out of my head) >> >> /Library/Frameworks/Python.framework/Versions/2.6/bin/python >> >> If that's working, it is successfully installed. >> >> Diez >> -- http://mail.python.org/mailman/listinfo/python-list > > If I work on the commandline, I have version 2.3, which works. But > some of the commands in the tutorial don't work with that version, > so I had to upgrade in order to do the tutorial. But I still can't > do it, obviously. The system Python (2.3) is in /usr/bin and that's probably first in your path, so when you simply type 'python' it finds /usr/bin/python. Python 2.6 might have installed itself in /usr/local/bin. Try invoking /usr/local/bin/python and see which one you get (if that works at all). If that's Python 2.6, then move /usr/local/bin ahead of usr/bin in your path and then you'll invoke Python 2.6 by just typing 'python' at the command line. If that doesn't work, hunt around in /Library/Frameworks as Diez suggested. Until we figure out whether or not you actually have 2.6 installed, it is difficult to suggest how to invoke it. Let us know what you find. bye Philip From Scott.Daniels at Acm.Org Wed Jun 24 17:13:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 14:13:13 -0700 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: Private Private wrote: > On Jun 24, 1:32 pm, Peter Otten <__pete... at web.de> wrote: ... >> lines = fileinput.input(filename) >> for line in lines: >> if "Data2" in line: >> print line.strip(), "-->", next(lines).strip() > > I get an error: > > ... > print line.strip(), "-->", next(lines).strip() > NameError: global name 'next' is not defined > Sorry, I am running 2.6 Try: print line.strip(), "-->", lines.next().strip() --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Wed Jun 24 17:13:58 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2009 22:13:58 +0100 Subject: Paramiko Help In-Reply-To: References: Message-ID: <4A429716.3070102@mrabarnett.plus.com> Frank Ruiz wrote: > Apologies.. Python newb here.. switching from perl to python.. so > please forgive if this is a dumb question. > > I am using the paramiko module and have some global variables defined. > > i.e. > > hostname = ' 10.10.10.10' > sshport = '22' > > I am then trying to pass this variable into the client connect method - > > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, root) > > I also have public key setup between source and destination host, so > not sure if this will work, but trying to jump one hurtle at at time. > > So it seems like the values past to the connect method are taken at > face value based on the error message I am seeing: > > TypeError: an integer is required > > Any help is much appreciated. > It looks like sshport needs to be an integer, not a string. Unlike Perl, Python won't magically convert the string to an integer. From twirlip at bigfoot.com Wed Jun 24 17:15:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:15:43 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 22:12:33 +0100, I wrote: >How exactly do I get detab, as a function from strings to strings >(for a fixed tab size)? (It's OK - this has been explained in another reply. I'm still a little hazy about what exactly objects are in Python, but the haze will soon clear, I'm sure, especially after I have written more than one one-line program!) -- Angus Rodgers From lie.1296 at gmail.com Wed Jun 24 17:17:18 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 21:17:18 GMT Subject: Why is it that str.replace doesn't work sometimes? In-Reply-To: References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: MRAB wrote: > There's no difference between the two types of quote character. a small exception is single-quote can contain double quote but cannot contain unescaped single quote while double-quote can contain single quote but cannot contain unescaped double quote. From lie.1296 at gmail.com Wed Jun 24 17:31:32 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Jun 2009 21:31:32 GMT Subject: Problem with multithreading In-Reply-To: References: Message-ID: Jeffrey Barish wrote: > I have a program that uses multithreading to monitor two loops. When > something happens in loop1, it sends a message to loop2 to have it execute > a command. loop2 might have to return a result. If it does, it puts the > result in a queue. loop1, meanwhile, would have blocked waiting for > something to appear in the queue. The program works for a while, but > eventually freezes. I know that freezing is a sign of deadlock. However, > I put in print statements to localize the problem and discovered something > weird. The freeze always occurs at a point in the code with the following > statements: > > print "about to try" > try: > print "in try" > > > I get "about to try", but not "in try". Is this observation consistent with > the deadlock theory? If not, what could be making the program freeze at > the try statement? I wrote a test program using the same techniques to > illustrate the problem, but the test program works perfectly. I could post > it, though, if it would help to understand what I am doing -- and what > might be wrong in the real program. The key in writing a test code is to reduce the buggy code until you can't reduce anymore without losing the bug. It is sometimes difficult to write a buggy test code... try writing the test code again with that technique, and post it From twirlip at bigfoot.com Wed Jun 24 17:43:01 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Wed, 24 Jun 2009 22:43:01 +0100 Subject: It's ... References: Message-ID: On Wed, 24 Jun 2009 14:10:54 -0700, Scott David Daniels wrote: >Angus Rodgers wrote: > >> from types import StringType # Is this awkwardness necessary? >Nope I'm starting to see some of the mental haze that was confusing me. >Also, expandtabs is an instance method, so the roundabout is not needed. > > def detab(s): > return s.expandtabs(stop) I'd forgotten where Beazley had explained that "methods such as ... s.expandtabs() always return a new string as opposed to mod- ifying the string s." I must have been hazily thinking of it as somehow modifying s, even though my awkward code itself depended on a vague understanding that it didn't. No point in nailing this polly to the perch any more! >I'd simply use: > for line in f: > print detab(line.rstrip()) >or even: > for line in f: > print line.rstrip().expandtabs(stop) I'll read up on iterating through files, somewhere online for the moment, and then get a more up-to-date textbook. And I'll try not too ask too many silly questions like this, but I wanted to make sure I wasn't getting into any bad programming habits right at the start - and it's a good thing I did, because I was! >Nope. But you could use a generator expression if you wanted: > g.writelines(detab(line) for line in f) Ah, so that actually does what I was fondly hoping my code would do. Thanks! I must learn about these "generator" thingies. -- Angus Rodgers From davea at ieee.org Wed Jun 24 17:43:20 2009 From: davea at ieee.org (Dave Angel) Date: Wed, 24 Jun 2009 17:43:20 -0400 Subject: Reading then sending new parts of a log file In-Reply-To: References: Message-ID: <4A429DF8.2000204@ieee.org> Chuck Connors wrote: > Hey guys. I'm trying to work up a little program that will send any > new lines written to a file (log file from my home automation > software) to me via instant message. I've gotten the instant message > sending part figured out using xmpppy. > > I've done a few things with Python in the past but I am in no means > more than a beginner/hacker. Can someone tell me what commands/ > modules/etc exist for monitoring and parsing a file for new > information that I can then send to my IM sending function? I am not > asking for anyone to write the code but merely a push in the right > direction. > > Thanks! > > I assume you have a reason not to put the logic into the program that's creating the log file. Tell us the Python version, and OS it's running on. So your problem is to monitor a text file, and detect whenever it grows, taking the new parts and incrementally doing something with them. Here's a fragment from my tail program: def getRest(options, filename, oldstat, stat, callback): more = stat.st_size - oldstat.st_size #Note: this could be negative, if the file shrank while we were waiting if more > 0: infile = open(filename, "rb") infile.seek(oldstat.st_size) buf = infile.read(more) #BUGBUG perhaps should break this into multiple reads, if over 8k callback(buf) #process the new text def follow(options, filename, oldstat, callback): while True: stat = os.stat(filename) if stat.st_mtime > oldstat.st_mtime or stat.st_size != oldstat.st_size: getRest(options, filename, oldstat, stat, callback) oldstat = stat else: time.sleep(options.sec_to_wait) The concept here is that we only do real work when the stat() of a file has changed. Then, if the size is larger than last time, we process the new text. options is an object with various optional attributes. In this case, I think the only one used was sec_to_wait, which is how long we should delay before re-checking the stat. If it's too small, you waste CPU time. Your callback will have to deal with breaking things into messages, probably at convenient line-breaks. And of course the whole thing might want to be turned inside out, and coded as a generator. But it's a starting point, as you asked. From aahz at pythoncraft.com Wed Jun 24 17:54:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 24 Jun 2009 14:54:34 -0700 Subject: It's ... References: Message-ID: In article , J. Cliff Dyer wrote: > >Glad you're enjoying Beazley. I would look for something more >up-to-date. Python's come a long way since 2.1. I'd hate for you to >miss out on all the iterators, booleans, codecs, subprocess, yield, >unified int/longs, decorators, decimals, sets, context managers and >new-style classes that have come since then. While those are all nice, they certainly aren't essential to learning Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From exarkun at divmod.com Wed Jun 24 17:55:12 2009 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 24 Jun 2009 17:55:12 -0400 Subject: Matplotlib - an odd problem In-Reply-To: <2717e804-3ec0-4bbc-b850-17dbefa5d45b@g15g2000pra.googlegroups.com> Message-ID: <20090624215513.22176.1757453334.divmod.quotient.9186@henry.divmod.com> On Wed, 24 Jun 2009 11:38:02 -0700 (PDT), koranthala wrote: >Hi, >I am using Matplotlib with Django to display charts on the web page. >I am facing an odd problem in that, everytime I do a refresh on the >web page, the image darkens - and the text becomes little unreadable. >5/6 refreshes later, the text becomes completely unreadable. >Since I am using Django test server, the same process is being used. >i.e. every refresh does not create a new process. When I tried killing >the process, the image again cleared. >So I think it is sort of memory leak or a saved value which is messing >up something. >But I cannot seem to find the issue at all. > >The code is as follows - > >import pylab >from cStringIO import StringIO > >def print_pie_chart(request): > labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > data = [15,30,45, 10] > pylab.figure(1, figsize=(2,2)) > ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) > pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', >shadow=True) > out = StringIO() > pylab.savefig(out, format="PNG") > out.seek(0) > response = HttpResponse() > response['Content-Type'] = 'image/png' > response.write(out.read()) > return response > >Can anyone help me out here? Your code redraws over the same graph over and over again. You need to create a new graph each time you want to draw something new. It took me ages (and help) to figure out how the non-global APIs in matplotlib. Here's an example: from matplotlib.figure import Figure from matplotlib.axes import Axes from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas fig = Figure(figsize=(9, 9), dpi=100) axe = Axes(fig, (0, 0, 1.0, 1.0)) axe.pie(range(5)) fig.add_axes(axe) canvas = FigureCanvas(fig) canvas.set_size_request(640, 480) fig.savefig("foo.png") Hope this helps, Jean-Paul From lists at cheimes.de Wed Jun 24 17:59:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Wed, 24 Jun 2009 23:59:52 +0200 Subject: Get name of class without instance In-Reply-To: References: <89574777-bce7-49f1-a4a5-f4fa87b5cfe7@v2g2000vbb.googlegroups.com> Message-ID: Terry Reedy wrote: > Bryan wrote: > >> How come dir(Foo) does not show __name__? That is how I was >> investigating the possibilities. > > Interesting question. Seems like an oversight. dir(some_module) and > dir(some_function) include '__name__'. I suggest you search the tracker > for existing issues on this subject and add a feature request if there > is none. The __name__ attribute of types and classes is actually a descriptor of the metaclass. It doesn't show up just like __bases__ and a few others. However for modules __name__ is just an ordinary attribute that gets set by the module class. Christian From milesck at umich.edu Wed Jun 24 18:04:38 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Wed, 24 Jun 2009 18:04:38 -0400 Subject: urllib2.urlopen issue In-Reply-To: <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> References: <854313cf-6323-4ca9-b883-65ca8f414d96@v23g2000pro.googlegroups.com> <0123dfb4-17c9-44ac-b312-5fea0352cc9d@a39g2000pre.googlegroups.com> Message-ID: <43B36CC2-259C-404D-8E28-36455C08C92B@umich.edu> On Jun 24, 2009, at 2:59 PM, David wrote: > On Jun 24, 11:27 am, Chris Rebert wrote: >> On Wed, Jun 24, 2009 at 10:50 AM, David wrote: >>> hello, >>> >>> I have a url that is "http://query.directrdr.com/ptrack? >>> pid=225&v_url=http:// >>> www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said". >>> If I open it on a browser, I can get its contents without any >>> problem. >>> However, if I use following code, >>> >>> import urllib2 >>> >>> url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http:// >>> www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said' >>> >>> xml = urllib2.urlopen(url).read() >>> >>> then I get an exception of >>> >>> File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open >>> raise URLError(err) >>> urllib2.URLError: >> >> Unable to reproduce with either urllib or urllib2's urlopen(). I get >> some XML back without error both ways. Using Python 2.6.2 on Mac OS >> X. >> > > Thanks Aahz. And thanks Chris. The XML content is what I am looking > for. I use Python 2.5. Maybe I should update to 2.6.2? Python version > problem? No, it also works for me on Python 2.5.1. A wild guess: does this code work? import socket socket.gethostbyname(socket.gethostname()) If it throws a similar exception (Name or service not known), the root problem may be a misconfiguration in your /etc/hosts or /etc/ resolv.conf files. -Miles From frank.ruiz at gmail.com Wed Jun 24 18:22:02 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 15:22:02 -0700 Subject: Paramiko help - processing multiple commands Message-ID: Greetings, I am trying to process multiple commands using paramiko. I have searched other threads, and I think my use case is a little different. I am trying to login to a storage node that has a special shell, and as such I cant execute a script on the storage node side. I am also trying to avoid using pexpect because I hate making system calls.. hence my leaning towards paramiko. Was hoping someone could help me identify a way to process multiple commands using paramiko. I have two commands listed below, however only one is getting processed. Any help is much appreciated. Thanks! Here is my script: #!/usr/bin/env python #-Modules--------------------------------------------------------------------- import optparse import sys import paramiko #-Variables------------------------------------------------------------------- plog = 'storagessh.log' suser = 'root' #-Config---------------------------------------------------------------------- #-Subs-Defined---------------------------------------------------------------- def options(): global hostname global goldenimage global lunclone global sshport usage = "usage: %prog [options] -n -g -l " parser = optparse.OptionParser(usage) parser.add_option("-n", "--node", dest="hostname", help="Name of storage node you are connecting to.") parser.add_option("-g", "--gold", dest="goldenimage", help="Name of goldenimage to clone.") parser.add_option("-l", "--lun", dest="lunclone", help="Name of lun to create.") parser.add_option("-p", "--port", dest="sshport", default=22, help="SSH port number.") options, args = parser.parse_args() if not options.hostname: parser.error("Missing hostname argument.") exit elif not options.goldenimage: parser.error("Missing goldenimage argument.") exit elif not options.lunclone: parser.error("Missing lun argument.") exit hostname = options.hostname goldenimage = options.goldenimage lunclone = options.lunclone sshport = options.sshport def storagessh(): paramiko.util.log_to_file(plog) client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, suser) stdin, stdout, stderr = client.exec_command('show') stdin, stdout, stderr = client.exec_command('help') print stdout.read() client.close() #--Initialization------------------------------------------------------------- if __name__ == "__main__": options() storagessh() From cmpython at gmail.com Wed Jun 24 19:03:00 2009 From: cmpython at gmail.com (Che M) Date: Wed, 24 Jun 2009 16:03:00 -0700 (PDT) Subject: dynamically associate radio buttons with droplists References: <16b382ee-a3ae-46ee-88fd-d87fc40d208d@g20g2000vba.googlegroups.com> Message-ID: <207e83b0-812b-4c24-9fda-99d599354d52@f30g2000vbf.googlegroups.com> On Jun 24, 10:37?am, a... at pythoncraft.com (Aahz) wrote: > In article <16b382ee-a3ae-46ee-88fd-d87fc40d2... at g20g2000vba.googlegroups.com>, > > > > Shoryuken ? wrote: > >On Jun 21, 8:43=A0pm, a... at pythoncraft.com (Aahz) wrote: > >> In article >.com>,LeoBrugud=A0 wrote: > > >>>Not being very familiar with python, nor with cgi/http, =A0I intend to > >>>have 3 of buttons in a webpage, each of them is associate with a file > >>>(so I have 3 files, too) > > >>>What I would like to have is, when users choose a button, the droplist > >>>update automatically to load the contents of the associated file. > > >> Are you trying to do this without requiring the user to click the submit > >> button? =A0If yes, you need to learn JavaScript (although I think there a= > >re > >> web frameworks that will auto-generate the JavaScript, you need to know > >> JavaScript in order to do debugging). > > >Thanks, and yes I want to do it without the submit button > > >So python alone cannot do this? > > Correct; you need to have code run in the browser, and few browsers > support Python. Might want to consider Pyjamas, the python-to-javascript Compiler and a Web Widget set: http://code.google.com/p/pyjamas/ From twirlip at bigfoot.com Wed Jun 24 19:03:55 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 00:03:55 +0100 Subject: It's ... References: Message-ID: <15b545hkm0vr3h77b8qjgrn7dq08a4c7lu@4ax.com> On Wed, 24 Jun 2009 22:43:01 +0100, I wrote: >No point in nailing this polly to the perch any more! Indeed not, so please skip what follows (I've surely been enough of an annoying newbie, already!), but I've just remembered why I wrote my program in such an awkward way. I wanted to be able to import the type name t (StringType in this case) so that I could simply use t.m() as the name of one of its methods [if "method" is the correct term]; but in this case, where m is expandtabs(), an additional parameter (the tab size) is needed; so, I used the lambda expression to get around this, entirely failing to realise that (as was clearly shown in the replies I got), if I was going to use "lambda" at all (not recommended!), then it would be a lot simpler to write the function as lambda s : s.m(), with or without any additional parameters needed. (It didn't really have anything to do with a separate confusion as to what exactly "objects" are.) >I wanted to make sure I wasn't getting into any bad programming >habits right at the start I'm just trying to make sure I really understand how I screwed up. (In future, I'll try to work through a textbook with exercises. But I thought I'd better try to get some quick feedback at the start, because I knew that I was fumbling around, and that it was unlikely to be necessary to use such circumlocutions.) -- Angus Rodgers From joncle at googlemail.com Wed Jun 24 19:34:41 2009 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Jun 2009 16:34:41 -0700 (PDT) Subject: Paramiko help - processing multiple commands References: Message-ID: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> On Jun 24, 11:22?pm, Frank Ruiz wrote: > Greetings, > > I am trying to process multiple commands using paramiko. I have > searched other threads, and I think my use case is a little different. > I am trying to login to a storage node that has a special shell, and > as such I cant execute a script on the storage node side. > > I am also trying to avoid using pexpect because I hate making system > calls.. hence my leaning towards paramiko. > > Was hoping someone could help me identify a way to process multiple > commands using paramiko. > > I have two commands listed below, however only one is getting processed. > > Any help is much appreciated. > > Thanks! > > Here is my script: > > #!/usr/bin/env python > > #-Modules--------------------------------------------------------------------- > import optparse > import sys > import paramiko > > #-Variables------------------------------------------------------------------- > plog = 'storagessh.log' > suser = 'root' > > #-Config---------------------------------------------------------------------- > > #-Subs-Defined---------------------------------------------------------------- > def options(): > ? ? global hostname > ? ? global goldenimage > ? ? global lunclone > ? ? global sshport > > ? ? usage = "usage: %prog [options] -n -g -l " > > ? ? parser = optparse.OptionParser(usage) > > ? ? parser.add_option("-n", "--node", > ? ? ? ? ? ? ? ? ? ? ? dest="hostname", > ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") > ? ? parser.add_option("-g", "--gold", > ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", > ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") > ? ? parser.add_option("-l", "--lun", > ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", > ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") > ? ? parser.add_option("-p", "--port", > ? ? ? ? ? ? ? ? ? ? ? dest="sshport", > ? ? ? ? ? ? ? ? ? ? ? default=22, > ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") > ? ? options, args = parser.parse_args() > > ? ? if not options.hostname: > ? ? ? ? parser.error("Missing hostname argument.") > ? ? ? ? exit > ? ? elif not options.goldenimage: > ? ? ? ? parser.error("Missing goldenimage argument.") > ? ? ? ? exit > ? ? elif not options.lunclone: > ? ? ? ? parser.error("Missing lun argument.") > ? ? ? ? exit > > ? ? hostname = options.hostname > ? ? goldenimage = options.goldenimage > ? ? lunclone = options.lunclone > ? ? sshport = options.sshport > > def storagessh(): > ? ? paramiko.util.log_to_file(plog) > ? ? client = paramiko.SSHClient() > ? ? client.load_system_host_keys() > ? ? client.connect(hostname, sshport, suser) > ? ? stdin, stdout, stderr = client.exec_command('show') > ? ? stdin, stdout, stderr = client.exec_command('help') > ? ? print stdout.read() > ? ? client.close() > > #--Initialization------------------------------------------------------------- > if __name__ == "__main__": > ? ? options() > ? ? storagessh() Again, as you were asked on the original post -- full tracebacks and explain "what is not working". The use of global variables scares me -- why are those needed? From jcd at sdf.lonestar.org Wed Jun 24 19:41:44 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Wed, 24 Jun 2009 19:41:44 -0400 Subject: It's ... In-Reply-To: References: Message-ID: <1245886904.29331.5.camel@mctell> On Wed, 2009-06-24 at 14:54 -0700, Aahz wrote: > In article , > J. Cliff Dyer wrote: > > > >Glad you're enjoying Beazley. I would look for something more > >up-to-date. Python's come a long way since 2.1. I'd hate for you to > >miss out on all the iterators, booleans, codecs, subprocess, yield, > >unified int/longs, decorators, decimals, sets, context managers and > >new-style classes that have come since then. > > While those are all nice, they certainly aren't essential to learning > Python. Mostly, no, you are correct. With some exceptions: 1) You have to know iterators at a basic level (not enough to understand how the iterator protocol works, but enough to know what 'for line in f:' does. 2) Sets are as essential as any other data structure. If you are learning both lists and tuples, you should be learning sets as well. 3) If you're learning object-oriented programmin, new-style classes should be the only classes you use. 4) You should know how a decorator works, in case you run across one in the wild. 5) Booleans are a basic type. You should know them. Codecs, the subprocess module, yield, decimals and context managers can certainly come later. (All this of course, is assuming the Python 2.x world, which I think is still the right way to learn, for now) Cheers, Cliff > -- > Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha From luismgz at gmail.com Wed Jun 24 19:44:48 2009 From: luismgz at gmail.com (Neuruss) Date: Wed, 24 Jun 2009 16:44:48 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: On 23 jun, 12:49, Kurt Smith wrote: > On Mon, Jun 22, 2009 at 9:49 PM, Andras > > > > > > Pikler wrote: > > Hi! > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > > and I am at a loss. > > > Long: I?m doing research/programming for a professor, and we are working > > with MIDI files (a type of simple music file). The research deals with > > generating variations from a musical melody; currently, my Python code uses > > a Python midi package I found online to read the notes in question from a > > midi file, about 350 lines of my own code to generate a variation based on > > these notes and the professor?s algorithms, and finally the package again to > > write the new melody to another midi file. > > > Now, my professor would like to have this exact code in C/C++, as she > > believes C is more compatible with MATLAB, and wants the code to be > > available in multiple languages in case a programmer works for her in the > > future who knows C but not Python. While I know a tiny bit of C (emphasis on > > the tiny), I would much prefer if there were some sort of automatic compiler > > I could use to turn my Python code into C than taking a week or two or three > > to learn the minimum I need about C, find a way to access MIDI files in it, > > and rewrite all of my code. > > > After some googling, I found and tried Shedskin, but it doesn?t work, as the > > Python midi package I?m using uses modules which Shedskin does not support. > > Otherwise, I haven?t found much. Is there anything out there to help me do > > this? If not, from anyone who has experience in this regard, how daunting > > should I expect this to be? > > Taking on C from a cold start and being able to handle the ins and > outs of interfacing with Python isn't something that's feasible in > 'two or three weeks'. ?Here are a couple of options -- take 'em or > leave 'em: > > 1) Put the code in Cython:http://www.cython.org/?(full disclosure: > I'm doing a GSoC project with Cython). ?It will convert pretty much > any python code into C code (even closures are supported in the most > recent version, I think), and the C code can then be compiled into an > extension module. > > The only problem with the above is the C code isn't, at first blush, > easy to read. ?Nor is it supposed to be changed by the user. ?So that > leads us to option... > > 2) Write the core functionality in C yourself, and then wrap those C > functions in Cython. ?You'll want to take a look at the documentation: > > http://docs.cython.org/ > > and, more specifically on wrapping C code: > > http://docs.cython.org/docs/external_C_code.html > > I don't think you'll be able to avoid learning C, though. > > Kurt There's another (very good) option: Try shedskin http://code.google.com/p/shedskin/ . Shedskin can compile a whole program or part of it as an extension module. It translates python code to c++ and compiles it. The good thing is that you don't have to know anything about c or c++. You simply have to restrict your coding style a little bit to make it explicitly static. For example: if you declare a = 5, that means that "a" is an integer, so you cannot then change it to a string (a = "hello", won't work). Luis From tommy.nordgren at comhem.se Wed Jun 24 20:20:38 2009 From: tommy.nordgren at comhem.se (Tommy Nordgren) Date: Thu, 25 Jun 2009 02:20:38 +0200 Subject: [Mac] file copy In-Reply-To: <7ac8e0F1tludjU1@mid.uni-berlin.de> References: <7ac8e0F1tludjU1@mid.uni-berlin.de> Message-ID: On Jun 23, 2009, at 4:54 PM, Diez B. Roggisch wrote: > Tobias Weber wrote: > >> Hi, >> which is the best way to copy files on OS X? I want to preserve >> resource >> forks and extended attributes. > > Are these still relevant on OSX? I've always only copied files > directly, and > never had any troubles. > > Diez > -- the cp command copies INCLUDING resource forks, since tiger. ------------------------------------------------------ "Home is not where you are born, but where your heart finds peace" - Tommy Nordgren, "The dying old crone" tommy.nordgren at comhem.se From frank.ruiz at gmail.com Wed Jun 24 20:35:18 2009 From: frank.ruiz at gmail.com (Frank Ruiz) Date: Wed, 24 Jun 2009 17:35:18 -0700 Subject: Paramiko help - processing multiple commands In-Reply-To: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> References: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> Message-ID: Hi Jon, Thanks for the reply. So there are no errors. Essentially everything runs as planned. Sorry for being ignorant, but I am not sure if there is another way for providing trace data. I will look into what other debugging I can provide. Essentially what happens is that only the second command gets processed and the first is ignored. As far as the global variables are concerned, I am not too sure what the best way is to allow my variables to be seen by another sub. In the script I am using optparse, however in order for the variables to make any sense to my storagessh sub, I have to declare them as global, since all the variables within my options sub have a local scope. I am not too sure of a better way to do this. I don't like it much either. Hopefully you can help me shed some light on this in terms of best practice. Normally I declare variable scope outside of my subroutines where required. However since variable scope is local within a subroutine, seems like I have to declare them global in order for the other subs to see it. Anyhow.. your feedback has been much appreciated.. The script is still a work in progress, so I plan to do so more cosmetic enhancements once I review it a few more times. Thanks! On Wed, Jun 24, 2009 at 4:34 PM, Jon Clements wrote: > On Jun 24, 11:22?pm, Frank Ruiz wrote: >> Greetings, >> >> I am trying to process multiple commands using paramiko. I have >> searched other threads, and I think my use case is a little different. >> I am trying to login to a storage node that has a special shell, and >> as such I cant execute a script on the storage node side. >> >> I am also trying to avoid using pexpect because I hate making system >> calls.. hence my leaning towards paramiko. >> >> Was hoping someone could help me identify a way to process multiple >> commands using paramiko. >> >> I have two commands listed below, however only one is getting processed. >> >> Any help is much appreciated. >> >> Thanks! >> >> Here is my script: >> >> #!/usr/bin/env python >> >> #-Modules--------------------------------------------------------------------- >> import optparse >> import sys >> import paramiko >> >> #-Variables------------------------------------------------------------------- >> plog = 'storagessh.log' >> suser = 'root' >> >> #-Config---------------------------------------------------------------------- >> >> #-Subs-Defined---------------------------------------------------------------- >> def options(): >> ? ? global hostname >> ? ? global goldenimage >> ? ? global lunclone >> ? ? global sshport >> >> ? ? usage = "usage: %prog [options] -n -g -l " >> >> ? ? parser = optparse.OptionParser(usage) >> >> ? ? parser.add_option("-n", "--node", >> ? ? ? ? ? ? ? ? ? ? ? dest="hostname", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") >> ? ? parser.add_option("-g", "--gold", >> ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") >> ? ? parser.add_option("-l", "--lun", >> ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", >> ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") >> ? ? parser.add_option("-p", "--port", >> ? ? ? ? ? ? ? ? ? ? ? dest="sshport", >> ? ? ? ? ? ? ? ? ? ? ? default=22, >> ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") >> ? ? options, args = parser.parse_args() >> >> ? ? if not options.hostname: >> ? ? ? ? parser.error("Missing hostname argument.") >> ? ? ? ? exit >> ? ? elif not options.goldenimage: >> ? ? ? ? parser.error("Missing goldenimage argument.") >> ? ? ? ? exit >> ? ? elif not options.lunclone: >> ? ? ? ? parser.error("Missing lun argument.") >> ? ? ? ? exit >> >> ? ? hostname = options.hostname >> ? ? goldenimage = options.goldenimage >> ? ? lunclone = options.lunclone >> ? ? sshport = options.sshport >> >> def storagessh(): >> ? ? paramiko.util.log_to_file(plog) >> ? ? client = paramiko.SSHClient() >> ? ? client.load_system_host_keys() >> ? ? client.connect(hostname, sshport, suser) >> ? ? stdin, stdout, stderr = client.exec_command('show') >> ? ? stdin, stdout, stderr = client.exec_command('help') >> ? ? print stdout.read() >> ? ? client.close() >> >> #--Initialization------------------------------------------------------------- >> if __name__ == "__main__": >> ? ? options() >> ? ? storagessh() > > Again, as you were asked on the original post -- full tracebacks and > explain "what is not working". > > The use of global variables scares me -- why are those needed? > -- > http://mail.python.org/mailman/listinfo/python-list > From sjmachin at lexicon.net Wed Jun 24 20:56:24 2009 From: sjmachin at lexicon.net (John Machin) Date: Wed, 24 Jun 2009 17:56:24 -0700 (PDT) Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: On Jun 25, 7:17?am, Lie Ryan wrote: > MRAB wrote: > > There's no difference between the two types of quote character. > > a small exception is single-quote can contain double quote but cannot > contain unescaped single quote while double-quote can contain single > quote but cannot contain unescaped double quote. Refinement 1: S can contain D but cannot contain unescaped S D can contain S but cannot contain unescaped D Refinement 2: for Q in list_of_defined_quote_characters: Q can contain non-Q but cannot contain unescaped Q I'd call that orthogonal and a similarity not a small exception to "no difference" :-) From pavlovevidence at gmail.com Wed Jun 24 21:42:25 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 18:42:25 -0700 (PDT) Subject: Converting Python code to C/C++ References: Message-ID: <5fcd261e-eb99-41a3-9814-b7829653f7f0@g23g2000vbr.googlegroups.com> On Jun 24, 7:10?am, Grant Edwards wrote: > On 2009-06-24, Couper, Tim T wrote: > > > Your prof. may find this thread of interest > > >http://mail.python.org/pipermail/python-list/2000-June/039779.html > > > My experience is that developers who know C and C++ can be productive in > > less than 1 week in python, and find it liberating, and educational, to > > do so. And at the same time they will have added a second language to > > their toolbox. As Kurt points out, learning C/C++ takes considerably > > longer (weeks/months to attain a level of competence). > > I agree. ?Your professor is deluded and knows nothing about > software development [not that either is particularly unusual > in an academic setting]. ?Converting a Python program to C or > C++ is a complete waste of time (both now _and_ later) unless > there are severe, insurmountable performance problems with the > Python version. What if the point of asking a student to convert Python to C is to teach them this: > Python is a far, far better language for both real-world > production application development and for algorithm R&D. ?With > Python, you spend your time working on algorithms and solving > real-world problems. ?In C or C++, you spend your time fighting > with the bugs in your code that are preventing the program from > running. ?An algorithm that takes a few hours to implement and > test in Python will take weeks in C or C++. If that [teaching them this] is the case, it might be best use of time they will ever have. Carl Banks From rompubil at gmail.com Wed Jun 24 21:51:56 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 18:51:56 -0700 (PDT) Subject: tkinter: get filename of askopenfilename Message-ID: Hi there, I am writing an interface with Tkinter. My minimal program looks like this: ############# import Tkinter import tkFileDialog root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): filename = tkFileDialog.askopenfilename(filetypes=[("all files","*")]) # print filename root.mainloop() ############# I would like to recover the filename variable outside the "open_file_dialog" function. For instance, to be able to print the selected file name (uncomment "# print filename" line). Is there a way to do that? Thanks in advance. R From pavlovevidence at gmail.com Wed Jun 24 22:42:03 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 24 Jun 2009 19:42:03 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: On Jun 24, 2:39?am, Norberto Lopes wrote: > Hi all. > Assuming that python dictionaries already provide a bit of "shoot > yourself in the foot", I think what I have in mind would not be so > bad. > > What do you think of dictionaries having a self lookup in their > declaration? > > Be able to do this: > > a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax > > instead of: > > a = { "foo" : "foo1" } > a["bar"] = a["foo"] > > Maybe I'm murdering python syntax/philosophy right here so let me know > if that's the case. > I was thinking this could probably be done in python abstract tree but > as I never looked into it I may be wrong. I'm willing to make the > effort, provided I get some directions and that this idea is worth it. > > Any feedback is welcome. If you don't mind abusing Python syntax, you can do it using something like this: def DictMaker(name,bases,dct): dct.pop('__metaclass__',None) return dct class a: __metaclass__ = DictMaker home = "/home/test" user1 = home + "/user1" user2 = home + "/user2" python_dev = user1 + "/py-dev" print a Carl Banks From amosanderson at gmail.com Wed Jun 24 23:07:14 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Wed, 24 Jun 2009 22:07:14 -0500 Subject: os.walk and os.listdir problems python 3.0+ Message-ID: I've run into a bit of an issue iterating through files in python 3.0 and 3.1rc2. When it comes to a files with '\u200b' in the file name it gives the error... Traceback (most recent call last): File "ListFiles.py", line 19, in f.write("file:{0}\n".format(i)) File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 30: character maps to Code is as follows... import os f = open("dirlist.txt", 'w') for root, dirs, files in os.walk("C:\\Users\\Filter\\"): f.write("root:{0}\n".format(root)) f.write("dirs:\n") for i in dirs: f.write("dir:{0}\n".format(i)) f.write("files:\n") for i in files: f.write("file:{0}\n".format(i)) f.close() input("done") The file it's choking on happens to be a link that internet explorer created. There are two files that appear in explorer to have the same name but one actually has a zero width space ('\u200b') just before the .url extension. In playing around with this I've found several files with the same character throughout my file system. OS: Vista SP2, Language: US English. Am I doing something wrong or did I find a bug? It's worth noting that Python 2.6 just displays this character as a ? just as it appears if you type dir at the windows command prompt. -------------- next part -------------- An HTML attachment was scrubbed... URL: From koranthala at gmail.com Wed Jun 24 23:25:26 2009 From: koranthala at gmail.com (koranthala) Date: Wed, 24 Jun 2009 20:25:26 -0700 (PDT) Subject: Matplotlib - an odd problem References: Message-ID: <52edee85-f229-448a-ad0d-319f748cfbe6@y28g2000prd.googlegroups.com> On Jun 25, 2:55?am, Jean-Paul Calderone wrote: > On Wed, 24 Jun 2009 11:38:02 -0700 (PDT), koranthala wrote: > >Hi, > >I am using Matplotlib with Django to display charts on the web page. > >I am facing an odd problem in that, everytime I do a refresh on the > >web page, the image darkens - and the text becomes little unreadable. > >5/6 refreshes later, the text becomes completely unreadable. > >Since I am using Django test server, the same process is being used. > >i.e. every refresh does not create a new process. When I tried killing > >the process, the image again cleared. > >So I think it is sort of memory leak or a saved value which is messing > >up something. > >But I cannot seem to find the issue at all. > > >The code is as follows - > > >import pylab > >from cStringIO import StringIO > > >def print_pie_chart(request): > > ? ?labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' > > ? ?data = [15,30,45, 10] > > ? ?pylab.figure(1, figsize=(2,2)) > > ? ?ax = pylab.axes([0.1, 0.1, 0.8, 0.8]) > > ? ?pylab.pie(data, explode=None, labels=labels, autopct='%1.1f%%', > >shadow=True) > > ? ?out = StringIO() > > ? ?pylab.savefig(out, format="PNG") > > ? ?out.seek(0) > > ? ?response = HttpResponse() > > ? ?response['Content-Type'] = 'image/png' > > ? ?response.write(out.read()) > > ? ?return response > > >Can anyone help me out here? > > Your code redraws over the same graph over and over again. ?You need to > create a new graph each time you want to draw something new. ?It took me > ages (and help) to figure out how the non-global APIs in matplotlib. > > Here's an example: > > ? from matplotlib.figure import Figure > ? from matplotlib.axes import Axes > ? from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas > > ? fig = Figure(figsize=(9, 9), dpi=100) > ? axe = Axes(fig, (0, 0, 1.0, 1.0)) > ? axe.pie(range(5)) > ? fig.add_axes(axe) > > ? canvas = FigureCanvas(fig) > ? canvas.set_size_request(640, 480) > > ? fig.savefig("foo.png") > > Hope this helps, > Jean-Paul Thank you Jean-Paul From jeff_barish at earthlink.net Thu Jun 25 00:09:44 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Wed, 24 Jun 2009 22:09:44 -0600 Subject: Problem with multithreading References: Message-ID: Jeffrey Barish wrote: > I have a program that uses multithreading to monitor two loops. When > something happens in loop1, it sends a message to loop2 to have it execute > a command. loop2 might have to return a result. If it does, it puts the > result in a queue. loop1, meanwhile, would have blocked waiting for > something to appear in the queue. The program works for a while, but > eventually freezes. I know that freezing is a sign of deadlock. However, > I put in print statements to localize the problem and discovered something > weird. The freeze always occurs at a point in the code with the following > statements: > > print "about to try" > try: > print "in try" > > > I get "about to try", but not "in try". Is this observation consistent > with > the deadlock theory? If not, what could be making the program freeze at > the try statement? I wrote a test program using the same techniques to > illustrate the problem, but the test program works perfectly. I could > post it, though, if it would help to understand what I am doing -- and > what might be wrong in the real program. As I ponder this problem, I am beginning to believe that the problem is not related to multithreading. If the problem were due to a collision between the two threads then timing would matter, yet I find that the program always freezes at exactly the same statement (which executes perfectly hundreds of times before the freeze). Moreover, the test program that I wrote to test the multithreading implementation works perfectly. And finally, there is nothing going on related to multithreading at this point in the code. Why else might the program freeze at a try statement? -- Jeffrey Barish From norseman at hughes.net Thu Jun 25 00:15:19 2009 From: norseman at hughes.net (norseman) Date: Wed, 24 Jun 2009 21:15:19 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A42F9D7.4080002@hughes.net> rom wrote: > Hi there, > > I am writing an interface with Tkinter. My minimal program looks like > this: > ############# > import Tkinter > import tkFileDialog > # define globals here filename= '' # will take care of the problem > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > filename = tkFileDialog.askopenfilename(filetypes=[("all > files","*")]) > > # print filename > > root.mainloop() > ############# > > I would like to recover the filename variable outside the > "open_file_dialog" function. For instance, to be able to print the > selected file name (uncomment "# print filename" line). > > Is there a way to do that? > > Thanks in advance. > > R From noahdain at gmail.com Thu Jun 25 00:16:13 2009 From: noahdain at gmail.com (Noah Dain) Date: Thu, 25 Jun 2009 00:16:13 -0400 Subject: Paramiko help - processing multiple commands In-Reply-To: References: <87eada89-3f6a-4183-a556-3f1576a7ed51@k20g2000vbp.googlegroups.com> Message-ID: On Wed, Jun 24, 2009 at 8:35 PM, Frank Ruiz wrote: > Hi Jon, > > Thanks for the reply. So there are no errors. Essentially everything > runs as planned. Sorry for being ignorant, but I am not sure if there > is another way for providing trace data. I will look into what other > debugging I can provide. > > Essentially what happens is that only the second command gets > processed and the first is ignored. > > As far as the global variables are concerned, I am not too sure what > the best way is to allow my variables to be seen by another sub. In > the script I am using optparse, however in order for the variables to > make any sense to my storagessh sub, I have to declare them as global, > since all the variables within my options sub have a local scope. > > I am not too sure of a better way to do this. I don't like it much > either. Hopefully you can help me shed some light on this in terms of > best practice. > > Normally I declare variable scope outside of my subroutines where required. > > However since variable scope is local within a subroutine, seems like > I have to declare them global in order for the other subs to see it. > > Anyhow.. your feedback has been much appreciated.. The script is still > a work in progress, so I plan to do so more cosmetic enhancements once > I review it a few more times. > > Thanks! > > On Wed, Jun 24, 2009 at 4:34 PM, Jon Clements wrote: >> On Jun 24, 11:22?pm, Frank Ruiz wrote: >>> Greetings, >>> >>> I am trying to process multiple commands using paramiko. I have >>> searched other threads, and I think my use case is a little different. >>> I am trying to login to a storage node that has a special shell, and >>> as such I cant execute a script on the storage node side. >>> >>> I am also trying to avoid using pexpect because I hate making system >>> calls.. hence my leaning towards paramiko. >>> >>> Was hoping someone could help me identify a way to process multiple >>> commands using paramiko. >>> >>> I have two commands listed below, however only one is getting processed. >>> >>> Any help is much appreciated. >>> >>> Thanks! >>> >>> Here is my script: >>> >>> #!/usr/bin/env python >>> >>> #-Modules--------------------------------------------------------------------- >>> import optparse >>> import sys >>> import paramiko >>> >>> #-Variables------------------------------------------------------------------- >>> plog = 'storagessh.log' >>> suser = 'root' >>> >>> #-Config---------------------------------------------------------------------- >>> >>> #-Subs-Defined---------------------------------------------------------------- >>> def options(): >>> ? ? global hostname >>> ? ? global goldenimage >>> ? ? global lunclone >>> ? ? global sshport >>> >>> ? ? usage = "usage: %prog [options] -n -g -l " >>> >>> ? ? parser = optparse.OptionParser(usage) >>> >>> ? ? parser.add_option("-n", "--node", >>> ? ? ? ? ? ? ? ? ? ? ? dest="hostname", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of storage node you are connecting to.") >>> ? ? parser.add_option("-g", "--gold", >>> ? ? ? ? ? ? ? ? ? ? ? dest="goldenimage", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of goldenimage to clone.") >>> ? ? parser.add_option("-l", "--lun", >>> ? ? ? ? ? ? ? ? ? ? ? dest="lunclone", >>> ? ? ? ? ? ? ? ? ? ? ? help="Name of lun to create.") >>> ? ? parser.add_option("-p", "--port", >>> ? ? ? ? ? ? ? ? ? ? ? dest="sshport", >>> ? ? ? ? ? ? ? ? ? ? ? default=22, >>> ? ? ? ? ? ? ? ? ? ? ? help="SSH port number.") >>> ? ? options, args = parser.parse_args() >>> >>> ? ? if not options.hostname: >>> ? ? ? ? parser.error("Missing hostname argument.") >>> ? ? ? ? exit >>> ? ? elif not options.goldenimage: >>> ? ? ? ? parser.error("Missing goldenimage argument.") >>> ? ? ? ? exit >>> ? ? elif not options.lunclone: >>> ? ? ? ? parser.error("Missing lun argument.") >>> ? ? ? ? exit >>> >>> ? ? hostname = options.hostname >>> ? ? goldenimage = options.goldenimage >>> ? ? lunclone = options.lunclone >>> ? ? sshport = options.sshport >>> >>> def storagessh(): >>> ? ? paramiko.util.log_to_file(plog) >>> ? ? client = paramiko.SSHClient() >>> ? ? client.load_system_host_keys() >>> ? ? client.connect(hostname, sshport, suser) >>> ? ? stdin, stdout, stderr = client.exec_command('show') >>> ? ? stdin, stdout, stderr = client.exec_command('help') >>> ? ? print stdout.read() >>> ? ? client.close() >>> >>> #--Initialization------------------------------------------------------------- >>> if __name__ == "__main__": >>> ? ? options() >>> ? ? storagessh() >> >> Again, as you were asked on the original post -- full tracebacks and >> explain "what is not working". >> >> The use of global variables scares me -- why are those needed? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list > this works for me: def storagessh(): paramiko.util.log_to_file(plog) client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, sshport, suser) stdin, stdout, stderr = client.exec_command('ps') print stdout.read() stdin, stdout, stderr = client.exec_command('help') print stdout.read() client.close() 1) you reassign stdin, stdout, stderr so with your code you will never see the stdout of the first command ('show') 2) the 'show' command did not exist on my system, so no output. I substituted 'ps' and added the print statement also, using user 'root' for dev code is a Bad Thing. -- Noah Dain From norseman at hughes.net Thu Jun 25 00:28:59 2009 From: norseman at hughes.net (norseman) Date: Wed, 24 Jun 2009 21:28:59 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A42FD0B.7090205@hughes.net> OOPS - I left out the global statement rom wrote: > Hi there, > > I am writing an interface with Tkinter. My minimal program looks like > this: > ############# > import Tkinter > import tkFileDialog > # define globals here filename= '' # will take care of the problem > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): global filename # need this to assign to it > filename = tkFileDialog.askopenfilename(filetypes=[("all > files","*")]) > > # print filename > > root.mainloop() > ############# > > I would like to recover the filename variable outside the > "open_file_dialog" function. For instance, to be able to print the > selected file name (uncomment "# print filename" line). > > Is there a way to do that? > > Thanks in advance. > > R From Scott.Daniels at Acm.Org Thu Jun 25 00:29:55 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 21:29:55 -0700 Subject: It's ... In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Angus Rodgers wrote: >> ... my first ... question is how best to find out what's changed from >> version 2.1 > > to version 2.5. (I've recently installed 2.5.4) > Consecutively read: > http://docs.python.org/whatsnew/2.2.html As someone else pointed out: http://www.python.org/doc/2.2.3/whatsnew/whatsnew22.html > http://docs.python.org/whatsnew/2.3.html > http://docs.python.org/whatsnew/2.4.html > http://docs.python.org/whatsnew/2.5.html I forgot to add Richard Gruet's excellent resources, homed here: http://rgruet.free.fr/ You want to check out PQR 2.5 or 2.6 reference; he encodes when (what version) a feature came into the language. SO it is a great overview to read through as you try to take yourself from 2.1 to 2.5. I'd go for the "modern" style unless the colors annoy you. --Scott David Daniels Scott.Daniels at Acm.Org From rompubil at gmail.com Thu Jun 25 00:46:31 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 21:46:31 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: Thanks for your response. I have modified this minimal program as you suggested but still is not able to print the filename: ###################### import Tkinter import tkFileDialog global filename filename='' root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print filename root.mainloop() ###################### Is this what you mean? On Jun 25, 1:28?pm, norseman wrote: > OOPS - I left out the global statement > > rom wrote: > > Hi there, > > > I am writing an interface with Tkinter. My minimal program looks like > > this: > > ############# > > import Tkinter > > import tkFileDialog > > # define globals here > filename= '' ? ? # will take care of the problem > > > root = Tkinter.Tk() > > > Tkinter.Button(root, text='Notch genes...', command=lambda: > > open_file_dialog()).pack() > > > def open_file_dialog(): > > ? ? ? ?global filename ? # need this to assign to it > > > ? ? filename = tkFileDialog.askopenfilename(filetypes=[("all > > files","*")]) > > > # print filename > > > root.mainloop() > > ############# > > > I would like to recover the filename variable outside the > > "open_file_dialog" function. For instance, to be able to print the > > selected file name (uncomment "# print filename" line). > > > Is there a way to do that? > > > Thanks in advance. > > > R > > From mail131 at gmail.com Thu Jun 25 00:57:36 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 21:57:36 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <08d4e77c-eb46-41ea-a970-c20b947a442a@g20g2000vba.googlegroups.com> On Jun 24, 11:00?pm, Peter Otten <__pete... at web.de> wrote: > Private Private wrote: > > > lines = fileinput.input(filename) > > > for line in lines: > > > ? ? if "Data2" in line: > > > ? ? ? ? print line.strip(), "-->", next(lines).strip() > > > I get an error: > > > ... > > ? ? print line.strip(), "-->", next(lines).strip() > > NameError: global name 'next' is not defined > > In Python versions prior to 2.6 instead of > > next(lines) > > you can use > > lines.next() > > Peter That works perfectly. Thank you :-) From mail131 at gmail.com Thu Jun 25 01:02:27 2009 From: mail131 at gmail.com (Private Private) Date: Wed, 24 Jun 2009 22:02:27 -0700 (PDT) Subject: fileinput.input, readlines and ... References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: On Jun 24, 12:23?pm, Przemyslaw Bak wrote: > Hello, > > I many files with log data. The structure of the file is quite Each requested value is in separated file. While traversing using os.path.walk I have noticed that I get files unsorted. Is it possible to get them sorted ? przemol From Scott.Daniels at Acm.Org Thu Jun 25 01:12:25 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 24 Jun 2009 22:12:25 -0700 Subject: Problem with multithreading In-Reply-To: References: Message-ID: <4umdnc6YSuk8mN7XnZ2dnUVZ_vidnZ2d@pdx.net> Jeffrey Barish wrote: > Jeffrey Barish wrote: >> >> print "about to try" >> try: >> print "in try" >> .... > > As I ponder this problem, I am beginning to believe that the problem is not > related to multithreading. If the problem were due to a collision between > the two threads then timing would matter, yet I find that the program > always freezes at exactly the same statement (which executes perfectly > hundreds of times before the freeze). Moreover, the test program that I > wrote to test the multithreading implementation works perfectly. And > finally, there is nothing going on related to multithreading at this point > in the code. Why else might the program freeze at a try statement? Or a print statement or ... We need more clues than three lines of source. --Scott David Daniels Scott.Daniels at Acm.Org From rompubil at gmail.com Thu Jun 25 01:44:25 2009 From: rompubil at gmail.com (rom) Date: Wed, 24 Jun 2009 22:44:25 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> Ok. I think I got it. I have to do it in this way: ########################### import Tkinter import tkFileDialog filename='' root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=lambda: open_file_dialog()).pack() def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print_filename() def print_filename(): print filename root.mainloop() ########################### Thanks again On Jun 25, 1:46?pm, rom wrote: > Thanks for your response. I have modified this minimal program as you > suggested but still is not able to print the filename: > > ###################### > import Tkinter > import tkFileDialog > > global filename > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > print filename > > root.mainloop() > ###################### > > Is this what you mean? > > On Jun 25, 1:28?pm, norseman wrote: > > > OOPS - I left out the global statement > > > rom wrote: > > > Hi there, > > > > I am writing an interface with Tkinter. My minimal program looks like > > > this: > > > ############# > > > import Tkinter > > > import tkFileDialog > > > # define globals here > > filename= '' ? ? # will take care of the problem > > > > root = Tkinter.Tk() > > > > Tkinter.Button(root, text='Notch genes...', command=lambda: > > > open_file_dialog()).pack() > > > > def open_file_dialog(): > > > ? ? ? ?global filename ? # need this to assign to it > > > > ? ? filename = tkFileDialog.askopenfilename(filetypes=[("all > > > files","*")]) > > > > # print filename > > > > root.mainloop() > > > ############# > > > > I would like to recover the filename variable outside the > > > "open_file_dialog" function. For instance, to be able to print the > > > selected file name (uncomment "# print filename" line). > > > > Is there a way to do that? > > > > Thanks in advance. > > > > R > > From metolone+gmane at gmail.com Thu Jun 25 01:57:02 2009 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 24 Jun 2009 22:57:02 -0700 Subject: os.walk and os.listdir problems python 3.0+ References: Message-ID: "Amos Anderson" wrote in message news:a073a9cf0906242007k5067314dn8e9d7b1c6da6286a at mail.gmail.com... > I've run into a bit of an issue iterating through files in python 3.0 and > 3.1rc2. When it comes to a files with '\u200b' in the file name it gives > the > error... > > Traceback (most recent call last): > File "ListFiles.py", line 19, in > f.write("file:{0}\n".format(i)) > File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_table)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in > position > 30: character maps to > > Code is as follows... > import os > f = open("dirlist.txt", 'w') > > for root, dirs, files in os.walk("C:\\Users\\Filter\\"): > f.write("root:{0}\n".format(root)) > f.write("dirs:\n") > for i in dirs: > f.write("dir:{0}\n".format(i)) > f.write("files:\n") > for i in files: > f.write("file:{0}\n".format(i)) > f.close() > input("done") > > The file it's choking on happens to be a link that internet explorer > created. There are two files that appear in explorer to have the same name > but one actually has a zero width space ('\u200b') just before the .url > extension. In playing around with this I've found several files with the > same character throughout my file system. OS: Vista SP2, Language: US > English. > > Am I doing something wrong or did I find a bug? It's worth noting that > Python 2.6 just displays this character as a ? just as it appears if you > type dir at the windows command prompt. In Python 3.x strings default to Unicode. Unless you choose an encoding, Python will use the default system encoding to encode the Unicode strings into a file. On Windows, the filesystem uses Unicode and supports the full character set, but cp1252 (on your system) is the default text file encoding, which doesn't support zero-width space. Specify an encoding for the output file such as UTF-8: >>> f=open('blah.txt','w',encoding='utf8') >>> f.write('\u200b') 1 >>> f.close() -Mark From wbrehaut at mcsnet.ca Thu Jun 25 02:04:12 2009 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Thu, 25 Jun 2009 00:04:12 -0600 Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh wrote: >Hi All, > >I am trying to move my application on a MVC architecture and plan to >use Jinja for the same. Can anyone provide me with few quick links >that might help me to get started with Jinja? Perhaps the most useful link is: http://www.google.com/ from which you can easily find many more with a very basic search, including: http://jinja.pocoo.org/ Hope that helps? wwwayne > >Thanks, >Saby From twirlip at bigfoot.com Thu Jun 25 03:05:58 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 08:05:58 +0100 Subject: [SPAM] It's ... References: Message-ID: Someone has gently directed me to the Tutor mailing list: which I hadn't known about. I've joined, and will try to confine my initial blundering experiments to there. Sorry about the spam spam spam spam, lovely spam, wonderful spam! -- Angus Rodgers From sean_mcilroy at yahoo.com Thu Jun 25 03:12:22 2009 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: Thu, 25 Jun 2009 00:12:22 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: Message-ID: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> i think what he means is to put the global declaration inside the function that assigns to filename: def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) as it was, the function was creating a new variable called filename and assigning to THAT (and then doing absolutely nothing with it). with the above modification, the function understands that filename refers to the global variable of that name, and that variable's value does indeed get printed, but since the print statement comes before root.mainloop() -- hence before the button gets pressed -- filename gets printed before the function has assigned to it. this fact becomes apparent if you initialize the variable with filename='blank' (for example). putting the print statement after root.mainloop() doesn't work either, since root.mainloop() keeps control from getting to the print statement. the effect i think you want can be gotten from putting the print statement into the function as well, so what you end up with is this: import Tkinter import tkFileDialog filename = 'uninitialized' def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) print filename root = Tkinter.Tk() Tkinter.Button(root, text='Notch genes...', command=open_file_dialog).pack() root.mainloop() From mail at microcorp.co.za Thu Jun 25 03:18:32 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 25 Jun 2009 09:18:32 +0200 Subject: Fw: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) Message-ID: <00eb01c9f565$25bfd240$0d00a8c0@Hendrik> Below is one that just disappeared, without any feedback: (unless I just missed it) - Hendrik ----- Original Message ----- From: "Hendrik van Rooyen" To: "Aahz" ; Sent: Wednesday, June 24, 2009 10:08 AM Subject: Re: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) > "Aahz" wrote: > > > While that's also a bug in Mailman (I have a long-standing to-do item to > > fix that), there are also plenty of posts that simply aren't showing up > > in c.l.py. As I said, I'm pretty sure (based on what was happening with > > c.l.py.announce) that it's some kind of weird problem with the mail->news > > gateway with MIME posts. > > I have lately had some posts returned with a "seems to be forged" message. > Two reasons for that: > - first is if I use the smtp server from our local telco - saix - then there is > no apparent relationship between where the message comes from and > where it comes from, if you follow my Irish... > - Second is if the same telco assigns me an IP that has been put on a list > of bad boy IPs. > > So it is kind of pot luck if you see this message or not. > > - Hendrik > From mail131 at gmail.com Thu Jun 25 03:29:28 2009 From: mail131 at gmail.com (Private Private) Date: Thu, 25 Jun 2009 00:29:28 -0700 (PDT) Subject: Python simple web development Message-ID: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Hi, I am looking for a python library which will allow me to do a simple web development. I need to use some forms (but nice looking :-) ), creating images based on input from those forms, etc. I have read a bit about Django and TurboGears but I am afraid that this is too big for my requirements (am I wrong ?). Can you suggest anything ? From steven at REMOVE.THIS.cybersource.com.au Thu Jun 25 03:34:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Jun 2009 07:34:24 GMT Subject: Barbara Liskov wins Turing Award Message-ID: I haven't seen any links to this here: Barbara Liskov has won the Turing Award: http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? [quote] Institute Professor Barbara Liskov has won the Association for Computing Machinery's A.M. Turing Award, one of the highest honors in science and engineering, for her pioneering work in the design of computer programming languages. Liskov's achievements underpin virtually every modern computing-related convenience in people's daily lives. [end quote] Liskov is well known for the "Liskov substitution principle". She also created the language CLU, one of the most important inspirations to Python, and coined the term "pass by object" (also known as "pass by object reference") to describe CLU's then novel argument passing behaviour. Such behaviour has since become a virtual standard for OO languages such as Python and Java. -- Steven From clp2 at rebertia.com Thu Jun 25 03:43:43 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Jun 2009 00:43:43 -0700 Subject: Barbara Liskov wins Turing Award In-Reply-To: References: Message-ID: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> On Thu, Jun 25, 2009 at 12:34 AM, Steven D'Aprano wrote: > I haven't seen any links to this here: Barbara Liskov has won the Turing > Award: > > http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? > > > [quote] > Institute Professor Barbara Liskov has won the Association for Computing > Machinery's A.M. Turing Award, one of the highest honors in science and > engineering, for her pioneering work in the design of computer > programming languages. Liskov's achievements underpin virtually every > modern computing-related convenience in people's daily lives. > [end quote] > > Liskov is well known for the "Liskov substitution principle". She also > created the language CLU, one of the most important inspirations to > Python Erm, Wikipedia (which is generally excellent on programming topics) seems to disagree with you. http://en.wikipedia.org/wiki/Python_(programming_language) "Influenced by ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java" Unless you mean it influenced Python indirectly by way of the aforelisted languages... Cheers, Chris -- http://blog.rebertia.com From rompubil at gmail.com Thu Jun 25 04:02:08 2009 From: rompubil at gmail.com (rom) Date: Thu, 25 Jun 2009 01:02:08 -0700 (PDT) Subject: tkinter: get filename of askopenfilename References: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> Message-ID: <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> Thanks again. After your replies, I have understood how to do what I wanted. What I wanted to do is to get a value after clicking a button and use it in another part of the program. As you said, after getting the value, I have to store it in a global variable. However, the program does not do anything with it until I trigger another event, e.g. by clicking on another button. Therefore, I have added another button to my program: ##################### import Tkinter import tkFileDialog filename = 'uninitialized' def open_file_dialog(): global filename filename = tkFileDialog.askopenfilename(filetypes= [("allfiles","*")]) def print_variable(variable): print variable root = Tkinter.Tk() Tkinter.Button(root, text='Select file...', command=open_file_dialog).pack() Tkinter.Button(root, text='Print file', command=lambda: print_variable (filename)).pack() root.mainloop() ##################### On Jun 25, 4:12?pm, Sean McIlroy wrote: > i think what he means is to put the global declaration inside the > function that assigns to filename: > > def open_file_dialog(): > ? ? global filename > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > as it was, the function was creating a new variable called filename > and assigning to THAT (and then doing absolutely nothing with it). > with the above modification, the function understands that filename > refers to the global variable of that name, and that variable's value > does indeed get printed, but since the print statement comes before > root.mainloop() -- hence before the button gets pressed -- filename > gets printed before the function has assigned to it. this fact becomes > apparent if you initialize the variable with filename='blank' (for > example). putting the print statement after root.mainloop() doesn't > work either, since root.mainloop() keeps control from getting to the > print statement. the effect i think you want can be gotten from > putting the print statement into the function as well, so what you end > up with is this: > > import Tkinter > import tkFileDialog > > filename = 'uninitialized' > > def open_file_dialog(): > ? ? global filename > ? ? filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > ? ? print filename > > root = Tkinter.Tk() > Tkinter.Button(root, text='Notch genes...', > command=open_file_dialog).pack() > root.mainloop() From bieffe62 at gmail.com Thu Jun 25 04:33:08 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 01:33:08 -0700 (PDT) Subject: Recipes for trace statements inside python programs? Message-ID: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Hi all, as many - I think - python programmers, I find muself debugging my scripts by placing print statements in strategic places rather than using the python debugger, and commenting/uncommenting them according to myy deugging needs. After a time, these prints staements start to evolving in some ad-hoc half-baked framework ... so I wonder if there is somewhere there is a full-baked trace statement support framework which I can use. I'm aware of the logging module, but for me it its more geared toward application logging rather than toward trace for debugging purpose. Having googlet and found nothing (or too much but nothing relef?vant), I'm now asking The List. Here is what I have in mind: Each module, function, class and method should have an attribute, say trace_flag, which can be set to true or false value. there should be a function TRACE which does something like this: if __debug__ : def TRACE(*args): if trace_enabled(): print "TRACE(%s) : %s " % ( context(), " ".join( str(x) for x in args ) ) where trace_enabled() should return the value of the innermost trace_flag (checking current function/method then current class (if any) then current module) and context() shoud return a string like "module.function" or "module.class.method" ). At this point I could in my test code enable the trace in the function/class that gives me trouble and disable it after I fixed it, without having to touch the actual code under test. I guess it should not be too hard do using python introspection modules, but of couse I first would like to know if something like this already exists. I'm aware that this imposes a performance penalty, but my scripts are not operformance-critical. And if I put an if __debug__ switch From bieffe62 at gmail.com Thu Jun 25 04:40:01 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 01:40:01 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: Sorry, hit the send button by mistake ... The definition of the trace function should be like: if __debug__ : def TRACE(*args): if trace_enabled(): print "TRACE(%s) : %s " % ( context(), " ".join( str(x) for x in args ) ) else : # optimazed code, only a function call performance penalty def TRACE(*args): pass If I don't find anything suitable, maybe I will bake my own again, this time aiming to something that I can reuse ... Ciao and thanks for any tip/suggestion ------ FB From tjreedy at udel.edu Thu Jun 25 04:49:19 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 04:49:19 -0400 Subject: Barbara Liskov wins Turing Award In-Reply-To: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> References: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Thu, Jun 25, 2009 at 12:34 AM, Steven > D'Aprano wrote: >> I haven't seen any links to this here: Barbara Liskov has won the Turing >> Award: It was posted about the time of the announcement, but is worth the reminded. >> http://web.mit.edu/newsoffice/2009/turing-liskov-0310.html/? >> >> >> [quote] >> Institute Professor Barbara Liskov has won the Association for Computing >> Machinery's A.M. Turing Award, one of the highest honors in science and >> engineering, for her pioneering work in the design of computer >> programming languages. Liskov's achievements underpin virtually every >> modern computing-related convenience in people's daily lives. >> [end quote] >> >> Liskov is well known for the "Liskov substitution principle". She also >> created the language CLU, one of the most important inspirations to >> Python This inspired me to to spend a couple of hours finding and reading a CLU manual. > Erm, Wikipedia (which is generally excellent on programming topics) > seems to disagree with you. > > http://en.wikipedia.org/wiki/Python_(programming_language) > "Influenced by ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java" > > Unless you mean it influenced Python indirectly by way of the > aforelisted languages... Python's object model, assignment semantics, and call-by-object mechanism, and that name, come from CLU. Whether Guido knew of it directly or not, I do not know. To the extent that the above is part of the heart of Python, I think Steven's statement stands pretty well. From chris at simplistix.co.uk Thu Jun 25 04:59:06 2009 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 25 Jun 2009 09:59:06 +0100 Subject: Python simple web development In-Reply-To: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <4A433C5A.5010101@simplistix.co.uk> Private Private wrote: > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). You are wrong :-) > Can you suggest anything ? http://www.djangoproject.com/ http://bfg.repoze.org/ http://pylonshq.com/ Drink whichever koolaid you like the taste of :-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From robin at reportlab.com Thu Jun 25 05:01:53 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 25 Jun 2009 10:01:53 +0100 Subject: Measuring Fractal Dimension ? In-Reply-To: References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com><7xfxdyrk97.fsf@ruckus.brouhaha.com><124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com><87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <4A433D01.3060506@chamonix.reportlab.co.uk> pdpi wrote: ....... > > But yeah, Log2 and LogE are the only two bases that make "natural" > sense except in specialized contexts. Base 10 (and, therefore, Log10) > is an artifact of having that 10 fingers (in fact, whatever base you > use, you always refer to it as base 10). someone once explained to me that the set of systems that are continuous in the calculus sense was of measure zero in the set of all systems I think it was a fairly formal discussion, but my understanding was of the hand waving sort. If true that makes calculus (and hence all of our understanding of such "natural" concepts) pretty small and perhaps non-applicable. On the other hand R Kalman (of Bucy and Kalman filter fame) likened study of continuous linear dynamical systems to "a man searching for a lost ring under the only light in a dark street" ie we search where we can see. Because such systems are tractable doesn't make them natural or essential or applicable in a generic sense. -- Robin Becker From martin.hellwig at dcuktec.org Thu Jun 25 05:10:50 2009 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Jun 2009 10:10:50 +0100 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS In-Reply-To: References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: Chris Rebert wrote: > > In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. > > Cheers, > Chris Let me demonstrate: Chris, I have no sympathy for you :-) -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' From lucaberto at libero.it Thu Jun 25 05:15:57 2009 From: lucaberto at libero.it (luca72) Date: Thu, 25 Jun 2009 02:15:57 -0700 (PDT) Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> <7a9bj5F1uhor1U1@mid.uni-berlin.de> Message-ID: <186cfa90-c309-4266-aae0-a89f9e49ef95@v4g2000vba.googlegroups.com> Hello but find_library find only the lib. but if i need to load from a list of lib how i have to do. My proble is that i have 5 lib (a,b,c,d,e), if i load the a i get lib b not found, if for first i load the b and than the a i get the same error how i have to proceed. Thanks Luca From http Thu Jun 25 05:38:44 2009 From: http (Paul Rubin) Date: 25 Jun 2009 02:38:44 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> Message-ID: <7x63eky7ob.fsf@ruckus.brouhaha.com> Robin Becker writes: > someone once explained to me that the set of systems that are > continuous in the calculus sense was of measure zero in the set of all > systems I think it was a fairly formal discussion, but my > understanding was of the hand waving sort. That is very straightforward if you don't mind a handwave. Let S be some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 otherwise (this is a discontinuous function if S is nonempty). How many different such f's can there be? Obviously one for every possible subset of the reals. The cardinality of such f's is the power set of the reals, i.e. much larger than the set of reals. On the other hand, let g be some arbitrary continuous function on the reals. Let H be the image of Q (the set of rationals) under g. That is, H = {g(x) such that x is rational}. Since g is continuous, it is completely determined by H, which is a countable set. So the cardinality is RxN which is the same as the cardinality of R. > If true that makes calculus (and hence all of our understanding of > such "natural" concepts) pretty small and perhaps non-applicable. No really, it is just set theory, which is a pretty bogus subject in some sense. There aren't many discontinuous functions in nature. There is a philosophy of mathematics (intuitionism) that says classical set theory is wrong and in fact there are NO discontinuous functions. They have their own mathematical axioms which allow developing calculus in a way that all functions are continuous. > On the other hand R Kalman (of Bucy and Kalman filter fame) likened > study of continuous linear dynamical systems to "a man searching for > a lost ring under the only light in a dark street" ie we search > where we can see. Because such systems are tractable doesn't make > them natural or essential or applicable in a generic sense. Really, I think the alternative he was thinking of may have been something like nonlinear PDE's, a horribly messy subject from a practical point of view, but still basically free of set-theoretic monstrosities. The Banach-Tarski paradox has nothing to do with nature. From nospam at invalid.invalid Thu Jun 25 06:05:58 2009 From: nospam at invalid.invalid (robert) Date: Thu, 25 Jun 2009 12:05:58 +0200 Subject: print u'\u2013' error on console/terminal Message-ID: >>> sys.stdout.encoding 'cp850' >>> print u'\u2013' Traceback (most recent call last): File "", line 1, in File "C:\Python25\Lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position 0: character maps to >>> sys.stdout.encoding='xy' Traceback (most recent call last): File "", line 1, in TypeError: readonly attribute is there a switch to suppress those encoding errors for standard print's on the console - e.g. for getting automatic behavior like 'replace' : >>> print u'a \2013 b'.encode('cp850','replace') a ?3 b >>> or a new filter file class necessary? From koranthala at gmail.com Thu Jun 25 07:15:23 2009 From: koranthala at gmail.com (koranthala) Date: Thu, 25 Jun 2009 04:15:23 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <00402361-e5f7-4583-975b-fa9a72048098@y6g2000prf.googlegroups.com> On Jun 25, 1:40?pm, Francesco Bochicchio wrote: > Sorry, hit the send button by mistake ... > The definition of the trace function should be like: > > if __debug__ : > ? ?def TRACE(*args): > ? ? ?if ?trace_enabled(): print "TRACE(%s) : %s " % ( context(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " ".join( str(x) for x in args ) ) > else : # optimazed code, only a function call performance penalty > ? ?def TRACE(*args): pass > > If I don't find anything suitable, maybe I will bake my own again, > this > time aiming to something that I can reuse ... > > Ciao and thanks for any tip/suggestion > ------ > FB Is assert what you are looking for? From samwyse at gmail.com Thu Jun 25 07:22:39 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 04:22:39 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <9ce574ea-2638-4f85-a61b-b594bb592e7f@r36g2000vbn.googlegroups.com> I use an @trace decorator. This (http://wordaligned.org/articles/ echo) will get you started but there are lots of others available. My personal preference is a decorator that catches, displays and re- raises exceptions as well as displaying both calling parameters and returned values. btw, here's a cool Python3K (or 2.6 if you turn on print functions) trick that's sort-of on topic since it relates to log files and such: import functools, sys warn = functools.partial(print, file=sys.stderr) logfile = open(...) log = functools.partial(print, file=logfile) # etc. On Jun 25, 3:33?am, Francesco Bochicchio wrote: > Hi all, > > as many - I think - python programmers, I find muself debugging my > scripts by placing print statements in strategic places rather than > using the python debugger, and commenting/uncommenting them according > to myy deugging needs. ?After a time, these prints staements start to > evolving in some ad-hoc half-baked framework ... so I wonder if there > is somewhere there is a full-baked trace statement support framework > which I can use. I'm aware of the logging module, but for me it its > more geared toward ?application logging rather than toward trace for > debugging purpose. From rajat.dudeja at aeroflex.com Thu Jun 25 07:22:54 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Thu, 25 Jun 2009 07:22:54 -0400 Subject: How to get filename from a pid? Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> Hi, I've a PID of a process (the process is a notepad application), I want to know which file is opened by this process. regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at reportlab.com Thu Jun 25 07:23:07 2009 From: robin at reportlab.com (Robin Becker) Date: Thu, 25 Jun 2009 12:23:07 +0100 Subject: Measuring Fractal Dimension ? In-Reply-To: <7x63eky7ob.fsf@ruckus.brouhaha.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <4A435E1B.3040701@chamonix.reportlab.co.uk> Paul Rubin wrote: ......... > That is very straightforward if you don't mind a handwave. Let S be > some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 > otherwise (this is a discontinuous function if S is nonempty). How > many different such f's can there be? Obviously one for every > possible subset of the reals. The cardinality of such f's is the > power set of the reals, i.e. much larger than the set of reals. > > On the other hand, let g be some arbitrary continuous function on the > reals. Let H be the image of Q (the set of rationals) under g. That > is, H = {g(x) such that x is rational}. Since g is continuous, it is > completely determined by H, which is a countable set. So the > cardinality is RxN which is the same as the cardinality of R. > ok so probably true then > >> If true that makes calculus (and hence all of our understanding of >> such "natural" concepts) pretty small and perhaps non-applicable. > > No really, it is just set theory, which is a pretty bogus subject in > some sense. There aren't many discontinuous functions in nature. > There is a philosophy of mathematics (intuitionism) that says > classical set theory is wrong and in fact there are NO discontinuous > functions. They have their own mathematical axioms which allow > developing calculus in a way that all functions are continuous. > so does this render all the discreteness implied by quantum theory unreliable? or is it that we just cannot see(measure) the continuity that really happens? Certainly there are people like Wolfram who seem to think we're in some kind of giant calculating engine where state transitions are discontinuous. >> On the other hand R Kalman (of Bucy and Kalman filter fame) likened >> study of continuous linear dynamical systems to "a man searching for >> a lost ring under the only light in a dark street" ie we search >> where we can see. Because such systems are tractable doesn't make >> them natural or essential or applicable in a generic sense. > > Really, I think the alternative he was thinking of may have been > something like nonlinear PDE's, a horribly messy subject from a > practical point of view, but still basically free of set-theoretic > monstrosities. The Banach-Tarski paradox has nothing to do with nature. My memory of his seminar was that he was concerned about our failure to model even the simplest of systems with non-linearity and/or discreteness. I seem to recall that was about the time that chaotic behaviours were starting to appear in the control literature and they certainly depend on non-linearity. -- Robin Becker From samwyse at gmail.com Thu Jun 25 07:27:57 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 04:27:57 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <876f577b-733f-4714-b520-0d087fd38ffc@q37g2000vbi.googlegroups.com> I just started with web2py (http://www.web2py.com/) for an internal- use-only app that doesn't need to be very pretty. Been using it for about a week and after re-watching the tutorial, I've decided that I'm making things way too complicated. So today I'm going to replace a lot of my code with some built-ins. On Jun 25, 2:29?am, Private Private wrote: > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? From bieffe62 at gmail.com Thu Jun 25 08:06:31 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 25 Jun 2009 05:06:31 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> <00402361-e5f7-4583-975b-fa9a72048098@y6g2000prf.googlegroups.com> Message-ID: On 25 Giu, 13:15, koranthala wrote: > On Jun 25, 1:40?pm, Francesco Bochicchio wrote: > > > Is assert what you are looking for? > No. Assert raises exception if some condition is met. I just want to be able to enable/disable the printout of intermediate data, on a per function/method/class/module basis, without altering the execution flow. Ciao --- FB From gnperumal at gmail.com Thu Jun 25 08:06:55 2009 From: gnperumal at gmail.com (krishna) Date: Thu, 25 Jun 2009 05:06:55 -0700 (PDT) Subject: How to convert he boolean values into integers Message-ID: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Hi Guys, I need to convert 1010100110 boolean value to some think like 2345, if its possible then post me your comment on this Advanced thanks for all Narayana perumal.G From dusan.smitran at gmail.com Thu Jun 25 08:14:48 2009 From: dusan.smitran at gmail.com (dusans) Date: Thu, 25 Jun 2009 05:14:48 -0700 (PDT) Subject: scipy stats binom_test Message-ID: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> Amm i using the function wrong or ...? cuz in R i get the right value >>> binom_test(3, 5, p=0.8) 0.262 > dbinom(3, 5, 0.8) [1] 0.205 From eckhardt at satorlaser.com Thu Jun 25 08:20:41 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 25 Jun 2009 14:20:41 +0200 Subject: How to convert he boolean values into integers References: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Message-ID: krishna wrote: > I need to convert 1010100110 boolean value to some think like 2345, if > its possible then post me your comment on this Yes, sure. You can simply sum up the digit values and then format them as decimal number. You can also just look up the number: def decode_binary(input): for i in range(2**len(input)): if bin(i)==input: return str(i) I Hope I was able to help you with your homework! ;^) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From samwyse at gmail.com Thu Jun 25 08:31:04 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 05:31:04 -0700 (PDT) Subject: I need a dict that inherits its mappings Message-ID: I need a dict-like object that, if it doesn't contain a key, will return the value from a "parent" object. Is there an easy way to do this so I don't have to define __getitem__ and __contains__ and others that I haven't even thought of yet? Here's a use case, if you're confused: en_GB=mydict() en_US=mydict(en_GB) en_GB['bonnet']='part of your car' print en_US['bonnet'] # prints 'part of your car' en_US['bonnet']='a type of hat' print en_US['bonnet'] # prints 'a type of hat' print en_GB['bonnet'] # prints 'part of your car' From samwyse at gmail.com Thu Jun 25 08:33:02 2009 From: samwyse at gmail.com (samwyse) Date: Thu, 25 Jun 2009 05:33:02 -0700 (PDT) Subject: How to convert he boolean values into integers References: <5578553b-a3c6-481d-b2fa-5e0300199841@q14g2000vbn.googlegroups.com> Message-ID: >>> int('1010100110', 2) 678 On Jun 25, 7:06?am, krishna wrote: > Hi Guys, > > I need to convert 1010100110 boolean value to some think like 2345, if > its possible then post me your comment on this > > Advanced thanks for all > > Narayana perumal.G From mail at timgolden.me.uk Thu Jun 25 08:52:55 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Jun 2009 13:52:55 +0100 Subject: How to get filename from a pid? In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F2@EVS1.aeroflex.corp> Message-ID: <4A437327.2020204@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I've a PID of a process (the process is a notepad application), > I want to know which file is opened by this process. Is there anything wrong with this answer which I gave you last week? (Note: there might be, but the fact that you seem to have ignored it makes me wonder...) http://groups.google.com/group/comp.lang.python/msg/6a44e15473b08de0?hl=en TJG From horos11 at gmail.com Thu Jun 25 08:56:45 2009 From: horos11 at gmail.com (Edward Peschko) Date: Thu, 25 Jun 2009 05:56:45 -0700 Subject: trace options Message-ID: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> All, I've been looking at the trace module, and although it looks useful, I'm surprised that there aren't a couple of features that I would have thought would be fairly basic. So, does trace support (for the --trace option): - indentation tracking stacklevel (where each function is prefixed by tabs equal to the number of stacklevels deep in the program) - output to something other than sys.stdout (eg. output to a file specified either by environmental variable or by parameter). - mult-threaded programs going to multiple output handles, especially in light of the above - fully qualified python modules in path: (eg: /path/to/module/my_module.py(1): print "HERE" instead of my_module.py(1): print "HERE". Ultimately, I'd like to be able to look at two runs of a program and be able to pinpoint the very first difference between thembased on the output of their trace runs. As it stands, I really can't do this. Of course I could implement the above, but I was hoping to avoid duplicated effort if someone has already implemented options like this..I posted the above to the python-dev list, they suggested I take it here, so any help would be appreciated. Ed From jcd at sdf.lonestar.org Thu Jun 25 09:37:58 2009 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Thu, 25 Jun 2009 09:37:58 -0400 Subject: Paramiko help - processing multiple commands In-Reply-To: References: Message-ID: <1245937078.28168.9.camel@mctell> On Wed, 2009-06-24 at 15:22 -0700, Frank Ruiz wrote: > Greetings, > > I am trying to process multiple commands using paramiko. I have > searched other threads, and I think my use case is a little different. > I am trying to login to a storage node that has a special shell, and > as such I cant execute a script on the storage node side. > > I am also trying to avoid using pexpect because I hate making system > calls.. hence my leaning towards paramiko. > > Was hoping someone could help me identify a way to process multiple > commands using paramiko. > > I have two commands listed below, however only one is getting processed. > > Any help is much appreciated. > > Thanks! > > Here is my script: > > #!/usr/bin/env python > > > #-Modules--------------------------------------------------------------------- > import optparse > import sys > import paramiko > > > #-Variables------------------------------------------------------------------- > plog = 'storagessh.log' > suser = 'root' > > > #-Config---------------------------------------------------------------------- > > #-Subs-Defined---------------------------------------------------------------- > def options(): > global hostname > global goldenimage > global lunclone > global sshport > > usage = "usage: %prog [options] -n -g -l " > > parser = optparse.OptionParser(usage) > > parser.add_option("-n", "--node", > dest="hostname", > help="Name of storage node you are connecting to.") > parser.add_option("-g", "--gold", > dest="goldenimage", > help="Name of goldenimage to clone.") > parser.add_option("-l", "--lun", > dest="lunclone", > help="Name of lun to create.") > parser.add_option("-p", "--port", > dest="sshport", > default=22, > help="SSH port number.") > options, args = parser.parse_args() > > if not options.hostname: > parser.error("Missing hostname argument.") > exit > elif not options.goldenimage: > parser.error("Missing goldenimage argument.") > exit > elif not options.lunclone: > parser.error("Missing lun argument.") > exit > > hostname = options.hostname > goldenimage = options.goldenimage > lunclone = options.lunclone > sshport = options.sshport > It looks like you are trying to create a configuration class, but going through extra gyrations to use global variables instead. Perl's class system is rather convoluted, but it is straightforward in python, and will make your code easier to maintain. I recommend you take a look at the section on classes in the python tutorial, and play around with it. Not everything needs to be a class in python, but in certain cases (and this is one of them) it will make things much cleaner. > def storagessh(): > paramiko.util.log_to_file(plog) > client = paramiko.SSHClient() > client.load_system_host_keys() > client.connect(hostname, sshport, suser) > stdin, stdout, stderr = client.exec_command('show') > stdin, stdout, stderr = client.exec_command('help') > print stdout.read() > client.close() > You just did it. You processed two commands. The only problem is that you wrote values to stdin, stdout, and stderr with the show command, and then immediately overwrote them with the help command. Use different variable names for each command (like stdout_show and stdout_help), and you should be fine. > > > > #--Initialization------------------------------------------------------------- > if __name__ == "__main__": > options() > storagessh() From gagsl-py2 at yahoo.com.ar Thu Jun 25 09:59:40 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Jun 2009 10:59:40 -0300 Subject: pyinstaller References: <9277fb5b-5b64-4a26-a022-630af5c94096@v35g2000pro.googlegroups.com> Message-ID: En Sun, 21 Jun 2009 21:48:29 -0300, Arlie escribi?: > Newbie here using Python 2.6.2 on MS WinXP Pro SP3. I'm trying create > an frozen exec and was able to generate and exe file. Have you tried py2exe? > Imported files in myprog.py: > import MySQLdb Probably using MySQLdb requires some extra work... Try a more specific forum, http://www.pyinstaller.org/ menctions a mailing list. -- Gabriel Genellina From amosanderson at gmail.com Thu Jun 25 10:15:15 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Thu, 25 Jun 2009 09:15:15 -0500 Subject: os.walk and os.listdir problems python 3.0+ In-Reply-To: References: Message-ID: Thank you. That works very well when writing to a text file but what is the equivalent when writing the information to stdout using print? Sorry when I originally replied I sent it directly and it didn't go to the list. On Thu, Jun 25, 2009 at 12:57 AM, Mark Tolonen > wrote: > > "Amos Anderson" wrote in message > news:a073a9cf0906242007k5067314dn8e9d7b1c6da6286a at mail.gmail.com... > > I've run into a bit of an issue iterating through files in python 3.0 and >> 3.1rc2. When it comes to a files with '\u200b' in the file name it gives >> the >> error... >> >> Traceback (most recent call last): >> File "ListFiles.py", line 19, in >> f.write("file:{0}\n".format(i)) >> File "c:\Python31\lib\encodings\cp1252.py", line 19, in encode >> return codecs.charmap_encode(input,self.errors,encoding_table)[0] >> UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in >> position >> 30: character maps to >> >> Code is as follows... >> import os >> f = open("dirlist.txt", 'w') >> >> for root, dirs, files in os.walk("C:\\Users\\Filter\\"): >> f.write("root:{0}\n".format(root)) >> f.write("dirs:\n") >> for i in dirs: >> f.write("dir:{0}\n".format(i)) >> f.write("files:\n") >> for i in files: >> f.write("file:{0}\n".format(i)) >> f.close() >> input("done") >> >> The file it's choking on happens to be a link that internet explorer >> created. There are two files that appear in explorer to have the same name >> but one actually has a zero width space ('\u200b') just before the .url >> extension. In playing around with this I've found several files with the >> same character throughout my file system. OS: Vista SP2, Language: US >> English. >> >> Am I doing something wrong or did I find a bug? It's worth noting that >> Python 2.6 just displays this character as a ? just as it appears if you >> type dir at the windows command prompt. >> > > In Python 3.x strings default to Unicode. Unless you choose an encoding, > Python will use the default system encoding to encode the Unicode strings > into a file. On Windows, the filesystem uses Unicode and supports the full > character set, but cp1252 (on your system) is the default text file > encoding, which doesn't support zero-width space. Specify an encoding for > the output file such as UTF-8: > > f=open('blah.txt','w',encoding='utf8') >>>> f.write('\u200b') >>>> >>> 1 > >> f.close() >>>> >>> > -Mark > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saurabh.gupta.7 at gmail.com Thu Jun 25 10:17:42 2009 From: saurabh.gupta.7 at gmail.com (Saurabh) Date: Thu, 25 Jun 2009 07:17:42 -0700 (PDT) Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: On Jun 25, 2:04?am, Wayne Brehaut wrote: > On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh > > wrote: > >Hi All, > > >I am trying to move my application on a MVC architecture and plan to > >use Jinja for the same. Can anyone provide me with few quick links > >that might help me to get started with Jinja? > > Perhaps the most useful link is: > > http://www.google.com/ > > from which you can easily find many more with a very basic search, > including: > > http://jinja.pocoo.org/ > > Hope that helps? > wwwayne > > > > >Thanks, > >Saby > > Thanks (Sir!). I was hoping to get some good tutorial on implementation (which I wasn't able to find with a basic search - http://dev.pocoo.org/projects/lodgeit/ is what I was referring to earlier) as this is my first assignment on any template engine (never used Cheetah, MakO, Tempita). I would appreciate people responding with something helpful. If you find a question pretty naive, kindly ignore the question rather than passing comments on it. Doesn't helps anyone's time. Thanks again From invalid at invalid Thu Jun 25 10:45:08 2009 From: invalid at invalid (Grant Edwards) Date: Thu, 25 Jun 2009 09:45:08 -0500 Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: On 2009-06-24, Chris Rebert wrote: > In the future, also NOTE THAT SHOUTING TYPICALLY DOES NOT EARN ONE SYMPATHY. And to insure that a post is ignored, make sure the subject contains no meaningful question, only a plea for help: http://catb.org/~esr/faqs/smart-questions.html#bespecificurget Also be sure to use "urgent", "important" or "high priority" in the subject: http://catb.org/~esr/faqs/smart-questions.html#urgent However, he did forget to use multiple exclamation points -- "the nails in the coffin of a Usenet post". -- Grant Edwards grante Yow! Kids, don't gross me at off ... "Adventures with visi.com MENTAL HYGIENE" can be carried too FAR! From jeseems at gmail.com Thu Jun 25 10:49:16 2009 From: jeseems at gmail.com (Jeseem S) Date: Thu, 25 Jun 2009 07:49:16 -0700 (PDT) Subject: compiling python 2.6.2 on uclibc Message-ID: hi, am looking for patched to compile python 2.6.2 on uclibc. any help is greatly appreciated thanks jeseem From msliczniak at gmail.com Thu Jun 25 11:10:12 2009 From: msliczniak at gmail.com (Michael Sliczniak) Date: Thu, 25 Jun 2009 08:10:12 -0700 (PDT) Subject: extending method descriptors Message-ID: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Suppose I have this: Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A(object): ... __slots__ = ('x', 'y') ... >>> a = A() >>> b = A() So I am using descriptors (and I want to). I also would like to have methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was to extend member_descriptor, but it seems that I cannot: >>> type(A.x) >>> class my_descriptor(type(A.x)): ... def foo(): ... return 1 ... Traceback (most recent call last): File "", line 1, in TypeError: Error when calling the metaclass bases type 'member_descriptor' is not an acceptable base type Is there some way, outside of using C, to be able to do what I want. Yes I want a.x and b.x to be different, but type(a).x.foo(), type (b).x.foo(), and A.x.foo() should all be the same. I have tried other approaches and get exceptions of one flavor or another with everything I have tried. Thanks, mzs From aahz at pythoncraft.com Thu Jun 25 11:26:59 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 08:26:59 -0700 Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <06c4c85e-fc21-4034-b022-18792f5929e8@c36g2000yqn.googlegroups.com> <13e776b0-6ca8-479e-ba82-eb5b7eb8f445@a5g2000pre.googlegroups.com> Message-ID: In article <13e776b0-6ca8-479e-ba82-eb5b7eb8f445 at a5g2000pre.googlegroups.com>, ssc wrote: >On Jun 18, 10:49=A0am, Jon Clements wrote: >> >> Why are you doing this? I'm assuming a code to title look up is >> required (don't forget military, royal and honorable titles >> etc... :) ) > >I'm in New Zealand. Hardly any need for military titles, rarely any >for royal and damn sure none for honorable :-D (scnr) +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From kirk at daycos.com Thu Jun 25 11:31:47 2009 From: kirk at daycos.com (Kirk Strauser) Date: Thu, 25 Jun 2009 10:31:47 -0500 Subject: It's ... References: Message-ID: <87ab3w72jg.fsf@daycos.com> At 2009-06-24T19:53:49Z, Angus Rodgers writes: > stop = 3 # Tab stops every 3 characters > from types import StringType # Is this awkwardness necessary? > detab = lambda s : StringType.expandtabs(s, stop) # Or use def > f = open('h071.txt') # Do some stuff to f, perhaps, and then: > f.seek(0) > print ''.join(map(detab, f.xreadlines())) > f.close() An equivalent in modern Pythons: >>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) In short: expandtabs is a method on strings, there's no need to seek to the beginning, and files are closed when they are garbage collected (although I can't make myself not close output files after years of doing so), and map() is largely deprecated in favor of list comprehensions and generator functions. -- Kirk Strauser The Day Companies From pdpinheiro at gmail.com Thu Jun 25 11:36:50 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 25 Jun 2009 08:36:50 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <4d764b41-a9aa-477f-9b8e-9a96f718d3bd@f16g2000vbf.googlegroups.com> On Jun 25, 12:23?pm, Robin Becker wrote: > Paul Rubin wrote: > > so does this render all the discreteness implied by quantum theory unreliable? > or is it that we just cannot see(measure) the continuity that really happens? > Certainly there are people like Wolfram who seem to think we're in some kind of > giant calculating engine where state transitions are discontinuous. More like that axiomatic system doesn't accurately map to reality as we currently understand it. Your posts made me think that I wasn't clear in saying e and 2 are the only "natural" bases for logs. The log function, as the inverse of the exponential, is a pretty fundamental function. The base e exponential has a load of very natural properties, f'(x) = f (x) being an example. As the smallest admissible integer base, log 2 is also a pretty natural notion, especially in computer science, or in general all that follow from binary true/false systems. From paul at boddie.org.uk Thu Jun 25 12:06:43 2009 From: paul at boddie.org.uk (Paul Boddie) Date: Thu, 25 Jun 2009 09:06:43 -0700 (PDT) Subject: IMPORTANT: I NEED TO HELP WITH ONE OF THE CORE DEVELOPERS References: <4a422981$0$1109$4fafbaef@reader4.news.tin.it> Message-ID: <2508eb2a-d641-4efe-b9f0-09e1873112ad@k26g2000vbp.googlegroups.com> On 24 Jun, 15:22, "Pegasus" wrote: > I need help with an implementation of your > interpreter under PSPE/PSP. There doesn't seem to be much of an intersection between the PSP and "mainstream" Python communities, so some more context may have been desirable here. [...] > We believe that the trouble is in a routine > of our Nanodesktop libc that can be > a bottleneck. But we don't know > which can be the interested routine > (string ? memory allocation ?) It sounds like a job for a profiler. Maybe KCachegrind [1] along with some other tools might be of assistance. Paul [1] http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindWhat From pdpinheiro at gmail.com Thu Jun 25 12:22:03 2009 From: pdpinheiro at gmail.com (pdpi) Date: Thu, 25 Jun 2009 09:22:03 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <80fc1882-eb07-4c10-9361-1fc151c6e2fb@r25g2000vbn.googlegroups.com> On Jun 25, 10:38?am, Paul Rubin wrote: > Robin Becker writes: > > someone once explained to me that the set of systems that are > > continuous in the calculus sense was of measure zero in the set of all > > systems I think it was a fairly formal discussion, but my > > understanding was of the hand waving sort. > > That is very straightforward if you don't mind a handwave. ?Let S be > some arbitrary subset of the reals, and let f(x)=0 if x is in S, and 1 > otherwise (this is a discontinuous function if S is nonempty). ?How > many different such f's can there be? ?Obviously one for every > possible subset of the reals. ?The cardinality of such f's is the > power set of the reals, i.e. much larger than the set of reals. > > On the other hand, let g be some arbitrary continuous function on the > reals. ?Let H be the image of Q (the set of rationals) under g. ?That > is, H = {g(x) such that x is rational}. ?Since g is continuous, it is > completely determined by H, which is a countable set. ?So the > cardinality is RxN which is the same as the cardinality of R. ? > > > If true that makes calculus (and hence all of our understanding of > > such "natural" concepts) pretty small and perhaps non-applicable. > > No really, it is just set theory, which is a pretty bogus subject in > some sense. ?There aren't many discontinuous functions in nature. > There is a philosophy of mathematics (intuitionism) that says > classical set theory is wrong and in fact there are NO discontinuous > functions. ?They have their own mathematical axioms which allow > developing calculus in a way that all functions are continuous. > > > On the other hand R Kalman (of Bucy and Kalman filter fame) likened > > study of continuous linear dynamical systems to "a man searching for > > a lost ring under the only light in a dark street" ie we search > > where we can see. Because such systems are tractable doesn't make > > them natural or essential or applicable in a generic sense. > > Really, I think the alternative he was thinking of may have been > something like nonlinear PDE's, a horribly messy subject from a > practical point of view, but still basically free of set-theoretic > monstrosities. ?The Banach-Tarski paradox has nothing to do with nature. I'll take the Banach-Tarski construct (it's not a paradox, damn it!) over non-linear PDEs any day of the week, thankyouverymuch. :) From nick at craig-wood.com Thu Jun 25 12:30:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 11:30:03 -0500 Subject: A superclass using a child classes' methods References: <6c8e440c-ebd9-41ae-9b03-14b0d3870d11@f10g2000vbf.googlegroups.com> <87ccaa96-6462-45d3-8108-f09a94ae6797@l28g2000vba.googlegroups.com> Message-ID: Kurt Schwehr wrote: > Thanks for the excellent response setting me straight. Now to figure > out what dumb thing I did to make my code not work... If you have trouble then post the code (or a cut down version demonstrating the code) - it always helps to have real code with real error messages when tracking down problems. A lot of people (like me) will enjoy the puzzle of looking through your code and finding out where it went wrong. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nick at craig-wood.com Thu Jun 25 12:30:03 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 11:30:03 -0500 Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: Carl Banks wrote: > On Jun 23, 10:02?pm, ?????? ??????????? wrote: > > I need to programmaticaly enumerate all the classes in a given module. > > Currently I'm using dir(module) but the Notice on the documentation page > > [1] ?says "dir() is supplied primarily as a convenience for use at an > > interactive prompt" so that kind of scares me. > > > > Is there a better approach? > > > > If there is, how do I get all the classes of the current module? > > You can use module.__dict__.values() (or .itervalues()) to retrieve > the contents of the module (and of course .keys() if you want names). > If you want to check the same module that the code appears in, use > globals() instead of module.__dict__. > > Something makes me think that module.__dict__ was only added to Python > fairly recently, but I'm not sure. It exists in python2.1 - I don't have an older python to check at the moment. > A word of warning (although I would guess you are already aware of > these issues, but for other readers): this method can't tell the > difference between a class defined in the module and a class imported > into it. > > Finally, despite the warning, I think you are ok to use dir() for that > purpose. It's not likely to change. Good advice... And as a double check >>> import sys >>> set(sys.__dict__.keys()) == set(dir(sys)) True >>> import os >>> set(os.__dict__.keys()) == set(dir(os)) True -- Nick Craig-Wood -- http://www.craig-wood.com/nick From __peter__ at web.de Thu Jun 25 12:53:12 2009 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Jun 2009 18:53:12 +0200 Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Message-ID: Michael Sliczniak wrote: > Suppose I have this: > > Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> class A(object): > ... __slots__ = ('x', 'y') > ... >>>> a = A() >>>> b = A() > > So I am using descriptors (and I want to). I also would like to have > methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was > to extend member_descriptor, but it seems that I cannot: > >>>> type(A.x) > >>>> class my_descriptor(type(A.x)): > ... def foo(): > ... return 1 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: Error when calling the metaclass bases > type 'member_descriptor' is not an acceptable base type > > Is there some way, outside of using C, to be able to do what I want. > Yes I want a.x and b.x to be different, but type(a).x.foo(), type > (b).x.foo(), and A.x.foo() should all be the same. I have tried other > approaches and get exceptions of one flavor or another with everything > I have tried. If you define an attribute with the same name in both the class and its instances the instance attribute just hides the class attribute: >>> class X(object): ... def foo(self): return "yadda" ... >>> class A(object): ... def __init__(self, x): ... self.x = x ... x = X() ... >>> a = A("foo") >>> b = A("bar") >>> a.x, b.x, type(a).x.foo(), type(b).x.foo() ('foo', 'bar', 'yadda', 'yadda') This is probably not what you expected. So what are you really trying to achieve? Peter From twirlip at bigfoot.com Thu Jun 25 12:53:51 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:53:51 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser wrote: >At 2009-06-24T19:53:49Z, Angus Rodgers writes: > >> print ''.join(map(detab, f.xreadlines())) > >An equivalent in modern Pythons: > >>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) I guess the code below would also have worked in 2.1? (It does in 2.5.4.) print ''.join(line.expandtabs(3) for line in \ file('h071.txt').xreadlines()) -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 12:56:47 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:56:47 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:53:51 +0100, I wrote: >On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser > wrote: > >>At 2009-06-24T19:53:49Z, Angus Rodgers writes: >> >>> print ''.join(map(detab, f.xreadlines())) >> >>An equivalent in modern Pythons: >> >>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) > >I guess the code below would also have worked in 2.1? >(It does in 2.5.4.) > > print ''.join(line.expandtabs(3) for line in \ > file('h071.txt').xreadlines()) Possibly silly question (in for a penny ...): does the new feature, by which a file becomes iterable, operate by some kind of coercion of a file object to a list object, via something like x.readlines()? -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 12:58:35 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 17:58:35 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:56:47 +0100, I found a new way to disgrace myself, thus: >[...] something like x.readlines()? ^ I don't know how that full stop got in there. Please ignore it! -- Angus Rodgers From twirlip at bigfoot.com Thu Jun 25 13:07:19 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Thu, 25 Jun 2009 18:07:19 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently: >[...] does the new feature, >by which a file becomes iterable, operate by some kind of coercion >of a file object to a list object, via something like x.readlines()? Sorry to follow up my own post yet again (amongst my weapons is a fanatical attention to detail when it's too late!), but I had better rephrase that question: Scratch "list object", and replace it with something like: "some kind of iterator object, that is at least already implicit in 2.1 (although the term 'iterator' isn't mentioned in the index to the 2nd edition of Beazley's book)". Something like that! 8-P -- Angus Rodgers From python at mrabarnett.plus.com Thu Jun 25 13:22:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 18:22:48 +0100 Subject: It's ... In-Reply-To: References: <87ab3w72jg.fsf@daycos.com> Message-ID: <4A43B268.1040202@mrabarnett.plus.com> Angus Rodgers wrote: > On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser > wrote: > >> At 2009-06-24T19:53:49Z, Angus Rodgers writes: >> >>> print ''.join(map(detab, f.xreadlines())) >> An equivalent in modern Pythons: >> >>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) > > I guess the code below would also have worked in 2.1? > (It does in 2.5.4.) > > print ''.join(line.expandtabs(3) for line in \ > file('h071.txt').xreadlines()) > That uses a generator expression, which was introduced in 2.4. From norseman at hughes.net Thu Jun 25 13:24:00 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:24:00 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: References: Message-ID: <4A43B2B0.1050006@hughes.net> rom wrote: > Thanks for your response. I have modified this minimal program as you > suggested but still is not able to print the filename: > > ###################### > import Tkinter > import tkFileDialog > > global filename # NO NO NO! No global line here > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): # global var goes here, inside the def so the var filename is not local # just like I show below. > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > > print filename > > root.mainloop() > ###################### > > Is this what you mean? > > > On Jun 25, 1:28 pm, norseman wrote: >> OOPS - I left out the global statement >> >> rom wrote: >>> Hi there, >>> I am writing an interface with Tkinter. My minimal program looks like >>> this: >>> ############# >>> import Tkinter >>> import tkFileDialog >> # define globals here >> filename= '' # will take care of the problem >> >>> root = Tkinter.Tk() >>> Tkinter.Button(root, text='Notch genes...', command=lambda: >>> open_file_dialog()).pack() >>> def open_file_dialog(): >> global filename # need this to assign to it >> >>> filename = tkFileDialog.askopenfilename(filetypes=[("all >>> files","*")]) >>> # print filename >>> root.mainloop() >>> ############# >>> I would like to recover the filename variable outside the >>> "open_file_dialog" function. For instance, to be able to print the >>> selected file name (uncomment "# print filename" line). >>> Is there a way to do that? >>> Thanks in advance. >>> R >> > From norseman at hughes.net Thu Jun 25 13:33:54 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:33:54 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> References: <46ea26c8-4605-49f9-a0fa-bd0091492c79@x6g2000prc.googlegroups.com> Message-ID: <4A43B502.8000400@hughes.net> rom wrote: > Ok. I think I got it. I have to do it in this way: > ########################### > import Tkinter > import tkFileDialog > > > filename='' > > root = Tkinter.Tk() > > Tkinter.Button(root, text='Notch genes...', command=lambda: > open_file_dialog()).pack() > > def open_file_dialog(): > global filename > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > print_filename() > > def print_filename(): > print filename > > root.mainloop() > ########################### > Thanks again > > On Jun 25, 1:46 pm, rom wrote: >> Thanks for your response. I have modified this minimal program as you >> suggested but still is not able to print the filename: >> >> ###################### >> import Tkinter >> import tkFileDialog >> >> global filename >> filename='' >> >> root = Tkinter.Tk() >> >> Tkinter.Button(root, text='Notch genes...', command=lambda: >> open_file_dialog()).pack() >> >> def open_file_dialog(): >> filename = tkFileDialog.askopenfilename(filetypes= >> [("allfiles","*")]) >> >> print filename >> >> root.mainloop() >> ###################### >> >> Is this what you mean? >> >> On Jun 25, 1:28 pm, norseman wrote: >> >>> OOPS - I left out the global statement >>> rom wrote: >>>> Hi there, >>>> I am writing an interface with Tkinter. My minimal program looks like >>>> this: >>>> ############# >>>> import Tkinter >>>> import tkFileDialog >>> # define globals here >>> filename= '' # will take care of the problem >>>> root = Tkinter.Tk() >>>> Tkinter.Button(root, text='Notch genes...', command=lambda: >>>> open_file_dialog()).pack() >>>> def open_file_dialog(): >>> global filename # need this to assign to it >>>> filename = tkFileDialog.askopenfilename(filetypes=[("all >>>> files","*")]) >>>> # print filename >>>> root.mainloop() >>>> ############# >>>> I would like to recover the filename variable outside the >>>> "open_file_dialog" function. For instance, to be able to print the >>>> selected file name (uncomment "# print filename" line). >>>> Is there a way to do that? >>>> Thanks in advance. >>>> R >> =========== Now you got it!! So ignore my just previous response. :) The global statement inside the def keeps the specified variable from being local by default. If the global statement is "higher up the food chain" then it will cause Python to look back for a definition from that point. There may not be one or it might be other than expected. Python works backward (or up) from global statement through the defs and modules enclosing it. Uses first found. A small suggestion, filename is a word usually used commonly. fname would be a better substitute. Or fn or ifil, ofil (in/out files) and so forth. Of course it is perfectly OK for question and answer time. version: Python OS : All or Not relevant date : June 25, 2009 Steve From larudwer at freenet.de Thu Jun 25 13:51:10 2009 From: larudwer at freenet.de (larudwer) Date: Thu, 25 Jun 2009 19:51:10 +0200 Subject: Problem with multithreading References: Message-ID: "Jeffrey Barish" schrieb im Newsbeitrag news:mailman.2091.1245902997.8015.python-list at python.org... > Jeffrey Barish wrote: > >> I have a program that uses multithreading to monitor two loops. When >> something happens in loop1, it sends a message to loop2 to have it >> execute >> a command. loop2 might have to return a result. If it does, it puts the >> result in a queue. loop1, meanwhile, would have blocked waiting for >> something to appear in the queue. The program works for a while, but >> eventually freezes. I know that freezing is a sign of deadlock. >> However, >> I put in print statements to localize the problem and discovered >> something >> weird. The freeze always occurs at a point in the code with the >> following >> statements: >> >> print "about to try" >> try: >> print "in try" >> >> >> I get "about to try", but not "in try". Is this observation consistent >> with >> the deadlock theory? If not, what could be making the program freeze at >> the try statement? I wrote a test program using the same techniques to >> illustrate the problem, but the test program works perfectly. I could >> post it, though, if it would help to understand what I am doing -- and >> what might be wrong in the real program. > > As I ponder this problem, I am beginning to believe that the problem is > not > related to multithreading. If the problem were due to a collision between > the two threads then timing would matter, yet I find that the program > always freezes at exactly the same statement (which executes perfectly > hundreds of times before the freeze). Moreover, the test program that I > wrote to test the multithreading implementation works perfectly. And > finally, there is nothing going on related to multithreading at this point > in the code. Why else might the program freeze at a try statement? > -- > Jeffrey Barish > If you have one thread sleeping you need another running thread to waken up the sleeping thread. If the running thread terminates unexpectedly the other thread will sleep forever. Though. Since there is a try statement in your example code and the failure always happens there, there might be the chance that some unexpected exception was thrown and cought somewhere else in your program. If the Program is terminated, the last print might also have gone lost in some I/O buffer. There is no guarantee that the print statement really wasn't executed. Think about things like exception Queue.Empty Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty. exception Queue.Full Exception raised when non-blocking put() (or put_nowait()) is called on a Queue object which is full. From mail131 at gmail.com Thu Jun 25 13:57:10 2009 From: mail131 at gmail.com (Private Private) Date: Thu, 25 Jun 2009 10:57:10 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> On Jun 25, 10:59?am, Chris Withers wrote: > Private Private wrote: > > from those forms, etc. I have read a bit about Django and TurboGears > > but I am afraid that this is too big for my requirements (am I > > wrong ?). > > You are wrong :-) Why ? What I've read about Django, Turbogears is that they are powerful enough to create big web-based portals, applications, etc. I need just simple forms without any sophisticated functionality. So again: why I am wrong ? przemol From norseman at hughes.net Thu Jun 25 13:58:05 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 10:58:05 -0700 Subject: tkinter: get filename of askopenfilename In-Reply-To: <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> References: <560f1a04-6b30-488b-807f-fd8f0bcc3371@a39g2000pre.googlegroups.com> <27e2f283-3b6a-4582-bed6-25f58eb8113d@w35g2000prg.googlegroups.com> Message-ID: <4A43BAAD.8040108@hughes.net> rom wrote: > Thanks again. After your replies, I have understood how to do what I > wanted. What I wanted to do is to get a value after clicking a button > and use it in another part of the program. As you said, after getting > the value, I have to store it in a global variable. However, the > program does not do anything with it until I trigger another event, > e.g. by clicking on another button. Therefore, I have added another > button to my program: > ##################### > import Tkinter > import tkFileDialog > > filename = 'uninitialized' > > def open_file_dialog(): > global filename > filename = tkFileDialog.askopenfilename(filetypes= > [("allfiles","*")]) > > def print_variable(variable): > print variable > > root = Tkinter.Tk() > Tkinter.Button(root, text='Select file...', > command=open_file_dialog).pack() > > Tkinter.Button(root, text='Print file', command=lambda: print_variable > (filename)).pack() > > root.mainloop() > ##################### Your original, as written, would open and print immediately. But it could be a problem as (or if) more code is added in that area. This current code allows the user to open, perhaps view via other code and print only if wanted. Either is OK, having both is OK, making it do what Rom wants is best. :) If open/print was wanted, put the print statement in the open file button group right after the open file statement. Anyone reading the code will immediately understand that is the intent. At least for that button. Also it would be best to put the def statements before the button statements. Actually it is best to put all defs BEFORE the GUI (frame, buttons, etc...) statements when using Tkinter. The print filename statement being placed as in the original request may attempt to print filename after other code above it is run. Since Tkinter is not a 'closed' package, that is, it's statements can be interspersed with program code, it is thus best to make sure what will and will not be triggered by other actions. I've beat my head on that a few times. :) Steve ...(snip) From bojan at sudarevic.com Thu Jun 25 14:04:57 2009 From: bojan at sudarevic.com (Bojan Sudarevic) Date: Thu, 25 Jun 2009 20:04:57 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? Message-ID: Hi, I'm PHP developer and entirely new to Python. I installed it (version 2.5.2, from Debian repos) today on the persuasion of a friend, who is a Python addict. The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, I don*t know, I just did). And the answer wasn't 9.6. Here it is: >>> 3.2*3 9.6000000000000014 So I became curious... >>> 3.21*3 9.629999999999999 >>> (3.2*3)*2 19.200000000000003 ... and so on ... After that I tried Windows version (3.1rc2), and... >>> 3.2*3 9.600000000000001 I wasn't particularly good in math in school and university, but I'm pretty sure that 3.2*3 is 9.6. Cheers, Bojan From amosanderson at gmail.com Thu Jun 25 14:18:08 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Thu, 25 Jun 2009 13:18:08 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: I think what your experiencing is addressed on this page... http://docs.python.org/tutorial/floatingpoint.html ... it has to do with the binary representation of the numbers. On Thu, Jun 25, 2009 at 1:04 PM, Bojan Sudarevic wrote: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > > >>> 3.2*3 > 9.6000000000000014 > > So I became curious... > > >>> 3.21*3 > 9.629999999999999 > >>> (3.2*3)*2 > 19.200000000000003 > ... and so on ... > > After that I tried Windows version (3.1rc2), and... > > >>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. > > Cheers, > Bojan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Thu Jun 25 14:19:22 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 11:19:22 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <26be756e-5a0a-40cd-b9a2-133ce14ac7d7@n30g2000vba.googlegroups.com> On Jun 25, 7:04?pm, Bojan Sudarevic wrote: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > [examples snipped] Hi Bojan, This is a FAQ. Take a look at: http://docs.python.org/tutorial/floatingpoint.html and let us know whether that explains things to your satisfaction. Mark From tomasz.zielinski at pyconsultant.eu Thu Jun 25 14:20:13 2009 From: tomasz.zielinski at pyconsultant.eu (=?ISO-8859-2?Q?Tomasz_Zieli=F1ski?=) Date: Thu, 25 Jun 2009 11:20:13 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <71fb8dc4-42ec-46e6-9ec9-ce066f14f706@l32g2000vba.googlegroups.com> On 25 Cze, 20:04, Bojan Sudarevic wrote: > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. > It's not math, it's floating point representation of numbers - and its limited accuracy. Type 9.6 and you'll get 9.5999999999999996 -- Tomasz Zielinski http://pyconsultant.eu From pecora at anvil.nrl.navy.mil Thu Jun 25 14:20:33 2009 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 25 Jun 2009 14:20:33 -0400 Subject: Problem with multithreading References: Message-ID: In article , "larudwer" wrote: > "Jeffrey Barish" schrieb im Newsbeitrag > news:mailman.2091.1245902997.8015.python-list at python.org... > > Jeffrey Barish wrote: > > > >> I have a program that uses multithreading to monitor two loops. When > >> something happens in loop1, it sends a message to loop2 to have it > >> execute > >> a command. loop2 might have to return a result. If it does, it puts the > >> result in a queue. loop1, meanwhile, would have blocked waiting for > >> something to appear in the queue. The program works for a while, but > >> eventually freezes. I know that freezing is a sign of deadlock. > >> However, > >> I put in print statements to localize the problem and discovered > >> something > >> weird. The freeze always occurs at a point in the code with the > >> following > >> statements: > >> > >> print "about to try" > >> try: > >> print "in try" > >> > >> > >> I get "about to try", but not "in try". Is this observation consistent Try putting a flush in after the 2nd print statement in case the output is left in some I/O buffer when the thing terminates. e.g. import sys .... try: print 'in try" sys.stdout.flush() -- -- Lou Pecora From tjreedy at udel.edu Thu Jun 25 14:21:18 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 14:21:18 -0400 Subject: I need a dict that inherits its mappings In-Reply-To: References: Message-ID: samwyse wrote: > I need a dict-like object that, if it doesn't contain a key, will > return the value from a "parent" object. Is there an easy way to do > this so I don't have to define __getitem__ and __contains__ and others > that I haven't even thought of yet? Here's a use case, if you're > confused: > > en_GB=mydict() > en_US=mydict(en_GB) > > en_GB['bonnet']='part of your car' > print en_US['bonnet'] # prints 'part of your car' > > en_US['bonnet']='a type of hat' > print en_US['bonnet'] # prints 'a type of hat' > print en_GB['bonnet'] # prints 'part of your car' For that specific case: def lookup(key): try: return en_US[key] except KeyError: return en_GB[key] More generally, def make_lookup_with_backup(d1, d2): def _l(key): try: return d1[key] except KeyError: return d2[key] return _ Terry Jan Reedy From emile at fenx.com Thu Jun 25 14:29:32 2009 From: emile at fenx.com (Emile van Sebille) Date: Thu, 25 Jun 2009 11:29:32 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: On 6/25/2009 11:04 AM Bojan Sudarevic said... >>>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. Yes -- in this world. But in the inner workings of computers, 3.2 isn't accurately representable in binary. This is a faq. ActivePython 2.6.2.2 (ActiveState Software Inc.) based on Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 3.2 3.2000000000000002 >>> Emile From paul.nospam at rudin.co.uk Thu Jun 25 14:32:12 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 25 Jun 2009 19:32:12 +0100 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <87ljngmafn.fsf@rudin.co.uk> Bojan Sudarevic writes: > Hi, > > I'm PHP developer and entirely new to Python. I installed it (version > 2.5.2, from Debian repos) today on the persuasion of a friend, who is a > Python addict. > > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > >>>> 3.2*3 > 9.6000000000000014 > > So I became curious... > >>>> 3.21*3 > 9.629999999999999 >>>> (3.2*3)*2 > 19.200000000000003 > ... and so on ... > > After that I tried Windows version (3.1rc2), and... > >>>> 3.2*3 > 9.600000000000001 > > I wasn't particularly good in math in school and university, but I'm > pretty sure that 3.2*3 is 9.6. This is almost certainly nothing to do with python per se, but the floating point implementation of your hardware. Floating point arithmetic on computers is not accurate to arbitrary precision. If you want such precision use a library that supports it or make you own translations to and from appropriate integer sums (but it's going to be slower). From dickinsm at gmail.com Thu Jun 25 14:35:12 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 11:35:12 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <11bda8df-45ce-4356-aafe-5e80b037105c@n21g2000vba.googlegroups.com> On Jun 25, 7:04?pm, Bojan Sudarevic wrote: > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. It looks like it's false in PHP too, by the way (not that I know any PHP, so I could well be missing something...) bernoulli:py3k dickinsm$ php -a Interactive mode enabled References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> Message-ID: <4A43C3DB.7080504@simplistix.co.uk> Private Private wrote: > What I've read about Django, Turbogears is that they are powerful > enough to create big web-based portals, applications, etc. > I need just simple forms without any sophisticated functionality. > So again: why I am wrong ? Just because something is powerful doesn't mean you can't do simple things with it. Have a read of the first few chapters of the Django book... http://www.djangobook.com/ Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From bojan at sudarevic.com Thu Jun 25 14:37:59 2009 From: bojan at sudarevic.com (Bojan Sudarevic) Date: Thu, 25 Jun 2009 20:37:59 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <26be756e-5a0a-40cd-b9a2-133ce14ac7d7@n30g2000vba.googlegroups.com> Message-ID: In article <26be756e-5a0a-40cd-b9a2-133ce14ac7d7 @n30g2000vba.googlegroups.com>, dickinsm at gmail.com says... > This is a FAQ. Take a look at: > > http://docs.python.org/tutorial/floatingpoint.html > > and let us know whether that explains things to your > satisfaction. > Hi Mark, Yes, that explains things to my satisfation. Now I'm embarrassed that I didn't know that before. Thanks, Bojan From torriem at gmail.com Thu Jun 25 14:41:13 2009 From: torriem at gmail.com (Michael Torrie) Date: Thu, 25 Jun 2009 12:41:13 -0600 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: Message-ID: <4A43C4C9.1020601@gmail.com> Bojan Sudarevic wrote: > The first thing I typed into it was 3.2*3 (don't ask why I typed *that*, > I don*t know, I just did). And the answer wasn't 9.6. > > Here it is: > >>>> 3.2*3 > 9.6000000000000014 I'm surprised how often people encounter this and wonder about it. As I began programming back in the day using C, this is just something I grew up with (grudging acceptance). I guess PHP artificially rounds the results or something to make it seem like it's doing accurate calculations, which is a bit surprising to me. We all know that IEEE floating point is a horribly inaccurate representation, but I guess I'd rather have my language not hide that fact from me. Maybe PHP is using BCD or something under the hood (slow but accurate). If you want accurate math, check out other types like what is in the decimal module: >>> import decimal >>> a=decimal.Decimal('3.2') >>> print a * 3 9.6 From robert.kern at gmail.com Thu Jun 25 14:44:47 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 13:44:47 -0500 Subject: scipy stats binom_test In-Reply-To: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> References: <8bb3e8af-5093-497b-b87e-5a2552e5ea1d@q14g2000vbn.googlegroups.com> Message-ID: On 2009-06-25 07:14, dusans wrote: > Amm i using the function wrong or ...? cuz in R i get the right value > >>>> binom_test(3, 5, p=0.8) > 0.262 > >> dbinom(3, 5, 0.8) > [1] 0.205 The R equivalent of scipy.stats.binom_test() is binom.test(), not dbinom(). If you want the equivalent of dbinom(), use scipy.stats.binom.pmf(3,5,0.8). If you have more scipy questions, you should ask them on the scipy 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 robert.kern at gmail.com Thu Jun 25 14:56:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 13:56:37 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: <4A43C4C9.1020601@gmail.com> References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 13:41, Michael Torrie wrote: > If you want accurate math, check out other types like what is in the > decimal module: > >>>> import decimal >>>> a=decimal.Decimal('3.2') >>>> print a * 3 > 9.6 I wish people would stop representing decimal floating point arithmetic as "more accurate" than binary floating point arithmetic. It isn't. Decimal floating point arithmetic does have an extremely useful niche: where the inputs have finite decimal representations and either the only operations are addition, subtraction and multiplication (e.g. many accounting problems) OR there are conventional rounding modes to follow (e.g. most of the other accounting problems). In the former case, you can claim that decimal floating point is more accurate *for those problems*. But as soon as you have a division operation, decimal floating point has the same accuracy problems as binary floating point. -- 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 spconv+m at gmail.com Thu Jun 25 15:02:48 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Thu, 25 Jun 2009 21:02:48 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem Message-ID: <111013c20906251202q5846efebw60ef54439ecefb6f@mail.gmail.com> Hello I'm writing an application in Python 2.5.4 under Windows (xp sp3 en). I use Tkinter as the main GUI toolkit. The app is intended to be portable (not fully but win & mac os x is a must). It works as it should on my system, but when I've sent the program to my friend who has a mac computer, he told me accented characters are turned into weird symbols. It is another must, the GUI consists of widgets with polish characters. I always use UTF-8 encoding in Python and I save my scripts in Notepad++ as UTF-8 without BOM. I've never experienced similar problems under Windows with Tkinter before I've created a simple test script: CODE_START >> # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() Label(root, text='?????????').pack() Button(root, text='?????????').pack() Entry(root).pack() root.mainloop() CODE_END >> No problem on Windows, but on mac Button widget has correct text. Label and Entry has garbage instead of accented characters. (Mac OS X 10.5.6 and 10.4.11 both armed with Python 2.5.4) I've tried various UTF file encoding (also with BOM mark), use of u"text" or unicode() function - non of this worked. Googling shows not much: reload(sys) sys.setdefaultencoding("utf-8") or: root = Tk() root.tk.call('encoding', 'system', 'utf-8') After applying this, the effect remains the same - one big garbage. I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both support UTF-8, Python also supports it - so where is the problem? How can I show mac-users polish signs? Please Help! From martin at v.loewis.de Thu Jun 25 15:25:07 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 25 Jun 2009 21:25:07 +0200 Subject: Barbara Liskov wins Turing Award In-Reply-To: References: <50697b2c0906250043gafdbbfavb5058460564fa06a@mail.gmail.com> Message-ID: <4a43cf13$0$5131$9b622d9e@news.freenet.de> > Python's object model, assignment semantics, and call-by-object > mechanism, and that name, come from CLU. Whether Guido knew of it > directly or not, I do not know. To the extent that the above is part of > the heart of Python, I think Steven's statement stands pretty well. Why do you say that? ISTM that Python is much closer to Smalltalk than to CLU in its object model. CLU is statically typed (and it is important to its notion of program correctness that it is statically typed); Smalltalk and Python aren't. In addition, Smalltalk and Python have inheritance; CLU (deliberately) doesn't. Liskov reported that she didn't know about Smalltalk until 1976. I believe that Python's, CLU's, and Smalltalk's assignment semantics actually all come from Simula. I would claim the same for the call-by-object mechanism - except that this is probably best described as coming from LISP (in the sense of caller and callee sharing references). FWIW, Simula has also inheritance, but that specific notion of inheritance did not transfer to any other language, except for Beta. Regards, Martin From pavlovevidence at gmail.com Thu Jun 25 15:30:30 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 12:30:30 -0700 (PDT) Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> Message-ID: <4dbdd92b-2f7d-45a4-933e-ed15e65f854c@s16g2000vbp.googlegroups.com> On Jun 25, 8:10?am, Michael Sliczniak wrote: > Suppose I have this: > > Python 2.5.1 (r251:54863, Feb ?6 2009, 19:02:12) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information.>>> class A(object): > > ... ? ? __slots__ = ('x', 'y') > ... > > >>> a = A() > >>> b = A() > > So I am using descriptors (and I want to). I also would like to have > methods A.x.foo(), A.x.bar(), A.y.foo(), and A.y.bar() and my idea was > to extend member_descriptor, but it seems that I cannot: > > >>> type(A.x) > > >>> class my_descriptor(type(A.x)): > > ... ? ? def foo(): > ... ? ? ? ? ? ? return 1 > ... > Traceback (most recent call last): > ? File "", line 1, in > TypeError: Error when calling the metaclass bases > ? ? type 'member_descriptor' is not an acceptable base type The question isn't too clear, but I can explain this error message. A Python type defined in C must have Py_TP_BASETYPE set in its tp_flags field, otherwise subclassing it isn't happening. If you want such functionality, I believe it would be easiest have to implement a MemberDescriptorWrapper class in Python that delegates to the actual member_descriptor. You would use it something like this: class A(object): __slots__ = ['_x_internal','_y_internal'] x = MemberDescriptorWrapper('_x_internal') y = MemberDescriptorWrapper('_y_internal') MemberDescriptorWrapper class would have to implement __get__, __set__, and __del__ methods and have them call the corresponding methods on the slot; details are left as an exercise. Carl Banks From dickinsm at gmail.com Thu Jun 25 15:31:05 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 25 Jun 2009 12:31:05 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: On Jun 25, 7:41?pm, Michael Torrie wrote: > I guess PHP artificially rounds the results or something to make it seem > like it's doing accurate calculations, which is a bit surprising to me. After a bit of experimentation on my machine, it *looks* as though PHP is using the usual hardware floats internally (no big surprise there), but implicit conversions to string use 14 significant digits. If Python's repr used '%.14g' internally instead of '%.17g' then we'd see pretty much the same thing in Python. > We all know that IEEE floating point is a horribly inaccurate > representation [...] That's a bit extreme! Care to elaborate? , but I guess I'd rather have my language not hide that > fact from me. ?Maybe PHP is using BCD or something under the hood (slow > but accurate). > > If you want accurate math, check out other types like what is in the > decimal module: As Robert Kern already said, there really isn't any sense in which decimal floating-point is any more accurate than binary floating-point, except that---somewhat tautologically---it's better at representing decimal values exactly. The converse isn't true, though, from a numerical perspective: there are some interesting examples of bad things that can happen with decimal floating-point but not with binary. For example, given any two Python floats a and b, and assuming IEEE 754 arithmetic with default rounding, it's always true that a <= (a+b)/2 <= b, provided that a+b doesn't overflow. Not so for decimal floating-point: >>> import decimal >>> decimal.getcontext().prec = 6 # set working precision to 6 sig figs >>> (decimal.Decimal('7.12346') + decimal.Decimal('7.12348'))/2 Decimal('7.12345') Similarly, sqrt(x*x) == x is always true for a positive IEEE 754 double x (again assuming the default roundTiesToEven rounding mode, and assuming that x*x neither overflows nor underflows). But this property fails for IEEE 754-compliant decimal floating-point. Mark From martin.schoon at gmail.com Thu Jun 25 15:36:53 2009 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Thu, 25 Jun 2009 21:36:53 +0200 Subject: Slow wxPyhon on Vista? References: <87y6ro3afs.fsf@crunchbang.Belkin> Message-ID: <87vdmkhzqi.fsf@crunchbang.Belkin> David Lyon writes: > On Fri, 19 Jun 2009 10:16:39 +0200, martin.schoon at gmail.com (Martin > Sch??n) wrote: >> Here is my problem. When I use it on a Vista box its >> user interface is very, very slow when it comes to >> some but not all operations. On any other Windows >> version it reacts instantaneously. I have not tried >> Task Coach on Linux or Solaris (yet). >> >> Is this how wxPython or Python works on Vista in >> general or is this the result of some local oddity on my >> employer's Vista configuration? > > I have encountered the same thing on XP in one instance > on a development box. For some reason, wxpython just > grinds to a halt. > > I couldn't solve it and reimaged the O/S... that > fixed it... Reimaged? Since my first post on this I have installed the very latest version of Task Coach and Vista has been through an SP1 install. The GUI speed issue remains despite this. /Martin From ---***gilucasa***--- at email.it Thu Jun 25 15:37:53 2009 From: ---***gilucasa***--- at email.it (gianbrix) Date: Thu, 25 Jun 2009 19:37:53 GMT Subject: py2exe: some problems Message-ID: Hi, I am trying to get an exe file using py2exe with one my application. If I let all in the same main folder it works fine. If I set zipfile="bin\\myapp.zip" I get some errors like this: "unable to load dlls:" relating to win32gui or win32print etc. What is wrong? There is a way to have zipfile set to None and move the pyds and dlls in the bin folder? Regards Gianluca From jeff_barish at earthlink.net Thu Jun 25 15:47:30 2009 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Thu, 25 Jun 2009 13:47:30 -0600 Subject: Problem with multithreading References: Message-ID: Lou Pecora wrote: > In article , > "larudwer" wrote: > >> "Jeffrey Barish" schrieb im Newsbeitrag >> news:mailman.2091.1245902997.8015.python-list at python.org... >> > Jeffrey Barish wrote: >> > >> >> I have a program that uses multithreading to monitor two loops. When >> >> something happens in loop1, it sends a message to loop2 to have it >> >> execute >> >> a command. loop2 might have to return a result. If it does, it puts >> >> the >> >> result in a queue. loop1, meanwhile, would have blocked waiting for >> >> something to appear in the queue. The program works for a while, but >> >> eventually freezes. I know that freezing is a sign of deadlock. >> >> However, >> >> I put in print statements to localize the problem and discovered >> >> something >> >> weird. The freeze always occurs at a point in the code with the >> >> following >> >> statements: >> >> >> >> print "about to try" >> >> try: >> >> print "in try" >> >> >> >> >> >> I get "about to try", but not "in try". Is this observation >> >> consistent > > Try putting a flush in after the 2nd print statement in case the output > is left in some I/O buffer when the thing terminates. e.g. > > import sys > > .... > > try: > print 'in try" > sys.stdout.flush() > > I was hoping for some suggestions of things to think about, so thanks especially to those who had such suggestions. Believe it or not (and I'm having trouble believing it myself), I didn't think to use flush. When I did, I found that, indeed, the program did progress past the try statement. It made it to a call to GStreamer (playbin2), which has been proving itself intractable in my experience. Note that my test program (which works) excised GStreamer. The next step will be to try again to compile the latest version of PyGST as the version in Ubuntu 9.04 is one generation old. The last time I tried, the compile failed. This is the first time in days that I have had any hope. -- Jeffrey Barish From tjreedy at udel.edu Thu Jun 25 16:08:24 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Jun 2009 16:08:24 -0400 Subject: trace options In-Reply-To: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> References: <5cfa99000906250556l2923e628pb08877e7c9e4b440@mail.gmail.com> Message-ID: Edward Peschko wrote: > All, > > I've been looking at the trace module, and although it looks useful, I'm > surprised that there aren't a couple of features that I would have thought > would be fairly basic. So, does trace support (for the --trace option): I have never used the trace module but decided to try it out, following the simple example in the docs with a simple function. It seems a bit underdocumented, so I presume help with that would be welcome. I also found deficiencies in the operation, though different from you. > - indentation tracking stacklevel (where each function is prefixed > by tabs equal to the number of stacklevels deep in the program) Trace already does one space indents for modules after the first --- modulename: threading, funcname: settrace --- modulename: compare, funcname: lt_iw and lines after the first compare.py(47): while m != 0 and n != 0: compare.py(48): m, n = m-1, n-1 That would have to be eliminated, at least when stack indents were on. Tabs are nasty when interpreted as 8 chars. If added, the user should specify the indent: indent = ' ', for instance, for 2 space indents. > - output to something other than sys.stdout (eg. output to a file > specified either by environmental variable or by parameter). That seems reasonable. It also seems reasonable that I be able to write counts *to* stdout (the screen) when running interactive. But when I changed r.write_results(show_missing=True, coverdir="/tmp") in the doc example to just r.write_results() I got nothing, rather than the line-by-line count I expected. A bug? On the other hand, r.write_results(summary=True) did give output - the coverage for the module, which was not helpful. This was so with both run('func(args)') and runfunc(func, args) Coverage should be by function, I think, especially with runfunc. > - mult-threaded programs going to multiple output handles, > especially in light of the above > > - fully qualified python modules in path: (eg: > > /path/to/module/my_module.py(1): print "HERE" > > instead of > > my_module.py(1): print "HERE". I think a full name in the modulename line would be good, but full names in the trace lines would be awful. In fact, I would prefer no name, and, especially when using runfunc, line numbers relative to the function rather than the module. Also remove the silly indent. So I would like --- modulename: compare, funcname: lt_iw compare.py(47): while m != 0 and n != 0: compare.py(48): m, n = m-1, n-1 changed to Modulename: path/compare, funcname: lt_iw 1: while m != 0 and n != 0: 2: m, n = m-1, n-1 > Ultimately, I'd like to be able to look at two runs of a program > and be able to pinpoint the very first difference > between thembased on the output of their trace runs. As it > stands, I really can't do this. When I trace a function mentally, to write or debug, I keep track of the values of the local names. Perhaps trace was not meant for this. However, if I were modifying trace, the first thing I would add would be the ability to print variable values with each line executed. > Of course I could implement the above, but I was > hoping to avoid duplicated effort if someone has > already implemented options like this..I posted the above to > the python-dev list, they suggested I take it here, so any help > would be appreciated. I searched http://pypi.python.org/pypi for 'trace' and did not see anything obvious. If you do modify trace and your changes are not immediately accepted, you could list your version on PyPI. In fact, that might be the best way to get them in. Of course, one problem you can see from the above is that different people will have different ideas on what constitutes 'better' ;-). Terry Jan Reedy From martin at v.loewis.de Thu Jun 25 16:12:46 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 25 Jun 2009 22:12:46 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: Message-ID: <4a43da3e$0$14855$9b622d9e@news.freenet.de> > I've tried various UTF file encoding (also with BOM mark), use of > u"text" Always use u"text". This should work. Everything else might not work. > After applying this, the effect remains the same - one big garbage. Can you please be more specific? What is "one big garbage"? > I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both > support UTF-8, Python also supports it - so where is the problem? Most likely, Tk does not work correctly on your system. See whether you can get correct results with wish. Regards, Martin From martin at v.loewis.de Thu Jun 25 16:16:11 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Thu, 25 Jun 2009 22:16:11 +0200 Subject: print u'\u2013' error on console/terminal In-Reply-To: References: Message-ID: <4a43db0b$0$14855$9b622d9e@news.freenet.de> > is there a switch to suppress those encoding errors for standard print's > on the console No, there is no such switch. > or a new filter file class necessary? You can wrap sys.stdout with a codecs.StreamWriter, passing "replace" as the error handler. Regards, Martin From spconv+m at gmail.com Thu Jun 25 16:52:57 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Thu, 25 Jun 2009 22:52:57 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4a43da3e$0$14855$9b622d9e@news.freenet.de> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> Message-ID: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> 2009/6/25 "Martin v. L?wis" : >> I've tried various UTF file encoding (also with BOM mark), use of >> u"text" > > Always use u"text". This should work. Everything else might not work. But I tried this here without success >> After applying this, the effect remains the same - one big garbage. > > Can you please be more specific? What is "one big garbage"? > There is a square (or some other weird sign) in place where polish accented character should be (like "?????" etc) This problem is only on mac os x and it doesn't apply to button widget (where characters are correct) >> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >> support UTF-8, Python also supports it - so where is the problem? > > Most likely, Tk does not work correctly on your system. See whether > you can get correct results with wish. > There is no wish. I'm talking about build-in Tkinter (isn't Tk build-in Python?). btw. I'm workin on Windows, my friend on Mac - he points me the problem he has with my script. He is not a computer geek nor a programmer - he even doesn't know what wish/Tk or Python is Does different endianness can have something to do here? From norseman at hughes.net Thu Jun 25 17:23:04 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 14:23:04 -0700 Subject: [Gimp-user] Color change a whole range based on a break point Message-ID: <4A43EAB8.6080402@hughes.net> I know I'm not the only one that does archival scanning and georefferencing of old maps. What follows is the combined conversations between myself (norseman at hughes.net and saulgoode at flashingtwelve.brickfilms.com) that lead to getting what is needed for the above process when working with sources that are copies made with the "Sepia" process of old (before Xerox copiers). Namely; a clean raster. For non-sepia source I use GIMP->Colors->Levels and get excellent results with minor effort. 1) original request and reply > > Wanted: > > In Gimp, to add (SUM) the RGB values for a pixel and then > > change all pixels who's RGB SUM is greater than a user stated value > > to WHITE. > > Second side of that is to change all RGB SUMs less than value given to Black. BUT not doing both at same time, thus allowing user to "step" > > in and see what got lost. * Duplicate the layer. * Desaturate the duplicate using the "Average" method. * Add layermask to the duplicate using the "Initialize to: Grayscale Copy of Layer" option. * Bucket fill the duplicate layer with white. * Run "Colors->Threshold" on the layermask, setting the value appropriately. * Bucket fill your original layer with black. 2) starting round 2 Quoting norseman : > I understand the idea. I am not getting any usable results. > > If I cut out a small piece of a project raster and send it to you > would you have the time to try your idea(s) on it? That would be fine. Perhaps I misinterpreted what you are trying to accomplish. 3) closing results As often happens, just as one is ready to quit, the unexpected happens. I went back to your idea of Desaturate and Threshold and tried them without doing the layer/fill parts. (keep original, save as newname the modified) Success! What I have is 45 year old sepias of USGS 7.5 minute Topo Quads with inked lines drawn on the sepia. They have 'faded' and the surface has corroded and some has rubbed off onto the inked lines originally drawn on them. Thus the black lines are tainted with color. The rest of the sepia is like any other old sepia. It is trying to become all one color - very dark sepia. :) What I did was try your idea of Desaturate (I settled on the Lightness setting) and then used Threshold (left or 'black' side set to 50 +/- and right or white side set to 200 to 220) and BINGO! -- I get what I want! The sepia (very nearly 100%) turns white and the inked lines are dark enough for further processing. Final manual touch-up prior to vectorizing will be very minor. Manually doing the major cleanup is less than 60 seconds per sheet. Majority of sheets take less than 30 seconds. Anticipate individual settings and times to vary with source conditions. :) Final product is to be inked lines converted to georefferenced vectors. side note: the 'small sample' I had clipped out was small compared to the original sheet but it was still 25 megabytes AFTER LZW compression! The original sheets are 200 megabytes each in uncompressed RGB Tiff. A totally manual cleanup of originals is definitely an unwanted task. GIMP: 2.6.6 OS : Window$ XP PRO As of writing, I have not tested on Linux but I do expect same results. Sincerely - I do appreciate your help. Steve From nick at craig-wood.com Thu Jun 25 17:30:02 2009 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 25 Jun 2009 16:30:02 -0500 Subject: C-extension 2 times slower than exe References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> <4a4233d0$1@news.fhg.de> Message-ID: Rolf Wester wrote: > Hello, > > thank you all very much for your replies. > > I tried to simplify things and make the two versions as comparable as > possible. I put the C++ part of the program into a shared object > libff.so. For the exe the main function is linked against this shared > object. For the python stuff I made an interface consiting of only one > function call_solver with the same code that has the main function used > for the exe. Then I created a wrapper for this interface using swig and > linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code > just imports _ff and calls call_solver wich creates an object of the > class Solver and calls its member solve (the main function of the exe > does the same). > > I included some code for timing into the C++-code. > > #include > > //beginning of solve > clock_t t0 = clock(); > ... > clock_t t1 = clock(); > //end of solve > cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; > > I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The > sources are compiled using the flags -fPIC -O3. > > Timing: > > 1) time python ff.py > time used = 3.74 > real 0m3.234s > user 0m3.712s > sys 0m0.192s Those times look odd because the user time is > than the real time. User time is number of CPU seconds used. Real time is wallclock time. That must mean a) your program is threading b) there is something up with timing on your computer Looks odd but exactly what it means I don't know! > 2) time ff > time used = 2.19 > real 0m3.170s > user 0m2.088s > sys 0m0.168s -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gagsl-py2 at yahoo.com.ar Thu Jun 25 17:32:49 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Jun 2009 18:32:49 -0300 Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: En Thu, 25 Jun 2009 04:29:28 -0300, Private Private escribi?: > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > Can you suggest anything ? You may try pesto: http://pesto.redgecko.org/ pesto is a very small framework (45k to download!), WSGI compliant, includes session management, mapping URL->function, caching, templates (optional, whichever you like). Minimalist but flexible. Anyway, learning to use Django isn't a bad idea. -- Gabriel Genellina From python at mrabarnett.plus.com Thu Jun 25 17:50:31 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 22:50:31 +0100 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> Message-ID: <4A43F127.5060807@mrabarnett.plus.com> Sebastian Paj?k wrote: > 2009/6/25 "Martin v. L?wis" : >>> I've tried various UTF file encoding (also with BOM mark), use of >>> u"text" >> Always use u"text". This should work. Everything else might not work. > > But I tried this here without success > >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) > >>> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >>> support UTF-8, Python also supports it - so where is the problem? >> Most likely, Tk does not work correctly on your system. See whether >> you can get correct results with wish. >> > > There is no wish. I'm talking about build-in Tkinter (isn't Tk > build-in Python?). > > btw. I'm workin on Windows, my friend on Mac - he points me the > problem he has with my script. He is not a computer geek nor a > programmer - he even doesn't know what wish/Tk or Python is > > > Does different endianness can have something to do here? In summary: You're providing the same text for a Button and a Label. On Mac OSX the Button shows the text correctly, but the Label doesn't. Is this correct? From norseman at hughes.net Thu Jun 25 17:57:08 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 14:57:08 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> Message-ID: <4A43F2B4.30604@hughes.net> Sebastian Paj?k wrote: > 2009/6/25 "Martin v. L?wis" : >>> I've tried various UTF file encoding (also with BOM mark), use of >>> u"text" >> Always use u"text". This should work. Everything else might not work. > > But I tried this here without success > >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) > >>> I'm out of ideas: my script is UTF-8 in 101%; Mac and Windows both >>> support UTF-8, Python also supports it - so where is the problem? >> Most likely, Tk does not work correctly on your system. See whether >> you can get correct results with wish. >> > > There is no wish. I'm talking about build-in Tkinter (isn't Tk > build-in Python?). > > btw. I'm workin on Windows, my friend on Mac - he points me the > problem he has with my script. He is not a computer geek nor a > programmer - he even doesn't know what wish/Tk or Python is > > > Does different endianness can have something to do here? ================ Can, but should not. I read that the problem is when using the Polish language only. Otherwise things work normally. Is that correct? If so then byte swap may be a problem. Using the u'string' should solve that. I am assuming you have the Polish alphabet working correctly on your machine. I think I read that was so in an earlier posting. Are there any problems with his alphabet scrambling on your machine? If so that needs investigating. Here I assume you are reading Polish from him on your machine and not a network translator version. No - Tkinter is not built in. tkinter is a module shipped with Python for people to use. (Tk interface) use: import tkinter From Google: Tkinter Life Preserver Tkinter is a Python interface to the Tk GUI toolkit. This document is not designed to be an exhaustive tutorial on either Tk or Tkinter. ...www.python.org/doc/life-preserver/ more properly Tcl/Tk see also www.tcl.tk Steve From python at mrabarnett.plus.com Thu Jun 25 17:57:20 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 22:57:20 +0100 Subject: Problem with multithreading In-Reply-To: References: Message-ID: <4A43F2C0.3020205@mrabarnett.plus.com> Jeffrey Barish wrote: [snip] > Lou Pecora wrote: > >> Try putting a flush in after the 2nd print statement in case the output >> is left in some I/O buffer when the thing terminates. e.g. >> >> import sys >> >> .... >> >> try: >> print 'in try" >> sys.stdout.flush() >> >> > > I was hoping for some suggestions of things to think about, so thanks > especially to those who had such suggestions. Believe it or not (and I'm > having trouble believing it myself), I didn't think to use flush. When I > did, I found that, indeed, the program did progress past the try statement. > It made it to a call to GStreamer (playbin2), which has been proving itself > intractable in my experience. Note that my test program (which works) > excised GStreamer. The next step will be to try again to compile the > latest version of PyGST as the version in Ubuntu 9.04 is one generation > old. The last time I tried, the compile failed. This is the first time in > days that I have had any hope. On occasion I've needed to debug a program that's crashing, and I've found it best to open the log file unbuffered, otherwise I lose the final log messages. It saves me from having to flush each message explicitly. From spconv+m at gmail.com Thu Jun 25 18:47:54 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 00:47:54 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4A43F2B4.30604@hughes.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> Message-ID: <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> > Can, but should not. > I read that the problem is when using the Polish language only. Otherwise > things work normally. Is that correct? Yes, correct > If so then byte swap may be a problem. ?Using the u'string' should solve > that. I am assuming you have the Polish alphabet working correctly on your > machine. I think I read that was so in an earlier posting. > > Are there any problems with his alphabet scrambling on your machine? > If so that needs investigating. ?Here I assume you are reading Polish from > him on your machine and not a network translator version. > The original thread is here: http://mail.python.org/pipermail/python-list/2009-June/717666.html I've explained the problem there From python at mrabarnett.plus.com Thu Jun 25 18:49:37 2009 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Jun 2009 23:49:37 +0100 Subject: C-extension 2 times slower than exe In-Reply-To: References: <4a40ddee$1@news.fhg.de> <4a40e4b6$1@news.fhg.de> <4a4233d0$1@news.fhg.de> Message-ID: <4A43FF01.5030406@mrabarnett.plus.com> Nick Craig-Wood wrote: > Rolf Wester wrote: >> Hello, >> >> thank you all very much for your replies. >> >> I tried to simplify things and make the two versions as comparable as >> possible. I put the C++ part of the program into a shared object >> libff.so. For the exe the main function is linked against this shared >> object. For the python stuff I made an interface consiting of only one >> function call_solver with the same code that has the main function used >> for the exe. Then I created a wrapper for this interface using swig and >> linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code >> just imports _ff and calls call_solver wich creates an object of the >> class Solver and calls its member solve (the main function of the exe >> does the same). >> >> I included some code for timing into the C++-code. >> >> #include >> >> //beginning of solve >> clock_t t0 = clock(); >> ... >> clock_t t1 = clock(); >> //end of solve >> cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl; >> >> I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The >> sources are compiled using the flags -fPIC -O3. >> >> Timing: >> >> 1) time python ff.py >> time used = 3.74 >> real 0m3.234s >> user 0m3.712s >> sys 0m0.192s > > Those times look odd because the user time is > than the real time. > > User time is number of CPU seconds used. Real time is wallclock time. > > That must mean > a) your program is threading > b) there is something up with timing on your computer > > Looks odd but exactly what it means I don't know! > >> 2) time ff >> time used = 2.19 >> real 0m3.170s >> user 0m2.088s >> sys 0m0.168s > Perhaps multithreading on dual cores? From Scott.Daniels at Acm.Org Thu Jun 25 19:43:33 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 25 Jun 2009 16:43:33 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: Robert Kern wrote: > ... I wish people would stop representing decimal floating point arithmetic > as "more accurate" than binary floating point arithmetic. It isn't. > Decimal floating point arithmetic does have an extremely useful niche: > ... Well, we don't actually have an arbitrary-precision, huge exponent version of binary floating point. In that sense the Decimal floating point beats it. Not that it would be too hard to have such a floating point in Python (long for mantissa, int for exponent, ...), but we don't in fact have such a module in place. --Scott David Daniels Scott.Daniels at Acm.Org From robert.kern at gmail.com Thu Jun 25 19:50:21 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 18:50:21 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 18:43, Scott David Daniels wrote: > Robert Kern wrote: >> ... I wish people would stop representing decimal floating point >> arithmetic as "more accurate" than binary floating point arithmetic. >> It isn't. Decimal floating point arithmetic does have an extremely >> useful niche: ... > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. You may not. I do. http://code.google.com/p/mpmath/ -- 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 Thu Jun 25 19:53:04 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 16:53:04 -0700 Subject: Meta question: disappearing posts (was Re: calculating aself.value, self.randomnum = normalvariate(x, y)) References: <77e831100906192220y5536d9d2oe5ca2dcc59084c0c@mail.gmail.com> Message-ID: In article , Hendrik van Rooyen wrote: > >I have lately had some posts returned with a "seems to be forged" message. >Two reasons for that: >- first is if I use the smtp server from our local telco - saix - then there is > no apparent relationship between where the message comes from and > where it comes from, if you follow my Irish... >- Second is if the same telco assigns me an IP that has been put on a list > of bad boy IPs. > >So it is kind of pot luck if you see this message or not. Sorry, didn't see it. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From mensanator at aol.com Thu Jun 25 19:53:39 2009 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Jun 2009 16:53:39 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: <4f0bb9cf-f2ca-4b1d-a803-0d77661a9899@p23g2000vbl.googlegroups.com> On Jun 25, 6:43?pm, Scott David Daniels wrote: > Robert Kern wrote: > > ... I wish people would stop representing decimal floating point arithmetic > > as "more accurate" than binary floating point arithmetic. It isn't. > > Decimal floating point arithmetic does have an extremely useful niche: > > ... > > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. ?In that sense the Decimal floating > point beats it. ?Not that it would be too hard to have such a floating > point in Python (long for mantissa, int for exponent, ...), but we don't > in fact have such a module in place. We have the gmpy module which can do arbitray precision floats. >>> gmpy.pi(600) mpf ('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446e0', 600) > > --Scott David Daniels > Scott.Dani... at Acm.Org From aahz at pythoncraft.com Thu Jun 25 19:55:40 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 16:55:40 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: In article , Scott David Daniels wrote: > >Well, we don't actually have an arbitrary-precision, huge exponent >version of binary floating point. gmpy? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From robert.kern at gmail.com Thu Jun 25 20:07:37 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Jun 2009 19:07:37 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-25 18:43, Scott David Daniels wrote: > Robert Kern wrote: >> ... I wish people would stop representing decimal floating point >> arithmetic as "more accurate" than binary floating point arithmetic. >> It isn't. Decimal floating point arithmetic does have an extremely >> useful niche: ... > Well, we don't actually have an arbitrary-precision, huge exponent > version of binary floating point. In that sense the Decimal floating > point beats it. And while that's true, to a point, that isn't what Michael or the many others are referring to when they claim that decimal is more accurate (without any qualifiers). They are misunderstanding the causes and limitations of the example "3.2 * 3 == 9.6". You can see a great example of this in the comparison between new Cobra language and Python: http://cobra-language.com/docs/python/ In that case, they have a fixed-precision decimal float from the underlying .NET runtime but still making the claim that it is more accurate arithmetic. While you may make (completely correct) claims that decimal.Decimal can be more accurate because of its arbitrary precision capabilities, this is not the claim others are making or the one I am arguing against. -- 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 norseman at hughes.net Thu Jun 25 20:09:15 2009 From: norseman at hughes.net (norseman) Date: Thu, 25 Jun 2009 17:09:15 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> Message-ID: <4A4411AB.1090302@hughes.net> Sebastian Paj?k wrote: >> Can, but should not. >> I read that the problem is when using the Polish language only. Otherwise >> things work normally. Is that correct? > > Yes, correct > >> If so then byte swap may be a problem. Using the u'string' should solve >> that. I am assuming you have the Polish alphabet working correctly on your >> machine. I think I read that was so in an earlier posting. >> >> Are there any problems with his alphabet scrambling on your machine? >> If so that needs investigating. Here I assume you are reading Polish from >> him on your machine and not a network translator version. >> > > The original thread is here: > http://mail.python.org/pipermail/python-list/2009-June/717666.html > I've explained the problem there ================ I re-read the posting. (Thanks for the link) You do not mention if he has sent you any Polish words and if they appear OK on your machine. A note here: In reading the original posting I get symbols that are not familiar to me as alphabet. From the line in your original: Label(root, text='?????????').pack() I see text=' then an e with a goatee a capitol O with an accent symbol on top (') an a with a tail on the right a s with an accent on top an I do no not know what - maybe some sort of l with a slash through the middle a couple of z with accents on top a capitol C with an accent on top a n with a short bar on top I put the code into python and took a look. I get: cat xx # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() Button(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() Entry(root).pack() root.mainloop() Then: python xx File "xx", line 10 SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details So I did. It notes Window$ puts things into those lines. Namely: "To aid with platforms such as Windows, which add Unicode BOM marks to the beginning of Unicode files, the UTF-8 signature '\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well (even if no magic encoding comment is given). " Then I took out the o with the accent and re-ran the file. Everything works except the text is exactly as shown above. That is: \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 (shows twice as directed, one for label, one for button, no apostrophes) OK - now I take a look at what in actually in the file. in MC on Linux Slackware 10.2 I read, in the mail folder, 0119 capitol A with a tilde on top. HEX readings beginning at the 0119\... 30 31 31 39 C3 B3 5C but in the python file xx, I read: 30 31 31 39 5C 0119\... I would have to say the mail system is screwing you up. Might try zipping the file and sending it that way and see if problem changes. Steve From martin at v.loewis.de Thu Jun 25 21:01:35 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Fri, 26 Jun 2009 03:01:35 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> Message-ID: <4a441def$0$12249$9b622d9e@news.freenet.de> >>> After applying this, the effect remains the same - one big garbage. >> Can you please be more specific? What is "one big garbage"? >> > > There is a square (or some other weird sign) ***PLEASE*** be specific. A square box is something *completely* different than any other weird sign. It is impossible to understand the problem if you don't know *exactly* what happens. in place where polish > accented character should be (like "?????" etc) > This problem is only on mac os x and it doesn't apply to button widget > (where characters are correct) I see. So it is a font problem: if the square box is displayed, it means that the font just doesn't have a glyph for the character you want to display. Try using a different font in the label widget. > There is no wish. I'm talking about build-in Tkinter So try installing Tk separately. > (isn't Tk build-in Python?). Depends on where exactly you got your Python from, and what exactly is your OSX version. Recent releases of OSX include a copy of Tcl/Tk, and some sets of Python binaries link against the Apple Tk. Regards, Martin From kee at kagi.com Thu Jun 25 21:02:25 2009 From: kee at kagi.com (Kee Nethery) Date: Thu, 25 Jun 2009 18:02:25 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working Message-ID: <87338909-96C7-489A-9B85-CB6F7FE8DA18@kagi.com> Summary: I have XML as string and I want to pull it into ElementTree so that I can play with it but it is not working for me. XML and fromstring when used with a string do not do the same thing as parse does with a file. How do I get this to work? Details: I have a CGI that receives XML via an HTTP POST as a POST variable named 'theXml'. The POST data is a string that the CGI receives, it is not a file on a hard disk. The POSTed string looks like this when viewed in pretty format: Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts jumbo at shrimp.edu The pseudocode in Python 2.6.2 looks like: import xml.etree.ElementTree as et formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et.XML(theXmlData) and when this runs, theXmlDataTree is set to: theXmlDataTree instance attrib dict {} tag str xml tail NoneType None text NoneType None I get the same result with fromstring: formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et.fromstring(theXmlData) I can put the xml in a file and reference the file by it's URL and use: et.parse(urllib.urlopen(theUrl)) and that will set theXmlDataTree to: theXmlDataTree instance This result I can play with. It contains all the XML. et.parse seems to pull in the entire XML document and give me something to play with whereas et.XML and et.fromstring do not. Questions: How do I get this to work? Where in the docs did it give me an example of how to make this work (what did I miss from reading the docs)? ... and for bonus points ... Why isn't et.parse the only way to do this? Why have XML or fromstring at all? Why not enhance parse and deprecate XML and fromstring with something like: formPostData = cgi.FieldStorage() theXmlData = formPostData['theXml'].value theXmlDataTree = et .parse (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) Thanks in advance, Kee Nethery From python at mrabarnett.plus.com Thu Jun 25 22:08:27 2009 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Jun 2009 03:08:27 +0100 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906251539vac5c017l613603a5fbc0bb36@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F127.5060807@mrabarnett.plus.com> <111013c20906251539vac5c017l613603a5fbc0bb36@mail.gmail.com> Message-ID: <4A442D9B.9090009@mrabarnett.plus.com> Sebastian Paj?k wrote: >> You're providing the same text for a Button and a Label. On Mac OSX the >> Button shows the text correctly, but the Label doesn't. >> >> Is this correct? > > Yes this is correct. My first mail is here: > http://mail.python.org/pipermail/python-list/2009-June/717666.html > My only other thought is that the widgets might be using different fonts, although in your example you're not specifying the fonts, so I assume they'll default to the same one. You could try specifying their fonts explicitly, just in case, although I'm expecting that it won't make a difference... From nobody at nowhere.com Thu Jun 25 22:38:14 2009 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Jun 2009 03:38:14 +0100 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: On Thu, 25 Jun 2009 18:02:25 -0700, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree > so that I can play with it but it is not working for me. XML and > fromstring when used with a string do not do the same thing as parse > does with a file. How do I get this to work? Why do you need an ElementTree rather than an Element? XML(string) returns the root element, as if you had used et.parse(f).getroot(). You can turn this into an ElementTree with e.g. et.ElementTree(XML(string)). > Why isn't et.parse the only way to do this? Why have XML or fromstring > at all? Why not enhance parse and deprecate XML and fromstring with > something like: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = > et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) If you want to treat a string as a file, use StringIO. From unayok at gmail.com Thu Jun 25 22:47:36 2009 From: unayok at gmail.com (unayok) Date: Thu, 25 Jun 2009 19:47:36 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: <0eab2287-62b0-42e4-a864-e2316b82dee8@f30g2000vbf.googlegroups.com> On Jun 25, 9:02 pm, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree > so that I can play with it but it is not working for me. XML and > fromstring when used with a string do not do the same thing as parse > does with a file. How do I get this to work? > > Details: > I have a CGI that receives XML via an HTTP POST as a POST variable > named 'theXml'. The POST data is a string that the CGI receives, it is > not a file on a hard disk. > > The POSTed string looks like this when viewed in pretty format: [...] > et.parse seems to pull in the entire XML document and give me > something to play with whereas et.XML and et.fromstring do not. > > Questions: > How do I get this to work? > Where in the docs did it give me an example of how to make this work > (what did I miss from reading the docs)? > [skipping bonus points question] I'm not sure what you're expecting. It looks to me like things are working okay: My test script: import xml.etree.ElementTree as ET data=""" Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts ju... at shrimp.edu """ xml = ET.fromstring( data ) print xml print "attrib ", xml.attrib print "tag ", xml.tag print "text ", xml.text print "contents " for element in xml : print element print "tostring" print ET.tostring( xml ) when run, produces: attrib {} tag xml text contents tostring Autumn 1 8.46 YES 19 Any Street Berkeley California 12345 People's Republic of Berkeley Jon Roberts ju... at shrimp.edu Which seems to me quite useful (i.e. it has the full XML available). Maybe you can explain how you were trying to "play with" the results of fromstring() that you can't do from parse(). The documentation for elementtree indicates: > The ElementTree wrapper type adds code to load XML files as trees > of Element objects, and save them back again. and > The Element type can be used to represent XML files in memory. > The ElementTree wrapper class is used to read and write XML files. In the above case, you should find that the getroot() of your loaded ElementTree instance ( parse().getroot() ) to be the same as the Element generated by fromstring(). From pavlovevidence at gmail.com Thu Jun 25 23:04:08 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 20:04:08 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: Message-ID: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> On Jun 25, 6:02?pm, Kee Nethery wrote: > Summary: I have XML as string and I want to pull it into ElementTree ? > so that I can play with it but it is not working for me. XML and ? > fromstring when used with a string do not do the same thing as parse ? > does with a file. How do I get this to work? > > Details: > I have a CGI that receives XML via an HTTP POST as a POST variable ? > named 'theXml'. The POST data is a string that the CGI receives, it is ? > not a file on a hard disk. > > The POSTed string looks like this when viewed in pretty format: > > > ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? Autumn > ? ? ? ? ? ? ? ? ? ? ? ? 1 > ? ? ? ? ? ? ? ? ? ? ? ? 8.46 > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? YES > ? ? ? ? > ? ? ? ? > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? 19 Any Street > ? ? ? ? ? ? ? ? ? ? ? ? Berkeley > ? ? ? ? ? ? ? ? ? ? ? ? California > ? ? ? ? ? ? ? ? ? ? ? ? 12345 > ? ? ? ? ? ? ? ? ? ? ? ? People's Republic of Berkeley > ? ? ? ? ? ? ? ? ? ? ? ? Jon Roberts > ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ju... at shrimp.edu > ? ? ? ? > > > The pseudocode in Python 2.6.2 looks like: > > import xml.etree.ElementTree as et > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.XML(theXmlData) > > and when this runs, theXmlDataTree is set to: > > theXmlDataTree ?instance ? ? ? ? > ? ? ? ? attrib ?dict ? ?{} > ? ? ? ? tag ? ? str ? ? xml > ? ? ? ? tail ? ?NoneType ? ? ? ?None > ? ? ? ? text ? ?NoneType ? ? ? ?None > > I get the same result with fromstring: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.fromstring(theXmlData) > > I can put the xml in a file and reference the file by it's URL and use: > > et.parse(urllib.urlopen(theUrl)) > > and that will set theXmlDataTree to: > > theXmlDataTree ?instance ? ? ? ? 0x67cb48> > > This result I can play with. It contains all the XML. I believe you are misunderstanding something. et.XML and et.fromstring return Elements, whereas et.parse returns an ElementTree. These are two different things; however, both of them "contain all the XML". In fact, an ElementTree (which is returned by et.parse) is just a container for the root Element (returned by et.fromstring)--and it adds no important functionality to the root Element as far as I can tell. Given an Element (as returned by et.XML or et.fromstring) you can pass it to the ElementTree constructor to get an ElementTree instance. The following line should give you something you can "play with": theXmlDataTree = et.ElementTree(et.fromstring(theXmlData)) Conversely, given an ElementTree (as returned bu et.parse) you can call the getroot method to obtain the root Element, like so: theXmlRootElement = et.parse(xmlfile).getroot() I have no use for ElementTree instances so I always call getroot right away and only store the root element. You may prefer to work with ElementTrees rather than with Elements directly, and that's perfectly fine; just use the technique above to wrap up the root Element if you use et.fromstring. [snip] > Why isn't et.parse the only way to do this? Why have XML or fromstring ? > at all? Because Fredrick Lundh wanted it that way. Unlike most Python libraries ElementTree is under the control of one person, which means it was not designed or vetted by the community, which means it would tend to have some interface quirks. You shouldn't complain: the library is superb compared to XML solutions like DOM. A few minor things should be no big deal. Carl Banks From kee at kagi.com Thu Jun 25 23:53:57 2009 From: kee at kagi.com (Kee Nethery) Date: Thu, 25 Jun 2009 20:53:57 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <839382F7-B326-45F2-B2C3-506B14FFE0B0@kagi.com> thank you to everyone, I'll play with these suggestions tomorrow at work and report back. On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > Because Fredrick Lundh wanted it that way. Unlike most Python > libraries ElementTree is under the control of one person, which means > it was not designed or vetted by the community, which means it would > tend to have some interface quirks. Yep > You shouldn't complain: the > library is superb compared to XML solutions like DOM. Which is why I want to use it. > A few minor > things should be no big deal. True and I will eventually get past the minor quirks. As a newbie, figured I'd point out the difficult portions, things that conceptually are confusing. I know that after lots of use I'm not going to notice that it is strange that I have to stand on my head and touch my nose 3 times to open the fridge door. The contortions will seem normal. Results tomorrow, thanks everyone for the assistance. Kee Nethery From timr at probo.com Fri Jun 26 00:31:42 2009 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Jun 2009 21:31:42 -0700 Subject: Why is it that str.replace doesn't work sometimes? References: <8d3c81ee-b38c-496e-9f60-2131e50baa4d@l28g2000vba.googlegroups.com> <4b82131f-f94b-49d3-ae21-5d4c6a4ab455@r34g2000vba.googlegroups.com> Message-ID: humn wrote: > >Thank you! Didn't know that it would escape characters with single >quotes. I thought it only did that with double quotes. That's only true in Perl and PHP, but not in Python or C. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Scott.Daniels at Acm.Org Fri Jun 26 00:32:28 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 25 Jun 2009 21:32:28 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> Message-ID: <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> norseman wrote: > ... A note here: In reading the original posting I get symbols that are not > familiar to me as alphabet. > From the line in your original: > Label(root, text='?????????').pack() > I see text=' > then an e with a goatee > a capitol O with an accent symbol on top (') > an a with a tail on the right > a s with an accent on top > an I do no not know what - maybe some sort of l with a > slash through the middle > a couple of z with accents on top > a capitol C with an accent on top > a n with a short bar on top Here's something to try in any future circumstances: Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import unicodedata as ud >>> for ch in '?????????': print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch))) 281 119 ? LATIN SMALL LETTER E WITH OGONEK 243 f3 ? LATIN SMALL LETTER O WITH ACUTE 261 105 ? LATIN SMALL LETTER A WITH OGONEK 347 15b ? LATIN SMALL LETTER S WITH ACUTE 322 142 ? LATIN SMALL LETTER L WITH STROKE 380 17c ? LATIN SMALL LETTER Z WITH DOT ABOVE 378 17a ? LATIN SMALL LETTER Z WITH ACUTE 263 107 ? LATIN SMALL LETTER C WITH ACUTE 324 144 ? LATIN SMALL LETTER N WITH ACUTE --Scott David Daniels Scott.Daniels at Acm.Org From pavlovevidence at gmail.com Fri Jun 26 00:38:39 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 21:38:39 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <19c53184-96d2-4ae8-aa2d-41ec9a71a218@e20g2000vbc.googlegroups.com> On Jun 25, 8:53?pm, Kee Nethery wrote: > On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > > A few minor > > things should be no big deal. > > True and I will eventually get past the minor quirks. As a newbie, ? > figured I'd point out the difficult portions, things that conceptually ? > are confusing. I know that after lots of use I'm not going to notice ? > that it is strange that I have to stand on my head and touch my nose 3 ? > times to open the fridge door. The contortions will seem normal. Well it's not *that* bad. (That would be PIL. :) Carl Banks From msrachel.e at gmail.com Fri Jun 26 00:47:51 2009 From: msrachel.e at gmail.com (Rachel P) Date: Thu, 25 Jun 2009 21:47:51 -0700 (PDT) Subject: I need a dict that inherits its mappings References: Message-ID: <8298a601-185b-4e50-b1c6-dea47ae51732@a5g2000pre.googlegroups.com> On Jun 25, 5:31?am, samwyse wrote: > I need a dict-like object that, if it doesn't contain a key, will > return the value from a "parent" object. ? See: http://code.activestate.com/recipes/305268/ Also try subclassing dict and implementing a __missing__() method. Raymond From stefan_ml at behnel.de Fri Jun 26 01:11:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 07:11:33 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> Message-ID: <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> Carl Banks wrote: >> Why isn't et.parse the only way to do this? Why have XML or fromstring >> at all? > > Because Fredrick Lundh wanted it that way. Unlike most Python > libraries ElementTree is under the control of one person, which means > it was not designed or vetted by the community, which means it would > tend to have some interface quirks. Just for the record: Fredrik doesn't actually consider it a design "quirk". He argues that it's designed for different use cases. While parse() parses a file, which normally contains a complete document (represented in ET as an ElementTree object), fromstring() and especially the 'literal wrapper' XML() are made for parsing strings, which (most?) often only contain XML fragments. With a fragment, you normally want to continue doing things like inserting it into another tree, so you need the top-level element in almost all cases. Stefan From tomreed05 at gmail.com Fri Jun 26 01:29:30 2009 From: tomreed05 at gmail.com (Tom Reed) Date: Fri, 26 Jun 2009 06:29:30 +0100 Subject: No trees in the stdlib? Message-ID: <4A445CBA.9080602@gmail.com> Why no trees in the standard library, if not as a built in? I searched the archive but couldn't find a relevant discussion. Seems like a glaring omission considering the batteries included philosophy, particularly balanced binary search trees. No interest, no good implementations, something other reason? Seems like a good fit for the collections module. Can anyone shed some light? Thanks. -- Tom From aahz at pythoncraft.com Fri Jun 26 01:32:13 2009 From: aahz at pythoncraft.com (Aahz) Date: 25 Jun 2009 22:32:13 -0700 Subject: No trees in the stdlib? References: Message-ID: In article , Tom Reed wrote: > >Why no trees in the standard library, if not as a built in? I searched >the archive but couldn't find a relevant discussion. Seems like a >glaring omission considering the batteries included philosophy, >particularly balanced binary search trees. No interest, no good >implementations, something other reason? Seems like a good fit for the >collections module. Can anyone shed some light? What do you want such a tree for? Why are dicts and the bisect module inadequate? Note that there are plenty of different tree implementations available from either PyPI or the Cookbook. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From pavlovevidence at gmail.com Fri Jun 26 01:46:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 25 Jun 2009 22:46:33 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> On Jun 25, 10:11?pm, Stefan Behnel wrote: > Carl Banks wrote: > >> Why isn't et.parse the only way to do this? Why have XML or fromstring ? > >> at all? > > > Because Fredrick Lundh wanted it that way. ?Unlike most Python > > libraries ElementTree is under the control of one person, which means > > it was not designed or vetted by the community, which means it would > > tend to have some interface quirks. > > Just for the record: Fredrik doesn't actually consider it a design "quirk". Well of course he wouldn't--it's his library. > He argues that it's designed for different use cases. While parse() parses > a file, which normally contains a complete document (represented in ET as > an ElementTree object), fromstring() and especially the 'literal wrapper' > XML() are made for parsing strings, which (most?) often only contain XML > fragments. With a fragment, you normally want to continue doing things like > inserting it into another tree, so you need the top-level element in almost > all cases. Whatever, like I said I am not going to nit-pick over small things, when all the big things are done right. Carl Banks From backup95 at netcabo.pt Fri Jun 26 01:55:50 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 06:55:50 +0100 Subject: No trees in the stdlib? In-Reply-To: References: Message-ID: <4A4462E6.7080700@netcabo.pt> Aahz wrote: > In article , > Tom Reed wrote: > >> Why no trees in the standard library, if not as a built in? I searched >> the archive but couldn't find a relevant discussion. Seems like a >> glaring omission considering the batteries included philosophy, >> particularly balanced binary search trees. No interest, no good >> implementations, something other reason? Seems like a good fit for the >> collections module. Can anyone shed some light? >> > > What do you want such a tree for? Why are dicts and the bisect module > inadequate? Note that there are plenty of different tree implementations > available from either PyPI or the Cookbook. > A hash table is very different to a BST. They are both useful. The bisect module I'm not familiar with, I'll have to look into that, thanks. I have found pyavl on the web, it does the job ok, but there no implementations for python3 that I know of. Simple example usage case: Insert string into data structure in sorted order if it doesn't exist, else retrieve it. From backup95 at netcabo.pt Fri Jun 26 02:05:18 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 07:05:18 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A44651E.40306@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > > Simple example usage case: Insert string into data structure in sorted > order if it doesn't exist, else retrieve it. > Crap, sorry about the mixed identities, I'm not using my own machine. The original post is mine also. From stefan_ml at behnel.de Fri Jun 26 02:20:15 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:20:15 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> Message-ID: <4a4468a0$0$32680$9b4e6d93@newsspool2.arcor-online.net> Carl Banks wrote: > On Jun 25, 10:11 pm, Stefan Behnel wrote: >> Carl Banks wrote: >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring >>>> at all? >>> Because Fredrick Lundh wanted it that way. Unlike most Python >>> libraries ElementTree is under the control of one person, which means >>> it was not designed or vetted by the community, which means it would >>> tend to have some interface quirks. >> Just for the record: Fredrik doesn't actually consider it a design "quirk". > > Well of course he wouldn't--it's his library. That's not an argument at all. Fredrik put out a alpha of ET 1.3 (long ago, actually), which is (or was?) meant as a clean-up release for a number of real quirks in the library (lxml also fixes most of them since 2.0). The above definitely hasn't changed, simply because it's not considered 'wrong' by the author(s). Stefan From backup95 at netcabo.pt Fri Jun 26 02:21:05 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 07:21:05 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A4468D1.700@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. The main problem with pyavl by the way is that it doesn't seem to be subclassable (?). Besides some interface glitches, like returning None on delete if I recall correctly. There's also rbtree, which I didn't try. And I think that's it. On the whole not a lot of choice and not as practical for such a common data structure. From clp2 at rebertia.com Fri Jun 26 02:23:41 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Jun 2009 23:23:41 -0700 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> On Thu, Jun 25, 2009 at 10:55 PM, Jo?o Valverde wrote: > Aahz wrote: >> >> In article , >> Tom Reed ? wrote: >> >>> >>> Why no trees in the standard library, if not as a built in? I searched >>> the archive but couldn't find a relevant discussion. Seems like a glaring >>> omission considering the batteries included philosophy, particularly >>> balanced binary search trees. No interest, no good implementations, >>> something other reason? Seems like a good fit for the collections module. >>> Can anyone shed some light? >>> >> >> What do you want such a tree for? ?Why are dicts and the bisect module >> inadequate? ?Note that there are plenty of different tree implementations >> available from either PyPI or the Cookbook. >> > > A hash table is very different to a BST. ?They are both useful. The bisect > module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > Simple example usage case: Insert string into data structure in sorted order > if it doesn't exist, else retrieve it. That's pretty much the bisect module in a nutshell. It manipulates a sorted list using binary search. Cheers, Chris -- http://blog.rebertia.com From stefan_ml at behnel.de Fri Jun 26 02:39:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:39:33 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: <4a446d25$0$32682$9b4e6d93@newsspool2.arcor-online.net> Hi, Kee Nethery wrote: > Why isn't et.parse the only way to do this? Why have XML or fromstring > at all? Well, use cases. XML() is an alias for fromstring(), because it's convenient (and well readable) to write section = XML('
A to Z
') section.append(paragraphs) for XML literals in source code. fromstring() is there because when you want to parse a fragment from a string that you got from whatever source, it's easy to express that with exactly that function, as in el = fromstring(some_string) If you want to parse a document from a file or file-like object, use parse(). Three use cases, three functions. The fourth use case of parsing a document from a string does not have its own function, because it is trivial to write tree = parse(BytesIO(some_byte_string)) I do not argue that fromstring() should necessarily return an Element, as parsing fragments is more likely for literals than for strings that come from somewhere else. However, given that the use case of parsing a document from a string is so easily handled with parse(), I find it ok to give the second use case its own function, simply because tree = fromstring(some_string) fragment_top_element = tree.getroot() absolutely does not catch it. > Why not enhance parse and deprecate XML and fromstring with > something like: > > formPostData = cgi.FieldStorage() > theXmlData = formPostData['theXml'].value > theXmlDataTree = et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) This will not work because ET cannot parse from unicode strings (unless they only contain plain ASCII characters and you happen to be using Python 2.x). lxml can parse from unicode strings, but it requires that the XML must not have an encoding declaration (which would render it non well-formed). This is convenient for parsing HTML, it's less convenient for XML usually. If what you meant is actually parsing from a byte string, this is easily done using BytesIO(), or StringIO() in Py2.x (x<6). Stefan From stefan_ml at behnel.de Fri Jun 26 02:48:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 08:48:52 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Jo?o Valverde wrote: > Besides some interface glitches, like returning None > on delete if I recall correctly. That's actually not /that/ uncommon. Operations that change an object are not (side-effect free) functions, so it's just purity if they do not have a return value. Although practicality beats purity, sometimes... ;) Stefan From milesck at umich.edu Fri Jun 26 02:54:45 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Fri, 26 Jun 2009 02:54:45 -0400 Subject: No trees in the stdlib? In-Reply-To: <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> References: <4A4462E6.7080700@netcabo.pt> <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> Message-ID: On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote: > On Thu, Jun 25, 2009 at 10:55 PM, Jo?o Valverde > wrote: >> Aahz wrote: >>> >>> In article , >>> Tom Reed wrote: >>> >>>> >>>> Why no trees in the standard library, if not as a built in? I >>>> searched >>>> the archive but couldn't find a relevant discussion. Seems like a >>>> glaring >>>> omission considering the batteries included philosophy, >>>> particularly >>>> balanced binary search trees. No interest, no good implementations, >>>> something other reason? Seems like a good fit for the collections >>>> module. >>>> Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? Why are dicts and the bisect >>> module >>> inadequate? Note that there are plenty of different tree >>> implementations >>> available from either PyPI or the Cookbook. >>> >> >> Simple example usage case: Insert string into data structure in >> sorted order >> if it doesn't exist, else retrieve it. > > That's pretty much the bisect module in a nutshell. It manipulates a > sorted list using binary search. With O(n) insertions and removals, though. A decent self-balancing binary tree will generally do those in O(log n). -Miles From jason.scheirer at gmail.com Fri Jun 26 03:09:06 2009 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Fri, 26 Jun 2009 00:09:06 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> On Jun 25, 10:32?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Tom Reed ? wrote: > > > > >Why no trees in the standard library, if not as a built in? I searched > >the archive but couldn't find a relevant discussion. Seems like a > >glaring omission considering the batteries included philosophy, > >particularly balanced binary search trees. No interest, no good > >implementations, something other reason? Seems like a good fit for the > >collections module. Can anyone shed some light? > > What do you want such a tree for? ?Why are dicts and the bisect module > inadequate? ?Note that there are plenty of different tree implementations > available from either PyPI or the Cookbook. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha ...And heapq is more-or-less an emulation of a tree structure in its underlying model. I once wrote a binary sorted tree data structure for Python in C. It performed anywhere from 15-40% worse than dicts. I think with optimization it will only perform 10% worse than dicts at best. Oh hey maybe that is why trees aren't an emphasized part of the standard. They are going to be much slower than the ultra-optimized dicts already in the standard lib. From backup95 at netcabo.pt Fri Jun 26 03:09:36 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:09:36 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A4462E6.7080700@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> Message-ID: <4A447430.1060201@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> Tom Reed wrote: >> >>> Why no trees in the standard library, if not as a built in? I >>> searched the archive but couldn't find a relevant discussion. Seems >>> like a glaring omission considering the batteries included >>> philosophy, particularly balanced binary search trees. No interest, >>> no good implementations, something other reason? Seems like a good >>> fit for the collections module. Can anyone shed some light? >>> >> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree >> implementations >> available from either PyPI or the Cookbook. >> > A hash table is very different to a BST. They are both useful. The > bisect module I'm not familiar with, I'll have to look into that, thanks. > > I have found pyavl on the web, it does the job ok, but there no > implementations for python3 that I know of. > > Simple example usage case: Insert string into data structure in sorted > order if it doesn't exist, else retrieve it. > After browsing the bisect module I don't think it is the complete answer. Please correct me if I'm mistaken but... Ignoring for a moment that subjectively I feel this is not very pythonic for my use case, if I get back the insertion position, doesn't that mean I have to go over on average N/2 items on a linked list to insert the item in position? Maybe less for sophisticated implementations but still O(n)? That doesn't compare favorably to the cost of (possibly) having to rebalance a tree on insertion. From eckhardt at satorlaser.com Fri Jun 26 03:17:02 2009 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 26 Jun 2009 09:17:02 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <4A43C4C9.1020601@gmail.com> Message-ID: Robert Kern wrote: > I wish people would stop representing decimal floating point arithmetic as > "more accurate" than binary floating point arithmetic. Those that failed, learned. You only see those that haven't learnt yet. Dialog between two teachers: T1: Oh those pupils, I told them hundred times! when will they learn? T2: They did, but there's always new pupils. TGIF Uli (wave and smile) -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From kushal.kumaran+python at gmail.com Fri Jun 26 03:47:37 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Jun 2009 13:17:37 +0530 Subject: fileinput.input, readlines and ... In-Reply-To: References: <43bb6274-fca0-42d9-9da3-c803f24d5993@j19g2000vbp.googlegroups.com> Message-ID: <1e364c4e0906260047s1a65763cqaf561646f05f5596@mail.gmail.com> On Thu, Jun 25, 2009 at 10:32 AM, Private Private wrote: > On Jun 24, 12:23?pm, Przemyslaw Bak wrote: >> Hello, >> >> I many files with log data. The structure of the file is quite > > Each requested value is in separated file. > While traversing using os.path.walk I have noticed that I get files > unsorted. > Is it possible to get them sorted ? > You can use the os.walk generator and sort the filenames in the returned tuple. -- regards, kushal From backup95 at netcabo.pt Fri Jun 26 03:48:49 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:48:49 +0100 Subject: No trees in the stdlib? In-Reply-To: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> Message-ID: <4A447D61.2090904@netcabo.pt> Jason Scheirer wrote: > On Jun 25, 10:32 pm, a... at pythoncraft.com (Aahz) wrote: > >> In article , >> Tom Reed wrote: >> >> >> >> >>> Why no trees in the standard library, if not as a built in? I searched >>> the archive but couldn't find a relevant discussion. Seems like a >>> glaring omission considering the batteries included philosophy, >>> particularly balanced binary search trees. No interest, no good >>> implementations, something other reason? Seems like a good fit for the >>> collections module. Can anyone shed some light? >>> >> What do you want such a tree for? Why are dicts and the bisect module >> inadequate? Note that there are plenty of different tree implementations >> available from either PyPI or the Cookbook. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> "as long as we like the same operating system, things are cool." --piranha >> > > ...And heapq is more-or-less an emulation of a tree structure in its > underlying model. I once wrote a binary sorted tree data structure for > Python in C. It performed anywhere from 15-40% worse than dicts. I > think with optimization it will only perform 10% worse than dicts at > best. > > Oh hey maybe that is why trees aren't an emphasized part of the > standard. They are going to be much slower than the ultra-optimized > dicts already in the standard lib. > But a dict can't be used to implement a (sorted) table ADT. From backup95 at netcabo.pt Fri Jun 26 03:49:45 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:49:45 +0100 Subject: No trees in the stdlib? In-Reply-To: <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4A447D99.70809@netcabo.pt> Stefan Behnel wrote: > Jo?o Valverde wrote: > >> Besides some interface glitches, like returning None >> on delete if I recall correctly. >> > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. > > Although practicality beats purity, sometimes... ;) > > Stefan > I didn't know that. But in this case I think purity gets pummeled every time :) It's still not making sense to force a lookup to fetch something before deleting (another lookup operation). If that were imposed by python's internal machinery I'd suggest fixing that instead. From aljosa.mohorovic at gmail.com Fri Jun 26 03:54:31 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 26 Jun 2009 00:54:31 -0700 (PDT) Subject: naming packages for pypi Message-ID: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> is it possible to have 2 packages with same name registered at pypi? are packages unique per name or also per category or something else? if package is unique per name how do you name you packages? do you name them something like -myapp, -myapp, -myapp, ... if this is current situation is this something that you learned to live with and there are no indications that this will eventually change? Aljosa Mohorovic From backup95 at netcabo.pt Fri Jun 26 03:58:29 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 08:58:29 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A447D99.70809@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <4A447D99.70809@netcabo.pt> Message-ID: <4A447FA5.4050602@netcabo.pt> Jo?o Valverde wrote: > Stefan Behnel wrote: >> Jo?o Valverde wrote: >> >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >>> >> >> That's actually not /that/ uncommon. Operations that change an object >> are >> not (side-effect free) functions, so it's just purity if they do not >> have a >> return value. >> >> Although practicality beats purity, sometimes... ;) >> >> Stefan >> > I didn't know that. But in this case I think purity gets pummeled > every time :) It's still not making sense to force a lookup to fetch > something before deleting (another lookup operation). If that were > imposed by python's internal machinery I'd suggest fixing that instead. > To be clear what I mean by that is that it's just reference passing so it can't generate programmatic errors. From clp2 at rebertia.com Fri Jun 26 04:00:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 01:00:40 -0700 Subject: No trees in the stdlib? In-Reply-To: <4A447430.1060201@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4A447430.1060201@netcabo.pt> Message-ID: <50697b2c0906260100h2fbb1ff3hc7035d72f236318f@mail.gmail.com> On Fri, Jun 26, 2009 at 12:09 AM, Jo?o Valverde wrote: > Jo?o Valverde wrote: >> >> Aahz wrote: >>> >>> In article , >>> Tom Reed ? wrote: >>> >>>> >>>> Why no trees in the standard library, if not as a built in? I searched >>>> the archive but couldn't find a relevant discussion. Seems like a glaring >>>> omission considering the batteries included philosophy, particularly >>>> balanced binary search trees. No interest, no good implementations, >>>> something other reason? Seems like a good fit for the collections module. >>>> Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? ?Why are dicts and the bisect module >>> inadequate? ?Note that there are plenty of different tree implementations >>> available from either PyPI or the Cookbook. >>> >> >> A hash table is very different to a BST. ?They are both useful. The bisect >> module I'm not familiar with, I'll have to look into that, thanks. >> >> I have found pyavl on the web, it does the job ok, but there no >> implementations for python3 that I know of. >> >> Simple example usage case: Insert string into data structure in sorted >> order if it doesn't exist, else retrieve it. >> > After browsing the bisect module I don't think it is the complete answer. > Please correct me if I'm mistaken but... > > Ignoring for a moment that subjectively I feel this is not very pythonic for > my use case, if I get back the insertion position, doesn't that mean I have > to go over on average N/2 items on a linked list to insert the item in Linked list?! Python lists are *array-based*. <"You must be new here" joke redacted> Cheers, Chris -- http://blog.rebertia.com From Andras.Horvath at cern.ch Fri Jun 26 04:04:21 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Fri, 26 Jun 2009 10:04:21 +0200 Subject: validating HTTPS certificates? Message-ID: <20090626080421.GI6455@cern.ch> Hi, (disclaimer: this might be a FAQ entry somewhere but I honestly did use Google) I'm in the process of picking a language for a client application that accesses a HTTPS (actually SOAP) server. This would be easy enough in Python, but I came across a strange fact: neither httplib nor urllib offer the possibility to actually verify the server's certificate. After some digging I've found that from 2.6 onward, the ssl module offers such functionality but it's not trivial, at least for me, to glue that to the HTTP protocol modules (and then those to the SOAP module). Did I miss something? If not, is this feature foreseen, e.g. the trivial build-up of a HTTPS connection while verifying the certificate chain? thanks, Andras From clp2 at rebertia.com Fri Jun 26 04:19:38 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 01:19:38 -0700 Subject: naming packages for pypi In-Reply-To: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: <50697b2c0906260119m27ee5ed3l61f3c5773712a8de@mail.gmail.com> On Fri, Jun 26, 2009 at 12:54 AM, Aljosa Mohorovic wrote: > is it possible to have 2 packages with same name registered at pypi? > are packages unique per name or also per category or something else? > > if package is unique per name how do you name you packages? > do you name them something like -myapp, -myapp, > -myapp, ... > > if this is current situation is this something that you learned to > live with and there are no indications that this will eventually > change? IIRC, packages support nesting, so just do that instead. Simply put project1..projectN into a "myapp" package and put "myapp" on PyPI. Cheers, Chris -- http://blog.rebertia.com From backup95 at netcabo.pt Fri Jun 26 04:28:56 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 09:28:56 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A447430.1060201@netcabo.pt> References: <4A4462E6.7080700@netcabo.pt> <4A447430.1060201@netcabo.pt> Message-ID: <4A4486C8.9060400@netcabo.pt> Jo?o Valverde wrote: > Jo?o Valverde wrote: >> Aahz wrote: >>> In article , >>> Tom Reed wrote: >>> >>>> Why no trees in the standard library, if not as a built in? I >>>> searched the archive but couldn't find a relevant discussion. Seems >>>> like a glaring omission considering the batteries included >>>> philosophy, particularly balanced binary search trees. No interest, >>>> no good implementations, something other reason? Seems like a good >>>> fit for the collections module. Can anyone shed some light? >>>> >>> >>> What do you want such a tree for? Why are dicts and the bisect module >>> inadequate? Note that there are plenty of different tree >>> implementations >>> available from either PyPI or the Cookbook. >>> >> A hash table is very different to a BST. They are both useful. The >> bisect module I'm not familiar with, I'll have to look into that, >> thanks. >> >> I have found pyavl on the web, it does the job ok, but there no >> implementations for python3 that I know of. >> >> Simple example usage case: Insert string into data structure in >> sorted order if it doesn't exist, else retrieve it. >> > After browsing the bisect module I don't think it is the complete > answer. Please correct me if I'm mistaken but... > > Ignoring for a moment that subjectively I feel this is not very > pythonic for my use case, if I get back the insertion position, > doesn't that mean I have to go over on average N/2 items on a linked > list to insert the item in position? Maybe less for sophisticated > implementations but still O(n)? That doesn't compare favorably to the > cost of (possibly) having to rebalance a tree on insertion. I was indeed corrected on this shameful blunder, but in my defense array based lists are implementation dependent and the case for trees can be made on deletion. From pavlovevidence at gmail.com Fri Jun 26 04:53:33 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 01:53:33 -0700 (PDT) Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working References: <909e3956-5792-430b-9db6-c19ee7b6a692@f10g2000vbf.googlegroups.com> <4a445886$0$32678$9b4e6d93@newsspool2.arcor-online.net> <561ff934-00e2-4051-9744-034465081b86@g23g2000vbr.googlegroups.com> <4a4468a0$0$32680$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <53ca7cd6-7bff-478b-a9c7-89c707f580d9@a5g2000pre.googlegroups.com> On Jun 25, 11:20?pm, Stefan Behnel wrote: > Carl Banks wrote: > > On Jun 25, 10:11 pm, Stefan Behnel wrote: > >> Carl Banks wrote: > >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring ? > >>>> at all? > >>> Because Fredrick Lundh wanted it that way. ?Unlike most Python > >>> libraries ElementTree is under the control of one person, which means > >>> it was not designed or vetted by the community, which means it would > >>> tend to have some interface quirks. > >> Just for the record: Fredrik doesn't actually consider it a design "quirk". > > > Well of course he wouldn't--it's his library. > > That's not an argument at all. I can't even imagine what you think I was arguing when I wrote this, or what issue you could have with this statement. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 05:10:15 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 09:10:15 GMT Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: <00606b41$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 11:30:03 -0500, Nick Craig-Wood wrote: >> Something makes me think that module.__dict__ was only added to Python >> fairly recently, but I'm not sure. > > It exists in python2.1 - I don't have an older python to check at the > moment. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import math >>> len(math.__dict__) 27 -- Steven From pavlovevidence at gmail.com Fri Jun 26 05:15:24 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 02:15:24 -0700 (PDT) Subject: naming packages for pypi References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: On Jun 26, 12:54?am, Aljosa Mohorovic wrote: > is it possible to have 2 packages with same name registered at pypi? > are packages unique per name or also per category or something else? > > if package is unique per name how do you name you packages? > do you name them something like -myapp, -myapp, > -myapp, ... > > if this is current situation is this something that you learned to > live with and there are no indications that this will eventually > change? First off, we need to distinguish between software package (a bunch of software and other data distributed together) and Python package (a hierarchical collection of python modules). Furthermore some Python packages are top-level packages, others are subpackages. Your post seems to suggest some conflating of these concepts so you need to make it clear what you really mean. Usually one PyPI entry corresponds to one software package which contains one unique top level package (which can in turn contain many subpackages), but that's not always the case. The main restriction is that a given top-level package may not appear in more than one PyPI entry. Top-level package names are unique. (That is, unless workarounds, such as customizing the installation, are employed.) Carl Banks From michele.simionato at gmail.com Fri Jun 26 05:56:15 2009 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Jun 2009 02:56:15 -0700 (PDT) Subject: Best way to enumerate classes in a module References: <9ko8h6-a15.ln1@archaeopteryx.softver.org.mk> Message-ID: <964863ac-bb22-4137-91fe-0c9a448819a9@f16g2000vbf.googlegroups.com> On Jun 24, 7:07?pm, Terry Reedy wrote: > ?????? ??????????? wrote: > > I need to programmaticaly enumerate all the classes in a given module. > > Currently I'm using dir(module) but the Notice on the documentation page > > [1] ?says "dir() is supplied primarily as a convenience for use at an > > interactive prompt" so that kind of scares me. > > That notice primarily refers to the fact that the special names (of > __xxx__ form) returned are implementation and version dependent, and may > not be complete in the sense that dir(ob) may not return __xyz__ even > though ob.__xyz__ exists and can be retrieved. > > If you are only interested in regular-name attribute of ob, let your > fear fly away. There are rather special cases (not your case) where dir does not retrieve all the names to which an object can respond. In particular this happens for class objects: In [1]: class C(object): pass ...: In [2]: dir(C) Out[2]: ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] Notice the absense of the special names __name__, __mro__, __subclasses__ and also mro, which is not special. All these names are defined on the metaclass type and C responds to them, but they are not retrieved by dir. From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:01:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:01:52 GMT Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <0060775a$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote: > If you want accurate math, check out other types like what is in the > decimal module: > >>>> import decimal >>>> a=decimal.Decimal('3.2') >>>> print a * 3 > 9.6 Not so. Decimal suffers from the exact same problem, just with different numbers: >>> import decimal >>> x = decimal.Decimal('1')/decimal.Decimal('3') >>> 3*x == 1 False Some numbers can't be represented exactly in base 2, and some numbers can't be represented exactly in base 10. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:04:04 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:04:04 GMT Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: Message-ID: <006077de$0$9721$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:31:05 -0700, Mark Dickinson wrote: >> We all know that IEEE floating point is a horribly inaccurate >> representation [...] > > That's a bit extreme! Care to elaborate? Well, 0.1 requires an infinite number of binary places, and IEEE floats only have a maximum of 53 or so, so that implies that floats are infinitely inaccurate... *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 26 06:08:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Jun 2009 10:08:38 GMT Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> Message-ID: <006078f0$0$9721$c3e8da3@news.astraweb.com> On Fri, 26 Jun 2009 00:09:06 -0700, Jason Scheirer wrote: > I once wrote a binary sorted tree data structure for Python in C. It > performed anywhere from 15-40% worse than dicts. I think with > optimization it will only perform 10% worse than dicts at best. > > Oh hey maybe that is why trees aren't an emphasized part of the > standard. They are going to be much slower than the ultra-optimized > dicts already in the standard lib. But dicts require hashable keys, and are in arbitrary order. You can't (for example) traverse a dict in post-order. Hash tables (dicts) are useful for many of the same things that trees are useful for, but they are different data structures with different strengths and weaknesses, and different uses. To argue that we don't need trees because we have dicts makes as much sense as arguing that we don't need dicts because we have lists. -- Steven From magawake at gmail.com Fri Jun 26 06:47:18 2009 From: magawake at gmail.com (Mag Gam) Date: Fri, 26 Jun 2009 06:47:18 -0400 Subject: Reading a large csv file In-Reply-To: References: <1cbd6f830906222017m694bc738m40a46e2851381e@mail.gmail.com> <1cbd6f830906222227q7ec2a89ke3d4805c9ace80e8@mail.gmail.com> <4A41D1FD.7080004@simplistix.co.uk> Message-ID: <1cbd6f830906260347g7c709213ucde150f28e18a8d8@mail.gmail.com> Thankyou everyone for the responses! I took some of your suggestions and my loading sped up by 25% On Wed, Jun 24, 2009 at 3:57 PM, Lie Ryan wrote: > Mag Gam wrote: >> Sorry for the delayed response. I was trying to figure this problem >> out. The OS is Linux, BTW > > Maybe I'm just being pedantic, but saying your OS is Linux means little > as there are hundreds of variants (distros) of Linux. (Not to mention > that Linux is a kernel, not a full blown OS, and people in GNU will > insist to call Linux-based OS GNU/Linux) > >> Here is some code I have: >> import numpy as np >> from numpy import * > > Why are you importing numpy twice as np and as *? > >> import gzip >> import h5py >> import re >> import sys, string, time, getopt >> import os >> >> src=sys.argv[1] >> fs = gzip.open(src) >> x=src.split("/") >> filename=x[len(x)-1] >> >> #Get YYYY/MM/DD format >> YYYY=(filename.rsplit(".",2)[0])[0:4] >> MM=(filename.rsplit(".",2)[0])[4:6] >> DD=(filename.rsplit(".",2)[0])[6:8] > >> >> f=h5py.File('/tmp/test_foo/FE.hdf5','w') > > this particular line would make it impossible to have more than one > instance of the program open. May not be your concern... > >> >> grp="/"+YYYY >> try: >> ? f.create_group(grp) >> except ValueError: >> ? print "Year group already exists" >> >> grp=grp+"/"+MM >> try: >> ? f.create_group(grp) >> except ValueError: >> ? print "Month group already exists" >> >> grp=grp+"/"+DD >> try: >> ? group=f.create_group(grp) >> except ValueError: >> ? print "Day group already exists" >> > >> str_type=h5py.new_vlen(str) > >> mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1', >> 'f4', 'f4')} >> print "Filename is: ",src >> fs = gzip.open(src) > >> dset = f.create_dataset ('Foo',data=arr,compression='gzip') > > What is `arr`? > >> s=0 >> >> #Takes the longest here >> for y in fs: >> ? ? ?continue >> ? a=y.split(',') > >> ? s=s+1 >> ? dset.resize(s,axis=0) > > You increment s by 1 for each iteration, would this copy the dataset? (I > never worked with h5py, so I don't know how it works) > -- > http://mail.python.org/mailman/listinfo/python-list > From magawake at gmail.com Fri Jun 26 06:49:38 2009 From: magawake at gmail.com (Mag Gam) Date: Fri, 26 Jun 2009 06:49:38 -0400 Subject: seeking thru a file Message-ID: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> I have a compressed CSV gziped file. I was wondering if it is possible to seek thru a file For example: I want to load the first 100 lines into an array. Process the data Seek from 101 line to 200 lines. Process the data (remove lines 0 - 100) from memory Seek 201 to 300 line. Process the data (remove 200-300)) from memory etc..etc.. From msliczniak at gmail.com Fri Jun 26 07:09:32 2009 From: msliczniak at gmail.com (Michael Sliczniak) Date: Fri, 26 Jun 2009 04:09:32 -0700 (PDT) Subject: extending method descriptors References: <3c9a8123-7887-45b4-bfd8-d47ea6a88680@r16g2000vbn.googlegroups.com> <4dbdd92b-2f7d-45a4-933e-ed15e65f854c@s16g2000vbp.googlegroups.com> Message-ID: <5ab86546-8d46-4313-a09d-82dc905f4e7b@j12g2000vbl.googlegroups.com> On Jun 25, 2:30?pm, Carl Banks wrote: Thank you for the very good reply. In fact delegating is the approach that works. The main thing to notice is that for an uninstantiated class the first arg to __get__ is None: class desc(object): __slots__ = ('x') def __init__(self, desc): self.x = desc def __get__(self, a, b): #print 'desc get', `self`, `a`, `b` if a == None: return self return self.x.__get__(a) def __set__(self, a, b): #print 'desc set', `self`, `a`, `b` self.x.__set__(a, b) def foo(self): return 'foo' def bar(self): return 'bar' class A(object): __slots__ = ('x', 'y') def __init__(self, *args): for i in xrange(len(args)): setattr(self, A.__slots__[i], args[i]) a = A(0, 1) b = A(2, 3) print a.x, a.y, b.x, b.y x = A.x dx = desc(x) A.x = dx y = A.y dy = desc(y) A.y = dy print type(a).x.foo() print type(a).x.bar() print type(a).y.foo() print type(a).y.bar() print type(b).x.foo() print type(b).x.bar() print type(b).y.foo() print type(b).y.bar() print a.x, a.y, b.x, b.y a.x = -1 a.y = -2 b.x = -3 b.y = -4 print a.x, a.y, b.x, b.y A.x = x print a.x, a.y, b.x, b.y This produces this output: 0 1 2 3 foo bar foo bar foo bar foo bar 0 1 2 3 -1 -2 -3 -4 -1 -2 -3 -4 The manner in which __get__ has to delegate is not pleasant compared to if you could simply derive a new class from method_descriptor with the foo and bar methods though, oh well. From http Fri Jun 26 07:14:18 2009 From: http (Paul Rubin) Date: 26 Jun 2009 04:14:18 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <7xy6rfjlh1.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > > Besides some interface glitches, like returning None > > on delete if I recall correctly. > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. But deletes in an AVL tree should not cause mutation. They should just allocate a new root and path up to where the deleted node was. That allows having references to the old and new versions of the tree, etc. From http Fri Jun 26 07:15:48 2009 From: http (Paul Rubin) Date: 26 Jun 2009 04:15:48 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> Message-ID: <7xtz23jlej.fsf@ruckus.brouhaha.com> Chris Rebert writes: > > Simple example usage case: Insert string into data structure in > > sorted order if it doesn't exist, else retrieve it. > > That's pretty much the bisect module in a nutshell. It manipulates a > sorted list using binary search. That lets you find an existing entry in log(n) time, but inserting or deleting an entry still takes linear time. Also, you don't get a persistent structure in the sense of functional programming. From stefan_ml at behnel.de Fri Jun 26 07:37:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 13:37:25 +0200 Subject: No trees in the stdlib? In-Reply-To: <7xy6rfjlh1.fsf@ruckus.brouhaha.com> References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <7xy6rfjlh1.fsf@ruckus.brouhaha.com> Message-ID: <4a44b2f5$0$31340$9b4e6d93@newsspool4.arcor-online.net> Paul Rubin wrote: > Stefan Behnel writes: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> not (side-effect free) functions, so it's just purity if they do not have a >> return value. > > But deletes in an AVL tree should not cause mutation. They should > just allocate a new root and path up to where the deleted node was. > That allows having references to the old and new versions of the tree, > etc. I doubt that there are many AVL implementations that do that. Plus, if deletion doesn't delete, I'd happily consider that a bug. Stefan From bhardwajjayesh at gmail.com Fri Jun 26 07:38:33 2009 From: bhardwajjayesh at gmail.com (jayesh bhardwaj) Date: Fri, 26 Jun 2009 04:38:33 -0700 (PDT) Subject: file transfer in python Message-ID: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> i am trying to find something useful in python to transfer html files from one terminal to other. Can this be done with some module or shall i start coding my own module using low level socket interface. If u know about some books on this topic or any online help then plz help. From twirlip at bigfoot.com Fri Jun 26 07:52:55 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Fri, 26 Jun 2009 12:52:55 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: <50d94559b1ki83o0k23g0sb5i9ps6mc25o@4ax.com> On Thu, 25 Jun 2009 18:22:48 +0100, MRAB wrote: >Angus Rodgers wrote: >> On Thu, 25 Jun 2009 10:31:47 -0500, Kirk Strauser >> wrote: >> >>> At 2009-06-24T19:53:49Z, Angus Rodgers writes: >>> >>>> print ''.join(map(detab, f.xreadlines())) >>> An equivalent in modern Pythons: >>> >>>>>> print ''.join(line.expandtabs(3) for line in file('h071.txt')) >> >> I guess the code below would also have worked in 2.1? >> (It does in 2.5.4.) >> >> print ''.join(line.expandtabs(3) for line in \ >> file('h071.txt').xreadlines()) >> >That uses a generator expression, which was introduced in 2.4. Sorry, I forgot that list comprehensions need square brackets. The following code works in 2.1 (I installed version 2.1.3, on a different machine, to check!): f = open('h071.txt') # Can't use file('h071.txt') in 2.1 print ''.join([line.expandtabs(3) for line in f.xreadlines()]) (Of course, in practice I'll stick to doing it the more sensible way that's already been explained to me. I'm ordering a copy of Wesley Chun, /Core Python Programming/ (2nd ed., 2006), to learn about version 2.5.) -- Angus Rodgers From nils at ccsg.de Fri Jun 26 08:00:58 2009 From: nils at ccsg.de (=?ISO-8859-1?Q?Nils_R=FCttershoff?=) Date: Fri, 26 Jun 2009 14:00:58 +0200 Subject: seeking thru a file In-Reply-To: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> References: <1cbd6f830906260349s195d2997se92a02d0277444e2@mail.gmail.com> Message-ID: <4A44B87A.80509@ccsg.de> Hi Mag, Mag Gam wrote: > I have a compressed CSV gziped file. I was wondering if it is possible > to seek thru a file > > For example: > > I want to load the first 100 lines into an array. Process the data > > Seek from 101 line to 200 lines. Process the data (remove lines 0 - > 100) from memory > > Seek 201 to 300 line. Process the data (remove 200-300)) from memory > > etc..etc.. > This would be very easy. Here is one way you could do it: (I didn't test the code; I've just write it down, assuming you use python 2.6, cause you didn't mentioned which version you are using...) import gzip step = 100 data_present = True with gzip.open(foo.csv.gzip) as my_file: counter = 0 my_buffer = [] while data_present: while counter <= step: line = my_file.readline() if line: my_buffer.append(my_file.readline()) counter += 1 else: data_present = False break if len(my_buffer) > 0: do_something(my_buffer) counter = 0 my_buffer = [] Kind Regards, Nils From doron.tal.list at gmail.com Fri Jun 26 08:07:45 2009 From: doron.tal.list at gmail.com (Doron Tal) Date: Fri, 26 Jun 2009 15:07:45 +0300 Subject: file transfer in python In-Reply-To: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: <2a8674c60906260507h164c5a99gd26ada06a9ec8b6d@mail.gmail.com> On Fri, Jun 26, 2009 at 2:38 PM, jayesh bhardwaj wrote: > i am trying to find something useful in python to transfer html files > from one terminal to other. Can this be done with some module or shall > i start coding my own module using low level socket interface. If u > know about some books on this topic or any online help then plz help. > -- > http://mail.python.org/mailman/listinfo/python-list > You can try the xmlrpclib: http://docs.python.org/library/xmlrpclib.html#binary-objects --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From bieffe62 at gmail.com Fri Jun 26 08:07:54 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Fri, 26 Jun 2009 05:07:54 -0700 (PDT) Subject: file transfer in python References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: On 26 Giu, 13:38, jayesh bhardwaj wrote: > i am trying to find something useful in python to transfer html files > from one terminal to other. Can this be done with some module or shall > i start coding my own module using low level socket interface. If u > know about some books on this topic or any online help then plz help. In the standard library there is ftplib, which allows your program to act as a FTP client. Of course the receiver end should have an FTP server installing and running. I don't tink it can handle SFTP protocol, so if you are concerned with security you should opt for someting else, or protect your connection somehow (e.g. SSH tunneling). Or, if you have ssh (client and server) installed, you could simply spawn a subprocess ( see the subprocess module for that ) which execute one or more 'scp' commands. Ciao ---- FB From bijoy.franco at gmail.com Fri Jun 26 08:23:17 2009 From: bijoy.franco at gmail.com (bijoy franco) Date: Fri, 26 Jun 2009 17:53:17 +0530 Subject: Python simple web development In-Reply-To: References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> Hi, I am learning pylons..It seems to be very simple and flexible.. Just give a try if it seems interesting for you Thanks Bijoy On Fri, Jun 26, 2009 at 3:02 AM, Gabriel Genellina wrote: > En Thu, 25 Jun 2009 04:29:28 -0300, Private Private > escribi?: > > I am looking for a python library which will allow me to do a simple >> web development. I need to use >> some forms (but nice looking :-) ), creating images based on input >> from those forms, etc. I have read a bit about Django and TurboGears >> but I am afraid that this is too big for my requirements (am I >> wrong ?). >> Can you suggest anything ? >> > > You may try pesto: http://pesto.redgecko.org/ > > pesto is a very small framework (45k to download!), WSGI compliant, > includes session management, mapping URL->function, caching, templates > (optional, whichever you like). Minimalist but flexible. > > Anyway, learning to use Django isn't a bad idea. > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From spconv+m at gmail.com Fri Jun 26 08:28:42 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 14:28:42 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4A4411AB.1090302@hughes.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> Message-ID: <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> 2009/6/26 norseman : > Sebastian Paj?k wrote: >>> >>> Can, but should not. >>> I read that the problem is when using the Polish language only. Otherwise >>> things work normally. Is that correct? >> >> Yes, correct >> >>> If so then byte swap may be a problem. ?Using the u'string' should solve >>> that. I am assuming you have the Polish alphabet working correctly on >>> your >>> machine. I think I read that was so in an earlier posting. >>> >>> Are there any problems with his alphabet scrambling on your machine? >>> If so that needs investigating. ?Here I assume you are reading Polish >>> from >>> him on your machine and not a network translator version. >>> >> >> The original thread is here: >> http://mail.python.org/pipermail/python-list/2009-June/717666.html >> I've explained the problem there > > ================ > I re-read the posting. (Thanks for the link) > > You do not mention if he has sent you any Polish words and if they > appear OK on your machine. > He has sent my a polish words, they appear correct. We both have the english version of systems (they are both set to polish locale (time, dates, keyboard etc.)) > A note here: ?In reading the original posting I get symbols that are not > familiar to me as alphabet. > From the line in your original: > ? ? Label(root, text='?????????').pack() > I see text=' > ? ? ? ? ? then an e with a goatee > ? ? ? ? ? ? ? ?a ?capitol O with an accent symbol on top (') > ? ? ? ? ? ? ? ?an a with a tail on the right > ? ? ? ? ? ? ? ?a ?s with an accent on top > ? ? ? ? ? ? ? ?an I do no not know what - maybe some sort of l with a > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? slash through the middle > ? ? ? ? ? ? ? ?a ?couple of z with accents on top > ? ? ? ? ? ? ? ?a ?capitol C with an accent on top > ? ? ? ? ? ? ? ?a ?n with a short bar on top > > I put the code into python and took a look. > > > > I get: > cat xx > > # -*- coding: utf-8 -*- > > import sys > from Tkinter import * > > root = Tk() > > Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() > Button(root, > text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() > Entry(root).pack() > > root.mainloop() > > Then: > python xx > ?File "xx", line 10 > SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no > encoding declared; see http://www.python.org/peps/pep-0263.html for details > > So I did. > It notes Window$ puts things into those lines. Namely: > "To aid with platforms such as Windows, which add Unicode BOM marks > ? ?to the beginning of Unicode files, the UTF-8 signature > ? ?'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well > ? ?(even if no magic encoding comment is given). > " > > Then I took out the o with the accent and re-ran the file. > > Everything works except the text is exactly as shown above. That is: > \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 > (shows twice as directed, one for label, one for button, no apostrophes) > > OK - now I take a look at what in actually in the file. > in MC on Linux Slackware 10.2 I read, in the mail folder, > 0119 capitol A with a tilde on top. > HEX readings beginning at the 0119\... > 30 31 31 39 C3 B3 5C > > but in the python file xx, I read: > 30 31 31 39 5C > 0119\... > > I would have to say the mail system is screwing you up. ?Might try zipping > the file and sending it that way and see if problem changes. > I've tried zipping It looks like you you didn't save the script in UTF-8. Try to run the original script file from attachment (UTF-8 without BOM). ps. Do you have mac os x? It would be better if someone with mac tested it # -*- coding: utf-8 -*- import sys from Tkinter import * root = Tk() root.tk.call('encoding', 'system', 'utf-8') Label(root, text=u'?????????').pack() Button(root, text=u'?????????').pack() root.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: test1.py Type: application/octet-stream Size: 242 bytes Desc: not available URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Jun 26 08:34:52 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 26 Jun 2009 14:34:52 +0200 Subject: seeking thru a file In-Reply-To: References: Message-ID: <4a44c06b$0$403$426a74cc@news.free.fr> Mag Gam a ?crit : > I have a compressed CSV gziped file. Then gunzip it first... > I was wondering if it is possible > to seek thru a file > > For example: > > I want to load the first 100 lines into an array. Process the data > > Seek from 101 line to 200 lines. Process the data (remove lines 0 - > 100) from memory > > Seek 201 to 300 line. Process the data (remove 200-300)) from memory > > etc..etc.. Yes, you can... Now is there any reason you want to micro-manage stuff already managed by Python and the file system ?-) To iterate on a text file's lines, just open the file - the file object is it's own iterator, and will (with help from the filesystem AFAIK) properly handle cache, buffers and whatnot. The canonical code snippet is: # iterating over a file line by line without # loading the while file in memory f = open("/path/to/some/file.txt") for line in f: do_something_with(line) f.close() Unless you have a good reason (micro-managing IO buffers not being one) to want to work by 100-lines batch, then this should be just enough. Now note that Python also have a csv module in the standard lib, which will probably (except perhaps in a very few corner cases) be more robust and efficient that whatever you'd write. HTH From spconv+m at gmail.com Fri Jun 26 08:37:41 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 14:37:41 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4a441def$0$12249$9b622d9e@news.freenet.de> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <4a441def$0$12249$9b622d9e@news.freenet.de> Message-ID: <111013c20906260537w893c0a2j75479e5d44f43209@mail.gmail.com> > ?in place where polish >> accented character should be (like "?????" etc) >> This problem is only on mac os x and it doesn't apply to button widget >> (where characters are correct) > > I see. So it is a font problem: if the square box is displayed, it means > that the font just doesn't have a glyph for the character you want to > display. Try using a different font in the label widget. I've tried many fonts, the effect is always the same. Standard fonts like Arial, Tahoma, Vedana all have Polish glyphs. The problem is that Tkinter selects wrong glyphs for non-ASCII chars. It's not the font issue as text on Button widget appears correctly >> There is no wish. I'm talking about build-in Tkinter > > So try installing Tk separately. > >> (isn't Tk build-in Python?). > > Depends on where exactly you got your Python from, and what exactly > is your OSX version. Recent releases of OSX include a copy of Tcl/Tk, > and some sets of Python binaries link against the Apple Tk. > As I said I don't have mac osx. I just expect my Python script to be portable and behave the same on both Windows and OSX, but It isn't. From udyantw at gmail.com Fri Jun 26 10:07:51 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 07:07:51 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation Message-ID: I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in both flavors of Python: 2.6.2 and 3.0.1 (CPython) The code: #!/usr/bin/env python def remaining_peg (peg1, peg2): return (6 - peg1 - peg2) def hanoi (num_discs, start, end): if (1 == num_discs): print "Top of peg {0} to peg {1}".format(start,end) # used print() for Py 3.0.1 else: hanoi ((num_discs - 1), start, (remaining_peg (start, end))) hanoi (1, start, end) hanoi ((num_discs - 1), (remaining_peg (start, end)), end) hanoi(20,2,3) The times: real usr sys Python 2.6.2 7.994s 3.336s 3.296s Python 3.0.1 55.302s 38.024s 5.876s What happened to Python? From pdpinheiro at gmail.com Fri Jun 26 10:09:25 2009 From: pdpinheiro at gmail.com (pdpi) Date: Fri, 26 Jun 2009 07:09:25 -0700 (PDT) Subject: 3.2*2 is 9.6 ... or maybe it isn't? References: <0060775a$0$9721$c3e8da3@news.astraweb.com> Message-ID: <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> On Jun 26, 11:01?am, Steven D'Aprano wrote: > On Thu, 25 Jun 2009 12:41:13 -0600, Michael Torrie wrote: > > If you want accurate math, check out other types like what is in the > > decimal module: > > >>>> import decimal > >>>> a=decimal.Decimal('3.2') > >>>> print a * 3 > > 9.6 > > Not so. Decimal suffers from the exact same problem, just with different > numbers: > > >>> import decimal > >>> x = decimal.Decimal('1')/decimal.Decimal('3') > >>> 3*x == 1 > > False > > Some numbers can't be represented exactly in base 2, and some numbers > can't be represented exactly in base 10. > > -- > Steven But since 10 = 2 * 5, all numbers that can be finitely represented in binary can be represented finitely in decimal as well, with the exact same number of places for the fractional part (and no more digits than the binary representation in the integer part) From stefan_ml at behnel.de Fri Jun 26 10:14:50 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 16:14:50 +0200 Subject: Py 3 slower than Py 2. Towers of Hanoi implementation In-Reply-To: References: Message-ID: <4a44d7d9$0$32673$9b4e6d93@newsspool2.arcor-online.net> Udyant Wig wrote: > I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > The code: > #!/usr/bin/env python > def remaining_peg (peg1, peg2): > return (6 - peg1 - peg2) > > def hanoi (num_discs, start, end): > if (1 == num_discs): > print "Top of peg {0} to peg {1}".format(start,end) # used print() > for Py 3.0.1 > > else: > hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > hanoi (1, start, end) > hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > The times: real usr sys > Python 2.6.2 7.994s 3.336s 3.296s > Python 3.0.1 55.302s 38.024s 5.876s > > What happened to Python? Have you tried Python 3.1? Have you made sure that both Python interpreters were build with the same compiler arguments and that none of them is a debug build? Stefan From h.b.furuseth at usit.uio.no Fri Jun 26 10:35:59 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Fri, 26 Jun 2009 16:35:59 +0200 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel writes: >Jo?o Valverde wrote: >> Besides some interface glitches, like returning None >> on delete if I recall correctly. > > That's actually not /that/ uncommon. Operations that change an object are > not (side-effect free) functions, so it's just purity if they do not have a > return value. It's purity that they don't return the modified tree/dict/whatever. They can still return the deleted element and remain pure. -- Hallvard From udyantw at gmail.com Fri Jun 26 10:37:09 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 07:37:09 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation References: <4a44d7d9$0$32673$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <5cc9327a-eedc-49ce-b817-35dad9616405@w31g2000prd.googlegroups.com> On Jun 26, 7:14?pm, Stefan Behnel wrote: > Udyant Wig wrote: > > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin > > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > > The code: > > #!/usr/bin/env python > > def remaining_peg (peg1, peg2): > > ? ?return (6 - peg1 - peg2) > > > def hanoi (num_discs, start, end): > > ? ?if (1 == num_discs): > > ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > > for Py 3.0.1 > > > ? ?else: > > ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > > ? ? ? ? ? ?hanoi (1, start, end) > > ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > > What happened to Python? > > Have you tried Python 3.1? Have you made sure that both Python interpreters > were build with the same compiler arguments and that none of them is a > debug build? > > Stefan Yes. Both were built with the same compiler parameters. No. None of them is a debug build. I'm currently getting Python 3.1 From stefan_ml at behnel.de Fri Jun 26 10:42:42 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 16:42:42 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4a44de62$0$32677$9b4e6d93@newsspool2.arcor-online.net> Hallvard B Furuseth wrote: > Stefan Behnel writes: >> Jo?o Valverde wrote: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> not (side-effect free) functions, so it's just purity if they do not have a >> return value. > > It's purity that they don't return the modified tree/dict/whatever. > They can still return the deleted element and remain pure. Fair enough. Stefan From Slattery_T at bls.gov Fri Jun 26 10:57:35 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 10:57:35 -0400 Subject: "The system cannot execute the specified program." Message-ID: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Our office has a copy of Python 3.0 installed on a network share device. When I try to run it I get this message: "The system cannot execute the specified program." When I googled that message, the links that came up had to do with missing DLLs. So I fired up Dependency Walker and found out that there were indeed DLLs that it needed that the OS couldn't find. So I supplied those DLLs. And it still gives the same message, even though Dependency Walker is now happy. Does anybody have a clue what might cause this amazingly uninformative message? On a related note: there's a *.chm file on the same share, that's a PYthon user's guide. When I start that, I get a window with the full table of contents and index on the left side. But on the right side where the contents should be ... "Navigation to the web page was canceled". WTF??? -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From p.f.moore at gmail.com Fri Jun 26 11:01:24 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 26 Jun 2009 16:01:24 +0100 Subject: Py 3 slower than Py 2. Towers of Hanoi implementation In-Reply-To: References: Message-ID: <79990c6b0906260801r6efc7560ud2c465cd68704d72@mail.gmail.com> 2009/6/26 Udyant Wig : > I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > The code: > #!/usr/bin/env python > def remaining_peg (peg1, peg2): > ? ? ? ?return (6 - peg1 - peg2) > > def hanoi (num_discs, start, end): > ? ? ? ?if (1 == num_discs): > ? ? ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > for Py 3.0.1 > > ? ? ? ?else: > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > ? ? ? ? ? ? ? ?hanoi (1, start, end) > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > What happened to Python? I/O in Python 3.0 is known to be slow, because the bulk of the implementation is in Python (rather than C). Python 3.1 addresses this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the print commented out, the second are with the print, redirected to the null device. The tests are on a pretty slow Windows XP SP2 laptop. >timer & \Apps\Python26\python.exe hanoi.py & timer Timer 1 on: 15:54:53 Timer 1 off: 15:54:57 Elapsed: 0:00:03.88 >timer & \Apps\Python31\python.exe hanoi.py & timer Timer 1 on: 15:57:05 Timer 1 off: 15:57:09 Elapsed: 0:00:03.67 >timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer Timer 1 on: 15:57:44 Timer 1 off: 15:58:14 Elapsed: 0:00:29.91 >timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer Timer 1 on: 15:58:38 Timer 1 off: 15:59:09 Elapsed: 0:00:30.63 Nothing much in it. Paul. From aljosa.mohorovic at gmail.com Fri Jun 26 11:05:01 2009 From: aljosa.mohorovic at gmail.com (Aljosa Mohorovic) Date: Fri, 26 Jun 2009 08:05:01 -0700 (PDT) Subject: naming packages for pypi References: <6557fdc3-ec7d-4364-a598-3828d2691ece@l32g2000vba.googlegroups.com> Message-ID: <96438f05-b536-4a79-8ba2-d19bdbd1eb8e@j20g2000vbp.googlegroups.com> On Jun 26, 11:15 am, Carl Banks wrote: > Your post seems to suggest some conflating of these concepts so you > need to make it clear what you really mean. my example: when creating website example.com (django project) it contains multiple django apps which i package separately. most of websites have news, about, contact so i would create 3 packages news, about and contact and add them to pypi.example.com (private pypi for my company). same thing happens for site example2.com, example3.com so finally i have something like: example.com-news # news package for project/site example.com example2.com-news # news package for project/site example2.com example3.com-news # news package for project/site example3.com i'm trying to find a better way, currently it looks to me like packaging system is missing namespaces/categories or something similar but i'm guessing it's only that i don't know how to do it properly. that's why i'm asking so please suggest a proper way for me to do it. Aljosa Mohorovic From Scott.Daniels at Acm.Org Fri Jun 26 11:07:24 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 08:07:24 -0700 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> References: <0060775a$0$9721$c3e8da3@news.astraweb.com> <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> Message-ID: pdpi wrote: > ... But since 10 = 2 * 5, all numbers that can be finitely represented in > binary can be represented finitely in decimal as well, with the exact > same number of places for the fractional part (and no more digits > than the binary representation in the integer part) OK, so base 30 is the obvious choice, digits and letters, and 1/N works for n in range(1, 7) + range(8, 11). G?del numbers, anyone? :-) --Scott David Daniels Scott.Daniels at Acm.Org From andreengels at gmail.com Fri Jun 26 11:17:03 2009 From: andreengels at gmail.com (Andre Engels) Date: Fri, 26 Jun 2009 17:17:03 +0200 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <0060775a$0$9721$c3e8da3@news.astraweb.com> <0e14ab04-a825-45bc-90c5-a713e4cb8188@p23g2000vbl.googlegroups.com> Message-ID: <6faf39c90906260817wbba0391x44d49b9cb6c7a521@mail.gmail.com> On Fri, Jun 26, 2009 at 5:07 PM, Scott David Daniels wrote: > pdpi wrote: >> >> ... But since 10 = 2 * 5, all numbers that can be finitely represented in >> binary can be represented finitely in decimal as well, with the exact >> same number of ?places for the fractional part (and no more digits >> than the binary representation in the integer part) > > OK, so base 30 is the obvious choice, digits and letters, and 1/N works > for n in range(1, 7) + range(8, 11). ?G?del numbers, anyone? :-) To get even more working, use real rational numbers: p/q represented by the pair of numbers (p,q) with p,q natural numbers. Then 1/N works for every N, and upto any desired precision. -- Andr? Engels, andreengels at gmail.com From fpm at u.washington.edu Fri Jun 26 11:18:29 2009 From: fpm at u.washington.edu (cassiope) Date: Fri, 26 Jun 2009 08:18:29 -0700 (PDT) Subject: Recipes for trace statements inside python programs? References: <715a02fc-e291-4ed0-b199-29ebf11817f6@l28g2000vba.googlegroups.com> Message-ID: <67a85e72-9171-4e54-8562-a30e0002191d@x1g2000prh.googlegroups.com> On Jun 25, 1:33?am, Francesco Bochicchio wrote: > Hi all, > > as many - I think - python programmers, I find muself debugging my > scripts by placing print statements in strategic places rather than > using the python debugger, and commenting/uncommenting them according > to myy deugging needs. ?After a time, these prints staements start to > evolving in some ad-hoc half-baked framework ... so I wonder if there > is somewhere there is a full-baked trace statement support framework > which I can use. I'm aware of the logging module, but for me it its > more geared toward ?application logging rather than toward trace for > debugging purpose. > > Having googlet and found nothing (or too much but nothing relef?vant), > I'm now asking The List. > > Here is what I have in mind: > > Each module, function, class and method should have an attribute, say > trace_flag, which can be set to true or false value. > > there should be a function TRACE which does something like this: > > if __debug__ : > def TRACE(*args): > ? ? ?if ?trace_enabled(): print "TRACE(%s) : %s " % ( context(), " > ".join( str(x) for x in args ) ) > > where trace_enabled() should return the value of the innermost > trace_flag (checking current function/method then current class (if > any) then current module) and context() shoud return a string like > "module.function" or "module.class.method" ). > > At this point I could in my test code enable ?the trace in the > function/class that gives me trouble and disable it after I fixed it, > without having to touch the actual code under test. > > I guess it should not be too hard do using python introspection > modules, but of couse I first would like to know if something like > this already exists. > > I'm ?aware that this imposes a performance penalty, but my scripts are > not operformance-critical. And if I put an if __debug__ switch What are you trying to achieve that could not be accomplished with the logging module? http://docs.python.org/library/logging.html#module-logging -f From mail at timgolden.me.uk Fri Jun 26 11:21:19 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 26 Jun 2009 16:21:19 +0100 Subject: "The system cannot execute the specified program." In-Reply-To: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <4A44E76F.6040305@timgolden.me.uk> Tim Slattery wrote: > Our office has a copy of Python 3.0 installed on a network share > device. When I try to run it I get this message: "The system cannot > execute the specified program." To be honest, I'd look at one of the Portable Python installations, specifically designed to be run off a stick or a network share. http://www.portablepython.com/ http://www.voidspace.org.uk/python/movpy/ TJG From spconv+m at gmail.com Fri Jun 26 11:27:26 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Fri, 26 Jun 2009 17:27:26 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: <111013c20906260827r62a06679lf3455f18ed34ff38@mail.gmail.com> Maybe this picture will tell you more: http://files.getdropbox.com/u/1211593/tkinter.png The original script: http://files.getdropbox.com/u/1211593/test1.py May someone can confirm this osx behaviour? 2009/6/26 Sebastian Paj?k : > 2009/6/26 norseman : >> Sebastian Paj?k wrote: >>>> >>>> Can, but should not. >>>> I read that the problem is when using the Polish language only. Otherwise >>>> things work normally. Is that correct? >>> >>> Yes, correct >>> >>>> If so then byte swap may be a problem. ?Using the u'string' should solve >>>> that. I am assuming you have the Polish alphabet working correctly on >>>> your >>>> machine. I think I read that was so in an earlier posting. >>>> >>>> Are there any problems with his alphabet scrambling on your machine? >>>> If so that needs investigating. ?Here I assume you are reading Polish >>>> from >>>> him on your machine and not a network translator version. >>>> >>> >>> The original thread is here: >>> http://mail.python.org/pipermail/python-list/2009-June/717666.html >>> I've explained the problem there >> >> ================ >> I re-read the posting. (Thanks for the link) >> >> You do not mention if he has sent you any Polish words and if they >> appear OK on your machine. >> > > He has sent my a polish words, they appear correct. We both have the > english version of systems (they are both set to polish locale (time, > dates, keyboard etc.)) > >> A note here: ?In reading the original posting I get symbols that are not >> familiar to me as alphabet. >> From the line in your original: >> ? ? Label(root, text='?????????').pack() >> I see text=' >> ? ? ? ? ? then an e with a goatee >> ? ? ? ? ? ? ? ?a ?capitol O with an accent symbol on top (') >> ? ? ? ? ? ? ? ?an a with a tail on the right >> ? ? ? ? ? ? ? ?a ?s with an accent on top >> ? ? ? ? ? ? ? ?an I do no not know what - maybe some sort of l with a >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? slash through the middle >> ? ? ? ? ? ? ? ?a ?couple of z with accents on top >> ? ? ? ? ? ? ? ?a ?capitol C with an accent on top >> ? ? ? ? ? ? ? ?a ?n with a short bar on top >> >> I put the code into python and took a look. >> >> >> >> I get: >> cat xx >> >> # -*- coding: utf-8 -*- >> >> import sys >> from Tkinter import * >> >> root = Tk() >> >> Label(root, text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() >> Button(root, >> text='\u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144').pack() >> Entry(root).pack() >> >> root.mainloop() >> >> Then: >> python xx >> ?File "xx", line 10 >> SyntaxError: Non-ASCII character '\xf3' in file xx on line 10, but no >> encoding declared; see http://www.python.org/peps/pep-0263.html for details >> >> So I did. >> It notes Window$ puts things into those lines. Namely: >> "To aid with platforms such as Windows, which add Unicode BOM marks >> ? ?to the beginning of Unicode files, the UTF-8 signature >> ? ?'\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well >> ? ?(even if no magic encoding comment is given). >> " >> >> Then I took out the o with the accent and re-ran the file. >> >> Everything works except the text is exactly as shown above. That is: >> \u0119?\u0105\u015b\u0142\u017c\u017a\u0107\u0144 >> (shows twice as directed, one for label, one for button, no apostrophes) >> >> OK - now I take a look at what in actually in the file. >> in MC on Linux Slackware 10.2 I read, in the mail folder, >> 0119 capitol A with a tilde on top. >> HEX readings beginning at the 0119\... >> 30 31 31 39 C3 B3 5C >> >> but in the python file xx, I read: >> 30 31 31 39 5C >> 0119\... >> >> I would have to say the mail system is screwing you up. ?Might try zipping >> the file and sending it that way and see if problem changes. >> > > I've tried zipping > It looks like you you didn't save the script in UTF-8. Try to run the > original script file from attachment (UTF-8 without BOM). > ps. Do you have mac os x? It would be better if someone with mac tested it > > > # -*- coding: utf-8 -*- > > import sys > > from Tkinter import * > > root = Tk() > root.tk.call('encoding', 'system', 'utf-8') > > Label(root, text=u'?????????').pack() > Button(root, text=u'?????????').pack() > > root.mainloop() > From news123 at free.fr Fri Jun 26 11:29:11 2009 From: news123 at free.fr (News123) Date: Fri, 26 Jun 2009 17:29:11 +0200 Subject: R-tree implemetation in python without external C_libraries Message-ID: <4a44e947$0$420$426a74cc@news.free.fr> Hi, I'd like to have a small rtree library for a small python project. ( good data structure for 2D searches ) For this mini - project I'd prefer, to have no C-library dependencies Does anyone have a small implementation which I'm allowed to use and modify, which does not use an external C-library? What I'm mostly interested in is the R-Tree creation. Thanks in advance for any pointers. If you don't know a pure python implementation, then I'd be also interested in implemetations in other languages. I could then use these implementations and recode them to python. The alternative languages could be perl java java-script C C++ thanks in advance for any pointers bye N From aadarshjajodia at gmail.com Fri Jun 26 11:58:45 2009 From: aadarshjajodia at gmail.com (Addy) Date: Fri, 26 Jun 2009 08:58:45 -0700 (PDT) Subject: opening a https web page Message-ID: <5e3e86e5-d908-4eff-8ea2-aff508eeae69@s38g2000prg.googlegroups.com> Dear sir, i am not being able to open "https://" web pages using urllib2 or urllib. I am being able to open "http" pages though. i am connecting the internet through a proxy server. I am being able to open "https://" pages if i am using an ineternet connection that does not connect through a proxy server.Please Help. Looking forward to your reply. Aadarsh Jajodia From niloyroy47 at gmail.com Fri Jun 26 12:08:40 2009 From: niloyroy47 at gmail.com (padfoot) Date: Fri, 26 Jun 2009 09:08:40 -0700 (PDT) Subject: handling https sites Message-ID: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Sir, Is there any module in python to open https sites through a proxy.I am connectyed to the net via a proxy server and i am unable to crawl https sites. From barakatx2 at gmail.com Fri Jun 26 12:09:41 2009 From: barakatx2 at gmail.com (BarakatX2) Date: Fri, 26 Jun 2009 09:09:41 -0700 (PDT) Subject: MultiValueDict? Message-ID: <4d67805e-2eed-4745-9e02-85797330013b@l5g2000vbp.googlegroups.com> , , ]}> for f in files['rqFiles']: print f.name This gives me an "'str' object has no attribute 'name'" error. I don't know if there is a special way to access MultiValueDicts values, but I assumed each key has a list that is accessed just like any other list. Any help is appreciated. From shawn.milo at gmail.com Fri Jun 26 12:28:20 2009 From: shawn.milo at gmail.com (Shawn Milochik) Date: Fri, 26 Jun 2009 12:28:20 -0400 Subject: handling https sites In-Reply-To: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> References: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Message-ID: <696448CE-B9E6-4412-9C98-E543218317E5@gmail.com> On Jun 26, 2009, at 12:08 PM, padfoot wrote: > Sir, > Is there any module in python to open https sites through a > proxy.I am connectyed to the net via a proxy server and i am unable to > crawl https sites. > -- > http://mail.python.org/mailman/listinfo/python-list Check out the "Scrape the Web" series from the 2009 PyCon: http://advocacy.python.org/podcasts/ From Slattery_T at bls.gov Fri Jun 26 12:29:39 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 12:29:39 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Tim Slattery wrote: >Our office has a copy of Python 3.0 installed on a network share >device. When I try to run it I get this message: "The system cannot >execute the specified program." I should add that before I knew about our shared installation, I downloaded the AS distribution of Python 2.6 from ActiveState. Their install procedure is a *.bat file that calls Python to put everything in the right place. When the bat file tries to invoke Python, I get the same message. -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From cgoldberg at gmail.com Fri Jun 26 12:34:02 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Fri, 26 Jun 2009 09:34:02 -0700 (PDT) Subject: handling https sites References: <82f54d4d-1967-4e22-9e5b-c7376171f9a7@y6g2000prf.googlegroups.com> Message-ID: > Is there any module in python to open https > sites through a proxy. yes, you can use "urllib2". from the urllib2 docs: "The default is to read the list of proxies from the environment variables" So if you have a proxy setup, it should detect it from your environment vars. If you want to specify something different, you want to build an opener with a ProxyHandler: http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler -Corey From duncan.booth at invalid.invalid Fri Jun 26 12:51:00 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Jun 2009 16:51:00 GMT Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: Tim Slattery wrote: > Our office has a copy of Python 3.0 installed on a network share > device. When I try to run it I get this message: "The system cannot > execute the specified program." > > When I googled that message, the links that came up had to do with > missing DLLs. So I fired up Dependency Walker and found out that there > were indeed DLLs that it needed that the OS couldn't find. So I > supplied those DLLs. And it still gives the same message, even though > Dependency Walker is now happy. > > Does anybody have a clue what might cause this amazingly uninformative > message? Are you using Vista? There seem to be some strange security settings for network shares in Vista. I had a file shared from an XP system which my Vista system could not access even though other machines could access it. Eventually I had to copy the file from the XP machine onto the Vista machine and it was happy to access it once it was on the local system. Alternatively for a non-Vista wild guess, could it be that Python 3.0 is loading some libraries that use .Net and is therefore triggering the 'code access security' which prevents the running of .Net applications from a network share? From nobody at nowhere.com Fri Jun 26 13:01:24 2009 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Jun 2009 18:01:24 +0100 Subject: validating HTTPS certificates? References: Message-ID: On Fri, 26 Jun 2009 10:04:21 +0200, Andras.Horvath wrote: > (disclaimer: this might be a FAQ entry somewhere but I honestly did use > Google) > > I'm in the process of picking a language for a client application that > accesses a HTTPS (actually SOAP) server. This would be easy enough in > Python, but I came across a strange fact: neither httplib nor urllib > offer the possibility to actually verify the server's certificate. > > After some digging I've found that from 2.6 onward, the ssl module > offers such functionality but it's not trivial, at least for me, to glue > that to the HTTP protocol modules (and then those to the SOAP module). > > Did I miss something? If not, is this feature foreseen, e.g. the trivial > build-up of a HTTPS connection while verifying the certificate chain? For a urllib-style interface, there's not much point in performing verification after the fact. Either the library performs verification or it doesn't. If it doesn't, you've just sent the (potentially confidential) request to an unknown server; discovering this after the fact doesn't really help. From http Fri Jun 26 13:13:25 2009 From: http (Paul Rubin) Date: 26 Jun 2009 10:13:25 -0700 Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> <7xy6rfjlh1.fsf@ruckus.brouhaha.com> <4a44b2f5$0$31340$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <7x1vp67way.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > > But deletes in an AVL tree should not cause mutation. They should > > just allocate a new root and path up to where the deleted node was. > I doubt that there are many AVL implementations that do that. Plus, if > deletion doesn't delete, I'd happily consider that a bug. I've never seen one that DIDN'T do that, but maybe it's just the crowd I hang out with. See "Purely Functional Data Structures" by Chris Okasaki for more detailed descriptions of such methods. From aahz at pythoncraft.com Fri Jun 26 13:15:58 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 10:15:58 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: In article <006078f0$0$9721$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >Hash tables (dicts) are useful for many of the same things that trees are >useful for, but they are different data structures with different >strengths and weaknesses, and different uses. To argue that we don't need >trees because we have dicts makes as much sense as arguing that we don't >need dicts because we have lists. The problem is that trees are like standards: there are so many to choose from. Each has its own tradeoffs, and because Python dicts and lists can substitute for many of the traditionals uses of trees, the tradeoffs are less clear. I think nobody would object to adding trees to the standard library, but it will certainly require a clear PEP, preferably with a pointer to an existing PyPI library that has acquired real-world use. (In particular, WRT the bisect module, although insertion and deletion are O(N), the constant factor for doing a simple memory move at C speed swamps bytecode until N gets very large -- and we already have collections.deque() for some other common use cases.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From udyantw at gmail.com Fri Jun 26 13:16:40 2009 From: udyantw at gmail.com (Udyant Wig) Date: Fri, 26 Jun 2009 10:16:40 -0700 (PDT) Subject: Py 3 slower than Py 2. Towers of Hanoi implementation References: Message-ID: <3ecf9ea5-b7e4-4a2d-ad97-8e1faec2ace6@v23g2000pro.googlegroups.com> On Jun 26, 8:01?pm, Paul Moore wrote: > 2009/6/26 Udyant Wig : > > > > > > > I implemented this ->http://www.apl.jhu.edu/~hall/lisp/Hanoi.lispin > > both flavors of Python: 2.6.2 and 3.0.1 (CPython) > > > The code: > > #!/usr/bin/env python > > def remaining_peg (peg1, peg2): > > ? ? ? ?return (6 - peg1 - peg2) > > > def hanoi (num_discs, start, end): > > ? ? ? ?if (1 == num_discs): > > ? ? ? ? ? ? ? ?print "Top of peg {0} to peg {1}".format(start,end) # used print() > > for Py 3.0.1 > > > ? ? ? ?else: > > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), start, (remaining_peg (start, end))) > > ? ? ? ? ? ? ? ?hanoi (1, start, end) > > ? ? ? ? ? ? ? ?hanoi ((num_discs - 1), (remaining_peg (start, end)), end) > > > hanoi(20,2,3) > > > The times: ? ? ? ? ? ?real ? ? ? ? ?usr ? ? ? ? ?sys > > Python 2.6.2 ? ? ? 7.994s ? ?3.336s ? 3.296s > > Python 3.0.1 ? ? ? 55.302s ?38.024s 5.876s > > > What happened to Python? > > I/O in Python 3.0 is known to be slow, because the bulk of the > implementation is in Python (rather than C). Python 3.1 addresses > this. Here are some tests of 2.6.1 vs 3.1rc2. The first tests have the > print commented out, the second are with the print, redirected to the > null device. The tests are on a pretty slow Windows XP SP2 laptop. > > >timer & \Apps\Python26\python.exe hanoi.py & timer > > Timer 1 on: 15:54:53 > Timer 1 off: 15:54:57 ?Elapsed: 0:00:03.88 > > >timer & \Apps\Python31\python.exe hanoi.py & timer > > Timer 1 on: 15:57:05 > Timer 1 off: 15:57:09 ?Elapsed: 0:00:03.67 > > >timer & (\Apps\Python26\python.exe hanoi.py >nul) & timer > > Timer 1 on: 15:57:44 > Timer 1 off: 15:58:14 ?Elapsed: 0:00:29.91 > > >timer & (\Apps\Python31\python.exe hanoi.py >nul) & timer > > Timer 1 on: 15:58:38 > Timer 1 off: 15:59:09 ?Elapsed: 0:00:30.63 > > Nothing much in it. > > Paul. Thank you for clearing that up. From http Fri Jun 26 13:25:17 2009 From: http (Paul Rubin) Date: 26 Jun 2009 10:25:17 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <7x3a9mkiv6.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > (In particular, WRT the bisect module, although insertion and deletion > are O(N), the constant factor for doing a simple memory move at C speed > swamps bytecode until N gets very large -- and we already have > collections.deque() for some other common use cases.) Again, at least in my case, I'd hope for an immutable structure. Also, "N very large" is likely to mean no more than a few thousand, which is small by today's standards. And the C speed difference goes away completely if the tree implementation is also in C. Hedgehog Lisp has a good functional AVL tree implementation written in C, that I might try to wrap with the Python C API sometime. I think it is LGPL licensed though, not so good for the Python stdlib. From daniel at stutzbachenterprises.com Fri Jun 26 13:33:31 2009 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Fri, 26 Jun 2009 12:33:31 -0500 Subject: No trees in the stdlib? In-Reply-To: References: <4A4462E6.7080700@netcabo.pt> <50697b2c0906252323y60c237d0i44725e841ad29ed5@mail.gmail.com> Message-ID: On Fri, Jun 26, 2009 at 1:54 AM, Miles Kaufmann wrote: > On Jun 26, 2009, at 2:23 AM, Chris Rebert wrote: > >> That's pretty much the bisect module in a nutshell. It manipulates a >> sorted list using binary search. >> > > With O(n) insertions and removals, though. A decent self-balancing binary > tree will generally do those in O(log n). FWIW, you can get O(log**2 n) inserts and deletes by using the bisect module on my blist extension type (http://pypi.python.org/pypi/blist/). It's a drop-in replacement for list(), with different asymptotic performance characteristics. Copying a blist is O(1), so the functional-programming types can wrap it in non-mutating semantics if they so choose. ;) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From trentm at activestate.com Fri Jun 26 13:40:12 2009 From: trentm at activestate.com (Trent Mick) Date: Fri, 26 Jun 2009 10:40:12 -0700 Subject: "The system cannot execute the specified program." In-Reply-To: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: <4A4507FC.9040105@activestate.com> Tim Slattery wrote: > Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." > > I should add that before I knew about our shared installation, I > downloaded the AS distribution of Python 2.6 from ActiveState. Their > install procedure is a *.bat file that calls Python to put everything > in the right place. When the bat file tries to invoke Python, I get > the same message. > I'm jumping in mid-thread here, so apologies if I've missed something. Just want to clarify something: the main AS distribution of Python (ActivePython) for Windows is an MSI. There is sometimes a .zip file with an install.bat -- but that isn't really intended for wide use. Is that what you are referring to here? Cheers, Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From backup95 at netcabo.pt Fri Jun 26 14:57:42 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Fri, 26 Jun 2009 19:57:42 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A451A26.402@netcabo.pt> Aahz wrote: > In article <006078f0$0$9721$c3e8da3 at news.astraweb.com>, > Steven D'Aprano wrote: > >> Hash tables (dicts) are useful for many of the same things that trees are >> useful for, but they are different data structures with different >> strengths and weaknesses, and different uses. To argue that we don't need >> trees because we have dicts makes as much sense as arguing that we don't >> need dicts because we have lists. >> > > The problem is that trees are like standards: there are so many to choose > from. Each has its own tradeoffs, and because Python dicts and lists can > substitute for many of the traditionals uses of trees, the tradeoffs are > less clear. I think nobody would object to adding trees to the standard > library, but it will certainly require a clear PEP, preferably with a > pointer to an existing PyPI library that has acquired real-world use. > > > Wish I had asked this before this year's GSoC started. What's lacking is an associative array that preserves ordering, doesn't require a hash function and has fast insertions and deletions in O(log(n)). The particular algorithm to achieve this is a secondary issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault for having opened the topic with simply "trees" instead, it would have avoided this vagueness problem, but I'm genuinely surprised to know there are no data structures that efficiently support such a common need in Python. And I really enjoy the using this language. From ffernand.list at gmail.com Fri Jun 26 15:09:35 2009 From: ffernand.list at gmail.com (Filipe Fernandes) Date: Fri, 26 Jun 2009 15:09:35 -0400 Subject: alternative to JoinableQueue's please Message-ID: I'm currently using the multiprocessing package and I'm hugely impressed at its simplicity (thanks very much Jesse Noller). Although, it seems that there's a bug in JoinableQueue's which renders using it pointless over a regular Queue as per Issue 4660 http://bugs.python.org/issue4660 To re-iterate... task_done() which is to be called for each get() throws the exception: ValueError: task_done() called too many times every once in a while. The reasons for this are outlined by Brian in the issue above, but no confirmation has been provided. The reasons for using JoinableQueue I think are obvious. I want to block the main processing using queue.join() until the tasks that have been placed on the queue have been finished by the worker processes. I can't be the only one experiencing this (besides Brian)... are there others who ran into this? Are there work arounds (besides a home-brewed one) ? filipe From norseman at hughes.net Fri Jun 26 15:10:02 2009 From: norseman at hughes.net (norseman) Date: Fri, 26 Jun 2009 12:10:02 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: <4A451D0A.4030607@hughes.net> Scott David Daniels wrote: > norseman wrote: >> ... A note here: In reading the original posting I get symbols that >> are not >> familiar to me as alphabet. >> From the line in your original: >> Label(root, text='?????????').pack() >> I see text=' >> then an e with a goatee >> a capitol O with an accent symbol on top (') >> an a with a tail on the right >> a s with an accent on top >> an I do no not know what - maybe some sort of l with a >> slash through the middle >> a couple of z with accents on top >> a capitol C with an accent on top >> a n with a short bar on top > > Here's something to try in any future circumstances: > > Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > >>> import unicodedata as ud > >>> for ch in '?????????': > print('%3d %4x %c %s' % (ord(ch), ord(ch), ch, ud.name(ch))) > > > 281 119 ? LATIN SMALL LETTER E WITH OGONEK > 243 f3 ? LATIN SMALL LETTER O WITH ACUTE > 261 105 ? LATIN SMALL LETTER A WITH OGONEK > 347 15b ? LATIN SMALL LETTER S WITH ACUTE > 322 142 ? LATIN SMALL LETTER L WITH STROKE > 380 17c ? LATIN SMALL LETTER Z WITH DOT ABOVE > 378 17a ? LATIN SMALL LETTER Z WITH ACUTE > 263 107 ? LATIN SMALL LETTER C WITH ACUTE > 324 144 ? LATIN SMALL LETTER N WITH ACUTE > > --Scott David Daniels > Scott.Daniels at Acm.Org ============== Good thought, good idea, useful tool. BUT - compare your output to what I *see*. And I do not see any f3 anywhere except in the doc ref I copy/duped and in this file. I suspect the mail handlers all have some differences. I also suspect Window$ is still cooking it's outputs. It has a long history of saying one thing and doing another. I used to program exclusively in assembly. I know for a fact Window$ can and does lie. Little ones, not often, but like your f3. I don't have one. Not from the copy/paste of the original posting, not anywhere I have looked in reviewing possible cause/effect of the problem posted. I do have a C3 B3 byte pair after the 30 31 31 39 (0119) and before the 5C (\) that follows the 0119. MC shows it as a CAP-A with a tilde on top of it. Firefox shows it as a CAP-O with an accent on top. (Kids today call the Accent a single quote.) I do not know what Window$ program to guide you to for proper hex listings. I'm not even sure an accurate one exists. (No doubt someone will now list a few thousand of them. :) Maybe zipping and transferring the .zip will help - maybe not. I would like to know the results. Steve From walton.nathaniel at gmail.com Fri Jun 26 15:11:19 2009 From: walton.nathaniel at gmail.com (Nate) Date: Fri, 26 Jun 2009 12:11:19 -0700 (PDT) Subject: os.system vs subprocess References: <0e218526-8520-4afe-8380-55b106bb3183@s16g2000vbp.googlegroups.com> Message-ID: <197ef967-cec7-4d5e-8dda-5ebb087b6d88@y6g2000prf.googlegroups.com> I ended up going with this: http://code.activestate.com/recipes/440554/ seems to feed me new lines of output atleast before the subprocess finishes, with some adjustment of the time delays. I'll guess I'll just be packing winpy into the installer. Or something. From stefan_ml at behnel.de Fri Jun 26 15:14:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Jun 2009 21:14:25 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4a451e11$0$30225$9b4e6d93@newsspool1.arcor-online.net> Jo?o Valverde wrote: > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). > [...] > I'm genuinely surprised to know > there are no data structures that efficiently support such a common need > in Python. That's because it's simply not that a common need (in the sense that there isn't a suitable alternative). I know that Trees have their use cases where they really shine, but in surprisingly many cases a dict, a set, a list or a combination of them will do just fine. And if you find a case where those just don't fit, you may need a database anyway. Stefan From aahz at pythoncraft.com Fri Jun 26 15:14:42 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 12:14:42 -0700 Subject: No trees in the stdlib? References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: In article , =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: > >What's lacking is an associative array that preserves ordering, doesn't >require a hash function and has fast insertions and deletions in >O(log(n)). The particular algorithm to achieve this is a secondary >issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault >for having opened the topic with simply "trees" instead, it would have >avoided this vagueness problem, but I'm genuinely surprised to know >there are no data structures that efficiently support such a common need >in Python. And I really enjoy the using this language. Why AVL/RBT instead of B*? It's not that simple.... Another problem is that unless the tree is coded in C, the constant factors are going to swamp algorithmic complexity for many use cases -- that in turn makes it more difficult to deploy a PyPI library for real-world testing. Anyway, I'm *not* trying to discourage you, just explain some of the roadblocks to acceptance that likely are why it hasn't already happened. If you're serious about pushing this through, you have two options: * Write the code and corresponding PEP yourself (which leads to the second option, anyway) * Lobby on the python-ideas mailing list -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From pavlovevidence at gmail.com Fri Jun 26 15:32:59 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 26 Jun 2009 12:32:59 -0700 (PDT) Subject: No trees in the stdlib? References: <4A4462E6.7080700@netcabo.pt> <4a446f54$0$32682$9b4e6d93@newsspool2.arcor-online.net> Message-ID: On Jun 26, 7:35?am, Hallvard B Furuseth wrote: > Stefan Behnel writes: > >Jo?o Valverde wrote: > >> Besides some interface glitches, like returning None > >> on delete if I recall correctly. > > > That's actually not /that/ uncommon. Operations that change an object are > > not (side-effect free) functions, so it's just purity if they do not have a > > return value. > > It's purity that they don't return the modified tree/dict/whatever. > They can still return the deleted element and remain pure. Correct, dict.pop does exactly this. Carl Banks From wong_powah at yahoo.ca Fri Jun 26 15:43:05 2009 From: wong_powah at yahoo.ca (powah) Date: Fri, 26 Jun 2009 12:43:05 -0700 (PDT) Subject: change the first character of the line to uppercase in a text file Message-ID: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> How to change the first character of the line to uppercase in a text file? e.g. input is: abc xyz Bd ef gH ij output should be: Abc xyz Bd ef GH ij From robert.kern at gmail.com Fri Jun 26 15:44:29 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Jun 2009 14:44:29 -0500 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: On 2009-06-26 02:17, Ulrich Eckhardt wrote: > Robert Kern wrote: >> I wish people would stop representing decimal floating point arithmetic as >> "more accurate" than binary floating point arithmetic. > > Those that failed, learned. You only see those that haven't learnt yet. > > Dialog between two teachers: > T1: Oh those pupils, I told them hundred times! when will they learn? > T2: They did, but there's always new pupils. Unfortunately, I keep seeing people who claim to be old hands at floating point making these unlearned remarks. I have no issue with neophytes like the OP expecting different results and asking questions. It is those who answer them with an air of authority that need to take a greater responsibility for knowing what they are talking about. I lament the teachers, not the pupils. -- 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 kee at kagi.com Fri Jun 26 15:56:24 2009 From: kee at kagi.com (Kee Nethery) Date: Fri, 26 Jun 2009 12:56:24 -0700 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: First, thanks to everyone who responded. Figured I'd test all the suggestions and provide a response to the list. Here goes ... On Jun 25, 2009, at 7:38 PM, Nobody wrote: > Why do you need an ElementTree rather than an Element? XML(string) > returns > the root element, as if you had used et.parse(f).getroot(). You can > turn > this into an ElementTree with e.g. et.ElementTree(XML(string)). I tried this: et.ElementTree(XML(theXmlData)) and it did not work. I had to modify it to this to get it to work: et.ElementTree(et.XML(theXmlData)) >> formPostData = cgi.FieldStorage() >> theXmlData = formPostData['theXml'].value >> theXmlDataTree = >> et >> .parse >> (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) > > If you want to treat a string as a file, use StringIO. I tried this: import StringIO theXmlDataTree = et.parse(StringIO.StringIO(theXmlData)) orderXml = theXmlDataTree.findall('purchase') and it did work. StringIO converts the string into what looks like a file so parse can process it as a file. Cool. On Jun 25, 2009, at 7:47 PM, unayok wrote: > I'm not sure what you're expecting. It looks to me like things are > working okay: > > My test script: > > [snip] I agree your code works. When I tried: theXmlDataTree = et.fromstring(theXmlData) orderXml = theXmlDataTree.findall('purchase') When I modified mine to programmatically look inside using the "for element in theXmlDataTree" I was able to see the contents. The debugger I am using does not offer me a window into the ElementTree data and that was part of the problem. So yes, et.fromstring is working correctly. It helps to have someone show me the missing step needed to confirm the code works and the IDE does not. On Jun 25, 2009, at 8:04 PM, Carl Banks wrote: > I believe you are misunderstanding something. et.XML and > et.fromstring return Elements, whereas et.parse returns an > ElementTree. These are two different things; however, both of them > "contain all the XML". In fact, an ElementTree (which is returned by > et.parse) is just a container for the root Element (returned by > et.fromstring)--and it adds no important functionality to the root > Element as far as I can tell. Thank you for explaining the difference. I absolutely was misunderstanding this. > Given an Element (as returned by et.XML or et.fromstring) you can pass > it to the ElementTree constructor to get an ElementTree instance. The > following line should give you something you can "play with": > > theXmlDataTree = et.ElementTree(et.fromstring(theXmlData)) Yes this works. On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote: > If you want to parse a document from a file or file-like object, use > parse(). Three use cases, three functions. The fourth use case of > parsing a > document from a string does not have its own function, because it is > trivial to write > > tree = parse(BytesIO(some_byte_string)) :-) Trivial for someone familiar with the language. For a newbie like me, that step was non-obvious. > If what you meant is actually parsing from a byte string, this is > easily > done using BytesIO(), or StringIO() in Py2.x (x<6). Yes, thanks! Looks like BytesIO is a v.3.x enhancement. Looks like the StringIO does what I need since all I'm doing is pulling the unicode string into et.parse. Am guessing that either would work equally well. >> theXmlDataTree = > et > .parse > (makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) > > This will not work because ET cannot parse from unicode strings > (unless > they only contain plain ASCII characters and you happen to be using > Python > 2.x). lxml can parse from unicode strings, but it requires that the > XML > must not have an encoding declaration (which would render it non > well-formed). This is convenient for parsing HTML, it's less > convenient for > XML usually. Right for my example, if the data is coming in as UTF-8 I believe I can do: theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding ='utf-8') Again, as a newbie, thanks to everyone who took the time to respond. Very helpful. Kee From Slattery_T at bls.gov Fri Jun 26 16:12:45 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 16:12:45 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: Trent Mick wrote: >Tim Slattery wrote: >> Tim Slattery wrote: >> >>> Our office has a copy of Python 3.0 installed on a network share >>> device. When I try to run it I get this message: "The system cannot >>> execute the specified program." >> >> I should add that before I knew about our shared installation, I >> downloaded the AS distribution of Python 2.6 from ActiveState. Their >> install procedure is a *.bat file that calls Python to put everything >> in the right place. When the bat file tries to invoke Python, I get >> the same message. >> > >I'm jumping in mid-thread here, so apologies if I've missed something. >Just want to clarify something: the main AS distribution of Python >(ActivePython) for Windows is an MSI. Given the way my machine here is locked down, I'm pretty sure I couldn't run the *.msi file. >There is sometimes a .zip file with an install.bat -- but that isn't >really intended for wide use. Is that what you are referring to here? That's what it is. They give you a choice of MSI or AS. The AS choice is a zip file that you unzip, then run the bat file on the top level. There's no indication that it's "not intended for wide use". -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From Slattery_T at bls.gov Fri Jun 26 16:14:25 2009 From: Slattery_T at bls.gov (Tim Slattery) Date: Fri, 26 Jun 2009 16:14:25 -0400 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: <2uaa45l8vefaac4evsji8nqifbm3bgleru@4ax.com> Duncan Booth wrote: >Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." >> >> When I googled that message, the links that came up had to do with >> missing DLLs. So I fired up Dependency Walker and found out that there >> were indeed DLLs that it needed that the OS couldn't find. So I >> supplied those DLLs. And it still gives the same message, even though >> Dependency Walker is now happy. >> >> Does anybody have a clue what might cause this amazingly uninformative >> message? > >Are you using Vista? No Vista involved. My machine is XP Pro. The server is some MS server OS, I'm not sure which one. >Alternatively for a non-Vista wild guess, could it be that Python 3.0 is >loading some libraries that use .Net and is therefore triggering the 'code >access security' which prevents the running of .Net applications from a >network share? I saw nothing that remotely resembled that message. -- Tim Slattery Slattery_T at bls.gov http://members.cox.net/slatteryt From trentm at activestate.com Fri Jun 26 16:40:08 2009 From: trentm at activestate.com (Trent Mick) Date: Fri, 26 Jun 2009 13:40:08 -0700 Subject: "The system cannot execute the specified program." In-Reply-To: References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: <4A453228.1010705@activestate.com> Tim Slattery wrote: > That's what it is. They give you a choice of MSI or AS. The AS choice > is a zip file that you unzip, then run the bat file on the top level. > There's no indication that it's "not intended for wide use". Granted not much, other than it isn't listed in the main download tables: http://www.activestate.com/activepython/downloads/ and not discussed in the install notes: http://docs.activestate.com/activepython/2.6/installnotes.html Cheers, Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From emile at fenx.com Fri Jun 26 16:46:43 2009 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Jun 2009 13:46:43 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On 6/26/2009 12:43 PM powah said... > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij How far have you gotten? Emile From tjreedy at udel.edu Fri Jun 26 16:47:05 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Jun 2009 16:47:05 -0400 Subject: "The system cannot execute the specified program." In-Reply-To: <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> <0ot94591di6dl67ffo8bsnffqk1h95amta@4ax.com> Message-ID: Tim Slattery wrote: > Tim Slattery wrote: > >> Our office has a copy of Python 3.0 installed on a network share >> device. When I try to run it I get this message: "The system cannot >> execute the specified program." Slightly OT, but do try to replace that with 3.1 as soon as you can. Significant improvements in certain areas. From clp2 at rebertia.com Fri Jun 26 16:51:36 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 13:51:36 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <50697b2c0906261351l182bf503kf308141a28739d25@mail.gmail.com> On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij We're not in the business of doing homework. Some hints though: `s.upper()` converts the string in variable `s` to all upper case (e.g. "aBcD".upper() --> "ABCD") `for line in afile:` iterates over each line in a file object. `afile` is the file object and `line` gets assigned each line in turn. `s[x]` gets you the (x+1)-th character in the string `s` (e.g. "abcd"[2] --> "c") And here are the docs on working with files: http://docs.python.org/library/functions.html#open http://docs.python.org/library/stdtypes.html#file-objects That should be enough to get you started. Cheers, Chris -- http://blog.rebertia.com From python.list at tim.thechases.com Fri Jun 26 16:59:35 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 26 Jun 2009 15:59:35 -0500 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <4A4536B7.6060407@tim.thechases.com> powah wrote: > How to change the first character of the line to uppercase in a text > file? > e.g. > input is: > abc xyz > Bd ef > gH ij > > output should be: > Abc xyz > Bd ef > GH ij While you're asking the Python list, I'd just use GNU sed: sed -i 's/./\U&/' myfile.txt I don't know if the "\U"=="make the replacement uppercase" is a GNU-sed specific thing, but it works here on my Debian box's version 4.1.5 when I tested it. -tkc From Scott.Daniels at Acm.Org Fri Jun 26 17:30:14 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 14:30:14 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: powah wrote: > How to change the first character of the line to uppercase in a text > file? Here is an English hint on the above: The "How ... file" above is a noun phrase, and is not a sentence, never mind a question. Putting a question mark after the noun phrase does not make that phrase a question. "Would someone explain to me how ...file?" would be a question albeit inappropriate here, since you showed no work. By the way, that strange sentence structure usually clues me in that it is you again, apparently someone who does homework by posting to the list before attempting to work it out alone. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Fri Jun 26 17:37:37 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 26 Jun 2009 14:37:37 -0700 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: norseman wrote: > Scott David Daniels wrote: >> norseman wrote: >>> ... A note here: In reading the original posting I get ... >>> then an e with a goatee >> >> Here's something to try in any future circumstances: >> > Good thought, good idea, useful tool. > > BUT - compare your output to what I *see*. Have you considered font issues when printing? The best encoding will not show anything reasonable when printed with a font without the characters in question. I'm not saying I know its wrong, only that there is another issue to check. you might both swap outputs from the over-explict printing I used above. --Scott David Daniels Scott.Daniels at Acm.Org From python at rcn.com Fri Jun 26 17:44:16 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 14:44:16 -0700 (PDT) Subject: alternative to JoinableQueue's please References: Message-ID: [Filipe Fernandes] > The reasons for using JoinableQueue I think are obvious. ?I want to > block the main processing using queue.join() until the tasks that have > been placed on the queue have been finished by the worker processes. > > I can't be the only one experiencing this (besides Brian)... are there > others who ran into this? ?Are there work arounds (besides a > home-brewed one) ? Before Queue.task_done() and Queue.task_join() were added, other idioms were used. One technique is to use a second queue to track incomplete tasks. # adding work unfinished_tasks.put(None) q.put(task) # doing work t = q.get() f(t) unfinished_tasks.get() # waiting for unfinished tasks to complete while unfinished_tasks.qsize(): sleep(0.1) Raymond From charles at declareSub.com Fri Jun 26 17:46:51 2009 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 26 Jun 2009 17:46:51 -0400 Subject: Python simple web development In-Reply-To: <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <358348b30906260523i74411b8fr79424849926daa44@mail.gmail.com> Message-ID: <43A85C9B-C1D8-44C5-9744-37488EA0CD3D@declareSub.com> Or you could try my approach and write your own web app. Charles Yeomans From fetchinson at googlemail.com Fri Jun 26 17:56:01 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 26 Jun 2009 14:56:01 -0700 Subject: Python simple web development In-Reply-To: <4A43C3DB.7080504@simplistix.co.uk> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <99130696-de2c-4449-9776-aad7496d8747@p23g2000vbl.googlegroups.com> <4A43C3DB.7080504@simplistix.co.uk> Message-ID: >> What I've read about Django, Turbogears is that they are powerful >> enough to create big web-based portals, applications, etc. >> I need just simple forms without any sophisticated functionality. >> So again: why I am wrong ? > > Just because something is powerful doesn't mean you can't do simple > things with it. But complexity typically brings in an extra overhead that the OP might not need. I'm using turbogears for a project but for other simple things I don't, because the all the super powerful infrastructure of turbogears is just not necessary and slows things down without a reason. So I would recommend the OP against using either django or turbogears if the project is really small and will stay small in the future. This last point is hard to guess in advance though :) Cheers, Daniel > Have a read of the first few chapters of the Django book... > > http://www.djangobook.com/ -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From thomasmallen at gmail.com Fri Jun 26 18:08:03 2009 From: thomasmallen at gmail.com (Thomas Allen) Date: Fri, 26 Jun 2009 15:08:03 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: On Jun 25, 3:29?am, Private Private wrote: > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? I don't think anything's lighter than web.py. http://webpy.org/ Thomas From anishaapte at gmail.com Fri Jun 26 18:11:12 2009 From: anishaapte at gmail.com (jythonuser) Date: Fri, 26 Jun 2009 15:11:12 -0700 (PDT) Subject: Dynamic method invocation References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> <7acq2qF1u879sU1@mid.uni-berlin.de> Message-ID: <06cb50d2-57fb-4583-86b5-bb5704c5ab13@p23g2000vbl.googlegroups.com> Sorry for being a little vague. The last part of your response seems like what I would need. So here are more details on what I am trying to do. I have an extensible command shell in java where commmand providers plug in to supply new commands. I have a java class called MyShell which has execCommand method on it. Thus MyShell class does not have a concrete method on it for each command that it supports (e.g. grep, ls, cat etc) but a generic execCommand method that takes the name of the command and command params as arguments. clas MyShell () { Object execCommand (cmdName, params) { Object o = // find command object from command name return o.invoke (cmdName, params); } | Now I want to use this in jython. So I could do something like shell = MyShell() shell.exec ("grep", grep_args) What I would like to do is - shell.grep (grep_args) That way my users don't have to use some gorpy exec/invoke syntax for each command but think that shell has all the commands defined on it. So based on your example I am hoping that I can use getattr on "some" object that returns me "some" method that I can call. Does this make sense and is there a way to do this in jython? From anishaapte at gmail.com Fri Jun 26 18:16:01 2009 From: anishaapte at gmail.com (jythonuser) Date: Fri, 26 Jun 2009 15:16:01 -0700 (PDT) Subject: Dynamic method invocation References: <0ea2629e-e826-445f-9912-cae2400b7e97@y7g2000yqa.googlegroups.com> <7acq2qF1u879sU1@mid.uni-berlin.de> <06cb50d2-57fb-4583-86b5-bb5704c5ab13@p23g2000vbl.googlegroups.com> Message-ID: <68e7fe05-a44b-452e-be67-795c499577f5@n19g2000vba.googlegroups.com> Actually let me add that in jython I don't need to always use MyShell. It may be ok to wrapper it with some Jython class which then delegates to MyShell. So something like shell = MyJythonShell() shell.grep (grep_args) So MyJythonShell is defined in Jython which calls MyShell. Am wondering how to go about all this. From torriem at gmail.com Fri Jun 26 18:27:18 2009 From: torriem at gmail.com (Michael Torrie) Date: Fri, 26 Jun 2009 16:27:18 -0600 Subject: 3.2*2 is 9.6 ... or maybe it isn't? In-Reply-To: References: <4A43C4C9.1020601@gmail.com> Message-ID: <4A454B46.9030801@gmail.com> Robert Kern wrote: > In the former case, you can claim that decimal floating point is more accurate > *for those problems*. But as soon as you have a division operation, decimal > floating point has the same accuracy problems as binary floating point. True. Poor choice of words on my part. No matter what representation one chooses for numbers, we can remember that digits != precision. That's why significant digits were drilled into our heads in physics! That's the reason IEEE actually works out for most things that we need floating point for. From petr.messner at gmail.com Fri Jun 26 18:35:45 2009 From: petr.messner at gmail.com (Petr Messner) Date: Sat, 27 Jun 2009 00:35:45 +0200 Subject: Python simple web development In-Reply-To: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <67c97cd90906261535m6031ca4q943fca58a4518773@mail.gmail.com> What about Werkzeug? I like its simplicity (well, basically everything I need are WSGI request/response objects :) + some templating library). Petr 2009/6/25 Private Private : > Hi, > > I am looking for a python library which will allow me to do a simple > web development. I need to use > some forms (but nice looking :-) ), creating images based on input > from those forms, etc. I have read a bit about Django and TurboGears > but I am afraid that this is too big for my requirements (am I > wrong ?). > > Can you suggest anything ? From martin at v.loewis.de Fri Jun 26 18:40:18 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 27 Jun 2009 00:40:18 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4LmdnXlxf9Rf0NnXnZ2dnUVZ_sydnZ2d@pdx.net> Message-ID: <4a454e52$0$5115$9b622d9e@news.freenet.de> > And I do not see any f3 anywhere except in the doc ref I copy/duped and > in this file. That surely is a bug in your email program - get a better one. Take a look at http://mail.python.org/pipermail/python-list/2009-June/717666.html which displays correctly - maybe you can find a web browser that works. Regards, Martin From python at rcn.com Fri Jun 26 19:14:14 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 16:14:14 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: <01c79050-7be5-4f9c-bfcd-5e5b0d63f16e@s1g2000prd.googlegroups.com> [Tom Reed] > Why no trees in the standard library, if not as a built in? The sqlite3 module is built on a binary-tree structure. It can be used with persistent data or kept in-memory. The gdbm module has similar flexibility (see the F mode). FWIW, there are some ASPN implementing various types of trees (red-black, pairing heaps, etc). Raymond From python at rcn.com Fri Jun 26 19:22:18 2009 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Jun 2009 16:22:18 -0700 (PDT) Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: [Jo?o Valverde] > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). FWIW, Py3.1 has an OrderedDict() that preserves insertion order. It has O(1) lookup, deletion, insertion, and popping; and O(n) iteration. The ASPN Cookbook has equivalent code that runs on earlier versions of Python. > in Python. And I really enjoy the using this language. Am glad you like it. Raymond From piet at cs.uu.nl Fri Jun 26 19:28:35 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 01:28:35 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: >>>>> Sebastian Paj?k (SP) wrote: >SP> Maybe this picture will tell you more: >SP> http://files.getdropbox.com/u/1211593/tkinter.png >SP> The original script: >SP> http://files.getdropbox.com/u/1211593/test1.py >SP> May someone can confirm this osx behaviour? Yes, I get the same. But it is a problem of the underlying Tk implementation. I get the same strange behaviour in wish. Text widgets seem to have the same problem and it has to do with the use of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but this seems to cause other problems. See: http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862062 http://aspn.activestate.com/ASPN/Mail/Message/tcl-mac/2862807 -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From sjmachin at lexicon.net Fri Jun 26 19:52:21 2009 From: sjmachin at lexicon.net (John Machin) Date: Fri, 26 Jun 2009 16:52:21 -0700 (PDT) Subject: MultiValueDict? References: <4d67805e-2eed-4745-9e02-85797330013b@l5g2000vbp.googlegroups.com> Message-ID: On Jun 27, 2:09?am, BarakatX2 wrote: > png)>, , > ]}> There is nothing in this schema to suggest that any object has a .name attribute . > > ? ? for f in files['rqFiles']: > ? ? ? ? print f.name > > This gives me an "'str' object has no attribute 'name'" error. I don't > know if there is a special way to access MultiValueDicts values, but I > assumed each key has a list that is accessed just like any other list. You might start by telling us what a MultiValueDict is -- it's not from the standard Python distribution AFAICT. Consider asking the source of MultiValueDicts. Consider reading any docs for the module or package that defines MultiValueDicts. Consider inspecting some of the objects: print files['rqFiles'] # given your error message, probably get sth like ['foo.png', 'bar.png', ...] print files From spconv+m at gmail.com Fri Jun 26 19:55:22 2009 From: spconv+m at gmail.com (=?UTF-8?Q?Sebastian_Paj=C4=85k?=) Date: Sat, 27 Jun 2009 01:55:22 +0200 Subject: Tkinter - non-ASCII characters in text widgets problem In-Reply-To: References: <4a43da3e$0$14855$9b622d9e@news.freenet.de> <111013c20906251352o60bf7927i235e2052250e49b@mail.gmail.com> <4A43F2B4.30604@hughes.net> <111013c20906251547y3f34093bp39138d47ab0ced88@mail.gmail.com> <4A4411AB.1090302@hughes.net> <111013c20906260528x3cae807alee3f7d75e3c7c327@mail.gmail.com> Message-ID: <111013c20906261655o78611affxc68fd720e99e980a@mail.gmail.com> 2009/6/27 Piet van Oostrum : >>>>>> Sebastian Paj?k (SP) wrote: > >>SP> Maybe this picture will tell you more: >>SP> http://files.getdropbox.com/u/1211593/tkinter.png > >>SP> The original script: >>SP> http://files.getdropbox.com/u/1211593/test1.py > >>SP> May someone can confirm this osx behaviour? > > Yes, I get the same. But it is a problem of the underlying Tk > implementation. I get the same strange behaviour in wish. > > Text widgets seem to have the same problem and it has to do with the use > of QuickDraw rather than ATSUI in Tcl/Tk 8.4. Whereas 8.5 uses ATSUI but > this seems to cause other problems. > Uhhh. good to know It should be written somewhere with BIG letters so people like me whouldn't be confused... Thanks Sebastian From davidh at ilm.com Fri Jun 26 20:09:53 2009 From: davidh at ilm.com (David Hirschfield) Date: Fri, 26 Jun 2009 17:09:53 -0700 Subject: Replacing a built-in method of a module object instance Message-ID: <4A456351.5050902@ilm.com> I have a need to replace one of the built-in methods of an arbitrary instance of a module in some python code I'm writing. Specifically, I want to replace the __getattribute__() method of the module I'm handed with my own __getattribute__() method which will do some special work on the attribute before letting the normal attribute lookup continue. I'm not sure how this would be done. I've looked at all the documentation on customizing classes and creating instance methods...but I think I'm missing something about how built-in methods are defined for built-in types, and where I'd have to replace it. I tried this naive approach, which doesn't work: m = def __getattribute__(self, attr): print "modified getattribute:",attr return object.__getattribute__(self, attr) import types m.__getattribute__ = types.MethodType(__getattribute__,m) It seems to create an appropriately named method on the module instance, but that method isn't called when doing any attribute lookups, so something's not right. Any ideas? Is this even possible? Thanks in advance! -David -- Presenting: mediocre nebula. From abuse at 127.0.0.1 Fri Jun 26 20:48:50 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 00:48:50 GMT Subject: looking for a book on python Message-ID: Hello and thank you for taking your time to read this. I was interested in learning about python. In the long ago past I did learn some programing but I have not used any of it for years. I do remember some basics however so the book does not have to be for a total beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) I have been using Linux for a while and overall still don't know much about it but I can find my way. I have my system dual boot with windows vista. I do realize that everyone is different but I would like to see some suggestions and maybe reasons why you think it is good. I have looked for/searched and found a few different books but as my means are a bit limited right now I don't really want to buy several just one or maybe two books. Oh and if someone knows a place to find some used books of this sort that would be great (ebay I guess :) Thanks for your thoughts Randy theslayers9 gmail From ffernand.list at gmail.com Fri Jun 26 21:19:58 2009 From: ffernand.list at gmail.com (Filipe Fernandes) Date: Fri, 26 Jun 2009 21:19:58 -0400 Subject: alternative to JoinableQueue's please In-Reply-To: References: Message-ID: <4A4573BE.9030704@gmail.com> Raymond Hettinger wrote: > [Filipe Fernandes] >> The reasons for using JoinableQueue I think are obvious. I want to >> block the main processing using queue.join() until the tasks that have >> been placed on the queue have been finished by the worker processes. >> >> I can't be the only one experiencing this (besides Brian)... are there >> others who ran into this? Are there work arounds (besides a >> home-brewed one) ? > > Before Queue.task_done() and Queue.task_join() were added, other > idioms were used. > > One technique is to use a second queue to track incomplete tasks. > > # adding work > unfinished_tasks.put(None) > q.put(task) > > > # doing work > t = q.get() > f(t) > unfinished_tasks.get() > > > # waiting for unfinished tasks to complete > while unfinished_tasks.qsize(): > sleep(0.1) Thanks Raymond... yours is by far is the simplest and should have been an obvious solution. I didn't want to stray too far from what I had and this fits the bill. In case others are curious... I had looked at using the example in http://docs.python.org/library/multiprocessing.html#using-a-remote-manager to use the traditional Queue from module Queue which includes the join and task_done method calls. But creating a server process/thread just for that is rather over-kill. I also looked at using process pools asynchronously and waiting for the iterators to come back to determine if jobs were completed. But your solution is the simplest to implement. And easy enough to create a composite class containing the two queues to simulate the real one (although I have not tried the following, I'm not in the office right now). class JoinableQueue(object): def __init__(*args, **kwargs): self.__tasks = Queue() self.__queue = Queue(*args, **kwargs) def put(self, *args, **kwargs): self.__tasks.put(None) self.__queue.put(*args, **kwargs) def get(self, *args, **kwargs): return self.__queue.get(*args, **kwargs) def task_done(): try: self.__tasks.get(False) except Queue.Empty: raise ValueError('task_done called too many times') def join(): while not self.__tasks.empty(): sleep(0.1) [Add methods to simulate as required....] filipe ps: Thanks Raymond for the quick reply... and I feel rather apologetic for having bothered the list with this :S From tkjthingone at gmail.com Fri Jun 26 21:22:09 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 26 Jun 2009 18:22:09 -0700 Subject: looking for a book on python In-Reply-To: References: Message-ID: Hello, http://diveintopython.org/ - might be a good place to start. There are also a bunch of free programming books (some related to python, some not) to be found here: http://www.e-booksdirectory.com/programming.php#python - How good these books may or may not be is up to you to find out. Also, some uni's/collegs have taken to posting videos of classes online, that you can watch for free. An example would be: http://webcast.berkeley.edu/ - Go to courses, and then 'select semester' (upper right) and start looking through. Some years have more programming classes than others. Not explicitly python, but programming is programming is programming or something like that. Should be enough to get you started :) On Fri, Jun 26, 2009 at 5:48 PM, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > I was interested in learning about python. In the long ago past I > did learn some programing but I have not used any of it for years. I do > remember some basics however so the book does not have to be for a total > beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) > I have been using Linux for a while and overall still don't know > much about it but I can find my way. I have my system dual boot with > windows vista. > I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe two > books. > Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 gmail > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg at cosc.canterbury.ac.nz Fri Jun 26 21:43:40 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 27 Jun 2009 13:43:40 +1200 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <7albocF1vlgm3U1@mid.individual.net> Jo?o Valverde wrote: > What's lacking is an associative array that preserves ordering, doesn't > require a hash function and has fast insertions and deletions in > O(log(n)). Careful here -- you can't get away from the need for hashability just by using a tree. Even if you don't need to actually hash the values, it's still important that the criterion for ordering between objects doesn't change while they're in the tree, otherwise they'll be in the wrong place and won't be found by subsequent lookups. > I'm genuinely surprised to know > there are no data structures that efficiently support such a common need > in Python. Is it really all that common? If it truly were common, there probably *would* be something for it in the stdlib by now. What sort of things are you doing that you want such a structure for? Maybe we can suggest a way of using the existing data structures to achieve the same goal. -- Greg From wong_powah at yahoo.ca Fri Jun 26 21:58:27 2009 From: wong_powah at yahoo.ca (powah) Date: Fri, 26 Jun 2009 18:58:27 -0700 (PDT) Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Jun 26, 4:51?pm, Chris Rebert wrote: > On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: > > How to change the first character of the line to uppercase in a text > > file? > > e.g. > > input is: > > abc xyz > > Bd ef > > gH ij > > > output should be: > > Abc xyz > > Bd ef > > GH ij > > We're not in the business of doing homework. Some hints though: > > `s.upper()` converts the string in variable `s` to all upper case > (e.g. "aBcD".upper() --> "ABCD") > `for line in afile:` iterates over each line in a file object. `afile` > is the file object and `line` gets assigned each line in turn. > `s[x]` gets you the (x+1)-th character in the string `s` (e.g. > "abcd"[2] --> "c") > > And here are the docs on working with files:http://docs.python.org/library/functions.html#openhttp://docs.python.org/library/stdtypes.html#file-objects > > That should be enough to get you started. > > Cheers, > Chris > --http://blog.rebertia.com Thank you for your hint. This is my solution: f = open('test', 'r') for line in f: print line[0].upper()+line[1:], From aahz at pythoncraft.com Fri Jun 26 22:02:29 2009 From: aahz at pythoncraft.com (Aahz) Date: 26 Jun 2009 19:02:29 -0700 Subject: looking for a book on python References: Message-ID: In article , Randy Foiles wrote: > > I do realize that everyone is different but I would like to see some >suggestions and maybe reasons why you think it is good. I have looked >for/searched and found a few different books but as my means are a bit >limited right now I don't really want to buy several just one or maybe >two books. You could get the book I co-wrote (Python for Dummies), but honestly, I think you should try using some of the online tutorials first. The standard Python tutorial is aimed at people with some programing experience: http://docs.python.org/tutorial/index.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From sato.photo at gmail.com Fri Jun 26 22:22:27 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Fri, 26 Jun 2009 19:22:27 -0700 (PDT) Subject: Beginning with Python; the right choice? Message-ID: Hi, As you can imagine, I am new, both to this group and to Python. I have read various posts on the best book to buy or online tutorial to read and have started to go through them. I was wondering, as someone with virtually no programming experience (I am a photographer by trade), is Python the right language for me to try and learn? I do vaguely remember learning what I think was BASIC on some old Apple's back in elementary school (circa 1992). Would something like that (the name at least makes it SOUND easier) be more feasible? If I do choose to learn Python, are there any tutorials for the absolute beginner. I do not mean beginner to Python, but rather, beginner to programming. Someone who hasn't a clue what object oriented whatcha-ma-whoozit means. I ask again because I understand that content is always evolving and there might be new tutorials out there. Thanks! -Daniel Sato From amosanderson at gmail.com Fri Jun 26 22:50:22 2009 From: amosanderson at gmail.com (Amos Anderson) Date: Fri, 26 Jun 2009 21:50:22 -0500 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: In learning most programming languages, in my experience anyway, it's easy to get overwhelmed and want to give up. Python is easy enough that you should be able to pick it to a point that it will be useful to you while still learning the more advanced features. Python generally teaches good programming practices and I can see easily moving from Python to a more advanced language. BASIC is so far removed from modern languages that, IMO, it would make it difficult to transition to a modern language like C, C++ or Java. Python.org has a tutorial that should get you going. It seems to assume some programming knowledge but I think it's clear enough that even an absolute beginner could learn from it. http://docs.python.org/tutorial/index.html I learned C++ coming from Applesoft BASIC and Tandy Coco3 BASIC. I got a Sam's Teach Yourself book to do it. I really don't recommend that approach to anybody. It was very hard for me to understand the concepts necessary to make good use of C++. If I had only known about Python. On Fri, Jun 26, 2009 at 9:22 PM, sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Sat Jun 27 00:09:04 2009 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Jun 2009 21:09:04 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On Jun 26, 9:22?pm, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? Yes, absolutely. > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? No, go with Python. You can still get BASIC today, but it is usually far different from what you saw on early Apples. If you have Excel, try doing some macro programming to get a feel for what BASIC is like. Excel's macro language is actually Visual Basic for Applications. I use it extensively, not because it's a wonderful language, but because I have things that need getting done in Excel, such as looking at the contents of a cell and deciding which of the Inhalation vs. Ingestion TACO standard has been exceeded and performing formatting accordingly. Nice to have that kind of power on your spreadsheet when you need it. But away from Excel, I drop Visual Basic like a live grenade. I do math research as a hobby and Excel even with VBA can't hold a candle to what I can do in Python. > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ? I've been using Python for 10 years and have never once done any object-oriented programming, so don't be intimidated by the fact that Python has it. You don't HAVE to use it. Sure, it would nice to learn it, but it need not stand in your way. > I ask again because I understand > that content is always evolving and there might be new tutorials out > there. I'm not up on what's available, tutorial-wise, but I'm sure others will point you in a decent direction. > > Thanks! > > -Daniel Sato From tkjthingone at gmail.com Sat Jun 27 00:10:11 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Fri, 26 Jun 2009 21:10:11 -0700 Subject: postgreSQL python bindings - which one? Message-ID: Hi, I'm having a hard time deciding which set of PGSQL python bindings to go with. I don't know much about SQL to begin with, so the collage of packages of somewhat daunting. I'm starting a pet project in order to teach my self more, but I want to avoid getting off on the wrong foot and picking a package that is not going to be actively updated in the future. There seem to be several implementations * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. * http://www.pygresql.org/ - version 4.0 was released beginning of this year, update before that was sometime in 06 ( http://www.pygresql.org/changelog.html ) * http://python.projects.postgresql.org/ - first release was this month? The last one of those three looks to be the most promising, but I just can't tell for sure. Your input is appreciated :) Small side note: Why PGSQL? I have a pre-existing database with good documentation that I want to use as my playground. The pre-existing database is also related to the pet project (in that it has information that I will need to get at in order for the pet project to be of much use). Thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sat Jun 27 00:56:11 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 01:56:11 -0300 Subject: ctypes list library References: <7a8usgF1mj0ccU1@mid.uni-berlin.de> <05b94256-94c5-485e-ab4b-78ac54db9b61@l21g2000vba.googlegroups.com> <7a8vo1F1sas0bU1@mid.uni-berlin.de> <7a9bj5F1uhor1U1@mid.uni-berlin.de> <186cfa90-c309-4266-aae0-a89f9e49ef95@v4g2000vba.googlegroups.com> Message-ID: En Thu, 25 Jun 2009 06:15:57 -0300, luca72 escribi?: > Hello but find_library find only the lib. but if i need to load from a > list of lib how i have to do. > My proble is that i have 5 lib (a,b,c,d,e), if i load the a i get lib > b not found, if for first i load the b and than the a i get the same > error how i have to proceed. Try adding the parameter mode=ctypes.RTLD_GLOBAL when loading the library. -- Gabriel Genellina From backup95 at netcabo.pt Sat Jun 27 01:03:11 2009 From: backup95 at netcabo.pt (=?UTF-8?B?Sm/Do28gVmFsdmVyZGU=?=) Date: Sat, 27 Jun 2009 06:03:11 +0100 Subject: No trees in the stdlib? In-Reply-To: <7albocF1vlgm3U1@mid.individual.net> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> Message-ID: <4A45A80F.4090600@netcabo.pt> greg wrote: > Jo?o Valverde wrote: > >> What's lacking is an associative array that preserves ordering, >> doesn't require a hash function and has fast insertions and deletions >> in O(log(n)). > > Careful here -- you can't get away from the need for > hashability just by using a tree. Even if you don't > need to actually hash the values, it's still important > that the criterion for ordering between objects doesn't > change while they're in the tree, otherwise they'll > be in the wrong place and won't be found by subsequent > lookups. I'm aware :) Technically it's necessary to define a total ordering on the set of keys. > > > I'm genuinely surprised to know >> there are no data structures that efficiently support such a common >> need in Python. > > Is it really all that common? If it truly were common, > there probably *would* be something for it in the > stdlib by now. Obviously my experience differs, but those were my expectations. > > What sort of things are you doing that you want such > a structure for? Maybe we can suggest a way of using > the existing data structures to achieve the same > goal. > To answer the question of what I need the BSTs for, without getting into too many boring details it is to merge and sort IP blocklists, that is, large datasets of ranges in the form of (IP address, IP address, string). Originally I was also serializing them in a binary format (but no more after a redesign). I kept the "merge and sort" part as a helper script, but that is considerably simpler to implement. Please note that I'm happy with my code, it works well. I intended to implement it in C all along, even before trying Python. The python code was a side thing for testing/curiosity/fun. It prompted my original question but that was really about Python and the standard library itself, and I don't wish to waste anyone's time. As an anecdotal data point (honestly not trying to raise the "Python is slow" strawman), I implemented the same algorithm in C and Python, using pyavl. Round numbers were 4 mins vs 4 seconds, against Python (plus pyavl). Even considering I'm a worse Python programmer than C programmer, it's a lot. I know many will probably think I tried to do "C in Python" but that's not the case, at least I don' t think so. Anyway like I said, not really relevant to this discussion. From debatem1 at gmail.com Sat Jun 27 01:05:56 2009 From: debatem1 at gmail.com (CTO) Date: Fri, 26 Jun 2009 22:05:56 -0700 (PDT) Subject: No trees in the stdlib? References: Message-ID: On Jun 26, 1:29?am, Tom Reed wrote: > Whynotrees in the standard library, if not as a built in? I searched > the archive but couldn't find a relevant discussion. Seems like a > glaring omission considering the batteries included philosophy, > particularly balanced binary search trees.Nointerest,nogood > implementations, something other reason? Seems like a good fit for the > collections module. Can anyone shed some light? > > Thanks. > -- > Tom I've written a graph library (trees being rooted connected acyclic graphs) called Graphine that you could try. Obviously not a part of the standard library, but it (or networkx) will almost certainly do what you're looking for. You can find graphine at graphine.org, or networkx at networkx.lanl.gov. Geremy Condra From backup95 at netcabo.pt Sat Jun 27 01:06:53 2009 From: backup95 at netcabo.pt (=?UTF-8?B?Sm/Do28gVmFsdmVyZGU=?=) Date: Sat, 27 Jun 2009 06:06:53 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45A80F.4090600@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> Message-ID: <4A45A8ED.9090103@netcabo.pt> Jo?o Valverde wrote: > greg wrote: >> Jo?o Valverde wrote: >> >>> What's lacking is an associative array that preserves ordering, >>> doesn't require a hash function and has fast insertions and >>> deletions in O(log(n)). >> >> Careful here -- you can't get away from the need for >> hashability just by using a tree. Even if you don't >> need to actually hash the values, it's still important >> that the criterion for ordering between objects doesn't >> change while they're in the tree, otherwise they'll >> be in the wrong place and won't be found by subsequent >> lookups. > > I'm aware :) Technically it's necessary to define a total ordering on > the set of keys. >> >> > I'm genuinely surprised to know >>> there are no data structures that efficiently support such a common >>> need in Python. >> >> Is it really all that common? If it truly were common, >> there probably *would* be something for it in the >> stdlib by now. > Obviously my experience differs, but those were my expectations. >> >> What sort of things are you doing that you want such >> a structure for? Maybe we can suggest a way of using >> the existing data structures to achieve the same >> goal. >> > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). Originally I was also serializing them in a binary > format (but no more after a redesign). I kept the "merge and sort" > part as a helper script, but that is considerably simpler to implement. Crap, this sentence is totally confusing. I meant kept the merge code as a helper script and moved the rest to C, see next paragraph. > Please note that I'm happy with my code, it works well. I intended to > implement it in C all along (for a system daemon), even before trying > Python. The python code was a side thing for testing/curiosity/fun. It > prompted my original question but that was really about Python and the > standard library itself, and I don't wish to waste anyone's time. > > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and Python, > using pyavl. Round numbers were 4 mins vs 4 seconds, against Python > (plus pyavl). Even considering I'm a worse Python programmer than C > programmer, it's a lot. I know many will probably think I tried to do > "C in Python" but that's not the case, at least I don' t think so. > Anyway like I said, not really relevant to this discussion. > From gagsl-py2 at yahoo.com.ar Sat Jun 27 01:18:32 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 02:18:32 -0300 Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: En Wed, 24 Jun 2009 23:42:03 -0300, Carl Banks escribi?: > On Jun 24, 2:39?am, Norberto Lopes wrote: >> What do you think of dictionaries having a self lookup in their >> declaration? >> >> Be able to do this: >> >> a = {"foo" : "foo1", "bar" : a["foo"]} # or with another syntax >> >> instead of: >> >> a = { "foo" : "foo1" } >> a["bar"] = a["foo"] > > If you don't mind abusing Python syntax, you can do it using something > like this: > > > def DictMaker(name,bases,dct): > dct.pop('__metaclass__',None) > return dct > > > class a: > __metaclass__ = DictMaker > > home = "/home/test" > user1 = home + "/user1" > user2 = home + "/user2" > python_dev = user1 + "/py-dev" Certainly an abuse of syntax, but it's a nice trick! -- Gabriel Genellina From tjreedy at udel.edu Sat Jun 27 01:39:14 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 01:39:14 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? I consider Python the Basic of the 21st century. From cmpython at gmail.com Sat Jun 27 01:41:28 2009 From: cmpython at gmail.com (Che M) Date: Fri, 26 Jun 2009 22:41:28 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On Jun 26, 10:22?pm, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ?I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato I was in your exact position (well, I wasn't a photographer) less than three years ago, and I started Python from no programming knowledge other than, just as you said, BASIC from long, long ago. I picked it up enough to do what I want to do and have been quite happy with it. I learned (my small subset of) it here and there over a year or so I guess, just as I felt like it, as it was purely for hobby (and I still learn new stuff of course). If you are hellbent on learning it and have good instructional material, you could learn a lot in a good month, really. My best advice is to get a couple of ultra-basic short tutorials read/viewed, and then identify *what it is you want to use Python to do*. Any language can be used to essentially anything, and I feel it is better to learn *per task* than to try to simply learn the whole language. You will feel better having accomplished something in line with your goals. In terms of good tutorials for absolute beginners, here are two: Alan Gauld's Learning to Program http://www.freenetpages.co.uk/hp/alan.gauld/ ShowMeDo.com has lots of Python instructional videos, including this one for absolute beginners: http://showmedo.com/videotutorials/series?name=irgGc9ChS I also recommend the Python tutor list, which you can sign up for here: http://mail.python.org/mailman/listinfo/tutor So what is it that you want to use Python for? Che From clp2 at rebertia.com Sat Jun 27 01:41:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Jun 2009 22:41:35 -0700 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> On Fri, Jun 26, 2009 at 10:39 PM, Terry Reedy wrote: > sato.photo at gmail.com wrote: >> >> Hi, >> >> As you can imagine, I am new, both to this group and to Python. ?I >> have read various posts on the best book to buy or online tutorial to >> read and have started to go through them. ?I was wondering, as someone >> with virtually no programming experience (I am a photographer by >> trade), is Python the right language for me to try and learn? >> >> I do vaguely remember learning what I think was BASIC on some old >> Apple's back in elementary school (circa 1992). ?Would something like >> that (the name at least makes it SOUND easier) be more feasible? > > I consider Python the Basic of the 21st century. I don't know whether that's an insult or a compliment... :P Cheers, Chris -- http://blog.rebertia.com From backup95 at netcabo.pt Sat Jun 27 01:42:21 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sat, 27 Jun 2009 06:42:21 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A45B13D.3000805@netcabo.pt> Aahz wrote: > In article , > =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: > >> What's lacking is an associative array that preserves ordering, doesn't >> require a hash function and has fast insertions and deletions in >> O(log(n)). The particular algorithm to achieve this is a secondary >> issue. It's a BST for sure, AVL vs RBT vs something else. It's my fault >> for having opened the topic with simply "trees" instead, it would have >> avoided this vagueness problem, but I'm genuinely surprised to know >> there are no data structures that efficiently support such a common need >> in Python. And I really enjoy the using this language. >> > > Why AVL/RBT instead of B*? It's not that simple.... Another problem is > that unless the tree is coded in C, the constant factors are going to > swamp algorithmic complexity for many use cases -- that in turn makes it > more difficult to deploy a PyPI library for real-world testing. > I wouldn't consider anything other than C for such a module on efficiency alone, unless it was a prototype of course. But I have little knowledge about the Python C API. About B* trees, again not an expert but I don't see how the added complexity brings any noticeable advantage to implement the associative array data structure I mentioned. Simple is better. > Anyway, I'm *not* trying to discourage you, just explain some of the > roadblocks to acceptance that likely are why it hasn't already happened. > > If you're serious about pushing this through, you have two options: > > * Write the code and corresponding PEP yourself (which leads to the > second option, anyway) > > * Lobby on the python-ideas mailing list > Currently I don't have a strong need for this. I just believe it would be a benefit to a language I like a lot. Lobbying isn't my thing. I'd rather write code, but neither am I the most qualified person for the job. It would certainly be interesting and fun and challenging in a good way and a great way to learn some new stuff. But I would definitely need mentoring or asking some silly questions on the mailing list. Maybe I'll seriously consider it some other time. From stefan_ml at behnel.de Sat Jun 27 01:52:26 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Jun 2009 07:52:26 +0200 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4a45b39a$0$30228$9b4e6d93@newsspool1.arcor-online.net> Jo?o Valverde wrote: > I wouldn't consider anything other than C for such a module on > efficiency alone, unless it was a prototype of course. But I have little > knowledge about the Python C API. Cython is your true friend, if only for rapid prototyping. http://cython.org/ Stefan From __peter__ at web.de Sat Jun 27 01:52:38 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 07:52:38 +0200 Subject: Replacing a built-in method of a module object instance References: Message-ID: David Hirschfield wrote: > I have a need to replace one of the built-in methods of an arbitrary > instance of a module in some python code I'm writing. > > Specifically, I want to replace the __getattribute__() method of the > module I'm handed with my own __getattribute__() method which will do > some special work on the attribute before letting the normal attribute > lookup continue. > > I'm not sure how this would be done. I've looked at all the > documentation on customizing classes and creating instance methods...but > I think I'm missing something about how built-in methods are defined for > built-in types, and where I'd have to replace it. I tried this naive > approach, which doesn't work: > > m = > > def __getattribute__(self, attr): > print "modified getattribute:",attr > return object.__getattribute__(self, attr) > > import types > m.__getattribute__ = types.MethodType(__getattribute__,m) > > It seems to create an appropriately named method on the module instance, > but that method isn't called when doing any attribute lookups, so > something's not right. > Any ideas? Is this even possible? Special methods are looked up in the type, not the instance, and you cannot set attributes of the module type. As a workaround you can write a wrapper class and put that into the sys.modules module cache: >>> class Module(object): ... def __init__(self, module): ... self.__module = module ... def __getattr__(self, name): ... try: ... return getattr(self.__module, name.lower()) ... except AttributeError: ... def dummy(*args): pass ... return dummy ... >>> import shutil >>> import sys >>> sys.modules["shutil"] = Module(shutil) >>> import shutil >>> shutil.MOVE >>> shutil.yadda Peter From stefan_ml at behnel.de Sat Jun 27 02:06:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Jun 2009 08:06:01 +0200 Subject: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working In-Reply-To: References: Message-ID: <4a45b6c9$0$30231$9b4e6d93@newsspool1.arcor-online.net> Kee Nethery wrote: > On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote: >> parsing a >> document from a string does not have its own function, because it is >> trivial to write >> >> tree = parse(BytesIO(some_byte_string)) > > :-) Trivial for someone familiar with the language. For a newbie like > me, that step was non-obvious. I actually meant the code complexity, not the fact that you need to know BytesIO to do the above. >> If what you meant is actually parsing from a byte string, this is easily >> done using BytesIO(), or StringIO() in Py2.x (x<6). > > Yes, thanks! Looks like BytesIO is a v.3.x enhancement. It should be available in 2.6 AFAIR, simply as an alias for StringIO. > Looks like the > StringIO does what I need since all I'm doing is pulling the unicode > string into et.parse. As I said, this won't work, unless you are either a) passing a unicode string with plain ASCII characters in Py2.x or b) confusing UTF-8 and Unicode >>> theXmlDataTree = >> et.parse(makeThisUnicodeStringLookLikeAFileSoParseWillDealWithIt(theXmlData)) >> >> This will not work because ET cannot parse from unicode strings (unless >> they only contain plain ASCII characters and you happen to be using >> Python >> 2.x). lxml can parse from unicode strings, but it requires that the XML >> must not have an encoding declaration (which would render it non >> well-formed). This is convenient for parsing HTML, it's less >> convenient for XML usually. > > Right for my example, if the data is coming in as UTF-8 I believe I can do: > theXmlDataTree = et.parse(StringIO.StringIO(theXmlData), encoding > ='utf-8') Yes, although in this case you are not parsing a unicode string but a UTF-8 encoded byte string. Plus, passing 'UTF-8' as encoding to the parser is redundant, as it is the default for XML. Stefan From laplacian42 at gmail.com Sat Jun 27 02:25:55 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:25:55 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: On Jun 26, 6:08?pm, Thomas Allen wrote: > On Jun 25, 3:29?am, Private Private wrote: > > > > Can you suggest anything ? > > I don't think anything's lighter than web.py. > > http://webpy.org/ > My impression is that webpy is intended for experienced users who might otherwise just write all their own code, but who might as well use webpy instead because it's there. It's tutorial is very brief, and (if memory serves) webpy didn't even have any docs at all for a while. As Thomas suggests, maybe have a look at Werkzeug http://werkzeug.pocoo.org/ . They've got substantial docs (which look quite good) and even a nifty screencast. From gagsl-py2 at yahoo.com.ar Sat Jun 27 02:32:12 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 03:32:12 -0300 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: En Thu, 25 Jun 2009 14:07:19 -0300, Angus Rodgers escribi?: > On Thu, 25 Jun 2009 17:56:47 +0100, I burbled incoherently: > >> [...] does the new feature, >> by which a file becomes iterable, operate by some kind of coercion >> of a file object to a list object, via something like x.readlines()? > > Sorry to follow up my own post yet again (amongst my weapons is > a fanatical attention to detail when it's too late!), but I had > better rephrase that question: > > Scratch "list object", and replace it with something like: "some > kind of iterator object, that is at least already implicit in 2.1 > (although the term 'iterator' isn't mentioned in the index to the > 2nd edition of Beazley's book)". Something like that! 8-P Iterators were added in Python 2.2. An iterator is an object that can be iterated over; that is, an object for which "for item in some_iterator: ..." works. Files are their own iterators, yielding one line at a time. See PEP 234 http://www.python.org/dev/peps/pep-0234/ -- Gabriel Genellina From laplacian42 at gmail.com Sat Jun 27 02:38:23 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:38:23 -0700 (PDT) Subject: looking for a book on python References: Message-ID: On Jun 26, 8:48?pm, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > ? ? ? ? I was interested in learning about python. ?In the long ago past I did > learn some programing but I have not used any of it for years. ?I do > remember some basics however so the book does not have to be for a total > beginner. ?(C, C++, BASIC, Visual BASIC, Pascal and some ADA) > ? ? ? ? I have been using Linux for a while and overall still don't know much > about it but I can find my way. ?I have my system dual boot with windows > vista. > ? ? ? ? I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. ?I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe > two books. > ? ? ? ? Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 ? gmail The Oreilly "Python in a Nutshell" (2006, 2nd ed.) book is very good and will get you up to speed in short order. From backup95 at netcabo.pt Sat Jun 27 02:41:39 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sat, 27 Jun 2009 07:41:39 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45B13D.3000805@netcabo.pt> References: <006078f0$0$9721$c3e8da3@news.astraweb.com> <4A45B13D.3000805@netcabo.pt> Message-ID: <4A45BF23.9080609@netcabo.pt> Jo?o Valverde wrote: > Aahz wrote: >> In article , >> =?ISO-8859-1?Q?Jo=E3o_Valverde?= wrote: >> Anyway, I'm *not* trying to discourage you, just explain some of the >> roadblocks to acceptance that likely are why it hasn't already happened. >> >> If you're serious about pushing this through, you have two options: >> >> * Write the code and corresponding PEP yourself (which leads to the >> second option, anyway) >> >> * Lobby on the python-ideas mailing list >> > > Currently I don't have a strong need for this. I just believe it would > be a benefit to a language I like a lot. Lobbying isn't my thing. I'd > rather write code, but neither am I the most qualified person for the > job. It would certainly be interesting and fun and challenging in a > good way and a great way to learn some new stuff. But I would > definitely need mentoring or asking some silly questions on the > mailing list. Maybe I'll seriously consider it some other time. There's also another issue raise by Paul Rubin I wasn't even aware of, that the LGPL is not suitable for the standard library. Having to write a complete BST implementation in C is a drag. There are already good C libraries available. From laplacian42 at gmail.com Sat Jun 27 02:47:05 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Fri, 26 Jun 2009 23:47:05 -0700 (PDT) Subject: Python simple web development References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> Message-ID: <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> On Jun 27, 2:25?am, "laplacia... at gmail.com" wrote: > > As Thomas suggests, maybe have a look at Werkzeug ... Typo: s/Thomas/Petr/ From gagsl-py2 at yahoo.com.ar Sat Jun 27 03:08:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 04:08:13 -0300 Subject: os.walk and os.listdir problems python 3.0+ References: Message-ID: En Thu, 25 Jun 2009 11:15:15 -0300, Amos Anderson escribi?: > Thank you. That works very well when writing to a text file but what is > the > equivalent when writing the information to stdout using print? See this recent post: http://comments.gmane.org/gmane.comp.python.general/627850 -- Gabriel Genellina From virtualbuddha at gmail.com Sat Jun 27 03:28:39 2009 From: virtualbuddha at gmail.com (Virtual Buddha) Date: Sat, 27 Jun 2009 00:28:39 -0700 (PDT) Subject: Regular Expression Non Capturing Grouping Does Not Work. Message-ID: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Hello all, I am having some difficulties with the non-capturing grouping in python regular expression module. Even the code from the online documentation (http://docs.python.org/ howto/regex.html#non-capturing-and-named-groups) does not seem to work. As per the docs given in the link above this should happen (text copied from the page): >>> m = re.match("([abc])+", "abc") >>> m.groups() ('c',) >>> m = re.match("(?:[abc])+", "abc") >>> m.groups() () BUT, this is what I get: >>> m = re.match("([abc])+", "abc") >>> m.group() 'abc' >>> m = re.match("(?:[abc])+", "abc") >>> m.group() 'abc' I am using python 2.6 on opensuse 11.1. Any one know what I might be doing wrong? Or is this a bug? Thank you VB From __peter__ at web.de Sat Jun 27 03:45:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 09:45:47 +0200 Subject: Regular Expression Non Capturing Grouping Does Not Work. References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: Virtual Buddha wrote: > Hello all, > > I am having some difficulties with the non-capturing grouping in > python regular expression module. > > Even the code from the online documentation (http://docs.python.org/ > howto/regex.html#non-capturing-and-named-groups) does not seem to > work. > > As per the docs given in the link above this should happen (text > copied from the page): > >>>> m = re.match("([abc])+", "abc") >>>> m.groups() > ('c',) >>>> m = re.match("(?:[abc])+", "abc") >>>> m.groups() > () > > BUT, this is what I get: > >>>> m = re.match("([abc])+", "abc") >>>> m.group() > 'abc' >>>> m = re.match("(?:[abc])+", "abc") >>>> m.group() > 'abc' > > I am using python 2.6 on opensuse 11.1. Any one know what I might be > doing wrong? Or is this a bug? group != groups match.group() or match.group(0) gives you a special group that comprises the whole match. Regular capturing groups start at index 1, and only those are returned by match.groups(): >> re.match("(?:[abc])+", "abc").group() # one group 'abc' >>> re.match("(?:[abc])+", "abc").groups() # all capturing groups () Peter From milesck at umich.edu Sat Jun 27 03:46:01 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 27 Jun 2009 03:46:01 -0400 Subject: Regular Expression Non Capturing Grouping Does Not Work. In-Reply-To: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: <7CFA84EB-FF01-4ABF-ABC7-77FA0677DFC1@umich.edu> On Jun 27, 2009, at 3:28 AM, Virtual Buddha wrote: > Hello all, > > I am having some difficulties with the non-capturing grouping in > python regular expression module. > > Even the code from the online documentation (http://docs.python.org/ > howto/regex.html#non-capturing-and-named-groups) does not seem to > work. > > ... Notice that you are calling .group() on the match object instead of .groups(). Without any arguments, .group() is equivalent to .group(0), which means "return the entire matching string." http://docs.python.org/library/re.html#re.MatchObject.group -Miles From tjreedy at udel.edu Sat Jun 27 03:57:30 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 03:57:30 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> References: <50697b2c0906262241g6c64bf02q176668dcde19c3db@mail.gmail.com> Message-ID: Chris Rebert wrote: > On Fri, Jun 26, 2009 at 10:39 PM, Terry Reedy wrote: >> sato.photo at gmail.com wrote: >>> Hi, >>> >>> As you can imagine, I am new, both to this group and to Python. I >>> have read various posts on the best book to buy or online tutorial to >>> read and have started to go through them. I was wondering, as someone >>> with virtually no programming experience (I am a photographer by >>> trade), is Python the right language for me to try and learn? >>> >>> I do vaguely remember learning what I think was BASIC on some old >>> Apple's back in elementary school (circa 1992). Would something like >>> that (the name at least makes it SOUND easier) be more feasible? >> I consider Python the Basic of the 21st century. > > I don't know whether that's an insult or a compliment... :P At one time, Basic was the language that everyone learned, at least amateurs and beginners of the time. It was an important part of the microcomputer revolution. It made beginning programming available to anyone, in spite of its faults. From mail at microcorp.co.za Sat Jun 27 03:58:21 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 27 Jun 2009 09:58:21 +0200 Subject: Beginning with Python; the right choice? References: Message-ID: <00ac01c9f6fd$9f0da480$0d00a8c0@Hendrik> "Terry Reedy" wrote: > I consider Python the Basic of the 21st century. Oh Dear. Was it not Dijkstra who said that learning basic rotted your brain, or words more or less to that effect? And here I am, feeling rather dull lately... :-) To the OP: - Learning Python will get you going, and productive in the sense of actually making programmes that do simple stuff with files on disk, and so on, faster than anything else I know of. And the beauty of it is that no matter how far, and in which direction, you want to go, there is a pythonic way to do it. So none of your effort put in to learn some python thing is wasted - you can literally start small and build up at your own pace. And when you get stuck, you can come here or to the tutor list, and you will get friendly help. - Hendrik From Olivier.Darge at gmail.com Sat Jun 27 04:16:06 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 27 Jun 2009 01:16:06 -0700 (PDT) Subject: looking for a book on python References: Message-ID: On 27 juin, 02:48, Randy Foiles wrote: > Hello and thank you for taking your time to read this. > ? ? ? ? I was interested in learning about python. ?In the long ago past I did > learn some programing but I have not used any of it for years. ?I do > remember some basics however so the book does not have to be for a total > beginner. ?(C, C++, BASIC, Visual BASIC, Pascal and some ADA) > ? ? ? ? I have been using Linux for a while and overall still don't know much > about it but I can find my way. ?I have my system dual boot with windows > vista. > ? ? ? ? I do realize that everyone is different but I would like to see some > suggestions and maybe reasons why you think it is good. ?I have looked > for/searched and found a few different books but as my means are a bit > limited right now I don't really want to buy several just one or maybe > two books. > ? ? ? ? Oh and if someone knows a place to find some used books of this sort > that would be great (ebay I guess :) > Thanks for your thoughts > Randy theslayers9 ? gmail "Learning Python" http://oreilly.com/catalog/9780596513986/ new issue soon, covering 2.6 and 3 http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c the best book I read concerning Py understanding, well written. I would start with web content, then later would buy the fourth edition of "Learning Python". enjoy, Olivier From virtualbuddha at gmail.com Sat Jun 27 04:16:59 2009 From: virtualbuddha at gmail.com (Virtual Buddha) Date: Sat, 27 Jun 2009 01:16:59 -0700 (PDT) Subject: Regular Expression Non Capturing Grouping Does Not Work. References: <4214d9f5-aab2-4334-871b-040bb33b6f3c@e20g2000vbc.googlegroups.com> Message-ID: <63f2fd74-e7a1-401e-ac83-cff70192efdb@g23g2000vbr.googlegroups.com> > group != groups > > match.group() or match.group(0) gives you a special group that comprises the > whole match. Regular capturing groups start at index 1, and only those are > returned by match.groups(): > > >> re.match("(?:[abc])+", "abc").group() # one group > 'abc' > >>> re.match("(?:[abc])+", "abc").groups() # all capturing groups > > () > > Peter Aaargh! Should have caught that myself. Sorry for wasting all your time. Thank you Peter and Miles! (I am off to bed now. 4:10 am :) From gagsl-py2 at yahoo.com.ar Sat Jun 27 04:31:24 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 27 Jun 2009 05:31:24 -0300 Subject: YASS (Yet Another Success Story) References: <534f19f6-181c-42ee-803c-9bd867b6d053@n4g2000vba.googlegroups.com> Message-ID: En Sat, 20 Jun 2009 07:58:02 -0300, k3xji escribi?: > Started a project year ago with hard goals in mind : Developing a game > server which can handle thousands of clients simultaneously. [...] > I don't know Python at the time and only coded few simple projects > with it. And you still could write the server - that's very good (and shows your own great skills and Python ease of use...) > After profiling the code, it turns out most of the time is spent on > the following: > [...] 3) Redundant try-except's in all over place(Again our fault to make > the system stable, we have put some debug purposed-assert like try- > excepts in the main server flow.) I don't think this should make a difference. Setting up a try/except block usually has a very small cost (if no exception is actually raised). Care to tell us more details? > Just one note > about optimizing Python code: do not optimize Python code based on > your assumptions, just go and test if it really runs faster. I don't > want to go to details of this hint, but believe me making Python code > optimized may be very very tricky. Yes, specially if you came from a statically typed language; what looks "innocent" may have a significant cost (e.g. resolving obj.name), and what looks complicated may be fairly fast (e.g. a list comprehension). > It is then I decided to write up here this as a success story, as I am > very newcomer to Python but come up with a nearly commercial product > in a very short period of time and I don't think this is about my > personal characteristics and intelligence or so:), as I am old enough > to know/meet that there are much much more brilliant people than I am > and they also have similar experiences with Python. Thanks for sharing your experience! > So, one last note: every software project goes same tasks as above > often much much more officially and carefully, I would suggest > managers to see that just do not listen to the ordinary brain-washes. > Python is a great choice for easy developing, easy debugging, easy > maintaining and most importantly very very time-friendly. Of course > there will be tasks .n which Python is suitable, but hey, if it Python > is in the list, take it seriously. Nice summary! -- Gabriel Genellina From Olivier.Darge at gmail.com Sat Jun 27 04:32:55 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sat, 27 Jun 2009 01:32:55 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: On 27 juin, 04:22, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. ?I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). ?Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. ?I do not mean beginner to Python, but rather, > beginner to programming. ?Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. ?I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato hi, what is for you the purpose of learning programming ? what do you want to do ? at first glance, I think Python is a good choice for you, for its clarity. Olivier From Joachim at Strombergson.com Sat Jun 27 04:54:41 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Sat, 27 Jun 2009 10:54:41 +0200 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <4A45DE51.7000907@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! Che M wrote: > In terms of good tutorials for absolute beginners, here are two: > > Alan Gauld's Learning to Program > http://www.freenetpages.co.uk/hp/alan.gauld/ ... Also, don't miss the great Dive into Python: http://diveintopython.org/ A well written, easy to understand and fun (yes) introduction to all fantastic things in Python. - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpF3lEACgkQZoPr8HT30QG+jQCgq5ZpTS8ErLA9/YKIPBdJSNGp F80AoKBZHSCDfzPawcECKsYiIKbmLA5G =ML8w -----END PGP SIGNATURE----- From twirlip at bigfoot.com Sat Jun 27 05:03:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 10:03:43 +0100 Subject: It's ... References: <87ab3w72jg.fsf@daycos.com> Message-ID: On Sat, 27 Jun 2009 03:32:12 -0300, "Gabriel Genellina" wrote: >Iterators were added in Python 2.2. Just my luck. :-) >See PEP 234 http://www.python.org/dev/peps/pep-0234/ You've got to love a language whose documentation contains sentences beginning like this: "Among its chief virtues are the following four -- no, five -- no, six -- points: [...]" -- Angus Rodgers From ldo at geek-central.gen.new_zealand Sat Jun 27 05:27:07 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Jun 2009 21:27:07 +1200 Subject: "The system cannot execute the specified program." References: <1co94553odu2d0dfnn89fdkgbsvo5dv3br@4ax.com> Message-ID: In message <1co94553odu2d0dfnn89fdkgbsvo5dv3br at 4ax.com>, Tim Slattery wrote: > When I googled that message, the links that came up had to do with > missing DLLs. Ironic, isn't it, that Microsoft designs these messages to be non-technical to avoid putting off ordinary users, and yet it just ends up blanding them to the point of unintelligibility, so that you need to resort to Google to figure out what they mean. From Iris-und-Thomas-Lehmann at T-Online.de Sat Jun 27 05:47:48 2009 From: Iris-und-Thomas-Lehmann at T-Online.de (Thomas Lehmann) Date: Sat, 27 Jun 2009 02:47:48 -0700 (PDT) Subject: Fast Dictionary Access Message-ID: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Hi! In C++, programming STL you will use the insert method which always provides a position and a flag which indicates whether the position results from a new insertion or an exisiting element. Idea is to have one search only. if data.has_key(key): value = data[key] But this does mean (does it?) that the dictionary is searched two times! If so, can somebody show me how to do this in one step? From peter.mosley at talk21.com Sat Jun 27 05:52:44 2009 From: peter.mosley at talk21.com (peter) Date: Sat, 27 Jun 2009 02:52:44 -0700 (PDT) Subject: Python Imaging Library download link broken? Message-ID: Just got a new computer and I'm trying to download my favourite applications. All's well until I get to PIL, and here pythonware and effbot both return a 502 Proxy error. Is this just a temporary glitch, or something more serious? And if it's the latter, is there any alternative source? Peter From clp2 at rebertia.com Sat Jun 27 05:53:40 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Jun 2009 02:53:40 -0700 Subject: Fast Dictionary Access In-Reply-To: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <50697b2c0906270253t6a5dd942l3343b92ba86ac138@mail.gmail.com> On Sat, Jun 27, 2009 at 2:47 AM, Thomas Lehmann wrote: > Hi! > > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if ?data.has_key(key): > ? value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? Use exception handling: try: value = data[key] except KeyError: print "No such key" else: print "The value for that key is", value Cheers, Chris -- http://blog.rebertia.com From sato.photo at gmail.com Sat Jun 27 05:57:56 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Sat, 27 Jun 2009 02:57:56 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: Thank you for all of the links and advice. What do I want to learn Python for? Again, pardon me for my lack of relevant information. I am also a journalist (an out of work one at the moment, like so many others) and I feel that learning python could be useful for computer assisted reporting, that is, utilizing databases, creating interactive maps and the like. http://chicago.everyblock.com/crime/ I also am fond of the Ellington Content Management System, made using django, which, if I am not mistaken, is related to Python...in...some...way..lol. I'll figure it out? Any additional advice now that you know what I want to learn and why would be greatly appreciated. Oh and, if you need a photographer, www.danielsato.com! thanks again! -daniel From http Sat Jun 27 05:58:21 2009 From: http (Paul Rubin) Date: 27 Jun 2009 02:58:21 -0700 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7x63eigfr6.fsf@ruckus.brouhaha.com> Thomas Lehmann writes: > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? value = data.get(key, None) sets value to None if the key is not in the dictionary. You can use some other sentinel if None might actually be a value in the dictionary. One way to get a unique sentinel is: sentinel = object() You can also use exception handling (this is quite efficient in Python) as Chris Rebert mentioned. From twirlip at bigfoot.com Sat Jun 27 06:21:32 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:21:32 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah wrote: >On Jun 26, 4:51?pm, Chris Rebert wrote: >> On Fri, Jun 26, 2009 at 12:43 PM, powah wrote: >> > How to change the first character of the line to uppercase in a text >> > file? >> > [...] >> >> We're not in the business of doing homework. Some hints though: >> >> `s.upper()` converts the string in variable `s` to all upper case >> (e.g. "aBcD".upper() --> "ABCD") >> `for line in afile:` iterates over each line in a file object. >> [...] >> >> And here are the docs on working with files: >> http://docs.python.org/library/functions.html#open >> http://docs.python.org/library/stdtypes.html#file-objects >> >> That should be enough to get you started. > >Thank you for your hint. >This is my solution: >f = open('test', 'r') >for line in f: > print line[0].upper()+line[1:], I know this is homework, so I didn't want to say anything (especially as I'm a newcomer, also just starting to learn the language), but it seems OK to mention that if you hunt around some more in the standard library documentation, you'll find an even shorter way to write this. -- Angus Rodgers From twirlip at bigfoot.com Sat Jun 27 06:39:28 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:39:28 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah wrote: >Thank you for your hint. >This is my solution: >f = open('test', 'r') >for line in f: > print line[0].upper()+line[1:], Will your program handle empty lines of input correctly? -- Angus Rodgers From albert at spenarnc.xs4all.nl Sat Jun 27 06:48:03 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 10:48:03 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: In article <0244e76b$0$20638$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >Nathan Stoddard wrote: > >> The best way to become a good programmer is to program. Write a lot of >> code; work on some large projects. This will improve your skill more than >> anything else. > >I think there are about 100 million VB code-monkeys who prove that theory >wrong. > >Seriously, and without denigrating any specific language, you can program by >(almost) mindlessly following a fixed number of recipes and patterns. This >will get the job done, but it won't make you a good programmer. For programming practice I do the problems of http://projecteuler.net/ I'm on the Eulerians page (best performers on 25 last problems). There is not a single VB programmer in the top 100. (Lots of Python programmers, C-family, also Haskel, APL, LISP Algol, Forth, Perl and I repeat not a single VB programmer.) Currently the top place is a Python programmer. These programs may be very demanding, minutes on very fast systems. Bad algorithms take days, weeks or literally forever. Interestingly the factor 5 between Python and C is irrelevant compared to a good algorithm, apparently. >-- >Steven 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 twirlip at bigfoot.com Sat Jun 27 06:54:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 11:54:43 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah > wrote: > >>Thank you for your hint. >>This is my solution: >>f = open('test', 'r') >>for line in f: >> print line[0].upper()+line[1:], > >Will your program handle empty lines of input correctly? Strangely enough, it seems to do so, but why? -- Angus Rodgers From albert at spenarnc.xs4all.nl Sat Jun 27 06:58:13 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 10:58:13 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: In article <0050ecf7$0$9684$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >> said: > >> I think I'm paraphrasing Richard Feynman here, but the >> only way to truly understand something is to do it. > >An amazingly inappropriate quote for a *theoretical* physicist to have said. The remark of Feynman goes to the heart of science and mathematics. (Try understanding some number theory or string theory by just reading about it.) > >Whether Feynman did or didn't say that, it's clearly untrue: many people do >without understanding. Many people can cook, some people are expert cooks, This is even a classical lack of logic skills. Feynman says a->b, and you attack b->a. >-- >Steven > 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 albert at spenarnc.xs4all.nl Sat Jun 27 07:02:09 2009 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 27 Jun 2009 11:02:09 GMT Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: In article <7xocssvzrh.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >koranthala writes: >> Which are the classic books in computer science which one should >> peruse? >> I have (a) Code Complete (b) GOF (c) Art of programming. >> >> Art of programming was too tough for me - and I couldnt understand >> much. The other two were good books - I understood and implemented >> quite a bit from both. >> What are the other books which I should peruse? > >Code Complete and GOF are software engineering books but not really >CS books. TAOCP is a CS book but a bit old fashioned. Other classics: > >Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, >Ronald L. Rivest, and Clifford Stein. Thanks. I lost that title a while ago, must buy. Also "Numerical Recipe's in FORTRAN/Pascal/C" (Have they done Python yet?) > >Structure and Interpretation of Computer Programs by Harold Abelson >and Gerald Jay Sussman (online at mitpress.mit.edu/sicp) 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 __peter__ at web.de Sat Jun 27 07:02:47 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:02:47 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Angus Rodgers wrote: > On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: > >>On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >> wrote: >> >>>Thank you for your hint. >>>This is my solution: >>>f = open('test', 'r') >>>for line in f: >>> print line[0].upper()+line[1:], >> >>Will your program handle empty lines of input correctly? > > Strangely enough, it seems to do so, but why? Because there aren't any. When you read lines from a file there will always be at least the newline character. Otherwise it would indeed fail: >>> for line in "peter\npaul\n\nmary".splitlines(): ... print line[0].upper() + line[1:] ... Peter Paul Traceback (most recent call last): File "", line 2, in IndexError: string index out of range From twirlip at bigfoot.com Sat Jun 27 07:13:57 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:13:57 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten <__peter__ at web.de> wrote: >Angus Rodgers wrote: > >> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >> >>>Will your program handle empty lines of input correctly? >> >> Strangely enough, it seems to do so, but why? > >Because there aren't any. When you read lines from a file there will always >be at least the newline character. Otherwise it would indeed fail: > >>>> for line in "peter\npaul\n\nmary".splitlines(): >... print line[0].upper() + line[1:] >... >Peter >Paul >Traceback (most recent call last): > File "", line 2, in >IndexError: string index out of range Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be treated as a single character. -- Angus Rodgers From twirlip at bigfoot.com Sat Jun 27 07:16:34 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:16:34 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: <5qvb45l9nmhgtkij7j2p7lc2lcsjjf1hf2@4ax.com> On Sat, 27 Jun 2009 12:13:57 +0100, I wrote: >the \r\n sequence at the end of a Win/DOS file Of course, I meant the end of a line of text, not the end of the file. (I promise I'll try to learn to proofread my posts. This is getting embarrassing!) -- Angus Rodgers From sanal.vikram at gmail.com Sat Jun 27 07:18:58 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sat, 27 Jun 2009 04:18:58 -0700 (PDT) Subject: to use unicode strings only Message-ID: Hey gentlemen, I wanna make all the strings in my code unicode strings. How to do it without giving unicode switch 'u' before every string? From jure.erznoznik at gmail.com Sat Jun 27 07:33:25 2009 From: jure.erznoznik at gmail.com (=?UTF-8?Q?Jure_Erzno=C5=BEnik?=) Date: Sat, 27 Jun 2009 04:33:25 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: Norberto, While certainly useful, this kind of functionality contradicts the way today's "string" libraries work. What you are proposing isn't dict self referencing, but rather strings referencing other external data (in this case other strings from the same dict). When you write code like config = {"home" : "/home/test"} config["user1"] = config["home"] + "/user1" config["user1"] isn't stored in memory as config["home"] + "/user1", but as a concatenated string ("/home/test/user1"), composed of both those strings. The reference to original composing strings is lost at the moment the expression itself is evaluated to be inserted into the dict. There's no compiler / interpreter that would do this any other way. At least not that I know of. So best suggestion would be to simply do an object that would parse strings before returning them. In the string itself, you can have special blocks that tell your parser that they are references to other objects. You can take good old DOS syntax for that: "%variable%" or something more elaborate if "%" is used in your strings too much. Anyway, your code would then look like (one possible way): config = {"home" : "/home/test"} config["user1"] = "%config["home"]%" + "/user1" or config = {"home" : "/home/test", "user1" : "%config[\"home\"]%/user1"} The parser would then just match "%(something)%" and replace it with actual value found in referenced variable. Eval() can help you there. Maybe there's already something in Python's libraries that matches your need. But you sure better not expect this to be included in language syntax. It's a pretty special case. Jure From duncan.booth at invalid.invalid Sat Jun 27 07:40:53 2009 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jun 2009 11:40:53 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: Thomas Lehmann wrote: > Hi! > > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? That code actually does 3 dictionary lookups and creates a temporary object: the first lookup is to find the 'has_key' method, then it has to bind the method to data which involves creating a 'built-in method' object and then it calls it. Only then do you get the two lookups you expected. Replacing your code with: if key in data: value = data[key] reduces the overhead to two dictionary lookups, no temporary objects or function calls. The suggested alternative: value = data.get(key, None) also has two dictionary lookups: one to find the 'get' method and one to find the key, but as in the first case it also has the overhead of binding the method and then calling it. In other words the get method is often the clearest (and therefore best) way to write the code, but if performance matters do a check using the 'in' operator (or if you know the key lookup will fail only very rarely consider using try..except). In all of the above I'm assuming the code is actually inside a function accessing local variables otherwise accessing variables might involve yet more dictionary lookups. From twirlip at bigfoot.com Sat Jun 27 07:49:39 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 12:49:39 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: <0h0c45dggsmas6kt5bv9tfvl2mmv3sgatf@4ax.com> On Sat, 27 Jun 2009 12:13:57 +0100, I wrote: >Hmm ... the \r\n sequence at the end of a Win/DOS file seems to be >treated as a single character. For instance, if test001A.txt is this file: abc xyz Bd ef gH ij and test001E.py is this: f = open('test001A.txt', 'r') for line in f: print repr(line) then the output from "python test001E.py > temp.txt" is this: 'abc xyz\n' 'Bd ef\n' '\n' 'gH ij\n' and indeed the output from "print repr(f.read())" is this: 'abc xyz\nBd ef\n\ngH ij\n' How do you actually get to see the raw bytes of a file in Windows? OK, this seems to work: f = open('test001A.txt', 'rb') # Binary mode print repr(f.read()) Output: 'abc xyz\r\nBd ef\r\n\r\ngH ij\r\n' Indeed, when a Windows file is opened for reading in binary mode, the length of an "empty" line is returned as 2. This is starting to make some sense to me now. -- Angus Rodgers From __peter__ at web.de Sat Jun 27 07:49:57 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:49:57 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: Angus Rodgers wrote: > On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten > <__peter__ at web.de> wrote: > >>Angus Rodgers wrote: >> >>> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >>> >>>>Will your program handle empty lines of input correctly? >>> >>> Strangely enough, it seems to do so, but why? >> >>Because there aren't any. When you read lines from a file there will >>always be at least the newline character. Otherwise it would indeed fail: >> >>>>> for line in "peter\npaul\n\nmary".splitlines(): >>... print line[0].upper() + line[1:] >>... >>Peter >>Paul >>Traceback (most recent call last): >> File "", line 2, in >>IndexError: string index out of range > > Hmm ... the \r\n sequence at the end of a Win/DOS line > seems to be treated as a single character. Yes, but "\n"[1:] will return an empty string rather than fail. From python at mrabarnett.plus.com Sat Jun 27 07:50:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 12:50:26 +0100 Subject: to use unicode strings only In-Reply-To: References: Message-ID: <4A460782.7010905@mrabarnett.plus.com> Gaudha wrote: > Hey gentlemen, > > I wanna make all the strings in my code unicode strings. How to do it > without giving unicode switch 'u' before every string? Use Python 3.1 instead. From olivergeorge at gmail.com Sat Jun 27 07:53:55 2009 From: olivergeorge at gmail.com (olivergeorge) Date: Sat, 27 Jun 2009 04:53:55 -0700 (PDT) Subject: Python Imaging Library download link broken? References: Message-ID: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Ditto. Anyone know what's happening with pythonware? (and why PIL is such a pain to install for that matter.) From __peter__ at web.de Sat Jun 27 07:54:19 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 13:54:19 +0200 Subject: to use unicode strings only References: Message-ID: MRAB wrote: > Gaudha wrote: >> I wanna make all the strings in my code unicode strings. How to do it >> without giving unicode switch 'u' before every string? > > Use Python 3.1 instead. or use from __future__ import unicode_literals in Python 2.6. From Iris-und-Thomas-Lehmann at T-Online.de Sat Jun 27 07:56:56 2009 From: Iris-und-Thomas-Lehmann at T-Online.de (Thomas Lehmann) Date: Sat, 27 Jun 2009 04:56:56 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: > read and have started to go through them. ?I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? Well, I'm a 100% C++ programmer but I like programming python for prototyping and tools. The answer on your question depends on your requirements. Some are saying that using Java and Swing are the best way to write applications. But nothing is for free except the most languages you can download and install. When you have no idea about software development you should have a look there first. Do you want some little scripting only to get some jobs easier done - well - you're right to use python. However - you should be aware of: When you have learned python a while and when you will be forced to programm C++, Java or C# you have to start again! Check your requirements... From twirlip at bigfoot.com Sat Jun 27 08:01:27 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 13:01:27 +0100 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: On Sat, 27 Jun 2009 13:49:57 +0200, Peter Otten <__peter__ at web.de> wrote: >Angus Rodgers wrote: > >> On Sat, 27 Jun 2009 13:02:47 +0200, Peter Otten >> <__peter__ at web.de> wrote: >> >>>Angus Rodgers wrote: >>> >>>> On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: >>>> >>>>>Will your program handle empty lines of input correctly? >>>> >>>> Strangely enough, it seems to do so, but why? >>> >>>Because there aren't any. When you read lines from a file there will >>>always be at least the newline character. Otherwise it would indeed fail: >>> >>>>>> for line in "peter\npaul\n\nmary".splitlines(): >>>... print line[0].upper() + line[1:] >>>... >>>Peter >>>Paul >>>Traceback (most recent call last): >>> File "", line 2, in >>>IndexError: string index out of range >> >> Hmm ... the \r\n sequence at the end of a Win/DOS > >line > >> seems to be treated as a single character. > >Yes, but "\n"[1:] will return an empty string rather than fail. Yes, I understood that, and it's logical, but what was worrying me was how to understand the cross-platform behaviour of Python with regard to the different representation of text files in Windows and Unix-like OSs. (I remember getting all in a tizzy about this the last time I tried to do any programming. That was in C++, about eight years ago. Since then, I've only written a couple of short BASIC programs for numerical analysis on a TI-84+ calculator, and I feel as if I don't understand ANYTHING any more, but I expect it'll come back to me. Sorry about my recent flurry of confused posts! If I have any silly questions of my own, I'll post then to the Tutor list, but in this instance, I imagined I knew what I was talking about, and didn't expect to get into difficulties ...) 8-P -- Angus Rodgers From philip.groeger at googlemail.com Sat Jun 27 08:12:20 2009 From: philip.groeger at googlemail.com (=?ISO-8859-1?Q?Philip_Gr=F6ger?=) Date: Sat, 27 Jun 2009 14:12:20 +0200 Subject: Animate 3D Surface Message-ID: <386f361c0906270512j3658727dvddf86cc92a6fd040@mail.gmail.com> Hi, is there a way to animate a 3D surface in python using matplotlib 0.98 / mayavi 3 (i have the python(xy) suite for windows) or vpython? In *vpython* I tried to adjust the included faces_heightfield.py demo. But didnt find a way to delete the old surface. I just add more... In *matplotlib* I heard that the 3d features are discontinued in 0.91 (or something like that) And in *mayavi* I played around with surf() but with the surf(fkt(z0,0)).mlab_source.set command the picture won't update + show (the demo file in the documentation didnt work as well). I know there are vpython and mayavi mailing lists, but I didn't get an answer from them. I just hope someone of you can give me some "construct" which will work. Maybe I am just using the wrong methods. thanks alot!! - Philip -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Jun 27 08:13:07 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 14:13:07 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <2ivb4513d59ngb2rcfsgkdkkjcq8j8r1ri@4ax.com> Message-ID: Angus Rodgers wrote: > Yes, I understood that, and it's logical, but what was worrying me > was how to understand the cross-platform behaviour of Python with > regard to the different representation of text files in Windows > and Unix-like OSs. (I remember getting all in a tizzy about this If you are concerned about line endings open the file in universal newline mode: f = open(filename, "rU") """ In addition to the standard fopen values mode may be 'U' or 'rU'. Python is usually built with universal newline support; supplying 'U' opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention '\n', the Macintosh convention '\r', or the Windows convention '\r\n'. All of these external representations are seen as '\n' by the Python program. If Python is built without universal newline support a mode with 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types seen. """ From marduk at letterboxes.org Sat Jun 27 08:27:36 2009 From: marduk at letterboxes.org (Albert Hopkins) Date: Sat, 27 Jun 2009 08:27:36 -0400 Subject: postgreSQL python bindings - which one? In-Reply-To: References: Message-ID: <1246105656.18806.2.camel@blackwidow.nbk> On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: > Hi, I'm having a hard time deciding which set of PGSQL python bindings > to go with. I don't know much about SQL to begin with, so the collage > of packages of somewhat daunting. I'm starting a pet project in order > to teach my self more, but I want to avoid getting off on the wrong > foot and picking a package that is not going to be actively updated in > the future. > > There seem to be several implementations > * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. > * http://www.pygresql.org/ - version 4.0 was released beginning of > this year, update before that was sometime in 06 > ( http://www.pygresql.org/changelog.html ) > * http://python.projects.postgresql.org/ - first release was this > month? > > The last one of those three looks to be the most promising, but I just > can't tell for sure. Your input is appreciated :) > psycopg2: http://initd.org/pub/software/psycopg/ Last release was in May. -a From magawake at gmail.com Sat Jun 27 08:44:12 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 08:44:12 -0400 Subject: csv blank fields Message-ID: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> I am using the csv package to parse a compressed .csv.gz file. So far its working perfectly fine but it fails when I have a missing value in on of the fields. For example, I have this Abc,def,,jkl Is it possible to fill the missing column with a null? I want, Abc,def,NULL,jkl TIA From http Sat Jun 27 08:58:35 2009 From: http (Paul Rubin) Date: 27 Jun 2009 05:58:35 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> Message-ID: <7x1vp56dfo.fsf@ruckus.brouhaha.com> Albert van der Horst writes: > >Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, > >Ronald L. Rivest, and Clifford Stein. > > Thanks. I lost that title a while ago, must buy. Wait a few months, a third edition is in the works. > Also "Numerical Recipe's in FORTRAN/Pascal/C" > (Have they done Python yet?) They haven't done Python AFAIK. I liked the C version but the licensing of the software is pretty evil and so I'm a bit turned off to the series these days. I think the hardcore numerics crowd never liked the book anyway. From http Sat Jun 27 08:59:39 2009 From: http (Paul Rubin) Date: 27 Jun 2009 05:59:39 -0700 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7xws6x4ytg.fsf@ruckus.brouhaha.com> Duncan Booth writes: > The suggested alternative: > > value = data.get(key, None) > > also has two dictionary lookups:... dg = data.get ... (inside loop): value = dg(key,None) From python at mrabarnett.plus.com Sat Jun 27 09:04:38 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 14:04:38 +0100 Subject: csv blank fields In-Reply-To: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> Message-ID: <4A4618E6.7000102@mrabarnett.plus.com> Mag Gam wrote: > I am using the csv package to parse a compressed .csv.gz file. So far > its working perfectly fine but it fails when I have a missing value in > on of the fields. > > For example, I have this > > Abc,def,,jkl > > Is it possible to fill the missing column with a null? > > I want, > Abc,def,NULL,jkl > What do you mean by "fails"? I get an empty string, which is what I'd expect. From magawake at gmail.com Sat Jun 27 09:33:09 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 09:33:09 -0400 Subject: csv blank fields In-Reply-To: <4A4618E6.7000102@mrabarnett.plus.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> well, I am actually loading the row into a fixed width array reader=csv.reader(fs) for s,row in enumerate(reader): t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) d[s]=t If there is a missing field, I get a problem in one of my rows On Sat, Jun 27, 2009 at 9:04 AM, MRAB wrote: > Mag Gam wrote: >> >> I am using the csv package to parse a compressed .csv.gz file. So far >> its working perfectly fine but it fails when I have a missing value in >> on of the fields. >> >> For example, I have this >> >> Abc,def,,jkl >> >> Is it possible to fill the missing column with a null? >> >> I want, >> Abc,def,NULL,jkl >> > What do you mean by "fails"? I get an empty string, which is what I'd > expect. > -- > http://mail.python.org/mailman/listinfo/python-list > From benjamin at python.org Sat Jun 27 09:43:17 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 13:43:17 +0000 (UTC) Subject: to use unicode strings only References: Message-ID: Gaudha gmail.com> writes: > > Hey gentlemen, > > I wanna make all the strings in my code unicode strings. How to do it > without giving unicode switch 'u' before every string? Or the -U flag, but that's probably a bad idea. From __peter__ at web.de Sat Jun 27 10:03:33 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 16:03:33 +0200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: Mag Gam wrote: > well, I am actually loading the row into a fixed width array > > reader=csv.reader(fs) > for s,row in enumerate(reader): > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > d[s]=t > > > If there is a missing field, I get a problem in one of my rows Please be specific. Describe what you want and what you get. If you give code make it self-contained so that others can run it without having to guess the values of the variables you introduce. If an exception occurs cut and paste the traceback into your post, too. Peter From darcy at druid.net Sat Jun 27 10:05:48 2009 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 27 Jun 2009 10:05:48 -0400 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <20090627100548.4440dd45.darcy@druid.net> On Sat, 27 Jun 2009 11:54:43 +0100 Angus Rodgers wrote: > On Sat, 27 Jun 2009 11:39:28 +0100, I asked rhetorically: > >>f = open('test', 'r') > >>for line in f: > >> print line[0].upper()+line[1:], > > > >Will your program handle empty lines of input correctly? > > Strangely enough, it seems to do so, but why? The clue is the comma at the end of the print statement. It is there because no lines are empty. They have at least a newline. -- 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 qq13234722 at gmail.com Sat Jun 27 10:12:22 2009 From: qq13234722 at gmail.com (=?GB2312?B?t+jNvMHp?=) Date: Sat, 27 Jun 2009 07:12:22 -0700 (PDT) Subject: Beginning with Python; the right choice? References: Message-ID: <96dd77f8-640f-4588-8c4a-008c5f28886c@n7g2000prc.googlegroups.com> On 6?27?, ??10?22?, "sato.ph... at gmail.com" wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato Oh, i think python is the best programing language for you ! From vasudevram at gmail.com Sat Jun 27 10:58:07 2009 From: vasudevram at gmail.com (vasudevram) Date: Sat, 27 Jun 2009 07:58:07 -0700 (PDT) Subject: file transfer in python References: <750b62b2-5a30-4727-a57e-1b2347357672@x29g2000prf.googlegroups.com> Message-ID: On Jun 26, 5:07?pm, Francesco Bochicchio wrote: > On 26 Giu, 13:38, jayesh bhardwaj wrote: > > > i am trying to find something useful in python to transfer html files > > from one terminal to other. Can this be done with some module or shall > > i start coding my own module using low level socket interface. If u > > know about some books on this topic or any online help then plz help. > > In the standard library there is ftplib, which allows your program to > act as a FTP client. Of course > the receiver end should have an FTP server installing and running. I > don't tink it can handle SFTP protocol, so > if you are concerned with security you should opt for someting else, > or protect your connection somehow (e.g. SSH tunneling). > > Or, if you have ssh (client and server) installed, you could simply > spawn a subprocess ( see the subprocess module for that ) which > execute one or more 'scp' commands. > > Ciao > ---- > FB There are many ways to do it; each may have it's own pros and cons. The low level sockets approach is feasible, as you said, and not too difficult, either. Read from each file and write the data to a socket from one end; read the data from the other end, and write it to a file. For the FTP approach, as Francesco said, the Python standard library has ftplib, which can help you with the client side, i.e. the sending side. If you don't have an FTP server on the receiving side, you could try using pyftpdlib to implement your own FTP server in Python: http://code.google.com/p/pyftpdlib/ Quoting from that URL: " Python FTP server library provides a high-level portable interface to easily write asynchronous FTP servers with Python. pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. It is used in projects like Google Chromium and Bazaar and included in Linux Fedora and FreeBSD package repositories. " Of course all that could be too much overhead; also, you would need permission to install your FTP daemon program written using pyftpdlib, on the receiving computer. As Francesco said, you could use the subprocess module and spawn a process that runs instances of scp. Another fairly easy way could be to write an XML-RPC client and server. The client, on the sending side, can send the data of each file to the server via an XML-RPC method call (in chunks, if needed, if the file is large); the server, on the receiving side, can read that data, and write it to a file on the file system. The client could send the file name of each file first, via a separate method call, before the data of each file, so the server would know under what name to save the file on its file system. By using the Binary data type supported by XML-RPC, you could send any type of file, whether text or binary, and irrespective of the operating system of the sender or receiver, whether Windows or UNIX. I've done this in some code of mine, so I know it works. You might have to take care about newline conversions (LF to CR + LF or vice versa), though, if one side is UNIX and the other is Windows, and do that conversion only for files that are text files. (For binary files, you actually have to make sure that you DO NOT do that conversion, or you will corrupt the data.) And do a similar conversion if one side is Mac and the other is Windows or Linux. On Mac, line endings are marked with a CR. LF = Line Feed (ASCII 10) CR = Carriage Return (ASCII 13) The subprocess + scp method may be slower than the XML-RPC method, since it will have to spawn a new scp process for each file sent, unless you use wildcards and transfer all or many files in one call. One the other hand, the XML-RPC method may be slower, since it transfers the data over HTTP (which rides on TCP which rides on IP), whereas scp probably uses a lower level protocol such as TCP packets directly, or something similar to what FTP uses - those protocols may have less overhead per unit of data sent. Which approach is best depends on your needs, whether it is a one-off job, or whether you need to repeat the job regularly, etc., how much time you have to write the code, etc. HTH, Vasudev --- Vasudev Ram Biz: www.dancingbison.com xtopdf: fast and easy PDF creation from other file formats: www.dancingbison.com/products.html Blog (on software innovation): jugad2.blogspot.com From jkv at unixcluster.dk Sat Jun 27 11:00:46 2009 From: jkv at unixcluster.dk (jkv) Date: Sat, 27 Jun 2009 17:00:46 +0200 Subject: csv blank fields In-Reply-To: <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270633l8cae971p6785a9835903b3f7@mail.gmail.com> Message-ID: <4A46341E.2010008@unixcluster.dk> Mag Gam wrote: > > well, I am actually loading the row into a fixed width array > > > > reader=csv.reader(fs) > > for s,row in enumerate(reader): > > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) > > d[s]=t > > > > > > If there is a missing field, I get a problem in one of my rows > > > I had a similar problem, my problem was that in my source data (csv file) sometimes the last cell was left out, so i ended up doing a try to check if the row existed, if not i appended to the row. Something like: try: row[11] except IndexError: row.append("") If you want to insert a value into empty cells you can do something like this: if row[10] == '' row[10] = 'NULL' -- Regards, jkv http://unixcluster.dk/public.key From sanal.vikram at gmail.com Sat Jun 27 11:57:24 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sat, 27 Jun 2009 08:57:24 -0700 (PDT) Subject: to use unicode strings only References: Message-ID: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> On Jun 27, 4:54?pm, Peter Otten <__pete... at web.de> wrote: > MRAB wrote: > > Gaudha wrote: > >> I wanna make all the strings in my code unicode strings. How to do it > >> without giving unicode switch 'u' before every string? > > > Use Python 3.1 instead. > > or use > > from __future__ import unicode_literals > > in Python 2.6. I know about Python 3.1 have the capability. But, unfortunately the community for which I'm working do not prefer Python 3.*... And Peter, I tried importing the __future__ module. It's also not working... From twirlip at bigfoot.com Sat Jun 27 12:02:43 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sat, 27 Jun 2009 17:02:43 +0100 Subject: Buffer pair for lexical analysis of raw binary data Message-ID: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Partly as an educational exercise, and partly for its practical benefit, I'm trying to pick up a programming project from where I left off in 2001. It implemented in slightly generalised form the "buffer pair" scheme for lexical analysis described on pp. 88--92 of Aho et al., /Compilers: Principles, Techniques and Tools/ (1986). (I'm afraid I don't have a page reference for the 2007 second edition. Presumably it's also in Knuth somewhere.) Documentation for one of the C++ header files describes it thus (but I never quite got the hang of C++, so some of the language- specific details may be very poorly conceived): "An object incorporates a handle to a file, opened in read-only mode, and a buffer containing (by default) raw binary data from that file. The constructor also has an option to open a file in text mode. The buffer may, optionally, consist of several segments, linked to one another in cyclic sequence. The number of segments is a constant class member, nblocks (1 <= nblocks <= 32,767). A second constant class member, block (1 <= block <= 32,767) gives the size of each of the segments in bytes. The purpose of creating a buffer in cyclically linked segments is to allow reference to the history of reading the file, even though it is being read sequentially. The bare class does not do this itself, but is designed so that classes derived from it may incorporate one or more pointers to parts of the buffer that have already been read (assuming these parts have not yet been overwritten). If there were only one segment, the length of available history would periodically be reduced to zero, when the buffer is re- freshed. In general, the available history occupies at least a fraction (nblocks - 1)/nblocks of a full buffer." Aho et al. describe the scheme thus (p. 90): "Two pointers to the input buffer are maintained. The string of characters between the two pointers is the current lexeme. Initially, both pointers point to the first character of the next lexeme to be found. One, called the forward pointer, scans ahead until a match for a pattern is found. Once the next lexeme is determined, the forward pointer is set to the character at its right end. After the lexeme is processed, both pointers are set to the character immediately past the lexeme." [There follows a description of the use of "sentinels" to test efficiently for pointers moving past the end of input to date.] I seem to remember (but my memory is still very hazy) that there was some annoying difficulty in coding the raw binary input file reading operation in C++ in an implementation-independent way; and I'm reluctant to go back and perhaps get bogged down again in whatever way I got bogged down before; so I would prefer to use Python for the whole thing, if possible (either using some existing library, or else by recoding it all myself in Python). Does some Python library already provide some functionality like this? (It's enough to do it with nblocks = 2, as in Aho et al.) If not, is this a reasonable thing to try to program in Python? (At the same time as learning the language, and partly as a fairly demanding exercise intended to help me to learn it.) Or should I just get my hands dirty with some C++ compiler or other, and get my original code working on my present machine (possibly in ANSI C instead of C++), and call it from Python? -- Angus Rodgers From magawake at gmail.com Sat Jun 27 12:35:47 2009 From: magawake at gmail.com (Mag Gam) Date: Sat, 27 Jun 2009 12:35:47 -0400 Subject: csv blank fields In-Reply-To: References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Peter: Sorry if I wasn't clear before. While reading my csv file, notice I am putting the content in an array. If lets say, row[5] has nothing in it, python gives an exception. Instead of the exception, I would like to assign 'NULL' to row[5]. Does that help? On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten<__peter__ at web.de> wrote: > Mag Gam wrote: > >> well, I am actually loading the row into a fixed width array >> >> reader=csv.reader(fs) >> for s,row in enumerate(reader): >> > t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) >> d[s]=t >> >> >> If there is a missing field, I get a problem in one of my rows > > Please be specific. Describe what you want and what you get. > > If you give code make it self-contained so that others can run it without > having to guess the values of the variables you introduce. > > If an exception occurs cut and paste the traceback into your post, too. > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > From msrachel.e at gmail.com Sat Jun 27 12:41:13 2009 From: msrachel.e at gmail.com (Rachel P) Date: Sat, 27 Jun 2009 09:41:13 -0700 (PDT) Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: [Thomas Lehmann] > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if ?data.has_key(key): > ? ?value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? Several thoughts for you: * Python isn't C++ * Dict lookups in Python are ubiquitous * Trying to avoid them is often an exercise in futility * Because of cache effects, double lookups are *very* cheap * If this particular fragment is critical, consider using get(): data_get = data.get ... # inner-loop code value = data_get(key) # assigns None for missing values * Another alternative is a try-block: try: # setup is cheap value = data[key] except KeyError: # matching is expensive ... * Or you can use collections.defaultdict() or a dict subclass that defines __missing__(). * In general though, think of dicts as one of Python's most optimized structures, one that should be embraced rather than avoided. * Tim Peter's take on the subject from year's ago (paraphrased): "Anything written using Python dictionaries is a gazillion times faster than C". Raymond From benjamin at python.org Sat Jun 27 12:44:30 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 16:44:30 +0000 (UTC) Subject: to use unicode strings only References: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> Message-ID: Gaudha gmail.com> writes: > And Peter, I tried importing the __future__ module. It's also not > working... How so? From charles at declareSub.com Sat Jun 27 12:46:23 2009 From: charles at declareSub.com (Charles Yeomans) Date: Sat, 27 Jun 2009 12:46:23 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: On Jun 26, 2009, at 10:22 PM, sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > As an alternative to Python, I'd suggest REALbasic. Its main disadvantage is that it is not free. But you get a language, editor, and two application frameworks in one package. Charles Yeomans From laplacian42 at gmail.com Sat Jun 27 12:54:36 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Sat, 27 Jun 2009 09:54:36 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? Message-ID: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> I just read a blog post of Guido's http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html and notice that he doesn't comment on what he wants in a GUI toolkit for Python. I sorta' wish he'd just come out and say, "This is what I think would be suitable for a GUI toolkit for Python: ...". That way, someone could then just come along and implement it. (Or maybe he's said this and I missed it?) So, what *does* Guido want in a GUI toolkit for Python? From python at mrabarnett.plus.com Sat Jun 27 13:06:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 18:06:23 +0100 Subject: csv blank fields In-Reply-To: <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: <4A46518F.40708@mrabarnett.plus.com> Mag Gam wrote: > Peter: > > Sorry if I wasn't clear before. > > While reading my csv file, notice I am putting the content in an array. > > If lets say, row[5] has nothing in it, python gives an exception. > Instead of the exception, I would like to assign 'NULL' to row[5]. > > Does that help? > You still didn't say what the exception was! Anyway, if you expect 'row' to contain 11 items, then you could append the missing ones: for s, row in enumerate(reader): # Fill any empty slots with "NULL". row = [r or "NULL" for r in row] # Append missing (empty) slots on the end. row += ["NULL"] * (11 - len(row)) d[s] = np.array([tuple(row)], dtype=mtype) > > On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten<__peter__ at web.de> wrote: >> Mag Gam wrote: >> >>> well, I am actually loading the row into a fixed width array >>> >>> reader=csv.reader(fs) >>> for s,row in enumerate(reader): >>> >> t=np.array([(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10])],dtype=mtype) >>> d[s]=t >>> >>> >>> If there is a missing field, I get a problem in one of my rows >> Please be specific. Describe what you want and what you get. >> >> If you give code make it self-contained so that others can run it without >> having to guess the values of the variables you introduce. >> >> If an exception occurs cut and paste the traceback into your post, too. >> From todorovic.dejan at gmail.com Sat Jun 27 13:06:32 2009 From: todorovic.dejan at gmail.com (netpork) Date: Sat, 27 Jun 2009 10:06:32 -0700 (PDT) Subject: encoding problem Message-ID: Hello, I have ssl socket with server and client, on my development machine everything works pretty well. Database which I have to use is mssql on ms server 2003, so I decided to install the same python config there and run my python server script. Now here is the problem, server is returning strange characters although default encoding is the same on both development and server machines. Any hints? Thanks in advance. From caseyhHAMMER_TIME at istar.ca Sat Jun 27 13:07:32 2009 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Sat, 27 Jun 2009 10:07:32 -0700 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: >So, what *does* Guido want in a GUI toolkit for Python? I saw a talk by a school teacher on pyFLTK: GUI programming made easy. On another note: I#: Groovy makes it easy to tie into the Java Swing GUI, so if Python could do that, with the added complication being the user would need a JVM. -- Regards, Casey From __peter__ at web.de Sat Jun 27 13:12:44 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 19:12:44 +0200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> Message-ID: Mag Gam wrote: Please don't top-post. > Sorry if I wasn't clear before. > > While reading my csv file, notice I am putting the content in an array. That's already in the code you posted. What's missing is the value of "mtypes". I really meant it when I asked you to provide a self-contained example, i. e. one that I can run on my computer. > If lets say, row[5] has nothing in it No, it containes an empty string as MRAB already inferred. > , python gives an exception. What exception? What traceback? Please take the time to read http://catb.org/esr/faqs/smart-questions.html > Instead of the exception, I would like to assign 'NULL' to row[5]. The string "NULL"? That would be # untested for s, row in enumerate(reader): row = tuple(c if c else "NULL" for c in row) t = np.array([row], dtype=mtype) ... I'm not a numpy expert, but creating a lot of temporary arrays does look wasteful... > Does that help? Sorry, no. I (or someone else who doesn't bother to guess) could have come up with a better answer in a shorter time if you had actually answered my questions. Peter From danger at rulez.sk Sat Jun 27 13:16:45 2009 From: danger at rulez.sk (Daniel Gerzo) Date: Sat, 27 Jun 2009 19:16:45 +0200 Subject: Looking for developer to help me Message-ID: <4A4653FD.6040208@rulez.sk> Hello guys, I have started to work on a new python library (called PySubLib), which is intended to allow applications to work with subtitles (the most common formats) easily. As I am pretty new to Python programming, I would appreciate if somebody with some spare time and Python foo could help/mentor me with this effort. In case there's somebody with Python skills willing to guide me, please let me know. I have already written some code, and if you're interested you may find it at http://bitbucket.org/danger/pysublib/src/. Thanks, -- S pozdravom / Best regards Daniel Gerzo From philip at semanchuk.com Sat Jun 27 13:23:04 2009 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Jun 2009 13:23:04 -0400 Subject: postgreSQL python bindings - which one? In-Reply-To: <1246105656.18806.2.camel@blackwidow.nbk> References: <1246105656.18806.2.camel@blackwidow.nbk> Message-ID: On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote: > On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: >> Hi, I'm having a hard time deciding which set of PGSQL python >> bindings >> to go with. I don't know much about SQL to begin with, so the collage >> of packages of somewhat daunting. I'm starting a pet project in order >> to teach my self more, but I want to avoid getting off on the wrong >> foot and picking a package that is not going to be actively updated >> in >> the future. >> >> There seem to be several implementations >> * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. >> * http://www.pygresql.org/ - version 4.0 was released beginning of >> this year, update before that was sometime in 06 >> ( http://www.pygresql.org/changelog.html ) >> * http://python.projects.postgresql.org/ - first release was this >> month? >> >> The last one of those three looks to be the most promising, but I >> just >> can't tell for sure. Your input is appreciated :) >> > > psycopg2: http://initd.org/pub/software/psycopg/ +1 Although I'm not using it anymore, I had good success with psycopg2 and strongly recommend it. From kee at kagi.com Sat Jun 27 13:35:03 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 10:35:03 -0700 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <5847CB44-D6E3-45C7-9765-BE66076832DB@kagi.com> I'll give you the same advice I used to give to people when they wanted to decide whether to get a Mac or a PC, go with what your local group of friends is using. In general, if you have a local friend who can come over weekly (or you can visit weekly) and have them help you with the stumbling blocks, that is way more important than whether one language is better than another. If there is someone at work who can stop by your desk on a daily basis, that is even better. All computer languages have a learning curve and a whole set of quirks that are things that "everyone knows" (-: unless you are new to the language). Eventually you will grok the language and know all the weird gotchas that make no sense to a new person and from that point forward the documentation will make sense and you'll be able to go very far without having to ask others for help. Until that time, something as simple as the use of a colon instead of a semi-colon can halt your project for weeks. Having someone who can look at your code and say "there's your problem ..." is way more important than the language itself. With all that background, here are my personal choices. I started a long time ago with FORTRAN, BASIC, assembly language for single chip micros, and ultimately Hypercard and AppleScript (on the Mac), and finally the language used by the Arduino micros. I've built a ton of code using Hypercard all the way from web server CGIs to standalone user applications, to unattended code that runs forever doing a task when needed. Hypercard is no longer a viable coding platform so I had to find alternatives. For GUI stuff on a Mac or PC, I use RunRev. For all the Hypercard stuff I've built in the past I migrated to Runtime Revolution (RunRev) which can be described as a multi-platform Hypercard on steroids. The workflow is similar to Cocoa on the Mac. You first create the user interface by dragging buttons and fields and controllers and such onto windows and then when you like the way the user interface works, you write code to have the various interface elements do what they are supposed to when a user interacts with them. For GUI type applications, things that run on a user's computer, sometimes referred to as a heavy client, I find Runtime Revolution to be extremely easy and I'm very productive in that environment. I have web CGIs built in RunRev and it works quite well but ... it is a single threaded system so a web site with tons simultaneous hits will have scaling up problems. That said, high traffic web sites do use RunRev but I wanted something that was not single threaded for web stuff. For web stuff I have used RunRev but am moving towards Python. I went with Python mostly because a friend of mine who knows me and who writes in many languages, thought it was the best fit for the way my mind works, and he volunteered to help me when I get stuck on stuff. He helped me find the Komodo IDE and got me set up to where I had a very simple hello world CGI that I could expand upon. Python has a proven ability to scale up and support more users than I will ever need to support. It is what Google and many others run on. The philosophy is for there to be only one way to perform a function. A competent Python programmer can follow the code written by another because there is only one dialect of Python (unlike Perl). These are things I like about Python. I'm using Python 2.6.2 with the Komodo IDE and I'm limiting myself to the packages that come with the standard install of Python. So I'm not using TurboGears or Django or WSGI or any of those, I just use cgi and urllib (and urllib2). Until I know enough to really understand what my code is doing, and more importantly what those packages are doing or not, I'm not going to use add-on packages. So far I have not needed them. All that said, right now I am extremely inefficient in Python as compared to RunRev. I can build a fairly complex CGI in RunRev in a day, with Python, it takes me a month. Much of that has to do with RunRev being a variation of Hypercard (both use a HyperTalk style language) and I'm way past the 10,000 hour usage level on the HyperTalk language. I'm barely at 100 hours with Python so right now everything is a struggle. But I like Python and plan to stick with it. Kee Nethery From tjreedy at udel.edu Sat Jun 27 13:35:16 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:35:16 -0400 Subject: Good books in computer science? In-Reply-To: References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <0050ecf7$0$9684$c3e8da3@news.astraweb.com> Message-ID: A > Steven D'Aprano wrote: > >>> On 2009-06-14 14:04:02 +0100, Steven D'Aprano >>> said: >>> I think I'm paraphrasing Richard Feynman here, but the >>> only way to truly understand something is to do it. >> An amazingly inappropriate quote for a *theoretical* physicist to have said. Who got his start *doing* calculations for the Manhattan (atomic bomb) project, and checking them against real results. Like it or not, they 'did' it is a big way. He got his Nobel Prize for finding out how to *do* calculations that matched quantum mechanics experiments. (or something like that). His early bobby was picking locks and cracking safes -- mostly as a way to understand them. It was not enough for him to just read about them. tjr From tjreedy at udel.edu Sat Jun 27 13:38:04 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:38:04 -0400 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Peter Otten wrote: >>> Will your program handle empty lines of input correctly? >> Strangely enough, it seems to do so, but why? > > Because there aren't any. When you read lines from a file there will always > be at least the newline character. Otherwise it would indeed fail: Except possibly for the last line. From kee at kagi.com Sat Jun 27 13:41:28 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 10:41:28 -0700 Subject: looking for a book on python In-Reply-To: References: Message-ID: <7D341BFE-01DB-4CFB-9969-6B90BA81D6E1@kagi.com> I'm a newbie and I need examples and I find that Python for Dummies is my best paper source for examples. Kee Nethery From piet at cs.uu.nl Sat Jun 27 13:44:42 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 19:44:42 +0200 Subject: encoding problem References: Message-ID: >>>>> netpork (n) wrote: >n> Hello, >n> I have ssl socket with server and client, on my development machine >n> everything works pretty well. >n> Database which I have to use is mssql on ms server 2003, so I decided >n> to install the same python config there and run my python server >n> script. >n> Now here is the problem, server is returning strange characters >n> although default encoding is the same on both development and server >n> machines. >n> Any hints? Yes, read http://catb.org/esr/faqs/smart-questions.html -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From tjreedy at udel.edu Sat Jun 27 13:47:42 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Jun 2009 13:47:42 -0400 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: laplacian42 at gmail.com wrote: > I just read a blog post of Guido's > http://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decline-of.html > and notice that he doesn't comment on what he wants in a GUI toolkit > for Python. > > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". That way, someone > could then just come along and implement it. (Or maybe he's said this > and I missed it?) > > So, what *does* Guido want in a GUI toolkit for Python? What he did say is "But it hasn't really gotten any less complex to create the simplest of simple UIs. And that's a shame. When is Microsoft going to learn the real lesson about simplicity of HTML?" From aahz at pythoncraft.com Sat Jun 27 13:53:33 2009 From: aahz at pythoncraft.com (Aahz) Date: 27 Jun 2009 10:53:33 -0700 Subject: looking for a book on python References: Message-ID: In article , Kee Nethery wrote: > >I'm a newbie and I need examples and I find that Python for Dummies is >my best paper source for examples. Thank you! That's one thing we worked hard on. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From piet at cs.uu.nl Sat Jun 27 13:55:17 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 27 Jun 2009 19:55:17 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: >>>>> Terry Reedy (TR) wrote: >TR> Peter Otten wrote: >>>>> Will your program handle empty lines of input correctly? >>>> Strangely enough, it seems to do so, but why? >>> >>> Because there aren't any. When you read lines from a file there will >>> always be at least the newline character. Otherwise it would indeed fail: >TR> Except possibly for the last line. But then that line wouldn't be empty either. If there is an empty line not terminated by a newline after the last newline, then that is called 'end-of-file' :=) -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From __peter__ at web.de Sat Jun 27 13:56:46 2009 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Jun 2009 19:56:46 +0200 Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: Terry Reedy wrote: > Peter Otten wrote: > >>>> Will your program handle empty lines of input correctly? >>> Strangely enough, it seems to do so, but why? >> >> Because there aren't any. When you read lines from a file there will >> always be at least the newline character. Otherwise it would indeed fail: > > Except possibly for the last line. It may not end with a newline, but it will still contain at least one character. From kee at kagi.com Sat Jun 27 14:35:53 2009 From: kee at kagi.com (Kee Nethery) Date: Sat, 27 Jun 2009 11:35:53 -0700 Subject: Python simple web development In-Reply-To: <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> References: <1bf98b40-6341-4a61-901b-f82f84d33002@z34g2000vbl.googlegroups.com> <1cc1ed41-3ddf-4124-9c41-0a92069f505a@q37g2000vbi.googlegroups.com> Message-ID: <5A63D179-3A31-4339-AE5D-A2A19D99D93E@kagi.com> Until I'm an experience Python coder, I'm sticking with built-in packages only. My simple CGI is: #!/usr/bin/env python # this simple CGI responds to a GET or a POST # send anything you want to this and it will parrot it back. # a line that starts with #2 is the old-style code you should use that works # with versions less than Python 2.6. I'm using 2.6.2 and am trying to use # code that works with Python 3.x and up. import cgi ## so that I can be a web server CGI import os ## only purpose is for getting the CGI client values like IP and URL def main(): # create the output variable and then add stuff to it that gets returned cgiResponseData = 'stuff from the client browser connection:\n' # so that there is something to return, go through the CGI client data #2 for cgiKey in os.environ.keys(): for cgiKey in list(os.environ.keys()): # for each client data value, add a line to the output cgiResponseData = cgiResponseData + \ str(cgiKey) + ' = ' + os.environ[cgiKey] + '\n' # this says give me a list of all the user inputs posted to the cgi formPostData = cgi.FieldStorage() cgiResponseData = cgiResponseData + '\n\nstuff from the URL POST or GET:\n' # cycle through those inputs and output them right back #2 for keyValue in formPostData: for keyValue in list(formPostData): cgiResponseData = cgiResponseData + \ str(keyValue) + ' = ' + formPostData[keyValue].value + '\n' #2 print 'Content-type: text/html' #2 print #2 print cgiResponseData print('Content-type: text/html') print('') print(cgiResponseData) main() From emile at fenx.com Sat Jun 27 15:54:33 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Jun 2009 12:54:33 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: On 6/27/2009 3:39 AM Angus Rodgers said... > On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah > wrote: > >> Thank you for your hint. >> This is my solution: >> f = open('test', 'r') >> for line in f: >> print line[0].upper()+line[1:], > > Will your program handle empty lines of input correctly? It will when the final line is changed to: print line[:1].upper()+line[1:] Emile From Scott.Daniels at Acm.Org Sat Jun 27 16:01:01 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 27 Jun 2009 13:01:01 -0700 Subject: Fast Dictionary Access In-Reply-To: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <7J6dnbkkVox95dvXnZ2dnUVZ_r2dnZ2d@pdx.net> Thomas Lehmann wrote: > In C++, programming STL you will use the insert method which always > provides a position and a flag which indicates whether the position > results from a new insertion or an exisiting element. Idea is to have > one search only. > > > if data.has_key(key): > value = data[key] > > > But this does mean (does it?) that the dictionary is searched two > times! If so, can somebody show me how to do this in one step? To get almost the same result (assuming value is already loaded): value = data.get(key, value) Otherwise, as others have said: if key in data: value = data[key] The form: try: value = data[key] except KeyError: pass works, but is not terribly efficient unless failures are rare. And this is a micro-optimization, measure before changing your program structure away from the clearest code you can write. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Sat Jun 27 16:02:22 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 27 Jun 2009 13:02:22 -0700 Subject: Python Imaging Library download link broken? In-Reply-To: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: <7J6dnbgkVoys5NvXnZ2dnUVZ_r1i4p2d@pdx.net> olivergeorge wrote: > Ditto. Anyone know what's happening with pythonware? (and why PIL is > such a pain to install for that matter.) (1) It is usually there; be patient. (2) I suggest you demand a refund. --Scott David Daniels Scott.Daniels at Acm.Org From python at mrabarnett.plus.com Sat Jun 27 16:25:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 21:25:15 +0100 Subject: change the first character of the line to uppercase in a text file In-Reply-To: References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <4A46802B.2070600@mrabarnett.plus.com> Emile van Sebille wrote: > On 6/27/2009 3:39 AM Angus Rodgers said... >> On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >> wrote: >> >>> Thank you for your hint. >>> This is my solution: >>> f = open('test', 'r') >>> for line in f: >>> print line[0].upper()+line[1:], >> >> Will your program handle empty lines of input correctly? > > > It will when the final line is changed to: > > print line[:1].upper()+line[1:] > 'line' will _never_ be ''. If a line ends with a newline then that will be preserved returned as part of the string. This applies to the 'file' methods 'readline', 'readlines', etc, and the iterator, which returns a line. 'readline' will return '' only when it has reached the end of the file. From no.email at please.post Sat Jun 27 16:31:29 2009 From: no.email at please.post (kj) Date: Sat, 27 Jun 2009 20:31:29 +0000 (UTC) Subject: The Python Way for module configuration? Message-ID: [PYTHON NOOB ALERT] I want to write a module that serves as a Python front-end to a database. This database can be either in the form of tab-delimited flat files, XML files, or a PostgreSQL server. The module is meant to hide these database implementation details from its users. But, minimally, the module needs to have some configuration details to know where to get the data. There are many ways to provide this configuration data to the module, but I would like to know what's considered "best practice" for this type of problem in the Python world. Ideally, I'm looking for a system that is unobtrusive under normal operations, but easy to override during testing and debugging. I would appreciate your comments and suggestions. TIA! kynn From laplacian42 at gmail.com Sat Jun 27 16:33:46 2009 From: laplacian42 at gmail.com (laplacian42 at gmail.com) Date: Sat, 27 Jun 2009 13:33:46 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <4626ad33-1dd5-4885-a373-b9cae3ff954e@a7g2000yqk.googlegroups.com> On Jun 27, 1:47?pm, Terry Reedy wrote: > laplacia... at gmail.com wrote: > > > So, what *does* Guido want in a GUI toolkit for Python? > > What he did say is "But it hasn't really gotten any less complex to > create the simplest of simple UIs. And that's a shame. When is Microsoft > going to learn the real lesson about simplicity of HTML?" Long ago I did some Java programming and tried out Swing. I think the complaints about it are that it's a very large toolkit that requires a lot of inheritance to use. However, the underlying premise used by the layout managers seemed sound: 1. Choose a layout manager. 2. Put one or more containers in it. 3. Fill the containers with widgets (or other containers), letting them decide how to lay out the widgets. That aspect, I liked. Seems a lot like nested elements in an html page. Perhaps this was what Guido was alluding to? From python at mrabarnett.plus.com Sat Jun 27 16:38:39 2009 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Jun 2009 21:38:39 +0100 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <4A46834F.7010205@mrabarnett.plus.com> kj wrote: > > > [PYTHON NOOB ALERT] > > I want to write a module that serves as a Python front-end to a > database. This database can be either in the form of tab-delimited > flat files, XML files, or a PostgreSQL server. The module is meant > to hide these database implementation details from its users. > > But, minimally, the module needs to have some configuration details > to know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. > > I would appreciate your comments and suggestions. > There are already modules which provide access to databases. From aaronjsherman at gmail.com Sat Jun 27 16:54:56 2009 From: aaronjsherman at gmail.com (Aaron Sherman) Date: Sat, 27 Jun 2009 13:54:56 -0700 (PDT) Subject: The Python Way for module configuration? References: Message-ID: On Jun 27, 4:38?pm, MRAB wrote: > > I would appreciate your comments and suggestions. > > There are already modules which provide access to databases. As you can see the "Python Way" is to be rude ;-) Anyway, your answer is that there are some abstraction layers called "ORMs". You can grab one of these and write a back end for it. However, you might first want to look at SQLLite and see if it already has what you want (e.g. a light-weight, zero-install database interface). From emile at fenx.com Sat Jun 27 17:01:40 2009 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Jun 2009 14:01:40 -0700 Subject: change the first character of the line to uppercase in a text file In-Reply-To: <4A46802B.2070600@mrabarnett.plus.com> References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> <4A46802B.2070600@mrabarnett.plus.com> Message-ID: On 6/27/2009 1:25 PM MRAB said... > Emile van Sebille wrote: >> On 6/27/2009 3:39 AM Angus Rodgers said... >>> On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah >>> wrote: >>> >>>> Thank you for your hint. >>>> This is my solution: >>>> f = open('test', 'r') >>>> for line in f: >>>> print line[0].upper()+line[1:], >>> >>> Will your program handle empty lines of input correctly? >> >> >> It will when the final line is changed to: >> >> print line[:1].upper()+line[1:] >> > 'line' will _never_ be ''. If a line ends with a newline then that will > be preserved returned as part of the string. This applies to the 'file' > methods 'readline', 'readlines', etc, and the iterator, which returns a > line. 'readline' will return '' only when it has reached the end of the > file. > Sorry -- habit. I tend to use that technique to avoid IndexErrors as a matter of course. Emile From martin at v.loewis.de Sat Jun 27 17:06:06 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 27 Jun 2009 23:06:06 +0200 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <4a4689bf$0$14790$9b622d9e@news.freenet.de> > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". He is not in the business of designing GUI toolkits, but in the business of designing programming languages. So he abstains from specifying (or even recommending) a GUI library. What he makes clear is the point that Terry cites: no matter what the GUI toolkit is or what features it has - it should be simple to create GUIs, as simple as creating HTML. > So, what *does* Guido want in a GUI toolkit for Python? His concern really isn't what is in the toolkit, but what isn't. It must not require lots of lines of code to produce a simple GUI, it must not require specification of absolute coordinates, ... - you should be able to continue the list yourself. Regards, Martin From benjamin at python.org Sat Jun 27 17:12:10 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 27 Jun 2009 16:12:10 -0500 Subject: [RELEASED] Python 3.1 final Message-ID: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> On behalf of the Python development team, I'm thrilled to announce the first production release of Python 3.1. Python 3.1 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 visit: http://www.python.org/download/releases/3.1/ 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's contributors) From tkjthingone at gmail.com Sat Jun 27 17:29:54 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Sat, 27 Jun 2009 14:29:54 -0700 Subject: postgreSQL python bindings - which one? In-Reply-To: References: <1246105656.18806.2.camel@blackwidow.nbk> Message-ID: On Sat, Jun 27, 2009 at 10:23 AM, Philip Semanchuk wrote: > > On Jun 27, 2009, at 8:27 AM, Albert Hopkins wrote: > > On Fri, 2009-06-26 at 21:10 -0700, Horace Blegg wrote: >> >>> Hi, I'm having a hard time deciding which set of PGSQL python bindings >>> to go with. I don't know much about SQL to begin with, so the collage >>> of packages of somewhat daunting. I'm starting a pet project in order >>> to teach my self more, but I want to avoid getting off on the wrong >>> foot and picking a package that is not going to be actively updated in >>> the future. >>> >>> There seem to be several implementations >>> * http://pypi.python.org/pypi/python-pgsql/ - last update in 08. >>> * http://www.pygresql.org/ - version 4.0 was released beginning of >>> this year, update before that was sometime in 06 >>> ( http://www.pygresql.org/changelog.html ) >>> * http://python.projects.postgresql.org/ - first release was this >>> month? >>> >>> The last one of those three looks to be the most promising, but I just >>> can't tell for sure. Your input is appreciated :) >>> >>> >> psycopg2: http://initd.org/pub/software/pPhilip Semanchuk >> sycopg/ >> > > > +1 > > Although I'm not using it anymore, I had good success with psycopg2 and > strongly recommend it. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Awesome, thank you very much for the link! -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sat Jun 27 17:41:36 2009 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Jun 2009 16:41:36 -0500 Subject: Good books in computer science? In-Reply-To: <7x1vp56dfo.fsf@ruckus.brouhaha.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <7xocssvzrh.fsf@ruckus.brouhaha.com> <7x1vp56dfo.fsf@ruckus.brouhaha.com> Message-ID: On 2009-06-27 07:58, Paul Rubin wrote: > Albert van der Horst writes: >>> Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, >>> Ronald L. Rivest, and Clifford Stein. >> Thanks. I lost that title a while ago, must buy. > > Wait a few months, a third edition is in the works. > >> Also "Numerical Recipe's in FORTRAN/Pascal/C" >> (Have they done Python yet?) > > They haven't done Python AFAIK. I liked the C version but the > licensing of the software is pretty evil and so I'm a bit turned off > to the series these days. I think the hardcore numerics crowd never > liked the book anyway. My opinion is that the text itself is a pretty good introduction to the workings of a broad variety of numerical algorithms. For any particular area, there are probably better books that go into more depth and are closer to the state of the art, but I don't think there are any books that cover the wide swath numerical algorithms that NR does. In that regard, I treat it like Wikipedia: a good place to start, not the best place to stop. I think the code succeeds reasonably well for teaching the algorithms, but I don't think they are well-engineered for production use. There are usually better libraries with better licenses. -- 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 cook_jim at yahoo.com Sat Jun 27 18:14:16 2009 From: cook_jim at yahoo.com (Jim) Date: Sat, 27 Jun 2009 15:14:16 -0700 (PDT) Subject: tokenize module Message-ID: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> I'm trying to understand the output of the tokenize.generate_tokens() generator. The token types returned seem to be more general than I'd expect. For example, when fed the following line of code: def func_a(): the (abbreviated) returned token tuples are as follows: (NAME, def, ..., def func_a():) (NAME , func_a, ..., def func_a():) (OP, (, ..., def func_a():) (OP, ), ..., def func_a():) (OP, :, ..., def func_a():) (NEWLINE, NEWLINE, ..., def func_a():) It seems to me that the token '(' should be identified as 'LPAR' and ')' as 'RPAR', as found in the dictionary token.tok_name. What am I missing here? From no.email at please.post Sat Jun 27 18:18:37 2009 From: no.email at please.post (kj) Date: Sat, 27 Jun 2009 22:18:37 +0000 (UTC) Subject: The Python Way for module configuration? References: Message-ID: In Aaron Sherman writes: >On Jun 27, 4:38=A0pm, MRAB wrote: >> > I would appreciate your comments and suggestions. >> >> There are already modules which provide access to databases. >As you can see the "Python Way" is to be rude ;-) >Anyway, your answer is that there are some abstraction layers called >"ORMs". You can grab one of these and write a back end for it. >However, you might first want to look at SQLLite and see if it already >has what you want (e.g. a light-weight, zero-install database >interface). Hi, thanks, but the database aspect of my question is tangential. What I'm interested in is the general problem of providing configuration parameters to a module. TIA! kynn From bearophileHUGS at lycos.com Sat Jun 27 18:40:59 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Sat, 27 Jun 2009 15:40:59 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> Message-ID: Albert van der Horst: > For programming practice I do the problems of > http://projecteuler.net/ Time ago I have solved some of them with Python, D and C (some of them are quite hard for me), I have tried to produce very fast code (like a D generator for prime numbers that's like 100 times faster of some 'fast' C# prime generators I've seen in that forum). But then I have stopped because to me they seem a waste of time, they look too much academic, they don't exercise the right muscles of the mind. They may be good if you want to become good in performing numerical number theory, and bad for everyone else. Seeing how many people like to do those Project Euler puzzles, I presume my ideas aren't shared by most people. I am now using some solutions of mine of those problems to spot "performance bugs" in a new D compiler (and even in ShedSkin), so they are somewhat useful again :-) Bye, bearophile From abuse at 127.0.0.1 Sat Jun 27 19:12:34 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:12:34 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: OdarR wrote: > On 27 juin, 02:48, Randy Foiles wrote: >> Hello and thank you for taking your time to read this. >> I was interested in learning about python. In the long ago past I did >> learn some programing but I have not used any of it for years. I do >> remember some basics however so the book does not have to be for a total >> beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) >> I have been using Linux for a while and overall still don't know much >> about it but I can find my way. I have my system dual boot with windows >> vista. >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. >> Oh and if someone knows a place to find some used books of this sort >> that would be great (ebay I guess :) >> Thanks for your thoughts >> Randy theslayers9 gmail > > "Learning Python" > http://oreilly.com/catalog/9780596513986/ > > new issue soon, covering 2.6 and 3 > http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c > > the best book I read concerning Py understanding, well written. > > I would start with web content, then later would buy the fourth > edition of "Learning Python". > > enjoy, > Olivier Thank you. I was thinking of that book and a few others. I am not sure at this point what the difference is in 2.6 and 3? Randy From abuse at 127.0.0.1 Sat Jun 27 19:13:22 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:13:22 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Randy Foiles wrote: >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. > > You could get the book I co-wrote (Python for Dummies), but honestly, I > think you should try using some of the online tutorials first. The > standard Python tutorial is aimed at people with some programing > experience: > > http://docs.python.org/tutorial/index.html I had not thought about the "dummies" books for this I will look and see if my local B&N has it. From abuse at 127.0.0.1 Sat Jun 27 19:16:17 2009 From: abuse at 127.0.0.1 (Randy Foiles) Date: Sat, 27 Jun 2009 23:16:17 GMT Subject: looking for a book on python In-Reply-To: References: Message-ID: <5Lx1m.1604$NF6.775@nwrddc02.gnilink.net> laplacian42 at gmail.com wrote: > On Jun 26, 8:48 pm, Randy Foiles wrote: >> Hello and thank you for taking your time to read this. >> I was interested in learning about python. In the long ago past I did >> learn some programing but I have not used any of it for years. I do >> remember some basics however so the book does not have to be for a total >> beginner. (C, C++, BASIC, Visual BASIC, Pascal and some ADA) >> I have been using Linux for a while and overall still don't know much >> about it but I can find my way. I have my system dual boot with windows >> vista. >> I do realize that everyone is different but I would like to see some >> suggestions and maybe reasons why you think it is good. I have looked >> for/searched and found a few different books but as my means are a bit >> limited right now I don't really want to buy several just one or maybe >> two books. >> Oh and if someone knows a place to find some used books of this sort >> that would be great (ebay I guess :) >> Thanks for your thoughts >> Randy theslayers9 gmail > > The Oreilly "Python in a Nutshell" (2006, 2nd ed.) book is very good > and will get you up to speed in short order. This is one of the books I see around and it does seem that O'Reilly is where most people go for them :) What is it that you like about this one? From todorovic.dejan at gmail.com Sat Jun 27 19:28:15 2009 From: todorovic.dejan at gmail.com (=?ISO-8859-2?Q?dejan_todorovi=E6?=) Date: Sat, 27 Jun 2009 16:28:15 -0700 (PDT) Subject: encoding problem References: Message-ID: <9a70fd24-9e40-4ea4-8ad7-1f952e9cd544@y9g2000yqg.googlegroups.com> It was problem with pymssql that not supports unicode, switched to pyodbc, everything is fine. Thanks for your swift reply. ;) On Jun 27, 7:44?pm, Piet van Oostrum wrote: > >>>>> netpork (n) wrote: > >n> Hello, > >n> I have ssl socket with server and client, on my development machine > >n> everything works pretty well. > >n> Database which I have to use is mssql on ms server 2003, so I decided > >n> to install the same python config there and run my python server > >n> script. > >n> Now here is the problem, server is returning strange characters > >n> although default encoding is the same on both development and server > >n> machines. > >n> Any hints? > > Yes, readhttp://catb.org/esr/faqs/smart-questions.html > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p... at vanoostrum.org From petr.messner at gmail.com Sat Jun 27 19:48:33 2009 From: petr.messner at gmail.com (Petr Messner) Date: Sun, 28 Jun 2009 01:48:33 +0200 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <67c97cd90906271648k7e74ac25qee1e5e6ae5608c55@mail.gmail.com> Hi, 2009/6/28 kj : ... > What I'm interested in is the general problem of providing > configuration parameters to a module. > Some database/ORM libraries are configured via simple strings in the form "dialect://user:password at host/dbname[?key=value..]", for example "mysql://me:topsecret at localhost/test?encoding=utf8". Is this what you want to know? Petr From davea at ieee.org Sat Jun 27 20:07:29 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Jun 2009 20:07:29 -0400 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <4A46B441.7020109@ieee.org> sato.photo at gmail.com wrote: > Hi, > > As you can imagine, I am new, both to this group and to Python. I > have read various posts on the best book to buy or online tutorial to > read and have started to go through them. I was wondering, as someone > with virtually no programming experience (I am a photographer by > trade), is Python the right language for me to try and learn? > > I do vaguely remember learning what I think was BASIC on some old > Apple's back in elementary school (circa 1992). Would something like > that (the name at least makes it SOUND easier) be more feasible? > > If I do choose to learn Python, are there any tutorials for the > absolute beginner. I do not mean beginner to Python, but rather, > beginner to programming. Someone who hasn't a clue what object > oriented whatcha-ma-whoozit means. I ask again because I understand > that content is always evolving and there might be new tutorials out > there. > > Thanks! > > -Daniel Sato > > I am also a photographer (portraits, weddings, parties, ...). But my previous career was computer software (9 patents). So I know a bit about both. I only learned Python in the past year, having used 35 languages professionally previously. And although Python wasn't the easiest to learn, it was in the top 3, and it has the best ratio of power to difficulty of learning. The real point is that unless you're trying to make a career in software, you're unlikely to need any of these "more powerful" languages. And you can probably write a useful utility in your first 24 hours with the language. Don't worry too much about "object oriented" at the start. And don't worry much about using "old tutorials." Until Python 3, the language has been quite stable for many years. So my advice would be to download Python 2.6 for your operating system, and start playing. Pick something simple for your first tasks, preferably something useful in your main career. For example, try writing a utility that examines a directory tree of image files, looking for some anomaly that you come up with. For example, I use Nikon cameras, so my raw files have a .NEF extension. I never delete the NEF file, but instead move it into a subdirectory "Culled." So I could write a script that searches all subdirectories of directory images/2009-05, looking for gaps in the filenames found. Or look for .psd files that don't have a corresponding .NEF file above them. Or check the .xmp files to make sure the business copyright is in all files. I don't know what operating system you're using, but it would be a big help if you're familiar with the use of the command prompt. From aahz at pythoncraft.com Sat Jun 27 20:09:45 2009 From: aahz at pythoncraft.com (Aahz) Date: 27 Jun 2009 17:09:45 -0700 Subject: looking for a book on python References: Message-ID: In article , Randy Foiles wrote: >OdarR wrote: >> >> "Learning Python" >> http://oreilly.com/catalog/9780596513986/ >> >> new issue soon, covering 2.6 and 3 >> http://oreilly.com/catalog/9780596158064/?CMP=AFC-ak_book&ATT=Learning+Python%2c+Fourth+Edition%2c > >I was thinking of that book and a few others. I am not sure at this >point what the difference is in 2.6 and 3? There are lots of differences between 2.6 and the just-released 3.1, but opinions are split about which is better for learning: some people say that you should learn 3.x first because it's the future of Python and it's simpler/cleaner; others (including me) say you should learn 2.x first because that's where the bulk of current code is and many 3rd-party libraries have not yet been ported to 3.x. In the end, it doesn't make a lot of difference, as long as you stick with only 2.x or 3.x during your initial learning: the core Python syntax changes very little between the 2.x and 3.x, and there are only two critical differences that will hit you up-front: * Python 2.x has ``print`` as a statement; 3.x has ``print()`` as a function * Python 2.x has 8-bit strings by default; 3.x uses Unicode and has no way to access 8-bit strings except as byte arrays You might want to bookmark this, though: http://docs.python.org/3.1/whatsnew/index.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From ChollaPete at gmail.com Sat Jun 27 20:32:20 2009 From: ChollaPete at gmail.com (ChollaPete) Date: Sat, 27 Jun 2009 17:32:20 -0700 (PDT) Subject: Clobbered 2.6 binary under Frameworks.python, reinstall fails Message-ID: <5a1fb8c8-2b23-4529-bd3e-9f6d10566cc2@y17g2000yqn.googlegroups.com> Mac OS X (Tiger 10.4), running Python 2.6 downloaded from python.org as a DMG installer. I clobbered the python binary in /Library/Frameworks/Python.frameworks/ Versions/Current/bin, so I tried to reinstall from the python.org 2.6.2 DMG installer. No joy. Install fails at the end with no helpful diagnostic message. So, I deleted everything in /Applications/Python2.6, in /Library/ Frameworks/Python.frameworks and /usr/local/bin. The install still fails. Any help would be appreciated. I realize that the upgraders often aren't intended to be used to repair an existing installation. My thinking now is that I may need to delete existing package receipts or plists, but this is just wild speculation. Thanks. Mark From ncoghlan at gmail.com Sat Jun 27 20:53:49 2009 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 28 Jun 2009 10:53:49 +1000 Subject: [Python-Dev] [RELEASED] Python 3.1 final In-Reply-To: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: <4A46BF1D.2090002@gmail.com> Benjamin Peterson wrote: > On behalf of the Python development team, I'm thrilled to announce the first > production release of Python 3.1. Excellent news! Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- From ChollaPete at gmail.com Sat Jun 27 20:54:23 2009 From: ChollaPete at gmail.com (ChollaPete) Date: Sat, 27 Jun 2009 17:54:23 -0700 (PDT) Subject: Clobbered 2.6 binary under Frameworks.python, reinstall fails References: <5a1fb8c8-2b23-4529-bd3e-9f6d10566cc2@y17g2000yqn.googlegroups.com> Message-ID: On Jun 27, 5:32?pm, ChollaPete wrote: > Mac OS ?X (Tiger 10.4), running Python 2.6 downloaded from python.org > as a DMG installer. > > I clobbered the python binary in /Library/Frameworks/Python.frameworks/ > Versions/Current/bin, so I tried to reinstall from the python.org > 2.6.2 DMG installer. ?No joy. ?Install fails at the end with no > helpful diagnostic message. > > So, I deleted everything in /Applications/Python2.6, in /Library/ > Frameworks/Python.frameworks and /usr/local/bin. ?The install still > fails. > > Any help would be appreciated. ?I realize that the upgraders often > aren't intended to be used to repair an existing installation. ?My > thinking now is that I may need to delete existing package receipts or > plists, but this is just wild speculation. > > Thanks. > > Mark Well, upon inspection of the various directories, everything seemed to be there, so I ran the interpreter and it seemed to work. Evaluated a simple expression at the >>> prompt, imported a module and ran its function. So, I don't know what part of the install failed. If anyone can tell me where to find the various scripts that the MPKG runs, that would help. Thanks, Mark From wuwei23 at gmail.com Sat Jun 27 21:03:23 2009 From: wuwei23 at gmail.com (alex23) Date: Sat, 27 Jun 2009 18:03:23 -0700 (PDT) Subject: No trees in the stdlib? References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: Jo?o Valverde wrote: > Currently I don't have a strong need for this. And clearly neither has anyone else, hence the absence from the stdlib. As others have pointed out, there are alternative approaches, and plenty of recipes on ActiveState, which seem to have scratched whatever itch there is for the data structure you're advocating. While Python's motto is "batteries included" I've always felt there was an implicit "but not the kitchen sink" following it. Just because something "could" be useful shouldn't be grounds for inclusion. That's what pypi & the recipes are for. Ideally, little should be created wholesale for the stdlib, what should be added are the existing 3rd party modules that have become so ubiquitous that their presence on any python platform is just expected. From backup95 at netcabo.pt Sat Jun 27 22:03:48 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sun, 28 Jun 2009 03:03:48 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A46CF84.2080005@netcabo.pt> alex23 wrote: > Jo?o Valverde wrote: > >> Currently I don't have a strong need for this. >> > > And clearly neither has anyone else, hence the absence from the > stdlib. As others have pointed out, there are alternative approaches, > and plenty of recipes on ActiveState, which seem to have scratched > whatever itch there is for the data structure you're advocating. > Propose such alternative then. There are none that offer the same performance. At best they're workarounds. I don't care about recipes. That's called research. If people don't find it to be useful, that's fine. Surprising, but fine. And I don't have a need because I'm not using Python for my project. If I wanted to I couldn't, without implementing myself or porting to Python 3 a basic computer science data structure. > While Python's motto is "batteries included" I've always felt there > was an implicit "but not the kitchen sink" following it. Just because > something "could" be useful shouldn't be grounds for inclusion. That's > what pypi & the recipes are for. Ideally, little should be created > wholesale for the stdlib, what should be added are the existing 3rd > party modules that have become so ubiquitous that their presence on > any python platform is just expected. > Agreed. From davea at ieee.org Sat Jun 27 22:52:47 2009 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Jun 2009 22:52:47 -0400 Subject: The Python Way for module configuration? In-Reply-To: References: Message-ID: <4A46DAFF.2000709@ieee.org> kj wrote: > In Aaron Sherman writes: > > >> On Jun 27, 4:38=A0pm, MRAB wrote: >> > > >>>> I would appreciate your comments and suggestions. >>>> >>> There are already modules which provide access to databases. >>> > > >> As you can see the "Python Way" is to be rude ;-) >> > > >> Anyway, your answer is that there are some abstraction layers called >> "ORMs". You can grab one of these and write a back end for it. >> However, you might first want to look at SQLLite and see if it already >> has what you want (e.g. a light-weight, zero-install database >> interface). >> > > > Hi, thanks, but the database aspect of my question is tangential. > What I'm interested in is the general problem of providing > configuration parameters to a module. > > TIA! > > kynn > > > Check out the ConfigParser module, a standard module. In Python 3.0, it's renamed to configparser, but still part of the standard distribution. This module interprets a file that's in roughly the INI format. From milesck at umich.edu Sat Jun 27 22:56:32 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Sat, 27 Jun 2009 22:56:32 -0400 Subject: No trees in the stdlib? In-Reply-To: <4A45A8ED.9090103@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> <4A45A8ED.9090103@netcabo.pt> Message-ID: Jo?o Valverde wrote: > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). Originally I was also serializing them in a binary > format (but no more after a redesign). I kept the "merge and sort" > part as a helper script, but that is considerably simpler to > implement. > > ... > > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and > Python, using pyavl. Round numbers were 4 mins vs 4 seconds, against > Python (plus pyavl). Even considering I'm a worse Python programmer > than C programmer, it's a lot. I know many will probably think I > tried to do "C in Python" but that's not the case, at least I don' t > think so. Anyway like I said, not really relevant to this discussion. What format were you using to represent the IP addresses? (Is it a Python class?) And why wouldn't you use a network address/subnet mask pair to represent block ranges? (It seems like being able to represent ranges that don't fit into a subnet's 2^n block wouldn't be that common of an occurrence, and that it might be more useful to make those ranges easier to manipulate.) One of the major disadvantages of using a tree container is that usually multiple comparisons must be done for every tree operation. When that comparison involves a call into Python bytecode (for custom cmp/lt methods) the cost can be substantial. Compare that to Python's hash-based containers, which only need to call comparison methods in the event of hash collisions (and that's hash collisions, not hash table bucket collisions, since the containers cache each object's hash value). I would imagine that tree-based containers would only be worth using with objects with comparison methods implemented in C. Not that I'm trying to be an apologist, or reject your arguments; I can definitely see the use case for a well-implemented, fast tree- based container for Python. And so much the better if, when you need one, there was a clear consensus about what package to use (like PIL for image manipulation--it won't meet every need, and there are others out there, but it's usually the first recommended), rather than having to search out and evaluate a dozen different ones. -Miles From ben+python at benfinney.id.au Sat Jun 27 23:28:31 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 13:28:31 +1000 Subject: The Python Way for module configuration? References: Message-ID: <87fxdlujds.fsf@benfinney.id.au> (Even if you don't want to receive email, could you please give your actual name in the ?From? field instead of just initials? It makes conversation less confusing.) kj writes: > But, minimally, the module needs to have some configuration details to > know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. The standard library provides the ability to parse plain text configuration files and populate a collection of values for configuration. The module's name is changing to conform to the library standards; see . This way, you can customise the execution of your program by modifying configuration settings in a non-executable configuration file. It also allows a cascade of overrides, for e.g. user-specific configuration overrides or test-specific overrides, etc. -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From backup95 at netcabo.pt Sat Jun 27 23:44:02 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Sun, 28 Jun 2009 04:44:02 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> <4A45A8ED.9090103@netcabo.pt> Message-ID: <4A46E702.40805@netcabo.pt> Miles Kaufmann wrote: > Jo?o Valverde wrote: >> To answer the question of what I need the BSTs for, without getting >> into too many boring details it is to merge and sort IP blocklists, >> that is, large datasets of ranges in the form of (IP address, IP >> address, string). Originally I was also serializing them in a binary >> format (but no more after a redesign). I kept the "merge and sort" >> part as a helper script, but that is considerably simpler to implement. >> >> ... >> >> As an anecdotal data point (honestly not trying to raise the "Python >> is slow" strawman), I implemented the same algorithm in C and Python, >> using pyavl. Round numbers were 4 mins vs 4 seconds, against Python >> (plus pyavl). Even considering I'm a worse Python programmer than C >> programmer, it's a lot. I know many will probably think I tried to do >> "C in Python" but that's not the case, at least I don' t think so. >> Anyway like I said, not really relevant to this discussion. > > What format were you using to represent the IP addresses? (Is it a > Python class?) And why wouldn't you use a network address/subnet mask > pair to represent block ranges? (It seems like being able to > represent ranges that don't fit into a subnet's 2^n block wouldn't be > that common of an occurrence, and that it might be more useful to make > those ranges easier to manipulate.) I was using a bytes subclass. I'm not free to choose CIDR notation, range boundaries must be arbitrary. > > One of the major disadvantages of using a tree container is that > usually multiple comparisons must be done for every tree operation. > When that comparison involves a call into Python bytecode (for custom > cmp/lt methods) the cost can be substantial. Compare that to Python's > hash-based containers, which only need to call comparison methods in > the event of hash collisions (and that's hash collisions, not hash > table bucket collisions, since the containers cache each object's hash > value). I would imagine that tree-based containers would only be > worth using with objects with comparison methods implemented in C. I would flip your statement and say one of the advantages of using trees is that they efficiently keep random input sorted. Obviously no algorithm can do that with single comparisons. And not requiring a hash function is a desirable quality for non-hashable objects. There's a world beyond dicts. :) I profiled the code and indeed the comparisons dominated the execution time. Trimming the comparison function to the bare minimum, a single python operation, almost doubled the program's speed. > > Not that I'm trying to be an apologist, or reject your arguments; I > can definitely see the use case for a well-implemented, fast > tree-based container for Python. And so much the better if, when you > need one, there was a clear consensus about what package to use (like > PIL for image manipulation--it won't meet every need, and there are > others out there, but it's usually the first recommended), rather than > having to search out and evaluate a dozen different ones. > Thanks, and I'm not trying to start a religion either. ;) From pavlovevidence at gmail.com Sun Jun 28 00:04:51 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 27 Jun 2009 21:04:51 -0700 (PDT) Subject: The Python Way for module configuration? References: Message-ID: <3583bbfc-4f89-4ee0-aa56-b934880a8523@t21g2000yqi.googlegroups.com> On Jun 27, 3:18?pm, kj wrote: > In Aaron Sherman writes: > > >On Jun 27, 4:38=A0pm, MRAB wrote: > >> > I would appreciate your comments and suggestions. > > >> There are already modules which provide access to databases. > >As you can see the "Python Way" is to be rude ;-) > >Anyway, your answer is that there are some abstraction layers called > >"ORMs". You can grab one of these and write a back end for it. > >However, you might first want to look at SQLLite and see if it already > >has what you want (e.g. a light-weight, zero-install database > >interface). > > Hi, thanks, but the database aspect of my question is tangential. > What I'm interested in is the general problem of providing > configuration parameters to a module. The best way to do this totally depends on how complex these parameters are. Are they simple one-to-one key-value pairs? Then the frontend should explose a dict interface. There are probably existing third-party libraries that expose dict-like interfaces to all of your imagined backends. Check pypi.python.org, and also Python cookbook. If the configuration is more complex, such as if it is hierarchical, if it includes many-to-many relationships, if it is graph-like, then a more sophisticated frontend will be needed. For these situations I second the recommendation to consider an ORM (such as SqlAlchemy). I am not aware of any ORMs that can use SQL, XML, and tab-delimited text all as backends, though. I am not a big database guy though. Also, I exhort to you consider whether you really need so many different backends for a configuration file. Might your time be better spent improving some other aspect of your application? Carl Banks From kay at fiber-space.de Sun Jun 28 00:44:44 2009 From: kay at fiber-space.de (Kay Schluehr) Date: Sat, 27 Jun 2009 21:44:44 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <6c737d94-a5a6-42a8-a6dc-13b6936f8eb0@t13g2000yqt.googlegroups.com> On 27 Jun., 23:06, "Martin v. L?wis" wrote: > > I sorta' wish he'd just come out and say, "This is what I think would > > be suitable for a GUI toolkit for Python: ...". > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. ... which isn't all that different today. One might just take a look at JavaFX and how gracefully it handles declarative data flow a.k.a. data binding. The evolution of programming languages goes on, with or rather without Python. From http Sun Jun 28 01:31:22 2009 From: http (Paul Rubin) Date: 27 Jun 2009 22:31:22 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <7xws6w2ac5.fsf@ruckus.brouhaha.com> Robin Becker writes: > > There is a philosophy of mathematics (intuitionism) that says... > > there are NO discontinuous functions. > so does this render all the discreteness implied by quantum theory > unreliable? or is it that we just cannot see(measure) the continuity > that really happens? I think the latter. Quantum theory anyway describes continuous operators that have discrete eigenvalues, not the same thing as discontinuous functions. From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:31:37 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:31:37 GMT Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: <0062db08$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: > (Even if you don't want to receive email, could you please give your > actual name in the ?From? field instead of just initials? It makes > conversation less confusing.) Some people prefer to be known by their initials. Some people's legal names *are* initials. There's nothing confusing about addressing somebody by their initials. The only complication in this case is knowing the correct way to capitalise it -- should it be K.J. or Kj or something else? > kj writes: Apart from capitalisation, it works perfectly. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:36:06 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:36:06 GMT Subject: change the first character of the line to uppercase in a text file References: <1a6a7d32-20e0-41fe-a98c-b7cd703a3031@v4g2000vba.googlegroups.com> Message-ID: <0062dc15$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 19:55:17 +0200, Piet van Oostrum wrote: >>>>>> Terry Reedy (TR) wrote: > >>TR> Peter Otten wrote: >>>>>> Will your program handle empty lines of input correctly? >>>>> Strangely enough, it seems to do so, but why? >>>> >>>> Because there aren't any. When you read lines from a file there will >>>> always be at least the newline character. Otherwise it would indeed >>>> fail: > >>TR> Except possibly for the last line. > > But then that line wouldn't be empty either. > > If there is an empty line not terminated by a newline after the last > newline, then that is called 'end-of-file' :=) I try to always write file-handling files under the assumption that some day somebody (possibly me) will pass the function a file-like object, and therefore make the minimum number of assumptions about each line. For example, I wouldn't assume that lines can't be empty, or that they must end in a newline. The later is violated even by ordinary files, but the former could be violated by a file-like object which iterated over (say) ['first line', 'second line', '', 'the previous line was blank']. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 01:37:18 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 05:37:18 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <0062dc5c$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: [...] > Raymond Raymond, does Rachel know you're using her gmail account? *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 02:19:22 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 06:19:22 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> Message-ID: <0062e638$0$9714$c3e8da3@news.astraweb.com> On Thu, 25 Jun 2009 12:23:07 +0100, Robin Becker wrote: > Paul Rubin wrote: [...] >> No really, it is just set theory, which is a pretty bogus subject in >> some sense. There aren't many discontinuous functions in nature. Depends on how you define "discontinuous". Catastrophe theory is full of discontinuous changes in state. Animal (by which I include human) behaviour often displays discontinuous changes. So does chemistry: one minute the grenade is sitting there, stable as can be, the next it's an expanding cloud of gas and metal fragments. Then there's spontaneous symmetry breaking. At an atomic level, it's difficult to think of things which *aren't* discontinuous. And of course, if quantum mechanics is right, nature is *nothing but* discontinuous functions. >> There >> is a philosophy of mathematics (intuitionism) that says classical set >> theory is wrong and in fact there are NO discontinuous functions. They >> have their own mathematical axioms which allow developing calculus in a >> way that all functions are continuous. On the other hand, there's also discrete mathematics, including discrete versions of calculus. > so does this render all the discreteness implied by quantum theory > unreliable? or is it that we just cannot see(measure) the continuity > that really happens? That's a question for scientific investigation, not mathematics or philosophy. It may be that the universe is fundamentally discontinuous, and the continuous functions we see are only because of our insufficiently high resolution senses and instruments. Or it may be that the discontinuities we see are only because we're not capable of looking closely enough to see the smooth function passing between the two ends of the discontinuity. My money is on the universe being fundamentally discontinuous. We can explain the continuous behaviour of classical-scale phenomenon in terms of discontinuous quantum behaviour, but it doesn't seem possible to explain discontinuous quantum behaviour in terms of lower-level continuous behaviour. -- Steven From zaphod at beeblebrox.net Sun Jun 28 02:26:14 2009 From: zaphod at beeblebrox.net (Zaphod) Date: Sun, 28 Jun 2009 06:26:14 GMT Subject: Beginning with Python; the right choice? References: Message-ID: snip > In terms of good tutorials for absolute beginners, here are two: > > Alan Gauld's Learning to Program > http://www.freenetpages.co.uk/hp/alan.gauld/ > > ShowMeDo.com has lots of Python instructional videos, including this one > for absolute beginners: > http://showmedo.com/videotutorials/series?name=irgGc9ChS > > I also recommend the Python tutor list, which you can sign up for here: > http://mail.python.org/mailman/listinfo/tutor > > So what is it that you want to use Python for? > > Che Also have a look at http://openbookproject.net/thinkcs/python/english2e/ which is a bit less in depth but faster and also fun way to get started. I teach high school programming and although I do teach Visual Basic at the lower levels (grade 9/10) I use Python for my grade 11/12 students. It's an easy language to learn and has an incredible amount of functionality through importable libraries. From http Sun Jun 28 02:52:02 2009 From: http (Paul Rubin) Date: 27 Jun 2009 23:52:02 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7xocs83l65.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Depends on how you define "discontinuous". The mathematical way, of course. For any epsilon > 0, etc. > Catastrophe theory is full of discontinuous changes in state. Animal > (by which I include human) behaviour often displays discontinuous > changes. So does chemistry: one minute the grenade is sitting there, > stable as can be, the next it's an expanding cloud of gas and metal > fragments. If that transition from grenade to gas cloud takes a minute (or even a femtosecond), it's not a mathematical discontinuity. The other examples work out about the same way. From lie.1296 at gmail.com Sun Jun 28 03:25:36 2009 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 28 Jun 2009 07:25:36 GMT Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: Jo?o Valverde wrote: > alex23 wrote: >> Jo?o Valverde wrote: >> >>> Currently I don't have a strong need for this. >>> >> >> And clearly neither has anyone else, hence the absence from the >> stdlib. As others have pointed out, there are alternative approaches, >> and plenty of recipes on ActiveState, which seem to have scratched >> whatever itch there is for the data structure you're advocating. >> > > Propose such alternative then. There are none that offer the same > performance. At best they're workarounds. > > I don't care about recipes. That's called research. > > If people don't find it to be useful, that's fine. Surprising, but fine. Python devs, based on my observation, tend to choose a data structure based on the interface and not its implementation. Binary Sorted Tree is an implementation, its interface can be a sorted dict (sorted key-value mapping) or a list (not the most natural interface for a tree). Basically, python already have all the common interfaces, i.e. list, set, and mapping/dict. Let's see it like this. In how many ways can a list be implemented? - Array (python's builtin list) - Linked List - Binary Tree - and the list goes on... All of them can expose their interface as list, but only array implementation is available as builtin. > And I don't have a need because I'm not using Python for my project. If > I wanted to I couldn't, without implementing myself or porting to Python > 3 a basic computer science data structure. > >> While Python's motto is "batteries included" I've always felt there >> was an implicit "but not the kitchen sink" following it. Just because >> something "could" be useful shouldn't be grounds for inclusion. That's >> what pypi & the recipes are for. Ideally, little should be created >> wholesale for the stdlib, what should be added are the existing 3rd >> party modules that have become so ubiquitous that their presence on >> any python platform is just expected. >> > > Agreed. From sajmikins at gmail.com Sun Jun 28 03:39:10 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 28 Jun 2009 00:39:10 -0700 (PDT) Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: <64cb06c8-8463-4664-9375-5f72d49df1d2@c9g2000yqm.googlegroups.com> On Jun 27, 12:54?pm, "laplacia... at gmail.com" wrote: > I just read a blog post of Guido'shttp://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decl... > and notice that he doesn't comment on what he wants in a GUI toolkit > for Python. > > I sorta' wish he'd just come out and say, "This is what I think would > be suitable for a GUI toolkit for Python: ...". That way, someone > could then just come along and implement it. (Or maybe he's said this > and I missed it?) > > So, what *does* Guido want in a GUI toolkit for Python? FWIW, I created a simple GUI builder module I call pygoo that lets you create Tkinter GUIs from a simple text "specification". http://www.pygoo.com/ http://code.google.com/p/pygoo/ Warm regards, ~Simon From timr at probo.com Sun Jun 28 03:46:05 2009 From: timr at probo.com (Tim Roberts) Date: Sun, 28 Jun 2009 00:46:05 -0700 Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> Message-ID: <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> Jim wrote: >I'm trying to understand the output of the tokenize.generate_tokens() >generator. The token types returned seem to be more general than I'd >expect. For example, when fed the following line of code: > >def func_a(): >... >It seems to me that the token '(' should be identified as 'LPAR' and >')' as 'RPAR', as found in the dictionary token.tok_name. What am I >missing here? Did you read the module? Right at the top, it says: It is designed to match the working of the Python tokenizer exactly, except that it produces COMMENT tokens for comments and gives type OP for all operators -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nobody at nowhere.com Sun Jun 28 03:51:07 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 08:51:07 +0100 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: On Sat, 27 Jun 2009 17:17:22 -0700, Dennis Lee Bieber wrote: >> His concern really isn't what is in the toolkit, but what isn't. >> It must not require lots of lines of code to produce a simple >> GUI, it must not require specification of absolute coordinates, >> ... - you should be able to continue the list yourself. >> > > Sounds a bit like a return of DECWindows on Xt... Which had a > textual design language to define the widgets in use, names for > callbacks, etc. and only required the application to load the file and > map the callbacks to actual code... > > You could change the layout without touching the application code > (as long as you weren't adding new widgets) Xt itself provides some of that, the rest can be had through UIL (which is part of Motif). GTK+ can do much of this using Glade. The concept of separating code from data is sensible enough, and mirrors the concept of stylesheets in HTML. It shouldn't be necessary to specify size, position, labels, colours and the like via code. Code only needs to be able to get a handle on a specific widget so that it can read and write its state, dynamically register callbacks, etc. From stef.mientki at gmail.com Sun Jun 28 04:06:11 2009 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 28 Jun 2009 10:06:11 +0200 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4a4689bf$0$14790$9b622d9e@news.freenet.de> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <4A472473.1030706@gmail.com> Martin v. L?wis wrote: >> I sorta' wish he'd just come out and say, "This is what I think would >> be suitable for a GUI toolkit for Python: ...". >> > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. > > What he makes clear is the point that Terry cites: no matter what the > GUI toolkit is or what features it has - it should be simple to create > GUIs, as simple as creating HTML. > > >> So, what *does* Guido want in a GUI toolkit for Python? >> > > His concern really isn't what is in the toolkit, but what isn't. > It must not require lots of lines of code to produce a simple > GUI, it must not require specification of absolute coordinates, > ... - you should be able to continue the list yourself. > > Gui_support obey the above 2 rules, so I guess, 'm on the right way with GUI_support http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html What are the other rules ? cheers, Stef > Regards, > Martin > From comet2005 at gmail.com Sun Jun 28 04:25:39 2009 From: comet2005 at gmail.com (iceangel89) Date: Sun, 28 Jun 2009 01:25:39 -0700 (PDT) Subject: Advantages of Python (for web/desktop apps)? Message-ID: <24239603.post@talk.nabble.com> i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python now (for desktop apps since its open source and just want to try what it offers, but will like to know what good it has for web development also) i wonder what do users of Python say? somethings i am curious abt (that came to my mind) now are: - performance - ide to use? - how do i design GUI for windows app? -- View this message in context: http://www.nabble.com/Advantages-of-Python-%28for-web-desktop-apps%29--tp24239603p24239603.html Sent from the Python - python-list mailing list archive at Nabble.com. From ben+python at benfinney.id.au Sun Jun 28 04:39:28 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 18:39:28 +1000 Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> Message-ID: <87bpo8vjjz.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: > > > (Even if you don't want to receive email, could you please give your > > actual name in the ?From? field instead of just initials? It makes > > conversation less confusing.) > > Some people prefer to be known by their initials. Some people prefer to spend their volunteer time conversing with people who don't just use initials or pseudonyms. > There's nothing confusing about addressing somebody by their initials. I find it much less confusing to converse with someone if I can keep straight who they are, and names work better than initials for that purpose. -- \ ?Whenever you read a good book, it's like the author is right | `\ there, in the room talking to you, which is why I don't like to | _o__) read good books.? ?Jack Handey | Ben Finney From ben+python at benfinney.id.au Sun Jun 28 04:40:20 2009 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 28 Jun 2009 18:40:20 +1000 Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> <0062dc5c$0$9714$c3e8da3@news.astraweb.com> Message-ID: <877hywvjij.fsf@benfinney.id.au> Steven D'Aprano writes: > On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote: > [...] > > Raymond > > Raymond, does Rachel know you're using her gmail account? It's a good thing names are being used here, rather than just initials. -- \ ?No one ever went broke underestimating the taste of the | `\ American public.? ?Henry L. Mencken | _o__) | Ben Finney From nobody at nowhere.com Sun Jun 28 04:58:14 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 09:58:14 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: > Python 3.1 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. That's a significant improvement. It still decodes os.environ and sys.argv before you have a chance to call sys.setfilesystemencoding(), but it appears to be recoverable (with some effort; I can't find any way to re-do the encoding without manually replacing the surrogates). However, sys.std{in,out,err} are still created as text streams, and AFAICT there's nothing you can do about this from within your code. All in all, Python 3.x still has a long way to go before it will be suitable for real-world use. From mail at microcorp.co.za Sun Jun 28 04:59:07 2009 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 28 Jun 2009 10:59:07 +0200 Subject: The Python Way for module configuration? References: Message-ID: <010601c9f7ce$be12da40$0d00a8c0@Hendrik> "kj" wrote: > I want to write a module that serves as a Python front-end to a > database. This database can be either in the form of tab-delimited > flat files, XML files, or a PostgreSQL server. The module is meant > to hide these database implementation details from its users. > > But, minimally, the module needs to have some configuration details > to know where to get the data. There are many ways to provide this > configuration data to the module, but I would like to know what's > considered "best practice" for this type of problem in the Python > world. > > Ideally, I'm looking for a system that is unobtrusive under normal > operations, but easy to override during testing and debugging. To pass in configuration to a module, you have basically two choices: - Use the command line and sys.argv - Put the stuff in a file of some sort. I would not recommend the first option, because it ultimately ends up as an abomination such as we can see with gcc, where it has spawned over elaborate systems of makefiles to tell it how to do something - so we are back at a file, in any event. So the questions become - how do you organise the file, and how do you get hold of the stuff in it. You have been pointed to configparser, and others. You can also do a simple thing, as a module gets executed upon import. If your parameters are simple, this may be the easiest way of doing it, namely to just write the bunch of them down, all in a configuration.py file, like this: P1 = 7 P2 = 42 alloweds = [john,mary,sally] Then where you want to use them, you do the following: import configuration as cf if cf.P1 > 3: do something if suspect in cf.alloweds: let user in else: print "Go away you fiend from the nether regions" sys.stdout.flush() sys.exit() if not cf.P2 == 42: print "The end of the universe has arrived - hide!" while True: pass Do not forget that you can put a dictionary there to handle more complex stuff. You can also get fancy and put whole classes of data into such a file. In what I do, I have never felt the need for that. You get the drift (I hope) - Hendrik From simon at brunningonline.net Sun Jun 28 05:04:25 2009 From: simon at brunningonline.net (Simon Brunning) Date: Sun, 28 Jun 2009 10:04:25 +0100 Subject: Beginning with Python; the right choice? In-Reply-To: References: Message-ID: <8c7f10c60906280204o2c21df34r334129c69ce3299c@mail.gmail.com> 2009/6/27 sato.photo at gmail.com : > Thank you for all of the links and advice. > > What do I want to learn Python for? > > Again, pardon me for my lack of relevant information. ?I am also a > journalist (an out of work one at the moment, like so many others) and > I feel that learning python could be useful for computer assisted > reporting, that is, utilizing databases, creating interactive maps and > the like. > > http://chicago.everyblock.com/crime/ That's a Python site! As a journalist, you might also be interested in - The Guardian, a UK national newspaper, quickly wrote and deployed a Python application to allow their readers to cooperate in the massive manual task of analysing MPs' expenses receipts, looking for ill-doing. -- Cheers, Simon B. From pavlovevidence at gmail.com Sun Jun 28 05:39:47 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Jun 2009 02:39:47 -0700 (PDT) Subject: Dictionary self lookup References: <35b25489-6afb-48e4-9a4a-764544443743@j20g2000vbp.googlegroups.com> Message-ID: <14b07411-5cda-48d9-8848-eeed216f856e@e21g2000yqb.googlegroups.com> On Jun 27, 4:33?am, Jure Erzno?nik wrote: > When you write code like > config = {"home" : "/home/test"} > config["user1"] = config["home"] + "/user1" > > config["user1"] isn't stored in memory as config["home"] + "/user1", > but as a concatenated string ("/home/test/user1"), composed of both > those strings. The reference to original composing strings is lost at > the moment the expression itself is evaluated to be inserted into the > dict. > There's no compiler / interpreter that would do this any other way. At > least not that I know of. It's called Lazy Evaluation and there are a bunch of tools that do it implicitly and automatically. Off hand I can think of make and Mathematica. I know there are some functional programming languages that do it as well. Also there are languages like Lisp that have strong syntactic support for lazy evaluation although it's not done implicitly. Not Python, though. > So best suggestion would be to simply do an object that would parse > strings before returning them. In the string itself, you can have > special blocks that tell your parser that they are references to other > objects. [snip example] > But you sure better not expect this to be included in language syntax. > It's a pretty special case. That is a very good suggestion that might be a better solution to the OP's problem. You are right that is would require a bit of work. Python does have string interpolation methods that can do keyword-based substitution, but they don't work recursively, and it's not straightforward to get it to work recursively. Carl Banks From pavlovevidence at gmail.com Sun Jun 28 05:57:50 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 28 Jun 2009 02:57:50 -0700 (PDT) Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: On Jun 27, 4:40?am, Duncan Booth wrote: > Thomas Lehmann wrote: > > Hi! > > > In C++, programming STL you will use the insert method which always > > provides a position and a flag which indicates whether the position > > results from a new insertion or an exisiting element. Idea is to have > > one search only. > > > > > if ?data.has_key(key): > > ? ?value = data[key] > > > > > But this does mean (does it?) that the dictionary is searched two > > times! If so, can somebody show me how to do this in one step? > > That code actually does 3 dictionary lookups and creates a temporary > object: the first lookup is to find the 'has_key' method, then it has to > bind the method to data which involves creating a 'built-in method' object > and then it calls it. Only then do you get the two lookups you expected. > > Replacing your code with: > > ? ?if key in data: value = data[key] > > reduces the overhead to two dictionary lookups, no temporary objects or > function calls. > > The suggested alternative: > > ? ?value = data.get(key, None) > > also has two dictionary lookups: one to find the 'get' method and one to > find the key, but as in the first case it also has the overhead of binding > the method and then calling it. > > In other words the get method is often the clearest (and therefore best) > way to write the code, but if performance matters do a check using the 'in' > operator (or if you know the key lookup will fail only very rarely consider > using try..except). It's not that simple. Attribute lookups are fast because the keys are interned strings. However, the key lookup in the data object might be an object where hash and compare operations are much slower. So it's not valid in general to equate the two lookups. Unless you know that your dict keys are going to be really fast like interned strings it makes sense to minimize dict lookups. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:07:38 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:07:38 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> Message-ID: <00631bb9$0$9714$c3e8da3@news.astraweb.com> On Sat, 27 Jun 2009 23:52:02 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Depends on how you define "discontinuous". > > The mathematical way, of course. For any epsilon > 0, etc. I thought we were talking about discontinuities in *nature*, not in mathematics. There's no "of course" about it. >> Catastrophe theory is full of discontinuous changes in state. Animal >> (by which I include human) behaviour often displays discontinuous >> changes. So does chemistry: one minute the grenade is sitting there, >> stable as can be, the next it's an expanding cloud of gas and metal >> fragments. > > If that transition from grenade to gas cloud takes a minute (or even a > femtosecond), it's not a mathematical discontinuity. In mathematics, you can cut up a pea and reassemble it into a solid sphere the size of the Earth. Try doing that with a real pea. Mathematics is an abstraction. It doesn't necessarily correspond to reality. Assuming that reality "really is" the mathematical abstraction underneath is just an assumption, and not one supported by any evidence. > The other examples work out about the same way. Quantum phenomenon are actual mathematical discontinuities, or at least they can be, e.g. electron levels in an atom. Even when they are continuous, they're continuous because they consist of an infinity of discontinuous levels infinitesimally far apart. -- Steven From sanal.vikram at gmail.com Sun Jun 28 06:09:20 2009 From: sanal.vikram at gmail.com (Gaudha) Date: Sun, 28 Jun 2009 03:09:20 -0700 (PDT) Subject: to use unicode strings only References: <3af9a21e-b568-4477-859e-6575f8c8a2e2@c9g2000yqm.googlegroups.com> Message-ID: <75bb932d-38cc-40b5-9489-6f807715b405@e21g2000yqb.googlegroups.com> On Jun 27, 9:44?pm, Benjamin Peterson wrote: > Gaudha gmail.com> writes: > > > And Peter, I tried importing the __future__ module. It's also not > > working... > > How so? Sorry guys, __future__ module is working excellent :-). I had some bad coding somewhere else, just fixed it. Anyway, thank you for all... From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:17:52 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:17:52 GMT Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> <87bpo8vjjz.fsf@benfinney.id.au> Message-ID: <00631e1f$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 18:39:28 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: >> >> > (Even if you don't want to receive email, could you please give your >> > actual name in the ?From? field instead of just initials? It makes >> > conversation less confusing.) >> >> Some people prefer to be known by their initials. > > Some people prefer to spend their volunteer time conversing with people > who don't just use initials or pseudonyms. And some people refuse to use words with the letter "E" in them. Just out of curiosity, how are you supposed to recognise people who are using pseudonyms? For all we know, "Steven D'Aprano" might be a pseudonym -- you haven't seen my birth certificate. I noticed that you ignored my comment about people's whose legal names are initials. >> There's nothing confusing about addressing somebody by their initials. > > I find it much less confusing to converse with someone if I can keep > straight who they are, and names work better than initials for that > purpose. Really? Can you cope with two-letter names like Jo, Li, Ed, Cy, or even Wm (a variant of William), or are you about to start insisting that people choose three-letter names? If you can cope with Al, Di or Mo, then what's the difference between those names and two-letter initials? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 06:23:50 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 10:23:50 GMT Subject: Fast Dictionary Access References: <74b1ac36-ee81-445a-b485-7943d86c3260@f16g2000vbf.googlegroups.com> Message-ID: <00631f86$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 02:57:50 -0700, Carl Banks wrote: > So it's not valid in general to equate the two lookups. Unless you know > that your dict keys are going to be really fast like interned strings it > makes sense to minimize dict lookups. Or to stop making assumptions about what's fast and what's not fast, and actually profile the code and see where the hold-ups are. "Dear Pythonistas, I have a program that runs for six hours performing some wickedly complicated calculations on data extracted from a dict. The dictionary lookups take five and a half seconds, how can I speed them up?" *wink* -- Steven From http Sun Jun 28 06:28:51 2009 From: http (Paul Rubin) Date: 28 Jun 2009 03:28:51 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7x3a9kfy8s.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I thought we were talking about discontinuities in *nature*, not in > mathematics. There's no "of course" about it. IIRC we were talking about fractals, which are a topic in mathematics. This led to some discussion of mathematical continuity, and the claim that mathematical discontinuity doesn't appear to occur in nature (and according to some, it shouldn't occur in mathematics either). > In mathematics, you can cut up a pea and reassemble it into a solid > sphere the size of the Earth. Try doing that with a real pea. That's another example of a mathematical phenomenon that doesn't occur in nature. What are you getting at? > Quantum phenomenon are actual mathematical discontinuities, or at > least they can be, e.g. electron levels in an atom. I'm sure you know more physics than I do, but I was always taught that observables (like electron levels) were eigenvalues of underlying continuous operators. That the eigenvalues are discrete just means some continuous function has multiple roots that are discrete. There is a theorem (I don't know the proof or even the precise statement) that if quantum mechanics has the slightest amount of linearity, then it's possible in principle to solve NP-hard problems in polynomial time with quantum computers. So I think it is treated as perfectly linear. From simone.perone at gmail.com Sun Jun 28 07:05:02 2009 From: simone.perone at gmail.com (sgperone) Date: Sun, 28 Jun 2009 04:05:02 -0700 (PDT) Subject: PyQT QWebView Local swf file not loading Message-ID: Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange behaviour: inside a widget i have this code: self.view = QWebView(self) self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True) that's i'm creating a QWebView instance with PluginsEnabled flag on. next lines are: Case 1 =================================================== f = QtCore.QUrl("http://www.example.com/myflashfile.swf") print f self.view.load(f) in this case f == True and the swf file is showing correctly inside the widget Case 2 =================================================== f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf") print f self.view.load(f) in this case f == False and no swf clip showed up. Really weird... if I use a local html file with code to embed the local swf file everything is working. So, it seems that: It is impossible to load a local swf file directly into QWebView without a "wrapper" html code. Anyone experienced the same issue ? Thanks From simone.perone at gmail.com Sun Jun 28 07:10:05 2009 From: simone.perone at gmail.com (sgperone) Date: Sun, 28 Jun 2009 04:10:05 -0700 (PDT) Subject: PyQT QWebView Local swf file not loading References: Message-ID: <332a45a5-cb9b-4a61-b975-9e04c8055196@z9g2000yqi.googlegroups.com> On 28 Giu, 13:05, sgperone wrote: > Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange > behaviour: > > inside a widget i have this code: > > self.view = QWebView(self) > self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True) > > that's i'm creating a QWebView instance with PluginsEnabled flag on. > > next lines are: > > Case 1 > =================================================== > f = QtCore.QUrl("http://www.example.com/myflashfile.swf") > print f > self.view.load(f) > > in this case f == True and the swf file is showing correctly inside > the widget > > Case 2 > =================================================== > f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf") > print f Correction: =================================================== it's not "f" that is True or False, but : inside code i have: self.connect(self.view,QtCore.SIGNAL("loadFinished (bool)"),self.loadFinished) and def loadFinished(self,bool): print bool > self.view.load(f) > > in this case f == False and no swf clip showed up. > > Really weird... if I use a local html file with code to embed the > local swf file everything is working. > > So, it seems that: > > It is impossible to load a local swf file directly into QWebView > without a "wrapper" html code. > > Anyone experienced the same issue ? > > Thanks From martin at v.loewis.de Sun Jun 28 08:36:37 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 28 Jun 2009 14:36:37 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <4a4763d5$0$307$9b622d9e@news.freenet.de> > That's a significant improvement. It still decodes os.environ and sys.argv > before you have a chance to call sys.setfilesystemencoding(), but it > appears to be recoverable (with some effort; I can't find any way to re-do > the encoding without manually replacing the surrogates). See PEP 383. > However, sys.std{in,out,err} are still created as text streams, and AFAICT > there's nothing you can do about this from within your code. That's intentional, and not going to change. You can access the underlying byte streams if you want to, as you could already in 3.0. Regards, Martin P.S. Please identify yourself on this newsgroup. From aahz at pythoncraft.com Sun Jun 28 08:38:34 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 05:38:34 -0700 Subject: Python and journalism (was Re: Beginning with Python; the right choice?) References: Message-ID: In article , sato.photo at gmail.com wrote: > >What do I want to learn Python for? > >Again, pardon me for my lack of relevant information. I am also a >journalist (an out of work one at the moment, like so many others) and >I feel that learning python could be useful for computer assisted >reporting, that is, utilizing databases, creating interactive maps and >the like. You're absolutely right! You're also not the first person to have that realization: http://www.time.com/time/business/article/0,8599,1902202,00.html http://www.ojr.org/ojr/stories/060605niles/ http://www.medill.northwestern.edu/admissions/page.aspx?id=58645 (Probably you already knew this, but I'm posting for other people.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From martin at v.loewis.de Sun Jun 28 08:41:04 2009 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 28 Jun 2009 14:41:04 +0200 Subject: encoding problem In-Reply-To: <8522bfaf-7efc-4ebb-a63a-b5ecc73e236d@35g2000pry.googlegroups.com> References: <85e9957b-ed0a-4983-8427-46ab520c4a4a@s9g2000prm.googlegroups.com> <6r1m72Ffb5kpU3@mid.uni-berlin.de> <8522bfaf-7efc-4ebb-a63a-b5ecc73e236d@35g2000pry.googlegroups.com> Message-ID: <4a4764e0$0$307$9b622d9e@news.freenet.de> > That is the reason why we have to explicitly declare a encoding as > long as we have non-ASCII in source. True - but it doesn't have to be the "correct" encoding. If you declared your source as latin-1, the effect is the same on byte string literals, but not on Unicode literals. In that sense, the encoding declaration only "matters" for Unicode literals (of course, it also matters for source editors, and in a few other places). Regards, Martin From python.list at tim.thechases.com Sun Jun 28 09:45:08 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Jun 2009 08:45:08 -0500 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: <24239603.post@talk.nabble.com> References: <24239603.post@talk.nabble.com> Message-ID: <4A4773E4.3030800@tim.thechases.com> iceangel89 wrote: > i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used > .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python > now (for desktop apps since its open source and just want to try what it > offers, but will like to know what good it has for web development also) > > somethings i am curious abt (that came to my mind) now are: gvn ur pnchnt 4 illgble shrthnd, u mgt prefr perl ovr pythn. or prhps u wnt asmbly lang. XOR EAX, EAX; MOV [EAX], EAX > - performance More than sufficient for my needs (scripting, web apps, most GUI apps) -- you can always drop to optimized C/C++ functions/modules if needed or use custom modules like numpy/numeric/etc for processor-intense work. > - ide to use? http://lmgtfy.com/?q=python+ide I use vim. Others use emacs. Some use Eclipse. Some use WingIDE. Etc, etc, etc. Try 'em each and see what you like > - how do i design GUI for windows app? http://lmgtfy.com/?q=python+gui Lots of options -- choose the one you like. -tkc From nuffnough at gmail.com Sun Jun 28 09:45:49 2009 From: nuffnough at gmail.com (Nuff Nuff) Date: Sun, 28 Jun 2009 06:45:49 -0700 (PDT) Subject: Running a script from a windows right click menu..? Message-ID: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> I wrote a little script that affects a bunch of files in the folder that it is run in. Now what I want to do is to make it run from the right click menu but I don't know how. Would you give me an example script that will simply print the woriking directory, and show me how to add that to the right click menu in windows explorer? TIA Nuffi From esj at harvee.org Sun Jun 28 10:09:21 2009 From: esj at harvee.org (Eric S. Johansson) Date: Sun, 28 Jun 2009 10:09:21 -0400 Subject: pep 8 constants In-Reply-To: <49a50517$0$3567$426a74cc@news.free.fr> References: <49a50517$0$3567$426a74cc@news.free.fr> Message-ID: <4A477991.4050109@harvee.org> Bruno Desthuilliers wrote: > Brendan Miller a ?crit : >> PEP 8 doesn't mention anything about using all caps to indicate a >> constant. >> >> Is all caps meaning "don't reassign this var" a strong enough >> convention to not be considered violating good python style? I see a >> lot of people using it, but I also see a lot of people writing >> non-pythonic code... so I thought I'd see what the consensus is. > > Most - if not all - of the python code I've seen so far used this > convention, and I always used (and respected) it myself. I reject this convention because any form of caps significantly increases vocal load for disabled programmers using speech recognition through extra utterances, and degraded recognition. In my experience, language conventions like this come about because most geeks generally don't think about disabled programmers and the effect that language changes will have on them. I deal by trying to build my accessibility tools as best I can but handling stuff like pep 8 is hard because it requires a smart environment that know the meanings of every class, method. or variable so it can lead the grammar in the right direction. ThenWenUHve names like this. Cr** in a stick. you might as well take a gun to my wrists because that is how much pain I will be in typing them. again need *good* editor support for English to name translation. so I reject pep 8 because I have no voice safe alternative From aahz at pythoncraft.com Sun Jun 28 11:00:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:00:23 -0700 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: In article <0qec45lho8lkng4n20sb1ad4eguat675pb at 4ax.com>, Angus Rodgers wrote: > >Partly as an educational exercise, and partly for its practical >benefit, I'm trying to pick up a programming project from where >I left off in 2001. It implemented in slightly generalised form >the "buffer pair" scheme for lexical analysis described on pp. >88--92 of Aho et al., /Compilers: Principles, Techniques and >Tools/ (1986). (I'm afraid I don't have a page reference for the >2007 second edition. Presumably it's also in Knuth somewhere.) > > [...] > >Does some Python library already provide some functionality like >this? (It's enough to do it with nblocks = 2, as in Aho et al.) Not AFAIK, but there may well be something in the recipes or PyPI; have you tried searching them? >If not, is this a reasonable thing to try to program in Python? Definitely! It should be lots easier to program this with Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From news123 at free.fr Sun Jun 28 11:03:07 2009 From: news123 at free.fr (News123) Date: Sun, 28 Jun 2009 17:03:07 +0200 Subject: creating garbage collectable objects (caching objects) Message-ID: <4a47862b$0$31117$426a74cc@news.free.fr> Hi. I started playing with PIL. I'm performing operations on multiple images and would like compromise between speed and memory requirement. The fast approach would load all images upfront and create then multiple result files. The problem is, that I do not have enough memory to load all files. The slow approach is to load each potential source file only when it is needed and to release it immediately after (leaving it up to the gc to free memory when needed) The question, that I have is whether there is any way to tell python, that certain objects could be garbage collected if needed and ask python at a later time whether the object has been collected so far (image has to be reloaded) or not (image would not have to be reloaded) # Fastest approach: imgs = {} for fname in all_image_files: imgs[fname] = Image.open(fname) for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): img = do_somethingwith(img,imgs[img_file]) img.save() # Slowest approach: for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): src_img = Image.open(img_file) img = do_somethingwith(img,src_img) img.save() # What I'd like to do is something like: imgs = GarbageCollectable_dict() for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): if src_img in imgs: # if 'm lucke the object is still there src_img = imgs[img_file] else: src_img = Image.open(img_file) img = do_somethingwith(img,src_img) img.save() Is this possible? Thaks in advance for an answer or any other ideas of how I could do smart caching without hogging all the system's memory From aahz at pythoncraft.com Sun Jun 28 11:03:21 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:03:21 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: In article , Tim Chase wrote: > >> - how do i design GUI for windows app? > >http://lmgtfy.com/?q=python+gui This is the first time I've tried LMGTFY, and it seems to be a piece of trash that requires JavaScript. I suggest that lmgtfy.com not be considered a standard part of the Python community. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From jfabiani at yolo.com Sun Jun 28 11:06:33 2009 From: jfabiani at yolo.com (John Fabiani) Date: Sun, 28 Jun 2009 08:06:33 -0700 Subject: What does Guido want in a GUI toolkit for Python? References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> Message-ID: Casey Hawthorne wrote: >>So, what *does* Guido want in a GUI toolkit for Python? > > I saw a talk by a school teacher on pyFLTK: GUI programming made easy. > > On another note: I#: Groovy makes it easy to tie into the Java Swing > GUI, so if Python could do that, with the added complication being the > user would need a JVM. > > -- > Regards, > Casey Dabo makes it transparent when it come to tying the data to the widget. Based on the wxPython. So it meets Guido's requirements. From benjamin at python.org Sun Jun 28 11:22:15 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 15:22:15 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > All in all, Python 3.x still has a long way to go before it will be > suitable for real-world use. Such as? From Scott.Daniels at Acm.Org Sun Jun 28 11:41:47 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 28 Jun 2009 08:41:47 -0700 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Nobody wrote: > On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: > > That's a significant improvement.... > All in all, Python 3.x still has a long way to go before it will be > suitable for real-world use. Fortunately, I have assiduously avoided the real word, and am happy to embrace the world from our 'bot overlords. Congratulations on another release from the hydra-like world of multi-head development. --Scott David Daniels Scott.Daniels at Acm.Org From p.f.moore at gmail.com Sun Jun 28 11:45:51 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 28 Jun 2009 16:45:51 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4a4763d5$0$307$9b622d9e@news.freenet.de> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> 2009/6/28 "Martin v. L?wis" : >> However, sys.std{in,out,err} are still created as text streams, and AFAICT >> there's nothing you can do about this from within your code. > > That's intentional, and not going to change. You can access the > underlying byte streams if you want to, as you could already in 3.0. I had a quick look at the documentation, and couldn't see how to do this. It's the first time I'd read the new IO module documentation, so I probably missed something obvious. Could you explain how I get the byte stream underlying sys.stdin? (That should give me enough to find what I was misunderstanding in the docs). Thanks, Paul. From aahz at pythoncraft.com Sun Jun 28 11:52:11 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 08:52:11 -0700 Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> <0062db08$0$9714$c3e8da3@news.astraweb.com> <87bpo8vjjz.fsf@benfinney.id.au> Message-ID: In article <87bpo8vjjz.fsf at benfinney.id.au>, Ben Finney wrote: >Steven D'Aprano writes: >> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote: >>> >>> (Even if you don't want to receive email, could you please give your >>> actual name in the ???From??? field instead of just initials? It makes >>> conversation less confusing.) >> >> Some people prefer to be known by their initials. > >Some people prefer to spend their volunteer time conversing with people >who don't just use initials or pseudonyms. Bully for you! Just don't bully people who don't follow your preferred naming system. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From twirlip at bigfoot.com Sun Jun 28 12:03:59 2009 From: twirlip at bigfoot.com (Angus Rodgers) Date: Sun, 28 Jun 2009 17:03:59 +0100 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: On 28 Jun 2009 08:00:23 -0700, aahz at pythoncraft.com (Aahz) wrote: >In article <0qec45lho8lkng4n20sb1ad4eguat675pb at 4ax.com>, >Angus Rodgers wrote: >> >>Partly as an educational exercise, and partly for its practical >>benefit, I'm trying to pick up a programming project from where >>I left off in 2001. It implemented in slightly generalised form >>the "buffer pair" scheme for lexical analysis described on pp. >>88--92 of Aho et al., /Compilers: Principles, Techniques and >>Tools/ (1986). (I'm afraid I don't have a page reference for the >>2007 second edition. Presumably it's also in Knuth somewhere.) >> >> [...] >> >>Does some Python library already provide some functionality like >>this? (It's enough to do it with nblocks = 2, as in Aho et al.) > >Not AFAIK, but there may well be something in the recipes or PyPI; have >you tried searching them? Searching for "buffer" at (which I didn't know about) gives quite a few hits (including reflex 0.1, "A lightweight regex-based lexical scanner library"). By "recipes", do you mean (also new to me)? There is certainly a lot of relevant code there (e.g. "Recipe 392150: Buffered Stream with Multiple Forward-Only Readers"), which I can try to learn from, even if I can't use it directly. Thanks! -- Angus Rodgers From piet at cs.uu.nl Sun Jun 28 12:09:47 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 28 Jun 2009 18:09:47 +0200 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: >>>>> Paul Moore (PM) wrote: >PM> 2009/6/28 "Martin v. L?wis" : >>>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>>> there's nothing you can do about this from within your code. >>> >>> That's intentional, and not going to change. You can access the >>> underlying byte streams if you want to, as you could already in 3.0. >PM> I had a quick look at the documentation, and couldn't see how to do >PM> this. It's the first time I'd read the new IO module documentation, so >PM> I probably missed something obvious. Could you explain how I get the >PM> byte stream underlying sys.stdin? (That should give me enough to find >PM> what I was misunderstanding in the docs). http://docs.python.org/3.1/library/sys.html#sys.stdin -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From lists at cheimes.de Sun Jun 28 12:09:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 28 Jun 2009 18:09:57 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> Message-ID: <4A4795D5.4070304@cheimes.de> Paul Moore schrieb: > 2009/6/28 "Martin v. L?wis" : >>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>> there's nothing you can do about this from within your code. >> That's intentional, and not going to change. You can access the >> underlying byte streams if you want to, as you could already in 3.0. > > I had a quick look at the documentation, and couldn't see how to do > this. It's the first time I'd read the new IO module documentation, so > I probably missed something obvious. Could you explain how I get the > byte stream underlying sys.stdin? (That should give me enough to find > what I was misunderstanding in the docs). You've missed the most obvious place to look for the feature -- the documentation of sys.stdin :) http://docs.python.org/3.0/library/sys.html#sys.stdin >>> import sys >>> sys.stdin >>> sys.stdin.buffer >>> sys.stdin.read(1) '\n' >>> sys.stdin.buffer.read(1) b'\n' Christian From lists at cheimes.de Sun Jun 28 12:09:57 2009 From: lists at cheimes.de (Christian Heimes) Date: Sun, 28 Jun 2009 18:09:57 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> Message-ID: <4A4795D5.4070304@cheimes.de> Paul Moore schrieb: > 2009/6/28 "Martin v. L?wis" : >>> However, sys.std{in,out,err} are still created as text streams, and AFAICT >>> there's nothing you can do about this from within your code. >> That's intentional, and not going to change. You can access the >> underlying byte streams if you want to, as you could already in 3.0. > > I had a quick look at the documentation, and couldn't see how to do > this. It's the first time I'd read the new IO module documentation, so > I probably missed something obvious. Could you explain how I get the > byte stream underlying sys.stdin? (That should give me enough to find > what I was misunderstanding in the docs). You've missed the most obvious place to look for the feature -- the documentation of sys.stdin :) http://docs.python.org/3.0/library/sys.html#sys.stdin >>> import sys >>> sys.stdin >>> sys.stdin.buffer >>> sys.stdin.read(1) '\n' >>> sys.stdin.buffer.read(1) b'\n' Christian From p.f.moore at gmail.com Sun Jun 28 12:18:37 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 28 Jun 2009 17:18:37 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4A4795D5.4070304@cheimes.de> References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> <4A4795D5.4070304@cheimes.de> Message-ID: <79990c6b0906280918r7a88480al5a1a795293a0cac9@mail.gmail.com> 2009/6/28 Christian Heimes : > Paul Moore schrieb: >> I had a quick look at the documentation, and couldn't see how to do >> this. It's the first time I'd read the new IO module documentation, so >> I probably missed something obvious. Could you explain how I get the >> byte stream underlying sys.stdin? (That should give me enough to find >> what I was misunderstanding in the docs). > > You've missed the most obvious place to look for the feature -- the > documentation of sys.stdin :) > > http://docs.python.org/3.0/library/sys.html#sys.stdin > >>>> import sys >>>> sys.stdin > >>>> sys.stdin.buffer > >>>> sys.stdin.read(1) > > '\n' >>>> sys.stdin.buffer.read(1) Thanks. Like you say, the obvious place I didn't think of... :-) (I'd have experimented, but this PC doesn't have Python 3 installed at the moment :-() The "buffer" attribute doesn't seem to be documented in the docs for the io module. I'm guessing that the TextIOBase class should have a note that you get at the buffer through the "buffer" attribute? Paul. From aahz at pythoncraft.com Sun Jun 28 12:26:23 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 09:26:23 -0700 Subject: Buffer pair for lexical analysis of raw binary data References: <0qec45lho8lkng4n20sb1ad4eguat675pb@4ax.com> Message-ID: In article , Angus Rodgers wrote: > >By "recipes", do you mean > (also new to me)? Yup! You may also want to pick up the edited recipes in the Python Cookbook. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From nobody at nowhere.com Sun Jun 28 12:27:52 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 17:27:52 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 15:22:15 +0000, Benjamin Peterson wrote: > Nobody nowhere.com> writes: >> All in all, Python 3.x still has a long way to go before it will be >> suitable for real-world use. > > Such as? Such as not trying to shoe-horn every byte string it encounters into Unicode. Some of them really are *just* byte strings. From no.email at please.post Sun Jun 28 13:22:29 2009 From: no.email at please.post (kj) Date: Sun, 28 Jun 2009 17:22:29 +0000 (UTC) Subject: The Python Way for module configuration? References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: In <87fxdlujds.fsf at benfinney.id.au> Ben Finney writes: >(Even if you don't want to receive email, could you please give your >actual name in the ???From??? field instead of just initials? It makes >conversation less confusing.) I don't know why, but for as long as I can remember everyone calls me kj, even my mom. My name is Keaweikekahiali??iokamoku Jallalahwallalruwalpindi kj From benjamin at python.org Sun Jun 28 13:24:11 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 17:24:11 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > Such as not trying to shoe-horn every byte string it encounters into > Unicode. Some of them really are *just* byte strings. You're certainly allowed to convert them back to byte strings if you want. From tjreedy at udel.edu Sun Jun 28 13:31:50 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 13:31:50 -0400 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Nobody wrote: > On Sun, 28 Jun 2009 15:22:15 +0000, Benjamin Peterson wrote: > >> Nobody nowhere.com> writes: >>> All in all, Python 3.x still has a long way to go before it will be >>> suitable for real-world use. >> Such as? > > Such as not trying to shoe-horn every byte string it encounters into > Unicode. Some of them really are *just* byte strings. Let's ignore the disinformation. So false it is hardly worth refuting. From benjamin at python.org Sun Jun 28 13:34:34 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 17:34:34 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> <79990c6b0906280845t65846f0ch90367a6db64767b@mail.gmail.com> <4A4795D5.4070304@cheimes.de> <79990c6b0906280918r7a88480al5a1a795293a0cac9@mail.gmail.com> Message-ID: Paul Moore gmail.com> writes: > The "buffer" attribute doesn't seem to be documented in the docs for > the io module. I'm guessing that the TextIOBase class should have a > note that you get at the buffer through the "buffer" attribute? Good point. I've now documented it, and the "raw" attribute of BufferedIOBase. From benjamin.kaplan at case.edu Sun Jun 28 13:51:08 2009 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 28 Jun 2009 13:51:08 -0400 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: References: <24239603.post@talk.nabble.com> Message-ID: On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote: > In article , > Tim Chase ? wrote: >> >>> - how do i design GUI for windows app? >> >>http://lmgtfy.com/?q=python+gui > > This is the first time I've tried LMGTFY, and it seems to be a piece of > trash that requires JavaScript. ?I suggest that lmgtfy.com not be > considered a standard part of the Python community. It's not a standard part of the python community. It stands for "let me google that for you" and it's a slightly more polite way of saying STFW. It's just an animation of typing the search term in a Google-like search page and clicking the search button. Then it says "was that so hard" and redirects you to the Google search results for that term. > -- > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > "as long as we like the same operating system, things are cool." --piranha > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sun Jun 28 14:10:23 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 14:10:23 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a47862b$0$31117$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) See the weakref module. But note that in CPython, objects are collected as soon as there all no normal references, not when 'needed'. > > > # Fastest approach: > imgs = {} > for fname in all_image_files: > imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > img = do_somethingwith(img,imgs[img_file]) > img.save() > > > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > if src_img in imgs: # if 'm lucke the object is still there > src_img = imgs[img_file] > else: > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > Is this possible? From sajmikins at gmail.com Sun Jun 28 14:19:26 2009 From: sajmikins at gmail.com (Simon Forman) Date: Sun, 28 Jun 2009 11:19:26 -0700 (PDT) Subject: creating garbage collectable objects (caching objects) References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <1c0621d9-c38b-4117-8bf9-0b4b8bf0ba15@r10g2000yqa.googlegroups.com> On Jun 28, 11:03?am, News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) > > # Fastest approach: > imgs = {} > for fname in all_image_files: > ? ? imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? img = do_somethingwith(img,imgs[img_file]) > ? ? img.save() > > # Slowest approach: > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? src_img = Image.open(img_file) > ? ? ? ? img = do_somethingwith(img,src_img) > ? ? img.save() > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > ? ? img = Image.new(...) > ? ? for img_file in creation_rule.input_files(): > ? ? ? ? if src_img in imgs: # if 'm lucke the object is still there > ? ? ? ? ? ? ? ? src_img = imgs[img_file] > ? ? ? ? else: > ? ? ? ? ? ? ? ? src_img = Image.open(img_file) > ? ? ? ? img = do_somethingwith(img,src_img) > ? ? img.save() > > Is this possible? > > Thaks in advance for an answer or any other ideas of > how I could do smart caching without hogging all the system's > memory Maybe I'm just being thick today, but why would the "slow" approach be slow? The same amount of I/O and processing would be done either way, no? Have you timed both methods? That said, take a look at the weakref module Terry Reedy already mentioned, and maybe the gc (garbage collector) module too (although that might just lead to wasting a lot of time fiddling with stuff that the gc is supposed to handle transparently for you in the first place.) From shr at basushr.net Sun Jun 28 14:31:00 2009 From: shr at basushr.net (Shrutarshi Basu) Date: Sun, 28 Jun 2009 14:31:00 -0400 Subject: Flexible warning system Message-ID: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> I'm writing a Python package where I have an underlying object model that is manipulated by a runtime control layer and clients that interface with this runtime. As I'm developing this i'm realizing that there are going to be a number of places where the runtime might affect the object model in ways that might not be immediately obvious to the user. I would like to have some sort of warning system where the runtime can raise a warning and then the clients can 'catch' those warnings and display them as they want to. Is there some sort of a system that will operates like that or will I have to roll my own? If I do need to roll my own, any ideas on how I should go about it? I know that there is a warning module, but it seems to that all outputs go to standard out which isn't what I want. Thanks, Basu Shrutarshi Basu Computer Science, Electrical and Computer Engineering, Lafayette College, The ByteBaker -- http://bytebaker.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Sun Jun 28 14:35:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 28 Jun 2009 15:35:45 -0300 Subject: Running a script from a windows right click menu..? References: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> Message-ID: En Sun, 28 Jun 2009 10:45:49 -0300, Nuff Nuff escribi?: > I wrote a little script that affects a bunch of files in the folder > that it is run in. > > Now what I want to do is to make it run from the right click menu but > I don't know how. > > Would you give me an example script that will simply print the > woriking directory, and show me how to add that to the right click > menu in windows explorer? In the Windows registry, add a new key under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell Make its default value the item text you want in the context menu. Add a new key under it, "command", and make its default value the command line you want to execute. Will look like this: "path to python.exe" "path to your script.py" %1 %* See http://msdn.microsoft.com/en-us/library/dd807139(VS.85).aspx for more details -- Gabriel Genellina From aahz at pythoncraft.com Sun Jun 28 14:43:19 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 11:43:19 -0700 Subject: [RELEASED] Python 3.1 final References: Message-ID: In article , Benjamin Peterson wrote: >Nobody nowhere.com> writes: >> >> Such as not trying to shoe-horn every byte string it encounters into >> Unicode. Some of them really are *just* byte strings. > >You're certainly allowed to convert them back to byte strings if you want. Yes, but do you get back the original byte strings? Maybe I'm missing something, but my impression is that this is still an issue for the email module as well as command-line arguments and environment variables. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From aahz at pythoncraft.com Sun Jun 28 14:45:06 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 11:45:06 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: In article , Benjamin Kaplan wrote: >On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote: >> In article , >> Tim Chase =A0 wrote: >>> >>>> - how do i design GUI for windows app? >>> >>>http://lmgtfy.com/?q=3Dpython+gui >> >> This is the first time I've tried LMGTFY, and it seems to be a piece of >> trash that requires JavaScript. =A0I suggest that lmgtfy.com not be >> considered a standard part of the Python community. > >It's not a standard part of the python community. It stands for "let >me google that for you" and it's a slightly more polite way of saying >STFW. > >It's just an animation of typing the search term in a Google-like >search page and clicking the search button. Then it says "was that so >hard" and redirects you to the Google search results for that term. Perhaps I was unclear: I already knew what LMGTFY stands for, and I think that using a site that requires JavaScript is anti-social. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From enleverLesX_XXmcX at XmclavXeauX.com Sun Jun 28 14:50:03 2009 From: enleverLesX_XXmcX at XmclavXeauX.com (Michel Claveau - MVP) Date: Sun, 28 Jun 2009 20:50:03 +0200 Subject: Running a script from a windows right click menu..? References: <14b5ff95-41d5-4419-9ddc-ab1ffb0b1faf@d32g2000yqh.googlegroups.com> Message-ID: <4a47bb5d$0$17099$ba4acef3@news.orange.fr> Bonsoir ! Un exemple l?: http://www.mclaveau.com/grimoire/bleu.html#999 @-salutations -- MCI From davea at ieee.org Sun Jun 28 14:51:31 2009 From: davea at ieee.org (Dave Angel) Date: Sun, 28 Jun 2009 14:51:31 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a47862b$0$31117$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <4A47BBB3.3050704@ieee.org> News123 wrote: > Hi. > > I started playing with PIL. > > I'm performing operations on multiple images and would like compromise > between speed and memory requirement. > > The fast approach would load all images upfront and create then multiple > result files. The problem is, that I do not have enough memory to load > all files. > > The slow approach is to load each potential source file only when it is > needed and to release it immediately after (leaving it up to the gc to > free memory when needed) > > > > The question, that I have is whether there is any way to tell python, > that certain objects could be garbage collected if needed and ask python > at a later time whether the object has been collected so far (image has > to be reloaded) or not (image would not have to be reloaded) > > > # Fastest approach: > imgs = {} > for fname in all_image_files: > imgs[fname] = Image.open(fname) > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > img = do_somethingwith(img,imgs[img_file]) > img.save() > > > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > # What I'd like to do is something like: > imgs = GarbageCollectable_dict() > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > if src_img in imgs: # if 'm lucke the object is still there > src_img = imgs[img_file] > else: > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) > img.save() > > > > Is this possible? > > Thaks in advance for an answer or any other ideas of > how I could do smart caching without hogging all the system's > memory > > > You don't say what implementation of Python, nor on what OS platform. Yet you're asking how to influence that implementation. In CPython, version 2.6 (and probably most other versions, but somebody else would have to chime in) an object is freed as soon as its reference count goes to zero. So the garbage collector is only there to catch cycles, and it runs relatively infrequently. So, if you keep a reference to an object, it'll not be freed. Theoretically, you can use the weakref module to keep a reference without inhibiting the garbage collection, but I don't have any experience with the module. You could start by studying its documentation. But probably you want a weakref.WeakValueDictionary. Use that in your third approach to store the cache. If you're using Cython or Jython, or one of many other implementations, the rules will be different. The real key to efficiency is usually managing locality of reference. If a given image is going to be used for many output files, you might try to do all the work with it before going on to the next image. In that case, it might mean searching all_creation_rules for rules which reference the file you've currently loaded, measurement is key. From benjamin at python.org Sun Jun 28 15:21:49 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 19:21:49 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Aahz pythoncraft.com> writes: > Yes, but do you get back the original byte strings? Maybe I'm missing > something, but my impression is that this is still an issue for the email > module as well as command-line arguments and environment variables. The email module is, yes, broken. You can recover the bytestrings of command-line arguments and environment variables. From nobody at nowhere.com Sun Jun 28 16:54:34 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 21:54:34 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: >> Yes, but do you get back the original byte strings? Maybe I'm missing >> something, but my impression is that this is still an issue for the email >> module as well as command-line arguments and environment variables. > > The email module is, yes, broken. You can recover the bytestrings of > command-line arguments and environment variables. 1. Does Python offer any assistance in doing so, or do you have to manually convert the surrogates which are generated for unrecognised bytes? 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? Most of the issues can be worked around by calling sys.setfilesystemencoding('iso-8859-1') at the start of the program, but sys.argv and os.environ have already been converted by this point. From thomas.robitaille at gmail.com Sun Jun 28 17:00:46 2009 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Sun, 28 Jun 2009 14:00:46 -0700 (PDT) Subject: Column types with DB API Message-ID: <24245424.post@talk.nabble.com> Hi, I'm trying to use DB API compliant database modules (psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to determine the type of each column in a table. The DB API defines cursor.description which contains information about the column names and types (once .execute() has been used to select part or all of the table), but the types are expressed as integers. I realize that these numbers can be checked against the type objects such as MySQLdb.NUMBER to determine whether a given column is a number, a date, text, etc. However, is there any way to determine what the sub-type of a column is, for example if a column is a NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or real number? Thanks in advance for any advice, Thomas -- View this message in context: http://www.nabble.com/Column-types-with-DB-API-tp24245424p24245424.html Sent from the Python - python-list mailing list archive at Nabble.com. From nobody at nowhere.com Sun Jun 28 17:01:34 2009 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Jun 2009 22:01:34 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 13:31:50 -0400, Terry Reedy wrote: >>> Nobody nowhere.com> writes: >>>> All in all, Python 3.x still has a long way to go before it will be >>>> suitable for real-world use. >>> Such as? >> >> Such as not trying to shoe-horn every byte string it encounters into >> Unicode. Some of them really are *just* byte strings. > > Let's ignore the disinformation. Translation: let's ignore anything which falsifies the assumptions. > So false it is hardly worth refuting. Your copy of Trolling by Numbers must be getting pretty dog-eared by now. From benjamin at python.org Sun Jun 28 17:25:13 2009 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 28 Jun 2009 21:25:13 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: > > >> Yes, but do you get back the original byte strings? Maybe I'm missing > >> something, but my impression is that this is still an issue for the email > >> module as well as command-line arguments and environment variables. > > > > The email module is, yes, broken. You can recover the bytestrings of > > command-line arguments and environment variables. > > 1. Does Python offer any assistance in doing so, or do you have to > manually convert the surrogates which are generated for unrecognised bytes? fs_encoding = sys.getfilesystemencoding() bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] > > 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? What's a non-invertible encoding? I can't find a reference to the term. From nikon at puffy.pl Sun Jun 28 17:26:21 2009 From: nikon at puffy.pl (Tomasz Pajor) Date: Sun, 28 Jun 2009 23:26:21 +0200 Subject: fork, threads and proper closing Message-ID: <4A47DFFD.2030400@puffy.pl> Hello, Configuration is as follows. I have a starter process which creates 3 sub processes (forks) and each of this processes creates a number of threads. Threads in that processes have semaphore so on KeyboardInterrupt without sending a sigterm to the subprocess i'm not able to close threads. Is there any work around? Can I somehow run join for the thread on keyboard interrupt? -- Best regards Tomasz Pajor From h.b.furuseth at usit.uio.no Sun Jun 28 17:34:10 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Sun, 28 Jun 2009 23:34:10 +0200 Subject: [RELEASED] Python 3.1 final References: Message-ID: Benjamin Peterson writes: >Nobody nowhere.com> writes: >> On Sun, 28 Jun 2009 19:21:49 +0000, Benjamin Peterson wrote: >> 1. Does Python offer any assistance in doing so, or do you have to >> manually convert the surrogates which are generated for unrecognised bytes? > > fs_encoding = sys.getfilesystemencoding() > bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] > >> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? > > What's a non-invertible encoding? I can't find a reference to the term. Different ISO-2022 strings can map to the same Unicode string. Thus you can convert back to _some_ ISO-2022 string, but it won't necessarily match the original. -- Hallvard From martin at v.loewis.de Sun Jun 28 17:50:44 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 28 Jun 2009 23:50:44 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <4a47e5b4$0$30303$9b622d9e@news.freenet.de> > 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? ISO-2022 cannot be used as a system encoding. Please do read the responses I write, and please do identify yourself. Regards, Martin From rhodri at wildebst.demon.co.uk Sun Jun 28 17:58:53 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 22:58:53 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: On Sat, 27 Jun 2009 22:12:10 +0100, Benjamin Peterson wrote: > On behalf of the Python development team, I'm thrilled to announce the > first production release of Python 3.1. Why is everyone always thrilled to announce things? Why is noone ever bored to announce? :-) So PEP 378 got in then? Bleh. It's still the wrong solution, and it still makes the right solution harder to do. -- Rhodri James *-* Wildebeest Herder to the Masses From martin at v.loewis.de Sun Jun 28 18:13:34 2009 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 29 Jun 2009 00:13:34 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> Message-ID: <4a47eb0e$0$30901$9b622d9e@news.freenet.de> >> On behalf of the Python development team, I'm thrilled to announce the >> first production release of Python 3.1. > > Why is everyone always thrilled to announce things? I cannot talk about everyone, but in the specific case, I suppose Benjamin was thrilled because it was his first release of a large open source software package. Knowing that you have worked so long on a single project, to see the project then finally completed, is exciting - just try it out for yourself. Regards, Martin From rhodri at wildebst.demon.co.uk Sun Jun 28 18:16:39 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 23:16:39 +0100 Subject: pep 8 constants In-Reply-To: <4A477991.4050109@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: On Sun, 28 Jun 2009 15:09:21 +0100, Eric S. Johansson wrote: > Bruno Desthuilliers wrote: >> Brendan Miller a ?crit : >>> PEP 8 doesn't mention anything about using all caps to indicate a >>> constant. >>> >>> Is all caps meaning "don't reassign this var" a strong enough >>> convention to not be considered violating good python style? I see a >>> lot of people using it, but I also see a lot of people writing >>> non-pythonic code... so I thought I'd see what the consensus is. >> >> Most - if not all - of the python code I've seen so far used this >> convention, and I always used (and respected) it myself. > > I reject this convention because any form of caps significantly > increases vocal > load for disabled programmers using speech recognition through extra > utterances, > and degraded recognition. Reject away, but I'm afraid you've still got some work to do to convince me that PEP 8 is more work for an SR system than any other convention. If, on the other hand you're trying to convince me that *no* convention is preferable, I'm going to laugh hollowly. -- Rhodri James *-* Wildebeest Herder to the Masses From rhodri at wildebst.demon.co.uk Sun Jun 28 18:17:37 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 28 Jun 2009 23:17:37 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: <4a47eb0e$0$30901$9b622d9e@news.freenet.de> References: <1afaf6160906271412v3ca3ef9bo4efa4523db3a3685@mail.gmail.com> <4a47eb0e$0$30901$9b622d9e@news.freenet.de> Message-ID: On Sun, 28 Jun 2009 23:13:34 +0100, Martin v. L?wis wrote: >>> On behalf of the Python development team, I'm thrilled to announce the >>> first production release of Python 3.1. >> >> Why is everyone always thrilled to announce things? > > I cannot talk about everyone, but in the specific case, I suppose > Benjamin was thrilled because it was his first release of a large > open source software package. Knowing that you have worked so long > on a single project, to see the project then finally completed, > is exciting - just try it out for yourself. There was a smiley at the end of that paragraph, Martin! -- Rhodri James *-* Wildebeest Herder to the Masses From gh at ghaering.de Sun Jun 28 18:21:22 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 29 Jun 2009 00:21:22 +0200 Subject: Column types with DB API In-Reply-To: <24245424.post@talk.nabble.com> References: <24245424.post@talk.nabble.com> Message-ID: Thomas Robitaille wrote: > Hi, > > I'm trying to use DB API compliant database modules > (psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to > determine the type of each column in a table. The DB API defines > cursor.description which contains information about the column names and > types (once .execute() has been used to select part or all of the table), > but the types are expressed as integers. I realize that these numbers can be > checked against the type objects such as MySQLdb.NUMBER to determine whether > a given column is a number, a date, text, etc. However, is there any way to > determine what the sub-type of a column is, for example if a column is a > NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or > real number? Not with the DB-API. You'll have to implement all this for each database separately. For some databases (like SQLite) it's even impossible. I suggest you don't bother with cursor.description at all. Depending on it doesn't harmonize with the way Python is typically used: duck typing. -- Gerhard From gh at ghaering.de Sun Jun 28 18:23:04 2009 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 29 Jun 2009 00:23:04 +0200 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: Scott David Daniels wrote: > Nobody wrote: >> On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: >> >> >> That's a significant improvement.... >> All in all, Python 3.x still has a long way to go before it will be >> suitable for real-world use. > > Fortunately, I have assiduously avoided the real word, and am happy to > embrace the world from our 'bot overlords. > > Congratulations on another release from the hydra-like world of > multi-head development. +1 QOTW -- Gerhard From hanooter at gmail.com Sun Jun 28 19:13:18 2009 From: hanooter at gmail.com (mclovin) Date: Sun, 28 Jun 2009 16:13:18 -0700 (PDT) Subject: handeling very large dictionaries Message-ID: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Hello all, I need to have a dictionary of about 8 gigs (well the data it is processing is around 4gb). so naturally i am running into memory errors. So i looked around and found bsddb which acts like a dictionary object only offloads the data from the RAM to the HDD, however that only supports strings. my dictionaries hold my own class objects Is there something like it that is more flexible? From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 19:23:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 23:23:02 GMT Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> Message-ID: <0063d626$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 03:28:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> I thought we were talking about discontinuities in *nature*, not in >> mathematics. There's no "of course" about it. > > IIRC we were talking about fractals, which are a topic in mathematics. > This led to some discussion of mathematical continuity, and the claim > that mathematical discontinuity doesn't appear to occur in nature (and > according to some, it shouldn't occur in mathematics either). I would argue that it's the other way around: mathematical *continuity* doesn't occur in nature. If things look continuous, it's only because we're not looking close enough. But that depends on what you call "things"... if electron shells are real (and they seem to be) and discontinuous, and the shells are predicted/ specified by eigenvalues of some continuous function, is the continuous function part of nature or just a theoretical abstraction? >> In mathematics, you can cut up a pea and reassemble it into a solid >> sphere the size of the Earth. Try doing that with a real pea. > > That's another example of a mathematical phenomenon that doesn't occur > in nature. What are you getting at? The point is that you can't safely draw conclusions about *nature* from *mathematics*. The existence or non-existence of discontinuities/ continuities in nature is an empirical question that can't be settled by any amount of armchair theorising, even very intelligent theorising, by theorists, philosophers or mathematicians. You have to go out and look. By the way, the reason you can't do to a pea in reality what you can do with a mathematical abstraction of a pea is because peas are made of discontinuous atoms. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Jun 28 19:30:23 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Jun 2009 23:30:23 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> Message-ID: <0063d7e0$0$9714$c3e8da3@news.astraweb.com> On Sun, 28 Jun 2009 10:09:21 -0400, Eric S. Johansson wrote: > Bruno Desthuilliers wrote: >> Brendan Miller a ?crit : >>> PEP 8 doesn't mention anything about using all caps to indicate a >>> constant. >>> >>> Is all caps meaning "don't reassign this var" a strong enough >>> convention to not be considered violating good python style? I see a >>> lot of people using it, but I also see a lot of people writing >>> non-pythonic code... so I thought I'd see what the consensus is. >> >> Most - if not all - of the python code I've seen so far used this >> convention, and I always used (and respected) it myself. > > I reject this convention because any form of caps significantly > increases vocal load for disabled programmers using speech recognition > through extra utterances, and degraded recognition. [...] > so I reject pep 8 because I have no voice safe alternative And you are perfectly entitled to. That puts you at a disadvantage if you wish to submit code for the standard library, where PEP 8 compliance is required, but for your own code you are entitled to use whatever conventions you prefer. -- Steven From http Sun Jun 28 19:59:09 2009 From: http (Paul Rubin) Date: 28 Jun 2009 16:59:09 -0700 Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7x4otzykoi.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > But that depends on what you call "things"... if electron shells are real > (and they seem to be) and discontinuous, and the shells are predicted/ > specified by eigenvalues of some continuous function, is the continuous > function part of nature or just a theoretical abstraction? Again, electron shells came up in the context of a question about quantum theory, which is a mathematical theory involving continuous operators. That theory appears to very accurately model and predict observable natural phenomena. Is the real physical mechanism underneath observable nature actually some kind of discrete "checkers game" to which quantum theory is merely a close approximation? Maybe, but there's not a predictive mathematical theory like that right now, and even if there was, we'd be back to the question of just how it is that the checkers get from one place to another. > By the way, the reason you can't do to a pea in reality what you can do > with a mathematical abstraction of a pea is because peas are made of > discontinuous atoms. Not so much discontinuity, as the physical unreality of non-measurable sets. From cook_jim at yahoo.com Sun Jun 28 21:40:55 2009 From: cook_jim at yahoo.com (bootkey) Date: Sun, 28 Jun 2009 18:40:55 -0700 (PDT) Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> Message-ID: <40e3eff9-9e5c-4979-91bd-c85988352e91@k15g2000yqc.googlegroups.com> On Jun 28, 1:46?am, Tim Roberts wrote: > Jim wrote: > >I'm trying to understand the output of the tokenize.generate_tokens() > >generator. ?The token types returned seem to be more general than I'd > >expect. ?For example, when fed the following line of code: > > >def func_a(): > >... > >It seems to me that the token '(' should be identified as 'LPAR' and > >')' as 'RPAR', as found in the dictionary token.tok_name. ?What am I > >missing here? > > Did you read the module? ?Right at the top, it says: > > > It is designed to match the working of the Python tokenizer exactly, except > that it produces COMMENT tokens for comments and gives type OP for all > operators > > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Thanks for the reply. I wonder why the tokenizer classifies all operators simply as OP, instead of the various operators listed in the tok_name dictionary. Jim Cook From greg at cosc.canterbury.ac.nz Sun Jun 28 21:51:12 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 29 Jun 2009 13:51:12 +1200 Subject: Measuring Fractal Dimension ? In-Reply-To: <0062e638$0$9714$c3e8da3@news.astraweb.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> Message-ID: <7aqkukF20j8k3U1@mid.individual.net> Steven D'Aprano wrote: > one > minute the grenade is sitting there, stable as can be, the next it's an > expanding cloud of gas and metal fragments. I'm not sure that counts as "discontinuous" in the mathematical sense. If you were to film the grenade exploding and play it back slowly enough, the process would actually look fairly smooth. Mathematically, it's possible for a system to exhibit chaotic behaviour (so that you can't tell exactly when the grenade is going to go off) even though all the equations describing its behaviour are smooth and continuous. > My money is on the universe being fundamentally discontinuous. That's quite likely true. Quantum mechanics doesn't actually predict discrete behaviour -- the mathematics deals with continuously-changing state functions. It's only the interpretation of those functions (as determining the probabilities of finding the system in one of a discrete set of states) that introduces discontinuities. So it seems quite plausible that the continuous functions are just approximations of some underlying discrete process. The trick will be figuring out how such a process can work without running afoul of the various theorems concerning the non-existince of hidden variable theories... -- Greg From greg at cosc.canterbury.ac.nz Sun Jun 28 22:17:18 2009 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 29 Jun 2009 14:17:18 +1200 Subject: Measuring Fractal Dimension ? In-Reply-To: <7x4otzykoi.fsf@ruckus.brouhaha.com> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> <7x4otzykoi.fsf@ruckus.brouhaha.com> Message-ID: <7aqmfiF1vh4vfU1@mid.individual.net> Paul Rubin wrote: > Steven D'Aprano writes: > >>But that depends on what you call "things"... if electron shells are real >>(and they seem to be) and discontinuous, and the shells are predicted/ >>specified by eigenvalues of some continuous function, is the continuous >>function part of nature or just a theoretical abstraction? Another thing to think about: If you put the atom in a magnetic field, the energy levels of the electrons get shifted slightly. To the extent that you can vary the magnetic field continuously, you can continuously adjust the energy levels. This of course raises the question of whether it's really possible to continuously adjust a magnetic field. But it's at least possible to do so with much finer granularity than the differences between energy levels in an atom. So if there is a fundamentally discrete model underlying everything, it must be at a much finer granularity than anything we've so far observed, and the discrete things that we have observed probably aren't direct reflections of it. -- Greg From aahz at pythoncraft.com Sun Jun 28 22:39:00 2009 From: aahz at pythoncraft.com (Aahz) Date: 28 Jun 2009 19:39:00 -0700 Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: In article <9efff087-bd6e-49fb-ad30-a955a64b85f9 at j32g2000yqh.googlegroups.com>, mclovin wrote: > >I need to have a dictionary of about 8 gigs (well the data it is >processing is around 4gb). so naturally i am running into memory >errors. > >So i looked around and found bsddb which acts like a dictionary object >only offloads the data from the RAM to the HDD, however that only >supports strings. Look at the pickle module. Personally, I'd use SQLite instead of bsddb. You might also look into a full-blown ORM such as SQLAlchemy. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From tjreedy at udel.edu Sun Jun 28 23:01:02 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Jun 2009 23:01:02 -0400 Subject: Measuring Fractal Dimension ? In-Reply-To: <7aqkukF20j8k3U1@mid.individual.net> References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <7xfxdyrk97.fsf@ruckus.brouhaha.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7aqkukF20j8k3U1@mid.individual.net> Message-ID: greg wrote: > Steven D'Aprano wrote: >> one minute the grenade is sitting there, stable as can be, the next >> it's an expanding cloud of gas and metal fragments. > > I'm not sure that counts as "discontinuous" in the mathematical > sense. If you were to film the grenade exploding and play it > back slowly enough, the process would actually look fairly > smooth. radioactive emission might be a better example then. I do not believe there is any acceleration like you see with grenade fragments. Certainly, none with em radiation. Nothing....emission at light speed. From wuwei23 at gmail.com Sun Jun 28 23:03:21 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 28 Jun 2009 20:03:21 -0700 (PDT) Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: On Jun 29, 9:13 am, mclovin wrote: > Is there something like it that is more flexible? Have you seen the stdlib module 'shelve'? http://docs.python.org/library/shelve.html It creates a persistent file-based dictionary, which can hold any type of object as long as it can be pickled. I really like the 3rd party module 'shove': http://pypi.python.org/pypi/shove It's similar to shelve but provides many more backend options, including dbs, svn and Amazon S3. Very handy. From backup95 at netcabo.pt Sun Jun 28 23:23:47 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 04:23:47 +0100 Subject: No trees in the stdlib? In-Reply-To: <7x3a9mkiv6.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> Message-ID: <4A4833C3.6090305@netcabo.pt> Paul Rubin wrote: > aahz at pythoncraft.com (Aahz) writes: > >> (In particular, WRT the bisect module, although insertion and deletion >> are O(N), the constant factor for doing a simple memory move at C speed >> swamps bytecode until N gets very large -- and we already have >> collections.deque() for some other common use cases.) >> > > Again, at least in my case, I'd hope for an immutable structure. > > Could you clarify what you mean by immutable? As in... not mutable? As in without supporting insertions and deletions? That's has the same performance as using binary search on a sorted list. What's the point of using a tree for that? From http Sun Jun 28 23:54:11 2009 From: http (Paul Rubin) Date: 28 Jun 2009 20:54:11 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> Message-ID: <7xeit3ae58.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Could you clarify what you mean by immutable? As in... not mutable? As > in without supporting insertions and deletions? Correct. > That's has the same performance as using binary search on a sorted > list. What's the point of using a tree for that? The idea is you can accomplish the equivalent of insertion or deletion by allocating a new root, along with the path down to the place you want to insert, i.e. O(log n) operations. So instead of mutating an existing tree, you create a new tree that shares most of its structure with the old tree, and switch over to using the new tree. This trivially lets you maintain snapshots of old versions of the tree, implement an "undo" operation, have a background thread do a complex operation on a snapshot while the foreground thread does any number of update-and-replace operations, etc. This is very standard stuff. See: http://en.wikipedia.org/wiki/Persistent_data_structure The wikipedia article on AVL trees makes it pretty obvious how an implementation would work. From esj at harvee.org Mon Jun 29 01:07:19 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 01:07:19 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A484C07.9050800@harvee.org> Rhodri James wrote: > Reject away, but I'm afraid you've still got some work to do to > convince me that PEP 8 is more work for an SR system than any other > convention. Name name higher than normal recognition error rate. can require multiple tries or hand correction MultiWordName mulitwordname very high error rate. many retries or hand hurting typing. multi_word_name multiwordname normal error rate (low), can need multiple tries or hand correction StdlYCps sierra tango delta lima yankee charley papa sierra *** very high error rate *** search and replace for all instances with a x_y_z form name is recommended If, on the other hand you're trying to convince me that > *no* convention is preferable, I'm going to laugh hollowly. no, I know the value if convention when editors can't tell you anything about the name in question. I would like to see more support for disabled programmers like myself and the thousands of programmers injured every year and forced to leave the field. seriously, there is no money in disability access especially for programmers. and forgive me if this comes off sounding like a jerk but if the collective you don't give a sh** about your fellow programmers, who will? should all disabled programmers be dumped on the shelf even their brains are still good and they have guts to try to work in a field that gave them a life rearranging injury? please help. the disability access you help build may save your own job someday. Or, what I need to edit code may make your world better as well. From Olivier.Darge at gmail.com Mon Jun 29 01:10:07 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Sun, 28 Jun 2009 22:10:07 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: On 28 juin, 23:26, Tomasz Pajor wrote: > Hello, > > Configuration is as follows. > > I have a starter process which creates 3 sub processes (forks) and each > of this processes creates a number of threads. > Threads in that processes have semaphore so on KeyboardInterrupt without > sending a sigterm to the subprocess i'm not able to close threads. > Is there any work around? Can I somehow run join for the thread on > keyboard interrupt? When creating a thread you can add a Queue parameter to communicate with threads: http://docs.python.org/library/queue.html easy and reliable. give them a "poison pill" in the queue: a recognizable object placed on the queue that means "when you get this, stop." better to not rely on keyboard for thread stopping. Olivier From backup95 at netcabo.pt Mon Jun 29 01:17:01 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:17:01 +0100 Subject: No trees in the stdlib? In-Reply-To: <7xeit3ae58.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: <4A484E4D.2050702@netcabo.pt> Paul Rubin wrote: > Jo?o Valverde writes: > >> Could you clarify what you mean by immutable? As in... not mutable? As >> in without supporting insertions and deletions? >> > > Correct. > > >> That's has the same performance as using binary search on a sorted >> list. What's the point of using a tree for that? >> > > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. This > trivially lets you maintain snapshots of old versions of the tree, > implement an "undo" operation, have a background thread do a complex > operation on a snapshot while the foreground thread does any number of > update-and-replace operations, etc. > > > Interesting, thanks. The concept is not difficult to understand but I'm not sure it would be preferable. A copy operation should have the same cost as a "snapshot", undo is kind of redundant and multithreading... don't see a compelling use that would justify it. Also the interface is a mapping so it'd be rather nice to emulate dict's. Have you considered how the syntax would work in Python by the way? This: new_tree = old_tree.insert(object) Just looks wrong. The interface should support non functional idioms too. From backup95 at netcabo.pt Mon Jun 29 01:24:36 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:24:36 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A484E4D.2050702@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <4A484E4D.2050702@netcabo.pt> Message-ID: <4A485014.902@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Could you clarify what you mean by immutable? As in... not mutable? As >>> in without supporting insertions and deletions? >> >> Correct. >> >>> That's has the same performance as using binary search on a sorted >>> list. What's the point of using a tree for that? >>> >> >> The idea is you can accomplish the equivalent of insertion or deletion >> by allocating a new root, along with the path down to the place you >> want to insert, i.e. O(log n) operations. So instead of mutating an >> existing tree, you create a new tree that shares most of its structure >> with the old tree, and switch over to using the new tree. This >> trivially lets you maintain snapshots of old versions of the tree, >> implement an "undo" operation, have a background thread do a complex >> operation on a snapshot while the foreground thread does any number of >> update-and-replace operations, etc. >> >> >> > Interesting, thanks. The concept is not difficult to understand but > I'm not sure it would be preferable. A copy operation should have the > same cost as a "snapshot", undo is kind of redundant and > multithreading... don't see a compelling use that would justify it. > Also the interface is a mapping so it'd be rather nice to emulate dict's. > > Have you considered how the syntax would work in Python by the way? This: > > new_tree = old_tree.insert(object) > Heh, that's a poor example for a mapping. But: bst[key] = object is even dicier for immutable structures no? From http Mon Jun 29 01:41:46 2009 From: http (Paul Rubin) Date: 28 Jun 2009 22:41:46 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: <7xprcny4th.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Interesting, thanks. The concept is not difficult to understand but > I'm not sure it would be preferable. A copy operation should have the > same cost as a "snapshot", You mean a deep-copy? That is unnecessarily expensive; with a functional structure you can snapshot (or copy) by copying a single pointer. > undo is kind of redundant and multithreading... don't see a > compelling use that would justify it. Here is one: http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b > Have you considered how the syntax would work in Python by the way? This: > new_tree = old_tree.insert(object) > Just looks wrong. It looks fine to me. Obviously you could support a wrapper with a mutating slot that holds a pointer to the tree. From http Mon Jun 29 01:42:19 2009 From: http (Paul Rubin) Date: 28 Jun 2009 22:42:19 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <4A484E4D.2050702@netcabo.pt> Message-ID: <7xljnby4sk.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > bst[key] = object > is even dicier for immutable structures no? bst = bst.insert(key, object) From ldo at geek-central.gen.new_zealand Mon Jun 29 01:44:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 29 Jun 2009 17:44:17 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message <976cc575-80b9-406a- ae4d-03cb4d401dc4 at p36g2000prn.googlegroups.com>, olivergeorge wrote: > (and why PIL is such a pain to install for that matter.) "apt-get install python-imaging", anybody? From turian at gmail.com Mon Jun 29 01:52:43 2009 From: turian at gmail.com (Joseph Turian) Date: Sun, 28 Jun 2009 22:52:43 -0700 (PDT) Subject: Abort SimpleXMLRPCServer request prematurely? Message-ID: <4886c8dc-235d-4442-b2d6-bc08a023bbd1@h2g2000yqg.googlegroups.com> With SimpleXMLRPCServer, if the server is taking too long, how can I use the client to kill the request and have the server abort prematurely? Thanks, Joseph From wuwei23 at gmail.com Mon Jun 29 01:53:09 2009 From: wuwei23 at gmail.com (alex23) Date: Sun, 28 Jun 2009 22:53:09 -0700 (PDT) Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: "Eric S. Johansson" wrote: > no, I know the value if convention when editors can't tell you anything about > the name in question. ?I would like to see more support for disabled programmers > like myself and the thousands of programmers injured every year and forced to > leave the field. ?seriously, there is no money in disability access especially > for programmers. Well, if we can't use conventions like uppercasing, camelcasing and underscoring, what are you recommending we do instead? You seem to be asking us to change our behaviour to benefit only others, but without offering any guidance on to how that is possible. More importantly, shouldn't these modifications to common conventions be coming _from_ the community of disabled programmers? I have a hard time ensuring that I've gotten accurate requirements from co-workers with whom I can actually see and speak, trying to determine how I could write my code with accessibility in mind without any established means of gauging success just seems impossible. > and forgive me if this comes off sounding like a jerk but if > the collective you don't give a sh** about your fellow programmers, who will? This isn't intended to be callous, as I feel that the collective doesn't care as a whole about _any_ programmers, but isn't the answer the very same disabled programmers for whom accessibility is an issue? Programming tends to be needs driven (which, admittedly, can be simply "to pay the bills"), and those who have a need tend to be better at working out how to address it. One possibility may be to approach a group for whom accessibility is already a consideration, such as the Gnome Accessibility Project: http://live.gnome.org/GAP As they are already developing Python-based accessibility tools for Gnome - http://live.gnome.org/Accessibility/PythonPoweredAccessibility - it wouldn't be a big stretch to start addressing coding accessibility within that scope, either as part of the project or as an independent adjunct to it, especially if someone with domain knowledge volunteered ;) From turian at gmail.com Mon Jun 29 01:54:57 2009 From: turian at gmail.com (Joseph Turian) Date: Sun, 28 Jun 2009 22:54:57 -0700 (PDT) Subject: handeling very large dictionaries References: <9efff087-bd6e-49fb-ad30-a955a64b85f9@j32g2000yqh.googlegroups.com> Message-ID: You could also try using a key-value store. I am using pytc, a Python API for Tokyo Cabinet. It seems to figure out quite nicely when to go to disk, and when to use memory. But I have not done extensive tests. Here is some example code for using pytc: http://github.com/turian/pytc-example/tree/master Joseph On Jun 28, 7:13 pm, mclovin wrote: > Hello all, > > I need to have a dictionary of about 8 gigs (well the data it is > processing is around 4gb). so naturally i am running into memory > errors. > > So i looked around and found bsddb which acts like a dictionary object > only offloads the data from the RAM to the HDD, however that only > supports strings. > > my dictionaries hold my own class objects > > Is there something like it that is more flexible? From backup95 at netcabo.pt Mon Jun 29 01:56:07 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 06:56:07 +0100 Subject: No trees in the stdlib? In-Reply-To: <7xprcny4th.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> Message-ID: <4A485777.2000301@netcabo.pt> Paul Rubin wrote: > Jo?o Valverde writes: > >> Interesting, thanks. The concept is not difficult to understand but >> I'm not sure it would be preferable. A copy operation should have the >> same cost as a "snapshot", >> > > You mean a deep-copy? That is unnecessarily expensive; with a > functional structure you can snapshot (or copy) by copying a single > pointer. > > Shallow copy... >> undo is kind of redundant and multithreading... don't see a >> compelling use that would justify it. >> > > Here is one: > http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b > > I just skimmed that but if someone really needs multithreading for such intensive processing without wanting a database, fair enough I guess. >> Have you considered how the syntax would work in Python by the way? This: >> new_tree = old_tree.insert(object) >> Just looks wrong. >> > > It looks fine to me. Obviously you could support a wrapper with > a mutating slot that holds a pointer to the tree. > I didn't get the last part, sorry. But I think you'd have a lot of users annoyed that the interface is similar to a list yet their objects mysteriously disappear. To me, tree.insert() implies mutability but I defer that to others like yourself with more experience in Python than me. From __peter__ at web.de Mon Jun 29 02:14:03 2009 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Jun 2009 08:14:03 +0200 Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: Eric S. Johansson wrote: > MultiWordName mulitwordname > very high error rate. many retries or hand hurting typing. Can you define macros in your speech recognition software? multiwordname might slightly lower the error rate. Peter From backup95 at netcabo.pt Mon Jun 29 02:16:21 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 07:16:21 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A485777.2000301@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <4A485C35.7090003@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Interesting, thanks. The concept is not difficult to understand but >>> I'm not sure it would be preferable. A copy operation should have the >>> same cost as a "snapshot", >> >> You mean a deep-copy? That is unnecessarily expensive; with a >> functional structure you can snapshot (or copy) by copying a single >> pointer. >> >> > > Shallow copy... > > Actually I meant whatever that snapshot operation is, minus the insertion, if that makes sense. From nikon at puffy.pl Mon Jun 29 02:22:06 2009 From: nikon at puffy.pl (Tomasz Pajor) Date: Mon, 29 Jun 2009 08:22:06 +0200 Subject: fork, threads and proper closing In-Reply-To: References: Message-ID: <4A485D8E.3000108@puffy.pl> > On 28 juin, 23:26, Tomasz Pajor wrote: > >> Hello, >> >> Configuration is as follows. >> >> I have a starter process which creates 3 sub processes (forks) and each >> of this processes creates a number of threads. >> Threads in that processes have semaphore so on KeyboardInterrupt without >> sending a sigterm to the subprocess i'm not able to close threads. >> Is there any work around? Can I somehow run join for the thread on >> keyboard interrupt? >> > > When creating a thread you can add a Queue parameter to communicate > with threads: > http://docs.python.org/library/queue.html > easy and reliable. > > give them a "poison pill" in the queue: a recognizable object placed > on the queue that means "when you get this, stop." > can You provide any working example? > better to not rely on keyboard for thread stopping. > i use keyboard interrupt only for debuging purposes > Olivier > From sjmachin at lexicon.net Mon Jun 29 02:28:39 2009 From: sjmachin at lexicon.net (John Machin) Date: Sun, 28 Jun 2009 23:28:39 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> <7J6dnbgkVoys5NvXnZ2dnUVZ_r1i4p2d@pdx.net> Message-ID: On Jun 28, 6:02?am, Scott David Daniels wrote: > olivergeorge wrote: > > Ditto. ?Anyone know what's happening with pythonware? ?(and why PIL is > > such a pain to install for that matter.) > > (2) I suggest you demand a refund. ... and tell us what the response was :-) From usernet at ilthio.net Mon Jun 29 03:02:53 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 07:02:53 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-29, Lawrence D'Oliveiro wrote: > "apt-get install python-imaging", anybody? C:\>apt-get install python-imaging Bad command or file name Nope. 01:10,501$ apt-get install python-imaging bash: apt-get: command not found Not quite; but, it does give me an idea. Debian usually keeps the origional source packages in their package repositories: 02:09,502,(1)$ wget http://ftp.de.debian.org/debian/pool/main/p/python-imaging/python1.1.5.orig.tar.gz => `python-imaging_1.1.5.orig.tar.gz' Resolving ftp.de.debian.org... 141.76.2.4 Connecting to ftp.de.debian.org|141.76.2.4|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 429,570 (420K) [application/x-gzip] 100%[=========================================>] 429,570 246.97K/s 02:09:43 (246.26 KB/s) - `python-imaging_1.1.5.orig.tar.gz' saved [429570/429570] 01:10,503$ Now that's the ticket! From Andras.Horvath at cern.ch Mon Jun 29 03:18:20 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Mon, 29 Jun 2009 09:18:20 +0200 Subject: validating HTTPS certificates? In-Reply-To: References: Message-ID: <20090629071820.GM3186@cern.ch> On Fri, Jun 26, 2009 at 07:01:24PM +0200, Nobody wrote: > For a urllib-style interface, there's not much point in performing > verification after the fact. Either the library performs verification or > it doesn't. If it doesn't, you've just sent the (potentially confidential) > request to an unknown server; discovering this after the fact doesn't > really help. I was more thinking about supplying a/some CA certificate(s) and requiring that the site cert be valid (otherwise the connection should fail). This sounds very EAFP to me. Andras From sajmikins at gmail.com Mon Jun 29 03:21:16 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:21:16 -0400 Subject: Flexible warning system In-Reply-To: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> References: <61b633e80906281131k5290788esd5f859ca9fd82ecb@mail.gmail.com> Message-ID: <50f98a4c0906290021m114bd8a5y6c91e1ebeceb3256@mail.gmail.com> On Sun, Jun 28, 2009 at 2:31 PM, Shrutarshi Basu wrote: > I'm writing a Python package where I have an underlying object model that is > manipulated by a runtime control layer and clients that interface with this > runtime. As I'm developing this i'm realizing that there are going to be a > number of places where the runtime might affect the object model in ways > that might not be immediately obvious to the user. I would like to have some > sort of warning system where the runtime can raise a warning and then the > clients can 'catch' those warnings and display them as they want to. Is > there some sort of a system that will operates like that or will I have to > roll my own? If I do need to roll my own, any ideas on how I should go about > it? I know that there is a warning module, but it seems to that all outputs > go to standard out which isn't what I want. > Thanks, > Basu > > Shrutarshi Basu > Computer Science, > Electrical and Computer Engineering, > Lafayette College, > The ByteBaker -- http://bytebaker.com > I just glanced at the docs for the warnings module and it seems like exactly what you're asking for, and you can change the default writing to stdout: "Warning messages are normally written to sys.stderr, but their disposition can be changed flexibly, from ignoring all warnings to turning them into exceptions. The disposition of warnings can vary based on the warning category (see below), the text of the warning message, and the source location where it is issued. Repetitions of a particular warning for the same source location are typically suppressed." - http://docs.python.org/library/warnings.html That said, why not just use exceptions? HTH, ~Simon From sajmikins at gmail.com Mon Jun 29 03:23:07 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:23:07 -0400 Subject: The Python Way for module configuration? In-Reply-To: References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: <50f98a4c0906290023w2cb7952bn867dc54e53933573@mail.gmail.com> On Sun, Jun 28, 2009 at 1:22 PM, kj wrote: > In <87fxdlujds.fsf at benfinney.id.au> Ben Finney writes: > >>(Even if you don't want to receive email, could you please give your >>actual name in the ?From? field instead of just initials? It makes >>conversation less confusing.) > > I don't know why, but for as long as I can remember everyone calls > me kj, even my mom. ?My name is Keaweikekahiali?iokamoku > Jallalahwallalruwalpindi > > kj > Now that's funny. +1 QotW ~SF From sajmikins at gmail.com Mon Jun 29 03:24:28 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 03:24:28 -0400 Subject: Good books in computer science? In-Reply-To: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <50f98a4c0906290024h304c52d1h64356a699accc1e9@mail.gmail.com> On Sat, Jun 13, 2009 at 11:49 AM, koranthala wrote: > Hi all, > ? ?I do understand that this is not a python question and I apologize > for that straight up. > ? ?But I am a full time follower of this group and I have seen very > very brilliant programmers and solutions. > ? ?I also want to be a good programmer - so this question. > > ? ?Which are the classic books in computer science which one should > peruse? > ? ?I have ?(a) Code Complete (b) GOF (c) Art of programming. > > ? ?Art of programming was too tough for me - and I couldnt understand > much. The other two were good books - I understood and implemented > quite a bit from both. > ? ?What are the other books which I should peruse? > > Regards > K Knuth. I.e. "The Art of Computer Programming" by Prof. Knuth Your library should have a copy (it's a multi-volume opus), if not consider donating yours after you read them. From casper.feldmann at googlemail.com Mon Jun 29 03:42:54 2009 From: casper.feldmann at googlemail.com (C. Feldmann) Date: Mon, 29 Jun 2009 00:42:54 -0700 (PDT) Subject: pythonware.com down? Message-ID: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Hi, I am trying to get a hold of PIL, but pythonware.com seems to be down. Are there mirrors out there? I get a 502 Error "Bad Gateway - The proxy server received an invalid response from an upstream server." Does anyone else get that error? Thanks Casper From news123 at free.fr Mon Jun 29 03:59:09 2009 From: news123 at free.fr (News123) Date: Mon, 29 Jun 2009 09:59:09 +0200 Subject: creating garbage collectable objects (caching objects) In-Reply-To: References: <4a47862b$0$31117$426a74cc@news.free.fr> Message-ID: <4a48744d$0$414$426a74cc@news.free.fr> Dave Angel wrote: > News123 wrote: >> Hi. >> >> I started playing with PIL. >> >> I'm performing operations on multiple images and would like compromise >> between speed and memory requirement. >> . . . >> >> The question, that I have is whether there is any way to tell python, >> that certain objects could be garbage collected if needed and ask python >> at a later time whether the object has been collected so far (image has >> to be reloaded) or not (image would not have to be reloaded) >> >> >> > You don't say what implementation of Python, nor on what OS platform. > Yet you're asking how to influence that implementation. Sorry my fault. I'm using C-python under Windows and under Linux > > In CPython, version 2.6 (and probably most other versions, but somebody > else would have to chime in) an object is freed as soon as its reference > count goes to zero. So the garbage collector is only there to catch > cycles, and it runs relatively infrequently. If CYthon frees objects as early as possible (as soon as the refcount is 0), then weakref wil not really help me. In this case I'd have to elaborate into a cache like structure. > > So, if you keep a reference to an object, it'll not be freed. > Theoretically, you can use the weakref module to keep a reference > without inhibiting the garbage collection, but I don't have any > experience with the module. You could start by studying its > documentation. But probably you want a weakref.WeakValueDictionary. > Use that in your third approach to store the cache. > > If you're using Cython or Jython, or one of many other implementations, > the rules will be different. > > The real key to efficiency is usually managing locality of reference. > If a given image is going to be used for many output files, you might > try to do all the work with it before going on to the next image. In > that case, it might mean searching all_creation_rules for rules which > reference the file you've currently loaded, measurement is key. Changing the order of the images to be calculated is key and I'm working on that. For a first step I can reorder the image creation such, that all outpout images, that depend only on one input image will be calculated one after the other. so for this case I can transform: # Slowest approach: for creation_rule in all_creation_rules(): img = Image.new(...) for img_file in creation_rule.input_files(): src_img = Image.open(img_file) img = do_somethingwith(img,src_img) # wrong indentation in OP img.save() into src_img = Image.open(img_file) for creation_rule in all_creation_rules_with_on_src_img(): img = Image.new(...) img = do_somethingwith(img,src_img) img.save() What I was more concerned is a group of output images depending on TWO or more input images. Depending on the platform (and the images) I might not be able to preload all two (or more images) So, as CPython's garbage collection takes always place immediately, then I'd like to pursue something else. I can create a cache, which caches input files as long as python leaves at least n MB available for the rest of the system. For this I have to know how much RAM is still available on a system. I'll start looking into this. thanks again N From nurazije at gmail.com Mon Jun 29 04:24:36 2009 From: nurazije at gmail.com (NurAzije) Date: Mon, 29 Jun 2009 01:24:36 -0700 (PDT) Subject: whizBase vs. Python Message-ID: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Hi, I am working on a study and I need expert opinion, I did not work with Python before, can anyone help me with a comparison between WhizBase (www.whizbase.com) and Python please. Thank you in advance, Ashraf Gheith From clp2 at rebertia.com Mon Jun 29 04:54:12 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 01:54:12 -0700 Subject: whizBase vs. Python In-Reply-To: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: <50697b2c0906290154o273d50dcsb258091c41291373@mail.gmail.com> On Mon, Jun 29, 2009 at 1:24 AM, NurAzije wrote: > Hi, > I am working on a study and I need expert opinion, I did not work with > Python before, can anyone help me with a comparison between WhizBase > (www.whizbase.com) and Python please. Python is a popular, open-source, cross-platform, general-purpose programming language with a large standard library that is often used in web programming. Popular Python web frameworks include TurboGears and Django. WhizBase appears to be a proprietary, Windows-only, database-centric web macro language (or proper programming language perhaps, I didn't investigate deeply). Proprietary language = Vendor lock-in = Lose. Cheers, Chris -- http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Mon Jun 29 04:58:42 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 29 Jun 2009 09:58:42 +0100 Subject: pep 8 constants In-Reply-To: <4A484C07.9050800@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: On Mon, 29 Jun 2009 06:07:19 +0100, Eric S. Johansson wrote: > Rhodri James wrote: > >> Reject away, but I'm afraid you've still got some work to do to >> convince me that PEP 8 is more work for an SR system than any other >> convention. > [snip sundry examples] Yes, yes, recognition systems need both training and a careful selection of words to recognise to be effective. This I learned twenty years ago: if "cap" has a high failure rate, use something else. As far as I can tell, the only thing that you are even vaguely suggesting for convention use is underscores_with_everything. As promised, I laugh hollowly. -- Rhodri James *-* Wildebeest Herder to the Masses From nobody at nowhere.com Mon Jun 29 04:59:54 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 09:59:54 +0100 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 28 Jun 2009 20:54:11 -0700, Paul Rubin wrote: > Jo?o Valverde writes: >> Could you clarify what you mean by immutable? As in... not mutable? As >> in without supporting insertions and deletions? > > Correct. > >> That's has the same performance as using binary search on a sorted >> list. What's the point of using a tree for that? > > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. The main issue here is that you need to be a bit smarter when it comes to "modifying" the tree. If you want to insert, delete or replace multiple elements, using repeated insert()s (etc) on the root is sub-optimal, as you will end up repeatedly duplicating the upper levels. Ideally you want to provide operations which will add/remove/replace multiple elements in a single traversal. From usernet at ilthio.net Mon Jun 29 05:04:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 09:04:44 GMT Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: On 2009-06-29, NurAzije wrote: > Hi, > I am working on a study and I need expert opinion, I did not work with > Python before, can anyone help me with a comparison between WhizBase > (www.whizbase.com) and Python please. Given posts like: http://groups.google.com/group/Server-side-programing/browse_thread/thread/16cfcf58bc943a0/15840d85eedd952e#15840d85eedd952e is this just thinly veiled spam? The domain and the posting IP address are both out of Sarajevo, Bosnia. Obviously you alreadly know your product is nothing but a database macro processor. Python is a dynamic programming language and therefore far more capable. Your product is proprietary with less capability while Python is free and powerful. From info at egenix.com Mon Jun 29 05:07:04 2009 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 29 Jun 2009 11:07:04 +0200 Subject: ANN: eGenix mxODBC Connect 1.0.2 - Python Database Interface Message-ID: <4A488438.7070409@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python Database Interface Version 1.0.2 Our new client-server product for connecting Python applications to relational databases - from all major platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-1.0.2-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable and convenient way. Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect the ideal basis for writing cross-platform database programs and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. By removing the need to install and configure ODBC drivers on the client side, mxODBC Connect greatly simplifies setup and configuration of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS mxODBC Connect 1.0.2 is a patch-level release of our new mxODBC Connect product. * More Secure We have upgraded the server to our latest eGenix pyOpenSSL release 0.9.0-0.9.8k, which includes a number of important bug fixes to both pyOpenSSL and the used OpenSSL library. * More Robust Previous versions had a timeout issue that we have solved with this release. We have have also added a special case for shutting down the client with a broken server connection. In such cases, the client will no longer wait for a timeout and terminate much faster. * Ideal for Building Bridges mxODBC Connect Client now works on all major Python platforms. As a result, connecting from e.g. Linux or Mac OS X to an SQL Server database has never been easier. You can even keep the data sources you already have configured on your Windows machine and connect to them as if your application were running on the database server itself. ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 1.0 licenses can download and upgrade their existing installations without having to purchase new licenses or upgrades. The licenses will continue to work with version 1.0.2. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 29 2009) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From usernet at ilthio.net Mon Jun 29 05:07:56 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 09:07:56 GMT Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: On 2009-06-29, C. Feldmann wrote: > I am trying to get a hold of PIL, but pythonware.com seems to be down. > Are there mirrors out there? > I get a 502 Error "Bad Gateway - The proxy server received an invalid > response from an upstream server." > Does anyone else get that error? Yes, more info below: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2dbba1a1bd6ebee6/1d832c468efc3828?tvc=1#1d832c468efc3828 From mfmdevine at gmail.com Mon Jun 29 05:20:39 2009 From: mfmdevine at gmail.com (amadain) Date: Mon, 29 Jun 2009 02:20:39 -0700 (PDT) Subject: urllib2.URLError: error using twill with python References: <023cef3d$0$20636$c3e8da3@news.astraweb.com> Message-ID: On Jun 8, 12:58?pm, Steven D'Aprano wrote: > On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote: > > Hi > > I wonder if someone could point me in the right direction. I used the > > following code to access gmail but I got a > > ? ? ? ? ?urllib2.URLError: > > error when I ran it. I have included the Traceback > > > import twill, string, os > > b=twill.commands.get_browser() > > b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; > > rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") b.clear_cookies() > > b.go('http://www.gmail.com') > > f=b.get_form("1") > > b.showforms() > > f['Email']= email > > f['Passwd'] =password > > b.clicked(f, f) > > b.submit() > > My bet is that the above is not the actual code you have run. I bet that > the offending line is actually something like the following: > > b.go("'http://www.gmail.com") > > Note that there is a single character difference. > > Consider the last two lines of the traceback: > > > ? ? raise URLError('unknown url type: %s' % type) > > urllib2.URLError: > > It seems to be saying that the url type is 'http -- note the leading > single quote. > > -- > Steven Actually that is the exact code run from a python shell. Try it yourself. I could not find anybody who successfully automated sending a gmail through python with twill so if you know how I would greatly appreciate any pointers. From gil.shinar at gmail.com Mon Jun 29 05:35:17 2009 From: gil.shinar at gmail.com (eranlevi) Date: Mon, 29 Jun 2009 02:35:17 -0700 (PDT) Subject: Timeout when connecting to sybase DBS Message-ID: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> Hi All, I'm using the Sybase module for connecting and using a sybase DBS. When I try to connect when the DBS is down, it take approximately 4 minutes for the function (conn.ct_connect) to return with an error. I have looked for a timeout parameter to limit the 4 minutes to something more reasonable but couldn't find one. Can anyone please help? BTW, I'm using Sybase.connect(, , , datetime='auto') Thanks Gil From nobody at nowhere.com Mon Jun 29 06:06:06 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 11:06:06 +0100 Subject: validating HTTPS certificates? References: Message-ID: On Mon, 29 Jun 2009 09:18:20 +0200, Andras.Horvath wrote: >> For a urllib-style interface, there's not much point in performing >> verification after the fact. Either the library performs verification or >> it doesn't. If it doesn't, you've just sent the (potentially confidential) >> request to an unknown server; discovering this after the fact doesn't >> really help. > > I was more thinking about supplying a/some CA certificate(s) and > requiring that the site cert be valid (otherwise the connection should > fail). This sounds very EAFP to me. This is easier to do with urllib2 than urllib. For urllib, you would need to either "fix" URLopener.open_https() or clone half of urllib (URLOpener and FancyURLOpener). For urllib2, you can use urllib2.install_opener() to replace the built-in HTTPSHandler with a subclass which performs validation. Validation should just be a matter of passing cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking that SSLSocket.getpeercert() returns a non-empty dictionary. Note: the above is purely theoretical, based upon the (2.6) documentation and source code. I suggest that you verify it by connecting to a site with a bogus (e.g. self-signed) certificate and checking that it fails. From lenglish5 at cox.net Mon Jun 29 06:18:28 2009 From: lenglish5 at cox.net (Lawson English) Date: Mon, 29 Jun 2009 03:18:28 -0700 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4a4689bf$0$14790$9b622d9e@news.freenet.de> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> Message-ID: <4A4894F4.7040606@cox.net> Martin v. L?wis wrote: >> I sorta' wish he'd just come out and say, "This is what I think would >> be suitable for a GUI toolkit for Python: ...". >> > > He is not in the business of designing GUI toolkits, but in the business > of designing programming languages. So he abstains from specifying > (or even recommending) a GUI library. > > What he makes clear is the point that Terry cites: no matter what the > GUI toolkit is or what features it has - it should be simple to create > GUIs, as simple as creating HTML. > > Tim Berners-Lee would laugh to hear html described as "simple." He was very frustrated with how long it took anyone to create a graphical toolkit to create webpages. >> So, what *does* Guido want in a GUI toolkit for Python? >> > > His concern really isn't what is in the toolkit, but what isn't. > It must not require lots of lines of code to produce a simple > GUI, it must not require specification of absolute coordinates, > ... - you should be able to continue the list yourself. > > Regards, > Martin > From marek at xivilization.net Mon Jun 29 06:19:40 2009 From: marek at xivilization.net (Marek Kubica) Date: Mon, 29 Jun 2009 12:19:40 +0200 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> Message-ID: <20090629121940.42b88764@halmanfloyd.lan.local> On 28 Jun 2009 11:45:06 -0700 aahz at pythoncraft.com (Aahz) wrote: > Perhaps I was unclear: I already knew what LMGTFY stands for, and I > think that using a site that requires JavaScript is anti-social. Maybe they could just redirect to Google if JS wasn't detected. regards, Marek From casper.feldmann at googlemail.com Mon Jun 29 06:31:08 2009 From: casper.feldmann at googlemail.com (C. Feldmann) Date: Mon, 29 Jun 2009 03:31:08 -0700 (PDT) Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: On 29 Jun., 11:07, Tim Harig wrote: > On 2009-06-29, C. Feldmann wrote: > > > I am trying to get a hold of PIL, but pythonware.com seems to be down. > > Are there mirrors out there? > > I get a 502 Error "Bad Gateway - The proxy server received an invalid > > response from an upstream server." > > Does anyone else get that error? > > Yes, more info below: > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... yeah. need the windows version. guess this is another reason to add to my "why I should buy a mac" list. :) From nobody at nowhere.com Mon Jun 29 06:33:55 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 11:33:55 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Sun, 28 Jun 2009 21:25:13 +0000, Benjamin Peterson wrote: >> > The email module is, yes, broken. You can recover the bytestrings of >> > command-line arguments and environment variables. >> >> 1. Does Python offer any assistance in doing so, or do you have to >> manually convert the surrogates which are generated for unrecognised bytes? > > fs_encoding = sys.getfilesystemencoding() > bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv] This results in an internal error: > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") Traceback (most recent call last): File "", line 1, in SystemError: Objects/bytesobject.c:3182: bad argument to internal function [FWIW, the error corresponds to _PyBytes_Resize, which has a cautionary comment almost as large as the code.] The documentation gives the impression that "surrogateescape" is only meaningful for decoding. >> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)? > > What's a non-invertible encoding? I can't find a reference to the term. One where different inputs can produce the same output. From godson.g at gmail.com Mon Jun 29 06:50:32 2009 From: godson.g at gmail.com (Godson Gera) Date: Mon, 29 Jun 2009 16:20:32 +0530 Subject: pythonware.com down? In-Reply-To: References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: way back machine,comes to rescue. http://web.archive.org/web/20071011003451/www.pythonware.com/products/pil/index.htm On Mon, Jun 29, 2009 at 4:01 PM, C. Feldmann wrote: > On 29 Jun., 11:07, Tim Harig wrote: > > On 2009-06-29, C. Feldmann wrote: > > > > > I am trying to get a hold of PIL, but pythonware.com seems to be down. > > > Are there mirrors out there? > > > I get a 502 Error "Bad Gateway - The proxy server received an invalid > > > response from an upstream server." > > > Does anyone else get that error? > > > > Yes, more info below: > > > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... > > yeah. need the windows version. guess this is another reason to add to > my "why I should buy a mac" list. :) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera http://godson.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Mon Jun 29 07:01:20 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 29 Jun 2009 07:01:20 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: <4a48744d$0$414$426a74cc@news.free.fr> References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> Message-ID: <4A489F00.1040003@ieee.org> News123 wrote: > Dave Angel wrote: > >> News123 wrote: >> >>> Hi. >>> >>> I started playing with PIL. >>> >>> I'm performing operations on multiple images and would like compromise >>> between speed and memory requirement. >>> . . . >>> >>> The question, that I have is whether there is any way to tell python, >>> that certain objects could be garbage collected if needed and ask python >>> at a later time whether the object has been collected so far (image has >>> to be reloaded) or not (image would not have to be reloaded) >>> >>> >>> > > >>> >>> >> You don't say what implementation of Python, nor on what OS platform. >> Yet you're asking how to influence that implementation. >> > > Sorry my fault. I'm using C-python under Windows and under Linux > >> In CPython, version 2.6 (and probably most other versions, but somebody >> else would have to chime in) an object is freed as soon as its reference >> count goes to zero. So the garbage collector is only there to catch >> cycles, and it runs relatively infrequently. >> > > If CYthon frees objects as early as possible (as soon as the refcount is > 0), then weakref wil not really help me. > In this case I'd have to elaborate into a cache like structure. > >> So, if you keep a reference to an object, it'll not be freed. >> Theoretically, you can use the weakref module to keep a reference >> without inhibiting the garbage collection, but I don't have any >> experience with the module. You could start by studying its >> documentation. But probably you want a weakref.WeakValueDictionary. >> Use that in your third approach to store the cache. >> >> If you're using Cython or Jython, or one of many other implementations, >> the rules will be different. >> >> The real key to efficiency is usually managing locality of reference. >> If a given image is going to be used for many output files, you might >> try to do all the work with it before going on to the next image. In >> that case, it might mean searching all_creation_rules for rules which >> reference the file you've currently loaded, measurement is key. >> > > Changing the order of the images to be calculated is key and I'm working > on that. > > For a first step I can reorder the image creation such, that all outpout > images, that depend only on one input image will be calculated one after > the other. > > so for this case I can transform: > # Slowest approach: > for creation_rule in all_creation_rules(): > img = Image.new(...) > for img_file in creation_rule.input_files(): > src_img = Image.open(img_file) > img = do_somethingwith(img,src_img) # wrong indentation in OP > img.save() > > > into > src_img = Image.open(img_file) > for creation_rule in all_creation_rules_with_on_src_img(): > img = Image.new(...) > img = do_somethingwith(img,src_img) > img.save() > > > What I was more concerned is a group of output images depending on TWO > or more input images. > > Depending on the platform (and the images) I might not be able to > preload all two (or more images) > > So, as CPython's garbage collection takes always place immediately, > then I'd like to pursue something else. > I can create a cache, which caches input files as long as python leaves > at least n MB available for the rest of the system. > > For this I have to know how much RAM is still available on a system. > > I'll start looking into this. > > thanks again > > > > N > > > As I said earlier, I think weakref is probably what you need. A weakref is still a reference from the point of view of the ref-counting, but not from the point of view of the garbage collector. Have you read the help on weakref module? In particular, did you read Pep 0205? http://www.python.org/dev/peps/pep-0205/ Object cache is one of the two reasons for the weakref module. From nobody at nowhere.com Mon Jun 29 07:02:20 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 12:02:20 +0100 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. L?wis wrote: >> That's a significant improvement. It still decodes os.environ and sys.argv >> before you have a chance to call sys.setfilesystemencoding(), but it >> appears to be recoverable (with some effort; I can't find any way to re-do >> the encoding without manually replacing the surrogates). > > See PEP 383. Okay, that's useful, except that it may have some bugs: > r = "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") Traceback (most recent call last): File "", line 1, in SystemError: Objects/bytesobject.c:3182: bad argument to internal function Trying a few random test cases suggests that the ratio of valid to invalid bytes has an effect. Strings which consist mostly of invalid bytes trigger the error, those which are mostly valid don't. The error corresponds to _PyBytes_Resize(), which has the following words of caution in a preceding comment: /* The following function breaks the notion that strings are immutable: it changes the size of a string. We get away with this only if there is only one module referencing the object. You can also think of it as creating a new string object and destroying the old one, only more efficiently. In any case, don't use this if the string may already be known to some other part of the code... Note that if there's not enough memory to resize the string, the original string object at *pv is deallocated, *pv is set to NULL, an "out of memory" exception is set, and -1 is returned. Else (on success) 0 is returned, and the value in *pv may or may not be the same as on input. As always, an extra byte is allocated for a trailing \0 byte (newsize does *not* include that), and a trailing \0 byte is stored. */ Assuming that this gets fixed, it should make most of the problems with 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. sys.argv_bytes and os.environ_bytes. >> However, sys.std{in,out,err} are still created as text streams, and AFAICT >> there's nothing you can do about this from within your code. > > That's intentional, and not going to change. You can access the > underlying byte streams if you want to, as you could already in 3.0. Okay, I've since been pointed to the relevant information (I was looking under "File Objects"; I didn't think to look at "sys"). From command.bbs at alexbbs.twbbs.org Mon Jun 29 07:13:00 2009 From: command.bbs at alexbbs.twbbs.org (§ä´M¦Û¤vªº¤@¤ù¤Ñ) Date: 29 Jun 2009 11:13:00 GMT Subject: python extend c++ module Message-ID: <4gb5PD$wPA@alexbbs.twbbs.org> I have written a c++ extend module and I use distutils to build. setup.py ---------------- from distutils.core import setup, Extension setup(name="noddy", version="1.0", ext_modules=[ Extension("noddy3", ["noddy3.cpp", "a.cpp"]) ]) I found it's quite strange when compiling. I didn't use extern "C" at all , how can python get the right c++ funciton name without any compile error?? I found that it first use gcc to compile noddy3.cpp and then link by g++. Could anyone explain what it's all about? Thanks a lot!! here is the compiling message. --------------------------------------- running install running build running build_ext building 'noddy3' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp -o build/temp.linux-i686-2.6/noddy3.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so running install_lib copying build/lib.linux-i686-2.6/noddy3.so -> /usr/local/lib/python2.6/site-packages running install_egg_info Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info -- ?Post by command from 59-124-255-226.HINET-IP. ?????????????????alexbbs.twbbs.org?140.113.166.7 From ldo at geek-central.gen.new_zealand Mon Jun 29 07:21:12 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 29 Jun 2009 23:21:12 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message , Tim Harig wrote: > On 2009-06-29, Lawrence D'Oliveiro > wrote: > >> "apt-get install python-imaging", anybody? > > C:\>apt-get install python-imaging > Bad command or file name Sounds more like broken OS with no integrated package management. From usernet at ilthio.net Mon Jun 29 07:23:44 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 11:23:44 GMT Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> Message-ID: <4v12m.1716$8r.173@nlpi064.nbdc.sbc.com> On 2009-06-29, C. Feldmann wrote: > On 29 Jun., 11:07, Tim Harig wrote: >> On 2009-06-29, C. Feldmann wrote: >> >> > I am trying to get a hold of PIL, but pythonware.com seems to be down. >> > Are there mirrors out there? >> > I get a 502 Error "Bad Gateway - The proxy server received an invalid >> > response from an upstream server." >> > Does anyone else get that error? >> >> Yes, more info below: >> >> http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db... > > yeah. need the windows version. guess this is another reason to add to > my "why I should buy a mac" list. :) The source is operating system agnostic. From python.list at tim.thechases.com Mon Jun 29 07:25:09 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 29 Jun 2009 06:25:09 -0500 Subject: pep 8 constants In-Reply-To: <4A484C07.9050800@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: <4A48A495.7040504@tim.thechases.com> >> Reject away, but I'm afraid you've still got some work to do to >> convince me that PEP 8 is more work for an SR system than any other >> convention. > > Name name > higher than normal recognition error rate. can require multiple tries or hand > correction > > MultiWordName mulitwordname > very high error rate. many retries or hand hurting typing. > > multi_word_name multiwordname > normal error rate (low), can need multiple tries or hand correction It sounds like the issue should be one of making your screen-reader smarter, not dumbing down Python conventions. I don't know what SR you're using (Jaws? Window Eyes? yasr? screeder? speakup? VoiceOver?) but it sounds like at least for the above cases, along with the PEP-8 MULTI_WORD_NAME constant convention, a simple regexp+transformation should be able to reprocess the input into something easier to handle/hear/understand. I'm not sure any/all of the previously-listed screen-readers give such regexp transformation control, but I would expect that at least the OSS ones (yasr, screeder, & speakup) it would be possible to add the feature if it doesn't already exist. For these three, you might ping the blinux mailing list to see if anybody there knows how to implement such transforms. > StdlYCps sierra tango delta lima yankee charley papa sierra > > *** very high error rate *** search and replace for all instances with a x_y_z > form name is recommended As for StuDlyCaps, it's hard on the seeing too, so I advocate a firm smack on the back of the head for those that prefer this abomination. :-) -tkc From lfscripter at gmail.com Mon Jun 29 07:28:29 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Mon, 29 Jun 2009 12:28:29 +0100 Subject: Running Invisible console Application Message-ID: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Hi, i have a console application that i want to ran (invisible) as a daemon, how can i do that? Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Jun 29 07:30:52 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 13:30:52 +0200 Subject: python extend c++ module In-Reply-To: <4gb5PD$wPA@alexbbs.twbbs.org> References: <4gb5PD$wPA@alexbbs.twbbs.org> Message-ID: ???????? schrieb: > I found it's quite strange when compiling. I didn't use extern "C" at all > , how can python get the right c++ funciton name without any compile error?? > > I found that it first use gcc to compile noddy3.cpp and then link by g++. > > Could anyone explain what it's all about? The Python header files already contain the necessary extern "C" declarations. You can safely import the Python.h header file in a cpp file without an extern "C" block. Christian From solipsis at pitrou.net Mon Jun 29 07:41:11 2009 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 29 Jun 2009 11:41:11 +0000 (UTC) Subject: [RELEASED] Python 3.1 final References: Message-ID: Nobody nowhere.com> writes: > > This results in an internal error: > > > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") > Traceback (most recent call last): > File "", line 1, in > SystemError: Objects/bytesobject.c:3182: bad argument to internal function Please report a bug on http://bugs.python.org As for a bytes version of sys.argv and os.environ, you're welcome to propose a patch (this would be a separate issue on the aforementioned issue tracker). Thanks Antoine. From h.b.furuseth at usit.uio.no Mon Jun 29 07:57:49 2009 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: Mon, 29 Jun 2009 13:57:49 +0200 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: Nobody writes: >On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. L?wis wrote: >> See PEP 383. > > Okay, that's useful, except that it may have some bugs: > (...) > Assuming that this gets fixed, it should make most of the problems with > 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. > sys.argv_bytes and os.environ_bytes. That's hopeless to keep track of across modules if something modifies sys.argv or os.environ. If the current scheme for recovering the original bytes proves insufficient, what could work is a string type which can have an attribute with the original bytes (if the source was bytes). And/or sys.argv and os.environ maintaining the correspondence when feasible. Anyway, I haven't looked at whether any of this is a problem, so don't mind me:-) As long as it's definitely possible to tell python once and for all not to apply locales and string conversions, instead of having to keep track of an ever-expanding list of variables to tame it's bytes->character conversions (as happened with Emacs). -- Hallvard From tim.wintle at teamrubber.com Mon Jun 29 08:01:19 2009 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 29 Jun 2009 13:01:19 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A45A80F.4090600@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7albocF1vlgm3U1@mid.individual.net> <4A45A80F.4090600@netcabo.pt> Message-ID: <1246276879.21161.25.camel@tim-laptop> On Sat, 2009-06-27 at 06:03 +0100, Jo?o Valverde wrote: > To answer the question of what I need the BSTs for, without getting > into too many boring details it is to merge and sort IP blocklists, > that is, large datasets of ranges in the form of (IP address, IP > address, string). > As an anecdotal data point (honestly not trying to raise the "Python > is slow" strawman), I implemented the same algorithm in C and Python, > using pyavl. Round numbers were 4 mins vs 4 seconds, against Python > (plus pyavl). Out of interest, I recently wrote something similar that imported (a class of) snort rules for blacklisting ip traffic. I could only use the standard library. I ended up writing a simple tree using dict-like objects [1]. Afraid I haven't got a taught CS background to know the name of the structure. (note insertion wasn't the focus, and I didn't bother writing it to handle updates/merges - this is a quick script I run every now and then, so I'm sure it could be done better - I just liked having the standard dict interface for each node) I only had three levels of branching, using the first octet to branch at the root node, the second octet to branch as the second node, and the final two to branch at the third node's depth (since even then that's normally sparse relative to the first two nodes). It works well enough for me - I'm IO bound reading in ip addresses from logs to check against the blacklist, and there is a fair bit of other processing going on for each line. (Obviously I converted the ip addresses to integers before doing all this to avoid hashing strings etc) [1] (As rules could be for any subnet I overloaded some of the dict methods to check against rules on unusual subnets etc. before checking individual ips in the final part) > Even considering I'm a worse Python programmer than C > programmer, it's a lot. I know many will probably think I tried to do > "C in Python" but that's not the case, at least I don' t think so. > Anyway like I said, not really relevant to this discussion. > From p.f.moore at gmail.com Mon Jun 29 08:05:51 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 29 Jun 2009 13:05:51 +0100 Subject: [RELEASED] Python 3.1 final In-Reply-To: References: Message-ID: <79990c6b0906290505m601bc4d2hf95622b88d3cdb17@mail.gmail.com> 2009/6/29 Antoine Pitrou : > As for a bytes version of sys.argv and os.environ, you're welcome to propose a > patch (this would be a separate issue on the aforementioned issue tracker). But please be aware that such a proposal would have to consider: 1. That on Windows, the native form is the character version, and the bytes version would have to address all the same sorts of encoding issues that the OP is complaining about in the character versions. [1] 2. That the proposal address the question of how to write portable, robust, code (given that choosing argv vs argv_bytes based on sys.platform is unlikely to count as a good option...) 3. Why defining your own argv_bytes as argv_bytes = [a.encode("iso-8859-1", "surrogateescape") for a in sys.argv] is insufficient (excluding issues with bugs, which will be fixed regardless) for the occasional cases where it's needed. Before writing the proposal, the OP should probably review the extensive discussions which can be found in the python-dev archives. It would be wrong for people reading this thread to think that the implemented approach is in any sense a "quick fix" - it's certainly a compromise (and no-one likes all aspects of any compromise!) but it's one made after a lot of input from people with widely differing requirements. Paul. [1] And my understanding, from the PEP, is that even on POSIX, the argv and environ data is intended to be character data, even though the native C APIs expose a byte-oriented interface. So conceptually, character format is "correct" on POSIX as well... (But I don't write code for POSIX systems, so I'll leave it to the POSIX users to debate this point further). From rustompmody at gmail.com Mon Jun 29 08:08:45 2009 From: rustompmody at gmail.com (rustom) Date: Mon, 29 Jun 2009 05:08:45 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: This thread has thrown up some interesting suggestions but they all seem to fall into one of two categories: - the high-ground: Dijkstra, Knuth etc - the low-ground: write (any-which-how) a lot of code And both these 'grounds' seem to cause more argument and less suggestions for good books. Let me therefore try to find a middle-ground and make a suggestion that I used to make to my students when I taught them programming: Read the Python Manual -- specifically the library. It contains a fairly good conspectus of modern day IT/CS. Some examples of what I mean: Want to study TDD? Read unittest and doctest and then go on to reading (and practising) Kent Beck etc Want to get into unix system programming? Nothing like playing around with os.path and stat before burining your hands with C. Networking protocols? smtplib, urllib, ftplib etc Low level networking? socket, select etc Algorithms? Good to get your feet on the ground with timeit From usernet at ilthio.net Mon Jun 29 08:13:13 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 12:13:13 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-29, Lawrence D'Oliveiro wrote: > Sounds more like broken OS with no integrated package management. Package managers with dependency tracking were all the rage when I first started using Linux. So I tried Red Hat and everything worked great until the depency database corrupted itself. Since then, I have learned to install using whatever package manager but to upgrade or install new packages from source. From lanuradha at gmail.com Mon Jun 29 08:15:19 2009 From: lanuradha at gmail.com (Anul) Date: Mon, 29 Jun 2009 05:15:19 -0700 (PDT) Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> Message-ID: <8bff581e-3178-44c8-b778-d7c0795b43c2@f19g2000yqo.googlegroups.com> On Jun 29, 5:08?pm, rustom wrote: > > Want to study TDD? ?Read unittest and doctest and then go on to > reading (and practising) Kent Beck etc > Want to get into unix system programming? ?Nothing like playing around > with os.path and stat before burining your hands with C. > Networking protocols? smtplib, urllib, ftplib etc > Low level networking? socket, select etc > Algorithms? Good to get your feet on the ground with timeit Ive found twisted is a good excuse to study lot of CS arcana ranging from laziness of lambdas, event driven programming From python at mrabarnett.plus.com Mon Jun 29 08:18:50 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 13:18:50 +0100 Subject: Running Invisible console Application In-Reply-To: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> References: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Message-ID: <4A48B12A.3060808@mrabarnett.plus.com> Elf Scripter wrote: > Hi, i have a console application that i want to ran (invisible) as > a daemon, how can i do that? > Change the extension from ".py" to ".pyw". From bieffe62 at gmail.com Mon Jun 29 08:44:27 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Mon, 29 Jun 2009 05:44:27 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: On 29 Giu, 07:10, OdarR wrote: > On 28 juin, 23:26, Tomasz Pajor wrote: > > > Hello, > > > Configuration is as follows. > > > I have a starter process which creates 3 sub processes (forks) and each > > of this processes creates a number of threads. > > Threads in that processes have semaphore so on KeyboardInterrupt without > > sending a sigterm to the subprocess i'm not able to close threads. > > Is there any work around? Can I somehow run join for the thread on > > keyboard interrupt? > > When creating a thread you can add a Queue parameter to communicate > with threads:http://docs.python.org/library/queue.html > easy and reliable. > > give them a "poison pill" in the queue: a recognizable object placed > on the queue that means "when you get this, stop." > This is the way I usually go, but it has one important limitation: if the thread is waiting for a blocking I/O operation to complete, like reading from a socket with no data or waiting for a locked resource (i.e. semaphore) to be unlocked, it will not service the queue and will not read the 'quit command' (the poison pill), and therefore will not quit until the blocking I/O terminates (and it could be never). ASAIK, there is no way - in python - to solve this. > Olivier Ciao ---- FB From peter.mosley at talk21.com Mon Jun 29 08:54:19 2009 From: peter.mosley at talk21.com (peter) Date: Mon, 29 Jun 2009 05:54:19 -0700 (PDT) Subject: Python Imaging Library download link broken? References: Message-ID: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Whilst this is an interesting discussion about installers, I'm still trying to find a copy of PIL. Any ideas? From bhardwajjayesh7 at gmail.com Mon Jun 29 08:55:39 2009 From: bhardwajjayesh7 at gmail.com (golu) Date: Mon, 29 Jun 2009 05:55:39 -0700 (PDT) Subject: problems with mysql db Message-ID: here i have posted my code...plz tell why am i getting the error "int argument required" on the hash marked line(see below) although i am giving an int value #the code import os import string import MySQLdb import stopcheck conn = MySQLdb.connect(host='localhost',user='root',db='urdb') def file_extractor(dir_name): url_count = 0 for file in os.listdir(dir_name): if(file[-4:] == '.txt'): file_path = os.path.join(dir_name,file) curse = conn.cursor() url_count += 1 curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", (url_count,file_path)) #error word_extractor(url_count,file_path) def word_extractor(url_count,file): fhandle = open(file) line = fhandle.readline() k=stopcheck.checker() k.create() while line: words = line.split() cursor = conn.cursor() for word1 in words: if word1 not in string.punctuation: if (k.check(word1) is 0) and (word1[0:4] != 'http') : word_count+=1 try: cursor.execute("INSERT INTO word_table(id,word) VALUES(%d,%s)" , (word_count,word1)) cursor.execute("INSERT INTO wordmatch (word_id,url_id) values(%d,%d)",(word_count,url_count)) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) line=fhandle.readline() if __name__ == '__main__': #url_count=0 #word_count=0 dir = os.path.join('D://','acm') file_extractor(dir) From Andras.Horvath at cern.ch Mon Jun 29 09:08:50 2009 From: Andras.Horvath at cern.ch (Andras.Horvath at cern.ch) Date: Mon, 29 Jun 2009 15:08:50 +0200 Subject: validating HTTPS certificates? In-Reply-To: References: Message-ID: <20090629130850.GB7799@cern.ch> > validation. Validation should just be a matter of passing > cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking > that SSLSocket.getpeercert() returns a non-empty dictionary. That'd be cool unless I can't use an already-open socket (by SSL, for verification) in any of the built-in HTTP engines, by the look of it. Andras From aahz at pythoncraft.com Mon Jun 29 09:12:47 2009 From: aahz at pythoncraft.com (Aahz) Date: 29 Jun 2009 06:12:47 -0700 Subject: Advantages of Python (for web/desktop apps)? References: <24239603.post@talk.nabble.com> <20090629121940.42b88764@halmanfloyd.lan.local> Message-ID: In article <20090629121940.42b88764 at halmanfloyd.lan.local>, Marek Kubica wrote: >On 28 Jun 2009 11:45:06 -0700 >aahz at pythoncraft.com (Aahz) wrote: >> >> Perhaps I was unclear: I already knew what LMGTFY stands for, and I >> think that using a site that requires JavaScript is anti-social. > >Maybe they could just redirect to Google if JS wasn't detected. Exactly. They have chosen to be anti-social; therefore, I think anyone using lmgtfy.com is also anti-social. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha From usernet at ilthio.net Mon Jun 29 09:25:21 2009 From: usernet at ilthio.net (Tim Harig) Date: Mon, 29 Jun 2009 13:25:21 GMT Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: <5h32m.1938$Wj7.746@nlpi065.nbdc.sbc.com> On 2009-06-29, peter wrote: > Whilst this is an interesting discussion about installers, I'm still > trying to find a copy of PIL. Any ideas? I alluded to a source version below. It will compile on Windows as well as on *nix. Google finds what looks like older versions here: http://sping.sourceforge.net/PIL/ From petr.messner at gmail.com Mon Jun 29 09:32:40 2009 From: petr.messner at gmail.com (Petr Messner) Date: Mon, 29 Jun 2009 15:32:40 +0200 Subject: problems with mysql db In-Reply-To: References: Message-ID: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Hi, use %s instead of %d in SQL statements, because (AFAIK) conversions (including SQL escaping) from Python values to SQL values are done before the % operator is called - that value is not a number by that point. I hope you understood it, sorry for my English :-) You can also check MySQLdb module source, it's pretty clear. PM 2009/6/29 golu : > here i have posted my code...plz tell why am i getting the error "int > argument required" on the hash marked line(see below) although i am > giving an int value > #the code > import os > import string > import MySQLdb > import stopcheck > conn = MySQLdb.connect(host='localhost',user='root',db='urdb') > > def file_extractor(dir_name): > url_count = 0 > > for file in os.listdir(dir_name): > if(file[-4:] == '.txt'): > file_path = os.path.join(dir_name,file) > curse = conn.cursor() > url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > (url_count,file_path)) #error > word_extractor(url_count,file_path) > def word_extractor(url_count,file): > fhandle = open(file) > line = fhandle.readline() > k=stopcheck.checker() > k.create() > > while line: > words = line.split() > cursor = conn.cursor() > for word1 in words: > if word1 not in string.punctuation: > if (k.check(word1) is 0) and (word1[0:4] != 'http') : > word_count+=1 > try: > cursor.execute("INSERT INTO word_table(id,word) > VALUES(%d,%s)" , (word_count,word1)) > cursor.execute("INSERT INTO wordmatch > (word_id,url_id) values(%d,%d)",(word_count,url_count)) > except MySQLdb.Error, e: > print "Error %d: %s" % (e.args[0], e.args[1]) > line=fhandle.readline() > > if __name__ == '__main__': > #url_count=0 > #word_count=0 > > dir = os.path.join('D://','acm') > file_extractor(dir) > -- > http://mail.python.org/mailman/listinfo/python-list > From charles at declareSub.com Mon Jun 29 10:16:22 2009 From: charles at declareSub.com (Charles Yeomans) Date: Mon, 29 Jun 2009 10:16:22 -0400 Subject: Running Invisible console Application In-Reply-To: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> References: <6be1e1a30906290428u68be76dcj654d31016a982f2e@mail.gmail.com> Message-ID: On Jun 29, 2009, at 7:28 AM, Elf Scripter wrote: > Hi, i have a console application that i want to ran (invisible) as a > daemon, how can i do that? > Search the web for python + daemon. I found plenty of code, including mostly prewritten solutions, for my own work. Charles Yemans From python-url at phaseit.net Mon Jun 29 10:16:23 2009 From: python-url at phaseit.net (Gabriel Genellina) Date: Mon, 29 Jun 2009 14:16:23 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Jun 29) Message-ID: QOTW: "Fortunately, I have assiduously avoided the real wor[l]d, and am happy to embrace the world from our 'bot overlords. Congratulations on another release from the hydra-like world of multi-head development." - Scott David Daniels, on release of 3.1 http://groups.google.com/group/comp.lang.python/msg/620d014fb549dbe6 A success story (involving a game server): http://groups.google.com/group/comp.lang.python/browse_thread/thread/11abba7af6e266b0/ Floats and Decimal objects demythified: http://groups.google.com/group/comp.lang.python/browse_thread/thread/77a9ecc671602e79/ Converting Python code to C/C++: how to do it, alternatives, and when it would be advisable: http://groups.google.com/group/comp.lang.python/browse_thread/thread/7152ab4f1c7dbced/ A generator expression declared at class scope: the namespace resolution rules aren't so intuitive: http://groups.google.com/group/comp.lang.python/browse_thread/thread/e1ab6188673fc623/ A look at 2.1 sample code shows how much (or how little) the language evolved over time: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3e2139c2191bb191/ No "tree" data structure is available in the standard library - should one exist? http://groups.google.com/group/comp.lang.python/browse_thread/thread/c632217cfc7c7dcc/ Correctly implementing rich comparisons so 'set' membership works as expected: http://groups.google.com/group/comp.lang.python/browse_thread/thread/c0b1c58585c110eb/ Python threading and the GIL (again): http://groups.google.com/group/comp.lang.python/browse_thread/thread/9e22ab012388b538/ In ElementTree, XML() and fromstring() aren't the same thing: http://groups.google.com/group/comp.lang.python/browse_thread/thread/397f410b060afca2/ Open source Python projects that need help: http://groups.google.com/group/comp.lang.python/browse_thread/thread/667b9922a60ea836/ Meta issue: some posts appear to be missing, depending on where you read this (the mailing list, the newsgroup, the gmane gateway...) http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cc24ff07dfd3afd/e7ad466392094c8c?#e7ad466392094c8c http://groups.google.com/group/comp.lang.python/browse_thread/thread/f67e695fa6364ec9/9174d8c5b4f07f74?#9174d8c5b4f07f74 [OT] Measuring Fractal Dimension (mad mathematicians only): http://groups.google.com/group/comp.lang.python/browse_thread/thread/a258b6c9005146c5/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From marshalc at carleton.edu Mon Jun 29 10:28:07 2009 From: marshalc at carleton.edu (Chris Marshall) Date: Mon, 29 Jun 2009 09:28:07 -0500 (CDT) Subject: Configuring Python for Tcl/Tk in UNIX Message-ID: <542109298.163561246285687188.JavaMail.root@mail2.its.carleton.edu> My goal is to use Tkinter on a ScientificLinux machine for a GUI I wrote. I installed Python 2.6.2, then built Tcl and Tk 8.5.7 from source. The final step is to configure Python 2.6 to run Tk. When I use the "make" command in the Python 2.6.2 directory, all is well until it tries to built _tkinter.so. I get an error as follows: *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory. Failed to build the following modules: _tkinter I cannot use the default install location of /usr/bin, so I am trying to install into another directory. I line-by-line edited the setup.py file to point to the proper directory and I get the same error. Has anyone had a similar problem? Any advice is greatly appreciated. Thanks, Chris From gagsl-py2 at yahoo.com.ar Mon Jun 29 10:43:26 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 11:43:26 -0300 Subject: creating garbage collectable objects (caching objects) References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> <4A489F00.1040003@ieee.org> Message-ID: En Mon, 29 Jun 2009 08:01:20 -0300, Dave Angel escribi?: > News123 wrote: >> What I was more concerned is a group of output images depending on TWO >> or more input images. >> >> Depending on the platform (and the images) I might not be able to >> preload all two (or more images) >> >> So, as CPython's garbage collection takes always place immediately, >> then I'd like to pursue something else. >> I can create a cache, which caches input files as long as python leaves >> at least n MB available for the rest of the system. > As I said earlier, I think weakref is probably what you need. A weakref > is still a reference from the point of view of the ref-counting, but not > from the point of view of the garbage collector. Have you read the help > on weakref module? In particular, did you read Pep 0205? > http://www.python.org/dev/peps/pep-0205/ You've misunderstood something. A weakref is NOT "a reference from the point of view of the ref-counting", it adds zero to the reference count. When the last "real" reference to some object is lost, the object is destroyed, even if there exist weak references to it. That's the whole point of a weak reference. The garbage collector isn't directly related. py> from sys import getrefcount as rc py> class X(object): pass ... py> x=X() py> rc(x) 2 py> y=x py> rc(x) 3 py> import weakref py> r=weakref.ref(x) py> r py> rc(x) 3 py> del y py> rc(x) 2 py> del x py> r (remember that getrefcount -as any function- holds a temporary reference to its argument, so the number it returns is one more than the expected value) > Object cache is one of the two reasons for the weakref module. ...when you don't want the object to stay artificially alive just because it's referenced in the cache. But the OP wants a different behavior, it seems. A standard dictionary where images are removed when they're no more needed (or a memory restriction is fired). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Mon Jun 29 10:59:59 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 11:59:59 -0300 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: En Mon, 29 Jun 2009 10:32:40 -0300, Petr Messner escribi?: > use %s instead of %d in SQL statements, because (AFAIK) conversions > (including SQL escaping) from Python values to SQL values are done > before the % operator is called - that value is not a number by that > point. > > I hope you understood it, sorry for my English :-) You can also check > MySQLdb module source, it's pretty clear. It's best to think of %s as just a marker; other adapters use ? or :3 for the same purpose, and other styles exist too. The fact that it's the same character used for formatting strings with the % operator is an unfortunate coincidence (or a very bad choice, I don't know). -- Gabriel Genellina From esj at harvee.org Mon Jun 29 11:03:05 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:03:05 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A48D7A9.40905@harvee.org> Peter Otten wrote: > Eric S. Johansson wrote: > >> MultiWordName mulitwordname >> very high error rate. many retries or hand hurting typing. > > Can you define macros in your speech recognition software? > > multiwordname > > might slightly lower the error rate. > Yes it would. I think it would be possible to specify a better grammar however. In the context of speech engine, if you know how the word is going to be used, (i.e. it's a method, it's a class, etc.) you can automatically do the transformation as part of the editors function. You need to know where you are in the syntax tree and that gives you enough knowledge to do the name transformation. When you stop thinking of speech recognition interactions as discrete macros or magic tricks, you can do a lot to accelerate coding. Fruit equals pear tree sub branch plus 5 The translator should know that the name on the lval is a variable (type signature determined later) and is terminated by the word equals (or =). The system would then apply the appropriate the name transformation. Continue on, equals would be transformed =, pear tree would be considered a complete name and based on whether it is a class definition or instance, would be transformed as a single name. Sub means there's an index here and would put the appropriate brackets between the expression branch (symbol terminated by plus) and 5 (symbol terminated by the end of line, fruit = pear_tree[branch+5] The next challenge comes in editing. It's fairly simple I would like to say "edit line [1*]" and put that line in an isolated buffer where I can edit the English form using all of the Select-and-Say controls. That should close the cycle from creation through editing. a small port of the development cycle. fyiw, the symbol trandformation code exists and has existed for almost 10 years. we need smart editing environments to make use of it. From nobody at nowhere.com Mon Jun 29 11:16:32 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 16:16:32 +0100 Subject: [RELEASED] Python 3.1 final References: <4a4763d5$0$307$9b622d9e@news.freenet.de> Message-ID: On Mon, 29 Jun 2009 13:57:49 +0200, Hallvard B Furuseth wrote: >> Okay, that's useful, except that it may have some bugs: >> (...) >> Assuming that this gets fixed, it should make most of the problems with >> 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g. >> sys.argv_bytes and os.environ_bytes. > > That's hopeless to keep track of across modules if something modifies > sys.argv or os.environ. Oh, I wasn't suggesting that they should be updated. Just that there should be some way to get at the original data. The mechanism used in 3.1 is sufficient. I'm mostly concerned that it's *possible* to recover the data; convenience is of secondary importance. Calling sys.setfilesystemencoding('iso-8859-1') right at the start of the code eliminates most of the issues. It's just the stuff which happens before the first line of code is executed (sys.argv, os.environ, sys.stdin etc) which was problematic. [BTW, it isn't just Python that has problems. The directory where I was performing tests happened to be an svn checkout. A subsequent "svn update" promptly crapped out because I'd left behind a file whose name wasn't valid ASCII.] From sk8in_zombi at yahoo.com.au Mon Jun 29 11:25:17 2009 From: sk8in_zombi at yahoo.com.au (Mr SZ) Date: Mon, 29 Jun 2009 08:25:17 -0700 (PDT) Subject: Find the name of a setup tools plugin when its class is known. Message-ID: <591684.58381.qm@web54504.mail.re2.yahoo.com> Hi, Using pkg_resources, I can iterate through the plugins in an entrypoint and note down the plugin classes and all using "pkg_resources.iter_entry_points(ENTRYPOINT)" Now, when the plugin is loaded, I want to know it's entrypoint name as I have to load a bunch of settings identified by the name string. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From nobody at nowhere.com Mon Jun 29 11:35:46 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 16:35:46 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Mon, 29 Jun 2009 11:41:11 +0000, Antoine Pitrou wrote: > Nobody nowhere.com> writes: >> >> This results in an internal error: >> >> > "\udce4\udceb\udcef\udcf6\udcfc".encode("iso-8859-1", "surrogateescape") >> Traceback (most recent call last): >> File "", line 1, in >> SystemError: Objects/bytesobject.c:3182: bad argument to internal function > > Please report a bug on http://bugs.python.org Done. > As for a bytes version of sys.argv and os.environ, you're welcome to propose a > patch (this would be a separate issue on the aforementioned issue tracker). Assuming that the above bug gets fixed, it isn't really necessary. In particular, maintaining bytes/string versions in the presence of updates is likely to be more trouble than it's worth. From aaron.hildebrandt at gmail.com Mon Jun 29 11:47:34 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Mon, 29 Jun 2009 08:47:34 -0700 (PDT) Subject: Using Python for file packing Message-ID: I'm working on a Python application right now that uses a large number of audio assets. Instead of having a directory full of audio, I'd like to pack all the audio into a single file. Is there any easy way to do this in Python? My first instinct was to attempt to pickle all the audio data, but something tells me that that experiment would only end in tears. From esj at harvee.org Mon Jun 29 11:49:04 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:49:04 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <4A48E270.6000403@harvee.org> alex23 wrote: > "Eric S. Johansson" wrote: >> no, I know the value if convention when editors can't tell you anything about >> the name in question. I would like to see more support for disabled programmers >> like myself and the thousands of programmers injured every year and forced to >> leave the field. seriously, there is no money in disability access especially >> for programmers. > > Well, if we can't use conventions like uppercasing, camelcasing and > underscoring, what are you recommending we do instead? help build a smart editing environment please. > > You seem to be asking us to change our behaviour to benefit only > others, but without offering any guidance on to how that is possible. > More importantly, shouldn't these modifications to common conventions > be coming _from_ the community of disabled programmers? I have a hard > time ensuring that I've gotten accurate requirements from co-workers > with whom I can actually see and speak, trying to determine how I > could write my code with accessibility in mind without any established > means of gauging success just seems impossible. Extremely valid point. The behavior I'm asking you to change is to consider the impact choices you make have on people with disabilities. I can only advocate for disabled programmer since I am one. Have been so for over 15 years. Have tried to maintain my position as architectural expert only to receive from venture capitalists and the likes "what good are you, you can't know enough to design our systems because you can't code" (yes, real quote). This is not always the case but enough that it really hurts my economics as well as the economics of other disabled programmers. Back in early 2000, I ran a series of workshops on the very issue of programming by voice. Back then we recognized the necessity for very smart editing environments which can tell us enough about what each symbol means so that we can direct the appropriate transformations from a higher-level grammar. I've introduce concepts such as command disambiguation through reduction of scope. Other people have added very good ideas with regards to usability and user interfaces for speech driven environment. Unfortunately, they all are gluons to an editor and they don't really integrate well because the editor isn't smart enough. Heck, have you ever noticed how most Python smart editors can't even indent properly according to local contexts. Emacs is the only one and even that one sometimes fails I can give you guidance as to what needs to be done. Other people can give guidance but I'm shooting for what may seem unachievable. Work with me a while and I will guide you as to how it's achievable. Maybe not by you but by someone we can find. I have lived way too many years with circus tricks. I don't want to end my life realizing I wasted my time in IT and regretting that I didn't take up the offer by mass rehab to go in restaurant or hotel management. one thing you can do to get a feel for out life is to get a copy of Naturally Speaking standard (100$ staples) and remove/cover keyboard. write email etc at first (10h) then try to write pep8 code. note to anyone who tries this, I'll support you in getting DNS running and help figure out any problems. only cost is if I tell you to do something like get a new mic, *do it*. I've lived this works and probably have put more deep thought and 8kloc into it because I do not accept circures tricks as a way of life. I want it to work right and I know how to do it. I just don't have the hands and hte money to pay me to do it. > >> and forgive me if this comes off sounding like a jerk but if >> the collective you don't give a sh** about your fellow programmers, who will? > > This isn't intended to be callous, as I feel that the collective > doesn't care as a whole about _any_ programmers, but isn't the answer > the very same disabled programmers for whom accessibility is an issue? > Programming tends to be needs driven (which, admittedly, can be simply > "to pay the bills"), and those who have a need tend to be better at > working out how to address it. yup how long will i be before you become disablesd? maybe not as badly as I am but you should start feeling some hand problems in your later 40's to early 50's and it goes down hill from there. self preservation/interest comes to mind as a possible motive for action. I thought 15 years would be enough for somebody else to push the isssue but no. if it is going to be, it has to be me. > > One possibility may be to approach a group for whom accessibility is > already a consideration, such as the Gnome Accessibility Project: > http://live.gnome.org/GAP not right focus for this project. tis one needs **deep** python knowledge (gvr level) and embedding it into an editor. heck, maybe we need a python interpreter in the editor to resolve some of the symbol stuff if we can get useful data from incomplete code. and I'll leave you an editor feature that may be usefull for all symbol not defined: choose from list or create new. I'll explain later. thanks for you thoughtful reply. From esj at harvee.org Mon Jun 29 11:51:35 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 11:51:35 -0400 Subject: pep 8 constants In-Reply-To: <4A48A495.7040504@tim.thechases.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> Message-ID: <4A48E307.50804@harvee.org> Tim Chase wrote: It sounds like the issue should be one of making your screen-reader > smarter, not dumbing down Python conventions. I don't know what SR > you're using (Jaws? Window Eyes? yasr? screeder? speakup? Naturally speaking is speech recognition (speech in text out) it is not text to speech although it does have a pluging for that From Scott.Daniels at Acm.Org Mon Jun 29 11:52:48 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 08:52:48 -0700 Subject: problems with mysql db In-Reply-To: References: Message-ID: golu wrote: > here i have posted my code...plz tell why am i getting the error "int > argument required" on the hash marked line(see below) although i am > giving an int value > ... url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > (url_count,file_path)) #error > ... Try something more like: > ... url_count += 1 > curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)", > [(url_count,file_path)]) > ... From davea at ieee.org Mon Jun 29 12:12:38 2009 From: davea at ieee.org (Dave Angel) Date: Mon, 29 Jun 2009 12:12:38 -0400 Subject: creating garbage collectable objects (caching objects) In-Reply-To: References: <4a47862b$0$31117$426a74cc@news.free.fr> <4a48744d$0$414$426a74cc@news.free.fr> <4A489F00.1040003@ieee.org> Message-ID: <4A48E7F6.9020404@ieee.org> Gabriel Genellina wrote: >
En Mon, > 29 Jun 2009 08:01:20 -0300, Dave Angel escribi?: >> News123 wrote: > >>> What I was more concerned is a group of output images depending on TWO >>> or more input images. >>> >>> Depending on the platform (and the images) I might not be able to >>> preload all two (or more images) >>> >>> So, as CPython's garbage collection takes always place immediately, >>> then I'd like to pursue something else. >>> I can create a cache, which caches input files as long as python leaves >>> at least n MB available for the rest of the system. > >> As I said earlier, I think weakref is probably what you need. A >> weakref is still a reference from the point of view of the >> ref-counting, but not from the point of view of the garbage >> collector. Have you read the help on weakref module? In particular, >> did you read Pep 0205? http://www.python.org/dev/peps/pep-0205/ > > You've misunderstood something. A weakref is NOT "a reference from the > point of view of the ref-counting", it adds zero to the reference > count. When the last "real" reference to some object is lost, the > object is destroyed, even if there exist weak references to it. That's > the whole point of a weak reference. The garbage collector isn't > directly related. > > py> from sys import getrefcount as rc > py> class X(object): pass > ... > py> x=X() > py> rc(x) > 2 > py> y=x > py> rc(x) > 3 > py> import weakref > py> r=weakref.ref(x) > py> r > > py> rc(x) > 3 > py> del y > py> rc(x) > 2 > py> del x > py> r > > > (remember that getrefcount -as any function- holds a temporary > reference to its argument, so the number it returns is one more than > the expected value) > >> Object cache is one of the two reasons for the weakref module. > > ...when you don't want the object to stay artificially alive just > because it's referenced in the cache. But the OP wants a different > behavior, it seems. A standard dictionary where images are removed > when they're no more needed (or a memory restriction is fired). > Thanks for correcting me. As I said earlier, I have no experience with weakref. The help and the PEP did sound to me like it would work for his needs. So how about adding an attribute in the large object that refers to the object iself?. Then the ref count will never go to zero, but it can be freed by the gc. Also store the ref in a WeakValueDictionary, and you can find the object without blocking its gc. And no, I haven't tried it, and wouldn't unless a machine had nothing important running on it. Clearly, the gc might not be able to keep up with this kind of abuse. But if gc is triggered by any attempt to make too-large an object, it might work. DaveA From nobody at nowhere.com Mon Jun 29 12:17:17 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 17:17:17 +0100 Subject: [RELEASED] Python 3.1 final References: Message-ID: On Mon, 29 Jun 2009 13:05:51 +0100, Paul Moore wrote: >> As for a bytes version of sys.argv and os.environ, you're welcome to >> propose a patch (this would be a separate issue on the aforementioned >> issue tracker). > > But please be aware that such a proposal would have to consider: > > 1. That on Windows, the native form is the character version, and the > bytes version would have to address all the same sorts of encoding > issues that the OP is complaining about in the character versions. [1] A bytes version doesn't make sense on Windows (at least, not on the NT-based versions, and the DOS-based branch isn't worth bothering about, IMHO). Also, Windows *needs* to deal with characters due to the fact that filenames, environment variables, etc are case-insensitive. > 2. That the proposal address the question of how to write portable, > robust, code (given that choosing argv vs argv_bytes based on > sys.platform is unlikely to count as a good option...) There is a tension here between robustness and portability. In my situation, robustness means getting the "unadulterated" data. I can always adulterate it myself if I need to. > 3. Why defining your own argv_bytes as argv_bytes = > [a.encode("iso-8859-1", "surrogateescape") for a in sys.argv] is > insufficient (excluding issues with bugs, which will be fixed > regardless) for the occasional cases where it's needed. Other than the bug, it appears to be sufficient. I don't need to support a locale where nl_langinfo(CODESET) is ISO-2022 (I *do* need to support lossless round-trip of ISO-2022 filenames, possibly stored in argv and maybe even in environ, but that's a different matter; the code only really needs to run with LANG=C). > [1] And my understanding, from the PEP, is that even on POSIX, the > argv and environ data is intended to be character data, even though > the native C APIs expose a byte-oriented interface. So conceptually, > character format is "correct" on POSIX as well... (But I don't write > code for POSIX systems, so I'll leave it to the POSIX users to debate > this point further). Even if it's "intended" to be character data, it isn't *required* to be. In particular, it's not required to be in the locale's encoding. A common example of what I need to handle is: find /www ... -print0 | xargs -0 myscript where the filenames can be in a wide variety of different encodings (sometimes even within a single directory). From lfscripter at gmail.com Mon Jun 29 12:18:20 2009 From: lfscripter at gmail.com (Elf Scripter) Date: Mon, 29 Jun 2009 17:18:20 +0100 Subject: Creating an Instance Messenger type of application Message-ID: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> Hello,Has anyone created an Instance Messenger in Python before, i mean a simple or Complex GUI based instance messenger? I thought about something like, the client also act as server, has it`s own listening port, but how can i handle uer auth? and adding visual effects to it. Please i am not trying to design another Yahoo IM/Skype but just for learning and also want to create real live application using the socket module. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchimento at gmail.com Mon Jun 29 12:19:31 2009 From: dchimento at gmail.com (Doug) Date: Mon, 29 Jun 2009 09:19:31 -0700 (PDT) Subject: Ctypes, pthreads and pthread_mutex_t Message-ID: <3ab1306f-3f37-403f-9768-81b657c87409@j14g2000vbp.googlegroups.com> Has any converted the structure pthread_mutex_t to a ctypes structure class ? I looking at some C code that is using pthreads and need to translate pthreads_mutex_t structure into python (via ctypes) Thanks From javier.collado at gmail.com Mon Jun 29 12:20:41 2009 From: javier.collado at gmail.com (Javier Collado) Date: Mon, 29 Jun 2009 18:20:41 +0200 Subject: Making code run in both source tree and installation path Message-ID: Hello, I would like to be able to run the main script in a python project from both the source tree and the path in which it's installed on Ubuntu. The script, among other things, imports a package which in turns makes use of some data files that contains some metadata that is needed in xml format. The source tree has an structure such as this one: setup.py debian/ (packaging files) src/ (source code) src/lib (package files) src/data (data files) src/bin (main script) However, when the project is installed using setup.py install, the directory structure is approximately this way: /usr/local/bin (main script) /usr/local/share/ (data files) /usr/local/lib/python2.x/dist-packages/ (library files) And when installing the code through a package, the structure is the same one, but removing "local". Hence, the data files aren't always in the same relative directories depending on we're executing code from the source tree or from the installation. To make it possible to run the code from both places, I've seen different approaches: - distutils trick in setup.py to modify the installed script (i.e. changing a global variable value) so that it has a reference to the data files location. - Heuristic in the package code to detect when it's being executed from the source tree and when it has been the installed - Just using an environment variable that the user must set according to his needs I guess that there are other options, for example, maybe using buildout. What would you say it's the best/more elegant option to solve this problem? Best regards, Javier From kushal.kumaran+python at gmail.com Mon Jun 29 12:23:17 2009 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 29 Jun 2009 21:53:17 +0530 Subject: Using Python for file packing In-Reply-To: References: Message-ID: <1e364c4e0906290923l2733e49es5ad85090c6a115ef@mail.gmail.com> On Mon, Jun 29, 2009 at 9:17 PM, Aaron Scott wrote: > I'm working on a Python application right now that uses a large number > of audio assets. Instead of having a directory full of audio, I'd like > to pack all the audio into a single file. Is there any easy way to do > this in Python? My first instinct was to attempt to pickle all the > audio data, but something tells me that that experiment would only end > in tears. Do you mean like a zip or tar file? http://docs.python.org/library/zipfile.html http://docs.python.org/library/tarfile.html -- kushal From aaron.hildebrandt at gmail.com Mon Jun 29 12:35:01 2009 From: aaron.hildebrandt at gmail.com (Aaron Scott) Date: Mon, 29 Jun 2009 09:35:01 -0700 (PDT) Subject: Using Python for file packing References: Message-ID: > Do you mean like a zip or tar file? > > http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html > I had no idea you could access a single file from a ZIP or TAR without explicitly extracting it somewhere. Thanks. From sajmikins at gmail.com Mon Jun 29 12:42:39 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 12:42:39 -0400 Subject: Creating an Instance Messenger type of application In-Reply-To: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> References: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> Message-ID: <50f98a4c0906290942s75b3bebl856ab7bc1688429e@mail.gmail.com> On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripter wrote: > Hello, > Has anyone created an Instance Messenger in Python before, i mean a simple > or Complex GUI based instance messenger? > I thought about something like, the client also act as server, has it`s own > listening port, but how can i handle uer auth? and adding visual effects to > it. > Please i am not trying to design another Yahoo IM/Skype but just for > learning and also want to create real live application using the socket > module. Instant, not Instance, Did you check google? From tomasz.dysinski at gmail.com Mon Jun 29 12:43:27 2009 From: tomasz.dysinski at gmail.com (bunnybones) Date: Mon, 29 Jun 2009 09:43:27 -0700 (PDT) Subject: pythonware.com down? References: <0cf67bd9-9ad9-471f-a566-1d45095bed51@t13g2000yqt.googlegroups.com> <4v12m.1716$8r.173@nlpi064.nbdc.sbc.com> Message-ID: <01fa223c-838d-446b-81c6-f7ed74da81e6@h2g2000yqg.googlegroups.com> I'm having the same problem accessing pythonware or effbot. I can't find any news about their server status. I can ping both addresses just fine. Does anyone know what is going on? Maybe the ghosts of celebrities recently passed are mucking with the tubes. RIP Billy Mays From sajmikins at gmail.com Mon Jun 29 12:58:00 2009 From: sajmikins at gmail.com (Simon Forman) Date: Mon, 29 Jun 2009 12:58:00 -0400 Subject: Creating an Instance Messenger type of application In-Reply-To: <6be1e1a30906290944m332fa62as12c134f78d00c715@mail.gmail.com> References: <6be1e1a30906290918h4554cfe5i7664eb907d66ed25@mail.gmail.com> <50f98a4c0906290942s75b3bebl856ab7bc1688429e@mail.gmail.com> <6be1e1a30906290944m332fa62as12c134f78d00c715@mail.gmail.com> Message-ID: <50f98a4c0906290958k4c646ac6pa5991994ae3f568d@mail.gmail.com> On Mon, Jun 29, 2009 at 12:44 PM, Elf Scripter wrote: > Thank you for correcting my mistake. > I checked google but nothing close. did you have any idea? > > On Mon, Jun 29, 2009 at 5:42 PM, Simon Forman wrote: >> >> On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripter >> wrote: >> > Hello, >> > Has anyone created an Instance Messenger in Python before, i mean a >> > simple >> > or Complex GUI based instance messenger? >> > I thought about something like, the client also act as server, has it`s >> > own >> > listening port, but how can i handle uer auth? and adding visual effects >> > to >> > it. >> > Please i am not trying to design another Yahoo IM/Skype but just for >> > learning and also want to create real live application using the socket >> > module. >> >> Instant, not Instance, ?Did you check google? > > I wouldn't try writing an IM or IRC client and/or server directly on the socket module, unless you really really wanted the learning experience. You might look at the "words" sub-project of the Twisted project [1] (although Twisted code has a significant learning curve itself, they do almost all of the network related heavy lifting for you.) There's also apparently a python binding to something called libpurple which seems to be a library used/provided by the "purple" multi-protocol IM/IRC client (used to be called GAIM). [2] HTH, ~Simon [1] http://twistedmatrix.com/trac/wiki/TwistedWords [2] http://briglia.net/wiki/tiki-index.php?page=Python-purple+Howto From Olivier.Darge at gmail.com Mon Jun 29 13:32:43 2009 From: Olivier.Darge at gmail.com (OdarR) Date: Mon, 29 Jun 2009 10:32:43 -0700 (PDT) Subject: fork, threads and proper closing References: Message-ID: <0b0454b8-aec1-40e4-b156-49030f80a46b@b9g2000yqm.googlegroups.com> On 29 juin, 14:44, Francesco Bochicchio wrote: > On 29 Giu, 07:10, OdarR wrote: > > > > > On 28 juin, 23:26, Tomasz Pajor wrote: > > > > Hello, > > > > Configuration is as follows. > > > > I have a starter process which creates 3 sub processes (forks) and each > > > of this processes creates a number of threads. > > > Threads in that processes have semaphore so on KeyboardInterrupt without > > > sending a sigterm to the subprocess i'm not able to close threads. > > > Is there any work around? Can I somehow run join for the thread on > > > keyboard interrupt? > > > When creating a thread you can add a Queue parameter to communicate > > with threads:http://docs.python.org/library/queue.html > > easy and reliable. > > > give them a "poison pill" in the queue: a recognizable object placed > > on the queue that means "when you get this, stop." > > This is the way I usually go, but it has one important limitation: if > the thread is waiting > for a blocking I/O operation to complete, like reading from a socket > with no data or waiting add a small wait (time.sleep()), and also, I/O function in Python can often releas the GIL... > for a locked resource (i.e. semaphore) to be unlocked, it will not > service the queue and will > not read the 'quit command' (the poison pill), and therefore will not > quit until the blocking > I/O terminates (and it could be never). > > ASAIK, there is no way - in python - to solve this. no easy way, yes... but I think I gave a good advice to our friend Tomasz :) Olivier From destroooooy at gmail.com Mon Jun 29 13:54:38 2009 From: destroooooy at gmail.com (destroooooy) Date: Mon, 29 Jun 2009 10:54:38 -0700 (PDT) Subject: python library call equivalent to `which' command Message-ID: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine the output from `which' itself, but I would like something more portable. I looked through the `os' and `os.path' modules but I didn't find anything. TIA Craig From hjtoi-better-remove-before-reply at comcast.net Mon Jun 29 14:22:37 2009 From: hjtoi-better-remove-before-reply at comcast.net (Heikki Toivonen) Date: Mon, 29 Jun 2009 11:22:37 -0700 Subject: validating HTTPS certificates? References: Message-ID: Andras.Horvath at cern.ch wrote: > I'm in the process of picking a language for a client application that > accesses a HTTPS (actually SOAP) server. This would be easy enough in > Python, but I came across a strange fact: neither httplib nor urllib > offer the possibility to actually verify the server's certificate. Right, stdlib does not do this for you automatically. You'd either need to write that code yourself, or use a third party library. I wrote a long post about this when 2.6 came out: http://www.heikkitoivonen.net/blog/2008/10/14/ssl-in-python-26/ -- Heikki Toivonen From ethan at stoneleaf.us Mon Jun 29 14:25:11 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Jun 2009 11:25:11 -0700 Subject: pep 8 constants In-Reply-To: <4A48E270.6000403@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> Message-ID: <4A490707.3040207@stoneleaf.us> Eric S. Johansson wrote: > > yup how long will i[t] be before you become disablesd? maybe not as badly as I am > but you should start feeling some hand problems in your later 40's to early 50's > and it goes down hill from there. self preservation/interest comes to mind as a > possible motive for action. I thought 15 years would be enough for somebody > else to push the isssue but no. if it is going to be, it has to be me. For anyone who is still able to use their hands for typing, especially if you're beginning to encounter the painful wrists, consider switching to a Dvorak layout. It was a system I was curious about even before I needed it, and when I did need it I was able to create the layout in assembler (now, of course, it's widely available as a standard keyboard layout). I started noticing the pain in my late twenties (aggravated, I'm sure, by arthritis), but with switching to Dvorak the pain left and has only very rarely been noticable again. It will mostly likely be a challenge to switch, but well worth it. http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard ~Ethan~ From georgedogaru at gmail.com Mon Jun 29 14:42:11 2009 From: georgedogaru at gmail.com (geo) Date: Mon, 29 Jun 2009 11:42:11 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: <26759d8f-be58-4c44-a524-015d64323dce@l31g2000yqb.googlegroups.com> On Jun 29, 2:54?pm, peter wrote: > Whilst this is an interesting discussion about installers, I'm still > trying to find a copy of PIL. ?Any ideas? Hello, I had the very same problem and found this: http://www.portablepython.com/ It contains PIL and some other cool stuff. Hope it helps. George From timpinkawa at gmail.com Mon Jun 29 14:53:30 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 13:53:30 -0500 Subject: python library call equivalent to `which' command In-Reply-To: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 12:54 PM, destroooooy wrote: > Hi, > I'm looking for a Python library function that provides the same > functionality as the `which' command--namely, search the $PATH > variable for a given string and see if it exists anywhere within. I > currently examine the output from `which' itself, but I would like > something more portable. I looked through the `os' and `os.path' > modules but I didn't find anything. This works on POSIX systems. Windows uses semicolons to separate paths rather than colons so that would need to be taken into account when running on Windows. This also doesn't recognize shell built-ins, only real binaries. import os def which(file): for path in os.environ["PATH"].split(":"): if file in os.listdir(path): print "%s/%s" % (path, file) >>> which("ls") /bin/ls From mail at timgolden.me.uk Mon Jun 29 14:58:00 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 29 Jun 2009 19:58:00 +0100 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A490EB8.3030101@timgolden.me.uk> Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 12:54 PM, destroooooy wrote: >> Hi, >> I'm looking for a Python library function that provides the same >> functionality as the `which' command--namely, search the $PATH >> variable for a given string and see if it exists anywhere within. I >> currently examine the output from `which' itself, but I would like >> something more portable. I looked through the `os' and `os.path' >> modules but I didn't find anything. > > This works on POSIX systems. Windows uses semicolons to separate paths > rather than colons so that would need to be taken into account when > running on Windows. This also doesn't recognize shell built-ins, only > real binaries. > > import os > > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) > >>>> which("ls") > /bin/ls There's a "which.py" in the tools directory included in the Python distribution. On windows, that's c:\python26\tools\scripts; don't know where to look on Linux. Don't know how good it is as I -- like many, I suspect -- wrote my own, which in my case is Windows-specific. TJG From mabdelkader at gmail.com Mon Jun 29 15:03:14 2009 From: mabdelkader at gmail.com (ma) Date: Mon, 29 Jun 2009 15:03:14 -0400 Subject: TWiki Python API Wrapper Message-ID: <148918f0906291203i222ca6i1eabc2e46656ba9e@mail.gmail.com> Has anyone come across a decent python API wrapper for TWiki? I'm trying to automate some reports and logs to automatically post, create topics, and re-arrange a few things on our TWiki, but my googleFu has failed me :( I did find an interesting module in Perl, http://cpanratings.perl.org/dist/WWW-Mechanize-TWiki . Looking at the TWiki documentations, I found a perl API reference: http://twiki.org/cgi-bin/view/TWiki/TWikiFuncDotPm . A proof of concept, using these two perl modules, was generated by a blog post here: http://roberthanson.blogspot.com/2006/01/copying-from-blogger-to-twiki-with.html Before I make my own pythonic port, using mechanize, and wrapping around the aforementioned TWiki api, I wanted to see if anyone had any other ideas, approaches, or modules to help expedite the task? Thanks! Mahmoud Abdelkader -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jun 29 15:06:52 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 15:06:52 -0400 Subject: No trees in the stdlib? In-Reply-To: <7xeit3ae58.fsf@ruckus.brouhaha.com> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > The idea is you can accomplish the equivalent of insertion or deletion > by allocating a new root, along with the path down to the place you > want to insert, i.e. O(log n) operations. So instead of mutating an > existing tree, you create a new tree that shares most of its structure > with the old tree, and switch over to using the new tree. Now I get what your have been talking about over several posts. Update and mutate are kind of synonymous in my mind, but the above explains how they can be different. This > trivially lets you maintain snapshots of old versions of the tree, > implement an "undo" operation, have a background thread do a complex > operation on a snapshot while the foreground thread does any number of > update-and-replace operations, etc. > > This is very standard stuff. Now for someone raised on arrays, iteration, and procedural programming ;-). > http://en.wikipedia.org/wiki/Persistent_data_structure Reading it now. > > The wikipedia article on AVL trees makes it pretty obvious how an > implementation would work. From gordon at panix.com Mon Jun 29 15:15:08 2009 From: gordon at panix.com (John Gordon) Date: Mon, 29 Jun 2009 19:15:08 +0000 (UTC) Subject: Q: finding distance between 2 time's References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: In <023130ef$0$19421$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: > > if time_difference < 3601: > That's a potential off-by-one error. [...] The right test is: > if time_difference <= 3600: Aren't those two comparisons the same? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From esj at harvee.org Mon Jun 29 15:15:32 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 15:15:32 -0400 Subject: pep 8 constants In-Reply-To: <4A490707.3040207@stoneleaf.us> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> <4A490707.3040207@stoneleaf.us> Message-ID: <4A4912D4.5070900@harvee.org> Ethan Furman wrote: > Eric S. Johansson wrote: >> >> yup how long will i[t] be before you become disablesd? maybe not as >> badly as I am >> but you should start feeling some hand problems in your later 40's to >> early 50's >> and it goes down hill from there. self preservation/interest comes to >> mind as a >> possible motive for action. I thought 15 years would be enough for >> somebody >> else to push the isssue but no. if it is going to be, it has to be me. > > For anyone who is still able to use their hands for typing, especially > if you're beginning to encounter the painful wrists, consider switching > to a Dvorak layout. It was a system I was curious about even before I > needed it, and when I did need it I was able to create the layout in > assembler (now, of course, it's widely available as a standard keyboard > layout). I started noticing the pain in my late twenties (aggravated, > I'm sure, by arthritis), but with switching to Dvorak the pain left and > has only very rarely been noticable again. It will mostly likely be a > challenge to switch, but well worth it. a good suggestion but not really addressing the point I'm trying to make of building a system that would help people more profoundly injured. for example, I've tried Dvorak and the act of typing was so painful that I couldn't learn it From chambon.pascal at gmail.com Mon Jun 29 15:15:52 2009 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Mon, 29 Jun 2009 21:15:52 +0200 Subject: Direct interaction with subprocess - the curse of blocking I/O Message-ID: <4A4912E8.7090506@gmail.com> Hello everyone I've had real issues with subprocesses recently : from a python script, on windows, I wanted to "give control" to a command line utility, i.e forward user in put to it and display its output on console. It seems simple, but I ran into walls : - subprocess.communicate() only deals with a forecast input, not step-by-step user interaction - pexpect module is unix-only, and for automation, not interactive input - when wanting to do all the job manually (transfering data between the standard streams of the python program and the binary subprocess, I met the issue : select() works only on windows, and python's I/O are blocking, so I can't just, for example, get data from the subprocess' stdout and expect the function to return if no input is present - the requesting thread might instead block forever. Browsing the web, I found some hints : - use the advanced win32 api to create non-blocking I/O : rather complicated, non portable and far from the python normal files - use threads that block on the different streams and eat/feed them without ever stopping : rather portable, but gives problems on shutdown (How to terminate these threads without danger ? On some OSes, a process never dies as long as any thread - even "daemonic" - lives, I've seen people complaining about it). So well, I'd like to know, do you people know any solution to this simple problem - making a user interact directly with a subprocess ? Or would this really require a library handling each case separately (win32 api, select().....) ? Thanks a lot for your interest and advice, regards, Pascal From lists at cheimes.de Mon Jun 29 15:17:20 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 21:17:20 +0200 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: Tim Pinkawa wrote: > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) "if file in os.list()" is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you have to verify that the file has the executable bit, too. Christian From esj at harvee.org Mon Jun 29 15:28:07 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 15:28:07 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> Message-ID: <4A4915C7.5050204@harvee.org> Rhodri James wrote: > On Mon, 29 Jun 2009 06:07:19 +0100, Eric S. Johansson > wrote: > >> Rhodri James wrote: >> >>> Reject away, but I'm afraid you've still got some work to do to >>> convince me that PEP 8 is more work for an SR system than any other >>> convention. >> > > [snip sundry examples] > > Yes, yes, recognition systems need both training and a careful selection > of words to recognise to be effective. This I learned twenty years ago: > if "cap" has a high failure rate, use something else. A more profitable way would be to build a framework doing the right job and not trying to make it happen by side effect and "speaking the keyboard". Speaking the keyboard is whenever you force someone to go through gyrations to adjust spacing, case or special single character assertions (i.e.;). > > As far as I can tell, the only thing that you are even vaguely suggesting > for convention use is underscores_with_everything. As promised, I laugh > hollowly. I'm sorry. It may have been too subtle. I'm suggesting a smart editor that can tell me anything about any name in the body of code I'm working or anything I've included. with that kind of tool, I can have a command grammar that is much friendlier to the voice and gets work done faster than typing.things such as: what is this name? it's a class. What are its methods? tree branch root root template plea se .root(howmany=1, branches=3, nodes={}) and the query can go from there. Using tools like these, one can keep pep-8 conventions and not create a discriminatory environment. From timpinkawa at gmail.com Mon Jun 29 15:31:25 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 14:31:25 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: > "if file in os.list()" is slow and not correct. You have to check if the > file is either a real file or a symlink to a file and not a directory or > special. Then you have to verify that the file has the executable bit, too. I realize four lines of Python does not replicate the functionality of which exactly. It was intended to give the original poster something to start with. I am curious about it being slow, though. Is there a faster way to get the contents of a directory than os.listdir() or is there a faster way to see if an element is in a list other than "x in y"? I believe 'which' will terminate once it finds any match, which mine does not, but that can be fixed by adding a break after the print. From nobody at nowhere.com Mon Jun 29 15:37:29 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 20:37:29 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 13:53:30 -0500, Tim Pinkawa wrote: >> I'm looking for a Python library function that provides the same >> functionality as the `which' command--namely, search the $PATH >> variable for a given string and see if it exists anywhere within. I >> currently examine the output from `which' itself, but I would like >> something more portable. I looked through the `os' and `os.path' >> modules but I didn't find anything. > > This works on POSIX systems. Windows uses semicolons to separate paths > rather than colons so that would need to be taken into account when > running on Windows. This also doesn't recognize shell built-ins, only > real binaries. FWIW, "which" doesn't recognise built-ins either; the "type" built-in does. > import os > > def which(file): > for path in os.environ["PATH"].split(":"): > if file in os.listdir(path): > print "%s/%s" % (path, file) There are a couple of problems with this: 1. "which" only considers executable files, and the default behaviour is to only display the first matching file. Also, I'm assuming that the OP wants a function which returns the path rather than printing it. 2. os.listdir() requires read permission (enumerate permission) on each directory. The standard "which" utility stat()s each possible candidate, so it only requires execute permission (lookup permission) on the directories. A secondary issue is performance; enumerating a directory to check for a specific entry can be much slower than stat()ing the specific entry. IOW: def which(file): for path in os.environ["PATH"].split(os.pathsep): if os.access(os.path.join(path, file), os.X_OK): return "%s/%s" % (path, file) But for Windows, you also need to use PATHEXT, e.g.: for dir in os.environ["PATH"].split(os.pathsep): for ext in os.environ["PATHEXT"].split(os.pathsep): full = os.path.join(dir, "%s.%s" % (file, ext)) if os.access(full, os.X_OK): return full Disclaimer: I don't know how accurate os.access(..., os.X_OK) is on Windows; OTOH, it's probably as good as you'll get. From timpinkawa at gmail.com Mon Jun 29 15:38:54 2009 From: timpinkawa at gmail.com (Tim Pinkawa) Date: Mon, 29 Jun 2009 14:38:54 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, Jun 29, 2009 at 2:31 PM, Tim Pinkawa wrote: > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. To answer my own question on this specific case, you could check with os.access which may be faster. I am still curious, Christian, if your issue with it being slow was that "os.listdir is slow" or "os.listdir is slow in this case". From robert.kern at gmail.com Mon Jun 29 15:43:04 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 29 Jun 2009 14:43:04 -0500 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On 2009-06-29 14:31, Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. Just check if os.path.exists(os.path.join(path, filename)). -- 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 a0046088 at airmail.net Mon Jun 29 15:51:24 2009 From: a0046088 at airmail.net (wwwayne) Date: Mon, 29 Jun 2009 13:51:24 -0600 Subject: Tutorials on Jinja References: <2e068b45-0635-4efb-8d7f-39229acb72ba@j9g2000vbp.googlegroups.com> Message-ID: <156i45d84n4g0ajhjrk80obhmahp5o9ha3@4ax.com> On Thu, 25 Jun 2009 07:17:42 -0700 (PDT), Saurabh wrote: >On Jun 25, 2:04?am, Wayne Brehaut wrote: >> On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh >> >> wrote: >> >Hi All, >> >> >I am trying to move my application on a MVC architecture and plan to >> >use Jinja for the same. Can anyone provide me with few quick links >> >that might help me to get started with Jinja? >> >> Perhaps the most useful link is: >> >> http://www.google.com/ >> >> from which you can easily find many more with a very basic search, >> including: >> >> http://jinja.pocoo.org/ >> >> Hope that helps? >> wwwayne >> >> >> >> >Thanks, >> >Saby >> >> > >Thanks (Sir!). I was hoping to get some good tutorial on >implementation (which I wasn't able to find with a basic search - >http://dev.pocoo.org/projects/lodgeit/ is what I was referring to >earlier) as this is my first assignment on any template engine (never >used Cheetah, MakO, Tempita). >I would appreciate people responding with something helpful. If you >find a question pretty naive, kindly ignore the question rather than >passing comments on it. Doesn't helps anyone's time. Not phrasing questions in a helpful way initially also doesn't lead to good use of anyone's time, and I suggest another link: http://catb.org/esr/faqs/smart-questions.html Your original question asked for a "few quick links that might help me to get started with Jinja", which made it appear you didn't know where to start and hadn't yet done even a basic search yourself, so I thought I *was* being helpful. Now that you provide the information that would have helped others to respond more usefully previously, perhaps they will. w >Thanks again From lists at cheimes.de Mon Jun 29 15:53:42 2009 From: lists at cheimes.de (Christian Heimes) Date: Mon, 29 Jun 2009 21:53:42 +0200 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A491BC6.3080901@cheimes.de> Tim Pinkawa wrote: > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. Agreed! > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. You don't need to get the entire directory content to see if a file exists. The stat() syscall is much faster because it requires fewer disk reads. On modern file systems stat() is a O(1) operation while "file" in listdir() is a O(n) operation. By the way you need the result of os.stat anyway to see if the file has the executable bits set. Christian From cgoldberg at gmail.com Mon Jun 29 16:06:35 2009 From: cgoldberg at gmail.com (cgoldberg) Date: Mon, 29 Jun 2009 13:06:35 -0700 (PDT) Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: <1ed266a1-fdb2-4887-bf7d-b1bae316988a@x3g2000yqa.googlegroups.com> > So well, I'd like to know, do you people know any solution to this > simple problem - making a user interact directly with a subprocess? you might want something like Expect. check out the pexpect module: http://pexpect.sourceforge.net/pexpect.html -Corey From ethan at stoneleaf.us Mon Jun 29 16:07:13 2009 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Jun 2009 13:07:13 -0700 Subject: alternative to JoinableQueue's please In-Reply-To: <4A4573BE.9030704@gmail.com> References: <4A4573BE.9030704@gmail.com> Message-ID: <4A491EF1.9030609@stoneleaf.us> > ps: Thanks Raymond for the quick reply... and I feel rather apologetic > for having bothered the list with this :S > No need to feel that way -- many of us still learn from simple looking problems! :) ~Ethan~ From nobody at nowhere.com Mon Jun 29 16:17:39 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:17:39 +0100 Subject: Q: finding distance between 2 time's References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Jun 2009 19:15:08 +0000, John Gordon wrote: >> > if time_difference < 3601: > >> That's a potential off-by-one error. [...] The right test is: > >> if time_difference <= 3600: > > Aren't those two comparisons the same? Not if time_difference is a float. From nobody at nowhere.com Mon Jun 29 16:26:29 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:26:29 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 14:31:25 -0500, Tim Pinkawa wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() No. > or is there a faster way to see if an element is in a list other than > "x in y"? No. However, there is a faster (and more correct) way to test for file existence than enumerating the directory then checking whether the file is in the resulting list, namely to stat() the file. I.e. os.path.exists() or os.access(); the latter will allow you to check for execute permission at the same time. On some systems, the speed difference may be very significant. If readdir() is a system call, os.listdir() will make one system call (two context switches) per directory entry, while os.access() will make one system call in total. [Linux has the (non-standard) getdents() system call, which returns multiple directory entries per call. The readdir() library function uses getdents(), as it is much more efficient than using the readdir() system call.] From Scott.Daniels at Acm.Org Mon Jun 29 16:30:13 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 13:30:13 -0700 Subject: Q: finding distance between 2 time's In-Reply-To: References: <90c970e0-630c-4910-91b9-ce6c547f0946@g1g2000yqh.googlegroups.com> <023130ef$0$19421$c3e8da3@news.astraweb.com> Message-ID: John Gordon wrote: > In <023130ef$0$19421$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >>> if time_difference < 3601: >> That's a potential off-by-one error. [...] The right test is: >> if time_difference <= 3600: > Aren't those two comparisons the same? Only if time_difference is an integer. --Scott David Daniels Scott.Daniels at Acm.Org From torriem at gmail.com Mon Jun 29 16:33:16 2009 From: torriem at gmail.com (Michael Torrie) Date: Mon, 29 Jun 2009 14:33:16 -0600 Subject: Advantages of Python (for web/desktop apps)? In-Reply-To: <24239603.post@talk.nabble.com> References: <24239603.post@talk.nabble.com> Message-ID: <4A49250C.1090801@gmail.com> iceangel89 wrote: > i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used > .NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python > now (for desktop apps since its open source and just want to try what it > offers, but will like to know what good it has for web development also) Give it a try. wxPython or PyQt is preferred for GUI development in general on win32. PyGTK also works on win32 but maybe isn't as nice-looking as the first two options (although the API is much more pythonic by some accounts). The Idle IDE may get you started. When you've profiled your program and found where the common cases are slow, then you can work on optimization substitution pure python routines with native ones written in C, C++, etc From nobody at nowhere.com Mon Jun 29 16:35:36 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:35:36 +0100 Subject: python library call equivalent to `which' command References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: On Mon, 29 Jun 2009 21:53:42 +0200, Christian Heimes wrote: >> I am curious about it being slow, though. Is there a faster way to get >> the contents of a directory than os.listdir() or is there a faster way >> to see if an element is in a list other than "x in y"? I believe >> 'which' will terminate once it finds any match, which mine does not, >> but that can be fixed by adding a break after the print. > > You don't need to get the entire directory content to see if a file > exists. The stat() syscall is much faster because it requires fewer disk > reads. On modern file systems stat() is a O(1) operation while "file" in > listdir() is a O(n) operation. Apart from performance, stat() is more correct. readdir() (and Linux' getdents()) requires read permission on the directory, while stat() (and open() etc) only requires execute permission. On shared web (etc) servers, it's not uncommon for system directories (e.g. /usr/bin) to be "drwxr-x--x", as normal users shouldn't need to enumerate these directories. From nobody at nowhere.com Mon Jun 29 16:45:06 2009 From: nobody at nowhere.com (Nobody) Date: Mon, 29 Jun 2009 21:45:06 +0100 Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: On Mon, 29 Jun 2009 21:15:52 +0200, Pascal Chambon wrote: > I've had real issues with subprocesses recently : from a python script, > on windows, I wanted to "give control" to a command line utility, i.e > forward user in put to it and display its output on console. Are you talking about a popen(..., 'w') situation? I.e. where Python feeds data to the child's stdin but the child's stdout doesn't go through Python? Or a slave process, where both stdin and stdout/stderr are piped to/from Python? The latter is inherently tricky (which is why C's popen() lets you connect to stdin or stdout but not both). You have to use either multiple threads, select/poll, or non-blocking I/O. If the child's output is to the console, it should presumably be the former, i.e. piping stdin but allowing the child to inherit stdout, in which case, where's the problem? Or are you piping its stdout via Python for the hell of it? From tjreedy at udel.edu Mon Jun 29 16:47:58 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 16:47:58 -0400 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: <4A4894F4.7040606@cox.net> References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> <4A4894F4.7040606@cox.net> Message-ID: > Martin v. L?wis wrote: >>> I sorta' wish he'd just come out and say, "This is what I think would >>> be suitable for a GUI toolkit for Python: ...". >>> >> >> He is not in the business of designing GUI toolkits, but in the business >> of designing programming languages. So he abstains from specifying >> (or even recommending) a GUI library. >> >> What he makes clear is the point that Terry cites: no matter what the >> GUI toolkit is or what features it has - it should be simple to create >> GUIs, as simple as creating HTML. Having quoted Guido, I will note a few other things: Python already comes with a GUI toolkit, so the question is really "What would Guido want in a replacement for tk/tkinter?" Obviously, it should be even better that the current (and even, prospective) version of TK. 'Better' would need to be demonstrated. Part of that would be a PEP written by or supported by the person in charge of the replacement, with a detailed comparison and argument. Part of that would also be a re-writing of IDLE with the new GUI, with some visible advantage in the gui part of the code. I do not believe either has been done. The replacement should also have majority support. However, there are at least 3 or 4 contenders. My impression is that most of the supporters of each prefer (and rationally so) the status quo to having one of the other contenders being chosen, and thereby shutting out their favorite. The replacement would need to work with Py 3. TK does. I have not noticed that anything else does, though that should change eventually. (And I am sure someone will point of something I have not noticed.) Guido is properly somewhat conservative about 'spending' BDFL points. There is no need to decide anything at present. Terry Jan Reedy From peter.mosley at talk21.com Mon Jun 29 16:57:48 2009 From: peter.mosley at talk21.com (peter) Date: Mon, 29 Jun 2009 13:57:48 -0700 (PDT) Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> <26759d8f-be58-4c44-a524-015d64323dce@l31g2000yqb.googlegroups.com> Message-ID: <1e4066cd-cc8b-4124-85ba-a239b88c1c4a@a36g2000yqc.googlegroups.com> Thanks for this - looks promising. But I've just tried pythonware again and it's back up - so it was just a glitch after all. Peter From piet at cs.uu.nl Mon Jun 29 17:12:09 2009 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 29 Jun 2009 23:12:09 +0200 Subject: Python Imaging Library download link broken? References: <36859d70-d0c1-41c1-b874-83680bf33e5b@j3g2000yqa.googlegroups.com> Message-ID: >>>>> peter (p) wrote: >p> Whilst this is an interesting discussion about installers, I'm still >p> trying to find a copy of PIL. Any ideas? Pythonware is up again: http://pythonware.com/products/pil/index.htm -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From Scott.Daniels at Acm.Org Mon Jun 29 17:16:34 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:16:34 -0700 Subject: Using Python for file packing In-Reply-To: References: Message-ID: Aaron Scott wrote: >> Do you mean like a zip or tar file? >> >> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >> > > I had no idea you could access a single file from a ZIP or TAR without > explicitly extracting it somewhere. Thanks. You will find the zip format works better if you are compressing. The zipfile compression is per file in the archive, rather than applied to the entire archive (as in tarfile). The results of the tar format decision is that extracting the last file in a .tgz (.tar.gz) or .tar.bz2 (sometimes called .tbz) requires the expansion of the entire archive, while extraction on a .zip is reposition, read, and possibly expand. --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Mon Jun 29 17:26:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:26:09 -0700 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: Robert Kern wrote: > On 2009-06-29 14:31, Tim Pinkawa wrote: >> On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes >> wrote: >>> "if file in os.list()" is slow and not correct. You have to check if the >>> file is either a real file or a symlink to a file and not a directory or >>> special. Then you have to verify that the file has the executable >>> bit, too. >> >> I realize four lines of Python does not replicate the functionality of >> which exactly. It was intended to give the original poster something >> to start with. >> >> I am curious about it being slow, though. Is there a faster way to get >> the contents of a directory than os.listdir() or is there a faster way >> to see if an element is in a list other than "x in y"? I believe >> 'which' will terminate once it finds any match, which mine does not, >> but that can be fixed by adding a break after the print. > > Just check if os.path.exists(os.path.join(path, filename)). > But on windows, checking for a list of possible extensions, it may well be faster to operate on the listdir output. I made my which-equivalent function a generator, so I could choose to stop at the first entry or continue at the invoker's pleasure (good for both Trojan-discovery and "forgot to delete the .pyc" operations). --Scott David Daniels Scott.Daniels at Acm.Org From rhvonlehe at gmail.com Mon Jun 29 17:41:34 2009 From: rhvonlehe at gmail.com (rhvonlehe at gmail.com) Date: Mon, 29 Jun 2009 14:41:34 -0700 (PDT) Subject: using input(), raw_input() to allow user to run different functions Message-ID: Something's been giving me difficulty.. We have a USB-attached device that we frequently debug with simple python scripts. The model has always been that each script logs on to the device, does something, then logs off. As it turns out, we have mostly written scripts as unit tests for each API command. So, we'll call one script that will configure a process on the device, and a separate script that will retrieve the results of that process. The model is changing inside the device such that all settings will be lost when we log off. This means we'll have to merge a bunch of scripts in various ways. I thought it would be neat if I could have one master python script do the logon, then allow the user to input the name of a previously- written script he wanted to execute while logged on. Finally, when exiting the master script, the user would logout from the device. I'm trying to test this by using input() or raw_input() to get the function the user wants to execute. I'm not having much luck. Here's an example: Shell.py: #! /usr/bin/env python from CollectNDResults import * ... request = input('Script shell >>> ') print request exec (request) ## I realize the parentheses are not needed ... When I run Shell.py I get this: Script shell >>> CollectNDResults Traceback (most recent call last): File "./Shell.py", line 35, in ? Shell(sys.argv[1:]) File "./Shell.py", line 24, in Shell exec (request) TypeError: exec: arg 1 must be a string, file, or code object Is there a good reference for me to figure out how to turn my function name into the code object that I want to execute? Is there a better way to do what I'm trying to do? Thanks, Rich From Scott.Daniels at Acm.Org Mon Jun 29 17:43:31 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 29 Jun 2009 14:43:31 -0700 Subject: Direct interaction with subprocess - the curse of blocking I/O In-Reply-To: References: Message-ID: Pascal Chambon wrote: > I've had real issues with subprocesses recently : from a python script, > on windows, I wanted to "give control" to a command line utility, i.e > forward user in put to it and display its output on console.... > Browsing the web, I found some hints : > - use the advanced win32 api to create non-blocking I/O : rather > complicated, non portable ... > > So well, I'd like to know, do you people know any solution to this > simple problem - making a user interact directly with a subprocess ? Or > would this really require a library handling each case separately (win32 > api, select().....) ? I would guess the architectural differences are so great that an attempt to "do something simple" is going to involve architecture-specific code. and I personally wouldn't have it any other way. Simulating a shell with hooks on its I/O should be so complicated that a "script kiddie" has trouble writing a Trojan. --Scott David Daniels Scott.Daniels at Acm.Org From trentm at activestate.com Mon Jun 29 17:45:44 2009 From: trentm at activestate.com (Trent Mick) Date: Mon, 29 Jun 2009 14:45:44 -0700 Subject: python library call equivalent to `which' command In-Reply-To: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A493608.2070907@activestate.com> destroooooy wrote: > Hi, > I'm looking for a Python library function that provides the same > functionality as the `which' command--namely, search the $PATH > variable for a given string and see if it exists anywhere within. I > currently examine the output from `which' itself, but I would like > something more portable. I looked through the `os' and `os.path' > modules but I didn't find anything. http://code.google.com/p/which/ Trent -- Trent Mick trentm at activestate.com http://trentm.com/blog/ From junhufr at gmail.com Mon Jun 29 17:51:50 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 14:51:50 -0700 (PDT) Subject: Drawing in PDF Message-ID: HEllo, I've a pdf file, and i want to draw some additional stuff on it, by example : some markup .... notation. Anyone has idea how to do that ? thank you in advance. From user at example.net Mon Jun 29 17:54:33 2009 From: user at example.net (superpollo) Date: Mon, 29 Jun 2009 23:54:33 +0200 Subject: timer Message-ID: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> hi folks. the follwing shoud print 'stuff' for 3 seconds and then stop. why it does not work? (prints stuff forever) 1 #!/usr/bin/python 2 3 import threading 4 import sys 5 6 t = threading.Timer(3.0, sys.exit) 7 t.start() 8 while True: 9 print "stuff ", bye From backup95 at netcabo.pt Mon Jun 29 17:54:38 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Mon, 29 Jun 2009 22:54:38 +0100 Subject: No trees in the stdlib? In-Reply-To: <4A485777.2000301@netcabo.pt> References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <4A49381E.9060303@netcabo.pt> Jo?o Valverde wrote: > Paul Rubin wrote: >> Jo?o Valverde writes: >> >>> Interesting, thanks. The concept is not difficult to understand but >>> I'm not sure it would be preferable. A copy operation should have the >>> same cost as a "snapshot", >> >> You mean a deep-copy? That is unnecessarily expensive; with a >> functional structure you can snapshot (or copy) by copying a single >> pointer. >> >> > > Shallow copy... > >>> undo is kind of redundant and multithreading... don't see a >>> compelling use that would justify it. >> >> Here is one: >> http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b >> >> > > I just skimmed that but if someone really needs multithreading for > such intensive processing without wanting a database, fair enough I > guess. > >>> Have you considered how the syntax would work in Python by the way? >>> This: >>> new_tree = old_tree.insert(object) >>> Just looks wrong. >> >> It looks fine to me. Obviously you could support a wrapper with >> a mutating slot that holds a pointer to the tree. >> > I didn't get the last part, sorry. But I think you'd have a lot of > users annoyed that the interface is similar to a list yet their > objects mysteriously disappear. To me, tree.insert() implies > mutability but I defer that to others like yourself with more > experience in Python than me. > Rereading this I got what you meant by "wrapper with mutating slot". But that is (like I think you implied) functionally equivalent to a mutating data structure, with worse performance because of additional memory allocation and such. Is it faster to rebalance the tree with a persistent data structure? From gagsl-py2 at yahoo.com.ar Mon Jun 29 17:58:45 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Jun 2009 18:58:45 -0300 Subject: Ctypes, pthreads and pthread_mutex_t References: <3ab1306f-3f37-403f-9768-81b657c87409@j14g2000vbp.googlegroups.com> Message-ID: En Mon, 29 Jun 2009 13:19:31 -0300, Doug escribi?: > Has any converted the structure pthread_mutex_t to > a ctypes structure class ? > I looking at some C code that is using pthreads and need to translate > pthreads_mutex_t structure into python (via ctypes) I think the pthread_mutex_t type is intended to be "opaque" to application code. You should not mess with its contents; the only thing one must know is its size (and only if one wants to allocate it from Python). For the most part, it's like a void* pointer. -- Gabriel Genellina From clp2 at rebertia.com Mon Jun 29 17:59:42 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 14:59:42 -0700 Subject: using input(), raw_input() to allow user to run different functions In-Reply-To: References: Message-ID: <50697b2c0906291459m483ee444ybd7142404992fe75@mail.gmail.com> On Mon, Jun 29, 2009 at 2:41 PM, rhvonlehe at gmail.com wrote: > Something's been giving me difficulty.. > > We have a USB-attached device that we frequently debug with simple > python scripts. ?The model has always been that each script logs on to > the device, does something, then logs off. ?As it turns out, we have > mostly written scripts as unit tests for each API command. ?So, we'll > call one script that will configure a process on the device, and a > separate script that will retrieve the results of that process. > > The model is changing inside the device such that all settings will be > lost when we log off. ?This means we'll have to merge a bunch of > scripts in various ways. > > I thought it would be neat if I could have one master python script do > the logon, then allow the user to input the name of a previously- > written script he wanted to execute while logged on. ?Finally, when > exiting the master script, the user would logout from the device. > > I'm trying to test this by using input() or raw_input() to get the > function the user wants to execute. ?I'm not having much luck. ?Here's > an example: > > > > Shell.py: > #! /usr/bin/env python > from CollectNDResults import * > ... > request = input('Script shell >>> ') > print request > exec (request) ? ## I realize the parentheses are not needed > ... > > > When I run Shell.py I get this: > > Script shell >>> CollectNDResults > > Traceback (most recent call last): > ?File "./Shell.py", line 35, in ? > ? ?Shell(sys.argv[1:]) > ?File "./Shell.py", line 24, in Shell > ? ?exec (request) > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > name into the code object that I want to execute? input() already does that. Note how you're getting back a *function object*. Just call the function (i.e. request() ). The exec statement takes a *string* of code to execute, not a function object, hence the error you're getting. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Mon Jun 29 18:08:15 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:08:15 +0100 Subject: python library call equivalent to `which' command In-Reply-To: References: <236fdf71-ecf0-4060-9b96-763604658a11@f30g2000vbf.googlegroups.com> Message-ID: <4A493B4F.2070102@mrabarnett.plus.com> Tim Pinkawa wrote: > On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes wrote: >> "if file in os.list()" is slow and not correct. You have to check if the >> file is either a real file or a symlink to a file and not a directory or >> special. Then you have to verify that the file has the executable bit, too. > > I realize four lines of Python does not replicate the functionality of > which exactly. It was intended to give the original poster something > to start with. > > I am curious about it being slow, though. Is there a faster way to get > the contents of a directory than os.listdir() or is there a faster way > to see if an element is in a list other than "x in y"? I believe > 'which' will terminate once it finds any match, which mine does not, > but that can be fixed by adding a break after the print. Have a look at os.path.isfile(), os.path.isdir() and os.path.islink(). From clp2 at rebertia.com Mon Jun 29 18:08:35 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 15:08:35 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <50697b2c0906291508w36f25ed0t8a2a38e8d5c8d74@mail.gmail.com> On Mon, Jun 29, 2009 at 2:51 PM, Jun wrote: > HEllo, > > I've a pdf file, and i want to draw some additional stuff on it, by > example : some markup .... notation. Anyone has idea how to do that ? > thank you in advance. ReportLab (http://www.reportlab.org/) can do PDF generation, although it sounds like the for-pay, proprietary "PageCatcher" add-on library might be needed to read from existing PDFs. Cheers, Chris -- http://blog.rebertia.com From emile at fenx.com Mon Jun 29 18:09:23 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 29 Jun 2009 15:09:23 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: On 6/29/2009 2:51 PM Jun said... > HEllo, > > I've a pdf file, and i want to draw some additional stuff on it, by > example : some markup .... notation. Anyone has idea how to do that ? > thank you in advance. ISTM that reportlab's commercial offering does that. http://www.reportlab.com/sectors/developers/ Emile From junhufr at gmail.com Mon Jun 29 18:14:10 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 15:14:10 -0700 (PDT) Subject: Drawing in PDF References: Message-ID: On Jun 30, 12:09?am, Emile van Sebille wrote: > On 6/29/2009 2:51 PM Jun said... > > > HEllo, > > > I've a pdf file, and i want to draw some additional stuff on it, by > > example : some markup .... notation. Anyone has idea how to do that ? > > thank you in advance. > > ISTM that reportlab's commercial offering does that. > > http://www.reportlab.com/sectors/developers/ > > Emile Thanks a lot, is there open source solution ? From python at mrabarnett.plus.com Mon Jun 29 18:18:30 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:18:30 +0100 Subject: Using Python for file packing In-Reply-To: References: Message-ID: <4A493DB6.6050005@mrabarnett.plus.com> Scott David Daniels wrote: > Aaron Scott wrote: >>> Do you mean like a zip or tar file? >>> >>> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >>> >>> >> >> I had no idea you could access a single file from a ZIP or TAR without >> explicitly extracting it somewhere. Thanks. > You will find the zip format works better if you are compressing. The > zipfile compression is per file in the archive, rather than applied to > the entire archive (as in tarfile). The results of the tar format > decision is that extracting the last file in a .tgz (.tar.gz) or > .tar.bz2 (sometimes called .tbz) requires the expansion of the entire > archive, while extraction on a .zip is reposition, read, and possibly > expand. > If the audio is already compressed then a zipfile probably won't be able to compress it any more. From python at mrabarnett.plus.com Mon Jun 29 18:22:23 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:22:23 +0100 Subject: using input(), raw_input() to allow user to run different functions In-Reply-To: References: Message-ID: <4A493E9F.2080606@mrabarnett.plus.com> rhvonlehe at gmail.com wrote: > Something's been giving me difficulty.. > > We have a USB-attached device that we frequently debug with simple > python scripts. The model has always been that each script logs on to > the device, does something, then logs off. As it turns out, we have > mostly written scripts as unit tests for each API command. So, we'll > call one script that will configure a process on the device, and a > separate script that will retrieve the results of that process. > > The model is changing inside the device such that all settings will be > lost when we log off. This means we'll have to merge a bunch of > scripts in various ways. > > I thought it would be neat if I could have one master python script do > the logon, then allow the user to input the name of a previously- > written script he wanted to execute while logged on. Finally, when > exiting the master script, the user would logout from the device. > > I'm trying to test this by using input() or raw_input() to get the > function the user wants to execute. I'm not having much luck. Here's > an example: > > > > Shell.py: > #! /usr/bin/env python > from CollectNDResults import * > ... > request = input('Script shell >>> ') > print request > exec (request) ## I realize the parentheses are not needed > ... > > > When I run Shell.py I get this: > > Script shell >>> CollectNDResults > > Traceback (most recent call last): > File "./Shell.py", line 35, in ? > Shell(sys.argv[1:]) > File "./Shell.py", line 24, in Shell > exec (request) > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > name into the code object that I want to execute? Is there a better > way to do what I'm trying to do? > >>> def foo(): print "running foo" >>> import sys >>> func_name = "foo" >>> getattr(sys.modules[__name__], func_name)() running foo From emile at fenx.com Mon Jun 29 18:22:48 2009 From: emile at fenx.com (Emile van Sebille) Date: Mon, 29 Jun 2009 15:22:48 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: On 6/29/2009 3:14 PM Jun said... > On Jun 30, 12:09 am, Emile van Sebille wrote: >> On 6/29/2009 2:51 PM Jun said... >> >>> HEllo, >>> I've a pdf file, and i want to draw some additional stuff on it, by >>> example : some markup .... notation. Anyone has idea how to do that ? >>> thank you in advance. >> ISTM that reportlab's commercial offering does that. >> >> http://www.reportlab.com/sectors/developers/ >> >> Emile > > Thanks a lot, is there open source solution ? Not that I'm aware of. If you have the appropriate source data you could create the complete document using the open source ReportLab. There are also tools available for combining PDFs. But if you want to insert into the middle of an existing PDF let us know if you find an open source answer. Emile From python at mrabarnett.plus.com Mon Jun 29 18:32:26 2009 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2009 23:32:26 +0100 Subject: timer In-Reply-To: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> Message-ID: <4A4940FA.9010206@mrabarnett.plus.com> superpollo wrote: > hi folks. > > the follwing shoud print 'stuff' for 3 seconds and then stop. why it > does not work? (prints stuff forever) > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 import sys > 5 > 6 t = threading.Timer(3.0, sys.exit) > 7 t.start() > 8 while True: > 9 print "stuff ", > The Timer runs the function in another thread. Perhaps sys.exit is just exiting that thread and not the main thread. From p.f.moore at gmail.com Mon Jun 29 18:38:01 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 29 Jun 2009 23:38:01 +0100 Subject: timer In-Reply-To: <4A4940FA.9010206@mrabarnett.plus.com> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <79990c6b0906291538j56d417eaxcc62bcc504dd28f4@mail.gmail.com> 2009/6/29 MRAB : > superpollo wrote: >> >> hi folks. >> >> the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >> not work? (prints stuff forever) >> >> ? ? ?1 #!/usr/bin/python >> ? ? ?2 >> ? ? ?3 import threading >> ? ? ?4 import sys >> ? ? ?5 >> ? ? ?6 t = threading.Timer(3.0, sys.exit) >> ? ? ?7 t.start() >> ? ? ?8 while True: >> ? ? ?9 ? ? print "stuff ", >> > The Timer runs the function in another thread. Perhaps sys.exit is just > exiting that thread and not the main thread. sys.exit raises a SystemExit exception, which will get handled in the new thread (where it won't do anything). Conceded, this isn't particularly intuitive. For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. Paul. From junhufr at gmail.com Mon Jun 29 18:57:54 2009 From: junhufr at gmail.com (Jun) Date: Mon, 29 Jun 2009 15:57:54 -0700 (PDT) Subject: Drawing in PDF References: Message-ID: <7b874bde-c7b6-4569-9646-a2dfe355e78f@b14g2000yqd.googlegroups.com> On Jun 30, 12:22?am, Emile van Sebille wrote: > On 6/29/2009 3:14 PM Jun said... > > > On Jun 30, 12:09 am, Emile van Sebille wrote: > >> On 6/29/2009 2:51 PM Jun said... > > >>> HEllo, > >>> I've a pdf file, and i want to draw some additional stuff on it, by > >>> example : some markup .... notation. Anyone has idea how to do that ? > >>> thank you in advance. > >> ISTM that reportlab's commercial offering does that. > > >>http://www.reportlab.com/sectors/developers/ > > >> Emile > > > Thanks a lot, is there open source solution ? > > Not that I'm aware of. ?If you have the appropriate source data you > could create the complete document using the open source ReportLab. > There are also tools available for combining PDFs. ?But if you want to > insert into the middle of an existing PDF let us know if you find an > open source answer. > > Emile I checked out whyteboard project (http://code.google.com/p/ whyteboard/) which intends to use cairo (Drawing) and Python Poppler (load PDF). From magicus23 at gmail.com Mon Jun 29 19:12:35 2009 From: magicus23 at gmail.com (magicus) Date: Mon, 29 Jun 2009 19:12:35 -0400 Subject: Python Imaging Library download link broken? In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On Mon Jun 29 2009 07:21:12 GMT-0400 (EDT) Lawrence D'Oliveiro typed: > In message , Tim Harig wrote: > >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >> >>> "apt-get install python-imaging", anybody? >> C:\>apt-get install python-imaging >> Bad command or file name > > Sounds more like broken OS with no integrated package management. > :-P It works here in the sense that it reports that there is nothing to do as it is already installed. ciao, f -- "Hell, if you understood everything I say, you'd be me." -- Miles Davis From rhodri at wildebst.demon.co.uk Mon Jun 29 19:18:17 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 00:18:17 +0100 Subject: pep 8 constants In-Reply-To: <4A4915C7.5050204@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> Message-ID: On Mon, 29 Jun 2009 20:28:07 +0100, Eric S. Johansson wrote: > Rhodri James wrote: >> As far as I can tell, the only thing that you are even vaguely >> suggesting >> for convention use is underscores_with_everything. As promised, I laugh >> hollowly. > > I'm sorry. It may have been too subtle. I'm suggesting a smart editor > that can > tell me anything about any name in the body of code I'm working or > anything I've > included. with that kind of tool, I can have a command grammar that is > much > friendlier to the voice and gets work done faster than typing.things > such as: > > what is this name? > it's a class. > What are its methods? > tree > branch > root > > root template plea > se > .root(howmany=1, branches=3, nodes={}) > > and the query can go from there. > > Using tools like these, one can keep pep-8 conventions and not create a > discriminatory environment. Could you elucidate a bit? I'm not seeing how you're intending to keep PEP-8 conventions in this, and I'm not entirely convinced that without them the smart editor approach doesn't in fact reduce your productivity. -- Rhodri James *-* Wildebeest Herder to the Masses From backup95 at netcabo.pt Mon Jun 29 19:27:33 2009 From: backup95 at netcabo.pt (=?ISO-8859-1?Q?Jo=E3o_Valverde?=) Date: Tue, 30 Jun 2009 00:27:33 +0100 Subject: No trees in the stdlib? In-Reply-To: References: <006078f0$0$9721$c3e8da3@news.astraweb.com> Message-ID: <4A494DE5.9070805@netcabo.pt> alex23 wrote: > Jo?o Valverde wrote: > >> Currently I don't have a strong need for this. >> > > And clearly neither has anyone else, hence the absence from the > stdlib. As others have pointed out, there are alternative approaches, > and plenty of recipes on ActiveState, which seem to have scratched > whatever itch there is for the data structure you're advocating. > > I can't resist quoting Sedgewick here. Then I'll shut up about it. [quote=http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf] Abstract The red-black tree model for implementing balanced search trees, introduced by Guibas and Sedge- wick thirty years ago, is now found throughout our computational infrastructure. Red-black trees are described in standard textbooks and are the underlying data structure for symbol-table imple- mentations within C++, Java, Python, BSD Unix, and many other modern systems. [/quote] You'd think so, but no. You should correct him that in Python a balanced search tree is the useless cross between a dict and a database. From superprad at gmail.com Mon Jun 29 19:47:27 2009 From: superprad at gmail.com (PK) Date: Mon, 29 Jun 2009 19:47:27 -0400 Subject: identify checksum type? Message-ID: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Given a checksum value, whats the best way to find out what type it is? meaning. I can use hashlib module and compute a md5 or sha1 for a given data etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats the best way for me to identify if its a sha1 or md5 or anyother sum type for that matter? is there a nice way to do this in python? ~ PK -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Jun 29 19:54:16 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 30 Jun 2009 01:54:16 +0200 Subject: identify checksum type? In-Reply-To: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Message-ID: PK schrieb: > Given a checksum value, whats the best way to find out what type it is? > > meaning. I can use hashlib module and compute a md5 or sha1 for a given data > etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats > the best way for me to identify if its a sha1 or md5 or anyother sum type > for that matter? > > is there a nice way to do this in python? As far as I know there is no way to identify a checksum by its value. A checksum is just a number. You can try an educated guess based on the length of the checksum. Or you can try all hash algorithms until you get a hit but that may lead to security issues. Some applications prefix the hash value with an identifier like "{MD5}" or "{SHA1}". Christian From steve at REMOVE-THIS-cybersource.com.au Mon Jun 29 20:11:02 2009 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 00:11:02 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> Message-ID: <025949cb$0$20671$c3e8da3@news.astraweb.com> On Mon, 29 Jun 2009 11:49:04 -0400, Eric S. Johansson wrote: > alex23 wrote: >> "Eric S. Johansson" wrote: >>> no, I know the value if convention when editors can't tell you >>> anything about the name in question. I would like to see more support >>> for disabled programmers like myself and the thousands of programmers >>> injured every year and forced to leave the field. seriously, there is >>> no money in disability access especially for programmers. >> >> Well, if we can't use conventions like uppercasing, camelcasing and >> underscoring, what are you recommending we do instead? > > help build a smart editing environment please. Why do you think a smart editing environment is in opposition to coding conventions? Surely an editor smart enough to know a variable name spoken as "pear tree" is an instance and therefore spelled as pear_tree (to use your own example) would be smart enough to know a variable name spoken as "red" is a constant and therefore spelled "RED"? Sounds to me that your speech environment needs a command to turn capslock on and off, and your problem with PEP 8 is solved: x equals caps on red caps off plus three > Heck, have you ever noticed how most Python smart editors can't even > indent properly according to local contexts. Emacs is the only one and > even that one sometimes fails I use kwrite for editing, and I can't say I've ever noticed a failure. > I've lived this works and probably have put more deep thought and 8kloc > into it because I do not accept circures tricks as a way of life. I > want it to work right and I know how to do it. I just don't have the > hands and hte money to pay me to do it. You're using a speech interface, right? You've written about "putting a gun to your wrists", said you can't follow PEP 8 because it's not voice safe, and generally given the impression that you can't use a keyboard. So... just how do you get "hte" from saying "the"? If you are using a keyboard to type this post, then surely it's not such a huge imposition to type a couple of words in all caps here and there while you speak the rest of the code? x equals R E D plus three I know that doesn't resolve the issue for those people who truly can't use a keyboard at all, even for a single character, but it's unfair to insist that the only permitted coding conventions are the ones suitable for the tiny minority who, frankly, are going to have problems no matter what coding conventions we have. Especially when these coding conventions are entirely optional. -- Steven From davidh at ilm.com Mon Jun 29 21:01:29 2009 From: davidh at ilm.com (David Hirschfield) Date: Mon, 29 Jun 2009 18:01:29 -0700 Subject: Determining if a function is a method of a class within a decorator Message-ID: <4A4963E9.30202@ilm.com> I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able to do some things a little differently depending on whether I'm swapping two functions, or two methods of a class. Trouble is, it appears that when the decorator is called the function is not yet bound to an instance, so no matter whether it's a method or function, it looks the same to the decorator. This simple example illustrates the problem: import inspect class swapWith(object): def __init__(self, replacement): self.replacement = replacement def __call__(self, thingToReplace): def _replacer(*args, **kws): import inspect print "replacing:",self.replacement,inspect.ismethod(self.replacement) return self.replacement(*args, **kws) return _replacer class MyClass(object): def swapIn(self): print "this method will be swapped in" @swapWith(swapIn) def swapOut(self): print "this method will be swapped out" c = MyClass() c.swapOut() def swapInFn(): print "this function will be swapped in" @swapWith(swapInFn) def swapOutFn(): print "this function will be swapped out" swapOutFn() Both MyClass.swapIn and swapInFn look like the same thing to the decorator, and MyClass.swapOut and swapOutFn look the same. So is there a pattern I can follow that will allow me to determine whether the objects I'm given are plain functions or belong to a class? Thanks in advance, -David -- Presenting: mediocre nebula. From tjreedy at udel.edu Mon Jun 29 21:31:45 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 29 Jun 2009 21:31:45 -0400 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: <4A4963E9.30202@ilm.com> References: <4A4963E9.30202@ilm.com> Message-ID: David Hirschfield wrote: > I'm having a little problem with some python metaprogramming. I want to > have a decorator which I can use either with functions or methods of > classes, which will allow me to swap one function or method for another. > It works as I want it to, except that I want to be able to do some > things a little differently depending on whether I'm swapping two > functions, or two methods of a class. Unbounds methods are simply functions which have become attributes of a class. Especially in Py3, there is *no* difference. Bound methods are a special type of partial function. In Python, both are something else, though still callables. Conceptually, a partial function *is* a function, just with fewer parameters. > Trouble is, it appears that when the decorator is called the function is > not yet bound to an instance, so no matter whether it's a method or > function, it looks the same to the decorator. Right. Whether it is an A or an A, it looks like an A. Worse: when the decorator is called, there is no class for there to be instances of. > > This simple example illustrates the problem: Add a second parameter to tell the decorator which variant of behavior you want. Or write two variations of the decorator and use the one you want. tjr From esj at harvee.org Mon Jun 29 21:52:37 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 21:52:37 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> Message-ID: <4A496FE5.9060005@harvee.org> Rhodri James wrote: > > Could you elucidate a bit? I'm not seeing how you're intending to keep > PEP-8 conventions in this, and I'm not entirely convinced that without > them the smart editor approach doesn't in fact reduce your productivity. > thank you for asking for an elaboration. Programming by voice has one goal. enable a disabled person such as myself to create code by voice with a minimum of vocal or hand damage. let's use an example. Admittedly, this is a very simple example but hopefully it illustrates my point What I dictate is: from pots is class telephone What should generate is: class Telephone (pots): as you can see, taken from the simplistic expression, we generate the right pep-8 convention. (I think). This is not the only grammar one can use but, it's one that comes to mind that doesn't have a lot of dead ends. So if I was dictating code, it would look something like: >From pots is new class telephone new constructor first argument last mile = between quotes copper Second argument fiber delivery date = between quotes when hell freezes over" jump to body first argument to self second argument to self new method construction crew . . . Telephone fieldwork = telephone second argument fiber delivery date = between quotes hell froze over recycled coffee = telephone fieldwork construction crew ----------------- This is the rough example of what I think should be spoken and what can be translated to code. What isn't shown is disambiguation techniques. For example, when a name is said, if it is not unique to the context, then a small pop-up shows the ambiguities and lets the user choose. Yes your focus shifts rapidly but you're in the groove of writing code and it's just making your choices explicit. For example, if telephone wasn't unique because we had telephone pole and telephone truck as classes elsewhere in the namespace, you would see a pop-up with each name with a number next to it. You could either click on the item or say a digit to reinforce the choice. If the class had more methods, when I say "telephone fieldwork" that gets translated into knowledge of what class it's an instance of and all the choices are displayed but at the same time, the natural language form are shoved into the grammar so you can continue speaking. If you speak quickly enough, you will see no choice but the grammar will still be loaded up so that you will get the right thing. at each stage of the way, names get transformed into the pep-8 form without me having to say anything special. The environment knows what form it wants and does the transformation automatically. I'm surprised people aren't doing this already for their handcrafted code. It's one less bit of detail you need to pay attention to. From davidh at ilm.com Mon Jun 29 22:01:01 2009 From: davidh at ilm.com (David Hirschfield) Date: Mon, 29 Jun 2009 19:01:01 -0700 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: References: <4A4963E9.30202@ilm.com> Message-ID: <4A4971DD.9080707@ilm.com> Yeah, it definitely seems like having two separate decorators is the solution. But the strange thing is that I found this snippet after some deep googling, that seems to do something *like* what I want, though I don't understand the descriptor stuff nearly well enough to get what's happening: http://stackoverflow.com/questions/306130/python-decorator-makes-function-forget-that-it-belongs-to-a-class answer number 3, by ianb. It seems to indicate there's a way to introspect and determine the class that the function is going to be bound to...but I don't get it, and I'm not sure it's applicable to my case. I'd love an explanation of what is going on in that setup, and if it isn't usable for my situation, why not? Thanks again, -David Terry Reedy wrote: > David Hirschfield wrote: >> I'm having a little problem with some python metaprogramming. I want >> to have a decorator which I can use either with functions or methods >> of classes, which will allow me to swap one function or method for >> another. It works as I want it to, except that I want to be able to >> do some things a little differently depending on whether I'm swapping >> two functions, or two methods of a class. > > Unbounds methods are simply functions which have become attributes of > a class. Especially in Py3, there is *no* difference. > > Bound methods are a special type of partial function. In Python, both > are something else, though still callables. Conceptually, a partial > function *is* a function, just with fewer parameters. > >> Trouble is, it appears that when the decorator is called the function >> is not yet bound to an instance, so no matter whether it's a method >> or function, it looks the same to the decorator. > > Right. Whether it is an A or an A, it looks like an A. > > Worse: when the decorator is called, there is no class for there to be > instances of. >> >> This simple example illustrates the problem: > > Add a second parameter to tell the decorator which variant of behavior > you want. Or write two variations of the decorator and use the one you > want. > > tjr > -- Presenting: mediocre nebula. From ldo at geek-central.gen.new_zealand Mon Jun 29 22:05:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 14:05:26 +1200 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: In message , Gabriel Genellina wrote: > The fact that it's the same character used for formatting strings with the > % operator is an unfortunate coincidence (or a very bad choice, I don't > know). That's not the problem. The problem is that MySQLdb IS indeed using Python format substitution to do its argument substitution. Python expects the value for "%d" to be an integer. But MySQLdb has already converted all the argument values to strings. Hence the error. If MySQLdb were doing its own parsing of the format string, it could produce a more meaningful error message when it sees "%d" (e.g. "only %s substitutions allowed"). From alitosis at gmail.com Mon Jun 29 22:12:12 2009 From: alitosis at gmail.com (alito) Date: Mon, 29 Jun 2009 19:12:12 -0700 (PDT) Subject: generator expression works in shell, NameError in script References: <945bc25c-559b-48e7-ae22-28b2ead27b14@c19g2000prh.googlegroups.com> <50697b2c0906171538s7c2eaec3ne41a4522bd4aca90@mail.gmail.com> <89d9a2c0-fb96-4494-9b18-597d3993ac10@y6g2000prf.googlegroups.com> <50697b2c0906171611q7906229fj8ab9c1981ee63789@mail.gmail.com> <8353a457-e7cb-4466-bbcb-58779abca7f0@o14g2000vbo.googlegroups.com> <8da76c16-2891-48ed-a1ae-4b4a555771ca@t11g2000vbc.googlegroups.com> Message-ID: On Jun 18, 11:56?pm, nn wrote: > On Jun 18, 8:38?am, guthrie wrote: > > > > > On Jun 17, 6:38?pm, Steven Samuel Cole > > wrote: > > > > Still don't really understand why my initial code didn't work, though... > > > Your code certainly looks reasonable, and looks to me like it "should" > > work. The comment of partial namespace is interesting, but > > unconvincing (to me) - but I am not a Python expert! It would > > certainly seem that within that code block it is in the local > > namespace, not removed from that scope to be in another. > > > Seems that it should either be a bug, or else is a design error in the > > language! > > > Just as in the above noted "WTF" - non-intuitive language constructs > > that surprise users are poor design. > > This is certainly an odd one. This code works fine under 2.6 but fails > in Python 3.1. > > >>> class x: > > ... ? ? lst=[2] > ... ? ? gen=[lst.index(e) for e in lst] > ... > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 3, in x > ? File "", line 3, in > NameError: global name 'lst' is not defined > Arghh. I see thousands of future wtf!? posts to c.l.p. triggered by this new feature. Might as well save some time and add it to the FAQ already. From lehchao at gmail.com Mon Jun 29 22:13:06 2009 From: lehchao at gmail.com (kio) Date: Mon, 29 Jun 2009 19:13:06 -0700 (PDT) Subject: why PyObject_VAR_HEAD? Message-ID: Hi, I'm studying the CPython source code. I don?t quite understand why they?re using PyObject_VAR_HEAD to define struct like PyListObject. To define such kind of struct, could I use _PyObject_HEAD_EXTRA as a header and add "items" pointer and "allocated" count explicity? Is there any difference? Thanks. Eric From bob at vitamindinc.com Mon Jun 29 22:21:07 2009 From: bob at vitamindinc.com (Bob Petersen) Date: Mon, 29 Jun 2009 19:21:07 -0700 Subject: Creating multiprocessing processes without forking on MacOSX? Message-ID: <9d4bd1f40906291921k57d11164t7bb1045080b86678@mail.gmail.com> All, I am using the multiprocessing backport with Python 2.5.4 on a cross-platform Mac/Windows app. Things were going swimmingly until I tried to load a library on the Mac that calls CoreFoundation system calls. I discovered that certain (many?) OSX system calls fail when called from a forked process. See http://developer.apple.com/technotes/tn2005/tn2083.html#SECDAEMONVSFRAMEWORKSand http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html(search for "fork"). Unfortunately, we are already using multprocessing (and its Queues and Pipes) and have a lot of time invested in it. The three options I see are (1) replace multiprocessing with subrocess calls, (2) wrap the library that makes the MacOSX calls in a separate "server" process, or (3) modify the multiprocessing module to, on the Mac, be able to create "non-forked" processes (using subprocess, or fork() then exec*(), or similar). My question is, how realistic is #3? On the Windows side multiprocessing is not using fork(), so it seems like the library may already support this. If this is not completely crazy, I'd be interested in suggestions on what would have to change. I'm happy to provide a patch if it is useful to others. Thanks, Bob Petersen -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Jun 29 22:25:24 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 02:25:24 GMT Subject: Determining if a function is a method of a class within a decorator References: Message-ID: On Mon, 29 Jun 2009 18:01:29 -0700, David Hirschfield wrote: > I'm having a little problem with some python metaprogramming. I want to > have a decorator which I can use either with functions or methods of > classes, which will allow me to swap one function or method for another. > It works as I want it to, except that I want to be able to do some > things a little differently depending on whether I'm swapping two > functions, or two methods of a class. > > Trouble is, it appears that when the decorator is called the function is > not yet bound to an instance, so no matter whether it's a method or > function, it looks the same to the decorator. Then: * use a naming convention to recognise methods (e.g. check if the first argument is called "self" by looking at function.func_code.co_varnames); * use two different decorators, or a decorator that takes an extra "method or function argument"; * play around with the class metaclass and see if you can do something special (and probably fragile); * do the replacements after the class is created without decorator syntax, e.g.: Class.method1 = swapWith(Class.method2)(Class.method1) > This simple example illustrates the problem: [snip] No it doesn't. It appears to work perfectly, from what I can guess you're trying to accomplish. Have you considered a possibly simpler way of swapping methods/functions? >>> def parrot(): ... print "It's pining for the fjords." ... >>> def cheeseshop(): ... print "We don't stock Cheddar." ... >>> parrot, cheeseshop = cheeseshop, parrot >>> >>> parrot() We don't stock Cheddar. >>> cheeseshop() It's pining for the fjords. Admittedly, this doesn't let you do extra processing before calling the swapped functions, but perhaps it will do for what you need. -- Steven From benjamin at python.org Mon Jun 29 22:30:18 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 30 Jun 2009 02:30:18 +0000 (UTC) Subject: why =?utf-8?b?UHlPYmplY3RfVkFSX0hFQUQ/?= References: Message-ID: kio gmail.com> writes: > > Hi, > > I'm studying the CPython source code. I don?t quite understand why > they?re using PyObject_VAR_HEAD to define struct like PyListObject. To > define such kind of struct, could I use _PyObject_HEAD_EXTRA as a > header and add "items" pointer and "allocated" count explicity? Is > there any difference? No, PyObject_VAR_HEAD adds a ob_size field, which is used to indicate the size of the list. PyList uses this just as a convenience; it does not actually use varsize mallocing. You could use PyObject_HEAD if you added an additional size field. From esj at harvee.org Mon Jun 29 22:37:15 2009 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 29 Jun 2009 22:37:15 -0400 Subject: pep 8 constants In-Reply-To: <025949cb$0$20671$c3e8da3@news.astraweb.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> Message-ID: <4A497A5B.4040503@harvee.org> Steven D'Aprano wrote: > Why do you think a smart editing environment is in opposition to coding > conventions? Surely an editor smart enough to know a variable name spoken > as "pear tree" is an instance and therefore spelled as pear_tree (to use > your own example) would be smart enough to know a variable name spoken as > "red" is a constant and therefore spelled "RED"? no. I think a smart editing environment should support a coding convention. If an editor is smart enough to track type and instance information, yes. It should be able to generate the right strings for symbols. The question is, how do we get such a smart editor. as far as I know, none exist and the smart ones so far seem to be oriented towards hand use and are almost inaccessible to speech. > > Sounds to me that your speech environment needs a command to turn > capslock on and off, and your problem with PEP 8 is solved: you haven't used recognition, have you? > > x equals caps on red caps off plus three it also means "red" is a single utterance. "RED" is three utterances. You've just tripled vocal load for single word which means vat you just cut my ability to work by two thirds. My voice is not as robust as my hands used to be. It's a coarse tools not designed for engraving fine detail but instead painting broadbrush strokes. for more you expect a person to say, the less time they can spend on work effort. This is why I'm advocating a very smart at her with very high level grammar structure using visual disambiguation techniques. >> Heck, have you ever noticed how most Python smart editors can't even >> indent properly according to local contexts. Emacs is the only one and >> even that one sometimes fails > > I use kwrite for editing, and I can't say I've ever noticed a failure. okay, it fails from a speech recognition user perspective. Put the cursor on the line and hit the tab key. Insert spaces/tabs in the line of text. Not good for speech recognition. If mess of indentation and hit the tab key, it doesn't automatically indent to the right location. I'll be damned if I'm in the sit there speaking "tabkeytabkeytabkeytabkeytabkey" because the error should take care of it for me and save my voice. Like I said, Emacs does it correctly and nobody else does as far as I can tell. >> I've lived this works and probably have put more deep thought and 8kloc >> into it because I do not accept circures tricks as a way of life. I >> want it to work right and I know how to do it. I just don't have the >> hands and hte money to pay me to do it. > > You're using a speech interface, right? You've written about "putting a > gun to your wrists", said you can't follow PEP 8 because it's not voice > safe, and generally given the impression that you can't use a keyboard. > > So... just how do you get "hte" from saying "the"? joys of speech recognition. it was probably either due to a persistent misrecognition that didn't have the right word and the correction dialog or, I found the speech recognition error and could not corrected by voice. and note, there are two errors above that lie would have had to correct by hand. > If you are using a keyboard to type this post, then surely it's not such > a huge imposition to type a couple of words in all caps here and there > while you speak the rest of the code? if I had typed this post, there would be two orders of magnitude more errors because of intentional tremors and reduction of targeting accuracy. to give you Monday an example. Sometimes my hands shake so badly, I cannot eat soup or even Chile. I'm unable to use an iPhone except with a great deal of effort. am the iPhone with a user with tremors, you activate more than one key about a third of the time. > x equals R E D plus > three I only have about 1000 keystrokes equivalents today in my hands. Where am I going to use them? Try adding (driving), preparing food, personal hygiene, or typing PEP-8 compliant code? What I usually do is I do something like constant_read = RED at the beginning of my code and well I think you know I'm getting at. I generate something only I can read which does nobody any good. > I know that doesn't resolve the issue for those people who truly can't > use a keyboard at all, even for a single character, but it's unfair to > insist that the only permitted coding conventions are the ones suitable > for the tiny minority who, frankly, are going to have problems no matter > what coding conventions we have. You're looking at it from the classical anti-accommodation perspective. Don't change the convention, give us the tools so we can comply with what the rest of you do. It's like instead of putting a cut out every street corner, every powered scooter/wheelchair comes with a antigravity boost that will lift them over the curbstone. Accessibility belongs with the individual through tools that take the standard and change it to their needs. While we don't have anti-gravitational devices, we can make smart matters and that would solve a lot more problems than just the simple compliance with PEP-8 > > Especially when these coding conventions are entirely optional. these conventions are religion for some special if you want to contribute code. But look at the bigger issue. If your brother, or best friend was disabled and couldn't make a living programming anymore, which you or which are not feel enough compassion/responsibility to try and help them get back on their feet? Assuming your answer was a compassionate one, try and extend that out word to tens of thousands of developers losing their livelihood every year. Do you feel enough compassion and can you get together enough people feel similar levels of compassion to try and build a smart editing environment (all dicksizing about gui kits aside) and make it possible for these people to continue in their desired profession? I know I hit on this point a lot but not are you helping your peers, some people you may even know but you are saving yourself from being forced away from programming at some point in the future whether it be from RSI, arthritis, broken wrist, drop the fee or whatever. As we age, we all lose ability. I wish I had known enough about the future to try and secure a future for myself but I didn't. And so now I play an absolute pain in the ass on the net trying to get people to think about themselves and their fellow programmers. I know I'm obnoxious, I'm sorry but I want something to work for more than just me. I want something that can be reproduce by individuals, rehabilitation facilities, handicap advocacy groups. I don't want anyone to go through what I did trying to rebuild my worklife. It was hell and if I can save somebody from it by being an advocate, I'm going to keep doing it So yeah, it would be swell to have a smart editor. I do believe that with the right groundwork, a smart editor could not only serve the needs of people with speech recognition but also present enough information so that text-to-speech users can hear what they're working with. He may not be able to imagine this but, you don't want to read the display, you want to read the meta-information behind the symbols on the display and that's what a blind programmer would need to hear in order to understand the code. Or at least that's what a few have told me. From http Mon Jun 29 22:40:56 2009 From: http (Paul Rubin) Date: 29 Jun 2009 19:40:56 -0700 Subject: No trees in the stdlib? References: <11eb0a6e-4e21-4a61-bf46-4221fd75dc8d@v15g2000prn.googlegroups.com> <006078f0$0$9721$c3e8da3@news.astraweb.com> <7x3a9mkiv6.fsf@ruckus.brouhaha.com> <7xeit3ae58.fsf@ruckus.brouhaha.com> <7xprcny4th.fsf@ruckus.brouhaha.com> <4A485777.2000301@netcabo.pt> Message-ID: <7xhbxy8mvb.fsf@ruckus.brouhaha.com> Jo?o Valverde writes: > Rereading this I got what you meant by "wrapper with mutating slot". > But that is (like I think you implied) functionally equivalent to a > mutating data structure, with worse performance because of additional > memory allocation and such. Is it faster to rebalance the tree with a > persistent data structure? If you're going to use a self-balancing tree you will have to do some tree rotations even if the tree is mutable. My guess is that it's still O(log n) updates, but with a smaller proportionality constant. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:39:22 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:39:22 +1200 Subject: Drawing in PDF References: Message-ID: In message , Jun wrote: > ... is there open source solution ? Poppler? From ldo at geek-central.gen.new_zealand Mon Jun 29 23:41:42 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:41:42 +1200 Subject: Direct interaction with subprocess - the curse of blocking I/O References: Message-ID: In message , Pascal Chambon wrote: > I met the issue : select() works only on windows ... No it doesn't. It works only on sockets on Windows, on Unix/Linux it works with all file descriptors . From timr at probo.com Mon Jun 29 23:42:22 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 29 Jun 2009 20:42:22 -0700 Subject: tokenize module References: <7fae895c-c21e-4abb-b61c-d960c784bb0f@h28g2000yqd.googlegroups.com> <6r7e45ttem5lbed4n1nv0cpv4asuj3kltu@4ax.com> <40e3eff9-9e5c-4979-91bd-c85988352e91@k15g2000yqc.googlegroups.com> Message-ID: bootkey wrote: > >Thanks for the reply. I wonder why the tokenizer classifies all >operators simply as OP, instead of the various operators listed in the >tok_name dictionary. I imagine it's just an exercise left to the reader. It's not that hard of an extension. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:47:26 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:47:26 +1200 Subject: csv blank fields References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: In message , MRAB wrote: > row = [r or "NULL" for r in row] I know that, in this particular case, all the elements of row are strings, and the only string that is equivalent to False is the empty string, but still row = [[r, "NULL"][r == ""] for r in row] From ldo at geek-central.gen.new_zealand Mon Jun 29 23:48:52 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:48:52 +1200 Subject: Looking for developer to help me References: Message-ID: In message , Daniel Gerzo wrote: > http://bitbucket.org/danger/pysublib/src/ Can't seem to get through to your site. From ldo at geek-central.gen.new_zealand Mon Jun 29 23:55:01 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:55:01 +1200 Subject: Making code run in both source tree and installation path References: Message-ID: In message , Javier Collado wrote: > - distutils trick in setup.py to modify the installed script (i.e. > changing a global variable value) so that it has a reference to the > data files location. This seems to me to be the cleanest solution, at least as a default. > - Heuristic in the package code to detect when it's being executed > from the source tree and when it has been the installed By definition, a "heuristic" can never be fully reliable. > - Just using an environment variable that the user must set according > to his needs This can be useful as a way to override default settings. But requiring it means extra trouble for the user. For configurable settings, best to observe a hierarchy like the following (from highest to lowest priority): * command-line options * environment-variable settings * user prefs in ~/.whatever * system configs in /etc * common data in /usr/share * hard-coded From ldo at geek-central.gen.new_zealand Mon Jun 29 23:58:22 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 15:58:22 +1200 Subject: fork, threads and proper closing References: Message-ID: In message , Francesco Bochicchio wrote: > ... if the thread is waiting for a blocking I/O operation to complete, > like reading from a socket with no data or waiting for a locked resource > (i.e. semaphore) to be unlocked, it will not service the queue and will > not read the 'quit command' (the poison pill), and therefore will not > quit until the blocking I/O terminates (and it could be never). Under Linux systems, threads are little different from processes. In particular, sending a thread/process a signal will cause any blocking I/O operation in progress to abort, either with only some bytes read/written, or if nothing was read/written, with an EINTR error. From clp2 at rebertia.com Tue Jun 30 00:17:17 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 29 Jun 2009 21:17:17 -0700 Subject: csv blank fields In-Reply-To: References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> Message-ID: <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> On Mon, Jun 29, 2009 at 8:47 PM, Lawrence D'Oliveiro wrote: > In message , MRAB > wrote: > >> ? ? ?row = [r or "NULL" for r in row] > > I know that, in this particular case, all the elements of row are strings, > and the only string that is equivalent to False is the empty string, but > still > > ? ?row = [[r, "NULL"][r == ""] for r in row] While I do find the use of booleans as integers interesting, I think the ternary operator would be clearer: row = [("NULL" if r == "" else r) for r in row] Cheers, Chris -- http://blog.rebertia.com From timr at probo.com Tue Jun 30 00:23:57 2009 From: timr at probo.com (Tim Roberts) Date: Mon, 29 Jun 2009 21:23:57 -0700 Subject: Python Imaging Library download link broken? References: Message-ID: peter wrote: > >Just got a new computer and I'm trying to download my favourite >applications. All's well until I get to PIL, and here pythonware and >effbot both return a 502 Proxy error. > >Is this just a temporary glitch, or something more serious? And if >it's the latter, is there any alternative source? Surprisingly, this appears to have been caused by the death of Michael Jackson. The burden of people sending messages, downloading videos, buying albums, etc., has crippled the Internet worldwide. AT&T reported at its peak that there were more than 60,000 text messages PER SECOND being sent regarding Jackson. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From magawake at gmail.com Tue Jun 30 00:47:21 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 30 Jun 2009 00:47:21 -0400 Subject: csv blank fields In-Reply-To: <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> <4A4618E6.7000102@mrabarnett.plus.com> <1cbd6f830906270935q6870664fr50d19dd6b02b7313@mail.gmail.com> <50697b2c0906292117g28de7f52sb35f3c7e7782b60b@mail.gmail.com> Message-ID: <1cbd6f830906292147x6e18b240q9a972e51dd7c6e4d@mail.gmail.com> Thankyou! On Tue, Jun 30, 2009 at 12:17 AM, Chris Rebert wrote: > On Mon, Jun 29, 2009 at 8:47 PM, Lawrence > D'Oliveiro wrote: >> In message , MRAB >> wrote: >> >>> ? ? ?row = [r or "NULL" for r in row] >> >> I know that, in this particular case, all the elements of row are strings, >> and the only string that is equivalent to False is the empty string, but >> still >> >> ? ?row = [[r, "NULL"][r == ""] for r in row] > > While I do find the use of booleans as integers interesting, I think > the ternary operator would be clearer: > > row = [("NULL" if r == "" else r) for r in row] > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > From steven at REMOVE.THIS.cybersource.com.au Tue Jun 30 01:45:17 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 05:45:17 GMT Subject: pep 8 constants References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Jun 2009 22:37:15 -0400, Eric S. Johansson wrote: > Steven D'Aprano wrote: ... >> Sounds to me that your speech environment needs a command to turn >> capslock on and off, and your problem with PEP 8 is solved: > > you haven't used recognition, have you? No. >> x equals caps on red caps off plus three > > it also means "red" is a single utterance. "RED" is three utterances. > You've just tripled vocal load for single word which means vat you just > cut my ability to work by two thirds. That assumes that every word is all caps. In practice, for real-life Python code, I've tripled the vocal load of perhaps one percent of your utterances, which cuts your productivity by 2%. If you have 10000 words in you per day, and one percent get wrapped with a leading and trailing "capslock", you have: 9900 regular words plus 100 constants versus 9700 regular words plus 100 constants plus 200 by capslock. Your productivity goes down by 200 words out of 10,000, or two percent. >>> Heck, have you ever noticed how most Python smart editors can't even >>> indent properly according to local contexts. Emacs is the only one and >>> even that one sometimes fails >> >> I use kwrite for editing, and I can't say I've ever noticed a failure. > > okay, it fails from a speech recognition user perspective. Put the > cursor on the line and hit the tab key. Insert spaces/tabs in the line > of text. Not good for speech recognition. If mess of indentation and > hit the tab key, it doesn't automatically indent to the right location. > I'll be damned if I'm in the sit there speaking > "tabkeytabkeytabkeytabkeytabkey" because the error should take care of > it for me and save my voice. Like I said, Emacs does it correctly and > nobody else does as far as I can tell. I don't understand what you're describing. If you set kwrite to use "Python style" indent mode, then starting a new line will automatically indent to either the current indent level, or one extra indent level if the line ends with a colon. You shouldn't need to indent forward more than one level at a time when writing Python code, although you will need to dedent multiple levels on occasion. > I only have about 1000 keystrokes equivalents today in my hands. Where > am I going to use them? Try adding (driving), preparing food, personal > hygiene, or typing PEP-8 compliant code? Your choice naturally. > You're looking at it from the classical anti-accommodation perspective. > Don't change the convention, give us the tools so we can comply with > what the rest of you do. Just a minute. You're the one who started this discussion rejecting the convention. Your first post started off: "I reject this convention..." and then finished with "so I reject pep 8 because I have no voice safe alternative" Do you blame us for reading this as a protest against uppercase identifiers? Now you're saying you're happy for us to keep the all-uppercase convention and just want better tools. Okay, you want better tools. Great. If you're attempting to raise the profile of disabled programmers, you've done so, but what exactly are you expecting? I've already said it's your right to reject the convention for your own code. Go right ahead. This is only a problem if you're editing other people's code which is using uppercase constants. You've rejected capslock red capslock because it takes three utterances, but said you use constant_red instead. That's two utterances, saving you only one. If you actually have to say the underscore, your convention takes six syllables versus five for my idea. >> Especially when these coding conventions are entirely optional. > > these conventions are religion for some special if you want to > contribute code. Does your editor have search and replace? Before you contribute code, do a global replacement of constant_red for RED. > But look at the bigger issue. Yes, we get it. It sucks to have a physical disability. The universe isn't arranged to make it easy for those who do, and even systems built by people are only indifferently suitable. So, let's get down to practical matters: Do you wish to register a protest against all-caps constants in PEP 8? Do you wish to ask the Python Dev team to rethink their decision? Do you wish to raise the profile of disabled programmers? Do you wish to start a project developing a better, smarter editor, and are looking for volunteers? -- Steven From http Tue Jun 30 02:54:01 2009 From: http (Paul Rubin) Date: 29 Jun 2009 23:54:01 -0700 Subject: Good books in computer science? References: <75a87527-b45e-458e-9b45-6f54e1b5783c@c20g2000prh.googlegroups.com> <0244e76b$0$20638$c3e8da3@news.astraweb.com> <429c12c9-f462-4649-923d-cc9a5cd6ad13@i6g2000yqj.googlegroups.com> <8f093893-310a-4f0f-9e67-61393c234299@f38g2000pra.googlegroups.com> Message-ID: <7xk52u2ovq.fsf@ruckus.brouhaha.com> I just came across this, a rather advanced algorithms book but my favorite kind: the text (in draft form, anyway) is free online. http://www.cs.princeton.edu/theory/complexity/ From saxi at nm.ru Tue Jun 30 02:54:33 2009 From: saxi at nm.ru (saxi) Date: Mon, 29 Jun 2009 23:54:33 -0700 (PDT) Subject: Error in Pango while using cairo/librsvg References: <4a363441$0$30238$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7d765488-3330-4a9d-904f-67f29dde59dd@h2g2000yqg.googlegroups.com> I use pyWxSVG to convert a svg file to a png image. pyWxSVG is svg canvas for wxPython. View and print svg file or svg content, convert svg to raster graphics. Open svg, svgz file as wx.Image, use wx.BITMAP_TYPE_SVG, wx.BITMAP_TYPE_SVGZ type. Partial support svg format. Tested with Python 2.5 and wxPython 2.8.9.2. Path parser and elliptical arc approximation from Enable. From phil at riverbankcomputing.com Tue Jun 30 03:00:43 2009 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 30 Jun 2009 08:00:43 +0100 Subject: What does Guido want in a GUI toolkit for Python? In-Reply-To: References: <2aa5f902-8d92-464a-b86d-4568b6121890@g1g2000yqh.googlegroups.com> <4a4689bf$0$14790$9b622d9e@news.freenet.de> <4A4894F4.7040606@cox.net> Message-ID: <6b03a4a46a2b070694248e216750c6d4@localhost> On Mon, 29 Jun 2009 16:47:58 -0400, Terry Reedy wrote: > The replacement would need to work with Py 3. TK does. I have not > noticed that anything else does, though that should change eventually. > (And I am sure someone will point of something I have not noticed.) PyQt does. Phil From nurazije at gmail.com Tue Jun 30 03:19:26 2009 From: nurazije at gmail.com (NurAzije) Date: Tue, 30 Jun 2009 00:19:26 -0700 (PDT) Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> Message-ID: <0bc58d9a-37cf-4e09-a28f-5edb0489ea30@h8g2000yqm.googlegroups.com> On Jun 29, 11:04?am, Tim Harig wrote: > On 2009-06-29, NurAzije wrote: > > > Hi, > > I am working on a study and I need expert opinion, I did not work with > > Python before, can anyone help me with a comparison betweenWhizBase > > (www.whizbase.com) and Python please. > > Given posts like:http://groups.google.com/group/Server-side-programing/browse_thread/t... > is this just thinly veiled spam? ?The domain and the posting IP address are > both out of Sarajevo, Bosnia. > > Obviously you alreadly know your product is nothing but a database > macro processor. ?Python is a dynamic programming language and therefore > far more capable. > > Your product is proprietary with less capability while Python is free and > powerful. Hi Tim, I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, for that it is interesting for me. regards, Ashraf Gheith From danger at rulez.sk Tue Jun 30 04:10:03 2009 From: danger at rulez.sk (Daniel Gerzo) Date: Tue, 30 Jun 2009 10:10:03 +0200 Subject: Looking for developer to help me In-Reply-To: References: Message-ID: <518b3e7bb9a4c28ae524f572d163df62@services.rulez.sk> Dear Lawrence, On Tue, 30 Jun 2009 15:48:52 +1200, Lawrence D'Oliveiro wrote: > In message , Daniel > Gerzo wrote: > >> http://bitbucket.org/danger/pysublib/src/ > > Can't seem to get through to your site. BitBucket isn't actually my site, it's a Mercurial hosting provider. I wonder why it doesn't work for you...maybe some routing problem, I advice you to try a bit later. -- S pozdravom / Best regards Daniel From gagsl-py2 at yahoo.com.ar Tue Jun 30 04:11:41 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 05:11:41 -0300 Subject: problems with mysql db References: <67c97cd90906290632q11342679s72966433b48c0a02@mail.gmail.com> Message-ID: En Tue, 30 Jun 2009 03:33:52 -0300, Dennis Lee Bieber escribi?: > On Mon, 29 Jun 2009 11:59:59 -0300, "Gabriel Genellina" > declaimed the following in > gmane.comp.python.general: > >> The fact that it's the same character used for formatting strings with >> the >> % operator is an unfortunate coincidence (or a very bad choice, I don't >> know). >> > At the core -- if one looks at the Python source of the module and > takes into account that, prior to MySQL 5.x, MySQL did not support > "prepared statements", everything being sent as a full string query -- > MySQLdb actually uses string interpolation to fill in the fields... > AFTER, of course, passing all the arguments through a function that > "safes" them (escaping sensitive characters, converting numerics to > string equivalent, etc., wrapping quotes about them). Thanks for the historical reference. Even then, the code *could* have used other markers, like ?, doing the appropiate substitutions before the final string interpolation... (but critisizing the original design after many years isn't fair!) -- Gabriel Genellina From ldo at geek-central.gen.new_zealand Tue Jun 30 04:16:02 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 30 Jun 2009 20:16:02 +1200 Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: In message , Tim Harig wrote: > On 2009-06-29, Lawrence D'Oliveiro > wrote: >> Sounds more like broken OS with no integrated package management. > > Package managers with dependency tracking were all the rage when I first > started using Linux. So I tried Red Hat and everything worked great until > the depency database corrupted itself. I have been using and administering various flavours of Linux--Red Hat, SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about the last decade, and I have NEVER seen this mythical dependency database corruption of which you speak. If you thought they were "all the rage" before, they're pretty much mandatory now. From usernet at ilthio.net Tue Jun 30 04:28:14 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:28:14 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-30, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> Package managers with dependency tracking were all the rage when I first >> started using Linux. So I tried Red Hat and everything worked great until >> the depency database corrupted itself. > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about > the last decade, and I have NEVER seen this mythical dependency database > corruption of which you speak. Its usually referred to as RPM hell (like DLL hell) although it can happen to DEB packages as well. You end up in a situation with cyclic dependencies where you cannot delete one application because it depends on a second but you cannot remove the second because it depends on the first. What can I say. It happens. It happened to me. > If you thought they were "all the rage" before, they're pretty much > mandatory now. I have been happy for years using my own heavily modified version of Slackware for installing the base system. After that, I install everything from source. Incidently, a similar discussion has started in a subthread of comp.unix.shell. From usernet at ilthio.net Tue Jun 30 04:36:03 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:36:03 GMT Subject: Spam? Re: whizBase vs. Python References: <620ad7d3-6c1a-4869-b844-1951095bb92c@g19g2000yql.googlegroups.com> <0bc58d9a-37cf-4e09-a28f-5edb0489ea30@h8g2000yqm.googlegroups.com> Message-ID: On 2009-06-30, NurAzije wrote: > On Jun 29, 11:04?am, Tim Harig wrote: >> On 2009-06-29, NurAzije wrote: >> > I am working on a study and I need expert opinion, I did not work with >> > Python before, can anyone help me with a comparison betweenWhizBase >> > (www.whizbase.com) and Python please. >> Given posts like:http://groups.google.com/group/Server-side-programing/browse_thread/t... >> is this just thinly veiled spam? ?The domain and the posting IP address are >> both out of Sarajevo, Bosnia. > I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, > for that it is interesting for me. >From your post in Server-side-programming you *do* heavily endorse the product and must therefore know about the product itself. I don't know what I can tell you about Python any more then to mention that it is a genteral purpose programming language. It can be used very effectively for creating websites. It could easily be used to create a program that does what the WhizBase product does; and, it can be used for tasks far outside of creating websites. Perhaps, if you give us a little more specific idea of what you want to know about it, we could be more helpful to you. From gruszczy at gmail.com Tue Jun 30 04:44:39 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Tue, 30 Jun 2009 10:44:39 +0200 Subject: Specific iterator in one line Message-ID: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> This is purely sport question. I don't really intend to use the answer in my code, but I am wondering, if such a feat could be done. I have a following problem: I have a list based upon which I would like to construct a different one. I could simply use list comprehensions, but there is an additional trick: for some elements on this list, I would like to return two objects. For example I have a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I would like to add 2 'b', like this: [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] The easy way is to return a tuple ('b', 'b') for 1s and then flatten them. But this doesn't seem very right - I'd prefer to create a nice iterable right away. Is it possible to achieve this? Curiosly, the other way round is pretty simple to achieve, because you can filter objects using if in list comprehension. -- Filip Gruszczy?ski From gruszczy at gmail.com Tue Jun 30 04:45:16 2009 From: gruszczy at gmail.com (=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=) Date: Tue, 30 Jun 2009 10:45:16 +0200 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <1be78d220906300145g1fa118cekd6619f70e66389b3@mail.gmail.com> Oh, and there is additional requirement: it must be a one liner with at most 80 characters ;-) W dniu 30 czerwca 2009 10:44 u?ytkownik Filip Gruszczy?ski napisa?: > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. > > > -- > Filip Gruszczy?ski > -- Filip Gruszczy?ski From steven at REMOVE.THIS.cybersource.com.au Tue Jun 30 04:48:34 2009 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Jun 2009 08:48:34 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: > >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> >> Package managers with dependency tracking were all the rage when I >> first started using Linux. So I tried Red Hat and everything worked >> great until the depency database corrupted itself. > > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over > about the last decade, and I have NEVER seen this mythical dependency > database corruption of which you speak. Really? I've seen it, or at least something that looks like it if you squint. In my experience, it can usually be fixed by: yum clean all on recent Redhat based systems. Worst case, there may be a lockfile that needs deleting as well. -- Steven From rajat.dudeja at aeroflex.com Tue Jun 30 04:50:37 2009 From: rajat.dudeja at aeroflex.com (Dudeja, Rajat) Date: Tue, 30 Jun 2009 04:50:37 -0400 Subject: Access NtQueryInformationProces() from Python Message-ID: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> Hi, I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. Can anyone direct me to some examples where they have been successfully called through Python? Thanks and regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Tue Jun 30 04:56:16 2009 From: usernet at ilthio.net (Tim Harig) Date: Tue, 30 Jun 2009 08:56:16 GMT Subject: Python Imaging Library download link broken? References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: On 2009-06-30, Steven D'Aprano wrote: > On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: >> In message , Tim Harig wrote: >>> Package managers with dependency tracking were all the rage when I >>> first started using Linux. So I tried Red Hat and everything worked >>> great until the depency database corrupted itself. >> I have been using and administering various flavours of Linux--Red Hat, >> SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over >> about the last decade, and I have NEVER seen this mythical dependency >> database corruption of which you speak. > Really? I've seen it, or at least something that looks like it if you > squint. In my experience, it can usually be fixed by: > yum clean all Yum wasn't available then and I have never used it. Maybe it does a better job these days. I don't know. I get along fine without it. From pdpinheiro at gmail.com Tue Jun 30 04:57:24 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 30 Jun 2009 01:57:24 -0700 (PDT) Subject: Measuring Fractal Dimension ? References: <9297740f-b9f5-47b7-8f9e-8bb07ef4b1ce@k38g2000yqh.googlegroups.com> <124ff411-05b3-42db-a4bc-e53abf99638b@r34g2000vba.googlegroups.com> <87jv35lgfdkk1fojo2bvjl70p1r836h7th@4ax.com> <7x63eky7ob.fsf@ruckus.brouhaha.com> <0062e638$0$9714$c3e8da3@news.astraweb.com> <7xocs83l65.fsf@ruckus.brouhaha.com> <00631bb9$0$9714$c3e8da3@news.astraweb.com> <7x3a9kfy8s.fsf@ruckus.brouhaha.com> <0063d626$0$9714$c3e8da3@news.astraweb.com> <7x4otzykoi.fsf@ruckus.brouhaha.com> <7aqmfiF1vh4vfU1@mid.individual.net> Message-ID: <977b3568-eaf9-4653-8825-1312cf0eeed3@n30g2000vba.googlegroups.com> On Jun 29, 3:17?am, greg wrote: > Paul Rubin wrote: > > Steven D'Aprano writes: > > >>But that depends on what you call "things"... if electron shells are real > >>(and they seem to be) and discontinuous, and the shells are predicted/ > >>specified by eigenvalues of some continuous function, is the continuous > >>function part of nature or just a theoretical abstraction? > > Another thing to think about: If you put the atom in a > magnetic field, the energy levels of the electrons get > shifted slightly. To the extent that you can vary the > magnetic field continuously, you can continuously > adjust the energy levels. > > This of course raises the question of whether it's > really possible to continuously adjust a magnetic field. > But it's at least possible to do so with much finer > granularity than the differences between energy levels > in an atom. > > So if there is a fundamentally discrete model > underlying everything, it must be at a much finer > granularity than anything we've so far observed, and > the discrete things that we have observed probably > aren't direct reflections of it. > > -- > Greg Electron shells and isolated electrons stuck in a magnetic field are different phenomena that can't be directly compared. Or, at least, such a comparison requires you to explain why it's proper. From rhodri at wildebst.demon.co.uk Tue Jun 30 04:57:27 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 09:57:27 +0100 Subject: pep 8 constants In-Reply-To: <4A497A5B.4040503@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> <4A497A5B.4040503@harvee.org> Message-ID: On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson wrote: > Steven D'Aprano wrote: > >> Why do you think a smart editing environment is in opposition to coding >> conventions? Surely an editor smart enough to know a variable name >> spoken >> as "pear tree" is an instance and therefore spelled as pear_tree (to use >> your own example) would be smart enough to know a variable name spoken >> as >> "red" is a constant and therefore spelled "RED"? > > no. I think a smart editing environment should support a coding > convention. If > an editor is smart enough to track type and instance information, yes. > It should > be able to generate the right strings for symbols. The question is, how > do we > get such a smart editor. as far as I know, none exist and the smart > ones so far > seem to be oriented towards hand use and are almost inaccessible to > speech. But is it really possible for an editor to be smart enough -- Rhodri James *-* Wildebeest Herder to the Masses From clp2 at rebertia.com Tue Jun 30 04:58:07 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Jun 2009 01:58:07 -0700 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <50697b2c0906300158tba3f511paa3de95615524066@mail.gmail.com> 2009/6/30 Filip Gruszczy?ski : > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. >>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) ['b', 'b', 'a', 'a', 'b', 'b'] 69 chars long (plus or minus how the input list is written). Where's my golf trophy? ;) Cheers, Chris -- Goes to burn this shameful code... http://blog.rebertia.com From rhodri at wildebst.demon.co.uk Tue Jun 30 05:03:11 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 10:03:11 +0100 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <025949cb$0$20671$c3e8da3@news.astraweb.com> <4A497A5B.4040503@harvee.org> Message-ID: On Tue, 30 Jun 2009 09:57:27 +0100, Rhodri James wrote: > On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson > wrote: > >> Steven D'Aprano wrote: >> >>> Why do you think a smart editing environment is in opposition to coding >>> conventions? Surely an editor smart enough to know a variable name >>> spoken >>> as "pear tree" is an instance and therefore spelled as pear_tree (to >>> use >>> your own example) would be smart enough to know a variable name spoken >>> as >>> "red" is a constant and therefore spelled "RED"? >> >> no. I think a smart editing environment should support a coding >> convention. If >> an editor is smart enough to track type and instance information, yes. >> It should >> be able to generate the right strings for symbols. The question is, how >> do we >> get such a smart editor. as far as I know, none exist and the smart >> ones so far >> seem to be oriented towards hand use and are almost inaccessible to >> speech. > > But is it really possible for an editor to be smart enough Gah. Ignore me. I hit 'send' instead of 'cancel', after my musings concluded that yes, an editor could be smart enough, but it would have to embed a hell of a lot of semantic knowledge of Python and it still wouldn't eliminate the need to speak the keyboard at times. -- Rhodri James *-* Wildebeest Herder to the Masses From mail at timgolden.me.uk Tue Jun 30 05:10:29 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 30 Jun 2009 10:10:29 +0100 Subject: Access NtQueryInformationProces() from Python In-Reply-To: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> References: <408014003A0DA34BA5287D7A07EC089A1F94F4@EVS1.aeroflex.corp> Message-ID: <4A49D685.5020109@timgolden.me.uk> Dudeja, Rajat wrote: > Hi, > > I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. > > Can anyone direct me to some examples where they have been successfully called through Python? You want to look at ctypes: http://docs.python.org/library/ctypes.html?highlight=ctypes#module-ctypes TJG From http Tue Jun 30 05:18:06 2009 From: http (Paul Rubin) Date: 30 Jun 2009 02:18:06 -0700 Subject: Specific iterator in one line References: Message-ID: <7xzlbqdqr5.fsf@ruckus.brouhaha.com> Filip Gruszczy?ski writes: > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] Using itertools: >>> list(chain(*imap([['a'],['b','b']].__getitem__, [1,0,0,1]))) ['b', 'b', 'a', 'a', 'b', 'b'] From bruno.42.desthuilliers at websiteburo.invalid Tue Jun 30 05:19:54 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 30 Jun 2009 11:19:54 +0200 Subject: Specific iterator in one line In-Reply-To: References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <4a49d8b4$0$445$426a74cc@news.free.fr> Chris Rebert a ?crit : (snip) >>>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) > ['b', 'b', 'a', 'a', 'b', 'b'] > > 69 chars long (plus or minus how the input list is written). You can save 4 more characters using tumple dispatch instead of dict dispatch: reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1])) > Where's my golf trophy? ;) golf ? Why golf ?-) From rhodri at wildebst.demon.co.uk Tue Jun 30 05:26:33 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 10:26:33 +0100 Subject: Specific iterator in one line In-Reply-To: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: On Tue, 30 Jun 2009 09:44:39 +0100, Filip Gruszczy?ski wrote: > This is purely sport question. I don't really intend to use the answer > in my code, but I am wondering, if such a feat could be done. > > I have a following problem: I have a list based upon which I would > like to construct a different one. I could simply use list > comprehensions, but there is an additional trick: for some elements on > this list, I would like to return two objects. For example I have a > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > would like to add 2 'b', like this: > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > them. But this doesn't seem very right - I'd prefer to create a nice > iterable right away. Is it possible to achieve this? Curiosly, the > other way round is pretty simple to achieve, because you can filter > objects using if in list comprehension. > If you'll allow me a prior "import itertools", >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] does the job in 62 characters. -- Rhodri James *-* Wildebeest Herder to the Masses From clp2 at rebertia.com Tue Jun 30 05:31:09 2009 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Jun 2009 02:31:09 -0700 Subject: Specific iterator in one line In-Reply-To: <4a49d8b4$0$445$426a74cc@news.free.fr> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <4a49d8b4$0$445$426a74cc@news.free.fr> Message-ID: <50697b2c0906300231t2a616d7fo3c82f81b1af4ab5a@mail.gmail.com> On Tue, Jun 30, 2009 at 2:19 AM, Bruno Desthuilliers wrote: > Chris Rebert a ?crit : > (snip) >>>>> >>>>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1])) >> >> ['b', 'b', 'a', 'a', 'b', 'b'] >> >> 69 chars long (plus or minus how the input list is written). > > You can save 4 more characters using tumple dispatch instead of dict > dispatch: > > reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1])) > >> Where's my golf trophy? ;) > > golf ? Why golf ?-) http://en.wikipedia.org/wiki/Code_golf It's the sport the OP is playing. Cheers, Chris From andreas.tawn at ubisoft.com Tue Jun 30 05:42:48 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 11:42:48 +0200 Subject: Specific iterator in one line In-Reply-To: References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> > > This is purely sport question. I don't really intend to use the answer > > in my code, but I am wondering, if such a feat could be done. > > > > I have a following problem: I have a list based upon which I would > > like to construct a different one. I could simply use list > > comprehensions, but there is an additional trick: for some elements on > > this list, I would like to return two objects. For example I have a > > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > > would like to add 2 'b', like this: > > > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > > them. But this doesn't seem very right - I'd prefer to create a nice > > iterable right away. Is it possible to achieve this? Curiosly, the > > other way round is pretty simple to achieve, because you can filter > > objects using if in list comprehension. > > > If you'll allow me a prior "import itertools", > > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] > > does the job in 62 characters. list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) 50 characters. Do I win ?5? From python.list at tim.thechases.com Tue Jun 30 06:00:18 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 05:00:18 -0500 Subject: pep 8 constants In-Reply-To: <4A48E307.50804@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> Message-ID: <4A49E232.6090101@tim.thechases.com> Eric S. Johansson wrote: > Tim Chase wrote: > It sounds like the issue should be one of making your screen-reader >> smarter, not dumbing down Python conventions. I don't know what SR >> you're using (Jaws? Window Eyes? yasr? screeder? speakup? > > Naturally speaking is speech recognition (speech in text out) it is not text to > speech although it does have a pluging for that Sorry...I didn't catch that you were using speech-recognition (SR) instead of text-to-speech (TTS). I didn't see it mentioned in another thread-branch after I had posted. While I have used SR in some testing, I've found that while it's passable for prose (and even that, proclamations of "95% accuracy" sound good until you realize how many words comprise 5% of your daily typing :), it's not so good for code unless you have a very specific programming-language+SR designed editing environment...as you've been griping. However, the problem seems not to be PEP-8, but rather the inabilities of your SR combined with the failings of your editor. For coding, you might want to investigate a tool like Dasher[1] which offers an alternate form of input. It allows for custom vocabularies/keymaps if you need, as well as more precise specification of a full keyboard (caps vs. mixed-case, specific punctuation characters, etc). The predictive entry should be smart enough to pick up previously entered constants/terms saving you entry speed. It can also be driven by a wide variety of pointing devices (mouse, trackball, touchpad, head-tracker, gyro-input, etc). You might also experiment with other editors that allow for more efficient editing. Hope these give you another option to consider, if SR plus your current editor aren't cutting it for you, -tkc [1] http://www.inference.phy.cam.ac.uk/dasher/ http://en.wikipedia.org/wiki/Dasher http://www.youtube.com/results?search_query=dasher http://video.google.com/videosearch?q=dasher From rhodri at wildebst.demon.co.uk Tue Jun 30 06:06:45 2009 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 30 Jun 2009 11:06:45 +0100 Subject: pep 8 constants In-Reply-To: <4A496FE5.9060005@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> <4A496FE5.9060005@harvee.org> Message-ID: [Trimming for length, sorry if that impacts too much on intelligibility] On Tue, 30 Jun 2009 02:52:37 +0100, Eric S. Johansson wrote: > let's use an example. Admittedly, this is a very simple example but > hopefully it > illustrates my point > > What I dictate is: > > from pots is class telephone > > What should generate is: > > class Telephone (pots): > > as you can see, taken from the simplistic expression, we generate the > right > pep-8 convention. (I think). This is not the only grammar one can use > but, it's > one that comes to mind that doesn't have a lot of dead ends. [snip fuller example] > at each stage of the way, names get transformed into the pep-8 form > without me > having to say anything special. The environment knows what form it wants > and > does the transformation automatically. I'm surprised people aren't > doing this > already for their handcrafted code. It's one less bit of detail you need > to pay > attention to. This goes a long way, but it doesn't eliminate the need for some forms of escape coming up on a moderately frequent basis. Consider "Coffee strength equals five" for example: this could mean either coffee_strength = 5 or COFFEE_STRENGTH = 5 depending on whether we will later be using it as a constant or not. Python doesn't have syntactic constants, which is precisely why PEP-8 is useful. You might have enough smarts in your system for it to remember after the first time you use "coffee strength", and it might be unambiguous, but at the very least you need to be able to say "Constant coffee strength equals five" first time round. This isn't the only occasion when you simply don't have the context to avoid verbal disambiguation. Are you accessing attributes of the class MyClass or its instance my_class, for instance? In your initial post you seemed to be claiming that having to do this disambiguation textually was bad, and PEP-8 should therefore be rejected. Given that I'm not prepared to lose the productivity increase that comes with being able to disambiguate visually at a glance, I don't see that it's avoidable. Incidentally, since what you're proposing is essentially templating, wouldn't it be better to do it as post-processing on the speech recognition rather than building it directly into an editor? to resolve -- Rhodri James *-* Wildebeest Herder to the Masses From andreas.tawn at ubisoft.com Tue Jun 30 06:11:24 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 12:11:24 +0200 Subject: Specific iterator in one line In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> > > > This is purely sport question. I don't really intend to use the answer > > > in my code, but I am wondering, if such a feat could be done. > > > > > > I have a following problem: I have a list based upon which I would > > > like to construct a different one. I could simply use list > > > comprehensions, but there is an additional trick: for some elements on > > > this list, I would like to return two objects. For example I have a > > > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I > > > would like to add 2 'b', like this: > > > > > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] > > > > > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten > > > them. But this doesn't seem very right - I'd prefer to create a nice > > > iterable right away. Is it possible to achieve this? Curiosly, the > > > other way round is pretty simple to achieve, because you can filter > > > objects using if in list comprehension. > > > > > If you'll allow me a prior "import itertools", > > > > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] > > > > does the job in 62 characters. > > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > > 50 characters. Do I win ?5? list("".join([("a","bb")[x] for x in [1,0,0,1]]) Or 49 :o) From tkjthingone at gmail.com Tue Jun 30 06:17:59 2009 From: tkjthingone at gmail.com (Horace Blegg) Date: Tue, 30 Jun 2009 03:17:59 -0700 Subject: The Python Way for module configuration? In-Reply-To: References: <87fxdlujds.fsf@benfinney.id.au> Message-ID: On Sun, Jun 28, 2009 at 10:22 AM, kj wrote: > In <87fxdlujds.fsf at benfinney.id.au> Ben Finney > > writes: > > >(Even if you don't want to receive email, could you please give your > >actual name in the ?From? field instead of just initials? It makes > >conversation less confusing.) > > I don't know why, but for as long as I can remember everyone calls > me kj, even my mom. My name is Keaweikekahiali?iokamoku > Jallalahwallalruwalpindi > > kj > > -- > http://mail.python.org/mailman/listinfo/python-list > > Is that Mongolian? :) (poor joke) Anyway, I tend to just use the name of a character from the most recent book I've read. People often can't tell the difference (though this one is something of a stretch) and I get to maintain my illusion of anonymous. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Jun 30 06:19:22 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Jun 2009 12:19:22 +0200 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: Andreas Tawn wrote: >> > > This is purely sport question. I don't really intend to use the >> > > answer in my code, but I am wondering, if such a feat could be done. >> > > >> > > I have a following problem: I have a list based upon which I would >> > > like to construct a different one. I could simply use list >> > > comprehensions, but there is an additional trick: for some elements >> > > on this list, I would like to return two objects. For example I have >> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I >> > > would like to add 2 'b', like this: >> > > >> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] >> > > >> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten >> > > them. But this doesn't seem very right - I'd prefer to create a nice >> > > iterable right away. Is it possible to achieve this? Curiosly, the >> > > other way round is pretty simple to achieve, because you can filter >> > > objects using if in list comprehension. >> > > >> > If you'll allow me a prior "import itertools", >> > >> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] >> > >> > does the job in 62 characters. >> >> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >> >> 50 characters. Do I win ?5? > > list("".join([("a","bb")[x] for x in [1,0,0,1]]) > > Or 49 :o) >>> len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""") 48 >>> sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[]) ['b', 'b', 'a', 'a', 'b', 'b'] From http Tue Jun 30 06:26:39 2009 From: http (Paul Rubin) Date: 30 Jun 2009 03:26:39 -0700 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> Message-ID: <7x7hyu2f1c.fsf@ruckus.brouhaha.com> "Andreas Tawn" writes: > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > 50 characters. Do I win ??5? Er, missing right paren. Try: list("".join(("a","bb")[x] for x in [1,0,0,1])) From python.list at tim.thechases.com Tue Jun 30 06:29:58 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 05:29:58 -0500 Subject: Specific iterator in one line In-Reply-To: <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> <8AEDA5E3386EA742B8C24C95FF0C7580076EE3FD@PDC-MAIL3.ubisoft.org> Message-ID: <4A49E926.8060209@tim.thechases.com> >> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >> >> 50 characters. Do I win ?5? > > list("".join([("a","bb")[x] for x in [1,0,0,1]]) > > Or 49 :o) Well, you have a missing ")" character, but that would be the 49th. You can[*] abuse python's parsing by removing certain spaces with list(''.join([('a','bb')[x]for x in[1,0,0,1]])) bringing you down to 47. In more recent versions of Python, you can then pass a generator instead of a list-comprehension: list(''.join(('a','bb')[x]for x in[1,0,0,1])) bringing you to 45. -tkc [*] not *should*, but *can* From sk8in_zombi at yahoo.com.au Tue Jun 30 06:34:15 2009 From: sk8in_zombi at yahoo.com.au (Mr SZ) Date: Tue, 30 Jun 2009 03:34:15 -0700 (PDT) Subject: Learning to use decorators with classes Message-ID: <370202.47877.qm@web54504.mail.re2.yahoo.com> Hi, I'm writing an LDAP plugin for my TG2 application. In this I wrote a small class based decorator with args to set up a connection and call the necessary functionality but I'm having problems with it. Here's my code: class getConnection(object): def __init__(self, settings, credentials): self.settings = settings self.credentials = credentials def __call__(self, f): def wrapped_f(*args, **kw): ...code snipped... try: if tls: connection.start_tls_s() if anon: con.simple_bind_s() else: con.simple_bind_s( dn, pw ) except ldap.LDAPError, e: print e.message['info'] else: kw['conn'] = connection try: f(*args, **kw) except Exception, e: print 'Exception in Plugin execution: %s' % e finally: connection.unbind() return wrapped_f class LdapPlugin(Plugin): ... def __init__(self, **kw): Plugin.__init__(self) @getConnection(self._settings, self.__cred__) def search(self, **kw): print 'Searching' ... Here the base class constructor(Plugin) fetches plugin specific settings from the web framework and stores it in self._settings and user info in self.__cred__ . Now when the method is invoked, this is the error I get: File '.../plugins/ldap/ldap/__init__.py', line 69 in LdapPlugin @getConnection(self._settings, self.__cred__) NameError: name 'self' is not defined I can simply write a method that gets a connection and deal with it but I wanted to know and learn why decorators is not working in this case. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From __peter__ at web.de Tue Jun 30 06:34:44 2009 From: __peter__ at web.de (Peter Otten) Date: Tue, 30 Jun 2009 12:34:44 +0200 Subject: Specific iterator in one line References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <8AEDA5E3386EA742B8C24C95FF0C7580076EE385@PDC-MAIL3.ubisoft.org> Message-ID: Peter Otten wrote: > Andreas Tawn wrote: > >>> > > This is purely sport question. I don't really intend to use the >>> > > answer in my code, but I am wondering, if such a feat could be done. >>> > > >>> > > I have a following problem: I have a list based upon which I would >>> > > like to construct a different one. I could simply use list >>> > > comprehensions, but there is an additional trick: for some elements >>> > > on this list, I would like to return two objects. For example I have >>> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I >>> > > would like to add 2 'b', like this: >>> > > >>> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] >>> > > >>> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten >>> > > them. But this doesn't seem very right - I'd prefer to create a nice >>> > > iterable right away. Is it possible to achieve this? Curiosly, the >>> > > other way round is pretty simple to achieve, because you can filter >>> > > objects using if in list comprehension. >>> > > >>> > If you'll allow me a prior "import itertools", >>> > >>> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)] >>> > >>> > does the job in 62 characters. >>> >>> list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) >>> >>> 50 characters. Do I win ?5? >> >> list("".join([("a","bb")[x] for x in [1,0,0,1]]) >> >> Or 49 :o) > >>>> len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""") > 48 >>>> sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[]) > ['b', 'b', 'a', 'a', 'b', 'b'] forgot one extra space: >>> sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[]) ['b', 'b', 'a', 'a', 'b', 'b'] >>> len("""sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[])""") 47 From venutaurus539 at gmail.com Tue Jun 30 06:46:36 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 30 Jun 2009 03:46:36 -0700 (PDT) Subject: Passing parameters for a C program in Linux. Message-ID: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Hi all, I have to write an automted script which will test my c program. That program when run will ask for the commands. For example: local-host# ./cli Enter 1 for add Enter 2 for sub Enter 3 for mul 1 -------Our option Enter two numbers 44 33 -------- Our option Result is 77 As shown in the above example it lists all the options and waits for user input and once given, it does some operations and waits for some more. This has to be automated. Can someone give suggestions how to do this in Python (Linux Platform in particular). Thank you, Venu. From shenyute at gmail.com Tue Jun 30 06:54:35 2009 From: shenyute at gmail.com (Shen, Yu-Teh) Date: Tue, 30 Jun 2009 03:54:35 -0700 (PDT) Subject: python extend c++ module Message-ID: <03d476cc-b633-44d4-b68f-46c64285d253@j32g2000yqh.googlegroups.com> I have written a c++ extend module and I use distutils to build. setup.py ---------------- from distutils.core import setup, Extension setup(name="noddy", version="1.0", ext_modules=[ Extension("noddy3", ["noddy3.cpp", "a.cpp"]) ]) I found it's quite strange when compiling. I didn't use extern "C" at all , how can python get the right c++ funciton name without any compile error?? I found that it first use gcc to compile noddy3.cpp and then link by g+ +. Could anyone explain what it's all about? Thanks a lot!! here is the compiling message. --------------------------------------- running install running build running build_ext building 'noddy3' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp -o build/temp.linux-i686-2.6/noddy3.o cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so running install_lib copying build/lib.linux-i686-2.6/noddy3.so -> /usr/local/lib/python2.6/site-packages running install_egg_info Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg- info Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info From andreas.tawn at ubisoft.com Tue Jun 30 06:55:21 2009 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Tue, 30 Jun 2009 12:55:21 +0200 Subject: Specific iterator in one line In-Reply-To: <7x7hyu2f1c.fsf@ruckus.brouhaha.com> References: <1be78d220906300144o15ea239fn425f1a67d9a31262@mail.gmail.com> <7x7hyu2f1c.fsf@ruckus.brouhaha.com> Message-ID: <8AEDA5E3386EA742B8C24C95FF0C7580076EE47A@PDC-MAIL3.ubisoft.org> > -----Original Message----- > From: python-list-bounces+andreas.tawn=ubisoft.com at python.org [mailto:python- > list-bounces+andreas.tawn=ubisoft.com at python.org] On Behalf Of Paul Rubin > Sent: Tuesday, June 30, 2009 11:27 AM > To: python-list at python.org > Subject: Re: Specific iterator in one line > > "Andreas Tawn" writes: > > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > > 50 characters. Do I win ??5? > > Er, missing right paren. Try: > > list("".join(("a","bb")[x] for x in [1,0,0,1])) > -- Indeed. Stupid paste ;o) From jeanmichel at sequans.com Tue Jun 30 07:00:34 2009 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Jun 2009 13:00:34 +0200 Subject: pep 8 constants In-Reply-To: <4A4912D4.5070900@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A48E270.6000403@harvee.org> <4A490707.3040207@stoneleaf.us> <4A4912D4.5070900@harvee.org> Message-ID: <4A49F052.7050004@sequans.com> Eric S. Johansson wrote: > Ethan Furman wrote: > >> Eric S. Johansson wrote: >> >>> yup how long will i[t] be before you become disablesd? maybe not as >>> badly as I am >>> but you should start feeling some hand problems in your later 40's to >>> early 50's >>> and it goes down hill from there. self preservation/interest comes to >>> mind as a >>> possible motive for action. I thought 15 years would be enough for >>> somebody >>> else to push the isssue but no. if it is going to be, it has to be me. >>> >> For anyone who is still able to use their hands for typing, especially >> if you're beginning to encounter the painful wrists, consider switching >> to a Dvorak layout. It was a system I was curious about even before I >> needed it, and when I did need it I was able to create the layout in >> assembler (now, of course, it's widely available as a standard keyboard >> layout). I started noticing the pain in my late twenties (aggravated, >> I'm sure, by arthritis), but with switching to Dvorak the pain left and >> has only very rarely been noticable again. It will mostly likely be a >> challenge to switch, but well worth it. >> > > a good suggestion but not really addressing the point I'm trying to make of > building a system that would help people more profoundly injured. for example, > I've tried Dvorak and the act of typing was so painful that I couldn't learn it > You must previously define what you are calling "more profoundly injured". Which disabled abilities are you talking about ? What about people that have difficulties to speak because of partial jaw paralysis. They would need systems that recognize eye blinks to write down code. What about blind people, color blind ... ? Would a new disabled friendly PEP 8 version fits all their needs ? To come back to a more python related subject, I don't think it falls into PEP responsibility to take into account all the disabled abilities you can find in the dev community. This falls into the tools they used to workaround their issues and there's surely much work to be done here. In the end, as someone mentioned before, PEPs are only guidelines, and you are entitled to break them if the rule hurts you. This is one of the many beauties of python, it's flexible. Jean-Michel From grante at visi.com Tue Jun 30 07:19:13 2009 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Jun 2009 06:19:13 -0500 Subject: Drawing in PDF References: Message-ID: On 2009-06-30, Eduardo Lenz wrote: > Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: >> In message > >> d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: >> > ... is there open source solution ? >> >> Poppler? > > pypdf -- http://pybrary.net/pyPdf/ > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > * extracting document information (title, author, ...), > * splitting documents page by page, > * merging documents page by page, > * cropping pages, > * merging multiple pages into a single page, > * encrypting and decrypting PDF files. While it may be a pure-python library, the problem is that AFAICT it doesn't actually solve the problem at hand. The requirement is to "draw" on the pages of an existing PDF document (add annotations). > By being Pure-Python, it should run on any Python platform > without any dependencies on external libraries. It can also > work entirely on StringIO objects rather than file streams, > allowing for PDF manipulation in memory. It is therefore a > useful tool for websites that manage or manipulate PDFs. True, but does it allow you to add text/lines/etc. to a page? -- Grant From bearophileHUGS at lycos.com Tue Jun 30 07:30:01 2009 From: bearophileHUGS at lycos.com (Bearophile) Date: Tue, 30 Jun 2009 04:30:01 -0700 (PDT) Subject: Specific iterator in one line References: Message-ID: Filip Gruszczy?ski: > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] I like this version (43 golf holes), it's readable enough: [c for d in[1,0,0,1]for c in("a","bb")[d]] Bye, bearophile From nobody at nowhere.com Tue Jun 30 07:30:42 2009 From: nobody at nowhere.com (Nobody) Date: Tue, 30 Jun 2009 12:30:42 +0100 Subject: Using Python for file packing References: Message-ID: On Mon, 29 Jun 2009 14:16:34 -0700, Scott David Daniels wrote: >>> Do you mean like a zip or tar file? >>> >>> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >>> >> >> I had no idea you could access a single file from a ZIP or TAR without >> explicitly extracting it somewhere. Thanks. > > You will find the zip format works better if you are compressing. The > zipfile compression is per file in the archive, rather than applied to > the entire archive (as in tarfile). The results of the tar format > decision is that extracting the last file in a .tgz (.tar.gz) or > .tar.bz2 (sometimes called .tbz) requires the expansion of the entire > archive, while extraction on a .zip is reposition, read, and possibly > expand. Even without compression, the tar format is ill-suited to random access. If you can choose the format, use a zip file. From harsha.reddy at db.com Tue Jun 30 07:45:40 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:15:40 +0530 Subject: Help me plsss... Message-ID: Hi All, Environment :- Solaris Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 Oracle version :- 10.2.0.3 Below is the library path echo $LD_LIBRARY_PATH /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib: /data/oracle/product/10.2.0.3/lib Issue :- We have been recently migrated from 9i to 10g database and also from AIX to Solaris. When we were using 9i i can able to import cx_oracle library... But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... newprd$ python ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. PLs help meee ... Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco.bizzarri at gmail.com Tue Jun 30 08:10:05 2009 From: marco.bizzarri at gmail.com (Marco Bizzarri) Date: Tue, 30 Jun 2009 14:10:05 +0200 Subject: Help me plsss... In-Reply-To: References: Message-ID: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- ? ? ? ? ? ? ? ? Solaris > Python Version :- ? ? ? ? ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > ? ? ? ? ? ? ? ? ? ? ? ? Python 2.4.3 (#1, Apr ?3 2006, 18:34:02) [C] on sunos5 > Oracle version :- ? ? ? ? 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr ?3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > ? File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ From harsha.reddy at db.com Tue Jun 30 08:13:42 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:43:42 +0530 Subject: Help me plsss... In-Reply-To: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Message-ID: Hi Marc, Thanks for the replyyyy... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/dbcom at DBEMEA cc python-list at python.org Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harsha.reddy at db.com Tue Jun 30 08:15:13 2009 From: harsha.reddy at db.com (Harsha Reddy) Date: Tue, 30 Jun 2009 17:45:13 +0530 Subject: Help me plsss... In-Reply-To: <3f0d61c40906300510t5a9be0aam6fdf32119bd6187a@mail.gmail.com> Message-ID: Hi Marc, Thanks for the replyyyy... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 ------------------------------------------------------------------------------------------------------------------------------------------------ P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence ------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" ----------------------------------------------------------------------------------------------- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/dbcom at DBEMEA cc python-list at python.org Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > ------------------------------------------------------------------------------------------------------------------------------------------------ > P.S.: Please ensure all your FXPCA queries are CC'd to fxpca_support at list.db.com & GCMS related queries are CC'd to "GCMS_IT_SUPPORT at DMG UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > ------------------------------------------------------------------------------------------------------------------------------------------------ > > ---------------------------------------------------------------------------------------------- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies ?bermittelt" > ----------------------------------------------------------------------------------------------- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. -------------- next part -------------- An HTML attachment was scrubbed... URL: From user at example.net Tue Jun 30 08:16:21 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 14:16:21 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/29 MRAB : > >>superpollo wrote: >> >>>hi folks. >>> >>>the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >>>not work? (prints stuff forever) >>> >>> 1 #!/usr/bin/python >>> 2 >>> 3 import threading >>> 4 import sys >>> 5 >>> 6 t = threading.Timer(3.0, sys.exit) >>> 7 t.start() >>> 8 while True: >>> 9 print "stuff ", >>> >> >>The Timer runs the function in another thread. Perhaps sys.exit is just >>exiting that thread and not the main thread. > > > sys.exit raises a SystemExit exception, which will get handled in the > new thread (where it won't do anything). Conceded, this isn't > particularly intuitive. > > For a non-toy example, you'd probably create an Event object, use your > timer to set the event, and your while loop would do while > event.is_set(), so the problem wouldn't arise. thank u paul. if u dont mind, would you give me a more detailed piece of code that does what i mean? tia From petr.messner at gmail.com Tue Jun 30 08:42:10 2009 From: petr.messner at gmail.com (Petr Messner) Date: Tue, 30 Jun 2009 14:42:10 +0200 Subject: Passing parameters for a C program in Linux. In-Reply-To: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <67c97cd90906300542o3479f4fdha81390b84965c469@mail.gmail.com> Hi, this can be done using module "subprocess"; there is also function popen() in module "os" and module popen2, but they are deprecated since Python 2.6. PM 2009/6/30 venutaurus539 at gmail.com : > Hi all, > I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1 -------Our option > Enter two numbers > 44 33 -------- Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. > -- > http://mail.python.org/mailman/listinfo/python-list > From david.lyon at preisshare.net Tue Jun 30 08:44:06 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 30 Jun 2009 08:44:06 -0400 Subject: ANN: Package Manager GUI for Python (Windows) In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: Hi All, I'm pleased to announce a GUI package manager (v 0.12) for Python versions 2.x under Windows. http://sourceforge.net/projects/pythonpkgmgr/ It's tightly linked to the pypi repository and offers the following functions: - search packages on pypi by name - install (via easyinstall or pip) - deinstall/remove packages - see package documentation - see package examples - install .EGG packages - Generate package manifest If you find any issues, please don't hesitate to report them via our tracker on the project page. Regards David From bruno.42.desthuilliers at websiteburo.invalid Tue Jun 30 08:48:23 2009 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 30 Jun 2009 14:48:23 +0200 Subject: Learning to use decorators with classes In-Reply-To: References: Message-ID: <4a4a0991$0$418$426a74cc@news.free.fr> Mr SZ a ?crit : > Hi, > > I'm writing an LDAP plugin for my TG2 application. In this I wrote a small class based decorator with args to set up a connection and call the necessary > functionality but I'm having problems with it. Here's my code: > (snip code) > > class LdapPlugin(Plugin): > ... > def __init__(self, **kw): > Plugin.__init__(self) > > @getConnection(self._settings, self.__cred__) Don't use '__name__', they are reserved for the implementation. And FWIW, don't use '__name' unless you have a really compelling reason to do so. > def search(self, **kw): > print 'Searching' > ... This can't work, and it's a FAQ FWIW - but since there's no official c.l.py FAQ, we won't hold it against you !-) def and class are both *executable* statements (yes, classes and functions creation - like almost anything in Python - are run-time operations). The first one creates a function object - *wherever* it happens - and bind the function object to the function's name in the current namespace. Think of it as an equivalent of the following javascript snippet: var func_name = function(arg) { /* function's body */ }; The second statement - class - builds a class object from the names defined in the class statement's body (that is, names defined in the class statement's body will become attributes of the class object). Now about the 'methods' and 'self' stuff... First understand that there's *nothing* magical with 'self'. It's *not* a keyword. It's only a naming convention, and you could use any legal Python identified instead. The reason we have to explicitly mention it as first argument of the function is that it's the only way the function's body can get access to the current instance. What happens is (overly simplified) that during attribute resolution, when the found attribute happens to be a function, this function is wrapped - together with the instance on which the attribute was looked up and it's class - into a callable method object. Then when you call this method object, it inserts the instance as first argument to the function call, and returns the result of the function call (if you want to read more about this and how computed attributes are implemented in Python, google for 'descriptor protocol'). IOW, and to make a long story short, calling instance.method is the same as calling Class.method(instance). Ok, now to the point: when you call getConnection within the class statement's body, there's no magical "self" keyword poiting to an instance, and since the class itself doesn't yet exists, so there's *no* way you could get at an instance of it anyway !-) There are many ways to solve your problem, the simplest bing probably to write another decorator calling on the first one, ie: def connected_method(func): def connected(self, *args, **kw): wrapped = getConnection(self.__this, self.__that)(func) return wrapped(*args, **kw) return connected Note that this may not be that efficient - you'll have quite a few function calls involved here. While we're at it, a couple comments on your code... First, please read pep08 (naming and coding conventions) on python.org. Conventions are very important in Python. wrt/ error handling: try: if tls: connection.start_tls_s() if anon: con.simple_bind_s() else: con.simple_bind_s(dn, pw) except ldap.LDAPError, e: print e.message['info'] This kind of "error handling" is more than useless - it's worse than no error handling at all. If you cannot handle the problem (I really mean *handle*, you know, like do something to fix it), just let the exception propagate - you'll get a nice traceback with all the necessary debugging informations. Users of your package can always add a top-level "catch-all" exception handler that will log tracebacks, send alert mails to the team, and present the end-user with a nicely formatted error message (and even possibly a way to handle the problem - like providing appropriate connection data (credentials, url, whatever) !-) Also note that sys.stdout is for *normal* program outputs. Error messages belongs to sys.stderr. else: kw['conn'] = connection try: f(*args, **kw) except Exception, e: print 'Exception in Plugin execution: %s' % e Same as above : if you can't handle the exception, leave it alone. HTH From p.f.moore at gmail.com Tue Jun 30 08:54:21 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 30 Jun 2009 13:54:21 +0100 Subject: timer In-Reply-To: <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <79990c6b0906300554j1062668du8f4cb2c8acf990df@mail.gmail.com> 2009/6/30 superpollo : > Paul Moore wrote: >> For a non-toy example, you'd probably create an Event object, use your >> timer to set the event, and your while loop would do while >> event.is_set(), so the problem wouldn't arise. > > thank u paul. if u dont mind, would you give me a more detailed piece of > code that does what i mean? No problem: import threading e = threading.Event() t = threading.Timer(3.0, e.set) t.start() while not e.is_set(): print "Hello, threading world" Hope this helps, Paul From user at example.net Tue Jun 30 09:04:11 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:04:11 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> Message-ID: <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/29 MRAB : > >>superpollo wrote: >> >>>hi folks. >>> >>>the follwing shoud print 'stuff' for 3 seconds and then stop. why it does >>>not work? (prints stuff forever) >>> >>> 1 #!/usr/bin/python >>> 2 >>> 3 import threading >>> 4 import sys >>> 5 >>> 6 t = threading.Timer(3.0, sys.exit) >>> 7 t.start() >>> 8 while True: >>> 9 print "stuff ", >>> >> >>The Timer runs the function in another thread. Perhaps sys.exit is just >>exiting that thread and not the main thread. > > > sys.exit raises a SystemExit exception, which will get handled in the > new thread (where it won't do anything). Conceded, this isn't > particularly intuitive. > > For a non-toy example, you'd probably create an Event object, use your > timer to set the event, and your while loop would do while > event.is_set(), so the problem wouldn't arise. > > Paul. so why this does not work? 1 #!/usr/bin/python 2 3 import threading 4 5 e = threading.Event() 6 t = threading.Timer(3.0, e.set()) 7 t.start() 8 while not e.isSet(): 9 print "stuff ", it does *NOT* print (but it should, shouldn't it?), then exits after 3 sec but with error: Exception in thread Thread-1:Traceback (most recent call last): File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap self.run() File "/usr/lib/python2.3/threading.py", line 575, in run self.function(*self.args, **self.kwargs) TypeError: 'NoneType' object is not callable what gives? From venutaurus539 at gmail.com Tue Jun 30 09:05:34 2009 From: venutaurus539 at gmail.com (venutaurus539 at gmail.com) Date: Tue, 30 Jun 2009 06:05:34 -0700 (PDT) Subject: Passing parameters for a C program in Linux. References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> On Jun 30, 5:42?pm, Petr Messner wrote: > Hi, > > this can be done using module "subprocess"; there is also function > popen() in module "os" and module popen2, but they are deprecated > since Python 2.6. > > PM > > 2009/6/30 venutaurus... at gmail.com : > > > Hi all, > > ? ? ? I have to write an automted script which will test my c > > program. That program when run will ask for the commands. For example: > > > local-host# ./cli > > Enter 1 for add > > Enter 2 for sub > > Enter 3 for mul > > 1 ? ? ? ? ? ?-------Our option > > Enter two numbers > > 44 33 ?-------- Our option > > Result is 77 > > > As shown in the above example it lists all the options and waits for > > user input and once given, it does some operations and waits for some > > more. This has to be automated. > > > Can someone give suggestions how to do this in Python (Linux Platform > > in particular). > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Can you give some more explanation about how exactly this can be done.. Thanks for reply, Venu From user at example.net Tue Jun 30 09:06:10 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:06:10 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <4a4a0dc3$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/30 superpollo : > >>Paul Moore wrote: >> >>>For a non-toy example, you'd probably create an Event object, use your >>>timer to set the event, and your while loop would do while >>>event.is_set(), so the problem wouldn't arise. >> >>thank u paul. if u dont mind, would you give me a more detailed piece of >>code that does what i mean? > > > No problem: > > import threading > > e = threading.Event() > t = threading.Timer(3.0, e.set) > t.start() > > while not e.is_set(): > print "Hello, threading world" > > Hope this helps, > Paul hi while i was waiting 4 ur reply, i posted an almost equal example, but it does not work... From paul.nospam at rudin.co.uk Tue Jun 30 09:08:38 2009 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 30 Jun 2009 14:08:38 +0100 Subject: timer References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <87vdmdrhrd.fsf@rudin.co.uk> superpollo writes: > so why this does not work? > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 > 5 e = threading.Event() > 6 t = threading.Timer(3.0, e.set()) The second arg needs to be a callable - maybe you meant e.set without the brackets? From user at example.net Tue Jun 30 09:09:05 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:09:05 +0200 Subject: timer In-Reply-To: References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> Message-ID: <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> Paul Moore wrote: > 2009/6/30 superpollo : > >>Paul Moore wrote: >> >>>For a non-toy example, you'd probably create an Event object, use your >>>timer to set the event, and your while loop would do while >>>event.is_set(), so the problem wouldn't arise. >> >>thank u paul. if u dont mind, would you give me a more detailed piece of >>code that does what i mean? > > > No problem: > > import threading > > e = threading.Event() > t = threading.Timer(3.0, e.set) > t.start() > > while not e.is_set(): > print "Hello, threading world" > > Hope this helps, > Paul do not bother answering... my fault. i wrote e.set() and not e.set thanks again From mail at timgolden.me.uk Tue Jun 30 09:09:43 2009 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 30 Jun 2009 14:09:43 +0100 Subject: timer In-Reply-To: <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0d4c$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <4A4A0E97.3070103@timgolden.me.uk> superpollo wrote: > so why this does not work? > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 > 5 e = threading.Event() > 6 t = threading.Timer(3.0, e.set()) > 7 t.start() > 8 while not e.isSet(): > 9 print "stuff ", > > it does *NOT* print (but it should, shouldn't it?), then exits after 3 > sec but with error: Nice try, but you're passing *the result of calling e.set* as the function parameter to Timer. And the result of calling e.set () is None. So you're passing None as the function-to-call. Which it does. And then... > TypeError: 'NoneType' object is not callable Try passing the function instead: threading.Timer (3.0, e.set).start () TJG From user at example.net Tue Jun 30 09:11:09 2009 From: user at example.net (superpollo) Date: Tue, 30 Jun 2009 15:11:09 +0200 Subject: timer In-Reply-To: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> Message-ID: <4a4a0eee$0$18931$4fafbaef@reader2.news.tin.it> i would like to thank each and everyone for help given, and aplologise for my inaccuracy. thanks 10**3! superchicken From p.f.moore at gmail.com Tue Jun 30 09:19:47 2009 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 30 Jun 2009 14:19:47 +0100 Subject: timer In-Reply-To: <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> References: <4a49381b$0$47538$4fafbaef@reader1.news.tin.it> <4A4940FA.9010206@mrabarnett.plus.com> <4a4a0216$0$18934$4fafbaef@reader2.news.tin.it> <4a4a0e72$0$18931$4fafbaef@reader2.news.tin.it> Message-ID: <79990c6b0906300619y681a0871g3ea438331c4f726@mail.gmail.com> 2009/6/30 superpollo : > Paul Moore wrote: >> >> 2009/6/30 superpollo : >> >>> Paul Moore wrote: >>> >>>> For a non-toy example, you'd probably create an Event object, use your >>>> timer to set the event, and your while loop would do while >>>> event.is_set(), so the problem wouldn't arise. >>> >>> thank u paul. if u dont mind, would you give me a more detailed piece of >>> code that does what i mean? >> >> >> No problem: >> >> import threading >> >> e = threading.Event() >> t = threading.Timer(3.0, e.set) >> t.start() >> >> while not e.is_set(): >> ? ?print "Hello, threading world" >> >> Hope this helps, >> Paul > > do not bother answering... my fault. > > i wrote e.set() and not e.set > > > > thanks again No problem - I made the same mistake while I was writing the sample :-) (I also forgot t.start() the first time. So I'm winning 2-1 on trivial mistakes :-)) Paul. From roop at forwardbias.in Tue Jun 30 09:27:32 2009 From: roop at forwardbias.in (roop) Date: Tue, 30 Jun 2009 06:27:32 -0700 (PDT) Subject: ImageEnhance.Contrast - is this fishy or what? References: <4815ce8f-b351-4d6e-9eab-b663473f8ed4@u9g2000prd.googlegroups.com> <-OadnW9hvbHbbqrXnZ2dnUVZ_s-dnZ2d@pdx.net> Message-ID: <15c1e087-17af-4df9-b882-ae548dc0a486@j19g2000vbp.googlegroups.com> On Jun 17, 12:38?am, Scott David Daniels wrote: > > Over on image-sig, Fredrik Lundh responded: > ?> And the award for finding the oldest bug in PIL goes to... (that code > ?> was last touched in 1996). > ?> > > Congrats, roop, on getting this discovered just in the nick of time. > /me takes a bow :) From petr.messner at gmail.com Tue Jun 30 09:59:35 2009 From: petr.messner at gmail.com (Petr Messner) Date: Tue, 30 Jun 2009 15:59:35 +0200 Subject: Passing parameters for a C program in Linux. In-Reply-To: <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> <46ce0137-0e7d-4c59-95c7-43f72e90179c@k20g2000vbp.googlegroups.com> Message-ID: <67c97cd90906300659l54004ec6t86e54a42146767e@mail.gmail.com> 2009/6/30 venutaurus539 at gmail.com : ... > Can you give some more explanation about how exactly this can be > done.. Popen object enables you to run any program in a newly-created child process, write to its standard input and read from its standard and error outputs. There is an example how your test program could look like: import subprocess p = subprocess.Popen("./cli", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) result, errs = p.communicate("1\n44 33\n") assert not errs assert result.splitlines()[-1] == "Result is 77" Popen objects have also attributes stdin, stdout and stderr, you can use them if you do not want to use communicate(). Be aware that you if you call stdout.read(), it reads everything and blocks until EOF occurrs (usually until the popen-ed program quits). You can also use readline(), but this can also block until the subprocess writes any line. In cases where this could be a problem (i think this automated test programs are not that cases) polling, nonblocking I/O or threads can be used. I have pasted complete example (with a script simulating your "cli" program) here: http://paste.pocoo.org/show/125944/ PM From thaisiang at gmail.com Tue Jun 30 10:43:10 2009 From: thaisiang at gmail.com (ts) Date: Tue, 30 Jun 2009 07:43:10 -0700 (PDT) Subject: python3 fail to start Message-ID: <788ec223-9894-4168-b1f8-758cd51a47ad@r16g2000vbn.googlegroups.com> i just install the python 3.1 dmg onto my mac. when i run python3, it fail with : Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: Abort trap couldnt understand the problem. anyone can help? From pdpinheiro at gmail.com Tue Jun 30 10:52:10 2009 From: pdpinheiro at gmail.com (pdpi) Date: Tue, 30 Jun 2009 07:52:10 -0700 (PDT) Subject: Passing parameters for a C program in Linux. References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: <4c1476cc-075e-4b5b-b370-012124505902@b15g2000yqd.googlegroups.com> On Jun 30, 11:46?am, "venutaurus... at gmail.com" wrote: > Hi all, > ? ? ? ?I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1 ? ? ? ? ? ?-------Our option > Enter two numbers > 44 33 ?-------- Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. The easiest (and ugliest) way to do this would probably be to write a file input.txt and a file output.txt with each input/output value, and then to do this on the command prompt: ./a.out < input.txt | diff output.txt - this will run a.out (assuming that's your program's name), feed in input.txt as input, and pipe that into diff to compute the differences between its output and output.txt From Scott.Daniels at Acm.Org Tue Jun 30 11:00:44 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 08:00:44 -0700 Subject: identify checksum type? In-Reply-To: References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> Message-ID: <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> Christian Heimes wrote: > PK schrieb: >> Given a checksum value, whats the best way to find out what type it is? >> >> meaning. I can use hashlib module and compute a md5 or sha1 for a given data >> etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats >> the best way for me to identify if its a sha1 or md5 or anyother sum type >> for that matter? >> >> is there a nice way to do this in python? > > As far as I know there is no way to identify a checksum by its value. A > checksum is just a number. You can try an educated guess based on the > length of the checksum. Or you can try all hash algorithms until you get > a hit but that may lead to security issues. > > Some applications prefix the hash value with an identifier like "{MD5}" > or "{SHA1}". > > Christian > fortunately, the hashlib checksums can be distinguished by their length On the newly minted 3.1: import hashlib text = b'BDFL forever; FLUFL for frequently' for name in 'md5 sha1 sha224 sha256 sha384 sha512'.split(): result = getattr(hashlib, name)(text).hexdigest() print('%6s:%3d %s' % (name, len(result), result)) md5: 32 457484d2817fbe475ab582bff2014e82 sha1: 40 242076dffbd432062b439335438f08ba53387897 sha224: 56 89c0439b1cf3ec7489364a4b8e50b3ba196706eecdb5e5aec6d6290f sha256: 64 e10938435e4b5b54c9276c05d5f5d7c4401997fbd7f27f4d4...807d sha384: 96 3fe7c7bf3e83d70dba7d59c3b79f619cf821a798040be2177...edb7 sha512:128 fe50d9f0c5780edb8a8a41e317a6936ec6305d856c78ccb8e...1fa0 You'll have to guess for adler32 vs. crc32 vs. seeded crc32, ... --Scott David Daniels Scott.Daniels at Acm.Org From sk8in_zombi at yahoo.com.au Tue Jun 30 11:02:30 2009 From: sk8in_zombi at yahoo.com.au (sk8in_zombi at yahoo.com.au) Date: Tue, 30 Jun 2009 08:02:30 -0700 (PDT) Subject: Learning to use decorators with classes Message-ID: <517138.79282.qm@web54507.mail.re2.yahoo.com> --- On Tue, 30/6/09, Bruno Desthuilliers wrote: > > Don't use '__name__', they are reserved for the > implementation. And FWIW, don't use '__name' unless you have > a really compelling reason to do so. > That was an honest mistake!. Noted :) > > >? ???def search(self, **kw): > >? ? ? ???print > 'Searching' > >? ? ? ???... > > > This can't work, and it's a FAQ FWIW - but since there's no > official c.l.py FAQ, we won't hold it against you !-) > Can you please point me to the FAQ related to this snippet. I would be grateful. > def and class are both *executable* statements (yes, > classes and functions creation - like almost anything in > Python - are run-time operations). > > The first one creates a function object - *wherever* it > happens - and bind the function object to the function's > name in the current namespace. Think of it as an equivalent > of the following javascript snippet: > > ???var func_name = function(arg) { /* > function's body */ }; > > The second statement - class - builds a class object from > the names defined in the class statement's body (that is, > names defined in the class statement's body will become > attributes of the class object). > > Now about the 'methods' and 'self' stuff... > > First understand that there's *nothing* magical with > 'self'. It's *not* a keyword. It's only a naming convention, > and you could use any legal Python identified instead. > > The reason we have to explicitly mention it as first > argument of the function is that it's the only way the > function's body can get access to the current instance. What > happens is (overly simplified) that during attribute > resolution, when the found attribute happens to be a > function,? this function is wrapped - together with the > instance on which the attribute was looked up and it's class > -? into a callable method object. Then when you call > this method object, it inserts the instance as first > argument to the function call, and returns the result of the > function call (if you want to read more about this and how > computed attributes are implemented in Python, google for > 'descriptor protocol'). > > IOW, and to make a long story short, calling > instance.method is the same as calling > Class.method(instance). > > Thank you very much for your explanation. I will remember these points by heart. > Ok, now to the point: when you call getConnection within > the class statement's body, there's no magical "self" > keyword poiting to an instance, and since the class itself > doesn't yet exists, so there's *no* way you could get at an > instance of it anyway !-) > > There are many ways to solve your problem, the simplest > bing probably to write another decorator calling on the > first one, ie: > > > def connected_method(func): > ? ? def connected(self, *args, **kw): > ? ? ? ? wrapped = > getConnection(self.__this, self.__that)(func) > ? ? ? ? return wrapped(*args, **kw) > > ? ? return connected > > > Note that this may not be that efficient - you'll have > quite a few function calls involved here. > I was trying follow the concept of decorators with arguments and I can now understand why it failed, thanks. Thanks and regards, SZ Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail From esj at harvee.org Tue Jun 30 11:06:08 2009 From: esj at harvee.org (Eric S. Johansson) Date: Tue, 30 Jun 2009 11:06:08 -0400 Subject: pep 8 constants In-Reply-To: References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A4915C7.5050204@harvee.org> <4A496FE5.9060005@harvee.org> Message-ID: <4A4A29E0.6050603@harvee.org> Rhodri James wrote: > [Trimming for length, sorry if that impacts too much on intelligibility] no problem, one of the hazards of speech recognition uses you become very verbose. > This goes a long way, but it doesn't eliminate the need for some forms > of escape coming up on a moderately frequent basis. Consider "Coffee > strength equals five" for example: this could mean either > > coffee_strength = 5 > > or > > COFFEE_STRENGTH = 5 > > depending on whether we will later be using it as a constant or not. > Python doesn't have syntactic constants, which is precisely why PEP-8 > is useful. You might have enough smarts in your system for it to > remember after the first time you use "coffee strength", and it might > be unambiguous, but at the very least you need to be able to say > "Constant coffee strength equals five" first time round. right. The initial state of a symbol is always a chatty moment. It sets the context and background information for subsequent use. My initial reaction is that when you do coffee strength equals five, it would pop up a simple dialog asking variable or constant? You would say "variable" and it would format everything the right way. This is a form of interactive dialogue that would be used consistently throughout the rest of the environment. > > This isn't the only occasion when you simply don't have the context > to avoid verbal disambiguation. Are you accessing attributes of the > class MyClass or its instance my_class, for instance? In your initial > post you seemed to be claiming that having to do this disambiguation > textually was bad, and PEP-8 should therefore be rejected. Given > that I'm not prepared to lose the productivity increase that comes > with being able to disambiguate visually at a glance, I don't see > that it's avoidable. I don't mind verbal disambiguation if it's infrequent. What I object to is being forced to disambiguate every time I use a symbol. The reason being is one is a minor increase in vocal load and can be made a dumb template (maybe) where is the other is just doing a bunch of makework over and over again. As for your my class example, you never ever use my_class unless it's prefaced by an instance of the class MyClass. And if you say something like My class yields fall class or fall class is my class or fall class = my class You have sufficient information to know that my class is a class name.and that you have some number of arguments and the system can run you through a dialogue to fill in the arguments. I wish I had the tools to create a simulation of what the editing sequence with the dialog box pop-ups in nice little animated movie. Heck, if I could just capture time lapse I could do it with paper and pencil and a voiceover. It would remind you of Gumby meets South Park but... I digress > > Incidentally, since what you're proposing is essentially templating, > wouldn't it be better to do it as post-processing on the speech > recognition rather than building it directly into an editor? > to resolve if my template in, you mean a system that can receive type information from somewhere about every single symbol in the system and then load up a grammar, handle the dialogs for disambiguation at the same time as providing an editing environment that lets you refer to symbols by their verbose name instead of their codename and still operate on. For example, replace an argument should pop up a dialog box with the second argument of the first method on the line. You then can change things by their names like second string or array index. Then sure, maybe a templating system would work. But I don't think it will thank you for continuing in this dialogue. From ronn.ross at gmail.com Tue Jun 30 11:11:15 2009 From: ronn.ross at gmail.com (Ronn Ross) Date: Tue, 30 Jun 2009 11:11:15 -0400 Subject: packaging apps Message-ID: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> I have a simple application that has a glade file and a .py file. How would I package that into an installer for Windows, Mac, and a deb file? Can anyone point me in the right direction? -------------- next part -------------- An HTML attachment was scrubbed... URL: From esj at harvee.org Tue Jun 30 11:27:33 2009 From: esj at harvee.org (Eric S. Johansson) Date: Tue, 30 Jun 2009 11:27:33 -0400 Subject: pep 8 constants In-Reply-To: <4A49E232.6090101@tim.thechases.com> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> Message-ID: <4A4A2EE5.8040301@harvee.org> Tim Chase wrote: > Eric S. Johansson wrote: > np. I get this confusion often. > > While I have used SR in some testing, I've found that while it's > passable for prose (and even that, proclamations of "95% accuracy" sound > good until you realize how many words comprise 5% of your daily typing > :), it's not so good for code unless you have a very specific > programming-language+SR designed editing environment...as you've been > griping. However, the problem seems not to be PEP-8, but rather the > inabilities of your SR combined with the failings of your editor. I've been working with speech recognition for 15 years. I've written something on the order of 10,000 lines of Python code both as open source and private projects. I've tried it least two dozen editors and they all fail miserably because they're focused on keyboard use (but understandable) I get good recognition accuracy because I train the system and then I let it train me. > > For coding, you might want to investigate a tool like Dasher[1] which > offers an alternate form of input. It allows for custom > vocabularies/keymaps if you need, as well as more precise specification > of a full keyboard (caps vs. mixed-case, specific punctuation > characters, etc). The predictive entry should be smart enough to pick > up previously entered constants/terms saving you entry speed. It can > also be driven by a wide variety of pointing devices (mouse, trackball, > touchpad, head-tracker, gyro-input, etc). I've tried it, it's quite promising but my hands term are sufficiently that I can't target accurately. This is a problem for me with mice as well. Maybe these tiny little spit dot icons and webpages drive me insane because it takes me two or three tries to put the right spot. but still, you would have the basic problem of getting the information about the code into language model of dasher so it could predict what might be chosen based on the previous context. It' 80% the same work and, doesn't help those of us with really bad hands. > > You might also experiment with other editors that allow for more > efficient editing. I've tried a whole bunch, like I said at least a dozen. They all fail for first reasons such as inability to access all functionality through keystrokes (easiest interface method from speech recognition) to virtually no autoformatting or worse yet, inconsistent autoformatting. The classic example is auto indentation based on previous lines. Emacs does a relatively right. I know this is also counter to the Python way but having something marking and outdent would be really useful so that a vocal driven command to indent or outdent a block would be practical. Oh, another failure point. Have you ever tried to selected beach and by voice. I mean I should say have you ever tried to select a region by voice. Doesn't work very well. Nuance has something called selective and say but it only works in very special Windows edit controls. Or, if you're doing toolkit supports the right signals/events. Nobody does in the the linux world and it doesn't look like they support them in the Windows world either. > > Hope these give you another option to consider, if SR plus your current > editor aren't cutting it for you, maybe we should have a conversation off list about different editors if you don't mind. I'm certainly open to alternatives but, I do have fairly high standards and one of them is that ^X^S doesn't crash the editor. :-) I have been using Emacs for too many years and it is such a reflex. Another alternative would be to help fix the NaturallySpeaking Emacs gateway vr-mode. While it doesn't truly improve the problem, it makes it a little more manageable. thank you for your time From lists at cheimes.de Tue Jun 30 11:34:22 2009 From: lists at cheimes.de (Christian Heimes) Date: Tue, 30 Jun 2009 17:34:22 +0200 Subject: identify checksum type? In-Reply-To: <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> References: <5b0681910906291647n78f17c6dof991ff2fa716fe40@mail.gmail.com> <_JOdnRgRmetlu9fXnZ2dnUVZ_oadnZ2d@pdx.net> Message-ID: Scott David Daniels wrote: > fortunately, the hashlib checksums can be distinguished by their length Unfortunately the world knows more hash algorithms than the Python standard library. :) Christian From milesck at umich.edu Tue Jun 30 11:44:50 2009 From: milesck at umich.edu (Miles Kaufmann) Date: Tue, 30 Jun 2009 11:44:50 -0400 Subject: Passing parameters for a C program in Linux. In-Reply-To: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> References: <7fa13d0c-d031-4576-8fee-a1c84af3e265@y7g2000yqa.googlegroups.com> Message-ID: On Jun 30, 2009, at 6:46 AM, venutaurus539 at gmail.com wrote: > I have to write an automted script which will test my c > program. That program when run will ask for the commands. Keep in mind that, if your test script checks the program's output before giving it input, you can run into problems with buffering. The standard C library uses line-based buffering when a program is using a terminal for output, but when it's outputting to a pipe it uses block buffering. This can be a problem when running a process using subprocess--your program will buffer the prompt, and your test script won't see it, so the test will deadlock. The problem can also exist in the opposite direction. Possible solutions: - Explicitly set both your test script and your program to have line- buffered output. - Add a flush statement whenever you finish writing output and expect input. - Use pexpect, which uses a pseudo-tty and will make C stdio default to line buffering. - Use pdpi's solution, which, since it doesn't wait for a prompt before supplying input, doesn't have this issue. From lenz at joinville.udesc.br Tue Jun 30 11:51:37 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 30 Jun 2009 08:51:37 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <200906300851.37718.lenz@joinville.udesc.br> Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: > In message > d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: > > ... is there open source solution ? > > Poppler? pypdf -- http://pybrary.net/pyPdf/ A Pure-Python library built as a PDF toolkit. It is capable of: * extracting document information (title, author, ...), * splitting documents page by page, * merging documents page by page, * cropping pages, * merging multiple pages into a single page, * encrypting and decrypting PDF files. By being Pure-Python, it should run on any Python platform without any dependencies on external libraries. It can also work entirely on StringIO objects rather than file streams, allowing for PDF manipulation in memory. It is therefore a useful tool for websites that manage or manipulate PDFs. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From rhvonlehe at gmail.com Tue Jun 30 12:01:31 2009 From: rhvonlehe at gmail.com (rhvonlehe at gmail.com) Date: Tue, 30 Jun 2009 09:01:31 -0700 (PDT) Subject: using input(), raw_input() to allow user to run different functions References: Message-ID: <2916135b-530b-4493-9dcd-01242e7a1cbd@a36g2000yqc.googlegroups.com> On Jun 29, 5:22?pm, MRAB wrote: > rhvonl... at gmail.com wrote: > > Something's been giving me difficulty.. > > > We have a USB-attached device that we frequently debug with simple > > python scripts. ?The model has always been that each script logs on to > > the device, does something, then logs off. ?As it turns out, we have > > mostly written scripts as unit tests for each API command. ?So, we'll > > call one script that will configure a process on the device, and a > > separate script that will retrieve the results of that process. > > > The model is changing inside the device such that all settings will be > > lost when we log off. ?This means we'll have to merge a bunch of > > scripts in various ways. > > > I thought it would be neat if I could have one master python script do > > the logon, then allow the user to input the name of a previously- > > written script he wanted to execute while logged on. ?Finally, when > > exiting the master script, the user would logout from the device. > > > I'm trying to test this by using input() or raw_input() to get the > > function the user wants to execute. ?I'm not having much luck. ?Here's > > an example: > > > Shell.py: > > #! /usr/bin/env python > > from CollectNDResults import * > > ... > > request = input('Script shell >>> ') > > print request > > exec (request) ? ## I realize the parentheses are not needed > > ... > > > When I run Shell.py I get this: > > > Script shell >>> CollectNDResults > > > > Traceback (most recent call last): > > ? File "./Shell.py", line 35, in ? > > ? ? Shell(sys.argv[1:]) > > ? File "./Shell.py", line 24, in Shell > > ? ? exec (request) > > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > > name into the code object that I want to execute? ?Is there a better > > way to do what I'm trying to do? > > ?>>> def foo(): > ? ? ? ? print "running foo" > > ?>>> import sys > ?>>> func_name = "foo" > ?>>> getattr(sys.modules[__name__], func_name)() > running foo Excellent replies, both. I'll get a lot of mileage out of this, thanks! From javier.collado at gmail.com Tue Jun 30 12:02:53 2009 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 30 Jun 2009 18:02:53 +0200 Subject: packaging apps In-Reply-To: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> References: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> Message-ID: Hello, Regarding packaging for debian (.deb), the best reference I've found is: https://wiki.ubuntu.com/PackagingGuide/Python However, all that mess probably won't be needed anymore once this is finished: https://blueprints.edge.launchpad.net/ubuntu/+spec/desktop-karmic-automagic-python-build-system Best regards, Javier 2009/6/30 Ronn Ross : > I have a simple application that has a glade file and a .py file. How would > I package that into an installer for Windows, Mac, and a deb file? Can > anyone point me in the right direction? > > -- > http://mail.python.org/mailman/listinfo/python-list > > From jerome.fuselier at gmail.com Tue Jun 30 12:05:42 2009 From: jerome.fuselier at gmail.com (=?ISO-8859-1?Q?J=E9r=F4me_Fuselier?=) Date: Tue, 30 Jun 2009 09:05:42 -0700 (PDT) Subject: Problem with uuid package when embedding a python interpreter Message-ID: <7d5cfbf0-38d5-4505-a93a-f321d0da74b8@c36g2000yqn.googlegroups.com> Hello, I've tried to import a script in an embedded python intrepreter but this script fails when it imports the uuid module. I have a segmentation fault in Py_Finalize(). Here is a simple program which imitate my problem. main.c : #include "Python.h" void test() { Py_Initialize(); PyImport_Import(PyString_FromString("uuid")); Py_Finalize(); } main(int argc, char **argv) { for (i=0 ; i < 10; i++) test(); } For my application, I have to call Py_initialize and Py_Finalize several times so factorizing them in the main function is not an easy solution for me. The core which is produced gives me this error : Program terminated with signal 11, Segmentation fault. #0 0x00190ef6 in type_dealloc (type=0x291320) at Objects/typeobject.c: 2609 2609 _PyObject_GC_UNTRACK(type); Thanks for your help Jerome From dickinsm at gmail.com Tue Jun 30 12:08:03 2009 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 30 Jun 2009 09:08:03 -0700 (PDT) Subject: python3 fail to start References: <788ec223-9894-4168-b1f8-758cd51a47ad@r16g2000vbn.googlegroups.com> Message-ID: <577baa71-930a-4cdc-9c78-cb5df318632c@l31g2000yqb.googlegroups.com> On Jun 30, 3:43?pm, ts wrote: > i just install the python 3.1 dmg onto my mac. when i run python3, it > fail with : > > Fatal Python error: Py_Initialize: can't initialize sys standard > streams > LookupError: unknown encoding: > Abort trap > > couldnt understand the problem. anyone can help? Hmm. It's working fine for me (OS X 10.5.7/Macbook Pro). What version of OS X are you using? How are you running python3---by typing 'python3' at a Terminal prompt, I assume? What's the output of the 'locale' command on your system? Mark From lenz at joinville.udesc.br Tue Jun 30 12:37:34 2009 From: lenz at joinville.udesc.br (Eduardo Lenz) Date: Tue, 30 Jun 2009 09:37:34 -0700 Subject: Drawing in PDF In-Reply-To: References: Message-ID: <200906300937.34534.lenz@joinville.udesc.br> Em Ter 30 Jun 2009, ?s 04:19:13, Grant Edwards escreveu: > On 2009-06-30, Eduardo Lenz wrote: > > Em Seg 29 Jun 2009, ?s 20:39:22, Lawrence D'Oliveiro escreveu: > >> In message >> > >> d7fe56d0593f at g19g2000yql.googlegroups.com>, Jun wrote: > >> > ... is there open source solution ? > >> > >> Poppler? > > > > pypdf -- http://pybrary.net/pyPdf/ > > > > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > > > * extracting document information (title, author, ...), > > * splitting documents page by page, > > * merging documents page by page, > > * cropping pages, > > * merging multiple pages into a single page, > > * encrypting and decrypting PDF files. > > While it may be a pure-python library, the problem is that > AFAICT it doesn't actually solve the problem at hand. The > requirement is to "draw" on the pages of an existing PDF > document (add annotations). > > > By being Pure-Python, it should run on any Python platform > > without any dependencies on external libraries. It can also > > work entirely on StringIO objects rather than file streams, > > allowing for PDF manipulation in memory. It is therefore a > > useful tool for websites that manage or manipulate PDFs. > > True, but does it allow you to add text/lines/etc. to a page? being a pure python library makes "easy" to add those features. And also, one can ask for those features for the developers. I think that this list is a good place to point the existing solutions (not always the exact solution) and also to collect valuable information about python libraries. Please, lets keep in mind that this is not the debian list :). []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: lenz at Joinville.udesc.br --------------------------------------------- -- Esta mensagem foi verificada pelo sistema de antiv?rus e acredita-se estar livre de perigo. From python.list at tim.thechases.com Tue Jun 30 12:39:29 2009 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Jun 2009 11:39:29 -0500 Subject: pep 8 constants In-Reply-To: <4A4A2EE5.8040301@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> <4A4A2EE5.8040301@harvee.org> Message-ID: <4A4A3FC1.5000108@tim.thechases.com> > I've tried it least two dozen editors and they all fail > miserably because they're focused on keyboard use (but > understandable) [...snip...] > I've tried a whole bunch, like I said at least a dozen. They > all fail for first reasons such as inability to access all > functionality through keystrokes (easiest interface method > from speech recognition) I'm not sure I follow which you want...you kvetch that they're too focused on keyboard use, but then that you can't access all functionality through the keyboard. [warning, blatant vim fanaticism follows] I use vim and can't remember the last time I used the mouse with it (save for occasionally lazily scrolling with the mouse-wheel, but you can scroll with the keyboard too), so it meets your "must be fully accessible through the keyboard" constraint. It also has single keystroke commands for indenting/exdenting the current line as you mention: > I know this is also counter to the Python way but having > something marking and outdent would be really useful so > that a vocal driven command to indent or outdent a block > would be practical. which can be done in insert-mode with control+D, control+T, and if you want to clear all indentation (all the way back to the first column), you can use "0" followed by control+D. Vim also allows for fairly detailed control over auto-indentation settings so you can match them to your preferences. I suspect Emacs may be configurable to offer similar functionality but I'd have to defer to the emacsen on the list. That said, I'll be the first to admit that the vi/vim learning curve is more like a brick wall than a curve. However, I find the efficiency gains abundantly than repaid the time I invested to learn it well. >> Dasher[1] > > I've tried it, it's quite promising but my hands term are > sufficiently that I can't target accurately. Last I tried it, it scaled the target sizes based on probability. You might also try unconventional pointing devices for better precision. I've seen web-cam eye-tracking tools which might make it a bit easier. Or try a tablet input (where the motion corresponds linearly, as opposed to accelerated mouse motion). Such input options are listed on the Dasher website, at least for those they tested. > Oh, another failure point. Have you ever tried to selected > beach and by voice. I mean I should say have you ever tried to > select a region by voice. yes, not a pleasant experience. Again, vim's modal interface allows for using text-objects so you can issue short-hand commands like ci" to "[c]hange the contents [i]nside the double-quotes I'm currently on/withing". The operator+motion and operator+textobject command syntax obviates a lot selection. While vim does offer a "visual" mode (akin to selection in other editors), I use it much less because of the power provided by the operator+[motion/textobject]. > maybe we should have a conversation off list about different > editors if you don't mind. I'm certainly open to alternatives > but, I do have fairly high standards and one of them is that > ^X^S doesn't crash the editor. :-) I have been using Emacs for > too many years and it is such a reflex. as you're an emacs user, my vim suggestions may sound like heresy. ;-) But I suspect a skilled emacs user (or perhaps asking on an emacs-users list) could mimic much of the vim functionality. I just can't be of much assistance there. You're welcome to move it off-list...it's kinda drifted from python to general accessibility issues. CC'ing c.p.l for this one in case any emacsen care to chime in on their suggested tweaks. -tkc From skip at pobox.com Tue Jun 30 12:48:29 2009 From: skip at pobox.com (skip at pobox.com) Date: Tue, 30 Jun 2009 11:48:29 -0500 Subject: Timeout when connecting to sybase DBS In-Reply-To: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> References: <2dc9f53f-acc0-44cd-9b5b-7062ab401030@a38g2000yqc.googlegroups.com> Message-ID: <19018.16861.439118.984635@montanaro.dyndns.org> Gil> I have looked for a timeout parameter to limit the 4 minutes to Gil> something more reasonable but couldn't find one. Can anyone please Gil> help? Gil> BTW, I'm using Sybase.connect(, , , Gil> datetime='auto') We use the Sybase module where I work, but I've never encountered this problem (or a timeout parameter of any kind). At any rate, you'll probably have more luck asking on the python-sybase mailing list: python-sybase-misc at lists.sourceforge.net -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org From fetchinson at googlemail.com Tue Jun 30 12:56:19 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 30 Jun 2009 09:56:19 -0700 Subject: ANN: Package Manager GUI for Python (Windows) In-Reply-To: References: <976cc575-80b9-406a-ae4d-03cb4d401dc4@p36g2000prn.googlegroups.com> Message-ID: > Hi All, > > I'm pleased to announce a GUI package manager (v 0.12) for > Python versions 2.x under Windows. > > http://sourceforge.net/projects/pythonpkgmgr/ > > It's tightly linked to the pypi repository and offers > the following functions: > > - search packages on pypi by name > > - install (via easyinstall or pip) > > - deinstall/remove packages > > - see package documentation > > - see package examples > > - install .EGG packages > > - Generate package manifest > > If you find any issues, please don't hesitate to report > them via our tracker on the project page. Another time machine! The Release Notes for version 0.11 on http://www.preisshare.net/pythonpkgmgr/ says it was released on 10/09/09 :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jenn.duerr at gmail.com Tue Jun 30 13:27:57 2009 From: jenn.duerr at gmail.com (noydb) Date: Tue, 30 Jun 2009 10:27:57 -0700 (PDT) Subject: string character count Message-ID: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> If I have a string for a file name such that I want to find the number of characters to the left of the dot, how can that be done? I did it this way: x = "text12345.txt" dot = x.find('.') print dot Was curious to see what method others would use - helps me learn. I guess I was most curious to see if it could be done in one line. And, how would a char count be done with no dot -- like if the string were "textstringwithoutdot" or "no dot in text string"? From jayshree06comp at gmail.com Tue Jun 30 13:43:23 2009 From: jayshree06comp at gmail.com (jayshree) Date: Tue, 30 Jun 2009 10:43:23 -0700 (PDT) Subject: python+encryption Message-ID: I have the key pair generated by the GPG. Now I want to use the public key for encrypting the password. I need to make a function in Python. Can somebody guide me on how to do this ? to encrypt password by the public key ..how can i do this ,which library is best and easy to prefer.i have to work on ssh secure shell client. thanks From bieffe62 at gmail.com Tue Jun 30 13:44:35 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Tue, 30 Jun 2009 10:44:35 -0700 (PDT) Subject: Unexpected behaviour of inner functions/ decorators Message-ID: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Hi all, I found a strange (for me) behaviour of inner function. If I execute the following code: # file in_f.py ----------- def dec_f(f): def inner_f(): if f.enabled: f() return inner_f @dec_f def funct(): print "Ciao" funct.enabled = True funct() # end of file ----------------- I get the following exception: File "/Users/fb/Documents/Prove python/in_f.py", line 15, in funct() File "/Users/fb/Documents/Prove python/in_f.py", line 5, in inner_f if f.enabled: AttributeError: 'function' object has no attribute 'enabled' The same happens when I rebind explicitely the function name instead of using the decorator: def funct(): print "Ciao" funct = dec_f(funct) It looks like the decorator uses an older instance of 'funct', which does not yet have the attribute dinamically attached to it. This seem to be confirmed by the fact that adding the attribute before rebinding the function name, the problem disappear: def funct(): print "Ciao" funct.enabled = False # this fixes the problem funct = dec_f(funct) So I have a workaround, but still don't understant why the original code does not work. Anyone can point me to an explanation? Thanks in advance Ciao ------- FB From python at mrabarnett.plus.com Tue Jun 30 13:56:39 2009 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Jun 2009 18:56:39 +0100 Subject: string character count In-Reply-To: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> Message-ID: <4A4A51D7.6040602@mrabarnett.plus.com> noydb wrote: > If I have a string for a file name such that I want to find the number > of characters to the left of the dot, how can that be done? > > I did it this way: > x = "text12345.txt" > dot = x.find('.') > print dot > > Was curious to see what method others would use - helps me learn. I > guess I was most curious to see if it could be done in one line. > >>> print "text12345.txt".find('.') 9 > And, how would a char count be done with no dot -- like if the string > were "textstringwithoutdot" or "no dot in text string"? If there's no dot then find() returns -1. If you wanted to know the number of characters before the dot, if present, or in total otherwise, then you could use split(): >>> len("text12345.txt".split(".", 1)[0]) 9 >>> len("textstringwithoutdot".split(".", 1)[0]) 20 From gagsl-py2 at yahoo.com.ar Tue Jun 30 14:02:13 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 15:02:13 -0300 Subject: Problem with uuid package when embedding a python interpreter References: <7d5cfbf0-38d5-4505-a93a-f321d0da74b8@c36g2000yqn.googlegroups.com> Message-ID: En Tue, 30 Jun 2009 13:05:42 -0300, J?r?me Fuselier escribi?: > I've tried to import a script in an embedded python intrepreter but > this script fails when it imports the uuid module. I have a > segmentation fault in Py_Finalize(). > > #include "Python.h" > > void test() { > Py_Initialize(); > PyImport_Import(PyString_FromString("uuid")); > Py_Finalize(); > } > > main(int argc, char **argv) > { > for (i=0 ; i < 10; i++) > test(); > } > > For my application, I have to call Py_initialize and Py_Finalize > several times so factorizing them in the main function is not an easy > solution for me. Are you sure you can't do that? Not even using Py_IsInitialized? Try to avoid repeatedly calling Py_Initialize - won't work. Python 2.x does not have a way to "un-initialize" an extension module (that's a big flaw in Python design). Modules that contain global state are likely to crash the interpreter when used by the second time. (Python 3 attempts to fix that) -- Gabriel Genellina From kaffeen at gmail.com Tue Jun 30 14:02:21 2009 From: kaffeen at gmail.com (kaffeen) Date: Tue, 30 Jun 2009 13:02:21 -0500 Subject: Noob Message-ID: Hello all, just joined this list and am just beginning to learn Python. Thanks to everyone for making this a great place to learn and their contributions. As mentioned, I'm new to Python (but have experience with other programming languages/scripting). I have a couple of questions... 1) Where might I find a comprehensive list of changes between Python 2.x and 3.x? 2) What are the differences between IPython and IDLE, is one better than the other, why? 3) Is there an IDE for Python development, which is the best? 4) I can't seem to install IPython for my 3.x branch (and I did install readline), I get the following error via Windows executable installation, *** run_installscript: internal error 0xFFFFFFFF ***.........it installs fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If not compatible, is there a timeline for compatibility? Regards, ~kaffeen -- If you understand, things are just as they are. If you do not understand, things are just as they are. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dstanek at dstanek.com Tue Jun 30 14:12:40 2009 From: dstanek at dstanek.com (David Stanek) Date: Tue, 30 Jun 2009 14:12:40 -0400 Subject: Unexpected behaviour of inner functions/ decorators In-Reply-To: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> References: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Message-ID: On Tue, Jun 30, 2009 at 1:44 PM, Francesco Bochicchio wrote: > [snip] > It looks like the decorator uses an older ?instance of 'funct', which > does not yet > have the attribute dinamically attached to it. This seem to be > confirmed by the fact that adding the attribute before > rebinding the function name, the problem disappear: The decorator is using the original function that you defined. By decorating 'funct' you are actually rebinding that name to the 'inner_f' function. So the statement 'funct.enabled = True' is actually creating an enabled property on the 'inner_f' function. Take a look at this code: >>> def def_f(f): ... def inner_f(): ... if iam.enabled: ... f() ... iam = inner_f ... return inner_f ... >>> @def_f ... def funct(): ... print 'Ciao' ... >>> funct.enabled = True >>> funct() Ciao -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek From cripplemeal at gmail.com Tue Jun 30 14:15:24 2009 From: cripplemeal at gmail.com (Crip) Date: Tue, 30 Jun 2009 11:15:24 -0700 (PDT) Subject: Python/Pygame question Message-ID: I have been experimenting with pygame. I would like to know how to go about placing an image of my creation as the background of the generated window. To where should I save the image, and what should it be saved as? From Scott.Daniels at Acm.Org Tue Jun 30 14:27:09 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 11:27:09 -0700 Subject: Unexpected behaviour of inner functions/ decorators In-Reply-To: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> References: <71c7d899-dea9-4999-b318-20b9afebf08d@n11g2000yqb.googlegroups.com> Message-ID: Francesco Bochicchio wrote: > def dec_f(f): > def inner_f(): > if f.enabled: > f() > return inner_f > @dec_f > def funct(): > print "Ciao" The three lines above should behave a lot like: def funct_original(): print "Ciao" funct = dec_f(funct_original) > funct.enabled = True > funct() This is decorating "funct", but inner_f is testing the argument it was passed (funct_original), not inner_f (which is now called funct). No wonder it finds no "enabled" attribute. > So I have a workaround, but still don't understant why the original > code does not work. > Anyone can point me to an explanation? So, you can fix this like so: def dec_f(f): def inner_f(): if inner_f.enabled: f() return inner_f Or even: def dec_f(f): def inner_f(): if inner_f.enabled: f() inner_f.enabled = False return inner_f Thus testing the thing that you were marking with funct.enabled = True. Does this help explain? --Scott David Daniels Scott.Daniels at Acm.Org From benjamin at python.org Tue Jun 30 14:32:14 2009 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 30 Jun 2009 18:32:14 +0000 (UTC) Subject: python+encryption References: Message-ID: jayshree gmail.com> writes: > > I have the key pair generated by the GPG. Now I want to use the public > key for encrypting the password. I need to make a function in Python. > Can somebody guide me on how to do this ? PyCrypto From gagsl-py2 at yahoo.com.ar Tue Jun 30 14:39:29 2009 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Jun 2009 15:39:29 -0300 Subject: Noob References: Message-ID: En Tue, 30 Jun 2009 15:02:21 -0300, kaffeen escribi?: > Hello all, just joined this list and am just beginning to learn Python. > Thanks to everyone for making this a great place to learn and their > contributions. Welcome! > As mentioned, I'm new to Python (but have experience with other > programming > languages/scripting). I have a couple of questions... > > 1) Where might I find a comprehensive list of changes between Python 2.x > and > 3.x? You may read the "What's new?" documents for 3.0 and 3.1: http://docs.python.org/3.1/whatsnew/index.html If you're learning Python the differences aren't so important now (the most obvious being that the print statement becomes a function). If you're using a book covering Python 2.x, install the latest on that series (2.6.2). Support for Python 3 is increasing but many 3rd party libraries have not been ported yet. > 3) Is there an IDE for Python development, which is the best? Look in the wiki: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments or search past messages in this list. The topic arises every two months or so. There is no definitive answer. > 4) I can't seem to install IPython for my 3.x branch (and I did install > readline), I get the following error via Windows executable installation, > *** run_installscript: internal error 0xFFFFFFFF ***.........it installs > fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If > not > compatible, is there a timeline for compatibility? Ask the IPython team; but unless a project explicitely states that it's compatible with Python 3, you should assume it isn't. -- Gabriel Genellina From SridharR at activestate.com Tue Jun 30 15:20:46 2009 From: SridharR at activestate.com (Sridhar Ratnakumar) Date: Tue, 30 Jun 2009 12:20:46 -0700 Subject: ANN: ActivePython 3.1.0.1 is now available Message-ID: I'm happy to announce that ActivePython 3.1.0.1 is now available for download from: http://www.activestate.com/activepython/python3/ This is a major release that updates ActivePython3 to core Python 3.1. What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. 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. See this page for full details: http://docs.activestate.com/activepython/3.1/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/3.1/ 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") Extra Bits ---------- ActivePython releases also include the following: - ActivePython31.chm: An MS compiled help collection of the full ActivePython documentation set. Linux users of applications such as xCHM might find this useful. This package is installed by default on Windows. Extra bits are available from: http://downloads.activestate.com/ActivePython/etc/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From tjreedy at udel.edu Tue Jun 30 15:32:57 2009 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 30 Jun 2009 15:32:57 -0400 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: <4A4971DD.9080707@ilm.com> References: <4A4963E9.30202@ilm.com> <4A4971DD.9080707@ilm.com> Message-ID: I do not like top posting. Some thoughts in randon order: Introspection is version-specific. Call-time introspection is different from definition-time introspection. Do what is easy and works. Do not use recipes that depend on version-specific stuff you do not understand. Code objects, I believe, know the names of parameters. That question and responses were only about methods, not non-class functions. You get to match these responses to your post ;-). Terry David Hirschfield wrote: > Yeah, it definitely seems like having two separate decorators is the > solution. But the strange thing is that I found this snippet after some > deep googling, that seems to do something *like* what I want, though I > don't understand the descriptor stuff nearly well enough to get what's > happening: > > http://stackoverflow.com/questions/306130/python-decorator-makes-function-forget-that-it-belongs-to-a-class > > > answer number 3, by ianb. It seems to indicate there's a way to > introspect and determine the class that the function is going to be > bound to...but I don't get it, and I'm not sure it's applicable to my case. > > I'd love an explanation of what is going on in that setup, and if it > isn't usable for my situation, why not? > Thanks again, > -David > > Terry Reedy wrote: >> David Hirschfield wrote: >>> I'm having a little problem with some python metaprogramming. I want >>> to have a decorator which I can use either with functions or methods >>> of classes, which will allow me to swap one function or method for >>> another. It works as I want it to, except that I want to be able to >>> do some things a little differently depending on whether I'm swapping >>> two functions, or two methods of a class. >> >> Unbounds methods are simply functions which have become attributes of >> a class. Especially in Py3, there is *no* difference. >> >> Bound methods are a special type of partial function. In Python, both >> are something else, though still callables. Conceptually, a partial >> function *is* a function, just with fewer parameters. >> >>> Trouble is, it appears that when the decorator is called the function >>> is not yet bound to an instance, so no matter whether it's a method >>> or function, it looks the same to the decorator. >> >> Right. Whether it is an A or an A, it looks like an A. >> >> Worse: when the decorator is called, there is no class for there to be >> instances of. >>> >>> This simple example illustrates the problem: >> >> Add a second parameter to tell the decorator which variant of behavior >> you want. Or write two variations of the decorator and use the one you >> want. >> >> tjr >> > From ziade.tarek at gmail.com Tue Jun 30 15:41:48 2009 From: ziade.tarek at gmail.com (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Tue, 30 Jun 2009 21:41:48 +0200 Subject: PEP 376 Message-ID: <94bdd2610906301241i6607ea27l19b7c7625dc328@mail.gmail.com> Hello, I would like to propose this PEP for inclusion into Python 2.7 / 3.2 http://www.python.org/dev/peps/pep-0376/ It has been discussed a lot already in the distutils-SIG, but new feedbacks are welcome there's an implementation prototype here : http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py Regards Tarek -- Tarek Ziad? | http://ziade.org From beni.cherniavsky at gmail.com Tue Jun 30 16:24:15 2009 From: beni.cherniavsky at gmail.com (Beni Cherniavsky) Date: Tue, 30 Jun 2009 13:24:15 -0700 (PDT) Subject: It's ... References: Message-ID: On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote: > Also note that you can iterate over a file several times: > > f = open('foo.txt') > for line in f: > print line[0] # prints the first character of every line > for line in f: > print line[1] #prints the second character of every line > No, you can't. The second loop prints nothing! A file by default advances forward. Once you reach the end, you stay there. You could explicitly call f.seek(0, 0) to rewind it. Note that not all file objects are seekable (e.g. pipes and sockets aren't). The cleaner way to read a regular file twice is to *open* it time: for line in open('foo.txt'): print line[0] # prints the first character of every line for line in open('foo.txt'): print line[1] # prints the second character of every line Quick recap for Angus: for loops work on "iterables" - objects that can be asked for an "iterator". Python iterators are unseekable - once exhausted they stay empty. Most iterables (e.g. lists) return a new iterator every time you ask, so you can iterate over the same data many times. But if you already have an iterator, you can use it in a for loop - when asked for an iterator, it will offer itself (in other words an iterator is a degenerate kind of iterable). This is what happened with the file object - it's an iterator and can't be reused. Reusing the same iterator between for loops is sometimes useful if you exit the first loop mid-way: f = open('foo.mail') # skip headers until you see an empty line for line in f: if not line.strip(): break # print remainer or file for line in f: sys.stdout.write(line) P.S. Warning: after you use ``for line in f``, it's dangerous to use ``f.read()`` and ``f.readline()`` (buffering mess - just don't.) > Glad you're enjoying Beazley. ?I would look for something more > up-to-date. ?Python's come a long way since 2.1. ?I'd hate for you to > miss out on all the iterators, booleans, codecs, subprocess, yield, > unified int/longs, decorators, decimals, sets, context managers and > new-style classes that have come since then. > Seconded - 2.1 is ancient. If you continue with the book, here is a quick list of the most fundamental improvements to keep in mind: 1. Iterators, generators, generator expressions. 2. Working nested scopes. 3. Decorators. 4. with statement. 5. set & bool types. 6. Descriptors (if confusing, just understand properties). 7. from __future__ import division, // operator. and the most refreshing modules added: - subprocess - ctypes - itertools - ElementTree - optparse and not new but I just love introducing it people: - doctest From pruebauno at latinmail.com Tue Jun 30 16:43:03 2009 From: pruebauno at latinmail.com (nn) Date: Tue, 30 Jun 2009 13:43:03 -0700 (PDT) Subject: string character count References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> Message-ID: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> On Jun 30, 1:56?pm, MRAB wrote: > noydb wrote: > > If I have a string for a file name such that I want to find the number > > of characters to the left of the dot, how can that be done? > > > I did it this way: > > x = "text12345.txt" > > dot = x.find('.') > > print dot > > > Was curious to see what method others would use - helps me learn. ?I > > guess I was most curious to see if it could be done in one line. > > ?>>> print "text12345.txt".find('.') > 9 > > > And, how would a char count be done with no dot -- like if the string > > were "textstringwithoutdot" or "no dot in text string"? > > If there's no dot then find() returns -1. > > If you wanted to know the number of characters before the dot, if > present, or in total otherwise, then you could use split(): > > ?>>> len("text12345.txt".split(".", 1)[0]) > 9 > ?>>> len("textstringwithoutdot".split(".", 1)[0]) > 20 Also: len("text12345.txt".partition('.')[0]) 9 From MLMLists at Comcast.net Tue Jun 30 16:49:34 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 16:49:34 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: In Python 3, how should super() be used to invoke a method defined in C that overrides its two superclasses A and B, in particular __init__? class A: def __init__(self): print('A') class B: def __init__(self): print('B') class C(A, B): def __init__(self): super().__init__() print('C') C() Output is: A C I've discovered the surprising fact described in the documentation of super that specifying a class as the first argument of super means to skip that class when scanning the mro so that if C.__init__ includes the line super(A, self).__init__() what gets called is B.__init__, so that if I want to call __init__ of both classes the definition of C should have both of the following lines: super().__init__() super(A, self).__init__() and that super(B, self).__init__() does nothing because B is the last class in the mro. This seems weird. Would someone please give a clear example and explanation of the recommended way of initializing both superclasses in a simple multiple inheritance situation? Note: I am EXTREMELY knowledgeable about OO, Python, and many OOLs. I don't mean to be arrogant, I just want to focus the discussion not open it to a broad interchange about multiple inheritance, the ways it can be used or avoided, etc. I just want to know how to use super. The documentation states the following: "There are two typical use cases for super. In a class hierarchy with single inheritance, super can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable." "The second use case is to support cooperative multiple inheritance in a dynamic execution environment. This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance. This makes it possible to implement "diamond diagrams" where multiple base classes implement the same method." "For both use cases, a typical superclass call looks like this: class C(B): def method(self, arg): super().method(arg) # This does the same thing as: # super(C, self).method(arg) " Though it claims to be demonstrating both cases, it is only demonstrating single inheritance and a particular kind of multiple inheritance where the method is found in only one class in the mro. This avoids situations where you want to call the method anywhere it is found in the mro, or at least in the direct superclasses. Perhaps __init__ is a special case, but I don't see how to figure out how to __init__ two superclasses of a class from the documentation. I often file "bug reports" about documentation ambiguities, vagueness, incompletenesses, etc., but I don't want to do so for this case until I've heard something definitive about how it should be handled. Thanks in advance. From shaibani at ymail.com Tue Jun 30 18:20:59 2009 From: shaibani at ymail.com (Ala) Date: Tue, 30 Jun 2009 23:20:59 +0100 Subject: Ubigraph vs Matplotlib (dynamic plotting, event handling) Message-ID: <300620092320590209%shaibani@ymail.com> Hello everyone, I intend to use python for some network graph plotting, with event handling (clicking on network nodes, zooming in/out etc..) and so far I have come across two good candidates which are Matplotlib and Ubigraph. Did anyone have any experience with either of them for dynamic plotting (a slider bar on a Qt interface causing the graph to be replotted for each value for example), as well as event handling? (it seems on first notice that Ubigraph will have an upperhand on that), as well as event handling such as mouse clicks? (on this one Matplotlib has good documentation showing it does achieve that while I find ubigraph's documentation lacking, but I'd preffere to have the opinion of those who have used them before). Thank you. From cs at zip.com.au Tue Jun 30 18:39:41 2009 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 1 Jul 2009 08:39:41 +1000 Subject: handling https sites In-Reply-To: Message-ID: <20090630223941.GA8395@cskk.homeip.net> On 26Jun2009 09:34, cgoldberg wrote: | > Is there any module in python to open https | > sites through a proxy. | | yes, you can use "urllib2". | | from the urllib2 docs: | "The default is to read the list of proxies from the environment | variables" | | So if you have a proxy setup, it should detect it from your | environment vars. If you want to specify something different, you | want to build an opener with a ProxyHandler: | | http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler Except that HTTPS through a proxy doesn't work: http://bugs.python.org/issue1424152 There's a patch under review. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From pavlovevidence at gmail.com Tue Jun 30 18:52:04 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 15:52:04 -0700 (PDT) Subject: PEP 376 References: Message-ID: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> On Jun 30, 12:41?pm, Tarek Ziad? wrote: > Hello, > > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > http://www.python.org/dev/peps/pep-0376/ > > It has been discussed a lot already in the distutils-SIG, but new > feedbacks are welcome > > there's an implementation prototype here :http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py +1 This seems to be a well-designed solution that corrects the ad-hoc- ness of installation while keeping its effects on existing tools small. I hate those egg-info files but I would be very happy if they'd at least always be in an accounted-for place. Maybe I'd even consider making use of them some day. As for setuptools, I'm sure it will accommodate the change and probably improve itself in the process. (And if the setuptools doesn't change then some other tool will grow into its niche; either way it'd be an improvement.) Carl Banks From emile at fenx.com Tue Jun 30 18:58:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Jun 2009 15:58:17 -0700 Subject: string character count In-Reply-To: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> Message-ID: <4A4A9889.30606@fenx.com> On 6/30/2009 1:43 PM nn said... > On Jun 30, 1:56 pm, MRAB wrote: >> >>> len("text12345.txt".split(".", 1)[0]) >> 9 >> >>> len("textstringwithoutdot".split(".", 1)[0]) >> 20 > > Also: > > >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> unless you've got file names like text.12345.txt, where you might prefer rpartition. >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> Emile From emile at fenx.com Tue Jun 30 18:58:17 2009 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Jun 2009 15:58:17 -0700 Subject: string character count In-Reply-To: <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> References: <58ceecd5-6d2c-44a9-8ef9-01feac5792f4@b9g2000yqm.googlegroups.com> <9ab32449-4e86-4be1-8767-c25d2a06a0c7@j12g2000vbl.googlegroups.com> Message-ID: <4A4A9889.30606@fenx.com> On 6/30/2009 1:43 PM nn said... > On Jun 30, 1:56 pm, MRAB wrote: >> >>> len("text12345.txt".split(".", 1)[0]) >> 9 >> >>> len("textstringwithoutdot".split(".", 1)[0]) >> 20 > > Also: > > >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> unless you've got file names like text.12345.txt, where you might prefer rpartition. >>> len("text.12345.txt".partition('.')[0]) 4 >>> len("text.12345.txt".rpartition('.')[0]) 10 >>> Emile From python at mrabarnett.plus.com Tue Jun 30 19:06:48 2009 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Jul 2009 00:06:48 +0100 Subject: pep 8 constants In-Reply-To: <4A4A2EE5.8040301@harvee.org> References: <49a50517$0$3567$426a74cc@news.free.fr> <4A477991.4050109@harvee.org> <4A484C07.9050800@harvee.org> <4A48A495.7040504@tim.thechases.com> <4A48E307.50804@harvee.org> <4A49E232.6090101@tim.thechases.com> <4A4A2EE5.8040301@harvee.org> Message-ID: <4A4A9A88.2040302@mrabarnett.plus.com> Eric S. Johansson wrote: > > I've been working with speech recognition for 15 years. I've written something > on the order of 10,000 lines of Python code both as open source and private > projects. I've tried it least two dozen editors and they all fail miserably > because they're focused on keyboard use (but understandable) I get good > recognition accuracy because I train the system and then I let it train me. > A bit OT, but relevant(ish): Microsoft Vista Speech Recognition Tested - Perl Scripting http://www.youtube.com/watch?v=KyLqUf4cdwc From Scott.Daniels at Acm.Org Tue Jun 30 19:49:18 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 16:49:18 -0700 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Mitchell L Model wrote: > In Python 3, how should super() be used to invoke a method defined in C > that overrides its two superclasses A and B, in particular __init__? > ... > I've discovered the surprising fact described in the documentation of super > > that specifying a class as the first argument of super means to skip that class when > scanning the mro so that .... > > This seems weird. Would someone please give a clear example and explanation of > the recommended way of initializing both superclasses in a simple multiple inheritance > situation? OK, in Diamond inheritance in Python (and all multi-inheritance is diamond-shaped in Python), the common ancestor must have a method in order to properly use super. The mro is guaranteed to have the top of the split (C below) before its children in the mro, and the join point (object or root below) after all of the classes from which it inherits. So, the correct way to do what you want: class A: def __init__(self): super().__init__() print('A') class B: def __init__(self): super().__init__() print('B') class C(A, B): def __init__(self): super().__init__() print('C') C() And, if you are doing it with a message not available in object: class root: def prints(self): print('root') # or pass if you prefer class A(root): def prints(self): super().prints() print('A') class B(root): def prints(self): super().prints() print('B') class C(A, B): def prints(self): super().prints() print('C') C().prints() --Scott David Daniels Scott.Daniels at Acm.Org From sato.photo at gmail.com Tue Jun 30 20:23:42 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Tue, 30 Jun 2009 17:23:42 -0700 (PDT) Subject: MIT OpenCourseWare Introduction to Computer Science and Programming Message-ID: I am wondering if anyone else is also going through the MIT OpenCourseWare Intro to CS class. http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/CourseHome/index.htm I've been doing the assignments and, as this class didn't include any answer key, was hoping to see what others did and perhaps collaborate on assignments. -Daniel From MLMLists at Comcast.net Tue Jun 30 20:34:02 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 20:34:02 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Allow me to add to my previous question that certainly the superclass methods can be called explicitly without resorting to super(), e.g.: class C(A, B): def __init__(self): A.__init__(self) B.__init__(self) My question is really whether there is any way of getting around the explicit class names by using super() and if not, shouldn't the documentation of super point out that if more than one class on the mro defines a method only the first will get called? What's strange is that it specifically mentions diamond patterns, which is an important case to get right, but it doesn't show how. I suspect we should have a Multiple Inheritance HOWTO, though details and recommendations would be controversial. I've accumulated lots of abstract examples along the lines of my question, using multiple inheritance both to create combination classes (the kinds that are probably best done with composition instead of inheritance) and mixins. I like mixins, and I like abstract classes. And yes I understand the horrors of working with a large component library that uses mixins heavily, because I've experienced many of them, going all the way back to Lisp-Machine Lisp's window system with very many combo classes such as FancyFontScrollingTitledMinimizableWindow, or whatever. Also, I understand that properties might be better instead of multiple inheritance for some situations. What I'm trying to do is puzzle out what the reasonable uses of multiple inheritance are in Python 3 and how classes and methods that follow them should be written. From sato.photo at gmail.com Tue Jun 30 20:36:20 2009 From: sato.photo at gmail.com (sato.photo at gmail.com) Date: Tue, 30 Jun 2009 17:36:20 -0700 (PDT) Subject: MIT OpenCourseWare Introduction to Computer Science and Programming References: Message-ID: I should note that the course utilized python when teaching computer science. On Jun 30, 5:23?pm, "sato.ph... at gmail.com" wrote: > I am wondering if anyone else is also going through the MIT > OpenCourseWare Intro to CS class. > > http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science... > > I've been doing the assignments and, as this class didn't include any > answer key, was hoping to see what others did and perhaps collaborate > on assignments. > > -Daniel From ziade.tarek at gmail.com Tue Jun 30 20:47:51 2009 From: ziade.tarek at gmail.com (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Wed, 1 Jul 2009 02:47:51 +0200 Subject: PEP 376 In-Reply-To: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> References: <6afbfab3-7dcc-4ffc-a475-11dc51ad06aa@k20g2000vbp.googlegroups.com> Message-ID: <94bdd2610906301747h7b805012xb42cd80a89727ec8@mail.gmail.com> On Wed, Jul 1, 2009 at 12:52 AM, Carl Banks wrote: > On Jun 30, 12:41?pm, Tarek Ziad? wrote: >> Hello, >> >> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >> >> http://www.python.org/dev/peps/pep-0376/ >> >> It has been discussed a lot already in the distutils-SIG, but new >> feedbacks are welcome >> >> there's an implementation prototype here :http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py > > +1 > > This seems to be a well-designed solution that corrects the ad-hoc- > ness of installation while keeping its effects on existing tools > small. > > I hate those egg-info files but I would be very happy if they'd at > least always be in an accounted-for place. ?Maybe I'd even consider > making use of them some day. > > As for setuptools, I'm sure it will accommodate the change and > probably improve itself in the process. ?(And if the setuptools > doesn't change then some other tool will grow into its niche; either > way it'd be an improvement.) > Yes exactly, the plan is to try to make distutils a reference layer for third party package managers and if possible to become a "smaller" package later on the road. Cheers Tarek From pavlovevidence at gmail.com Tue Jun 30 20:50:20 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 17:50:20 -0700 (PDT) Subject: Determining if a function is a method of a class within a decorator References: Message-ID: On Jun 29, 6:01?pm, David Hirschfield wrote: > So is there > a pattern I can follow that will allow me to determine whether the > objects I'm given are plain functions or belong to a class? > > Thanks in advance, class HomemadeUnboundMethod(object): def __init__(self,func): self.func = func def __call__(self,*args,**kwargs): print "is a function: %s" % self.func.func_name return self.func(*args,**kwargs) def __get__(self,obj,owner): return HomemadeBoundMethod(obj,self.func) class HomemadeBoundMethod(object): def __init__(self,obj,func): self.obj = obj self.func = func def __call__(self,*args,**kwargs): print "is a method: %s" % self.func.func_name return self.func(self.obj,*args,**kwargs) class A(object): @HomemadeUnboundMethod def method(self): pass @HomemadeUnboundMethod def function(): pass A().method() function() Just override the __call__ functions to do what you want the decorated function to do. There are other little improvements you might make (account for the owner parameter of __get__ for instance) but you get the idea. Carl Banks From ldo at geek-central.gen.new_zealand Tue Jun 30 20:55:17 2009 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 01 Jul 2009 12:55:17 +1200 Subject: PEP 376 References: Message-ID: In message , Tarek Ziad? wrote: > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > http://www.python.org/dev/peps/pep-0376/ Why are you using MD5? From pavlovevidence at gmail.com Tue Jun 30 21:03:00 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:03:00 -0700 (PDT) Subject: PEP 376 References: Message-ID: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> On Jun 30, 5:55?pm, Lawrence D'Oliveiro wrote: > In message , Tarek > > Ziad? wrote: > > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > >http://www.python.org/dev/peps/pep-0376/ > > Why are you using MD5? I doubt it's the design aim for eggs to be cryptographically secure, and MD5 is sufficient to detect changes. Carl Banks From norseman at hughes.net Tue Jun 30 21:08:44 2009 From: norseman at hughes.net (norseman) Date: Tue, 30 Jun 2009 18:08:44 -0700 Subject: csv blank fields In-Reply-To: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> References: <1cbd6f830906270544h4f3a92baqea196123b491ae5b@mail.gmail.com> Message-ID: <4A4AB71C.4000608@hughes.net> Mag Gam wrote: > I am using the csv package to parse a compressed .csv.gz file. So far > its working perfectly fine but it fails when I have a missing value in > on of the fields. > > For example, I have this > > Abc,def,,jkl > > Is it possible to fill the missing column with a null? > > I want, > Abc,def,NULL,jkl > > TIA ======================== Ideally you need to test each field for a zero length and put at least a single space in any that are BEFORE porting to another format. If you are going to a fixed field format (SDF) then place that field's width spaces into the SDF field. In any case, DO NOT USE NULLS! There are many programs that will crash on them. HTH Steve From davidh at ilm.com Tue Jun 30 21:14:11 2009 From: davidh at ilm.com (David Hirschfield) Date: Tue, 30 Jun 2009 18:14:11 -0700 Subject: Determining if a function is a method of a class within a decorator In-Reply-To: References: Message-ID: <4A4AB863.1020205@ilm.com> Unfortunately that still requires two separate decorators, when I was hoping there was a way to determine if I was handed a function or method from within the same decorator. Seems like there really isn't, so two decorators is the way to go. Thanks, -David Carl Banks wrote: > On Jun 29, 6:01 pm, David Hirschfield wrote: > >> So is there >> a pattern I can follow that will allow me to determine whether the >> objects I'm given are plain functions or belong to a class? >> >> Thanks in advance, >> > > > > class HomemadeUnboundMethod(object): > def __init__(self,func): > self.func = func > def __call__(self,*args,**kwargs): > print "is a function: %s" % self.func.func_name > return self.func(*args,**kwargs) > def __get__(self,obj,owner): > return HomemadeBoundMethod(obj,self.func) > > class HomemadeBoundMethod(object): > def __init__(self,obj,func): > self.obj = obj > self.func = func > def __call__(self,*args,**kwargs): > print "is a method: %s" % self.func.func_name > return self.func(self.obj,*args,**kwargs) > > class A(object): > @HomemadeUnboundMethod > def method(self): pass > > @HomemadeUnboundMethod > def function(): pass > > A().method() > function() > > > > Just override the __call__ functions to do what you want the decorated > function to do. There are other little improvements you might make > (account for the owner parameter of __get__ for instance) but you get > the idea. > > > Carl Banks > -- Presenting: mediocre nebula. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Tue Jun 30 21:23:11 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:23:11 -0700 (PDT) Subject: invoking a method from two superclasses References: Message-ID: <31fe4bef-6738-4de5-b9bb-c0dc42c695a7@o6g2000yqj.googlegroups.com> On Jun 30, 5:34?pm, Mitchell L Model wrote: > Allow me to add to my previous question that certainly the superclass > methods can be called explicitly without resorting to super(), e.g.: > > ? ? class C(A, B): > ? ? ? ? def __init__(self): > ? ? ? ? ? ? A.__init__(self) > ? ? ? ? ? ? B.__init__(self) > > My question is really whether there is any way of getting around the > explicit class names by using super() Yes there is: just make sure that all subclasses also call super. class A: def __init__(self): super().__init__() print('A') class B: def __init__(self): super().__init__() print('B') class C(A, B): def __init__(self): super().__init__() print('C') Bam, that's it. What's happening is that A's super calls B. That is likely to seem wrong to someone who is very familiar with OOP, but it's how Python's MI works. Read this essay/rant that explains how super works and why the author thinks it's not useful. Then ignore the last part, because I and many others have found it very useful, desipte its drawbacks. http://fuhm.net/super-harmful/ Carl Banks From pavlovevidence at gmail.com Tue Jun 30 21:33:42 2009 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 30 Jun 2009 18:33:42 -0700 (PDT) Subject: invoking a method from two superclasses References: <31fe4bef-6738-4de5-b9bb-c0dc42c695a7@o6g2000yqj.googlegroups.com> Message-ID: On Jun 30, 6:23?pm, Carl Banks wrote: > On Jun 30, 5:34?pm, Mitchell L Model wrote: > > > Allow me to add to my previous question that certainly the superclass > > methods can be called explicitly without resorting to super(), e.g.: > > > ? ? class C(A, B): > > ? ? ? ? def __init__(self): > > ? ? ? ? ? ? A.__init__(self) > > ? ? ? ? ? ? B.__init__(self) > > > My question is really whether there is any way of getting around the > > explicit class names by using super() > > Yes there is: just make sure that all subclasses also call super. And by subclasses I mean base classes, of course. ugh Carl Banks From magawake at gmail.com Tue Jun 30 21:52:18 2009 From: magawake at gmail.com (Mag Gam) Date: Tue, 30 Jun 2009 21:52:18 -0400 Subject: Multi thread reading a file Message-ID: <1cbd6f830906301852t4febbb02q99528f2d6ec94a82@mail.gmail.com> Hello All, I am very new to python and I am in the process of loading a very large compressed csv file into another format. I was wondering if I can do this in a multi thread approach. Here is the pseudo code I was thinking about: Let T = Total number of lines in a file, Example 1000000 (1 million files) Let B = Total number of lines in a buffer, for example 10000 lines Create a thread to read until buffer Create another thread to read buffer+buffer ( So we have 2 threads now. But since the file is zipped I have to wait until the first thread is completed. Unless someone knows of a clever technique. Write the content of thread 1 into a numpy array Write the content of thread 2 into a numpy array But I don't think we are capable of multiprocessing tasks for this.... Any ideas? Has anyone ever tackled a problem like this before? From david.lyon at preisshare.net Tue Jun 30 22:12:09 2009 From: david.lyon at preisshare.net (David Lyon) Date: Tue, 30 Jun 2009 22:12:09 -0400 Subject: packaging apps In-Reply-To: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> References: <9c8c445f0906300811v443d3424s46afd7185e0d1d89@mail.gmail.com> Message-ID: On Tue, 30 Jun 2009 11:11:15 -0400, Ronn Ross wrote: > I have a simple application that has a glade file and a .py file. How would > I package that into an installer for Windows, Mac, and a deb file? Can > anyone point me in the right direction? I don't think there is a simple way to do that just yet... Of course, you could make a source distribution and do it for each of these platforms using the documentation available at: http://docs.python.org/distutils/ I'm struggling with that myself.. I can never remember command lines.. So maybe it is time that I try to throw together a tool a little bit like the package manager except that it does the building.. for all those platforms... I think it's time for distutils to have some sort of gui build tool... and I've been talking about it for too long now... haha David From Scott.Daniels at Acm.Org Tue Jun 30 23:11:38 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 20:11:38 -0700 Subject: PEP 376 In-Reply-To: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> References: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> Message-ID: <1fSdnV38IJnYT9fXnZ2dnUVZ_g2dnZ2d@pdx.net> Carl Banks wrote: > On Jun 30, 5:55 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Tarek >> >> Ziad? wrote: >>> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >>> http://www.python.org/dev/peps/pep-0376/ >> Why are you using MD5? > > I doubt it's the design aim for eggs to be cryptographically secure, > and MD5 is sufficient to detect changes. On the other hand, SHA1 is easily within the reach of current and older CPUs, while problems have already been found with forgeble MD5 puns, and we cannot expect the cases to shrink. I don't see much harm in going for SHA1 now as something likely to last a few years. --Scott David Daniels Scott.Daniels at Acm.Org From Joachim at Strombergson.com Tue Jun 30 23:19:52 2009 From: Joachim at Strombergson.com (=?ISO-8859-1?Q?Joachim_Str=F6mbergson?=) Date: Wed, 01 Jul 2009 05:19:52 +0200 Subject: PEP 376 In-Reply-To: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> References: <73587ae3-4f4f-4243-a8af-cf4a6bfb598b@k26g2000vbp.googlegroups.com> Message-ID: <4A4AD5D8.9060208@Strombergson.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Aloha! Carl Banks wrote: > On Jun 30, 5:55 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Tarek >> >> Ziad? wrote: >>> I would like to propose this PEP for inclusion into Python 2.7 / 3.2 >>> http://www.python.org/dev/peps/pep-0376/ >> Why are you using MD5? > > I doubt it's the design aim for eggs to be cryptographically secure, > and MD5 is sufficient to detect changes. Even so, choosing md5 in 2009 for something that (hopefully) will be used in years is a bad design decision. It creates a dependency for to an algorithm that all sensible recommendations point you to move away from. Just check hashlib documentation for example: http://docs.python.org/library/hashlib.html I would suggest to use the SHA-256 in the library. The reason for this is that md5 and SHA-1 are weak. The computational complexity of SHA-256 is bigger, but since it probably wont be done many thousands of times during an egg installation, it shouldn't add a noticable delay. - -- Med v?nlig h?lsning, Yours Joachim Str?mbergson - Alltid i harmonisk sv?ngning. ======================================================================== Kryptoblog - IT-s?kerhet p? svenska http://www.strombergson.com/kryptoblog ======================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpK1dgACgkQZoPr8HT30QEwRACg0vhO6TO1k0Pesm5qQOJVen/H vxwAoKdNZZkrDvm/CtQVbr0kZog0sX/U =Frss -----END PGP SIGNATURE----- From MLMLists at Comcast.net Tue Jun 30 23:39:16 2009 From: MLMLists at Comcast.net (Mitchell L Model) Date: Tue, 30 Jun 2009 23:39:16 -0400 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: >From: Scott David Daniels >Date: Tue, 30 Jun 2009 16:49:18 -0700 >Message-ID: >Subject: Re: invoking a method from two superclasses > >Mitchell L Model wrote: >>In Python 3, how should super() be used to invoke a method defined in C > > that overrides its two superclasses A and B, in particular __init__? >>... >>I've discovered the surprising fact described in the documentation of super >> >>that specifying a class as the first argument of super means to skip that class when >>scanning the mro so that .... >> >>This seems weird. Would someone please give a clear example and explanation of >>the recommended way of initializing both superclasses in a simple multiple inheritance >>situation? > >OK, in Diamond inheritance in Python (and all multi-inheritance is >diamond-shaped in Python), the common ancestor must have a method >in order to properly use super. The mro is guaranteed to have the >top of the split (C below) before its children in the mro, and the >join point (object or root below) after all of the classes from >which it inherits. > >So, the correct way to do what you want: > class A: > def __init__(self): > super().__init__() > print('A') > > class B: > def __init__(self): > super().__init__() > print('B') > > class C(A, B): > def __init__(self): > super().__init__() > print('C') > > C() > >And, if you are doing it with a message not available in object: > > class root: > def prints(self): > print('root') # or pass if you prefer > > class A(root): > def prints(self): > super().prints() > print('A') > > class B(root): > def prints(self): > super().prints() > print('B') > > class C(A, B): > def prints(self): > super().prints() > print('C') > > C().prints() > >--Scott David Daniels >Scott.Daniels at Acm.Org > Great explanation, and 1/2 a "duh" to me. Thanks. What I was missing is that each path up to and including the top of the diamond must include a definition of the method, along with super() calls to move the method calling on its way up. Is this what the documentation means by "cooperative multiple inheritance"? If your correction of my example, if you remove super().__init__ from B.__init__ the results aren't affected, because object.__init__ doesn't do anything and B comes after A in C's mro. However, if you remove super().__init__ from A.__init__, it stops the "supering" process dead in its tracks. It would appear that "super()" really means something like CLOS's call-next-method. I've seen various discussions in people's blogs to the effect that super() doesn't really mean superclass, and I'm beginning to develop sympathy with that view. I realize that implementationally super is a complicated proxy; understanding the practical implications isn't so easy. While I've seen all sorts of arguments and discussions, including the relevant PEP(s), I don't think I've ever seen anyone lay out an example such as we are discussing with the recommendation that basically if you are using super() in multiple inheritance situations, make sure that the methods of all the classes in the mro up to at least the top of a diamond all call super() so it can continue to move the method calls along the mro. The documentation of super(), for instance, recommends that all the methods in the diamond should have the same signature, but and it says that super() can be used to implement the diamond, but it never actually comes out and says that each method below the top must call super() at the risk of the chain of calls being broken. I do wonder whether this should go in the doc of super, the tutorial, or a HOWTO -- it just seems to important and subtle to leave for people to discover. Again, many thanks for the quick and clear response. From Scott.Daniels at Acm.Org Tue Jun 30 23:57:27 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 30 Jun 2009 20:57:27 -0700 Subject: invoking a method from two superclasses In-Reply-To: References: Message-ID: Mitchell L Model wrote: >> From: Scott David Daniels >> Date: Tue, 30 Jun 2009 16:49:18 -0700 >> Message-ID: >> Subject: Re: invoking a method from two superclasses >> >> Mitchell L Model wrote: >>> In Python 3, how should super() be used to invoke a method defined in C >>> that overrides its two superclasses A and B, in particular __init__? >>> ... >>> I've discovered the surprising fact described in the documentation of super >>> >>> that specifying a class as the first argument of super means to skip that class when >>> scanning the mro so that .... >>> >>> This seems weird. Would someone please give a clear example and explanation of >>> the recommended way of initializing both superclasses in a simple multiple inheritance >>> situation? >> OK, in Diamond inheritance in Python (and all multi-inheritance is >> diamond-shaped in Python), the common ancestor must have a method >> in order to properly use super. The mro is guaranteed to have the >> top of the split (C below) before its children in the mro, and the >> join point (object or root below) after all of the classes from >> which it inherits. >> >> So, the correct way to do what you want: >> class A: >> def __init__(self): >> super().__init__() >> print('A') >> >> class B: >> def __init__(self): >> super().__init__() >> print('B') >> >> class C(A, B): >> def __init__(self): >> super().__init__() >> print('C') >> >> C() >> >> And, if you are doing it with a message not available in object: >> >> class root: >> def prints(self): >> print('root') # or pass if you prefer >> >> class A(root): >> def prints(self): >> super().prints() >> print('A') >> >> class B(root): >> def prints(self): >> super().prints() >> print('B') >> >> class C(A, B): >> def prints(self): >> super().prints() >> print('C') >> >> C().prints() >> >> --Scott David Daniels >> Scott.Daniels at Acm.Org >> > > Great explanation, and 1/2 a "duh" to me. Thanks. > What I was missing is that each path up to and including the top of the diamond > must include a definition of the method, along with super() calls to move the method > calling on its way up. Is this what the documentation means by > "cooperative multiple inheritance"? I expect so. > ... Again, many thanks for the quick and clear response. Since you know exactly what is confusing right now, and what the resolution is, could I lean on you to take a stab at improving the explanation? I think I know what the solution is, but I don't have a good handle on what needs explaining and what is easily understood. If you do something, others can fix it where it doesn't work. --Scott David Daniels Scott.Daniels at Acm.Org